react-semaphor 0.1.504 → 0.1.506

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 (1468) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +10 -10
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +4 -4
  5. package/dist/briefings/index.cjs +1 -1
  6. package/dist/briefings/index.js +5 -5
  7. package/dist/chunks/{calculated-field-identity-BC2NViZZ.js → calculated-field-identity-BTpUqfEu.js} +4 -4
  8. package/dist/chunks/{calculated-field-identity-CtYhhZoG.cjs → calculated-field-identity-rMuXuzEY.cjs} +1 -1
  9. package/dist/chunks/{constants-CTRduy1g.js → constants-NUleP4DY.js} +5 -5
  10. package/dist/chunks/{constants-DNgpRMaX.cjs → constants-vtu7_IUo.cjs} +1 -1
  11. package/dist/chunks/{dashboard-briefing-launcher-C3X_EL1X.cjs → dashboard-briefing-launcher-C8nDSDnV.cjs} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-COiVqc_h.js → dashboard-briefing-launcher-DXTpU85p.js} +9 -9
  13. package/dist/chunks/{dashboard-controls-r_oYt62o.js → dashboard-controls-CyL0yimg.js} +11 -11
  14. package/dist/chunks/{dashboard-controls-BQFt_Om0.cjs → dashboard-controls-DlxeddZN.cjs} +1 -1
  15. package/dist/chunks/{dashboard-date-comparison-definition-C1vJshiP.js → dashboard-date-comparison-definition-BX0ltXzm.js} +1 -1
  16. package/dist/chunks/{dashboard-date-comparison-definition-CWz_Yte8.cjs → dashboard-date-comparison-definition-C_w-GO_5.cjs} +1 -1
  17. package/dist/chunks/{dashboard-json-CUfulKs3.js → dashboard-json-5Jr3RudV.js} +7 -7
  18. package/dist/chunks/{dashboard-json-zT5RVUQH.cjs → dashboard-json-DhS4yJfc.cjs} +1 -1
  19. package/dist/chunks/{edit-dashboard-visual-B07ITktK.js → edit-dashboard-visual-C7X-um9g.js} +15 -15
  20. package/dist/chunks/{edit-dashboard-visual-kDqyZQZg.cjs → edit-dashboard-visual-X3OCnivL.cjs} +1 -1
  21. package/dist/chunks/{editor-action-buttons-ZoxtR85t.js → editor-action-buttons-C5Wja_J4.js} +6 -6
  22. package/dist/chunks/{editor-action-buttons-BC0asNB0.cjs → editor-action-buttons-CcDm8nA5.cjs} +1 -1
  23. package/dist/chunks/{field-aggregations-tLaXZ2VJ.js → field-aggregations-BU_3gHKR.js} +5 -5
  24. package/dist/chunks/{field-aggregations-mlkON_QA.cjs → field-aggregations-CDCamEsQ.cjs} +1 -1
  25. package/dist/chunks/{field-dependencies-ZE2klbHO.js → field-dependencies-DVl2p1Nm.js} +1 -1
  26. package/dist/chunks/{field-dependencies-R7MrlW6D.cjs → field-dependencies-r_U0CGQ-.cjs} +1 -1
  27. package/dist/chunks/{index-BVIet238.js → index-BVr4fcCB.js} +11 -11
  28. package/dist/chunks/{index-Bh3SlWJS.cjs → index-BlYf8gNa.cjs} +1 -1
  29. package/dist/chunks/{index-mSHUZATx.cjs → index-DSa6RSdg.cjs} +6 -6
  30. package/dist/chunks/{index-Cx2yQ9nq.js → index-De2QNsqV.js} +60 -62
  31. package/dist/chunks/{matrix-analytical-definition-wIEDXvV5.cjs → matrix-analytical-definition-Ct5Tu8np.cjs} +1 -1
  32. package/dist/chunks/{matrix-analytical-definition-CIVFNNnF.js → matrix-analytical-definition-xesmc3Qa.js} +1 -1
  33. package/dist/chunks/{matrix-card-Dh0J0_Of.cjs → matrix-card-CRXcmAjp.cjs} +1 -1
  34. package/dist/chunks/{matrix-card-BVvKHL7s.js → matrix-card-DACDwdTq.js} +2 -2
  35. package/dist/chunks/{matrix-control-sources-a67fwoOO.cjs → matrix-control-sources-CeC5EMyq.cjs} +1 -1
  36. package/dist/chunks/{matrix-control-sources-CjnsBREg.js → matrix-control-sources-ClQzIk7E.js} +5 -5
  37. package/dist/chunks/{matrix-definition-CKVi4VVg.cjs → matrix-definition-CBJW_4ii.cjs} +1 -1
  38. package/dist/chunks/{matrix-definition-BEXCfZAe.js → matrix-definition-RyU0cpLX.js} +1 -1
  39. package/dist/chunks/{matrix-formatter-CWtdnbfv.cjs → matrix-formatter-7GLTcBuy.cjs} +1 -1
  40. package/dist/chunks/{matrix-formatter-BTPfthsa.js → matrix-formatter-xsq7n_e6.js} +4 -4
  41. package/dist/chunks/{matrix-member-presentation-e_KZoZOx.cjs → matrix-member-presentation-E2B4k3ws.cjs} +1 -1
  42. package/dist/chunks/{matrix-member-presentation-DiDUvZts.js → matrix-member-presentation-qiHxv67e.js} +1 -1
  43. package/dist/chunks/{matrix-operation-contract-CPgckXxm.js → matrix-operation-contract-Cqy4EW2H.js} +1 -1
  44. package/dist/chunks/{matrix-operation-contract-thtFuUYf.cjs → matrix-operation-contract-D9dLX-Wr.cjs} +1 -1
  45. package/dist/chunks/{metric-comparison-Dgyq1I3d.js → metric-comparison-C-sYqv0g.js} +1 -1
  46. package/dist/chunks/{metric-comparison-CAqV6VnZ.cjs → metric-comparison-DBQ3EJTz.cjs} +1 -1
  47. package/dist/chunks/{pivot-header-presentation-DUXM-VOP.cjs → pivot-header-presentation-3wqWChFd.cjs} +1 -1
  48. package/dist/chunks/{pivot-header-presentation-DcCO8-Ij.js → pivot-header-presentation-D44ODZGn.js} +3 -3
  49. package/dist/chunks/{pivot-result-identity-Be1zm0AV.js → pivot-result-identity-BSudrDLN.js} +1 -1
  50. package/dist/chunks/{pivot-result-identity-DJyF4I2K.cjs → pivot-result-identity-uTiylUNr.cjs} +1 -1
  51. package/dist/chunks/{pivot-result-lifecycle-DpSZOMOZ.js → pivot-result-lifecycle-BSmqVkVG.js} +7 -7
  52. package/dist/chunks/{pivot-result-lifecycle-E_huAPev.cjs → pivot-result-lifecycle-DZ0ZSMoM.cjs} +1 -1
  53. package/dist/chunks/{raw-temporal-DYoPBY6B.cjs → raw-temporal-BUeTpG76.cjs} +1 -1
  54. package/dist/chunks/{raw-temporal-DfnRBxQn.js → raw-temporal-CUJ86xHI.js} +2 -2
  55. package/dist/chunks/{raw-temporal-contract-D1_n2pBj.cjs → raw-temporal-contract-DECbTuzA.cjs} +1 -1
  56. package/dist/chunks/{raw-temporal-contract-CNwYygW2.js → raw-temporal-contract-Eyr5U8DK.js} +1 -1
  57. package/dist/chunks/{report-preferences-dialog-BMktSijb.cjs → report-preferences-dialog-7Vsc_fsG.cjs} +1 -1
  58. package/dist/chunks/{report-preferences-dialog-CGUaGQGv.js → report-preferences-dialog-xADifRXs.js} +6 -6
  59. package/dist/chunks/{report-runtime-context-Dln1qvGS.js → report-runtime-context-DWvUf1HT.js} +1 -1
  60. package/dist/chunks/{report-runtime-context-CqFbgZq9.cjs → report-runtime-context-DzvHBPxl.cjs} +1 -1
  61. package/dist/chunks/{semantic-format-C7Goni6h.cjs → semantic-format-BhIL1PXP.cjs} +1 -1
  62. package/dist/chunks/{semantic-format-PKQt2EAz.js → semantic-format-C3amkGmY.js} +2 -2
  63. package/dist/chunks/{source-entity-resolution-BMKxwdKN.cjs → source-entity-resolution-CjbgnwyX.cjs} +1 -1
  64. package/dist/chunks/{source-entity-resolution-BSZ07Sl6.js → source-entity-resolution-DZhUckix.js} +1 -1
  65. package/dist/chunks/{switch-Dp4U6GwI.cjs → switch-BytP6QY8.cjs} +1 -1
  66. package/dist/chunks/{switch-BNPVlnfs.js → switch-DHGiC0aU.js} +12 -12
  67. package/dist/chunks/{temporal-bucket-contract-_WCvDnvn.js → temporal-bucket-contract-D5QlJbmm.js} +1 -1
  68. package/dist/chunks/{temporal-bucket-contract-CSdspcYj.cjs → temporal-bucket-contract-ZctiyXYk.cjs} +1 -1
  69. package/dist/chunks/{update-policy-BESKAspa.cjs → update-policy-Cc9h57pA.cjs} +1 -1
  70. package/dist/chunks/{update-policy-BWbXhkk-.js → update-policy-eTcz52jO.js} +2 -2
  71. package/dist/chunks/{validators-CHlnnHuS.js → validators-BDYzZFgs.js} +177 -177
  72. package/dist/chunks/validators-DVYAnnX0.cjs +1 -0
  73. package/dist/dashboard/index.cjs +1 -1
  74. package/dist/dashboard/index.js +1 -1
  75. package/dist/dashboard-authoring/index.cjs +1 -1
  76. package/dist/dashboard-authoring/index.js +9 -9
  77. package/dist/data-app-builder/index.cjs +1 -1
  78. package/dist/data-app-builder/index.js +2 -2
  79. package/dist/data-app-codegen/index.cjs +1 -1
  80. package/dist/data-app-codegen/index.js +2 -2
  81. package/dist/data-app-codegen-node/index.cjs +1 -1
  82. package/dist/data-app-codegen-node/index.js +3 -3
  83. package/dist/data-app-sdk/index.cjs +2 -2
  84. package/dist/data-app-sdk/index.js +189 -171
  85. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  86. package/dist/data-app-sdk-adapters/index.js +2 -2
  87. package/dist/data-app-sdk-validation/index.cjs +1 -1
  88. package/dist/data-app-sdk-validation/index.js +5 -5
  89. package/dist/format-utils/index.cjs +1 -1
  90. package/dist/format-utils/index.js +16 -16
  91. package/dist/index.cjs +1 -1
  92. package/dist/index.js +15 -15
  93. package/dist/report-runtime-context/index.cjs +1 -1
  94. package/dist/report-runtime-context/index.js +2 -2
  95. package/dist/surfboard/index.cjs +1 -1
  96. package/dist/surfboard/index.js +2 -2
  97. package/dist/types/analytics-protocol.d.ts +2 -69099
  98. package/dist/types/appearance/index.d.ts +4 -0
  99. package/dist/types/appearance/runtime.d.ts +2 -0
  100. package/dist/types/appearance-runtime.d.ts +2 -152
  101. package/dist/types/appearance.d.ts +2 -177
  102. package/dist/types/brand-studio/brand-studio-draft.d.ts +81 -0
  103. package/dist/types/brand-studio/brand-studio-editor.d.ts +14 -0
  104. package/dist/types/brand-studio/index.d.ts +2 -0
  105. package/dist/types/brand-studio.d.ts +2 -246
  106. package/dist/types/briefings/attachments.d.ts +15 -0
  107. package/dist/types/briefings/capabilities.d.ts +5 -0
  108. package/dist/types/briefings/creation.d.ts +6 -0
  109. package/dist/types/briefings/display.d.ts +21 -0
  110. package/dist/types/briefings/index.d.ts +362 -0
  111. package/dist/types/briefings/presentation-contract.d.ts +64 -0
  112. package/dist/types/briefings/schedule.d.ts +18 -0
  113. package/dist/types/briefings.d.ts +2 -17437
  114. package/dist/types/components/ai/assistant-context-entity-controls.d.ts +25 -0
  115. package/dist/types/components/ai/assistant-message-components.d.ts +59 -0
  116. package/dist/types/components/ai/assistant-message.d.ts +10 -0
  117. package/dist/types/components/ai/assistant-virtualized-messages.d.ts +21 -0
  118. package/dist/types/components/ai/chat-custom-visual.d.ts +21 -0
  119. package/dist/types/components/ai/chat-input-with-context.d.ts +16 -0
  120. package/dist/types/components/ai/chat-input.d.ts +11 -0
  121. package/dist/types/components/ai/chat-visual-query-utils.d.ts +95 -0
  122. package/dist/types/components/ai/chat-visual.d.ts +12 -0
  123. package/dist/types/components/ai/clarification-card.d.ts +20 -0
  124. package/dist/types/components/ai/context-entity-display.d.ts +10 -0
  125. package/dist/types/components/ai/dashboard-assistant.d.ts +30 -0
  126. package/dist/types/components/ai/debug-message-array.d.ts +1 -0
  127. package/dist/types/components/ai/dynamic-visual-host.d.ts +23 -0
  128. package/dist/types/components/ai/editor-assistant.d.ts +7 -0
  129. package/dist/types/components/ai/entity-mention-dropdown.d.ts +15 -0
  130. package/dist/types/components/ai/file-upload/file-preview.d.ts +14 -0
  131. package/dist/types/components/ai/file-upload/file-upload-button.d.ts +9 -0
  132. package/dist/types/components/ai/file-upload/file-upload-zone.d.ts +11 -0
  133. package/dist/types/components/ai/file-upload/file-utils.d.ts +63 -0
  134. package/dist/types/components/ai/highlighted-input.d.ts +22 -0
  135. package/dist/types/components/ai/message-feedback-buttons.d.ts +9 -0
  136. package/dist/types/components/ai/pending-messages-display.d.ts +7 -0
  137. package/dist/types/components/ai/persisted-dynamic-visual.d.ts +15 -0
  138. package/dist/types/components/ai/placeholders.d.ts +8 -0
  139. package/dist/types/components/ai/pre-block.d.ts +30 -0
  140. package/dist/types/components/ai/quick-replies.d.ts +8 -0
  141. package/dist/types/components/ai/reasoning-effort-slider.d.ts +7 -0
  142. package/dist/types/components/ai/seed-questions.d.ts +6 -0
  143. package/dist/types/components/ai/tool-call-error.d.ts +8 -0
  144. package/dist/types/components/ai/tool-call.d.ts +12 -0
  145. package/dist/types/components/ai/tool-output-errors.d.ts +2 -0
  146. package/dist/types/components/ai/tool-part-renderer.d.ts +32 -0
  147. package/dist/types/components/appearance/dashboard-appearance-adapter.d.ts +17 -0
  148. package/dist/types/components/appearance/surface-appearance-adapter.d.ts +21 -0
  149. package/dist/types/components/briefings/attachments/briefing-attachment-list.d.ts +9 -0
  150. package/dist/types/components/briefings/attachments/briefing-attachment-selector.d.ts +27 -0
  151. package/dist/types/components/briefings/attachments/briefing-attachment-settings-dialog.d.ts +16 -0
  152. package/dist/types/components/briefings/briefing-author/attachment-section.d.ts +20 -0
  153. package/dist/types/components/briefings/briefing-author/author-actions.d.ts +25 -0
  154. package/dist/types/components/briefings/briefing-author/content-composers.d.ts +9 -0
  155. package/dist/types/components/briefings/briefing-author/defaults.d.ts +1 -0
  156. package/dist/types/components/briefings/briefing-author/delivery-section.d.ts +56 -0
  157. package/dist/types/components/briefings/briefing-author/form-primitives.d.ts +20 -0
  158. package/dist/types/components/briefings/briefing-author/output.d.ts +2 -0
  159. package/dist/types/components/briefings/briefing-author/policy.d.ts +40 -0
  160. package/dist/types/components/briefings/briefing-author/presentation-vocabulary.d.ts +17 -0
  161. package/dist/types/components/briefings/briefing-author/run-model.d.ts +49 -0
  162. package/dist/types/components/briefings/briefing-author/run-ui.d.ts +81 -0
  163. package/dist/types/components/briefings/briefing-author/schedule-model.d.ts +3 -0
  164. package/dist/types/components/briefings/briefing-author/schedule-section.d.ts +5 -0
  165. package/dist/types/components/briefings/briefing-author/schedule.d.ts +8 -0
  166. package/dist/types/components/briefings/briefing-author/scope-picker.d.ts +14 -0
  167. package/dist/types/components/briefings/briefing-author/slack-channel-picker.d.ts +22 -0
  168. package/dist/types/components/briefings/briefing-author/styles.d.ts +4 -0
  169. package/dist/types/components/briefings/briefing-author-dialog.d.ts +24 -0
  170. package/dist/types/components/briefings/briefing-author.d.ts +72 -0
  171. package/dist/types/components/briefings/briefing-html-frame.d.ts +5 -0
  172. package/dist/types/components/briefings/briefing-recipient-field.d.ts +17 -0
  173. package/dist/types/components/briefings/briefing-tones.d.ts +30 -0
  174. package/dist/types/components/briefings/briefing-ui-capabilities.d.ts +16 -0
  175. package/dist/types/components/briefings/dashboard-briefing-launcher-list.d.ts +25 -0
  176. package/dist/types/components/briefings/dashboard-briefing-launcher-model.d.ts +14 -0
  177. package/dist/types/components/briefings/dashboard-briefing-launcher.d.ts +25 -0
  178. package/dist/types/components/briefings/dashboard-schedule-report-menu-item.d.ts +11 -0
  179. package/dist/types/components/briefings/index.d.ts +9 -0
  180. package/dist/types/components/briefings/use-briefing-run-polling.d.ts +34 -0
  181. package/dist/types/components/briefings/watch-dashboard-button.d.ts +7 -0
  182. package/dist/types/components/calculated-fields/ai-compose-panel.d.ts +19 -0
  183. package/dist/types/components/calculated-fields/calculated-field-editor-utils.d.ts +44 -0
  184. package/dist/types/components/calculated-fields/calculated-field-editor.d.ts +26 -0
  185. package/dist/types/components/calculated-fields/domain-definition-notice.d.ts +4 -0
  186. package/dist/types/components/calculated-fields/expression-validator.d.ts +8 -0
  187. package/dist/types/components/calculated-fields/field-picker-panel.d.ts +16 -0
  188. package/dist/types/components/calculated-fields/field-type-toggle.d.ts +7 -0
  189. package/dist/types/components/calculated-fields/index.d.ts +10 -0
  190. package/dist/types/components/calculated-fields/insert-field-popover.d.ts +18 -0
  191. package/dist/types/components/calculated-fields/summary-ribbon.d.ts +23 -0
  192. package/dist/types/components/calculated-fields/templates-menu.d.ts +14 -0
  193. package/dist/types/components/calculated-fields/validation-results.d.ts +4 -0
  194. package/dist/types/components/calculated-fields/validation-tooltip-content.d.ts +4 -0
  195. package/dist/types/components/chart-selector/chart-icon.d.ts +36 -0
  196. package/dist/types/components/chart-selector/chart-selector-item.d.ts +19 -0
  197. package/dist/types/components/chart-selector/chart-selector.d.ts +19 -0
  198. package/dist/types/components/chart-selector/chart-type-picker.d.ts +12 -0
  199. package/dist/types/components/chart-selector/index.d.ts +5 -0
  200. package/dist/types/components/chart-selector/star-button.d.ts +13 -0
  201. package/dist/types/components/chart-selector/use-chart-selector-model.d.ts +18 -0
  202. package/dist/types/components/dashboard/ai-dashboard-create-dialog.d.ts +38 -0
  203. package/dist/types/components/dashboard/card-actions-menu.d.ts +10 -0
  204. package/dist/types/components/dashboard/card-summary.d.ts +8 -0
  205. package/dist/types/components/dashboard/comparison-badge-state.d.ts +3 -0
  206. package/dist/types/components/dashboard/comparison-metadata-badge.d.ts +11 -0
  207. package/dist/types/components/dashboard/dashboard-card.d.ts +17 -0
  208. package/dist/types/components/dashboard/dashboard-container.d.ts +9 -0
  209. package/dist/types/components/dashboard/dashboard-create-template.d.ts +10 -0
  210. package/dist/types/components/dashboard/dashboard-error-state.d.ts +9 -0
  211. package/dist/types/components/dashboard/dashboard-export-dialog.d.ts +5 -0
  212. package/dist/types/components/dashboard/dashboard-frame-expand-dialog.d.ts +5 -0
  213. package/dist/types/components/dashboard/dashboard-frame.d.ts +14 -0
  214. package/dist/types/components/dashboard/dashboard-hub-row.d.ts +18 -0
  215. package/dist/types/components/dashboard/dashboard-hub-sort.d.ts +8 -0
  216. package/dist/types/components/dashboard/dashboard-hub.d.ts +5 -0
  217. package/dist/types/components/dashboard/dashboard-tabs.d.ts +1 -0
  218. package/dist/types/components/dashboard/dashboard-visual-error-state.d.ts +14 -0
  219. package/dist/types/components/dashboard/dashboard-web-component.d.ts +1 -0
  220. package/dist/types/components/dashboard/dashboard.d.ts +2 -0
  221. package/dist/types/components/dashboard/download-pdf.d.ts +10 -0
  222. package/dist/types/components/dashboard/drill-breadcrumb.d.ts +6 -0
  223. package/dist/types/components/dashboard/drill-navigation-controls.d.ts +13 -0
  224. package/dist/types/components/dashboard/index.d.ts +3 -0
  225. package/dist/types/components/dashboard/inline-filter-bar.d.ts +16 -0
  226. package/dist/types/components/dashboard/inline-filter-component.d.ts +29 -0
  227. package/dist/types/components/dashboard/kpi-header.d.ts +2 -0
  228. package/dist/types/components/dashboard/semaphor-style-wrapper.d.ts +3 -0
  229. package/dist/types/components/dashboard/sheet/delete-sheet-alert.d.ts +6 -0
  230. package/dist/types/components/dashboard/sheet/layout-change-guard.d.ts +6 -0
  231. package/dist/types/components/dashboard/sheet/sheet-empty-state.d.ts +5 -0
  232. package/dist/types/components/dashboard/sheet/sheet-layout.d.ts +4 -0
  233. package/dist/types/components/dashboard/sheet/sheet-layout_backup.d.ts +0 -0
  234. package/dist/types/components/dashboard/summary-card.d.ts +16 -0
  235. package/dist/types/components/dashboard/summary-number-formatter.d.ts +12 -0
  236. package/dist/types/components/dashboard/summary-warning-utils.d.ts +6 -0
  237. package/dist/types/components/dashboard/unconfigured-card-state.d.ts +21 -0
  238. package/dist/types/components/data-app-runtime/published-data-app-runtime.d.ts +7 -0
  239. package/dist/types/components/document-sheet/document-control-options-resolver.d.ts +9 -0
  240. package/dist/types/components/document-sheet/document-control-toolbar-actions.d.ts +12 -0
  241. package/dist/types/components/document-sheet/document-controls-settings.d.ts +7 -0
  242. package/dist/types/components/document-sheet/document-input-bar.d.ts +32 -0
  243. package/dist/types/components/document-sheet/document-inspector-primitives.d.ts +10 -0
  244. package/dist/types/components/document-sheet/document-outline.d.ts +15 -0
  245. package/dist/types/components/document-sheet/document-page.d.ts +64 -0
  246. package/dist/types/components/document-sheet/document-sheet.d.ts +10 -0
  247. package/dist/types/components/document-sheet/document-table-section.d.ts +32 -0
  248. package/dist/types/components/document-sheet/document-text-editor.d.ts +8 -0
  249. package/dist/types/components/editor/dashboard-json.d.ts +1 -0
  250. package/dist/types/components/editor/dynamic-visualization-menu-items.d.ts +3 -0
  251. package/dist/types/components/editor/editable.d.ts +14 -0
  252. package/dist/types/components/editor/editor-aside/utils.d.ts +28 -0
  253. package/dist/types/components/editor/editor-main/advanced-mode-toggle.d.ts +21 -0
  254. package/dist/types/components/editor/editor-main/card-display-options-dropdown.d.ts +7 -0
  255. package/dist/types/components/editor/editor-main/card-tabs.d.ts +16 -0
  256. package/dist/types/components/editor/editor-main/chart-configuration-options.d.ts +1 -0
  257. package/dist/types/components/editor/editor-main/clear-card-utils.d.ts +2 -0
  258. package/dist/types/components/editor/editor-main/code-editors/expanded-query-editor-dialog.d.ts +14 -0
  259. package/dist/types/components/editor/editor-main/code-editors/json-editor-readonly.d.ts +3 -0
  260. package/dist/types/components/editor/editor-main/code-editors/python-editor.d.ts +2 -0
  261. package/dist/types/components/editor/editor-main/code-editors/sql-editor.d.ts +6 -0
  262. package/dist/types/components/editor/editor-main/code-editors/use-query-editor-session-transfer.d.ts +17 -0
  263. package/dist/types/components/editor/editor-main/content-editable-text.d.ts +10 -0
  264. package/dist/types/components/editor/editor-main/context-hover-card.d.ts +1 -0
  265. package/dist/types/components/editor/editor-main/customize-visual/customize-chart-config.d.ts +7 -0
  266. package/dist/types/components/editor/editor-main/customize-visual/customize-visual-dialog.d.ts +7 -0
  267. package/dist/types/components/editor/editor-main/dashboard-filter-subscription-status.d.ts +6 -0
  268. package/dist/types/components/editor/editor-main/dashboard-variable-node.d.ts +25 -0
  269. package/dist/types/components/editor/editor-main/data-label-settings.d.ts +5 -0
  270. package/dist/types/components/editor/editor-main/dynamic-visual-editor.d.ts +13 -0
  271. package/dist/types/components/editor/editor-main/edit-dashboard-visual.d.ts +1 -0
  272. package/dist/types/components/editor/editor-main/editor-action-buttons.d.ts +28 -0
  273. package/dist/types/components/editor/editor-main/editor-actions-biz-mode.d.ts +1 -0
  274. package/dist/types/components/editor/editor-main/editor-card.d.ts +4 -0
  275. package/dist/types/components/editor/editor-main/editor-chart-config-execution.d.ts +6 -0
  276. package/dist/types/components/editor/editor-main/editor-main-component.d.ts +1 -0
  277. package/dist/types/components/editor/editor-main/editor-query-section.d.ts +10 -0
  278. package/dist/types/components/editor/editor-main/editor-visual-dropdown.d.ts +0 -0
  279. package/dist/types/components/editor/editor-main/editor-visual-section.d.ts +28 -0
  280. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer-constants.d.ts +7 -0
  281. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer-prompts.d.ts +19 -0
  282. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer-telemetry.d.ts +2 -0
  283. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer-types.d.ts +48 -0
  284. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer-utils.d.ts +11 -0
  285. package/dist/types/components/editor/editor-main/inline-query-writer/inline-query-writer.d.ts +2 -0
  286. package/dist/types/components/editor/editor-main/legend-popover.d.ts +1 -0
  287. package/dist/types/components/editor/editor-main/raw-output-table.d.ts +14 -0
  288. package/dist/types/components/editor/editor-main/realtime-popover.d.ts +1 -0
  289. package/dist/types/components/editor/editor-main/table-type-switcher.d.ts +5 -0
  290. package/dist/types/components/editor/editor-main/text-card-rich-editor.d.ts +21 -0
  291. package/dist/types/components/editor/editor-main/text-card.d.ts +9 -0
  292. package/dist/types/components/editor/editor-main/use-editor-clear-action.d.ts +1 -0
  293. package/dist/types/components/editor/editor-main/visual-aside.d.ts +5 -0
  294. package/dist/types/components/editor/editor-main/visual-editing-controls.d.ts +6 -0
  295. package/dist/types/components/editor/editor-main/visual-save-as-dialog.d.ts +17 -0
  296. package/dist/types/components/editor/editor-main/visual-settings.d.ts +9 -0
  297. package/dist/types/components/editor/editor.d.ts +8 -0
  298. package/dist/types/components/editor/mode-toggle.d.ts +13 -0
  299. package/dist/types/components/editor/query-feedback/query-card-details.d.ts +14 -0
  300. package/dist/types/components/editor/query-feedback/query-error.d.ts +42 -0
  301. package/dist/types/components/editor/query-feedback/query-feedback-layout.d.ts +10 -0
  302. package/dist/types/components/editor/query-feedback/query-info-clipboard.d.ts +3 -0
  303. package/dist/types/components/editor/query-feedback/query-info.d.ts +21 -0
  304. package/dist/types/components/editor/query-feedback/query-sql-preview.d.ts +23 -0
  305. package/dist/types/components/editor/query-feedback/use-query-error-feedback.d.ts +7 -0
  306. package/dist/types/components/editor/query-feedback/use-query-error.d.ts +16 -0
  307. package/dist/types/components/editor/query-feedback/visual-query-error-state.d.ts +5 -0
  308. package/dist/types/components/editor/utils/utils.d.ts +2 -0
  309. package/dist/types/components/error-fallbacks/delivery-render-error.d.ts +7 -0
  310. package/dist/types/components/error-fallbacks/fallback.d.ts +19 -0
  311. package/dist/types/components/explorer/chart-configuration/area-series-config-section.d.ts +5 -0
  312. package/dist/types/components/explorer/chart-configuration/axis-config-section.d.ts +1 -0
  313. package/dist/types/components/explorer/chart-configuration/bar-series-config-section.d.ts +5 -0
  314. package/dist/types/components/explorer/chart-configuration/bar-style-config-section.d.ts +7 -0
  315. package/dist/types/components/explorer/chart-configuration/bubble-scatter-config-section.d.ts +1 -0
  316. package/dist/types/components/explorer/chart-configuration/bullet-config-section.d.ts +1 -0
  317. package/dist/types/components/explorer/chart-configuration/chart-config-sections.d.ts +15 -0
  318. package/dist/types/components/explorer/chart-configuration/chart-configuration-panel.d.ts +18 -0
  319. package/dist/types/components/explorer/chart-configuration/chart-fields-configuration.d.ts +22 -0
  320. package/dist/types/components/explorer/chart-configuration/chart-quick-selector.d.ts +19 -0
  321. package/dist/types/components/explorer/chart-configuration/chart-type-row.d.ts +25 -0
  322. package/dist/types/components/explorer/chart-configuration/color-config-section.d.ts +18 -0
  323. package/dist/types/components/explorer/chart-configuration/combo-series-config-section.d.ts +6 -0
  324. package/dist/types/components/explorer/chart-configuration/comparison-config-section.d.ts +7 -0
  325. package/dist/types/components/explorer/chart-configuration/custom-color-picker.d.ts +7 -0
  326. package/dist/types/components/explorer/chart-configuration/data-labels-config-section.d.ts +1 -0
  327. package/dist/types/components/explorer/chart-configuration/data-labels-fields.d.ts +21 -0
  328. package/dist/types/components/explorer/chart-configuration/funnel-config-section.d.ts +1 -0
  329. package/dist/types/components/explorer/chart-configuration/heatmap-color-config-section.d.ts +1 -0
  330. package/dist/types/components/explorer/chart-configuration/kpi-format-config-section.d.ts +1 -0
  331. package/dist/types/components/explorer/chart-configuration/legend-config-section.d.ts +1 -0
  332. package/dist/types/components/explorer/chart-configuration/line-series-config-section.d.ts +5 -0
  333. package/dist/types/components/explorer/chart-configuration/line-style-config-section.d.ts +7 -0
  334. package/dist/types/components/explorer/chart-configuration/matrix-authoring-controls.d.ts +36 -0
  335. package/dist/types/components/explorer/chart-configuration/matrix-authoring-panel.d.ts +21 -0
  336. package/dist/types/components/explorer/chart-configuration/matrix-editor-settings.d.ts +5 -0
  337. package/dist/types/components/explorer/chart-configuration/metric-format-editor.d.ts +12 -0
  338. package/dist/types/components/explorer/chart-configuration/number-format-config.d.ts +17 -0
  339. package/dist/types/components/explorer/chart-configuration/number-format-config.utils.d.ts +11 -0
  340. package/dist/types/components/explorer/chart-configuration/stacked-sort-section.d.ts +1 -0
  341. package/dist/types/components/explorer/chart-configuration/summary-config-section.d.ts +1 -0
  342. package/dist/types/components/explorer/chart-configuration/tooltip-format-config-section.d.ts +1 -0
  343. package/dist/types/components/explorer/chart-configuration/treemap-color-mode-section.d.ts +1 -0
  344. package/dist/types/components/explorer/chart-configuration/use-effective-card-type.d.ts +1 -0
  345. package/dist/types/components/explorer/data-source/add-data-picker.d.ts +23 -0
  346. package/dist/types/components/explorer/data-source/data-source-panel.d.ts +6 -0
  347. package/dist/types/components/explorer/data-source/dataset-selector-popover.d.ts +11 -0
  348. package/dist/types/components/explorer/data-source/db-schema-selector.d.ts +8 -0
  349. package/dist/types/components/explorer/data-source/direct-source-tree.d.ts +10 -0
  350. package/dist/types/components/explorer/data-source/entity-tooltip.d.ts +14 -0
  351. package/dist/types/components/explorer/data-source/file-upload-manager.d.ts +1 -0
  352. package/dist/types/components/explorer/data-source/select-data-dialog.d.ts +6 -0
  353. package/dist/types/components/explorer/data-source/selected-entities-summary.d.ts +15 -0
  354. package/dist/types/components/explorer/data-source/semantic-domain-access-utils.d.ts +10 -0
  355. package/dist/types/components/explorer/data-source/semantic-domain-selection.d.ts +9 -0
  356. package/dist/types/components/explorer/data-source/semantic-domain-tree.d.ts +22 -0
  357. package/dist/types/components/explorer/data-source/url-source-manager.d.ts +1 -0
  358. package/dist/types/components/explorer/data-source/utils.d.ts +11 -0
  359. package/dist/types/components/explorer/drag-and-drop/attribute-filter-dialog.d.ts +11 -0
  360. package/dist/types/components/explorer/drag-and-drop/data-concept-tooltip.d.ts +17 -0
  361. package/dist/types/components/explorer/drag-and-drop/drag-overlay.d.ts +12 -0
  362. package/dist/types/components/explorer/drag-and-drop/draggable-field-shell.d.ts +15 -0
  363. package/dist/types/components/explorer/drag-and-drop/draggable-field.d.ts +13 -0
  364. package/dist/types/components/explorer/drag-and-drop/droppable-zone.d.ts +13 -0
  365. package/dist/types/components/explorer/drag-and-drop/inline-edit-field.d.ts +9 -0
  366. package/dist/types/components/explorer/drag-and-drop/matrix-draggable-field.d.ts +5 -0
  367. package/dist/types/components/explorer/drag-and-drop/pivot-alias-template-editor.d.ts +6 -0
  368. package/dist/types/components/explorer/drag-and-drop/pivot-member-order-visibility.d.ts +3 -0
  369. package/dist/types/components/explorer/drag-and-drop/pivot-value-aliases-editor.d.ts +6 -0
  370. package/dist/types/components/explorer/fields/field-expression-annotation.d.ts +15 -0
  371. package/dist/types/components/explorer/fields/field-group.d.ts +0 -0
  372. package/dist/types/components/explorer/fields/field-hover-preview.d.ts +10 -0
  373. package/dist/types/components/explorer/fields/field-option-list.d.ts +52 -0
  374. package/dist/types/components/explorer/fields/field-row.d.ts +39 -0
  375. package/dist/types/components/explorer/fields/fields-list.d.ts +10 -0
  376. package/dist/types/components/explorer/fields/fields-section.d.ts +6 -0
  377. package/dist/types/components/explorer/fields/filterable-fields-panel.d.ts +11 -0
  378. package/dist/types/components/explorer/fields/icon-for-field-type.d.ts +3 -0
  379. package/dist/types/components/explorer/fields/numeric-popover.d.ts +6 -0
  380. package/dist/types/components/explorer/fields/source-field.d.ts +28 -0
  381. package/dist/types/components/explorer/fields/type-glyph.d.ts +14 -0
  382. package/dist/types/components/explorer/filters/card-date-filter.d.ts +12 -0
  383. package/dist/types/components/explorer/filters/card-filter-builder.d.ts +10 -0
  384. package/dist/types/components/explorer/filters/card-filter-manager.d.ts +12 -0
  385. package/dist/types/components/explorer/filters/field-multi-select.d.ts +15 -0
  386. package/dist/types/components/explorer/filters/field-single-select.d.ts +15 -0
  387. package/dist/types/components/explorer/filters/searchable-field-combobox.d.ts +16 -0
  388. package/dist/types/components/explorer/filters/utils.d.ts +2 -0
  389. package/dist/types/components/explorer/join-configuration/auto-join-info.d.ts +16 -0
  390. package/dist/types/components/explorer/join-configuration/join-conditions-builder.d.ts +10 -0
  391. package/dist/types/components/explorer/join-configuration/join-dialog.d.ts +14 -0
  392. package/dist/types/components/explorer/join-configuration/join-manager.d.ts +10 -0
  393. package/dist/types/components/explorer/join-configuration/join-tooltip-content.d.ts +9 -0
  394. package/dist/types/components/explorer/main/explorer.d.ts +1 -0
  395. package/dist/types/components/explorer/main/view-tabs.d.ts +17 -0
  396. package/dist/types/components/explorer/spreadsheet/column-header.d.ts +11 -0
  397. package/dist/types/components/explorer/spreadsheet/editor-panel.d.ts +7 -0
  398. package/dist/types/components/explorer/spreadsheet/formula-bar.d.ts +11 -0
  399. package/dist/types/components/explorer/spreadsheet/index.d.ts +5 -0
  400. package/dist/types/components/explorer/spreadsheet/spreadsheet-table.d.ts +10 -0
  401. package/dist/types/components/explorer/spreadsheet/spreadsheet-view.d.ts +5 -0
  402. package/dist/types/components/explorer/visualization/chart-settings-panel.d.ts +6 -0
  403. package/dist/types/components/explorer/visualization/chart-split-view.d.ts +18 -0
  404. package/dist/types/components/explorer/visualization/feedback-dialog.d.ts +10 -0
  405. package/dist/types/components/explorer/visualization/row-limit-selector.d.ts +1 -0
  406. package/dist/types/components/explorer/visualization/visualization-panel.d.ts +18 -0
  407. package/dist/types/components/icons/bullet-chart-icon.d.ts +2 -0
  408. package/dist/types/components/index.d.ts +69 -0
  409. package/dist/types/components/interactions/applied-filters-display.d.ts +35 -0
  410. package/dist/types/components/interactions/card-renderer.d.ts +17 -0
  411. package/dist/types/components/interactions/configuration-popover.d.ts +1 -0
  412. package/dist/types/components/interactions/drill-config/hierarchy-steps-display.d.ts +9 -0
  413. package/dist/types/components/interactions/drill-config/hierarchy-templates.d.ts +5 -0
  414. package/dist/types/components/interactions/drill-config/sortable-hierarchy.d.ts +15 -0
  415. package/dist/types/components/interactions/drill-config/sortable-step.d.ts +14 -0
  416. package/dist/types/components/interactions/drill-config/step-configuration-popup.d.ts +13 -0
  417. package/dist/types/components/interactions/drill-hierarchy-modal.d.ts +43 -0
  418. package/dist/types/components/interactions/drill-to-url-modal.d.ts +26 -0
  419. package/dist/types/components/interactions/filter-badge-tooltip.d.ts +13 -0
  420. package/dist/types/components/interactions/hooks/use-drill-hierarchy.d.ts +15 -0
  421. package/dist/types/components/interactions/hooks/use-hierarchy-templates.d.ts +5 -0
  422. package/dist/types/components/interactions/hooks/use-step-reordering.d.ts +6 -0
  423. package/dist/types/components/interactions/insight-modal.d.ts +39 -0
  424. package/dist/types/components/interactions/insight-viewer.d.ts +28 -0
  425. package/dist/types/components/interactions/interaction-card.d.ts +59 -0
  426. package/dist/types/components/interactions/interaction-event-handler.d.ts +11 -0
  427. package/dist/types/components/interactions/interactions-list.d.ts +50 -0
  428. package/dist/types/components/interactions/panels/cross-filter-panel.d.ts +24 -0
  429. package/dist/types/components/interactions/panels/drill-down-panel.d.ts +43 -0
  430. package/dist/types/components/interactions/panels/drill-to-dashboard-panel.d.ts +24 -0
  431. package/dist/types/components/interactions/panels/drill-to-insight-panel.d.ts +24 -0
  432. package/dist/types/components/interactions/panels/drill-to-url-panel-v2.d.ts +9 -0
  433. package/dist/types/components/interactions/panels/dynamic-drill-panel.d.ts +24 -0
  434. package/dist/types/components/interactions/panels/inline-drill-panel.d.ts +24 -0
  435. package/dist/types/components/interactions/panels/panel-field.d.ts +29 -0
  436. package/dist/types/components/interactions/pickers/dashboard-picker.d.ts +36 -0
  437. package/dist/types/components/interactions/pickers/insight-picker.d.ts +36 -0
  438. package/dist/types/components/interactions/replaced-card-wrapper.d.ts +13 -0
  439. package/dist/types/components/interactions/reusable/field-combobox.d.ts +21 -0
  440. package/dist/types/components/interactions/reusable/field-selector.d.ts +15 -0
  441. package/dist/types/components/interactions/reusable/inline-field-selector.d.ts +11 -0
  442. package/dist/types/components/interactions/reusable/interaction-selection-popover.d.ts +107 -0
  443. package/dist/types/components/interactions/selectors/action-selector.d.ts +31 -0
  444. package/dist/types/components/interactions/selectors/trigger-selector.d.ts +38 -0
  445. package/dist/types/components/kpi-visual-v2/country-selector.d.ts +11 -0
  446. package/dist/types/components/kpi-visual-v2/kpi-card-explorer.d.ts +12 -0
  447. package/dist/types/components/kpi-visual-v2/kpi-settings.d.ts +1 -0
  448. package/dist/types/components/kpi-visual-v2/kpi-tooltip-components.d.ts +25 -0
  449. package/dist/types/components/kpi-visual-v2/kpi-tooltip-utils.d.ts +8 -0
  450. package/dist/types/components/kpi-visual-v2/kpi-tooltip.d.ts +14 -0
  451. package/dist/types/components/kpi-visual-v2/metric-comparison-indicator.d.ts +16 -0
  452. package/dist/types/components/kpi-visual-v2/metric-comparison-kpi.d.ts +11 -0
  453. package/dist/types/components/notifications/export-notification-item.d.ts +23 -0
  454. package/dist/types/components/notifications/export-notification-list.d.ts +7 -0
  455. package/dist/types/components/notifications/index.d.ts +3 -0
  456. package/dist/types/components/notifications/notification-bell.d.ts +12 -0
  457. package/dist/types/components/providers/appearance-context.d.ts +23 -0
  458. package/dist/types/components/providers/appearance-provider.d.ts +4 -0
  459. package/dist/types/components/providers/appearance-runtime-provider.d.ts +19 -0
  460. package/dist/types/components/providers/brand-studio-preview-context.d.ts +5 -0
  461. package/dist/types/components/providers/dashboard-matrix-execution-provider.d.ts +10 -0
  462. package/dist/types/components/providers/dashboard-preferences-provider.d.ts +12 -0
  463. package/dist/types/components/providers/display-preferences-provider.d.ts +10 -0
  464. package/dist/types/components/providers/semaphor-context-provider.d.ts +13 -0
  465. package/dist/types/components/providers/semaphor-query-provider.d.ts +3 -0
  466. package/dist/types/components/providers/theme-provider-context.d.ts +7 -0
  467. package/dist/types/components/providers/theme-provider.d.ts +8 -0
  468. package/dist/types/components/providers/ux-provider.d.ts +6 -0
  469. package/dist/types/components/semaphor/code-block.d.ts +20 -0
  470. package/dist/types/components/semaphor/code-editor.d.ts +86 -0
  471. package/dist/types/components/semaphor/code-highlight.d.ts +15 -0
  472. package/dist/types/components/shared/unsaved-changes/index.d.ts +2 -0
  473. package/dist/types/components/shared/unsaved-changes/unsaved-changes-alert.d.ts +14 -0
  474. package/dist/types/components/shared/unsaved-changes/use-pristine-snapshot-initializer.d.ts +6 -0
  475. package/dist/types/components/sharing-and-management/common-loading-skeleton.d.ts +1 -0
  476. package/dist/types/components/sharing-and-management/create-dashboard-dialog.d.ts +11 -0
  477. package/dist/types/components/sharing-and-management/create-visual-dialog.d.ts +11 -0
  478. package/dist/types/components/sharing-and-management/dashboard-actions-menu.d.ts +19 -0
  479. package/dist/types/components/sharing-and-management/group-management-dialog.d.ts +6 -0
  480. package/dist/types/components/sharing-and-management/hooks/use-current-user-info.d.ts +41 -0
  481. package/dist/types/components/sharing-and-management/hooks/use-group-management.d.ts +30 -0
  482. package/dist/types/components/sharing-and-management/hooks/use-groups.d.ts +26 -0
  483. package/dist/types/components/sharing-and-management/hooks/use-resource-management.d.ts +235 -0
  484. package/dist/types/components/sharing-and-management/hooks/use-resource-share-data.d.ts +27 -0
  485. package/dist/types/components/sharing-and-management/hooks/use-unified-users.d.ts +53 -0
  486. package/dist/types/components/sharing-and-management/hooks/use-visual-utils.d.ts +33 -0
  487. package/dist/types/components/sharing-and-management/resource-edit-dialog.d.ts +14 -0
  488. package/dist/types/components/sharing-and-management/resource-share-dialog/index.d.ts +10 -0
  489. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/access-list.d.ts +14 -0
  490. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/adapter.d.ts +33 -0
  491. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/configs.d.ts +28 -0
  492. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/invite-combobox.d.ts +17 -0
  493. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/primitives.d.ts +33 -0
  494. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/share-shape.d.ts +13 -0
  495. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/shell.d.ts +17 -0
  496. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/status-bar.d.ts +5 -0
  497. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/submission.d.ts +38 -0
  498. package/dist/types/components/sharing-and-management/resource-share-dialog/unified/types.d.ts +60 -0
  499. package/dist/types/components/sharing-and-management/utils/group-types.d.ts +105 -0
  500. package/dist/types/components/sharing-and-management/utils/resource-query-keys.d.ts +14 -0
  501. package/dist/types/components/sharing-and-management/utils/shares-types.d.ts +122 -0
  502. package/dist/types/components/sharing-and-management/utils/types.d.ts +86 -0
  503. package/dist/types/components/sharing-and-management/visuals-library-dialog.d.ts +6 -0
  504. package/dist/types/components/surfboard/card-controls-toolbar.d.ts +17 -0
  505. package/dist/types/components/surfboard/controls/card-runtime-controls.d.ts +6 -0
  506. package/dist/types/components/surfboard/controls/control-authoring-utils.d.ts +182 -0
  507. package/dist/types/components/surfboard/controls/control-binding-list-editor.d.ts +21 -0
  508. package/dist/types/components/surfboard/controls/control-definition-editor-helpers.d.ts +43 -0
  509. package/dist/types/components/surfboard/controls/control-definition-editor-sections.d.ts +65 -0
  510. package/dist/types/components/surfboard/controls/control-definition-list-editor.d.ts +29 -0
  511. package/dist/types/components/surfboard/controls/control-select-ui-utils.d.ts +13 -0
  512. package/dist/types/components/surfboard/controls/control-toolbar-item.d.ts +22 -0
  513. package/dist/types/components/surfboard/controls/control-toolbar-settings-form.d.ts +30 -0
  514. package/dist/types/components/surfboard/controls/control-toolbar-settings-shell.d.ts +37 -0
  515. package/dist/types/components/surfboard/controls/control-usage-utils.d.ts +22 -0
  516. package/dist/types/components/surfboard/controls/control-validation-message-utils.d.ts +5 -0
  517. package/dist/types/components/surfboard/controls/dashboard-control-delete-dialog.d.ts +7 -0
  518. package/dist/types/components/surfboard/controls/dashboard-control-toolbar-popover.d.ts +9 -0
  519. package/dist/types/components/surfboard/controls/dashboard-controls-settings.d.ts +10 -0
  520. package/dist/types/components/surfboard/controls/dashboard-filter-controls-button.d.ts +34 -0
  521. package/dist/types/components/surfboard/controls/dashboard-filter-controls-launcher.d.ts +26 -0
  522. package/dist/types/components/surfboard/controls/dashboard-runtime-controls.d.ts +1 -0
  523. package/dist/types/components/surfboard/controls/matrix-structural-targets.d.ts +10 -0
  524. package/dist/types/components/surfboard/controls/presentation-currency-binding-editor.d.ts +15 -0
  525. package/dist/types/components/surfboard/controls/runtime-control-input.d.ts +16 -0
  526. package/dist/types/components/surfboard/controls/runtime-control-utils.d.ts +16 -0
  527. package/dist/types/components/surfboard/controls/runtime-controls-group.d.ts +12 -0
  528. package/dist/types/components/surfboard/controls/sortable-control-toolbar-item.d.ts +9 -0
  529. package/dist/types/components/surfboard/controls/use-create-flow-overlay-state.d.ts +32 -0
  530. package/dist/types/components/surfboard/controls/use-dashboard-structural-participants.d.ts +14 -0
  531. package/dist/types/components/surfboard/controls/use-resolved-control-toolbar-options.d.ts +26 -0
  532. package/dist/types/components/surfboard/dashboard-controls.d.ts +1 -0
  533. package/dist/types/components/surfboard/dashboard-plus-main.d.ts +1 -0
  534. package/dist/types/components/surfboard/dashboard-plus.d.ts +7 -0
  535. package/dist/types/components/surfboard/expanded-card-view.d.ts +10 -0
  536. package/dist/types/components/surfboard/export-dialog.d.ts +15 -0
  537. package/dist/types/components/surfboard/filter/apply-filters-check-box.d.ts +7 -0
  538. package/dist/types/components/surfboard/filter/click-filter-section.d.ts +5 -0
  539. package/dist/types/components/surfboard/filter/custom-filter/custom-filter-selector.d.ts +12 -0
  540. package/dist/types/components/surfboard/filter/custom-filter/custom-filter-types.d.ts +45 -0
  541. package/dist/types/components/surfboard/filter/custom-filter/dashboard-custom-filter.d.ts +19 -0
  542. package/dist/types/components/surfboard/filter/custom-filter-popover.d.ts +75 -0
  543. package/dist/types/components/surfboard/filter/dashboard-filter-info-group.d.ts +21 -0
  544. package/dist/types/components/surfboard/filter/dashboard-filter-mapping-panel.d.ts +13 -0
  545. package/dist/types/components/surfboard/filter/date-comparison-controls.d.ts +8 -0
  546. package/dist/types/components/surfboard/filter/date-comparison-label.d.ts +2 -0
  547. package/dist/types/components/surfboard/filter/date-range-filter-v2.d.ts +38 -0
  548. package/dist/types/components/surfboard/filter/date-range-filter.d.ts +7 -0
  549. package/dist/types/components/surfboard/filter/day-picker.d.ts +29 -0
  550. package/dist/types/components/surfboard/filter/field-date-comparison-scope-message.d.ts +2 -0
  551. package/dist/types/components/surfboard/filter/field-date-filter.d.ts +9 -0
  552. package/dist/types/components/surfboard/filter/filter-actions-popover-content.d.ts +9 -0
  553. package/dist/types/components/surfboard/filter/filter-aside.d.ts +1 -0
  554. package/dist/types/components/surfboard/filter/filter-component.d.ts +12 -0
  555. package/dist/types/components/surfboard/filter/filter-configuration-panel.d.ts +102 -0
  556. package/dist/types/components/surfboard/filter/filter-default-values-picker.d.ts +29 -0
  557. package/dist/types/components/surfboard/filter/filter-error-state.d.ts +7 -0
  558. package/dist/types/components/surfboard/filter/filter-header.d.ts +4 -0
  559. package/dist/types/components/surfboard/filter/filter-info.d.ts +17 -0
  560. package/dist/types/components/surfboard/filter/filter-option-dependencies-settings.d.ts +33 -0
  561. package/dist/types/components/surfboard/filter/filter-option-list.d.ts +39 -0
  562. package/dist/types/components/surfboard/filter/filter-option-source-settings.d.ts +14 -0
  563. package/dist/types/components/surfboard/filter/filter-picker-popover-content.d.ts +1 -0
  564. package/dist/types/components/surfboard/filter/filter-popover-parts.d.ts +37 -0
  565. package/dist/types/components/surfboard/filter/filter-scope-config.d.ts +8 -0
  566. package/dist/types/components/surfboard/filter/filter-settings-popover-delete.d.ts +0 -0
  567. package/dist/types/components/surfboard/filter/filter-settings-popover.d.ts +5 -0
  568. package/dist/types/components/surfboard/filter/filter-toolbar-item.d.ts +21 -0
  569. package/dist/types/components/surfboard/filter/filter-toolbar-order-utils.d.ts +3 -0
  570. package/dist/types/components/surfboard/filter/filter-toolbar.d.ts +7 -0
  571. package/dist/types/components/surfboard/filter/global-date-comparison-footer.d.ts +14 -0
  572. package/dist/types/components/surfboard/filter/global-date-filter.d.ts +9 -0
  573. package/dist/types/components/surfboard/filter/hidden-filters.d.ts +1 -0
  574. package/dist/types/components/surfboard/filter/month-picker.d.ts +18 -0
  575. package/dist/types/components/surfboard/filter/multi-select-filter.d.ts +16 -0
  576. package/dist/types/components/surfboard/filter/multi-select-inline-content.d.ts +39 -0
  577. package/dist/types/components/surfboard/filter/numeric-filter-input.d.ts +8 -0
  578. package/dist/types/components/surfboard/filter/radio-button-filter.d.ts +8 -0
  579. package/dist/types/components/surfboard/filter/sortable-filter-toolbar-item.d.ts +24 -0
  580. package/dist/types/components/surfboard/filter/tabs-filter.d.ts +8 -0
  581. package/dist/types/components/surfboard/filter/types.d.ts +245 -0
  582. package/dist/types/components/surfboard/filter/use-dashboard-filter-mapping-popover.d.ts +74 -0
  583. package/dist/types/components/surfboard/filter/use-filter-header-width.d.ts +12 -0
  584. package/dist/types/components/surfboard/filter/utils.d.ts +4 -0
  585. package/dist/types/components/surfboard/index.d.ts +5 -0
  586. package/dist/types/components/surfboard/inline-options-error-state.d.ts +6 -0
  587. package/dist/types/components/surfboard/input-chip-row.d.ts +21 -0
  588. package/dist/types/components/surfboard/json-to-csv.d.ts +7 -0
  589. package/dist/types/components/surfboard/lens/add-lens-dialog.d.ts +9 -0
  590. package/dist/types/components/surfboard/lens/default-lens-checkbox.d.ts +1 -0
  591. package/dist/types/components/surfboard/lens/lens-dropdown.d.ts +10 -0
  592. package/dist/types/components/surfboard/lens/lens-utils.d.ts +21 -0
  593. package/dist/types/components/surfboard/preferences/calendar-preferences-panel.d.ts +6 -0
  594. package/dist/types/components/surfboard/preferences/display-format-preferences-fields.d.ts +9 -0
  595. package/dist/types/components/surfboard/preferences/display-format-preferences-panel.d.ts +6 -0
  596. package/dist/types/components/surfboard/preferences/report-preferences-dialog.d.ts +6 -0
  597. package/dist/types/components/surfboard/toolbar-item-shell.d.ts +17 -0
  598. package/dist/types/components/ui/accordion.d.ts +7 -0
  599. package/dist/types/components/ui/alert-dialog.d.ts +20 -0
  600. package/dist/types/components/ui/alert.d.ts +8 -0
  601. package/dist/types/components/ui/audience-type-badge.d.ts +9 -0
  602. package/dist/types/components/ui/avatar.d.ts +6 -0
  603. package/dist/types/components/ui/badge.d.ts +9 -0
  604. package/dist/types/components/ui/button.d.ts +11 -0
  605. package/dist/types/components/ui/calendar.d.ts +8 -0
  606. package/dist/types/components/ui/card.d.ts +8 -0
  607. package/dist/types/components/ui/checkbox.d.ts +4 -0
  608. package/dist/types/components/ui/collapsible.d.ts +5 -0
  609. package/dist/types/components/ui/command.d.ts +82 -0
  610. package/dist/types/components/ui/context-menu.d.ts +27 -0
  611. package/dist/types/components/ui/dialog.d.ts +28 -0
  612. package/dist/types/components/ui/dropdown-menu.d.ts +27 -0
  613. package/dist/types/components/ui/hover-card.d.ts +6 -0
  614. package/dist/types/components/ui/input.d.ts +9 -0
  615. package/dist/types/components/ui/label.d.ts +5 -0
  616. package/dist/types/components/ui/popover.d.ts +7 -0
  617. package/dist/types/components/ui/portal-scope.d.ts +6 -0
  618. package/dist/types/components/ui/progress.d.ts +4 -0
  619. package/dist/types/components/ui/radio-group.d.ts +5 -0
  620. package/dist/types/components/ui/resizable.d.ts +23 -0
  621. package/dist/types/components/ui/scroll-area.d.ts +5 -0
  622. package/dist/types/components/ui/select.d.ts +16 -0
  623. package/dist/types/components/ui/separator.d.ts +4 -0
  624. package/dist/types/components/ui/sheet.d.ts +39 -0
  625. package/dist/types/components/ui/skeleton.d.ts +2 -0
  626. package/dist/types/components/ui/slider.d.ts +4 -0
  627. package/dist/types/components/ui/sonner.d.ts +4 -0
  628. package/dist/types/components/ui/switch.d.ts +10 -0
  629. package/dist/types/components/ui/table.d.ts +13 -0
  630. package/dist/types/components/ui/tabs.d.ts +14 -0
  631. package/dist/types/components/ui/textarea.d.ts +9 -0
  632. package/dist/types/components/ui/toggle.d.ts +12 -0
  633. package/dist/types/components/ui/tooltip.d.ts +8 -0
  634. package/dist/types/components/ui-custom/color-field.d.ts +30 -0
  635. package/dist/types/components/ui-custom/column-search.d.ts +41 -0
  636. package/dist/types/components/ui-custom/combo-box-2.d.ts +40 -0
  637. package/dist/types/components/ui-custom/combo-box.d.ts +16 -0
  638. package/dist/types/components/ui-custom/command-input-custom.d.ts +9 -0
  639. package/dist/types/components/ui-custom/copy-button.d.ts +15 -0
  640. package/dist/types/components/ui-custom/copy-on-click.d.ts +11 -0
  641. package/dist/types/components/ui-custom/custom-scroll-area.d.ts +6 -0
  642. package/dist/types/components/ui-custom/date-range-picker.d.ts +57 -0
  643. package/dist/types/components/ui-custom/date-range-popover.d.ts +14 -0
  644. package/dist/types/components/ui-custom/date-range-presets.d.ts +47 -0
  645. package/dist/types/components/ui-custom/details.d.ts +7 -0
  646. package/dist/types/components/ui-custom/dev-mode-switch.d.ts +8 -0
  647. package/dist/types/components/ui-custom/editable-text.d.ts +21 -0
  648. package/dist/types/components/ui-custom/grip-reveal.d.ts +4 -0
  649. package/dist/types/components/ui-custom/icon-button.d.ts +13 -0
  650. package/dist/types/components/ui-custom/load-on-scroll-status.d.ts +8 -0
  651. package/dist/types/components/ui-custom/load-on-scroll-utils.d.ts +1 -0
  652. package/dist/types/components/ui-custom/loading-dots.d.ts +7 -0
  653. package/dist/types/components/ui-custom/local-blur-input.d.ts +9 -0
  654. package/dist/types/components/ui-custom/option-search-input.d.ts +16 -0
  655. package/dist/types/components/ui-custom/overflow-div.d.ts +5 -0
  656. package/dist/types/components/ui-custom/overflow-span.d.ts +5 -0
  657. package/dist/types/components/ui-custom/popover-content-custom.d.ts +4 -0
  658. package/dist/types/components/ui-custom/pre-tag.d.ts +4 -0
  659. package/dist/types/components/ui-custom/radio-indicator.d.ts +13 -0
  660. package/dist/types/components/ui-custom/resizable-handle-custom.d.ts +7 -0
  661. package/dist/types/components/ui-custom/reusable-select.d.ts +16 -0
  662. package/dist/types/components/ui-custom/visual-badge.d.ts +9 -0
  663. package/dist/types/components/visual/aggregated-table/aggregate-table.d.ts +2 -0
  664. package/dist/types/components/visual/aggregated-table/columns/aggregate-columns.d.ts +4 -0
  665. package/dist/types/components/visual/aggregated-table/columns/column-cell-components.d.ts +16 -0
  666. package/dist/types/components/visual/aggregated-table/columns/column-definitions.d.ts +29 -0
  667. package/dist/types/components/visual/aggregated-table/columns/column-header-components.d.ts +31 -0
  668. package/dist/types/components/visual/aggregated-table/components/aggregate-table-body.d.ts +18 -0
  669. package/dist/types/components/visual/aggregated-table/components/grand-total-footer.d.ts +22 -0
  670. package/dist/types/components/visual/aggregated-table/hooks/use-aggregate-table.d.ts +15 -0
  671. package/dist/types/components/visual/aggregated-table/types/aggregate-table.d.ts +68 -0
  672. package/dist/types/components/visual/aggregated-table/utils/cell-formatters.d.ts +6 -0
  673. package/dist/types/components/visual/aggregated-table/utils/data-organizer.d.ts +12 -0
  674. package/dist/types/components/visual/aggregated-table/utils/export-utils.d.ts +31 -0
  675. package/dist/types/components/visual/aggregated-table/utils/metric-format-resolver.d.ts +66 -0
  676. package/dist/types/components/visual/aggregated-table/utils/temporal-presentation.d.ts +17 -0
  677. package/dist/types/components/visual/chart-utils.d.ts +15 -0
  678. package/dist/types/components/visual/chartjs-visual.d.ts +9 -0
  679. package/dist/types/components/visual/column-display-utils.d.ts +2 -0
  680. package/dist/types/components/visual/custom-visual/build-inline-filter-nodes.d.ts +21 -0
  681. package/dist/types/components/visual/custom-visual/build-multi-input-props.d.ts +48 -0
  682. package/dist/types/components/visual/custom-visual/component-combo-box.d.ts +10 -0
  683. package/dist/types/components/visual/custom-visual/custom-card-theme-adapter.d.ts +3 -0
  684. package/dist/types/components/visual/custom-visual/custom-visual-settings.d.ts +1 -0
  685. package/dist/types/components/visual/custom-visual/custom-visual-temporal-presentation.d.ts +35 -0
  686. package/dist/types/components/visual/custom-visual/custom-visual-types.d.ts +171 -0
  687. package/dist/types/components/visual/custom-visual/custom-visual-utils.d.ts +57 -0
  688. package/dist/types/components/visual/custom-visual/dashboard-custom-visual.d.ts +7 -0
  689. package/dist/types/components/visual/custom-visual/editor-custom-visual.d.ts +6 -0
  690. package/dist/types/components/visual/custom-visual/hooks/use-ensure-react-globals.d.ts +10 -0
  691. package/dist/types/components/visual/custom-visual/hooks/use-remote-chart-store.d.ts +9 -0
  692. package/dist/types/components/visual/custom-visual/multi-input-empty-renderer.d.ts +8 -0
  693. package/dist/types/components/visual/custom-visual/use-custom-visual.d.ts +16 -0
  694. package/dist/types/components/visual/data-table/column-def.d.ts +54 -0
  695. package/dist/types/components/visual/data-table/column-resize-handle.d.ts +8 -0
  696. package/dist/types/components/visual/data-table/copyable-cell.d.ts +9 -0
  697. package/dist/types/components/visual/data-table/data-table-column-settings.d.ts +2 -0
  698. package/dist/types/components/visual/data-table/data-table-conditional-formatting-settings.d.ts +21 -0
  699. package/dist/types/components/visual/data-table/data-table-pagination.d.ts +2 -0
  700. package/dist/types/components/visual/data-table/data-table-toolbar.d.ts +2 -0
  701. package/dist/types/components/visual/data-table/data-table.d.ts +2 -0
  702. package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +97 -0
  703. package/dist/types/components/visual/data-table/hooks/use-sql-raw-temporal-format-draft.d.ts +15 -0
  704. package/dist/types/components/visual/data-table/hooks/use-table-query-state.d.ts +30 -0
  705. package/dist/types/components/visual/data-table/overflow-cell.d.ts +9 -0
  706. package/dist/types/components/visual/data-table/table-conditional-formatting-authoring.d.ts +17 -0
  707. package/dist/types/components/visual/data-table/table-conditional-formatting-rule-model.d.ts +33 -0
  708. package/dist/types/components/visual/data-table/table-settings-toolbar-button.d.ts +9 -0
  709. package/dist/types/components/visual/data-table/table-skeleton.d.ts +6 -0
  710. package/dist/types/components/visual/data-table/table-visual.d.ts +39 -0
  711. package/dist/types/components/visual/data-table/types/data-table.d.ts +286 -0
  712. package/dist/types/components/visual/data-table/utils/data-table-utils.d.ts +74 -0
  713. package/dist/types/components/visual/data-table/utils/export-utils.d.ts +31 -0
  714. package/dist/types/components/visual/data-table/utils/pagination-utils.d.ts +39 -0
  715. package/dist/types/components/visual/data-table/utils/sort-conversion.d.ts +5 -0
  716. package/dist/types/components/visual/data-table/utils/table-behavior.d.ts +33 -0
  717. package/dist/types/components/visual/data-table/utils/utils.d.ts +4 -0
  718. package/dist/types/components/visual/info-hover.d.ts +6 -0
  719. package/dist/types/components/visual/kpi-visual/format-number-setting.d.ts +1 -0
  720. package/dist/types/components/visual/kpi-visual/kpi-bulb-utils.d.ts +3 -0
  721. package/dist/types/components/visual/kpi-visual/kpi-card-with-info.d.ts +9 -0
  722. package/dist/types/components/visual/kpi-visual/kpi-card.d.ts +28 -0
  723. package/dist/types/components/visual/kpi-visual/kpi-editor-ownership-badge.d.ts +4 -0
  724. package/dist/types/components/visual/kpi-visual/kpi-utils.d.ts +12 -0
  725. package/dist/types/components/visual/matrix-table/matrix-axis-menu.d.ts +21 -0
  726. package/dist/types/components/visual/matrix-table/matrix-card-view.d.ts +16 -0
  727. package/dist/types/components/visual/matrix-table/matrix-interaction-actions.d.ts +12 -0
  728. package/dist/types/components/visual/matrix-table/matrix-loading-skeleton.d.ts +14 -0
  729. package/dist/types/components/visual/matrix-table/matrix-tabular-boundary.d.ts +8 -0
  730. package/dist/types/components/visual/matrix-table/matrix-viewer-geometry.d.ts +21 -0
  731. package/dist/types/components/visual/matrix-table/matrix-window-viewer.d.ts +26 -0
  732. package/dist/types/components/visual/pivot-table/aggregation-menu.d.ts +23 -0
  733. package/dist/types/components/visual/pivot-table/columns/data-columns.d.ts +26 -0
  734. package/dist/types/components/visual/pivot-table/columns/row-header-columns.d.ts +20 -0
  735. package/dist/types/components/visual/pivot-table/columns/row-total-column.d.ts +12 -0
  736. package/dist/types/components/visual/pivot-table/components/pivot-table-body.d.ts +23 -0
  737. package/dist/types/components/visual/pivot-table/components/pivot-table-footer.d.ts +29 -0
  738. package/dist/types/components/visual/pivot-table/hooks/use-pivot-column-headers.d.ts +28 -0
  739. package/dist/types/components/visual/pivot-table/hooks/use-pivot-pagination.d.ts +29 -0
  740. package/dist/types/components/visual/pivot-table/hooks/use-pivot-sorting.d.ts +21 -0
  741. package/dist/types/components/visual/pivot-table/hooks/use-pivot-table-settings.d.ts +15 -0
  742. package/dist/types/components/visual/pivot-table/pivot-table-tanstack.d.ts +41 -0
  743. package/dist/types/components/visual/pivot-table/pivot-table.d.ts +100 -0
  744. package/dist/types/components/visual/pivot-table/types.d.ts +80 -0
  745. package/dist/types/components/visual/pivot-table/utils/cell-value-formatter.d.ts +14 -0
  746. package/dist/types/components/visual/pivot-table/utils/pivot-field-identity.d.ts +8 -0
  747. package/dist/types/components/visual/pivot-table/utils/pivot-formatting-utils.d.ts +24 -0
  748. package/dist/types/components/visual/pivot-table/utils/pivot-metric-formatting.d.ts +18 -0
  749. package/dist/types/components/visual/pivot-table/utils/pivot-physical-schema.d.ts +14 -0
  750. package/dist/types/components/visual/pivot-table/utils/pivot-table-aggregation-helpers.d.ts +21 -0
  751. package/dist/types/components/visual/pivot-table/utils/pivot-table-data-processor.d.ts +35 -0
  752. package/dist/types/components/visual/pivot-table/utils/pivot-table-export-utils.d.ts +23 -0
  753. package/dist/types/components/visual/pivot-table/utils/pivot-table-response.d.ts +50 -0
  754. package/dist/types/components/visual/pivot-table/utils/pivot-table-sorter.d.ts +7 -0
  755. package/dist/types/components/visual/pivot-table/utils/row-span-calculator.d.ts +14 -0
  756. package/dist/types/components/visual/settings/axis-mapping.d.ts +9 -0
  757. package/dist/types/components/visual/settings/chart-documentation.d.ts +28 -0
  758. package/dist/types/components/visual/settings/chart-orientation.d.ts +1 -0
  759. package/dist/types/components/visual/settings/color-format.d.ts +7 -0
  760. package/dist/types/components/visual/settings/controls-settings.d.ts +7 -0
  761. package/dist/types/components/visual/settings/dataset-label-popover.d.ts +3 -0
  762. package/dist/types/components/visual/settings/display-labels.d.ts +1 -0
  763. package/dist/types/components/visual/settings/filter-on-click-columns.d.ts +1 -0
  764. package/dist/types/components/visual/settings/frame-filters.d.ts +6 -0
  765. package/dist/types/components/visual/settings/inline-filters-settings.d.ts +11 -0
  766. package/dist/types/components/visual/settings/kpi-settings.d.ts +1 -0
  767. package/dist/types/components/visual/settings/map-chart-settings.d.ts +1 -0
  768. package/dist/types/components/visual/settings/scale-options.d.ts +1 -0
  769. package/dist/types/components/visual/settings/table-column-visibility-settings.d.ts +16 -0
  770. package/dist/types/components/visual/settings/table-presentation-settings.d.ts +27 -0
  771. package/dist/types/components/visual/settings/table-visual-settings.d.ts +8 -0
  772. package/dist/types/components/visual/settings/text-settings.d.ts +1 -0
  773. package/dist/types/components/visual/settings/text-type-radio.d.ts +1 -0
  774. package/dist/types/components/visual/shared/hooks/use-column-resizing.d.ts +15 -0
  775. package/dist/types/components/visual/shared/utils/column-type-detector.d.ts +25 -0
  776. package/dist/types/components/visual/shared/utils/table-column-order.d.ts +45 -0
  777. package/dist/types/components/visual/shared/utils/table-render-policy.d.ts +20 -0
  778. package/dist/types/components/visual/table-appearance/table-appearance-adapter.d.ts +41 -0
  779. package/dist/types/components/visual/table-appearance/table-appearance-primitives.d.ts +32 -0
  780. package/dist/types/components/visual/visual-error-state.d.ts +13 -0
  781. package/dist/types/components/visual/visual-utils.d.ts +33 -0
  782. package/dist/types/components/visual/visual.d.ts +7 -0
  783. package/dist/types/dashboard-assistant/index.d.ts +101 -0
  784. package/dist/types/dashboard-assistant.d.ts +2 -13074
  785. package/dist/types/dashboard-authoring.d.ts +2 -15283
  786. package/dist/types/dashboard.d.ts +2 -10880
  787. package/dist/types/data-app-builder/browser-runtime.d.ts +174 -0
  788. package/dist/types/data-app-builder/constants.d.ts +14 -0
  789. package/dist/types/data-app-builder/data-app-builder.d.ts +14 -0
  790. package/dist/types/data-app-builder/index.d.ts +1 -0
  791. package/dist/types/data-app-builder/lib/api.d.ts +36 -0
  792. package/dist/types/data-app-builder/lib/context-select.d.ts +3 -0
  793. package/dist/types/data-app-builder/lib/diagnostics.d.ts +12 -0
  794. package/dist/types/data-app-builder/lib/file-tree.d.ts +2 -0
  795. package/dist/types/data-app-builder/types.d.ts +558 -0
  796. package/dist/types/data-app-builder-browser-runtime.d.ts +2 -185
  797. package/dist/types/data-app-builder.d.ts +2 -4830
  798. package/dist/types/data-app-codegen/generate-contract.d.ts +26 -0
  799. package/dist/types/data-app-codegen/generated-contract-files.d.ts +7 -0
  800. package/dist/types/data-app-codegen/generated-contract-validation.d.ts +13 -0
  801. package/dist/types/data-app-codegen/index.d.ts +6 -0
  802. package/dist/types/data-app-codegen/live-execution.d.ts +42 -0
  803. package/dist/types/data-app-codegen/node.d.ts +2 -0
  804. package/dist/types/data-app-codegen/update-policy.d.ts +25 -0
  805. package/dist/types/data-app-codegen/validation.d.ts +8 -0
  806. package/dist/types/data-app-codegen-node.d.ts +2 -7263
  807. package/dist/types/data-app-codegen.d.ts +2 -7235
  808. package/dist/types/data-app-sdk/adapters.d.ts +34 -0
  809. package/dist/types/data-app-sdk/analysis-payload.d.ts +2 -0
  810. package/dist/types/data-app-sdk/builders.d.ts +61 -0
  811. package/dist/types/data-app-sdk/contracts.d.ts +523 -0
  812. package/dist/types/data-app-sdk/devtools/index.d.ts +49 -0
  813. package/dist/types/data-app-sdk/devtools/issues.d.ts +21 -0
  814. package/dist/types/data-app-sdk/devtools/labels.d.ts +4 -0
  815. package/dist/types/data-app-sdk/devtools/result-preview.d.ts +8 -0
  816. package/dist/types/data-app-sdk/devtools/styles.d.ts +15 -0
  817. package/dist/types/data-app-sdk/devtools/window-snapshot.d.ts +3 -0
  818. package/dist/types/data-app-sdk/devtools.d.ts +1 -0
  819. package/dist/types/data-app-sdk/executor.d.ts +5 -0
  820. package/dist/types/data-app-sdk/field-catalog-validation.d.ts +29 -0
  821. package/dist/types/data-app-sdk/hooks.d.ts +11 -0
  822. package/dist/types/data-app-sdk/index.d.ts +10 -0
  823. package/dist/types/data-app-sdk/matrix-filter-validation.d.ts +12 -0
  824. package/dist/types/data-app-sdk/provider.d.ts +8 -0
  825. package/dist/types/data-app-sdk/query-request.d.ts +27 -0
  826. package/dist/types/data-app-sdk/relationship-aware-field-policy.d.ts +21 -0
  827. package/dist/types/data-app-sdk/runtime.d.ts +21 -0
  828. package/dist/types/data-app-sdk/validation.d.ts +58 -0
  829. package/dist/types/data-app-sdk-adapters.d.ts +2 -6874
  830. package/dist/types/data-app-sdk-validation.d.ts +2 -10410
  831. package/dist/types/data-app-sdk.d.ts +2 -35142
  832. package/dist/types/format-utils.d.ts +2 -12162
  833. package/dist/types/index.cjs +1 -1
  834. package/dist/types/index.js +4 -4
  835. package/dist/types/layouts.d.ts +2 -33
  836. package/dist/types/lib/actions/data-point-click-action.d.ts +12 -0
  837. package/dist/types/lib/ai/dynamic-visual-card-utils.d.ts +70 -0
  838. package/dist/types/lib/ai/dynamic-visual-theme.d.ts +11 -0
  839. package/dist/types/lib/ai-utils.d.ts +16 -0
  840. package/dist/types/lib/api/briefings-api.d.ts +51 -0
  841. package/dist/types/lib/api/exports-api.d.ts +152 -0
  842. package/dist/types/lib/api/index.d.ts +2 -0
  843. package/dist/types/lib/appearance/chart-style-adapter.d.ts +4 -0
  844. package/dist/types/lib/appearance/color.d.ts +13 -0
  845. package/dist/types/lib/appearance/compiler.d.ts +9 -0
  846. package/dist/types/lib/appearance/defaults.d.ts +3 -0
  847. package/dist/types/lib/appearance/dom.d.ts +3 -0
  848. package/dist/types/lib/appearance/fonts.d.ts +9 -0
  849. package/dist/types/lib/appearance/index.d.ts +7 -0
  850. package/dist/types/lib/appearance/merge.d.ts +3 -0
  851. package/dist/types/lib/appearance/resolver.d.ts +2 -0
  852. package/dist/types/lib/appearance/schema.d.ts +3 -0
  853. package/dist/types/lib/appearance/types.d.ts +163 -0
  854. package/dist/types/lib/briefings/briefing-attachment-model.d.ts +106 -0
  855. package/dist/types/lib/briefings/briefing-form-model.d.ts +55 -0
  856. package/dist/types/lib/charts/area-chart.d.ts +5 -0
  857. package/dist/types/lib/charts/bar-chart.d.ts +5 -0
  858. package/dist/types/lib/charts/bubble-scatter-chart.d.ts +28 -0
  859. package/dist/types/lib/charts/bullet-chart.d.ts +17 -0
  860. package/dist/types/lib/charts/chart-availability.d.ts +7 -0
  861. package/dist/types/lib/charts/chart-axis-policy.d.ts +20 -0
  862. package/dist/types/lib/charts/chart-config.d.ts +9 -0
  863. package/dist/types/lib/charts/chart-documentation.d.ts +23 -0
  864. package/dist/types/lib/charts/chart-font.d.ts +10 -0
  865. package/dist/types/lib/charts/chart-selector.d.ts +2 -0
  866. package/dist/types/lib/charts/chart-utils.d.ts +255 -0
  867. package/dist/types/lib/charts/color-utils.d.ts +29 -0
  868. package/dist/types/lib/charts/combo-chart.d.ts +5 -0
  869. package/dist/types/lib/charts/configuration/axis-configurator.d.ts +36 -0
  870. package/dist/types/lib/charts/configuration/combo-config.d.ts +36 -0
  871. package/dist/types/lib/charts/configuration/data-labels-config.d.ts +36 -0
  872. package/dist/types/lib/charts/configuration/legend-config.d.ts +18 -0
  873. package/dist/types/lib/charts/create-chart.d.ts +30 -0
  874. package/dist/types/lib/charts/custom-config-utils.d.ts +0 -0
  875. package/dist/types/lib/charts/funnel-chart.d.ts +13 -0
  876. package/dist/types/lib/charts/heatmap-chart.d.ts +15 -0
  877. package/dist/types/lib/charts/heatmap-constants.d.ts +7 -0
  878. package/dist/types/lib/charts/line-chart.d.ts +5 -0
  879. package/dist/types/lib/charts/range-chart.d.ts +12 -0
  880. package/dist/types/lib/charts/shared/dataset-utils.d.ts +36 -0
  881. package/dist/types/lib/charts/tornado-chart.d.ts +13 -0
  882. package/dist/types/lib/charts/treemap-chart.d.ts +15 -0
  883. package/dist/types/lib/charts/types.d.ts +64 -0
  884. package/dist/types/lib/charts/utils.d.ts +12 -0
  885. package/dist/types/lib/class-utils.d.ts +2 -0
  886. package/dist/types/lib/constants/summary.d.ts +2 -0
  887. package/dist/types/lib/constants/tool-status-messages.d.ts +12 -0
  888. package/dist/types/lib/constants.d.ts +30 -0
  889. package/dist/types/lib/contexts/dashboard-preferences-context.d.ts +7 -0
  890. package/dist/types/lib/contexts/display-preferences-context.d.ts +6 -0
  891. package/dist/types/lib/contexts/interactions-popover-context.d.ts +21 -0
  892. package/dist/types/lib/controls/control-authoring-types.d.ts +28 -0
  893. package/dist/types/lib/countries.d.ts +8 -0
  894. package/dist/types/lib/dashboard/duplicate-sheet.d.ts +11 -0
  895. package/dist/types/lib/dashboard/global-date-filter-utils.d.ts +22 -0
  896. package/dist/types/lib/dashboard/normalize-dashboard-for-dirty-check.d.ts +18 -0
  897. package/dist/types/lib/dashboard/semantic-dataset-references.d.ts +24 -0
  898. package/dist/types/lib/dashboard-inputs/build-normalized-dashboard-inputs.d.ts +41 -0
  899. package/dist/types/lib/dashboard-inputs/card-compat-adapter.d.ts +9 -0
  900. package/dist/types/lib/dashboard-inputs/dashboard-control-compat-adapter.d.ts +7 -0
  901. package/dist/types/lib/dashboard-inputs/dashboard-date-comparison-plan.d.ts +61 -0
  902. package/dist/types/lib/dashboard-inputs/dashboard-date-comparison.d.ts +42 -0
  903. package/dist/types/lib/dashboard-inputs/dashboard-filter-authoring-policy.d.ts +21 -0
  904. package/dist/types/lib/dashboard-inputs/dashboard-filter-compat-adapter.d.ts +10 -0
  905. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +142 -0
  906. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-candidate-metadata.d.ts +104 -0
  907. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-storage-transition.d.ts +75 -0
  908. package/dist/types/lib/dashboard-inputs/dashboard-filter-ownership.d.ts +13 -0
  909. package/dist/types/lib/dashboard-inputs/dashboard-filter-value-identity.d.ts +36 -0
  910. package/dist/types/lib/dashboard-inputs/dashboard-input-authoring-aliases.d.ts +13 -0
  911. package/dist/types/lib/dashboard-inputs/dashboard-input-edit-validation.d.ts +20 -0
  912. package/dist/types/lib/dashboard-inputs/dashboard-input-helpers.d.ts +15 -0
  913. package/dist/types/lib/dashboard-inputs/dashboard-input-snapshot.d.ts +58 -0
  914. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +120 -0
  915. package/dist/types/lib/dashboard-inputs/dashboard-input-text.d.ts +11 -0
  916. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +43 -0
  917. package/dist/types/lib/dashboard-inputs/dashboard-option-dependency-context.d.ts +40 -0
  918. package/dist/types/lib/dashboard-inputs/document-input-prototype-normalizer.d.ts +2 -0
  919. package/dist/types/lib/dashboard-inputs/filter-authoring-capabilities.d.ts +39 -0
  920. package/dist/types/lib/dashboard-inputs/find-normalized-dashboard-filter-input.d.ts +4 -0
  921. package/dist/types/lib/dashboard-inputs/index.d.ts +11 -0
  922. package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +57 -0
  923. package/dist/types/lib/dashboard-inputs/resolve-field-date-comparison-coverage.d.ts +17 -0
  924. package/dist/types/lib/dashboard-inputs/text-card-rich-content.d.ts +5 -0
  925. package/dist/types/lib/dashboard-inputs/use-effective-dashboard-filter-storage.d.ts +7 -0
  926. package/dist/types/lib/dnd-utils.d.ts +5 -0
  927. package/dist/types/lib/document/document-dashboard-inputs.d.ts +48 -0
  928. package/dist/types/lib/document/document-definition.d.ts +14 -0
  929. package/dist/types/lib/document/document-input-order.d.ts +5 -0
  930. package/dist/types/lib/document/document-input-runtime.d.ts +25 -0
  931. package/dist/types/lib/document/document-inputs.d.ts +30 -0
  932. package/dist/types/lib/document/document-page-metrics.d.ts +34 -0
  933. package/dist/types/lib/document/document-pagination.d.ts +57 -0
  934. package/dist/types/lib/document/document-render-mode.d.ts +8 -0
  935. package/dist/types/lib/document/document-section-editor.d.ts +8 -0
  936. package/dist/types/lib/document/document-section-utils.d.ts +11 -0
  937. package/dist/types/lib/document/document-sheet-utils.d.ts +4 -0
  938. package/dist/types/lib/document/document-table-data-policy.d.ts +15 -0
  939. package/dist/types/lib/document/document-table-dom.d.ts +31 -0
  940. package/dist/types/lib/document/document-table-pagination-model.d.ts +67 -0
  941. package/dist/types/lib/document/document-table-print-model.d.ts +52 -0
  942. package/dist/types/lib/document/document-table-result-columns.d.ts +10 -0
  943. package/dist/types/lib/document/document-table-style.d.ts +33 -0
  944. package/dist/types/lib/document/document-table-totals.d.ts +8 -0
  945. package/dist/types/lib/document/document-variables.d.ts +59 -0
  946. package/dist/types/lib/document/document-visual-render-contract.d.ts +8 -0
  947. package/dist/types/lib/document/use-document-table-rows.d.ts +21 -0
  948. package/dist/types/lib/download-pdf.d.ts +104 -0
  949. package/dist/types/lib/drag-and-drop-utils.d.ts +2 -0
  950. package/dist/types/lib/editor-draft-sync.d.ts +2 -0
  951. package/dist/types/lib/encrypt-utils.d.ts +9 -0
  952. package/dist/types/lib/explorer-utils.d.ts +11 -0
  953. package/dist/types/lib/export-utils.d.ts +45 -0
  954. package/dist/types/lib/exports/export-status.d.ts +17 -0
  955. package/dist/types/lib/fields/field-display.d.ts +35 -0
  956. package/dist/types/lib/filter-values/build-card-filter-definition.d.ts +18 -0
  957. package/dist/types/lib/filter-values/build-filter-values-request-payload.d.ts +116 -0
  958. package/dist/types/lib/filter-values/filter-option-dependency-feedback.d.ts +43 -0
  959. package/dist/types/lib/filter-values/filter-option-identity.d.ts +10 -0
  960. package/dist/types/lib/filter-values/filter-option-selection-relevance.d.ts +27 -0
  961. package/dist/types/lib/filter-values/filter-record-value.d.ts +9 -0
  962. package/dist/types/lib/filter-values/merge-additional-filter-values.d.ts +12 -0
  963. package/dist/types/lib/formatters/active-numeric-presentation.d.ts +25 -0
  964. package/dist/types/lib/formatters/canonical-format-adapter.d.ts +34 -0
  965. package/dist/types/lib/formatters/card-format-context.d.ts +14 -0
  966. package/dist/types/lib/formatters/cartesian-temporal-presentation.d.ts +75 -0
  967. package/dist/types/lib/formatters/chart-numeric-presentation.d.ts +25 -0
  968. package/dist/types/lib/formatters/currency-presentation-binding.d.ts +72 -0
  969. package/dist/types/lib/formatters/dashboard-temporal-presentation.d.ts +10 -0
  970. package/dist/types/lib/formatters/dashboard-temporal-snapshot.d.ts +28 -0
  971. package/dist/types/lib/formatters/grouped-temporal-activation.d.ts +36 -0
  972. package/dist/types/lib/formatters/grouped-temporal-authoring.d.ts +33 -0
  973. package/dist/types/lib/formatters/grouped-temporal-presentation.d.ts +124 -0
  974. package/dist/types/lib/formatters/kpi-number-formatter.d.ts +24 -0
  975. package/dist/types/lib/formatters/kpi-result-columns.d.ts +3 -0
  976. package/dist/types/lib/formatters/metric-formatting.d.ts +197 -0
  977. package/dist/types/lib/formatters/numeric-presentation.d.ts +10 -0
  978. package/dist/types/lib/formatters/numeric-value-coercion.d.ts +10 -0
  979. package/dist/types/lib/formatters/pivot-result-lifecycle-config.d.ts +15 -0
  980. package/dist/types/lib/formatters/raw-temporal-on-demand-delivery.d.ts +63 -0
  981. package/dist/types/lib/formatters/raw-temporal-presentation.d.ts +155 -0
  982. package/dist/types/lib/formatters/regular-table-temporal-presentation.d.ts +9 -0
  983. package/dist/types/lib/formatters/result-column-identity.d.ts +3 -0
  984. package/dist/types/lib/formatters/saved-temporal-bucket-format.d.ts +43 -0
  985. package/dist/types/lib/formatters/semantic-column-presentation.d.ts +9 -0
  986. package/dist/types/lib/formatters/value-formatter.d.ts +64 -0
  987. package/dist/types/lib/hooks/ai/assistant-context-entity-utils.d.ts +6 -0
  988. package/dist/types/lib/hooks/ai/assistant-session.d.ts +3 -0
  989. package/dist/types/lib/hooks/ai/dashboard-assistant-context.d.ts +35 -0
  990. package/dist/types/lib/hooks/ai/dashboard-context.d.ts +34 -0
  991. package/dist/types/lib/hooks/ai/use-active-tool-status.d.ts +10 -0
  992. package/dist/types/lib/hooks/ai/use-assistant-context-entities.d.ts +19 -0
  993. package/dist/types/lib/hooks/ai/use-assistant-profile.d.ts +6 -0
  994. package/dist/types/lib/hooks/ai/use-assistant-scroll.d.ts +8 -0
  995. package/dist/types/lib/hooks/ai/use-auto-submit-queue.d.ts +13 -0
  996. package/dist/types/lib/hooks/ai/use-dashboard-assistant.d.ts +36 -0
  997. package/dist/types/lib/hooks/ai/use-editor-assistant.d.ts +33 -0
  998. package/dist/types/lib/hooks/ai/use-entity-mentions.d.ts +36 -0
  999. package/dist/types/lib/hooks/ai/use-local-storage-state.d.ts +1 -0
  1000. package/dist/types/lib/hooks/ai/utils.d.ts +64 -0
  1001. package/dist/types/lib/hooks/calculated-fields/use-ai-expression.d.ts +23 -0
  1002. package/dist/types/lib/hooks/calculated-fields/use-available-fields.d.ts +111 -0
  1003. package/dist/types/lib/hooks/calculated-fields/use-expression-validation.d.ts +18 -0
  1004. package/dist/types/lib/hooks/calculated-fields/use-promote-to-domain.d.ts +17 -0
  1005. package/dist/types/lib/hooks/chartjs/use-chart-blur.d.ts +6 -0
  1006. package/dist/types/lib/hooks/control-values-query-utils.d.ts +6 -0
  1007. package/dist/types/lib/hooks/explorer/column-catalog.d.ts +4 -0
  1008. package/dist/types/lib/hooks/explorer/column-native-datatype.d.ts +8 -0
  1009. package/dist/types/lib/hooks/explorer/field-management-utils.d.ts +2 -0
  1010. package/dist/types/lib/hooks/explorer/use-card-filter-option-browse.d.ts +10 -0
  1011. package/dist/types/lib/hooks/explorer/use-columns.d.ts +11 -0
  1012. package/dist/types/lib/hooks/explorer/use-data-models.d.ts +8 -0
  1013. package/dist/types/lib/hooks/explorer/use-database-entities.d.ts +15 -0
  1014. package/dist/types/lib/hooks/explorer/use-databases.d.ts +12 -0
  1015. package/dist/types/lib/hooks/explorer/use-datasets.d.ts +53 -0
  1016. package/dist/types/lib/hooks/explorer/use-dev-mode-actions.d.ts +10 -0
  1017. package/dist/types/lib/hooks/explorer/use-domain-calculated-fields.d.ts +6 -0
  1018. package/dist/types/lib/hooks/explorer/use-drag-and-drop.d.ts +22 -0
  1019. package/dist/types/lib/hooks/explorer/use-field-availability-context.d.ts +16 -0
  1020. package/dist/types/lib/hooks/explorer/use-field-management.d.ts +42 -0
  1021. package/dist/types/lib/hooks/explorer/use-files.d.ts +13 -0
  1022. package/dist/types/lib/hooks/explorer/use-filter-builder.d.ts +24 -0
  1023. package/dist/types/lib/hooks/explorer/use-filterable-fields.d.ts +61 -0
  1024. package/dist/types/lib/hooks/explorer/use-join-conditions-builder.d.ts +27 -0
  1025. package/dist/types/lib/hooks/explorer/use-schemas.d.ts +8 -0
  1026. package/dist/types/lib/hooks/explorer/use-scoped-fields.d.ts +53 -0
  1027. package/dist/types/lib/hooks/explorer/use-semantic-domains.d.ts +17 -0
  1028. package/dist/types/lib/hooks/explorer/use-sync-legacy-editor-state.d.ts +20 -0
  1029. package/dist/types/lib/hooks/index.d.ts +14 -0
  1030. package/dist/types/lib/hooks/interactions/use-event-engine.d.ts +65 -0
  1031. package/dist/types/lib/hooks/query-context/use-card-query-context.d.ts +3 -0
  1032. package/dist/types/lib/hooks/query-context/use-dashboard-card-execution-snapshot.d.ts +4 -0
  1033. package/dist/types/lib/hooks/semaphor-ready-indicator.d.ts +17 -0
  1034. package/dist/types/lib/hooks/summary/create-summary-action-handler.d.ts +15 -0
  1035. package/dist/types/lib/hooks/use-add-new-frame.d.ts +8 -0
  1036. package/dist/types/lib/hooks/use-assign-filter.d.ts +5 -0
  1037. package/dist/types/lib/hooks/use-attribute-values.d.ts +20 -0
  1038. package/dist/types/lib/hooks/use-auth-token.d.ts +1 -0
  1039. package/dist/types/lib/hooks/use-authorization-scope.d.ts +2 -0
  1040. package/dist/types/lib/hooks/use-calendar-context.d.ts +13 -0
  1041. package/dist/types/lib/hooks/use-calendar-preferences.d.ts +16 -0
  1042. package/dist/types/lib/hooks/use-card-filter-values.d.ts +19 -0
  1043. package/dist/types/lib/hooks/use-card-numeric-presentation.d.ts +11 -0
  1044. package/dist/types/lib/hooks/use-card-summary.d.ts +17 -0
  1045. package/dist/types/lib/hooks/use-chart-numeric-presentation.d.ts +3 -0
  1046. package/dist/types/lib/hooks/use-click-outside.d.ts +21 -0
  1047. package/dist/types/lib/hooks/use-column-sizing.d.ts +27 -0
  1048. package/dist/types/lib/hooks/use-connection-type.d.ts +0 -0
  1049. package/dist/types/lib/hooks/use-connections.d.ts +27 -0
  1050. package/dist/types/lib/hooks/use-control-values-query.d.ts +48 -0
  1051. package/dist/types/lib/hooks/use-copy-paste-frame.d.ts +2 -0
  1052. package/dist/types/lib/hooks/use-custom-visuals-query.d.ts +30 -0
  1053. package/dist/types/lib/hooks/use-dashboard-authoring.d.ts +49 -0
  1054. package/dist/types/lib/hooks/use-dashboard-card-query.d.ts +4 -0
  1055. package/dist/types/lib/hooks/use-dashboard-card.d.ts +41 -0
  1056. package/dist/types/lib/hooks/use-dashboard-creation.d.ts +17 -0
  1057. package/dist/types/lib/hooks/use-dashboard-filter-mapping-candidates.d.ts +22 -0
  1058. package/dist/types/lib/hooks/use-dashboard-filter-option-fields.d.ts +15 -0
  1059. package/dist/types/lib/hooks/use-dashboard-frame-query.d.ts +44 -0
  1060. package/dist/types/lib/hooks/use-dashboard-frame.d.ts +0 -0
  1061. package/dist/types/lib/hooks/use-dashboard-input-target-context.d.ts +24 -0
  1062. package/dist/types/lib/hooks/use-dashboard-interaction-mode.d.ts +1 -0
  1063. package/dist/types/lib/hooks/use-dashboard-kpi-actions.d.ts +11 -0
  1064. package/dist/types/lib/hooks/use-dashboard-preferences.d.ts +5 -0
  1065. package/dist/types/lib/hooks/use-dashboard-query.d.ts +28 -0
  1066. package/dist/types/lib/hooks/use-dashboard-summary.d.ts +13 -0
  1067. package/dist/types/lib/hooks/use-dashboard-unsaved-changes-check.d.ts +3 -0
  1068. package/dist/types/lib/hooks/use-dashboard.d.ts +49 -0
  1069. package/dist/types/lib/hooks/use-data-columns.d.ts +8 -0
  1070. package/dist/types/lib/hooks/use-date-filter.d.ts +36 -0
  1071. package/dist/types/lib/hooks/use-date-range-for-filter.d.ts +7 -0
  1072. package/dist/types/lib/hooks/use-debounce.d.ts +1 -0
  1073. package/dist/types/lib/hooks/use-debounced-dirty-check.d.ts +17 -0
  1074. package/dist/types/lib/hooks/use-debounced-editor-value.d.ts +28 -0
  1075. package/dist/types/lib/hooks/use-default-dashboard-mutation.d.ts +9 -0
  1076. package/dist/types/lib/hooks/use-default-sheet-preference.d.ts +9 -0
  1077. package/dist/types/lib/hooks/use-display-preferences.d.ts +4 -0
  1078. package/dist/types/lib/hooks/use-document-section-editor.d.ts +3 -0
  1079. package/dist/types/lib/hooks/use-draggable-button.d.ts +20 -0
  1080. package/dist/types/lib/hooks/use-draggable-corner.d.ts +22 -0
  1081. package/dist/types/lib/hooks/use-dynamic-fallback-render-context.d.ts +12 -0
  1082. package/dist/types/lib/hooks/use-dynamic-icon.d.ts +1 -0
  1083. package/dist/types/lib/hooks/use-edit-visual.d.ts +6 -0
  1084. package/dist/types/lib/hooks/use-editor-aside.d.ts +52 -0
  1085. package/dist/types/lib/hooks/use-editor-setup.d.ts +45 -0
  1086. package/dist/types/lib/hooks/use-export-polling.d.ts +24 -0
  1087. package/dist/types/lib/hooks/use-export-recovery.d.ts +11 -0
  1088. package/dist/types/lib/hooks/use-feedback.d.ts +12 -0
  1089. package/dist/types/lib/hooks/use-filter-aside-setup.d.ts +13 -0
  1090. package/dist/types/lib/hooks/use-filter-option-browse.d.ts +83 -0
  1091. package/dist/types/lib/hooks/use-filter-option-labels.d.ts +12 -0
  1092. package/dist/types/lib/hooks/use-filter-query.d.ts +79 -0
  1093. package/dist/types/lib/hooks/use-filter-search.d.ts +49 -0
  1094. package/dist/types/lib/hooks/use-frame-semantic-execution-payload.d.ts +15 -0
  1095. package/dist/types/lib/hooks/use-has-dashboard-id.d.ts +6 -0
  1096. package/dist/types/lib/hooks/use-insight-card-info.d.ts +30 -0
  1097. package/dist/types/lib/hooks/use-interactions-popover.d.ts +14 -0
  1098. package/dist/types/lib/hooks/use-is-dashboard-ready.d.ts +11 -0
  1099. package/dist/types/lib/hooks/use-joinability-map.d.ts +24 -0
  1100. package/dist/types/lib/hooks/use-kpi.d.ts +6 -0
  1101. package/dist/types/lib/hooks/use-metric-keys-visual.d.ts +6 -0
  1102. package/dist/types/lib/hooks/use-plugin-query.d.ts +6 -0
  1103. package/dist/types/lib/hooks/use-previous.d.ts +1 -0
  1104. package/dist/types/lib/hooks/use-query-feedback.d.ts +45 -0
  1105. package/dist/types/lib/hooks/use-query-key.d.ts +8 -0
  1106. package/dist/types/lib/hooks/use-role-aware-display-preferences.d.ts +29 -0
  1107. package/dist/types/lib/hooks/use-selected-column.d.ts +29 -0
  1108. package/dist/types/lib/hooks/use-semaphor-context.d.ts +4 -0
  1109. package/dist/types/lib/hooks/use-split-view-preference.d.ts +1 -0
  1110. package/dist/types/lib/hooks/use-stable-value.d.ts +38 -0
  1111. package/dist/types/lib/hooks/use-starred-charts.d.ts +1 -0
  1112. package/dist/types/lib/hooks/use-text-filter.d.ts +66 -0
  1113. package/dist/types/lib/hooks/use-theme.d.ts +1 -0
  1114. package/dist/types/lib/hooks/use-topojson.d.ts +7 -0
  1115. package/dist/types/lib/hooks/use-user-preferences.d.ts +24 -0
  1116. package/dist/types/lib/hooks/use-value-format-preferences.d.ts +15 -0
  1117. package/dist/types/lib/hooks/use-visual-editing-status.d.ts +6 -0
  1118. package/dist/types/lib/hooks/use-visual-save-as.d.ts +9 -0
  1119. package/dist/types/lib/hooks/visuals/use-pivot-table-config.d.ts +6 -0
  1120. package/dist/types/lib/interactions/build-interaction-event.d.ts +25 -0
  1121. package/dist/types/lib/interactions/click-filter-display.d.ts +13 -0
  1122. package/dist/types/lib/interactions/convert-click-filters-to-filter-group.d.ts +10 -0
  1123. package/dist/types/lib/interactions/execute-interaction-event.d.ts +80 -0
  1124. package/dist/types/lib/interactions/field-utils.d.ts +11 -0
  1125. package/dist/types/lib/interactions/get-click-context-from-chartjs.d.ts +21 -0
  1126. package/dist/types/lib/interactions/get-click-context-from-matrix.d.ts +37 -0
  1127. package/dist/types/lib/interactions/get-click-context-from-pivot-table.d.ts +12 -0
  1128. package/dist/types/lib/interactions/get-click-context-from-table.d.ts +35 -0
  1129. package/dist/types/lib/interactions/handle-chart-click.d.ts +75 -0
  1130. package/dist/types/lib/interactions/interaction-utils.d.ts +16 -0
  1131. package/dist/types/lib/interactions/interaction-validation-utils.d.ts +9 -0
  1132. package/dist/types/lib/interactions/interpolate-url-parameters.d.ts +73 -0
  1133. package/dist/types/lib/interactions/linked-interaction-utils.d.ts +14 -0
  1134. package/dist/types/lib/interactions/source-card-filter-utils.d.ts +9 -0
  1135. package/dist/types/lib/internal-print-report-context.d.ts +5 -0
  1136. package/dist/types/lib/matrix-table/matrix-application-adapter.d.ts +64 -0
  1137. package/dist/types/lib/matrix-table/matrix-card-adapter.d.ts +488 -0
  1138. package/dist/types/lib/matrix-table/matrix-card-draft.d.ts +350 -0
  1139. package/dist/types/lib/matrix-table/matrix-card-fields.d.ts +14 -0
  1140. package/dist/types/lib/matrix-table/matrix-card-interactions.d.ts +5 -0
  1141. package/dist/types/lib/matrix-table/matrix-clipboard.d.ts +45 -0
  1142. package/dist/types/lib/matrix-table/matrix-conditional-formatting.d.ts +36 -0
  1143. package/dist/types/lib/matrix-table/matrix-delivery-policy.d.ts +27 -0
  1144. package/dist/types/lib/matrix-table/matrix-delivery.d.ts +751 -0
  1145. package/dist/types/lib/matrix-table/matrix-editor.d.ts +40 -0
  1146. package/dist/types/lib/matrix-table/matrix-execution-context.d.ts +18 -0
  1147. package/dist/types/lib/matrix-table/matrix-execution-provider.d.ts +7 -0
  1148. package/dist/types/lib/matrix-table/matrix-failure-copy.d.ts +16 -0
  1149. package/dist/types/lib/matrix-table/matrix-field-metadata.d.ts +3 -0
  1150. package/dist/types/lib/matrix-table/matrix-label-boundary.d.ts +6 -0
  1151. package/dist/types/lib/matrix-table/matrix-layout.d.ts +18 -0
  1152. package/dist/types/lib/matrix-table/matrix-measure-presentation.d.ts +8 -0
  1153. package/dist/types/lib/matrix-table/matrix-operation-queue.d.ts +8 -0
  1154. package/dist/types/lib/matrix-table/matrix-query-transport.d.ts +3 -0
  1155. package/dist/types/lib/matrix-table/matrix-row-labels.d.ts +13 -0
  1156. package/dist/types/lib/matrix-table/matrix-runtime-types.d.ts +117 -0
  1157. package/dist/types/lib/matrix-table/matrix-runtime.d.ts +76 -0
  1158. package/dist/types/lib/matrix-table/matrix-selection.d.ts +20 -0
  1159. package/dist/types/lib/matrix-table/submit-matrix-delivery.d.ts +19 -0
  1160. package/dist/types/lib/matrix-table/use-matrix-card-catalog.d.ts +20 -0
  1161. package/dist/types/lib/matrix-table/use-matrix-delivery-capture.d.ts +6 -0
  1162. package/dist/types/lib/matrix-table/use-matrix-editor-catalog.d.ts +5 -0
  1163. package/dist/types/lib/matrix-table/use-matrix-editor-refresh.d.ts +15 -0
  1164. package/dist/types/lib/matrix-table/use-matrix-selection.d.ts +59 -0
  1165. package/dist/types/lib/matrix-table/use-matrix.d.ts +68 -0
  1166. package/dist/types/lib/mock-data.d.ts +0 -0
  1167. package/dist/types/lib/object-utils.d.ts +4 -0
  1168. package/dist/types/lib/pdf-execution-snapshot.d.ts +12 -0
  1169. package/dist/types/lib/pdf-fast-path/aggregate-metric-semantics.d.ts +1 -0
  1170. package/dist/types/lib/pdf-fast-path/builders.d.ts +46 -0
  1171. package/dist/types/lib/pdf-fast-path/candidate-eligibility.d.ts +17 -0
  1172. package/dist/types/lib/pdf-fast-path/extract-table-structure.d.ts +5 -0
  1173. package/dist/types/lib/pdf-fast-path/index.d.ts +27 -0
  1174. package/dist/types/lib/pdf-fast-path/pivot-fast-path-utils.d.ts +12 -0
  1175. package/dist/types/lib/pdf-fast-path/prepare-server-table-pdf-export.d.ts +37 -0
  1176. package/dist/types/lib/print-state/capture-expanded-state.d.ts +38 -0
  1177. package/dist/types/lib/print-state/use-expose-print-state.d.ts +30 -0
  1178. package/dist/types/lib/python/default-code.d.ts +1 -0
  1179. package/dist/types/lib/query-context/build-card-control-context.d.ts +16 -0
  1180. package/dist/types/lib/query-context/build-card-query-context.d.ts +45 -0
  1181. package/dist/types/lib/query-context/build-dashboard-card-query-contract.d.ts +67 -0
  1182. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +54 -0
  1183. package/dist/types/lib/query-context/build-dashboard-frame-base-query-contexts.d.ts +50 -0
  1184. package/dist/types/lib/query-context/build-global-date-comparison-context.d.ts +9 -0
  1185. package/dist/types/lib/query-context/build-query-relevant-card-config.d.ts +15 -0
  1186. package/dist/types/lib/query-context/compile-dashboard-card-filters.d.ts +72 -0
  1187. package/dist/types/lib/query-context/control-contract-serialization.d.ts +11 -0
  1188. package/dist/types/lib/query-context/dashboard-card-query-key.d.ts +28 -0
  1189. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +36 -0
  1190. package/dist/types/lib/query-context/dashboard-query-result-context.d.ts +17 -0
  1191. package/dist/types/lib/query-context/global-date-filter-materialization.d.ts +65 -0
  1192. package/dist/types/lib/query-context/normalize-dashboard-card-execution.d.ts +7 -0
  1193. package/dist/types/lib/query-context/resolve-card-primary-date-field.d.ts +35 -0
  1194. package/dist/types/lib/query-context/resolve-render-card-config.d.ts +16 -0
  1195. package/dist/types/lib/query-context/temporal-context-preview.d.ts +14 -0
  1196. package/dist/types/lib/query-context/use-semantic-execution-payload-for-cards.d.ts +24 -0
  1197. package/dist/types/lib/resize-observer-utils.d.ts +10 -0
  1198. package/dist/types/lib/stores/ai-interaction-store.d.ts +97 -0
  1199. package/dist/types/lib/stores/assistant-layout-store.d.ts +17 -0
  1200. package/dist/types/lib/stores/chartjs-store.d.ts +36 -0
  1201. package/dist/types/lib/stores/dashboard-store.d.ts +321 -0
  1202. package/dist/types/lib/stores/drill-actions.d.ts +139 -0
  1203. package/dist/types/lib/stores/editor-store.d.ts +222 -0
  1204. package/dist/types/lib/stores/explorer-actions.d.ts +45 -0
  1205. package/dist/types/lib/stores/explorer-empty-states.d.ts +8 -0
  1206. package/dist/types/lib/stores/export-store.d.ts +51 -0
  1207. package/dist/types/lib/stores/index.d.ts +10 -0
  1208. package/dist/types/lib/stores/interaction-store.d.ts +113 -0
  1209. package/dist/types/lib/stores/management-store.d.ts +31 -0
  1210. package/dist/types/lib/stores/mount-store-devtool.d.ts +2 -0
  1211. package/dist/types/lib/stores/pointer-interaction-store.d.ts +18 -0
  1212. package/dist/types/lib/stores/starred-charts-store.d.ts +27 -0
  1213. package/dist/types/lib/stores/store-events.d.ts +35 -0
  1214. package/dist/types/lib/stores/table-actions.d.ts +28 -0
  1215. package/dist/types/lib/stores/utils.d.ts +40 -0
  1216. package/dist/types/lib/table-formatting/index.d.ts +11 -0
  1217. package/dist/types/lib/table-formatting/table-base-formatting-resolver.d.ts +7 -0
  1218. package/dist/types/lib/table-formatting/table-column-visibility.d.ts +5 -0
  1219. package/dist/types/lib/table-formatting/table-conditional-formatting-columns.d.ts +14 -0
  1220. package/dist/types/lib/table-formatting/table-conditional-formatting-evaluator.d.ts +9 -0
  1221. package/dist/types/lib/table-formatting/table-conditional-formatting-range-source.d.ts +8 -0
  1222. package/dist/types/lib/table-formatting/table-conditional-formatting-range.d.ts +9 -0
  1223. package/dist/types/lib/table-formatting/table-formatting-css.d.ts +10 -0
  1224. package/dist/types/lib/table-formatting/table-formatting-normalize.d.ts +3 -0
  1225. package/dist/types/lib/table-formatting/table-formatting-render-model.d.ts +16 -0
  1226. package/dist/types/lib/table-formatting/table-formatting-schemas.d.ts +1101 -0
  1227. package/dist/types/lib/table-formatting/table-formatting-types.d.ts +220 -0
  1228. package/dist/types/lib/table-formatting/table-formatting-utils.d.ts +30 -0
  1229. package/dist/types/lib/table-formatting/table-formatting-validation.d.ts +12 -0
  1230. package/dist/types/lib/table-formatting/table-presentation-fields.d.ts +21 -0
  1231. package/dist/types/lib/table-formatting/table-presentation-style.d.ts +45 -0
  1232. package/dist/types/lib/table-formatting/table-result-bindings.d.ts +12 -0
  1233. package/dist/types/lib/table-formatting/table-text-flow.d.ts +26 -0
  1234. package/dist/types/lib/table-formatting/table-totals-settings.d.ts +23 -0
  1235. package/dist/types/lib/temporal-filter/temporal-filter-utils.d.ts +41 -0
  1236. package/dist/types/lib/types/assistant-types.d.ts +127 -0
  1237. package/dist/types/lib/types/briefing-types.d.ts +216 -0
  1238. package/dist/types/lib/types/calculated-field-domain-payloads.d.ts +36 -0
  1239. package/dist/types/lib/types/calculated-field-editor-types.d.ts +64 -0
  1240. package/dist/types/lib/types/common-types.d.ts +1621 -0
  1241. package/dist/types/lib/types/dropdown-types.d.ts +11 -0
  1242. package/dist/types/lib/types/explorer-types.d.ts +736 -0
  1243. package/dist/types/lib/types/feedback-types.d.ts +60 -0
  1244. package/dist/types/lib/types/index.d.ts +10 -0
  1245. package/dist/types/lib/types/interaction-types.d.ts +483 -0
  1246. package/dist/types/lib/types/query-types.d.ts +81 -0
  1247. package/dist/types/lib/types/semantic-runtime-types.d.ts +14 -0
  1248. package/dist/types/lib/types/semantic-types.d.ts +118 -0
  1249. package/dist/types/lib/types/summary-types.d.ts +74 -0
  1250. package/dist/types/lib/types/token-types.d.ts +312 -0
  1251. package/dist/types/lib/ui/tenancy-ui.d.ts +25 -0
  1252. package/dist/types/lib/utils/aggregate-expression-utils.d.ts +6 -0
  1253. package/dist/types/lib/utils/app-url-utils.d.ts +7 -0
  1254. package/dist/types/lib/utils/assistant-visibility.d.ts +9 -0
  1255. package/dist/types/lib/utils/async-export-visible-columns.d.ts +12 -0
  1256. package/dist/types/lib/utils/authored-card-fields.d.ts +17 -0
  1257. package/dist/types/lib/utils/briefings-visibility.d.ts +9 -0
  1258. package/dist/types/lib/utils/build-card-export-request.d.ts +30 -0
  1259. package/dist/types/lib/utils/calculate-card-filter-values.d.ts +23 -0
  1260. package/dist/types/lib/utils/calculate-context-aware-filters.d.ts +37 -0
  1261. package/dist/types/lib/utils/calculated-date-dimension-defaults.d.ts +9 -0
  1262. package/dist/types/lib/utils/calculated-dimension-utils.d.ts +2 -0
  1263. package/dist/types/lib/utils/calculated-field-identity-utils.d.ts +20 -0
  1264. package/dist/types/lib/utils/calculated-field-normalization.d.ts +2 -0
  1265. package/dist/types/lib/utils/calculated-field-operations.d.ts +40 -0
  1266. package/dist/types/lib/utils/calculated-field-permissions.d.ts +12 -0
  1267. package/dist/types/lib/utils/calculated-field-scope-utils.d.ts +20 -0
  1268. package/dist/types/lib/utils/calculated-field-token-utils.d.ts +11 -0
  1269. package/dist/types/lib/utils/calculated-field-transition-utils.d.ts +113 -0
  1270. package/dist/types/lib/utils/calculated-field-utils.d.ts +37 -0
  1271. package/dist/types/lib/utils/card-calculated-field-utils.d.ts +12 -0
  1272. package/dist/types/lib/utils/card-config-utils.d.ts +24 -0
  1273. package/dist/types/lib/utils/card-definition.d.ts +387 -0
  1274. package/dist/types/lib/utils/card-loading-state.d.ts +17 -0
  1275. package/dist/types/lib/utils/card-utils.d.ts +52 -0
  1276. package/dist/types/lib/utils/chart-icon-utils.d.ts +26 -0
  1277. package/dist/types/lib/utils/chart-type-field-validation.d.ts +25 -0
  1278. package/dist/types/lib/utils/comparison-export-utils.d.ts +31 -0
  1279. package/dist/types/lib/utils/comparison-output-keys.d.ts +37 -0
  1280. package/dist/types/lib/utils/comparison-period-utils.d.ts +6 -0
  1281. package/dist/types/lib/utils/comparison-validation-utils.d.ts +16 -0
  1282. package/dist/types/lib/utils/comparison-window-caption.d.ts +12 -0
  1283. package/dist/types/lib/utils/connection-capabilities.d.ts +26 -0
  1284. package/dist/types/lib/utils/control-default-value-utils.d.ts +46 -0
  1285. package/dist/types/lib/utils/control-placeholder-utils.d.ts +14 -0
  1286. package/dist/types/lib/utils/control-reference-utils.d.ts +18 -0
  1287. package/dist/types/lib/utils/copy-control-bindings.d.ts +3 -0
  1288. package/dist/types/lib/utils/custom-visual-inputs.d.ts +43 -0
  1289. package/dist/types/lib/utils/dashboard-controls-visibility.d.ts +24 -0
  1290. package/dist/types/lib/utils/dashboard-date-filter-utils.d.ts +16 -0
  1291. package/dist/types/lib/utils/dashboard-interaction-mode.d.ts +12 -0
  1292. package/dist/types/lib/utils/data-source-semantic-domain.d.ts +12 -0
  1293. package/dist/types/lib/utils/data-source-utils.d.ts +22 -0
  1294. package/dist/types/lib/utils/date-filter-column-utils.d.ts +2 -0
  1295. package/dist/types/lib/utils/date-format-utils.d.ts +8 -0
  1296. package/dist/types/lib/utils/date-granularity-utils.d.ts +5 -0
  1297. package/dist/types/lib/utils/date-hierarchy-utils.d.ts +73 -0
  1298. package/dist/types/lib/utils/date-timezone-utils.d.ts +99 -0
  1299. package/dist/types/lib/utils/drag-and-drop-utils.d.ts +8 -0
  1300. package/dist/types/lib/utils/drill-context-utils.d.ts +32 -0
  1301. package/dist/types/lib/utils/entity-consistency-utils.d.ts +48 -0
  1302. package/dist/types/lib/utils/entity-icon-utils.d.ts +17 -0
  1303. package/dist/types/lib/utils/explorer-derived-field.d.ts +4 -0
  1304. package/dist/types/lib/utils/explorer-field-identity.d.ts +15 -0
  1305. package/dist/types/lib/utils/export-result-source.d.ts +20 -0
  1306. package/dist/types/lib/utils/export-utils.d.ts +26 -0
  1307. package/dist/types/lib/utils/expression-field-classification.d.ts +12 -0
  1308. package/dist/types/lib/utils/fetch-export-data.d.ts +14 -0
  1309. package/dist/types/lib/utils/field-availability-context.d.ts +25 -0
  1310. package/dist/types/lib/utils/field-dependencies.d.ts +87 -0
  1311. package/dist/types/lib/utils/field-icon-utils.d.ts +10 -0
  1312. package/dist/types/lib/utils/field-state-calculator.d.ts +159 -0
  1313. package/dist/types/lib/utils/filter-default-value-utils.d.ts +24 -0
  1314. package/dist/types/lib/utils/filter-formatter.d.ts +19 -0
  1315. package/dist/types/lib/utils/filter-metadata-utils.d.ts +28 -0
  1316. package/dist/types/lib/utils/filter-name-utils.d.ts +27 -0
  1317. package/dist/types/lib/utils/filter-scoping-utils.d.ts +64 -0
  1318. package/dist/types/lib/utils/filter-search-sql.d.ts +17 -0
  1319. package/dist/types/lib/utils/format-config-extractor.d.ts +21 -0
  1320. package/dist/types/lib/utils/frame-utils.d.ts +27 -0
  1321. package/dist/types/lib/utils/inline-expression-utils.d.ts +11 -0
  1322. package/dist/types/lib/utils/inline-filter-utils.d.ts +15 -0
  1323. package/dist/types/lib/utils/interaction-display-utils.d.ts +30 -0
  1324. package/dist/types/lib/utils/interaction-icons.d.ts +10 -0
  1325. package/dist/types/lib/utils/is-safari-browser.d.ts +6 -0
  1326. package/dist/types/lib/utils/join-plan-entity-matching.d.ts +26 -0
  1327. package/dist/types/lib/utils/kpi-comparison-utils.d.ts +12 -0
  1328. package/dist/types/lib/utils/kpi-field-cleanup-utils.d.ts +19 -0
  1329. package/dist/types/lib/utils/kpi-format-migration.d.ts +2 -0
  1330. package/dist/types/lib/utils/metric-comparison-config.d.ts +9 -0
  1331. package/dist/types/lib/utils/physical-source-identity.d.ts +12 -0
  1332. package/dist/types/lib/utils/qualified-entity-name.d.ts +2 -0
  1333. package/dist/types/lib/utils/resolve-selected-sheet-id.d.ts +11 -0
  1334. package/dist/types/lib/utils/role-display-mappings.d.ts +44 -0
  1335. package/dist/types/lib/utils/semantic-metric-format-defaults.d.ts +3 -0
  1336. package/dist/types/lib/utils/slot-validation.d.ts +12 -0
  1337. package/dist/types/lib/utils/stable-serialize.d.ts +1 -0
  1338. package/dist/types/lib/utils/summary-eligibility.d.ts +7 -0
  1339. package/dist/types/lib/utils/summary-filter-utils.d.ts +2 -0
  1340. package/dist/types/lib/utils/table-comparison-utils.d.ts +9 -0
  1341. package/dist/types/lib/utils/text-card-runtime-utils.d.ts +6 -0
  1342. package/dist/types/lib/utils/url-parameter-utils.d.ts +60 -0
  1343. package/dist/types/lib/utils/window-transform-utils.d.ts +41 -0
  1344. package/dist/types/lib/utils.d.ts +58 -0
  1345. package/dist/types/lib/visuals/frame-object.d.ts +4 -0
  1346. package/dist/types/main.d.ts +2 -27077
  1347. package/dist/types/pdf-export-policy.d.ts +2 -28
  1348. package/dist/types/report-runtime-context.d.ts +2 -102
  1349. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +2354 -0
  1350. package/dist/types/shared/analytics-protocol/analyze-result-contract.d.ts +5 -0
  1351. package/dist/types/shared/analytics-protocol/analyze-result-types.d.ts +105 -0
  1352. package/dist/types/shared/analytics-protocol/catalog-field-grounding.d.ts +60 -0
  1353. package/dist/types/shared/analytics-protocol/catalog-source-address.d.ts +27 -0
  1354. package/dist/types/shared/analytics-protocol/contracts.d.ts +845 -0
  1355. package/dist/types/shared/analytics-protocol/dashboard-date-comparison-definition.d.ts +24 -0
  1356. package/dist/types/shared/analytics-protocol/dashboard-input-contract.d.ts +8 -0
  1357. package/dist/types/shared/analytics-protocol/data-app-codegen-summary.d.ts +418 -0
  1358. package/dist/types/shared/analytics-protocol/exact-decimal.d.ts +15 -0
  1359. package/dist/types/shared/analytics-protocol/execution-input-schemas.d.ts +1927 -0
  1360. package/dist/types/shared/analytics-protocol/explorer-input-schemas.d.ts +5 -0
  1361. package/dist/types/shared/analytics-protocol/field-validation.d.ts +15 -0
  1362. package/dist/types/shared/analytics-protocol/fixtures.d.ts +249 -0
  1363. package/dist/types/shared/analytics-protocol/index.d.ts +30 -0
  1364. package/dist/types/shared/analytics-protocol/matrix-analytical-definition.d.ts +253 -0
  1365. package/dist/types/shared/analytics-protocol/matrix-definition-contract.d.ts +7409 -0
  1366. package/dist/types/shared/analytics-protocol/matrix-member-presentation.d.ts +20 -0
  1367. package/dist/types/shared/analytics-protocol/matrix-operation-contract.d.ts +759 -0
  1368. package/dist/types/shared/analytics-protocol/matrix-operation-request.d.ts +743 -0
  1369. package/dist/types/shared/analytics-protocol/matrix-path-contract.d.ts +427 -0
  1370. package/dist/types/shared/analytics-protocol/matrix-window-contract.d.ts +404 -0
  1371. package/dist/types/shared/analytics-protocol/metric-comparison.d.ts +183 -0
  1372. package/dist/types/shared/analytics-protocol/operators.d.ts +10 -0
  1373. package/dist/types/shared/analytics-protocol/option-predicate.d.ts +43 -0
  1374. package/dist/types/shared/analytics-protocol/option-relevance.d.ts +19 -0
  1375. package/dist/types/shared/analytics-protocol/physical-source-resolution.d.ts +54 -0
  1376. package/dist/types/shared/analytics-protocol/qualified-identity.d.ts +3 -0
  1377. package/dist/types/shared/analytics-protocol/raw-temporal-contract.d.ts +14 -0
  1378. package/dist/types/shared/analytics-protocol/runtime-schemas.d.ts +3373 -0
  1379. package/dist/types/shared/analytics-protocol/scalar-value.d.ts +55 -0
  1380. package/dist/types/shared/analytics-protocol/source-capabilities.d.ts +64 -0
  1381. package/dist/types/shared/analytics-protocol/source-entity-resolution.d.ts +80 -0
  1382. package/dist/types/shared/analytics-protocol/source-identity.d.ts +36 -0
  1383. package/dist/types/shared/analytics-protocol/temporal-bucket-contract.d.ts +39 -0
  1384. package/dist/types/shared/analytics-protocol/temporal-context.d.ts +35 -0
  1385. package/dist/types/shared/analytics-protocol/validators.d.ts +21 -0
  1386. package/dist/types/shared/dashboard-authoring/artifact-compiler.d.ts +6 -0
  1387. package/dist/types/shared/dashboard-authoring/calculated-field-identity.d.ts +22 -0
  1388. package/dist/types/shared/dashboard-authoring/calculated-field-placement.d.ts +16 -0
  1389. package/dist/types/shared/dashboard-authoring/canonical-result-keys.d.ts +25 -0
  1390. package/dist/types/shared/dashboard-authoring/card-reference-remapping.d.ts +6 -0
  1391. package/dist/types/shared/dashboard-authoring/change-compiler.d.ts +7 -0
  1392. package/dist/types/shared/dashboard-authoring/comparison-document-migration.d.ts +36 -0
  1393. package/dist/types/shared/dashboard-authoring/contracts.d.ts +153 -0
  1394. package/dist/types/shared/dashboard-authoring/control-value-resolution.d.ts +51 -0
  1395. package/dist/types/shared/dashboard-authoring/dashboard-card-source-index.d.ts +37 -0
  1396. package/dist/types/shared/dashboard-authoring/dashboard-filter-automatic-target.d.ts +37 -0
  1397. package/dist/types/shared/dashboard-authoring/dashboard-filter-mapping-contract.d.ts +32 -0
  1398. package/dist/types/shared/dashboard-authoring/dashboard-filter-mapping-types.d.ts +46 -0
  1399. package/dist/types/shared/dashboard-authoring/dashboard-filter-sql-subscription.d.ts +10 -0
  1400. package/dist/types/shared/dashboard-authoring/dashboard-filter-sql-target.d.ts +20 -0
  1401. package/dist/types/shared/dashboard-authoring/dashboard-filter-value-compatibility.d.ts +9 -0
  1402. package/dist/types/shared/dashboard-authoring/dashboard-option-dependencies.d.ts +81 -0
  1403. package/dist/types/shared/dashboard-authoring/field-aggregations.d.ts +29 -0
  1404. package/dist/types/shared/dashboard-authoring/filter-defaults.d.ts +2 -0
  1405. package/dist/types/shared/dashboard-authoring/index.d.ts +29 -0
  1406. package/dist/types/shared/dashboard-authoring/layout-compiler.d.ts +2 -0
  1407. package/dist/types/shared/dashboard-authoring/matrix-authoring.d.ts +59 -0
  1408. package/dist/types/shared/dashboard-authoring/matrix-card.d.ts +25 -0
  1409. package/dist/types/shared/dashboard-authoring/matrix-control-resolution.d.ts +19 -0
  1410. package/dist/types/shared/dashboard-authoring/matrix-control-sources.d.ts +14 -0
  1411. package/dist/types/shared/dashboard-authoring/matrix-definition.d.ts +15 -0
  1412. package/dist/types/shared/dashboard-authoring/matrix-delivery.d.ts +1453 -0
  1413. package/dist/types/shared/dashboard-authoring/protocol-adapter.d.ts +7 -0
  1414. package/dist/types/shared/dashboard-authoring/source-matching.d.ts +34 -0
  1415. package/dist/types/shared/dashboard-authoring/temporal-bucket-authoring.d.ts +19 -0
  1416. package/dist/types/shared/dashboard-authoring/temporal-result-owner.d.ts +25 -0
  1417. package/dist/types/shared/dashboard-authoring/validators.d.ts +3 -0
  1418. package/dist/types/shared/dirty-check/index.d.ts +2 -0
  1419. package/dist/types/shared/filter-native-data-type.d.ts +59 -0
  1420. package/dist/types/shared/format-utils/aggregate-table-row-presentation.d.ts +85 -0
  1421. package/dist/types/shared/format-utils/export-policy.d.ts +19 -0
  1422. package/dist/types/shared/format-utils/exporters/csv-utils.d.ts +23 -0
  1423. package/dist/types/shared/format-utils/exporters/index.d.ts +3 -0
  1424. package/dist/types/shared/format-utils/exporters/pivot-exporter.d.ts +13 -0
  1425. package/dist/types/shared/format-utils/exporters/table-exporter.d.ts +10 -0
  1426. package/dist/types/shared/format-utils/flat-table-export-totals.d.ts +25 -0
  1427. package/dist/types/shared/format-utils/formatters/cell-formatter.d.ts +22 -0
  1428. package/dist/types/shared/format-utils/formatters/date-formatter.d.ts +62 -0
  1429. package/dist/types/shared/format-utils/formatters/duration-formatter.d.ts +2 -0
  1430. package/dist/types/shared/format-utils/formatters/exact-number.d.ts +1 -0
  1431. package/dist/types/shared/format-utils/formatters/index.d.ts +6 -0
  1432. package/dist/types/shared/format-utils/formatters/matrix-formatter.d.ts +35 -0
  1433. package/dist/types/shared/format-utils/formatters/metric-comparison-formatter.d.ts +22 -0
  1434. package/dist/types/shared/format-utils/formatters/number-formatter.d.ts +47 -0
  1435. package/dist/types/shared/format-utils/grouped-table-presentation.d.ts +15 -0
  1436. package/dist/types/shared/format-utils/index.d.ts +38 -0
  1437. package/dist/types/shared/format-utils/json-record.d.ts +6 -0
  1438. package/dist/types/shared/format-utils/matrix-continuation.d.ts +195 -0
  1439. package/dist/types/shared/format-utils/matrix-export-presentation.d.ts +22 -0
  1440. package/dist/types/shared/format-utils/numeric-presentation.d.ts +36 -0
  1441. package/dist/types/shared/format-utils/pdf-delivery.d.ts +25 -0
  1442. package/dist/types/shared/format-utils/pdf-export-policy.d.ts +20 -0
  1443. package/dist/types/shared/format-utils/pivot-header-presentation.d.ts +28 -0
  1444. package/dist/types/shared/format-utils/pivot-result-contract-expectations.d.ts +28 -0
  1445. package/dist/types/shared/format-utils/pivot-result-identity.d.ts +52 -0
  1446. package/dist/types/shared/format-utils/pivot-result-lifecycle.d.ts +55 -0
  1447. package/dist/types/shared/format-utils/presentation-execution.d.ts +88 -0
  1448. package/dist/types/shared/format-utils/raw-temporal.d.ts +89 -0
  1449. package/dist/types/shared/format-utils/semantic-format.d.ts +44 -0
  1450. package/dist/types/shared/format-utils/table-structure.d.ts +43 -0
  1451. package/dist/types/shared/format-utils/temporal-bucket-format-policy.d.ts +41 -0
  1452. package/dist/types/shared/format-utils/temporal-bucket.d.ts +77 -0
  1453. package/dist/types/shared/format-utils/types/format-types.d.ts +233 -0
  1454. package/dist/types/shared/format-utils/types/index.d.ts +1 -0
  1455. package/dist/types/shared/index.d.ts +1 -0
  1456. package/dist/types/shared/layouts/create-frame-layouts.d.ts +27 -0
  1457. package/dist/types/shared/layouts/index.d.ts +1 -0
  1458. package/dist/types/shared/report-runtime-context/calendar-validation.d.ts +2 -0
  1459. package/dist/types/shared/report-runtime-context/index.d.ts +2 -0
  1460. package/dist/types/shared/report-runtime-context/report-runtime-context.d.ts +58 -0
  1461. package/dist/types/shared/value-format-preferences/index.d.ts +1 -0
  1462. package/dist/types/shared/value-format-preferences/value-format-preferences.d.ts +102 -0
  1463. package/dist/types/shared.d.ts +2 -9998
  1464. package/dist/types/surfboard.d.ts +2 -10912
  1465. package/dist/types/types.d.ts +2 -12281
  1466. package/dist/types/value-format-preferences.d.ts +2 -129
  1467. package/package.json +3 -2
  1468. package/dist/chunks/validators-D2F_uxxP.cjs +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";var Kye=Object.defineProperty;var qB=e=>{throw TypeError(e)};var Wye=(e,t,n)=>t in e?Kye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Se=(e,t,n)=>Wye(e,typeof t!="symbol"?t+"":t,n),dD=(e,t,n)=>t.has(e)||qB("Cannot "+n);var je=(e,t,n)=>(dD(e,t,"read from private field"),n?n.call(e):t.get(e)),zt=(e,t,n)=>t.has(e)?qB("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jt=(e,t,n,r)=>(dD(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),rn=(e,t,n)=>(dD(e,t,"access private method"),n);var RC=(e,t,n,r)=>({set _(o){jt(e,t,o,n)},get _(){return je(e,t,r)}});const l=require("react/jsx-runtime"),v=require("react"),Mr=require("react-dom"),m=require("./switch-Dp4U6GwI.cjs"),Re=require("./x-B6ghREd2.cjs"),lt=require("./constants-DNgpRMaX.cjs"),ze=require("./validators-D2F_uxxP.cjs"),Dv=require("./matrix-operation-contract-thtFuUYf.cjs"),Yi=require("../value-format-preferences/index.cjs"),fg=require("./appearance-runtime-provider-Ca8rxO86.cjs"),fi=require("./appearance-context-tNjvTJj3.cjs"),Am=require("./index-C8XCKzB6.cjs"),Gye=require("react-dom/client"),lo=require("./field-aggregations-mlkON_QA.cjs");require("zod");require("./matrix-continuation-6nhDy-lF.cjs");const Ft=require("./search-BqqhaMx9.cjs"),Yye=require("./color-CyB5o13F.cjs"),Ev=require("./field-dependencies-R7MrlW6D.cjs"),rt=require("./index-Bh3SlWJS.cjs"),en=require("./calculated-field-identity-CtYhhZoG.cjs"),Io=require("./metric-comparison-CAqV6VnZ.cjs"),Dn=require("./pivot-header-presentation-DUXM-VOP.cjs"),Xn=require("./matrix-formatter-CWtdnbfv.cjs"),Ji=require("./pivot-result-identity-DJyF4I2K.cjs"),un=require("./raw-temporal-DYoPBY6B.cjs"),Lt=require("./semantic-format-C7Goni6h.cjs"),mu=require("./matrix-card-Dh0J0_Of.cjs"),_s=require("./matrix-definition-CKVi4VVg.cjs"),ji=require("./pivot-result-lifecycle-E_huAPev.cjs"),kd=require("../pdf-export-policy/index.cjs"),Ld=require("./source-entity-resolution-BMKxwdKN.cjs"),es=require("./stable-serialize-jqCpyZvd.cjs"),kN=require("./matrix-analytical-definition-wIEDXvV5.cjs"),Es=require("./matrix-control-sources-a67fwoOO.cjs"),OY=require("./report-runtime-context-CqFbgZq9.cjs"),Zye=require("./operators-DEfKaU_V.cjs"),IN=require("./matrix-member-presentation-e_KZoZOx.cjs"),Xye=require("./temporal-bucket-4YEPEKlJ.cjs"),Qye=require("./temporal-bucket-contract-CSdspcYj.cjs"),gR=require("./index-F25jnH0p.cjs"),_N=require("./dashboard-date-comparison-definition-CWz_Yte8.cjs"),LY=require("../dashboard-assistant/index.cjs"),Id=require("./common-types-nBuCd3u2.cjs"),Jye=require("../layouts/index.cjs"),UB=require("./normalize-dashboard-for-dirty-check-BYtBA708.cjs");function OO(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const KB=OO(l),ie=OO(v),xR=OO(Mr);function eve(e){return Lt.toDate(e).getMonth()}function tve(e){return Lt.toDate(e).getFullYear()}function nve(e){const t=Ld.resolveSemaphorPhysicalSourceEntity({entities:e.entities,connectionType:e.connectionType,qualifiedHints:[e.identity.qualifiedEntityName],bareHints:[e.identity.entityName,e.identity.entityId]});return t.kind==="resolved"?t.entity:void 0}function $Y(e,t){const n=t.split(".").pop()||t;return e.fieldMeta&&ze.isDerivedField(e.fieldMeta)?{column:t,nativeDataType:void 0,fieldMeta:void 0}:{column:t,nativeDataType:void 0,...e.fieldMeta?{fieldMeta:{...e.fieldMeta,name:n,qualifiedFieldName:t,nativeDataType:void 0}}:{}}}function rve(e){return e!=null&&e.length?e.every(t=>t.type==="model"?!0:t.type!=="dataset"?!1:t.datasetType!=="physical"):!1}function LO(e){const t=e;return{id:e.id,name:e.name,qualifiedFieldName:e.qualifiedFieldName,qualifiedEntityName:e.qualifiedEntityName,entityName:e.entityName,entityId:e.entityId,entityType:e.entityType,dataType:e.dataType,...e.nativeDataType?{nativeDataType:e.nativeDataType}:{},role:e.role,fieldScope:e.fieldScope,calculationRepresentation:e.calculationRepresentation,calculatedFieldOrigin:e.calculatedFieldOrigin,derivedField:e.derivedField,expression:t.expression,calculatedFormula:t.calculatedFormula}}function $O(e,t,n){if(!e&&!t)return;const r=(e==null?void 0:e.selectedEntities)||[],o=e&&e.mode!=="semanticDomain"&&n&&!ze.isDerivedField(n)&&!rve(r)?[nve({entities:r,connectionType:e.connectionType,identity:n})].filter(s=>!!s):r;return{semanticDomainId:e==null?void 0:e.semanticDomainId,selectedEntities:o,connectionId:(e==null?void 0:e.connectionId)||(t==null?void 0:t.connectionId),connectionType:(e==null?void 0:e.connectionType)||(t==null?void 0:t.connectionType)}}function zY(e,t,n){var s,i,a;const r=(s=t==null?void 0:t.selectedEntities)==null?void 0:s[0];if(r&&typeof r=="object"){const c=r.database;if(typeof c=="string"&&c)return c}return!!(e&&e.mode!=="semanticDomain"&&!ze.isDerivedField(n))||(a=(i=e==null?void 0:e.selectedEntities)==null?void 0:i[0])==null?void 0:a.database}function WB(e){return e!=null&&e.startsWith("card-source-")?e.replace("card-source-",""):e}function qg(e,t){var x,b,y,C,w,N,S;if(!e.fieldMeta)return e.column===t.qualifiedFieldName||e.column===t.name;const n=WB((x=e.fieldMeta)==null?void 0:x.id),r=WB(t.id),o=((b=e.fieldMeta)==null?void 0:b.qualifiedFieldName)||e.column,s=o===t.qualifiedFieldName||o===t.name,i=(y=e.fieldMeta)==null?void 0:y.qualifiedEntityName,a=!i||!t.qualifiedEntityName||i===t.qualifiedEntityName,c=(C=e.fieldMeta)==null?void 0:C.entityId,u=!c||!t.entityId||c===t.entityId,d=(w=e.fieldMeta)==null?void 0:w.fieldScope;if(d&&t.fieldScope&&d!==t.fieldScope)return!1;const f=(N=e.fieldMeta)==null?void 0:N.role;if(f&&t.role&&f!==t.role)return!1;const h=ze.isDerivedField(e.fieldMeta)||ze.isDerivedField(t);if(h&&n&&r&&n===r)return!0;if(!h&&(!a||!u))return!1;const p=(S=e.fieldMeta)==null?void 0:S.expression,g=t.expression;return p||g?s&&a&&u&&p===g:s&&a&&u}var TN={exports:{}};TN.exports;(function(e,t){var n=200,r="__lodash_hash_undefined__",o=800,s=16,i=9007199254740991,a="[object Arguments]",c="[object Array]",u="[object AsyncFunction]",d="[object Boolean]",f="[object Date]",h="[object Error]",p="[object Function]",g="[object GeneratorFunction]",x="[object Map]",b="[object Number]",y="[object Null]",C="[object Object]",w="[object Proxy]",N="[object RegExp]",S="[object Set]",j="[object String]",k="[object Undefined]",_="[object WeakMap]",T="[object ArrayBuffer]",I="[object DataView]",D="[object Float32Array]",E="[object Float64Array]",R="[object Int8Array]",F="[object Int16Array]",M="[object Int32Array]",O="[object Uint8Array]",z="[object Uint8ClampedArray]",L="[object Uint16Array]",V="[object Uint32Array]",A=/[\\^$.*+?()[\]{}|]/g,B=/^\[object .+?Constructor\]$/,$=/^(?:0|[1-9]\d*)$/,P={};P[D]=P[E]=P[R]=P[F]=P[M]=P[O]=P[z]=P[L]=P[V]=!0,P[a]=P[c]=P[T]=P[d]=P[I]=P[f]=P[h]=P[p]=P[x]=P[b]=P[C]=P[N]=P[S]=P[j]=P[_]=!1;var U=typeof lt.commonjsGlobal=="object"&&lt.commonjsGlobal&&lt.commonjsGlobal.Object===Object&&lt.commonjsGlobal,H=typeof self=="object"&&self&&self.Object===Object&&self,G=U||H||Function("return this")(),q=t&&!t.nodeType&&t,Y=q&&!0&&e&&!e.nodeType&&e,W=Y&&Y.exports===q,ne=W&&U.process,Z=function(){try{var Ce=Y&&Y.require&&Y.require("util").types;return Ce||ne&&ne.binding&&ne.binding("util")}catch{}}(),K=Z&&Z.isTypedArray;function X(Ce,Le,Ye){switch(Ye.length){case 0:return Ce.call(Le);case 1:return Ce.call(Le,Ye[0]);case 2:return Ce.call(Le,Ye[0],Ye[1]);case 3:return Ce.call(Le,Ye[0],Ye[1],Ye[2])}return Ce.apply(Le,Ye)}function J(Ce,Le){for(var Ye=-1,Ht=Array(Ce);++Ye<Ce;)Ht[Ye]=Le(Ye);return Ht}function re(Ce){return function(Le){return Ce(Le)}}function te(Ce,Le){return Ce==null?void 0:Ce[Le]}function Q(Ce,Le){return function(Ye){return Ce(Le(Ye))}}var se=Array.prototype,oe=Function.prototype,fe=Object.prototype,pe=G["__core-js_shared__"],xe=oe.toString,Ie=fe.hasOwnProperty,be=function(){var Ce=/[^.]+$/.exec(pe&&pe.keys&&pe.keys.IE_PROTO||"");return Ce?"Symbol(src)_1."+Ce:""}(),ge=fe.toString,ee=xe.call(Object),ce=RegExp("^"+xe.call(Ie).replace(A,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ae=W?G.Buffer:void 0,me=G.Symbol,ve=G.Uint8Array;ae&&ae.allocUnsafe;var _e=Q(Object.getPrototypeOf,Object),De=Object.create,Ue=fe.propertyIsEnumerable,Ne=se.splice,Oe=me?me.toStringTag:void 0,ye=function(){try{var Ce=Wt(Object,"defineProperty");return Ce({},"",{}),Ce}catch{}}(),Be=ae?ae.isBuffer:void 0,he=Math.max,ue=Date.now,de=Wt(G,"Map"),Te=Wt(Object,"create"),we=function(){function Ce(){}return function(Le){if(!ua(Le))return{};if(De)return De(Le);Ce.prototype=Le;var Ye=new Ce;return Ce.prototype=void 0,Ye}}();function Ee(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function Ke(){this.__data__=Te?Te(null):{},this.size=0}function He(Ce){var Le=this.has(Ce)&&delete this.__data__[Ce];return this.size-=Le?1:0,Le}function qe(Ce){var Le=this.__data__;if(Te){var Ye=Le[Ce];return Ye===r?void 0:Ye}return Ie.call(Le,Ce)?Le[Ce]:void 0}function Je(Ce){var Le=this.__data__;return Te?Le[Ce]!==void 0:Ie.call(Le,Ce)}function We(Ce,Le){var Ye=this.__data__;return this.size+=this.has(Ce)?0:1,Ye[Ce]=Te&&Le===void 0?r:Le,this}Ee.prototype.clear=Ke,Ee.prototype.delete=He,Ee.prototype.get=qe,Ee.prototype.has=Je,Ee.prototype.set=We;function bt(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function pt(){this.__data__=[],this.size=0}function Bt(Ce){var Le=this.__data__,Ye=Xe(Le,Ce);if(Ye<0)return!1;var Ht=Le.length-1;return Ye==Ht?Le.pop():Ne.call(Le,Ye,1),--this.size,!0}function ut(Ce){var Le=this.__data__,Ye=Xe(Le,Ce);return Ye<0?void 0:Le[Ye][1]}function $t(Ce){return Xe(this.__data__,Ce)>-1}function Fe(Ce,Le){var Ye=this.__data__,Ht=Xe(Ye,Ce);return Ht<0?(++this.size,Ye.push([Ce,Le])):Ye[Ht][1]=Le,this}bt.prototype.clear=pt,bt.prototype.delete=Bt,bt.prototype.get=ut,bt.prototype.has=$t,bt.prototype.set=Fe;function ct(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function It(){this.size=0,this.__data__={hash:new Ee,map:new(de||bt),string:new Ee}}function yt(Ce){var Le=kt(this,Ce).delete(Ce);return this.size-=Le?1:0,Le}function vt(Ce){return kt(this,Ce).get(Ce)}function mt(Ce){return kt(this,Ce).has(Ce)}function St(Ce,Le){var Ye=kt(this,Ce),Ht=Ye.size;return Ye.set(Ce,Le),this.size+=Ye.size==Ht?0:1,this}ct.prototype.clear=It,ct.prototype.delete=yt,ct.prototype.get=vt,ct.prototype.has=mt,ct.prototype.set=St;function it(Ce){var Le=this.__data__=new bt(Ce);this.size=Le.size}function nt(){this.__data__=new bt,this.size=0}function gt(Ce){var Le=this.__data__,Ye=Le.delete(Ce);return this.size=Le.size,Ye}function Vt(Ce){return this.__data__.get(Ce)}function Me(Ce){return this.__data__.has(Ce)}function Qe(Ce,Le){var Ye=this.__data__;if(Ye instanceof bt){var Ht=Ye.__data__;if(!de||Ht.length<n-1)return Ht.push([Ce,Le]),this.size=++Ye.size,this;Ye=this.__data__=new ct(Ht)}return Ye.set(Ce,Le),this.size=Ye.size,this}it.prototype.clear=nt,it.prototype.delete=gt,it.prototype.get=Vt,it.prototype.has=Me,it.prototype.set=Qe;function $e(Ce,Le){var Ye=_r(Ce),Ht=!Ye&&rr(Ce),Bn=!Ye&&!Ht&&Ao(Ce),or=!Ye&&!Ht&&!Bn&&Eb(Ce),Jn=Ye||Ht||Bn||or,On=Jn?J(Ce.length,String):[],vr=On.length;for(var $i in Ce)Jn&&($i=="length"||Bn&&($i=="offset"||$i=="parent")||or&&($i=="buffer"||$i=="byteLength"||$i=="byteOffset")||qs($i,vr))||On.push($i);return On}function le(Ce,Le,Ye){(Ye!==void 0&&!Kt(Ce[Le],Ye)||Ye===void 0&&!(Le in Ce))&&Ot(Ce,Le,Ye)}function Ae(Ce,Le,Ye){var Ht=Ce[Le];(!(Ie.call(Ce,Le)&&Kt(Ht,Ye))||Ye===void 0&&!(Le in Ce))&&Ot(Ce,Le,Ye)}function Xe(Ce,Le){for(var Ye=Ce.length;Ye--;)if(Kt(Ce[Ye][0],Le))return Ye;return-1}function Ot(Ce,Le,Ye){Le=="__proto__"&&ye?ye(Ce,Le,{configurable:!0,enumerable:!0,value:Ye,writable:!0}):Ce[Le]=Ye}var qt=at();function Pt(Ce){return Ce==null?Ce===void 0?k:y:Oe&&Oe in Object(Ce)?fn(Ce):hp(Ce)}function Fn(Ce){return If(Ce)&&Pt(Ce)==a}function ft(Ce){if(!ua(Ce)||qo(Ce))return!1;var Le=Gr(Ce)?ce:B;return Le.test(Pn(Ce))}function Tt(Ce){return If(Ce)&&Ws(Ce.length)&&!!P[Pt(Ce)]}function ke(Ce){if(!ua(Ce))return Ks(Ce);var Le=vs(Ce),Ye=[];for(var Ht in Ce)Ht=="constructor"&&(Le||!Ie.call(Ce,Ht))||Ye.push(Ht);return Ye}function Ve(Ce,Le,Ye,Ht,Bn){Ce!==Le&&qt(Le,function(or,Jn){if(Bn||(Bn=new it),ua(or))dt(Ce,Le,Jn,Ye,Ve,Ht,Bn);else{var On=Ht?Ht(et(Ce,Jn),or,Jn+"",Ce,Le,Bn):void 0;On===void 0&&(On=or),le(Ce,Jn,On)}},mp)}function dt(Ce,Le,Ye,Ht,Bn,or,Jn){var On=et(Ce,Ye),vr=et(Le,Ye),$i=Jn.get(vr);if($i){le(Ce,Ye,$i);return}var rs=or?or(On,vr,Ye+"",Ce,Le,Jn):void 0,_f=rs===void 0;if(_f){var Mb=_r(vr),pp=!Mb&&Ao(vr),MC=!Mb&&!pp&&Eb(vr);rs=vr,Mb||pp||MC?_r(On)?rs=On:mo(On)?rs=Rt(On):pp?(_f=!1,rs=wn(vr)):MC?(_f=!1,rs=ot(vr)):rs=[]:TC(vr)||rr(vr)?(rs=On,rr(On)?rs=lD(On):(!ua(On)||Gr(On))&&(rs=qr(vr))):_f=!1}_f&&(Jn.set(vr,rs),Bn(rs,vr,Ht,or,Jn),Jn.delete(vr)),le(Ce,Ye,rs)}function _t(Ce,Le){return hn(Ku(Ce,Le,EC),Ce+"")}var Xt=ye?function(Ce,Le){return ye(Ce,"toString",{configurable:!0,enumerable:!1,value:cD(Le),writable:!0})}:EC;function wn(Ce,Le){return Ce.slice()}function cn(Ce){var Le=new Ce.constructor(Ce.byteLength);return new ve(Le).set(new ve(Ce)),Le}function ot(Ce,Le){var Ye=cn(Ce.buffer);return new Ce.constructor(Ye,Ce.byteOffset,Ce.length)}function Rt(Ce,Le){var Ye=-1,Ht=Ce.length;for(Le||(Le=Array(Ht));++Ye<Ht;)Le[Ye]=Ce[Ye];return Le}function Pe(Ce,Le,Ye,Ht){var Bn=!Ye;Ye||(Ye={});for(var or=-1,Jn=Le.length;++or<Jn;){var On=Le[or],vr=void 0;vr===void 0&&(vr=Ce[On]),Bn?Ot(Ye,On,vr):Ae(Ye,On,vr)}return Ye}function Ge(Ce){return _t(function(Le,Ye){var Ht=-1,Bn=Ye.length,or=Bn>1?Ye[Bn-1]:void 0,Jn=Bn>2?Ye[2]:void 0;for(or=Ce.length>3&&typeof or=="function"?(Bn--,or):void 0,Jn&&Us(Ye[0],Ye[1],Jn)&&(or=Bn<3?void 0:or,Bn=1),Le=Object(Le);++Ht<Bn;){var On=Ye[Ht];On&&Ce(Le,On,Ht,or)}return Le})}function at(Ce){return function(Le,Ye,Ht){for(var Bn=-1,or=Object(Le),Jn=Ht(Le),On=Jn.length;On--;){var vr=Jn[++Bn];if(Ye(or[vr],vr,or)===!1)break}return Le}}function kt(Ce,Le){var Ye=Ce.__data__;return Va(Le)?Ye[typeof Le=="string"?"string":"hash"]:Ye.map}function Wt(Ce,Le){var Ye=te(Ce,Le);return ft(Ye)?Ye:void 0}function fn(Ce){var Le=Ie.call(Ce,Oe),Ye=Ce[Oe];try{Ce[Oe]=void 0;var Ht=!0}catch{}var Bn=ge.call(Ce);return Ht&&(Le?Ce[Oe]=Ye:delete Ce[Oe]),Bn}function qr(Ce){return typeof Ce.constructor=="function"&&!vs(Ce)?we(_e(Ce)):{}}function qs(Ce,Le){var Ye=typeof Ce;return Le=Le??i,!!Le&&(Ye=="number"||Ye!="symbol"&&$.test(Ce))&&Ce>-1&&Ce%1==0&&Ce<Le}function Us(Ce,Le,Ye){if(!ua(Ye))return!1;var Ht=typeof Le;return(Ht=="number"?vo(Ye)&&qs(Le,Ye.length):Ht=="string"&&Le in Ye)?Kt(Ye[Le],Ce):!1}function Va(Ce){var Le=typeof Ce;return Le=="string"||Le=="number"||Le=="symbol"||Le=="boolean"?Ce!=="__proto__":Ce===null}function qo(Ce){return!!be&&be in Ce}function vs(Ce){var Le=Ce&&Ce.constructor,Ye=typeof Le=="function"&&Le.prototype||fe;return Ce===Ye}function Ks(Ce){var Le=[];if(Ce!=null)for(var Ye in Object(Ce))Le.push(Ye);return Le}function hp(Ce){return ge.call(Ce)}function Ku(Ce,Le,Ye){return Le=he(Le===void 0?Ce.length-1:Le,0),function(){for(var Ht=arguments,Bn=-1,or=he(Ht.length-Le,0),Jn=Array(or);++Bn<or;)Jn[Bn]=Ht[Le+Bn];Bn=-1;for(var On=Array(Le+1);++Bn<Le;)On[Bn]=Ht[Bn];return On[Le]=Ye(Jn),X(Ce,this,On)}}function et(Ce,Le){if(!(Le==="constructor"&&typeof Ce[Le]=="function")&&Le!="__proto__")return Ce[Le]}var hn=Gt(Xt);function Gt(Ce){var Le=0,Ye=0;return function(){var Ht=ue(),Bn=s-(Ht-Ye);if(Ye=Ht,Bn>0){if(++Le>=o)return arguments[0]}else Le=0;return Ce.apply(void 0,arguments)}}function Pn(Ce){if(Ce!=null){try{return xe.call(Ce)}catch{}try{return Ce+""}catch{}}return""}function Kt(Ce,Le){return Ce===Le||Ce!==Ce&&Le!==Le}var rr=Fn(function(){return arguments}())?Fn:function(Ce){return If(Ce)&&Ie.call(Ce,"callee")&&!Ue.call(Ce,"callee")},_r=Array.isArray;function vo(Ce){return Ce!=null&&Ws(Ce.length)&&!Gr(Ce)}function mo(Ce){return If(Ce)&&vo(Ce)}var Ao=Be||uD;function Gr(Ce){if(!ua(Ce))return!1;var Le=Pt(Ce);return Le==p||Le==g||Le==u||Le==w}function Ws(Ce){return typeof Ce=="number"&&Ce>-1&&Ce%1==0&&Ce<=i}function ua(Ce){var Le=typeof Ce;return Ce!=null&&(Le=="object"||Le=="function")}function If(Ce){return Ce!=null&&typeof Ce=="object"}function TC(Ce){if(!If(Ce)||Pt(Ce)!=C)return!1;var Le=_e(Ce);if(Le===null)return!0;var Ye=Ie.call(Le,"constructor")&&Le.constructor;return typeof Ye=="function"&&Ye instanceof Ye&&xe.call(Ye)==ee}var Eb=K?re(K):Tt;function lD(Ce){return Pe(Ce,mp(Ce))}function mp(Ce){return vo(Ce)?$e(Ce):ke(Ce)}var DC=Ge(function(Ce,Le,Ye){Ve(Ce,Le,Ye)});function cD(Ce){return function(){return Ce}}function EC(Ce){return Ce}function uD(){return!1}e.exports=DC})(TN,TN.exports);var ove=TN.exports;const sc=lt.getDefaultExportFromCjs(ove),BY=()=>{const e=v.useContext(fg.ThemeProviderContext);if(e===void 0)throw new Error("useTheme must be used within a ThemeProvider");return e},VY="__semaphorAuthoredFontFamily";var SY,NY;const sve=(NY=(SY=lt.DEFAULT_STYLE.default.chart)==null?void 0:SY.font)==null?void 0:NY.family,ive=new Set([sve,"Open Sans, Arial, sans-serif",'"Open Sans", Arial, sans-serif'].filter(Boolean));function ave(e,t){if(!e)return t?{family:t}:void 0;const{[VY]:n,...r}=e,o=lve(r.family,t,!!n);return{...r,...o?{family:o}:void 0}}function lve(e,t,n=!1){return n&&e||e&&!cve(e)?e:t||e}function cve(e){return ive.has(e.trim())}function uve(e,t){if(!t)return e;const n={...e,font:ba(e.font,t)},r=hve(e.plugins,t);r&&(n.plugins=r);const o=mve(e.scales,t);return o&&(n.scales=o),n}function dve(e,t){return!e||!t?e:e.map(n=>{if(!n||typeof n!="object")return n;const r=n,o=r.datalabels;return!o||typeof o!="object"?n:{...r,datalabels:{...o,font:ba(o.font,t)}}})}function fve(e,t){if(!e||typeof e!="object"||!t)return e;const n=e.datasets;return Array.isArray(n)?{...e,datasets:dve(n,t)}:e}function hve(e,t){var n;return e&&{...e,title:e.title?{...e.title,font:ba(e.title.font,t)}:e.title,subtitle:e.subtitle?{...e.subtitle,font:ba(e.subtitle.font,t)}:e.subtitle,legend:e.legend?{...e.legend,labels:e.legend.labels?{...e.legend.labels,font:ba(e.legend.labels.font,t)}:e.legend.labels}:e.legend,tooltip:e.tooltip?{...e.tooltip,titleFont:ba(e.tooltip.titleFont,t),bodyFont:ba(e.tooltip.bodyFont,t),footerFont:ba(e.tooltip.footerFont,t)}:e.tooltip,datalabels:e.datalabels?{...e.datalabels,font:ba((n=e.datalabels)==null?void 0:n.font,t)}:e.datalabels}}function mve(e,t){return e&&Object.entries(e).reduce((n,[r,o])=>{if(!o||typeof o!="object")return n[r]=o,n;const s=o;return n[r]={...s,ticks:s.ticks?{...s.ticks,font:ba(s.ticks.font,t)}:s.ticks,title:s.title?{...s.title,font:ba(s.title.font,t)}:s.title,pointLabels:s.pointLabels?{...s.pointLabels,font:ba(s.pointLabels.font,t)}:s.pointLabels},n},{})}function ba(e,t){return typeof e=="function"?e:{...t,...e&&typeof e=="object"?e:{}}}function pve(e,t){const n=en.cloneDeep(e??{}),r=gve(t);if(!r)return n;const o=sc(n,r);return yve(o,r),o}function gve(e){var h,p,g,x;const t=(h=e.scheme.components)==null?void 0:h.chart,n=Am.SEMAPHOR_DEFAULT_APPEARANCE_SPEC.schemes[e.mode],r=(p=n.components)==null?void 0:p.chart,o=(g=n.tokens)==null?void 0:g.typography,s={};bve(t==null?void 0:t.palette,r==null?void 0:r.palette)&&(s.dataset={backgroundColor:[...t.palette],borderColor:[...t.palette]});const i=(x=e.scheme.tokens)==null?void 0:x.typography,a=gp(i==null?void 0:i.fontFamily,o==null?void 0:o.fontFamily),c=gp(i==null?void 0:i.baseFontSize,o==null?void 0:o.baseFontSize);if(a||c!==void 0){const b={...a?{family:a}:void 0,...c!==void 0?{size:c}:void 0};a&&(b[VY]=!0),s.font=b}const u=gp(t==null?void 0:t.gridColor,r==null?void 0:r.gridColor),d=gp(t==null?void 0:t.axisColor,r==null?void 0:r.axisColor)??gp(t==null?void 0:t.foreground,r==null?void 0:r.foreground);(u||d)&&(s.options={scales:{x:fD({gridColor:u,axisColor:d}),y:fD({gridColor:u,axisColor:d}),y2:fD({gridColor:u,axisColor:d}),r:xve({gridColor:u,axisColor:d})}});const f=gp(t==null?void 0:t.foreground,r==null?void 0:r.foreground);return f&&(s.options=sc(s.options??{},{plugins:{legend:{labels:{color:f}}}})),Object.keys(s).length>0?{chart:s}:void 0}function fD({gridColor:e,axisColor:t}){return{...e?{grid:{color:e}}:void 0,...t?{ticks:{color:t},title:{color:t}}:void 0}}function xve({gridColor:e,axisColor:t}){return{...e?{grid:{color:e},angleLines:{color:e}}:void 0,...t?{ticks:{color:t},title:{color:t},pointLabels:{color:t}}:void 0}}function bve(e,t){return e!=null&&e.length?!(t!=null&&t.length)||e.length!==t.length?!0:e.some((n,r)=>n!==t[r]):!1}function gp(e,t){return e!==void 0&&e!==t?e:void 0}function yve(e,t){var r;const n=(r=t.chart)==null?void 0:r.dataset;n&&(e.chart=e.chart??{},e.chart.dataset=e.chart.dataset??{},Array.isArray(n.backgroundColor)&&(e.chart.dataset.backgroundColor=[...n.backgroundColor]),Array.isArray(n.borderColor)&&(e.chart.dataset.borderColor=[...n.borderColor]))}var Fm=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},vve={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},$l,Ch,jY,wve=(jY=class{constructor(){zt(this,$l,vve);zt(this,Ch,!1)}setTimeoutProvider(e){process.env.NODE_ENV!=="production"&&je(this,Ch)&&e!==je(this,$l)&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:je(this,$l),provider:e}),jt(this,$l,e),process.env.NODE_ENV!=="production"&&jt(this,Ch,!1)}setTimeout(e,t){return process.env.NODE_ENV!=="production"&&jt(this,Ch,!0),je(this,$l).setTimeout(e,t)}clearTimeout(e){je(this,$l).clearTimeout(e)}setInterval(e,t){return process.env.NODE_ENV!=="production"&&jt(this,Ch,!0),je(this,$l).setInterval(e,t)}clearInterval(e){je(this,$l).clearInterval(e)}},$l=new WeakMap,Ch=new WeakMap,jY),lh=new wve;function Cve(e){setTimeout(e,0)}var Xh=typeof window>"u"||"Deno"in globalThis;function Is(){}function Sve(e,t){return typeof e=="function"?e(t):e}function bR(e){return typeof e=="number"&&e>=0&&e!==1/0}function HY(e,t){return Math.max(e+(t||0)-Date.now(),0)}function _d(e,t){return typeof e=="function"?e(t):e}function ya(e,t){return typeof e=="function"?e(t):e}function GB(e,t){const{type:n="all",exact:r,fetchStatus:o,predicate:s,queryKey:i,stale:a}=e;if(i){if(r){if(t.queryHash!==zO(i,t.options))return!1}else if(!Mv(t.queryKey,i))return!1}if(n!=="all"){const c=t.isActive();if(n==="active"&&!c||n==="inactive"&&c)return!1}return!(typeof a=="boolean"&&t.isStale()!==a||o&&o!==t.state.fetchStatus||s&&!s(t))}function YB(e,t){const{exact:n,status:r,predicate:o,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(n){if(pu(t.options.mutationKey)!==pu(s))return!1}else if(!Mv(t.options.mutationKey,s))return!1}return!(r&&t.state.status!==r||o&&!o(t))}function zO(e,t){return((t==null?void 0:t.queryKeyHashFn)||pu)(e)}function pu(e){return JSON.stringify(e,(t,n)=>yR(n)?Object.keys(n).sort().reduce((r,o)=>(r[o]=n[o],r),{}):n)}function Mv(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>Mv(e[n],t[n])):!1}var Nve=Object.prototype.hasOwnProperty;function DN(e,t){if(e===t)return e;const n=ZB(e)&&ZB(t);if(!n&&!(yR(e)&&yR(t)))return t;const o=(n?e:Object.keys(e)).length,s=n?t:Object.keys(t),i=s.length,a=n?new Array(i):{};let c=0;for(let u=0;u<i;u++){const d=n?u:s[u],f=e[d],h=t[d];if(f===h){a[d]=f,(n?u<o:Nve.call(e,d))&&c++;continue}if(f===null||h===null||typeof f!="object"||typeof h!="object"){a[d]=h;continue}const p=DN(f,h);a[d]=p,p===f&&c++}return o===i&&c===o?e:a}function Rv(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function ZB(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function yR(e){if(!XB(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!XB(n)||!n.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function XB(e){return Object.prototype.toString.call(e)==="[object Object]"}function jve(e){return new Promise(t=>{lh.setTimeout(t,e)})}function vR(e,t,n){if(typeof n.structuralSharing=="function")return n.structuralSharing(e,t);if(n.structuralSharing!==!1){if(process.env.NODE_ENV!=="production")try{return DN(e,t)}catch(r){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${r}`),r}return DN(e,t)}return t}function kve(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function Ive(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var EN=Symbol();function qY(e,t){return process.env.NODE_ENV!=="production"&&e.queryFn===EN&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`),!e.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!e.queryFn||e.queryFn===EN?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function UY(e,t){return typeof e=="function"?e(...t):!!e}var Sh,od,Dg,kY,_ve=(kY=class extends Fm{constructor(){super();zt(this,Sh);zt(this,od);zt(this,Dg);jt(this,Dg,t=>{if(!Xh&&window.addEventListener){const n=()=>t();return window.addEventListener("visibilitychange",n,!1),()=>{window.removeEventListener("visibilitychange",n)}}})}onSubscribe(){je(this,od)||this.setEventListener(je(this,Dg))}onUnsubscribe(){var t;this.hasListeners()||((t=je(this,od))==null||t.call(this),jt(this,od,void 0))}setEventListener(t){var n;jt(this,Dg,t),(n=je(this,od))==null||n.call(this),jt(this,od,t(r=>{typeof r=="boolean"?this.setFocused(r):this.onFocus()}))}setFocused(t){je(this,Sh)!==t&&(jt(this,Sh,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(n=>{n(t)})}isFocused(){var t;return typeof je(this,Sh)=="boolean"?je(this,Sh):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},Sh=new WeakMap,od=new WeakMap,Dg=new WeakMap,kY),iI=new _ve;function wR(){let e,t;const n=new Promise((o,s)=>{e=o,t=s});n.status="pending",n.catch(()=>{});function r(o){Object.assign(n,o),delete n.resolve,delete n.reject}return n.resolve=o=>{r({status:"fulfilled",value:o}),e(o)},n.reject=o=>{r({status:"rejected",reason:o}),t(o)},n}var Tve=Cve;function Dve(){let e=[],t=0,n=a=>{a()},r=a=>{a()},o=Tve;const s=a=>{t?e.push(a):o(()=>{n(a)})},i=()=>{const a=e;e=[],a.length&&o(()=>{r(()=>{a.forEach(c=>{n(c)})})})};return{batch:a=>{let c;t++;try{c=a()}finally{t--,t||i()}return c},batchCalls:a=>(...c)=>{s(()=>{a(...c)})},schedule:s,setNotifyFunction:a=>{n=a},setBatchNotifyFunction:a=>{r=a},setScheduler:a=>{o=a}}}var Qr=Dve(),Eg,sd,Mg,IY,Eve=(IY=class extends Fm{constructor(){super();zt(this,Eg,!0);zt(this,sd);zt(this,Mg);jt(this,Mg,t=>{if(!Xh&&window.addEventListener){const n=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",n,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",r)}}})}onSubscribe(){je(this,sd)||this.setEventListener(je(this,Mg))}onUnsubscribe(){var t;this.hasListeners()||((t=je(this,sd))==null||t.call(this),jt(this,sd,void 0))}setEventListener(t){var n;jt(this,Mg,t),(n=je(this,sd))==null||n.call(this),jt(this,sd,t(this.setOnline.bind(this)))}setOnline(t){je(this,Eg)!==t&&(jt(this,Eg,t),this.listeners.forEach(r=>{r(t)}))}isOnline(){return je(this,Eg)}},Eg=new WeakMap,sd=new WeakMap,Mg=new WeakMap,IY),Av=new Eve;function Mve(e){return Math.min(1e3*2**e,3e4)}function KY(e){return(e??"online")==="online"?Av.isOnline():!0}var CR=class extends Error{constructor(e){super("CancelledError"),this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function WY(e){let t=!1,n=0,r;const o=wR(),s=()=>o.status!=="pending",i=x=>{var b;if(!s()){const y=new CR(x);h(y),(b=e.onCancel)==null||b.call(e,y)}},a=()=>{t=!0},c=()=>{t=!1},u=()=>iI.isFocused()&&(e.networkMode==="always"||Av.isOnline())&&e.canRun(),d=()=>KY(e.networkMode)&&e.canRun(),f=x=>{s()||(r==null||r(),o.resolve(x))},h=x=>{s()||(r==null||r(),o.reject(x))},p=()=>new Promise(x=>{var b;r=y=>{(s()||u())&&x(y)},(b=e.onPause)==null||b.call(e)}).then(()=>{var x;r=void 0,s()||(x=e.onContinue)==null||x.call(e)}),g=()=>{if(s())return;let x;const b=n===0?e.initialPromise:void 0;try{x=b??e.fn()}catch(y){x=Promise.reject(y)}Promise.resolve(x).then(f).catch(y=>{var j;if(s())return;const C=e.retry??(Xh?0:3),w=e.retryDelay??Mve,N=typeof w=="function"?w(n,y):w,S=C===!0||typeof C=="number"&&n<C||typeof C=="function"&&C(n,y);if(t||!S){h(y);return}n++,(j=e.onFail)==null||j.call(e,n,y),jve(N).then(()=>u()?void 0:p()).then(()=>{t?h(y):g()})})};return{promise:o,status:()=>o.status,cancel:i,continue:()=>(r==null||r(),o),cancelRetry:a,continueRetry:c,canStart:d,start:()=>(d()?g():p().then(g),o)}}var Nh,_Y,GY=(_Y=class{constructor(){zt(this,Nh)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),bR(this.gcTime)&&jt(this,Nh,lh.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Xh?1/0:5*60*1e3))}clearGcTimeout(){je(this,Nh)&&(lh.clearTimeout(je(this,Nh)),jt(this,Nh,void 0))}},Nh=new WeakMap,_Y),jh,Rg,ga,kh,Uo,U0,Ih,Ka,Tc,TY,Rve=(TY=class extends GY{constructor(t){super();zt(this,Ka);zt(this,jh);zt(this,Rg);zt(this,ga);zt(this,kh);zt(this,Uo);zt(this,U0);zt(this,Ih);jt(this,Ih,!1),jt(this,U0,t.defaultOptions),this.setOptions(t.options),this.observers=[],jt(this,kh,t.client),jt(this,ga,je(this,kh).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,jt(this,jh,JB(this.options)),this.state=t.state??je(this,jh),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=je(this,Uo))==null?void 0:t.promise}setOptions(t){if(this.options={...je(this,U0),...t},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const n=JB(this.options);n.data!==void 0&&(this.setState(QB(n.data,n.dataUpdatedAt)),jt(this,jh,n))}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&je(this,ga).remove(this)}setData(t,n){const r=vR(this.state.data,t,this.options);return rn(this,Ka,Tc).call(this,{data:r,type:"success",dataUpdatedAt:n==null?void 0:n.updatedAt,manual:n==null?void 0:n.manual}),r}setState(t,n){rn(this,Ka,Tc).call(this,{type:"setState",state:t,setStateOptions:n})}cancel(t){var r,o;const n=(r=je(this,Uo))==null?void 0:r.promise;return(o=je(this,Uo))==null||o.cancel(t),n?n.then(Is).catch(Is):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(je(this,jh))}isActive(){return this.observers.some(t=>ya(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===EN||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>_d(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!HY(this.state.dataUpdatedAt,t)}onFocus(){var n;const t=this.observers.find(r=>r.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(n=je(this,Uo))==null||n.continue()}onOnline(){var n;const t=this.observers.find(r=>r.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(n=je(this,Uo))==null||n.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),je(this,ga).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(n=>n!==t),this.observers.length||(je(this,Uo)&&(je(this,Ih)?je(this,Uo).cancel({revert:!0}):je(this,Uo).cancelRetry()),this.scheduleGc()),je(this,ga).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||rn(this,Ka,Tc).call(this,{type:"invalidate"})}async fetch(t,n){var c,u,d,f,h,p,g,x,b,y,C,w;if(this.state.fetchStatus!=="idle"&&((c=je(this,Uo))==null?void 0:c.status())!=="rejected"){if(this.state.data!==void 0&&(n!=null&&n.cancelRefetch))this.cancel({silent:!0});else if(je(this,Uo))return je(this,Uo).continueRetry(),je(this,Uo).promise}if(t&&this.setOptions(t),!this.options.queryFn){const N=this.observers.find(S=>S.options.queryFn);N&&this.setOptions(N.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const r=new AbortController,o=N=>{Object.defineProperty(N,"signal",{enumerable:!0,get:()=>(jt(this,Ih,!0),r.signal)})},s=()=>{const N=qY(this.options,n),j=(()=>{const k={client:je(this,kh),queryKey:this.queryKey,meta:this.meta};return o(k),k})();return jt(this,Ih,!1),this.options.persister?this.options.persister(N,j,this):N(j)},a=(()=>{const N={fetchOptions:n,options:this.options,queryKey:this.queryKey,client:je(this,kh),state:this.state,fetchFn:s};return o(N),N})();(u=this.options.behavior)==null||u.onFetch(a,this),jt(this,Rg,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((d=a.fetchOptions)==null?void 0:d.meta))&&rn(this,Ka,Tc).call(this,{type:"fetch",meta:(f=a.fetchOptions)==null?void 0:f.meta}),jt(this,Uo,WY({initialPromise:n==null?void 0:n.initialPromise,fn:a.fetchFn,onCancel:N=>{N instanceof CR&&N.revert&&this.setState({...je(this,Rg),fetchStatus:"idle"}),r.abort()},onFail:(N,S)=>{rn(this,Ka,Tc).call(this,{type:"failed",failureCount:N,error:S})},onPause:()=>{rn(this,Ka,Tc).call(this,{type:"pause"})},onContinue:()=>{rn(this,Ka,Tc).call(this,{type:"continue"})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0}));try{const N=await je(this,Uo).start();if(N===void 0)throw process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),new Error(`${this.queryHash} data is undefined`);return this.setData(N),(p=(h=je(this,ga).config).onSuccess)==null||p.call(h,N,this),(x=(g=je(this,ga).config).onSettled)==null||x.call(g,N,this.state.error,this),N}catch(N){if(N instanceof CR){if(N.silent)return je(this,Uo).promise;if(N.revert){if(this.state.data===void 0)throw N;return this.state.data}}throw rn(this,Ka,Tc).call(this,{type:"error",error:N}),(y=(b=je(this,ga).config).onError)==null||y.call(b,N,this),(w=(C=je(this,ga).config).onSettled)==null||w.call(C,this.state.data,N,this),N}finally{this.scheduleGc()}}},jh=new WeakMap,Rg=new WeakMap,ga=new WeakMap,kh=new WeakMap,Uo=new WeakMap,U0=new WeakMap,Ih=new WeakMap,Ka=new WeakSet,Tc=function(t){const n=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...YY(r.data,this.options),fetchMeta:t.meta??null};case"success":const o={...r,...QB(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return jt(this,Rg,t.manual?o:void 0),o;case"error":const s=t.error;return{...r,error:s,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=n(this.state),Qr.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),je(this,ga).notify({query:this,type:"updated",action:t})})},TY);function YY(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:KY(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function QB(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function JB(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var Ci,Vn,K0,ei,_h,Ag,Lc,id,W0,Fg,Pg,Th,Dh,ad,Og,ur,wy,SR,NR,jR,kR,IR,_R,TR,ZY,DY,aI=(DY=class extends Fm{constructor(t,n){super();zt(this,ur);zt(this,Ci);zt(this,Vn);zt(this,K0);zt(this,ei);zt(this,_h);zt(this,Ag);zt(this,Lc);zt(this,id);zt(this,W0);zt(this,Fg);zt(this,Pg);zt(this,Th);zt(this,Dh);zt(this,ad);zt(this,Og,new Set);this.options=n,jt(this,Ci,t),jt(this,id,null),jt(this,Lc,wR()),this.bindMethods(),this.setOptions(n)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(je(this,Vn).addObserver(this),eV(je(this,Vn),this.options)?rn(this,ur,wy).call(this):this.updateResult(),rn(this,ur,kR).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return DR(je(this,Vn),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return DR(je(this,Vn),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,rn(this,ur,IR).call(this),rn(this,ur,_R).call(this),je(this,Vn).removeObserver(this)}setOptions(t){const n=this.options,r=je(this,Vn);if(this.options=je(this,Ci).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof ya(this.options.enabled,je(this,Vn))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");rn(this,ur,TR).call(this),je(this,Vn).setOptions(this.options),n._defaulted&&!Rv(this.options,n)&&je(this,Ci).getQueryCache().notify({type:"observerOptionsUpdated",query:je(this,Vn),observer:this});const o=this.hasListeners();o&&tV(je(this,Vn),r,this.options,n)&&rn(this,ur,wy).call(this),this.updateResult(),o&&(je(this,Vn)!==r||ya(this.options.enabled,je(this,Vn))!==ya(n.enabled,je(this,Vn))||_d(this.options.staleTime,je(this,Vn))!==_d(n.staleTime,je(this,Vn)))&&rn(this,ur,SR).call(this);const s=rn(this,ur,NR).call(this);o&&(je(this,Vn)!==r||ya(this.options.enabled,je(this,Vn))!==ya(n.enabled,je(this,Vn))||s!==je(this,ad))&&rn(this,ur,jR).call(this,s)}getOptimisticResult(t){const n=je(this,Ci).getQueryCache().build(je(this,Ci),t),r=this.createResult(n,t);return Fve(this,r)&&(jt(this,ei,r),jt(this,Ag,this.options),jt(this,_h,je(this,Vn).state)),r}getCurrentResult(){return je(this,ei)}trackResult(t,n){return new Proxy(t,{get:(r,o)=>(this.trackProp(o),n==null||n(o),o==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&je(this,Lc).status==="pending"&&je(this,Lc).reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,o))})}trackProp(t){je(this,Og).add(t)}getCurrentQuery(){return je(this,Vn)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const n=je(this,Ci).defaultQueryOptions(t),r=je(this,Ci).getQueryCache().build(je(this,Ci),n);return r.fetch().then(()=>this.createResult(r,n))}fetch(t){return rn(this,ur,wy).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),je(this,ei)))}createResult(t,n){var T;const r=je(this,Vn),o=this.options,s=je(this,ei),i=je(this,_h),a=je(this,Ag),u=t!==r?t.state:je(this,K0),{state:d}=t;let f={...d},h=!1,p;if(n._optimisticResults){const I=this.hasListeners(),D=!I&&eV(t,n),E=I&&tV(t,r,n,o);(D||E)&&(f={...f,...YY(d.data,t.options)}),n._optimisticResults==="isRestoring"&&(f.fetchStatus="idle")}let{error:g,errorUpdatedAt:x,status:b}=f;p=f.data;let y=!1;if(n.placeholderData!==void 0&&p===void 0&&b==="pending"){let I;s!=null&&s.isPlaceholderData&&n.placeholderData===(a==null?void 0:a.placeholderData)?(I=s.data,y=!0):I=typeof n.placeholderData=="function"?n.placeholderData((T=je(this,Pg))==null?void 0:T.state.data,je(this,Pg)):n.placeholderData,I!==void 0&&(b="success",p=vR(s==null?void 0:s.data,I,n),h=!0)}if(n.select&&p!==void 0&&!y)if(s&&p===(i==null?void 0:i.data)&&n.select===je(this,W0))p=je(this,Fg);else try{jt(this,W0,n.select),p=n.select(p),p=vR(s==null?void 0:s.data,p,n),jt(this,Fg,p),jt(this,id,null)}catch(I){jt(this,id,I)}je(this,id)&&(g=je(this,id),p=je(this,Fg),x=Date.now(),b="error");const C=f.fetchStatus==="fetching",w=b==="pending",N=b==="error",S=w&&C,j=p!==void 0,_={status:b,fetchStatus:f.fetchStatus,isPending:w,isSuccess:b==="success",isError:N,isInitialLoading:S,isLoading:S,data:p,dataUpdatedAt:f.dataUpdatedAt,error:g,errorUpdatedAt:x,failureCount:f.fetchFailureCount,failureReason:f.fetchFailureReason,errorUpdateCount:f.errorUpdateCount,isFetched:f.dataUpdateCount>0||f.errorUpdateCount>0,isFetchedAfterMount:f.dataUpdateCount>u.dataUpdateCount||f.errorUpdateCount>u.errorUpdateCount,isFetching:C,isRefetching:C&&!w,isLoadingError:N&&!j,isPaused:f.fetchStatus==="paused",isPlaceholderData:h,isRefetchError:N&&j,isStale:BO(t,n),refetch:this.refetch,promise:je(this,Lc),isEnabled:ya(n.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const I=R=>{_.status==="error"?R.reject(_.error):_.data!==void 0&&R.resolve(_.data)},D=()=>{const R=jt(this,Lc,_.promise=wR());I(R)},E=je(this,Lc);switch(E.status){case"pending":t.queryHash===r.queryHash&&I(E);break;case"fulfilled":(_.status==="error"||_.data!==E.value)&&D();break;case"rejected":(_.status!=="error"||_.error!==E.reason)&&D();break}}return _}updateResult(){const t=je(this,ei),n=this.createResult(je(this,Vn),this.options);if(jt(this,_h,je(this,Vn).state),jt(this,Ag,this.options),je(this,_h).data!==void 0&&jt(this,Pg,je(this,Vn)),Rv(n,t))return;jt(this,ei,n);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:o}=this.options,s=typeof o=="function"?o():o;if(s==="all"||!s&&!je(this,Og).size)return!0;const i=new Set(s??je(this,Og));return this.options.throwOnError&&i.add("error"),Object.keys(je(this,ei)).some(a=>{const c=a;return je(this,ei)[c]!==t[c]&&i.has(c)})};rn(this,ur,ZY).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&rn(this,ur,kR).call(this)}},Ci=new WeakMap,Vn=new WeakMap,K0=new WeakMap,ei=new WeakMap,_h=new WeakMap,Ag=new WeakMap,Lc=new WeakMap,id=new WeakMap,W0=new WeakMap,Fg=new WeakMap,Pg=new WeakMap,Th=new WeakMap,Dh=new WeakMap,ad=new WeakMap,Og=new WeakMap,ur=new WeakSet,wy=function(t){rn(this,ur,TR).call(this);let n=je(this,Vn).fetch(this.options,t);return t!=null&&t.throwOnError||(n=n.catch(Is)),n},SR=function(){rn(this,ur,IR).call(this);const t=_d(this.options.staleTime,je(this,Vn));if(Xh||je(this,ei).isStale||!bR(t))return;const r=HY(je(this,ei).dataUpdatedAt,t)+1;jt(this,Th,lh.setTimeout(()=>{je(this,ei).isStale||this.updateResult()},r))},NR=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(je(this,Vn)):this.options.refetchInterval)??!1},jR=function(t){rn(this,ur,_R).call(this),jt(this,ad,t),!(Xh||ya(this.options.enabled,je(this,Vn))===!1||!bR(je(this,ad))||je(this,ad)===0)&&jt(this,Dh,lh.setInterval(()=>{(this.options.refetchIntervalInBackground||iI.isFocused())&&rn(this,ur,wy).call(this)},je(this,ad)))},kR=function(){rn(this,ur,SR).call(this),rn(this,ur,jR).call(this,rn(this,ur,NR).call(this))},IR=function(){je(this,Th)&&(lh.clearTimeout(je(this,Th)),jt(this,Th,void 0))},_R=function(){je(this,Dh)&&(lh.clearInterval(je(this,Dh)),jt(this,Dh,void 0))},TR=function(){const t=je(this,Ci).getQueryCache().build(je(this,Ci),this.options);if(t===je(this,Vn))return;const n=je(this,Vn);jt(this,Vn,t),jt(this,K0,t.state),this.hasListeners()&&(n==null||n.removeObserver(this),t.addObserver(this))},ZY=function(t){Qr.batch(()=>{t.listeners&&this.listeners.forEach(n=>{n(je(this,ei))}),je(this,Ci).getQueryCache().notify({query:je(this,Vn),type:"observerResultsUpdated"})})},DY);function Ave(e,t){return ya(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function eV(e,t){return Ave(e,t)||e.state.data!==void 0&&DR(e,t,t.refetchOnMount)}function DR(e,t,n){if(ya(t.enabled,e)!==!1&&_d(t.staleTime,e)!=="static"){const r=typeof n=="function"?n(e):n;return r==="always"||r!==!1&&BO(e,t)}return!1}function tV(e,t,n,r){return(e!==t||ya(r.enabled,e)===!1)&&(!n.suspense||e.state.status!=="error")&&BO(e,n)}function BO(e,t){return ya(t.enabled,e)!==!1&&e.isStaleByTime(_d(t.staleTime,e))}function Fve(e,t){return!Rv(e.getCurrentResult(),t)}function MN(e){return{onFetch:(t,n)=>{var d,f,h,p,g;const r=t.options,o=(h=(f=(d=t.fetchOptions)==null?void 0:d.meta)==null?void 0:f.fetchMore)==null?void 0:h.direction,s=((p=t.state.data)==null?void 0:p.pages)||[],i=((g=t.state.data)==null?void 0:g.pageParams)||[];let a={pages:[],pageParams:[]},c=0;const u=async()=>{let x=!1;const b=w=>{Object.defineProperty(w,"signal",{enumerable:!0,get:()=>(t.signal.aborted?x=!0:t.signal.addEventListener("abort",()=>{x=!0}),t.signal)})},y=qY(t.options,t.fetchOptions),C=async(w,N,S)=>{if(x)return Promise.reject();if(N==null&&w.pages.length)return Promise.resolve(w);const k=(()=>{const D={client:t.client,queryKey:t.queryKey,pageParam:N,direction:S?"backward":"forward",meta:t.options.meta};return b(D),D})(),_=await y(k),{maxPages:T}=t.options,I=S?Ive:kve;return{pages:I(w.pages,_,T),pageParams:I(w.pageParams,N,T)}};if(o&&s.length){const w=o==="backward",N=w?XY:ER,S={pages:s,pageParams:i},j=N(r,S);a=await C(S,j,w)}else{const w=e??s.length;do{const N=c===0?i[0]??r.initialPageParam:ER(r,a);if(c>0&&N==null)break;a=await C(a,N),c++}while(c<w)}return a};t.options.persister?t.fetchFn=()=>{var x,b;return(b=(x=t.options).persister)==null?void 0:b.call(x,u,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n)}:t.fetchFn=u}}}function ER(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function XY(e,{pages:t,pageParams:n}){var r;return t.length>0?(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,n[0],n):void 0}function Pve(e,t){return t?ER(e,t)!=null:!1}function Ove(e,t){return!t||!e.getPreviousPageParam?!1:XY(e,t)!=null}var Lve=class extends aI{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:MN()})}getOptimisticResult(e){return e.behavior=MN(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){var g,x;const{state:n}=e,r=super.createResult(e,t),{isFetching:o,isRefetching:s,isError:i,isRefetchError:a}=r,c=(x=(g=n.fetchMeta)==null?void 0:g.fetchMore)==null?void 0:x.direction,u=i&&c==="forward",d=o&&c==="forward",f=i&&c==="backward",h=o&&c==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Pve(t,n.data),hasPreviousPage:Ove(t,n.data),isFetchNextPageError:u,isFetchingNextPage:d,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:a&&!u&&!f,isRefetching:s&&!d&&!h}}},G0,zl,ti,Eh,Bl,Qu,EY,$ve=(EY=class extends GY{constructor(t){super();zt(this,Bl);zt(this,G0);zt(this,zl);zt(this,ti);zt(this,Eh);jt(this,G0,t.client),this.mutationId=t.mutationId,jt(this,ti,t.mutationCache),jt(this,zl,[]),this.state=t.state||QY(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){je(this,zl).includes(t)||(je(this,zl).push(t),this.clearGcTimeout(),je(this,ti).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){jt(this,zl,je(this,zl).filter(n=>n!==t)),this.scheduleGc(),je(this,ti).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){je(this,zl).length||(this.state.status==="pending"?this.scheduleGc():je(this,ti).remove(this))}continue(){var t;return((t=je(this,Eh))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var i,a,c,u,d,f,h,p,g,x,b,y,C,w,N,S,j,k,_,T;const n=()=>{rn(this,Bl,Qu).call(this,{type:"continue"})},r={client:je(this,G0),meta:this.options.meta,mutationKey:this.options.mutationKey};jt(this,Eh,WY({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(I,D)=>{rn(this,Bl,Qu).call(this,{type:"failed",failureCount:I,error:D})},onPause:()=>{rn(this,Bl,Qu).call(this,{type:"pause"})},onContinue:n,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>je(this,ti).canRun(this)}));const o=this.state.status==="pending",s=!je(this,Eh).canStart();try{if(o)n();else{rn(this,Bl,Qu).call(this,{type:"pending",variables:t,isPaused:s}),await((a=(i=je(this,ti).config).onMutate)==null?void 0:a.call(i,t,this,r));const D=await((u=(c=this.options).onMutate)==null?void 0:u.call(c,t,r));D!==this.state.context&&rn(this,Bl,Qu).call(this,{type:"pending",context:D,variables:t,isPaused:s})}const I=await je(this,Eh).start();return await((f=(d=je(this,ti).config).onSuccess)==null?void 0:f.call(d,I,t,this.state.context,this,r)),await((p=(h=this.options).onSuccess)==null?void 0:p.call(h,I,t,this.state.context,r)),await((x=(g=je(this,ti).config).onSettled)==null?void 0:x.call(g,I,null,this.state.variables,this.state.context,this,r)),await((y=(b=this.options).onSettled)==null?void 0:y.call(b,I,null,t,this.state.context,r)),rn(this,Bl,Qu).call(this,{type:"success",data:I}),I}catch(I){try{throw await((w=(C=je(this,ti).config).onError)==null?void 0:w.call(C,I,t,this.state.context,this,r)),await((S=(N=this.options).onError)==null?void 0:S.call(N,I,t,this.state.context,r)),await((k=(j=je(this,ti).config).onSettled)==null?void 0:k.call(j,void 0,I,this.state.variables,this.state.context,this,r)),await((T=(_=this.options).onSettled)==null?void 0:T.call(_,void 0,I,t,this.state.context,r)),I}finally{rn(this,Bl,Qu).call(this,{type:"error",error:I})}}finally{je(this,ti).runNext(this)}}},G0=new WeakMap,zl=new WeakMap,ti=new WeakMap,Eh=new WeakMap,Bl=new WeakSet,Qu=function(t){const n=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=n(this.state),Qr.batch(()=>{je(this,zl).forEach(r=>{r.onMutationUpdate(t)}),je(this,ti).notify({mutation:this,type:"updated",action:t})})},EY);function QY(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var $c,Wa,Y0,MY,zve=(MY=class extends Fm{constructor(t={}){super();zt(this,$c);zt(this,Wa);zt(this,Y0);this.config=t,jt(this,$c,new Set),jt(this,Wa,new Map),jt(this,Y0,0)}build(t,n,r){const o=new $ve({client:t,mutationCache:this,mutationId:++RC(this,Y0)._,options:t.defaultMutationOptions(n),state:r});return this.add(o),o}add(t){je(this,$c).add(t);const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n);r?r.push(t):je(this,Wa).set(n,[t])}this.notify({type:"added",mutation:t})}remove(t){if(je(this,$c).delete(t)){const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n);if(r)if(r.length>1){const o=r.indexOf(t);o!==-1&&r.splice(o,1)}else r[0]===t&&je(this,Wa).delete(n)}}this.notify({type:"removed",mutation:t})}canRun(t){const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n),o=r==null?void 0:r.find(s=>s.state.status==="pending");return!o||o===t}else return!0}runNext(t){var r;const n=AC(t);if(typeof n=="string"){const o=(r=je(this,Wa).get(n))==null?void 0:r.find(s=>s!==t&&s.state.isPaused);return(o==null?void 0:o.continue())??Promise.resolve()}else return Promise.resolve()}clear(){Qr.batch(()=>{je(this,$c).forEach(t=>{this.notify({type:"removed",mutation:t})}),je(this,$c).clear(),je(this,Wa).clear()})}getAll(){return Array.from(je(this,$c))}find(t){const n={exact:!0,...t};return this.getAll().find(r=>YB(n,r))}findAll(t={}){return this.getAll().filter(n=>YB(t,n))}notify(t){Qr.batch(()=>{this.listeners.forEach(n=>{n(t)})})}resumePausedMutations(){const t=this.getAll().filter(n=>n.state.isPaused);return Qr.batch(()=>Promise.all(t.map(n=>n.continue().catch(Is))))}},$c=new WeakMap,Wa=new WeakMap,Y0=new WeakMap,MY);function AC(e){var t;return(t=e.options.scope)==null?void 0:t.id}var zc,ld,Si,Bc,hu,R1,MR,RY,Bve=(RY=class extends Fm{constructor(n,r){super();zt(this,hu);zt(this,zc);zt(this,ld);zt(this,Si);zt(this,Bc);jt(this,zc,n),this.setOptions(r),this.bindMethods(),rn(this,hu,R1).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(n){var o;const r=this.options;this.options=je(this,zc).defaultMutationOptions(n),Rv(this.options,r)||je(this,zc).getMutationCache().notify({type:"observerOptionsUpdated",mutation:je(this,Si),observer:this}),r!=null&&r.mutationKey&&this.options.mutationKey&&pu(r.mutationKey)!==pu(this.options.mutationKey)?this.reset():((o=je(this,Si))==null?void 0:o.state.status)==="pending"&&je(this,Si).setOptions(this.options)}onUnsubscribe(){var n;this.hasListeners()||(n=je(this,Si))==null||n.removeObserver(this)}onMutationUpdate(n){rn(this,hu,R1).call(this),rn(this,hu,MR).call(this,n)}getCurrentResult(){return je(this,ld)}reset(){var n;(n=je(this,Si))==null||n.removeObserver(this),jt(this,Si,void 0),rn(this,hu,R1).call(this),rn(this,hu,MR).call(this)}mutate(n,r){var o;return jt(this,Bc,r),(o=je(this,Si))==null||o.removeObserver(this),jt(this,Si,je(this,zc).getMutationCache().build(je(this,zc),this.options)),je(this,Si).addObserver(this),je(this,Si).execute(n)}},zc=new WeakMap,ld=new WeakMap,Si=new WeakMap,Bc=new WeakMap,hu=new WeakSet,R1=function(){var r;const n=((r=je(this,Si))==null?void 0:r.state)??QY();jt(this,ld,{...n,isPending:n.status==="pending",isSuccess:n.status==="success",isError:n.status==="error",isIdle:n.status==="idle",mutate:this.mutate,reset:this.reset})},MR=function(n){Qr.batch(()=>{var r,o,s,i,a,c,u,d;if(je(this,Bc)&&this.hasListeners()){const f=je(this,ld).variables,h=je(this,ld).context,p={client:je(this,zc),meta:this.options.meta,mutationKey:this.options.mutationKey};(n==null?void 0:n.type)==="success"?((o=(r=je(this,Bc)).onSuccess)==null||o.call(r,n.data,f,h,p),(i=(s=je(this,Bc)).onSettled)==null||i.call(s,n.data,null,f,h,p)):(n==null?void 0:n.type)==="error"&&((c=(a=je(this,Bc)).onError)==null||c.call(a,n.error,f,h,p),(d=(u=je(this,Bc)).onSettled)==null||d.call(u,void 0,n.error,f,h,p))}this.listeners.forEach(f=>{f(je(this,ld))})})},RY);function nV(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function Vve(e,t,n){const r=e.slice(0);return r[t]=n,r}var Mh,qi,Lg,$g,xa,cd,Z0,X0,Q0,ys,RR,AR,FR,PR,OR,AY,Hve=(AY=class extends Fm{constructor(t,n,r){super();zt(this,ys);zt(this,Mh);zt(this,qi);zt(this,Lg);zt(this,$g);zt(this,xa);zt(this,cd);zt(this,Z0);zt(this,X0);zt(this,Q0,[]);jt(this,Mh,t),jt(this,$g,r),jt(this,Lg,[]),jt(this,xa,[]),jt(this,qi,[]),this.setQueries(n)}onSubscribe(){this.listeners.size===1&&je(this,xa).forEach(t=>{t.subscribe(n=>{rn(this,ys,PR).call(this,t,n)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,je(this,xa).forEach(t=>{t.destroy()})}setQueries(t,n){if(jt(this,Lg,t),jt(this,$g,n),process.env.NODE_ENV!=="production"){const r=t.map(o=>je(this,Mh).defaultQueryOptions(o).queryHash);new Set(r).size!==r.length&&console.warn("[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.")}Qr.batch(()=>{const r=je(this,xa),o=rn(this,ys,FR).call(this,je(this,Lg));jt(this,Q0,o),o.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const s=o.map(f=>f.observer),i=s.map(f=>f.getCurrentResult()),a=r.length!==s.length,c=s.some((f,h)=>f!==r[h]),u=a||c,d=u?!0:i.some((f,h)=>{const p=je(this,qi)[h];return!p||!Rv(f,p)});!u&&!d||(u&&jt(this,xa,s),jt(this,qi,i),this.hasListeners()&&(u&&(nV(r,s).forEach(f=>{f.destroy()}),nV(s,r).forEach(f=>{f.subscribe(h=>{rn(this,ys,PR).call(this,f,h)})})),rn(this,ys,OR).call(this)))})}getCurrentResult(){return je(this,qi)}getQueries(){return je(this,xa).map(t=>t.getCurrentQuery())}getObservers(){return je(this,xa)}getOptimisticResult(t,n){const r=rn(this,ys,FR).call(this,t),o=r.map(s=>s.observer.getOptimisticResult(s.defaultedQueryOptions));return[o,s=>rn(this,ys,AR).call(this,s??o,n),()=>rn(this,ys,RR).call(this,o,r)]}},Mh=new WeakMap,qi=new WeakMap,Lg=new WeakMap,$g=new WeakMap,xa=new WeakMap,cd=new WeakMap,Z0=new WeakMap,X0=new WeakMap,Q0=new WeakMap,ys=new WeakSet,RR=function(t,n){return n.map((r,o)=>{const s=t[o];return r.defaultedQueryOptions.notifyOnChangeProps?s:r.observer.trackResult(s,i=>{n.forEach(a=>{a.observer.trackProp(i)})})})},AR=function(t,n){return n?((!je(this,cd)||je(this,qi)!==je(this,X0)||n!==je(this,Z0))&&(jt(this,Z0,n),jt(this,X0,je(this,qi)),jt(this,cd,DN(je(this,cd),n(t)))),je(this,cd)):t},FR=function(t){const n=new Map;je(this,xa).forEach(o=>{const s=o.options.queryHash;if(!s)return;const i=n.get(s);i?i.push(o):n.set(s,[o])});const r=[];return t.forEach(o=>{var c;const s=je(this,Mh).defaultQueryOptions(o),a=((c=n.get(s.queryHash))==null?void 0:c.shift())??new aI(je(this,Mh),s);r.push({defaultedQueryOptions:s,observer:a})}),r},PR=function(t,n){const r=je(this,xa).indexOf(t);r!==-1&&(jt(this,qi,Vve(je(this,qi),r,n)),rn(this,ys,OR).call(this))},OR=function(){var t;if(this.hasListeners()){const n=je(this,cd),r=rn(this,ys,RR).call(this,je(this,qi),je(this,Q0)),o=rn(this,ys,AR).call(this,r,(t=je(this,$g))==null?void 0:t.combine);n!==o&&Qr.batch(()=>{this.listeners.forEach(s=>{s(je(this,qi))})})}},AY),Vl,FY,JY=(FY=class extends Fm{constructor(t={}){super();zt(this,Vl);this.config=t,jt(this,Vl,new Map)}build(t,n,r){const o=n.queryKey,s=n.queryHash??zO(o,n);let i=this.get(s);return i||(i=new Rve({client:t,queryKey:o,queryHash:s,options:t.defaultQueryOptions(n),state:r,defaultOptions:t.getQueryDefaults(o)}),this.add(i)),i}add(t){je(this,Vl).has(t.queryHash)||(je(this,Vl).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const n=je(this,Vl).get(t.queryHash);n&&(t.destroy(),n===t&&je(this,Vl).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Qr.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return je(this,Vl).get(t)}getAll(){return[...je(this,Vl).values()]}find(t){const n={exact:!0,...t};return this.getAll().find(r=>GB(n,r))}findAll(t={}){const n=this.getAll();return Object.keys(t).length>0?n.filter(r=>GB(t,r)):n}notify(t){Qr.batch(()=>{this.listeners.forEach(n=>{n(t)})})}onFocus(){Qr.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Qr.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Vl=new WeakMap,FY),no,ud,dd,zg,Bg,fd,Vg,Hg,PY,qve=(PY=class{constructor(e={}){zt(this,no);zt(this,ud);zt(this,dd);zt(this,zg);zt(this,Bg);zt(this,fd);zt(this,Vg);zt(this,Hg);jt(this,no,e.queryCache||new JY),jt(this,ud,e.mutationCache||new zve),jt(this,dd,e.defaultOptions||{}),jt(this,zg,new Map),jt(this,Bg,new Map),jt(this,fd,0)}mount(){RC(this,fd)._++,je(this,fd)===1&&(jt(this,Vg,iI.subscribe(async e=>{e&&(await this.resumePausedMutations(),je(this,no).onFocus())})),jt(this,Hg,Av.subscribe(async e=>{e&&(await this.resumePausedMutations(),je(this,no).onOnline())})))}unmount(){var e,t;RC(this,fd)._--,je(this,fd)===0&&((e=je(this,Vg))==null||e.call(this),jt(this,Vg,void 0),(t=je(this,Hg))==null||t.call(this),jt(this,Hg,void 0))}isFetching(e){return je(this,no).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return je(this,ud).findAll({...e,status:"pending"}).length}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=je(this,no).get(t.queryHash))==null?void 0:n.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=je(this,no).build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(_d(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return je(this,no).findAll(e).map(({queryKey:t,state:n})=>{const r=n.data;return[t,r]})}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),o=je(this,no).get(r.queryHash),s=o==null?void 0:o.state.data,i=Sve(t,s);if(i!==void 0)return je(this,no).build(this,r).setData(i,{...n,manual:!0})}setQueriesData(e,t,n){return Qr.batch(()=>je(this,no).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,n)]))}getQueryState(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=je(this,no).get(t.queryHash))==null?void 0:n.state}removeQueries(e){const t=je(this,no);Qr.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=je(this,no);return Qr.batch(()=>(n.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},r=Qr.batch(()=>je(this,no).findAll(e).map(o=>o.cancel(n)));return Promise.all(r).then(Is).catch(Is)}invalidateQueries(e,t={}){return Qr.batch(()=>(je(this,no).findAll(e).forEach(n=>{n.invalidate()}),(e==null?void 0:e.refetchType)==="none"?Promise.resolve():this.refetchQueries({...e,type:(e==null?void 0:e.refetchType)??(e==null?void 0:e.type)??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},r=Qr.batch(()=>je(this,no).findAll(e).filter(o=>!o.isDisabled()&&!o.isStatic()).map(o=>{let s=o.fetch(void 0,n);return n.throwOnError||(s=s.catch(Is)),o.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(r).then(Is)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=je(this,no).build(this,t);return n.isStaleByTime(_d(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Is).catch(Is)}fetchInfiniteQuery(e){return e.behavior=MN(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Is).catch(Is)}ensureInfiniteQueryData(e){return e.behavior=MN(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return Av.isOnline()?je(this,ud).resumePausedMutations():Promise.resolve()}getQueryCache(){return je(this,no)}getMutationCache(){return je(this,ud)}getDefaultOptions(){return je(this,dd)}setDefaultOptions(e){jt(this,dd,e)}setQueryDefaults(e,t){je(this,zg).set(pu(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...je(this,zg).values()],n={};return t.forEach(r=>{Mv(e,r.queryKey)&&Object.assign(n,r.defaultOptions)}),n}setMutationDefaults(e,t){je(this,Bg).set(pu(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...je(this,Bg).values()],n={};return t.forEach(r=>{Mv(e,r.mutationKey)&&Object.assign(n,r.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...je(this,dd).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=zO(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===EN&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...je(this,dd).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){je(this,no).clear(),je(this,ud).clear()}},no=new WeakMap,ud=new WeakMap,dd=new WeakMap,zg=new WeakMap,Bg=new WeakMap,fd=new WeakMap,Vg=new WeakMap,Hg=new WeakMap,PY),VO=ie.createContext(void 0),Hr=e=>{const t=ie.useContext(VO);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},Uve=({client:e,children:t})=>(ie.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),l.jsx(VO.Provider,{value:e,children:t})),eZ=ie.createContext(!1),tZ=()=>ie.useContext(eZ);eZ.Provider;function Kve(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Wve=ie.createContext(Kve()),nZ=()=>ie.useContext(Wve),rZ=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},oZ=e=>{ie.useEffect(()=>{e.clearReset()},[e])},sZ=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:o})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(o&&e.data===void 0||UY(n,[e.error,r])),iZ=e=>{if(e.suspense){const n=o=>o==="static"?o:Math.max(o??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...o)=>n(r(...o)):n(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},aZ=(e,t)=>e.isLoading&&e.isFetching&&!t,LR=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,RN=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function cf({queries:e,...t},n){const r=Hr(),o=tZ(),s=nZ(),i=ie.useMemo(()=>e.map(x=>{const b=r.defaultQueryOptions(x);return b._optimisticResults=o?"isRestoring":"optimistic",b}),[e,r,o]);i.forEach(x=>{iZ(x),rZ(x,s)}),oZ(s);const[a]=ie.useState(()=>new Hve(r,i,t)),[c,u,d]=a.getOptimisticResult(i,t.combine),f=!o&&t.subscribed!==!1;ie.useSyncExternalStore(ie.useCallback(x=>f?a.subscribe(Qr.batchCalls(x)):Is,[a,f]),()=>a.getCurrentResult(),()=>a.getCurrentResult()),ie.useEffect(()=>{a.setQueries(i,t)},[i,t,a]);const p=c.some((x,b)=>LR(i[b],x))?c.flatMap((x,b)=>{const y=i[b];if(y){const C=new aI(r,y);if(LR(y,x))return RN(y,C,s);aZ(x,o)&&RN(y,C,s)}return[]}):[];if(p.length>0)throw Promise.all(p);const g=c.find((x,b)=>{const y=i[b];return y&&sZ({result:x,errorResetBoundary:s,throwOnError:y.throwOnError,query:r.getQueryCache().get(y.queryHash),suspense:y.suspense})});if(g!=null&&g.error)throw g.error;return u(d())}function lZ(e,t,n){var f,h,p,g,x;if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const r=tZ(),o=nZ(),s=Hr(),i=s.defaultQueryOptions(e);(h=(f=s.getDefaultOptions().queries)==null?void 0:f._experimental_beforeQuery)==null||h.call(f,i),process.env.NODE_ENV!=="production"&&(i.queryFn||console.error(`[${i.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)),i._optimisticResults=r?"isRestoring":"optimistic",iZ(i),rZ(i,o),oZ(o);const a=!s.getQueryCache().get(i.queryHash),[c]=ie.useState(()=>new t(s,i)),u=c.getOptimisticResult(i),d=!r&&e.subscribed!==!1;if(ie.useSyncExternalStore(ie.useCallback(b=>{const y=d?c.subscribe(Qr.batchCalls(b)):Is;return c.updateResult(),y},[c,d]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),ie.useEffect(()=>{c.setOptions(i)},[i,c]),LR(i,u))throw RN(i,c,o);if(sZ({result:u,errorResetBoundary:o,throwOnError:i.throwOnError,query:s.getQueryCache().get(i.queryHash),suspense:i.suspense}))throw u.error;if((g=(p=s.getDefaultOptions().queries)==null?void 0:p._experimental_afterQuery)==null||g.call(p,i,u),i.experimental_prefetchInRender&&!Xh&&aZ(u,r)){const b=a?RN(i,c,o):(x=s.getQueryCache().get(i.queryHash))==null?void 0:x.promise;b==null||b.catch(Is).finally(()=>{c.updateResult()})}return i.notifyOnChangeProps?u:c.trackResult(u)}function Yn(e,t){return lZ(e,aI)}function Gve(e,t){const n=Hr(),r=n.getQueryCache();return ie.useSyncExternalStore(ie.useCallback(o=>r.subscribe(Qr.batchCalls(o)),[r]),()=>n.isFetching(e),()=>n.isFetching(e))}function Os(e,t){const n=Hr(),[r]=ie.useState(()=>new Bve(n,e));ie.useEffect(()=>{r.setOptions(e)},[r,e]);const o=ie.useSyncExternalStore(ie.useCallback(i=>r.subscribe(Qr.batchCalls(i)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),s=ie.useCallback((i,a)=>{r.mutate(i,a).catch(Is)},[r]);if(o.error&&UY(r.options.throwOnError,[o.error]))throw o.error;return{...o,mutate:s,mutateAsync:o.mutate}}function Yve(e,t){return lZ(e,Lve)}function cZ(e){const t=v.useId(),[n,r]=v.useState({token:e,revision:0});return n.token!==e&&r({token:e,revision:n.revision+1}),`${t}:${n.revision}`}function Zve(){const e=v.useContext(VO);if(e&&e.isSemaphorClient)return e}function uZ({children:e}){const{setIsSessionExpired:t}=m.useDashboardActions(),n=Zve(),[r]=v.useState(()=>{const o=new qve({queryCache:new JY({onError:s=>{s instanceof Error?(console.error(`Something went wrong: ${s.message}`),s.message==="invalid token"&&t(!0)):console.error("Something went wrong:",s)}}),defaultOptions:{queries:{gcTime:36e5,staleTime:3e5,refetchOnWindowFocus:!1,retry:!1}}});return o.isSemaphorClient=!0,o});return n?l.jsx(l.Fragment,{children:e}):l.jsx(Uve,{client:r,children:e})}const dZ=v.createContext(null);function fZ(e){return hZ({rowKey:ze.matrixPathKey(e.rowPath),columnKey:ze.matrixPathKey(e.columnPath),measureId:e.measureId})}function hZ(e){return JSON.stringify([e.rowKey,e.columnKey,e.measureId])}const Po=Object.freeze({rowPageSize:100,columnPageSize:20,operations:2,dashboardOperations:4,pages:32,blocks:64,cells:1e5,bytes:32*1024*1024,checkpoints:64,overrides:2e3,mountedCells:5e3,clipboardCells:1e4,clipboardBytes:1024*1024,clipboardTimeoutMs:3e4});class Xve{constructor(){Se(this,"pending",new Map);Se(this,"activeByCard",new Map);Se(this,"active",0)}run(t,n,r){const o=()=>new DOMException("Matrix acquisition was cancelled.","AbortError");return n.aborted?Promise.reject(o()):new Promise((s,i)=>{let a=!1;const c=()=>{var f;if(!a){const h=(f=this.pending.get(t))==null?void 0:f.filter(p=>p!==u);h!=null&&h.length?this.pending.set(t,h):this.pending.delete(t),n.removeEventListener("abort",c)}i(o())},u={start:()=>{a=!0,this.active++,this.activeByCard.set(t,(this.activeByCard.get(t)??0)+1),Promise.resolve().then(()=>{if(n.aborted)throw o();return r()}).then(s,i).finally(()=>{n.removeEventListener("abort",c),this.active--;const f=this.activeByCard.get(t)-1;f?this.activeByCard.set(t,f):this.activeByCard.delete(t),this.pump()})}},d=this.pending.get(t)??[];d.push(u),this.pending.set(t,d),n.addEventListener("abort",c,{once:!0}),this.pump()})}pump(){for(;this.active<Po.dashboardOperations;){const t=Array.from(this.pending).find(([s])=>(this.activeByCard.get(s)??0)<Po.operations);if(!t)return;const[n,r]=t,o=r.shift();this.pending.delete(n),r.length&&this.pending.set(n,r),o.start()}}}function Qve({value:e,children:t}){const[n]=v.useState(()=>new Xve),r=v.useMemo(()=>({...e,queue:n}),[e,n]);return l.jsx(dZ.Provider,{value:r,children:t})}function Jve(e,t){return async n=>{var i;const r=await fetch(e,{method:"POST",signal:n.signal,headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(lt.buildMatrixCardQueryPayload(n))});if(r.status===401||r.status===403)return{status:"failed",failure:{code:"forbidden",message:"Matrix query access was denied.",retryable:!1,scope:{kind:"operation"}}};const o=await r.json().catch(()=>null);if(!o||typeof o!="object")return{status:"failed",failure:{code:"execution_failed",message:"Matrix query returned an invalid response.",retryable:r.ok||r.status>=500,scope:{kind:"operation"}}};if(!r.ok||o.error){const a=Dv.matrixExecutionResultSchema.safeParse(o.executionResult);if(a.success&&a.data.metadata.matrixFailure)return{status:"failed",failure:a.data.metadata.matrixFailure};const c=a.success?a.data.validation.errors[0]:void 0;return{status:"failed",failure:{code:"execution_failed",message:(c==null?void 0:c.message)??"Matrix query failed.",retryable:r.status>=500,scope:{kind:"operation"}}}}const s=Dv.matrixWindowSchema.parse((i=o.data)==null?void 0:i.matrixWindow);return{status:s.failures.length?"partial":"success",window:s}}}function e0e({children:e,authToken:t,apiServiceUrl:n,dashboardId:r}){const o=(t==null?void 0:t.accessToken)??"",s=v.useMemo(()=>({ready:!!(o&&n),identity:JSON.stringify([r,n]),execute:Jve(`${n??""}/v1/query`,o)}),[r,n,o]);return l.jsx(Qve,{value:s,children:e})}const t0e={id:"",authToken:void 0,tokenProps:{},authorizationScope:"unconfigured"},J0=v.createContext(t0e),HO=({children:e,dashboardProps:t})=>{var o;const n=cZ((o=t.authToken)==null?void 0:o.accessToken),r=v.useMemo(()=>{let s={};const i=t.authToken;return i&&(s=Re.jwtDecode(i.accessToken)),{...t,tokenProps:s,authorizationScope:n}},[t,n]);return l.jsx(uZ,{children:l.jsx(J0.Provider,{value:r,children:l.jsx(e0e,{dashboardId:r.id,authToken:r.authToken,apiServiceUrl:r.tokenProps.apiServiceUrl,children:e})})})};function Mt(){const e=v.useContext(J0);if(e===void 0)throw new Error("useApplicationContext must be used within a ApplicationContextProvider");return e}const Ls=m.create()(m.immer(e=>({initialDashboard:null,selectedDashboard:null,selectedVisual:null,lastSelectedDashboard:null,lastSelectedVisual:null,showHub:!1,actions:{setInitialDashboard:t=>{e(n=>{n.initialDashboard=t})},selectDashboard:t=>{e(n=>{var r;((r=n.selectedDashboard)==null?void 0:r.id)!==t.id&&(n.lastSelectedDashboard=n.selectedDashboard,n.selectedDashboard=t),n.showHub=!1})},updateSelectedDashboard:t=>{e(n=>{n.selectedDashboard=t})},selectVisual:t=>{e(n=>{n.lastSelectedVisual=n.selectedVisual,n.selectedVisual=t})},clearSelectedDashboard:()=>{e(t=>{t.lastSelectedDashboard=t.selectedDashboard,t.selectedDashboard=null,t.showHub=!0})},clearSelectedVisual:()=>{e(t=>{t.lastSelectedVisual=t.selectedVisual,t.selectedVisual=null})},setShowHub:t=>{e(n=>{n.showHub=t})}}}))),n0e=()=>Ls(e=>e.selectedVisual),Pm=()=>Ls(e=>e.actions);function ew(){const{authToken:e,version:t,tokenProps:n,id:r}=Mt(),o=Ls(g=>g.selectedDashboard),s=Ls(g=>g.showHub),i=m.useDashboardStore(g=>g.selectedLensId),a=r0e({showHub:s,selectedDashboardId:o==null?void 0:o.id,dashboardId:r,tokenDashboardId:n==null?void 0:n.dashboard_id});function c(){return!(!(e!=null&&e.accessToken)||!a)}const{data:u,isLoading:d,isFetching:f,isError:h,refetch:p}=Yn({queryKey:["dashboard",i,e==null?void 0:e.accessToken,a],queryFn:()=>m.getDashboard(n.apiServiceUrl,e==null?void 0:e.accessToken,{lensId:i,version:t,dashboardId:a}),enabled:c()});return{data:u,isLoading:d,isFetching:f,isError:h,refetch:p,dashboardIdToFetch:a}}function r0e({showHub:e,selectedDashboardId:t,dashboardId:n,tokenDashboardId:r}){return e?null:t||n||r||null}function o0e(){const{authToken:e}=Mt(),t=m.useDashboardStore(r=>r.authToken),{setAuthToken:n}=m.useDashboardActions();return v.useLayoutEffect(()=>{const r=e==null?void 0:e.accessToken,o=t==null?void 0:t.accessToken;e&&r!==o&&n(e)},[e,t,n]),e}function mZ(e){const t=v.useCallback(s=>`semaphor-default-sheet-${s}`,[]),n=v.useCallback(()=>{if(!e)return null;try{const s=t(e);return localStorage.getItem(s)}catch(s){return console.error("Error reading default sheet preference:",s),null}},[e,t]),r=v.useCallback(s=>{if(!(!e||!s))try{const i=t(e);localStorage.setItem(i,s)}catch(i){console.error("Error saving default sheet preference:",i)}},[e,t]),o=v.useCallback(()=>{if(e)try{const s=t(e);localStorage.removeItem(s)}catch(s){console.error("Error clearing default sheet preference:",s)}},[e,t]);return{getDefaultSheetId:n,setDefaultSheetId:r,clearDefaultSheetId:o}}const s0e=["kpi","table","detailTable","aggregateTable","pivotTable","bar","horizontalBar","stackedBar","line","stackedLine","area","stackedArea","combo","pie","doughnut","polarArea","radar","scatter","bubble","tornado","pyramid","range","funnel","bullet","heatmap","treemap","map","matrixTable"],i0e=new Set(s0e),a0e=["table","detailTable","aggregateTable","pivotTable","matrixTable"],l0e=new Set(a0e);function qO(e){return typeof e=="string"&&l0e.has(e)}function tw(e){return typeof e=="string"&&i0e.has(e)}function AN(e){return(e==null?void 0:e.type)==="number"||(e==null?void 0:e.type)==="currency"}function pZ(e){var n,r;const t=(r=(n=e.preferences)==null?void 0:n.formatNumber)==null?void 0:r.enabled;return t===!1||t==="false"}function gZ(e){return(e==null?void 0:e.type)==="number"}function c0e(e){var n;if(!gZ(e))return!1;const t=(n=e==null?void 0:e.numberFormat)==null?void 0:n.style;return t===void 0||t==="decimal"||t==="currency"}function xZ(e,t){const n=t==null?void 0:t.type;if(n&&n!=="none"&&n!=="number")return{currencyBindable:!1};const r=n==="number"?t!=null&&t.numberFormat?m.fromColumnNumberFormat(t.numberFormat,{preserveOmittedProperties:!0}):{type:"number"}:void 0,o=Lt.fromSemanticFormat(e.format,{preserveOmittedProperties:!0}),s=ze.normalizeAnalyticsCatalogDataType(e.dataType)==="number"?{type:"number"}:void 0,a=(t==null?void 0:t.inheritMetricFormat)===!1||!!(t!=null&&t.numberFormat)&&(t==null?void 0:t.inheritMetricFormat)!==!0?r:o||s||r;return{authoredFormat:a,currencyBindable:AN(a)}}function UO(e,t){var c,u;const n=Lt.fromSemanticFormat(t.format,{preserveOmittedProperties:!0}),r=m.fromNumberAxisFormat((c=e.preferences)==null?void 0:c.numberAxisFormat),o=pZ(e)?void 0:m.fromLegacyFormatNumber((u=e.preferences)==null?void 0:u.formatNumber),s=ze.normalizeAnalyticsCatalogDataType(t.dataType)==="number"?{type:"number"}:void 0,i=n||r||o||s;return{authoredFormat:i,source:n?"semantic":r?"number_axis":o?"legacy":s?"inferred":void 0,currencyBindable:AN(i)}}function Fv(e,t={}){var h,p,g,x,b,y;const n=t.metricIndex??0,r=!!((h=e.sql)!=null&&h.trim()),o=m.fromPersistedKpiFormatOptions((g=(p=e.preferences)==null?void 0:p.kpiVisualOptions)==null?void 0:g.formatOptions),s=n===0?m.fromLegacyFormatNumber((x=e.preferences)==null?void 0:x.formatNumber):void 0,i=pZ(e);if(r){const C=t.resultColumnKey?{kind:"column",columnKey:t.resultColumnKey}:void 0;return{target:C,authoredFormat:o||s,currencyBindable:!i&&!!C&&AN(o)}}const a=(y=(b=e.config)==null?void 0:b.metricColumns)==null?void 0:y[n],c=a!=null&&a.id?{kind:"metric",metricId:a.id}:void 0,u=Lt.fromSemanticFormat(a==null?void 0:a.format,{preserveOmittedProperties:!0}),d=ze.normalizeAnalyticsCatalogDataType(a==null?void 0:a.dataType)==="number"?{type:"number"}:void 0,f=o||u||s||d;return{target:c,authoredFormat:f,currencyBindable:!i&&tw(e.type)&&!!c&&AN(f)}}function lI(e,t=[]){const n=mu.inspectMatrixCardConfig(e);if(n.status!=="ready")return[];const{spec:r,presentation:o}=n.config,s=lt.createMatrixCatalogResolver(t);return r.measures.map(i=>{var g,x;const a=i.kind==="aggregate"?s(i.field,r.source):void 0,c=i.kind==="calculated"?i.definition.format:((g=i.field.derivedField)==null?void 0:g.format)??(a==null?void 0:a.format)??(a==null?void 0:a.resolvedField.format),u=Xn.resolveMatrixValueFormat(o.measureFormats[i.id],c),d=i.kind==="calculated"?i.definition.dataType:["MIN","MAX"].includes(i.aggregate)?((x=i.field.derivedField)==null?void 0:x.dataType)??(a==null?void 0:a.resolvedField.dataType)??i.field.dataType:"number",f=ze.normalizeAnalyticsCatalogDataType(d)==="number",h=i.kind==="calculated"||!!(a||i.field.derivedField||i.field.name==="*"),p=u&&Lt.isNumericCanonicalFormat(u)?u:!u&&f&&h?{type:"number"}:void 0;return{measureId:i.id,label:_s.getMatrixMeasureLabel(i,o),canonical:p}})}function bZ(e){var t,n;return e.type==="detailTable"?((t=e.config)==null?void 0:t.detailColumns)||[]:((n=e.config)==null?void 0:n.metricColumns)||[]}function yZ(e){return new Set(m.getDashboardCards(e).flatMap(t=>(t.controlBindings||[]).filter(nw).map(n=>n.controlId)))}function u0e(e,t){const n=[t.id,t.alias,t.label,t.name,t.qualifiedFieldName].filter(s=>!!s);for(const s of n)if(e[s])return e[s];const r=new Set(n.map(s=>s.trim().toLowerCase())),o=Object.entries(e).find(([s])=>r.has(s.trim().toLowerCase()));return o==null?void 0:o[1]}function rV(e){return[...new Map(e.map(t=>[Ta(t),t])).values()]}function cI(e,t=[],n){var N,S,j;const r=!!((N=e.sql)!=null&&N.trim()),o=tw(e.type),s=r&&o&&e.type!=="kpi"&&e.type!=="matrixTable",i=bZ(e),a=((j=(S=e.preferences)==null?void 0:S.tablePrefs)==null?void 0:j.columnSettingsMap)||{},c=!r&&e.type==="kpi"?i.map((k,_)=>Fv(e,{metricIndex:_})):[],u=!r&&e.type==="matrixTable"?lI(e,n):[],d=(r?[]:i).map(k=>({kind:"metric",metricId:k.id})),f=u.map(k=>({kind:"matrix_measure",measureId:k.measureId})),h=u.filter(k=>{var _,T;return((_=k.canonical)==null?void 0:_.type)==="number"||((T=k.canonical)==null?void 0:T.type)==="currency"}).map(k=>({kind:"matrix_measure",measureId:k.measureId})),p=e.type==="matrixTable"?[]:e.type==="kpi"?c.filter(k=>k.currencyBindable).flatMap(k=>k.target?[k.target]:[]):(r||!o?[]:i).filter(k=>(qO(e.type)?xZ(k,u0e(a,k)):UO(e,k)).currencyBindable).map(k=>({kind:"metric",metricId:k.id})),g=[...new Set(t)],x=(s?g:[]).map(k=>({kind:"column",columnKey:k})),b=(s?g:[]).filter(k=>c0e(a[k])).map(k=>({kind:"column",columnKey:k})),y=(r&&e.type==="kpi"?g.slice(0,1):[]).map(k=>({kind:"column",columnKey:k})),C=r&&e.type==="kpi"?Fv(e,{resultColumnKey:g[0]}):void 0,w=o&&(C!=null&&C.currencyBindable)?y:[];return{knownTargets:rV([...e.type==="matrixTable"?f:d,...x,...y]),eligibleTargets:rV([...p,...h,...b,...w])}}function vZ(e,t){const n=Fv(e,{resultColumnKey:t});return n.currencyBindable?n.target:void 0}function ic(e){var t;return(t=e.card.sql)!=null&&t.trim()?{kind:"column",columnKey:e.columnKey}:e.metricId?{kind:"metric",metricId:e.metricId}:void 0}function Ta(e){return e.kind==="metric"?`metric:${e.metricId}`:e.kind==="column"?`column:${e.columnKey}`:`matrix_measure:${e.measureId}`}function d0e(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t=e;if(t.kind==="metric"&&typeof t.metricId=="string"&&t.metricId.trim())return{kind:"metric",metricId:t.metricId};if(t.kind==="column"&&typeof t.columnKey=="string"&&t.columnKey.trim())return{kind:"column",columnKey:t.columnKey};if(t.kind==="matrix_measure"&&typeof t.measureId=="string"&&t.measureId.trim())return{kind:"matrix_measure",measureId:t.measureId}}function nw(e){return e.target==="presentation_currency"}function f0e(e){return e.target!=="sql_param"&&e.target!=="presentation_currency"}function oV(e){const t=Yi.canonicalizeSupportedCurrencyCode(e);return typeof e=="string"&&e===t?t:void 0}function wZ(e){if(e.type!=="enum"||e.source.kind!=="manual")return{diagnostic:"invalid_control_type"};const t=e.source.options.map(n=>oV(n.value));if(t.length===0||t.some(n=>!n))return{diagnostic:"invalid_currency_option"};if(e.requiredAtExecution){const n=e.initialValueStrategy==="saved_default"?oV(e.defaultValue):void 0;if(!n||!t.includes(n))return{diagnostic:"invalid_control_default"}}return{control:e,currencies:t}}function h0e(e){return"control"in wZ(e)}function CZ(e){const t=yZ(e.dashboard);if(t.size===0)return{definitions:e.definitions||[],values:e.values||{}};const n=new Set([...t].filter(r=>!e.referencedControlIds.has(r)));return{definitions:(e.definitions||[]).filter(r=>!n.has(r.id)),values:Object.fromEntries(Object.entries(e.values||{}).filter(([r])=>!n.has(r)))}}function SZ(e){return CZ({...e,referencedControlIds:new Set(en.extractReferencedControlIds({sql:e.filterSql,controlBindings:[]}))})}function m0e(e){var t;return CZ({...e,referencedControlIds:new Set(en.extractReferencedControlIds({sql:(t=e.source)==null?void 0:t.sql,controlBindings:[]}))})}function NZ(e){return{knownKeys:new Set(e.knownTargets.map(Ta)),eligibleKeys:new Set(e.eligibleTargets.map(Ta)),controlsById:new Map((e.controls||[]).map(t=>[t.id,t]))}}function jZ(e,t){if(!e||typeof e!="object"||e.target!=="presentation_currency")return{};const n=e,r=typeof n.controlId=="string"&&n.controlId.trim()?n.controlId:void 0;if(!r)return{diagnostic:{code:"invalid_binding_shape"}};const o=d0e(n.presentationTarget);if(!o)return{diagnostic:{code:"missing_target",controlId:r}};const s=Ta(o);if(!t.knownKeys.has(s))return{diagnostic:{code:"stale_target",controlId:r}};if(!t.eligibleKeys.has(s))return{diagnostic:{code:"inapplicable_target",controlId:r}};const i=t.controlsById.get(r);if(!i)return{diagnostic:{code:"missing_control",controlId:r}};const a=wZ(i);return"diagnostic"in a?{diagnostic:{code:a.diagnostic,controlId:r}}:{binding:{controlId:r,presentationTarget:o,control:a.control,currencies:a.currencies}}}function p0e(e){const t=NZ(e);return(e.bindings||[]).flatMap(n=>{const r=jZ(n,t);return"diagnostic"in r?[r.diagnostic]:[]})}function KO(e){var o;const t=[],n=Ta(e.target),r=NZ(e);for(const s of e.bindings||[]){const i=jZ(s,r);if("diagnostic"in i){t.push(i.diagnostic);continue}const a=i.binding;if(!a||Ta(a.presentationTarget)!==n)continue;const u=Yi.canonicalizeSupportedCurrencyCode((o=e.values)==null?void 0:o[a.control.id]);if(!(!u||!a.currencies.includes(u)))return{currency:u,diagnostics:t}}return{diagnostics:t}}function g0e(e,t,n,r){const o={...e,config:{...e.config,matrix:t}},s=cI(o,[],r),i=lI(o,r),a={...t.presentation.measureFormats};for(const c of i){const u={kind:"matrix_measure",measureId:c.measureId},{currency:d}=KO({...n,...s,bindings:e.controlBindings,target:u});if(!d||!c.canonical)continue;const{locale:f,...h}=c.canonical;a[c.measureId]={...h,type:"currency",currency:d}}return{...t.presentation,measureFormats:a}}function x0e(e,t){if(!e||typeof e!="object"||!("kind"in e))return e;switch(e.kind){case"manual":return{kind:"manual",...t!=null&&t.includePresentation?{options:e.options.map(n=>({value:n.value,label:n.label,presentation:n.presentation}))}:{optionValues:e.options.map(n=>n.value).sort()}};case"dataset_values":return{kind:"dataset_values",fieldId:e.fieldId,connectionId:e.connectionId||""};case"field_allowlist":return{kind:"field_allowlist",fieldIds:[...e.fieldIds].sort()};case"metric_allowlist":return{kind:"metric_allowlist",metricIds:[...e.metricIds].sort()};case"sql_query":return{kind:"sql_query",connectionId:e.connectionId,sql:e.sql,valueColumn:e.valueColumn,labelColumn:e.labelColumn};default:return e}}function b0e(e,t){return{id:e.id,scope:e.scope,type:e.type,source:x0e(e.source,t),initialValueStrategy:e.initialValueStrategy,defaultValue:e.defaultValue,requiredAtExecution:e.requiredAtExecution,...t!=null&&t.includePresentation?{label:e.label,helpText:e.helpText,hidden:e.hidden,locked:e.locked,placement:e.placement,showLabel:e.showLabel,toolbarWidth:e.toolbarWidth}:{}}}function y0e(e,t){return e.target==="sql_param"||e.target==="presentation_currency"?e:e.target==="config_field_selector"&&!(t!=null&&t.includePresentation)?{...e,mapping:Object.fromEntries(Object.entries(e.mapping).sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>{if("kind"in r)return[n,r];const o={...r};return delete o.format,delete o.dateFormat,delete o.customFormat,delete o.semanticTemporalPresentation,[n,o]}))}:{...e,mapping:Object.fromEntries(Object.entries(e.mapping).sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>[n,r&&typeof r=="object"&&!Array.isArray(r)?Object.fromEntries(Object.entries(r).sort(([o],[s])=>o.localeCompare(s))):r]))}}function sV(e=[],t){return[...e].map(n=>b0e(n,t)).sort((n,r)=>n.id.localeCompare(r.id)||n.scope.localeCompare(r.scope)||n.type.localeCompare(r.type))}function v0e(e=[],t){return e.filter(n=>(t==null?void 0:t.includePresentation)||!nw(n)).map(n=>y0e(n,t)).sort((n,r)=>es.stableSerialize(n).localeCompare(es.stableSerialize(r)))}function $R(e,t){return e?es.stableSerialize({controlDefinitions:sV(e.controlDefinitions,t),cardControlDefinitions:sV(e.cardControlDefinitions,t),controlBindings:v0e(e.controlBindings,t)}):"__none__"}function hD(e,t){return e&&t.has(e)?e:null}function w0e({selectedSheetId:e,preservedSelectedSheetId:t,defaultSheetId:n,sheets:r}){var s;const o=new Set((r||[]).map(i=>i.id).filter(i=>typeof i=="string"));return hD(e,o)||hD(t,o)||hD(n,o)||((s=r==null?void 0:r[0])==null?void 0:s.id)||null}function C0e(e){var i,a;en.requireNormalizedDashboardInputs({inputs:e.inputs,dashboardFilters:e.filters});const t=[...Array.isArray(e.inputs)?e.inputs:[]],n=new Set(t.map(c=>c.id)),r=new Set((e.sheets||[]).filter(c=>c.kind==="document").map(c=>c.id));let o=!1;for(const c of e.sheets||[])if(!(c.kind!=="document"||!((a=(i=c.document)==null?void 0:i.inputs)!=null&&a.length)))for(const u of c.document.inputs)n.has(u.id)||(t.push(S0e(u,c.id)),n.add(u.id),o=!0);const s=t.map(c=>{if(c.kind==="filter"&&c.filter!==void 0&&iV(c,r)&&c.filter.variableName!==c.variableName)return o=!0,{...c,filter:{...c.filter,variableName:c.variableName}};if(c.kind!=="control"||!iV(c,r))return c;const u=m.createUniqueDashboardInputVariableNameFromName(c.control.id||c.variableName,t.filter(d=>d.id!==c.id));return c.variableName===u&&c.control.id===u?c:(o=!0,{...c,variableName:u,control:{...c.control,id:u}})});return o?{...e,inputs:s}:e}function S0e(e,t){const n={id:e.id,label:e.label,variableName:e.variableName,description:e.description,requiredAtExecution:e.requiredAtExecution,scope:{kind:"sheets",sheetIds:[t]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},exports:e.exports,compatibility:{source:"documentInput",sheetId:t,inputId:e.id}};return e.kind==="filter"?{...n,kind:"filter",filter:e.filter}:{...n,kind:"control",control:e.control}}function iV(e,t){var n;switch(e.scope.kind){case"allSheets":return!((n=e.scope.sheetKinds)!=null&&n.length)||e.scope.sheetKinds.includes("document");case"sheets":return e.scope.sheetIds.some(r=>t.has(r));case"documentSections":return t.has(e.scope.sheetId);default:return!1}}function zR({dashboard:e,dashboardInputValues:t,sheetId:n,cardId:r}){let o=m.compactDashboardInputValues(t||{});const s=j0e({dashboard:e,sheetId:n,cardId:r});if(s.status==="unresolved")return{};o=N0e({dashboardInputValues:o,savedSheetId:n,cardId:r,targets:s.targets});for(const i of s.targets){const a=m.removeShadowedCompatibilityInputs(m.buildNormalizedDashboardInputs({dashboard:e,card:i.card}).allInputs).filter(c=>m.canAddressDashboardInputRuntimeSlot(c,i)&&m.doesDashboardInputApplyToTarget(c,i));for(const c of a){const u=m.getDashboardInputRuntimeSlot(o,c,i),d=m.materializeDashboardInputRuntimeSlot(c,u);if(d&&d!==u&&(o=m.setDashboardInputRuntimeSlot(o,c,i,d)),!d||d.status===void 0){o=m.setDashboardInputRuntimeSlot(o,c,i,{status:"cleared",comparisonSelection:d==null?void 0:d.comparisonSelection});continue}d.status==="set"&&m.isComparisonCapableDashboardDateInput(c)&&!d.comparisonSelection&&(o=m.setDashboardInputRuntimeSlot(o,c,i,{...d,comparisonSelection:{mode:"off"}}))}}return m.compactDashboardInputValues(o)}function N0e({dashboardInputValues:e,savedSheetId:t,cardId:n,targets:r}){var c,u,d,f;const o={},s=new Set(r.flatMap(h=>h.sheetId?[h.sheetId]:[])),i=new Set(r.flatMap(h=>h.cardId?[h.cardId]:[])),a=new Set(r.flatMap(h=>h.sectionId?[h.sectionId]:[]));if(e.shared&&(o.shared={...e.shared}),n){const h=r[0],p=(t?(c=e.bySheetId)==null?void 0:c[t]:void 0)??(h.sheetId?(u=e.bySheetId)==null?void 0:u[h.sheetId]:void 0);h.sheetId&&p&&(o.bySheetId={[h.sheetId]:{...p}});const g=h.cardId?(d=e.byCardId)==null?void 0:d[h.cardId]:void 0;h.cardId&&g&&(o.byCardId={[h.cardId]:{...g}});const x=Object.entries(e.byDocumentSectionId||{}),b=(h.sectionId?(f=e.byDocumentSectionId)==null?void 0:f[h.sectionId]:void 0)??(x.length===1?x[0][1]:void 0);return h.sectionId&&b&&(o.byDocumentSectionId={[h.sectionId]:{...b}}),m.compactDashboardInputValues(o)}return o.bySheetId=mD(e.bySheetId,s),o.byCardId=mD(e.byCardId,i),o.byDocumentSectionId=mD(e.byDocumentSectionId,a),m.compactDashboardInputValues(o)}function mD(e,t){if(!e)return;const n=Object.entries(e).filter(([r])=>t.has(r));return n.length>0?Object.fromEntries(n.map(([r,o])=>[r,{...o}])):void 0}function j0e({dashboard:e,sheetId:t,cardId:n}){var i;if(n){const a=k0e(e,n);return a?{status:"resolved",targets:[a]}:{status:"unresolved",targetKind:"card"}}const r=(e.sheets||[]).filter(a=>!t||a.id===t);if(t&&r.length===0)return{status:"unresolved",targetKind:"sheet"};const o=r.map(a=>({sheetId:a.id,sheetKind:a.kind||"dashboard"})),s=new Set(r.map(a=>a.id));for(const a of m.getDashboardCardEntries(e))s.has(a.sheet.id)&&o.push({sheetId:a.sheet.id,cardId:a.card.id,card:a.card,sheetKind:a.sheet.kind||"dashboard"});for(const a of r)if(a.kind==="document")for(const c of((i=a.document)==null?void 0:i.sections)||[])o.push({sheetId:a.id,sectionId:c.id,...(c.type==="table"||c.type==="chart")&&{cardId:c.card.id,card:c.card},sheetKind:"document"});return{status:"resolved",targets:o.length>0?o:[{}]}}function k0e(e,t){var r;const n=m.findCardLocationById(e,t);if(n)return{sheetId:n.sheet.id,cardId:n.card.id,card:n.card,sheetKind:n.sheet.kind||"dashboard"};for(const o of e.sheets||[])if(o.kind==="document"){for(const s of((r=o.document)==null?void 0:r.sections)||[])if((s.type==="table"||s.type==="chart")&&s.card.id===t)return{sheetId:o.id,sectionId:s.id,cardId:s.card.id,card:s.card,sheetKind:"document"}}}function kZ({dashboardInputValues:e,dashboard:t,filterValues:n,sheetId:r,cardId:o,sectionId:s,sheetKind:i}){var u,d,f;if(!((u=t.inputs)!=null&&u.length))return e;const a=new Map(n.map(h=>[h.filterId,h]));let c=e||{};for(const h of t.inputs){if(h.kind!=="filter"||!m.doesDashboardInputApplyToTarget(h,{sheetId:r,cardId:o,sectionId:s,sheetKind:i}))continue;const p=((d=h.filter)==null?void 0:d.id)||((f=h.filterReference)==null?void 0:f.filterId);if(!p)continue;const g=a.get(p),x=g?m.createFilterDashboardInputSlot(g):void 0,b=(x==null?void 0:x.status)==="set"?x:{status:"cleared"};c=m.setDashboardInputRuntimeValueAspect(c,h,{sheetId:r,cardId:o,sectionId:s},b)}return c}function su({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,generatedAt:a,timezone:c}){const u=A1({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,timezone:c});return{context:u,snapshot:{...t?{sheetId:t}:{},...n!=null&&n.id?{cardId:n.id}:{},mode:s,dashboardInputValues:_0e({inputs:u.inputs,context:u,sheetId:t,cardId:n==null?void 0:n.id,sectionId:r}),generatedAt:a,timezone:c}}}function IZ({sectionIds:e,...t}){const n=new Set,r=o=>{for(const s of o.missingRequiredInputs)n.add(s.label)};r(A1(t));for(const o of e)r(A1({...t,sectionId:o}));for(const{sectionId:o,card:s}of TZ(t.dashboard,t.sheetId,e))r(A1({...t,sectionId:o,card:s}));return Array.from(n)}function WO({sheetIds:e,sheetKind:t="dashboard",...n}){const r=e.map(a=>su({...n,sheetId:a,sheetKind:t})),o=e.flatMap(a=>I0e(n.dashboard,a).map(c=>su({...n,sheetId:a,card:c,sheetKind:t}))),s=r[0]||o[0]||su({...n,sheetKind:t}),i=DZ(...r.map(a=>a.snapshot.dashboardInputValues),...o.map(a=>a.snapshot.dashboardInputValues));return{context:s.context,snapshot:{...e.length===1?{sheetId:e[0]}:{},mode:n.mode,dashboardInputValues:i,generatedAt:n.generatedAt,timezone:n.timezone}}}function I0e(e,t){var i;const n=(i=e.sheets)==null?void 0:i.find(a=>a.id===t),r=[],o=new Set,s=a=>{!(a!=null&&a.id)||o.has(a.id)||(o.add(a.id),r.push(a))};for(const a of(n==null?void 0:n.cards)||[])s(a);for(const a of(n==null?void 0:n.frames)||[])for(const c of(a==null?void 0:a.cards)||[])s(c);return r}function _Z({sectionIds:e,...t}){const n=su(t),r=e.map(s=>su({...t,sectionId:s})),o=TZ(t.dashboard,t.sheetId,e).map(({sectionId:s,card:i})=>su({...t,sectionId:s,card:i}));return{...n,snapshot:{...n.snapshot,dashboardInputValues:DZ(n.snapshot.dashboardInputValues,...r.map(s=>s.snapshot.dashboardInputValues),...o.map(s=>s.snapshot.dashboardInputValues))}}}function TZ(e,t,n){var i,a;const r=new Set(n),o=(i=e.sheets)==null?void 0:i.find(c=>c.id===t);return(((a=o==null?void 0:o.document)==null?void 0:a.sections)||[]).flatMap(c=>c.id&&r.has(c.id)&&c.card?[{sectionId:c.id,card:c.card}]:[])}function _0e({inputs:e,context:t,sheetId:n,cardId:r,sectionId:o}){const s=new Map(t.resolvedInputs.map(a=>[a.id,a]));let i={};for(const a of e){const c=s.get(a.id),u=m.materializeDashboardInputRuntimeSlot(a,c==null?void 0:c.slot)||{status:"cleared"};i=m.setDashboardInputRuntimeSlot(i,a,{sheetId:n,cardId:r,sectionId:o},u)}return m.compactDashboardInputValues(i)}function T0e(e){return e==="document"||e==="visual"?"export":"print"}function A1({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,timezone:a}){return m.resolveDashboardInputContext({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,runtimeValues:i,mode:T0e(s),timezone:a})}function DZ(...e){const t={};for(const n of e)n.shared&&(t.shared={...t.shared,...n.shared}),pD(t,"bySheetId",n.bySheetId),pD(t,"byCardId",n.byCardId),pD(t,"byDocumentSectionId",n.byDocumentSectionId);return m.compactDashboardInputValues(t)}function pD(e,t,n){if(n){e[t]||(e[t]={});for(const[r,o]of Object.entries(n))e[t][r]={...e[t][r],...o}}}function EZ(e){var n;return typeof window>"u"||new URLSearchParams(window.location.search).get("isPdfRender")!=="true"?null:((n=kx(e))==null?void 0:n.reportContext)??null}function kx(e){if(typeof window>"u")return e?ji.parsePresentationExecutionSnapshot(e):null;const t=new URLSearchParams(window.location.search);if(t.get("isPdfRender")!=="true")return null;if(e)return ji.parsePresentationExecutionSnapshot(e);const n=t.get("presentationExecutionSnapshot");if(!n)return null;let r;try{r=JSON.parse(n)}catch{throw new ji.PresentationExecutionSnapshotError("Internal print presentation snapshot JSON is invalid.")}return ji.parsePresentationExecutionSnapshot(r)}function rw(){if(typeof window>"u")return;const e=new URLSearchParams(window.location.search).get("presentationAttachmentIndex");if(e===null)return;const t=Number(e);if(!Number.isInteger(t)||t<0)throw new Error("Internal print presentation attachment index is invalid");return t}function D0e(e){return e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e}function E0e(e,t){const n=D0e(e);return n==="dark"?sc({...t==null?void 0:t.default},{...t==null?void 0:t.dark}):t==null?void 0:t.default}function aV(e,t,n){return pve(E0e(e,t),n)}function M0e(e){return es.stableSerialize({hasExplicitDefaultControlValues:e!==void 0,values:e??null})}function R0e(e,t){const{controlContractOverrides:n,cardId:r}=t;if(!n||(n.controlDefinitions!==void 0&&(e.controls=n.controlDefinitions),typeof r!="string"||r.trim().length===0))return e;const o=m.findCardById(e,r);return o&&(n.cardControlDefinitions!==void 0&&(o.controls=n.cardControlDefinitions),n.controlBindings!==void 0&&(o.controlBindings=n.controlBindings)),e}function A0e(e,t){const n=v.useRef({key:t,value:e});return n.current.key!==t&&(n.current={key:t,value:e}),n.current.value}function F0e({customStyle:e,currentTheme:t,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,defaultFilterValues:s,defaultControlValues:i,controlContractOverrides:a,dashboardInputExecutionSnapshot:c,interactionExecutionSnapshot:u,presentationExecutionSnapshot:d,type:f,cardId:h,selectedSheetId:p,onFilterValuesChange:g}){var ge,ee;const{authToken:x,tokenProps:b}=Mt(),y=x==null?void 0:x.accessToken,C=x==null?void 0:x.refreshToken,w=v.useMemo(()=>EZ(d),[d]);o0e();const N=m.useDashboardStore(ce=>ce.selectedLensId),S=m.useDashboardStore(ce=>ce.relaodToken),{data:j,isLoading:k,isFetching:_,isError:T,refetch:I,dashboardIdToFetch:D}=ew(),E=(ge=j==null?void 0:j.dashboard)==null?void 0:ge.id,{getDefaultSheetId:R,clearDefaultSheetId:F}=mZ(E),[M,O]=v.useState(s||[]),z=v.useRef(null),L=v.useRef(null),V=M0e(i),A=$R(a),B=$R(a,{includePresentation:!0}),$=v.useRef(i);$.current=i;const P=v.useRef(V);P.current=V;const U=A0e(a,B),H=v.useRef(null),G=v.useRef(!1),q=v.useRef({dashboardId:null,defaultControlValuesKey:V,controlContractOverridesKey:A}),{setTheme:Y}=BY(),{compiledAppearance:W}=fi.useAppearance(),ne=m.useDashboardStore(ce=>ce.dashboard.globalStyle),Z=v.useMemo(()=>j!=null&&j.dashboard?C0e(R0e(en.cloneDeep(j.dashboard),{controlContractOverrides:U,cardId:h})):void 0,[j==null?void 0:j.dashboard,U,f,h]),{setDashboardWithFilterValues:K,hydrateRuntimeControlValues:X,setStyle:J,setOnSaveFunction:re,setLenses:te,setSelectedLensId:Q,setInlineFilterValuesMap:se}=m.useDashboardActions();m.useDashboardStore(ce=>ce.actions.setCustomCards);const oe=m.useDashboardStore(ce=>ce.filterValues),fe=m.useDashboardStore(ce=>ce.actions.setThemeStyle),pe=m.useDashboardStore(ce=>ce.actions.setDashboardTheme),xe=m.useDashboardStore(ce=>ce.actions.setOnEvent),Ie=m.useDashboardStore(ce=>ce.actions.setOnDashboardLifecycleEvent);v.useEffect(()=>{const ce=L.current;ce&&ce!==D&&m.storeEvents.emit("dashboard:unload"),L.current=D},[D]),v.useEffect(()=>{S&&I()},[I,S]),v.useEffect(()=>{var me;const ce=((me=j==null?void 0:j.dashboard)==null?void 0:me.id)||null,ae=z.current;ce&&ce!==ae&&m.storeEvents.emit("dashboard:load"),z.current=ce},[(ee=j==null?void 0:j.dashboard)==null?void 0:ee.id]),v.useEffect(()=>{pe(W.mode)},[W.mode,pe]),v.useEffect(()=>{t&&Y(t)},[t,Y]);const be=v.useCallback(()=>{const ce=en.cloneDeep(lt.DEFAULT_STYLE),ae=sc(ce,ne);if(e){const me=sc(ae,e),ve=aV(W.mode,me,W);fe(ve),J(me)}else{const me=aV(W.mode,ae,W);fe(me),J(lt.DEFAULT_STYLE)}},[W,e,ne,fe,J]);return v.useEffect(()=>{j&&j.dashboard&&be()},[W.mode,e,ne,be,j]),v.useEffect(()=>{var Bt,ut,$t,Fe,ct,It;function ce(yt,vt){const mt=yt.filters||[],St=[];for(const it of vt){const nt=mt.find(gt=>gt.id===it.filterId);nt&&St.push(en.materializeFilterValueNativeDataType({definition:nt,sourceValue:it,value:{filterId:it.filterId,name:nt.column,operation:it.operation,valueType:m.getFilterValueType(nt),values:it.values,dataType:nt.dataType,fieldMeta:nt.fieldMeta,semanticContext:nt.semanticContext}}))}return St}if(!j||!Z)return;const ae=Z,me=m.useDashboardStore.getState(),ve=me.reportContextSessionAccessToken===y&&((Bt=me.dashboard)==null?void 0:Bt.id)===Z.id&&me.reportContext!==null,_e=w??j.initialReportContext,De=(ve?(ut=me.reportContext)==null?void 0:ut.calendar.tz:void 0)??_e.calendar.tz,{filterValues:Ue,defaultLensId:Ne,lenses:Oe}=j;function ye(){if(Ue&&(Ue==null?void 0:Ue.length)>0)return Ue;const vt=[...m.buildFilterValuesFromDefaults(ae.filters,De)];if(ae.defaultFilterValues&&ae.defaultFilterValues.length>0)for(const it of ae.defaultFilterValues){const nt=vt.findIndex(gt=>gt.filterId===it.filterId);nt>=0?vt[nt]=it:vt.push(it)}const mt=ce(ae,M||[]),St=[...vt];for(const it of mt){const nt=St.findIndex(gt=>gt.filterId===it.filterId);nt>=0?St[nt]=it:St.push(it)}return St}const Be=H.current===Z.id&&(($t=me.dashboard)==null?void 0:$t.id)===Z.id,he=ye(),ue=Be?m.resolveSameDashboardFilterValues({previousFilters:(Fe=me.dashboard)==null?void 0:Fe.filters,nextFilters:ae.filters,currentFilterValues:me.filterValues,defaultFilterValues:he}):he,de=en.materializeFilterValuesNativeDataType({filterDefinitions:ae.filters,filterValues:ue}),Te=m.computeInlineFilterDefaults(ae,De),we=Be&&q.current.controlContractOverridesKey===A?m.flattenRuntimeControlValues({dashboardValues:me.controlValues,cardValuesMap:me.cardControlValuesMap}):$.current,Ee=me.selectedSheetId;let Ke=R(),He=Ee;He&&((ct=Z==null?void 0:Z.sheets)!=null&&ct.some(vt=>vt.id===He)||(He=null)),Ke&&((It=Z==null?void 0:Z.sheets)!=null&&It.some(vt=>vt.id===Ke)||(F(),Ke=null));const qe=w0e({selectedSheetId:p,preservedSelectedSheetId:He,defaultSheetId:Ke,sheets:Z==null?void 0:Z.sheets}),Je=!!c,We=!!(N||j!=null&&j.defaultLensId),bt=!Je&&G.current,pt=c?zR({dashboard:ae,dashboardInputValues:c.dashboardInputValues,sheetId:c.sheetId,cardId:c.cardId}):(j==null?void 0:j.inputValues)!=null?zR({dashboard:ae,dashboardInputValues:j.inputValues.dashboardInputValues}):void 0;K(ae,de||[],we,{selectedSheetId:qe,reportContext:ve?void 0:_e,authToken:y?{accessToken:y,refreshToken:C}:void 0,...j!=null&&j.semanticExecutionPayload?{semanticExecutionPayload:j.semanticExecutionPayload}:{},...c?{dashboardInputValues:pt,dashboardInputReferenceTime:c.generatedAt}:We?{dashboardInputValues:pt||{},dashboardInputReferenceTime:(j==null?void 0:j.inputValues)!=null?j.inputValues.generatedAt:void 0}:bt?{dashboardInputValues:{},dashboardInputReferenceTime:void 0}:{}}),u&&m.useInteractionStore.setState({interactionStates:en.cloneDeep(u)}),G.current=Je,H.current=Z.id,q.current.dashboardId!==Z.id&&(q.current={dashboardId:Z.id,defaultControlValuesKey:P.current,controlContractOverridesKey:A}),se(Te),Oe&&te(Oe),Ne&&Q(Ne)},[j,N,te,K,Q,se,M,p,R,F,A,c,u,Z,y,C,w]),v.useEffect(()=>{if(!(Z!=null&&Z.id))return;const ce=q.current;if(ce.dashboardId!==Z.id){q.current={dashboardId:Z.id,defaultControlValuesKey:V,controlContractOverridesKey:A};return}ce.defaultControlValuesKey===V&&ce.controlContractOverridesKey===A||(X(Z,$.current),q.current={dashboardId:Z.id,defaultControlValuesKey:V,controlContractOverridesKey:A})},[Z,V,A,X]),v.useEffect(()=>{g&&oe&&g(oe)},[oe,g]),v.useEffect(()=>{n&&re(n),r&&xe(r)},[n,re,r,xe]),v.useEffect(()=>(Ie(o),()=>{m.useDashboardStore.getState().onDashboardLifecycleEvent===o&&Ie(void 0)}),[o,Ie]),{isFetching:_,isLoading:k,isError:T,refetch:I}}const FN=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));FN.displayName="Card";const GO=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("flex flex-col space-y-1.5 p-6",e),...t}));GO.displayName="CardHeader";const Ix=ie.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:m.cn("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ix.displayName="CardTitle";const P0e=ie.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:m.cn("text-sm text-muted-foreground",e),...t}));P0e.displayName="CardDescription";const YO=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("px-6 pt-0",e),...t}));YO.displayName="CardContent";const MZ=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("flex items-center p-6 pt-0",e),...t}));MZ.displayName="CardFooter";/**
1
+ "use strict";var Kye=Object.defineProperty;var qB=e=>{throw TypeError(e)};var Wye=(e,t,n)=>t in e?Kye(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Se=(e,t,n)=>Wye(e,typeof t!="symbol"?t+"":t,n),dD=(e,t,n)=>t.has(e)||qB("Cannot "+n);var je=(e,t,n)=>(dD(e,t,"read from private field"),n?n.call(e):t.get(e)),zt=(e,t,n)=>t.has(e)?qB("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),jt=(e,t,n,r)=>(dD(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),rn=(e,t,n)=>(dD(e,t,"access private method"),n);var RC=(e,t,n,r)=>({set _(o){jt(e,t,o,n)},get _(){return je(e,t,r)}});const l=require("react/jsx-runtime"),v=require("react"),Mr=require("react-dom"),m=require("./switch-BytP6QY8.cjs"),Re=require("./x-B6ghREd2.cjs"),lt=require("./constants-vtu7_IUo.cjs"),ze=require("./validators-DVYAnnX0.cjs"),Dv=require("./matrix-operation-contract-D9dLX-Wr.cjs"),Yi=require("../value-format-preferences/index.cjs"),fg=require("./appearance-runtime-provider-Ca8rxO86.cjs"),fi=require("./appearance-context-tNjvTJj3.cjs"),Am=require("./index-C8XCKzB6.cjs"),Gye=require("react-dom/client"),lo=require("./field-aggregations-CDCamEsQ.cjs");require("zod");require("./matrix-continuation-6nhDy-lF.cjs");const Ft=require("./search-BqqhaMx9.cjs"),Yye=require("./color-CyB5o13F.cjs"),Ev=require("./field-dependencies-r_U0CGQ-.cjs"),rt=require("./index-BlYf8gNa.cjs"),en=require("./calculated-field-identity-rMuXuzEY.cjs"),Io=require("./metric-comparison-DBQ3EJTz.cjs"),Dn=require("./pivot-header-presentation-3wqWChFd.cjs"),Xn=require("./matrix-formatter-7GLTcBuy.cjs"),Ji=require("./pivot-result-identity-uTiylUNr.cjs"),un=require("./raw-temporal-BUeTpG76.cjs"),Lt=require("./semantic-format-BhIL1PXP.cjs"),mu=require("./matrix-card-CRXcmAjp.cjs"),_s=require("./matrix-definition-CBJW_4ii.cjs"),ji=require("./pivot-result-lifecycle-DZ0ZSMoM.cjs"),kd=require("../pdf-export-policy/index.cjs"),Ld=require("./source-entity-resolution-CjbgnwyX.cjs"),es=require("./stable-serialize-jqCpyZvd.cjs"),kN=require("./matrix-analytical-definition-Ct5Tu8np.cjs"),Es=require("./matrix-control-sources-CeC5EMyq.cjs"),OY=require("./report-runtime-context-DzvHBPxl.cjs"),Zye=require("./operators-DEfKaU_V.cjs"),IN=require("./matrix-member-presentation-E2B4k3ws.cjs"),Xye=require("./temporal-bucket-4YEPEKlJ.cjs"),Qye=require("./temporal-bucket-contract-ZctiyXYk.cjs"),gR=require("./index-F25jnH0p.cjs"),_N=require("./dashboard-date-comparison-definition-C_w-GO_5.cjs"),LY=require("../dashboard-assistant/index.cjs"),Id=require("./common-types-nBuCd3u2.cjs"),Jye=require("../layouts/index.cjs"),UB=require("./normalize-dashboard-for-dirty-check-BYtBA708.cjs");function OO(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const KB=OO(l),ie=OO(v),xR=OO(Mr);function eve(e){return Lt.toDate(e).getMonth()}function tve(e){return Lt.toDate(e).getFullYear()}function nve(e){const t=Ld.resolveSemaphorPhysicalSourceEntity({entities:e.entities,connectionType:e.connectionType,qualifiedHints:[e.identity.qualifiedEntityName],bareHints:[e.identity.entityName,e.identity.entityId]});return t.kind==="resolved"?t.entity:void 0}function $Y(e,t){const n=t.split(".").pop()||t;return e.fieldMeta&&ze.isDerivedField(e.fieldMeta)?{column:t,nativeDataType:void 0,fieldMeta:void 0}:{column:t,nativeDataType:void 0,...e.fieldMeta?{fieldMeta:{...e.fieldMeta,name:n,qualifiedFieldName:t,nativeDataType:void 0}}:{}}}function rve(e){return e!=null&&e.length?e.every(t=>t.type==="model"?!0:t.type!=="dataset"?!1:t.datasetType!=="physical"):!1}function LO(e){const t=e;return{id:e.id,name:e.name,qualifiedFieldName:e.qualifiedFieldName,qualifiedEntityName:e.qualifiedEntityName,entityName:e.entityName,entityId:e.entityId,entityType:e.entityType,dataType:e.dataType,...e.nativeDataType?{nativeDataType:e.nativeDataType}:{},role:e.role,fieldScope:e.fieldScope,calculationRepresentation:e.calculationRepresentation,calculatedFieldOrigin:e.calculatedFieldOrigin,derivedField:e.derivedField,expression:t.expression,calculatedFormula:t.calculatedFormula}}function $O(e,t,n){if(!e&&!t)return;const r=(e==null?void 0:e.selectedEntities)||[],o=e&&e.mode!=="semanticDomain"&&n&&!ze.isDerivedField(n)&&!rve(r)?[nve({entities:r,connectionType:e.connectionType,identity:n})].filter(s=>!!s):r;return{semanticDomainId:e==null?void 0:e.semanticDomainId,selectedEntities:o,connectionId:(e==null?void 0:e.connectionId)||(t==null?void 0:t.connectionId),connectionType:(e==null?void 0:e.connectionType)||(t==null?void 0:t.connectionType)}}function zY(e,t,n){var s,i,a;const r=(s=t==null?void 0:t.selectedEntities)==null?void 0:s[0];if(r&&typeof r=="object"){const c=r.database;if(typeof c=="string"&&c)return c}return!!(e&&e.mode!=="semanticDomain"&&!ze.isDerivedField(n))||(a=(i=e==null?void 0:e.selectedEntities)==null?void 0:i[0])==null?void 0:a.database}function WB(e){return e!=null&&e.startsWith("card-source-")?e.replace("card-source-",""):e}function qg(e,t){var x,b,y,C,w,N,S;if(!e.fieldMeta)return e.column===t.qualifiedFieldName||e.column===t.name;const n=WB((x=e.fieldMeta)==null?void 0:x.id),r=WB(t.id),o=((b=e.fieldMeta)==null?void 0:b.qualifiedFieldName)||e.column,s=o===t.qualifiedFieldName||o===t.name,i=(y=e.fieldMeta)==null?void 0:y.qualifiedEntityName,a=!i||!t.qualifiedEntityName||i===t.qualifiedEntityName,c=(C=e.fieldMeta)==null?void 0:C.entityId,u=!c||!t.entityId||c===t.entityId,d=(w=e.fieldMeta)==null?void 0:w.fieldScope;if(d&&t.fieldScope&&d!==t.fieldScope)return!1;const f=(N=e.fieldMeta)==null?void 0:N.role;if(f&&t.role&&f!==t.role)return!1;const h=ze.isDerivedField(e.fieldMeta)||ze.isDerivedField(t);if(h&&n&&r&&n===r)return!0;if(!h&&(!a||!u))return!1;const p=(S=e.fieldMeta)==null?void 0:S.expression,g=t.expression;return p||g?s&&a&&u&&p===g:s&&a&&u}var TN={exports:{}};TN.exports;(function(e,t){var n=200,r="__lodash_hash_undefined__",o=800,s=16,i=9007199254740991,a="[object Arguments]",c="[object Array]",u="[object AsyncFunction]",d="[object Boolean]",f="[object Date]",h="[object Error]",p="[object Function]",g="[object GeneratorFunction]",x="[object Map]",b="[object Number]",y="[object Null]",C="[object Object]",w="[object Proxy]",N="[object RegExp]",S="[object Set]",j="[object String]",k="[object Undefined]",_="[object WeakMap]",T="[object ArrayBuffer]",I="[object DataView]",D="[object Float32Array]",E="[object Float64Array]",R="[object Int8Array]",F="[object Int16Array]",M="[object Int32Array]",O="[object Uint8Array]",z="[object Uint8ClampedArray]",L="[object Uint16Array]",V="[object Uint32Array]",A=/[\\^$.*+?()[\]{}|]/g,B=/^\[object .+?Constructor\]$/,$=/^(?:0|[1-9]\d*)$/,P={};P[D]=P[E]=P[R]=P[F]=P[M]=P[O]=P[z]=P[L]=P[V]=!0,P[a]=P[c]=P[T]=P[d]=P[I]=P[f]=P[h]=P[p]=P[x]=P[b]=P[C]=P[N]=P[S]=P[j]=P[_]=!1;var U=typeof lt.commonjsGlobal=="object"&&lt.commonjsGlobal&&lt.commonjsGlobal.Object===Object&&lt.commonjsGlobal,H=typeof self=="object"&&self&&self.Object===Object&&self,G=U||H||Function("return this")(),q=t&&!t.nodeType&&t,Y=q&&!0&&e&&!e.nodeType&&e,W=Y&&Y.exports===q,ne=W&&U.process,Z=function(){try{var Ce=Y&&Y.require&&Y.require("util").types;return Ce||ne&&ne.binding&&ne.binding("util")}catch{}}(),K=Z&&Z.isTypedArray;function X(Ce,Le,Ye){switch(Ye.length){case 0:return Ce.call(Le);case 1:return Ce.call(Le,Ye[0]);case 2:return Ce.call(Le,Ye[0],Ye[1]);case 3:return Ce.call(Le,Ye[0],Ye[1],Ye[2])}return Ce.apply(Le,Ye)}function J(Ce,Le){for(var Ye=-1,Ht=Array(Ce);++Ye<Ce;)Ht[Ye]=Le(Ye);return Ht}function re(Ce){return function(Le){return Ce(Le)}}function te(Ce,Le){return Ce==null?void 0:Ce[Le]}function Q(Ce,Le){return function(Ye){return Ce(Le(Ye))}}var se=Array.prototype,oe=Function.prototype,fe=Object.prototype,pe=G["__core-js_shared__"],xe=oe.toString,Ie=fe.hasOwnProperty,be=function(){var Ce=/[^.]+$/.exec(pe&&pe.keys&&pe.keys.IE_PROTO||"");return Ce?"Symbol(src)_1."+Ce:""}(),ge=fe.toString,ee=xe.call(Object),ce=RegExp("^"+xe.call(Ie).replace(A,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ae=W?G.Buffer:void 0,me=G.Symbol,ve=G.Uint8Array;ae&&ae.allocUnsafe;var _e=Q(Object.getPrototypeOf,Object),De=Object.create,Ue=fe.propertyIsEnumerable,Ne=se.splice,Oe=me?me.toStringTag:void 0,ye=function(){try{var Ce=Wt(Object,"defineProperty");return Ce({},"",{}),Ce}catch{}}(),Be=ae?ae.isBuffer:void 0,he=Math.max,ue=Date.now,de=Wt(G,"Map"),Te=Wt(Object,"create"),we=function(){function Ce(){}return function(Le){if(!ua(Le))return{};if(De)return De(Le);Ce.prototype=Le;var Ye=new Ce;return Ce.prototype=void 0,Ye}}();function Ee(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function Ke(){this.__data__=Te?Te(null):{},this.size=0}function He(Ce){var Le=this.has(Ce)&&delete this.__data__[Ce];return this.size-=Le?1:0,Le}function qe(Ce){var Le=this.__data__;if(Te){var Ye=Le[Ce];return Ye===r?void 0:Ye}return Ie.call(Le,Ce)?Le[Ce]:void 0}function Je(Ce){var Le=this.__data__;return Te?Le[Ce]!==void 0:Ie.call(Le,Ce)}function We(Ce,Le){var Ye=this.__data__;return this.size+=this.has(Ce)?0:1,Ye[Ce]=Te&&Le===void 0?r:Le,this}Ee.prototype.clear=Ke,Ee.prototype.delete=He,Ee.prototype.get=qe,Ee.prototype.has=Je,Ee.prototype.set=We;function bt(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function pt(){this.__data__=[],this.size=0}function Bt(Ce){var Le=this.__data__,Ye=Xe(Le,Ce);if(Ye<0)return!1;var Ht=Le.length-1;return Ye==Ht?Le.pop():Ne.call(Le,Ye,1),--this.size,!0}function ut(Ce){var Le=this.__data__,Ye=Xe(Le,Ce);return Ye<0?void 0:Le[Ye][1]}function $t(Ce){return Xe(this.__data__,Ce)>-1}function Fe(Ce,Le){var Ye=this.__data__,Ht=Xe(Ye,Ce);return Ht<0?(++this.size,Ye.push([Ce,Le])):Ye[Ht][1]=Le,this}bt.prototype.clear=pt,bt.prototype.delete=Bt,bt.prototype.get=ut,bt.prototype.has=$t,bt.prototype.set=Fe;function ct(Ce){var Le=-1,Ye=Ce==null?0:Ce.length;for(this.clear();++Le<Ye;){var Ht=Ce[Le];this.set(Ht[0],Ht[1])}}function It(){this.size=0,this.__data__={hash:new Ee,map:new(de||bt),string:new Ee}}function yt(Ce){var Le=kt(this,Ce).delete(Ce);return this.size-=Le?1:0,Le}function vt(Ce){return kt(this,Ce).get(Ce)}function mt(Ce){return kt(this,Ce).has(Ce)}function St(Ce,Le){var Ye=kt(this,Ce),Ht=Ye.size;return Ye.set(Ce,Le),this.size+=Ye.size==Ht?0:1,this}ct.prototype.clear=It,ct.prototype.delete=yt,ct.prototype.get=vt,ct.prototype.has=mt,ct.prototype.set=St;function it(Ce){var Le=this.__data__=new bt(Ce);this.size=Le.size}function nt(){this.__data__=new bt,this.size=0}function gt(Ce){var Le=this.__data__,Ye=Le.delete(Ce);return this.size=Le.size,Ye}function Vt(Ce){return this.__data__.get(Ce)}function Me(Ce){return this.__data__.has(Ce)}function Qe(Ce,Le){var Ye=this.__data__;if(Ye instanceof bt){var Ht=Ye.__data__;if(!de||Ht.length<n-1)return Ht.push([Ce,Le]),this.size=++Ye.size,this;Ye=this.__data__=new ct(Ht)}return Ye.set(Ce,Le),this.size=Ye.size,this}it.prototype.clear=nt,it.prototype.delete=gt,it.prototype.get=Vt,it.prototype.has=Me,it.prototype.set=Qe;function $e(Ce,Le){var Ye=_r(Ce),Ht=!Ye&&rr(Ce),Bn=!Ye&&!Ht&&Ao(Ce),or=!Ye&&!Ht&&!Bn&&Eb(Ce),Jn=Ye||Ht||Bn||or,On=Jn?J(Ce.length,String):[],vr=On.length;for(var $i in Ce)Jn&&($i=="length"||Bn&&($i=="offset"||$i=="parent")||or&&($i=="buffer"||$i=="byteLength"||$i=="byteOffset")||qs($i,vr))||On.push($i);return On}function le(Ce,Le,Ye){(Ye!==void 0&&!Kt(Ce[Le],Ye)||Ye===void 0&&!(Le in Ce))&&Ot(Ce,Le,Ye)}function Ae(Ce,Le,Ye){var Ht=Ce[Le];(!(Ie.call(Ce,Le)&&Kt(Ht,Ye))||Ye===void 0&&!(Le in Ce))&&Ot(Ce,Le,Ye)}function Xe(Ce,Le){for(var Ye=Ce.length;Ye--;)if(Kt(Ce[Ye][0],Le))return Ye;return-1}function Ot(Ce,Le,Ye){Le=="__proto__"&&ye?ye(Ce,Le,{configurable:!0,enumerable:!0,value:Ye,writable:!0}):Ce[Le]=Ye}var qt=at();function Pt(Ce){return Ce==null?Ce===void 0?k:y:Oe&&Oe in Object(Ce)?fn(Ce):hp(Ce)}function Fn(Ce){return If(Ce)&&Pt(Ce)==a}function ft(Ce){if(!ua(Ce)||qo(Ce))return!1;var Le=Gr(Ce)?ce:B;return Le.test(Pn(Ce))}function Tt(Ce){return If(Ce)&&Ws(Ce.length)&&!!P[Pt(Ce)]}function ke(Ce){if(!ua(Ce))return Ks(Ce);var Le=vs(Ce),Ye=[];for(var Ht in Ce)Ht=="constructor"&&(Le||!Ie.call(Ce,Ht))||Ye.push(Ht);return Ye}function Ve(Ce,Le,Ye,Ht,Bn){Ce!==Le&&qt(Le,function(or,Jn){if(Bn||(Bn=new it),ua(or))dt(Ce,Le,Jn,Ye,Ve,Ht,Bn);else{var On=Ht?Ht(et(Ce,Jn),or,Jn+"",Ce,Le,Bn):void 0;On===void 0&&(On=or),le(Ce,Jn,On)}},mp)}function dt(Ce,Le,Ye,Ht,Bn,or,Jn){var On=et(Ce,Ye),vr=et(Le,Ye),$i=Jn.get(vr);if($i){le(Ce,Ye,$i);return}var rs=or?or(On,vr,Ye+"",Ce,Le,Jn):void 0,_f=rs===void 0;if(_f){var Mb=_r(vr),pp=!Mb&&Ao(vr),MC=!Mb&&!pp&&Eb(vr);rs=vr,Mb||pp||MC?_r(On)?rs=On:mo(On)?rs=Rt(On):pp?(_f=!1,rs=wn(vr)):MC?(_f=!1,rs=ot(vr)):rs=[]:TC(vr)||rr(vr)?(rs=On,rr(On)?rs=lD(On):(!ua(On)||Gr(On))&&(rs=qr(vr))):_f=!1}_f&&(Jn.set(vr,rs),Bn(rs,vr,Ht,or,Jn),Jn.delete(vr)),le(Ce,Ye,rs)}function _t(Ce,Le){return hn(Ku(Ce,Le,EC),Ce+"")}var Xt=ye?function(Ce,Le){return ye(Ce,"toString",{configurable:!0,enumerable:!1,value:cD(Le),writable:!0})}:EC;function wn(Ce,Le){return Ce.slice()}function cn(Ce){var Le=new Ce.constructor(Ce.byteLength);return new ve(Le).set(new ve(Ce)),Le}function ot(Ce,Le){var Ye=cn(Ce.buffer);return new Ce.constructor(Ye,Ce.byteOffset,Ce.length)}function Rt(Ce,Le){var Ye=-1,Ht=Ce.length;for(Le||(Le=Array(Ht));++Ye<Ht;)Le[Ye]=Ce[Ye];return Le}function Pe(Ce,Le,Ye,Ht){var Bn=!Ye;Ye||(Ye={});for(var or=-1,Jn=Le.length;++or<Jn;){var On=Le[or],vr=void 0;vr===void 0&&(vr=Ce[On]),Bn?Ot(Ye,On,vr):Ae(Ye,On,vr)}return Ye}function Ge(Ce){return _t(function(Le,Ye){var Ht=-1,Bn=Ye.length,or=Bn>1?Ye[Bn-1]:void 0,Jn=Bn>2?Ye[2]:void 0;for(or=Ce.length>3&&typeof or=="function"?(Bn--,or):void 0,Jn&&Us(Ye[0],Ye[1],Jn)&&(or=Bn<3?void 0:or,Bn=1),Le=Object(Le);++Ht<Bn;){var On=Ye[Ht];On&&Ce(Le,On,Ht,or)}return Le})}function at(Ce){return function(Le,Ye,Ht){for(var Bn=-1,or=Object(Le),Jn=Ht(Le),On=Jn.length;On--;){var vr=Jn[++Bn];if(Ye(or[vr],vr,or)===!1)break}return Le}}function kt(Ce,Le){var Ye=Ce.__data__;return Va(Le)?Ye[typeof Le=="string"?"string":"hash"]:Ye.map}function Wt(Ce,Le){var Ye=te(Ce,Le);return ft(Ye)?Ye:void 0}function fn(Ce){var Le=Ie.call(Ce,Oe),Ye=Ce[Oe];try{Ce[Oe]=void 0;var Ht=!0}catch{}var Bn=ge.call(Ce);return Ht&&(Le?Ce[Oe]=Ye:delete Ce[Oe]),Bn}function qr(Ce){return typeof Ce.constructor=="function"&&!vs(Ce)?we(_e(Ce)):{}}function qs(Ce,Le){var Ye=typeof Ce;return Le=Le??i,!!Le&&(Ye=="number"||Ye!="symbol"&&$.test(Ce))&&Ce>-1&&Ce%1==0&&Ce<Le}function Us(Ce,Le,Ye){if(!ua(Ye))return!1;var Ht=typeof Le;return(Ht=="number"?vo(Ye)&&qs(Le,Ye.length):Ht=="string"&&Le in Ye)?Kt(Ye[Le],Ce):!1}function Va(Ce){var Le=typeof Ce;return Le=="string"||Le=="number"||Le=="symbol"||Le=="boolean"?Ce!=="__proto__":Ce===null}function qo(Ce){return!!be&&be in Ce}function vs(Ce){var Le=Ce&&Ce.constructor,Ye=typeof Le=="function"&&Le.prototype||fe;return Ce===Ye}function Ks(Ce){var Le=[];if(Ce!=null)for(var Ye in Object(Ce))Le.push(Ye);return Le}function hp(Ce){return ge.call(Ce)}function Ku(Ce,Le,Ye){return Le=he(Le===void 0?Ce.length-1:Le,0),function(){for(var Ht=arguments,Bn=-1,or=he(Ht.length-Le,0),Jn=Array(or);++Bn<or;)Jn[Bn]=Ht[Le+Bn];Bn=-1;for(var On=Array(Le+1);++Bn<Le;)On[Bn]=Ht[Bn];return On[Le]=Ye(Jn),X(Ce,this,On)}}function et(Ce,Le){if(!(Le==="constructor"&&typeof Ce[Le]=="function")&&Le!="__proto__")return Ce[Le]}var hn=Gt(Xt);function Gt(Ce){var Le=0,Ye=0;return function(){var Ht=ue(),Bn=s-(Ht-Ye);if(Ye=Ht,Bn>0){if(++Le>=o)return arguments[0]}else Le=0;return Ce.apply(void 0,arguments)}}function Pn(Ce){if(Ce!=null){try{return xe.call(Ce)}catch{}try{return Ce+""}catch{}}return""}function Kt(Ce,Le){return Ce===Le||Ce!==Ce&&Le!==Le}var rr=Fn(function(){return arguments}())?Fn:function(Ce){return If(Ce)&&Ie.call(Ce,"callee")&&!Ue.call(Ce,"callee")},_r=Array.isArray;function vo(Ce){return Ce!=null&&Ws(Ce.length)&&!Gr(Ce)}function mo(Ce){return If(Ce)&&vo(Ce)}var Ao=Be||uD;function Gr(Ce){if(!ua(Ce))return!1;var Le=Pt(Ce);return Le==p||Le==g||Le==u||Le==w}function Ws(Ce){return typeof Ce=="number"&&Ce>-1&&Ce%1==0&&Ce<=i}function ua(Ce){var Le=typeof Ce;return Ce!=null&&(Le=="object"||Le=="function")}function If(Ce){return Ce!=null&&typeof Ce=="object"}function TC(Ce){if(!If(Ce)||Pt(Ce)!=C)return!1;var Le=_e(Ce);if(Le===null)return!0;var Ye=Ie.call(Le,"constructor")&&Le.constructor;return typeof Ye=="function"&&Ye instanceof Ye&&xe.call(Ye)==ee}var Eb=K?re(K):Tt;function lD(Ce){return Pe(Ce,mp(Ce))}function mp(Ce){return vo(Ce)?$e(Ce):ke(Ce)}var DC=Ge(function(Ce,Le,Ye){Ve(Ce,Le,Ye)});function cD(Ce){return function(){return Ce}}function EC(Ce){return Ce}function uD(){return!1}e.exports=DC})(TN,TN.exports);var ove=TN.exports;const sc=lt.getDefaultExportFromCjs(ove),BY=()=>{const e=v.useContext(fg.ThemeProviderContext);if(e===void 0)throw new Error("useTheme must be used within a ThemeProvider");return e},VY="__semaphorAuthoredFontFamily";var SY,NY;const sve=(NY=(SY=lt.DEFAULT_STYLE.default.chart)==null?void 0:SY.font)==null?void 0:NY.family,ive=new Set([sve,"Open Sans, Arial, sans-serif",'"Open Sans", Arial, sans-serif'].filter(Boolean));function ave(e,t){if(!e)return t?{family:t}:void 0;const{[VY]:n,...r}=e,o=lve(r.family,t,!!n);return{...r,...o?{family:o}:void 0}}function lve(e,t,n=!1){return n&&e||e&&!cve(e)?e:t||e}function cve(e){return ive.has(e.trim())}function uve(e,t){if(!t)return e;const n={...e,font:ba(e.font,t)},r=hve(e.plugins,t);r&&(n.plugins=r);const o=mve(e.scales,t);return o&&(n.scales=o),n}function dve(e,t){return!e||!t?e:e.map(n=>{if(!n||typeof n!="object")return n;const r=n,o=r.datalabels;return!o||typeof o!="object"?n:{...r,datalabels:{...o,font:ba(o.font,t)}}})}function fve(e,t){if(!e||typeof e!="object"||!t)return e;const n=e.datasets;return Array.isArray(n)?{...e,datasets:dve(n,t)}:e}function hve(e,t){var n;return e&&{...e,title:e.title?{...e.title,font:ba(e.title.font,t)}:e.title,subtitle:e.subtitle?{...e.subtitle,font:ba(e.subtitle.font,t)}:e.subtitle,legend:e.legend?{...e.legend,labels:e.legend.labels?{...e.legend.labels,font:ba(e.legend.labels.font,t)}:e.legend.labels}:e.legend,tooltip:e.tooltip?{...e.tooltip,titleFont:ba(e.tooltip.titleFont,t),bodyFont:ba(e.tooltip.bodyFont,t),footerFont:ba(e.tooltip.footerFont,t)}:e.tooltip,datalabels:e.datalabels?{...e.datalabels,font:ba((n=e.datalabels)==null?void 0:n.font,t)}:e.datalabels}}function mve(e,t){return e&&Object.entries(e).reduce((n,[r,o])=>{if(!o||typeof o!="object")return n[r]=o,n;const s=o;return n[r]={...s,ticks:s.ticks?{...s.ticks,font:ba(s.ticks.font,t)}:s.ticks,title:s.title?{...s.title,font:ba(s.title.font,t)}:s.title,pointLabels:s.pointLabels?{...s.pointLabels,font:ba(s.pointLabels.font,t)}:s.pointLabels},n},{})}function ba(e,t){return typeof e=="function"?e:{...t,...e&&typeof e=="object"?e:{}}}function pve(e,t){const n=en.cloneDeep(e??{}),r=gve(t);if(!r)return n;const o=sc(n,r);return yve(o,r),o}function gve(e){var h,p,g,x;const t=(h=e.scheme.components)==null?void 0:h.chart,n=Am.SEMAPHOR_DEFAULT_APPEARANCE_SPEC.schemes[e.mode],r=(p=n.components)==null?void 0:p.chart,o=(g=n.tokens)==null?void 0:g.typography,s={};bve(t==null?void 0:t.palette,r==null?void 0:r.palette)&&(s.dataset={backgroundColor:[...t.palette],borderColor:[...t.palette]});const i=(x=e.scheme.tokens)==null?void 0:x.typography,a=gp(i==null?void 0:i.fontFamily,o==null?void 0:o.fontFamily),c=gp(i==null?void 0:i.baseFontSize,o==null?void 0:o.baseFontSize);if(a||c!==void 0){const b={...a?{family:a}:void 0,...c!==void 0?{size:c}:void 0};a&&(b[VY]=!0),s.font=b}const u=gp(t==null?void 0:t.gridColor,r==null?void 0:r.gridColor),d=gp(t==null?void 0:t.axisColor,r==null?void 0:r.axisColor)??gp(t==null?void 0:t.foreground,r==null?void 0:r.foreground);(u||d)&&(s.options={scales:{x:fD({gridColor:u,axisColor:d}),y:fD({gridColor:u,axisColor:d}),y2:fD({gridColor:u,axisColor:d}),r:xve({gridColor:u,axisColor:d})}});const f=gp(t==null?void 0:t.foreground,r==null?void 0:r.foreground);return f&&(s.options=sc(s.options??{},{plugins:{legend:{labels:{color:f}}}})),Object.keys(s).length>0?{chart:s}:void 0}function fD({gridColor:e,axisColor:t}){return{...e?{grid:{color:e}}:void 0,...t?{ticks:{color:t},title:{color:t}}:void 0}}function xve({gridColor:e,axisColor:t}){return{...e?{grid:{color:e},angleLines:{color:e}}:void 0,...t?{ticks:{color:t},title:{color:t},pointLabels:{color:t}}:void 0}}function bve(e,t){return e!=null&&e.length?!(t!=null&&t.length)||e.length!==t.length?!0:e.some((n,r)=>n!==t[r]):!1}function gp(e,t){return e!==void 0&&e!==t?e:void 0}function yve(e,t){var r;const n=(r=t.chart)==null?void 0:r.dataset;n&&(e.chart=e.chart??{},e.chart.dataset=e.chart.dataset??{},Array.isArray(n.backgroundColor)&&(e.chart.dataset.backgroundColor=[...n.backgroundColor]),Array.isArray(n.borderColor)&&(e.chart.dataset.borderColor=[...n.borderColor]))}var Fm=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},vve={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),setInterval:(e,t)=>setInterval(e,t),clearInterval:e=>clearInterval(e)},$l,Ch,jY,wve=(jY=class{constructor(){zt(this,$l,vve);zt(this,Ch,!1)}setTimeoutProvider(e){process.env.NODE_ENV!=="production"&&je(this,Ch)&&e!==je(this,$l)&&console.error("[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.",{previous:je(this,$l),provider:e}),jt(this,$l,e),process.env.NODE_ENV!=="production"&&jt(this,Ch,!1)}setTimeout(e,t){return process.env.NODE_ENV!=="production"&&jt(this,Ch,!0),je(this,$l).setTimeout(e,t)}clearTimeout(e){je(this,$l).clearTimeout(e)}setInterval(e,t){return process.env.NODE_ENV!=="production"&&jt(this,Ch,!0),je(this,$l).setInterval(e,t)}clearInterval(e){je(this,$l).clearInterval(e)}},$l=new WeakMap,Ch=new WeakMap,jY),lh=new wve;function Cve(e){setTimeout(e,0)}var Xh=typeof window>"u"||"Deno"in globalThis;function Is(){}function Sve(e,t){return typeof e=="function"?e(t):e}function bR(e){return typeof e=="number"&&e>=0&&e!==1/0}function HY(e,t){return Math.max(e+(t||0)-Date.now(),0)}function _d(e,t){return typeof e=="function"?e(t):e}function ya(e,t){return typeof e=="function"?e(t):e}function GB(e,t){const{type:n="all",exact:r,fetchStatus:o,predicate:s,queryKey:i,stale:a}=e;if(i){if(r){if(t.queryHash!==zO(i,t.options))return!1}else if(!Mv(t.queryKey,i))return!1}if(n!=="all"){const c=t.isActive();if(n==="active"&&!c||n==="inactive"&&c)return!1}return!(typeof a=="boolean"&&t.isStale()!==a||o&&o!==t.state.fetchStatus||s&&!s(t))}function YB(e,t){const{exact:n,status:r,predicate:o,mutationKey:s}=e;if(s){if(!t.options.mutationKey)return!1;if(n){if(pu(t.options.mutationKey)!==pu(s))return!1}else if(!Mv(t.options.mutationKey,s))return!1}return!(r&&t.state.status!==r||o&&!o(t))}function zO(e,t){return((t==null?void 0:t.queryKeyHashFn)||pu)(e)}function pu(e){return JSON.stringify(e,(t,n)=>yR(n)?Object.keys(n).sort().reduce((r,o)=>(r[o]=n[o],r),{}):n)}function Mv(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?Object.keys(t).every(n=>Mv(e[n],t[n])):!1}var Nve=Object.prototype.hasOwnProperty;function DN(e,t){if(e===t)return e;const n=ZB(e)&&ZB(t);if(!n&&!(yR(e)&&yR(t)))return t;const o=(n?e:Object.keys(e)).length,s=n?t:Object.keys(t),i=s.length,a=n?new Array(i):{};let c=0;for(let u=0;u<i;u++){const d=n?u:s[u],f=e[d],h=t[d];if(f===h){a[d]=f,(n?u<o:Nve.call(e,d))&&c++;continue}if(f===null||h===null||typeof f!="object"||typeof h!="object"){a[d]=h;continue}const p=DN(f,h);a[d]=p,p===f&&c++}return o===i&&c===o?e:a}function Rv(e,t){if(!t||Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in e)if(e[n]!==t[n])return!1;return!0}function ZB(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function yR(e){if(!XB(e))return!1;const t=e.constructor;if(t===void 0)return!0;const n=t.prototype;return!(!XB(n)||!n.hasOwnProperty("isPrototypeOf")||Object.getPrototypeOf(e)!==Object.prototype)}function XB(e){return Object.prototype.toString.call(e)==="[object Object]"}function jve(e){return new Promise(t=>{lh.setTimeout(t,e)})}function vR(e,t,n){if(typeof n.structuralSharing=="function")return n.structuralSharing(e,t);if(n.structuralSharing!==!1){if(process.env.NODE_ENV!=="production")try{return DN(e,t)}catch(r){throw console.error(`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${n.queryHash}]: ${r}`),r}return DN(e,t)}return t}function kve(e,t,n=0){const r=[...e,t];return n&&r.length>n?r.slice(1):r}function Ive(e,t,n=0){const r=[t,...e];return n&&r.length>n?r.slice(0,-1):r}var EN=Symbol();function qY(e,t){return process.env.NODE_ENV!=="production"&&e.queryFn===EN&&console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${e.queryHash}'`),!e.queryFn&&(t!=null&&t.initialPromise)?()=>t.initialPromise:!e.queryFn||e.queryFn===EN?()=>Promise.reject(new Error(`Missing queryFn: '${e.queryHash}'`)):e.queryFn}function UY(e,t){return typeof e=="function"?e(...t):!!e}var Sh,od,Dg,kY,_ve=(kY=class extends Fm{constructor(){super();zt(this,Sh);zt(this,od);zt(this,Dg);jt(this,Dg,t=>{if(!Xh&&window.addEventListener){const n=()=>t();return window.addEventListener("visibilitychange",n,!1),()=>{window.removeEventListener("visibilitychange",n)}}})}onSubscribe(){je(this,od)||this.setEventListener(je(this,Dg))}onUnsubscribe(){var t;this.hasListeners()||((t=je(this,od))==null||t.call(this),jt(this,od,void 0))}setEventListener(t){var n;jt(this,Dg,t),(n=je(this,od))==null||n.call(this),jt(this,od,t(r=>{typeof r=="boolean"?this.setFocused(r):this.onFocus()}))}setFocused(t){je(this,Sh)!==t&&(jt(this,Sh,t),this.onFocus())}onFocus(){const t=this.isFocused();this.listeners.forEach(n=>{n(t)})}isFocused(){var t;return typeof je(this,Sh)=="boolean"?je(this,Sh):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},Sh=new WeakMap,od=new WeakMap,Dg=new WeakMap,kY),iI=new _ve;function wR(){let e,t;const n=new Promise((o,s)=>{e=o,t=s});n.status="pending",n.catch(()=>{});function r(o){Object.assign(n,o),delete n.resolve,delete n.reject}return n.resolve=o=>{r({status:"fulfilled",value:o}),e(o)},n.reject=o=>{r({status:"rejected",reason:o}),t(o)},n}var Tve=Cve;function Dve(){let e=[],t=0,n=a=>{a()},r=a=>{a()},o=Tve;const s=a=>{t?e.push(a):o(()=>{n(a)})},i=()=>{const a=e;e=[],a.length&&o(()=>{r(()=>{a.forEach(c=>{n(c)})})})};return{batch:a=>{let c;t++;try{c=a()}finally{t--,t||i()}return c},batchCalls:a=>(...c)=>{s(()=>{a(...c)})},schedule:s,setNotifyFunction:a=>{n=a},setBatchNotifyFunction:a=>{r=a},setScheduler:a=>{o=a}}}var Qr=Dve(),Eg,sd,Mg,IY,Eve=(IY=class extends Fm{constructor(){super();zt(this,Eg,!0);zt(this,sd);zt(this,Mg);jt(this,Mg,t=>{if(!Xh&&window.addEventListener){const n=()=>t(!0),r=()=>t(!1);return window.addEventListener("online",n,!1),window.addEventListener("offline",r,!1),()=>{window.removeEventListener("online",n),window.removeEventListener("offline",r)}}})}onSubscribe(){je(this,sd)||this.setEventListener(je(this,Mg))}onUnsubscribe(){var t;this.hasListeners()||((t=je(this,sd))==null||t.call(this),jt(this,sd,void 0))}setEventListener(t){var n;jt(this,Mg,t),(n=je(this,sd))==null||n.call(this),jt(this,sd,t(this.setOnline.bind(this)))}setOnline(t){je(this,Eg)!==t&&(jt(this,Eg,t),this.listeners.forEach(r=>{r(t)}))}isOnline(){return je(this,Eg)}},Eg=new WeakMap,sd=new WeakMap,Mg=new WeakMap,IY),Av=new Eve;function Mve(e){return Math.min(1e3*2**e,3e4)}function KY(e){return(e??"online")==="online"?Av.isOnline():!0}var CR=class extends Error{constructor(e){super("CancelledError"),this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function WY(e){let t=!1,n=0,r;const o=wR(),s=()=>o.status!=="pending",i=x=>{var b;if(!s()){const y=new CR(x);h(y),(b=e.onCancel)==null||b.call(e,y)}},a=()=>{t=!0},c=()=>{t=!1},u=()=>iI.isFocused()&&(e.networkMode==="always"||Av.isOnline())&&e.canRun(),d=()=>KY(e.networkMode)&&e.canRun(),f=x=>{s()||(r==null||r(),o.resolve(x))},h=x=>{s()||(r==null||r(),o.reject(x))},p=()=>new Promise(x=>{var b;r=y=>{(s()||u())&&x(y)},(b=e.onPause)==null||b.call(e)}).then(()=>{var x;r=void 0,s()||(x=e.onContinue)==null||x.call(e)}),g=()=>{if(s())return;let x;const b=n===0?e.initialPromise:void 0;try{x=b??e.fn()}catch(y){x=Promise.reject(y)}Promise.resolve(x).then(f).catch(y=>{var j;if(s())return;const C=e.retry??(Xh?0:3),w=e.retryDelay??Mve,N=typeof w=="function"?w(n,y):w,S=C===!0||typeof C=="number"&&n<C||typeof C=="function"&&C(n,y);if(t||!S){h(y);return}n++,(j=e.onFail)==null||j.call(e,n,y),jve(N).then(()=>u()?void 0:p()).then(()=>{t?h(y):g()})})};return{promise:o,status:()=>o.status,cancel:i,continue:()=>(r==null||r(),o),cancelRetry:a,continueRetry:c,canStart:d,start:()=>(d()?g():p().then(g),o)}}var Nh,_Y,GY=(_Y=class{constructor(){zt(this,Nh)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),bR(this.gcTime)&&jt(this,Nh,lh.setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Xh?1/0:5*60*1e3))}clearGcTimeout(){je(this,Nh)&&(lh.clearTimeout(je(this,Nh)),jt(this,Nh,void 0))}},Nh=new WeakMap,_Y),jh,Rg,ga,kh,Uo,U0,Ih,Ka,Tc,TY,Rve=(TY=class extends GY{constructor(t){super();zt(this,Ka);zt(this,jh);zt(this,Rg);zt(this,ga);zt(this,kh);zt(this,Uo);zt(this,U0);zt(this,Ih);jt(this,Ih,!1),jt(this,U0,t.defaultOptions),this.setOptions(t.options),this.observers=[],jt(this,kh,t.client),jt(this,ga,je(this,kh).getQueryCache()),this.queryKey=t.queryKey,this.queryHash=t.queryHash,jt(this,jh,JB(this.options)),this.state=t.state??je(this,jh),this.scheduleGc()}get meta(){return this.options.meta}get promise(){var t;return(t=je(this,Uo))==null?void 0:t.promise}setOptions(t){if(this.options={...je(this,U0),...t},this.updateGcTime(this.options.gcTime),this.state&&this.state.data===void 0){const n=JB(this.options);n.data!==void 0&&(this.setState(QB(n.data,n.dataUpdatedAt)),jt(this,jh,n))}}optionalRemove(){!this.observers.length&&this.state.fetchStatus==="idle"&&je(this,ga).remove(this)}setData(t,n){const r=vR(this.state.data,t,this.options);return rn(this,Ka,Tc).call(this,{data:r,type:"success",dataUpdatedAt:n==null?void 0:n.updatedAt,manual:n==null?void 0:n.manual}),r}setState(t,n){rn(this,Ka,Tc).call(this,{type:"setState",state:t,setStateOptions:n})}cancel(t){var r,o;const n=(r=je(this,Uo))==null?void 0:r.promise;return(o=je(this,Uo))==null||o.cancel(t),n?n.then(Is).catch(Is):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(je(this,jh))}isActive(){return this.observers.some(t=>ya(t.options.enabled,this)!==!1)}isDisabled(){return this.getObserversCount()>0?!this.isActive():this.options.queryFn===EN||this.state.dataUpdateCount+this.state.errorUpdateCount===0}isStatic(){return this.getObserversCount()>0?this.observers.some(t=>_d(t.options.staleTime,this)==="static"):!1}isStale(){return this.getObserversCount()>0?this.observers.some(t=>t.getCurrentResult().isStale):this.state.data===void 0||this.state.isInvalidated}isStaleByTime(t=0){return this.state.data===void 0?!0:t==="static"?!1:this.state.isInvalidated?!0:!HY(this.state.dataUpdatedAt,t)}onFocus(){var n;const t=this.observers.find(r=>r.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(n=je(this,Uo))==null||n.continue()}onOnline(){var n;const t=this.observers.find(r=>r.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(n=je(this,Uo))==null||n.continue()}addObserver(t){this.observers.includes(t)||(this.observers.push(t),this.clearGcTimeout(),je(this,ga).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){this.observers.includes(t)&&(this.observers=this.observers.filter(n=>n!==t),this.observers.length||(je(this,Uo)&&(je(this,Ih)?je(this,Uo).cancel({revert:!0}):je(this,Uo).cancelRetry()),this.scheduleGc()),je(this,ga).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return this.observers.length}invalidate(){this.state.isInvalidated||rn(this,Ka,Tc).call(this,{type:"invalidate"})}async fetch(t,n){var c,u,d,f,h,p,g,x,b,y,C,w;if(this.state.fetchStatus!=="idle"&&((c=je(this,Uo))==null?void 0:c.status())!=="rejected"){if(this.state.data!==void 0&&(n!=null&&n.cancelRefetch))this.cancel({silent:!0});else if(je(this,Uo))return je(this,Uo).continueRetry(),je(this,Uo).promise}if(t&&this.setOptions(t),!this.options.queryFn){const N=this.observers.find(S=>S.options.queryFn);N&&this.setOptions(N.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const r=new AbortController,o=N=>{Object.defineProperty(N,"signal",{enumerable:!0,get:()=>(jt(this,Ih,!0),r.signal)})},s=()=>{const N=qY(this.options,n),j=(()=>{const k={client:je(this,kh),queryKey:this.queryKey,meta:this.meta};return o(k),k})();return jt(this,Ih,!1),this.options.persister?this.options.persister(N,j,this):N(j)},a=(()=>{const N={fetchOptions:n,options:this.options,queryKey:this.queryKey,client:je(this,kh),state:this.state,fetchFn:s};return o(N),N})();(u=this.options.behavior)==null||u.onFetch(a,this),jt(this,Rg,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((d=a.fetchOptions)==null?void 0:d.meta))&&rn(this,Ka,Tc).call(this,{type:"fetch",meta:(f=a.fetchOptions)==null?void 0:f.meta}),jt(this,Uo,WY({initialPromise:n==null?void 0:n.initialPromise,fn:a.fetchFn,onCancel:N=>{N instanceof CR&&N.revert&&this.setState({...je(this,Rg),fetchStatus:"idle"}),r.abort()},onFail:(N,S)=>{rn(this,Ka,Tc).call(this,{type:"failed",failureCount:N,error:S})},onPause:()=>{rn(this,Ka,Tc).call(this,{type:"pause"})},onContinue:()=>{rn(this,Ka,Tc).call(this,{type:"continue"})},retry:a.options.retry,retryDelay:a.options.retryDelay,networkMode:a.options.networkMode,canRun:()=>!0}));try{const N=await je(this,Uo).start();if(N===void 0)throw process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),new Error(`${this.queryHash} data is undefined`);return this.setData(N),(p=(h=je(this,ga).config).onSuccess)==null||p.call(h,N,this),(x=(g=je(this,ga).config).onSettled)==null||x.call(g,N,this.state.error,this),N}catch(N){if(N instanceof CR){if(N.silent)return je(this,Uo).promise;if(N.revert){if(this.state.data===void 0)throw N;return this.state.data}}throw rn(this,Ka,Tc).call(this,{type:"error",error:N}),(y=(b=je(this,ga).config).onError)==null||y.call(b,N,this),(w=(C=je(this,ga).config).onSettled)==null||w.call(C,this.state.data,N,this),N}finally{this.scheduleGc()}}},jh=new WeakMap,Rg=new WeakMap,ga=new WeakMap,kh=new WeakMap,Uo=new WeakMap,U0=new WeakMap,Ih=new WeakMap,Ka=new WeakSet,Tc=function(t){const n=r=>{switch(t.type){case"failed":return{...r,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...r,fetchStatus:"paused"};case"continue":return{...r,fetchStatus:"fetching"};case"fetch":return{...r,...YY(r.data,this.options),fetchMeta:t.meta??null};case"success":const o={...r,...QB(t.data,t.dataUpdatedAt),dataUpdateCount:r.dataUpdateCount+1,...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};return jt(this,Rg,t.manual?o:void 0),o;case"error":const s=t.error;return{...r,error:s,errorUpdateCount:r.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:r.fetchFailureCount+1,fetchFailureReason:s,fetchStatus:"idle",status:"error"};case"invalidate":return{...r,isInvalidated:!0};case"setState":return{...r,...t.state}}};this.state=n(this.state),Qr.batch(()=>{this.observers.forEach(r=>{r.onQueryUpdate()}),je(this,ga).notify({query:this,type:"updated",action:t})})},TY);function YY(e,t){return{fetchFailureCount:0,fetchFailureReason:null,fetchStatus:KY(t.networkMode)?"fetching":"paused",...e===void 0&&{error:null,status:"pending"}}}function QB(e,t){return{data:e,dataUpdatedAt:t??Date.now(),error:null,isInvalidated:!1,status:"success"}}function JB(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,n=t!==void 0,r=n?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:n?r??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:n?"success":"pending",fetchStatus:"idle"}}var Ci,Vn,K0,ei,_h,Ag,Lc,id,W0,Fg,Pg,Th,Dh,ad,Og,ur,wy,SR,NR,jR,kR,IR,_R,TR,ZY,DY,aI=(DY=class extends Fm{constructor(t,n){super();zt(this,ur);zt(this,Ci);zt(this,Vn);zt(this,K0);zt(this,ei);zt(this,_h);zt(this,Ag);zt(this,Lc);zt(this,id);zt(this,W0);zt(this,Fg);zt(this,Pg);zt(this,Th);zt(this,Dh);zt(this,ad);zt(this,Og,new Set);this.options=n,jt(this,Ci,t),jt(this,id,null),jt(this,Lc,wR()),this.bindMethods(),this.setOptions(n)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(je(this,Vn).addObserver(this),eV(je(this,Vn),this.options)?rn(this,ur,wy).call(this):this.updateResult(),rn(this,ur,kR).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return DR(je(this,Vn),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return DR(je(this,Vn),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,rn(this,ur,IR).call(this),rn(this,ur,_R).call(this),je(this,Vn).removeObserver(this)}setOptions(t){const n=this.options,r=je(this,Vn);if(this.options=je(this,Ci).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof ya(this.options.enabled,je(this,Vn))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");rn(this,ur,TR).call(this),je(this,Vn).setOptions(this.options),n._defaulted&&!Rv(this.options,n)&&je(this,Ci).getQueryCache().notify({type:"observerOptionsUpdated",query:je(this,Vn),observer:this});const o=this.hasListeners();o&&tV(je(this,Vn),r,this.options,n)&&rn(this,ur,wy).call(this),this.updateResult(),o&&(je(this,Vn)!==r||ya(this.options.enabled,je(this,Vn))!==ya(n.enabled,je(this,Vn))||_d(this.options.staleTime,je(this,Vn))!==_d(n.staleTime,je(this,Vn)))&&rn(this,ur,SR).call(this);const s=rn(this,ur,NR).call(this);o&&(je(this,Vn)!==r||ya(this.options.enabled,je(this,Vn))!==ya(n.enabled,je(this,Vn))||s!==je(this,ad))&&rn(this,ur,jR).call(this,s)}getOptimisticResult(t){const n=je(this,Ci).getQueryCache().build(je(this,Ci),t),r=this.createResult(n,t);return Fve(this,r)&&(jt(this,ei,r),jt(this,Ag,this.options),jt(this,_h,je(this,Vn).state)),r}getCurrentResult(){return je(this,ei)}trackResult(t,n){return new Proxy(t,{get:(r,o)=>(this.trackProp(o),n==null||n(o),o==="promise"&&(this.trackProp("data"),!this.options.experimental_prefetchInRender&&je(this,Lc).status==="pending"&&je(this,Lc).reject(new Error("experimental_prefetchInRender feature flag is not enabled"))),Reflect.get(r,o))})}trackProp(t){je(this,Og).add(t)}getCurrentQuery(){return je(this,Vn)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const n=je(this,Ci).defaultQueryOptions(t),r=je(this,Ci).getQueryCache().build(je(this,Ci),n);return r.fetch().then(()=>this.createResult(r,n))}fetch(t){return rn(this,ur,wy).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),je(this,ei)))}createResult(t,n){var T;const r=je(this,Vn),o=this.options,s=je(this,ei),i=je(this,_h),a=je(this,Ag),u=t!==r?t.state:je(this,K0),{state:d}=t;let f={...d},h=!1,p;if(n._optimisticResults){const I=this.hasListeners(),D=!I&&eV(t,n),E=I&&tV(t,r,n,o);(D||E)&&(f={...f,...YY(d.data,t.options)}),n._optimisticResults==="isRestoring"&&(f.fetchStatus="idle")}let{error:g,errorUpdatedAt:x,status:b}=f;p=f.data;let y=!1;if(n.placeholderData!==void 0&&p===void 0&&b==="pending"){let I;s!=null&&s.isPlaceholderData&&n.placeholderData===(a==null?void 0:a.placeholderData)?(I=s.data,y=!0):I=typeof n.placeholderData=="function"?n.placeholderData((T=je(this,Pg))==null?void 0:T.state.data,je(this,Pg)):n.placeholderData,I!==void 0&&(b="success",p=vR(s==null?void 0:s.data,I,n),h=!0)}if(n.select&&p!==void 0&&!y)if(s&&p===(i==null?void 0:i.data)&&n.select===je(this,W0))p=je(this,Fg);else try{jt(this,W0,n.select),p=n.select(p),p=vR(s==null?void 0:s.data,p,n),jt(this,Fg,p),jt(this,id,null)}catch(I){jt(this,id,I)}je(this,id)&&(g=je(this,id),p=je(this,Fg),x=Date.now(),b="error");const C=f.fetchStatus==="fetching",w=b==="pending",N=b==="error",S=w&&C,j=p!==void 0,_={status:b,fetchStatus:f.fetchStatus,isPending:w,isSuccess:b==="success",isError:N,isInitialLoading:S,isLoading:S,data:p,dataUpdatedAt:f.dataUpdatedAt,error:g,errorUpdatedAt:x,failureCount:f.fetchFailureCount,failureReason:f.fetchFailureReason,errorUpdateCount:f.errorUpdateCount,isFetched:f.dataUpdateCount>0||f.errorUpdateCount>0,isFetchedAfterMount:f.dataUpdateCount>u.dataUpdateCount||f.errorUpdateCount>u.errorUpdateCount,isFetching:C,isRefetching:C&&!w,isLoadingError:N&&!j,isPaused:f.fetchStatus==="paused",isPlaceholderData:h,isRefetchError:N&&j,isStale:BO(t,n),refetch:this.refetch,promise:je(this,Lc),isEnabled:ya(n.enabled,t)!==!1};if(this.options.experimental_prefetchInRender){const I=R=>{_.status==="error"?R.reject(_.error):_.data!==void 0&&R.resolve(_.data)},D=()=>{const R=jt(this,Lc,_.promise=wR());I(R)},E=je(this,Lc);switch(E.status){case"pending":t.queryHash===r.queryHash&&I(E);break;case"fulfilled":(_.status==="error"||_.data!==E.value)&&D();break;case"rejected":(_.status!=="error"||_.error!==E.reason)&&D();break}}return _}updateResult(){const t=je(this,ei),n=this.createResult(je(this,Vn),this.options);if(jt(this,_h,je(this,Vn).state),jt(this,Ag,this.options),je(this,_h).data!==void 0&&jt(this,Pg,je(this,Vn)),Rv(n,t))return;jt(this,ei,n);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:o}=this.options,s=typeof o=="function"?o():o;if(s==="all"||!s&&!je(this,Og).size)return!0;const i=new Set(s??je(this,Og));return this.options.throwOnError&&i.add("error"),Object.keys(je(this,ei)).some(a=>{const c=a;return je(this,ei)[c]!==t[c]&&i.has(c)})};rn(this,ur,ZY).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&rn(this,ur,kR).call(this)}},Ci=new WeakMap,Vn=new WeakMap,K0=new WeakMap,ei=new WeakMap,_h=new WeakMap,Ag=new WeakMap,Lc=new WeakMap,id=new WeakMap,W0=new WeakMap,Fg=new WeakMap,Pg=new WeakMap,Th=new WeakMap,Dh=new WeakMap,ad=new WeakMap,Og=new WeakMap,ur=new WeakSet,wy=function(t){rn(this,ur,TR).call(this);let n=je(this,Vn).fetch(this.options,t);return t!=null&&t.throwOnError||(n=n.catch(Is)),n},SR=function(){rn(this,ur,IR).call(this);const t=_d(this.options.staleTime,je(this,Vn));if(Xh||je(this,ei).isStale||!bR(t))return;const r=HY(je(this,ei).dataUpdatedAt,t)+1;jt(this,Th,lh.setTimeout(()=>{je(this,ei).isStale||this.updateResult()},r))},NR=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(je(this,Vn)):this.options.refetchInterval)??!1},jR=function(t){rn(this,ur,_R).call(this),jt(this,ad,t),!(Xh||ya(this.options.enabled,je(this,Vn))===!1||!bR(je(this,ad))||je(this,ad)===0)&&jt(this,Dh,lh.setInterval(()=>{(this.options.refetchIntervalInBackground||iI.isFocused())&&rn(this,ur,wy).call(this)},je(this,ad)))},kR=function(){rn(this,ur,SR).call(this),rn(this,ur,jR).call(this,rn(this,ur,NR).call(this))},IR=function(){je(this,Th)&&(lh.clearTimeout(je(this,Th)),jt(this,Th,void 0))},_R=function(){je(this,Dh)&&(lh.clearInterval(je(this,Dh)),jt(this,Dh,void 0))},TR=function(){const t=je(this,Ci).getQueryCache().build(je(this,Ci),this.options);if(t===je(this,Vn))return;const n=je(this,Vn);jt(this,Vn,t),jt(this,K0,t.state),this.hasListeners()&&(n==null||n.removeObserver(this),t.addObserver(this))},ZY=function(t){Qr.batch(()=>{t.listeners&&this.listeners.forEach(n=>{n(je(this,ei))}),je(this,Ci).getQueryCache().notify({query:je(this,Vn),type:"observerResultsUpdated"})})},DY);function Ave(e,t){return ya(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function eV(e,t){return Ave(e,t)||e.state.data!==void 0&&DR(e,t,t.refetchOnMount)}function DR(e,t,n){if(ya(t.enabled,e)!==!1&&_d(t.staleTime,e)!=="static"){const r=typeof n=="function"?n(e):n;return r==="always"||r!==!1&&BO(e,t)}return!1}function tV(e,t,n,r){return(e!==t||ya(r.enabled,e)===!1)&&(!n.suspense||e.state.status!=="error")&&BO(e,n)}function BO(e,t){return ya(t.enabled,e)!==!1&&e.isStaleByTime(_d(t.staleTime,e))}function Fve(e,t){return!Rv(e.getCurrentResult(),t)}function MN(e){return{onFetch:(t,n)=>{var d,f,h,p,g;const r=t.options,o=(h=(f=(d=t.fetchOptions)==null?void 0:d.meta)==null?void 0:f.fetchMore)==null?void 0:h.direction,s=((p=t.state.data)==null?void 0:p.pages)||[],i=((g=t.state.data)==null?void 0:g.pageParams)||[];let a={pages:[],pageParams:[]},c=0;const u=async()=>{let x=!1;const b=w=>{Object.defineProperty(w,"signal",{enumerable:!0,get:()=>(t.signal.aborted?x=!0:t.signal.addEventListener("abort",()=>{x=!0}),t.signal)})},y=qY(t.options,t.fetchOptions),C=async(w,N,S)=>{if(x)return Promise.reject();if(N==null&&w.pages.length)return Promise.resolve(w);const k=(()=>{const D={client:t.client,queryKey:t.queryKey,pageParam:N,direction:S?"backward":"forward",meta:t.options.meta};return b(D),D})(),_=await y(k),{maxPages:T}=t.options,I=S?Ive:kve;return{pages:I(w.pages,_,T),pageParams:I(w.pageParams,N,T)}};if(o&&s.length){const w=o==="backward",N=w?XY:ER,S={pages:s,pageParams:i},j=N(r,S);a=await C(S,j,w)}else{const w=e??s.length;do{const N=c===0?i[0]??r.initialPageParam:ER(r,a);if(c>0&&N==null)break;a=await C(a,N),c++}while(c<w)}return a};t.options.persister?t.fetchFn=()=>{var x,b;return(b=(x=t.options).persister)==null?void 0:b.call(x,u,{client:t.client,queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},n)}:t.fetchFn=u}}}function ER(e,{pages:t,pageParams:n}){const r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function XY(e,{pages:t,pageParams:n}){var r;return t.length>0?(r=e.getPreviousPageParam)==null?void 0:r.call(e,t[0],t,n[0],n):void 0}function Pve(e,t){return t?ER(e,t)!=null:!1}function Ove(e,t){return!t||!e.getPreviousPageParam?!1:XY(e,t)!=null}var Lve=class extends aI{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:MN()})}getOptimisticResult(e){return e.behavior=MN(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"forward"}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:"backward"}}})}createResult(e,t){var g,x;const{state:n}=e,r=super.createResult(e,t),{isFetching:o,isRefetching:s,isError:i,isRefetchError:a}=r,c=(x=(g=n.fetchMeta)==null?void 0:g.fetchMore)==null?void 0:x.direction,u=i&&c==="forward",d=o&&c==="forward",f=i&&c==="backward",h=o&&c==="backward";return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:Pve(t,n.data),hasPreviousPage:Ove(t,n.data),isFetchNextPageError:u,isFetchingNextPage:d,isFetchPreviousPageError:f,isFetchingPreviousPage:h,isRefetchError:a&&!u&&!f,isRefetching:s&&!d&&!h}}},G0,zl,ti,Eh,Bl,Qu,EY,$ve=(EY=class extends GY{constructor(t){super();zt(this,Bl);zt(this,G0);zt(this,zl);zt(this,ti);zt(this,Eh);jt(this,G0,t.client),this.mutationId=t.mutationId,jt(this,ti,t.mutationCache),jt(this,zl,[]),this.state=t.state||QY(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options=t,this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){je(this,zl).includes(t)||(je(this,zl).push(t),this.clearGcTimeout(),je(this,ti).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){jt(this,zl,je(this,zl).filter(n=>n!==t)),this.scheduleGc(),je(this,ti).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){je(this,zl).length||(this.state.status==="pending"?this.scheduleGc():je(this,ti).remove(this))}continue(){var t;return((t=je(this,Eh))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var i,a,c,u,d,f,h,p,g,x,b,y,C,w,N,S,j,k,_,T;const n=()=>{rn(this,Bl,Qu).call(this,{type:"continue"})},r={client:je(this,G0),meta:this.options.meta,mutationKey:this.options.mutationKey};jt(this,Eh,WY({fn:()=>this.options.mutationFn?this.options.mutationFn(t,r):Promise.reject(new Error("No mutationFn found")),onFail:(I,D)=>{rn(this,Bl,Qu).call(this,{type:"failed",failureCount:I,error:D})},onPause:()=>{rn(this,Bl,Qu).call(this,{type:"pause"})},onContinue:n,retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode,canRun:()=>je(this,ti).canRun(this)}));const o=this.state.status==="pending",s=!je(this,Eh).canStart();try{if(o)n();else{rn(this,Bl,Qu).call(this,{type:"pending",variables:t,isPaused:s}),await((a=(i=je(this,ti).config).onMutate)==null?void 0:a.call(i,t,this,r));const D=await((u=(c=this.options).onMutate)==null?void 0:u.call(c,t,r));D!==this.state.context&&rn(this,Bl,Qu).call(this,{type:"pending",context:D,variables:t,isPaused:s})}const I=await je(this,Eh).start();return await((f=(d=je(this,ti).config).onSuccess)==null?void 0:f.call(d,I,t,this.state.context,this,r)),await((p=(h=this.options).onSuccess)==null?void 0:p.call(h,I,t,this.state.context,r)),await((x=(g=je(this,ti).config).onSettled)==null?void 0:x.call(g,I,null,this.state.variables,this.state.context,this,r)),await((y=(b=this.options).onSettled)==null?void 0:y.call(b,I,null,t,this.state.context,r)),rn(this,Bl,Qu).call(this,{type:"success",data:I}),I}catch(I){try{throw await((w=(C=je(this,ti).config).onError)==null?void 0:w.call(C,I,t,this.state.context,this,r)),await((S=(N=this.options).onError)==null?void 0:S.call(N,I,t,this.state.context,r)),await((k=(j=je(this,ti).config).onSettled)==null?void 0:k.call(j,void 0,I,this.state.variables,this.state.context,this,r)),await((T=(_=this.options).onSettled)==null?void 0:T.call(_,void 0,I,t,this.state.context,r)),I}finally{rn(this,Bl,Qu).call(this,{type:"error",error:I})}}finally{je(this,ti).runNext(this)}}},G0=new WeakMap,zl=new WeakMap,ti=new WeakMap,Eh=new WeakMap,Bl=new WeakSet,Qu=function(t){const n=r=>{switch(t.type){case"failed":return{...r,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...r,isPaused:!0};case"continue":return{...r,isPaused:!1};case"pending":return{...r,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:t.isPaused,status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...r,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...r,data:void 0,error:t.error,failureCount:r.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=n(this.state),Qr.batch(()=>{je(this,zl).forEach(r=>{r.onMutationUpdate(t)}),je(this,ti).notify({mutation:this,type:"updated",action:t})})},EY);function QY(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var $c,Wa,Y0,MY,zve=(MY=class extends Fm{constructor(t={}){super();zt(this,$c);zt(this,Wa);zt(this,Y0);this.config=t,jt(this,$c,new Set),jt(this,Wa,new Map),jt(this,Y0,0)}build(t,n,r){const o=new $ve({client:t,mutationCache:this,mutationId:++RC(this,Y0)._,options:t.defaultMutationOptions(n),state:r});return this.add(o),o}add(t){je(this,$c).add(t);const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n);r?r.push(t):je(this,Wa).set(n,[t])}this.notify({type:"added",mutation:t})}remove(t){if(je(this,$c).delete(t)){const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n);if(r)if(r.length>1){const o=r.indexOf(t);o!==-1&&r.splice(o,1)}else r[0]===t&&je(this,Wa).delete(n)}}this.notify({type:"removed",mutation:t})}canRun(t){const n=AC(t);if(typeof n=="string"){const r=je(this,Wa).get(n),o=r==null?void 0:r.find(s=>s.state.status==="pending");return!o||o===t}else return!0}runNext(t){var r;const n=AC(t);if(typeof n=="string"){const o=(r=je(this,Wa).get(n))==null?void 0:r.find(s=>s!==t&&s.state.isPaused);return(o==null?void 0:o.continue())??Promise.resolve()}else return Promise.resolve()}clear(){Qr.batch(()=>{je(this,$c).forEach(t=>{this.notify({type:"removed",mutation:t})}),je(this,$c).clear(),je(this,Wa).clear()})}getAll(){return Array.from(je(this,$c))}find(t){const n={exact:!0,...t};return this.getAll().find(r=>YB(n,r))}findAll(t={}){return this.getAll().filter(n=>YB(t,n))}notify(t){Qr.batch(()=>{this.listeners.forEach(n=>{n(t)})})}resumePausedMutations(){const t=this.getAll().filter(n=>n.state.isPaused);return Qr.batch(()=>Promise.all(t.map(n=>n.continue().catch(Is))))}},$c=new WeakMap,Wa=new WeakMap,Y0=new WeakMap,MY);function AC(e){var t;return(t=e.options.scope)==null?void 0:t.id}var zc,ld,Si,Bc,hu,R1,MR,RY,Bve=(RY=class extends Fm{constructor(n,r){super();zt(this,hu);zt(this,zc);zt(this,ld);zt(this,Si);zt(this,Bc);jt(this,zc,n),this.setOptions(r),this.bindMethods(),rn(this,hu,R1).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(n){var o;const r=this.options;this.options=je(this,zc).defaultMutationOptions(n),Rv(this.options,r)||je(this,zc).getMutationCache().notify({type:"observerOptionsUpdated",mutation:je(this,Si),observer:this}),r!=null&&r.mutationKey&&this.options.mutationKey&&pu(r.mutationKey)!==pu(this.options.mutationKey)?this.reset():((o=je(this,Si))==null?void 0:o.state.status)==="pending"&&je(this,Si).setOptions(this.options)}onUnsubscribe(){var n;this.hasListeners()||(n=je(this,Si))==null||n.removeObserver(this)}onMutationUpdate(n){rn(this,hu,R1).call(this),rn(this,hu,MR).call(this,n)}getCurrentResult(){return je(this,ld)}reset(){var n;(n=je(this,Si))==null||n.removeObserver(this),jt(this,Si,void 0),rn(this,hu,R1).call(this),rn(this,hu,MR).call(this)}mutate(n,r){var o;return jt(this,Bc,r),(o=je(this,Si))==null||o.removeObserver(this),jt(this,Si,je(this,zc).getMutationCache().build(je(this,zc),this.options)),je(this,Si).addObserver(this),je(this,Si).execute(n)}},zc=new WeakMap,ld=new WeakMap,Si=new WeakMap,Bc=new WeakMap,hu=new WeakSet,R1=function(){var r;const n=((r=je(this,Si))==null?void 0:r.state)??QY();jt(this,ld,{...n,isPending:n.status==="pending",isSuccess:n.status==="success",isError:n.status==="error",isIdle:n.status==="idle",mutate:this.mutate,reset:this.reset})},MR=function(n){Qr.batch(()=>{var r,o,s,i,a,c,u,d;if(je(this,Bc)&&this.hasListeners()){const f=je(this,ld).variables,h=je(this,ld).context,p={client:je(this,zc),meta:this.options.meta,mutationKey:this.options.mutationKey};(n==null?void 0:n.type)==="success"?((o=(r=je(this,Bc)).onSuccess)==null||o.call(r,n.data,f,h,p),(i=(s=je(this,Bc)).onSettled)==null||i.call(s,n.data,null,f,h,p)):(n==null?void 0:n.type)==="error"&&((c=(a=je(this,Bc)).onError)==null||c.call(a,n.error,f,h,p),(d=(u=je(this,Bc)).onSettled)==null||d.call(u,void 0,n.error,f,h,p))}this.listeners.forEach(f=>{f(je(this,ld))})})},RY);function nV(e,t){const n=new Set(t);return e.filter(r=>!n.has(r))}function Vve(e,t,n){const r=e.slice(0);return r[t]=n,r}var Mh,qi,Lg,$g,xa,cd,Z0,X0,Q0,ys,RR,AR,FR,PR,OR,AY,Hve=(AY=class extends Fm{constructor(t,n,r){super();zt(this,ys);zt(this,Mh);zt(this,qi);zt(this,Lg);zt(this,$g);zt(this,xa);zt(this,cd);zt(this,Z0);zt(this,X0);zt(this,Q0,[]);jt(this,Mh,t),jt(this,$g,r),jt(this,Lg,[]),jt(this,xa,[]),jt(this,qi,[]),this.setQueries(n)}onSubscribe(){this.listeners.size===1&&je(this,xa).forEach(t=>{t.subscribe(n=>{rn(this,ys,PR).call(this,t,n)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,je(this,xa).forEach(t=>{t.destroy()})}setQueries(t,n){if(jt(this,Lg,t),jt(this,$g,n),process.env.NODE_ENV!=="production"){const r=t.map(o=>je(this,Mh).defaultQueryOptions(o).queryHash);new Set(r).size!==r.length&&console.warn("[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.")}Qr.batch(()=>{const r=je(this,xa),o=rn(this,ys,FR).call(this,je(this,Lg));jt(this,Q0,o),o.forEach(f=>f.observer.setOptions(f.defaultedQueryOptions));const s=o.map(f=>f.observer),i=s.map(f=>f.getCurrentResult()),a=r.length!==s.length,c=s.some((f,h)=>f!==r[h]),u=a||c,d=u?!0:i.some((f,h)=>{const p=je(this,qi)[h];return!p||!Rv(f,p)});!u&&!d||(u&&jt(this,xa,s),jt(this,qi,i),this.hasListeners()&&(u&&(nV(r,s).forEach(f=>{f.destroy()}),nV(s,r).forEach(f=>{f.subscribe(h=>{rn(this,ys,PR).call(this,f,h)})})),rn(this,ys,OR).call(this)))})}getCurrentResult(){return je(this,qi)}getQueries(){return je(this,xa).map(t=>t.getCurrentQuery())}getObservers(){return je(this,xa)}getOptimisticResult(t,n){const r=rn(this,ys,FR).call(this,t),o=r.map(s=>s.observer.getOptimisticResult(s.defaultedQueryOptions));return[o,s=>rn(this,ys,AR).call(this,s??o,n),()=>rn(this,ys,RR).call(this,o,r)]}},Mh=new WeakMap,qi=new WeakMap,Lg=new WeakMap,$g=new WeakMap,xa=new WeakMap,cd=new WeakMap,Z0=new WeakMap,X0=new WeakMap,Q0=new WeakMap,ys=new WeakSet,RR=function(t,n){return n.map((r,o)=>{const s=t[o];return r.defaultedQueryOptions.notifyOnChangeProps?s:r.observer.trackResult(s,i=>{n.forEach(a=>{a.observer.trackProp(i)})})})},AR=function(t,n){return n?((!je(this,cd)||je(this,qi)!==je(this,X0)||n!==je(this,Z0))&&(jt(this,Z0,n),jt(this,X0,je(this,qi)),jt(this,cd,DN(je(this,cd),n(t)))),je(this,cd)):t},FR=function(t){const n=new Map;je(this,xa).forEach(o=>{const s=o.options.queryHash;if(!s)return;const i=n.get(s);i?i.push(o):n.set(s,[o])});const r=[];return t.forEach(o=>{var c;const s=je(this,Mh).defaultQueryOptions(o),a=((c=n.get(s.queryHash))==null?void 0:c.shift())??new aI(je(this,Mh),s);r.push({defaultedQueryOptions:s,observer:a})}),r},PR=function(t,n){const r=je(this,xa).indexOf(t);r!==-1&&(jt(this,qi,Vve(je(this,qi),r,n)),rn(this,ys,OR).call(this))},OR=function(){var t;if(this.hasListeners()){const n=je(this,cd),r=rn(this,ys,RR).call(this,je(this,qi),je(this,Q0)),o=rn(this,ys,AR).call(this,r,(t=je(this,$g))==null?void 0:t.combine);n!==o&&Qr.batch(()=>{this.listeners.forEach(s=>{s(je(this,qi))})})}},AY),Vl,FY,JY=(FY=class extends Fm{constructor(t={}){super();zt(this,Vl);this.config=t,jt(this,Vl,new Map)}build(t,n,r){const o=n.queryKey,s=n.queryHash??zO(o,n);let i=this.get(s);return i||(i=new Rve({client:t,queryKey:o,queryHash:s,options:t.defaultQueryOptions(n),state:r,defaultOptions:t.getQueryDefaults(o)}),this.add(i)),i}add(t){je(this,Vl).has(t.queryHash)||(je(this,Vl).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const n=je(this,Vl).get(t.queryHash);n&&(t.destroy(),n===t&&je(this,Vl).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Qr.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return je(this,Vl).get(t)}getAll(){return[...je(this,Vl).values()]}find(t){const n={exact:!0,...t};return this.getAll().find(r=>GB(n,r))}findAll(t={}){const n=this.getAll();return Object.keys(t).length>0?n.filter(r=>GB(t,r)):n}notify(t){Qr.batch(()=>{this.listeners.forEach(n=>{n(t)})})}onFocus(){Qr.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Qr.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Vl=new WeakMap,FY),no,ud,dd,zg,Bg,fd,Vg,Hg,PY,qve=(PY=class{constructor(e={}){zt(this,no);zt(this,ud);zt(this,dd);zt(this,zg);zt(this,Bg);zt(this,fd);zt(this,Vg);zt(this,Hg);jt(this,no,e.queryCache||new JY),jt(this,ud,e.mutationCache||new zve),jt(this,dd,e.defaultOptions||{}),jt(this,zg,new Map),jt(this,Bg,new Map),jt(this,fd,0)}mount(){RC(this,fd)._++,je(this,fd)===1&&(jt(this,Vg,iI.subscribe(async e=>{e&&(await this.resumePausedMutations(),je(this,no).onFocus())})),jt(this,Hg,Av.subscribe(async e=>{e&&(await this.resumePausedMutations(),je(this,no).onOnline())})))}unmount(){var e,t;RC(this,fd)._--,je(this,fd)===0&&((e=je(this,Vg))==null||e.call(this),jt(this,Vg,void 0),(t=je(this,Hg))==null||t.call(this),jt(this,Hg,void 0))}isFetching(e){return je(this,no).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return je(this,ud).findAll({...e,status:"pending"}).length}getQueryData(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=je(this,no).get(t.queryHash))==null?void 0:n.state.data}ensureQueryData(e){const t=this.defaultQueryOptions(e),n=je(this,no).build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(_d(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return je(this,no).findAll(e).map(({queryKey:t,state:n})=>{const r=n.data;return[t,r]})}setQueryData(e,t,n){const r=this.defaultQueryOptions({queryKey:e}),o=je(this,no).get(r.queryHash),s=o==null?void 0:o.state.data,i=Sve(t,s);if(i!==void 0)return je(this,no).build(this,r).setData(i,{...n,manual:!0})}setQueriesData(e,t,n){return Qr.batch(()=>je(this,no).findAll(e).map(({queryKey:r})=>[r,this.setQueryData(r,t,n)]))}getQueryState(e){var n;const t=this.defaultQueryOptions({queryKey:e});return(n=je(this,no).get(t.queryHash))==null?void 0:n.state}removeQueries(e){const t=je(this,no);Qr.batch(()=>{t.findAll(e).forEach(n=>{t.remove(n)})})}resetQueries(e,t){const n=je(this,no);return Qr.batch(()=>(n.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries({type:"active",...e},t)))}cancelQueries(e,t={}){const n={revert:!0,...t},r=Qr.batch(()=>je(this,no).findAll(e).map(o=>o.cancel(n)));return Promise.all(r).then(Is).catch(Is)}invalidateQueries(e,t={}){return Qr.batch(()=>(je(this,no).findAll(e).forEach(n=>{n.invalidate()}),(e==null?void 0:e.refetchType)==="none"?Promise.resolve():this.refetchQueries({...e,type:(e==null?void 0:e.refetchType)??(e==null?void 0:e.type)??"active"},t)))}refetchQueries(e,t={}){const n={...t,cancelRefetch:t.cancelRefetch??!0},r=Qr.batch(()=>je(this,no).findAll(e).filter(o=>!o.isDisabled()&&!o.isStatic()).map(o=>{let s=o.fetch(void 0,n);return n.throwOnError||(s=s.catch(Is)),o.state.fetchStatus==="paused"?Promise.resolve():s}));return Promise.all(r).then(Is)}fetchQuery(e){const t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);const n=je(this,no).build(this,t);return n.isStaleByTime(_d(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Is).catch(Is)}fetchInfiniteQuery(e){return e.behavior=MN(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Is).catch(Is)}ensureInfiniteQueryData(e){return e.behavior=MN(e.pages),this.ensureQueryData(e)}resumePausedMutations(){return Av.isOnline()?je(this,ud).resumePausedMutations():Promise.resolve()}getQueryCache(){return je(this,no)}getMutationCache(){return je(this,ud)}getDefaultOptions(){return je(this,dd)}setDefaultOptions(e){jt(this,dd,e)}setQueryDefaults(e,t){je(this,zg).set(pu(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...je(this,zg).values()],n={};return t.forEach(r=>{Mv(e,r.queryKey)&&Object.assign(n,r.defaultOptions)}),n}setMutationDefaults(e,t){je(this,Bg).set(pu(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...je(this,Bg).values()],n={};return t.forEach(r=>{Mv(e,r.mutationKey)&&Object.assign(n,r.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;const t={...je(this,dd).queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=zO(t.queryKey,t)),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!=="always"),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode="offlineFirst"),t.queryFn===EN&&(t.enabled=!1),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...je(this,dd).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){je(this,no).clear(),je(this,ud).clear()}},no=new WeakMap,ud=new WeakMap,dd=new WeakMap,zg=new WeakMap,Bg=new WeakMap,fd=new WeakMap,Vg=new WeakMap,Hg=new WeakMap,PY),VO=ie.createContext(void 0),Hr=e=>{const t=ie.useContext(VO);if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},Uve=({client:e,children:t})=>(ie.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),l.jsx(VO.Provider,{value:e,children:t})),eZ=ie.createContext(!1),tZ=()=>ie.useContext(eZ);eZ.Provider;function Kve(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Wve=ie.createContext(Kve()),nZ=()=>ie.useContext(Wve),rZ=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},oZ=e=>{ie.useEffect(()=>{e.clearReset()},[e])},sZ=({result:e,errorResetBoundary:t,throwOnError:n,query:r,suspense:o})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&(o&&e.data===void 0||UY(n,[e.error,r])),iZ=e=>{if(e.suspense){const n=o=>o==="static"?o:Math.max(o??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...o)=>n(r(...o)):n(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},aZ=(e,t)=>e.isLoading&&e.isFetching&&!t,LR=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,RN=(e,t,n)=>t.fetchOptimistic(e).catch(()=>{n.clearReset()});function cf({queries:e,...t},n){const r=Hr(),o=tZ(),s=nZ(),i=ie.useMemo(()=>e.map(x=>{const b=r.defaultQueryOptions(x);return b._optimisticResults=o?"isRestoring":"optimistic",b}),[e,r,o]);i.forEach(x=>{iZ(x),rZ(x,s)}),oZ(s);const[a]=ie.useState(()=>new Hve(r,i,t)),[c,u,d]=a.getOptimisticResult(i,t.combine),f=!o&&t.subscribed!==!1;ie.useSyncExternalStore(ie.useCallback(x=>f?a.subscribe(Qr.batchCalls(x)):Is,[a,f]),()=>a.getCurrentResult(),()=>a.getCurrentResult()),ie.useEffect(()=>{a.setQueries(i,t)},[i,t,a]);const p=c.some((x,b)=>LR(i[b],x))?c.flatMap((x,b)=>{const y=i[b];if(y){const C=new aI(r,y);if(LR(y,x))return RN(y,C,s);aZ(x,o)&&RN(y,C,s)}return[]}):[];if(p.length>0)throw Promise.all(p);const g=c.find((x,b)=>{const y=i[b];return y&&sZ({result:x,errorResetBoundary:s,throwOnError:y.throwOnError,query:r.getQueryCache().get(y.queryHash),suspense:y.suspense})});if(g!=null&&g.error)throw g.error;return u(d())}function lZ(e,t,n){var f,h,p,g,x;if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const r=tZ(),o=nZ(),s=Hr(),i=s.defaultQueryOptions(e);(h=(f=s.getDefaultOptions().queries)==null?void 0:f._experimental_beforeQuery)==null||h.call(f,i),process.env.NODE_ENV!=="production"&&(i.queryFn||console.error(`[${i.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`)),i._optimisticResults=r?"isRestoring":"optimistic",iZ(i),rZ(i,o),oZ(o);const a=!s.getQueryCache().get(i.queryHash),[c]=ie.useState(()=>new t(s,i)),u=c.getOptimisticResult(i),d=!r&&e.subscribed!==!1;if(ie.useSyncExternalStore(ie.useCallback(b=>{const y=d?c.subscribe(Qr.batchCalls(b)):Is;return c.updateResult(),y},[c,d]),()=>c.getCurrentResult(),()=>c.getCurrentResult()),ie.useEffect(()=>{c.setOptions(i)},[i,c]),LR(i,u))throw RN(i,c,o);if(sZ({result:u,errorResetBoundary:o,throwOnError:i.throwOnError,query:s.getQueryCache().get(i.queryHash),suspense:i.suspense}))throw u.error;if((g=(p=s.getDefaultOptions().queries)==null?void 0:p._experimental_afterQuery)==null||g.call(p,i,u),i.experimental_prefetchInRender&&!Xh&&aZ(u,r)){const b=a?RN(i,c,o):(x=s.getQueryCache().get(i.queryHash))==null?void 0:x.promise;b==null||b.catch(Is).finally(()=>{c.updateResult()})}return i.notifyOnChangeProps?u:c.trackResult(u)}function Yn(e,t){return lZ(e,aI)}function Gve(e,t){const n=Hr(),r=n.getQueryCache();return ie.useSyncExternalStore(ie.useCallback(o=>r.subscribe(Qr.batchCalls(o)),[r]),()=>n.isFetching(e),()=>n.isFetching(e))}function Os(e,t){const n=Hr(),[r]=ie.useState(()=>new Bve(n,e));ie.useEffect(()=>{r.setOptions(e)},[r,e]);const o=ie.useSyncExternalStore(ie.useCallback(i=>r.subscribe(Qr.batchCalls(i)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),s=ie.useCallback((i,a)=>{r.mutate(i,a).catch(Is)},[r]);if(o.error&&UY(r.options.throwOnError,[o.error]))throw o.error;return{...o,mutate:s,mutateAsync:o.mutate}}function Yve(e,t){return lZ(e,Lve)}function cZ(e){const t=v.useId(),[n,r]=v.useState({token:e,revision:0});return n.token!==e&&r({token:e,revision:n.revision+1}),`${t}:${n.revision}`}function Zve(){const e=v.useContext(VO);if(e&&e.isSemaphorClient)return e}function uZ({children:e}){const{setIsSessionExpired:t}=m.useDashboardActions(),n=Zve(),[r]=v.useState(()=>{const o=new qve({queryCache:new JY({onError:s=>{s instanceof Error?(console.error(`Something went wrong: ${s.message}`),s.message==="invalid token"&&t(!0)):console.error("Something went wrong:",s)}}),defaultOptions:{queries:{gcTime:36e5,staleTime:3e5,refetchOnWindowFocus:!1,retry:!1}}});return o.isSemaphorClient=!0,o});return n?l.jsx(l.Fragment,{children:e}):l.jsx(Uve,{client:r,children:e})}const dZ=v.createContext(null);function fZ(e){return hZ({rowKey:ze.matrixPathKey(e.rowPath),columnKey:ze.matrixPathKey(e.columnPath),measureId:e.measureId})}function hZ(e){return JSON.stringify([e.rowKey,e.columnKey,e.measureId])}const Po=Object.freeze({rowPageSize:100,columnPageSize:20,operations:2,dashboardOperations:4,pages:32,blocks:64,cells:1e5,bytes:32*1024*1024,checkpoints:64,overrides:2e3,mountedCells:5e3,clipboardCells:1e4,clipboardBytes:1024*1024,clipboardTimeoutMs:3e4});class Xve{constructor(){Se(this,"pending",new Map);Se(this,"activeByCard",new Map);Se(this,"active",0)}run(t,n,r){const o=()=>new DOMException("Matrix acquisition was cancelled.","AbortError");return n.aborted?Promise.reject(o()):new Promise((s,i)=>{let a=!1;const c=()=>{var f;if(!a){const h=(f=this.pending.get(t))==null?void 0:f.filter(p=>p!==u);h!=null&&h.length?this.pending.set(t,h):this.pending.delete(t),n.removeEventListener("abort",c)}i(o())},u={start:()=>{a=!0,this.active++,this.activeByCard.set(t,(this.activeByCard.get(t)??0)+1),Promise.resolve().then(()=>{if(n.aborted)throw o();return r()}).then(s,i).finally(()=>{n.removeEventListener("abort",c),this.active--;const f=this.activeByCard.get(t)-1;f?this.activeByCard.set(t,f):this.activeByCard.delete(t),this.pump()})}},d=this.pending.get(t)??[];d.push(u),this.pending.set(t,d),n.addEventListener("abort",c,{once:!0}),this.pump()})}pump(){for(;this.active<Po.dashboardOperations;){const t=Array.from(this.pending).find(([s])=>(this.activeByCard.get(s)??0)<Po.operations);if(!t)return;const[n,r]=t,o=r.shift();this.pending.delete(n),r.length&&this.pending.set(n,r),o.start()}}}function Qve({value:e,children:t}){const[n]=v.useState(()=>new Xve),r=v.useMemo(()=>({...e,queue:n}),[e,n]);return l.jsx(dZ.Provider,{value:r,children:t})}function Jve(e,t){return async n=>{var i;const r=await fetch(e,{method:"POST",signal:n.signal,headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(lt.buildMatrixCardQueryPayload(n))});if(r.status===401||r.status===403)return{status:"failed",failure:{code:"forbidden",message:"Matrix query access was denied.",retryable:!1,scope:{kind:"operation"}}};const o=await r.json().catch(()=>null);if(!o||typeof o!="object")return{status:"failed",failure:{code:"execution_failed",message:"Matrix query returned an invalid response.",retryable:r.ok||r.status>=500,scope:{kind:"operation"}}};if(!r.ok||o.error){const a=Dv.matrixExecutionResultSchema.safeParse(o.executionResult);if(a.success&&a.data.metadata.matrixFailure)return{status:"failed",failure:a.data.metadata.matrixFailure};const c=a.success?a.data.validation.errors[0]:void 0;return{status:"failed",failure:{code:"execution_failed",message:(c==null?void 0:c.message)??"Matrix query failed.",retryable:r.status>=500,scope:{kind:"operation"}}}}const s=Dv.matrixWindowSchema.parse((i=o.data)==null?void 0:i.matrixWindow);return{status:s.failures.length?"partial":"success",window:s}}}function e0e({children:e,authToken:t,apiServiceUrl:n,dashboardId:r}){const o=(t==null?void 0:t.accessToken)??"",s=v.useMemo(()=>({ready:!!(o&&n),identity:JSON.stringify([r,n]),execute:Jve(`${n??""}/v1/query`,o)}),[r,n,o]);return l.jsx(Qve,{value:s,children:e})}const t0e={id:"",authToken:void 0,tokenProps:{},authorizationScope:"unconfigured"},J0=v.createContext(t0e),HO=({children:e,dashboardProps:t})=>{var o;const n=cZ((o=t.authToken)==null?void 0:o.accessToken),r=v.useMemo(()=>{let s={};const i=t.authToken;return i&&(s=Re.jwtDecode(i.accessToken)),{...t,tokenProps:s,authorizationScope:n}},[t,n]);return l.jsx(uZ,{children:l.jsx(J0.Provider,{value:r,children:l.jsx(e0e,{dashboardId:r.id,authToken:r.authToken,apiServiceUrl:r.tokenProps.apiServiceUrl,children:e})})})};function Mt(){const e=v.useContext(J0);if(e===void 0)throw new Error("useApplicationContext must be used within a ApplicationContextProvider");return e}const Ls=m.create()(m.immer(e=>({initialDashboard:null,selectedDashboard:null,selectedVisual:null,lastSelectedDashboard:null,lastSelectedVisual:null,showHub:!1,actions:{setInitialDashboard:t=>{e(n=>{n.initialDashboard=t})},selectDashboard:t=>{e(n=>{var r;((r=n.selectedDashboard)==null?void 0:r.id)!==t.id&&(n.lastSelectedDashboard=n.selectedDashboard,n.selectedDashboard=t),n.showHub=!1})},updateSelectedDashboard:t=>{e(n=>{n.selectedDashboard=t})},selectVisual:t=>{e(n=>{n.lastSelectedVisual=n.selectedVisual,n.selectedVisual=t})},clearSelectedDashboard:()=>{e(t=>{t.lastSelectedDashboard=t.selectedDashboard,t.selectedDashboard=null,t.showHub=!0})},clearSelectedVisual:()=>{e(t=>{t.lastSelectedVisual=t.selectedVisual,t.selectedVisual=null})},setShowHub:t=>{e(n=>{n.showHub=t})}}}))),n0e=()=>Ls(e=>e.selectedVisual),Pm=()=>Ls(e=>e.actions);function ew(){const{authToken:e,version:t,tokenProps:n,id:r}=Mt(),o=Ls(g=>g.selectedDashboard),s=Ls(g=>g.showHub),i=m.useDashboardStore(g=>g.selectedLensId),a=r0e({showHub:s,selectedDashboardId:o==null?void 0:o.id,dashboardId:r,tokenDashboardId:n==null?void 0:n.dashboard_id});function c(){return!(!(e!=null&&e.accessToken)||!a)}const{data:u,isLoading:d,isFetching:f,isError:h,refetch:p}=Yn({queryKey:["dashboard",i,e==null?void 0:e.accessToken,a],queryFn:()=>m.getDashboard(n.apiServiceUrl,e==null?void 0:e.accessToken,{lensId:i,version:t,dashboardId:a}),enabled:c()});return{data:u,isLoading:d,isFetching:f,isError:h,refetch:p,dashboardIdToFetch:a}}function r0e({showHub:e,selectedDashboardId:t,dashboardId:n,tokenDashboardId:r}){return e?null:t||n||r||null}function o0e(){const{authToken:e}=Mt(),t=m.useDashboardStore(r=>r.authToken),{setAuthToken:n}=m.useDashboardActions();return v.useLayoutEffect(()=>{const r=e==null?void 0:e.accessToken,o=t==null?void 0:t.accessToken;e&&r!==o&&n(e)},[e,t,n]),e}function mZ(e){const t=v.useCallback(s=>`semaphor-default-sheet-${s}`,[]),n=v.useCallback(()=>{if(!e)return null;try{const s=t(e);return localStorage.getItem(s)}catch(s){return console.error("Error reading default sheet preference:",s),null}},[e,t]),r=v.useCallback(s=>{if(!(!e||!s))try{const i=t(e);localStorage.setItem(i,s)}catch(i){console.error("Error saving default sheet preference:",i)}},[e,t]),o=v.useCallback(()=>{if(e)try{const s=t(e);localStorage.removeItem(s)}catch(s){console.error("Error clearing default sheet preference:",s)}},[e,t]);return{getDefaultSheetId:n,setDefaultSheetId:r,clearDefaultSheetId:o}}const s0e=["kpi","table","detailTable","aggregateTable","pivotTable","bar","horizontalBar","stackedBar","line","stackedLine","area","stackedArea","combo","pie","doughnut","polarArea","radar","scatter","bubble","tornado","pyramid","range","funnel","bullet","heatmap","treemap","map","matrixTable"],i0e=new Set(s0e),a0e=["table","detailTable","aggregateTable","pivotTable","matrixTable"],l0e=new Set(a0e);function qO(e){return typeof e=="string"&&l0e.has(e)}function tw(e){return typeof e=="string"&&i0e.has(e)}function AN(e){return(e==null?void 0:e.type)==="number"||(e==null?void 0:e.type)==="currency"}function pZ(e){var n,r;const t=(r=(n=e.preferences)==null?void 0:n.formatNumber)==null?void 0:r.enabled;return t===!1||t==="false"}function gZ(e){return(e==null?void 0:e.type)==="number"}function c0e(e){var n;if(!gZ(e))return!1;const t=(n=e==null?void 0:e.numberFormat)==null?void 0:n.style;return t===void 0||t==="decimal"||t==="currency"}function xZ(e,t){const n=t==null?void 0:t.type;if(n&&n!=="none"&&n!=="number")return{currencyBindable:!1};const r=n==="number"?t!=null&&t.numberFormat?m.fromColumnNumberFormat(t.numberFormat,{preserveOmittedProperties:!0}):{type:"number"}:void 0,o=Lt.fromSemanticFormat(e.format,{preserveOmittedProperties:!0}),s=ze.normalizeAnalyticsCatalogDataType(e.dataType)==="number"?{type:"number"}:void 0,a=(t==null?void 0:t.inheritMetricFormat)===!1||!!(t!=null&&t.numberFormat)&&(t==null?void 0:t.inheritMetricFormat)!==!0?r:o||s||r;return{authoredFormat:a,currencyBindable:AN(a)}}function UO(e,t){var c,u;const n=Lt.fromSemanticFormat(t.format,{preserveOmittedProperties:!0}),r=m.fromNumberAxisFormat((c=e.preferences)==null?void 0:c.numberAxisFormat),o=pZ(e)?void 0:m.fromLegacyFormatNumber((u=e.preferences)==null?void 0:u.formatNumber),s=ze.normalizeAnalyticsCatalogDataType(t.dataType)==="number"?{type:"number"}:void 0,i=n||r||o||s;return{authoredFormat:i,source:n?"semantic":r?"number_axis":o?"legacy":s?"inferred":void 0,currencyBindable:AN(i)}}function Fv(e,t={}){var h,p,g,x,b,y;const n=t.metricIndex??0,r=!!((h=e.sql)!=null&&h.trim()),o=m.fromPersistedKpiFormatOptions((g=(p=e.preferences)==null?void 0:p.kpiVisualOptions)==null?void 0:g.formatOptions),s=n===0?m.fromLegacyFormatNumber((x=e.preferences)==null?void 0:x.formatNumber):void 0,i=pZ(e);if(r){const C=t.resultColumnKey?{kind:"column",columnKey:t.resultColumnKey}:void 0;return{target:C,authoredFormat:o||s,currencyBindable:!i&&!!C&&AN(o)}}const a=(y=(b=e.config)==null?void 0:b.metricColumns)==null?void 0:y[n],c=a!=null&&a.id?{kind:"metric",metricId:a.id}:void 0,u=Lt.fromSemanticFormat(a==null?void 0:a.format,{preserveOmittedProperties:!0}),d=ze.normalizeAnalyticsCatalogDataType(a==null?void 0:a.dataType)==="number"?{type:"number"}:void 0,f=o||u||s||d;return{target:c,authoredFormat:f,currencyBindable:!i&&tw(e.type)&&!!c&&AN(f)}}function lI(e,t=[]){const n=mu.inspectMatrixCardConfig(e);if(n.status!=="ready")return[];const{spec:r,presentation:o}=n.config,s=lt.createMatrixCatalogResolver(t);return r.measures.map(i=>{var g,x;const a=i.kind==="aggregate"?s(i.field,r.source):void 0,c=i.kind==="calculated"?i.definition.format:((g=i.field.derivedField)==null?void 0:g.format)??(a==null?void 0:a.format)??(a==null?void 0:a.resolvedField.format),u=Xn.resolveMatrixValueFormat(o.measureFormats[i.id],c),d=i.kind==="calculated"?i.definition.dataType:["MIN","MAX"].includes(i.aggregate)?((x=i.field.derivedField)==null?void 0:x.dataType)??(a==null?void 0:a.resolvedField.dataType)??i.field.dataType:"number",f=ze.normalizeAnalyticsCatalogDataType(d)==="number",h=i.kind==="calculated"||!!(a||i.field.derivedField||i.field.name==="*"),p=u&&Lt.isNumericCanonicalFormat(u)?u:!u&&f&&h?{type:"number"}:void 0;return{measureId:i.id,label:_s.getMatrixMeasureLabel(i,o),canonical:p}})}function bZ(e){var t,n;return e.type==="detailTable"?((t=e.config)==null?void 0:t.detailColumns)||[]:((n=e.config)==null?void 0:n.metricColumns)||[]}function yZ(e){return new Set(m.getDashboardCards(e).flatMap(t=>(t.controlBindings||[]).filter(nw).map(n=>n.controlId)))}function u0e(e,t){const n=[t.id,t.alias,t.label,t.name,t.qualifiedFieldName].filter(s=>!!s);for(const s of n)if(e[s])return e[s];const r=new Set(n.map(s=>s.trim().toLowerCase())),o=Object.entries(e).find(([s])=>r.has(s.trim().toLowerCase()));return o==null?void 0:o[1]}function rV(e){return[...new Map(e.map(t=>[Ta(t),t])).values()]}function cI(e,t=[],n){var N,S,j;const r=!!((N=e.sql)!=null&&N.trim()),o=tw(e.type),s=r&&o&&e.type!=="kpi"&&e.type!=="matrixTable",i=bZ(e),a=((j=(S=e.preferences)==null?void 0:S.tablePrefs)==null?void 0:j.columnSettingsMap)||{},c=!r&&e.type==="kpi"?i.map((k,_)=>Fv(e,{metricIndex:_})):[],u=!r&&e.type==="matrixTable"?lI(e,n):[],d=(r?[]:i).map(k=>({kind:"metric",metricId:k.id})),f=u.map(k=>({kind:"matrix_measure",measureId:k.measureId})),h=u.filter(k=>{var _,T;return((_=k.canonical)==null?void 0:_.type)==="number"||((T=k.canonical)==null?void 0:T.type)==="currency"}).map(k=>({kind:"matrix_measure",measureId:k.measureId})),p=e.type==="matrixTable"?[]:e.type==="kpi"?c.filter(k=>k.currencyBindable).flatMap(k=>k.target?[k.target]:[]):(r||!o?[]:i).filter(k=>(qO(e.type)?xZ(k,u0e(a,k)):UO(e,k)).currencyBindable).map(k=>({kind:"metric",metricId:k.id})),g=[...new Set(t)],x=(s?g:[]).map(k=>({kind:"column",columnKey:k})),b=(s?g:[]).filter(k=>c0e(a[k])).map(k=>({kind:"column",columnKey:k})),y=(r&&e.type==="kpi"?g.slice(0,1):[]).map(k=>({kind:"column",columnKey:k})),C=r&&e.type==="kpi"?Fv(e,{resultColumnKey:g[0]}):void 0,w=o&&(C!=null&&C.currencyBindable)?y:[];return{knownTargets:rV([...e.type==="matrixTable"?f:d,...x,...y]),eligibleTargets:rV([...p,...h,...b,...w])}}function vZ(e,t){const n=Fv(e,{resultColumnKey:t});return n.currencyBindable?n.target:void 0}function ic(e){var t;return(t=e.card.sql)!=null&&t.trim()?{kind:"column",columnKey:e.columnKey}:e.metricId?{kind:"metric",metricId:e.metricId}:void 0}function Ta(e){return e.kind==="metric"?`metric:${e.metricId}`:e.kind==="column"?`column:${e.columnKey}`:`matrix_measure:${e.measureId}`}function d0e(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t=e;if(t.kind==="metric"&&typeof t.metricId=="string"&&t.metricId.trim())return{kind:"metric",metricId:t.metricId};if(t.kind==="column"&&typeof t.columnKey=="string"&&t.columnKey.trim())return{kind:"column",columnKey:t.columnKey};if(t.kind==="matrix_measure"&&typeof t.measureId=="string"&&t.measureId.trim())return{kind:"matrix_measure",measureId:t.measureId}}function nw(e){return e.target==="presentation_currency"}function f0e(e){return e.target!=="sql_param"&&e.target!=="presentation_currency"}function oV(e){const t=Yi.canonicalizeSupportedCurrencyCode(e);return typeof e=="string"&&e===t?t:void 0}function wZ(e){if(e.type!=="enum"||e.source.kind!=="manual")return{diagnostic:"invalid_control_type"};const t=e.source.options.map(n=>oV(n.value));if(t.length===0||t.some(n=>!n))return{diagnostic:"invalid_currency_option"};if(e.requiredAtExecution){const n=e.initialValueStrategy==="saved_default"?oV(e.defaultValue):void 0;if(!n||!t.includes(n))return{diagnostic:"invalid_control_default"}}return{control:e,currencies:t}}function h0e(e){return"control"in wZ(e)}function CZ(e){const t=yZ(e.dashboard);if(t.size===0)return{definitions:e.definitions||[],values:e.values||{}};const n=new Set([...t].filter(r=>!e.referencedControlIds.has(r)));return{definitions:(e.definitions||[]).filter(r=>!n.has(r.id)),values:Object.fromEntries(Object.entries(e.values||{}).filter(([r])=>!n.has(r)))}}function SZ(e){return CZ({...e,referencedControlIds:new Set(en.extractReferencedControlIds({sql:e.filterSql,controlBindings:[]}))})}function m0e(e){var t;return CZ({...e,referencedControlIds:new Set(en.extractReferencedControlIds({sql:(t=e.source)==null?void 0:t.sql,controlBindings:[]}))})}function NZ(e){return{knownKeys:new Set(e.knownTargets.map(Ta)),eligibleKeys:new Set(e.eligibleTargets.map(Ta)),controlsById:new Map((e.controls||[]).map(t=>[t.id,t]))}}function jZ(e,t){if(!e||typeof e!="object"||e.target!=="presentation_currency")return{};const n=e,r=typeof n.controlId=="string"&&n.controlId.trim()?n.controlId:void 0;if(!r)return{diagnostic:{code:"invalid_binding_shape"}};const o=d0e(n.presentationTarget);if(!o)return{diagnostic:{code:"missing_target",controlId:r}};const s=Ta(o);if(!t.knownKeys.has(s))return{diagnostic:{code:"stale_target",controlId:r}};if(!t.eligibleKeys.has(s))return{diagnostic:{code:"inapplicable_target",controlId:r}};const i=t.controlsById.get(r);if(!i)return{diagnostic:{code:"missing_control",controlId:r}};const a=wZ(i);return"diagnostic"in a?{diagnostic:{code:a.diagnostic,controlId:r}}:{binding:{controlId:r,presentationTarget:o,control:a.control,currencies:a.currencies}}}function p0e(e){const t=NZ(e);return(e.bindings||[]).flatMap(n=>{const r=jZ(n,t);return"diagnostic"in r?[r.diagnostic]:[]})}function KO(e){var o;const t=[],n=Ta(e.target),r=NZ(e);for(const s of e.bindings||[]){const i=jZ(s,r);if("diagnostic"in i){t.push(i.diagnostic);continue}const a=i.binding;if(!a||Ta(a.presentationTarget)!==n)continue;const u=Yi.canonicalizeSupportedCurrencyCode((o=e.values)==null?void 0:o[a.control.id]);if(!(!u||!a.currencies.includes(u)))return{currency:u,diagnostics:t}}return{diagnostics:t}}function g0e(e,t,n,r){const o={...e,config:{...e.config,matrix:t}},s=cI(o,[],r),i=lI(o,r),a={...t.presentation.measureFormats};for(const c of i){const u={kind:"matrix_measure",measureId:c.measureId},{currency:d}=KO({...n,...s,bindings:e.controlBindings,target:u});if(!d||!c.canonical)continue;const{locale:f,...h}=c.canonical;a[c.measureId]={...h,type:"currency",currency:d}}return{...t.presentation,measureFormats:a}}function x0e(e,t){if(!e||typeof e!="object"||!("kind"in e))return e;switch(e.kind){case"manual":return{kind:"manual",...t!=null&&t.includePresentation?{options:e.options.map(n=>({value:n.value,label:n.label,presentation:n.presentation}))}:{optionValues:e.options.map(n=>n.value).sort()}};case"dataset_values":return{kind:"dataset_values",fieldId:e.fieldId,connectionId:e.connectionId||""};case"field_allowlist":return{kind:"field_allowlist",fieldIds:[...e.fieldIds].sort()};case"metric_allowlist":return{kind:"metric_allowlist",metricIds:[...e.metricIds].sort()};case"sql_query":return{kind:"sql_query",connectionId:e.connectionId,sql:e.sql,valueColumn:e.valueColumn,labelColumn:e.labelColumn};default:return e}}function b0e(e,t){return{id:e.id,scope:e.scope,type:e.type,source:x0e(e.source,t),initialValueStrategy:e.initialValueStrategy,defaultValue:e.defaultValue,requiredAtExecution:e.requiredAtExecution,...t!=null&&t.includePresentation?{label:e.label,helpText:e.helpText,hidden:e.hidden,locked:e.locked,placement:e.placement,showLabel:e.showLabel,toolbarWidth:e.toolbarWidth}:{}}}function y0e(e,t){return e.target==="sql_param"||e.target==="presentation_currency"?e:e.target==="config_field_selector"&&!(t!=null&&t.includePresentation)?{...e,mapping:Object.fromEntries(Object.entries(e.mapping).sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>{if("kind"in r)return[n,r];const o={...r};return delete o.format,delete o.dateFormat,delete o.customFormat,delete o.semanticTemporalPresentation,[n,o]}))}:{...e,mapping:Object.fromEntries(Object.entries(e.mapping).sort(([n],[r])=>n.localeCompare(r)).map(([n,r])=>[n,r&&typeof r=="object"&&!Array.isArray(r)?Object.fromEntries(Object.entries(r).sort(([o],[s])=>o.localeCompare(s))):r]))}}function sV(e=[],t){return[...e].map(n=>b0e(n,t)).sort((n,r)=>n.id.localeCompare(r.id)||n.scope.localeCompare(r.scope)||n.type.localeCompare(r.type))}function v0e(e=[],t){return e.filter(n=>(t==null?void 0:t.includePresentation)||!nw(n)).map(n=>y0e(n,t)).sort((n,r)=>es.stableSerialize(n).localeCompare(es.stableSerialize(r)))}function $R(e,t){return e?es.stableSerialize({controlDefinitions:sV(e.controlDefinitions,t),cardControlDefinitions:sV(e.cardControlDefinitions,t),controlBindings:v0e(e.controlBindings,t)}):"__none__"}function hD(e,t){return e&&t.has(e)?e:null}function w0e({selectedSheetId:e,preservedSelectedSheetId:t,defaultSheetId:n,sheets:r}){var s;const o=new Set((r||[]).map(i=>i.id).filter(i=>typeof i=="string"));return hD(e,o)||hD(t,o)||hD(n,o)||((s=r==null?void 0:r[0])==null?void 0:s.id)||null}function C0e(e){var i,a;en.requireNormalizedDashboardInputs({inputs:e.inputs,dashboardFilters:e.filters});const t=[...Array.isArray(e.inputs)?e.inputs:[]],n=new Set(t.map(c=>c.id)),r=new Set((e.sheets||[]).filter(c=>c.kind==="document").map(c=>c.id));let o=!1;for(const c of e.sheets||[])if(!(c.kind!=="document"||!((a=(i=c.document)==null?void 0:i.inputs)!=null&&a.length)))for(const u of c.document.inputs)n.has(u.id)||(t.push(S0e(u,c.id)),n.add(u.id),o=!0);const s=t.map(c=>{if(c.kind==="filter"&&c.filter!==void 0&&iV(c,r)&&c.filter.variableName!==c.variableName)return o=!0,{...c,filter:{...c.filter,variableName:c.variableName}};if(c.kind!=="control"||!iV(c,r))return c;const u=m.createUniqueDashboardInputVariableNameFromName(c.control.id||c.variableName,t.filter(d=>d.id!==c.id));return c.variableName===u&&c.control.id===u?c:(o=!0,{...c,variableName:u,control:{...c.control,id:u}})});return o?{...e,inputs:s}:e}function S0e(e,t){const n={id:e.id,label:e.label,variableName:e.variableName,description:e.description,requiredAtExecution:e.requiredAtExecution,scope:{kind:"sheets",sheetIds:[t]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},exports:e.exports,compatibility:{source:"documentInput",sheetId:t,inputId:e.id}};return e.kind==="filter"?{...n,kind:"filter",filter:e.filter}:{...n,kind:"control",control:e.control}}function iV(e,t){var n;switch(e.scope.kind){case"allSheets":return!((n=e.scope.sheetKinds)!=null&&n.length)||e.scope.sheetKinds.includes("document");case"sheets":return e.scope.sheetIds.some(r=>t.has(r));case"documentSections":return t.has(e.scope.sheetId);default:return!1}}function zR({dashboard:e,dashboardInputValues:t,sheetId:n,cardId:r}){let o=m.compactDashboardInputValues(t||{});const s=j0e({dashboard:e,sheetId:n,cardId:r});if(s.status==="unresolved")return{};o=N0e({dashboardInputValues:o,savedSheetId:n,cardId:r,targets:s.targets});for(const i of s.targets){const a=m.removeShadowedCompatibilityInputs(m.buildNormalizedDashboardInputs({dashboard:e,card:i.card}).allInputs).filter(c=>m.canAddressDashboardInputRuntimeSlot(c,i)&&m.doesDashboardInputApplyToTarget(c,i));for(const c of a){const u=m.getDashboardInputRuntimeSlot(o,c,i),d=m.materializeDashboardInputRuntimeSlot(c,u);if(d&&d!==u&&(o=m.setDashboardInputRuntimeSlot(o,c,i,d)),!d||d.status===void 0){o=m.setDashboardInputRuntimeSlot(o,c,i,{status:"cleared",comparisonSelection:d==null?void 0:d.comparisonSelection});continue}d.status==="set"&&m.isComparisonCapableDashboardDateInput(c)&&!d.comparisonSelection&&(o=m.setDashboardInputRuntimeSlot(o,c,i,{...d,comparisonSelection:{mode:"off"}}))}}return m.compactDashboardInputValues(o)}function N0e({dashboardInputValues:e,savedSheetId:t,cardId:n,targets:r}){var c,u,d,f;const o={},s=new Set(r.flatMap(h=>h.sheetId?[h.sheetId]:[])),i=new Set(r.flatMap(h=>h.cardId?[h.cardId]:[])),a=new Set(r.flatMap(h=>h.sectionId?[h.sectionId]:[]));if(e.shared&&(o.shared={...e.shared}),n){const h=r[0],p=(t?(c=e.bySheetId)==null?void 0:c[t]:void 0)??(h.sheetId?(u=e.bySheetId)==null?void 0:u[h.sheetId]:void 0);h.sheetId&&p&&(o.bySheetId={[h.sheetId]:{...p}});const g=h.cardId?(d=e.byCardId)==null?void 0:d[h.cardId]:void 0;h.cardId&&g&&(o.byCardId={[h.cardId]:{...g}});const x=Object.entries(e.byDocumentSectionId||{}),b=(h.sectionId?(f=e.byDocumentSectionId)==null?void 0:f[h.sectionId]:void 0)??(x.length===1?x[0][1]:void 0);return h.sectionId&&b&&(o.byDocumentSectionId={[h.sectionId]:{...b}}),m.compactDashboardInputValues(o)}return o.bySheetId=mD(e.bySheetId,s),o.byCardId=mD(e.byCardId,i),o.byDocumentSectionId=mD(e.byDocumentSectionId,a),m.compactDashboardInputValues(o)}function mD(e,t){if(!e)return;const n=Object.entries(e).filter(([r])=>t.has(r));return n.length>0?Object.fromEntries(n.map(([r,o])=>[r,{...o}])):void 0}function j0e({dashboard:e,sheetId:t,cardId:n}){var i;if(n){const a=k0e(e,n);return a?{status:"resolved",targets:[a]}:{status:"unresolved",targetKind:"card"}}const r=(e.sheets||[]).filter(a=>!t||a.id===t);if(t&&r.length===0)return{status:"unresolved",targetKind:"sheet"};const o=r.map(a=>({sheetId:a.id,sheetKind:a.kind||"dashboard"})),s=new Set(r.map(a=>a.id));for(const a of m.getDashboardCardEntries(e))s.has(a.sheet.id)&&o.push({sheetId:a.sheet.id,cardId:a.card.id,card:a.card,sheetKind:a.sheet.kind||"dashboard"});for(const a of r)if(a.kind==="document")for(const c of((i=a.document)==null?void 0:i.sections)||[])o.push({sheetId:a.id,sectionId:c.id,...(c.type==="table"||c.type==="chart")&&{cardId:c.card.id,card:c.card},sheetKind:"document"});return{status:"resolved",targets:o.length>0?o:[{}]}}function k0e(e,t){var r;const n=m.findCardLocationById(e,t);if(n)return{sheetId:n.sheet.id,cardId:n.card.id,card:n.card,sheetKind:n.sheet.kind||"dashboard"};for(const o of e.sheets||[])if(o.kind==="document"){for(const s of((r=o.document)==null?void 0:r.sections)||[])if((s.type==="table"||s.type==="chart")&&s.card.id===t)return{sheetId:o.id,sectionId:s.id,cardId:s.card.id,card:s.card,sheetKind:"document"}}}function kZ({dashboardInputValues:e,dashboard:t,filterValues:n,sheetId:r,cardId:o,sectionId:s,sheetKind:i}){var u,d,f;if(!((u=t.inputs)!=null&&u.length))return e;const a=new Map(n.map(h=>[h.filterId,h]));let c=e||{};for(const h of t.inputs){if(h.kind!=="filter"||!m.doesDashboardInputApplyToTarget(h,{sheetId:r,cardId:o,sectionId:s,sheetKind:i}))continue;const p=((d=h.filter)==null?void 0:d.id)||((f=h.filterReference)==null?void 0:f.filterId);if(!p)continue;const g=a.get(p),x=g?m.createFilterDashboardInputSlot(g):void 0,b=(x==null?void 0:x.status)==="set"?x:{status:"cleared"};c=m.setDashboardInputRuntimeValueAspect(c,h,{sheetId:r,cardId:o,sectionId:s},b)}return c}function su({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,generatedAt:a,timezone:c}){const u=A1({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,timezone:c});return{context:u,snapshot:{...t?{sheetId:t}:{},...n!=null&&n.id?{cardId:n.id}:{},mode:s,dashboardInputValues:_0e({inputs:u.inputs,context:u,sheetId:t,cardId:n==null?void 0:n.id,sectionId:r}),generatedAt:a,timezone:c}}}function IZ({sectionIds:e,...t}){const n=new Set,r=o=>{for(const s of o.missingRequiredInputs)n.add(s.label)};r(A1(t));for(const o of e)r(A1({...t,sectionId:o}));for(const{sectionId:o,card:s}of TZ(t.dashboard,t.sheetId,e))r(A1({...t,sectionId:o,card:s}));return Array.from(n)}function WO({sheetIds:e,sheetKind:t="dashboard",...n}){const r=e.map(a=>su({...n,sheetId:a,sheetKind:t})),o=e.flatMap(a=>I0e(n.dashboard,a).map(c=>su({...n,sheetId:a,card:c,sheetKind:t}))),s=r[0]||o[0]||su({...n,sheetKind:t}),i=DZ(...r.map(a=>a.snapshot.dashboardInputValues),...o.map(a=>a.snapshot.dashboardInputValues));return{context:s.context,snapshot:{...e.length===1?{sheetId:e[0]}:{},mode:n.mode,dashboardInputValues:i,generatedAt:n.generatedAt,timezone:n.timezone}}}function I0e(e,t){var i;const n=(i=e.sheets)==null?void 0:i.find(a=>a.id===t),r=[],o=new Set,s=a=>{!(a!=null&&a.id)||o.has(a.id)||(o.add(a.id),r.push(a))};for(const a of(n==null?void 0:n.cards)||[])s(a);for(const a of(n==null?void 0:n.frames)||[])for(const c of(a==null?void 0:a.cards)||[])s(c);return r}function _Z({sectionIds:e,...t}){const n=su(t),r=e.map(s=>su({...t,sectionId:s})),o=TZ(t.dashboard,t.sheetId,e).map(({sectionId:s,card:i})=>su({...t,sectionId:s,card:i}));return{...n,snapshot:{...n.snapshot,dashboardInputValues:DZ(n.snapshot.dashboardInputValues,...r.map(s=>s.snapshot.dashboardInputValues),...o.map(s=>s.snapshot.dashboardInputValues))}}}function TZ(e,t,n){var i,a;const r=new Set(n),o=(i=e.sheets)==null?void 0:i.find(c=>c.id===t);return(((a=o==null?void 0:o.document)==null?void 0:a.sections)||[]).flatMap(c=>c.id&&r.has(c.id)&&c.card?[{sectionId:c.id,card:c.card}]:[])}function _0e({inputs:e,context:t,sheetId:n,cardId:r,sectionId:o}){const s=new Map(t.resolvedInputs.map(a=>[a.id,a]));let i={};for(const a of e){const c=s.get(a.id),u=m.materializeDashboardInputRuntimeSlot(a,c==null?void 0:c.slot)||{status:"cleared"};i=m.setDashboardInputRuntimeSlot(i,a,{sheetId:n,cardId:r,sectionId:o},u)}return m.compactDashboardInputValues(i)}function T0e(e){return e==="document"||e==="visual"?"export":"print"}function A1({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,mode:s,runtimeValues:i,timezone:a}){return m.resolveDashboardInputContext({dashboard:e,sheetId:t,card:n,sectionId:r,sheetKind:o,runtimeValues:i,mode:T0e(s),timezone:a})}function DZ(...e){const t={};for(const n of e)n.shared&&(t.shared={...t.shared,...n.shared}),pD(t,"bySheetId",n.bySheetId),pD(t,"byCardId",n.byCardId),pD(t,"byDocumentSectionId",n.byDocumentSectionId);return m.compactDashboardInputValues(t)}function pD(e,t,n){if(n){e[t]||(e[t]={});for(const[r,o]of Object.entries(n))e[t][r]={...e[t][r],...o}}}function EZ(e){var n;return typeof window>"u"||new URLSearchParams(window.location.search).get("isPdfRender")!=="true"?null:((n=kx(e))==null?void 0:n.reportContext)??null}function kx(e){if(typeof window>"u")return e?ji.parsePresentationExecutionSnapshot(e):null;const t=new URLSearchParams(window.location.search);if(t.get("isPdfRender")!=="true")return null;if(e)return ji.parsePresentationExecutionSnapshot(e);const n=t.get("presentationExecutionSnapshot");if(!n)return null;let r;try{r=JSON.parse(n)}catch{throw new ji.PresentationExecutionSnapshotError("Internal print presentation snapshot JSON is invalid.")}return ji.parsePresentationExecutionSnapshot(r)}function rw(){if(typeof window>"u")return;const e=new URLSearchParams(window.location.search).get("presentationAttachmentIndex");if(e===null)return;const t=Number(e);if(!Number.isInteger(t)||t<0)throw new Error("Internal print presentation attachment index is invalid");return t}function D0e(e){return e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e}function E0e(e,t){const n=D0e(e);return n==="dark"?sc({...t==null?void 0:t.default},{...t==null?void 0:t.dark}):t==null?void 0:t.default}function aV(e,t,n){return pve(E0e(e,t),n)}function M0e(e){return es.stableSerialize({hasExplicitDefaultControlValues:e!==void 0,values:e??null})}function R0e(e,t){const{controlContractOverrides:n,cardId:r}=t;if(!n||(n.controlDefinitions!==void 0&&(e.controls=n.controlDefinitions),typeof r!="string"||r.trim().length===0))return e;const o=m.findCardById(e,r);return o&&(n.cardControlDefinitions!==void 0&&(o.controls=n.cardControlDefinitions),n.controlBindings!==void 0&&(o.controlBindings=n.controlBindings)),e}function A0e(e,t){const n=v.useRef({key:t,value:e});return n.current.key!==t&&(n.current={key:t,value:e}),n.current.value}function F0e({customStyle:e,currentTheme:t,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,defaultFilterValues:s,defaultControlValues:i,controlContractOverrides:a,dashboardInputExecutionSnapshot:c,interactionExecutionSnapshot:u,presentationExecutionSnapshot:d,type:f,cardId:h,selectedSheetId:p,onFilterValuesChange:g}){var ge,ee;const{authToken:x,tokenProps:b}=Mt(),y=x==null?void 0:x.accessToken,C=x==null?void 0:x.refreshToken,w=v.useMemo(()=>EZ(d),[d]);o0e();const N=m.useDashboardStore(ce=>ce.selectedLensId),S=m.useDashboardStore(ce=>ce.relaodToken),{data:j,isLoading:k,isFetching:_,isError:T,refetch:I,dashboardIdToFetch:D}=ew(),E=(ge=j==null?void 0:j.dashboard)==null?void 0:ge.id,{getDefaultSheetId:R,clearDefaultSheetId:F}=mZ(E),[M,O]=v.useState(s||[]),z=v.useRef(null),L=v.useRef(null),V=M0e(i),A=$R(a),B=$R(a,{includePresentation:!0}),$=v.useRef(i);$.current=i;const P=v.useRef(V);P.current=V;const U=A0e(a,B),H=v.useRef(null),G=v.useRef(!1),q=v.useRef({dashboardId:null,defaultControlValuesKey:V,controlContractOverridesKey:A}),{setTheme:Y}=BY(),{compiledAppearance:W}=fi.useAppearance(),ne=m.useDashboardStore(ce=>ce.dashboard.globalStyle),Z=v.useMemo(()=>j!=null&&j.dashboard?C0e(R0e(en.cloneDeep(j.dashboard),{controlContractOverrides:U,cardId:h})):void 0,[j==null?void 0:j.dashboard,U,f,h]),{setDashboardWithFilterValues:K,hydrateRuntimeControlValues:X,setStyle:J,setOnSaveFunction:re,setLenses:te,setSelectedLensId:Q,setInlineFilterValuesMap:se}=m.useDashboardActions();m.useDashboardStore(ce=>ce.actions.setCustomCards);const oe=m.useDashboardStore(ce=>ce.filterValues),fe=m.useDashboardStore(ce=>ce.actions.setThemeStyle),pe=m.useDashboardStore(ce=>ce.actions.setDashboardTheme),xe=m.useDashboardStore(ce=>ce.actions.setOnEvent),Ie=m.useDashboardStore(ce=>ce.actions.setOnDashboardLifecycleEvent);v.useEffect(()=>{const ce=L.current;ce&&ce!==D&&m.storeEvents.emit("dashboard:unload"),L.current=D},[D]),v.useEffect(()=>{S&&I()},[I,S]),v.useEffect(()=>{var me;const ce=((me=j==null?void 0:j.dashboard)==null?void 0:me.id)||null,ae=z.current;ce&&ce!==ae&&m.storeEvents.emit("dashboard:load"),z.current=ce},[(ee=j==null?void 0:j.dashboard)==null?void 0:ee.id]),v.useEffect(()=>{pe(W.mode)},[W.mode,pe]),v.useEffect(()=>{t&&Y(t)},[t,Y]);const be=v.useCallback(()=>{const ce=en.cloneDeep(lt.DEFAULT_STYLE),ae=sc(ce,ne);if(e){const me=sc(ae,e),ve=aV(W.mode,me,W);fe(ve),J(me)}else{const me=aV(W.mode,ae,W);fe(me),J(lt.DEFAULT_STYLE)}},[W,e,ne,fe,J]);return v.useEffect(()=>{j&&j.dashboard&&be()},[W.mode,e,ne,be,j]),v.useEffect(()=>{var Bt,ut,$t,Fe,ct,It;function ce(yt,vt){const mt=yt.filters||[],St=[];for(const it of vt){const nt=mt.find(gt=>gt.id===it.filterId);nt&&St.push(en.materializeFilterValueNativeDataType({definition:nt,sourceValue:it,value:{filterId:it.filterId,name:nt.column,operation:it.operation,valueType:m.getFilterValueType(nt),values:it.values,dataType:nt.dataType,fieldMeta:nt.fieldMeta,semanticContext:nt.semanticContext}}))}return St}if(!j||!Z)return;const ae=Z,me=m.useDashboardStore.getState(),ve=me.reportContextSessionAccessToken===y&&((Bt=me.dashboard)==null?void 0:Bt.id)===Z.id&&me.reportContext!==null,_e=w??j.initialReportContext,De=(ve?(ut=me.reportContext)==null?void 0:ut.calendar.tz:void 0)??_e.calendar.tz,{filterValues:Ue,defaultLensId:Ne,lenses:Oe}=j;function ye(){if(Ue&&(Ue==null?void 0:Ue.length)>0)return Ue;const vt=[...m.buildFilterValuesFromDefaults(ae.filters,De)];if(ae.defaultFilterValues&&ae.defaultFilterValues.length>0)for(const it of ae.defaultFilterValues){const nt=vt.findIndex(gt=>gt.filterId===it.filterId);nt>=0?vt[nt]=it:vt.push(it)}const mt=ce(ae,M||[]),St=[...vt];for(const it of mt){const nt=St.findIndex(gt=>gt.filterId===it.filterId);nt>=0?St[nt]=it:St.push(it)}return St}const Be=H.current===Z.id&&(($t=me.dashboard)==null?void 0:$t.id)===Z.id,he=ye(),ue=Be?m.resolveSameDashboardFilterValues({previousFilters:(Fe=me.dashboard)==null?void 0:Fe.filters,nextFilters:ae.filters,currentFilterValues:me.filterValues,defaultFilterValues:he}):he,de=en.materializeFilterValuesNativeDataType({filterDefinitions:ae.filters,filterValues:ue}),Te=m.computeInlineFilterDefaults(ae,De),we=Be&&q.current.controlContractOverridesKey===A?m.flattenRuntimeControlValues({dashboardValues:me.controlValues,cardValuesMap:me.cardControlValuesMap}):$.current,Ee=me.selectedSheetId;let Ke=R(),He=Ee;He&&((ct=Z==null?void 0:Z.sheets)!=null&&ct.some(vt=>vt.id===He)||(He=null)),Ke&&((It=Z==null?void 0:Z.sheets)!=null&&It.some(vt=>vt.id===Ke)||(F(),Ke=null));const qe=w0e({selectedSheetId:p,preservedSelectedSheetId:He,defaultSheetId:Ke,sheets:Z==null?void 0:Z.sheets}),Je=!!c,We=!!(N||j!=null&&j.defaultLensId),bt=!Je&&G.current,pt=c?zR({dashboard:ae,dashboardInputValues:c.dashboardInputValues,sheetId:c.sheetId,cardId:c.cardId}):(j==null?void 0:j.inputValues)!=null?zR({dashboard:ae,dashboardInputValues:j.inputValues.dashboardInputValues}):void 0;K(ae,de||[],we,{selectedSheetId:qe,reportContext:ve?void 0:_e,authToken:y?{accessToken:y,refreshToken:C}:void 0,...j!=null&&j.semanticExecutionPayload?{semanticExecutionPayload:j.semanticExecutionPayload}:{},...c?{dashboardInputValues:pt,dashboardInputReferenceTime:c.generatedAt}:We?{dashboardInputValues:pt||{},dashboardInputReferenceTime:(j==null?void 0:j.inputValues)!=null?j.inputValues.generatedAt:void 0}:bt?{dashboardInputValues:{},dashboardInputReferenceTime:void 0}:{}}),u&&m.useInteractionStore.setState({interactionStates:en.cloneDeep(u)}),G.current=Je,H.current=Z.id,q.current.dashboardId!==Z.id&&(q.current={dashboardId:Z.id,defaultControlValuesKey:P.current,controlContractOverridesKey:A}),se(Te),Oe&&te(Oe),Ne&&Q(Ne)},[j,N,te,K,Q,se,M,p,R,F,A,c,u,Z,y,C,w]),v.useEffect(()=>{if(!(Z!=null&&Z.id))return;const ce=q.current;if(ce.dashboardId!==Z.id){q.current={dashboardId:Z.id,defaultControlValuesKey:V,controlContractOverridesKey:A};return}ce.defaultControlValuesKey===V&&ce.controlContractOverridesKey===A||(X(Z,$.current),q.current={dashboardId:Z.id,defaultControlValuesKey:V,controlContractOverridesKey:A})},[Z,V,A,X]),v.useEffect(()=>{g&&oe&&g(oe)},[oe,g]),v.useEffect(()=>{n&&re(n),r&&xe(r)},[n,re,r,xe]),v.useEffect(()=>(Ie(o),()=>{m.useDashboardStore.getState().onDashboardLifecycleEvent===o&&Ie(void 0)}),[o,Ie]),{isFetching:_,isLoading:k,isError:T,refetch:I}}const FN=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));FN.displayName="Card";const GO=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("flex flex-col space-y-1.5 p-6",e),...t}));GO.displayName="CardHeader";const Ix=ie.forwardRef(({className:e,...t},n)=>l.jsx("h3",{ref:n,className:m.cn("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ix.displayName="CardTitle";const P0e=ie.forwardRef(({className:e,...t},n)=>l.jsx("p",{ref:n,className:m.cn("text-sm text-muted-foreground",e),...t}));P0e.displayName="CardDescription";const YO=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("px-6 pt-0",e),...t}));YO.displayName="CardContent";const MZ=ie.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:m.cn("flex items-center p-6 pt-0",e),...t}));MZ.displayName="CardFooter";/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -725,7 +725,7 @@ For more information, see https://radix-ui.com/primitives/docs/components/alert-
725
725
  <\/script>
726
726
  <script type="module" crossorigin="anonymous" src="${wD(e.runtime.entryUrl)}"><\/script>
727
727
  </body>
728
- </html>`}function rNe({dataApp:e,onBack:t}){var d;const{authToken:n,tokenProps:r}=Mt(),[o,s]=v.useState(null),i=Yn({queryKey:["published-data-app-runtime",r.apiServiceUrl,n==null?void 0:n.accessToken,e.id],queryFn:async()=>m.getRequest(`${r.apiServiceUrl}/data-apps/${e.id}/runtime`,(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)&&!!e.id});v.useEffect(()=>{function f(h){const p=h.data;(p==null?void 0:p.source)!=="semaphor-data-app-runtime"||p.type!=="runtime-error"||s(p.message||"Published Data App failed to load.")}return window.addEventListener("message",f),()=>window.removeEventListener("message",f)},[]),v.useEffect(()=>{s(null)},[e.id]);const a=(d=i.data)==null?void 0:d.dataApp,c=a==null?void 0:a.runtime,u=v.useMemo(()=>!a||!c?"":nNe({title:a.title||e.title,apiBaseUrl:r.apiServiceUrl,dataApp:a,runtime:c}),[e.title,c,a,r.apiServiceUrl]);return l.jsxs("div",{className:"flex h-full grow flex-col bg-background text-foreground",children:[l.jsxs("header",{className:"flex h-14 shrink-0 items-center justify-between border-b border-border/60 px-4",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx(m.Button,{"aria-label":"Back to Analytics workspace",className:"h-8 w-8 px-0",onClick:t,size:"xs",variant:"ghost",children:l.jsx(ow,{className:"h-4 w-4"})}),l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data App"}),l.jsx("h1",{className:"truncate text-[14px] font-semibold",children:(a==null?void 0:a.title)||e.title})]})]}),c?l.jsxs("div",{className:"rounded-md border border-border px-2 py-1 text-[11px] text-muted-foreground",children:["v",c.version]}):null]}),i.isLoading?l.jsx("div",{className:"flex flex-1 items-center justify-center",children:l.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Loading Data App..."]})}):i.isError?l.jsx("div",{className:"flex flex-1 items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-5 w-5 text-destructive"}),l.jsx("h2",{className:"text-[13px] font-medium",children:"Couldn't load Data App"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"The published runtime could not be fetched. Please try again."})]})}):c?l.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[o?l.jsx("div",{className:"border-b border-destructive/30 bg-destructive/10 px-4 py-2 text-[12px] text-destructive",children:o}):null,l.jsx("iframe",{className:"min-h-0 flex-1 border-0",sandbox:"allow-forms allow-modals allow-popups allow-scripts",srcDoc:u,title:(a==null?void 0:a.title)||e.title})]}):l.jsx("div",{className:"flex flex-1 items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-5 w-5 text-muted-foreground/60"}),l.jsx("h2",{className:"text-[13px] font-medium",children:"No published version yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Publish this Data App before opening it from the Analytics workspace."})]})})]})}function wJ(e){if(e&&e.type!=="organization"&&e.type==="tenant")return fw(e.role)?void 0:{showFilters:!1}}function oNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function sNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function iNe(e){return!!e}function CJ(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function aNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function lNe(e){var t;return e?e.type==="organization"?!0:e.type==="tenant"?((t=e.role)==null?void 0:t.toUpperCase())==="POWER_USER":!1:!1}function fw(e){const t=e==null?void 0:e.toUpperCase();return t?t!=="VIEWER":!1}function cNe(e){var t;return e.isPublic?"public":(((t=e.ownership)==null?void 0:t.sharedCount)??0)>0?"shared":"private"}function $C(e,t){var n,r,o,s;switch(t){case"name":return((n=e.title)==null?void 0:n.toLowerCase())??"";case"createdBy":return((s=(o=(r=e.ownership)==null?void 0:r.createdBy)==null?void 0:o.name)==null?void 0:s.toLowerCase())??"";case"updatedAt":return new Date(e.updatedAt).getTime()||0;case"visibility":return cNe(e);default:return""}}function gV(e,t){return typeof e=="number"&&typeof t=="number"?e-t:String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:"base"})}function uNe(e,t,n){const r=t.direction==="asc"?1:-1;return[...e].sort((o,s)=>{if(n){if(o.id===n)return-1;if(s.id===n)return 1}const i=gV($C(o,t.key),$C(s,t.key))*r;if(i!==0)return i;const a=gV($C(o,"name"),$C(s,"name"));return a!==0?a:o.id.localeCompare(s.id)})}function SJ(e){return(e==null?void 0:e.showDashboardSharing)!==!1}function dNe({isDashboardEditing:e,canEditDashboard:t,hasCurrentLens:n}){return e&&t&&!n}function fNe({config:e,canNavigateDashboardHub:t,canShareDashboard:n,canManageGroups:r}){return{showDashboardHub:(e==null?void 0:e.showDashboardHub)!==!1&&t,showDashboardSharing:SJ(e)&&n,showGroupManagement:(e==null?void 0:e.showGroupManagement)!==!1&&r}}function hNe({onDashboardSelect:e}){var ee,ce,ae,me;const{authToken:t,tokenProps:n}=Mt(),r=SJ(n.config),o=((ce=(ee=n.config)==null?void 0:ee.projectFeatures)==null?void 0:ce.features.dashboardAiAuthoring)!==!1,[s,i]=v.useState(!1),[a,c]=v.useState(!1),[u,d]=v.useState(null),[f,h]=v.useState(!1),[p,g]=v.useState(null),[x,b]=v.useState(null),[y,C]=v.useState(null),[w,N]=v.useState(null),[S,j]=v.useState(""),[k,_]=v.useState("all"),[T,I]=v.useState({key:"updatedAt",direction:"desc"}),{data:D}=qQ(),E=((ae=D==null?void 0:D.preference)==null?void 0:ae.defaultDashboardId)||null,R=Ls(ve=>ve.actions.selectDashboard),{currentUser:F,userContext:M}=hi(),O=((me=M==null?void 0:M.permissions)==null?void 0:me.canCreateDashboard)??CJ(F),{onCreateSuccess:z}=iSe({onDashboardSelect:e}),{resources:L,isLoading:V,isError:A,createResourceAsync:B,updateResource:$,deleteResource:P,duplicateResource:U,isCreating:H,isDeleting:G,refetch:q}=nSe(()=>{h(!1),g(null)},ve=>{i(!1),z(ve,q)}),{startUpdating:Y,stopUpdating:W,isUpdating:ne}=CQ(),Z=ve=>{const _e=L.find(De=>De.id===ve);if(_e){if(_e.kind==="data_app"){N(_e);return}R(_e),e==null||e(ve)}},K=ve=>{const _e=eNe(ve);return B({title:ve.title,description:ve.description,isPrivate:!1,..._e?{template:_e}:{}})},X=ve=>{g(ve),h(!0)},J=()=>{p&&P(p.id)},re=ve=>{b(ve),U(ve,{onSettled:()=>b(null)})},te=(ve,_e,De)=>{var ye;const Ue=Object.fromEntries(Object.entries(_e).filter(([,Be])=>Be!==void 0));if(Object.keys(Ue).length===0){(ye=De==null?void 0:De.onSuccess)==null||ye.call(De);return}const Ne=Object.keys(Ue),Oe=Ne.length===1?Ne[0]:void 0;Y(ve,Oe),$({resourceId:ve,data:Ue},{onSuccess:()=>{var Be;W(ve,Oe),(Be=De==null?void 0:De.onSuccess)==null||Be.call(De)},onError:()=>{var Be;W(ve,Oe),(Be=De==null?void 0:De.onError)==null||Be.call(De)}})},Q=ve=>{d(ve),c(!0)},se=ve=>new Date(ve).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),oe=L.length>5,fe=oe?S.trim().toLowerCase():"",pe=v.useMemo(()=>L.filter(ve=>ve.kind!=="data_app").length,[L]),xe=v.useMemo(()=>L.filter(ve=>ve.kind==="data_app").length,[L]),Ie=pe>0&&xe>0,be=v.useMemo(()=>{let ve=L;return Ie&&k!=="all"&&(ve=ve.filter(_e=>k==="data_app"?_e.kind==="data_app":_e.kind!=="data_app")),fe&&(ve=ve.filter(_e=>{var Ne,Oe;const De=((Ne=_e.title)==null?void 0:Ne.toLowerCase())??"",Ue=((Oe=_e.description)==null?void 0:Oe.toLowerCase())??"";return De.includes(fe)||Ue.includes(fe)})),uNe(ve,T,E)},[fe,L,E,k,Ie,T]),ge=ve=>{I(_e=>_e.key!==ve?{key:ve,direction:ve==="updatedAt"?"desc":"asc"}:{key:ve,direction:_e.direction==="asc"?"desc":"asc"})};return w?l.jsx(rNe,{dataApp:w,onBack:()=>N(null)}):t?A?l.jsx("div",{className:"flex h-full grow items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-6 w-6 text-destructive"}),l.jsx("h2",{className:"text-[13px] font-medium text-foreground",children:"Couldn't load dashboards"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Unable to fetch your dashboards. Please try again."}),l.jsx(m.Button,{size:"xs",variant:"outline",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):l.jsxs(mNe,{children:[l.jsxs(pNe,{children:[l.jsxs("div",{className:"flex items-start justify-between gap-6",children:[l.jsxs("div",{className:"min-w-0",children:[l.jsx("h1",{className:"text-[15px] font-semibold tracking-tight text-foreground",children:"Analytics workspace"}),l.jsxs("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:["Pick an existing dashboard or app, or create a dashboard.",!V&&L.length>0?l.jsxs("span",{className:"ml-1.5",children:["· ",L.length," item",L.length!==1?"s":""]}):null]})]}),O&&l.jsx("div",{className:"flex items-center gap-1.5",children:l.jsxs(m.Button,{size:"xs",onClick:()=>i(!0),children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"New dashboard"]})})]}),V?l.jsx(gNe,{}):L.length===0?l.jsx("div",{className:"flex items-center justify-center py-20",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(zd,{className:"h-6 w-6 text-muted-foreground/60"}),l.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:"No dashboards yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:O?"Create your first dashboard to get started.":"No dashboards have been shared with you yet."}),O&&l.jsx("div",{className:"mt-2 flex items-center gap-1.5",children:l.jsxs(m.Button,{size:"xs",onClick:()=>i(!0),children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Create dashboard"]})})]})}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"mt-7 flex items-center gap-6 border-b border-border/60",children:Ie?l.jsxs(l.Fragment,{children:[l.jsx(CD,{label:"All",count:L.length,active:k==="all",onClick:()=>_("all")}),l.jsx(CD,{label:"Dashboards",count:pe,active:k==="dashboard",onClick:()=>_("dashboard")}),l.jsx(CD,{label:"Data apps",count:xe,active:k==="data_app",onClick:()=>_("data_app")})]}):l.jsxs("span",{className:"-mb-px border-b-2 border-foreground px-0.5 pb-2.5 text-[13px] font-medium text-foreground",children:["Your dashboards",l.jsx("span",{className:"ml-1.5 text-[11px] font-normal tabular-nums text-muted-foreground/70",children:L.length})]})}),be.length===0&&!oe?l.jsx("div",{className:"flex items-center justify-center py-20 text-center",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-1",children:[l.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:"No dashboards found"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No items match the current filter."})]})}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:m.cn("mt-1 grid items-center gap-4 border-b border-border/60 px-2 py-2.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",gQ),children:[l.jsx("div",{children:l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx("div",{className:"min-w-0 flex-1",children:oe?l.jsx(xwe,{label:"Name",value:S,onChange:j,placeholder:"Filter dashboards…"}):l.jsx("span",{children:"Name"})}),l.jsx(zC,{sortKey:"name",sortState:T,onSort:ge,label:"Sort by name"})]})}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Created by"}),l.jsx(zC,{sortKey:"createdBy",sortState:T,onSort:ge,label:"Sort by created by"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Updated"}),l.jsx(zC,{sortKey:"updatedAt",sortState:T,onSort:ge,label:"Sort by updated"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Visibility"}),l.jsx(zC,{sortKey:"visibility",sortState:T,onSort:ge,label:"Sort by visibility"})]}),l.jsx("div",{})]}),be.length===0?l.jsx("div",{className:"flex items-center justify-center py-12 text-center",children:l.jsxs("p",{className:"text-[12px] text-muted-foreground",children:["No dashboards match “",S.trim(),"”."]})}):l.jsx("div",{children:be.map(ve=>l.jsx(xNe,{dashboard:ve,isDefault:ve.kind!=="data_app"&&ve.id===E,onView:Z,isDeleting:G&&(p==null?void 0:p.id)===ve.id,isDuplicating:x===ve.id,onEditDetails:C,onDeleteClick:X,onDuplicateDashboard:re,onShareDashboard:r?Q:void 0,formatDate:se},ve.id))})]})]})]}),l.jsx(ESe,{open:s,onOpenChange:i,onCreateBlank:K,onAiCreateSuccess:ve=>{i(!1),z(ve.dashboard,q)},isCreatingBlank:H,aiAuthoringEnabled:o}),y&&l.jsx(vJ,{open:!!y,resourceLabel:"Dashboard",initialTitle:y.title||"",initialDescription:y.description||"",onClose:()=>C(null),onSave:ve=>{te(y.id,ve,{onSuccess:()=>{C(null)}})},isSaving:ne(y.id)}),l.jsx(ff,{open:f,onOpenChange:h,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete Dashboard?"}),l.jsxs(Ru,{children:['Are you sure you want to delete "',p==null?void 0:p.title,'"? This action cannot be undone.']})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{disabled:G,children:"Cancel"}),l.jsx(Au,{onClick:J,disabled:G,children:G?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete"})]})]})}),r&&u&&a&&l.jsx(yJ,{resource:u,resourceType:uo.DASHBOARD,onClose:()=>{c(!1),d(null)}})]}):l.jsx("div",{className:"flex h-full grow items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-6 w-6 text-muted-foreground/60"}),l.jsx("h2",{className:"text-[13px] font-medium text-foreground",children:"Authentication required"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Please provide authentication to view dashboards."})]})})}function CD({label:e,count:t,active:n,onClick:r}){return l.jsxs("button",{type:"button",onClick:r,className:m.cn("-mb-px border-b-2 px-0.5 pb-2.5 text-[13px] transition-colors",n?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:[e,l.jsx("span",{className:m.cn("ml-1.5 text-[11px] tabular-nums",n?"font-normal text-muted-foreground/70":"text-muted-foreground/70"),children:t})]})}function zC({sortKey:e,sortState:t,onSort:n,label:r}){const o=t.key===e,s=o&&t.direction==="asc",i=o&&t.direction==="desc";return l.jsx("button",{type:"button",onClick:()=>n(e),"aria-label":r,className:m.cn("inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-[3px] transition-colors",o?"text-foreground":"text-muted-foreground/60 hover:text-foreground focus-visible:text-foreground","focus:outline-none"),children:s?l.jsx(m.ChevronUp,{className:"h-3 w-3","aria-hidden":!0}):i?l.jsx(Re.ChevronDown,{className:"h-3 w-3","aria-hidden":!0}):l.jsx(ZZ,{className:"h-3 w-3","aria-hidden":!0})})}function mNe({children:e}){const t=Pu();return l.jsx("div",{"data-content-type":"dashboard-hub",className:"flex h-full grow flex-col bg-background text-foreground",style:t.dashboardContainerStyle,children:e})}function pNe({children:e}){const t=Pu();return l.jsx("div",{className:"flex flex-1 flex-col overflow-y-auto bg-background px-6 py-8 lg:px-10",style:t.dashboardCanvasStyle,children:e})}function gNe(){return l.jsx("div",{className:"flex min-h-[280px] flex-1 items-center justify-center",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Loading dashboards..."})]})})}function xNe(e){return l.jsx(zCe,{...e})}const Rh=m.create()(e=>({panels:{dashboard:{isOpen:!1,container:null},editor:{isOpen:!1,container:null}},fullscreen:null,setPanelOpen:(t,n)=>e(r=>r.panels[t].isOpen===n?r:{panels:{...r.panels,[t]:{...r.panels[t],isOpen:n}},fullscreen:!n&&r.fullscreen===t?null:r.fullscreen}),setFullscreen:t=>e(n=>n.fullscreen===t?n:{fullscreen:t}),setContainer:(t,n)=>e(r=>r.panels[t].container===n?r:{panels:{...r.panels,[t]:{...r.panels[t],container:n}}})})),NJ=e=>Rh(t=>t.panels[e]),jJ=()=>Rh(e=>e.fullscreen),kJ=e=>Rh(t=>t.panels[e].container??null);m.enableMapSet();const jI=m.create()(m.immer((e,t)=>({activeExports:new Map,actions:{addExport:n=>{e(r=>{r.activeExports.set(n.id,{...n,lastUpdatedAt:n.lastUpdatedAt??new Date})})},updateExport:(n,r)=>{e(o=>{const s=o.activeExports.get(n);if(s){const i={...s,...r};r.lastUpdatedAt||(i.lastUpdatedAt=new Date),o.activeExports.set(n,i)}})},removeExport:n=>{e(r=>{r.activeExports.delete(n)})},getInProgressExports:()=>Array.from(t().activeExports.values()).filter(r=>["pending","processing","chunking","compacting"].includes(r.status)),getAllExports:()=>Array.from(t().activeExports.values()).sort((n,r)=>r.startedAt.getTime()-n.startedAt.getTime()),clearCompleted:()=>{e(n=>{for(const[r,o]of n.activeExports)(o.status==="completed"||o.status==="failed")&&n.activeExports.delete(r)})},hasInProgressExports:()=>Array.from(t().activeExports.values()).some(r=>["pending","processing","chunking","compacting"].includes(r.status))}}))),IJ=()=>jI(e=>e.actions),bNe=()=>jI(e=>e.activeExports),yNe=()=>jI(e=>Array.from(e.activeExports.values()).filter(n=>["pending","processing","chunking","compacting"].includes(n.status)).length);function _J(){const{tokenProps:e,id:t}=Mt(),n=Ls(o=>o.selectedDashboard);return Ls(o=>o.showHub)?!1:!!(n!=null&&n.id||t||e!=null&&e.dashboard_id)}function vNe({title:e,description:t,onRetry:n,isRetrying:r=!1,className:o}){return l.jsx("div",{className:m.cn("flex h-full min-h-[320px] w-full grow items-center justify-center bg-muted/20 px-6 py-10",o),role:"alert",children:l.jsx("div",{className:"w-full max-w-sm rounded-md border border-border/70 bg-background p-5 shadow-sm",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-destructive/10 text-destructive",children:l.jsx(ea,{className:"h-4 w-4","aria-hidden":"true"})}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("h2",{className:"text-pretty text-[13px] font-medium text-foreground",children:e}),l.jsx("p",{className:"mt-1 break-words text-[12px] leading-5 text-muted-foreground",children:t}),n?l.jsxs(m.Button,{size:"xs",variant:"outline",className:"mt-3",onClick:n,disabled:r,children:[r?l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):null,r?"Trying Again…":"Try Again"]}):null]})]})})})}function k5({className:e,customStyle:t,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,LoadingComponent:s,ErrorComponent:i,onChartElementClicked:a,id:c,authToken:u,currentTheme:d,appearance:f,version:h,customCards:p,showAssistant:g,defaultFilterValues:x,defaultControlValues:b,controlContractOverrides:y,documentInputValues:C,dashboardInputExecutionSnapshot:w,interactionExecutionSnapshot:N,presentationExecutionSnapshot:S,renderMode:j,onFilterValuesChange:k,selectedSheetId:_,eventHandlers:T,type:I="dashboard",cardId:D,dashboardId:E,style:R,...F}){const{placeholders:M,tokenProps:O,id:z}=Mt();Ls(G=>G.selectedDashboard);const L=m.useDashboardStore(G=>G.themeStyle),V=Pu(),A=m.useDashboardStore(G=>G.isSessionExpired),{isLoading:B,isFetching:$,isError:P,refetch:U}=F0e({customStyle:t,currentTheme:d,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,defaultFilterValues:x,defaultControlValues:b,controlContractOverrides:y,dashboardInputExecutionSnapshot:w,interactionExecutionSnapshot:N,presentationExecutionSnapshot:S,onFilterValuesChange:k,selectedSheetId:_,type:I,cardId:D}),H=_J();return u&&!H&&!B?l.jsx(hNe,{}):P?(r==null||r({type:"error",message:"Error fetching dashboard"}),i?(console.log("Error fetching dashboard"),l.jsx(i,{})):l.jsx(vNe,{title:"Dashboard Couldn’t Load",description:"Check your connection and dashboard access, then try again.",onRetry:()=>void U(),isRetrying:$})):A?(r==null||r({type:"error",message:"Session Expired"}),M!=null&&M.SessionExpired?l.jsx("div",{className:"flex h-full w-full items-center justify-center",children:l.jsx("div",{children:M.SessionExpired})}):l.jsx("div",{className:"flex h-full w-full items-center justify-center",children:l.jsxs("div",{className:"space-y-4 rounded-md border border-muted p-10",children:[l.jsx(Ix,{children:"Session Expired"}),l.jsx("p",{className:"text-muted-foreground",children:"Please refresh your page to continue"})]})})):B||!u?(r==null||r({type:"info",message:"Loading dashboard"}),s?l.jsx(s,{message:"loading"}):l.jsx("div",{className:"flex h-full min-h-[320px] w-full grow items-center justify-center",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Loading dashboard…"})]})})):l.jsx("div",{className:m.cn("isolate flex grow flex-col",{"h-full":I==="visual"},L==null?void 0:L.dashboardPanel,e),style:{...V.dashboardContainerStyle,...R},"data-role":"semaphor-container",...F})}var TJ={exports:{}},hw={},ZR={exports:{}};(function(e,t){(function(n,r){r(t)})(lt.commonjsGlobal,function(n){function r(Y){return function(ne,Z,K,X,J,re,te){return Y(ne,Z,te)}}function o(Y){return function(ne,Z,K,X){if(!ne||!Z||typeof ne!="object"||typeof Z!="object")return Y(ne,Z,K,X);var J=X.get(ne),re=X.get(Z);if(J&&re)return J===Z&&re===ne;X.set(ne,Z),X.set(Z,ne);var te=Y(ne,Z,K,X);return X.delete(ne),X.delete(Z),te}}function s(Y,W){var ne={};for(var Z in Y)ne[Z]=Y[Z];for(var Z in W)ne[Z]=W[Z];return ne}function i(Y){return Y.constructor===Object||Y.constructor==null}function a(Y){return typeof Y.then=="function"}function c(Y,W){return Y===W||Y!==Y&&W!==W}var u="[object Arguments]",d="[object Boolean]",f="[object Date]",h="[object RegExp]",p="[object Map]",g="[object Number]",x="[object Object]",b="[object Set]",y="[object String]",C=Object.prototype.toString;function w(Y){var W=Y.areArraysEqual,ne=Y.areDatesEqual,Z=Y.areMapsEqual,K=Y.areObjectsEqual,X=Y.areRegExpsEqual,J=Y.areSetsEqual,re=Y.createIsNestedEqual,te=re(Q);function Q(se,oe,fe){if(se===oe)return!0;if(!se||!oe||typeof se!="object"||typeof oe!="object")return se!==se&&oe!==oe;if(i(se)&&i(oe))return K(se,oe,te,fe);var pe=Array.isArray(se),xe=Array.isArray(oe);if(pe||xe)return pe===xe&&W(se,oe,te,fe);var Ie=C.call(se);return Ie!==C.call(oe)?!1:Ie===f?ne(se,oe,te,fe):Ie===h?X(se,oe,te,fe):Ie===p?Z(se,oe,te,fe):Ie===b?J(se,oe,te,fe):Ie===x||Ie===u?a(se)||a(oe)?!1:K(se,oe,te,fe):Ie===d||Ie===g||Ie===y?c(se.valueOf(),oe.valueOf()):!1}return Q}function N(Y,W,ne,Z){var K=Y.length;if(W.length!==K)return!1;for(;K-- >0;)if(!ne(Y[K],W[K],K,K,Y,W,Z))return!1;return!0}var S=o(N);function j(Y,W){return c(Y.valueOf(),W.valueOf())}function k(Y,W,ne,Z){var K=Y.size===W.size;if(!K)return!1;if(!Y.size)return!0;var X={},J=0;return Y.forEach(function(re,te){if(K){var Q=!1,se=0;W.forEach(function(oe,fe){!Q&&!X[se]&&(Q=ne(te,fe,J,se,Y,W,Z)&&ne(re,oe,te,fe,Y,W,Z))&&(X[se]=!0),se++}),J++,K=Q}}),K}var _=o(k),T="_owner",I=Object.prototype.hasOwnProperty;function D(Y,W,ne,Z){var K=Object.keys(Y),X=K.length;if(Object.keys(W).length!==X)return!1;for(var J;X-- >0;){if(J=K[X],J===T){var re=!!Y.$$typeof,te=!!W.$$typeof;if((re||te)&&re!==te)return!1}if(!I.call(W,J)||!ne(Y[J],W[J],J,J,Y,W,Z))return!1}return!0}var E=o(D);function R(Y,W){return Y.source===W.source&&Y.flags===W.flags}function F(Y,W,ne,Z){var K=Y.size===W.size;if(!K)return!1;if(!Y.size)return!0;var X={};return Y.forEach(function(J,re){if(K){var te=!1,Q=0;W.forEach(function(se,oe){!te&&!X[Q]&&(te=ne(J,se,re,oe,Y,W,Z))&&(X[Q]=!0),Q++}),K=te}}),K}var M=o(F),O=Object.freeze({areArraysEqual:N,areDatesEqual:j,areMapsEqual:k,areObjectsEqual:D,areRegExpsEqual:R,areSetsEqual:F,createIsNestedEqual:r}),z=Object.freeze({areArraysEqual:S,areDatesEqual:j,areMapsEqual:_,areObjectsEqual:E,areRegExpsEqual:R,areSetsEqual:M,createIsNestedEqual:r}),L=w(O);function V(Y,W){return L(Y,W,void 0)}var A=w(s(O,{createIsNestedEqual:function(){return c}}));function B(Y,W){return A(Y,W,void 0)}var $=w(z);function P(Y,W){return $(Y,W,new WeakMap)}var U=w(s(z,{createIsNestedEqual:function(){return c}}));function H(Y,W){return U(Y,W,new WeakMap)}function G(Y){return w(s(O,Y(O)))}function q(Y){var W=w(s(z,Y(z)));return function(ne,Z,K){return K===void 0&&(K=new WeakMap),W(ne,Z,K)}}n.circularDeepEqual=P,n.circularShallowEqual=H,n.createCustomCircularEqual=q,n.createCustomEqual=G,n.deepEqual=V,n.sameValueZeroEqual=c,n.shallowEqual=B,Object.defineProperty(n,"__esModule",{value:!0})})})(ZR,ZR.exports);var I5=ZR.exports;const kI=lt.getAugmentedNamespace(m.clsx);var An={},wNe=function(t,n,r){return t===n?!0:t.className===n.className&&r(t.style,n.style)&&t.width===n.width&&t.autoSize===n.autoSize&&t.cols===n.cols&&t.draggableCancel===n.draggableCancel&&t.draggableHandle===n.draggableHandle&&r(t.verticalCompact,n.verticalCompact)&&r(t.compactType,n.compactType)&&r(t.layout,n.layout)&&r(t.margin,n.margin)&&r(t.containerPadding,n.containerPadding)&&t.rowHeight===n.rowHeight&&t.maxRows===n.maxRows&&t.isBounded===n.isBounded&&t.isDraggable===n.isDraggable&&t.isResizable===n.isResizable&&t.allowOverlap===n.allowOverlap&&t.preventCollision===n.preventCollision&&t.useCSSTransforms===n.useCSSTransforms&&t.transformScale===n.transformScale&&t.isDroppable===n.isDroppable&&r(t.resizeHandles,n.resizeHandles)&&r(t.resizeHandle,n.resizeHandle)&&t.onLayoutChange===n.onLayoutChange&&t.onDragStart===n.onDragStart&&t.onDrag===n.onDrag&&t.onDragStop===n.onDragStop&&t.onResizeStart===n.onResizeStart&&t.onResize===n.onResize&&t.onResizeStop===n.onResizeStop&&t.onDrop===n.onDrop&&r(t.droppingItem,n.droppingItem)&&r(t.innerRef,n.innerRef)};Object.defineProperty(An,"__esModule",{value:!0});An.bottom=_5;An.childrenEqual=jNe;An.cloneLayout=DJ;An.cloneLayoutItem=Ah;An.collides=II;An.compact=MJ;An.compactItem=RJ;An.compactType=LNe;An.correctBounds=AJ;An.fastPositionEqual=kNe;An.fastRGLPropsEqual=void 0;An.getAllCollisions=FJ;An.getFirstCollision=ch;An.getLayoutItem=T5;An.getStatics=D5;An.modifyLayout=EJ;An.moveElement=Ny;An.moveElementAwayFromCollision=QR;An.noop=void 0;An.perc=_Ne;An.resizeItemInDirection=ANe;An.setTopLeft=PNe;An.setTransform=FNe;An.sortLayoutItems=P5;An.sortLayoutItemsByColRow=zJ;An.sortLayoutItemsByRowCol=$J;An.synchronizeLayoutWithChildren=ONe;An.validateLayout=BJ;An.withLayoutItem=NNe;var xV=I5,Sy=CNe(v);function CNe(e){return e&&e.__esModule?e:{default:e}}const SNe=process.env.NODE_ENV==="production";function _5(e){let t=0,n;for(let r=0,o=e.length;r<o;r++)n=e[r].y+e[r].h,n>t&&(t=n);return t}function DJ(e){const t=Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=Ah(e[n]);return t}function EJ(e,t){const n=Array(e.length);for(let r=0,o=e.length;r<o;r++)t.i===e[r].i?n[r]=t:n[r]=e[r];return n}function NNe(e,t,n){let r=T5(e,t);return r?(r=n(Ah(r)),e=EJ(e,r),[e,r]):[e,null]}function Ah(e){return{w:e.w,h:e.h,x:e.x,y:e.y,i:e.i,minW:e.minW,maxW:e.maxW,minH:e.minH,maxH:e.maxH,moved:!!e.moved,static:!!e.static,isDraggable:e.isDraggable,isResizable:e.isResizable,resizeHandles:e.resizeHandles,isBounded:e.isBounded}}function jNe(e,t){return(0,xV.deepEqual)(Sy.default.Children.map(e,n=>n==null?void 0:n.key),Sy.default.Children.map(t,n=>n==null?void 0:n.key))&&(0,xV.deepEqual)(Sy.default.Children.map(e,n=>n==null?void 0:n.props["data-grid"]),Sy.default.Children.map(t,n=>n==null?void 0:n.props["data-grid"]))}An.fastRGLPropsEqual=wNe;function kNe(e,t){return e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function II(e,t){return!(e.i===t.i||e.x+e.w<=t.x||e.x>=t.x+t.w||e.y+e.h<=t.y||e.y>=t.y+t.h)}function MJ(e,t,n,r){const o=D5(e),s=P5(e,t),i=Array(e.length);for(let a=0,c=s.length;a<c;a++){let u=Ah(s[a]);u.static||(u=RJ(o,u,t,n,s,r),o.push(u)),i[e.indexOf(s[a])]=u,u.moved=!1}return i}const INe={x:"w",y:"h"};function XR(e,t,n,r){const o=INe[r];t[r]+=1;const s=e.map(i=>i.i).indexOf(t.i);for(let i=s+1;i<e.length;i++){const a=e[i];if(!a.static){if(a.y>t.y+t.h)break;II(t,a)&&XR(e,a,n+t[o],r)}}t[r]=n}function RJ(e,t,n,r,o,s){const i=n==="vertical",a=n==="horizontal";if(i)for(t.y=Math.min(_5(e),t.y);t.y>0&&!ch(e,t);)t.y--;else if(a)for(;t.x>0&&!ch(e,t);)t.x--;let c;for(;(c=ch(e,t))&&!(n===null&&s);)if(a?XR(o,t,c.x+c.w,"x"):XR(o,t,c.y+c.h,"y"),a&&t.x+t.w>r)for(t.x=r-t.w,t.y++;t.x>0&&!ch(e,t);)t.x--;return t.y=Math.max(t.y,0),t.x=Math.max(t.x,0),t}function AJ(e,t){const n=D5(e);for(let r=0,o=e.length;r<o;r++){const s=e[r];if(s.x+s.w>t.cols&&(s.x=t.cols-s.w),s.x<0&&(s.x=0,s.w=t.cols),!s.static)n.push(s);else for(;ch(n,s);)s.y++}return e}function T5(e,t){for(let n=0,r=e.length;n<r;n++)if(e[n].i===t)return e[n]}function ch(e,t){for(let n=0,r=e.length;n<r;n++)if(II(e[n],t))return e[n]}function FJ(e,t){return e.filter(n=>II(n,t))}function D5(e){return e.filter(t=>t.static)}function Ny(e,t,n,r,o,s,i,a,c){if(t.static&&t.isDraggable!==!0||t.y===r&&t.x===n)return e;`${t.i}${String(n)}${String(r)}${t.x}${t.y}`;const u=t.x,d=t.y;typeof n=="number"&&(t.x=n),typeof r=="number"&&(t.y=r),t.moved=!0;let f=P5(e,i);(i==="vertical"&&typeof r=="number"?d>=r:i==="horizontal"&&typeof n=="number"?u>=n:!1)&&(f=f.reverse());const p=FJ(f,t),g=p.length>0;if(g&&c)return DJ(e);if(g&&s)return`${t.i}`,t.x=u,t.y=d,t.moved=!1,e;for(let x=0,b=p.length;x<b;x++){const y=p[x];`${t.i}${t.x}${t.y}${y.i}${y.x}${y.y}`,!y.moved&&(y.static?e=QR(e,y,t,o,i):e=QR(e,t,y,o,i))}return e}function QR(e,t,n,r,o,s){const i=o==="horizontal",a=o==="vertical",c=t.static;if(r){r=!1;const f={x:i?Math.max(t.x-n.w,0):n.x,y:a?Math.max(t.y-n.h,0):n.y,w:n.w,h:n.h,i:"-1"},h=ch(e,f),p=h&&h.y+h.h>t.y,g=h&&t.x+t.w>h.x;if(h){if(p&&a)return Ny(e,n,void 0,t.y+1,r,c,o);if(p&&o==null)return t.y=n.y,n.y=n.y+n.h,e;if(g&&i)return Ny(e,t,n.x,void 0,r,c,o)}else return`${n.i}${f.x}${f.y}`,Ny(e,n,i?f.x:void 0,a?f.y:void 0,r,c,o)}const u=i?n.x+1:void 0,d=a?n.y+1:void 0;return u==null&&d==null?e:Ny(e,n,i?n.x+1:void 0,a?n.y+1:void 0,r,c,o)}function _Ne(e){return e*100+"%"}const PJ=(e,t,n,r)=>e+n>r?t:n,OJ=(e,t,n)=>e<0?t:n,LJ=e=>Math.max(0,e),E5=e=>Math.max(0,e),M5=(e,t,n)=>{let{left:r,height:o,width:s}=t;const i=e.top-(o-e.height);return{left:r,width:s,height:OJ(i,e.height,o),top:E5(i)}},R5=(e,t,n)=>{let{top:r,left:o,height:s,width:i}=t;return{top:r,height:s,width:PJ(e.left,e.width,i,n),left:LJ(o)}},A5=(e,t,n)=>{let{top:r,height:o,width:s}=t;const i=e.left-(s-e.width);return{height:o,width:i<0?e.width:PJ(e.left,e.width,s,n),top:E5(r),left:LJ(i)}},F5=(e,t,n)=>{let{top:r,left:o,height:s,width:i}=t;return{width:i,left:o,height:OJ(r,e.height,s),top:E5(r)}},TNe=function(){return M5(arguments.length<=0?void 0:arguments[0],R5(...arguments))},DNe=function(){return M5(arguments.length<=0?void 0:arguments[0],A5(...arguments))},ENe=function(){return F5(arguments.length<=0?void 0:arguments[0],R5(...arguments))},MNe=function(){return F5(arguments.length<=0?void 0:arguments[0],A5(...arguments))},RNe={n:M5,ne:TNe,e:R5,se:ENe,s:F5,sw:MNe,w:A5,nw:DNe};function ANe(e,t,n,r){const o=RNe[e];return o?o(t,{...t,...n},r):n}function FNe(e){let{top:t,left:n,width:r,height:o}=e;const s=`translate(${n}px,${t}px)`;return{transform:s,WebkitTransform:s,MozTransform:s,msTransform:s,OTransform:s,width:`${r}px`,height:`${o}px`,position:"absolute"}}function PNe(e){let{top:t,left:n,width:r,height:o}=e;return{top:`${t}px`,left:`${n}px`,width:`${r}px`,height:`${o}px`,position:"absolute"}}function P5(e,t){return t==="horizontal"?zJ(e):t==="vertical"?$J(e):e}function $J(e){return e.slice(0).sort(function(t,n){return t.y>n.y||t.y===n.y&&t.x>n.x?1:t.y===n.y&&t.x===n.x?0:-1})}function zJ(e){return e.slice(0).sort(function(t,n){return t.x>n.x||t.x===n.x&&t.y>n.y?1:-1})}function ONe(e,t,n,r,o){e=e||[];const s=[];Sy.default.Children.forEach(t,a=>{if((a==null?void 0:a.key)==null)return;const c=T5(e,String(a.key)),u=a.props["data-grid"];c&&u==null?s.push(Ah(c)):u?(SNe||BJ([u],"ReactGridLayout.children"),s.push(Ah({...u,i:a.key}))):s.push(Ah({w:1,h:1,x:0,y:_5(s),i:String(a.key)}))});const i=AJ(s,{cols:n});return o?i:MJ(i,r,n)}function BJ(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"Layout";const n=["x","y","w","h"];if(!Array.isArray(e))throw new Error(t+" must be an array!");for(let r=0,o=e.length;r<o;r++){const s=e[r];for(let i=0;i<n.length;i++){const a=n[i],c=s[a];if(typeof c!="number"||Number.isNaN(c))throw new Error(`ReactGridLayout: ${t}[${r}].${a} must be a number! Received: ${c} (${typeof c})`)}if(typeof s.i<"u"&&typeof s.i!="string")throw new Error(`ReactGridLayout: ${t}[${r}].i must be a string! Received: ${s.i} (${typeof s.i})`)}}function LNe(e){const{verticalCompact:t,compactType:n}=e||{};return t===!1?null:n}const $Ne=()=>{};An.noop=$Ne;var gc={};Object.defineProperty(gc,"__esModule",{value:!0});gc.calcGridColWidth=_I;gc.calcGridItemPosition=zNe;gc.calcGridItemWHPx=JR;gc.calcWH=VNe;gc.calcXY=BNe;gc.clamp=uh;function _I(e){const{margin:t,containerPadding:n,containerWidth:r,cols:o}=e;return(r-t[0]*(o-1)-n[0]*2)/o}function JR(e,t,n){return Number.isFinite(e)?Math.round(t*e+Math.max(0,e-1)*n):e}function zNe(e,t,n,r,o,s){const{margin:i,containerPadding:a,rowHeight:c}=e,u=_I(e),d={};return s&&s.resizing?(d.width=Math.round(s.resizing.width),d.height=Math.round(s.resizing.height)):(d.width=JR(r,u,i[0]),d.height=JR(o,c,i[1])),s&&s.dragging?(d.top=Math.round(s.dragging.top),d.left=Math.round(s.dragging.left)):s&&s.resizing&&typeof s.resizing.top=="number"&&typeof s.resizing.left=="number"?(d.top=Math.round(s.resizing.top),d.left=Math.round(s.resizing.left)):(d.top=Math.round((c+i[1])*n+a[1]),d.left=Math.round((u+i[0])*t+a[0])),d}function BNe(e,t,n,r,o){const{margin:s,containerPadding:i,cols:a,rowHeight:c,maxRows:u}=e,d=_I(e);let f=Math.round((n-i[0])/(d+s[0])),h=Math.round((t-i[1])/(c+s[1]));return f=uh(f,0,a-r),h=uh(h,0,u-o),{x:f,y:h}}function VNe(e,t,n,r,o,s){const{margin:i,maxRows:a,cols:c,rowHeight:u}=e,d=_I(e);let f=Math.round((t+i[0])/(d+i[0])),h=Math.round((n+i[1])/(u+i[1])),p=uh(f,0,c-r),g=uh(h,0,a-o);return["sw","w","nw"].indexOf(s)!==-1&&(p=uh(f,0,c)),["nw","n","ne"].indexOf(s)!==-1&&(g=uh(h,0,a)),{w:p,h:g}}function uh(e,t,n){return Math.max(Math.min(e,n),t)}var TI={},eA={exports:{}},BC={exports:{}},sr={};/** @license React v16.13.1
728
+ </html>`}function rNe({dataApp:e,onBack:t}){var d;const{authToken:n,tokenProps:r}=Mt(),[o,s]=v.useState(null),i=Yn({queryKey:["published-data-app-runtime",r.apiServiceUrl,n==null?void 0:n.accessToken,e.id],queryFn:async()=>m.getRequest(`${r.apiServiceUrl}/data-apps/${e.id}/runtime`,(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)&&!!e.id});v.useEffect(()=>{function f(h){const p=h.data;(p==null?void 0:p.source)!=="semaphor-data-app-runtime"||p.type!=="runtime-error"||s(p.message||"Published Data App failed to load.")}return window.addEventListener("message",f),()=>window.removeEventListener("message",f)},[]),v.useEffect(()=>{s(null)},[e.id]);const a=(d=i.data)==null?void 0:d.dataApp,c=a==null?void 0:a.runtime,u=v.useMemo(()=>!a||!c?"":nNe({title:a.title||e.title,apiBaseUrl:r.apiServiceUrl,dataApp:a,runtime:c}),[e.title,c,a,r.apiServiceUrl]);return l.jsxs("div",{className:"flex h-full grow flex-col bg-background text-foreground",children:[l.jsxs("header",{className:"flex h-14 shrink-0 items-center justify-between border-b border-border/60 px-4",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx(m.Button,{"aria-label":"Back to Analytics workspace",className:"h-8 w-8 px-0",onClick:t,size:"xs",variant:"ghost",children:l.jsx(ow,{className:"h-4 w-4"})}),l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data App"}),l.jsx("h1",{className:"truncate text-[14px] font-semibold",children:(a==null?void 0:a.title)||e.title})]})]}),c?l.jsxs("div",{className:"rounded-md border border-border px-2 py-1 text-[11px] text-muted-foreground",children:["v",c.version]}):null]}),i.isLoading?l.jsx("div",{className:"flex flex-1 items-center justify-center",children:l.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin"}),"Loading Data App..."]})}):i.isError?l.jsx("div",{className:"flex flex-1 items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-5 w-5 text-destructive"}),l.jsx("h2",{className:"text-[13px] font-medium",children:"Couldn't load Data App"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"The published runtime could not be fetched. Please try again."})]})}):c?l.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[o?l.jsx("div",{className:"border-b border-destructive/30 bg-destructive/10 px-4 py-2 text-[12px] text-destructive",children:o}):null,l.jsx("iframe",{className:"min-h-0 flex-1 border-0",sandbox:"allow-forms allow-modals allow-popups allow-scripts",srcDoc:u,title:(a==null?void 0:a.title)||e.title})]}):l.jsx("div",{className:"flex flex-1 items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-5 w-5 text-muted-foreground/60"}),l.jsx("h2",{className:"text-[13px] font-medium",children:"No published version yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Publish this Data App before opening it from the Analytics workspace."})]})})]})}function wJ(e){if(e&&e.type!=="organization"&&e.type==="tenant")return fw(e.role)?void 0:{showFilters:!1}}function oNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function sNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function iNe(e){return!!e}function CJ(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function aNe(e){return e?e.type==="organization"?!0:e.type==="tenant"?fw(e.role):!1:!1}function lNe(e){var t;return e?e.type==="organization"?!0:e.type==="tenant"?((t=e.role)==null?void 0:t.toUpperCase())==="POWER_USER":!1:!1}function fw(e){const t=e==null?void 0:e.toUpperCase();return t?t!=="VIEWER":!1}function cNe(e){var t;return e.isPublic?"public":(((t=e.ownership)==null?void 0:t.sharedCount)??0)>0?"shared":"private"}function $C(e,t){var n,r,o,s;switch(t){case"name":return((n=e.title)==null?void 0:n.toLowerCase())??"";case"createdBy":return((s=(o=(r=e.ownership)==null?void 0:r.createdBy)==null?void 0:o.name)==null?void 0:s.toLowerCase())??"";case"updatedAt":return new Date(e.updatedAt).getTime()||0;case"visibility":return cNe(e);default:return""}}function gV(e,t){return typeof e=="number"&&typeof t=="number"?e-t:String(e).localeCompare(String(t),void 0,{numeric:!0,sensitivity:"base"})}function uNe(e,t,n){const r=t.direction==="asc"?1:-1;return[...e].sort((o,s)=>{if(n){if(o.id===n)return-1;if(s.id===n)return 1}const i=gV($C(o,t.key),$C(s,t.key))*r;if(i!==0)return i;const a=gV($C(o,"name"),$C(s,"name"));return a!==0?a:o.id.localeCompare(s.id)})}function SJ(e){return(e==null?void 0:e.showDashboardSharing)!==!1}function dNe({isDashboardEditing:e,canEditDashboard:t,hasCurrentLens:n}){return e&&t&&!n}function fNe({config:e,canNavigateDashboardHub:t,canShareDashboard:n,canManageGroups:r}){return{showDashboardHub:(e==null?void 0:e.showDashboardHub)!==!1&&t,showDashboardSharing:SJ(e)&&n,showGroupManagement:(e==null?void 0:e.showGroupManagement)!==!1&&r}}function hNe({onDashboardSelect:e}){var ee,ce,ae,me;const{authToken:t,tokenProps:n}=Mt(),r=SJ(n.config),o=((ce=(ee=n.config)==null?void 0:ee.projectFeatures)==null?void 0:ce.features.dashboardAiAuthoring)!==!1,[s,i]=v.useState(!1),[a,c]=v.useState(!1),[u,d]=v.useState(null),[f,h]=v.useState(!1),[p,g]=v.useState(null),[x,b]=v.useState(null),[y,C]=v.useState(null),[w,N]=v.useState(null),[S,j]=v.useState(""),[k,_]=v.useState("all"),[T,I]=v.useState({key:"updatedAt",direction:"desc"}),{data:D}=qQ(),E=((ae=D==null?void 0:D.preference)==null?void 0:ae.defaultDashboardId)||null,R=Ls(ve=>ve.actions.selectDashboard),{currentUser:F,userContext:M}=hi(),O=((me=M==null?void 0:M.permissions)==null?void 0:me.canCreateDashboard)??CJ(F),{onCreateSuccess:z}=iSe({onDashboardSelect:e}),{resources:L,isLoading:V,isError:A,createResourceAsync:B,updateResource:$,deleteResource:P,duplicateResource:U,isCreating:H,isDeleting:G,refetch:q}=nSe(()=>{h(!1),g(null)},ve=>{i(!1),z(ve,q)}),{startUpdating:Y,stopUpdating:W,isUpdating:ne}=CQ(),Z=ve=>{const _e=L.find(De=>De.id===ve);if(_e){if(_e.kind==="data_app"){N(_e);return}R(_e),e==null||e(ve)}},K=ve=>{const _e=eNe(ve);return B({title:ve.title,description:ve.description,isPrivate:!1,..._e?{template:_e}:{}})},X=ve=>{g(ve),h(!0)},J=()=>{p&&P(p.id)},re=ve=>{b(ve),U(ve,{onSettled:()=>b(null)})},te=(ve,_e,De)=>{var ye;const Ue=Object.fromEntries(Object.entries(_e).filter(([,Be])=>Be!==void 0));if(Object.keys(Ue).length===0){(ye=De==null?void 0:De.onSuccess)==null||ye.call(De);return}const Ne=Object.keys(Ue),Oe=Ne.length===1?Ne[0]:void 0;Y(ve,Oe),$({resourceId:ve,data:Ue},{onSuccess:()=>{var Be;W(ve,Oe),(Be=De==null?void 0:De.onSuccess)==null||Be.call(De)},onError:()=>{var Be;W(ve,Oe),(Be=De==null?void 0:De.onError)==null||Be.call(De)}})},Q=ve=>{d(ve),c(!0)},se=ve=>new Date(ve).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),oe=L.length>5,fe=oe?S.trim().toLowerCase():"",pe=v.useMemo(()=>L.filter(ve=>ve.kind!=="data_app").length,[L]),xe=v.useMemo(()=>L.filter(ve=>ve.kind==="data_app").length,[L]),Ie=pe>0&&xe>0,be=v.useMemo(()=>{let ve=L;return Ie&&k!=="all"&&(ve=ve.filter(_e=>k==="data_app"?_e.kind==="data_app":_e.kind!=="data_app")),fe&&(ve=ve.filter(_e=>{var Ne,Oe;const De=((Ne=_e.title)==null?void 0:Ne.toLowerCase())??"",Ue=((Oe=_e.description)==null?void 0:Oe.toLowerCase())??"";return De.includes(fe)||Ue.includes(fe)})),uNe(ve,T,E)},[fe,L,E,k,Ie,T]),ge=ve=>{I(_e=>_e.key!==ve?{key:ve,direction:ve==="updatedAt"?"desc":"asc"}:{key:ve,direction:_e.direction==="asc"?"desc":"asc"})};return w?l.jsx(rNe,{dataApp:w,onBack:()=>N(null)}):t?A?l.jsx("div",{className:"flex h-full grow items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-6 w-6 text-destructive"}),l.jsx("h2",{className:"text-[13px] font-medium text-foreground",children:"Couldn't load dashboards"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Unable to fetch your dashboards. Please try again."}),l.jsx(m.Button,{size:"xs",variant:"outline",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):l.jsxs(mNe,{children:[l.jsxs(pNe,{children:[l.jsxs("div",{className:"flex items-start justify-between gap-6",children:[l.jsxs("div",{className:"min-w-0",children:[l.jsx("h1",{className:"text-[15px] font-semibold tracking-tight text-foreground",children:"Analytics workspace"}),l.jsxs("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:["Pick an existing dashboard or app, or create a dashboard.",!V&&L.length>0?l.jsxs("span",{className:"ml-1.5",children:["· ",L.length," item",L.length!==1?"s":""]}):null]})]}),O&&l.jsx("div",{className:"flex items-center gap-1.5",children:l.jsxs(m.Button,{size:"xs",onClick:()=>i(!0),children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"New dashboard"]})})]}),V?l.jsx(gNe,{}):L.length===0?l.jsx("div",{className:"flex items-center justify-center py-20",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(zd,{className:"h-6 w-6 text-muted-foreground/60"}),l.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:"No dashboards yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:O?"Create your first dashboard to get started.":"No dashboards have been shared with you yet."}),O&&l.jsx("div",{className:"mt-2 flex items-center gap-1.5",children:l.jsxs(m.Button,{size:"xs",onClick:()=>i(!0),children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Create dashboard"]})})]})}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"mt-7 flex items-center gap-6 border-b border-border/60",children:Ie?l.jsxs(l.Fragment,{children:[l.jsx(CD,{label:"All",count:L.length,active:k==="all",onClick:()=>_("all")}),l.jsx(CD,{label:"Dashboards",count:pe,active:k==="dashboard",onClick:()=>_("dashboard")}),l.jsx(CD,{label:"Data apps",count:xe,active:k==="data_app",onClick:()=>_("data_app")})]}):l.jsxs("span",{className:"-mb-px border-b-2 border-foreground px-0.5 pb-2.5 text-[13px] font-medium text-foreground",children:["Your dashboards",l.jsx("span",{className:"ml-1.5 text-[11px] font-normal tabular-nums text-muted-foreground/70",children:L.length})]})}),be.length===0&&!oe?l.jsx("div",{className:"flex items-center justify-center py-20 text-center",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-1",children:[l.jsx("h3",{className:"text-[13px] font-medium text-foreground",children:"No dashboards found"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No items match the current filter."})]})}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:m.cn("mt-1 grid items-center gap-4 border-b border-border/60 px-2 py-2.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",gQ),children:[l.jsx("div",{children:l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx("div",{className:"min-w-0 flex-1",children:oe?l.jsx(xwe,{label:"Name",value:S,onChange:j,placeholder:"Filter dashboards…"}):l.jsx("span",{children:"Name"})}),l.jsx(zC,{sortKey:"name",sortState:T,onSort:ge,label:"Sort by name"})]})}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Created by"}),l.jsx(zC,{sortKey:"createdBy",sortState:T,onSort:ge,label:"Sort by created by"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Updated"}),l.jsx(zC,{sortKey:"updatedAt",sortState:T,onSort:ge,label:"Sort by updated"})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{children:"Visibility"}),l.jsx(zC,{sortKey:"visibility",sortState:T,onSort:ge,label:"Sort by visibility"})]}),l.jsx("div",{})]}),be.length===0?l.jsx("div",{className:"flex items-center justify-center py-12 text-center",children:l.jsxs("p",{className:"text-[12px] text-muted-foreground",children:["No dashboards match “",S.trim(),"”."]})}):l.jsx("div",{children:be.map(ve=>l.jsx(xNe,{dashboard:ve,isDefault:ve.kind!=="data_app"&&ve.id===E,onView:Z,isDeleting:G&&(p==null?void 0:p.id)===ve.id,isDuplicating:x===ve.id,onEditDetails:C,onDeleteClick:X,onDuplicateDashboard:re,onShareDashboard:r?Q:void 0,formatDate:se},ve.id))})]})]})]}),l.jsx(ESe,{open:s,onOpenChange:i,onCreateBlank:K,onAiCreateSuccess:ve=>{i(!1),z(ve.dashboard,q)},isCreatingBlank:H,aiAuthoringEnabled:o}),y&&l.jsx(vJ,{open:!!y,resourceLabel:"Dashboard",initialTitle:y.title||"",initialDescription:y.description||"",onClose:()=>C(null),onSave:ve=>{te(y.id,ve,{onSuccess:()=>{C(null)}})},isSaving:ne(y.id)}),l.jsx(ff,{open:f,onOpenChange:h,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete Dashboard?"}),l.jsxs(Ru,{children:['Are you sure you want to delete "',p==null?void 0:p.title,'"? This action cannot be undone.']})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{disabled:G,children:"Cancel"}),l.jsx(Au,{onClick:J,disabled:G,children:G?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete"})]})]})}),r&&u&&a&&l.jsx(yJ,{resource:u,resourceType:uo.DASHBOARD,onClose:()=>{c(!1),d(null)}})]}):l.jsx("div",{className:"flex h-full grow items-center justify-center px-6",children:l.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2 text-center",children:[l.jsx(ea,{className:"h-6 w-6 text-muted-foreground/60"}),l.jsx("h2",{className:"text-[13px] font-medium text-foreground",children:"Authentication required"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Please provide authentication to view dashboards."})]})})}function CD({label:e,count:t,active:n,onClick:r}){return l.jsxs("button",{type:"button",onClick:r,className:m.cn("-mb-px border-b-2 px-0.5 pb-2.5 text-[13px] transition-colors",n?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:[e,l.jsx("span",{className:m.cn("ml-1.5 text-[11px] tabular-nums",n?"font-normal text-muted-foreground/70":"text-muted-foreground/70"),children:t})]})}function zC({sortKey:e,sortState:t,onSort:n,label:r}){const o=t.key===e,s=o&&t.direction==="asc",i=o&&t.direction==="desc";return l.jsx("button",{type:"button",onClick:()=>n(e),"aria-label":r,className:m.cn("inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-[3px] transition-colors",o?"text-foreground":"text-muted-foreground/60 hover:text-foreground focus-visible:text-foreground","focus:outline-none"),children:s?l.jsx(m.ChevronUp,{className:"h-3 w-3","aria-hidden":!0}):i?l.jsx(Re.ChevronDown,{className:"h-3 w-3","aria-hidden":!0}):l.jsx(ZZ,{className:"h-3 w-3","aria-hidden":!0})})}function mNe({children:e}){const t=Pu();return l.jsx("div",{"data-content-type":"dashboard-hub",className:"flex h-full grow flex-col bg-background text-foreground",style:t.dashboardContainerStyle,children:e})}function pNe({children:e}){const t=Pu();return l.jsx("div",{className:"flex flex-1 flex-col overflow-y-auto bg-background px-6 py-8 lg:px-10",style:t.dashboardCanvasStyle,children:e})}function gNe(){return l.jsx("div",{className:"flex min-h-[280px] flex-1 items-center justify-center",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Loading dashboards..."})]})})}function xNe(e){return l.jsx(zCe,{...e})}const Rh=m.create()(e=>({panels:{dashboard:{isOpen:!1,container:null},editor:{isOpen:!1,container:null}},fullscreen:null,setPanelOpen:(t,n)=>e(r=>r.panels[t].isOpen===n?r:{panels:{...r.panels,[t]:{...r.panels[t],isOpen:n}},fullscreen:!n&&r.fullscreen===t?null:r.fullscreen}),setFullscreen:t=>e(n=>n.fullscreen===t?n:{fullscreen:t}),setContainer:(t,n)=>e(r=>r.panels[t].container===n?r:{panels:{...r.panels,[t]:{...r.panels[t],container:n}}})})),NJ=e=>Rh(t=>t.panels[e]),jJ=()=>Rh(e=>e.fullscreen),kJ=e=>Rh(t=>t.panels[e].container??null);m.enableMapSet();const jI=m.create()(m.immer((e,t)=>({activeExports:new Map,actions:{addExport:n=>{e(r=>{r.activeExports.set(n.id,{...n,lastUpdatedAt:n.lastUpdatedAt??new Date})})},updateExport:(n,r)=>{e(o=>{const s=o.activeExports.get(n);if(s){const i={...s,...r};r.lastUpdatedAt||(i.lastUpdatedAt=new Date),o.activeExports.set(n,i)}})},removeExport:n=>{e(r=>{r.activeExports.delete(n)})},getInProgressExports:()=>Array.from(t().activeExports.values()).filter(r=>["pending","processing","chunking","compacting"].includes(r.status)),getAllExports:()=>Array.from(t().activeExports.values()).sort((n,r)=>r.startedAt.getTime()-n.startedAt.getTime()),clearCompleted:()=>{e(n=>{for(const[r,o]of n.activeExports)(o.status==="completed"||o.status==="failed")&&n.activeExports.delete(r)})},hasInProgressExports:()=>Array.from(t().activeExports.values()).some(r=>["pending","processing","chunking","compacting"].includes(r.status))}}))),IJ=()=>jI(e=>e.actions),bNe=()=>jI(e=>e.activeExports),yNe=()=>jI(e=>Array.from(e.activeExports.values()).filter(n=>["pending","processing","chunking","compacting"].includes(n.status)).length);function _J(){const{tokenProps:e,id:t}=Mt(),n=Ls(o=>o.selectedDashboard);return Ls(o=>o.showHub)?!1:!!(n!=null&&n.id||t||e!=null&&e.dashboard_id)}function vNe({title:e,description:t,onRetry:n,isRetrying:r=!1,className:o}){return l.jsx("div",{className:m.cn("flex h-full min-h-[320px] w-full grow items-center justify-center bg-muted/20 px-6 py-10",o),role:"alert",children:l.jsx("div",{className:"w-full max-w-sm rounded-md border border-border/70 bg-background p-5 shadow-sm",children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md bg-destructive/10 text-destructive",children:l.jsx(ea,{className:"h-4 w-4","aria-hidden":"true"})}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("h2",{className:"text-pretty text-[13px] font-medium text-foreground",children:e}),l.jsx("p",{className:"mt-1 break-words text-[12px] leading-5 text-muted-foreground",children:t}),n?l.jsxs(m.Button,{size:"xs",variant:"outline",className:"mt-3",onClick:n,disabled:r,children:[r?l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):null,r?"Trying Again…":"Try Again"]}):null]})]})})})}function k5({className:e,customStyle:t,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,LoadingComponent:s,ErrorComponent:i,onChartElementClicked:a,id:c,authToken:u,currentTheme:d,appearance:f,version:h,customCards:p,showAssistant:g,defaultFilterValues:x,defaultControlValues:b,controlContractOverrides:y,documentInputValues:C,dashboardInputExecutionSnapshot:w,interactionExecutionSnapshot:N,presentationExecutionSnapshot:S,renderMode:j,onFilterValuesChange:k,selectedSheetId:_,eventHandlers:T,type:I="dashboard",cardId:D,dashboardId:E,style:R,...F}){const{placeholders:M,tokenProps:O,id:z}=Mt();Ls(G=>G.selectedDashboard);const L=m.useDashboardStore(G=>G.themeStyle),V=Pu(),A=m.useDashboardStore(G=>G.isSessionExpired),{isLoading:B,isFetching:$,isError:P,refetch:U}=F0e({customStyle:t,currentTheme:d,onSave:n,onEvent:r,onDashboardLifecycleEvent:o,defaultFilterValues:x,defaultControlValues:b,controlContractOverrides:y,dashboardInputExecutionSnapshot:w,interactionExecutionSnapshot:N,presentationExecutionSnapshot:S,onFilterValuesChange:k,selectedSheetId:_,type:I,cardId:D}),H=_J();return u&&!H&&!B?l.jsx(hNe,{}):P?(r==null||r({type:"error",message:"Error fetching dashboard"}),i?(console.log("Error fetching dashboard"),l.jsx(i,{})):l.jsx(vNe,{title:"Dashboard Couldn’t Load",description:"Check your connection and dashboard access, then try again.",onRetry:()=>void U(),isRetrying:$})):A?(r==null||r({type:"error",message:"Session Expired"}),M!=null&&M.SessionExpired?l.jsx("div",{className:"flex h-full w-full items-center justify-center",children:l.jsx("div",{children:M.SessionExpired})}):l.jsx("div",{className:"flex h-full w-full items-center justify-center",children:l.jsxs("div",{className:"space-y-4 rounded-md border border-muted p-10",children:[l.jsx(Ix,{children:"Session Expired"}),l.jsx("p",{className:"text-muted-foreground",children:"Please refresh your page to continue"})]})})):B||!u?(r==null||r({type:"info",message:"Loading dashboard"}),s?l.jsx(s,{message:"loading"}):l.jsx("div",{className:"flex h-full min-h-[320px] w-full grow items-center justify-center",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Loading dashboard…"})]})})):l.jsx("div",{className:m.cn("isolate flex min-w-0 grow flex-col",{"h-full":I==="visual"},L==null?void 0:L.dashboardPanel,e),style:{...V.dashboardContainerStyle,...R},"data-role":"semaphor-container",...F})}var TJ={exports:{}},hw={},ZR={exports:{}};(function(e,t){(function(n,r){r(t)})(lt.commonjsGlobal,function(n){function r(Y){return function(ne,Z,K,X,J,re,te){return Y(ne,Z,te)}}function o(Y){return function(ne,Z,K,X){if(!ne||!Z||typeof ne!="object"||typeof Z!="object")return Y(ne,Z,K,X);var J=X.get(ne),re=X.get(Z);if(J&&re)return J===Z&&re===ne;X.set(ne,Z),X.set(Z,ne);var te=Y(ne,Z,K,X);return X.delete(ne),X.delete(Z),te}}function s(Y,W){var ne={};for(var Z in Y)ne[Z]=Y[Z];for(var Z in W)ne[Z]=W[Z];return ne}function i(Y){return Y.constructor===Object||Y.constructor==null}function a(Y){return typeof Y.then=="function"}function c(Y,W){return Y===W||Y!==Y&&W!==W}var u="[object Arguments]",d="[object Boolean]",f="[object Date]",h="[object RegExp]",p="[object Map]",g="[object Number]",x="[object Object]",b="[object Set]",y="[object String]",C=Object.prototype.toString;function w(Y){var W=Y.areArraysEqual,ne=Y.areDatesEqual,Z=Y.areMapsEqual,K=Y.areObjectsEqual,X=Y.areRegExpsEqual,J=Y.areSetsEqual,re=Y.createIsNestedEqual,te=re(Q);function Q(se,oe,fe){if(se===oe)return!0;if(!se||!oe||typeof se!="object"||typeof oe!="object")return se!==se&&oe!==oe;if(i(se)&&i(oe))return K(se,oe,te,fe);var pe=Array.isArray(se),xe=Array.isArray(oe);if(pe||xe)return pe===xe&&W(se,oe,te,fe);var Ie=C.call(se);return Ie!==C.call(oe)?!1:Ie===f?ne(se,oe,te,fe):Ie===h?X(se,oe,te,fe):Ie===p?Z(se,oe,te,fe):Ie===b?J(se,oe,te,fe):Ie===x||Ie===u?a(se)||a(oe)?!1:K(se,oe,te,fe):Ie===d||Ie===g||Ie===y?c(se.valueOf(),oe.valueOf()):!1}return Q}function N(Y,W,ne,Z){var K=Y.length;if(W.length!==K)return!1;for(;K-- >0;)if(!ne(Y[K],W[K],K,K,Y,W,Z))return!1;return!0}var S=o(N);function j(Y,W){return c(Y.valueOf(),W.valueOf())}function k(Y,W,ne,Z){var K=Y.size===W.size;if(!K)return!1;if(!Y.size)return!0;var X={},J=0;return Y.forEach(function(re,te){if(K){var Q=!1,se=0;W.forEach(function(oe,fe){!Q&&!X[se]&&(Q=ne(te,fe,J,se,Y,W,Z)&&ne(re,oe,te,fe,Y,W,Z))&&(X[se]=!0),se++}),J++,K=Q}}),K}var _=o(k),T="_owner",I=Object.prototype.hasOwnProperty;function D(Y,W,ne,Z){var K=Object.keys(Y),X=K.length;if(Object.keys(W).length!==X)return!1;for(var J;X-- >0;){if(J=K[X],J===T){var re=!!Y.$$typeof,te=!!W.$$typeof;if((re||te)&&re!==te)return!1}if(!I.call(W,J)||!ne(Y[J],W[J],J,J,Y,W,Z))return!1}return!0}var E=o(D);function R(Y,W){return Y.source===W.source&&Y.flags===W.flags}function F(Y,W,ne,Z){var K=Y.size===W.size;if(!K)return!1;if(!Y.size)return!0;var X={};return Y.forEach(function(J,re){if(K){var te=!1,Q=0;W.forEach(function(se,oe){!te&&!X[Q]&&(te=ne(J,se,re,oe,Y,W,Z))&&(X[Q]=!0),Q++}),K=te}}),K}var M=o(F),O=Object.freeze({areArraysEqual:N,areDatesEqual:j,areMapsEqual:k,areObjectsEqual:D,areRegExpsEqual:R,areSetsEqual:F,createIsNestedEqual:r}),z=Object.freeze({areArraysEqual:S,areDatesEqual:j,areMapsEqual:_,areObjectsEqual:E,areRegExpsEqual:R,areSetsEqual:M,createIsNestedEqual:r}),L=w(O);function V(Y,W){return L(Y,W,void 0)}var A=w(s(O,{createIsNestedEqual:function(){return c}}));function B(Y,W){return A(Y,W,void 0)}var $=w(z);function P(Y,W){return $(Y,W,new WeakMap)}var U=w(s(z,{createIsNestedEqual:function(){return c}}));function H(Y,W){return U(Y,W,new WeakMap)}function G(Y){return w(s(O,Y(O)))}function q(Y){var W=w(s(z,Y(z)));return function(ne,Z,K){return K===void 0&&(K=new WeakMap),W(ne,Z,K)}}n.circularDeepEqual=P,n.circularShallowEqual=H,n.createCustomCircularEqual=q,n.createCustomEqual=G,n.deepEqual=V,n.sameValueZeroEqual=c,n.shallowEqual=B,Object.defineProperty(n,"__esModule",{value:!0})})})(ZR,ZR.exports);var I5=ZR.exports;const kI=lt.getAugmentedNamespace(m.clsx);var An={},wNe=function(t,n,r){return t===n?!0:t.className===n.className&&r(t.style,n.style)&&t.width===n.width&&t.autoSize===n.autoSize&&t.cols===n.cols&&t.draggableCancel===n.draggableCancel&&t.draggableHandle===n.draggableHandle&&r(t.verticalCompact,n.verticalCompact)&&r(t.compactType,n.compactType)&&r(t.layout,n.layout)&&r(t.margin,n.margin)&&r(t.containerPadding,n.containerPadding)&&t.rowHeight===n.rowHeight&&t.maxRows===n.maxRows&&t.isBounded===n.isBounded&&t.isDraggable===n.isDraggable&&t.isResizable===n.isResizable&&t.allowOverlap===n.allowOverlap&&t.preventCollision===n.preventCollision&&t.useCSSTransforms===n.useCSSTransforms&&t.transformScale===n.transformScale&&t.isDroppable===n.isDroppable&&r(t.resizeHandles,n.resizeHandles)&&r(t.resizeHandle,n.resizeHandle)&&t.onLayoutChange===n.onLayoutChange&&t.onDragStart===n.onDragStart&&t.onDrag===n.onDrag&&t.onDragStop===n.onDragStop&&t.onResizeStart===n.onResizeStart&&t.onResize===n.onResize&&t.onResizeStop===n.onResizeStop&&t.onDrop===n.onDrop&&r(t.droppingItem,n.droppingItem)&&r(t.innerRef,n.innerRef)};Object.defineProperty(An,"__esModule",{value:!0});An.bottom=_5;An.childrenEqual=jNe;An.cloneLayout=DJ;An.cloneLayoutItem=Ah;An.collides=II;An.compact=MJ;An.compactItem=RJ;An.compactType=LNe;An.correctBounds=AJ;An.fastPositionEqual=kNe;An.fastRGLPropsEqual=void 0;An.getAllCollisions=FJ;An.getFirstCollision=ch;An.getLayoutItem=T5;An.getStatics=D5;An.modifyLayout=EJ;An.moveElement=Ny;An.moveElementAwayFromCollision=QR;An.noop=void 0;An.perc=_Ne;An.resizeItemInDirection=ANe;An.setTopLeft=PNe;An.setTransform=FNe;An.sortLayoutItems=P5;An.sortLayoutItemsByColRow=zJ;An.sortLayoutItemsByRowCol=$J;An.synchronizeLayoutWithChildren=ONe;An.validateLayout=BJ;An.withLayoutItem=NNe;var xV=I5,Sy=CNe(v);function CNe(e){return e&&e.__esModule?e:{default:e}}const SNe=process.env.NODE_ENV==="production";function _5(e){let t=0,n;for(let r=0,o=e.length;r<o;r++)n=e[r].y+e[r].h,n>t&&(t=n);return t}function DJ(e){const t=Array(e.length);for(let n=0,r=e.length;n<r;n++)t[n]=Ah(e[n]);return t}function EJ(e,t){const n=Array(e.length);for(let r=0,o=e.length;r<o;r++)t.i===e[r].i?n[r]=t:n[r]=e[r];return n}function NNe(e,t,n){let r=T5(e,t);return r?(r=n(Ah(r)),e=EJ(e,r),[e,r]):[e,null]}function Ah(e){return{w:e.w,h:e.h,x:e.x,y:e.y,i:e.i,minW:e.minW,maxW:e.maxW,minH:e.minH,maxH:e.maxH,moved:!!e.moved,static:!!e.static,isDraggable:e.isDraggable,isResizable:e.isResizable,resizeHandles:e.resizeHandles,isBounded:e.isBounded}}function jNe(e,t){return(0,xV.deepEqual)(Sy.default.Children.map(e,n=>n==null?void 0:n.key),Sy.default.Children.map(t,n=>n==null?void 0:n.key))&&(0,xV.deepEqual)(Sy.default.Children.map(e,n=>n==null?void 0:n.props["data-grid"]),Sy.default.Children.map(t,n=>n==null?void 0:n.props["data-grid"]))}An.fastRGLPropsEqual=wNe;function kNe(e,t){return e.left===t.left&&e.top===t.top&&e.width===t.width&&e.height===t.height}function II(e,t){return!(e.i===t.i||e.x+e.w<=t.x||e.x>=t.x+t.w||e.y+e.h<=t.y||e.y>=t.y+t.h)}function MJ(e,t,n,r){const o=D5(e),s=P5(e,t),i=Array(e.length);for(let a=0,c=s.length;a<c;a++){let u=Ah(s[a]);u.static||(u=RJ(o,u,t,n,s,r),o.push(u)),i[e.indexOf(s[a])]=u,u.moved=!1}return i}const INe={x:"w",y:"h"};function XR(e,t,n,r){const o=INe[r];t[r]+=1;const s=e.map(i=>i.i).indexOf(t.i);for(let i=s+1;i<e.length;i++){const a=e[i];if(!a.static){if(a.y>t.y+t.h)break;II(t,a)&&XR(e,a,n+t[o],r)}}t[r]=n}function RJ(e,t,n,r,o,s){const i=n==="vertical",a=n==="horizontal";if(i)for(t.y=Math.min(_5(e),t.y);t.y>0&&!ch(e,t);)t.y--;else if(a)for(;t.x>0&&!ch(e,t);)t.x--;let c;for(;(c=ch(e,t))&&!(n===null&&s);)if(a?XR(o,t,c.x+c.w,"x"):XR(o,t,c.y+c.h,"y"),a&&t.x+t.w>r)for(t.x=r-t.w,t.y++;t.x>0&&!ch(e,t);)t.x--;return t.y=Math.max(t.y,0),t.x=Math.max(t.x,0),t}function AJ(e,t){const n=D5(e);for(let r=0,o=e.length;r<o;r++){const s=e[r];if(s.x+s.w>t.cols&&(s.x=t.cols-s.w),s.x<0&&(s.x=0,s.w=t.cols),!s.static)n.push(s);else for(;ch(n,s);)s.y++}return e}function T5(e,t){for(let n=0,r=e.length;n<r;n++)if(e[n].i===t)return e[n]}function ch(e,t){for(let n=0,r=e.length;n<r;n++)if(II(e[n],t))return e[n]}function FJ(e,t){return e.filter(n=>II(n,t))}function D5(e){return e.filter(t=>t.static)}function Ny(e,t,n,r,o,s,i,a,c){if(t.static&&t.isDraggable!==!0||t.y===r&&t.x===n)return e;`${t.i}${String(n)}${String(r)}${t.x}${t.y}`;const u=t.x,d=t.y;typeof n=="number"&&(t.x=n),typeof r=="number"&&(t.y=r),t.moved=!0;let f=P5(e,i);(i==="vertical"&&typeof r=="number"?d>=r:i==="horizontal"&&typeof n=="number"?u>=n:!1)&&(f=f.reverse());const p=FJ(f,t),g=p.length>0;if(g&&c)return DJ(e);if(g&&s)return`${t.i}`,t.x=u,t.y=d,t.moved=!1,e;for(let x=0,b=p.length;x<b;x++){const y=p[x];`${t.i}${t.x}${t.y}${y.i}${y.x}${y.y}`,!y.moved&&(y.static?e=QR(e,y,t,o,i):e=QR(e,t,y,o,i))}return e}function QR(e,t,n,r,o,s){const i=o==="horizontal",a=o==="vertical",c=t.static;if(r){r=!1;const f={x:i?Math.max(t.x-n.w,0):n.x,y:a?Math.max(t.y-n.h,0):n.y,w:n.w,h:n.h,i:"-1"},h=ch(e,f),p=h&&h.y+h.h>t.y,g=h&&t.x+t.w>h.x;if(h){if(p&&a)return Ny(e,n,void 0,t.y+1,r,c,o);if(p&&o==null)return t.y=n.y,n.y=n.y+n.h,e;if(g&&i)return Ny(e,t,n.x,void 0,r,c,o)}else return`${n.i}${f.x}${f.y}`,Ny(e,n,i?f.x:void 0,a?f.y:void 0,r,c,o)}const u=i?n.x+1:void 0,d=a?n.y+1:void 0;return u==null&&d==null?e:Ny(e,n,i?n.x+1:void 0,a?n.y+1:void 0,r,c,o)}function _Ne(e){return e*100+"%"}const PJ=(e,t,n,r)=>e+n>r?t:n,OJ=(e,t,n)=>e<0?t:n,LJ=e=>Math.max(0,e),E5=e=>Math.max(0,e),M5=(e,t,n)=>{let{left:r,height:o,width:s}=t;const i=e.top-(o-e.height);return{left:r,width:s,height:OJ(i,e.height,o),top:E5(i)}},R5=(e,t,n)=>{let{top:r,left:o,height:s,width:i}=t;return{top:r,height:s,width:PJ(e.left,e.width,i,n),left:LJ(o)}},A5=(e,t,n)=>{let{top:r,height:o,width:s}=t;const i=e.left-(s-e.width);return{height:o,width:i<0?e.width:PJ(e.left,e.width,s,n),top:E5(r),left:LJ(i)}},F5=(e,t,n)=>{let{top:r,left:o,height:s,width:i}=t;return{width:i,left:o,height:OJ(r,e.height,s),top:E5(r)}},TNe=function(){return M5(arguments.length<=0?void 0:arguments[0],R5(...arguments))},DNe=function(){return M5(arguments.length<=0?void 0:arguments[0],A5(...arguments))},ENe=function(){return F5(arguments.length<=0?void 0:arguments[0],R5(...arguments))},MNe=function(){return F5(arguments.length<=0?void 0:arguments[0],A5(...arguments))},RNe={n:M5,ne:TNe,e:R5,se:ENe,s:F5,sw:MNe,w:A5,nw:DNe};function ANe(e,t,n,r){const o=RNe[e];return o?o(t,{...t,...n},r):n}function FNe(e){let{top:t,left:n,width:r,height:o}=e;const s=`translate(${n}px,${t}px)`;return{transform:s,WebkitTransform:s,MozTransform:s,msTransform:s,OTransform:s,width:`${r}px`,height:`${o}px`,position:"absolute"}}function PNe(e){let{top:t,left:n,width:r,height:o}=e;return{top:`${t}px`,left:`${n}px`,width:`${r}px`,height:`${o}px`,position:"absolute"}}function P5(e,t){return t==="horizontal"?zJ(e):t==="vertical"?$J(e):e}function $J(e){return e.slice(0).sort(function(t,n){return t.y>n.y||t.y===n.y&&t.x>n.x?1:t.y===n.y&&t.x===n.x?0:-1})}function zJ(e){return e.slice(0).sort(function(t,n){return t.x>n.x||t.x===n.x&&t.y>n.y?1:-1})}function ONe(e,t,n,r,o){e=e||[];const s=[];Sy.default.Children.forEach(t,a=>{if((a==null?void 0:a.key)==null)return;const c=T5(e,String(a.key)),u=a.props["data-grid"];c&&u==null?s.push(Ah(c)):u?(SNe||BJ([u],"ReactGridLayout.children"),s.push(Ah({...u,i:a.key}))):s.push(Ah({w:1,h:1,x:0,y:_5(s),i:String(a.key)}))});const i=AJ(s,{cols:n});return o?i:MJ(i,r,n)}function BJ(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"Layout";const n=["x","y","w","h"];if(!Array.isArray(e))throw new Error(t+" must be an array!");for(let r=0,o=e.length;r<o;r++){const s=e[r];for(let i=0;i<n.length;i++){const a=n[i],c=s[a];if(typeof c!="number"||Number.isNaN(c))throw new Error(`ReactGridLayout: ${t}[${r}].${a} must be a number! Received: ${c} (${typeof c})`)}if(typeof s.i<"u"&&typeof s.i!="string")throw new Error(`ReactGridLayout: ${t}[${r}].i must be a string! Received: ${s.i} (${typeof s.i})`)}}function LNe(e){const{verticalCompact:t,compactType:n}=e||{};return t===!1?null:n}const $Ne=()=>{};An.noop=$Ne;var gc={};Object.defineProperty(gc,"__esModule",{value:!0});gc.calcGridColWidth=_I;gc.calcGridItemPosition=zNe;gc.calcGridItemWHPx=JR;gc.calcWH=VNe;gc.calcXY=BNe;gc.clamp=uh;function _I(e){const{margin:t,containerPadding:n,containerWidth:r,cols:o}=e;return(r-t[0]*(o-1)-n[0]*2)/o}function JR(e,t,n){return Number.isFinite(e)?Math.round(t*e+Math.max(0,e-1)*n):e}function zNe(e,t,n,r,o,s){const{margin:i,containerPadding:a,rowHeight:c}=e,u=_I(e),d={};return s&&s.resizing?(d.width=Math.round(s.resizing.width),d.height=Math.round(s.resizing.height)):(d.width=JR(r,u,i[0]),d.height=JR(o,c,i[1])),s&&s.dragging?(d.top=Math.round(s.dragging.top),d.left=Math.round(s.dragging.left)):s&&s.resizing&&typeof s.resizing.top=="number"&&typeof s.resizing.left=="number"?(d.top=Math.round(s.resizing.top),d.left=Math.round(s.resizing.left)):(d.top=Math.round((c+i[1])*n+a[1]),d.left=Math.round((u+i[0])*t+a[0])),d}function BNe(e,t,n,r,o){const{margin:s,containerPadding:i,cols:a,rowHeight:c,maxRows:u}=e,d=_I(e);let f=Math.round((n-i[0])/(d+s[0])),h=Math.round((t-i[1])/(c+s[1]));return f=uh(f,0,a-r),h=uh(h,0,u-o),{x:f,y:h}}function VNe(e,t,n,r,o,s){const{margin:i,maxRows:a,cols:c,rowHeight:u}=e,d=_I(e);let f=Math.round((t+i[0])/(d+i[0])),h=Math.round((n+i[1])/(u+i[1])),p=uh(f,0,c-r),g=uh(h,0,a-o);return["sw","w","nw"].indexOf(s)!==-1&&(p=uh(f,0,c)),["nw","n","ne"].indexOf(s)!==-1&&(g=uh(h,0,a)),{w:p,h:g}}function uh(e,t,n){return Math.max(Math.min(e,n),t)}var TI={},eA={exports:{}},BC={exports:{}},sr={};/** @license React v16.13.1
729
729
  * react-is.production.min.js
730
730
  *
731
731
  * Copyright (c) Facebook, Inc. and its affiliates.
@@ -1318,7 +1318,7 @@ Include in the briefing:
1318
1318
  `);return l.jsx(_me,{role:"option",tabIndex:L?-1:0,"data-option-index":O,"data-field-id":M.id,"aria-selected":z,"aria-disabled":L||void 0,title:A,selected:z,disableHover:L,onClick:()=>{L||n(M)},onKeyDown:B=>E(B,M,O,L),className:m.cn("rounded-[4px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/20",k&&"px-2",L?"cursor-not-allowed opacity-50":"cursor-pointer"),icon:l.jsxs(l.Fragment,{children:[r==="multiple"&&l.jsx(jn,{checked:z,className:"pointer-events-none h-3.5 w-3.5",tabIndex:-1,"aria-hidden":"true"}),l.jsx(mC,{dataType:M.dataType,calculated:f==null?void 0:f(M)})]}),label:V,trailing:l.jsxs(l.Fragment,{children:[h==null?void 0:h(M,z),r==="single"&&z&&l.jsx(m.Check,{className:"h-3.5 w-3.5 shrink-0 text-foreground","aria-hidden":"true"})]})},M.id)};return l.jsxs(l.Fragment,{children:[l.jsx(zue,{value:N,onChange:S,onKeyDown:D,placeholder:i,autoFocus:b,className:"mb-1.5"}),p,l.jsx("div",{ref:j,role:"listbox","aria-label":a,"aria-multiselectable":r==="multiple",className:m.cn("overflow-y-auto",x),children:T.length===0?l.jsx("div",{className:"px-2 py-6 text-center text-[12px] text-muted-foreground",children:y??(N?"No fields match your search.":"No fields")}):_.map(M=>l.jsxs("div",{role:"group","aria-label":M.label||void 0,children:[M.label&&l.jsxs("div",{title:M.label,className:m.cn("flex items-center gap-1.5 py-1.5",k?"px-2":"px-4"),children:[l.jsx("span",{className:"max-w-[180px] truncate text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:M.label}),l.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:M.fields.length})]}),M.fields.map(F)]},M.id))})]})}const hht=new Set;function mht({hierarchy:e,sampleFieldReferences:t,onUpdateHierarchy:n,onDeleteHierarchy:r,onUpdateStep:o,onRemoveStep:s,onAddStep:i}){const[a,c]=v.useState(!1),{attributes:u,listeners:d,setNodeRef:f,transform:h,transition:p}=dp({id:e.id,disabled:!1}),g={transform:Pi.Transform.toString(h),transition:p},x=e.steps.filter(b=>b.field).map(b=>b.field.id);return l.jsxs("div",{ref:f,style:g,className:"hierarchy-container relative rounded-card border border-border bg-background p-3 transition-colors hover:border-border/80",children:[l.jsxs("div",{className:"mb-3 flex cursor-move items-center justify-between",...u,...d,children:[l.jsx("div",{className:"flex items-center gap-2",children:l.jsx("div",{onPointerDown:b=>b.stopPropagation(),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),children:l.jsx(Di,{value:e.label||"",onSave:b=>{n(e.id,{label:b})},placeholder:"Hierarchy name",displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium"})})}),l.jsx("div",{className:"flex items-center gap-1",children:l.jsx(m.Button,{size:"xs",variant:"ghost","aria-label":"Delete hierarchy",className:"h-7 w-7 p-0 text-muted-foreground hover:text-destructive",onClick:b=>{b.stopPropagation(),r(e.id)},onPointerDown:b=>b.stopPropagation(),children:l.jsx(Ra,{className:"h-3.5 w-3.5"})})})]}),l.jsx(dht,{hierarchy:e,onUpdateStep:o,onRemoveStep:s,onUpdateHierarchy:n}),l.jsx("div",{className:"mt-3 border-t border-border/60 pt-3","data-hierarchy-editing":!0,children:a?l.jsx("div",{className:"flex flex-col rounded-card border border-border p-1.5",children:l.jsx(PT,{fields:t.filter(b=>!x.includes(b.id)),selectedIds:hht,onSelect:b=>{i(e.id,b.id),c(!1)},density:"compact",listLabel:"Hierarchy steps",listClassName:"max-h-40",autoFocusSearch:!0})}):l.jsxs(m.Button,{type:"button",variant:"outline",size:"xs",onClick:b=>{b.preventDefault(),b.stopPropagation(),c(!0)},children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Add step"]})})]})}function pht({open:e,onOpenChange:t,drillHierarchies:n,onUpdateHierarchies:r,availableFields:o}){const[s,i]=v.useState(n);v.useEffect(()=>{e&&i(n)},[e,n]);const a=v.useMemo(()=>o.filter(C=>m.getDataType(C.dataType)==="string"),[o]),c=bC(Em(cp),Em(yC,{coordinateGetter:v4})),{createNewHierarchy:u,deleteHierarchy:d,updateHierarchy:f,addStepToHierarchy:h,removeStepFromHierarchy:p,updateStep:g,setDefaultHierarchy:x}=iht(s,i,a),b=C=>{const{active:w,over:N}=C;if(w.id!==(N==null?void 0:N.id)){const S=s.findIndex(k=>k.id===w.id),j=s.findIndex(k=>k.id===(N==null?void 0:N.id));i(up(s,S,j))}},y=C=>{C||r(s),t(C)};return l.jsx(To,{modal:!0,open:e,onOpenChange:y,children:l.jsx(bo,{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden p-0",onInteractOutside:C=>C.preventDefault(),onEscapeKeyDown:C=>C.preventDefault(),children:l.jsx(m.FocusScope,{trapped:!1,children:l.jsxs("div",{className:"flex max-h-[85vh] max-w-3xl flex-col overflow-hidden",children:[l.jsxs($s,{className:"space-y-1 border-b border-border px-5 pb-3.5 pt-4 text-left",children:[l.jsx(yo,{className:"text-[15px] font-semibold tracking-tight",children:"Manage drill hierarchies"}),l.jsx(Ho,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:"Create multiple drill paths for different analysis scenarios."})]}),l.jsx(m.ScrollArea,{className:"flex-1 px-5",children:l.jsxs("div",{className:"space-y-4 py-4",children:[s.length>0&&l.jsx("div",{className:"flex justify-end",children:l.jsxs(m.Button,{type:"button",size:"xs",onClick:C=>{C.preventDefault(),C.stopPropagation(),u()},children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Add hierarchy"]})}),s.length>0?l.jsx(Sb,{sensors:c,collisionDetection:wb,onDragEnd:b,children:l.jsx(Nb,{items:s.map(C=>C.id),strategy:y4,children:l.jsx("div",{className:"space-y-4",children:s.map(C=>l.jsx(mht,{hierarchy:C,sampleFieldReferences:a,onUpdateHierarchy:f,onDeleteHierarchy:d,onSetDefaultHierarchy:x,onUpdateStep:g,onRemoveStep:p,onAddStep:h},C.id))})})}):l.jsxs("div",{className:"flex flex-col items-center gap-3 py-16 text-center",children:[l.jsx(zm,{className:"h-8 w-8 text-muted-foreground/40",strokeWidth:1.5}),l.jsxs("div",{className:"max-w-[360px] space-y-1",children:[l.jsx("p",{className:"text-[14px] font-medium",children:"No hierarchies yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Create your first hierarchy to enable drill-down interactions."})]}),l.jsxs(m.Button,{type:"button",size:"xs",variant:"outline",onClick:C=>{C.preventDefault(),C.stopPropagation(),u()},children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Create hierarchy"]})]})]})}),l.jsx("div",{className:"flex justify-end gap-1.5 border-t border-border px-5 py-3",children:l.jsx(m.Button,{size:"xs",onClick:()=>y(!1),children:"Done"})})]})})})})}const ght="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function PW({hierarchy:e,selected:t,path:n,onSelect:r}){return l.jsxs("button",{type:"button",onClick:()=>r(e.id),className:m.cn("flex w-full flex-col items-start gap-0.5 rounded-control px-2 py-1.5 text-left transition-colors hover:bg-muted/60",t&&"bg-accent"),children:[l.jsx("span",{className:"w-full truncate text-[13px] font-medium",children:e.label||"Unnamed hierarchy"}),l.jsx("span",{className:"w-full truncate text-[12px] text-muted-foreground",children:n})]})}function xht({interaction:e,onUpdate:t,card:n,availableFields:r,onUpdateHierarchies:o,onManageHierarchies:s}){var D;const[i,a]=v.useState(!1),[c,u]=v.useState(!1),[d,f]=v.useState(null),[h,p]=v.useState(!1),[g,x]=v.useState({}),b=v.useMemo(()=>{var E;return((E=n.interactionConfig)==null?void 0:E.drillHierarchies)||[]},[(D=n.interactionConfig)==null?void 0:D.drillHierarchies]),y=v.useMemo(()=>{var M,O;const E=[],R=e.trigger;if(!R)return E;let F;if(R.type==="attribute"){const z=r.find(V=>V.id===R.field.id);z&&(z.dataType==="date"||z.dataType==="timestamp")&&(F=z)}else if(R.type==="metric"){const z=(O=(M=n.config)==null?void 0:M.groupByColumns)==null?void 0:O.find(L=>L.dataType==="date"||L.dataType==="timestamp");z&&(F=z)}if(F&&m.shouldAutoGenerateDateHierarchy(F,b)){const z=m.generateDateHierarchy(F);E.push(z)}return E},[r,b,e.trigger,n.config]),C=v.useMemo(()=>[...b,...y],[b,y]),w=C.find(E=>E.id===e.hierarchyId);ie.useEffect(()=>{i&&w&&w.type==="date"?f(w.id):i||f(null)},[i,w]);const N=E=>{if(y.some(F=>F.id===E)&&o){const F=y.find(M=>M.id===E);F&&o([...b,F])}t({...e,hierarchyId:E}),a(!1)},S=()=>{a(!1),u(!0),s&&s()},j=E=>{o&&o(E)},k=E=>E.steps.map(F=>fo(F.field)).join(" → "),_=E=>E&&E.charAt(0).toUpperCase()+E.slice(1),T=(E,R,F)=>{var A,B;const M=(A=E.steps[R])==null?void 0:A.field;if(!(M!=null&&M.granularity))return;const O=lo.getTemporalBucketAuthoringOptions(M.granularity).find($=>$.value==="custom"),z=g[R]||(((B=O==null?void 0:O.format)==null?void 0:B.presentation.mode)==="pattern"?O.format.presentation.pattern:"");x($=>{const P={...$};return F==="custom"?P[R]=z:delete P[R],P});const L=[...E.steps];L[R]={...L[R],field:{...L[R].field,format:lo.resolveTemporalBucketAuthoringFormat(M.granularity,F,z),dateFormat:void 0,customFormat:void 0}};const V={...E,steps:L};if(o){const $=b.findIndex(P=>P.id===E.id);if($>=0){const P=[...b];P[$]=V,o(P)}else o([...b,V])}},I=(E,R,F)=>{var L;x(V=>({...V,[R]:F}));const M=(L=E.steps[R])==null?void 0:L.field;if(!(M!=null&&M.granularity))return;const O=[...E.steps];O[R]={...O[R],field:{...O[R].field,format:lo.resolveTemporalBucketAuthoringFormat(M.granularity,"custom",F),dateFormat:void 0,customFormat:void 0}};const z={...E,steps:O};if(o){const V=b.findIndex(A=>A.id===E.id);if(V>=0){const A=[...b];A[V]=z,o(A)}else o([...b,z])}};return l.jsxs("div",{className:"space-y-4",children:[l.jsx(si,{label:"Choose hierarchy",description:"Select which hierarchy to drill through when this interaction triggers",children:C.length>0?l.jsxs(l.Fragment,{children:[l.jsxs(m.Popover,{open:i,onOpenChange:a,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs(m.Button,{variant:"outline",role:"combobox",className:"h-auto w-full justify-between px-2.5 py-1.5",children:[l.jsx("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5 text-left",children:w?l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"w-full truncate text-[13px] font-medium",children:w.label||"Unnamed hierarchy"}),l.jsx("span",{className:"w-full truncate text-[12px] font-normal text-muted-foreground",children:k(w)})]}):l.jsx("span",{className:"text-[13px] font-normal text-muted-foreground",children:"Select hierarchy…"})}),l.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[w&&w.type==="date"&&l.jsx("span",{role:"button",tabIndex:0,"aria-label":"Customize date formats",className:"inline-flex h-6 w-6 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",onClick:E=>{E.stopPropagation(),p(!h)},onKeyDown:E=>{E.key!=="Enter"&&E.key!==" "||(E.preventDefault(),E.stopPropagation(),p(!h))},children:l.jsx(n5,{className:"h-3.5 w-3.5"})}),l.jsx(Ft.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]})]})}),l.jsxs(m.PopoverContent,{className:"w-[500px] p-0",align:"start",children:[l.jsxs("div",{className:"flex h-10 items-center justify-between gap-2 border-b border-border px-3",children:[l.jsx("span",{className:"text-[13px] font-medium",children:"Select hierarchy"}),l.jsxs(m.Button,{variant:"ghost",size:"xs",onClick:S,children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Create new"]})]}),l.jsxs("div",{className:"p-1.5",children:[y.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"px-2 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Auto-generated"}),y.map(E=>l.jsx(PW,{hierarchy:E,selected:e.hierarchyId===E.id,path:k(E),onSelect:N},E.id))]}),b.length>0&&l.jsxs(l.Fragment,{children:[y.length>0&&l.jsx("div",{className:"my-1.5 border-t border-border/60"}),b.map(E=>l.jsx(PW,{hierarchy:E,selected:e.hierarchyId===E.id,path:k(E),onSelect:N},E.id))]})]})]})]}),w&&w.type==="date"&&h&&l.jsxs("div",{className:"mt-3 space-y-3 rounded-card border border-border/60 p-3",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx(m.Label,{className:"text-[13px] font-medium",children:"Customize date formats"}),l.jsx(m.Button,{variant:"ghost",size:"xs",className:"h-6",onClick:()=>p(!1),children:"Close"})]}),w.steps.map((E,R)=>{const F=E.field.granularity;if(!F)return null;const M=m.readTemporalBucketAuthoringSelection({fieldId:E.field.id,dataType:E.field.dataType,granularity:F,format:E.field.format,dateFormat:E.field.dateFormat,customFormat:E.field.customFormat,semanticTemporalPresentation:E.field.semanticTemporalPresentation}),O=lo.getTemporalBucketAuthoringOptions(F,M.format),z=g[R]!==void 0?"custom":M.value;return l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:ght,children:fo(E.field)||_(F)}),l.jsxs(m.Select,{value:z,onValueChange:L=>{T(w,R,L)},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:O.map(L=>l.jsx(m.SelectItem,{value:L.value,className:"text-[12px]",children:L.label},L.value))})]}),z==="custom"&&l.jsxs("div",{className:"mt-2 space-y-1",children:[l.jsx(m.Input,{size:"xs",placeholder:"Enter custom format (e.g., YYYY-MM-DD)",value:g[R]??M.customPattern??"",onChange:L=>{I(w,R,L.target.value)}}),l.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Common tokens: YYYY (year), MM (month), DD (day), HH (hour), mm (minute)"})]})]},R)})]})]}):l.jsxs("div",{className:"flex flex-col items-center gap-3 py-8 text-center",children:[l.jsx(zm,{className:"h-8 w-8 text-muted-foreground/40",strokeWidth:1.5}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("p",{className:"text-[13px] font-medium",children:"No hierarchies yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Create one to define your drill path."})]}),l.jsxs(m.Button,{variant:"outline",size:"xs",onClick:S,children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Create hierarchy"]})]})}),l.jsx(pht,{open:c,onOpenChange:u,drillHierarchies:b,onUpdateHierarchies:j,availableFields:r})]})}function bht({fields:e,selectedFieldIds:t,onSelectionChange:n,searchPlaceholder:r="Search fields",className:o=""}){const[s,i]=v.useState(""),a=v.useMemo(()=>new Set(t),[t]),c=v.useMemo(()=>e.filter(h=>hb(h,s)),[e,s]),u=()=>{n([...new Set([...t,...c.map(h=>h.id)])])},d=()=>{const h=new Set(c.map(p=>p.id));n(t.filter(p=>!h.has(p)))},f=h=>{a.has(h.id)?n(t.filter(p=>p!==h.id)):n([...t,h.id])};return l.jsx("div",{className:m.cn("flex flex-col",o),children:l.jsx(PT,{fields:e,selectedIds:a,onSelect:f,selectionMode:"multiple",query:s,onQueryChange:i,searchPlaceholder:r,listLabel:"Available fields",density:"compact",listClassName:"max-h-40 rounded-card border border-border/60 py-0.5",emptyMessage:s?`No fields found matching "${s}"`:void 0,toolbar:l.jsxs("div",{className:"mb-1.5 flex items-center gap-1.5",children:[l.jsx(m.Button,{size:"xs",variant:"ghost",onClick:u,children:"Select all"}),l.jsx(m.Button,{size:"xs",variant:"ghost",onClick:d,children:"Clear"}),l.jsxs("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:[t.length," of ",e.length," selected"]})]})})})}const yht=e=>["string","boolean"].includes(m.getDataType(e.dataType));function vht({interaction:e,availableFields:t,onUpdate:n}){var i;const r=t.filter(yht),o=((i=e.availableFields)==null?void 0:i.map(a=>a.id))||[],s=a=>{const c=r.filter(u=>a.includes(u.id));n({...e,availableFields:c})};return l.jsx("div",{className:"space-y-4",children:l.jsxs(si,{label:"Available dimensions",description:"Choose which fields users can explore dynamically",children:[l.jsx(bht,{fields:r,selectedFieldIds:o,onSelectionChange:s,searchPlaceholder:"Search fields…"}),o.length===0&&l.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-muted-foreground",children:[l.jsx(ea,{className:"h-3.5 w-3.5 shrink-0"}),"Select at least one field to finish this interaction"]})]})})}function wht({value:e,onChange:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(""),[i,a]=v.useState("all"),{currentUser:c}=hi(),{data:u,isLoading:d}=b5(uo.DASHBOARD,o),f=(u==null?void 0:u.dashboards)||[],h=f.filter(x=>i==="me"?x.ownership.createdBy.userId===(c==null?void 0:c.id):!0),p=f.find(x=>x.id===e),g=x=>{t(x.id,x.title),r(!1),s("")};return l.jsxs(m.Popover,{open:n,onOpenChange:r,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx(m.Button,{variant:"outline",size:"sm",className:m.cn("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:p?l.jsx("span",{className:"truncate",children:p.title}):"Choose dashboard…"})}),l.jsx(m.PopoverContent,{className:"w-[500px] p-0",align:"start",children:l.jsxs(m.Tabs,{value:i,onValueChange:x=>a(x),children:[l.jsx("div",{className:"border-b border-border p-2",children:l.jsxs("div",{className:"relative",children:[l.jsx(Ft.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),l.jsx(m.Input,{size:"sm",placeholder:"Search all dashboards…",value:o,onChange:x=>s(x.target.value),className:"pl-7"})]})}),l.jsxs(m.TabsList,{variant:"underline",className:"px-3",children:[l.jsx(m.TabsTrigger,{variant:"underline",value:"me",children:"Created by me"}),l.jsx(m.TabsTrigger,{variant:"underline",value:"all",children:"All"})]}),l.jsx(m.TabsContent,{value:i,className:"mt-0",children:l.jsx(m.ScrollArea,{className:"h-[300px]",children:d?l.jsx("div",{className:"p-8 text-center text-[13px] text-muted-foreground",children:"Loading dashboards…"}):h.length===0?l.jsx("div",{className:"p-8 text-center text-[13px] text-muted-foreground",children:o?`No dashboards found matching "${o}"`:i==="me"?"No dashboards created by you":"No dashboards available"}):l.jsx("div",{className:"p-1.5",children:h.map(x=>l.jsxs("button",{onClick:()=>g(x),className:m.cn("flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left transition-colors hover:bg-muted/60",e===x.id&&"bg-accent"),children:[l.jsx(zd,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"truncate text-[13px] font-medium",children:x.title}),l.jsx("div",{className:"mt-0.5 text-[11px] uppercase tracking-[0.04em] text-muted-foreground",children:Cht(x.createdAt)})]})]},x.id))})})})]})})]})}function Cht(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),c=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${c}`}const o=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),s=t.getDate();return`${o} ${s}`}const Sht=[{value:"interactionFilters",label:"Interaction filters",description:"Pass only the clicked element as a filter"},{value:"full",label:"All filters",description:"Pass current dashboard filters + clicked element"},{value:"none",label:"None",description:"Navigate without passing any filters"}];function Nht({interaction:e,onUpdate:t}){return l.jsxs("div",{className:"space-y-4",children:[l.jsxs(si,{label:"Target dashboard",description:"Select which dashboard to navigate to when this interaction triggers",children:[l.jsx(wht,{value:e.targetDashboardId,onChange:(n,r)=>{const o={...e,targetDashboardId:n};!e.label&&r&&(o.label=r),t(o)}}),!e.targetDashboardId&&l.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-muted-foreground",children:[l.jsx(ea,{className:"h-3.5 w-3.5 shrink-0"}),"Select a target dashboard to finish this interaction"]})]}),l.jsx(si,{label:"Propagate filters",description:"Choose what filters to pass to the target dashboard",children:l.jsxs(m.Select,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[l.jsx(m.SelectTrigger,{size:"sm",children:l.jsxs(m.SelectValue,{placeholder:"Choose context mode…",children:[e.contextMode==="interactionFilters"&&"Interaction filters",(e.contextMode==="full"||!e.contextMode)&&"All filters",e.contextMode==="none"&&"None"]})}),l.jsx(m.SelectContent,{children:Sht.map(n=>l.jsx(m.SelectItem,{value:n.value,className:E0,children:l.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[l.jsx("span",{className:"text-[13px] font-medium leading-[1.35]",children:n.label}),l.jsx("span",{className:"text-[12px] leading-[1.35] text-muted-foreground",children:n.description})]})},n.value))})]})}),l.jsx(si,{label:"Menu label",description:"How this interaction appears when multiple actions are available",children:l.jsx(m.Input,{size:"sm",value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:ap(e.mode)})})]})}function jht({value:e,onChange:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(""),[i,a]=v.useState("all"),{currentUser:c}=hi(),{data:u,isLoading:d}=b5(uo.VISUAL,o),f=(u==null?void 0:u.visuals)||[],h=f.filter(x=>i==="me"?x.ownership.createdBy.userId===(c==null?void 0:c.id):!0),p=f.find(x=>x.id===e),g=x=>{t(x.id,x.title),r(!1),s("")};return l.jsxs(m.Popover,{open:n,onOpenChange:r,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx(m.Button,{variant:"outline",size:"sm",className:m.cn("w-full justify-start text-left font-normal",!e&&"text-muted-foreground"),children:p?l.jsx("span",{className:"truncate",children:p.title}):"Choose insight…"})}),l.jsx(m.PopoverContent,{className:"w-[500px] p-0",align:"start",children:l.jsxs(m.Tabs,{value:i,onValueChange:x=>a(x),children:[l.jsx("div",{className:"border-b border-border p-2",children:l.jsxs("div",{className:"relative",children:[l.jsx(Ft.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),l.jsx(m.Input,{size:"sm",placeholder:"Search all insights…",value:o,onChange:x=>s(x.target.value),className:"pl-7"})]})}),l.jsxs(m.TabsList,{variant:"underline",className:"px-3",children:[l.jsx(m.TabsTrigger,{variant:"underline",value:"me",children:"Created by me"}),l.jsx(m.TabsTrigger,{variant:"underline",value:"all",children:"All"})]}),l.jsx(m.TabsContent,{value:i,className:"mt-0",children:l.jsx(m.ScrollArea,{className:"h-[300px]",children:d?l.jsx("div",{className:"p-8 text-center text-[13px] text-muted-foreground",children:"Loading insights…"}):h.length===0?l.jsx("div",{className:"p-8 text-center text-[13px] text-muted-foreground",children:o?`No insights found matching "${o}"`:i==="me"?"No insights created by you":"No insights available"}):l.jsx("div",{className:"p-1.5",children:h.map(x=>l.jsxs("button",{onClick:()=>g(x),className:m.cn("flex w-full items-start gap-2 rounded-control px-2 py-1.5 text-left transition-colors hover:bg-muted/60",e===x.id&&"bg-accent"),children:[l.jsx(m.ChartColumn,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"truncate text-[13px] font-medium",children:x.title}),l.jsx("div",{className:"mt-0.5 text-[11px] uppercase tracking-[0.04em] text-muted-foreground",children:kht(x.createdAt)})]})]},x.id))})})})]})})]})}function kht(e){const t=new Date(e),n=new Date;if(t.getDate()===n.getDate()&&t.getMonth()===n.getMonth()&&t.getFullYear()===n.getFullYear()){const i=t.getHours(),a=t.getMinutes(),c=i>=12?"PM":"AM",u=i%12||12,d=a.toString().padStart(2,"0");return`TODAY AT ${u}:${d} ${c}`}const o=t.toLocaleString("en-US",{month:"short"}).toUpperCase(),s=t.getDate();return`${o} ${s}`}const Iht=[{value:"interactionFilters",label:"Interaction filters",description:"Pass only the clicked element as a filter"},{value:"full",label:"All filters",description:"Pass all current filters and selections"},{value:"none",label:"None",description:"Open insight without any filters"}];function _ht({interaction:e,onUpdate:t}){return l.jsxs("div",{className:"space-y-4",children:[l.jsxs(si,{label:"Target insight",description:"Select the saved insight to navigate to",children:[l.jsx(jht,{value:e.targetInsightId,onChange:(n,r)=>{const o={...e,targetInsightId:n};!e.label&&r&&(o.label=r),t(o)}}),!e.targetInsightId&&l.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] text-muted-foreground",children:[l.jsx(ea,{className:"h-3.5 w-3.5 shrink-0"}),"Select a target insight to finish this interaction"]})]}),l.jsx(si,{label:"Propagate filters",description:"Choose what filters to pass to the insight",children:l.jsxs(m.Select,{value:e.contextMode||"full",onValueChange:n=>t({...e,contextMode:n}),children:[l.jsx(m.SelectTrigger,{size:"sm",children:l.jsxs(m.SelectValue,{placeholder:"Choose context mode…",children:[e.contextMode==="interactionFilters"&&"Interaction filters",(e.contextMode==="full"||!e.contextMode)&&"All filters",e.contextMode==="none"&&"None"]})}),l.jsx(m.SelectContent,{children:Iht.map(n=>l.jsx(m.SelectItem,{value:n.value,className:E0,children:l.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[l.jsx("span",{className:"text-[13px] font-medium leading-[1.35]",children:n.label}),l.jsx("span",{className:"text-[12px] leading-[1.35] text-muted-foreground",children:n.description})]})},n.value))})]})}),l.jsx(si,{label:"Display mode",description:"Choose how the insight should be displayed",children:l.jsxs(m.Select,{value:e.displayMode||"modal",onValueChange:n=>t({...e,displayMode:n}),children:[l.jsx(m.SelectTrigger,{size:"sm",children:l.jsx(m.SelectValue,{placeholder:"Choose display mode…"})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"modal",children:"Open in modal"}),l.jsx(m.SelectItem,{value:"replace-card",children:"Replace the card"})]})]})}),l.jsx(si,{label:"Menu label",description:"How this interaction appears when multiple actions are available",children:l.jsx(m.Input,{size:"sm",value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:ap(e.mode)})})]})}function Tht(e){return e.filter(t=>t.role==="groupby"||t.role==="pivotby").map(t=>({id:t.name,label:t.label||t.name,category:"attribute",field:t}))}function Dht(){return[{id:"card_id",label:"Card ID",category:"identifier"},{id:"frame_id",label:"Frame ID",category:"identifier"},{id:"sheet_id",label:"Sheet ID",category:"identifier"}]}function Eht(e,t){const n=`{{${t}}}`;return e.includes(n)}function Mht(e,t){return t.filter(n=>Eht(e,n.id))}function Rht(e,t,n){const r=`{{${t}}}`,o=e.slice(0,n)+r+e.slice(n),s=n+r.length;return{newTemplate:o,newCursorPosition:s}}function Aht(e,t){let n=e;return t.forEach(r=>{const o=`{{${r.id}}}`;let s;if(r.category==="identifier")s=`${r.id.toUpperCase()}-abc123`;else{const i=r.label.toLowerCase();i.includes("name")?s="Example Name":i.includes("region")||i.includes("location")?s="California":i.includes("id")?s="ID-12345":i.includes("category")?s="Category A":s="Sample Value"}n=n.replace(new RegExp(o,"g"),s)}),n}const I2="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Fht({open:e,onOpenChange:t,interaction:n,availableFields:r,onSave:o}){const[s,i]=v.useState(n.urlTemplate||""),[a,c]=v.useState(0),[u,d]=v.useState(n.encodeParameters!==!1),[f,h]=v.useState(n.label||""),p=v.useRef(null);v.useEffect(()=>{e&&(i(n.urlTemplate||""),d(n.encodeParameters!==!1),h(n.label||""),c(0))},[e,n.urlTemplate,n.encodeParameters,n.label]);const g=Tht(r),x=Dht(),b=[...g,...x],y=Mht(s,b),C=m.validateURLTemplate(s),w=s&&C.valid?Aht(s,y):"",N=I=>{i(I.target.value),c(I.target.selectionStart)},S=I=>{const D=I.target;c(D.selectionStart)},j=I=>{const D=I.target;c(D.selectionStart)},k=I=>{const{newTemplate:D,newCursorPosition:E}=Rht(s,I.id,a);i(D),c(E),p.current&&(p.current.focus(),setTimeout(()=>{p.current&&p.current.setSelectionRange(E,E)},0))},_=()=>{C.valid&&(o({...n,urlTemplate:s,parameters:y,encodeParameters:u,label:f}),t(!1))},T=()=>{t(!1)};return l.jsx(To,{open:e,onOpenChange:t,children:l.jsxs(bo,{className:"flex max-h-[90vh] max-w-5xl flex-col gap-0 overflow-hidden p-0",onOpenAutoFocus:I=>{I.preventDefault(),setTimeout(()=>{var D;(D=p.current)==null||D.focus()},0)},children:[l.jsxs($s,{className:"space-y-1 border-b border-border px-5 pb-3.5 pt-4 text-left",children:[l.jsx(yo,{className:"text-[15px] font-semibold tracking-tight",children:"Configure drill to URL"}),l.jsx(Ho,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:"Build a custom URL with dynamic parameters that opens when users click on chart elements."})]}),l.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto px-5 py-4",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-5",children:[l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Label,{htmlFor:"url-template",className:"text-[13px] font-medium",children:"URL"}),l.jsx(m.TooltipProvider,{children:l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})}),l.jsx(m.TooltipContent,{children:l.jsx("p",{className:"max-w-xs text-[12px]",children:"Enter your URL and click parameters from the right panel to insert them. Parameters will be replaced with actual values when the URL is opened."})})]})})]}),l.jsx(qm,{ref:p,id:"url-template",value:s,onChange:N,onClick:S,onKeyUp:j,placeholder:"https://example.com/product/{{product_id}}?region={{region}}",className:"min-h-[200px] font-mono text-[12px] leading-[1.55]"}),!C.valid&&s&&l.jsx("div",{className:"space-y-0.5 text-[12px] text-destructive",children:C.errors.map((I,D)=>l.jsx("div",{children:I},D))}),w&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("div",{className:I2,children:"Preview"}),l.jsx("p",{className:"break-all rounded-control border border-border/70 bg-muted/40 px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:w})]})]}),l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Label,{className:"text-[13px] font-medium",children:"Parameters"}),l.jsx(m.TooltipProvider,{children:l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})}),l.jsx(m.TooltipContent,{children:l.jsx("p",{className:"max-w-xs text-[12px]",children:"Click any parameter to insert it into your URL at the cursor position. Attributes come from your chart data, identifiers are system values."})})]})})]}),l.jsxs("div",{className:"flex flex-col gap-4 rounded-card border border-border/60 p-3",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("div",{className:I2,children:"Attributes"}),l.jsxs("div",{className:"space-y-0.5",children:[g.map(I=>l.jsx(OW,{parameter:I,isUsed:y.some(D=>D.id===I.id),onClick:()=>k(I)},I.id)),g.length===0&&l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No attributes available"})]})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("div",{className:I2,children:"Identifiers"}),l.jsx("div",{className:"space-y-0.5",children:x.map(I=>l.jsx(OW,{parameter:I,isUsed:y.some(D=>D.id===I.id),onClick:()=>k(I)},I.id))})]})]})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(jn,{id:"encode-params",checked:u,onCheckedChange:I=>d(I===!0)}),l.jsx(m.Label,{htmlFor:"encode-params",className:"cursor-pointer text-[13px] font-normal",children:"URL encode parameters"}),l.jsx(m.TooltipProvider,{children:l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})}),l.jsx(m.TooltipContent,{children:l.jsx("p",{className:"max-w-xs text-[12px]",children:"Recommended. Encodes special characters in parameter values to ensure valid URLs (e.g., spaces become %20)."})})]})})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Label,{className:"text-[13px] font-medium",children:"Menu label"}),l.jsx(m.TooltipProvider,{children:l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})}),l.jsx(m.TooltipContent,{children:l.jsx("p",{className:"max-w-xs text-[12px]",children:"How this interaction appears when multiple actions are available"})})]})})]}),l.jsx(m.Input,{size:"sm",value:f,onChange:I=>h(I.target.value),placeholder:ap("drillToURL")})]}),l.jsxs("p",{className:"flex items-start gap-1.5 text-[12px] text-muted-foreground",children:[l.jsx(m.Info,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),"URLs always open in a new browser tab when clicked."]})]}),l.jsxs(ll,{className:"gap-1.5 border-t border-border px-5 py-3 sm:space-x-0",children:[l.jsx(m.Button,{size:"xs",variant:"outline",onClick:T,children:"Cancel"}),l.jsx(m.Button,{size:"xs",onClick:_,disabled:!C.valid,children:"Save"})]})]})})}function OW({parameter:e,isUsed:t,onClick:n}){var s,i;const r=e.category==="attribute"?mX:_x,o=((s=e.field)==null?void 0:s.qualifiedFieldName)||((i=e.field)==null?void 0:i.name);return l.jsxs(m.Button,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-2 py-1.5 font-normal hover:bg-muted/60",onClick:n,children:[l.jsx(r,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/70"}),l.jsxs("div",{className:"flex min-w-0 flex-1 flex-col items-start gap-0.5",children:[l.jsx("span",{className:"w-full truncate text-[13px]",children:e.label}),o&&l.jsx("span",{className:"w-full truncate font-mono text-[11px] text-muted-foreground",children:o})]}),t&&l.jsx(m.Check,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-muted-foreground"})]})}function Pht({interaction:e,availableFields:t,onUpdate:n}){const[r,o]=v.useState(!1),s=!!e.urlTemplate;return l.jsxs("div",{className:"flex flex-col gap-4",children:[s?l.jsxs("div",{className:"flex flex-col gap-3 rounded-card border border-border/60 p-3",children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx($d,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"text-[13px] font-medium",children:"URL template"})]}),l.jsx("p",{className:"break-all rounded-control border border-border/70 bg-muted/40 px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:e.urlTemplate})]}),l.jsxs(m.Button,{variant:"outline",size:"xs",onClick:()=>o(!0),children:[l.jsx(r5,{className:"h-3.5 w-3.5"}),"Edit"]})]}),l.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[e.parameters&&e.parameters.length>0?`${e.parameters.length} parameter${e.parameters.length!==1?"s":""} · `:"","URL encoding"," ",e.encodeParameters!==!1?"enabled":"disabled"]})]}):l.jsxs("div",{className:"flex flex-col items-center gap-3 py-8 text-center",children:[l.jsx($d,{className:"h-8 w-8 text-muted-foreground/40",strokeWidth:1.5}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No URL configured"}),l.jsx(m.Button,{variant:"outline",size:"xs",onClick:()=>o(!0),children:"Add custom URL"})]}),l.jsx(Fht,{open:r,onOpenChange:o,interaction:e,availableFields:t,onSave:n})]})}function Oht({interaction:e,onUpdate:t}){return l.jsxs("div",{className:"space-y-4",children:[l.jsxs(si,{label:"Fetch mode",description:"Choose when to load the detailed data",children:[l.jsxs(m.Select,{value:e.fetchMode||"lazy",onValueChange:n=>t({...e,fetchMode:n}),children:[l.jsx(m.SelectTrigger,{size:"sm",children:l.jsx(m.SelectValue,{placeholder:"Choose fetch mode…"})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"lazy",className:E0,children:l.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[l.jsx("span",{className:"text-[13px] font-medium leading-[1.35]",children:"Lazy loading"}),l.jsx("span",{className:"text-[12px] leading-[1.35] text-muted-foreground",children:"Fetch data only when user clicks"})]})}),l.jsx(m.SelectItem,{value:"preloaded",className:E0,children:l.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[l.jsx("span",{className:"text-[13px] font-medium leading-[1.35]",children:"Preloaded"}),l.jsx("span",{className:"text-[12px] leading-[1.35] text-muted-foreground",children:"Fetch all data when dashboard loads"})]})})]})]}),l.jsxs("p",{className:"flex gap-1.5 text-[12px] leading-[1.5] text-muted-foreground",children:[l.jsx(m.Info,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),l.jsx("span",{children:e.fetchMode==="lazy"?"Data is fetched on-demand when the user clicks. Best for large datasets or when detailed data isn't always needed.":"Data is fetched when the dashboard loads. Best for small datasets or when instant drill-down is required."})]})]}),l.jsx(si,{label:"Record limit",description:"Maximum number of detailed records to show (0 for unlimited)",children:l.jsx(m.Input,{size:"sm",type:"number",min:"0",placeholder:"100",value:e.inlineLimit??100,onChange:n=>{const r=parseInt(n.target.value)||0;t({...e,inlineLimit:r})}})}),l.jsx(si,{label:"Display mode",description:"How to display the detailed records",children:l.jsxs(m.Select,{value:e.displayMode||"table",onValueChange:n=>t({...e,displayMode:n}),children:[l.jsx(m.SelectTrigger,{size:"sm",children:l.jsx(m.SelectValue,{placeholder:"Choose display mode…"})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"table",children:"Table view"}),l.jsx(m.SelectItem,{value:"list",children:"List view"}),l.jsx(m.SelectItem,{value:"cards",children:"Card view"})]})]})}),l.jsxs("div",{className:"divide-y divide-border/60 border-y border-border/60",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3 py-2.5",children:[l.jsxs("div",{className:"space-y-0.5",children:[l.jsx(m.Label,{className:"text-[13px] font-medium",children:"Show in modal"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display detailed records in a modal overlay"})]}),l.jsx(m.Switch,{checked:e.showInModal??!1,onCheckedChange:n=>t({...e,showInModal:n})})]}),l.jsxs("div",{className:"flex items-center justify-between gap-3 py-2.5",children:[l.jsxs("div",{className:"space-y-0.5",children:[l.jsx(m.Label,{className:"text-[13px] font-medium",children:"Allow export"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Enable users to export the detailed records"})]}),l.jsx(m.Switch,{checked:e.allowExport??!0,onCheckedChange:n=>t({...e,allowExport:n})})]})]}),l.jsx(si,{label:"Menu label",description:"How this interaction appears when multiple actions are available",children:l.jsx(m.Input,{size:"sm",value:e.label||"",onChange:n=>t({...e,label:n.target.value}),placeholder:ap(e.mode)})})]})}function Lht({interaction:e,metrics:t,attributes:n,availableFields:r,card:o,onUpdateHierarchies:s,onUpdate:i,onRemove:a}){const c=e.trigger!==void 0,u=e.mode!==void 0,d=c&&u,[f,h]=v.useState(!d),p=()=>{var y;if(!c)return"Configure interaction";const x=`When ${(y=e.trigger)!=null&&y.field?fo(e.trigger.field):"..."}`;if(!u)return`${x} → Choose action`;const b=e.label||ap(e.mode);return`${x} → ${b}`},g=u?pk(e.mode):null;return l.jsxs("div",{className:"relative rounded-card border border-border bg-card text-card-foreground",children:[l.jsx(m.Button,{variant:"ghost",size:"xs",className:"absolute right-1.5 top-1.5 z-10 h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":"Remove interaction",children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})}),l.jsxs(Nu,{open:f,onOpenChange:h,children:[l.jsx(ju,{asChild:!0,children:l.jsxs(m.Button,{variant:"ghost",className:"h-auto w-full justify-between gap-3 rounded-card px-3 py-2.5 pr-10 hover:bg-muted/50",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[g&&l.jsx(g,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"truncate text-left text-[13px] font-medium",children:p()})]}),l.jsx(Re.ChevronDown,{className:m.cn("h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform",f&&"rotate-180")})]})}),l.jsx(ku,{children:l.jsxs("div",{className:"space-y-5 border-t border-border/60 p-4",children:[l.jsx("div",{className:"space-y-3",children:c?l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"text-[13px] font-medium",children:["When I click on"," ",l.jsx("span",{className:"text-muted-foreground",children:"(value of)"})]}),e.trigger&&l.jsxs("button",{type:"button","aria-label":`Change trigger field (currently ${fo(e.trigger.field)})`,className:"inline-flex h-6 items-center gap-1 rounded-control border border-transparent bg-muted/60 pl-1 pr-1.5 text-[11px] font-medium text-foreground transition-colors hover:border-border/60 hover:bg-muted [&_svg]:h-3 [&_svg]:w-3",onClick:()=>{i({...e,trigger:void 0})},children:[kk(e.trigger.field.dataType),l.jsx("span",{children:fo(e.trigger.field)})]})]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"text-[13px] font-medium",children:"When I click on"}),l.jsx(pdt,{value:e.trigger,onChange:x=>{i({...e,trigger:x})},metrics:t,attributes:n})]})}),c&&l.jsx(l.Fragment,{children:l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"text-[13px] font-medium",children:"I want to"}),l.jsx(gdt,{allowedModes:o.type==="matrixTable"?["clickFilter","drillToDetail"]:void 0,value:e.mode,onChange:x=>{if(!e.trigger){console.error("Trigger must be defined before selecting action");return}const b={mode:x,trigger:e.trigger};switch(x){case"clickFilter":i({...b,mode:"clickFilter",filterFields:[]});break;case"drillDown":i({...b,mode:"drillDown",filterFields:[]});break;case"dynamicDrill":i({...b,mode:"dynamicDrill",availableFields:[]});break;case"drillThrough":i({...b,mode:"drillThrough",filterFields:[],targetDashboardId:""});break;case"drillToDetail":i({...b,mode:"drillToDetail",filterFields:[]});break;case"drillToURL":i({...b,mode:"drillToURL",filterFields:[],urlTemplate:"",parameters:[],encodeParameters:!0});break;case"inlineDrill":i({...b,mode:"inlineDrill",filterFields:[]});break}}})]})}),c&&u&&l.jsxs(l.Fragment,{children:[l.jsx(m.Separator,{}),l.jsx($ht,{interaction:e,metrics:t,attributes:n,availableFields:r,card:o,onUpdateHierarchies:s,onUpdate:i})]})]})})]})]})}function $ht({interaction:e,metrics:t,attributes:n,availableFields:r,card:o,onUpdateHierarchies:s,onUpdate:i}){switch(e.mode){case"clickFilter":return l.jsx(bdt,{interaction:e,onUpdate:a=>i(a)});case"drillDown":return l.jsx(xht,{interaction:e,onUpdate:a=>i(a),card:o,availableFields:r,onUpdateHierarchies:s});case"dynamicDrill":return l.jsx(vht,{interaction:e,onUpdate:a=>i(a),availableFields:r});case"drillThrough":return l.jsx(Nht,{interaction:e,onUpdate:a=>i(a)});case"drillToDetail":return l.jsx(_ht,{interaction:e,onUpdate:a=>i(a)});case"drillToURL":return l.jsx(Pht,{interaction:e,availableFields:[...t,...n],onUpdate:a=>i(a)});case"inlineDrill":return l.jsx(Oht,{interaction:e,onUpdate:a=>i(a)});default:return l.jsx("div",{className:"text-[13px] text-muted-foreground",children:"Unknown interaction type"})}}function zht({interactions:e,metrics:t,attributes:n,availableFields:r,card:o,onUpdateHierarchies:s,onChange:i}){const[a,c]=v.useState(null),u=()=>{const h=m.createInteractionWithStableId().id,p={id:h};i([...e,p]),c(h)},d=(h,p)=>{const g=e[h],x={...p,id:p.id||(g==null?void 0:g.id)},b=[...e];b[h]=x,i(b)},f=h=>{var g;const p=e.filter((x,b)=>b!==h);i(p),a===((g=e[h])==null?void 0:g.id)&&c(null)};return l.jsxs("div",{className:"space-y-4",children:[e.length>0?l.jsx("div",{className:"space-y-3",children:e.map((h,p)=>l.jsx(Lht,{interaction:h,metrics:t,attributes:n,availableFields:r,card:o,onUpdateHierarchies:s,onUpdate:g=>d(p,g),onRemove:()=>f(p)},h.id||p))}):l.jsxs("div",{className:"flex flex-col items-center gap-3 py-10 text-center",children:[l.jsx(twe,{className:"h-8 w-8 text-muted-foreground/40",strokeWidth:1.5}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("p",{className:"text-[13px] font-medium",children:"No interactions yet"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Add one to make this chart respond to clicks."})]}),l.jsxs(m.Button,{onClick:u,size:"xs",variant:"outline",children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Add interaction"]})]}),e.length>0&&l.jsx("div",{className:"flex justify-start pt-2",children:l.jsxs(m.Button,{onClick:u,size:"xs",variant:"outline",children:[l.jsx(Ar,{className:"h-3.5 w-3.5"}),"Add interaction"]})})]})}function w4(e){var n,r;const t=(n=e==null?void 0:e.semanticDomainId)==null?void 0:n.trim();if(t)return t;for(const o of(e==null?void 0:e.selectedEntities)||[]){if((o==null?void 0:o.type)!=="dataset")continue;const s=(r=o.domainId)==null?void 0:r.trim();if(s)return s}}const Bht=[],Vht=[],Hht=[];function _2(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!=null))}function qht(e){return e.flatMap(t=>t.columns.map(n=>{const r=Tm(n)?n.label:void 0,o=r?void 0:n.derivedLabel??m.toTitleCase(n.name),s=r??o??n.name;return{...n,id:n.id||`${t.entityId}-${n.name}`,name:n.name,qualifiedFieldName:n.qualifiedFieldName||n.name,dataType:n.dataType,qualifiedEntityName:n.qualifiedEntityName||t.qualifiedEntityName,label:s,...o!==void 0?{derivedLabel:o}:{},description:n.description,entityId:n.entityId||t.entityId,entityName:n.entityName||t.entityName,entityType:n.entityType||t.entityType}}))}function C4(e){var N;const{tokenProps:t}=Mt(),n=m.useDashboardStore(S=>S.authToken)||e,{selectedConnection:r,hasSchemaSupport:o}=cte(e),s=m.useEditorStore(S=>{var j;return(j=S.card.dataSource)==null?void 0:j.connectionId}),i=m.useEditorStore(S=>w4(S.card.dataSource)),a=m.useEditorStore(S=>{var j;return(j=S.card.dataSource)==null?void 0:j.selectedEntities}),c=v.useMemo(()=>(a==null?void 0:a.filter(S=>S.type==="model"))||Bht,[a]),u=v.useMemo(()=>(a==null?void 0:a.filter(S=>lt.DATABASE_ENTITY_TYPES.includes(S.type)))||Vht,[a]),d=v.useMemo(()=>(a==null?void 0:a.filter(S=>S.type==="dataset"))||Hht,[a]);function f(S){var j;if(S.type==="dataset")return!!s&&!!S.domainId&&!!S.name;if(S.type==="model")return!!s&&!!S.id;if(lt.DATABASE_ENTITY_TYPES.includes(S.type)){const k=((j=r==null?void 0:r.capabilities)==null?void 0:j.path)||[],_=k.includes("database"),T=k.includes("schema")||o;return!(!s||!S.name||_&&!S.database||T&&!S.schema)}return!1}const h=[...c,...u,...d],p=cf({queries:h.map(S=>{let j={};return S.type==="model"?j=_2({connection_id:s,datamodel_id:S.id,database_name:"",schema_name:"",table_name:""}):S.type==="dataset"?j=_2({connection_id:S.connectionId,domain_id:S.domainId,dataset_name:S.name,database_name:S.database,schema_name:S.schema,table_name:S.table}):j=_2({connection_id:s,datamodel_id:"",database_name:S.database,schema_name:S.schema,table_name:S.name}),{queryKey:["columns",s,S,i||null],queryFn:()=>m.getRequest(`${t.apiServiceUrl}/v1/columns`,(n==null?void 0:n.accessToken)||"",j),enabled:!!s&&f(S)}})}),g=p.some(S=>S.isPending&&S.fetchStatus==="fetching"),x=p.some(S=>S.isError),b=(N=p.find(S=>S.isError))==null?void 0:N.error,y=p.map((S,j)=>{var T;const k=h[j],_=((T=S.data)==null?void 0:T.columns)||[];return kse(k,_)}).filter(S=>{var j;return((j=S==null?void 0:S.columns)==null?void 0:j.length)>0})||[],C=p.flatMap(S=>{var j;return((j=S.data)==null?void 0:j.calculatedFields)||[]}).map(S=>({...S,id:en.getStableDomainCalculatedFieldId({...S}),fieldScope:"domain"}));if(C.length>0){const S=new Map;C.forEach(j=>{const k=en.getStableDomainCalculatedFieldId(j);S.has(k)||S.set(k,j)}),y.unshift({entityId:lt.CALCULATED_FIELDS_GROUP_ID,entityType:"dataset",entityName:lt.CALCULATED_FIELDS_GROUP_NAME,label:"Calculated Fields",description:"Domain-level calculated metrics and dimensions",qualifiedEntityName:lt.CALCULATED_FIELDS_GROUP_NAME,columns:Array.from(S.values())})}const w=qht(y);return{columnGroups:y,columns:w,isLoading:g,hasError:x,error:b,refetch:async()=>{await Promise.all(p.map(S=>S.refetch()))}}}function Uht(e){return!!e.expression}function Tme(e){return e.fieldScope==="domain"&&e.entityName===ze.CALCULATED_FIELD_ENTITY_MARKER||e.entityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.qualifiedEntityName===lt.CALCULATED_FIELDS_GROUP_NAME}function nf(e){if(!Uht(e))return"none";const t=ze.inspectCalculatedField(e);return t.ownership==="domain"&&Tme(e)?"domain_calculated":t.ownership==="local"&&t.representation!=="physical"&&(ze.hasSyntheticCalculatedFieldOwner(e)||!e.entityName)?"user_calculated":"inline_expression"}function jb(e){return nf(e)!=="none"}function il(e){if(!jb(e))return!1;const t=nf(e);return t==="domain_calculated"||t==="user_calculated"?!0:e.fieldScope==="domain"||e.fieldScope==="dashboard"||e.fieldScope==="sheet"||e.fieldScope==="card"}function Dme(e){return il(e)&&e.fieldScope!=="card"}function Eme(e,t,n){return jb(e)?t==="editor"?!0:t==="filter"?il(e)&&e.fieldScope!=="card":il(e)&&(n==null?void 0:n.isValuePickSafe)!==!1:!1}function T2(e,t){return e.map(n=>({...n,fieldScope:t}))}function Mme(){const{columns:e,columnGroups:t,isLoading:n,hasError:r,error:o,refetch:s}=C4(),i=m.useEditorStore(k=>k.frame.calculatedFields),a=m.useEditorStore(k=>k.card.calculatedFields),c=m.useEditorStore(k=>k.card.config),u=m.useDashboardStore(k=>k.dashboard),d=m.useDashboardStore(k=>k.visualEditPendingDashboardCalculatedFields),f=m.useDashboardStore(k=>k.selectedSheetId),h=m.useDashboardStore(k=>k.selectedFrameId),p=m.useDashboardStore(k=>k.isVisualEditing),g=v.useMemo(()=>e.filter(k=>nf(k)==="domain_calculated"),[e]),x=v.useMemo(()=>e.filter(k=>nf(k)!=="domain_calculated"),[e]),b=v.useMemo(()=>{var _;if(p)return i||[];const k=(_=u==null?void 0:u.sheets)==null?void 0:_.find(T=>T.id===f);return m.getSheetCalculatedFields(k)},[u==null?void 0:u.sheets,i,p,h,f]),y=v.useMemo(()=>{const k=d??(u==null?void 0:u.calculatedFields)??[];return k.length?T2(k,"dashboard"):[]},[u==null?void 0:u.calculatedFields,d]),C=v.useMemo(()=>b.length?T2(b,"sheet"):[],[b]),w=v.useMemo(()=>m.buildCalculatedFieldComparableKeySet([...y,...C]),[y,C]),N=v.useMemo(()=>{const k=(a||[]).filter(E=>il(E)&&E.fieldScope!=="domain"),_=((c==null?void 0:c.metricColumns)||[]).filter(E=>il(E)&&E.fieldScope!=="domain"),T=((c==null?void 0:c.groupByColumns)||[]).filter(E=>il(E)&&E.fieldScope!=="domain"),D=m.dedupeCalculatedFields([...k,..._,...T]).filter(E=>!w.has(m.getCalculatedFieldComparableKey(E)));return T2(D,"card").map(E=>({...E,id:`card-source-${E.id}`}))},[a,c==null?void 0:c.groupByColumns,c==null?void 0:c.metricColumns,w]),S=v.useMemo(()=>[...g,...y,...C,...N,...x],[N,x,y,g,C]),j=v.useMemo(()=>t.filter(k=>k.entityId!==lt.CALCULATED_FIELDS_GROUP_ID),[t]);return{columns:e,columnGroups:j,rawColumnGroups:t,columnFields:x,domainCalculatedFields:g,dashboardCalculatedFields:y,sheetCalculatedFields:C,cardCalculatedFields:N,scopedFields:S,isLoading:n,hasError:r,error:o,refetch:s}}function Kht(e){const t="expression"in e&&e.expression||"",n=e.qualifiedEntityName||e.entityName||"",r=e.fieldScope||"unscoped",o=e.qualifiedFieldName||e.name;return t?["calculated",r,e.role||"field",n,o,t].join("::"):["calculated",r,e.role||"field",n,m.normalizeCalculatedFieldId(e.id)||o].join("::")}function Wht(e){return["physical",e.fieldScope||"physical",e.role||"field",e.qualifiedEntityName||"",e.qualifiedFieldName||e.name,e.name].join("::")}function Up(e){const t=new Map;return e.forEach(n=>{const r=jb(n)?Kht(n):Wht(n);t.has(r)||t.set(r,n)}),Array.from(t.values())}function S4(e){return!ze.isCalculatedMetric(e)}function D2(e,t){return Up(e.filter(n=>Eme(n,t,{isValuePickSafe:S4(n)})))}function Ght(e){return!jb(e)||Eme(e,"inline-filter",{isValuePickSafe:S4(e)})}function Yht(e){return!jb(e)||Dme(e)}function N4(){const e=Mme(),t=v.useMemo(()=>Up(e.scopedFields),[e.scopedFields]),n=v.useMemo(()=>Up([...e.columns,...e.dashboardCalculatedFields,...e.sheetCalculatedFields]),[e.columns,e.dashboardCalculatedFields,e.sheetCalculatedFields]),r=v.useMemo(()=>Up(n.filter(Yht)),[n]),o=v.useMemo(()=>D2(t,"editor"),[t]),s=v.useMemo(()=>D2(n.filter(Dme),"filter"),[n]),i=v.useMemo(()=>Up(t.filter(S4)),[t]),a=v.useMemo(()=>Up(i.filter(Ght)),[i]),c=v.useMemo(()=>D2(a,"inline-filter"),[a]);return{...e,filterableFields:t,sharedFilterableFields:n,dashboardFilterableFields:r,inlineFilterableFields:a,scopedCalculatedFields:o,sharedCalculatedFields:s,inlineCalculatedFields:c,valuePickFilterableFields:i}}function Rme(e){var i,a;const{scopedFields:t}=N4(),n=e==null?void 0:e.type,r=e==null?void 0:e.dataSource,o=(a=(i=e==null?void 0:e.config)==null?void 0:i.matrix)==null?void 0:a.spec.source;return{catalog:v.useMemo(()=>n==="matrixTable"?wd({dataSource:r,config:o?{matrix:{spec:{source:o}}}:void 0},t):[],[n,r,o,t])}}function Zht(e){const t=n=>{if(!n||typeof n!="object")return!1;const r=n;return Array.isArray(r.cards)};if(!e)return null;if(typeof e=="string")try{const n=JSON.parse(e);return t(n)?n:null}catch{return null}return t(e)?e:null}function Rk(e){return Array.isArray(e)?e.map(t=>Rk(t)):e&&typeof e=="object"?Object.entries(e).filter(([,t])=>t!==void 0).sort(([t],[n])=>t.localeCompare(n)).reduce((t,[n,r])=>(t[n]=Rk(r),t),{}):e}function E2(e,t){return JSON.stringify(Rk(e))===JSON.stringify(Rk(t))}function Xht(){var W,ne,Z,K,X,J,re,te,Q;const{open:e,frameId:t,cardId:n,closePopover:r,anchorPosition:o}=xL(),{authToken:s,tokenProps:i}=Mt(),a=Hr(),{updateCurrentDashboardCard:c,updateFrameCard:u}=m.useDashboardActions(),{setCard:d}=m.useEditorActions(),f=m.useDashboardStore(se=>se.dashboard),h=((W=f==null?void 0:f.sheets)==null?void 0:W.flatMap(se=>se.frames||[]).find(se=>(se==null?void 0:se.id)===t))||null,p=h&&n?h.cards.find(se=>se.id===n):null,g=!!(h!=null&&h.visualId&&p),x=bI((h==null?void 0:h.visualId)||"",{enabled:e&&g&&!!(s!=null&&s.accessToken)&&!!(i!=null&&i.apiServiceUrl)}),b=((ne=x.data)==null?void 0:ne.frameObject)||((K=(Z=x.data)==null?void 0:Z.visual)==null?void 0:K.frameObject),y=v.useMemo(()=>Zht(b),[b]),C=((X=x.data)==null?void 0:X.lastModified)||((re=(J=x.data)==null?void 0:J.visual)==null?void 0:re.lastModified),w=v.useMemo(()=>{if(!p||!h||!y)return null;const se=p.linkedSourceCardId&&y.cards.find(fe=>fe.id===p.linkedSourceCardId);if(se)return se;const oe=h.cards.findIndex(fe=>fe.id===p.id);return oe>=0&&y.cards[oe]||null},[p,h,y]),N=v.useMemo(()=>{const se=new Map;return!h||!y||h.cards.forEach((oe,fe)=>{var xe;const pe=oe.linkedSourceCardId||((xe=y.cards[fe])==null?void 0:xe.id);pe&&se.set(pe,oe.id)}),se},[h,y]),S=v.useMemo(()=>{var oe;if(!w)return[];const se=m.ensureInteractionIds((oe=w.interactionConfig)==null?void 0:oe.interactions);return m.remapClickFilterTargetsToInstance(se,N)},[w,N]),j=v.useMemo(()=>p?m.applyLinkedTargetOverrides(S,p.linkedInteractionTargetOverrides):[],[p,S]),k=g?w:p,_=g&&!!b&&!y&&!x.isFetching;v.useEffect(()=>{if(!e)return;const se=g&&w||p;se&&d(se)},[e,g,w,p,d]);const{columns:T}=C4(),{catalog:I}=Rme(k??void 0),D=T,{metrics:E,rows:R,columns:F}=m.getAuthoredCardFields(k,I),M=[...R,...F],[O,z]=v.useState(((te=k==null?void 0:k.interactionConfig)==null?void 0:te.drillHierarchies)||[]),[L,V]=v.useState(((Q=k==null?void 0:k.interactionConfig)==null?void 0:Q.allowedDrillTargets)||[]),[A,B]=v.useState([]),[$,P]=v.useState(!1),U=v.useRef(null),H=v.useMemo(()=>`${e}-${t}-${n}-${g?(w==null?void 0:w.id)||"loading":(p==null?void 0:p.id)||"none"}`,[e,t,n,g,w==null?void 0:w.id,p==null?void 0:p.id]);v.useEffect(()=>{e||(U.current=null)},[e]),v.useEffect(()=>{var se,oe,fe;!e||!k||g&&!w||U.current!==H&&(z(((se=k.interactionConfig)==null?void 0:se.drillHierarchies)||[]),V(((oe=k.interactionConfig)==null?void 0:oe.allowedDrillTargets)||[]),B(g?j:m.ensureInteractionIds((fe=k.interactionConfig)==null?void 0:fe.interactions)),U.current=H)},[e,k,H,g,w,j]);const G=async()=>{var se,oe,fe,pe,xe;if(p){P(!0);try{const Ie=m.ensureInteractionIds(m.normalizeInteractionsForSave(A));if(!g||!(h!=null&&h.visualId)||!y||!w){const ue={...p,interactionConfig:{...p.interactionConfig,drillHierarchies:O,allowedDrillTargets:L,interactions:Ie}},de=(oe=(se=f==null?void 0:f.sheets)==null?void 0:se.find(Te=>(Te.frames||[]).some(we=>we.id===(h==null?void 0:h.id))))==null?void 0:oe.id;de&&(h!=null&&h.id)&&u?u(de,h.id,ue):c(ue),d(ue),r();return}const be=m.ensureInteractionIds((fe=w.interactionConfig)==null?void 0:fe.interactions),ge=m.stripClickFilterTargetsForLibrarySave(Ie,be),ee=((pe=w.interactionConfig)==null?void 0:pe.drillHierarchies)||[],ce=((xe=w.interactionConfig)==null?void 0:xe.allowedDrillTargets)||[],ae=!E2(O,ee)||!E2(L,ce)||!E2(ge,be),me={...w,interactionConfig:{...w.interactionConfig,drillHierarchies:O,allowedDrillTargets:L,interactions:ge}},ve={...y,cards:y.cards.map(ue=>ue.id===w.id?me:ue)};if(ae){if(!(i!=null&&i.apiServiceUrl)||!(s!=null&&s.accessToken))throw new Error("Missing authentication context for visual update");const ue=await fetch(`${i.apiServiceUrl}/management/v1/visuals/${h.visualId}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${(s==null?void 0:s.accessToken)||""}`},body:JSON.stringify({frameObject:ve,expectedLastModified:C})});if(!ue.ok){const Te=await ue.json().catch(()=>({})),we=new Error((Te==null?void 0:Te.error)||"Failed to update visual");throw we.status=ue.status,we}const de=await ue.json();a.setQueryData(["resource-by-id","visual",h.visualId],de)}const _e=m.remapClickFilterTargetsToInstance(m.ensureInteractionIds(ge),N),De=_e.filter(ue=>ue.id).map(ue=>ue.id),Ue=m.pruneLinkedTargetOverrides(m.buildLinkedTargetOverrides(Ie,_e),De),Ne=m.applyLinkedTargetOverrides(_e,Ue),Oe={...p,linkedSourceCardId:p.linkedSourceCardId||w.id,linkedInteractionTargetOverrides:Ue,interactionConfig:{...p.interactionConfig,drillHierarchies:O,allowedDrillTargets:L,interactions:Ne}},ye=ue=>{const de=new Map;return ue.cards.forEach((Te,we)=>{var Ke;const Ee=Te.linkedSourceCardId||((Ke=y.cards[we])==null?void 0:Ke.id);Ee&&de.set(Ee,Te.id)}),de},Be=ue=>{const de=ue.cards.find(we=>we.linkedSourceCardId===w.id);if(de)return de;const Te=y.cards.findIndex(we=>we.id===w.id);return Te>=0&&ue.cards[Te]||null},he=[];if((f.sheets||[]).forEach(ue=>{(ue.frames||[]).forEach(de=>{if(de.visualId!==h.visualId)return;const Te=Be(de);if(!Te)return;const we=ye(de),Ee=m.remapClickFilterTargetsToInstance(m.ensureInteractionIds(ge),we),Ke=Ee.filter(We=>We.id).map(We=>We.id),He=de.id===h.id&&Te.id===p.id?Ue:Te.linkedInteractionTargetOverrides,qe=m.pruneLinkedTargetOverrides(He,Ke),Je=m.applyLinkedTargetOverrides(Ee,qe);he.push({sheetId:ue.id,frameId:de.id,isCurrentCard:de.id===h.id&&Te.id===p.id,card:{...Te,linkedSourceCardId:Te.linkedSourceCardId||w.id,linkedInteractionTargetOverrides:qe,interactionConfig:{...Te.interactionConfig,drillHierarchies:O,allowedDrillTargets:L,interactions:Je}}})})}),he.length>0&&u){he.forEach(de=>{u(de.sheetId,de.frameId,de.card)});const ue=he.find(de=>de.isCurrentCard);ue||c(Oe),d((ue==null?void 0:ue.card)||Oe)}else c(Oe),d(Oe);r()}catch(Ie){Ie.status===409?(m.ue.error("This saved visual was updated by another editor. Refresh and retry."),U.current=null,await x.refetch()):m.ue.error(Ie.message||"Failed to save interactions")}finally{P(!1)}}},q=()=>{U.current=null,r()};if(!e||!t||!n||!p||!o)return null;const Y={position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`};return l.jsxs(m.Popover,{modal:!1,open:e,onOpenChange:se=>!se&&r(),children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx("div",{style:Y,className:"pointer-events-none invisible","aria-hidden":"true"})}),l.jsxs(m.PopoverContent,{onEscapeKeyDown:se=>se.preventDefault(),className:"mt-5 flex max-h-[70vh] w-[600px] max-w-4xl flex-col overflow-hidden p-0",align:"start",side:"right",sideOffset:20,children:[l.jsx(m.Arrow2,{className:"fill-border",width:12,height:8}),l.jsxs("div",{className:"flex flex-col border-b border-border px-5 pb-3.5 pt-4",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("h2",{className:"text-[15px] font-semibold tracking-tight",children:"Configure interactions"}),A.length>0&&l.jsx("span",{className:"text-[11px] tabular-nums text-muted-foreground/70",children:A.length})]}),l.jsxs("p",{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:["Set up drill behaviors for ",(p==null?void 0:p.title)||"this chart"]}),g&&l.jsx("p",{className:"mt-2 text-[12px] leading-[1.5] text-muted-foreground",children:"Logic is owned by the saved visual. Filter target routing is saved per dashboard instance."})]}),l.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:l.jsx("div",{className:"space-y-6 px-5 py-4",children:g&&!w?l.jsx("p",{className:"text-[13px] text-muted-foreground",children:x.isFetching?"Loading saved visual interaction config...":_?"Unable to load interaction settings for this saved visual. Please refresh or relink the visual.":"Unable to map this dashboard card to its source card in the saved visual. Re-link the visual to continue."}):l.jsx("div",{children:l.jsx("div",{className:"grid grid-cols-1 gap-4",children:l.jsx(zht,{interactions:A,metrics:E,attributes:M,availableFields:D,card:{...k||p,interactionConfig:{...(k==null?void 0:k.interactionConfig)||p.interactionConfig,drillHierarchies:O}},onUpdateHierarchies:z,onChange:se=>B(se)})})})})}),l.jsxs("div",{className:"flex justify-end gap-1.5 border-t border-border px-5 py-3",children:[l.jsx(m.Button,{size:"xs",variant:"outline",onClick:q,children:"Cancel"}),l.jsx(m.Button,{size:"xs",onClick:G,disabled:$||g&&!w,children:$?"Saving…":g?"Save to library":"Save"})]})]})]})}function nO(e,t){return UB.serializeLayoutsForDirtyCheck(e)!==UB.serializeLayoutsForDirtyCheck(t)}function Qht(e,t){return t&&nO(e,t)?t:null}function Jht(e){const{tokenProps:t,authToken:n}=Mt(),r=t==null?void 0:t.apiServiceUrl;return Yn({queryKey:["joinability-map",e],queryFn:async()=>{if(!e||!(n!=null&&n.accessToken))return null;const o=`${r}/v1/domains/${e}/joinability`;return m.getRequest(o,n.accessToken)},enabled:!!e&&!!(n!=null&&n.accessToken)&&!!r,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:o=>Math.min(1e3*2**o,3e4)})}function emt(e){var a;const{card:t,joinabilityData:n,autoJoinMetadata:r,extraDatasetLabels:o}=e,s=w4(t==null?void 0:t.dataSource),i={...o||{}};return((n==null?void 0:n.datasets)||[]).forEach(c=>{c.label&&(i[c.name]=c.label)}),{semanticDomainId:s,hasSemanticDomain:!!s,joinabilityMap:(n==null?void 0:n.joinabilityMap)||null,datasetAliases:n==null?void 0:n.datasets,datasetLabels:i,joinPlan:t?lt.getAuthoredCardJoinPlan(t):void 0,autoJoinMetadata:r,dataSourceEntities:(a=t==null?void 0:t.dataSource)==null?void 0:a.selectedEntities}}function j4(e,t){const n=m.useEditorStore(c=>c.card),r=e??n,o=w4(r==null?void 0:r.dataSource),{data:s}=Jht(o),{autoJoinMetadata:i}=Ax(r),a=t==null?void 0:t.extraDatasetLabels;return v.useMemo(()=>emt({card:r,joinabilityData:s,autoJoinMetadata:i,extraDatasetLabels:a}),[r,s,i,a])}function Ame(e,t,n){if(t==="source")return{isValid:!0};const r=m.getDataType(e.dataType);if(n==="detailTable"&&t!=="detailColumns"&&t!=="sortBy")return{isValid:!1,reason:"Detail tables only accept columns"};if(n==="kpi"){if(t==="groupBy"&&r!=="date")return{isValid:!1,reason:"KPI Trend By only accepts date fields"};if(t==="metrics"&&r==="date")return{isValid:!1,reason:"KPI metrics cannot be date fields"}}return{isValid:!0}}function Fme(e,t,n,r,o){if(e!=="kpi"||o.length<3)return;const s=(t==null?void 0:t.groupByColumns)&&t.groupByColumns.length>0,i=o.some(a=>{var c;return((c=a.comparison)==null?void 0:c.mode)==="explicit"});!s&&!i||n(r,{groupByColumns:[],metricColumns:o.map(a=>({...a,comparison:void 0}))})}function tmt(e,t){return(e||[]).map(n=>({...n,id:t(n),label:n.label!==void 0?n.label:n.name}))}const nmt=new Set(["COUNT","DISTINCT"]),rmt=new Set(["running_total","moving_average","previous_period_delta"]);function omt(e){return m.getDataType(e.dataType||"")==="number"?!0:e.aggregate?nmt.has(e.aggregate.toUpperCase()):!1}function smt(e,t){var r,o;return!!((o=(r=e.parameters)==null?void 0:r.windowTransform)==null?void 0:o.function)}function k4(e,t){var n,r;return e==="aggregateTable"&&((((n=t.rowAggregates)==null?void 0:n.length)??0)>0||(((r=t.columnAggregates)==null?void 0:r.length)??0)>0)}function Pme({cardType:e,cardConfig:t,metric:n,transformMode:r}){var i,a,c;if(e==="detailTable"||e==="kpi")return{supported:!1,reason:"Metric transforms are not supported for this card type."};if((((i=t.groupByColumns)==null?void 0:i.length)??0)===0)return{supported:!1,reason:"Metric transforms require at least one grouped dimension."};if(!omt(n))return{supported:!1,reason:"Metric transforms are only available for numeric metrics."};const o=(((a=t.pivotByColumns)==null?void 0:a.length)??0)>0,s=e==="pivotTable"||k4(e,t);return o&&!s?{supported:!1,reason:"Metric transforms with pivot dimensions are only supported for pivotTable and subtotal-enabled aggregateTable in V1."}:rmt.has(r)&&(((c=t.groupByColumns)==null?void 0:c.length)??0)===0?{supported:!1,reason:"This transform requires grouped dimensions for ordering."}:{supported:!0}}function imt(e){return e.find(t=>m.getDataType(t.dataType||"")==="date")}function amt(e){return e}function Iv({cardType:e,cardConfig:t,orderByFieldId:n}){const r=(t.groupByColumns||[]).filter(s=>s.id&&s.id!==n).map(s=>s.id),o=[];if(e==="pivotTable"||k4(e,t))for(const s of t.pivotByColumns||[])s.id&&o.push(s.id);return Array.from(new Set([...r,...o]))}function lmt({transformMode:e,cardType:t,cardConfig:n,fallbackOrderByFieldId:r}){var i;const o=r||((i=imt(n.groupByColumns||[]))==null?void 0:i.id),s=Iv({cardType:t,cardConfig:n,orderByFieldId:o});return e==="moving_average"?{function:"moving_average",...o?{orderBy:{fieldId:o,direction:"asc"}}:{},partitionByFieldIds:s,movingAverage:{windowSize:7,minPeriods:1}}:e==="previous_period_delta"?{function:"previous_period_delta",...o?{orderBy:{fieldId:o,direction:"asc"}}:{},partitionByFieldIds:s,previousPeriodDelta:{mode:"absolute"}}:e==="percent_of_total"?{function:"percent_of_total",percentOfTotal:{scope:"grand_total",output:"percent"},partitionByFieldIds:[]}:{function:"running_total",...o?{orderBy:{fieldId:o,direction:"asc"}}:{},partitionByFieldIds:s,frame:"unbounded_preceding"}}const cmt=new Set(["table","aggregateTable","pivotTable","detailTable"]);function umt(e){return e.alias||e.label||e.name}function Ome(e,t,n){var a,c,u;if(!e)return null;const r=Lt.fromSemanticFormat(t.format);if(!r)return null;const o=n||{};let s=o,i=!1;if(cmt.has(e.type)){const d=m.toColumnNumberFormat(r),f=umt(t);if(d&&!((c=(a=o.tablePrefs)==null?void 0:a.columnSettingsMap)==null?void 0:c[f])){const p=ko();s={...s,tablePrefs:{...s.tablePrefs||{},columnSettingsMap:{...((u=s.tablePrefs)==null?void 0:u.columnSettingsMap)||{},[f]:{...p,type:"number",textAlign:"right",numberFormat:{...p.numberFormat,...d}}}}},i=!0}if(!o.formatNumber){const h=m.toLegacyFormatNumber(r);h&&(s={...s,formatNumber:{decimalPlaces:h.decimalPlaces,minimumFractionDigits:h.minimumFractionDigits,maximumFractionDigits:h.maximumFractionDigits,currency:h.currency,locale:h.locale,prefix:h.prefix,suffix:h.suffix,useGrouping:h.useGrouping,percentValueMode:h.percentValueMode,enabled:!0}},i=!0)}}return i?s:null}const dmt=[];function g1({card:e,notices:t}){m.useEditorStore.getState().actions.updateCard(e.id,e),t.length&&m.ue.info("Matrix configuration updated",{description:[...new Set(t.map(n=>n.message))].join(" ")})}const Lme=(e,t=dmt)=>{var J,re;const n=e==null?void 0:e.type,r=e==null?void 0:e.dataSource,o=(re=(J=e==null?void 0:e.config)==null?void 0:J.matrix)==null?void 0:re.spec.source,s=v.useMemo(()=>n==="matrixTable"?wd({dataSource:r,config:o?{matrix:{spec:{source:o}}}:void 0},t):[],[n,r,o,t]),i=j4(e),{updateCardConfig:a,updateGroupByColumn:c,updateMetricColumn:u,updatePivotByColumn:d,updateSortByColumn:f,removeGroupByColumn:h,removeMetricColumn:p,removePivotByColumn:g,removeSortByColumn:x,setCardPreferences:b}=m.useEditorActions(),y=m.useEditorStore(te=>te.card.type),C=e==null?void 0:e.id,w=v.useCallback((te,Q)=>{if((e==null?void 0:e.type)!=="matrixTable")return!1;const se=$Be(e,t,te,Q);return se.card!==e&&g1(se),!0},[e,t]),N=v.useCallback(te=>{if((e==null?void 0:e.type)!=="matrixTable")return!1;try{const Q=t.length||te.from!=="source"?s:wd(e,[te.field]);if(te.from==="source"){const oe=["groupBy","pivotBy","metrics"].flatMap(pe=>lt.matrixEditorFields(e,pe,Q)),fe=aF(te.field,oe,i);if(!fe.isValid)return fe.showError&&lF(fe.fieldState),!0}const se=OBe(e,Q,te);g1(se)}catch(Q){m.ue.error(Q instanceof Error?Q.message:"Cannot move this field.")}return!0},[e,s,t,i]),S=v.useCallback(()=>{var te;if(e){if(e.type==="matrixTable"){(te=e.config)!=null&&te.matrix&&g1(pm(e,e.config.matrix,{kind:"structure",rows:[],columns:[],measures:[]},s));return}a(e.id,{groupByColumns:[],pivotByColumns:[],metricColumns:[],sortByColumns:[],detailColumns:[]})}},[e,s,a]),j=(te,Q)=>m.resolveShelfFieldId(te,Q),k=v.useCallback(te=>{if((e==null?void 0:e.type)==="matrixTable")return lt.matrixEditorFields(e,te,s);if(!(e!=null&&e.config))return[];switch(te){case"groupBy":return(e.config.groupByColumns||[]).map(Q=>({...Q,id:j(Q,"groupBy"),label:Q.label!==void 0?Q.label:Q.name}));case"metrics":return(e.config.metricColumns||[]).map(Q=>({...Q,id:j(Q,"metrics"),label:Q.label!==void 0?Q.label:Q.name}));case"pivotBy":return(e.config.pivotByColumns||[]).map(Q=>({...Q,id:j(Q,"pivotBy"),label:Q.label!==void 0?Q.label:Q.name}));case"sortBy":return(e.config.sortByColumns||[]).map(Q=>({...Q,id:j(Q,"sortBy"),label:Q.label!==void 0?Q.label:Q.name}));case"detailColumns":return tmt(e.config.detailColumns,Q=>j(Q,"detailColumns"));case"source":return[];default:return[]}},[e,s]),_=v.useCallback((te,Q)=>{if(C)switch(te){case"groupBy":{a(C,{groupByColumns:Q});break}case"metrics":{a(C,{metricColumns:Q});break}case"pivotBy":{a(C,{pivotByColumns:Q});break}case"sortBy":{a(C,{sortByColumns:Q});break}case"detailColumns":{a(C,{detailColumns:Q});break}}},[C,a]),T=v.useCallback((te,Q,se)=>{if(!C)return;const oe=k(te),fe=oe[Q];if(fe)switch(te){case"groupBy":c(C,fe.id,{label:se,labelOrigin:"override"});break;case"metrics":u(C,fe.id,{label:se,labelOrigin:"override"});break;case"pivotBy":d(C,fe.id,{label:se,labelOrigin:"override"});break;case"sortBy":f(C,fe.id,{label:se,labelOrigin:"override"});break;case"detailColumns":{const pe=oe.map((xe,Ie)=>Ie===Q?{...xe,label:se,labelOrigin:"override"}:xe);a(C,{detailColumns:pe});break}}},[C,k,c,u,d,f,a]),I=v.useCallback((te,Q)=>{if(!C)return;const oe=k("metrics")[te];oe&&u(C,oe.id,{aggregate:Q,aggregateOrigin:"explicit",...oe.labelOrigin!=="override"?{label:Ioe(oe.name,Q),labelOrigin:"semantic"}:{}})},[C,k,u]),D=v.useCallback((te,Q,se)=>{if(!C)return;const oe=k("detailColumns");if(!oe[te])return;const pe={dateFormat:Q,customFormat:Q==="custom"&&se?se:void 0,formatOrigin:"override"},xe=oe.map((Ie,be)=>be===te?{...Ie,...pe}:Ie);a(C,{detailColumns:xe})},[C,k,a]),E=v.useCallback((te,Q,se)=>{if(!C)return;const oe=k(te),fe=oe[Q];if(!fe)return;if(te==="groupBy"){c(C,fe.id,{format:se,formatOrigin:"override"});return}const pe=oe.map((xe,Ie)=>Ie===Q?{...xe,format:se,formatOrigin:"override"}:xe);a(C,{detailColumns:pe})},[C,k,a,c]),R=v.useCallback((te,Q)=>{if(!C)return;const se=k("groupBy")[te];if(!se)return;const oe=m.readTemporalBucketAuthoringState({fieldId:se.id,dataType:se.dataType,granularity:se.granularity,format:se.format,dateFormat:se.dateFormat,customFormat:se.customFormat,semanticTemporalPresentation:se.semanticTemporalPresentation});oe.ok&&c(C,se.id,{granularity:oe.granularity,format:Q,formatOrigin:"override",dateFormat:void 0,customFormat:void 0})},[C,k,c]),F=v.useCallback((te,Q)=>{if(!C)return;const oe=k("groupBy")[te];if(!oe)return;const fe=Q,pe=m.readTemporalBucketAuthoringSelection({fieldId:oe.id,dataType:oe.dataType,granularity:fe,format:oe.format,dateFormat:oe.dateFormat,customFormat:oe.customFormat,semanticTemporalPresentation:oe.semanticTemporalPresentation}).format;c(C,oe.id,{granularity:fe,format:lo.reconcileTemporalBucketAuthoringFormat(pe,fe),dateFormat:void 0,customFormat:void 0})},[C,k,c]),M=v.useCallback((te,Q)=>{if(!C)return;const oe=k("metrics")[te];oe&&u(C,oe.id,{aliasTemplate:Q})},[C,k,u]),O=v.useCallback((te,Q)=>{if(!C)return;const oe=k("pivotBy")[te];oe&&d(C,oe.id,{memberOrder:Q})},[C,k,d]),z=v.useCallback((te,Q)=>{if(console.log("handleValueAliasesChange",te,Q),!C)return;console.log("handleValueAliasesChange",te,Q);const oe=k("metrics")[te];oe&&(console.log("handleValueAliasesChange",Q),u(C,oe.id,{valueAliases:Q}))},[C,k,u]),L=v.useCallback((te,Q)=>{var fe,pe;if(!C)return;const oe=k("metrics")[te];oe&&(u(C,oe.id,{format:Q,formatOrigin:"override"}),y==="kpi"&&((pe=(fe=e==null?void 0:e.preferences)==null?void 0:fe.kpiVisualOptions)!=null&&pe.formatOptions)&&b({...e.preferences,kpiVisualOptions:{...e.preferences.kpiVisualOptions,formatOptions:void 0}}))},[e,C,y,k,b,u]),V=v.useCallback((te,Q)=>{var xe,Ie;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=Q!=="inherit"&&Q!=="off"&&((xe=oe.parameters)==null?void 0:xe.windowTransform),pe=Q==="inherit"?void 0:Q==="off"?{mode:"off"}:Q==="target"?{mode:"explicit",spec:{kind:"target",targetValue:((Ie=oe.comparison)==null?void 0:Ie.mode)==="explicit"&&oe.comparison.spec.kind==="target"?oe.comparison.spec.targetValue:0}}:{mode:"explicit",spec:{kind:Q}};u(C,oe.id,{comparison:pe,...fe?{parameters:{...oe.parameters||{},windowTransform:void 0}}:{}})},[C,k,u]),A=v.useCallback((te,Q)=>{if(!C)return;const se=k("metrics")[te];se&&u(C,se.id,{comparison:{mode:"explicit",spec:Q}})},[C,k,u]),B=v.useCallback((te,Q)=>{if(!C)return;const se=k("metrics")[te];!se||se.semanticComparisonPolarity||u(C,se.id,{comparisonPolarity:Q})},[C,k,u]),$=v.useCallback((te,Q)=>{var ge,ee,ce;if(!C||!(e!=null&&e.config))return;const oe=k("metrics")[te];if(!oe)return;if(Q==="none"){u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:void 0}});return}const fe=Pme({cardType:y,cardConfig:e.config,metric:oe,transformMode:Q});if(!fe.supported){m.ue.error(fe.reason||"Metric transform is not supported here.");return}const pe=new Set((e.config.groupByColumns||[]).map(ae=>ae.id)),xe=(ce=(ee=(ge=oe.parameters)==null?void 0:ge.windowTransform)==null?void 0:ee.orderBy)==null?void 0:ce.fieldId,Ie=xe&&pe.has(xe)?xe:void 0,be=lmt({transformMode:Q,cardType:y,cardConfig:e.config,fallbackOrderByFieldId:Ie});u(C,oe.id,{comparison:void 0,parameters:{...oe.parameters||{},windowTransform:be}})},[e,C,y,k,u]),P=v.useCallback((te,Q)=>{var be,ge;if(!C||!(e!=null&&e.config))return;const oe=k("metrics")[te];if(!oe)return;const fe=(be=oe.parameters)==null?void 0:be.windowTransform;if(!fe||!["running_total","moving_average","previous_period_delta"].includes(fe.function))return;const pe=Iv({cardType:y,cardConfig:e.config,orderByFieldId:Q}),Ie=(fe.partitionByFieldIds||pe).filter(ee=>ee!==Q);u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,orderBy:{fieldId:Q,direction:((ge=fe.orderBy)==null?void 0:ge.direction)||"asc"},partitionByFieldIds:Ie}}})},[e,C,y,k,u]),U=v.useCallback((te,Q)=>{var pe;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=(pe=oe.parameters)==null?void 0:pe.windowTransform;!fe||!["running_total","moving_average","previous_period_delta"].includes(fe.function)||u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,orderBy:fe.orderBy?{...fe.orderBy,direction:Q}:fe.orderBy}}})},[C,k,u]),H=v.useCallback((te,Q)=>{var Ie,be;if(!C||!(e!=null&&e.config))return;const oe=k("metrics")[te];if(!oe)return;const fe=(Ie=oe.parameters)==null?void 0:Ie.windowTransform;if(!fe)return;const pe=Iv({cardType:y,cardConfig:e.config,orderByFieldId:(be=fe.orderBy)==null?void 0:be.fieldId}),xe=new Set(fe.partitionByFieldIds||pe);xe.has(Q)?xe.delete(Q):xe.add(Q),u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,partitionByFieldIds:Array.from(xe)}}})},[e,C,y,k,u]),G=v.useCallback((te,Q)=>{var be,ge;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=(be=oe.parameters)==null?void 0:be.windowTransform;if(!fe||fe.function!=="moving_average")return;const pe=Math.max(1,Math.floor(Q||1)),xe=((ge=fe.movingAverage)==null?void 0:ge.minPeriods)||1,Ie=Math.min(xe,pe);u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,movingAverage:{windowSize:pe,minPeriods:Ie}}}})},[C,k,u]),q=v.useCallback((te,Q)=>{var Ie,be;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=(Ie=oe.parameters)==null?void 0:Ie.windowTransform;if(!fe||fe.function!=="moving_average")return;const pe=((be=fe.movingAverage)==null?void 0:be.windowSize)||7,xe=Math.max(1,Math.min(Math.floor(Q||1),pe));u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,movingAverage:{windowSize:pe,minPeriods:xe}}}})},[C,k,u]),Y=v.useCallback((te,Q)=>{var pe;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=(pe=oe.parameters)==null?void 0:pe.windowTransform;!fe||fe.function!=="previous_period_delta"||u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,previousPeriodDelta:{mode:Q}}}})},[C,k,u]),W=v.useCallback((te,Q)=>{var xe;if(!C||!(e!=null&&e.config))return;const oe=k("metrics")[te];if(!oe)return;const fe=(xe=oe.parameters)==null?void 0:xe.windowTransform;if(!fe||fe.function!=="percent_of_total")return;const pe=Q==="grand_total"?[]:(fe.partitionByFieldIds||[]).length>0?fe.partitionByFieldIds||[]:Iv({cardType:y,cardConfig:e.config,orderByFieldId:void 0});u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,partitionByFieldIds:pe,percentOfTotal:{...fe.percentOfTotal||{},scope:Q}}}})},[e,C,y,k,u]),ne=v.useCallback((te,Q)=>{var pe;if(!C)return;const oe=k("metrics")[te];if(!oe)return;const fe=(pe=oe.parameters)==null?void 0:pe.windowTransform;!fe||fe.function!=="percent_of_total"||u(C,oe.id,{parameters:{...oe.parameters||{},windowTransform:{...fe,percentOfTotal:{...fe.percentOfTotal||{},output:Q}}}})},[C,k,u]),Z=v.useCallback((te,Q)=>{if(!C)return;const oe=k("metrics")[te];oe&&u(C,oe.id,{comparison:Q===void 0?{mode:"explicit",spec:{kind:"target",targetValue:0}}:{mode:"explicit",spec:{kind:"target",targetValue:Q}}})},[C,k,u]),K=v.useCallback(async te=>{if(!C)return;const Q=z9(te,[],y);if(Q&&N({field:te,from:"source",to:Q}))return;const se=[...k("groupBy"),...k("pivotBy"),...k("metrics"),...k("sortBy"),...k("detailColumns")],oe=te,fe=aF(oe,se,i);if(!fe.isValid){fe.showError&&lF(fe.fieldState);return}const pe=z9(oe,se,y);if(!pe){m.ue.error("Invalid Field",{description:"This field cannot be added to any container",position:"top-center",duration:3e3});return}const xe=Ame(oe,pe,y);if(!xe.isValid){m.ue.error("Invalid Field Type",{description:xe.reason,position:"top-center",duration:3e3});return}const Ie=k(pe);if(Soe(oe,Ie))return;const be=_oe(oe,pe,Ie);if(be){const ge=[...Ie,be];if(_(pe,ge),pe==="metrics"){const ee=Ome(e,be,e==null?void 0:e.preferences);ee&&b(ee),Fme(y,e==null?void 0:e.config,a,C,ge)}}},[C,e,k,_,i,y,a,b,N]),X=v.useCallback((te,Q)=>{if(!C)return;const oe=k(te)[Q];if(oe){if((e==null?void 0:e.type)==="matrixTable"){try{g1(LBe(e,te,oe.id,s))}catch(fe){m.ue.error(fe instanceof Error?fe.message:"Cannot remove this field.")}return}if(te!=="sortBy"){const fe=k("sortBy"),pe=fe.filter(xe=>!(xe.name===oe.name&&xe.qualifiedEntityName===oe.qualifiedEntityName));pe.length!==fe.length&&a(C,{sortByColumns:pe})}switch(te){case"groupBy":h(C,oe.id);break;case"metrics":p(C,oe.id);break;case"pivotBy":g(C,oe.id);break;case"sortBy":x(C,oe.id);break;case"detailColumns":{a(C,{detailColumns:(k("detailColumns")||[]).filter((fe,pe)=>pe!==Q)});break}}}},[C,k,h,p,g,x,a,e,s]);return{reconcileMatrixCalculation:w,moveField:N,resetFields:S,getFieldsForContainer:k,setFieldsForContainer:_,updateLabel:T,handleAggregationChange:I,handleDetailDateFormatChange:D,handleDimensionFormatChange:E,handleTemporalBucketFormatChange:R,handleGranularityChange:F,handleAliasTemplateChange:M,handlePivotMemberOrderChange:O,handleValueAliasesChange:z,handleMetricFormatChange:L,removeField:X,handleFieldClick:K,handleMetricComparisonChange:V,handleMetricComparisonSpecChange:A,handleMetricComparisonPolarityChange:B,handleMetricWindowTransformChange:$,handleMetricWindowOrderByChange:P,handleMetricWindowDirectionChange:U,handleMetricWindowPartitionToggle:H,handleMetricMovingAverageWindowSizeChange:G,handleMetricMovingAverageMinPeriodsChange:q,handleMetricPreviousPeriodDeltaModeChange:Y,handleMetricPercentOfTotalScopeChange:W,handleMetricPercentOfTotalOutputChange:ne,handleMetricTargetValueChange:Z,cardType:y}};function $me(e){var y;const{tokenProps:t}=Mt(),n=m.useDashboardStore(C=>C.authToken)||e,r=m.useEditorStore(C=>C.selectedConnectionId),o=m.useEditorStore(C=>C.selectedDatabaseName),s=m.useEditorStore(C=>C.selectedDatamodelId),i=m.useEditorStore(C=>C.selectedSchemaName),a=m.useEditorStore(C=>C.selectedTableName),{selectedConnection:c}=La(),u=c==null?void 0:c.type,{data:d,isLoading:f,isFetching:h,isError:p,refetch:g}=Yn({queryKey:["columns",r,o,s,i,a],queryFn:()=>m.getRequest(`${t.apiServiceUrl}/v1/columns`,(n==null?void 0:n.accessToken)||"",{connection_id:r,datamodel_id:s||"",database_name:o,schema_name:i,table_name:a}),enabled:x(u)});function x(C){var k;if(!(n!=null&&n.accessToken))return!1;if(s&&s)return!0;if(!r||!C)return!1;const w=((k=c==null?void 0:c.capabilities)==null?void 0:k.path)||[],N=w.includes("database"),S=w.includes("schema"),j=w.includes("table");return!(N&&(!o||o==="NA")||S&&!i||j&&!a)}return{columns:(y=d==null?void 0:d.columns)==null?void 0:y.map(C=>({...C,data_type:C.data_type.toLowerCase()})),isColumnsLoading:f,isColumnsFetching:h,isColumnsError:p,refetchColumns:g}}function fmt(e){const t=m.useDashboardStore(y=>y.dashboard),n=m.useDashboardStore(y=>{var C;return((C=y.reportContext)==null?void 0:C.calendar)??null}),r=m.useDashboardStore(y=>y.selectedLensId),o=m.useFinalFilterGroupKey(e)||"",s=k_(e),{controlValues:i,queryRelevantConfig:a}=s,c=m.useDashboardStore(y=>y.dashboardInputReferenceTime),u=v.useMemo(()=>m.getDashboardCards(t),[t]),d=v.useMemo(()=>u.length>0?u:[e],[e,u]),f=v.useMemo(()=>Object.fromEntries(d.map(y=>[y.id,y.id===e.id?a:y.config])),[e.id,a,d]),h=Mx(d,{authority:"editor",queryRelevantConfigsByCardId:f}).payload,p=m.resolveCardPrimaryDateField({card:e,cardConfig:a,semanticExecutionPayload:h}),g=(e==null?void 0:e.sql)||"",x=m.getGlobalDateFilterCoverage(t,h),b=n?eL(e,{...s,finalFiltersKey:o},{selectedLensId:r,resolvedPrimaryDateField:p,calendarContext:n,allowGlobalDateMinutePrecision:x.allEligibleTargetsAreDateTime,globalDateComparisonReferenceTime:c}):void 0;return{queryKey:(b==null?void 0:b.status)==="ready"?b.queryKey:[],sql:g,cardFilterValues:(b==null?void 0:b.status)==="ready"?b.compiledFilters.cardFilterValues:[],controlValues:i}}function OT(e,t){var De,Ue,Ne,Oe,ye,Be,he,ue;const{tokenProps:n}=Mt(),r=Hr(),o=Mt().authToken||e,s=m.useEditorStore(de=>de.selectedConnectionId),i=m.useEditorStore(de=>de.card),{queryKey:a}=fmt(i),c=m.useEditorStore(de=>de.selectedDatamodelId),u=m.useEditorStore(de=>de.isDevMode),d=m.useEditorStore(de=>de.selectedDatabaseName),f=m.useEditorStore(de=>de.selectedSchemaName),h=m.useEditorStore(de=>de.selectedTableName),p=m.useEditorStore(de=>de.actions.setSelectedConnectionId),g=m.useEditorStore(de=>de.actions.setSelectedDatamodelId),x=m.useEditorStore(de=>de.actions.setSelectedDatabaseName),b=m.useEditorStore(de=>de.actions.setSelectedSchemaName),y=m.useEditorStore(de=>de.actions.setSelectedTableName);m.useEditorStore(de=>de.actions.setCardSql);const{setQueryConfig:C}=m.useEditorActions();function w(de){var He;if(!s||!de)return!1;const Te=((He=T==null?void 0:T.capabilities)==null?void 0:He.path)||[],we=Te.includes("database"),Ee=Te.includes("schema");return!(!Te.includes("table")||we&&(!d||d==="NA")||Ee&&!f)}function N(de){var Te;return!s||!de?!1:!!((Te=T==null?void 0:T.capabilities)!=null&&Te.path.includes("database"))}const{refetchConnections:S,connectionsData:j,isConnectionsLoading:k,isConnectionsError:_,selectedConnection:T}=La(e),{refetch:I,data:D,isLoading:E,isError:R}=Yn({queryKey:["models",s],queryFn:()=>m.getRequest(`${n.apiServiceUrl}/v1/datamodels`,(o==null?void 0:o.accessToken)||"",{connection_id:s}),enabled:!!(o!=null&&o.accessToken)&&!!s}),F=T==null?void 0:T.type,M=((De=T==null?void 0:T.capabilities)==null?void 0:De.path.includes("schema"))??!1,O=((Ue=T==null?void 0:T.capabilities)==null?void 0:Ue.path.length)===1&&((Ne=T==null?void 0:T.capabilities)==null?void 0:Ne.path[0])==="table",z=O,{data:L,isLoading:V,isFetching:A,isError:B,refetch:$}=Yn({queryKey:["databases",s],queryFn:()=>m.getRequest(`${n.apiServiceUrl}/v1/databases`,(o==null?void 0:o.accessToken)||"",{connection_id:s}),enabled:N(F)}),{data:P,isLoading:U,isFetching:H,isError:G,refetch:q}=Yn({queryKey:["schemas",s,d],queryFn:()=>m.getRequest(`${n.apiServiceUrl}/v1/schemas`,(o==null?void 0:o.accessToken)||"",{connection_id:s,database_name:d}),enabled:!!s&&!!d&&M&&d!=="NA"}),{data:Y,isLoading:W,isFetching:ne,isError:Z,refetch:K}=Yn({queryKey:["tables",s,d,f],queryFn:()=>m.getRequest(`${n.apiServiceUrl}/v1/tables`,(o==null?void 0:o.accessToken)||"",{connection_id:s,database_name:d,schema_name:f}),enabled:w(F)}),{columns:X,isColumnsLoading:J,isColumnsFetching:re,isColumnsError:te,refetchColumns:Q}=$me(e);v.useEffect(()=>{O&&(x(""),b(""),g(""),F==="API"&&y("api"))},[F,y,x,b,g,O]);const se=(T==null?void 0:T.type)==="API"?(Oe=T==null?void 0:T.type)==null?void 0:Oe.toLowerCase():h||"",oe=M&&f||"";function fe(de){y(de),C(void 0),u||(r.setQueryData(a,null),r.removeQueries({queryKey:a,exact:!0}))}function pe(de){b(de),y("")}function xe(de){x(de==="none"?"":de),b(""),y(""),de!=="none"&&de!==""&&g("")}function Ie(de){p(de)}function be(de){g(de==="none"?"":de),de!=="none"&&de!==""&&x("")}L&&((ye=L==null?void 0:L.databases)==null?void 0:ye.length)>0,P&&((Be=P==null?void 0:P.schemas)==null?void 0:Be.length)>0;const ge=j==null?void 0:j.connections.map(de=>({id:de.id,name:de.name,type:de.type})),ee=(he=D==null?void 0:D.datamodels)==null?void 0:he.map(de=>({id:de.id,name:de.name})),ce=L==null?void 0:L.databases.map(de=>({id:de.database_name,name:de.database_name})),ae=P==null?void 0:P.schemas.map(de=>({id:de.schema_name,name:de.schema_name})),me=Y==null?void 0:Y.tables.map(de=>({id:de.table_name,name:de.table_name})),ve=(ue=D==null?void 0:D.datamodels.find(de=>de.id===c))==null?void 0:ue.name,_e=T!=null&&T.capabilities?m.getFormattedTableNameForQuery({schemaName:oe,tableName:se,modelName:ve,databaseName:d||"",capabilities:T.capabilities}):se;return{connectionItems:ge,selectedConnectionId:s,selectedConnection:T,isConnectionsLoading:k,isConnectionsError:_,modelItems:ee,selectedDatamodelId:c,selectedDatamodelName:ve,isModelsLoading:E,isModelsError:R,selectedDatabaseName:d,databaseItems:ce,isDatabasesLoadingOrFetching:V||A,isDatabaseError:B,schemaItems:ae,selectedSchemaName:f,isSchemaLoadingOrFetching:U||H,isSchemaError:G,tableItems:me,selectedTableName:h,isTableLoadingOrFetching:W||ne,isTableError:Z,columns:X,isColumnsLoadingOrFetching:J||re,isColumnsError:te,isNonDbConnection:z,connectionType:F,tableName:se,formattedTableName:_e,schemaName:oe,refetchConnections:S,refetchModels:I,refetchDatabases:$,refetchSchemas:q,refetchTables:K,refetchColumns:Q,handleConnectionChange:Ie,handleDatamodelChange:be,handleDatabaseChange:xe,handleSchemaChange:pe,handleTableChange:fe}}function x1(e){return`${e}-${lt.v4()}`}function LW(e,t){const n=m.toTitleCase(e.replace(/_/g," "));switch(t){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function hmt(e,t){const n=m.toTitleCase(e.replace(/_/g," "));switch(t){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"quarter":return`Quarter of ${n}`;case"year":return`Year of ${n}`;case"hour":return`Hour of ${n}`;case"minute":return`Minute of ${n}`;case"second":return`Second of ${n}`;default:return n}}function I4(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return{tableName:void 0,schemaName:void 0,databaseName:void 0,connectionId:e==null?void 0:e.connectionId,connectionType:e==null?void 0:e.connectionType};const t=e.selectedEntities[0];return{tableName:t==null?void 0:t.name,schemaName:t==null?void 0:t.schema,databaseName:t==null?void 0:t.database,connectionId:e.connectionId,connectionType:e.connectionType}}function zme(e){if(!e||!e.selectedEntities||e.selectedEntities.length===0)return!1;const t=e.selectedEntities[0];return!!(t!=null&&t.name)}function Bme(){const e=m.useEditorStore(k=>k.sqlGen),t=m.useEditorStore(k=>k.isDevMode),n=m.useEditorStore(k=>k.card.dataSource),r=m.useEditorStore(k=>{var _,T;return(T=(_=k.card)==null?void 0:_.queryConfig)==null?void 0:T.metricColumns}),{tableName:o,schemaName:s,databaseName:i}=I4(n),a=zme(n),c=m.useEditorStore(k=>k.selectedDatamodelId),{addColumnToMetricColumns:u,addColumnToGroupBy:d,setCardSql:f,setRunSql:h,setSqlGen:p,setIsShowingVisual:g}=m.useEditorActions(),{modelItems:x,selectedDatamodelName:b}=OT(),{selectedConnection:y}=La(),C=y==null?void 0:y.capabilities,w=k=>({column_name:k.name,data_type:k.dataType,label:k.label,description:k.description});return{handleDevModeFieldClick:k=>{var T;if(!t)return;const _=w(k);if(t&&a&&o&&C){const I=m.createSqlGenConfig(_,e);p(I);const D=(T=x==null?void 0:x.find(R=>R.id===c))==null?void 0:T.name,E=m.getSql(I,s||"",o,D||"",i||"",C,k.qualifiedEntityName);E&&(f(E),h(!0))}else if(!t){if(m.isTextDataType(_.data_type))if(r&&r.length>0){const I={..._,role:"groupby",id:x1(_.column_name),name:_.column_name,type:_.data_type};d(I)}else{const I={..._,role:"metric",id:x1(_.column_name),name:_.column_name,label:LW(_.column_name,"COUNT"),type:_.data_type,aggregate:"COUNT"};u(I)}if(m.isDateDataType(_.data_type)){const I={..._,role:"groupby",id:x1(_.column_name),name:_.column_name,type:_.data_type,label:hmt(_.column_name,"month"),granularity:"month"};d(I)}if(m.isNumberDataType(_.data_type)){const I={..._,role:"metric",id:x1(_.column_name),name:_.column_name,label:LW(_.column_name,"SUM"),type:_.data_type,aggregate:"SUM"};u(I)}}},handleShowSample:()=>{if(!a||!o||!C){console.warn("Cannot generate SQL: missing table metadata or capabilities");return}const k=m.getFormattedTableNameForQuery({schemaName:s||"",tableName:o,modelName:b,databaseName:i||"",capabilities:C});g(!1);const T=(y==null?void 0:y.type)==="MSSQL"?`SELECT top 10 * FROM ${k}`:`SELECT * FROM ${k} LIMIT 10`;f(T),h(!0)},handleShowCount:()=>{if(!a||!o||!C){console.warn("Cannot generate SQL: missing table metadata or capabilities");return}const k=m.getFormattedTableNameForQuery({schemaName:s||"",tableName:o,modelName:b,databaseName:i||"",capabilities:C});f(`SELECT COUNT(*) as count FROM ${k}`),h(!0)},isNumberField:k=>m.isNumberDataType(k.dataType)}}function Vme(e){const t=e.qualifiedFieldName,r=(e.qualifiedEntityName||e.qualifiedFieldName.split(".").slice(0,-1).join(".")).split(".").map(s=>m.fmt(s)).join("."),o=m.fmt(e.name);return{qualifiedColumnName:t,qualifiedTableName:r,formattedColumnName:o}}function mmt(){const e=m.useDashboardStore(c=>c.dashboard.filters)||[],t=m.useDashboardStore(c=>c.selectedSheetId),n=m.useDashboardStore(c=>c.actions.addFilter),r=m.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:o}=m.useDashboardActions(),s=m.useEditorStore(c=>c.card.dataSource),{selectedConnection:i}=La();function a(c,u="sheet"){const{qualifiedColumnName:d,qualifiedTableName:f}=Vme(c);let h;if(u==="sheet"&&t){const p=Ox(e,t);h=p.find(g=>g.fieldMeta&&qg(g,c))||$Te(p.filter(g=>!g.fieldMeta),d,f,t)}else h=e==null?void 0:e.find(p=>qg(p,c)||!p.fieldMeta&&nx(p.column)===nx(d));if(h)o(h.id),r(h.id);else{const p=lt.v4(),g=LO(c),x=$O(s,{connectionId:i==null?void 0:i.id,connectionType:i==null?void 0:i.type},c),b=u==="sheet"&&t?[t]:void 0,y=m.getDataType(c.dataType)==="date"?"between":"in";return n({id:p,location:u,column:d,title:c.label||c.name,dataType:c.dataType,...c.nativeDataType?{nativeDataType:c.nativeDataType}:{},qualifiedTableName:f,connectionId:(i==null?void 0:i.id)||"",operation:y,applyToSheetIds:b,sql:"",fieldMeta:g,semanticContext:x}),p}}return{assignFilter:a}}function pmt({column:e}){const[t,n]=v.useState(!1),r=m.useEditorStore(w=>w.isDevMode),o=m.useEditorStore(w=>w.card.dataSource),{tableName:s,schemaName:i,databaseName:a}=I4(o),c=m.useEditorStore(w=>w.selectedDatamodelId),u=m.useEditorStore(w=>w.sqlGen),{modelItems:d,selectedConnection:f}=OT(),h=f==null?void 0:f.capabilities,p=m.useEditorStore(w=>w.actions.setSqlGen),g=m.useEditorStore(w=>w.actions.setCardSql),x=m.useEditorStore(w=>w.actions.setRunSql),b=zme(o);function y(w,N){var T,I;if(!b||!s){console.warn("Cannot generate SQL: missing table metadata");return}const S=m.createSqlGenConfig(w,u,N),j=(T=d==null?void 0:d.find(D=>D.id===c))==null?void 0:T.name;if(p(S),!h){console.warn("Cannot generate SQL: missing connection capabilities");return}const k=(I=w.qualifiedFieldName)==null?void 0:I.split(".").slice(0,-1).join("."),_=m.getSql(S,i||"",s,j||"",a||"",h,k);_&&(g(_),x(!0)),n(!1)}function C(){return l.jsxs("ul",{className:"text-xs",children:[l.jsx("li",{onClick:()=>y(e,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),l.jsx("li",{onClick:()=>y(e,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),l.jsx("li",{onClick:()=>y(e,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),l.jsx("li",{onClick:()=>y(e,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),l.jsx("li",{onClick:()=>y(e,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return!r||!b?null:l.jsxs(ep,{openDelay:0,open:t,onOpenChange:n,children:[l.jsx(Yd,{asChild:!0,children:l.jsx(Lm,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover/container:visible"})}),l.jsx(wu,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:C()})]})}const $W="bg-emerald-500/90 text-white",gmt="bg-blue-500/90 text-white";function _4(e){var n;const t=(n=e.derivedField)==null?void 0:n.computeStage;return t==="aggregate"?"metric":t==="row"?"dimension":T4(e)?e.role==="metric"?"metric":"dimension":!1}function T4(e){const t=nf(e);return t==="none"?null:t==="inline_expression"?{label:"{}",badgeClassName:$W}:{label:"fx",badgeClassName:e.role==="metric"?$W:gmt}}const LT=[{id:"sum",label:"Sum",symbol:"+",description:"Add two metrics together",template:()=>"({field_0} + {field_1})",insertTemplate:()=>"({a} + {b})",insertHint:"A + B",requiresTwoInputs:!0},{id:"difference",label:"Difference",symbol:"−",description:"Subtract one metric from another",template:()=>"({field_0} - {field_1})",insertTemplate:()=>"({a} - {b})",insertHint:"A − B",requiresTwoInputs:!0},{id:"product",label:"Product",symbol:"×",description:"Multiply two metrics",template:()=>"({field_0} * {field_1})",insertTemplate:()=>"({a} * {b})",insertHint:"A × B",requiresTwoInputs:!0},{id:"ratio",label:"Ratio",symbol:"÷",description:"Divide one metric by another",template:()=>"({field_0} / NULLIF({field_1}, 0))",insertTemplate:()=>"({a} / NULLIF({b}, 0))",insertHint:"A ÷ B (null-safe)",requiresTwoInputs:!0},{id:"change",label:"Change",symbol:"Δ",description:"Calculate percentage change from A to B",template:()=>"(({field_1} - {field_0}) / NULLIF({field_0}, 0))",insertTemplate:()=>"(({b} - {a}) / NULLIF({a}, 0))",insertHint:"% change A → B",requiresTwoInputs:!0},{id:"percentage",label:"Percentage",symbol:"%",description:"Calculate (A / B) × 100",template:()=>"(({field_0} / NULLIF({field_1}, 0)) * 100)",insertTemplate:()=>"(({a} / NULLIF({b}, 0)) * 100)",insertHint:"(A ÷ B) × 100",requiresTwoInputs:!0},{id:"scale",label:"Scale",symbol:"×n",description:"Multiply a metric by a constant factor",template:()=>"({field_0} * {constant})",insertTemplate:()=>"({a} * 1.0)",insertHint:"A × constant",requiresTwoInputs:!1},{id:"custom",label:"Custom Expression",symbol:"{}",description:"Drag fields to create custom expression with tokens",requiresTwoInputs:!1,allowsCustomExpression:!0}],xmt=LT.filter(e=>e.id!=="custom"&&!!e.insertTemplate);let Hme=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");const D4=e=>e.trim().toLowerCase().replace(/\s+/g,"_"),Ak=e=>e!=null&&e.startsWith("card-source-")?e.replace("card-source-",""):e;function qme(e,t){e.forEach(n=>{var i;const r=n.id||n.qualifiedFieldName||n.name;if(r&&t.visited.has(r))return;if(r&&t.visited.add(r),Tme(n)){t.disqualified=!0;return}const o=(i=n.calculatedFormula)==null?void 0:i.inputFields;if(o!=null&&o.length){qme(o,t);return}if(n.expression&&!(nf(n)==="inline_expression"&&il(n)&&n.fieldScope==="domain")){t.disqualified=!0;return}if(!n.entityName||!n.entityId){t.disqualified=!0;return}const s=n.qualifiedEntityName||n.entityId||n.entityName;t.entities.has(s)||t.entities.set(s,{entityName:n.entityName,entityId:n.entityId,qualifiedEntityName:n.qualifiedEntityName})})}function E4(e){const t={entities:new Map,disqualified:!1,visited:new Set};if(qme(e,t),t.disqualified||t.entities.size!==1)return{kind:"multi-entity"};const[n]=Array.from(t.entities.values());return!(n!=null&&n.entityName)||!n.entityId?{kind:"multi-entity"}:{kind:"inline",entityName:n.entityName,entityId:n.entityId,qualifiedEntityName:n.qualifiedEntityName}}function bmt(e){return e.aggregate?e.aggregate:j3(e.dataType)}function ymt(e,t){const n=bmt(t);return n==="DISTINCT"?`COUNT(DISTINCT ${e})`:`${n}(${e})`}function vmt(e,t){return e.replace(/\{field_(\d+)\}/g,(n,r)=>{const o=Number(r),s=t[o];return!s||ze.inspectCalculatedField(s).representation!=="physical"||typeof s.expression=="string"&&Noe(s.expression)?n:ymt(n,s)})}function wmt(e,t,n,r,o,s,i,a,c,u){if(!LT.find(C=>C.id===t))throw new Error(`Unknown operation: ${t}`);let f,h=[],p;{if(!(a!=null&&a.trim()))throw new Error("Custom expression is required");f=a.trim(),h=u||[]}const g={operation:t,inputFields:h,...p!==void 0},x=D4(e),b=E4(h);return{id:i||`calc_${Hme(10)}`,name:x,label:e,alias:x,qualifiedFieldName:x,dataType:"number",role:"metric",expression:f,calculationRepresentation:b.kind==="inline"?"inline-expression":"manual",calculatedFormula:g,entityId:b.kind==="inline"?b.entityId:s,entityName:b.kind==="inline"?b.entityName:ze.CALCULATED_FIELD_ENTITY_MARKER,qualifiedEntityName:b.kind==="inline"?b.qualifiedEntityName:void 0,entityType:b.kind==="inline"?"dataset":"table",description:`Calculated field: ${e}`}}function Cmt(e){var r,o;const t=LT.find(s=>s.id===e.operation);if(!t)return"Unknown operation";if(e.operation==="custom")return"Custom expression";if(e.operation==="scale"){const s=((r=e.inputFields[0])==null?void 0:r.label)||((o=e.inputFields[0])==null?void 0:o.name)||"A",i=e.constant??1;return`${s} × ${i}`}return e.inputFields.map(s=>s.label||s.name).join(` ${t.symbol} `)}function Smt(e){return e==="metric"?"Aggregate":"Per row"}function Nmt(e){return e==="metric"?"Computed after rows are aggregated. Use it as a metric such as a total, ratio, or rate. Aggregate functions are allowed.":"Computed for each row. Use it as a column to group, filter, or aggregate. Aggregate functions such as SUM are not allowed here."}function jmt(e){return e==="inline"?"Single dataset":"Cross-entity"}function Kp(e){switch(e){case"card":return"This card";case"sheet":return"This sheet";case"dashboard":return"This dashboard";case"domain":return"Semantic domain"}}function zW(e){return e.replace(/\s+/g,"")}function kmt(e){var o;const t=e.calculatedFormula;if(!t||t.operation==="custom")return;const n=LT.find(s=>s.id===t.operation),r=(o=n==null?void 0:n.template)==null?void 0:o.call(n);if(r)return t.operation!=="scale"?r:r.replace("{constant}",String(t.constant??1))}function Imt(e){var r;const t=e.expression||"",n=kmt(e);return!n||zW(t)!==zW(n)?t:vmt(t,((r=e.calculatedFormula)==null?void 0:r.inputFields)||[])}function _mt(e){const t=new Set,n=/\{field_(\d+)\}/g;let r=n.exec(e);for(;r;)t.add(Number(r[1])),r=n.exec(e);return[...t].sort((o,s)=>o-s)}function Tmt(e){var s;const t=e.expression||"",n=_mt(t);if(n.length===0)return{readOnly:!1};const r=((s=e.calculatedFormula)==null?void 0:s.inputFields)||[];return n[n.length-1]<r.length?{readOnly:!1}:{readOnly:!0,reason:"This legacy metric uses saved field tokens but is missing the input metadata needed to reopen it safely. It can be viewed, but editing is disabled to avoid changing query semantics."}}function Dmt(e,t){const{aggregate:n,...r}=e;return{...r,...t}}function Emt(e){var r;const t=new Map;return(((r=e==null?void 0:e.calculatedFormula)==null?void 0:r.inputFields)||[]).forEach(o=>{const s=Ak(o.id);s&&t.set(s,o),o.qualifiedFieldName&&t.set(o.qualifiedFieldName,o),o.name&&t.set(o.name,o)}),t}function Mmt(e,t){const n=Ak(e.id);return n&&t.get(n)||e.qualifiedFieldName&&t.get(e.qualifiedFieldName)||t.get(e.name)}function Rmt(e){const t=j3(e.dataType);if(e.role==="metric"){const n=e;return n.aggregate||n.expression||n.calculatedFormula?n:{...n,aggregate:t}}return{...e,role:"metric",aggregate:t,alias:`${(e.alias||e.name).toLowerCase()}_${t.toLowerCase()}`}}function Amt(e,t){const n=Emt(t);return e.map(r=>{const o=Mmt(r,n);return(o==null?void 0:o.role)==="metric"?o:Rmt(r)})}function Fmt({fields:e,normalizedName:t,existingFieldId:n,targetKind:r,targetEntityName:o,targetQualifiedEntityName:s}){return e.some(i=>{if(n&&i.id===n||i.name!==t)return!1;const a=nf(i);if(r==="inline"){const c=en.getCalculatedFieldNamespace(i),u=s||o;return a==="inline_expression"&&!!u&&c===u}return a==="domain_calculated"})}function Pmt(e){if(!e)return[];const t=[{label:"Type",value:e.type}];if("locale"in e&&e.locale&&t.push({label:"Locale",value:e.locale}),"prefix"in e&&e.prefix&&t.push({label:"Prefix",value:e.prefix}),"suffix"in e&&e.suffix&&t.push({label:"Suffix",value:e.suffix}),e.type==="temporal_bucket")return t.push({label:"Presentation",value:e.presentation.mode}),t;if(e.type==="date")return e.pattern&&t.push({label:"Pattern",value:e.pattern}),e.timezone&&t.push({label:"Timezone",value:e.timezone}),e.sourceTimezone&&t.push({label:"Source TZ",value:e.sourceTimezone}),e.relative!==void 0&&t.push({label:"Relative",value:e.relative?"On":"Off"}),t;if("minimumFractionDigits"in e||"maximumFractionDigits"in e){const n=e.minimumFractionDigits,r=e.maximumFractionDigits;if(n!==void 0||r!==void 0){const o=n!==void 0&&r!==void 0?n===r?`${n}`:`${n}-${r}`:`${n??"auto"}-${r??"auto"}`;t.push({label:"Decimals",value:o})}}return"useGrouping"in e&&e.useGrouping!==void 0&&t.push({label:"Grouping",value:e.useGrouping?"On":"Off"}),"currency"in e&&e.currency&&t.push({label:"Currency",value:e.currency}),"percentValueMode"in e&&e.percentValueMode&&t.push({label:"Percent Input",value:e.percentValueMode}),"negativeStyle"in e&&e.negativeStyle&&t.push({label:"Negative Style",value:e.negativeStyle}),"compact"in e&&e.compact!==void 0&&t.push({label:"Compact",value:e.compact?"On":"Off"}),"scale"in e&&e.scale!==void 0&&t.push({label:"Scale",value:String(e.scale)}),t}function Omt(e){var n;if(!e.expression)return null;const t=((n=e.calculatedFormula)==null?void 0:n.inputFields)||[];return t.length?e.expression.replace(/\{field_(\d+)\}/g,(r,o)=>{const s=t[Number(o)];return s?`{${s.name||s.label}}`:r}):e.expression}function Lmt({field:e,fieldState:t}){var p;const n=Omt(e),r=Pmt(((p=e.semanticTemporalPresentation)==null?void 0:p.format)??e.format),o=_4(e),[s,i]=v.useState(!1),a=e.fieldScope?Kp(e.fieldScope):null,c=t?fm(t.state):!1,u=(t==null?void 0:t.dependencies)??[],d=t&&(c||t.verified===!1),f=t&&!t.dependencies&&!c&&t.verified!==!1&&t.state!=="base"&&t.tooltip!=="Select to establish base dataset"?t.tooltip:null,h=u.length>0||!!f||!!a||r.length>0;return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"px-3 pb-2.5 pt-2.5",children:[l.jsxs("div",{className:"flex items-start gap-1.5",children:[l.jsx("span",{className:"flex h-[18px] shrink-0 items-center",children:l.jsx(mC,{dataType:e.dataType,calculated:o})}),l.jsx("p",{className:"min-w-0 flex-1 break-words text-[13px] font-semibold leading-[18px] text-foreground",children:fo(e)})]}),l.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:[l.jsx("code",{className:"font-mono",children:e.dataType}),o&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"mx-1 text-muted-foreground/60",children:"·"}),o==="metric"?"Metric, after aggregation":"Calculated per row"]})]}),e.description&&l.jsx("p",{className:"mt-1.5 text-[12px] leading-[1.55] text-muted-foreground",children:e.description})]}),h&&l.jsxs("dl",{className:"grid grid-cols-[72px_1fr] gap-x-3 gap-y-1.5 border-t border-border/60 px-3 py-2.5 text-[11px]",children:[u.length>0&&l.jsxs(l.Fragment,{children:[l.jsx("dt",{className:b1,children:"Depends on"}),l.jsx("dd",{className:"min-w-0",children:l.jsx("ul",{className:"space-y-0.5",children:u.map(g=>{const x=N3(g.state).tag;return l.jsxs("li",{className:"min-w-0",children:[l.jsx("p",{className:m.cn("break-words leading-[1.4]",x?"text-muted-foreground":"text-foreground/90"),children:g.label}),x&&l.jsx("p",{className:"text-[10px] font-medium leading-[1.4] text-destructive",children:x})]},g.entityName)})})})]}),f&&l.jsxs(l.Fragment,{children:[l.jsx("dt",{className:b1,children:"Join"}),l.jsx("dd",{className:"text-foreground/90",children:f})]}),a&&l.jsxs(l.Fragment,{children:[l.jsx("dt",{className:b1,children:"Scope"}),l.jsx("dd",{className:"text-foreground/90",children:a})]}),r.map(g=>l.jsxs("div",{className:"contents",children:[l.jsx("dt",{className:b1,children:g.label}),l.jsx("dd",{className:"truncate font-mono tabular-nums text-foreground/90",children:g.value})]},`${g.label}-${g.value}`))]}),d&&l.jsxs("div",{className:"border-t border-border/60 bg-muted/40 px-3 py-2 text-[11px] leading-[1.5]",children:[l.jsx("p",{className:"text-foreground/90",children:t.reason?$mt(t.reason,t.mentions):t.verified===!1?"Availability could not be verified yet.":t.tooltip}),t.action&&l.jsx("p",{className:"mt-0.5 text-muted-foreground",children:t.action})]}),(t==null?void 0:t.warning)&&!c&&l.jsx("div",{className:"border-t border-border/60 px-3 py-2 text-[11px] leading-[1.5] text-muted-foreground",children:t.warning}),n&&l.jsxs("div",{className:"border-t border-border/60",children:[l.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>i(g=>!g),className:"flex w-full items-center gap-1 px-3 py-2 text-left text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground hover:text-foreground",children:[l.jsx(Ft.ChevronRight,{className:m.cn("h-3 w-3 transition-transform",s&&"rotate-90"),"aria-hidden":!0}),"Expression"]}),s&&l.jsx("code",{className:"block select-text whitespace-pre-wrap break-all bg-muted/40 px-3 py-2 font-mono text-[11px] leading-[1.55] text-foreground/90",children:n})]}),l.jsx("div",{className:"border-t border-border/60 px-3 py-2",children:l.jsx("code",{className:"block select-text break-all font-mono text-[11px] leading-[1.45] text-muted-foreground",children:e.name})})]})}function $mt(e,t){const n=(t||[]).filter(Boolean);if(n.length===0)return e;const r=new RegExp(`(${n.map(o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})`);return e.split(r).map((o,s)=>n.includes(o)?l.jsx("span",{className:"font-semibold text-foreground",children:o},`${o}-${s}`):l.jsx(v.Fragment,{children:o},s))}const b1="pt-px text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function BW({field:e,onAddField:t,context:n="editor",fieldState:r,onFieldSelect:o,inlineFilters:s,actions:i,hideActions:a,onHover:c}){const u=m.useEditorStore(X=>X.isDevMode),d=n==="inline-filter"||n==="document-filter",f=n==="filter"||d,h=fm(r==null?void 0:r.state),p=u||f||h&&!f,g=m.useDashboardStore(X=>X.dashboard.filters),x=m.useDashboardStore(X=>X.selectedSheetId),b=m.useDashboardStore(X=>X.actions.removeFilter),{removeFilterValues:y}=m.useDashboardActions(),{assignFilter:C}=mmt(),w=n==="filter"?Ox(g,x):g,N=n==="filter"?w==null?void 0:w.find(X=>{if(qg(X,e))return!0;if(X.fieldMeta)return!1;const J=nx(X.column||""),re=nx(e.name);return J.endsWith(`.${re}`)||J===re}):void 0,S=!!N,j=d&&(s==null?void 0:s.some(X=>qg(X,e))),k=S||j,_=N&&f?g==null?void 0:g.find(X=>X.id===N.id):void 0,T=_&&(_.applyToSheetIds&&_.applyToSheetIds.length>1||_.excludeSheetIds&&_.excludeSheetIds.length>0||!_.applyToSheetIds&&!_.excludeSheetIds&&!_.sheetId),[I,D]=v.useState(!1),[,E]=v.useState(null),{attributes:R,listeners:F,setNodeRef:M,transform:O,transition:z,isDragging:L}=dp({id:e.id,disabled:p});m.useEditorStore(X=>X.card);const{handleDevModeFieldClick:V,isNumberField:A}=Bme(),B=()=>{_&&(console.log("[SourceField] Removing multi-sheet filter:",_.id),y(_.id),b(_.id)),E(null),D(!1)},$=()=>{if(d&&o){o(e);return}n==="filter"?k&&T?(E(e),D(!0)):C(e,"sheet"):u?V(e):h?c==null||c(!0,P.current??void 0):t==null||t(e)},P=v.useRef(null),U={column_name:e.name,data_type:e.dataType,label:e.label,description:e.description},H={transform:Pi.Transform.toString(O),transition:z};function G(X){return X==="domain"?{label:"Semantic domain · read-only here",Icon:owe}:X==="sheet"?{label:"Sheet",Icon:zd}:X==="dashboard"?{label:"Dashboard",Icon:zd}:{label:"Card",Icon:o5}}const q=T4(e),Y=_4(e),W=e.fieldScope,ne=W&&(!q||W==="domain")?G(W):null,Z=h,K=(r==null?void 0:r.state)==="indirect";return l.jsxs(l.Fragment,{children:[l.jsx(_me,{ref:X=>{P.current=X,M(X)},style:H,...p?{}:R,...p?{}:F,...p&&!f?{tabIndex:0,"aria-disabled":h||void 0,onKeyDown:X=>{X.target===X.currentTarget&&(X.key==="Enter"||X.key===" ")&&(X.preventDefault(),$())}}:{},onClick:$,onMouseEnter:X=>c==null?void 0:c(!0,X.currentTarget),onMouseLeave:X=>c==null?void 0:c(!1,void 0,X.relatedTarget),onFocus:X=>c==null?void 0:c(!0,X.currentTarget),onBlur:X=>c==null?void 0:c(!1,void 0,X.relatedTarget),selected:S,dragging:L,disableHover:Z,inQuery:!f&&!!(r!=null&&r.isSelected),icon:l.jsx(mC,{dataType:e.dataType,calculated:Y}),label:fo(e),trailing:l.jsxs(l.Fragment,{children:[u&&!f&&A(e)&&l.jsx("span",{onClick:X=>X.stopPropagation(),onPointerDown:X=>X.stopPropagation(),children:l.jsx(pmt,{column:U})}),a?null:i?l.jsx("span",{className:"pointer-events-none inline-flex items-center opacity-0 transition-opacity group-focus-within/field-row:pointer-events-auto group-focus-within/field-row:opacity-100 group-hover/field-row:pointer-events-auto group-hover/field-row:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100",onClick:X=>X.stopPropagation(),onPointerDown:X=>X.stopPropagation(),children:i}):n==="editor"?l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":"Field actions",onClick:X=>X.stopPropagation(),onPointerDown:X=>X.stopPropagation(),className:"pointer-events-none inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-muted hover:text-foreground group-focus-within/field-row:pointer-events-auto group-focus-within/field-row:opacity-100 group-hover/field-row:pointer-events-auto group-hover/field-row:opacity-100 data-[state=open]:pointer-events-auto data-[state=open]:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100",children:l.jsx(Ai,{className:"h-3 w-3"})})}),l.jsx(_o,{align:"end",className:"w-44",children:l.jsx(ln,{onClick:X=>{X.stopPropagation(),navigator.clipboard.writeText(e.name).then(()=>{m.ue.success(`Copied "${e.name}"`)}).catch(()=>{m.ue.error("Could not copy field name")})},children:"Copy field name"})})]}):null,n==="editor"&&ne&&l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx("span",{"aria-label":`${ne.label} · calculated field`,className:"inline-flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground/70 transition-colors hover:text-foreground",onClick:X=>X.stopPropagation(),onPointerDown:X=>X.stopPropagation(),children:l.jsx(ne.Icon,{className:"h-3 w-3"})})}),l.jsx(m.TooltipContent,{side:"top",align:"end",children:ne.label})]})]}),className:m.cn((u||f)&&"cursor-pointer",!p&&!u&&!f&&"cursor-grab active:cursor-grabbing",Z&&"cursor-not-allowed opacity-50",K&&"text-muted-foreground/80",j&&"bg-primary/10 hover:bg-primary/15")}),l.jsx(ff,{open:I,onOpenChange:D,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Remove Filter from Multiple Sheets?"}),l.jsx(Ru,{children:"This filter is currently applied to multiple sheets. Removing it will affect all sheets where it's applied."})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{children:"Cancel"}),l.jsx(Au,{onClick:B,children:"Remove Filter"})]})]})})]})}const zmt=v.forwardRef(function({wrapperRef:t,disabled:n},r){const[o,s]=v.useState(null),i=280,a=v.useRef(null),c=(u,d,f,h,p)=>{var y;if(!f){if(p instanceof Node&&((y=a.current)!=null&&y.contains(p)))return;s(C=>C&&C.field.id===u.id?null:C);return}if(n){s(null);return}if(!h||!t.current)return;const g=h.getBoundingClientRect(),x=t.current.getBoundingClientRect(),b=Math.max(0,x.bottom-i);s({field:u,fieldState:d,top:Math.min(g.top,b),left:x.right})};return v.useImperativeHandle(r,()=>({hover:c,clear:()=>s(null)})),o?l.jsx("div",{ref:a,style:{position:"fixed",top:o.top,left:o.left},onMouseLeave:()=>s(null),className:"z-50 pl-3",children:l.jsx("div",{className:"w-[280px] select-text overflow-hidden rounded-control border border-border bg-popover shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:l.jsx(Lmt,{field:o.field,fieldState:o.fieldState},o.field.id)})}):null});var jl="Accordion",Bmt=["Home","End","ArrowDown","ArrowUp","ArrowLeft","ArrowRight"],[M4,Vmt,Hmt]=m.createCollection(jl),[$T]=m.createContextScope(jl,[Hmt,dde]),R4=dde(),Ume=v.forwardRef((e,t)=>{const{type:n,...r}=e,o=r,s=r;return l.jsx(M4.Provider,{scope:e.__scopeAccordion,children:n==="multiple"?l.jsx(Wmt,{...s,ref:t}):l.jsx(Kmt,{...o,ref:t})})});Ume.displayName=jl;var[Kme,qmt]=$T(jl),[Wme,Umt]=$T(jl,{collapsible:!1}),Kmt=v.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:o=()=>{},collapsible:s=!1,...i}=e,[a,c]=m.useControllableState({prop:n,defaultProp:r??"",onChange:o,caller:jl});return l.jsx(Kme,{scope:e.__scopeAccordion,value:v.useMemo(()=>a?[a]:[],[a]),onItemOpen:c,onItemClose:v.useCallback(()=>s&&c(""),[s,c]),children:l.jsx(Wme,{scope:e.__scopeAccordion,collapsible:s,children:l.jsx(Gme,{...i,ref:t})})})}),Wmt=v.forwardRef((e,t)=>{const{value:n,defaultValue:r,onValueChange:o=()=>{},...s}=e,[i,a]=m.useControllableState({prop:n,defaultProp:r??[],onChange:o,caller:jl}),c=v.useCallback(d=>a((f=[])=>[...f,d]),[a]),u=v.useCallback(d=>a((f=[])=>f.filter(h=>h!==d)),[a]);return l.jsx(Kme,{scope:e.__scopeAccordion,value:i,onItemOpen:c,onItemClose:u,children:l.jsx(Wme,{scope:e.__scopeAccordion,collapsible:!0,children:l.jsx(Gme,{...s,ref:t})})})}),[Gmt,zT]=$T(jl),Gme=v.forwardRef((e,t)=>{const{__scopeAccordion:n,disabled:r,dir:o,orientation:s="vertical",...i}=e,a=v.useRef(null),c=m.useComposedRefs(a,t),u=Vmt(n),f=m.useDirection(o)==="ltr",h=m.composeEventHandlers(e.onKeyDown,p=>{var _;if(!Bmt.includes(p.key))return;const g=p.target,x=u().filter(T=>{var I;return!((I=T.ref.current)!=null&&I.disabled)}),b=x.findIndex(T=>T.ref.current===g),y=x.length;if(b===-1)return;p.preventDefault();let C=b;const w=0,N=y-1,S=()=>{C=b+1,C>N&&(C=w)},j=()=>{C=b-1,C<w&&(C=N)};switch(p.key){case"Home":C=w;break;case"End":C=N;break;case"ArrowRight":s==="horizontal"&&(f?S():j());break;case"ArrowDown":s==="vertical"&&S();break;case"ArrowLeft":s==="horizontal"&&(f?j():S());break;case"ArrowUp":s==="vertical"&&j();break}const k=C%y;(_=x[k].ref.current)==null||_.focus()});return l.jsx(Gmt,{scope:n,disabled:r,direction:o,orientation:s,children:l.jsx(M4.Slot,{scope:n,children:l.jsx(m.Primitive.div,{...i,"data-orientation":s,ref:c,onKeyDown:r?void 0:h})})})}),Fk="AccordionItem",[Ymt,A4]=$T(Fk),Yme=v.forwardRef((e,t)=>{const{__scopeAccordion:n,value:r,...o}=e,s=zT(Fk,n),i=qmt(Fk,n),a=R4(n),c=m.useId(),u=r&&i.value.includes(r)||!1,d=s.disabled||e.disabled;return l.jsx(Ymt,{scope:n,open:u,disabled:d,triggerId:c,children:l.jsx(mde,{"data-orientation":s.orientation,"data-state":tpe(u),...a,...o,ref:t,disabled:d,open:u,onOpenChange:f=>{f?i.onItemOpen(r):i.onItemClose(r)}})})});Yme.displayName=Fk;var Zme="AccordionHeader",Xme=v.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,o=zT(jl,n),s=A4(Zme,n);return l.jsx(m.Primitive.h3,{"data-orientation":o.orientation,"data-state":tpe(s.open),"data-disabled":s.disabled?"":void 0,...r,ref:t})});Xme.displayName=Zme;var rO="AccordionTrigger",Qme=v.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,o=zT(jl,n),s=A4(rO,n),i=Umt(rO,n),a=R4(n);return l.jsx(M4.ItemSlot,{scope:n,children:l.jsx(vet,{"aria-disabled":s.open&&!i.collapsible||void 0,"data-orientation":o.orientation,id:s.triggerId,...a,...r,ref:t})})});Qme.displayName=rO;var Jme="AccordionContent",epe=v.forwardRef((e,t)=>{const{__scopeAccordion:n,...r}=e,o=zT(jl,n),s=A4(Jme,n),i=R4(n);return l.jsx(wet,{role:"region","aria-labelledby":s.triggerId,"data-orientation":o.orientation,...i,...r,ref:t,style:{"--radix-accordion-content-height":"var(--radix-collapsible-content-height)","--radix-accordion-content-width":"var(--radix-collapsible-content-width)",...e.style}})});epe.displayName=Jme;function tpe(e){return e?"open":"closed"}var Zmt=Ume,Xmt=Yme,Qmt=Xme,npe=Qme,rpe=epe;const ope=Zmt,Pk=ie.forwardRef(({className:e,...t},n)=>l.jsx(Xmt,{ref:n,className:m.cn("border-b",e),...t}));Pk.displayName="AccordionItem";const Ok=ie.forwardRef(({className:e,children:t,...n},r)=>l.jsx(Qmt,{className:"flex",children:l.jsxs(npe,{ref:r,className:m.cn("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",e),...n,children:[t,l.jsx(Re.ChevronDown,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]})}));Ok.displayName=npe.displayName;const Lk=ie.forwardRef(({className:e,children:t,...n},r)=>l.jsx(rpe,{ref:r,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down",...n,children:l.jsx("div",{className:m.cn("pb-4 pt-0",e),children:t})}));Lk.displayName=rpe.displayName;function Jmt(e,t,n,r,o,s){const i=D4(e),a=E4(n);return joe({id:s||`calc_dim_${Hme(10)}`,name:i,label:e.trim(),alias:i,qualifiedFieldName:i,dataType:r,role:"groupby",expression:t.trim(),calculationRepresentation:a.kind==="inline"?"inline-expression":"manual",calculatedFormula:{operation:"custom",inputFields:n.map(c=>c.role==="metric"?{...c,role:"metric"}:{...c,role:"groupby"})},entityId:a.kind==="inline"?a.entityId:o,entityName:a.kind==="inline"?a.entityName:ze.CALCULATED_FIELD_ENTITY_MARKER,qualifiedEntityName:a.kind==="inline"?a.qualifiedEntityName:void 0,entityType:a.kind==="inline"?"dataset":"table",description:`Calculated field: ${e.trim()}`})}function ept({value:e,onChange:t,disabled:n,options:r=["dimension","metric"]}){const o=r.length>0?r:["dimension","metric"],s=["dimension","metric"].filter(c=>o.includes(c)),i=n||s.length<=1,a=s.includes(e)?e:s[0];return l.jsx(m.Tabs,{value:a,onValueChange:c=>t(c),className:"w-fit shrink-0",children:l.jsx(m.TabsList,{size:"xs",className:"border border-border bg-transparent shadow-none",children:s.map(c=>l.jsx(m.TabsTrigger,{value:c,disabled:i,className:"data-[state=active]:bg-muted data-[state=active]:shadow-none",children:Smt(c)},c))})})}const F4=ie.forwardRef(({className:e,sideOffset:t=8,...n},r)=>l.jsx(m.Portal$2,{children:l.jsx(gb,{children:l.jsx(m.Content2$1,{ref:r,sideOffset:t,className:m.cn("z-[60] overflow-hidden rounded-lg border bg-popover text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95","data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95","data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})})}));F4.displayName="ValidationTooltipContent";const spe=m.Arrow2$1;function M2(e,t){return`${e} ${t}${e===1?"":"s"}`}function tpt({result:e}){const t=e.errors.length>0,n=M2(e.tokens.length,"token"),r=e.errors.length>0?M2(e.errors.length,"error"):null,o=e.warnings.length>0?M2(e.warnings.length,"warning"):null,s=e.errors.map(i=>i.suggestion?`${i.message} (${i.suggestion})`:i.message).join(`
1319
1319
  `);return l.jsxs(m.Tooltip,{delayDuration:120,children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":t?"Validation failed. Hover to view details.":"Validation passed. Hover to view details.",className:m.cn("inline-flex h-5 w-5 items-center justify-center rounded-full transition-colors",t?"bg-destructive text-destructive-foreground hover:bg-destructive/90":"bg-emerald-600 text-white hover:bg-emerald-700"),children:t?l.jsx(Re.X,{className:"h-3 w-3","aria-hidden":!0}):l.jsx(m.Check,{className:"h-3 w-3","aria-hidden":!0})})}),l.jsxs(F4,{side:"top",align:"start",avoidCollisions:!0,collisionPadding:12,className:"w-[min(440px,calc(100vw-32px))] p-0",children:[l.jsxs("div",{className:"space-y-2.5 p-3 text-xs",children:[l.jsx("div",{className:m.cn("font-semibold",t?"text-destructive":"text-emerald-700"),children:t?"Validation failed":"Validation passed"}),l.jsxs("div",{className:"flex flex-wrap gap-x-2 gap-y-1 text-[11px] text-muted-foreground",children:[l.jsx("span",{children:n}),r&&l.jsx("span",{children:r}),o&&l.jsx("span",{children:o}),e.inferredDataType&&l.jsxs("span",{children:["type: ",e.inferredDataType]})]}),e.tokens.length>0&&l.jsxs("div",{className:"space-y-1.5 border-t pt-2",children:[l.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Tokens"}),l.jsx("div",{className:"max-h-28 space-y-1 overflow-y-auto pr-1 select-text",children:e.tokens.map((i,a)=>l.jsxs("div",{className:"flex items-start gap-1.5",children:[l.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 font-mono leading-none",children:`{${i.token}}`}),l.jsx(sw,{className:"mt-0.5 h-3 w-3 shrink-0 text-muted-foreground"}),i.field?l.jsx("span",{className:"break-all text-muted-foreground",children:i.field.qualifiedFieldName||i.field.name}):l.jsx("span",{className:"text-muted-foreground",children:"Unresolved"})]},`${i.token}-${a}`))})]}),e.errors.length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-destructive",children:"Errors"}),l.jsx(Pd,{text:s,ariaLabel:"Copy validation errors",className:"h-5 w-5 p-0 text-destructive/70 hover:text-destructive"})]}),l.jsx("div",{className:"max-h-32 space-y-1 overflow-y-auto pr-1 text-destructive select-text",children:e.errors.map((i,a)=>l.jsxs("div",{className:"break-words",children:[i.message,i.suggestion?` (${i.suggestion})`:""]},`${i.code}-${a}`))})]}),e.warnings.length>0&&l.jsxs("div",{className:"space-y-1.5",children:[l.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wide text-amber-700",children:"Warnings"}),l.jsx("div",{className:"max-h-32 space-y-1 overflow-y-auto pr-1 text-amber-700 select-text",children:e.warnings.map((i,a)=>l.jsxs("div",{className:"break-words",children:[i.message,i.suggestion?` (${i.suggestion})`:""]},`${i.code}-${a}`))})]}),e.inferredDataType&&l.jsxs("div",{className:"border-t pt-2 text-[11px] text-muted-foreground",children:["Inferred output type:"," ",l.jsx("span",{className:"font-medium text-foreground",children:e.inferredDataType})]})]}),l.jsx(spe,{className:"fill-popover"})]})]})}function npt({onValidate:e,isValidating:t,validationResult:n,error:r,disabled:o}){return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:e,disabled:t||o,children:t?"Validating…":"Validate"}),n&&l.jsx(tpt,{result:n}),!n&&r&&l.jsxs(m.Tooltip,{delayDuration:120,children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":"Validation failed. Hover to view details.",className:"inline-flex h-5 w-5 items-center justify-center rounded-full bg-destructive text-destructive-foreground hover:bg-destructive/90",children:l.jsx(Re.X,{className:"h-3 w-3","aria-hidden":!0})})}),l.jsxs(F4,{side:"top",align:"start",avoidCollisions:!0,collisionPadding:12,className:"w-[min(420px,calc(100vw-32px))] p-3",children:[l.jsxs("div",{className:"space-y-2 text-xs",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("span",{className:"font-semibold text-destructive",children:"Validation failed"}),l.jsx(Pd,{text:r,ariaLabel:"Copy validation error",className:"h-5 w-5 p-0 text-destructive/70 hover:text-destructive"})]}),l.jsx("p",{className:"max-h-40 overflow-y-auto break-words text-destructive select-text",children:r})]}),l.jsx(spe,{className:"fill-popover"})]})]})]})}const rpt={metric:["Average revenue per order","Profit margin %","Active customers last 30 days"],dimension:["Order month from created_at","Bucket revenue into 'Large' / 'Small'","Country and state combined"]};function opt({mode:e,fieldType:t,prompt:n,onPromptChange:r,generated:o,explanation:s,isGenerating:i,error:a,onGenerate:c,onTryAgain:u,onCancel:d,onUseDraft:f,disabled:h}){const p=e==="result",g=e==="loading"||i,x=rpt[t],b=t==="metric"?"e.g. average revenue per order, in dollars":"e.g. bucket orders into 'Large' / 'Small' by amount";return l.jsxs("div",{"data-testid":"ai-compose-panel","data-mode":e,className:"rounded-[6px] border border-blue-200 bg-blue-50/40 dark:border-blue-900/40 dark:bg-blue-950/20",children:[l.jsxs("div",{className:"flex items-center gap-2 border-b border-blue-200/60 px-3 py-2 dark:border-blue-900/30",children:[l.jsx(Ov,{className:"h-3 w-3 text-blue-600 dark:text-blue-400","aria-hidden":!0}),l.jsx("span",{className:"text-[11px] font-medium text-zinc-900 dark:text-zinc-100",children:p?"AI draft — ready to use":"Compose with AI"}),l.jsx("span",{className:"text-[10px] text-zinc-500 dark:text-zinc-400",children:p?"Review before using.":"Describe in plain English. AI knows your fields."}),l.jsx("button",{type:"button","aria-label":"Close AI compose",onClick:d,disabled:h,className:"ml-auto text-blue-700/70 hover:text-blue-900 disabled:opacity-50 dark:text-blue-300/70 dark:hover:text-blue-100",children:l.jsx(Re.X,{className:"h-3 w-3"})})]}),l.jsx("div",{className:"space-y-2 p-3",children:p?l.jsxs(l.Fragment,{children:[n.trim()&&l.jsxs("div",{className:"flex items-start gap-1.5 rounded-[4px] bg-white px-2 py-1.5 text-[11px] dark:bg-zinc-950",children:[l.jsx("span",{className:"shrink-0 text-zinc-400",children:"›"}),l.jsxs("span",{className:"italic text-zinc-600 dark:text-zinc-400",children:["“",n.trim(),"”"]})]}),l.jsx("div",{className:"overflow-hidden rounded-[5px] border border-zinc-200 bg-white dark:border-zinc-800 dark:bg-zinc-950",children:l.jsx("div",{className:"max-h-[180px]",children:l.jsx(m.CodeEditor,{value:o,language:"sql-jinja",readOnly:!0,embedded:!0,hideLineNumbers:!0,dense:!0,ariaLabel:"Generated expression"})})}),s?l.jsx("p",{className:"text-[11px] text-zinc-500 dark:text-zinc-400",children:s}):null]}):l.jsxs(l.Fragment,{children:[l.jsx(m.Label,{htmlFor:"ai-compose-prompt",className:"sr-only",children:"Describe what you want to calculate"}),l.jsx(qm,{id:"ai-compose-prompt",value:n,onChange:y=>r(y.target.value),placeholder:b,rows:2,disabled:g||h,className:"resize-none border-zinc-200 bg-white text-[13px] text-zinc-900 shadow-none placeholder:text-zinc-400 focus:border-zinc-400 focus-visible:ring-0 disabled:opacity-60 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-50"}),!g&&l.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[l.jsx("span",{className:"mr-1 text-[10px] uppercase tracking-[0.08em] text-zinc-400",children:"Try"}),x.map(y=>l.jsx("button",{type:"button",onClick:()=>r(y),disabled:h,className:"inline-flex h-5 items-center rounded-[4px] border border-zinc-200 bg-white px-1.5 text-[11px] text-zinc-600 hover:bg-zinc-50 hover:text-zinc-900 disabled:opacity-50 dark:border-zinc-800 dark:bg-zinc-950 dark:text-zinc-400 dark:hover:bg-zinc-900 dark:hover:text-zinc-100",children:y},y))]}),a&&l.jsx("p",{className:"whitespace-pre-wrap text-[11px] text-destructive",children:a})]})}),l.jsx("div",{className:"flex items-center justify-end gap-1.5 border-t border-blue-200/60 px-3 py-2 dark:border-blue-900/30",children:p?l.jsxs(l.Fragment,{children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:u,disabled:h,children:"Try again"}),l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:d,disabled:h,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:f,disabled:h||!o.trim(),children:"Use draft"})]}):l.jsxs(l.Fragment,{children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:d,disabled:h,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:c,disabled:g||h||!n.trim(),className:m.cn("gap-1.5",g&&"pointer-events-none"),children:g?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"h-3 w-3 animate-spin","aria-hidden":!0}),"Generating…"]}):l.jsxs(l.Fragment,{children:[l.jsx(Ov,{className:"h-3 w-3","aria-hidden":!0}),"Generate"]})})]})})]})}function spt({groups:e,searchTerm:t,onSearchTermChange:n,onFieldClick:r,selectedFieldIds:o,unavailableFieldReasons:s,disabled:i}){const a=v.useMemo(()=>new Set(o||[]),[o]),{fields:c,groupByFieldId:u}=v.useMemo(()=>{const d=new Map,f=[];for(const h of e)for(const p of h.fields)d.set(p.id,{id:h.id,label:h.label}),f.push(p);return{fields:f,groupByFieldId:d}},[e]);return l.jsx("div",{className:"flex h-full min-h-0 flex-col",children:l.jsx(PT,{fields:c,selectedIds:a,onSelect:r,query:t,onQueryChange:n,listLabel:"Insert field",listClassName:"min-h-0 flex-1",getGroup:d=>u.get(d.id)??null,isDisabled:d=>!d.isCompatible||!!i,isCalculated:d=>d.isCalculated?d.role==="metric"?"metric":"dimension":!1,density:"compact",renderTrailing:(d,f)=>f?l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Selected"}):s!=null&&s[d.id]?l.jsx("span",{title:s[d.id],className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground/70",children:"Not in this visual"}):void 0})})}function ipt({groups:e,searchTerm:t,onSearchTermChange:n,onFieldSelect:r,selectedFieldIds:o,unavailableFieldReasons:s,disabled:i}){const[a,c]=v.useState(!1);return l.jsxs(m.Popover,{open:a,onOpenChange:c,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs(m.Button,{type:"button",variant:"outline",size:"xs",disabled:i,className:"gap-1.5",children:[l.jsx(Ar,{className:"h-3 w-3","aria-hidden":!0}),"Insert field"]})}),l.jsx(m.PopoverContent,{align:"end",sideOffset:6,collisionPadding:8,className:"z-[51] w-[320px] max-w-[min(320px,calc(100vw-32px))] p-2",children:l.jsx("div",{className:"flex h-[min(360px,calc(var(--radix-popover-content-available-height)-16px))] min-h-0 flex-col",children:l.jsx(spt,{groups:e,searchTerm:t,unavailableFieldReasons:s,onSearchTermChange:n,onFieldClick:u=>{r(u),c(!1)},selectedFieldIds:o,disabled:i})})})]})}function apt({onInsert:e,disabled:t}){return l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsxs(m.Button,{type:"button",variant:"outline",size:"xs",disabled:t,className:"gap-1.5",children:["Templates",l.jsx(Re.ChevronDown,{className:"h-3 w-3","aria-hidden":!0})]})}),l.jsx(_o,{align:"end",className:"w-[300px]",children:xmt.map(n=>{var r;return l.jsxs(ln,{onSelect:o=>{var i;o.preventDefault();const s=(i=n.insertTemplate)==null?void 0:i.call(n);s&&e(s)},className:"flex items-start justify-between gap-3 py-2",children:[l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"font-mono text-[12px] text-muted-foreground",children:n.symbol}),l.jsx("span",{className:"text-[12px] font-medium",children:n.label})]}),l.jsx("div",{className:"mt-0.5 truncate font-mono text-[11px] text-muted-foreground",children:(r=n.insertTemplate)==null?void 0:r.call(n)})]}),n.insertHint?l.jsx("span",{className:"shrink-0 text-[10px] text-muted-foreground",children:n.insertHint}):null]},n.id)})})]})}const lpt="Calculated fields";function cpt(e){var t;if(e.kind==="inline"){const n=(t=e.entityName)==null?void 0:t.trim();if(n)return`${n} dataset`}return lpt}function upt({inlineAnalysis:e,hasInputFields:t=!0}){const n=[];return t&&(n.push({label:"Uses",value:jmt(e.kind)}),n.push({label:"Stored with",value:cpt(e)})),n}function dpt(e){const t=upt(e);return t.length===0?null:l.jsx("div",{className:"flex items-center gap-3 border-t bg-muted/40 px-5 py-2","data-testid":"calculated-field-summary-ribbon",children:l.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:t.map(n=>l.jsxs("span",{className:"inline-flex items-baseline gap-1.5 rounded-[4px] border bg-background px-1.5 py-0.5 text-[11px]",children:[l.jsx("span",{className:"text-[9px] font-medium uppercase tracking-[0.06em] text-muted-foreground/80",children:n.label}),l.jsx("span",{className:"text-foreground",children:n.value})]},n.label))})})}function fpt(e){var r;const t=m.getRequestErrorMessage(e,"AI generation failed"),n=(r=m.getRequestErrorViolations(e))==null?void 0:r[0];return n?n.hint?`${n.message} Hint: ${n.hint}`:n.message||t:t}function hpt({endpoint:e,availableFields:t,fieldType:n,dialect:r}){const{authToken:o}=Mt(),[s,i]=v.useState(!1),[a,c]=v.useState(null),u=v.useCallback(async f=>{var h;if(!e)return c("AI generation is not available"),null;if(!f.trim())return c("Describe what you want to calculate"),null;i(!0),c(null);try{const p={type:"calculated-field-expression",context:{userQuery:f,availableFields:t.map(x=>({name:x.tokenLabel,dataType:x.dataType,...x.role==="metric"||x.role==="groupby"?{role:x.role}:{}})),fieldType:n},options:{dialect:r}},g=await m.postRequestRegular(e,(o==null?void 0:o.accessToken)||"",p);if(!g.success||!((h=g.result)!=null&&h.generated))throw new Error(g.error||"No expression generated");return{generated:g.result.generated,explanation:g.result.explanation}}catch(p){return c(fpt(p)),null}finally{i(!1)}},[e,t,n,r,o==null?void 0:o.accessToken]),d=v.useCallback(()=>c(null),[]);return{generateExpression:u,isGenerating:s,error:a,resetError:d}}const mpt=/\{([^}]+)\}/g;function BT(e){return e.trim().toLowerCase()}function ipe(e){return Array.from(e.matchAll(mpt)).map(t=>t[1]).filter(Boolean)}function ppt(e){const t=new Set,n=[];return e.forEach(r=>{const o=BT(r);t.has(o)||(t.add(o),n.push(r))}),n}function P4(e){const t=new Map,n=(r,o)=>{const s=BT(r),i=t.get(s)||[];i.some(a=>a.id===o.id)||t.set(s,[...i,o])};return e.forEach(r=>{n(r.tokenLabel,r),r.name&&r.name!==r.tokenLabel&&n(r.name,r),r.baseLabel&&r.baseLabel!==r.tokenLabel&&n(r.baseLabel,r)}),t}function bN(e,t){const n=ipe(e),r=ppt(n),o=P4(t),s=r.map(a=>{const c=o.get(BT(a))||[];return c.length===1?c[0]:null}),i=r.filter((a,c)=>!s[c]);return{orderedTokens:r,orderedFields:s,unresolvedTokens:i}}function oO(e,t){return t.reduce((n,r,o)=>{const s=new RegExp(`\\{${gpt(r)}\\}`,"gi");return n.replace(s,`{field_${o}}`)},e)}function gpt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const xpt=e=>e.entityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.qualifiedEntityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.entityName===ze.CALCULATED_FIELD_ENTITY_MARKER?"Calculated Fields":e.qualifiedEntityName?m.toLabel(e.entityName||e.qualifiedEntityName):m.toLabel(e.entityName||"Other");function bpt(e){return e.entityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.qualifiedEntityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.entityName===ze.CALCULATED_FIELD_ENTITY_MARKER?lt.CALCULATED_FIELDS_GROUP_NAME:e.qualifiedEntityName||e.entityName||"Other"}function ypt(e){return e.role!=="metric"?!1:e.fieldScope==="domain"||e.fieldScope==="sheet"||e.fieldScope==="dashboard"||e.fieldScope==="card"||e.entityName===ze.CALCULATED_FIELD_ENTITY_MARKER||e.entityName===lt.CALCULATED_FIELDS_GROUP_NAME||e.qualifiedEntityName===lt.CALCULATED_FIELDS_GROUP_NAME}function vpt(e,t){const n=new Set((t||[]).map(r=>Ak(r)));return e.filter(r=>{const o=Ak(r.id);return!(o&&n.has(o))})}function wpt(e){const t=new Map,n=new Map;return e.forEach(r=>{let s=r.entityName&&r.entityName!==ze.CALCULATED_FIELD_ENTITY_MARKER?`${r.entityName}.${r.name}`:r.name;const i=s.toLowerCase(),a=n.get(i)||0;a>0&&(s=`${s} ${a+1}`),n.set(i,a+1),t.set(r.id,s)}),t}function Cpt(e,t,n,r){return t==="dimension"?e.map(o=>({...o,isCompatible:!ypt(o)})).filter(o=>r):t!=="metric"?e.map(o=>({...o,isCompatible:!0})):e.map(o=>({...o,isCompatible:!0}))}function Spt(e,t){if(!t)return e;const n=ek(t);return e.filter(r=>hb(r,t)||ek(r.tokenLabel).includes(n))}function Npt(e){const t=new Map;return e.forEach(n=>{var o;const r=bpt(n);t.has(r)||t.set(r,{id:r,label:xpt(n),fields:[]}),(o=t.get(r))==null||o.fields.push(n)}),Array.from(t.values())}function jpt({fields:e,mode:t,searchTerm:n,excludeFieldIds:r,selectedAggregate:o,showIncompatible:s}){const i=v.useMemo(()=>vpt(e,r),[e,r]),a=v.useMemo(()=>wpt(i),[i]),c=v.useMemo(()=>i.map(g=>{const x=fo(g),b=g.role==="metric"&&ze.isCalculatedMetric(g)||g.role==="groupby"&&ze.isCalculatedDimension(g);return{...g,baseLabel:x,tokenLabel:a.get(g.id)||x,isCalculated:b,isCompatible:!0}}),[i,a]),u=v.useMemo(()=>Cpt(c,t,o,s),[c,t,o,s]),d=v.useMemo(()=>Spt(u,n),[u,n]),f=v.useMemo(()=>u.filter(g=>g.isCompatible),[u]),h=v.useMemo(()=>P4(f),[f]),p=v.useMemo(()=>Npt(d),[d]);return{allFields:c,filteredFields:d,groups:p,tokenCandidates:h,tokenFields:f}}const kpt=e=>m.getDataType(e.dataType||"")==="number",VW=e=>kpt(e)?"SUM":"COUNT",Ipt=e=>{if(e.role==="metric"){const n=e;return{...n,aggregate:n.aggregate||VW(e)}}const t=VW(e);return{...e,role:"metric",aggregate:t,alias:`${(e.alias||e.name).toLowerCase()}_${t.toLowerCase()}`}},_pt=(e,t)=>{var r;const n=e.trim();if(n){if(/\bDATE_TRUNC\b/i.test(n))return"date";if(/\bTIMESTAMP\b/i.test(n))return"datetime";if(/\bDATE\b/i.test(n)&&!/\bUPDATE\b/i.test(n))return"date";if(/['"]/.test(n))return"string";if(/[+\-*/]/.test(n))return"number";if(t.length===1)return m.getDataType(((r=t[0])==null?void 0:r.dataType)||"")}};function Tpt({expression:e,availableFields:t,validationEndpoint:n,connectionId:r,dialect:o,fieldType:s,outputType:i,validationContext:a}){const{authToken:c}=Mt(),[u,d]=v.useState(null),[f,h]=v.useState(!1),[p,g]=v.useState(null),x=v.useMemo(()=>P4(t),[t]),b=v.useMemo(()=>ipe(e).map(S=>{const j=x.get(BT(S))||[];return{token:S,field:j.length===1?j[0]:null}}),[e,x]),y=v.useCallback((N,S)=>{const j=[{code:"SQL_VALIDATION_ERROR",message:N,suggestion:(S==null?void 0:S.suggestion)||(S==null?void 0:S.errorCode)}];return{isValid:!1,tokens:b,errors:j,warnings:[]}},[b]),C=v.useCallback(async()=>{var F;g(null);const N=n==null?void 0:n.trim();if(!N){const M=y("Validation endpoint is not configured");return d(M),M}if(!!!(a!=null&&a.cardConfig&&(a!=null&&a.cardDataSource)&&(a!=null&&a.cardId)&&(a!=null&&a.connectionId||r))){const M=y("Validation context is incomplete for server-side validation");return d(M),M}const{orderedTokens:j,orderedFields:k}=bN(e,t),_=[],T=[];j.forEach((M,O)=>{const z=k[O];z&&(_.push(M),T.push(z))});const I=s==="metric"?T.map(Ipt):T,D=_pt(e,T),E=oO(e,_),R={type:"calculated-field-expression",fieldType:s,expression:E,inputFields:I,outputType:i,options:{validateWithExplain:!0},context:{connectionId:(a==null?void 0:a.connectionId)||r,cardId:a==null?void 0:a.cardId,cardConfig:a==null?void 0:a.cardConfig,cardDataSource:a==null?void 0:a.cardDataSource,activeFilters:(a==null?void 0:a.activeFilters)||[],cardType:(a==null?void 0:a.cardType)||"table",dialect:o}};h(!0);try{const M=await m.postRequestRegular(N,(c==null?void 0:c.accessToken)||"",R),O=M==null?void 0:M.status,z=M==null?void 0:M.error,L=M==null?void 0:M.errorCode,V=[],A=[];O==="invalid"?V.push({code:"SQL_VALIDATION_ERROR",message:z||"Expression failed SQL validation",suggestion:L?`Validation code: ${L}`:void 0}):O==="unverified"?A.push({code:"EXECUTION_UNVERIFIED",message:z||"Execution could not be fully verified in this environment.",suggestion:"Syntax checks passed. This expression may still run successfully."}):O!=="valid"&&V.push({code:"SQL_VALIDATION_ERROR",message:z||"Unexpected SQL validation response from server",suggestion:L?`Validation code: ${L}`:void 0});const B={isValid:(O==="valid"||O==="unverified")&&V.length===0,tokens:b,errors:V,warnings:A,inferredDataType:(M==null?void 0:M.inferredDataType)??((F=M==null?void 0:M.metadata)==null?void 0:F.inferredDataType)??D??i??void 0};return d(B),B}catch(M){const O=(M==null?void 0:M.error)||(M==null?void 0:M.message)||"Expression validation failed";g(O);const z=y(O);return d(z),z}finally{h(!1)}},[n,a,r,e,t,s,i,o,c==null?void 0:c.accessToken,y,b]),w=v.useCallback(()=>{d(null),g(null)},[]);return{validationResult:u,isValidating:f,serverError:p,validateExpression:C,resetValidation:w}}function O4(e){var t;return(e==null?void 0:e.type)==="organization"?!0:(e==null?void 0:e.type)==="tenant"&&((t=e.permissions)==null?void 0:t.canEdit)===!0}function Dpt({status:e}){const t=e==="effective"?"This is the current effective domain formula. Saved visuals resolve it again when they run.":e==="loading"?"The domain catalog is still loading. This saved formula is not verified as current.":e==="unavailable"?"The domain catalog is unavailable. This saved formula is not verified as current.":"This saved formula could not be matched to the current domain catalog and is not verified as current. Reselect the field to repair it.";return l.jsxs("div",{className:"rounded-control border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground","data-testid":"domain-definition-status",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Governed domain calculation"}),l.jsx("p",{children:t})]})}const R2=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"date",label:"Date"},{value:"datetime",label:"Datetime"},{value:"json",label:"JSON"},{value:"geo",label:"Geo"}],Ept=[],Mpt="https://docs.semaphor.cloud/docs/concepts/calculated-fields",Rpt="SUM({revenue}) / NULLIF(COUNT({order_id}), 0)",Apt="DATE_TRUNC('month', {created_at})";function ape({open:e,onOpenChange:t,availableFields:n,unavailableFieldReasons:r,existingField:o,existingFieldScope:s,domainDefinitionStatus:i,onSave:a,onSaveToSheet:c,onSaveToDashboard:u,cardId:d,initialFieldType:f="metric",allowedFieldTypes:h}){var dt,_t,Xt,wn,cn;const{tokenProps:p}=Mt(),g=((_t=(dt=p.config)==null?void 0:dt.projectFeatures)==null?void 0:_t.features.aiWritingHelpers)!==!1,{selectedConnection:x}=cte(),b=m.useEditorStore(ot=>{var Rt;return(Rt=ot.card)==null?void 0:Rt.config}),y=m.useEditorStore(ot=>{var Rt;return(Rt=ot.card)==null?void 0:Rt.dataSource}),C=m.useEditorStore(ot=>{var Rt;return(Rt=ot.card)==null?void 0:Rt.type}),N=m.useEditorStore(ot=>ot.filterValues)??Ept,S=s==="domain",[j,k]=v.useState(f),[_,T]=v.useState(""),[I,D]=v.useState(""),E=S?(o==null?void 0:o.role)==="metric"?"metric":"dimension":j,R=S?(o==null?void 0:o.label)||(o==null?void 0:o.name)||"":_,[F,M]=v.useState(null),O=S?((Xt=R2.find(ot=>ot.value===(o==null?void 0:o.dataType)))==null?void 0:Xt.value)||null:F,[z,L]=v.useState("card"),V=S?"domain":z,[A,B]=v.useState({}),[$,P]=v.useState(""),[U,H]=v.useState(!1),[G,q]=v.useState(""),[Y,W]=v.useState(""),[ne,Z]=v.useState(void 0),[K,X]=v.useState(null),[J,re]=v.useState(!1),[te,Q]=v.useState(!1),[se,oe]=v.useState(null),fe=S?null:se,pe=v.useId(),xe=v.useRef(!1),Ie=v.useRef(null),{userContext:be}=hi(),ge=v.useMemo(()=>n.filter(ot=>ot.fieldScope==="domain"&&!!ot.expression),[n]),ee=v.useMemo(()=>ge.filter(ot=>ot.role==="metric"),[ge]),ce=v.useMemo(()=>ge.filter(ot=>ot.role==="groupby"),[ge]),me=!O4(be),ve=!!fe,_e=me||ve||S,De=!!c,Ue=!!u,Ne=(wn=p==null?void 0:p.apiServiceUrl)==null?void 0:wn.replace(/\/$/,""),Oe=Ne?`${Ne}/v1/calculated-fields/validate`:"/v1/calculated-fields/validate",ye=Ne?`${Ne}/v1/ai/generate`:"/v1/ai/generate",Be=v.useMemo(()=>{var Pe;const ot=[...n];return(((Pe=o==null?void 0:o.calculatedFormula)==null?void 0:Pe.inputFields)||[]).forEach(Ge=>{ot.some(kt=>kt.id===Ge.id||kt.qualifiedFieldName===Ge.qualifiedFieldName||kt.name===Ge.name)||ot.push(Ge)}),ot},[n,o]),{tokenFields:he,groups:ue}=jpt({fields:Be,mode:E,excludeFieldIds:o?[o.id]:void 0,selectedAggregate:void 0,showIncompatible:!0}),de=he,Te=v.useCallback((ot,Rt)=>ot.replace(/\{field_(\d+)\}/g,(Pe,Ge)=>{var Wt;const at=Rt[Number(Ge)];return at?`{${((Wt=de.find(fn=>fn.id===at.id))==null?void 0:Wt.tokenLabel)||at.label||at.name}}`:Pe}),[de]),we=S?Te((o==null?void 0:o.expression)||"",((cn=o==null?void 0:o.calculatedFormula)==null?void 0:cn.inputFields)||[]):I,{generateExpression:Ee,isGenerating:Ke,error:He,resetError:qe}=hpt({endpoint:ye,availableFields:de,fieldType:E,dialect:x==null?void 0:x.dialect}),Je=Ke?"loading":Y?"result":"prompt",{validationResult:We,validateExpression:bt,isValidating:pt,serverError:Bt,resetValidation:ut}=Tpt({expression:we,availableFields:de,validationEndpoint:Oe,connectionId:x==null?void 0:x.id,dialect:x==null?void 0:x.dialect,fieldType:E,outputType:O||void 0,validationContext:{connectionId:(x==null?void 0:x.id)||(y==null?void 0:y.connectionId),cardId:d,cardConfig:b||{},cardDataSource:y||null,activeFilters:N,cardType:C}}),$t=We==null?void 0:We.inferredDataType,Fe=O||$t||"string",ct=v.useCallback(()=>{H(!1),q(""),W(""),Z(void 0),qe()},[qe]),It=v.useCallback(()=>{_e||!g||(W(""),Z(void 0),qe(),H(!0))},[g,_e,qe]),yt=v.useCallback(async()=>{if(!G.trim())return;const ot=await Ee(G);ot&&(W(ot.generated),Z(ot.explanation))},[G,Ee]),vt=v.useCallback(()=>{W(""),Z(void 0),qe()},[qe]),mt=v.useCallback(()=>{Y.trim()&&(D(Y),ut(),ct())},[Y,ct,ut]),St=v.useMemo(()=>{const{orderedFields:ot}=bN(we,de);return ot.filter(Rt=>!!Rt)},[de,we]),it=v.useMemo(()=>E4(St),[St]),nt=v.useMemo(()=>{if(!R.trim())return!1;const ot=D4(R);return Fmt({fields:E==="metric"?ee:ce,normalizedName:ot,existingFieldId:s==="domain"?o==null?void 0:o.id:void 0,targetKind:it.kind==="inline"?"inline":"root",targetEntityName:it.kind==="inline"?it.entityName:void 0,targetQualifiedEntityName:it.kind==="inline"?it.qualifiedEntityName:void 0})},[it,ce,ee,o,s,E,R]),gt=v.useMemo(()=>St.map(ot=>ot.id),[St]),Vt=ot=>{_e||o||k(ot)},Me=v.useCallback(()=>{T(""),D(""),M(null),L("card"),B({}),P(""),H(!1),q(""),W(""),Z(void 0),oe(null),X(null),re(!1),ut(),qe(),t(!1)},[t,ut,qe]),Qe=v.useCallback(ot=>{var Ge;const Rt=((Ge=ot.calculatedFormula)==null?void 0:Ge.inputFields)||[],Pe=ot.role==="metric"?Imt(ot):ot.expression||"";D(Te(Pe,Rt))},[Te]);v.useEffect(()=>{if(!e||S){xe.current=!1,Ie.current=null;return}const ot=o?`${o.role}-${o.id||o.name}`:"new";if(xe.current&&Ie.current===ot)return;if(xe.current=!0,Ie.current=ot,B({}),P(""),ut(),o){if(o.role==="metric"){const at=Tmt(o);k("metric"),T(o.label||o.name),L(s||"card"),oe(at.reason||null),Qe(o),M(null);return}oe(null),k("dimension");const Pe=o;T(Pe.label||Pe.name),L(s||"card"),Qe(Pe);const Ge=R2.some(at=>at.value===Pe.dataType)?Pe.dataType:"string";M(Ge);return}const Rt=h&&h.length>0?h.includes(f)?f:h[0]:f;k(Rt),T(""),D(""),M(null),oe(null),L("card")},[e,S,o,s,f,h,Qe,ut]);const $e=v.useCallback(ot=>{const Rt=typeof document<"u"?document.getElementById(pe):null;if(!Rt){D(at=>at+ot);return}const Pe=Rt.selectionStart||0,Ge=Rt.selectionEnd||0;D(at=>`${at.slice(0,Pe)}${ot}${at.slice(Ge)}`),requestAnimationFrame(()=>{Rt.focus();const at=Pe+ot.length;Rt.setSelectionRange(at,at)})},[pe]),le=ot=>{if(_e)return;const Rt=ot.tokenLabel||ot.label||ot.name;$e(`{${Rt}}`)},Ae=ot=>{_e||$e(ot)},Xe=async()=>{const ot={};return R.trim()||(ot.name="Name is required"),we.trim()||(ot.expression="Expression is required"),ot.expression||(await bt()).isValid||(ot.expression="Fix validation errors before saving"),B(ot),Object.keys(ot).length===0},Ot=()=>{const{orderedTokens:ot,orderedFields:Rt}=bN(we,de),Pe=Rt.filter(kt=>!!kt),Ge=oO(we,ot),at=Jmt(R,Ge,Pe,Fe,d,o==null?void 0:o.id);return o&&o.role==="groupby"?{...o,...at}:at},qt=()=>{const{orderedTokens:ot,orderedFields:Rt}=bN(we,de),Pe=Rt.filter(Wt=>!!Wt),Ge=Amt(Pe,(o==null?void 0:o.role)==="metric"?o:void 0),at=oO(we,ot),kt=wmt(R,"custom",null,null,{},d,o==null?void 0:o.id,at,void 0,Ge);return o&&o.role==="metric"?Dmt(o,kt):kt},Pt=async ot=>{if(ot==="domain"){B(Pe=>({...Pe,scope:"Domain scope is not available in this explorer."}));return}const Rt=E==="dimension"?Ot():qt();if(ot==="sheet"){if(!c){B(Pe=>({...Pe,scope:"Sheet scope is not available"}));return}await c(Rt),Me();return}if(ot==="dashboard"){if(!u){B(Pe=>({...Pe,scope:"Dashboard scope is not available"}));return}await u(Rt),Me();return}await a(Rt),Me()},Fn=async()=>{if(_e||(B({}),!await Xe()))return;const ot=De||Ue?V:s||"card";if(E==="metric"&&ot!=="domain"&&nt&&!o){X(ot),re(!0);return}Q(!0);try{await Pt(ot)}finally{Q(!1)}},ft=E==="metric"?Rpt:Apt,Tt=E==="metric"?"Metric formula":"Column expression",ke=De||Ue,Ve=h||["metric","dimension"];return l.jsxs(l.Fragment,{children:[l.jsxs(To,{modal:!1,open:e,onOpenChange:ot=>{ot?t(!0):Me()},children:[e&&l.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-background/80 backdrop-blur-sm"}),l.jsxs(bo,{className:"max-w-3xl max-h-[90vh] gap-0 overflow-hidden p-0",onInteractOutside:ot=>{ot.preventDefault()},children:[l.jsxs($s,{className:"space-y-0 border-b py-3 pl-5 pr-12",children:[l.jsx(yo,{className:"text-[13px] font-medium",children:o?"Edit calculated field":"New calculated field"}),l.jsx(Ho,{className:"sr-only",children:"Build a calculated dimension or metric using expressions."})]}),l.jsxs("div",{className:"flex max-h-[calc(80vh-180px)] min-h-0 flex-col gap-4 overflow-y-auto px-5 py-4",children:[S&&l.jsx(Dpt,{status:i||"unverified"}),fe&&l.jsxs("div",{className:"rounded-control border border-border bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:[l.jsx("p",{className:"font-medium text-foreground",children:"Read-only legacy metric"}),l.jsx("p",{children:fe})]}),l.jsxs("div",{className:"grid grid-cols-[120px_1fr] items-center gap-3",children:[l.jsx(m.Label,{htmlFor:"calculated-name",className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Name"}),l.jsx(m.Input,{id:"calculated-name",value:R,onChange:ot=>T(ot.target.value),placeholder:"Field name","aria-invalid":!!A.name,size:"xs",className:`max-w-sm ${A.name?"border-destructive":""}`,disabled:_e}),A.name&&l.jsx("p",{className:"col-start-2 text-xs text-destructive",children:A.name})]}),l.jsxs("div",{className:"grid grid-cols-[120px_1fr] items-center gap-3",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),l.jsx(ept,{value:E,onChange:Vt,disabled:_e||!!o,options:Ve}),l.jsx("p",{className:"col-start-2 text-[11px] text-muted-foreground",children:Nmt(E)})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsxs("div",{className:"flex items-center gap-2 whitespace-nowrap",children:[l.jsx(m.Label,{htmlFor:pe,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:Tt}),l.jsxs("a",{href:Mpt,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-0.5 text-[11px] text-muted-foreground hover:text-foreground",children:["Docs"," ",l.jsx($d,{className:"relative top-px h-2.5 w-2.5","aria-hidden":!0})]})]}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(ipt,{groups:ue,searchTerm:$,onSearchTermChange:P,onFieldSelect:le,selectedFieldIds:gt,unavailableFieldReasons:r,disabled:_e||U}),E==="metric"&&l.jsx(apt,{onInsert:Ae,disabled:_e||U}),!!ye&&g&&!_e&&l.jsxs(m.Button,{type:"button",variant:U?"default":"outline",size:"xs",onClick:It,disabled:U,className:"gap-1.5",children:[l.jsx(Ov,{className:"h-3 w-3","aria-hidden":!0}),U?"Composing…":"Generate"]})]})]}),U?l.jsx(opt,{mode:Je,fieldType:E,prompt:G,onPromptChange:q,generated:Y,explanation:ne,isGenerating:Ke,error:He,onGenerate:()=>void yt(),onTryAgain:vt,onCancel:ct,onUseDraft:mt}):l.jsxs(l.Fragment,{children:[l.jsx("div",{"aria-invalid":!!A.expression,className:`overflow-hidden rounded-control border ${A.expression?"border-destructive":"border-input"}`,children:l.jsx("div",{className:"h-[112px]",children:l.jsx(m.CodeEditor,{value:we,onValueChange:D,language:"sql-jinja",placeholder:ft,ariaLabel:E==="metric"?"Metric formula":"Column expression",textareaId:pe,readOnly:_e,embedded:!0,hideLineNumbers:!0,wrapLines:!0,dense:!0})})}),l.jsx(npt,{onValidate:bt,isValidating:pt,validationResult:We,error:Bt,disabled:_e}),A.expression&&l.jsx("p",{className:"text-xs text-destructive",children:A.expression})]})]}),E==="dimension"&&l.jsxs("div",{className:"grid grid-cols-[120px_1fr] items-center gap-3",children:[l.jsx(m.Label,{htmlFor:"calculated-output-type",className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Output type"}),l.jsxs(m.Select,{value:Fe,onValueChange:ot=>M(ot),disabled:_e,children:[l.jsx(m.SelectTrigger,{id:"calculated-output-type",size:"xs",className:"w-44",children:l.jsx(m.SelectValue,{placeholder:"Select output type"})}),l.jsx(m.SelectContent,{children:R2.map(ot=>l.jsx(m.SelectItem,{value:ot.value,children:ot.label},ot.value))})]}),$t&&!O&&l.jsxs("p",{className:"col-start-2 text-[11px] text-muted-foreground",children:["Suggested type: ",$t]})]}),l.jsxs("div",{className:"grid grid-cols-[120px_1fr] items-center gap-3",children:[l.jsx(m.Label,{htmlFor:ke?"calculated-availability":void 0,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Availability"}),ke?l.jsxs(m.Select,{value:V,onValueChange:ot=>L(ot),disabled:_e,children:[l.jsx(m.SelectTrigger,{id:"calculated-availability",size:"xs",className:"w-44",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"card",children:Kp("card")}),De&&l.jsx(m.SelectItem,{value:"sheet",children:Kp("sheet")}),Ue&&l.jsx(m.SelectItem,{value:"dashboard",children:Kp("dashboard")})]})]}):l.jsx("span",{className:"text-[12px] text-foreground",children:Kp(s||"card")}),A.scope&&l.jsx("p",{className:"col-start-2 text-xs text-destructive",children:A.scope})]})]}),l.jsx(dpt,{inlineAnalysis:it,hasInputFields:St.length>0}),l.jsxs(ll,{className:"gap-1.5 border-t px-5 py-2.5",children:[l.jsx(m.Button,{variant:"outline",size:"xs",onClick:Me,disabled:te,children:"Cancel"}),l.jsx(m.Button,{size:"xs",onClick:()=>void Fn(),disabled:te||pt||_e,children:te?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"mr-1.5 h-3 w-3 animate-spin"}),"Applying…"]}):ve||S?"Read-only":"Apply"})]})]})]}),l.jsx(ff,{open:J,onOpenChange:re,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Name conflict"}),l.jsxs(Ru,{children:['A domain metric named "',R.trim(),'" already exists. Your local version will override it for the selected availability:'," ",Kp(K||"card"),". Continue?"]})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{onClick:()=>{X(null)},children:"Choose different name"}),l.jsx(Au,{onClick:async()=>{if(K){re(!1),Q(!0);try{await Pt(K)}finally{Q(!1),X(null)}}},children:"Continue"})]})]})})]})}function Fpt(e,t){const n=e.fieldScope==="sheet"||e.fieldScope==="dashboard";if(e.role==="metric"){const r=t.metricFields.find(o=>m.matchesCalculatedField(o,e,{allowComparableFallback:n}));if(r)return r}if(e.role==="groupby"){const r=t.groupByFields.find(o=>m.matchesCalculatedField(o,e,{allowComparableFallback:n}));if(r)return r}return t.storedCalculatedFields.find(r=>m.matchesCalculatedField(r,e,{allowComparableFallback:n}))}function Ppt(e,t){const n=en.readExactDomainCalculatedFieldReference(e);if(!n)return;const r=t.filter(o=>o.fieldScope==="domain"&&en.getStableDomainCalculatedFieldId(o)===n);return r.length===1?r[0]:void 0}function Opt(e,t){const n=ze.getCalculatedFieldComputeStage(t)||ze.getCalculatedFieldComputeStage(e);if(t={...t,...Es.getCalculatedFieldShelfOverrides(e),role:e.role,calculatedFieldOrigin:t.calculatedFieldOrigin||e.calculatedFieldOrigin,calculatedFormula:t.calculatedFormula?{...t.calculatedFormula,computeStage:n}:void 0},t={...t,...Es.getCalculatedFieldAggregateOverrides(e,t,"selection")},e.role==="metric"&&t.role==="metric"){const r=e,o=t;return{...o,parameters:Es.getCalculatedFieldParameters(r,o,o.fieldScope==="domain"?"domain":"local"),aliasTemplate:r.aliasTemplate??o.aliasTemplate,valueAliases:r.valueAliases??o.valueAliases,customFormat:r.customFormat??o.customFormat,comparison:r.comparison??o.comparison,comparisonPolarity:r.comparisonPolarity??o.comparisonPolarity}}if(e.role==="groupby"&&t.role==="groupby"){const r=e,o=t,s=r.granularity??o.granularity,i=s&&m.getDataType(r.dataType)==="date"?m.readTemporalBucketAuthoringSelectionWithOverride({fieldId:o.id,dataType:o.dataType,granularity:s,format:o.format,dateFormat:o.dateFormat,customFormat:o.customFormat,semanticTemporalPresentation:r.semanticTemporalPresentation??o.semanticTemporalPresentation},{format:r.format,dateFormat:r.dateFormat,customFormat:r.customFormat}).format:r.format??o.format;return{...o,granularity:s,format:i,dateFormat:void 0,customFormat:void 0,timeDrillPath:r.timeDrillPath??o.timeDrillPath}}return t}function Lpt(e,t){return{...ze.normalizeCalculatedFieldRepresentation(e),fieldScope:t}}function $pt(e,t,n){return m.matchesCalculatedField(e,t,n)?!0:e.role&&t.role&&e.role!==t.role?m.matchesCalculatedField(e,{...t,role:e.role},n):!1}function HW(e,t,n,r){if(!(e!=null&&e.length)||!n)return null;const o=e.findIndex(c=>$pt(c,n,r));if(o<0)return null;const s=e[o],i=Opt(s,t),a=s.id&&s.id!==i.id?{...i,id:s.id}:i;return e.map((c,u)=>u===o?a:c)}function zpt(e,t,n,r){const o={};for(const s of["metricColumns","groupByColumns","pivotByColumns","detailColumns","sortByColumns"]){const i=e==null?void 0:e[s];if(!i)continue;const a=s==="sortByColumns"||n.role==="metric"&&s==="metricColumns"||n.role==="groupby"&&s==="groupByColumns";let c=!1;const u=i.map(d=>{const h=HW([d],n,t)||(r!=null&&r.allowLegacyComparableFallback&&a?HW([d],n,t,{allowComparableFallback:!0}):null);return h?(c=!0,h[0]):d});c&&Object.assign(o,{[s]:u})}return o}function Bpt(e,t){const n=e==="sheet"||e==="dashboard";return{destinationComparableFallback:t!=="card"||n,selectionComparableFallback:n,removeSource:e!==t&&(e==="card"||n)}}function L4(e){const t=Bpt(e.previousScope,e.targetScope),n=Lpt(e.updatedField,e.targetScope),r={...e.collections};if(r[e.targetScope]=m.upsertCalculatedField(r[e.targetScope]||[],n,e.editingField,{allowComparableFallback:t.destinationComparableFallback}),t.removeSource&&e.editingField){const s=e.previousScope;r[s]&&(r[s]=m.removeCalculatedField(r[s],e.editingField,{allowComparableFallback:!0}))}const o=e.editingField&&e.cardConfig?zpt(e.cardConfig,e.editingField,n,{allowLegacyComparableFallback:t.selectionComparableFallback}):{};return{collections:r,cardConfigPatch:o}}function sO(e){const t=e.previousScope==="dashboard"?"dashboard":"sheet",n=L4({...e,targetScope:"card",collections:{card:e.storedFields,[t]:e.sharedFields}});return{nextStoredFields:n.collections.card,nextSharedFields:n.collections[t],cardConfigPatch:n.cardConfigPatch}}function iO(e){const t=L4({...e,targetScope:"sheet",collections:{card:e.storedFields,sheet:e.sheetFields,dashboard:e.dashboardFields}});return{nextStoredFields:t.collections.card,nextSheetFields:t.collections.sheet,nextDashboardFields:t.collections.dashboard,cardConfigPatch:t.cardConfigPatch}}function lpe(e){const t=L4({...e,targetScope:"dashboard",collections:{card:e.storedFields,sheet:e.sheetFields,dashboard:e.sharedFields}});return{nextStoredFields:t.collections.card,nextSharedFields:t.collections.dashboard,nextSheetFields:t.collections.sheet,cardConfigPatch:t.cardConfigPatch}}function Jf(e){const{nextSharedFields:t,currentSharedFields:n,isVisualEditing:r,selectedSheetId:o,updateFrame:s,updateSheetCalculatedFields:i,currentFrame:a,nextFramePatch:c,persistFrame:u,persistFrames:d}=e,f=c?{...c,calculatedFields:t}:{calculatedFields:t};(t!==n||c)&&s(f),o&&(r||(u&&(d!=null&&d.length)?d.forEach(h=>{u(o,{...h,calculatedFields:void 0})}):u&&a&&c&&u(o,{...a,...c,calculatedFields:void 0}),i&&i(o,t)))}const y1="scope-calculated",Vpt=[];function v1({label:e,count:t,active:n,onClick:r,ariaLabel:o,disabled:s=!1}){return l.jsxs("button",{type:"button",onClick:r,disabled:s,"aria-label":o,"aria-pressed":n,className:m.cn("-mb-px inline-flex items-center gap-1 border-b-2 px-0.5 pb-2 pt-1 text-[12px] transition-colors disabled:cursor-wait",n?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:[l.jsx("span",{children:e}),l.jsx("span",{className:m.cn("font-mono text-[10px] tabular-nums",n?"text-muted-foreground":"text-muted-foreground/70"),children:t})]})}const $4=v.memo(function({context:t="editor",onFieldSelect:n,inlineFilters:r}={}){const[o,s]=v.useState(""),[i,a]=v.useState("all"),c=v.useRef(null),u=v.useRef(null),[d,f]=v.useState(!1),h=(ke,Ve)=>(dt,_t,Xt)=>{var wn;(wn=u.current)==null||wn.hover(ke,Ve,dt,_t,Xt)},[p,g]=v.useState(!1),[x,b]=v.useState(null),[y,C]=v.useState("card"),[w,N]=v.useState("metric"),[S,j]=v.useState(null),[k,_]=v.useState(!1);m.useEditorStore(ke=>ke.isDevMode);const T=m.useEditorStore(ke=>ke.card.dataSource),I=m.useEditorStore(ke=>ke.card.config),D=m.useEditorStore(ke=>ke.card),E=m.useEditorStore(ke=>ke.frame),R=m.useEditorStore(ke=>ke.actions.updateCardConfig),F=m.useEditorStore(ke=>ke.actions.updateCard),M=m.useEditorStore(ke=>ke.actions.updateFrame),O=m.useDashboardStore(ke=>ke.isVisualEditing),z=m.useDashboardStore(ke=>ke.selectedSheetId),L=m.useDashboardStore(ke=>ke.actions.updateSheetCalculatedFields),V=m.useDashboardStore(ke=>ke.actions.updateDashboardCalculatedFields),B=m.useDashboardStore(ke=>{var Ve;return ke.visualEditPendingDashboardCalculatedFields??((Ve=ke.dashboard)==null?void 0:Ve.calculatedFields)})??Vpt,{userContext:$}=hi(),{rawColumnGroups:P,scopedFields:U,filterableFields:H,dashboardFilterableFields:G,inlineFilterableFields:q,scopedCalculatedFields:Y,sharedCalculatedFields:W,inlineCalculatedFields:ne,isLoading:Z,error:K}=N4(),{reconcileMatrixCalculation:X,handleFieldClick:J}=Lme(D,U),re=v.useMemo(()=>{const ke={};return P.forEach(Ve=>{Ve.label&&(ke[Ve.entityName]=Ve.label)}),ke},[P]),te=j4(D,{extraDatasetLabels:re}),Q=D.config,se=D.type,oe=v.useMemo(()=>{const ke=se==="matrixTable"?wd({config:Q,dataSource:T},U):[];return m.getAuthoredCardFieldList({type:se,config:Q},ke)},[se,Q,T,U]);Bme();const fe=t==="editor"?Y:t==="filter"||t==="document-filter"?W:ne,pe=t==="editor"?fe.filter(ke=>en.getCalculatedFieldNamespace(ke)==="root"):fe,xe=pe.length>0,Ie=O4($),be=t==="editor"?H||U:t==="filter"||t==="document-filter"?G:q,ge=P,ee=o.toLowerCase(),ce=(I==null?void 0:I.metricColumns)||[],ae=(I==null?void 0:I.groupByColumns)||[];I!=null&&I.sortByColumns;const me=D.calculatedFields||[],ve=ke=>hb(ke,ee),_e=v.useCallback((ke,Ve)=>Xue(ke,Ve),[]),De=be.filter(ve).sort(_e),Ue=v.useCallback(ke=>t==="editor"?jb(ke):il(ke),[t]),Ne=ke=>{if(Ue(ke))return"calculated";if(ke.dataType==="number"||ke.dataType==="integer"||ke.dataType==="float"||ke.dataType==="decimal"||ke.dataType==="currency")return"metrics";const Ve=m.getDataType(ke.dataType);return["date","string","boolean"].includes(Ve)?"dimensions":Ve==="number"?"metrics":"dimensions"},Oe=ke=>{const Ve=ke.filter(ve);return i==="all"?Ve:Ve.filter(dt=>Ne(dt)===i)},ye=i==="all"?De:De.filter(ke=>Ne(ke)===i),Be=xe?Oe(pe).sort(_e):[],he=v.useCallback(ke=>Ue(ke)&&(t!=="editor"||en.getCalculatedFieldNamespace(ke)==="root"),[t,Ue]),ue=be.filter(ke=>!he(ke)),Te=Oe(ue).sort(_e).reduce((ke,Ve)=>{const dt=Ve.qualifiedEntityName||"Other Fields";return ke[dt]||(ke[dt]={label:m.toLabel(Ve.entityName),fields:[]}),ke[dt].fields.push(Ve),ke},{}),we=v.useMemo(()=>Object.entries(Te).map(([ke,Ve])=>{const dt=ge.find(Xt=>Xt.entityName===ke)||{entityName:ke,label:Ve.label},_t=ke===lt.CALCULATED_FIELDS_GROUP_NAME?"Domain Calculated Fields":dt.label||dt.entityName;return{groupName:ke,groupLabel:_t,fields:[...Ve.fields].sort(_e)}}).sort((ke,Ve)=>ke.groupLabel.localeCompare(Ve.groupLabel,void 0,{numeric:!0,sensitivity:"base"})),[Te,ge,_e]),Ee=ke=>ke.id||`${ke.entityName}-${ke.qualifiedEntityName}-${ke.name}-${ke.role||"field"}`,Ke=v.useMemo(()=>{const ke=new Map;return be.forEach(dt=>{ke.set(Ee(dt),iF(dt,{...te,selectedFields:oe}))}),pe.forEach(dt=>{const _t=Ee(dt);ke.has(_t)||ke.set(_t,iF(dt,{...te,selectedFields:oe}))}),ke},[be,pe,te,oe]),He=v.useMemo(()=>{const ke={};return Ke.forEach((Ve,dt)=>{fm(Ve.state)&&Ve.reason&&(ke[dt]=Ve.reason)}),ke},[Ke]),qe=6,[Je,We]=v.useState(!1),bt=i==="calculated"&&Ie&&t==="editor"&&pe.length===0,pt=Be.length>0?[{key:y1,label:"Calculated Fields",fields:Be}]:bt?[{key:y1,label:"Calculated Fields",fields:[]}]:[],Bt=[...pt.map(ke=>ke.key),...we.map(ke=>ke.groupName)],[ut,$t]=v.useState(()=>new Set(t==="editor"?[y1]:[])),Fe=i==="calculated"||o.trim().length>0,ct=Bt.filter(ke=>!ut.has(ke)||ke===y1&&Fe),It=ke=>{const Ve=new Set(ke);$t(new Set(Bt.filter(dt=>!Ve.has(dt))))},yt=De.filter(ke=>Ne(ke)==="dimensions").length,vt=De.filter(ke=>Ne(ke)==="metrics").length,mt=De.filter(ke=>Ne(ke)==="calculated").length,St=(De.length>0||Z&&t==="filter")&&t!=="inline-filter"&&t!=="document-filter",it=t==="filter"||t==="inline-filter"||t==="document-filter"?"w-full":"w-[290px]";if(Z&&t!=="filter")return l.jsx("div",{className:m.cn("flex h-full flex-col items-center justify-center py-8",it),children:l.jsx(Cu,{size:"md",color:"muted","aria-label":"Loading data"})});if(K)return l.jsxs("div",{className:m.cn("flex h-full flex-col items-center justify-center py-8",it),children:[l.jsx(ps,{className:"mb-3 h-8 w-8 text-destructive/40"}),l.jsx("p",{className:"mb-1 text-[12px] text-destructive",children:"Error loading fields"}),l.jsx("p",{className:"px-4 text-center text-[11px] leading-[1.45] text-muted-foreground",children:K.message||"Failed to load column data"})]});if(!T||!T.selectedEntities||T.selectedEntities.length===0)return l.jsxs("div",{className:m.cn("flex flex-col items-center justify-center py-8 text-center",it),children:[l.jsx(ps,{className:"mb-3 h-8 w-8 text-muted-foreground/40"}),l.jsx("p",{className:"mb-1 text-[12px] text-foreground",children:"No data source selected"}),l.jsx("p",{className:"px-4 text-[11px] leading-[1.45] text-muted-foreground",children:t==="filter"||t==="inline-filter"||t==="document-filter"?"Configure a data source for this card to see available fields":"Select a table, view, or dataset from the data source panel to see available fields"})]});const nt=t==="inline-filter"||t==="document-filter"?"pb-3":"pb-2",gt=t==="inline-filter"||t==="document-filter"?"overflow-hidden":"",Vt=ke=>Fpt(ke,{storedCalculatedFields:me,metricFields:ce,groupByFields:ae}),Me=ke=>m.resolveLocalCalculatedFieldScope({field:ke,sheetFields:(E==null?void 0:E.calculatedFields)||[],dashboardFields:B}),Qe=(ke,Ve)=>{F(D.id,{calculatedFields:m.removeCalculatedField(me,ke,Ve)})},$e=ke=>{var Ve;return(Ve=E==null?void 0:E.calculatedFields)==null?void 0:Ve.find(dt=>m.matchesCalculatedField(dt,ke))},le=ke=>B.find(Ve=>m.matchesCalculatedField(Ve,ke,{allowComparableFallback:!0})),Ae=(ke,Ve)=>{if(!X(ke)){if(ke.role==="metric"){R(D.id,{metricColumns:m.removeCalculatedField(ce,ke,Ve)});return}ke.role==="groupby"&&R(D.id,{groupByColumns:m.removeCalculatedField(ae,ke,Ve)})}},Xe=ke=>{V(m.removeCalculatedField(B,ke,{allowComparableFallback:!0}))},Ot=(ke,Ve)=>{try{return X(x??void 0,{...ke,fieldScope:Ve}),!0}catch(dt){return m.ue.error(dt instanceof Error?dt.message:"The calculation could not be updated."),!1}},qt=ke=>{if(!E)return;const Ve=m.removeCalculatedField(E.calculatedFields||[],ke);Jf({nextSharedFields:Ve,currentSharedFields:E.calculatedFields||[],isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L})},Pt=ke=>{var _t;if(!Ie)return;if((_t=u.current)==null||_t.clear(),ke.fieldScope==="domain"){m.ue.error("Domain calculated fields are read-only in this explorer.");return}const Ve=Me(ke);if(Ve.scope==="sheet"){const Xt=Ve.matchedField||$e(ke);if(!Xt)return;b(Xt),C("sheet"),N(Xt.role==="metric"?"metric":"dimension"),g(!0);return}if(Ve.scope==="dashboard"){const Xt=Ve.matchedField||le(ke);if(!Xt)return;b(Xt),C("dashboard"),N(Xt.role==="metric"?"metric":"dimension"),g(!0);return}const dt=Vt(ke);dt&&(b(dt),C("card"),N(dt.role==="metric"?"metric":"dimension"),g(!0))},Fn=async ke=>{if(!Ie)return;if(ke.fieldScope==="domain"){m.ue.error("Domain calculated fields are read-only in this explorer.");return}const Ve=Me(ke),dt={allowComparableFallback:Ve.scope!=="card"};if(Ve.scope==="sheet"){Ae(ke,dt),qt(Ve.matchedField||ke);return}if(Ve.scope==="dashboard"){Ae(ke,dt),Xe(Ve.matchedField||ke);return}Ae(ke,dt),Qe(ke,dt)},ft=async()=>{if(S){_(!0);try{await Fn(S),j(null)}catch(ke){m.ue.error(ke instanceof Error?ke.message:"The calculation could not be deleted.")}finally{_(!1)}}},Tt=ke=>!Ie||ke.fieldScope==="domain"?null:l.jsxs(Bo,{onOpenChange:Ve=>{var dt;f(Ve),Ve&&((dt=u.current)==null||dt.clear())},children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":"Calculated field actions",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(Ai,{className:"h-3 w-3"})})}),l.jsx(_o,{align:"end",className:"w-36",children:l.jsxs(l.Fragment,{children:[l.jsx(ln,{onClick:()=>Pt(ke),children:"Edit"}),l.jsx(ln,{className:"text-destructive focus:text-destructive",onClick:()=>j(ke),children:"Delete"})]})})]});return l.jsxs(l.Fragment,{children:[l.jsxs("div",{ref:c,className:m.cn("relative flex h-full w-full grow flex-col",nt,gt),children:[l.jsxs("div",{className:"flex-shrink-0 space-y-2 px-4 pt-2",children:[(be.length>0||Z)&&l.jsxs("div",{className:"flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring",children:[l.jsx(Ft.Search,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),l.jsx("input",{type:"text",placeholder:"Search fields",value:o,onChange:ke=>s(ke.target.value),disabled:Z,className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-wait"}),o&&l.jsx("button",{type:"button","aria-label":"Clear search",onClick:()=>s(""),className:"inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:l.jsx(Re.X,{className:"h-3 w-3"})})]}),St&&l.jsxs("div",{className:"-mx-4 flex items-center gap-4 border-b border-border px-4",children:[l.jsx(v1,{label:"All",count:De.length,active:i==="all",onClick:()=>a("all"),disabled:Z}),l.jsx(v1,{label:"Dim",count:yt,active:i==="dimensions",onClick:()=>a(ke=>ke==="dimensions"?"all":"dimensions"),ariaLabel:"Dimensions",disabled:Z}),l.jsx(v1,{label:"Metric",count:vt,active:i==="metrics",onClick:()=>a(ke=>ke==="metrics"?"all":"metrics"),ariaLabel:"Metrics",disabled:Z}),l.jsx(v1,{label:"Calc",count:mt,active:i==="calculated",onClick:()=>a(ke=>ke==="calculated"?"all":"calculated"),ariaLabel:"Calculated",disabled:Z})]})]}),Z?l.jsx("div",{role:"status","aria-label":"Loading fields",className:"flex min-h-0 flex-1 items-center justify-center",children:l.jsx(Cu,{size:"md",color:"muted"})}):l.jsxs($u,{className:"min-h-0 flex-1 [&>[data-radix-scroll-area-viewport]>div]:!block [&>[data-radix-scroll-area-viewport]>div]:w-full",children:[l.jsxs(ope,{type:"multiple",value:ct,onValueChange:It,className:"space-y-2",children:[pt.map(ke=>l.jsxs(Pk,{value:ke.key,className:"border-none",children:[l.jsxs(Ok,{className:"group flex w-full items-center gap-1.5 rounded-[4px] px-4 py-1.5 text-left hover:bg-muted hover:no-underline [&>svg]:order-first [&>svg]:h-3 [&>svg]:w-3 [&>svg]:-rotate-90 [&>svg]:text-muted-foreground/70 data-[state=open]:[&>svg]:rotate-90",children:[l.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[l.jsx("span",{className:"max-w-[180px] truncate text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:ke.label}),l.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:ke.fields.length})]}),t==="editor"&&Ie&&l.jsx("span",{role:"button",tabIndex:0,"aria-label":"Add calculated field",title:"Add calculated field",onClick:Ve=>{Ve.stopPropagation(),b(null),C("card"),N("dimension"),g(!0)},onKeyDown:Ve=>{(Ve.key==="Enter"||Ve.key===" ")&&(Ve.preventDefault(),Ve.stopPropagation(),b(null),C("card"),N("dimension"),g(!0))},className:"inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(Ar,{className:"h-3 w-3"})})]}),l.jsx(Lk,{className:"pb-1",children:l.jsxs("div",{children:[ke.fields.length===0&&bt&&l.jsx("p",{className:"px-4 py-2 text-[11px] text-muted-foreground",children:"No calculated fields yet — click + to add."}),(()=>{const Ve=ke.fields.filter(cn=>{var ot;return fm((ot=Ke.get(Ee(cn)))==null?void 0:ot.state)}),dt=!o&&Ve.length>=qe,_t=dt?ke.fields.filter(cn=>!Ve.includes(cn)):ke.fields,Xt=dt?Ve:[],wn=cn=>{const ot=Ke.get(Ee(cn)),Rt=t==="editor"&&Ie&&il(cn);return l.jsx(BW,{onAddField:J,field:cn,context:t,fieldState:ot,onFieldSelect:n,inlineFilters:t==="inline-filter"||t==="document-filter"?r:void 0,actions:Rt?Tt(cn):void 0,hideActions:Rt&&cn.fieldScope==="domain",onHover:h(cn,ot)},cn.id)};return l.jsxs(l.Fragment,{children:[_t.map(wn),Xt.length>0&&l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button","aria-expanded":Je,onClick:()=>We(cn=>!cn),className:"flex h-7 w-full items-center gap-1.5 px-4 text-left text-[11px] text-muted-foreground hover:bg-muted/60 hover:text-foreground",children:[l.jsx(Ft.ChevronRight,{className:m.cn("h-3 w-3 transition-transform",Je&&"rotate-90"),"aria-hidden":!0}),"Unavailable with this visual",l.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:Xt.length})]}),Je&&Xt.map(wn)]})]})})()]})})]},ke.key)),we.map(({groupName:ke,groupLabel:Ve,fields:dt})=>l.jsxs(Pk,{value:ke,className:"border-none",children:[l.jsx(Ok,{className:"group flex w-full items-center gap-1.5 rounded-[4px] px-4 py-1.5 text-left hover:bg-muted hover:no-underline [&>svg]:order-first [&>svg]:h-3 [&>svg]:w-3 [&>svg]:-rotate-90 [&>svg]:text-muted-foreground/70 data-[state=open]:[&>svg]:rotate-90",children:l.jsxs("div",{title:Ve,className:"flex min-w-0 flex-1 items-center gap-1.5",children:[l.jsx("span",{className:"max-w-[180px] truncate text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:Ve}),l.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:dt.length})]})}),l.jsx(Lk,{className:"pb-2",children:l.jsx("div",{className:"space-y-1",children:dt.map(_t=>{const Xt=Ke.get(Ee(_t)),wn=t==="editor"&&Ie&&il(_t);return l.jsx(BW,{onAddField:J,field:_t,context:t,fieldState:Xt,onFieldSelect:n,inlineFilters:t==="inline-filter"||t==="document-filter"?r:void 0,actions:wn?Tt(_t):void 0,hideActions:wn&&_t.fieldScope==="domain",onHover:h(_t,Xt)},_t.id)})})})]},ke))]}),be.length===0&&l.jsxs("div",{className:"px-4 py-6 text-center",children:[l.jsx("p",{className:"text-[12px] text-foreground",children:"No fields found for selected data source"}),l.jsx("p",{className:"mt-1 text-[11px] leading-[1.45] text-muted-foreground",children:t==="filter"?"The selected data source has no available fields":"Try selecting different data sources"})]}),be.length>0&&ye.length===0&&!bt&&l.jsx("div",{className:"py-4 text-center text-[11px] text-muted-foreground",children:"No fields found for this category"}),l.jsx(m.ScrollBar,{orientation:"vertical"})]})]}),l.jsx(zmt,{ref:u,wrapperRef:c,disabled:d}),l.jsx(ff,{open:!!S,onOpenChange:ke=>{ke||j(null)},children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete calculated field?"}),l.jsxs(Ru,{children:["This will remove"," ",l.jsx("span",{className:"font-medium text-foreground",children:(S==null?void 0:S.label)||(S==null?void 0:S.name)||"this calculated field"})," ",(S==null?void 0:S.fieldScope)==="domain"?"from the semantic domain.":"from this configuration."]})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{disabled:k,children:"Cancel"}),l.jsx(Au,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:k,onClick:ke=>{ke.preventDefault(),ft()},children:k?"Deleting...":"Delete"})]})]})}),l.jsx(ape,{open:p,onOpenChange:ke=>{g(ke),ke||(b(null),C("card"))},availableFields:U,unavailableFieldReasons:He,existingField:x??void 0,existingFieldScope:y,initialFieldType:w,onSave:ke=>{if(D.type==="matrixTable"&&!Ot(ke,"card"))return;const Ve=x,dt=y==="dashboard"?B:(E==null?void 0:E.calculatedFields)||[];if(ke.role==="metric"){const{cardConfigPatch:cn,nextStoredFields:ot,nextSharedFields:Rt}=sO({cardConfig:D.config,storedFields:me,sharedFields:dt,updatedField:ke,editingField:Ve,previousScope:y});Object.keys(cn).length&&R(D.id,cn),F(D.id,{calculatedFields:ot}),y==="dashboard"&&Rt!==dt?V(Rt):E&&Rt!==dt&&Jf({nextSharedFields:Rt,currentSharedFields:dt,isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L});return}const{cardConfigPatch:_t,nextStoredFields:Xt,nextSharedFields:wn}=sO({cardConfig:D.config,storedFields:me,sharedFields:dt,updatedField:ke,editingField:Ve,previousScope:y});Object.keys(_t).length&&R(D.id,_t),F(D.id,{calculatedFields:Xt}),y==="dashboard"&&wn!==dt?V(wn):E&&wn!==dt&&Jf({nextSharedFields:wn,currentSharedFields:dt,isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L})},onSaveToSheet:ke=>{if(D.type==="matrixTable"&&!Ot(ke,"sheet"))return;const Ve=x,dt=(E==null?void 0:E.calculatedFields)||[];if(ke.role==="metric"){const{cardConfigPatch:ot,nextStoredFields:Rt,nextSheetFields:Pe,nextDashboardFields:Ge}=iO({cardConfig:D.config,storedFields:me,sheetFields:dt,dashboardFields:B,updatedField:ke,editingField:Ve,previousScope:y});E&&Jf({nextSharedFields:Pe,currentSharedFields:dt,isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L}),Ge&&Ge!==B&&V(Ge),Object.keys(ot).length&&R(D.id,ot),F(D.id,{calculatedFields:Rt});return}const{cardConfigPatch:_t,nextStoredFields:Xt,nextSheetFields:wn,nextDashboardFields:cn}=iO({cardConfig:D.config,storedFields:me,sheetFields:dt,dashboardFields:B,updatedField:ke,editingField:Ve,previousScope:y});E&&Jf({nextSharedFields:wn,currentSharedFields:dt,isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L}),cn&&cn!==B&&V(cn),Object.keys(_t).length&&R(D.id,_t),F(D.id,{calculatedFields:Xt})},onSaveToDashboard:ke=>{if(D.type==="matrixTable"&&!Ot(ke,"dashboard"))return;const Ve=x,dt=(E==null?void 0:E.calculatedFields)||[],{cardConfigPatch:_t,nextStoredFields:Xt,nextSharedFields:wn,nextSheetFields:cn}=lpe({cardConfig:D.config,storedFields:me,sharedFields:B,sheetFields:dt,updatedField:ke,editingField:Ve,previousScope:y});V(wn),E&&cn&&cn!==dt&&Jf({nextSharedFields:cn,currentSharedFields:dt,isVisualEditing:O,selectedSheetId:z,updateFrame:M,updateSheetCalculatedFields:L}),Object.keys(_t).length&&R(D.id,_t),F(D.id,{calculatedFields:Xt})},cardId:D.id})]})}),cpe=v.memo(function({context:t,className:n,inlineFilters:r,onFieldSelect:o}){return l.jsx("div",{"data-content":"filterable-fields-panel",className:m.cn("flex min-h-0 grow flex-col overflow-hidden",n),children:l.jsx(Sb,{collisionDetection:wb,children:l.jsx(Nb,{items:[],strategy:y4,children:l.jsx($4,{context:t,inlineFilters:r,onFieldSelect:o})})})})}),Hpt=/{{\s*([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?\s*}}/g,qpt=new Set(["generatedAt","pageNumber","pageCount"]),z4="document",Upt=/^(\d{4})-(\d{2})-(\d{2})$/;function Kpt(e,t){const n=[],r=[];let o=0;for(const s of e.matchAll(Hpt)){const i=s[0],a=s.index??0;a>o&&n.push({type:"text",value:e.slice(o,a),sourceStart:o,sourceEnd:a});const c=Ypt({aliasOrKey:s[1],exportKey:s[2],inputs:t});c?n.push({type:"variable",ref:c,sourceStart:a,sourceEnd:a+i.length}):(n.push({type:"text",value:i,sourceStart:a,sourceEnd:a+i.length}),r.push(i)),o=a+i.length}return o<e.length&&n.push({type:"text",value:e.slice(o),sourceStart:o,sourceEnd:e.length}),{content:n,unresolvedTokens:r}}function Wpt(e){return[...e.flatMap(n=>V4(n).map(r=>({label:`${n.variableName}.${r}`,token:`{{${n.variableName}.${r}}}`,ref:{source:"input",inputId:n.id,export:r}}))),{label:yN("generatedAt",e),token:A2("generatedAt",e),ref:{source:"documentMeta",key:"generatedAt"}},{label:yN("pageNumber",e),token:A2("pageNumber",e),ref:{source:"documentMeta",key:"pageNumber"}},{label:yN("pageCount",e),token:A2("pageCount",e),ref:{source:"documentMeta",key:"pageCount"}}]}function B4(e,t){if(e.source==="documentMeta")return yN(e.key,t);const n=t.find(r=>r.id===e.inputId);return`${(n==null?void 0:n.variableName)||e.inputId}.${e.export}`}function Gpt({inputs:e,filterValuesByInputId:t,controlValuesByInputId:n,controlOptionsByInputId:r={},generatedAt:o,timezone:s,generatedAtFormat:i,pageNumber:a=1,pageCount:c=1}){const u={};for(const d of e)u[d.id]=d.kind==="filter"?Xpt(d,t[d.id],s):Qpt(d,n[d.id],s,r[d.id]);return{inputs:e,resolvedInputsById:u,timezone:s,generatedAtFormat:i,meta:{generatedAt:o,pageNumber:a,pageCount:c}}}function upe(e,t){return(e==null?void 0:e.map(n=>n.type==="text"?{type:"text",value:n.value,...n.format?{format:n.format}:{}}:{type:"variable",value:Zpt(n.ref,t),...n.format?{format:n.format}:{}}))||[]}function Ypt({aliasOrKey:e,exportKey:t,inputs:n}){if(e===z4&&t&&qW(t))return{source:"documentMeta",key:t};const r=n.find(o=>o.variableName===e);if(r){const o=t||egt(r);return!dpe(o)||!new Set(V4(r)).has(o)?null:{source:"input",inputId:r.id,export:o}}return!t&&qW(e)?{source:"documentMeta",key:e}:null}function Zpt(e,t){var o;if(e.source==="documentMeta")return e.key==="generatedAt"?mpe(t.meta.generatedAt,t.timezone,t.generatedAtFormat||m.DEFAULT_DOCUMENT_GENERATED_AT_FORMAT):String(t.meta[e.key]);const n=t.resolvedInputsById[e.inputId],r=(o=n==null?void 0:n.exports)==null?void 0:o[e.export];return r==null?"":String(r)}function Xpt(e,t,n){const r=(t==null?void 0:t.values)||[];if(m.getDataType(e.filter.dataType)==="date"){const a=r[0]?$k(r[0],n):"",c=r[1]?$k(r[1],n):"",u=a&&c?`${a} - ${c}`:a||c;return{inputId:e.id,variableName:e.variableName,rawValue:r.length>1?r:r[0]??null,displayValue:u,filterValues:t?[t]:void 0,exports:{label:u||null,value:u||null,start:a||null,end:c||null,range:u||null}}}const i=r.map(rgt).join(", ");return{inputId:e.id,variableName:e.variableName,rawValue:r.length>1?r:r[0]??null,displayValue:i,filterValues:t?[t]:void 0,exports:{label:i||null,value:i||null}}}function Qpt(e,t,n,r=[]){const o=ngt(t),i=o.map(c=>e.control.type==="date"?$k(c,n):tgt(e.control,c,r)).join(", "),a=o.map(hpe).join(", ");return{inputId:e.id,variableName:e.variableName,rawValue:t??null,displayValue:i,controlValue:t,exports:{label:i||null,value:a||null}}}function V4(e){const t=Jpt(e),n=(e.exports||[]).filter(dpe);return Array.from(new Set([...t,...n]))}function Jpt(e){return e.kind==="filter"?m.getDataType(e.filter.dataType)==="date"?["label","start","end","range"]:["label","value"]:["label","value"]}function egt(e){const t=V4(e);return t.includes("label")?"label":t.includes("range")?"range":t[0]||"value"}function dpe(e){return e==="label"||e==="value"||e==="start"||e==="end"||e==="range"}function qW(e){return qpt.has(e)}function fpe(e,t){return t.some(n=>n.variableName===e)}function A2(e,t){return fpe(e,t)?`{{${z4}.${e}}}`:`{{${e}}}`}function yN(e,t){return fpe(e,t)?`${z4}.${e}`:e}function tgt(e,t,n=[]){var s;const r=hpe(t),o=n.find(i=>i.value===r);return o?o.label:e.source.kind==="manual"&&((s=e.source.options.find(i=>i.value===r))==null?void 0:s.label)||r}function ngt(e){return e==null?[]:Array.isArray(e)?e:[e]}function rgt(e){return e instanceof Date?$k(e):e==null?"":String(e)}function hpe(e){return e instanceof Date?e.toISOString():e==null?"":String(e)}function $k(e,t){return e?mpe(e,t,"MMM d, yyyy"):""}function mpe(e,t,n){const r=sgt(n),o=ogt(e);if(o)return Lt.format(o,r);const s=e instanceof Date?e:new Date(String(e));return Number.isNaN(s.getTime())?e==null?"":String(e):Lt.formatInTimeZone(s,t||"UTC",r)}function ogt(e){if(typeof e!="string")return null;const t=Upt.exec(e.trim());if(!t)return null;const n=Number(t[1]),r=Number(t[2]),o=Number(t[3]),s=new Date(n,r-1,o);return s.getFullYear()!==n||s.getMonth()!==r-1||s.getDate()!==o?null:s}function sgt(e){return e.replace(/\[([^\]]+)\]/g,"'$1'").replace(/YYYY/g,"yyyy").replace(/YY/g,"yy").replace(/DD/g,"dd").replace(/D/g,"d").replace(/A/g,"a")}const wC={text:"Text",table:"Table",chart:"Chart",spacer:"Spacer",page_break:"Page break"},ppe=["text","table","spacer","page_break"];function F0(e){return e==="table"?m.Table2:e==="text"?m.Type:e==="spacer"?cwe:e==="page_break"?awe:li}function igt(e){const t=`doc_section_${lt.v4()}`;return e==="text"?{id:t,type:"text",content:m.textContent("New text section")}:e==="table"?{id:t,type:"table",title:"Table",card:{id:`doc_card_${t}`,title:"Table",type:"table",preferences:{tablePrefs:{density:"compact",tableStyle:{headerStyle:"filled",stripedRows:!1,gridLines:"horizontal",wrapText:!1,totals:{enabled:!1}}}}},table:{totalsRow:!1,repeatHeaderOnPageBreak:!0,rowHeightPx:28}}:e==="spacer"?{id:t,type:"spacer",heightPx:24}:{id:t,type:"page_break"}}function F2(e,t){if(e.type==="text"){const n=m.textContentToString(e.content,t).trim();return n?n.split(`
1320
1320
  `)[0].slice(0,40):"Text"}return e.type==="table"?e.title||e.card.title||"Table":e.type==="spacer"?`Spacer (${e.heightPx}px)`:wC[e.type]}function agt(e,t){if(e.type==="spacer")return"Spacer";if(e.type==="text"){const n=m.textContentToString(e.content,t).trim();return n?n.split(`
1321
- `)[0].slice(0,28):"Text section"}return e.type==="table"?e.title||e.card.title||"Table":e.type==="page_break"?"Page break":wC[e.type]}function lgt(e){return e.type==="spacer"?`${e.heightPx} px`:e.type==="table"?"Table":null}const zf=Ad,Bf=ka,cgt={spacious:40,comfortable:36,standard:32,compact:28,dense:24};function H4(e){var t;return K3((t=e.card.preferences)==null?void 0:t.tablePrefs)}function ugt(e){return[e.density,e.headerStyle,e.headerBackgroundColor,e.headerTextColor,e.headerWrapText,e.stripedRows,e.gridLines,e.wrapText,e.totalsStyle.backgroundColor,e.totalsStyle.textColor,e.totalsStyle.fontWeight,e.totalsStyle.borderTop,e.totalsStyle.borderTopStyle,e.totalsStyle.borderTopColor].join(":")}const dgt=wse;function aO(e){return cgt[e]}function fgt(e){return e.table.rowHeightPx??aO(H4(e).density)}function hgt(e){const t=new Set;return e.forEach(n=>{Object.keys(n).forEach(r=>t.add(r))}),Array.from(t)}function gpe(e){var o;if(e.type!=="table"||e.card.type!=="table")return"";const t=e.card,n=t.config,r=t.dataSource;return JSON.stringify({type:t.type,connectionId:t.connectionId||(r==null?void 0:r.connectionId)||"",sql:((o=t.sql)==null?void 0:o.trim())||"",datamodelId:t.datamodelId||(r==null?void 0:r.datamodelId)||"",semanticDomainId:(r==null?void 0:r.semanticDomainId)||"",selectedEntities:(r==null?void 0:r.selectedEntities)||null,lastSelectedDatabase:t.lastSelectedDatabase||"",lastSelectedSchema:t.lastSelectedSchema||"",lastSelectedTable:t.lastSelectedTable||"",detailColumns:w1(n==null?void 0:n.detailColumns),groupByColumns:w1(n==null?void 0:n.groupByColumns),metricColumns:w1(n==null?void 0:n.metricColumns),pivotByColumns:w1(n==null?void 0:n.pivotByColumns)})}function w1(e){return Array.isArray(e)?e.map(t=>{if(!t||typeof t!="object")return String(t??"");const n=t;return{id:n.id,alias:n.alias,name:n.name,label:n.label,column:n.column,expression:n.expression,aggregate:n.aggregate,aggregation:n.aggregation,dataType:n.dataType,type:n.type}}):[]}function pl(e){return e.kind==="filter"}function oc(e){return e.kind==="control"}function xpe(e,t){return e.reduce((n,r)=>{if(!pl(r))return n;const o=m.buildFilterValueFromDefaults(r.filter,t);return o&&(n[r.id]=o),n},{})}function bpe(e){return e.reduce((t,n)=>{if(!oc(n))return t;const r=m.buildAuthoringPreviewControlValues({controls:[n.control]});return Object.prototype.hasOwnProperty.call(r,n.control.id)&&(t[n.id]=r[n.control.id]),t},{})}function mgt(e){return e.map(t=>`${t.id}:${vpe(t)}`).join("|")}function ype(e){return e.reduce((t,n)=>(t[n.id]=vpe(n),t),{})}function vpe(e){if(oc(e))return JSON.stringify({kind:e.kind,controlId:e.control.id,type:e.control.type,source:e.control.source});const t=en.materializeFilterDefinitionNativeDataType(e.filter);return JSON.stringify({kind:e.kind,filterId:t.id,connectionId:t.connectionId,qualifiedTableName:t.qualifiedTableName||null,table:t.table||null,database:t.database||null,sql:t.sql,column:t.column,dataType:t.dataType,nativeDataType:t.nativeDataType||null,operation:t.operation,type:t.type||null,fieldMeta:t.fieldMeta||null,semanticContext:t.semanticContext||null,targetColumns:t.targetColumns||null})}function pgt(e,t,n,r,o){const s={};for(const i of t){if(!pl(i))continue;const a=e[i.id],c=CC(i.id,r,o),u=Sx(i,a),d=Object.prototype.hasOwnProperty.call(e,i.id);if(!c&&d&&!a){s[i.id]=void 0;continue}if(!c&&u){s[i.id]=u;continue}n[i.id]&&(s[i.id]=n[i.id])}return ygt(e,s)?e:s}function ggt(e,t,n,r,o){const s={};for(const i of t){if(!oc(i))continue;if(!CC(i.id,r,o)&&Object.prototype.hasOwnProperty.call(e,i.id)){s[i.id]=e[i.id];continue}Object.prototype.hasOwnProperty.call(n,i.id)&&(s[i.id]=n[i.id])}return vgt(e,s)?e:s}function q4(e,t){const n={...t,filterId:e.filter.id};return m.isCompatibleFilterValue(e.filter,n)?xgt(e).has(t.name):!1}function Sx(e,t){if(!t||!q4(e,t))return;const n=t.filterId===e.filter.id?t:{...t,filterId:e.filter.id};return en.materializeFilterValueNativeDataType({definition:e.filter,value:n})}function wpe(e,t){const n=new Map(t.filter(pl).map(o=>[o.id,o]));let r=e;for(const[o,s]of Object.entries(e)){const i=n.get(o),a=i?Sx(i,s):void 0;!a||a===s||(r===e&&(r={...e}),r[o]=a)}return r}function xgt(e){return new Set([e.filter.column,...(e.filter.targetColumns||[]).map(t=>t.column)])}function bgt(e,t){const n=new Set(t.filter(o=>pl(o)&&VT(o.filter.operation)).map(o=>o.id)),r={};for(const[o,s]of Object.entries(e))n.has(o)&&(r[o]=s);return wgt(e,r)?e:r}function ygt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>e[o]===t[o])}function vgt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>Object.is(e[o],t[o]))}function wgt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>e[o]===t[o])}function VT(e){return e==="in"||e==="not in"}function Cpe(e){return e==="not in"?"exclude":"include"}function lO(e){return e==="exclude"?"not in":"in"}function Cgt(e,t,n,r){return t.map(o=>{if(!pl(o))return;const s=e[o.id];if(!(!s||CC(o.id,n,r)||!q4(o,s)))return Sx(o,s)}).filter(o=>!!o)}function Sgt(e,t,n,r){return t.reduce((o,s)=>(!oc(s)||CC(s.id,n,r)||!Object.prototype.hasOwnProperty.call(e,s.id)||(o[s.control.id]=e[s.id]),o),{})}function Spe(e,t,n,r,o){return e.filter(s=>s.requiredAtExecution?CC(s.id,r,o)?!0:pl(s)?!t[s.id]||!q4(s,t[s.id]):!Ngt(n,s.id):!1).map(s=>s.label)}function Ngt(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;const n=e[t];return n==null?!1:Array.isArray(n)?n.length>0:typeof n=="string"?n.trim().length>0:!0}function CC(e,t,n){const r=n[e];return!!r&&r!==t[e]}const jgt=["table","pivotTable"];function kgt(e){return{id:`doc_editor_frame_${e.id}`,cards:[e.card],activeCardId:e.card.id}}function Igt(e,t){return e.cards.find(n=>n.id===t)||null}function _gt(e){return jgt.includes(e.type)}function Tgt(){const e=m.useDashboardStore(I=>I.dashboard),t=m.useEditorStore(I=>I.selectedConnectionId),n=m.useEditorStore(I=>I.selectedDatabaseName),r=m.useEditorStore(I=>I.selectedSchemaName),o=m.useEditorStore(I=>I.selectedTableName),s=m.useEditorStore(I=>I.selectedDatamodelId),{clearSelectedVisual:i}=Pm(),{setIsDashboardEditing:a,setIsVisualEditing:c}=m.useDashboardActions(),{setFrame:u,setCard:d,setIsDevMode:f,initializeModeDrafts:h,setActiveTabCardId:p,updateDataSource:g,setQueryResultColumns:x,setFilterValues:b,setInlineFilterValuesMap:y,setApplyFilters:C,clearModeDrafts:w,setEditorContext:N}=m.useEditorActions(),S=m.useEditorStore(I=>I.actions.setSelectedConnectionId),j=m.useEditorStore(I=>I.actions.setSelectedDatamodelId),k=m.useEditorStore(I=>I.actions.setSelectedDatabaseName),_=m.useEditorStore(I=>I.actions.setSelectedSchemaName),T=m.useEditorStore(I=>I.actions.setSelectedTableName);return v.useCallback((I,D,E=[],R=[],F={},M=[])=>{const O=kgt(D);i(),w(),N({type:"documentSection",sheetId:I,sectionId:D.id,cardId:D.card.id,documentFilterValues:Dgt(E),documentControlDefinitions:Egt(R),documentControlValues:{...F},missingRequiredInputLabels:[...M]}),e_({frame:O,card:D.card,setFrame:u,setCard:d,setIsDevMode:f,initializeModeDrafts:h,setActiveTabCardId:p,updateDataSource:g,setQueryResultColumns:x,setSelectedConnectionId:S,setSelectedDatabaseName:k,setSelectedSchemaName:_,setSelectedTableName:T,setSelectedDatamodelId:j,setFilterValues:b,setInlineFilterValuesMap:y,setApplyFilters:C,setIsDashboardEditing:a,setIsVisualEditing:c,dashboard:e,selectedSheetId:I,selectedFrameId:null,currentSelections:{connectionId:t,databaseName:n,schemaName:r,tableName:o,datamodelId:s}})},[w,i,e,h,t,n,s,r,o,p,C,d,N,b,u,y,a,f,c,x,S,k,j,_,T,g])}function Dgt(e){return e.map(t=>({...t,values:[...t.values]}))}function Egt(e){return e.map(t=>({...t,source:t.source.kind==="manual"?{...t.source,options:t.source.options.map(n=>({...n}))}:{...t.source}}))}function P2({inputs:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o}){return l.jsx(l.Fragment,{children:e.filter(oc).map(s=>l.jsx(Mgt,{input:s,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o},s.id))})}function Mgt({input:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o}){const s=e.control,i=s.source.kind==="sql_query"?s.source:void 0,a=cC({controlId:s.id,source:i,enabled:!!i,controlDefinitionsOverride:n,controlValuesOverride:r,activeFiltersOverride:t}),c=v.useMemo(()=>i?[]:Lz(s),[s,i]),u=i?a.options:c;return v.useEffect(()=>{o(e.id,u)},[e.id,o,u]),null}function cO({children:e,className:t,empty:n,wrap:r=!1}){const o=v.Children.toArray(e).filter(s=>s!=null);return o.length===0?n??null:l.jsx("div",{className:m.cn("flex items-center gap-2 pr-1",r?"min-w-0 flex-wrap gap-y-2":"min-w-max",t),children:o})}const zk=v.forwardRef(function({children:t,className:n,...r},o){return l.jsx("div",{ref:o,className:m.cn("shrink-0",n),...r,children:t})}),O2=({dataType:e})=>kk(e),Npe=["day","week","month","quarter","year"],Rgt=[...Npe,"hour","minute","second"],Agt=e=>m.isDateTimeLikeDataType(e),jpe=e=>Agt(e)?Rgt:Npe;function kpe(e){const{controlId:t,onCommit:n}=e,[r,o]=v.useState(t);return l.jsx(m.Input,{size:"xs",value:r,onChange:s=>o(s.target.value),onBlur:()=>{n(r),o(s=>s.trim().length===0?t:s)}})}function UW(e){const{control:t,onChange:n}=e,r=m.ensureManualSource(t),o=r.source.kind==="manual"?r.source.options:[],i=!!m.getPresetOptionsForControlType(t.type),a=h=>{n({...r,source:{kind:"manual",options:h}})},c=()=>{const h=o.length+1,p=`Option ${h}`;a([...o,{label:p,value:m.slugifyControlValue(p)||`option_${h}`}])},u=(h,p)=>{a(o.map((g,x)=>{if(x!==h)return g;const b=m.slugifyControlValue(g.label),y=m.slugifyControlValue(p)||g.value,C=g.value.trim().length===0||g.value===b;return{...g,label:p,value:C?y:g.value}}))},d=(h,p)=>{a(o.map((g,x)=>x===h?{...g,value:p}:g))},f=h=>{a(o.filter((p,g)=>g!==h))};return l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Options"}),!i&&l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:c,children:[l.jsx(Ar,{className:"mr-1 h-3 w-3"}),"Add option"]})]}),o.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-2.5 text-xs text-muted-foreground",children:"No options yet."}):l.jsxs("div",{className:"rounded-md border",children:[l.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_32px] gap-2 border-b bg-muted/50 px-2.5 py-1.5",children:[l.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Label"}),l.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Value"}),l.jsx("span",{})]}),o.map((h,p)=>l.jsxs("div",{className:m.cn("grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_32px] items-center gap-2 px-2.5 py-1.5",p<o.length-1&&"border-b"),children:[l.jsx(m.Input,{size:"xs",value:h.label,placeholder:"Label",className:"h-7 text-xs",onChange:g=>u(p,g.target.value),disabled:i}),l.jsx(m.Input,{size:"xs",value:h.value,placeholder:"Value",className:"h-7 text-xs",onChange:g=>d(p,g.target.value),disabled:i}),l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>f(p),disabled:i,children:l.jsx(Ra,{className:"h-3.5 w-3.5"})})]},`${t.id}-option-${p}`))]})]})}function Fgt(e){return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Choices (built in)"}),l.jsx("div",{className:"rounded-md border bg-muted/20 px-3 py-2 text-sm text-muted-foreground",children:e.options.map(t=>t.label).join(" · ")})]})}function Pgt(e){return e?m.getDataType(e.dataType||"")==="date":!1}function Ogt(e){if(!e)return;const t=m.readTemporalBucketAuthoringState({fieldId:e.id,dataType:e.dataType,granularity:e.granularity,format:e.format,dateFormat:e.dateFormat,customFormat:e.customFormat,semanticTemporalPresentation:e.semanticTemporalPresentation});return t.ok?t.granularity:void 0}function KW(e,t){return m.readTemporalBucketAuthoringSelection({fieldId:(e==null?void 0:e.id)||"structural-control-option",dataType:(e==null?void 0:e.dataType)||"date",granularity:t,format:e==null?void 0:e.format,dateFormat:e==null?void 0:e.dateFormat,customFormat:e==null?void 0:e.customFormat,semanticTemporalPresentation:e==null?void 0:e.semanticTemporalPresentation})}function Lgt(e){var k,_;const{control:t,choices:n,choiceLabel:r,emptyMessage:o,onChange:s}=e,i=m.ensureManualSource(t),a=i.source.kind==="manual"?i.source.options:[],c=new Map(a.map(T=>[T.value,T])),u=new Set(a.map(T=>T.value)),[d,f]=v.useState(""),[h,p]=v.useState(((k=a[0])==null?void 0:k.value)||null),[g,x]=v.useState({}),b=T=>{s({...i,source:{kind:"manual",options:T}})},y=(T,I)=>{b(a.map(D=>D.value===T?I(D):D))},C=n.filter(({option:T})=>u.has(T.value)),w=h&&a.some(T=>T.value===h)?h:((_=a[0])==null?void 0:_.value)||null,N=C.find(({option:T})=>T.value===w)||C[0],S=n.filter(({option:T})=>{var D,E,R,F;if(u.has(T.value))return!1;const I=d.trim().toLowerCase();return I?T.label.toLowerCase().includes(I)||T.value.toLowerCase().includes(I)||((E=(D=T.presentation)==null?void 0:D.customFormat)==null?void 0:E.toLowerCase().includes(I))||((F=(R=T.presentation)==null?void 0:R.format)==null?void 0:F.presentation.mode)==="pattern"&&T.presentation.format.presentation.pattern.toLowerCase().includes(I):!0}),j=(T,I)=>{var A;const D=c.get(T.value),E=I?m.getDataType(I.dataType||""):void 0,R=Pgt(I),F=R?((A=D==null?void 0:D.presentation)==null?void 0:A.granularity)??Ogt(I):void 0,M=R&&F?KW(I,F):void 0,O=R&&F?m.readTemporalBucketAuthoringSelectionWithOverride({fieldId:(I==null?void 0:I.id)||T.value,dataType:(I==null?void 0:I.dataType)||"date",granularity:F,format:M==null?void 0:M.format},D==null?void 0:D.presentation):void 0,z=R&&F?lo.getTemporalBucketAuthoringOptions(F,O==null?void 0:O.format):[],L=g[T.value],V=L!==void 0?"custom":(O==null?void 0:O.value)||"auto";return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("p",{className:"text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Editing selected ",r.slice(0,-1).toLowerCase()]}),l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsx("span",{className:"text-sm font-medium text-foreground/90",children:(D==null?void 0:D.label)??T.label}),E?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:E}):null,"aggregate"in(I||{})&&typeof(I==null?void 0:I.aggregate)=="string"?l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:I.aggregate}):null]}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]}),l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Shown as"}),l.jsx(m.Input,{size:"xs",value:(D==null?void 0:D.label)??T.label,onChange:B=>y(T.value,$=>({...$,label:B.target.value}))})]}),R?l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Granularity"}),l.jsxs(m.Select,{value:F,onValueChange:B=>{const $=B;x(U=>{const H={...U};return delete H[T.value],H});const P=lo.reconcileTemporalBucketAuthoringFormat((O==null?void 0:O.format)??KW(I,$).format,$);y(T.value,U=>({...U,presentation:{granularity:$,format:P}}))},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:"Select granularity..."})}),l.jsx(m.SelectContent,{children:jpe(I.dataType).map(B=>l.jsx(m.SelectItem,{value:B,children:B.charAt(0).toUpperCase()+B.slice(1)},B))})]})]}):null,R&&F?l.jsx("div",{className:"space-y-1 md:col-span-2",children:l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Date format"}),l.jsxs(m.Select,{value:V,onValueChange:B=>{var P;let $=L??(O==null?void 0:O.customPattern)??"";if(B==="custom"){const U=z.find(G=>G.value==="custom"),H=((P=U==null?void 0:U.format)==null?void 0:P.presentation.mode)==="pattern"?U.format.presentation.pattern:"";$=(O==null?void 0:O.customPattern)||H||"",x(G=>({...G,[T.value]:$}))}else x(U=>{const H={...U};return delete H[T.value],H});y(T.value,U=>({...U,presentation:{granularity:F,format:lo.resolveTemporalBucketAuthoringFormat(F,B,$)}}))},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:z.map(B=>l.jsx(m.SelectItem,{value:B.value,children:B.label},B.value))})]})]}),V==="custom"?l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Custom format"}),l.jsx(m.Input,{size:"xs",value:L??(O==null?void 0:O.customPattern)??"",placeholder:"MMM YYYY",onChange:B=>{const $=B.target.value;x(P=>({...P,[T.value]:$})),y(T.value,P=>({...P,presentation:{granularity:F,format:lo.resolveTemporalBucketAuthoringFormat(F,"custom",$)}}))}})]}):null]})}):null]})]})};return l.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[l.jsxs("div",{className:"flex min-h-0 flex-col gap-3 rounded-lg border bg-muted/10 p-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Add ",r.toLowerCase()]}),l.jsxs("div",{className:"relative",children:[l.jsx(Ft.Search,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),l.jsx(m.Input,{size:"xs",value:d,name:`${t.id}-search-${r.toLowerCase()}`,placeholder:`Search ${r.toLowerCase()}…`,autoComplete:"off",onChange:T=>f(T.target.value),className:"pl-9 pr-9"}),d?l.jsx("button",{type:"button","aria-label":`Clear ${r.toLowerCase()} search`,className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>f(""),children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})}):null]})]}),n.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:o}):S.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:d.trim().length>0?"No matching fields found.":`All compatible ${r.toLowerCase()} are already selected.`}):l.jsx("div",{className:"h-[320px] overflow-y-auto pr-1",children:l.jsx("div",{className:"space-y-1",children:S.map(({option:T,target:I})=>{const D=I?m.getDataType(I.dataType||""):void 0;return l.jsxs("button",{type:"button",className:"group/container flex w-full items-center gap-3 rounded-lg border border-transparent px-2 py-2 text-left transition-all hover:bg-muted",onClick:()=>{b([...a,{...T}]),p(T.value),f("")},children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[l.jsx("div",{className:"truncate text-sm text-foreground/85 group-hover/container:text-foreground",children:(I==null?void 0:I.label)||T.label}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]}),l.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[D?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:D}):null,l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:"Add"})]})]},`${t.id}-available-${T.value}`)})})})]}),l.jsxs("div",{className:"flex min-h-0 flex-col gap-3 rounded-lg border bg-card p-3",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsxs(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Selected ",r.toLowerCase()]}),l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:C.length})]}),C.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:"Choose at least one option from the catalog."}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"max-h-[220px] overflow-y-auto pr-1",children:l.jsx("div",{className:"space-y-1",children:C.map(({option:T,target:I})=>{const D=c.get(T.value),E=I?m.getDataType(I.dataType||""):void 0,R=(N==null?void 0:N.option.value)===T.value;return l.jsxs("div",{className:m.cn("flex items-center gap-2 rounded-lg border p-2 transition-colors",R?"border-foreground/20 bg-muted/40":"border-transparent hover:bg-muted/20"),children:[l.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 text-left",onClick:()=>p(T.value),children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"truncate text-sm font-medium text-foreground/90",children:(D==null?void 0:D.label)??T.label}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]})]}),l.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[E?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:E}):null,l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":`Remove ${(D==null?void 0:D.label)??T.label}`,onClick:()=>{var M;const F=a.filter(O=>O.value!==T.value);b(F),w===T.value&&p(((M=F[0])==null?void 0:M.value)||null)},children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})]},`${t.id}-selected-${T.value}`)})})}),l.jsx("div",{className:"rounded-lg border bg-muted/5 p-3",children:N?j(N.option,N.target):l.jsx("div",{className:"text-xs text-muted-foreground",children:"Select a field to configure how it appears in the control."})})]})]})]})}function Ipe(e){if(e.participants.length===0)return null;const t=new Set(e.selectedCardIds);return l.jsxs("div",{className:"space-y-2",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Cards using this shared control"}),l.jsx("div",{className:"space-y-2 rounded-md border p-3",children:e.participants.map(n=>l.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[l.jsx(jn,{checked:t.has(n.cardId),onCheckedChange:r=>{if(r===!0){e.onChange([...e.selectedCardIds,n.cardId]);return}e.onChange(e.selectedCardIds.filter(o=>o!==n.cardId))}}),l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"font-medium",children:n.title}),l.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.choiceCount," ",e.type==="field_selector"?"compatible group-by fields":"compatible metrics"]})]})]},n.cardId))})]})}function $gt(e){const t=e.value===!0?"true":"false";return l.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[l.jsx(m.Button,{type:"button",variant:t==="true"?"default":"outline",onClick:()=>e.onChange(!0),children:"On"}),l.jsx(m.Button,{type:"button",variant:t==="false"?"default":"outline",onClick:()=>e.onChange(!1),children:"Off"})]})}function zgt(e){return e.scope==="dashboard"&&(e.type==="enum"||e.type==="multi_enum")}const _pe={kind:"sql_query",connectionId:"",sql:"",valueColumn:""};function WW(e){return{kind:"manual",options:e.options.map(t=>({...t,...t.presentation?{presentation:{...t.presentation}}:{}}))}}function GW(e){return{...e}}function Bgt(e){return e.source.kind==="sql_query"?e.source:_pe}function Tpe(e){const t=U4(e);return JSON.stringify({controlId:e.controlId,source:zz(e.source),controlDefinitions:$de(t.controlDefinitions),controlValues:Lde(t.controlValues,t.controlDefinitions),activeFilters:e.activeFiltersOverride??null})}function U4(e){const t=Pde(e.previewControlDefinitions),n={...e.previewControlValues||{}};delete n[e.controlId];const r=Ode(n,t);return{controlDefinitions:t,controlValues:r}}function Vgt(e){const[t,n]=v.useState(null),r=v.useRef(e);return v.useEffect(()=>{r.current!==e&&(r.current=e,n(null))},[e]),{requestedForCurrentKey:t===e,markCurrentKeyRequested:()=>n(e)}}function Hgt(e){var w;const{control:t,onChange:n,previewControlDefinitions:r,previewControlValues:o,activeFiltersOverride:s}=e,i=Bgt(t),{connections:a,isPending:c}=La(),u=t.id||"preview",d=i.connectionId.trim().length>0&&i.sql.trim().length>0&&i.valueColumn.trim().length>0,f=U4({controlId:u,previewControlDefinitions:r,previewControlValues:o}),h=Tpe({controlId:u,source:i,previewControlDefinitions:r,previewControlValues:o,activeFiltersOverride:s}),{requestedForCurrentKey:p,markCurrentKeyRequested:g}=Vgt(h),x=cC({controlId:u,source:d?i:void 0,enabled:p&&d,controlDefinitionsOverride:f.controlDefinitions,controlValuesOverride:f.controlValues,activeFiltersOverride:s}),b=N=>{const S={...i,...N,kind:"sql_query"};(!S.labelColumn||S.labelColumn.trim().length===0)&&delete S.labelColumn,n({...t,source:S})},y=m.getRequestErrorMessage(x.error,""),C=x.options;return v.useEffect(()=>{var j;if(i.connectionId||a.length!==1)return;const N=(j=a[0])==null?void 0:j.id;if(!N)return;const S={...i,kind:"sql_query",connectionId:N};(!S.labelColumn||S.labelColumn.trim().length===0)&&delete S.labelColumn,n({...t,source:S})},[a,t,i,n]),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Connection"}),l.jsxs(m.Select,{value:i.connectionId,onValueChange:N=>{b({connectionId:N})},disabled:c||a.length===0,children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:c?"Loading connections…":a.length===0?"No connections available":"Select a connection"})}),l.jsx(m.SelectContent,{children:a.map(N=>l.jsx(m.SelectItem,{value:N.id,children:N.name},N.id))})]})]}),i.connectionId.trim().length===0?l.jsxs("div",{className:"flex min-h-[200px] flex-col items-center justify-center gap-1 rounded-control border border-border/60 bg-muted/20 px-4 py-8 text-center",children:[l.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"Pick a connection above"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Then write your SQL query to source options."})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL"}),l.jsx("div",{className:"h-24 w-full overflow-hidden rounded-control border border-input",onKeyDown:N=>N.stopPropagation(),children:l.jsx(m.CodeEditor,{value:i.sql,onValueChange:N=>b({sql:N}),language:"sql-jinja",embedded:!0,hideLineNumbers:!0,dense:!0,ariaLabel:"Control options SQL query",placeholder:"SELECT id, name FROM segments WHERE account_id = [[param.tenantId]]"})})]}),l.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Value column"}),l.jsx(m.Input,{size:"xs",value:i.valueColumn,placeholder:"id",onChange:N=>{b({valueColumn:N.target.value})}})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label column (optional)"}),l.jsx(m.Input,{size:"xs",value:i.labelColumn||"",placeholder:"name",onChange:N=>{b({labelColumn:N.target.value})}})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",disabled:!d||x.isFetching,onClick:()=>{if(p){x.refetch();return}g()},children:x.isFetching?"Loading…":"Preview options"}),p&&!x.isFetching&&x.data?l.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[C.length," option",C.length===1?"":"s",(w=x.metadata)!=null&&w.truncated?" (truncated)":""]}):null]}),p&&x.isError?l.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Preview unavailable",y?` — ${y}`:""]}):null]})]})}function qgt(e){const{control:t,onChange:n,controlLifecycle:r="edit"}=e,o=t.source.kind==="sql_query"?"sql_query":"manual",s=v.useRef(t.source.kind==="manual"?WW(t.source):null),i=v.useRef(t.source.kind==="manual"?t.requiredAtExecution:null),a=v.useRef(t.source.kind==="sql_query"?GW(t.source):null);t.source.kind==="manual"?(s.current=WW(t.source),i.current=t.requiredAtExecution):t.source.kind==="sql_query"&&(a.current=GW(t.source));const c=u=>{if(u!==o){if(u==="manual"){n({...t,source:s.current||{kind:"manual",options:[]},requiredAtExecution:i.current??t.requiredAtExecution});return}n({...t,source:a.current||_pe,requiredAtExecution:t.initialValueStrategy==="embed_required"?!0:r==="create"?!1:t.requiredAtExecution})}};return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Option source"}),l.jsxs(cc,{value:o,onValueChange:u=>c(u),className:"flex flex-col gap-1.5",children:[l.jsxs("label",{className:"flex items-start gap-2 text-xs",children:[l.jsx(Ms,{value:"manual",className:"mt-0.5"}),l.jsxs("span",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Manual"}),l.jsx("span",{className:"ml-1 text-muted-foreground",children:"— enter label/value rows"})]})]}),l.jsxs("label",{className:"flex items-start gap-2 text-xs",children:[l.jsx(Ms,{value:"sql_query",className:"mt-0.5"}),l.jsxs("span",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"SQL query"}),l.jsx("span",{className:"ml-1 text-muted-foreground",children:"— resolve options from a database query at runtime"})]})]})]})]})}function Dpe(e){const t=m.getPresetOptionsForControlType(e.control.type),n=e.control.source.kind==="sql_query"?e.control:m.ensureManualSource(e.control),r=e.control.type==="field_selector"?e.availableFieldChoices||[]:e.control.type==="metric_selector"?e.availableMetricChoices||[]:[];if(t)return l.jsx(Fgt,{options:t});if(n.type==="field_selector"||n.type==="metric_selector"){const o=n.type==="field_selector"?"Fields":"Metrics",s=n.type==="field_selector"?"No valid group-by fields are available yet. Add fields to the card first.":"No valid metrics are available yet. Add metrics to the card first.";return l.jsx(Lgt,{control:n,choices:r,choiceLabel:o,emptyMessage:s,onChange:e.onChange})}return m.needsManualOptions(n)?zgt(n)?l.jsxs("div",{className:"space-y-3",children:[l.jsx(qgt,{control:n,onChange:e.onChange,controlLifecycle:e.controlLifecycle}),n.source.kind==="sql_query"?l.jsx(Hgt,{control:n,onChange:e.onChange,previewControlDefinitions:e.previewControlDefinitions,previewControlValues:e.previewControlValues,activeFiltersOverride:e.activeFiltersOverride}):l.jsx(UW,{control:n,onChange:e.onChange})]}):l.jsx(UW,{control:n,onChange:e.onChange}):null}function Epe(e){const{control:t,value:n,onChange:r,allowNoDefault:o=!1,allowCardDefault:s=!1,hint:i}=e;if(t.source.kind==="sql_query")return l.jsx(Kgt,{control:t,value:n,onChange:r,allowNoDefault:o,allowCardDefault:s,hint:i,previewControlDefinitions:e.previewControlDefinitions,previewControlValues:e.previewControlValues,activeFiltersOverride:e.activeFiltersOverride});const a=m.ensureManualSource(t),c=m.getDefaultValueForType(t,n),d=m.getPresetOptionsForControlType(t.type)??(a.source.kind==="manual"?a.source.options:[]),f=t.type==="enum"||t.type==="field_selector"||t.type==="metric_selector"||t.type==="aggregation_selector"||t.type==="grain_selector";return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default"}),t.type==="boolean"?l.jsx($gt,{value:c,onChange:r}):f&&d.length>0?l.jsx(Mpe,{controlType:t.type,options:d,value:c,onChange:r,allowNoDefault:o,allowCardDefault:s}):f?l.jsx(m.Input,{size:"xs",value:"",placeholder:"Add choices first",disabled:!0,readOnly:!0}):l.jsx(m.Input,{size:"xs",value:Array.isArray(c)?c.join(", "):String(c??""),placeholder:t.type==="multi_enum"?"value_one, value_two":"Default value",onChange:h=>r(m.parseControlDefaultValue(a,h.target.value))}),i?l.jsx("p",{className:"text-[11px] text-muted-foreground",children:i}):null]})}function Mpe(e){const{controlType:t,options:n,value:r,onChange:o,allowNoDefault:s=!1,allowCardDefault:i=!1}=e,a=i&&m.supportsCardDefaultValue(t),c=r===void 0&&s?m.CONTROL_SELECT_UI_VALUES.noDefault:r===Id.CONTROL_CARD_DEFAULT_VALUE&&a?m.CONTROL_SELECT_UI_VALUES.cardDefault:typeof r=="string"?m.findControlSelectOptionUiValue(n,r):void 0;return l.jsxs(m.Select,{value:c,onValueChange:u=>{if(u===m.CONTROL_SELECT_UI_VALUES.noDefault){o(void 0);return}if(u===m.CONTROL_SELECT_UI_VALUES.cardDefault){o(Id.CONTROL_CARD_DEFAULT_VALUE);return}const d=m.getControlSelectOptionFromUiValue(n,u);d&&o(d.value)},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:"Choose a default"})}),l.jsxs(m.SelectContent,{children:[s?l.jsx(m.SelectItem,{value:m.CONTROL_SELECT_UI_VALUES.noDefault,children:"No default"}):null,a?l.jsx(m.SelectItem,{value:m.CONTROL_SELECT_UI_VALUES.cardDefault,children:"Card default"}):null,n.map((u,d)=>l.jsx(m.SelectItem,{value:m.getControlSelectOptionUiValue(d),children:u.label},u.value))]})]})}function Ugt(e){var a;const{options:t,value:n,onChange:r,allowNoDefault:o=!1}=e,s=m.normalizeControlStringArrayValue(n),i=s.length===0?o?"No default":"Choose defaults":s.length===1?((a=t.find(c=>c.value===s[0]))==null?void 0:a.label)||s[0]:`${s.length} selected`;return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(m.Popover,{children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx(m.Button,{type:"button",variant:"outline",className:"w-full justify-between",children:l.jsx("span",{className:"truncate",children:i})})}),l.jsx(m.PopoverContent,{align:"start",className:"w-64",children:l.jsx("div",{className:"space-y-2",children:t.map(c=>{const u=s.includes(c.value);return l.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[l.jsx(jn,{checked:u,onCheckedChange:d=>{const f=d?[...s,c.value]:s.filter(h=>h!==c.value);r(f.length>0?f:void 0)}}),l.jsx("span",{children:c.label})]},c.value)})})})]}),o&&s.length>0?l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"text-muted-foreground",onClick:()=>r(void 0),children:"Clear"}):null]})}function Kgt(e){const{control:t,value:n,onChange:r,allowNoDefault:o=!1,allowCardDefault:s=!1,hint:i,previewControlDefinitions:a,previewControlValues:c,activeFiltersOverride:u}=e,d=t.source,f=t.id||"preview",h=d.connectionId.trim().length>0&&d.sql.trim().length>0&&d.valueColumn.trim().length>0,p=U4({controlId:f,previewControlDefinitions:a,previewControlValues:c});Tpe({controlId:f,source:d,previewControlDefinitions:a,previewControlValues:c,activeFiltersOverride:u});const g=cC({controlId:f,source:h?d:void 0,enabled:!1,controlDefinitionsOverride:p.controlDefinitions,controlValuesOverride:p.controlValues,activeFiltersOverride:u}),x=g.data!==void 0&&!g.isError,b=g.options.map(N=>({value:N.value,label:N.label})),y=t.type==="multi_enum"?m.normalizeControlStringArrayValue(n):m.getDefaultValueForType(t,n),C=(()=>{const N=[...b],S=new Set(N.map(k=>k.value)),j=k=>{typeof k!="string"||k.length===0||S.has(k)||(S.add(k),N.push({value:k,label:k}))};return Array.isArray(y)?y.forEach(j):j(y),N})(),w=x&&C.length>0;return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default"}),w&&t.type==="multi_enum"?l.jsx(Ugt,{options:C,value:y,onChange:r,allowNoDefault:o}):w?l.jsx(Mpe,{controlType:t.type,options:C,value:y,onChange:r,allowNoDefault:o,allowCardDefault:s}):l.jsx(m.Input,{size:"xs",value:"",placeholder:h?"Preview options above to pick a default (optional)":"Complete the SQL source to pick a default (optional)",disabled:!0,readOnly:!0}),i?l.jsx("p",{className:"text-[11px] text-muted-foreground",children:i}):null]})}function Wgt(e){const{control:t,onChange:n}=e;return l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"space-y-1",children:l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:t.hidden===!0,onCheckedChange:r=>n({...t,hidden:r===!0})}),"Hide control UI from viewers"]})}),l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:t.locked===!0,onCheckedChange:r=>n({...t,locked:r===!0})}),"Locked"]})]})}function Rpe(e){const t=j0(e);return e.scope==="dashboard"?t==="advanced"?"More controls":"dashboard toolbar":t==="advanced"?"More options":"card header"}function Ggt(e){const t=new Map;for(const n of e.controls||[])t.set(n.id,0);for(const n of m.getDashboardCards(e)){const r=new Set(lC(n));for(const o of r)t.has(o)&&t.set(o,(t.get(o)||0)+1)}return Object.fromEntries((e.controls||[]).map(n=>{if(n.hidden)return[n.id,{tone:"default",status:"Hidden from viewers",helper:"This control can still be used by connected cards, but it will not appear in the dashboard UI."}];const r=t.get(n.id)||0,o=Rpe(n);return r===0?[n.id,{tone:"warning",status:"Not used by any cards yet",helper:`This control is already available in the ${o}. Next: open a card's Controls and either bind this control or reference [[param.${n.id}]] in SQL.`}]:[n.id,{tone:"success",status:`Used in ${r} ${r===1?"card":"cards"}`,helper:`Available in the ${o}. ${r===1?"That card":"Those cards"} will respond when the value changes.`}]}))}function Ygt(e){const t=new Set(lC(e.card));return Object.fromEntries(e.controls.map(n=>{var o;const r=Rpe(n);return n.hidden?[n.id,{tone:"default",status:"Hidden from viewers",helper:"This control is available for runtime state but will not appear in this card UI."}]:t.has(n.id)?[n.id,{tone:"success",status:"Used by this card",helper:`Available in the ${r} for this card.`}]:[n.id,{tone:"warning",status:"Not used by this card yet",helper:(o=e.card)!=null&&o.sql?`Reference [[param.${n.id}]] in this card's SQL to make the card respond to it.`:"Choose what this control changes below to make this card respond to it."}]}))}function Zgt(e){let t=0,n=0,r=0;const o=[];for(const s of m.getDashboardCards(e.dashboard)){if(!new Set(lC(s)).has(e.controlId))continue;t+=1,o.push(s.title||s.id),en.extractSqlParamReferences({sql:s.sql,controlBindings:s.controlBindings}).some(u=>u.controlId===e.controlId)&&(n+=1),(s.controlBindings||[]).some(u=>u.target!=="sql_param"&&u.target!=="presentation_currency"&&u.controlId===e.controlId)&&(r+=1)}return{totalCards:t,sqlCards:n,configCards:r,cardTitles:o}}function Ape(e){var n;const t=new Map;for(const r of m.getDashboardCards(e))for(const o of r.controlBindings||[])o.target!=="config_field_selector"&&o.target!=="config_metric_selector"||(t.has(o.controlId)||t.set(o.controlId,new Set),(n=t.get(o.controlId))==null||n.add(r.id));return Object.fromEntries(Array.from(t.entries()).map(([r,o])=>[r,Array.from(o)]))}function Fpe(e){var n;return(((n=e.dataSource)==null?void 0:n.selectedEntities)||[]).filter(r=>r.type!=="file"&&r.type!=="url"&&r.type!=="upload").map(r=>({cardId:e.id,target:r}))}function Xgt(e){if(e.type==="model")return`model:${e.connectionId}:${e.id}`;if(e.type==="dataset"){const t=e;return`dataset:${t.connectionId}:${t.domainId}:${t.name}`}return`table:${e.connectionId}:${e.database||""}:${e.schema||""}:${e.name}`}function Qgt(e){const t=new Map;return e.flatMap(n=>Fpe(n)).forEach(({cardId:n,target:r})=>{const o=Xgt(r),s=t.get(o);if(!s){t.set(o,{key:o,cardIds:[n],target:r});return}s.cardIds.includes(n)||s.cardIds.push(n)}),Array.from(t.values())}function Jgt(e){if(e.type==="dataset"){const t=e;return!!(t.connectionId&&t.domainId&&t.name)}if(e.type==="model"){const t=e;return!!(t.connectionId&&t.id)}return!!(e.connectionId&&e.name)}function ext(e){if(e.type==="model"){const t=e;return{connection_id:t.connectionId,datamodel_id:t.id,database_name:"",schema_name:"",table_name:""}}if(e.type==="dataset"){const t=e;return{connection_id:t.connectionId,domain_id:t.domainId,dataset_name:t.name}}return{connection_id:e.connectionId,datamodel_id:"",database_name:e.database,schema_name:e.schema,table_name:e.name}}function txt(e){const{target:t,column:n}=e,r=m.getQualifiedEntityName(t);return{id:`${t.name}-${n.column_name}`,name:n.column_name,qualifiedFieldName:n.qualifiedFieldName||n.column_name,dataType:n.data_type,label:n.label||n.column_name,description:n.description||"",qualifiedEntityName:r,entityId:t.id||t.id||t.name,entityName:t.name,entityType:t.type,role:n.role==="metric"?"metric":void 0,expression:n.expression,calculatedFormula:n.calculatedFormula,...Nse(n)}}function Ppe(e){const{tokenProps:t}=Mt(),n=m.useDashboardStore(f=>f.authToken),r=v.useMemo(()=>Qgt(e.filter(f=>f.type!=="matrixTable")),[e]),o=v.useMemo(()=>new Map(e.flatMap(f=>{const h=mu.inspectMatrixCardConfig(f);if(h.status!=="ready")return[];const p=Fpe(f).flatMap(({target:g})=>{const x=lo.resolveDashboardEntitySource(g,f.dataSource);return x?[x]:[]});return[[f.id,Es.matrixCatalogSources(h.config.spec,f.controlBindings,p)]]})),[e]),s=v.useMemo(()=>[...o.values()].flat(),[o]),i=Pw(s),a=cf({queries:r.map(({key:f,target:h})=>({queryKey:["dashboard-structural-columns",f],queryFn:()=>m.getRequest(`${t.apiServiceUrl}/v1/columns`,(n==null?void 0:n.accessToken)||"",ext(h)),enabled:!!(n!=null&&n.accessToken)&&Jgt(h)}))}),c=i.pending||a.some(f=>f.isPending&&f.fetchStatus==="fetching"),u=v.useMemo(()=>{const f=new Map;a.forEach((h,p)=>{const g=r[p],x=g==null?void 0:g.target;if(!g||!x||!h.data)return;const b=[...(h.data.columns||[]).map(y=>txt({target:x,column:y})),...h.data.calculatedFields||[]];g.cardIds.forEach(y=>{f.set(y,[...f.get(y)||[],...b])})});for(const[h,p]of o)f.set(h,i.catalog.filter(g=>p.some(x=>ze.semaphorSourcesReferToSameDataset(x,g.field.source))).map(g=>({...g.resolvedField,source:g.field.source})));return f},[a,r,o,i.catalog]);return{participants:v.useMemo(()=>e.map(f=>{var N;const h=u.get(f.id)||[],p=m.getAuthoredCardFields(f),g=mu.inspectMatrixCardConfig(f);if(f.type==="matrixTable"&&g.status!=="ready")return{cardId:f.id,title:f.title||f.id,canBindStructuralControl:!1,fieldChoices:[],metricChoices:[]};const x=((N=p.metrics[0])==null?void 0:N.aggregate)||"SUM",b=m.buildDashboardFieldSelectorChoicesFromFields(h,g.status==="ready"),y=m.buildDashboardMetricSelectorChoicesFromFields(h,x,g.status==="ready"),C=m.getFieldSelectorChoicesForCard(f),w=m.getMetricSelectorChoicesForCard(f);return{cardId:f.id,matrixSpec:g.status==="ready"?g.config.spec:void 0,controlBindings:f.controlBindings,title:f.title||f.id,canBindStructuralControl:f.type==="matrixTable"?g.status==="ready":!!f.config,fieldChoices:b.choices.length>0?b.choices:C,metricChoices:y.choices.length>0?y.choices:w,fieldTargetMap:b.choices.length>0?b.targetMap:Object.fromEntries([...p.rows,...p.columns].filter(S=>typeof S.id=="string").map(S=>[S.id,{...S,role:"groupby"}])),metricTargetMap:y.choices.length>0?y.targetMap:Object.fromEntries(p.metrics.filter(S=>w.some(j=>j.value===S.id)).map(S=>[S.id,{...S,role:"metric",aggregate:S.aggregate??x}]))}}),[e,u]),isLoading:c}}function Ope({control:e,defaultValue:t,defaultPlacement:n,placementOptions:r,previewControlDefinitions:o,previewControlValues:s,availableFieldChoices:i=[],availableMetricChoices:a=[],structuralParticipantSelector:c,allowCardDefault:u=!1,allowControlIdEdit:d=!0,showPlacementSelect:f=!0,showViewerVisibilityToggle:h=!0,activeFiltersOverride:p,onChangeControl:g,onChangeDefaultValue:x,onCommitControlId:b}){const y="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",C=d&&!!b,w=f?C?"grid grid-cols-3 gap-2":"grid grid-cols-2 gap-2":C?"grid grid-cols-2 gap-2":"grid grid-cols-1 gap-2";return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:w,children:[l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Label"}),l.jsx(m.Input,{size:"xs",value:e.label,placeholder:"Control label",onChange:N=>g(S=>({...S,label:N.target.value}))})]}),C?l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Variable name"}),l.jsx(kpe,{controlId:e.id,onCommit:b},e.id)]}):null,f?l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Show in"}),l.jsxs(m.Select,{value:e.placement||n,onValueChange:N=>g(S=>({...S,placement:N})),children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:r.map(N=>l.jsx(m.SelectItem,{value:N.value,children:N.label},N.value))})]})]}):null]}),c,l.jsx(Dpe,{control:e,availableFieldChoices:i,availableMetricChoices:a,previewControlDefinitions:o,previewControlValues:s,activeFiltersOverride:p,controlLifecycle:"edit",onChange:N=>g(()=>N)}),e.initialValueStrategy==="saved_default"&&l.jsx(Epe,{control:e,value:t,allowNoDefault:!0,allowCardDefault:u,previewControlDefinitions:o,previewControlValues:s,activeFiltersOverride:p,onChange:x}),l.jsx("div",{className:"grid grid-cols-1 gap-2",children:l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Initial value"}),l.jsxs(m.Select,{value:e.initialValueStrategy,onValueChange:N=>g(S=>({...S,initialValueStrategy:N})),children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:m.INITIAL_VALUE_STRATEGY_OPTIONS.map(N=>l.jsx(m.SelectItem,{value:N.value,children:N.label},N.value))})]})]})}),l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:e.showLabel??!0,onCheckedChange:N=>g(S=>({...S,showLabel:N===!0}))}),"Show label in toolbar"]}),h?l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:e.hidden===!0,onCheckedChange:N=>g(S=>({...S,hidden:N===!0}))}),"Hide control UI from viewers"]}):null]})}function Lpe({open:e,onOpenChange:t,trigger:n,title:r,subtitle:o,description:s,body:i,footer:a,onClose:c,useDialog:u=!1,deleteDialogOpen:d,onDeleteDialogOpenChange:f,deleteDescription:h,deleteDetails:p,onConfirmDelete:g}){const x=xl("interactive"),b=l.jsx(nxt,{title:r,subtitle:o,onClose:c,titleAsDialogTitle:u});return l.jsxs(l.Fragment,{children:[u?l.jsxs(To,{open:e,onOpenChange:t,children:[l.jsx(zQ,{asChild:!0,children:n}),l.jsxs(bo,{showCloseButton:!1,className:"flex max-h-[88vh] flex-col overflow-hidden rounded-control border border-border/60 p-0 shadow-sm sm:max-w-[600px] sm:rounded-control",style:x.controlStyle,onInteractOutside:y=>y.preventDefault(),children:[l.jsx(Ho,{className:"sr-only",children:s}),b,l.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-4",children:i}),l.jsx("div",{className:"shrink-0 border-t border-border/60 px-4 py-2.5",children:a})]})]}):l.jsxs(m.Popover,{open:e,onOpenChange:t,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:n}),l.jsxs(m.PopoverContent,{align:"start",className:"m-2 flex h-[440px] max-h-[85vh] w-[480px] max-w-[95vw] flex-col overflow-hidden rounded-control border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",style:x.controlStyle,onMouseDown:y=>y.stopPropagation(),children:[b,l.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-4",children:i}),l.jsx("div",{className:"shrink-0 border-t border-border/60 px-4 py-2.5",children:a})]})]}),f&&g?l.jsx($pe,{open:d,onOpenChange:f,description:h,details:p,onConfirm:g}):null]})}function $pe({open:e,defaultOpen:t,onOpenChange:n,description:r,details:o,onConfirm:s}){const i=xl("interactive");return l.jsx(ff,{open:e,defaultOpen:t,onOpenChange:n,children:l.jsxs(Tu,{style:i.controlStyle,children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete control?"}),l.jsx(Ru,{children:r}),o]}),l.jsxs(Eu,{children:[l.jsx(Fu,{children:"Cancel"}),l.jsx(Au,{onClick:s,children:"Delete control"})]})]})})}function nxt({title:e,subtitle:t,onClose:n,titleAsDialogTitle:r}){const o="truncate text-[13px] font-medium text-foreground",s=r?l.jsx(yo,{className:o,title:e,children:e}):l.jsx("span",{className:o,title:e,children:e});return l.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx(m.SlidersHorizontal,{"aria-hidden":!0,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s,l.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})]}),l.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})}function rxt({control:e,onClose:t}){const n=m.useDashboardStore(d=>d.dashboard),{setDashboardControlsModel:r}=m.useDashboardActions(),o=v.useMemo(()=>Zgt({dashboard:n,controlId:e.id}),[n,e.id]),s=()=>{const d=(n.controls||[]).filter(h=>h.id!==e.id),f={...n.defaultControlValues||{}};delete f[e.id],r(d,f,{removedControlId:e.id}),t()},i=o.totalCards===0?`Delete "${e.label}"?`:`This control is used by ${o.totalCards} ${o.totalCards===1?"card":"cards"}. Deleting it will remove bindings and replace SQL references with NULL on affected cards.`,a=o.cardTitles.slice(0,3).join(", "),c=o.cardTitles.length>3,u=o.totalCards>0?l.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[l.jsxs("p",{children:["Affected cards: ",a,c?` +${o.cardTitles.length-3} more`:""]}),o.sqlCards>0?l.jsxs("p",{children:["SQL references on ",o.sqlCards," ",o.sqlCards===1?"card":"cards"," will be replaced with `NULL`."]}):null,o.configCards>0?l.jsxs("p",{children:["Config bindings on ",o.configCards," ",o.configCards===1?"card":"cards"," will be removed."]}):null]}):void 0;return l.jsx($pe,{defaultOpen:!0,onOpenChange:d=>!d&&t(),description:i,details:u,onConfirm:s})}function zpe(e){return l.jsx(l.Fragment,{children:e.participants.filter(t=>t.matrixSpec&&e.selectedCardIds.includes(t.cardId)).map(t=>{var s;const n=m.getStructuralMatrixTargets(t,e.control.type),r=m.resolveStructuralMatrixTarget(t,e.control,(s=e.selected)==null?void 0:s[t.cardId]),o=n.some(i=>i.id===r);return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"text-xs",children:[t.title,": Matrix target"]}),l.jsxs(m.Select,{value:r??"",onValueChange:i=>e.onChange(t.cardId,i),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":`${t.title}: Matrix target`,children:l.jsx(m.SelectValue,{placeholder:"Choose target"})}),l.jsxs(m.SelectContent,{children:[r&&!o&&l.jsx(m.SelectItem,{value:r,disabled:!0,children:"Missing target"}),n.map(i=>l.jsx(m.SelectItem,{value:i.id,children:i.label},i.id))]})]}),!o&&l.jsx("p",{role:"alert",className:"text-xs text-muted-foreground",children:"Select a Matrix target."})]},t.cardId)})})}function Bpe({onOpen:e,className:t}){return l.jsx("button",{type:"button",className:t??"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Control settings",onClick:n=>{n.stopPropagation(),e==null||e()},children:l.jsx(uf,{className:"h-3 w-3"})})}function oxt({control:e,triggerClassName:t}){const[n,r]=v.useState("closed");return n==="closed"?l.jsx(Bpe,{onOpen:()=>r("settings"),className:t}):n==="delete"?l.jsx(rxt,{control:e,onClose:()=>r("closed")}):l.jsx(sxt,{control:e,triggerClassName:t,onClose:()=>r("closed"),onDelete:()=>r("delete")})}function sxt({control:e,triggerClassName:t,onClose:n,onDelete:r}){const o=m.useDashboardStore(B=>B.dashboard),{setDashboardControlsModel:s}=m.useDashboardActions(),i=m.getPlacementOptionsForScope("dashboard"),a=m.getDefaultPlacement("dashboard"),{participants:c}=Ppe(m.getDashboardCards(o)),u=Ape(o),d=v.useMemo(()=>u[e.id]||[],[u,e.id]),f=m.isStructuralSelectorControlType(e.type)?m.getEligibleParticipantsForStructuralControl(c,e.type):[],h=m.resolveAuthoringControlDefaultValue({control:e,defaultValues:o.defaultControlValues||{}}),p=v.useCallback(B=>({...B,source:B.source.kind==="manual"?{kind:"manual",options:B.source.options.map($=>({...$,presentation:$.presentation?{...$.presentation}:void 0}))}:{...B.source}}),[]),g=v.useCallback(()=>({control:p(e),selectedCardIds:[...d],matrixTargetIds:Object.fromEntries(c.flatMap(B=>{const $=m.resolveStructuralMatrixTarget(B,e);return $?[[B.cardId,$]]:[]})),defaultValue:h}),[p,e,h,d,c]),[x,b]=v.useState(g),y=v.useRef(h),C=x.control,w=x.selectedCardIds,N=m.isStructuralSelectorControlType(C.type)?m.getCompatibleStructuralChoiceCatalog({controlType:C.type,participants:c,selectedCardIds:w}):{choices:[],fieldTargetMap:{},metricTargetMap:{}},S=C.type==="field_selector"?N.choices.map(B=>({option:B,target:N.fieldTargetMap[B.value]})):Array.from(new Map(c.flatMap(B=>B.fieldChoices.map($=>{var P;return[$.value,{option:$,target:(P=B.fieldTargetMap)==null?void 0:P[$.value]}]}))).values()),j=C.type==="metric_selector"?N.choices.map(B=>({option:B,target:N.metricTargetMap[B.value]})):Array.from(new Map(c.flatMap(B=>B.metricChoices.map($=>{var P;return[$.value,{option:$,target:(P=B.metricTargetMap)==null?void 0:P[$.value]}]}))).values()),k=v.useMemo(()=>(o.controls||[]).map(B=>B.id===e.id?C:B),[e.id,o.controls,C]),_=v.useMemo(()=>m.buildAuthoringPreviewControlValues({controls:k,defaultValues:o.defaultControlValues||{},overrides:[{controlId:e.id,value:void 0},{controlId:C.id,value:x.defaultValue}]}),[e.id,o.defaultControlValues,x.defaultValue,C.id,k]),T=B=>{b($=>{const P=B($.control);$.control.source.kind==="manual"&&P.source.kind==="sql_query"&&(y.current=$.defaultValue);const U=$.defaultValue===void 0&&$.control.source.kind==="sql_query"&&P.source.kind==="manual"?y.current:$.defaultValue,H=m.getNextEditedControlDefaultValue({previousControl:$.control,nextControl:P,currentDefaultValue:U});return P.source.kind==="manual"&&(y.current=H),{...$,control:P,defaultValue:H}})},I=B=>{if(!m.isStructuralSelectorControlType(C.type))return;const $=m.getCompatibleStructuralChoiceCatalog({controlType:C.type,participants:c,selectedCardIds:B}),P=m.reconcileStructuralControlChoices({control:C,choices:$.choices});b(U=>({...U,selectedCardIds:B,control:P,defaultValue:m.getNextEditedControlDefaultValue({previousControl:U.control,nextControl:P,currentDefaultValue:U.defaultValue})}))},D=B=>{if(!B.trim())return;const $=m.normalizeDashboardInputVariableName(B);$!==e.id&&Jue(o,{source:"dashboardControl",controlId:e.id}).includes($)||b(P=>P.control.id===$?P:{...P,control:{...P.control,id:$}})},E=()=>{y.current=h,b(g()),n()},R=()=>{const B={...o.defaultControlValues||{}};delete B[e.id];let $=x.control,P;const U=m.structuralControlBindingsChanged({control:e,cardIds:d,matrixTargetIds:g().matrixTargetIds},{control:$,cardIds:x.selectedCardIds,matrixTargetIds:x.matrixTargetIds});if(m.isStructuralSelectorControlType($.type)&&U){const q=m.getCompatibleStructuralChoiceCatalog({controlType:$.type,participants:c,selectedCardIds:x.selectedCardIds});$=m.reconcileStructuralControlChoices({control:$,choices:q.choices}),P=Object.fromEntries(d.filter(Y=>!x.selectedCardIds.includes(Y)).map(Y=>[Y,void 0])),x.selectedCardIds.length>0&&$.source.kind==="manual"&&$.source.options.length>0&&Object.assign(P,m.buildStructuralControlBindingsForParticipants({control:$,participants:c,selectedCardIds:x.selectedCardIds,matrixTargetIds:x.matrixTargetIds}))}!m.isStructuralSelectorControlType($.type)&&m.isStructuralSelectorControlType(e.type)&&(P=Object.fromEntries(d.map(q=>[q,void 0]))),$.initialValueStrategy==="saved_default"&&x.defaultValue!==void 0&&(B[$.id]=x.defaultValue),$={...$,defaultValue:B[$.id]},$=m.syncSqlQueryControlExecutionRequirement($,B[$.id]);const H=(o.controls||[]).map(q=>q.id===e.id?$:q),G={renamed:$.id!==e.id?{oldId:e.id,newId:$.id}:void 0,cardBindingsById:P,affectedBindingControlIds:m.isStructuralSelectorControlType($.type)?[$.id]:m.isStructuralSelectorControlType(e.type)?[e.id]:void 0};s(H,B,G),n()},F=m.isStructuralSelectorControlType(e.type),M=B=>{B||E()},O=l.jsx(Bpe,{className:t}),z=l.jsx(Ope,{control:C,defaultValue:x.defaultValue,defaultPlacement:a,placementOptions:i,previewControlDefinitions:k,previewControlValues:_,availableFieldChoices:S,availableMetricChoices:j,allowCardDefault:!0,structuralParticipantSelector:m.isStructuralSelectorControlType(C.type)?l.jsxs(l.Fragment,{children:[l.jsx(Ipe,{type:C.type,participants:f.map(B=>({cardId:B.cardId,title:B.title,choiceCount:C.type==="field_selector"?B.fieldChoices.length:B.metricChoices.length})),selectedCardIds:w,onChange:I}),l.jsx(zpe,{participants:c,selectedCardIds:w,control:e,selected:x.matrixTargetIds,onChange:(B,$)=>b(P=>({...P,matrixTargetIds:{...P.matrixTargetIds,[B]:$}}))})]}):null,onChangeControl:T,onChangeDefaultValue:B=>{C.source.kind==="manual"&&(y.current=B),b($=>({...$,defaultValue:B}))},onCommitControlId:D}),L=l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",onClick:r,children:"Delete"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:E,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:R,disabled:m.isStructuralSelectorControlType(C.type)&&!m.hasStructuralMatrixTargets({participants:c,selectedCardIds:w,control:e,selected:x.matrixTargetIds}),children:"Accept"})]})]}),V=C.label||"Control",A=m.getFriendlyTypeOption(C.type).label;return l.jsx(Lpe,{open:!0,onOpenChange:M,trigger:O,title:V,subtitle:A,description:"Update how this control appears and behaves in the dashboard toolbar.",body:z,footer:L,onClose:E,useDialog:F})}function ixt(e,t){return e.length===t.length&&e.every((n,r)=>{var o,s;return n.value===((o=t[r])==null?void 0:o.value)&&n.label===((s=t[r])==null?void 0:s.label)})}function axt(e){if(!(e.source.kind!=="sql_query"||e.type!=="enum"&&e.type!=="multi_enum"))return e.source}function lxt(e){return e.source.kind==="manual"?e.source.options:[]}function cxt({control:e,value:t,popoverOpen:n,controlDefinitionsOverride:r,controlValuesOverride:o,activeFiltersOverride:s}){const i=axt(e),a=v.useMemo(()=>{const w=zz(i);return w===null?null:`${e.id}:${e.type}:${w}`},[e.id,e.type,i]),c=i!==void 0&&(n||$z(t)),u=cC({controlId:e.id,source:i,enabled:c,controlDefinitionsOverride:r,controlValuesOverride:o,activeFiltersOverride:s}),[d,f]=v.useState(()=>({key:a,labels:new Map,options:[]})),h=u.options,p=c&&!u.isLoading&&!u.isFetching&&!u.isError,g=h.length>0||p;if(v.useEffect(()=>{if(!i){f(w=>w.key===null&&w.options.length===0?w:{key:null,labels:new Map,options:[]});return}f(w=>{const N=w.key===a;if(!g)return N?w:{key:a,labels:new Map,options:[]};const S=N?new Map(w.labels):new Map;let j=!N;for(const k of h)S.get(k.value)!==k.label&&(S.set(k.value,k.label),j=!0);return N&&!j&&ixt(w.options,h)?w:{key:a,labels:S,options:h}})},[h,g,a,i]),!i)return{options:lxt(e),labelByValue:void 0,isInitialLoading:!1,hasBlockingError:!1};const x=new Map(d.key===a?d.labels:void 0);for(const w of h)x.set(w.value,w.label);const b=[...g?h:d.key===a?d.options:[]],y=new Set(b.map(w=>w.value)),C=w=>{typeof w!="string"||w.length===0||y.has(w)||(y.add(w),b.push({value:w,label:x.get(w)??w}))};if(Array.isArray(t))for(const w of t)C(w);else C(t);return{options:b,labelByValue:x,isInitialLoading:u.isLoading&&b.length===0,hasBlockingError:u.isError&&b.length===0}}const uxt=24,dxt=/^\d{4}-\d{2}-\d{2}$/;function Vf(e,t=uxt){return e.length<=t?e:`${e.slice(0,t-1)}…`}function fxt(e,t,n,r){if(t==null||t==="")return null;if(e.type==="date")try{if(typeof t=="string"&&dxt.test(t)){const[s,i,a]=t.split("-").map(Number);return Lt.format(new Date(s,i-1,a),"MMM d, yyyy")}const o=t instanceof Date?t:new Date(t);return Number.isNaN(o.getTime())?null:Lt.formatInTimeZone(o,n,"MMM d, yyyy")}catch{return null}if(e.type==="multi_enum"&&Array.isArray(t)){if(t.length===0)return null;if(t.length===1){const o=L2(e,t[0],r);return o!==null?Vf(o):e.source.kind==="sql_query"?null:Vf(String(t[0]))}return`${t.length} selected`}if(e.type==="enum"){const o=L2(e,t,r);return o!==null?Vf(o):e.source.kind==="sql_query"?null:Vf(String(t))}if(Fde(e)){const o=L2(e,t,r);return Vf(o===null?String(t):o)}return e.type==="boolean"?t?"On":"Off":Vf(String(t))}function L2(e,t,n){const r=String(t);if(n!=null&&n.has(r))return n.get(r)??null;const o=e.source;if(!o)return null;if(o.kind==="manual"&&Array.isArray(o.options)){const a=o.options.find(c=>c.value===t);return(a==null?void 0:a.label)??null}const i=hxt(e,t).find(a=>a.value===t);return i?i.label:null}function hxt(e,t){const n=Lz(e);return!(t===Id.CONTROL_CARD_DEFAULT_VALUE||e.defaultValue===Id.CONTROL_CARD_DEFAULT_VALUE)||n.some(o=>o.value===MP.value)?n:[MP,...n]}function mxt(e){return e.type==="date"?Pv:m.SlidersHorizontal}function pxt(e){return e.type==="date"?360:e.type==="multi_enum"?300:e.type==="number"?240:280}function Vpe({control:e,value:t,isEditing:n=!1,dragListeners:r,dragAttributes:o,onChange:s,onUpdateControl:i,disabled:a=!1,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d,actions:f}){const h=xl("interactive"),[p,g]=v.useState(!1),x=vl(),b=cxt({control:e,value:t,popoverOpen:p,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d}),y=fxt(e,t,x,b.labelByValue),C=$z(t),w=y!==null,N=e.showLabel??!0,S=a||e.locked===!0,j=gxt(e,t,S),k=mxt(e);return l.jsxs("div",{className:"group/chip flex shrink-0 items-center gap-2",children:[n&&r&&l.jsx("span",{role:"button",tabIndex:-1,"aria-label":"Drag to reorder",className:"inline-flex h-7 cursor-grab items-center justify-center px-0.5 text-muted-foreground/50 transition-colors hover:text-muted-foreground active:cursor-grabbing",...r,...o,children:l.jsx(Iu,{className:"size-3"})}),l.jsxs(m.Popover,{open:p,onOpenChange:g,children:[l.jsxs("div",{className:m.cn("inline-flex h-7 items-stretch overflow-hidden rounded-control border border-border text-[12px] transition-colors",C?h.hasAppearance?"bg-accent/80 hover:bg-accent":"bg-muted/80 hover:bg-muted":h.hasAppearance?"bg-muted/40 hover:bg-accent/50":"bg-muted/40 hover:bg-muted/70"),style:h.chipStyle,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":w?`${e.label}: ${y}`:e.label,className:m.cn("inline-flex items-center gap-1.5 pl-2 focus:outline-none",C&&j||n?"pr-1":"pr-2"),children:[l.jsx(k,{className:m.cn("h-3 w-3 shrink-0",C?"text-muted-foreground":"text-muted-foreground/70")}),N&&l.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:e.label}),w&&l.jsxs(l.Fragment,{children:[N&&l.jsx("span",{className:"text-border","aria-hidden":"true",children:"·"}),l.jsx("span",{className:"max-w-[160px] truncate whitespace-nowrap font-medium text-foreground",children:y})]}),l.jsx(Re.ChevronDown,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"})]})}),C&&j&&l.jsx("button",{type:"button",onClick:_=>{_.preventDefault(),_.stopPropagation(),s(void 0)},"aria-label":`Clear ${e.label}`,className:"inline-flex w-6 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(Re.X,{className:"h-3 w-3"})}),n&&l.jsx("span",{className:"inline-flex shrink-0 items-center justify-center",children:f!==void 0?l.jsx("span",{className:"inline-flex items-center px-1",children:f}):l.jsx(oxt,{control:e,triggerClassName:"inline-flex h-full w-7 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"})})]}),l.jsx(m.PopoverContent,{align:"start",sideOffset:4,style:{width:pxt(e),...h.contentStyle},className:m.cn(YW(e)||ZW(e)?"p-1.5":"p-3"),onMouseDown:_=>_.stopPropagation(),onClick:_=>_.stopPropagation(),children:YW(e)?l.jsx(XW,{control:e,value:t,disabled:S,multi:!1,options:b.options,isInitialLoading:b.isInitialLoading,hasBlockingError:b.hasBlockingError,onChange:_=>{s(_),g(!1)}}):ZW(e)?l.jsx(XW,{control:e,value:t,disabled:S,multi:!0,options:b.options,isInitialLoading:b.isInitialLoading,hasBlockingError:b.hasBlockingError,onChange:_=>{g(!1),s(_)}}):l.jsx(RP,{control:e,value:t,onChange:s,showLabel:!1,disabled:S,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d})})]})]})}function YW(e){return e.type==="enum"&&(e.source.kind==="manual"||e.source.kind==="sql_query")}function ZW(e){return e.type==="multi_enum"&&(e.source.kind==="manual"||e.source.kind==="sql_query")}function XW({control:e,value:t,disabled:n,multi:r,options:o,isInitialLoading:s,hasBlockingError:i,onChange:a}){return s?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"Loading options…"}):i?l.jsx(Bue,{}):r?l.jsx(bxt,{control:e,options:o,value:t,disabled:n,onChange:a}):l.jsx(xxt,{control:e,options:o,value:t,disabled:n,onChange:a})}function gxt(e,t,n){return!n&&!e.requiredAtExecution&&$z(t)}function xxt({control:e,options:t,value:n,disabled:r,onChange:o}){return t.length===0?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"No options"}):l.jsx("div",{role:"radiogroup",className:"flex flex-col gap-0.5",children:t.map(s=>{const i=n===s.value;return l.jsxs("button",{type:"button",role:"radio","aria-checked":i,disabled:r,onClick:()=>{r||o(s.value)},className:m.cn("flex w-full items-center gap-2 rounded-[4px] px-1.5 py-1 text-left text-[13px] transition-colors",r?"cursor-not-allowed opacity-50":i?"bg-muted text-foreground hover:bg-foreground/[0.08]":"text-foreground hover:bg-muted"),children:[l.jsx($ue,{checked:i,className:m.cn("h-3.5 w-3.5",r&&"opacity-50")}),l.jsx("span",{className:"truncate",children:s.label})]},String(s.value))})})}function bxt({control:e,options:t,value:n,disabled:r,onChange:o}){const[s,i]=v.useState(""),[a,c]=v.useState(()=>QW(n)),[u,d]=v.useState(!1),f=v.useMemo(()=>QW(n),[n]),h=u?a:f,p=v.useMemo(()=>{const C=s.trim().toLowerCase();return C?t.filter(w=>w.label.toLowerCase().includes(C)||w.value.toLowerCase().includes(C)):t},[t,s]),g=v.useMemo(()=>new Set(h.map(C=>String(C))),[h]),x=()=>{if(r)return;const C=a.length===0&&!e.requiredAtExecution?void 0:a;o(C),d(!1)},b=()=>{r||e.requiredAtExecution||(c([]),d(!0))},y=C=>{if(r)return;const w=String(C),N=g.has(w);N&&h.length===1&&e.requiredAtExecution||(d(!0),c(()=>N?h.filter(S=>String(S)!==w):[...h,C]))};return t.length===0?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"No options"}):l.jsxs("div",{className:"flex min-w-0 flex-col",children:[l.jsxs("div",{className:"mb-1.5 flex h-7 shrink-0 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring",children:[l.jsx(Ft.Search,{className:"h-3 w-3 shrink-0 text-muted-foreground","aria-hidden":"true"}),l.jsx("input",{type:"text",value:s,onChange:C=>i(C.target.value),placeholder:`Search ${e.label.toLowerCase()}`,"aria-label":`Search ${e.label.toLowerCase()}`,className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),l.jsx("div",{role:"listbox","aria-multiselectable":"true",className:"-mx-0.5 max-h-[260px] overflow-y-auto px-0.5",children:p.length===0?l.jsx("div",{className:"px-2 py-6 text-center text-[12px] text-muted-foreground",children:s?"No matches":"No options"}):p.map(C=>{const w=g.has(String(C.value)),N=r||w&&h.length===1&&e.requiredAtExecution;return l.jsxs("button",{type:"button",role:"option","aria-selected":w,disabled:N,onClick:()=>y(C.value),className:m.cn("flex w-full items-center gap-2 rounded-[4px] px-1.5 py-1 text-left text-[13px] transition-colors",N?"cursor-not-allowed opacity-50":w?"bg-muted text-foreground hover:bg-foreground/[0.08]":"text-foreground hover:bg-muted"),children:[l.jsx("span",{"aria-hidden":"true",className:m.cn("inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background text-primary",w&&"border-primary bg-primary text-primary-foreground",N&&"opacity-60"),children:w?l.jsx(m.Check,{className:"h-2.5 w-2.5",strokeWidth:3}):null}),l.jsx("span",{className:"truncate",children:C.label})]},String(C.value))})}),l.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2 border-t border-border pt-1.5",children:[l.jsxs("span",{className:"px-0.5 text-[11px] text-muted-foreground",children:[l.jsx("span",{className:"tabular-nums text-foreground",children:h.length})," ","selected"]}),l.jsxs("div",{className:"flex items-center gap-1",children:[!e.requiredAtExecution&&(u||f.length>0)&&l.jsx("button",{type:"button",onClick:b,className:"inline-flex h-6 items-center rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground",children:"Clear"}),l.jsx("button",{type:"button",onClick:x,disabled:r||!u,className:"inline-flex h-6 items-center rounded-control bg-primary px-2 text-[12px] text-primary-foreground disabled:pointer-events-none disabled:opacity-50",children:"Apply"})]})]})]})}function QW(e){return Array.isArray(e)?e:e==null?[]:[e]}function yxt(e,t,n){if(t===n)return null;const r=e.indexOf(t),o=e.indexOf(n);return r===-1||o===-1?null:up(e,r,o)}function vxt({control:e,controls:t,reservedVariableNames:n=[],activeFiltersOverride:r,onUpdateControl:o,onRemoveControl:s}){const[i,a]=v.useState(!1),[c,u]=v.useState(!1),d=m.getPlacementOptionsForScope("dashboard"),f=m.getDefaultPlacement("dashboard"),h=v.useMemo(()=>Cxt(t),[t]),p=m.resolveAuthoringControlDefaultValue({control:e,defaultValues:h}),g=v.useCallback(z=>({...z,source:z.source.kind==="manual"?{kind:"manual",options:z.source.options.map(L=>({...L,presentation:L.presentation?{...L.presentation}:void 0}))}:{...z.source}}),[]),x=v.useCallback(()=>({control:g(e),defaultValue:p}),[g,e,p]),[b,y]=v.useState(x),C=v.useRef(p),w=b.control,N=v.useMemo(()=>t.map(z=>z.id===e.id?w:z),[e.id,t,w]),S=v.useMemo(()=>m.buildAuthoringPreviewControlValues({controls:N,defaultValues:h,overrides:[{controlId:e.id,value:void 0},{controlId:w.id,value:b.defaultValue}]}),[e.id,h,b.defaultValue,w.id,N]),j=z=>{y(L=>{const V=z(L.control);L.control.source.kind==="manual"&&V.source.kind==="sql_query"&&(C.current=L.defaultValue);const A=L.defaultValue===void 0&&L.control.source.kind==="sql_query"&&V.source.kind==="manual"?C.current:L.defaultValue,B=m.getNextEditedControlDefaultValue({previousControl:L.control,nextControl:V,currentDefaultValue:A});return V.source.kind==="manual"&&(C.current=B),{...L,control:V,defaultValue:B}})},k=z=>{if(!z.trim())return;const L=m.normalizeDashboardInputVariableName(z);L!==e.id&&(n.includes(L)||t.some(V=>V.id===L&&V.id!==e.id))||y(V=>V.control.id===L?V:{...V,control:{...V.control,id:L}})},_=()=>{C.current=p,y(x()),a(!1)},T=()=>{if(!o){_();return}const z=w.initialValueStrategy==="saved_default"?b.defaultValue:void 0,L=m.syncSqlQueryControlExecutionRequirement({...w,defaultValue:z});o(wxt(L)),a(!1)},I=z=>{if(z){C.current=p,y(x()),a(!0);return}_()},D=()=>{s==null||s(),u(!1),a(!1)},E=w.label||"Control",R=m.getFriendlyTypeOption(w.type).label,F=l.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Control settings",onClick:z=>z.stopPropagation(),children:l.jsx(uf,{className:"h-3 w-3"})}),M=l.jsx(Ope,{control:w,defaultValue:b.defaultValue,defaultPlacement:f,placementOptions:d,previewControlDefinitions:N,previewControlValues:S,allowControlIdEdit:!0,showPlacementSelect:!1,showViewerVisibilityToggle:!1,activeFiltersOverride:r,onChangeControl:j,onChangeDefaultValue:z=>{w.source.kind==="manual"&&(C.current=z),y(L=>({...L,defaultValue:z}))},onCommitControlId:k}),O=l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",onClick:()=>u(!0),children:"Delete"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:_,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:T,children:"Accept"})]})]});return l.jsx(Lpe,{open:i,onOpenChange:I,trigger:F,title:E,subtitle:R,description:"Update how this control appears and behaves in the document toolbar.",body:M,footer:O,onClose:_,deleteDialogOpen:c,onDeleteDialogOpenChange:u,deleteDescription:`Delete "${e.label}" from this document sheet?`,onConfirmDelete:D})}function wxt(e){const t={...e};return delete t.placement,delete t.hidden,t}function Cxt(e){const t={};for(const n of e)n.defaultValue!==void 0&&(t[n.id]=n.defaultValue);return t}function Hpe({className:e,sheetId:t,inputs:n,dashboardInputsById:r,filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,onSetFilterValue:c,onSetFilterMode:u,onUpdateFilterInput:d,onUpdateControlInput:f,onRemoveFilterValue:h,onRemoveInput:p,onReorderInputs:g,controlValuesByInputId:x,onSetControlValue:b,actions:y,isEditing:C=!1}){const w=v.useMemo(()=>n.filter(oc).map(E=>E.control),[n]),N=m.useDashboardStore(E=>{var R;return((R=E.dashboard.filterLayout)==null?void 0:R.toolbarWrap)??!1}),S=C&&!!g,j=v.useMemo(()=>n.map(E=>E.id),[n]),k=bC(Em(cp,{activationConstraint:{distance:5}}));function _(E){const{active:R,over:F}=E;if(!F)return;const M=yxt(j,String(R.id),String(F.id));M&&(g==null||g(M))}const T=l.jsx("span",{className:"block shrink-0 text-[12px] text-muted-foreground",children:"None yet"}),I=n.map(E=>l.jsx(Sxt,{inputId:E.id,canReorder:S,children:R=>l.jsx(Nxt,{input:E,sheetId:t,dragHandle:R,dashboardInput:r.get(E.id),filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,documentControlDefinitions:w,onSetFilterValue:c,onSetFilterMode:u,onUpdateFilterInput:d,onUpdateControlInput:f,onRemoveFilterValue:h,onRemoveInput:p,reservedVariableNames:n.filter(F=>F.id!==E.id).map(F=>F.variableName),controlValuesByInputId:x,onSetControlValue:b,isEditing:C})},E.id)),D=N?l.jsxs(cO,{wrap:!0,className:"w-full gap-3 pr-0",children:[I.length>0?I:l.jsx(zk,{children:T}),y?l.jsx(zk,{children:y}):null]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"min-w-0 overflow-x-auto overflow-y-hidden",children:l.jsx(cO,{empty:T,children:I})}),y?l.jsx("div",{className:"shrink-0 justify-self-end",children:y}):null]});return l.jsx("div",{className:m.cn("sticky top-0 z-30 shrink-0 gap-3 border-b bg-background/95 px-3 py-1.5 shadow-[0_1px_0_rgba(0,0,0,0.04)] backdrop-blur supports-[backdrop-filter]:bg-background/90",N?"flex min-h-10 items-start overflow-visible":"grid h-10 grid-cols-[minmax(0,1fr)_auto] items-center overflow-hidden",e),children:S?l.jsx(Sb,{sensors:k,collisionDetection:wb,onDragEnd:_,children:l.jsx(Nb,{items:j,strategy:FT,children:D})}):D})}function Sxt({inputId:e,canReorder:t,children:n}){const{attributes:r,listeners:o,setNodeRef:s,transform:i,transition:a,isDragging:c}=dp({id:e,disabled:!t});return t?l.jsx(zk,{ref:s,style:{transform:Pi.Translate.toString(i),transition:a,opacity:c?.5:1,zIndex:c?10:void 0},children:n({listeners:o,attributes:r})}):l.jsx(zk,{children:n(void 0)})}function Nxt({input:e,sheetId:t,dragHandle:n,dashboardInput:r,filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,documentControlDefinitions:c,onSetFilterValue:u,onSetFilterMode:d,onUpdateFilterInput:f,onUpdateControlInput:h,onRemoveFilterValue:p,onRemoveInput:g,reservedVariableNames:x,controlValuesByInputId:b,onSetControlValue:y,isEditing:C}){if(e.kind==="control"){const D=Object.prototype.hasOwnProperty.call(b,e.id)?b[e.id]:a[e.control.id];return l.jsx(Vpe,{control:e.control,value:D,isEditing:C,dragListeners:C?n==null?void 0:n.listeners:void 0,dragAttributes:C?n==null?void 0:n.attributes:void 0,onChange:E=>y(e.id,E),onUpdateControl:E=>h==null?void 0:h(e.id,E),controlDefinitionsOverride:c,controlValuesOverride:a,activeFiltersOverride:i,actions:C?l.jsx(vxt,{control:e.control,controls:c,reservedVariableNames:x,activeFiltersOverride:i,onUpdateControl:E=>h==null?void 0:h(e.id,E),onRemoveControl:()=>g==null?void 0:g(e.id)}):null})}const w=e,N=Sx(w,o[w.id]),S=N?[N]:[],j=s[w.id]||Cpe(w.filter.operation),k=VT(w.filter.operation)?{...w.filter,operation:lO(j)}:w.filter,_=(r==null?void 0:r.kind)==="filter"?r:void 0;function T(D,E){const R={...w.filter,...D,operation:w.filter.operation};return f==null?void 0:f(w.id,R,E)}const I=_?{storageTarget:"dashboardInput",dashboardInput:_,sheetId:t,sheetKind:"document"}:{storageTarget:"card",sheetId:t,sheetKind:"document",inlineFilterValues:S,setInlineFilterValue:D=>u(w.id,D),removeInlineFilterValue:()=>p(w.id),setInlineFilterMode:(D,E)=>d(w.id,E),inputContext:Xle({filter:k,scope:{sheetId:t,sheetKind:"document"},values:i,controls:{definitions:c,values:a}})};return l.jsx(mz,{filter:k,isEditing:C,dragListeners:C?n==null?void 0:n.listeners:void 0,dragAttributes:C?n==null?void 0:n.attributes:void 0,settingsVariant:"document",inputVariableName:w.variableName,reservedInputVariableNames:x,onUpdateFilter:T,onRemoveFilter:()=>g==null?void 0:g(w.id),storageOptions:I})}function Bk(e,t,n){const r=new Set(t),o=[...n];return e.map(s=>r.has(s.id)?o.shift()??s.id:s.id)}function jxt({sections:e,inputs:t,selectedSectionId:n,onSelectSection:r,onDeleteSection:o,onReorderSection:s,onInsertSection:i}){const[a,c]=v.useState(null),[u,d]=v.useState(!1);return l.jsxs("aside",{"data-testid":"document-outline",className:"flex w-64 shrink-0 flex-col border-r bg-background",children:[l.jsxs("div",{className:"flex h-10 items-center justify-between border-b px-3",children:[l.jsxs("div",{className:"flex items-baseline gap-1.5",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Sections"}),l.jsxs("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground",children:["· ",e.length]})]}),i?l.jsxs(m.Popover,{open:u,onOpenChange:d,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Add section",className:"inline-flex h-6 items-center gap-1 rounded-[4px] px-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[l.jsx(Ar,{className:"h-3 w-3"}),"Add"]})}),l.jsx(m.PopoverContent,{align:"end",side:"bottom",sideOffset:6,className:"w-48 p-1",children:ppe.map(f=>{const h=F0(f);return l.jsxs("button",{type:"button",onClick:()=>{i(f),d(!1)},className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[12px] text-foreground transition-colors hover:bg-muted",children:[l.jsx(h,{className:"h-3.5 w-3.5 text-muted-foreground"}),wC[f]]},f)})})]}):null]}),l.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:e.length===0?l.jsx("p",{className:"px-3 py-3 text-[12px] text-muted-foreground",children:"No sections yet"}):e.map(f=>{const h=F0(f.type),p=f.id===n,g=agt(f,t),x=lgt(f);return l.jsxs("div",{"data-testid":`document-outline-section-${f.id}`,"data-selected":p?"true":void 0,draggable:!0,onDragStart:b=>{c(f.id),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("application/x-semaphor-document-section",f.id)},onDragOver:b=>{!a||a===f.id||(b.preventDefault(),b.dataTransfer.dropEffect="move")},onDrop:b=>{b.preventDefault();const y=b.dataTransfer.getData("application/x-semaphor-document-section")||a;if(y&&y!==f.id){const C=b.currentTarget.getBoundingClientRect(),w=b.clientY<C.top+C.height/2?"before":"after";s(y,f.id,w)}c(null)},onDragEnd:()=>c(null),className:m.cn("group mx-1 flex w-[calc(100%-8px)] items-start rounded transition-colors",p?"bg-muted":"hover:bg-muted/70",a===f.id&&"opacity-40"),children:[l.jsxs("button",{type:"button",onClick:()=>r(f.id),className:"flex min-w-0 flex-1 items-start gap-2 rounded-l px-2 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[l.jsx(Iu,{className:"mt-0.5 h-3 w-3 shrink-0 cursor-grab text-muted-foreground/50"}),l.jsx(h,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:m.cn("truncate text-[13px] leading-tight",p?"font-medium text-foreground":"text-foreground/90"),children:g}),x?l.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:x}):null]})]}),l.jsx("div",{className:"flex shrink-0 items-center pr-1 pt-2 opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 group-data-[selected=true]:opacity-100",children:l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-destructive","aria-label":`Delete ${g}`,onClick:b=>{b.stopPropagation(),o(f.id)},children:l.jsx(Re.X,{className:"h-3 w-3"})})})]},f.id)})})]})}const $2=[];function kxt({card:e,queryOptions:t,surfaceMode:n,previewRowLimit:r,onPreviewRowLimitChange:o}){const{authToken:s,tokenProps:i}=Mt(),a=m.useDashboardStore(re=>re.authToken),u=Zg(e)?n==="print"?"export-full-with-cap":"preview-window":void 0,d=u?u==="preview-window"&&r||WC(u):void 0,f=v.useMemo(()=>{if(u!=="preview-window")return"";const{paginationConfig:re,...te}=e;return JSON.stringify({card:te,queryOptions:t,surfaceMode:n})},[e,u,t,n]),h=v.useRef(null),p=v.useMemo(()=>u&&d?{...e,paginationConfig:{page:1,pageSize:d}}:e,[e,d,u]),g=v.useMemo(()=>({...t,...u?{documentTableDataPolicy:u}:{}}),[u,t]),x=yu(p,g),b=!!u&&x.isFetching&&(x.isPlaceholderData||x.dataUpdatedAt===0),y=b?void 0:x.data,C=v.useMemo(()=>Array.isArray(y==null?void 0:y.records)?y.records:$2,[y==null?void 0:y.records]),w=h.current,N=u==="preview-window"&&x.isFetching&&!x.error&&!y&&(w==null?void 0:w.identity)===f,S=N?w.records:C,j=N?w.data:y,k=N?w.pagination:b?void 0:x.pagination,_=N?w.comparisonMetadata:b?void 0:x.comparisonMetadata,T=N?w.queryRequestPayload:b?void 0:x.queryRequestPayload,I=N?w.dataUpdatedAt:x.dataUpdatedAt;v.useEffect(()=>{u!=="preview-window"||b||C.length===0||!y||(h.current={identity:f,data:y,pagination:x.pagination,comparisonMetadata:x.comparisonMetadata,queryRequestPayload:x.queryRequestPayload,records:C,dataUpdatedAt:x.dataUpdatedAt})},[x.comparisonMetadata,x.data,x.dataUpdatedAt,x.pagination,x.queryRequestPayload,y,b,u,f,C]);const D=typeof(k==null?void 0:k.totalCount)=="number"?k.totalCount:void 0,E=!u||typeof(k==null?void 0:k.totalCount)=="number",R=u==="export-full-with-cap"&&D!==void 0&&D>LD,F=v.useMemo(()=>JSON.stringify(x.queryKey),[x.queryKey]),M=u&&d&&D!==void 0&&!R&&u==="export-full-with-cap"?Math.max(1,Math.ceil(D/d)):1,O=u&&d&&E&&M>1?Array.from({length:M-1},(re,te)=>te+2):[],z=T,L=(s==null?void 0:s.accessToken)||(a==null?void 0:a.accessToken)||"",V=cf({queries:O.map(re=>({queryKey:["documentTableRows",F,I,re,d,i.apiServiceUrl],enabled:!!(u&&d&&z&&L&&E&&!R),queryFn:async()=>{const te={...z||{},pagination:{page:re,pageSize:d}};return delete te.tableTotalsRequest,m.postRequest(`${i.apiServiceUrl}/v1/query`,L,te)}}))}),A=V.map(re=>{var Q;const te=Array.isArray((Q=re.data)==null?void 0:Q.records)?re.data.records.length:0;return`${re.dataUpdatedAt}:${te}`}).join("|"),B=v.useMemo(()=>V.length===0?$2:V.flatMap(re=>{var te;return Array.isArray((te=re.data)==null?void 0:te.records)?re.data.records:$2}),[V.length,A]),$=v.useMemo(()=>u?B.length===0?S:[...S,...B]:S,[B,S,u]),P=V.map(re=>{var te,Q;return re.error?{error:m.getRequestErrorMessage(re.error,"Query failed",{preserveSyntheticMessage:!0}),sql:m.getRequestErrorSql(re.error)||""}:(te=re.data)!=null&&te.error?{error:m.getRequestErrorMessage(re.data,"Query failed"),sql:m.getRequestErrorSql(re.data)||(typeof((Q=re.data)==null?void 0:Q.errorSql)=="string"?re.data.errorSql:"")}:void 0}).find(Boolean),U=b&&!N?"":x.errorMessage,H=u&&T&&!x.isLoading&&!x.isPending&&!U&&!E?"Document table queries require backend pagination metadata.":"",G=R&&D!==void 0?`This table has ${D.toLocaleString()} rows. Paginated report export currently supports up to ${LD.toLocaleString()} rows. Add filters or reduce the result set before exporting.`:"",q=U||(P==null?void 0:P.error)||H||G,Y=x.errorSql||(P==null?void 0:P.sql)||"",W=[u??"single-query",I,A,$.length,D??"unknown",q].join(":"),ne=V.some(re=>re.isFetching),Z=V.some(re=>re.isLoading||re.isPending),K=u==="export-full-with-cap"&&!q&&M>1&&B.length+S.length<Math.min(D??0,LD),X=u==="preview-window"&&D!==void 0&&$.length<D,J=v.useCallback(()=>{u!=="preview-window"||!o||!d||o(Math.min(d+WC("preview-window"),D??d+WC("preview-window")))},[o,d,u,D]);return{data:j&&{...j,records:$},records:$,pagination:k,comparisonMetadata:_,queryRequestPayload:T,errorMessage:q,errorSql:Y,isLoading:!N&&x.isLoading||Z||K,isPending:!N&&x.isPending||Z||K,isFetching:x.isFetching||ne,isPreviewWindowIncomplete:X,loadedRowCount:$.length,totalRowCount:D,rowDataVersion:W,loadMorePreviewRows:X&&o?J:void 0}}function Ixt(e){return ww(e)}function _xt(e){var o,s,i,a;if(!Ixt(e)||!XI(e))return[];const t=(s=(o=e.preferences)==null?void 0:o.tablePrefs)==null?void 0:s.columnSettingsMap,n=(a=(i=e.preferences)==null?void 0:i.tablePrefs)==null?void 0:a.columnVisibility;let r=!1;return hL(e).flatMap(c=>oTe(c,n)?c.role!=="metric"&&!r?(r=!0,[XV(c,t)]):c.role==="metric"?[XV(c,t)]:[]:[])}function qpe(e){return sTe(e)}function Txt(e){return Sw(e)}function Dxt(e){return!!(e!=null&&e.columns.some(t=>t.behavior!=="label"))}function Ext(e){return iTe(e)}const Mxt={mode:"table-print"},Rxt={suppressSortControls:!0,renderPlainWrapper:!0,disableDashboardInteractions:!0};function Axt(e){return e.interactionConfig?{...e,interactionConfig:void 0}:e}function Fxt(e){return Array.from(e.querySelectorAll("tbody tr, tfoot tr"))}function Pxt({sectionElement:e,tableSurfaceElement:t,firstRowElement:n,lastRowElement:r,measurementScale:o}){const s=Number.isFinite(o)&&o>0?o:1,i=e.getBoundingClientRect(),a=t==null?void 0:t.getBoundingClientRect(),c=n.getBoundingClientRect(),u=r.getBoundingClientRect(),d=r.closest("table"),f=d?d.getBoundingClientRect().bottom:u.bottom,h=Math.max(0,(c.top-i.top)/s),p=Math.max(0,(Math.max(f,u.bottom)-u.bottom)/s),g=t?Oxt({sectionRect:i,tableSurfaceElement:t,tableSurfaceRect:a,measurementScale:s}):void 0;return{chromeHeightPx:Math.ceil(h+p),trailingChromePx:Math.ceil(p),...g!==void 0?{renderedMinHeightPx:g}:{}}}function Oxt({sectionRect:e,tableSurfaceElement:t,tableSurfaceRect:n,measurementScale:r}){const o=window.getComputedStyle(t),s=Number.parseFloat(o.minHeight||"0")||0;if(s<=0||!n)return;const i=Math.max(0,(n.top-e.top)/r);return Math.ceil(i+s)}function JW(e){return e==null?void 0:e.closest('[data-testid="document-page"]')}function Upe(e){return e==null?void 0:e.querySelector('[data-document-region="footer"]')}function Lxt(e){const t=Number.parseFloat(e.style.height||"")||Number.parseFloat(e.style.minHeight||"");if(t>0)return t;const n=window.getComputedStyle(e),r=Number.parseFloat(n.height||"")||Number.parseFloat(n.minHeight||"");return r>0?r:e.clientHeight}function $xt(e,t){return e?Math.abs(e.rowHeightPx-t.rowHeightPx)>1||Math.abs((e.averageRowHeightPx??e.rowHeightPx)-(t.averageRowHeightPx??t.rowHeightPx))>1||zxt(e.rowHeightsPx,t.rowHeightsPx)||Math.abs(e.chromeHeightPx-t.chromeHeightPx)>1||Math.abs((e.renderedMinHeightPx??0)-(t.renderedMinHeightPx??0))>1||e.rowsPerPage!==t.rowsPerPage:!0}function zxt(e,t){return!e&&!t?!1:!e||!t||e.length!==t.length?!0:e.some((n,r)=>{const o=t[r];return n===void 0||o===void 0?n!==o:Math.abs(n-o)>1})}const eG=40,HT=18,Bxt=120;function fu({section:e,totalRowCount:t=0,layoutMeasurement:n}){var g;const r=qxt(e),o=r!=="unsupported",s=!!(e.card.connectionId||(g=e.card.dataSource)!=null&&g.connectionId),i=Uxt(e,r),a=r==="table"?Kxt(e):[],c=a.length>0?1:0,u=Math.max(0,t),d=Vxt(e),f=n==null?void 0:n.rowHeightPx,h=n==null?void 0:n.averageRowHeightPx,p=n==null?void 0:n.rowHeightsPx;return{sectionId:e.id,kind:r,isSupported:o,hasConnection:s,hasRunnableQuery:i,isRunnable:o&&s&&i,totalRowCount:u,bodyRowCount:Math.max(0,u-c),trailingRowCount:c,visibleTotalsColumnIds:a,fallbackRowHeightPx:d,measuredRowHeightPx:f,measuredAverageRowHeightPx:h,measuredRowHeightsPx:p,effectiveRowHeightPx:Kpe({fallbackRowHeightPx:d,measuredRowHeightPx:f,measuredRowHeightsPx:p,totalRowCount:u}),chromeHeightPx:n==null?void 0:n.chromeHeightPx,renderedMinHeightPx:n==null?void 0:n.renderedMinHeightPx,measuredRowsPerPage:n==null?void 0:n.rowsPerPage,renderContract:Rxt}}function Vxt(e){return Math.max(eG,e.table.rowHeightPx??eG)}function Kpe({fallbackRowHeightPx:e,measuredRowHeightPx:t,measuredRowHeightsPx:n,totalRowCount:r}){return n&&r!==void 0&&!Hxt(n,r)?e:t!==void 0?Math.max(HT,t):e}function Hxt(e,t){if(e.length<t)return!1;for(let n=0;n<t;n+=1)if(e[n]===void 0)return!1;return!0}function qxt(e){return e.card.type==="table"||e.card.type==="pivotTable"?e.card.type:"unsupported"}function Uxt(e,t){var n;return t==="unsupported"?!1:t==="pivotTable"?lt.hasValidCardConfig(e.card.config):!!((n=e.card.sql)!=null&&n.trim()||lt.hasValidCardConfig(e.card.config))}function Kxt(e){return e.table.totalsRow?_xt(qpe(e.card)):[]}function qT({totalRowCount:e,fallbackRowHeightPx:t,layoutMeasurement:n}){const r=Math.max(0,e),o=Math.max(HT,t),s=n==null?void 0:n.rowHeightsPx;if(!s||s.length===0){if((n==null?void 0:n.rowHeightPx)!==void 0){const d=Vk(n.rowHeightPx)??o;return{kind:"uniform",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:d,measuredAverageRowHeightPx:n.averageRowHeightPx}}return{kind:"unmeasured",totalRowCount:r,fallbackRowHeightPx:o}}const i=Array.from({length:r},(d,f)=>Vk(s[f])),a=i.filter(d=>d!==void 0);if(a.length===0)return{kind:"unmeasured",totalRowCount:r,fallbackRowHeightPx:o};const c=Math.max(...a),u=n.averageRowHeightPx??Math.ceil(a.reduce((d,f)=>d+f,0)/a.length);return Qxt(i)?{kind:"complete",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:c,measuredAverageRowHeightPx:u,rowHeightsPx:i}:{kind:"sparse",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:c,measuredAverageRowHeightPx:u,rowHeightsPx:i}}function Wxt(e,t){const{rowHeightsPx:n,rowRangeStartIndex:r,rowRangeEndIndex:o,totalRowCount:s}=t;if(!n||r===void 0||o===void 0||s===void 0)return B2(e,z2(t));const i=Math.max(0,s),a=Math.min(Math.max(0,r),i),c=Math.min(Math.max(a,o),i),u=c-a,d=z2({...t,rowRangeStartIndex:a,rowRangeEndIndex:c,totalRowCount:i});if(u===i||u!==n.length)return B2(e,d);const f=(e==null?void 0:e.totalRowCount)===i||(e==null?void 0:e.totalRowCount)===void 0,h=Array.from({length:i},(p,g)=>{var x;return f?(x=e==null?void 0:e.rowHeightsPx)==null?void 0:x[g]:void 0});return n.forEach((p,g)=>{h[a+g]=Vk(p)}),B2(e,z2({...d,rowHeightsPx:h}))}function Wpe(e,t){return e.kind!=="unmeasured"&&e.kind!=="uniform"&&e.rowHeightsPx[t]!==void 0?e.rowHeightsPx[t]:e.kind==="uniform"?e.measuredRowHeightPx:e.fallbackRowHeightPx}function K4({rowMeasurementState:e,startIndex:t,endIndex:n}){let r=0;const o=Math.max(0,t),s=Math.min(Math.max(o,n),e.totalRowCount);for(let i=o;i<s;i+=1)r+=Wpe(e,i);return r}function Gxt({rowMeasurementState:e,startIndex:t,endIndex:n,chromeHeightPx:r,renderedMinHeightPx:o}){const s=K4({rowMeasurementState:e,startIndex:t,endIndex:n});return Math.max(r+s,Ype(o)??0)}function Yxt({rowMeasurementState:e,startIndex:t,endIndex:n,chromeHeightPx:r}){return r+K4({rowMeasurementState:e,startIndex:t,endIndex:n})}function Gpe({rowMeasurementState:e,startIndex:t,availableHeightPx:n}){if(!Number.isFinite(n)||n<=0)return 0;let r=0,o=Math.max(0,t);for(;o<e.totalRowCount;){const s=Wpe(e,o);if(s<=0||r+s>n)break;r+=s,o+=1}return o-Math.max(0,t)}function Zxt(e){return e.kind==="complete"||e.kind==="uniform"?e.measuredRowHeightPx:e.fallbackRowHeightPx}function Xxt({tableSlice:e}){return!e||e.pageIndex===0}function z2(e){var s;const t=(s=e.rowHeightsPx)==null?void 0:s.map(i=>Vk(i)),n=(t??[]).filter(i=>i!==void 0),r=n.length>0?Math.max(...n):Math.max(HT,e.rowHeightPx),o=n.length>0?Math.ceil(n.reduce((i,a)=>i+a,0)/n.length):e.averageRowHeightPx;return{...e,rowHeightPx:r,averageRowHeightPx:o,rowHeightsPx:t,renderedMinHeightPx:Ype(e.renderedMinHeightPx),canUpdateLayoutChrome:e.canUpdateLayoutChrome}}function B2(e,t){return!e||t.canUpdateLayoutChrome===void 0||t.canUpdateLayoutChrome?t:{...t,chromeHeightPx:e.chromeHeightPx,renderedMinHeightPx:e.renderedMinHeightPx,rowsPerPage:e.rowsPerPage}}function Ype(e){if(!(e===void 0||!Number.isFinite(e)||e<=0))return Math.ceil(e)}function Vk(e){if(!(e===void 0||!Number.isFinite(e)||e<=0))return Math.max(HT,Math.ceil(e))}function Qxt(e){return e.every(t=>t!==void 0)}const Jxt={colorScheme:"light","--semaphor-background":"0 0% 100%","--semaphor-foreground":"240 5.9% 10%","--semaphor-card":"0 0% 100%","--semaphor-card-foreground":"240 5.9% 10%","--semaphor-muted":"0 0% 98%","--semaphor-muted-foreground":"240 3.8% 46.1%","--semaphor-accent":"240 4.8% 95.9%","--semaphor-accent-foreground":"240 5.9% 10%","--semaphor-border":"240 5.9% 90%","--background":"0 0% 100%","--foreground":"240 5.9% 10%","--muted":"0 0% 98%","--muted-foreground":"240 3.8% 46.1%","--border":"240 5.9% 90%"},ebt=[],tbt={spacious:"[&_tbody_td]:!py-3 [&_tfoot_td]:!py-3 [&_tbody_td>div]:!leading-6",comfortable:"[&_tbody_td]:!py-2 [&_tfoot_td]:!py-2 [&_tbody_td>div]:!leading-5",standard:"[&_tbody_td]:!py-1.5 [&_tfoot_td]:!py-1.5 [&_tbody_td>div]:!leading-5",compact:"[&_tbody_td]:!py-1 [&_tfoot_td]:!py-1 [&_tbody_td>div]:!leading-5",dense:"[&_tbody_td]:!py-1 [&_tfoot_td]:!py-1 [&_tbody_td]:!text-[11px] [&_tfoot_td]:!text-[11px] [&_tbody_td>div]:!leading-4"};function nbt(e){const t=["full","outer"].includes(e.gridLines),n=t||e.gridLines==="top",r=t||e.gridLines==="right",o=t||e.gridLines==="bottom",s=t||e.gridLines==="left",i=["full","inner","horizontal"].includes(e.gridLines),a=["full","inner","vertical"].includes(e.gridLines);return m.cn("relative min-h-[var(--document-table-min-surface-height)] overflow-hidden rounded-none bg-white text-zinc-950",n?"border-t border-t-zinc-200":"border-t-0",r?"border-r border-r-zinc-200":"border-r-0",o?"border-b border-b-zinc-200":"border-b-0",s?"border-l border-l-zinc-200":"border-l-0","[&_.data-table-scroll-container]:!rounded-none [&_.data-table-scroll-container]:!border-0 [&_.data-table-scroll-container]:!bg-white","[&_table]:!bg-white","[&_tbody_td>div]:!text-[var(--document-table-cell-color)] [&_tbody_td]:!text-[var(--document-table-cell-color)]","[&_tbody_tr:hover]:!bg-white [&_tbody_tr]:h-[var(--document-table-row-height)] [&_tbody_tr]:!bg-white","[&_tfoot_td]:!bg-[var(--document-table-totals-bg)] [&_tfoot_td]:!text-[var(--document-table-totals-color)] [&_tfoot_td]:!font-[var(--document-table-totals-font-weight)]","[&_thead]:!bg-[var(--document-table-header-bg)] [&_thead_tr]:!bg-[var(--document-table-header-bg)]","[&_th]:!bg-[var(--document-table-header-bg)] [&_th]:!text-[var(--document-table-header-color)]",tbt[e.density],e.stripedRows&&"[&_tbody_tr:nth-child(even)]:!bg-zinc-50 [&_tbody_tr:nth-child(even):hover]:!bg-zinc-50","[&_table]:!border-0",i?"[&_tbody_tr]:!border-zinc-200 [&_th]:!border-b [&_th]:!border-zinc-200":"[&_tbody_tr]:!border-transparent [&_th]:!border-b-0",e.totalsStyle.borderTop?["[&_tfoot_td]:![border-top-color:var(--document-table-totals-border-color)]","[&_tfoot_td]:!border-[var(--document-table-totals-border-color)]",e.totalsStyle.borderTopStyle==="double"?"[&_tfoot_td]:!border-t-[3px] [&_tfoot_td]:!border-double":"[&_tfoot_td]:!border-t",e.totalsStyle.borderTopStyle==="dashed"&&"[&_tfoot_td]:!border-dashed",e.totalsStyle.borderTopStyle==="dotted"&&"[&_tfoot_td]:!border-dotted",e.totalsStyle.borderTopStyle==="solid"&&"[&_tfoot_td]:!border-solid"]:"[&_tfoot_td]:!border-t-0",a?"[&_td]:!border-r [&_td]:!border-zinc-200 [&_td:last-child]:!border-r-0 [&_th]:!border-r [&_th]:!border-zinc-200 [&_th:last-child]:!border-r-0 [&_tfoot_td]:!border-r [&_tfoot_td]:!border-zinc-200 [&_tfoot_td:last-child]:!border-r-0":"[&_td]:!border-r-0 [&_th]:!border-r-0 [&_tfoot_td]:!border-r-0")}function rbt({section:e,documentFilterValues:t=[],documentControlDefinitions:n=[],documentControlValues:r={},documentDashboardInputValues:o,missingRequiredInputLabels:s=[],isEditing:i=!0,surfaceMode:a="preview",tableSlice:c,initialRowsPerPageLimit:u,previewRowLimit:d,showInlineEditAction:f=!0,onEditTableSection:h,onTableRowCountChange:p,onTableResultColumnsChange:g,onTableLayoutMeasure:x,onTableLayoutInvalidate:b,onUpdateTableSection:y,onPreviewRowLimitChange:C,measurementScale:w=1}){const N=fu({section:e});return N.isRunnable?s.length>0?l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Required inputs missing",message:`Set ${s.join(", ")} to run this table.`,exportState:"blocked",isEditing:i,showInlineEditAction:f,onEditTableSection:h}):l.jsx(xT,{displayPreferences:Mxt,children:l.jsx(ui,{fallbackRender:({error:S})=>l.jsx("div",{...wx(S),children:l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table unavailable",message:"The table result could not be validated. Refresh or reconfigure the table.",exportState:"error",isEditing:i,showInlineEditAction:f,onEditTableSection:h})}),children:l.jsx(abt,{section:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,documentDashboardInputValues:o,isEditing:i,surfaceMode:a,tableSlice:c,initialRowsPerPageLimit:u,previewRowLimit:d,showInlineEditAction:f,onEditTableSection:h,onTableRowCountChange:p,onTableResultColumnsChange:g,onTableLayoutMeasure:x,onTableLayoutInvalidate:b,onUpdateTableSection:y,onPreviewRowLimitChange:C,measurementScale:w})})}):l.jsx(hbt,{section:e,isEditing:i,reason:N.isSupported?void 0:"Unsupported table type",showInlineEditAction:f,onEditTableSection:h})}const Zpe=v.memo(rbt,obt);Zpe.displayName="DocumentTableSectionRenderer";function obt(e,t){return e.section===t.section&&e.documentFilterValues===t.documentFilterValues&&e.documentControlDefinitions===t.documentControlDefinitions&&e.documentControlValues===t.documentControlValues&&e.documentDashboardInputValues===t.documentDashboardInputValues&&sbt(e.missingRequiredInputLabels,t.missingRequiredInputLabels)&&e.isEditing===t.isEditing&&e.surfaceMode===t.surfaceMode&&e.initialRowsPerPageLimit===t.initialRowsPerPageLimit&&e.previewRowLimit===t.previewRowLimit&&e.showInlineEditAction===t.showInlineEditAction&&e.measurementScale===t.measurementScale&&ibt(e.tableSlice,t.tableSlice)&&e.onEditTableSection===t.onEditTableSection&&e.onTableRowCountChange===t.onTableRowCountChange&&e.onTableResultColumnsChange===t.onTableResultColumnsChange&&e.onTableLayoutMeasure===t.onTableLayoutMeasure&&e.onTableLayoutInvalidate===t.onTableLayoutInvalidate&&e.onUpdateTableSection===t.onUpdateTableSection&&e.onPreviewRowLimitChange===t.onPreviewRowLimitChange}function sbt(e,t){if(e===t)return!0;const n=e||[],r=t||[];return n.length===r.length&&n.every((o,s)=>o===r[s])}function ibt(e,t){return e===t?!0:!e||!t?!1:e.startIndex===t.startIndex&&e.endIndex===t.endIndex&&e.pageIndex===t.pageIndex&&e.pageCount===t.pageCount&&e.totalRows===t.totalRows&&e.rowsPerPage===t.rowsPerPage}function abt({section:e,documentFilterValues:t=[],documentControlDefinitions:n=[],documentControlValues:r={},documentDashboardInputValues:o,isEditing:s=!0,surfaceMode:i="preview",tableSlice:a,initialRowsPerPageLimit:c,previewRowLimit:u,showInlineEditAction:d=!0,onEditTableSection:f,onTableRowCountChange:h,onTableResultColumnsChange:p,onTableLayoutMeasure:g,onTableLayoutInvalidate:x,onUpdateTableSection:b,onPreviewRowLimitChange:y,measurementScale:C=1}){var pe,xe,Ie,be,ge,ee,ce,ae;const w=v.useMemo(()=>e.card.type==="table"&&e.table.totalsRow?qpe(e.card):e.card,[e.card,e.table.totalsRow]),N=v.useMemo(()=>Axt(w),[w]),S=v.useMemo(()=>H4(e),[e]),j=v.useMemo(()=>e.card.type==="table"&&e.table.totalsRow?Txt(w):void 0,[w,e.card.type,e.table.totalsRow]),k=Dxt(j),_=v.useMemo(()=>{const me=t.length>0,ve=n.length>0||Object.keys(r).length>0;return{runtimeContext:"documentSection",documentSectionId:e.id,...j?{tableTotalsRequest:j}:{},...me?{documentFilterValues:t}:{},...ve?{documentControlDefinitions:n,documentControlValues:r}:{},...o?{documentDashboardInputValues:o}:{}}},[t,n,r,o,e.id,j]),T=kxt({card:w,queryOptions:_,surfaceMode:i,previewRowLimit:u,onPreviewRowLimitChange:y}),I=T.records||ebt,D=v.useMemo(()=>hgt(I),[I]),E=v.useMemo(()=>gpe(e),[e]),R=w.type==="table"?fu({section:e}).trailingRowCount:0,F=v.useMemo(()=>fu({section:e,totalRowCount:w.type==="table"?I.length+R:0}),[w.type,R,I.length,e]),M=w.type==="table"&&I.length>0&&F.trailingRowCount>0,O=T.errorMessage?0:F.totalRowCount,z=M&&(a?a.endIndex>I.length:!c||F.totalRowCount<=c),L=M&&z,V=v.useMemo(()=>w.type==="table"&&!L?Ext(N):N,[w.type,N,L]),A=v.useCallback(me=>{b==null||b(e.id,ve=>{var Ue;const _e=(Ue=ve.card.preferences)==null?void 0:Ue.tablePrefs,De=typeof me=="function"?me((_e==null?void 0:_e.columnSizing)||{}):me;return{...ve,card:{...ve.card,preferences:{...ve.card.preferences,tablePrefs:{..._e,columnSizing:De}}}}})},[b,e.id]);let B=I;w.type==="table"&&a?B=I.slice(Math.min(a.startIndex,I.length),Math.min(a.endIndex,I.length)):w.type==="table"&&c&&(B=I.slice(0,c));const $=(T.isLoading||T.isPending||T.isFetching)&&I.length===0,P=i!=="print"&&T.isFetching&&I.length>0,U=i==="print"&&T.isLoading&&I.length>0;v.useEffect(()=>{w.type==="table"&&(h==null||h(e.id,O))},[w.type,h,e.id,O]),v.useEffect(()=>{var me;w.type==="table"&&(p==null||p(e.id,D,E,(me=T.data)==null?void 0:me.columnKeyMap))},[w.type,p,E,D,(pe=T.data)==null?void 0:pe.columnKeyMap,e.id]);const H=v.useMemo(()=>w.type!=="pivotTable"||T.errorMessage?{kind:"not_loaded"}:Jm({data:T.data,card:w}),[w,T.data,T.errorMessage]),G=Qm(w,H,T.comparisonMetadata),q=v.useMemo(()=>{if(w.type!=="pivotTable"||!G)return 0;const me=$L(G.data);return fu({section:e,totalRowCount:me.tableData.length+me.grandTotalRows.length}).totalRowCount},[w.type,G,e]);v.useEffect(()=>{w.type==="pivotTable"&&(h==null||h(e.id,q))},[w.type,h,G,q,e.id]);const Y=fgt(e),W=ugt(S),ne=v.useRef(null),Z=v.useRef(null),K=v.useRef({rowDataVersion:T.rowDataVersion,errorMessage:T.errorMessage}),[X,J]=v.useState(!1),[re,te]=v.useState(0),Q=ubt({tableSlice:a,initialRowsPerPageLimit:c,totalRowCount:w.type==="pivotTable"?q:O}),se=a?`${a.pageIndex}:${a.startIndex}:${a.endIndex}:${a.totalRows}`:"unsliced";if(v.useEffect(()=>{const me=K.current;K.current={rowDataVersion:T.rowDataVersion,errorMessage:T.errorMessage},!(me.rowDataVersion===T.rowDataVersion&&me.errorMessage===T.errorMessage)&&(x==null||x(e.id),te(ve=>ve+1))},[x,T.errorMessage,T.rowDataVersion,e.id]),lbt({sectionId:e.id,sectionRef:ne,tableSurfaceRef:Z,enabled:!X,measureKey:`${I.length}:${B.length}:${$?"loading":"ready"}:${W}:${se}:${re}`,measurementScale:C,fallbackRowHeightPx:Y,fallbackRowCount:Math.max(0,Q.endIndex-Q.startIndex),rowRangeStartIndex:Q.startIndex,rowRangeEndIndex:Q.endIndex,totalRowCount:Q.totalRowCount,canUpdateLayoutChrome:Xxt({tableSlice:a}),onTableLayoutMeasure:g}),T.errorMessage)return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table query failed",message:T.errorMessage,exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if($)return l.jsx(mbt,{section:e,isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(U)return l.jsx(nd,{section:e,icon:l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin text-zinc-400"}),title:"Preparing report table",message:"Rows are being acquired for the final document export.",exportState:"loading",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(L&&k&&!((xe=T.data)!=null&&xe.tableTotalsByColumnId)&&T.isFetching)return l.jsx(nd,{section:e,icon:l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin text-zinc-400"}),title:"Computing table totals",message:"Grand totals are being computed for this document table.",exportState:"loading",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(L&&k&&!((Ie=T.data)!=null&&Ie.tableTotalsByColumnId))return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table totals unavailable",message:"Grand totals could not be computed for this document table.",exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(I.length===0&&w.type!=="pivotTable")return l.jsx(nd,{section:e,icon:l.jsx(m.Table2,{className:"h-4 w-4 text-zinc-300"}),title:e.title||w.title||"Table",message:"No records to display",exportState:"empty",isEditing:s,showInlineEditAction:d,onEditTableSection:f});let oe;if(w.type==="pivotTable"){if(!G)return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Pivot table configuration unavailable",message:"Edit the table to confirm its rows, columns, and metrics.",exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});oe=l.jsx(pb,{card:N,data:fbt(G.data,a,c),options:G.options,suppressSortControls:F.renderContract.suppressSortControls,renderPlainWrapper:F.renderContract.renderPlainWrapper})}else oe=l.jsx(Zd,{card:V,data:B,resultColumns:(be=T.data)==null?void 0:be.columns,columnKeyMap:(ge=T.data)==null?void 0:ge.columnKeyMap,formattingFullRows:I,totalsData:L?I:void 0,totalsByColumnId:L?(ee=T.data)==null?void 0:ee.tableTotalsByColumnId:void 0,comparisonMetadata:T.comparisonMetadata,paginationMetadata:T.pagination,isLoading:$,columnSizing:(ae=(ce=V.preferences)==null?void 0:ce.tablePrefs)==null?void 0:ae.columnSizing,onColumnSizingChange:s&&i!=="print"?A:void 0,onColumnResizeStateChange:J,showColumnResizeHandles:s&&i!=="print",suppressSortControls:F.renderContract.suppressSortControls,suppressCellHoverCards:F.renderContract.disableDashboardInteractions});const fe=i!=="print"&&T.isPreviewWindowIncomplete&&(!a||a.endIndex>=I.length);return l.jsxs("div",{className:"relative",children:[l.jsxs("div",{ref:ne,className:"pt-3",children:[l.jsx(pbt,{section:e}),l.jsxs("div",{ref:Z,"data-document-table-section":"true",className:nbt(S),style:{...Jxt,"--document-table-row-height":`${Y}px`,"--document-table-min-surface-height":`${a?0:Bxt}px`,"--document-table-header-bg":S.headerBackgroundColor,"--document-table-header-color":S.headerTextColor,"--document-table-totals-bg":S.totalsStyle.backgroundColor,"--document-table-totals-color":S.totalsStyle.textColor,"--document-table-totals-border-color":S.totalsStyle.borderTopColor,"--document-table-totals-font-weight":String(dgt(S.totalsStyle.fontWeight)),"--document-table-cell-color":"#18181b"},children:[P?l.jsx(gbt,{}):null,oe]})]}),fe?l.jsx(xbt,{loadedRowCount:T.loadedRowCount,totalRowCount:T.totalRowCount,isFetching:T.isFetching,onLoadMore:T.loadMorePreviewRows}):null]})}function lbt({sectionId:e,sectionRef:t,tableSurfaceRef:n,enabled:r,measureKey:o,measurementScale:s,fallbackRowHeightPx:i,fallbackRowCount:a,rowRangeStartIndex:c,rowRangeEndIndex:u,totalRowCount:d,canUpdateLayoutChrome:f,onTableLayoutMeasure:h}){const p=v.useRef(null);v.useEffect(()=>{if(!r||!h)return;p.current=null;let g=null;const x=()=>{const I=t.current,D=n.current;if(!I||!D)return;const E=Number.isFinite(s)&&s>0?s:1,R=Y=>Y/E,F=Fxt(D),M=F.length>0?F.map(Y=>{const W=R(Y.getBoundingClientRect().height);return W>0?W:i}).filter(Y=>Y>0):Array.from({length:a},()=>i);if(M.length===0)return;const O=M.map(Y=>Math.ceil(Y)),z=Math.ceil(Math.max(...M)),L=M.reduce((Y,W)=>Y+W,0),V=Math.ceil(L/M.length),A=Math.ceil(R(I.getBoundingClientRect().height)),B=JW(I),$=F[0],P=F[F.length-1],U=$&&P?Pxt({sectionElement:I,tableSurfaceElement:D,firstRowElement:$,lastRowElement:P,measurementScale:E}):void 0;let H;if(B&&$&&P){const Y=B.getBoundingClientRect(),W=dbt(B,E,Y),ne=$.getBoundingClientRect(),Z=R(ne.top-Y.top),K=(U==null?void 0:U.trailingChromePx)??0,X=W-Z-K;H=Math.max(1,cbt(M,X))}const G=(U==null?void 0:U.chromeHeightPx)??Math.max(0,Math.ceil(A-L)),q={rowHeightPx:z,averageRowHeightPx:V,rowHeightsPx:O,rowRangeStartIndex:c,rowRangeEndIndex:u,totalRowCount:d,chromeHeightPx:G,renderedMinHeightPx:U==null?void 0:U.renderedMinHeightPx,canUpdateLayoutChrome:f,rowsPerPage:H};$xt(p.current,q)&&(p.current=q,h(e,q))},b=()=>{g!==null&&window.cancelAnimationFrame(g),g=window.requestAnimationFrame(()=>{g=null,x()})};if(b(),typeof ResizeObserver>"u")return()=>{g!==null&&window.cancelAnimationFrame(g)};const y=new ResizeObserver(b),C=typeof MutationObserver>"u"?null:new MutationObserver(b),w=new Set,N=I=>{!I||w.has(I)||(y.observe(I),w.add(I))},S=I=>{!I||!C||C.observe(I,{attributes:!0,characterData:!0,childList:!0,subtree:!0})},j=t.current,k=n.current,_=JW(j),T=Upe(_);return N(j),N(k),N(_),N(T),S(_),()=>{g!==null&&window.cancelAnimationFrame(g),y.disconnect(),C==null||C.disconnect()}},[r,s,o,h,e,t,n,i,a,c,u,d,f])}function cbt(e,t){if(!Number.isFinite(t)||t<=0)return 0;let n=0,r=0;for(const o of e){if(n+o>t)break;n+=o,r+=1}return r}function ubt({tableSlice:e,initialRowsPerPageLimit:t,totalRowCount:n}){const r=Math.max(0,n),o=Math.min((e==null?void 0:e.startIndex)??0,r),s=Math.min((e==null?void 0:e.endIndex)??t??r,r);return{startIndex:o,endIndex:Math.max(o,s),totalRowCount:r}}function dbt(e,t,n){const r=Upe(e);if(r)return(r.getBoundingClientRect().top-n.top)/t;const o=window.getComputedStyle(e),s=Number.parseFloat(o.paddingBottom||"0")||0;return Lxt(e)-s}function fbt(e,t,n){var f,h,p,g,x,b;const r=(t==null?void 0:t.startIndex)??0,o=(t==null?void 0:t.endIndex)??(n||void 0);if(o===void 0)return e;const s=((f=e.rowData)==null?void 0:f.length)??((h=e.rowHeaders)==null?void 0:h.length)??0,i=((p=e.grandTotalRows)==null?void 0:p.length)??0,a=Math.min(r,s),c=Math.min(o,s),u=Math.max(0,r-s),d=Math.max(0,Math.min(o-s,i));return{...e,rowData:(g=e.rowData)==null?void 0:g.slice(a,c),rowHeaders:((x=e.rowHeaders)==null?void 0:x.slice(a,c))??[],grandTotalRows:((b=e.grandTotalRows)==null?void 0:b.slice(u,d))??[]}}function hbt({section:e,isEditing:t,reason:n,showInlineEditAction:r,onEditTableSection:o}){return l.jsx("div",{className:"pt-3",children:l.jsxs("div",{className:"rounded border border-dashed border-zinc-200 px-4 py-8 text-center","data-document-render-error":"true",children:[l.jsx(m.Table2,{className:"mx-auto mb-2 h-5 w-5 text-zinc-300"}),l.jsx("p",{className:"text-[12px] font-medium text-zinc-600",children:e.title||e.card.title||"Table"}),n?l.jsx("p",{className:"mt-1 text-[11px] text-zinc-400",children:n}):null,r?l.jsx(W4,{section:e,isEditing:t,className:"mt-3",onEditTableSection:o}):null]})})}function mbt({section:e,isEditing:t,showInlineEditAction:n,onEditTableSection:r}){return l.jsx("div",{className:"pt-3","data-document-render-loading":"true",children:l.jsxs("div",{className:"relative h-[220px] overflow-hidden rounded",children:[l.jsx(Pz,{columns:5,rows:8}),n?l.jsx("div",{className:"absolute right-2 top-2 z-20",children:l.jsx(W4,{section:e,isEditing:t,onEditTableSection:r})}):null]})})}function nd({section:e,icon:t,title:n,message:r,exportState:o,isEditing:s,showInlineEditAction:i,onEditTableSection:a}){const c=o==="blocked"||o==="error",u=o==="loading";return l.jsx("div",{className:"pt-3",children:l.jsx("div",{className:"rounded border border-zinc-200 bg-zinc-50 px-4 py-5","data-document-render-error":c?"true":void 0,"data-document-render-loading":u?"true":void 0,children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"mt-0.5 shrink-0",children:t}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("p",{className:"text-[12px] font-medium text-zinc-700",children:n}),l.jsx("p",{className:"mt-1 break-words text-[11px] text-zinc-500",children:r})]}),i?l.jsx(W4,{section:e,isEditing:s,onEditTableSection:a}):null]})})})}function pbt({section:e}){const t=e.title||e.card.title;return t?l.jsx("div",{className:"mb-2 min-w-0",children:t?l.jsx("p",{className:"whitespace-normal break-words text-[12px] font-semibold leading-4 text-zinc-800",children:t}):null}):null}function gbt(){return l.jsxs("div",{role:"status","aria-live":"polite",className:"pointer-events-none absolute right-2 top-2 z-10 inline-flex items-center gap-1.5 rounded-full border border-zinc-200 bg-white/95 px-2 py-1 text-[10px] font-medium text-zinc-500 shadow-sm",children:[l.jsx(m.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Updating..."]})}function xbt({loadedRowCount:e,totalRowCount:t,isFetching:n,onLoadMore:r}){const o=t===void 0?"unknown":t.toLocaleString();return l.jsxs("div",{className:"absolute left-0 top-full z-20 mt-2 flex max-w-full items-center gap-2 rounded border border-zinc-200 bg-white px-2 py-1 text-[11px] text-zinc-500 shadow-sm print:hidden",children:[l.jsxs("span",{className:"whitespace-nowrap",children:["Previewing ",e.toLocaleString()," of ",o," rows"]}),r?l.jsx(m.Button,{type:"button",variant:"outline",size:"sm",className:"h-6 rounded px-2 text-[11px]",disabled:n,onClick:r,children:n?"Loading...":"Load more pages"}):null]})}function W4({section:e,isEditing:t,className:n,onEditTableSection:r}){return t?l.jsxs(m.Button,{type:"button",variant:"outline",size:"sm",className:n?`h-8 gap-2 ${n}`:"h-8 gap-2",onClick:o=>{o.stopPropagation(),r==null||r(e)},children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Edit table"]}):null}const bbt={a4:{width:595,height:842},letter:{width:612,height:792}},ybt=96/72;function Xpe(e){return vbt(e)}function vbt(e){return wbt(e,{pointToPixelScale:ybt})}function wbt(e,{pointToPixelScale:t}){const n=bbt[e.size],r=e.orientation==="landscape"?n.height:n.width,o=e.orientation==="landscape"?n.width:n.height,s=e.margins,i=s.unit==="mm"?72/25.4:72,a=u=>Math.round(u*i*t),c={top:a(s.top),right:a(s.right),bottom:a(s.bottom),left:a(s.left)};return{width:Math.round(r*t),height:Math.round(o*t),padding:`${c.top}px ${c.right}px ${c.bottom}px ${c.left}px`,paddingPx:c}}const Cbt=16,Nx=78,Sbt=0,Nbt=0,jbt=72,kbt=40;function Ibt(e,t={}){var p;const n=t.tablePaginationBySectionId??{},r=t.pageMetricsMode??"preview",o=t.document?Jpe(t.document):Number.POSITIVE_INFINITY,s=[];let i=[],a=0,c=0,u;const d=(g,x=i,b=a,y=`document-page-${s.length+1}-${b}`,C=u)=>{s.push({id:y,startInsertIndex:b,sections:x,breakAfterSection:g,layoutError:C})},f=g=>{const x=s[s.length-1];return!x||x.breakAfterSection||x.sections.length===0?!1:(x.breakAfterSection=g,!0)};e.forEach((g,x)=>{if(g.type==="page_break"){i.length>0?d(g):f(g)||d(g),i=[],c=0,a=x+1;return}if(g.type==="table"){const C=n[g.id],w=(C==null?void 0:C.rowCount)??0,N=(C==null?void 0:C.rowsPerPage)??0,S=!!t.document,j=S&&N>0?Dbt(g,C,o-c):N;if(N>0&&(w>N||S&&i.length>0&&j>0&&w>j)&&C){!S&&i.length>0&&(d(),i=[],c=0,u=void 0,a=x),S&&i.length>0&&j<=0&&(d(),i=[],c=0,u=void 0,a=x);const _=G4(g,C),T=_bt({rowCount:w,rowsPerPage:N,footerRowCount:(C==null?void 0:C.footerRowCount)??0,firstRowsPerPage:S&&i.length>0?j:N,rowMeasurementState:_,capFirstRowsPerPage:S&&i.length>0&&C.measuredRowsPerPage!==void 0,firstRowsAvailableHeightPx:S&&i.length>0?vN(C,o-c):vN(C,o),fullRowsAvailableHeightPx:vN(C,o)});T.forEach((I,D)=>{const E=D===T.length-1,R={section:g,sectionIndex:x,tableSlice:{startIndex:I.startIndex,endIndex:I.endIndex,pageIndex:D,pageCount:T.length,totalRows:w,rowsPerPage:N}},F=Ebt(g,C,I.startIndex,I.endIndex);if(S&&D===0&&i.length>0){i.push(R),c+=F,E||(d(),i=[],c=0,u=void 0,a=x+1);return}if(E&&S){i=[R],c=F,u=void 0,a=x;return}d(void 0,[R],x,`document-page-table-${g.id}-${D+1}`,void 0)});return}}const b=t.document?Rbt({section:g,document:t.document,tablePagination:n[g.id],pageMetricsMode:r,textRenderContext:t.textRenderContext}):0;if(Number.isFinite(o)&&b>o){i.length>0&&(d(),i=[],c=0,u=void 0,a=x),d(void 0,[{section:g,sectionIndex:x}],x,`document-page-overflow-${g.id}`,`Section "${g.id}" exceeds the available page body height.`),i=[],c=0,u=void 0,a=x+1;return}i.length>0&&c+b>o&&(d(),i=[],c=0,u=void 0,a=x),i.push({section:g,sectionIndex:x}),c+=b}),(s.length===0||i.length>0||((p=e[e.length-1])==null?void 0:p.type)==="page_break")&&d();const h=s.length;return s.map((g,x)=>({...g,pageNumber:x+1,pageCount:h}))}function _bt({rowCount:e,rowsPerPage:t,footerRowCount:n=0,firstRowsPerPage:r,rowMeasurementState:o,capFirstRowsPerPage:s=!1,firstRowsAvailableHeightPx:i,fullRowsAvailableHeightPx:a}){const c=[];let u=0,d=Math.max(1,r);const f=Math.max(0,n),h=Math.max(0,e-f);for(;u<e;){const p=c.length===0?i:a,x=(o.kind==="sparse"||o.kind==="complete")&&Number.isFinite(p)?Gpe({rowMeasurementState:o,startIndex:u,availableHeightPx:p??0}):void 0,b=x!==void 0?Math.max(1,c.length===0&&s?Math.min(x,d):x):Math.max(1,d);let y;if(f===0||u>=h)y=Math.min(u+b,e);else{const C=h-u;if(C+f<=b&&K4({rowMeasurementState:o,startIndex:u,endIndex:e})<=(p??Number.POSITIVE_INFINITY))y=e;else{let w=Math.min(b,C);w===C&&f>0&&C>1&&(w-=1),y=u+Math.max(1,w)}}c.push({startIndex:u,endIndex:y}),u=y,d=t}return c}function Tbt({document:e,tableRowCountsBySectionId:t,tableLayoutMeasurementsBySectionId:n,shouldPaginateTables:r,pageMetricsMode:o="preview"}){if(!r)return{};const s={};for(const i of e.sections){if(!_v(i))continue;const a=t[i.id]??0;if(a<=0)continue;const c=n==null?void 0:n[i.id],u=fu({section:i,totalRowCount:a,layoutMeasurement:c}),d=qT({totalRowCount:u.totalRowCount,fallbackRowHeightPx:u.fallbackRowHeightPx,layoutMeasurement:c});s[i.id]={rowCount:u.totalRowCount,rowsPerPage:Qpe(e,u,o),footerRowCount:u.trailingRowCount,fallbackRowHeightPx:u.fallbackRowHeightPx,rowMeasurementState:d,rowHeightPx:u.measuredRowHeightPx,averageRowHeightPx:u.measuredAverageRowHeightPx,rowHeightsPx:u.measuredRowHeightsPx,chromeHeightPx:u.chromeHeightPx,renderedMinHeightPx:u.renderedMinHeightPx,measuredRowsPerPage:u.measuredRowsPerPage}}return s}function _v(e){return e.type!=="table"?!1:fu({section:e}).isRunnable}function Qpe(e,t,n="preview"){const o=Jpe(e)-(t.chromeHeightPx??Nx),s=Math.floor(o/t.effectiveRowHeightPx);return Math.max(1,s)}function Dbt(e,t,n){if(!Number.isFinite(n))return(t==null?void 0:t.rowsPerPage)??0;const r=vN(t,n),o=t&&G4(e,t),i=(o&&o.kind!=="unmeasured"?Gpe({rowMeasurementState:o,startIndex:0,availableHeightPx:r}):void 0)??Math.max(0,Math.floor(r/Hk(e,t)));return(t==null?void 0:t.measuredRowsPerPage)!==void 0?Math.max(0,Math.min(i,t.measuredRowsPerPage)):i}function Ebt(e,t,n,r){return Yxt({rowMeasurementState:t?G4(e,t):qT({totalRowCount:r,fallbackRowHeightPx:Hk(e,t)}),startIndex:n,endIndex:r,chromeHeightPx:(t==null?void 0:t.chromeHeightPx)??Nx})}function vN(e,t){return t-((e==null?void 0:e.chromeHeightPx)??Nx)}function Hk(e,t){if(t!=null&&t.rowMeasurementState)return Zxt(t.rowMeasurementState);const n=(t==null?void 0:t.fallbackRowHeightPx)??fu({section:e}).fallbackRowHeightPx;return Kpe({fallbackRowHeightPx:n,measuredRowHeightPx:t==null?void 0:t.rowHeightPx,measuredRowHeightsPx:t==null?void 0:t.rowHeightsPx,totalRowCount:t==null?void 0:t.rowCount})}function G4(e,t){return t.rowMeasurementState?t.rowMeasurementState:qT({totalRowCount:t.rowCount,fallbackRowHeightPx:Hk(e,t),layoutMeasurement:t.rowHeightPx!==void 0||t.rowHeightsPx?{rowHeightPx:t.rowHeightPx??Hk(e,t),averageRowHeightPx:t.averageRowHeightPx,rowHeightsPx:t.rowHeightsPx,chromeHeightPx:t.chromeHeightPx??Nx,renderedMinHeightPx:t.renderedMinHeightPx,rowsPerPage:t.rowsPerPage}:void 0})}function Jpe(e,t){const n=ege(e),r=tG(e.header,jbt),o=tG(e.footer,kbt);return n.height-n.paddingPx.top-n.paddingPx.bottom-r-o-Cbt}function Mbt(e,t){const n=ege(e);return n.width-n.paddingPx.left-n.paddingPx.right}function Rbt({section:e,document:t,tablePagination:n,pageMetricsMode:r,textRenderContext:o}){if(e.type==="spacer")return Math.max(8,e.heightPx);if(e.type==="text")return Abt(e,t,r,o);if(e.type==="table"){const s=fu({section:e,totalRowCount:(n==null?void 0:n.rowCount)??3,layoutMeasurement:n!=null&&n.rowHeightPx?{rowHeightPx:n.rowHeightPx,averageRowHeightPx:n.averageRowHeightPx,rowHeightsPx:n.rowHeightsPx,chromeHeightPx:n.chromeHeightPx??Nx,renderedMinHeightPx:n.renderedMinHeightPx,rowsPerPage:n.rowsPerPage}:void 0}),i=(n==null?void 0:n.rowCount)??3;return Gxt({rowMeasurementState:(n==null?void 0:n.rowMeasurementState)??qT({totalRowCount:i,fallbackRowHeightPx:s.effectiveRowHeightPx}),startIndex:0,endIndex:i,chromeHeightPx:(n==null?void 0:n.chromeHeightPx)??Nx,renderedMinHeightPx:n==null?void 0:n.renderedMinHeightPx})}return 0}function Abt(e,t,n,r){var c,u;const o=((c=e.style)==null?void 0:c.fontSize)??13,s=Math.ceil(o*((u=e.style)!=null&&u.fontSize?1.45:1.55)),i=Math.max(120,Mbt(t)-Sbt),a=Fbt({content:e.content,bodyWidthPx:i,fontSize:o,textRenderContext:r});return Nbt+a*s}function Fbt({content:e,bodyWidthPx:t,fontSize:n,textRenderContext:r}){const o=n*.54,s=r?upe(e,r):Pbt(e),i=Obt(s,o);return i.length===0?1:i.reduce((a,c)=>a+Math.max(1,Math.ceil(c/t)),0)}function Pbt(e){return e.map(t=>({type:t.type,value:t.type==="text"?t.value:"0".repeat(120),format:t.format}))}function Obt(e,t){const n=[0];for(const r of e){const o=Lbt(r);r.value.split(`
1321
+ `)[0].slice(0,28):"Text section"}return e.type==="table"?e.title||e.card.title||"Table":e.type==="page_break"?"Page break":wC[e.type]}function lgt(e){return e.type==="spacer"?`${e.heightPx} px`:e.type==="table"?"Table":null}const zf=Ad,Bf=ka,cgt={spacious:40,comfortable:36,standard:32,compact:28,dense:24};function H4(e){var t;return K3((t=e.card.preferences)==null?void 0:t.tablePrefs)}function ugt(e){return[e.density,e.headerStyle,e.headerBackgroundColor,e.headerTextColor,e.headerWrapText,e.stripedRows,e.gridLines,e.wrapText,e.totalsStyle.backgroundColor,e.totalsStyle.textColor,e.totalsStyle.fontWeight,e.totalsStyle.borderTop,e.totalsStyle.borderTopStyle,e.totalsStyle.borderTopColor].join(":")}const dgt=wse;function aO(e){return cgt[e]}function fgt(e){return e.table.rowHeightPx??aO(H4(e).density)}function hgt(e){const t=new Set;return e.forEach(n=>{Object.keys(n).forEach(r=>t.add(r))}),Array.from(t)}function gpe(e){var o;if(e.type!=="table"||e.card.type!=="table")return"";const t=e.card,n=t.config,r=t.dataSource;return JSON.stringify({type:t.type,connectionId:t.connectionId||(r==null?void 0:r.connectionId)||"",sql:((o=t.sql)==null?void 0:o.trim())||"",datamodelId:t.datamodelId||(r==null?void 0:r.datamodelId)||"",semanticDomainId:(r==null?void 0:r.semanticDomainId)||"",selectedEntities:(r==null?void 0:r.selectedEntities)||null,lastSelectedDatabase:t.lastSelectedDatabase||"",lastSelectedSchema:t.lastSelectedSchema||"",lastSelectedTable:t.lastSelectedTable||"",detailColumns:w1(n==null?void 0:n.detailColumns),groupByColumns:w1(n==null?void 0:n.groupByColumns),metricColumns:w1(n==null?void 0:n.metricColumns),pivotByColumns:w1(n==null?void 0:n.pivotByColumns)})}function w1(e){return Array.isArray(e)?e.map(t=>{if(!t||typeof t!="object")return String(t??"");const n=t;return{id:n.id,alias:n.alias,name:n.name,label:n.label,column:n.column,expression:n.expression,aggregate:n.aggregate,aggregation:n.aggregation,dataType:n.dataType,type:n.type}}):[]}function pl(e){return e.kind==="filter"}function oc(e){return e.kind==="control"}function xpe(e,t){return e.reduce((n,r)=>{if(!pl(r))return n;const o=m.buildFilterValueFromDefaults(r.filter,t);return o&&(n[r.id]=o),n},{})}function bpe(e){return e.reduce((t,n)=>{if(!oc(n))return t;const r=m.buildAuthoringPreviewControlValues({controls:[n.control]});return Object.prototype.hasOwnProperty.call(r,n.control.id)&&(t[n.id]=r[n.control.id]),t},{})}function mgt(e){return e.map(t=>`${t.id}:${vpe(t)}`).join("|")}function ype(e){return e.reduce((t,n)=>(t[n.id]=vpe(n),t),{})}function vpe(e){if(oc(e))return JSON.stringify({kind:e.kind,controlId:e.control.id,type:e.control.type,source:e.control.source});const t=en.materializeFilterDefinitionNativeDataType(e.filter);return JSON.stringify({kind:e.kind,filterId:t.id,connectionId:t.connectionId,qualifiedTableName:t.qualifiedTableName||null,table:t.table||null,database:t.database||null,sql:t.sql,column:t.column,dataType:t.dataType,nativeDataType:t.nativeDataType||null,operation:t.operation,type:t.type||null,fieldMeta:t.fieldMeta||null,semanticContext:t.semanticContext||null,targetColumns:t.targetColumns||null})}function pgt(e,t,n,r,o){const s={};for(const i of t){if(!pl(i))continue;const a=e[i.id],c=CC(i.id,r,o),u=Sx(i,a),d=Object.prototype.hasOwnProperty.call(e,i.id);if(!c&&d&&!a){s[i.id]=void 0;continue}if(!c&&u){s[i.id]=u;continue}n[i.id]&&(s[i.id]=n[i.id])}return ygt(e,s)?e:s}function ggt(e,t,n,r,o){const s={};for(const i of t){if(!oc(i))continue;if(!CC(i.id,r,o)&&Object.prototype.hasOwnProperty.call(e,i.id)){s[i.id]=e[i.id];continue}Object.prototype.hasOwnProperty.call(n,i.id)&&(s[i.id]=n[i.id])}return vgt(e,s)?e:s}function q4(e,t){const n={...t,filterId:e.filter.id};return m.isCompatibleFilterValue(e.filter,n)?xgt(e).has(t.name):!1}function Sx(e,t){if(!t||!q4(e,t))return;const n=t.filterId===e.filter.id?t:{...t,filterId:e.filter.id};return en.materializeFilterValueNativeDataType({definition:e.filter,value:n})}function wpe(e,t){const n=new Map(t.filter(pl).map(o=>[o.id,o]));let r=e;for(const[o,s]of Object.entries(e)){const i=n.get(o),a=i?Sx(i,s):void 0;!a||a===s||(r===e&&(r={...e}),r[o]=a)}return r}function xgt(e){return new Set([e.filter.column,...(e.filter.targetColumns||[]).map(t=>t.column)])}function bgt(e,t){const n=new Set(t.filter(o=>pl(o)&&VT(o.filter.operation)).map(o=>o.id)),r={};for(const[o,s]of Object.entries(e))n.has(o)&&(r[o]=s);return wgt(e,r)?e:r}function ygt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>e[o]===t[o])}function vgt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>Object.is(e[o],t[o]))}function wgt(e,t){const n=Object.keys(e),r=Object.keys(t);return n.length!==r.length?!1:n.every(o=>e[o]===t[o])}function VT(e){return e==="in"||e==="not in"}function Cpe(e){return e==="not in"?"exclude":"include"}function lO(e){return e==="exclude"?"not in":"in"}function Cgt(e,t,n,r){return t.map(o=>{if(!pl(o))return;const s=e[o.id];if(!(!s||CC(o.id,n,r)||!q4(o,s)))return Sx(o,s)}).filter(o=>!!o)}function Sgt(e,t,n,r){return t.reduce((o,s)=>(!oc(s)||CC(s.id,n,r)||!Object.prototype.hasOwnProperty.call(e,s.id)||(o[s.control.id]=e[s.id]),o),{})}function Spe(e,t,n,r,o){return e.filter(s=>s.requiredAtExecution?CC(s.id,r,o)?!0:pl(s)?!t[s.id]||!q4(s,t[s.id]):!Ngt(n,s.id):!1).map(s=>s.label)}function Ngt(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;const n=e[t];return n==null?!1:Array.isArray(n)?n.length>0:typeof n=="string"?n.trim().length>0:!0}function CC(e,t,n){const r=n[e];return!!r&&r!==t[e]}const jgt=["table","pivotTable"];function kgt(e){return{id:`doc_editor_frame_${e.id}`,cards:[e.card],activeCardId:e.card.id}}function Igt(e,t){return e.cards.find(n=>n.id===t)||null}function _gt(e){return jgt.includes(e.type)}function Tgt(){const e=m.useDashboardStore(I=>I.dashboard),t=m.useEditorStore(I=>I.selectedConnectionId),n=m.useEditorStore(I=>I.selectedDatabaseName),r=m.useEditorStore(I=>I.selectedSchemaName),o=m.useEditorStore(I=>I.selectedTableName),s=m.useEditorStore(I=>I.selectedDatamodelId),{clearSelectedVisual:i}=Pm(),{setIsDashboardEditing:a,setIsVisualEditing:c}=m.useDashboardActions(),{setFrame:u,setCard:d,setIsDevMode:f,initializeModeDrafts:h,setActiveTabCardId:p,updateDataSource:g,setQueryResultColumns:x,setFilterValues:b,setInlineFilterValuesMap:y,setApplyFilters:C,clearModeDrafts:w,setEditorContext:N}=m.useEditorActions(),S=m.useEditorStore(I=>I.actions.setSelectedConnectionId),j=m.useEditorStore(I=>I.actions.setSelectedDatamodelId),k=m.useEditorStore(I=>I.actions.setSelectedDatabaseName),_=m.useEditorStore(I=>I.actions.setSelectedSchemaName),T=m.useEditorStore(I=>I.actions.setSelectedTableName);return v.useCallback((I,D,E=[],R=[],F={},M=[])=>{const O=kgt(D);i(),w(),N({type:"documentSection",sheetId:I,sectionId:D.id,cardId:D.card.id,documentFilterValues:Dgt(E),documentControlDefinitions:Egt(R),documentControlValues:{...F},missingRequiredInputLabels:[...M]}),e_({frame:O,card:D.card,setFrame:u,setCard:d,setIsDevMode:f,initializeModeDrafts:h,setActiveTabCardId:p,updateDataSource:g,setQueryResultColumns:x,setSelectedConnectionId:S,setSelectedDatabaseName:k,setSelectedSchemaName:_,setSelectedTableName:T,setSelectedDatamodelId:j,setFilterValues:b,setInlineFilterValuesMap:y,setApplyFilters:C,setIsDashboardEditing:a,setIsVisualEditing:c,dashboard:e,selectedSheetId:I,selectedFrameId:null,currentSelections:{connectionId:t,databaseName:n,schemaName:r,tableName:o,datamodelId:s}})},[w,i,e,h,t,n,s,r,o,p,C,d,N,b,u,y,a,f,c,x,S,k,j,_,T,g])}function Dgt(e){return e.map(t=>({...t,values:[...t.values]}))}function Egt(e){return e.map(t=>({...t,source:t.source.kind==="manual"?{...t.source,options:t.source.options.map(n=>({...n}))}:{...t.source}}))}function P2({inputs:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o}){return l.jsx(l.Fragment,{children:e.filter(oc).map(s=>l.jsx(Mgt,{input:s,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o},s.id))})}function Mgt({input:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,onOptionsChange:o}){const s=e.control,i=s.source.kind==="sql_query"?s.source:void 0,a=cC({controlId:s.id,source:i,enabled:!!i,controlDefinitionsOverride:n,controlValuesOverride:r,activeFiltersOverride:t}),c=v.useMemo(()=>i?[]:Lz(s),[s,i]),u=i?a.options:c;return v.useEffect(()=>{o(e.id,u)},[e.id,o,u]),null}function cO({children:e,className:t,empty:n,wrap:r=!1}){const o=v.Children.toArray(e).filter(s=>s!=null);return o.length===0?n??null:l.jsx("div",{className:m.cn("flex items-center gap-2 pr-1",r?"min-w-0 flex-wrap gap-y-2":"min-w-max",t),children:o})}const zk=v.forwardRef(function({children:t,className:n,...r},o){return l.jsx("div",{ref:o,className:m.cn("shrink-0",n),...r,children:t})}),O2=({dataType:e})=>kk(e),Npe=["day","week","month","quarter","year"],Rgt=[...Npe,"hour","minute","second"],Agt=e=>m.isDateTimeLikeDataType(e),jpe=e=>Agt(e)?Rgt:Npe;function kpe(e){const{controlId:t,onCommit:n}=e,[r,o]=v.useState(t);return l.jsx(m.Input,{size:"xs",value:r,onChange:s=>o(s.target.value),onBlur:()=>{n(r),o(s=>s.trim().length===0?t:s)}})}function UW(e){const{control:t,onChange:n}=e,r=m.ensureManualSource(t),o=r.source.kind==="manual"?r.source.options:[],i=!!m.getPresetOptionsForControlType(t.type),a=h=>{n({...r,source:{kind:"manual",options:h}})},c=()=>{const h=o.length+1,p=`Option ${h}`;a([...o,{label:p,value:m.slugifyControlValue(p)||`option_${h}`}])},u=(h,p)=>{a(o.map((g,x)=>{if(x!==h)return g;const b=m.slugifyControlValue(g.label),y=m.slugifyControlValue(p)||g.value,C=g.value.trim().length===0||g.value===b;return{...g,label:p,value:C?y:g.value}}))},d=(h,p)=>{a(o.map((g,x)=>x===h?{...g,value:p}:g))},f=h=>{a(o.filter((p,g)=>g!==h))};return l.jsxs("div",{className:"space-y-1.5",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Options"}),!i&&l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:c,children:[l.jsx(Ar,{className:"mr-1 h-3 w-3"}),"Add option"]})]}),o.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-2.5 text-xs text-muted-foreground",children:"No options yet."}):l.jsxs("div",{className:"rounded-md border",children:[l.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_32px] gap-2 border-b bg-muted/50 px-2.5 py-1.5",children:[l.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Label"}),l.jsx("span",{className:"text-[11px] font-medium text-muted-foreground",children:"Value"}),l.jsx("span",{})]}),o.map((h,p)=>l.jsxs("div",{className:m.cn("grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_32px] items-center gap-2 px-2.5 py-1.5",p<o.length-1&&"border-b"),children:[l.jsx(m.Input,{size:"xs",value:h.label,placeholder:"Label",className:"h-7 text-xs",onChange:g=>u(p,g.target.value),disabled:i}),l.jsx(m.Input,{size:"xs",value:h.value,placeholder:"Value",className:"h-7 text-xs",onChange:g=>d(p,g.target.value),disabled:i}),l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>f(p),disabled:i,children:l.jsx(Ra,{className:"h-3.5 w-3.5"})})]},`${t.id}-option-${p}`))]})]})}function Fgt(e){return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Choices (built in)"}),l.jsx("div",{className:"rounded-md border bg-muted/20 px-3 py-2 text-sm text-muted-foreground",children:e.options.map(t=>t.label).join(" · ")})]})}function Pgt(e){return e?m.getDataType(e.dataType||"")==="date":!1}function Ogt(e){if(!e)return;const t=m.readTemporalBucketAuthoringState({fieldId:e.id,dataType:e.dataType,granularity:e.granularity,format:e.format,dateFormat:e.dateFormat,customFormat:e.customFormat,semanticTemporalPresentation:e.semanticTemporalPresentation});return t.ok?t.granularity:void 0}function KW(e,t){return m.readTemporalBucketAuthoringSelection({fieldId:(e==null?void 0:e.id)||"structural-control-option",dataType:(e==null?void 0:e.dataType)||"date",granularity:t,format:e==null?void 0:e.format,dateFormat:e==null?void 0:e.dateFormat,customFormat:e==null?void 0:e.customFormat,semanticTemporalPresentation:e==null?void 0:e.semanticTemporalPresentation})}function Lgt(e){var k,_;const{control:t,choices:n,choiceLabel:r,emptyMessage:o,onChange:s}=e,i=m.ensureManualSource(t),a=i.source.kind==="manual"?i.source.options:[],c=new Map(a.map(T=>[T.value,T])),u=new Set(a.map(T=>T.value)),[d,f]=v.useState(""),[h,p]=v.useState(((k=a[0])==null?void 0:k.value)||null),[g,x]=v.useState({}),b=T=>{s({...i,source:{kind:"manual",options:T}})},y=(T,I)=>{b(a.map(D=>D.value===T?I(D):D))},C=n.filter(({option:T})=>u.has(T.value)),w=h&&a.some(T=>T.value===h)?h:((_=a[0])==null?void 0:_.value)||null,N=C.find(({option:T})=>T.value===w)||C[0],S=n.filter(({option:T})=>{var D,E,R,F;if(u.has(T.value))return!1;const I=d.trim().toLowerCase();return I?T.label.toLowerCase().includes(I)||T.value.toLowerCase().includes(I)||((E=(D=T.presentation)==null?void 0:D.customFormat)==null?void 0:E.toLowerCase().includes(I))||((F=(R=T.presentation)==null?void 0:R.format)==null?void 0:F.presentation.mode)==="pattern"&&T.presentation.format.presentation.pattern.toLowerCase().includes(I):!0}),j=(T,I)=>{var A;const D=c.get(T.value),E=I?m.getDataType(I.dataType||""):void 0,R=Pgt(I),F=R?((A=D==null?void 0:D.presentation)==null?void 0:A.granularity)??Ogt(I):void 0,M=R&&F?KW(I,F):void 0,O=R&&F?m.readTemporalBucketAuthoringSelectionWithOverride({fieldId:(I==null?void 0:I.id)||T.value,dataType:(I==null?void 0:I.dataType)||"date",granularity:F,format:M==null?void 0:M.format},D==null?void 0:D.presentation):void 0,z=R&&F?lo.getTemporalBucketAuthoringOptions(F,O==null?void 0:O.format):[],L=g[T.value],V=L!==void 0?"custom":(O==null?void 0:O.value)||"auto";return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("p",{className:"text-[11px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Editing selected ",r.slice(0,-1).toLowerCase()]}),l.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsx("span",{className:"text-sm font-medium text-foreground/90",children:(D==null?void 0:D.label)??T.label}),E?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:E}):null,"aggregate"in(I||{})&&typeof(I==null?void 0:I.aggregate)=="string"?l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:I.aggregate}):null]}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]}),l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Shown as"}),l.jsx(m.Input,{size:"xs",value:(D==null?void 0:D.label)??T.label,onChange:B=>y(T.value,$=>({...$,label:B.target.value}))})]}),R?l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Granularity"}),l.jsxs(m.Select,{value:F,onValueChange:B=>{const $=B;x(U=>{const H={...U};return delete H[T.value],H});const P=lo.reconcileTemporalBucketAuthoringFormat((O==null?void 0:O.format)??KW(I,$).format,$);y(T.value,U=>({...U,presentation:{granularity:$,format:P}}))},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:"Select granularity..."})}),l.jsx(m.SelectContent,{children:jpe(I.dataType).map(B=>l.jsx(m.SelectItem,{value:B,children:B.charAt(0).toUpperCase()+B.slice(1)},B))})]})]}):null,R&&F?l.jsx("div",{className:"space-y-1 md:col-span-2",children:l.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Date format"}),l.jsxs(m.Select,{value:V,onValueChange:B=>{var P;let $=L??(O==null?void 0:O.customPattern)??"";if(B==="custom"){const U=z.find(G=>G.value==="custom"),H=((P=U==null?void 0:U.format)==null?void 0:P.presentation.mode)==="pattern"?U.format.presentation.pattern:"";$=(O==null?void 0:O.customPattern)||H||"",x(G=>({...G,[T.value]:$}))}else x(U=>{const H={...U};return delete H[T.value],H});y(T.value,U=>({...U,presentation:{granularity:F,format:lo.resolveTemporalBucketAuthoringFormat(F,B,$)}}))},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:z.map(B=>l.jsx(m.SelectItem,{value:B.value,children:B.label},B.value))})]})]}),V==="custom"?l.jsxs("div",{className:"space-y-1",children:[l.jsx(m.Label,{className:"text-[11px] text-muted-foreground",children:"Custom format"}),l.jsx(m.Input,{size:"xs",value:L??(O==null?void 0:O.customPattern)??"",placeholder:"MMM YYYY",onChange:B=>{const $=B.target.value;x(P=>({...P,[T.value]:$})),y(T.value,P=>({...P,presentation:{granularity:F,format:lo.resolveTemporalBucketAuthoringFormat(F,"custom",$)}}))}})]}):null]})}):null]})]})};return l.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[l.jsxs("div",{className:"flex min-h-0 flex-col gap-3 rounded-lg border bg-muted/10 p-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Add ",r.toLowerCase()]}),l.jsxs("div",{className:"relative",children:[l.jsx(Ft.Search,{className:"pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground","aria-hidden":"true"}),l.jsx(m.Input,{size:"xs",value:d,name:`${t.id}-search-${r.toLowerCase()}`,placeholder:`Search ${r.toLowerCase()}…`,autoComplete:"off",onChange:T=>f(T.target.value),className:"pl-9 pr-9"}),d?l.jsx("button",{type:"button","aria-label":`Clear ${r.toLowerCase()} search`,className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>f(""),children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})}):null]})]}),n.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:o}):S.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:d.trim().length>0?"No matching fields found.":`All compatible ${r.toLowerCase()} are already selected.`}):l.jsx("div",{className:"h-[320px] overflow-y-auto pr-1",children:l.jsx("div",{className:"space-y-1",children:S.map(({option:T,target:I})=>{const D=I?m.getDataType(I.dataType||""):void 0;return l.jsxs("button",{type:"button",className:"group/container flex w-full items-center gap-3 rounded-lg border border-transparent px-2 py-2 text-left transition-all hover:bg-muted",onClick:()=>{b([...a,{...T}]),p(T.value),f("")},children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[l.jsx("div",{className:"truncate text-sm text-foreground/85 group-hover/container:text-foreground",children:(I==null?void 0:I.label)||T.label}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]}),l.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[D?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:D}):null,l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:"Add"})]})]},`${t.id}-available-${T.value}`)})})})]}),l.jsxs("div",{className:"flex min-h-0 flex-col gap-3 rounded-lg border bg-card p-3",children:[l.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l.jsxs(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["Selected ",r.toLowerCase()]}),l.jsx(ki,{variant:"secondary",className:"text-[11px]",children:C.length})]}),C.length===0?l.jsx("div",{className:"rounded-md border border-dashed p-3 text-xs text-muted-foreground",children:"Choose at least one option from the catalog."}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"max-h-[220px] overflow-y-auto pr-1",children:l.jsx("div",{className:"space-y-1",children:C.map(({option:T,target:I})=>{const D=c.get(T.value),E=I?m.getDataType(I.dataType||""):void 0,R=(N==null?void 0:N.option.value)===T.value;return l.jsxs("div",{className:m.cn("flex items-center gap-2 rounded-lg border p-2 transition-colors",R?"border-foreground/20 bg-muted/40":"border-transparent hover:bg-muted/20"),children:[l.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-3 text-left",onClick:()=>p(T.value),children:[l.jsx("div",{className:"shrink-0",children:l.jsx(O2,{dataType:(I==null?void 0:I.dataType)||"string"})}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:"truncate text-sm font-medium text-foreground/90",children:(D==null?void 0:D.label)??T.label}),I!=null&&I.qualifiedFieldName?l.jsx("div",{className:"truncate text-xs text-muted-foreground",children:I.qualifiedFieldName}):null]})]}),l.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[E?l.jsx(ki,{variant:"outline",className:"text-[11px]",children:E}):null,l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7","aria-label":`Remove ${(D==null?void 0:D.label)??T.label}`,onClick:()=>{var M;const F=a.filter(O=>O.value!==T.value);b(F),w===T.value&&p(((M=F[0])==null?void 0:M.value)||null)},children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})]},`${t.id}-selected-${T.value}`)})})}),l.jsx("div",{className:"rounded-lg border bg-muted/5 p-3",children:N?j(N.option,N.target):l.jsx("div",{className:"text-xs text-muted-foreground",children:"Select a field to configure how it appears in the control."})})]})]})]})}function Ipe(e){if(e.participants.length===0)return null;const t=new Set(e.selectedCardIds);return l.jsxs("div",{className:"space-y-2",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Cards using this shared control"}),l.jsx("div",{className:"space-y-2 rounded-md border p-3",children:e.participants.map(n=>l.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[l.jsx(jn,{checked:t.has(n.cardId),onCheckedChange:r=>{if(r===!0){e.onChange([...e.selectedCardIds,n.cardId]);return}e.onChange(e.selectedCardIds.filter(o=>o!==n.cardId))}}),l.jsxs("div",{className:"min-w-0",children:[l.jsx("div",{className:"font-medium",children:n.title}),l.jsxs("div",{className:"text-xs text-muted-foreground",children:[n.choiceCount," ",e.type==="field_selector"?"compatible group-by fields":"compatible metrics"]})]})]},n.cardId))})]})}function $gt(e){const t=e.value===!0?"true":"false";return l.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[l.jsx(m.Button,{type:"button",variant:t==="true"?"default":"outline",onClick:()=>e.onChange(!0),children:"On"}),l.jsx(m.Button,{type:"button",variant:t==="false"?"default":"outline",onClick:()=>e.onChange(!1),children:"Off"})]})}function zgt(e){return e.scope==="dashboard"&&(e.type==="enum"||e.type==="multi_enum")}const _pe={kind:"sql_query",connectionId:"",sql:"",valueColumn:""};function WW(e){return{kind:"manual",options:e.options.map(t=>({...t,...t.presentation?{presentation:{...t.presentation}}:{}}))}}function GW(e){return{...e}}function Bgt(e){return e.source.kind==="sql_query"?e.source:_pe}function Tpe(e){const t=U4(e);return JSON.stringify({controlId:e.controlId,source:zz(e.source),controlDefinitions:$de(t.controlDefinitions),controlValues:Lde(t.controlValues,t.controlDefinitions),activeFilters:e.activeFiltersOverride??null})}function U4(e){const t=Pde(e.previewControlDefinitions),n={...e.previewControlValues||{}};delete n[e.controlId];const r=Ode(n,t);return{controlDefinitions:t,controlValues:r}}function Vgt(e){const[t,n]=v.useState(null),r=v.useRef(e);return v.useEffect(()=>{r.current!==e&&(r.current=e,n(null))},[e]),{requestedForCurrentKey:t===e,markCurrentKeyRequested:()=>n(e)}}function Hgt(e){var w;const{control:t,onChange:n,previewControlDefinitions:r,previewControlValues:o,activeFiltersOverride:s}=e,i=Bgt(t),{connections:a,isPending:c}=La(),u=t.id||"preview",d=i.connectionId.trim().length>0&&i.sql.trim().length>0&&i.valueColumn.trim().length>0,f=U4({controlId:u,previewControlDefinitions:r,previewControlValues:o}),h=Tpe({controlId:u,source:i,previewControlDefinitions:r,previewControlValues:o,activeFiltersOverride:s}),{requestedForCurrentKey:p,markCurrentKeyRequested:g}=Vgt(h),x=cC({controlId:u,source:d?i:void 0,enabled:p&&d,controlDefinitionsOverride:f.controlDefinitions,controlValuesOverride:f.controlValues,activeFiltersOverride:s}),b=N=>{const S={...i,...N,kind:"sql_query"};(!S.labelColumn||S.labelColumn.trim().length===0)&&delete S.labelColumn,n({...t,source:S})},y=m.getRequestErrorMessage(x.error,""),C=x.options;return v.useEffect(()=>{var j;if(i.connectionId||a.length!==1)return;const N=(j=a[0])==null?void 0:j.id;if(!N)return;const S={...i,kind:"sql_query",connectionId:N};(!S.labelColumn||S.labelColumn.trim().length===0)&&delete S.labelColumn,n({...t,source:S})},[a,t,i,n]),l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Connection"}),l.jsxs(m.Select,{value:i.connectionId,onValueChange:N=>{b({connectionId:N})},disabled:c||a.length===0,children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:c?"Loading connections…":a.length===0?"No connections available":"Select a connection"})}),l.jsx(m.SelectContent,{children:a.map(N=>l.jsx(m.SelectItem,{value:N.id,children:N.name},N.id))})]})]}),i.connectionId.trim().length===0?l.jsxs("div",{className:"flex min-h-[200px] flex-col items-center justify-center gap-1 rounded-control border border-border/60 bg-muted/20 px-4 py-8 text-center",children:[l.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"Pick a connection above"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Then write your SQL query to source options."})]}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL"}),l.jsx("div",{className:"h-24 w-full overflow-hidden rounded-control border border-input",onKeyDown:N=>N.stopPropagation(),children:l.jsx(m.CodeEditor,{value:i.sql,onValueChange:N=>b({sql:N}),language:"sql-jinja",embedded:!0,hideLineNumbers:!0,dense:!0,ariaLabel:"Control options SQL query",placeholder:"SELECT id, name FROM segments WHERE account_id = [[param.tenantId]]"})})]}),l.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Value column"}),l.jsx(m.Input,{size:"xs",value:i.valueColumn,placeholder:"id",onChange:N=>{b({valueColumn:N.target.value})}})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label column (optional)"}),l.jsx(m.Input,{size:"xs",value:i.labelColumn||"",placeholder:"name",onChange:N=>{b({labelColumn:N.target.value})}})]})]}),l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",disabled:!d||x.isFetching,onClick:()=>{if(p){x.refetch();return}g()},children:x.isFetching?"Loading…":"Preview options"}),p&&!x.isFetching&&x.data?l.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[C.length," option",C.length===1?"":"s",(w=x.metadata)!=null&&w.truncated?" (truncated)":""]}):null]}),p&&x.isError?l.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Preview unavailable",y?` — ${y}`:""]}):null]})]})}function qgt(e){const{control:t,onChange:n,controlLifecycle:r="edit"}=e,o=t.source.kind==="sql_query"?"sql_query":"manual",s=v.useRef(t.source.kind==="manual"?WW(t.source):null),i=v.useRef(t.source.kind==="manual"?t.requiredAtExecution:null),a=v.useRef(t.source.kind==="sql_query"?GW(t.source):null);t.source.kind==="manual"?(s.current=WW(t.source),i.current=t.requiredAtExecution):t.source.kind==="sql_query"&&(a.current=GW(t.source));const c=u=>{if(u!==o){if(u==="manual"){n({...t,source:s.current||{kind:"manual",options:[]},requiredAtExecution:i.current??t.requiredAtExecution});return}n({...t,source:a.current||_pe,requiredAtExecution:t.initialValueStrategy==="embed_required"?!0:r==="create"?!1:t.requiredAtExecution})}};return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Option source"}),l.jsxs(cc,{value:o,onValueChange:u=>c(u),className:"flex flex-col gap-1.5",children:[l.jsxs("label",{className:"flex items-start gap-2 text-xs",children:[l.jsx(Ms,{value:"manual",className:"mt-0.5"}),l.jsxs("span",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Manual"}),l.jsx("span",{className:"ml-1 text-muted-foreground",children:"— enter label/value rows"})]})]}),l.jsxs("label",{className:"flex items-start gap-2 text-xs",children:[l.jsx(Ms,{value:"sql_query",className:"mt-0.5"}),l.jsxs("span",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"SQL query"}),l.jsx("span",{className:"ml-1 text-muted-foreground",children:"— resolve options from a database query at runtime"})]})]})]})]})}function Dpe(e){const t=m.getPresetOptionsForControlType(e.control.type),n=e.control.source.kind==="sql_query"?e.control:m.ensureManualSource(e.control),r=e.control.type==="field_selector"?e.availableFieldChoices||[]:e.control.type==="metric_selector"?e.availableMetricChoices||[]:[];if(t)return l.jsx(Fgt,{options:t});if(n.type==="field_selector"||n.type==="metric_selector"){const o=n.type==="field_selector"?"Fields":"Metrics",s=n.type==="field_selector"?"No valid group-by fields are available yet. Add fields to the card first.":"No valid metrics are available yet. Add metrics to the card first.";return l.jsx(Lgt,{control:n,choices:r,choiceLabel:o,emptyMessage:s,onChange:e.onChange})}return m.needsManualOptions(n)?zgt(n)?l.jsxs("div",{className:"space-y-3",children:[l.jsx(qgt,{control:n,onChange:e.onChange,controlLifecycle:e.controlLifecycle}),n.source.kind==="sql_query"?l.jsx(Hgt,{control:n,onChange:e.onChange,previewControlDefinitions:e.previewControlDefinitions,previewControlValues:e.previewControlValues,activeFiltersOverride:e.activeFiltersOverride}):l.jsx(UW,{control:n,onChange:e.onChange})]}):l.jsx(UW,{control:n,onChange:e.onChange}):null}function Epe(e){const{control:t,value:n,onChange:r,allowNoDefault:o=!1,allowCardDefault:s=!1,hint:i}=e;if(t.source.kind==="sql_query")return l.jsx(Kgt,{control:t,value:n,onChange:r,allowNoDefault:o,allowCardDefault:s,hint:i,previewControlDefinitions:e.previewControlDefinitions,previewControlValues:e.previewControlValues,activeFiltersOverride:e.activeFiltersOverride});const a=m.ensureManualSource(t),c=m.getDefaultValueForType(t,n),d=m.getPresetOptionsForControlType(t.type)??(a.source.kind==="manual"?a.source.options:[]),f=t.type==="enum"||t.type==="field_selector"||t.type==="metric_selector"||t.type==="aggregation_selector"||t.type==="grain_selector";return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default"}),t.type==="boolean"?l.jsx($gt,{value:c,onChange:r}):f&&d.length>0?l.jsx(Mpe,{controlType:t.type,options:d,value:c,onChange:r,allowNoDefault:o,allowCardDefault:s}):f?l.jsx(m.Input,{size:"xs",value:"",placeholder:"Add choices first",disabled:!0,readOnly:!0}):l.jsx(m.Input,{size:"xs",value:Array.isArray(c)?c.join(", "):String(c??""),placeholder:t.type==="multi_enum"?"value_one, value_two":"Default value",onChange:h=>r(m.parseControlDefaultValue(a,h.target.value))}),i?l.jsx("p",{className:"text-[11px] text-muted-foreground",children:i}):null]})}function Mpe(e){const{controlType:t,options:n,value:r,onChange:o,allowNoDefault:s=!1,allowCardDefault:i=!1}=e,a=i&&m.supportsCardDefaultValue(t),c=r===void 0&&s?m.CONTROL_SELECT_UI_VALUES.noDefault:r===Id.CONTROL_CARD_DEFAULT_VALUE&&a?m.CONTROL_SELECT_UI_VALUES.cardDefault:typeof r=="string"?m.findControlSelectOptionUiValue(n,r):void 0;return l.jsxs(m.Select,{value:c,onValueChange:u=>{if(u===m.CONTROL_SELECT_UI_VALUES.noDefault){o(void 0);return}if(u===m.CONTROL_SELECT_UI_VALUES.cardDefault){o(Id.CONTROL_CARD_DEFAULT_VALUE);return}const d=m.getControlSelectOptionFromUiValue(n,u);d&&o(d.value)},children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{placeholder:"Choose a default"})}),l.jsxs(m.SelectContent,{children:[s?l.jsx(m.SelectItem,{value:m.CONTROL_SELECT_UI_VALUES.noDefault,children:"No default"}):null,a?l.jsx(m.SelectItem,{value:m.CONTROL_SELECT_UI_VALUES.cardDefault,children:"Card default"}):null,n.map((u,d)=>l.jsx(m.SelectItem,{value:m.getControlSelectOptionUiValue(d),children:u.label},u.value))]})]})}function Ugt(e){var a;const{options:t,value:n,onChange:r,allowNoDefault:o=!1}=e,s=m.normalizeControlStringArrayValue(n),i=s.length===0?o?"No default":"Choose defaults":s.length===1?((a=t.find(c=>c.value===s[0]))==null?void 0:a.label)||s[0]:`${s.length} selected`;return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(m.Popover,{children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx(m.Button,{type:"button",variant:"outline",className:"w-full justify-between",children:l.jsx("span",{className:"truncate",children:i})})}),l.jsx(m.PopoverContent,{align:"start",className:"w-64",children:l.jsx("div",{className:"space-y-2",children:t.map(c=>{const u=s.includes(c.value);return l.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[l.jsx(jn,{checked:u,onCheckedChange:d=>{const f=d?[...s,c.value]:s.filter(h=>h!==c.value);r(f.length>0?f:void 0)}}),l.jsx("span",{children:c.label})]},c.value)})})})]}),o&&s.length>0?l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"text-muted-foreground",onClick:()=>r(void 0),children:"Clear"}):null]})}function Kgt(e){const{control:t,value:n,onChange:r,allowNoDefault:o=!1,allowCardDefault:s=!1,hint:i,previewControlDefinitions:a,previewControlValues:c,activeFiltersOverride:u}=e,d=t.source,f=t.id||"preview",h=d.connectionId.trim().length>0&&d.sql.trim().length>0&&d.valueColumn.trim().length>0,p=U4({controlId:f,previewControlDefinitions:a,previewControlValues:c});Tpe({controlId:f,source:d,previewControlDefinitions:a,previewControlValues:c,activeFiltersOverride:u});const g=cC({controlId:f,source:h?d:void 0,enabled:!1,controlDefinitionsOverride:p.controlDefinitions,controlValuesOverride:p.controlValues,activeFiltersOverride:u}),x=g.data!==void 0&&!g.isError,b=g.options.map(N=>({value:N.value,label:N.label})),y=t.type==="multi_enum"?m.normalizeControlStringArrayValue(n):m.getDefaultValueForType(t,n),C=(()=>{const N=[...b],S=new Set(N.map(k=>k.value)),j=k=>{typeof k!="string"||k.length===0||S.has(k)||(S.add(k),N.push({value:k,label:k}))};return Array.isArray(y)?y.forEach(j):j(y),N})(),w=x&&C.length>0;return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default"}),w&&t.type==="multi_enum"?l.jsx(Ugt,{options:C,value:y,onChange:r,allowNoDefault:o}):w?l.jsx(Mpe,{controlType:t.type,options:C,value:y,onChange:r,allowNoDefault:o,allowCardDefault:s}):l.jsx(m.Input,{size:"xs",value:"",placeholder:h?"Preview options above to pick a default (optional)":"Complete the SQL source to pick a default (optional)",disabled:!0,readOnly:!0}),i?l.jsx("p",{className:"text-[11px] text-muted-foreground",children:i}):null]})}function Wgt(e){const{control:t,onChange:n}=e;return l.jsxs("div",{className:"space-y-3",children:[l.jsx("div",{className:"space-y-1",children:l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:t.hidden===!0,onCheckedChange:r=>n({...t,hidden:r===!0})}),"Hide control UI from viewers"]})}),l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:t.locked===!0,onCheckedChange:r=>n({...t,locked:r===!0})}),"Locked"]})]})}function Rpe(e){const t=j0(e);return e.scope==="dashboard"?t==="advanced"?"More controls":"dashboard toolbar":t==="advanced"?"More options":"card header"}function Ggt(e){const t=new Map;for(const n of e.controls||[])t.set(n.id,0);for(const n of m.getDashboardCards(e)){const r=new Set(lC(n));for(const o of r)t.has(o)&&t.set(o,(t.get(o)||0)+1)}return Object.fromEntries((e.controls||[]).map(n=>{if(n.hidden)return[n.id,{tone:"default",status:"Hidden from viewers",helper:"This control can still be used by connected cards, but it will not appear in the dashboard UI."}];const r=t.get(n.id)||0,o=Rpe(n);return r===0?[n.id,{tone:"warning",status:"Not used by any cards yet",helper:`This control is already available in the ${o}. Next: open a card's Controls and either bind this control or reference [[param.${n.id}]] in SQL.`}]:[n.id,{tone:"success",status:`Used in ${r} ${r===1?"card":"cards"}`,helper:`Available in the ${o}. ${r===1?"That card":"Those cards"} will respond when the value changes.`}]}))}function Ygt(e){const t=new Set(lC(e.card));return Object.fromEntries(e.controls.map(n=>{var o;const r=Rpe(n);return n.hidden?[n.id,{tone:"default",status:"Hidden from viewers",helper:"This control is available for runtime state but will not appear in this card UI."}]:t.has(n.id)?[n.id,{tone:"success",status:"Used by this card",helper:`Available in the ${r} for this card.`}]:[n.id,{tone:"warning",status:"Not used by this card yet",helper:(o=e.card)!=null&&o.sql?`Reference [[param.${n.id}]] in this card's SQL to make the card respond to it.`:"Choose what this control changes below to make this card respond to it."}]}))}function Zgt(e){let t=0,n=0,r=0;const o=[];for(const s of m.getDashboardCards(e.dashboard)){if(!new Set(lC(s)).has(e.controlId))continue;t+=1,o.push(s.title||s.id),en.extractSqlParamReferences({sql:s.sql,controlBindings:s.controlBindings}).some(u=>u.controlId===e.controlId)&&(n+=1),(s.controlBindings||[]).some(u=>u.target!=="sql_param"&&u.target!=="presentation_currency"&&u.controlId===e.controlId)&&(r+=1)}return{totalCards:t,sqlCards:n,configCards:r,cardTitles:o}}function Ape(e){var n;const t=new Map;for(const r of m.getDashboardCards(e))for(const o of r.controlBindings||[])o.target!=="config_field_selector"&&o.target!=="config_metric_selector"||(t.has(o.controlId)||t.set(o.controlId,new Set),(n=t.get(o.controlId))==null||n.add(r.id));return Object.fromEntries(Array.from(t.entries()).map(([r,o])=>[r,Array.from(o)]))}function Fpe(e){var n;return(((n=e.dataSource)==null?void 0:n.selectedEntities)||[]).filter(r=>r.type!=="file"&&r.type!=="url"&&r.type!=="upload").map(r=>({cardId:e.id,target:r}))}function Xgt(e){if(e.type==="model")return`model:${e.connectionId}:${e.id}`;if(e.type==="dataset"){const t=e;return`dataset:${t.connectionId}:${t.domainId}:${t.name}`}return`table:${e.connectionId}:${e.database||""}:${e.schema||""}:${e.name}`}function Qgt(e){const t=new Map;return e.flatMap(n=>Fpe(n)).forEach(({cardId:n,target:r})=>{const o=Xgt(r),s=t.get(o);if(!s){t.set(o,{key:o,cardIds:[n],target:r});return}s.cardIds.includes(n)||s.cardIds.push(n)}),Array.from(t.values())}function Jgt(e){if(e.type==="dataset"){const t=e;return!!(t.connectionId&&t.domainId&&t.name)}if(e.type==="model"){const t=e;return!!(t.connectionId&&t.id)}return!!(e.connectionId&&e.name)}function ext(e){if(e.type==="model"){const t=e;return{connection_id:t.connectionId,datamodel_id:t.id,database_name:"",schema_name:"",table_name:""}}if(e.type==="dataset"){const t=e;return{connection_id:t.connectionId,domain_id:t.domainId,dataset_name:t.name}}return{connection_id:e.connectionId,datamodel_id:"",database_name:e.database,schema_name:e.schema,table_name:e.name}}function txt(e){const{target:t,column:n}=e,r=m.getQualifiedEntityName(t);return{id:`${t.name}-${n.column_name}`,name:n.column_name,qualifiedFieldName:n.qualifiedFieldName||n.column_name,dataType:n.data_type,label:n.label||n.column_name,description:n.description||"",qualifiedEntityName:r,entityId:t.id||t.id||t.name,entityName:t.name,entityType:t.type,role:n.role==="metric"?"metric":void 0,expression:n.expression,calculatedFormula:n.calculatedFormula,...Nse(n)}}function Ppe(e){const{tokenProps:t}=Mt(),n=m.useDashboardStore(f=>f.authToken),r=v.useMemo(()=>Qgt(e.filter(f=>f.type!=="matrixTable")),[e]),o=v.useMemo(()=>new Map(e.flatMap(f=>{const h=mu.inspectMatrixCardConfig(f);if(h.status!=="ready")return[];const p=Fpe(f).flatMap(({target:g})=>{const x=lo.resolveDashboardEntitySource(g,f.dataSource);return x?[x]:[]});return[[f.id,Es.matrixCatalogSources(h.config.spec,f.controlBindings,p)]]})),[e]),s=v.useMemo(()=>[...o.values()].flat(),[o]),i=Pw(s),a=cf({queries:r.map(({key:f,target:h})=>({queryKey:["dashboard-structural-columns",f],queryFn:()=>m.getRequest(`${t.apiServiceUrl}/v1/columns`,(n==null?void 0:n.accessToken)||"",ext(h)),enabled:!!(n!=null&&n.accessToken)&&Jgt(h)}))}),c=i.pending||a.some(f=>f.isPending&&f.fetchStatus==="fetching"),u=v.useMemo(()=>{const f=new Map;a.forEach((h,p)=>{const g=r[p],x=g==null?void 0:g.target;if(!g||!x||!h.data)return;const b=[...(h.data.columns||[]).map(y=>txt({target:x,column:y})),...h.data.calculatedFields||[]];g.cardIds.forEach(y=>{f.set(y,[...f.get(y)||[],...b])})});for(const[h,p]of o)f.set(h,i.catalog.filter(g=>p.some(x=>ze.semaphorSourcesReferToSameDataset(x,g.field.source))).map(g=>({...g.resolvedField,source:g.field.source})));return f},[a,r,o,i.catalog]);return{participants:v.useMemo(()=>e.map(f=>{var N;const h=u.get(f.id)||[],p=m.getAuthoredCardFields(f),g=mu.inspectMatrixCardConfig(f);if(f.type==="matrixTable"&&g.status!=="ready")return{cardId:f.id,title:f.title||f.id,canBindStructuralControl:!1,fieldChoices:[],metricChoices:[]};const x=((N=p.metrics[0])==null?void 0:N.aggregate)||"SUM",b=m.buildDashboardFieldSelectorChoicesFromFields(h,g.status==="ready"),y=m.buildDashboardMetricSelectorChoicesFromFields(h,x,g.status==="ready"),C=m.getFieldSelectorChoicesForCard(f),w=m.getMetricSelectorChoicesForCard(f);return{cardId:f.id,matrixSpec:g.status==="ready"?g.config.spec:void 0,controlBindings:f.controlBindings,title:f.title||f.id,canBindStructuralControl:f.type==="matrixTable"?g.status==="ready":!!f.config,fieldChoices:b.choices.length>0?b.choices:C,metricChoices:y.choices.length>0?y.choices:w,fieldTargetMap:b.choices.length>0?b.targetMap:Object.fromEntries([...p.rows,...p.columns].filter(S=>typeof S.id=="string").map(S=>[S.id,{...S,role:"groupby"}])),metricTargetMap:y.choices.length>0?y.targetMap:Object.fromEntries(p.metrics.filter(S=>w.some(j=>j.value===S.id)).map(S=>[S.id,{...S,role:"metric",aggregate:S.aggregate??x}]))}}),[e,u]),isLoading:c}}function Ope({control:e,defaultValue:t,defaultPlacement:n,placementOptions:r,previewControlDefinitions:o,previewControlValues:s,availableFieldChoices:i=[],availableMetricChoices:a=[],structuralParticipantSelector:c,allowCardDefault:u=!1,allowControlIdEdit:d=!0,showPlacementSelect:f=!0,showViewerVisibilityToggle:h=!0,activeFiltersOverride:p,onChangeControl:g,onChangeDefaultValue:x,onCommitControlId:b}){const y="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",C=d&&!!b,w=f?C?"grid grid-cols-3 gap-2":"grid grid-cols-2 gap-2":C?"grid grid-cols-2 gap-2":"grid grid-cols-1 gap-2";return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:w,children:[l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Label"}),l.jsx(m.Input,{size:"xs",value:e.label,placeholder:"Control label",onChange:N=>g(S=>({...S,label:N.target.value}))})]}),C?l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Variable name"}),l.jsx(kpe,{controlId:e.id,onCommit:b},e.id)]}):null,f?l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Show in"}),l.jsxs(m.Select,{value:e.placement||n,onValueChange:N=>g(S=>({...S,placement:N})),children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:r.map(N=>l.jsx(m.SelectItem,{value:N.value,children:N.label},N.value))})]})]}):null]}),c,l.jsx(Dpe,{control:e,availableFieldChoices:i,availableMetricChoices:a,previewControlDefinitions:o,previewControlValues:s,activeFiltersOverride:p,controlLifecycle:"edit",onChange:N=>g(()=>N)}),e.initialValueStrategy==="saved_default"&&l.jsx(Epe,{control:e,value:t,allowNoDefault:!0,allowCardDefault:u,previewControlDefinitions:o,previewControlValues:s,activeFiltersOverride:p,onChange:x}),l.jsx("div",{className:"grid grid-cols-1 gap-2",children:l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx(m.Label,{className:y,children:"Initial value"}),l.jsxs(m.Select,{value:e.initialValueStrategy,onValueChange:N=>g(S=>({...S,initialValueStrategy:N})),children:[l.jsx(m.SelectTrigger,{size:"xs",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:m.INITIAL_VALUE_STRATEGY_OPTIONS.map(N=>l.jsx(m.SelectItem,{value:N.value,children:N.label},N.value))})]})]})}),l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:e.showLabel??!0,onCheckedChange:N=>g(S=>({...S,showLabel:N===!0}))}),"Show label in toolbar"]}),h?l.jsxs("label",{className:"flex items-center gap-2 text-[13px]",children:[l.jsx(jn,{checked:e.hidden===!0,onCheckedChange:N=>g(S=>({...S,hidden:N===!0}))}),"Hide control UI from viewers"]}):null]})}function Lpe({open:e,onOpenChange:t,trigger:n,title:r,subtitle:o,description:s,body:i,footer:a,onClose:c,useDialog:u=!1,deleteDialogOpen:d,onDeleteDialogOpenChange:f,deleteDescription:h,deleteDetails:p,onConfirmDelete:g}){const x=xl("interactive"),b=l.jsx(nxt,{title:r,subtitle:o,onClose:c,titleAsDialogTitle:u});return l.jsxs(l.Fragment,{children:[u?l.jsxs(To,{open:e,onOpenChange:t,children:[l.jsx(zQ,{asChild:!0,children:n}),l.jsxs(bo,{showCloseButton:!1,className:"flex max-h-[88vh] flex-col overflow-hidden rounded-control border border-border/60 p-0 shadow-sm sm:max-w-[600px] sm:rounded-control",style:x.controlStyle,onInteractOutside:y=>y.preventDefault(),children:[l.jsx(Ho,{className:"sr-only",children:s}),b,l.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-4",children:i}),l.jsx("div",{className:"shrink-0 border-t border-border/60 px-4 py-2.5",children:a})]})]}):l.jsxs(m.Popover,{open:e,onOpenChange:t,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:n}),l.jsxs(m.PopoverContent,{align:"start",className:"m-2 flex h-[440px] max-h-[85vh] w-[480px] max-w-[95vw] flex-col overflow-hidden rounded-control border border-border/60 p-0 shadow-[0_10px_28px_rgba(0,0,0,0.14)] dark:shadow-[0_10px_28px_rgba(0,0,0,0.5)]",style:x.controlStyle,onMouseDown:y=>y.stopPropagation(),children:[b,l.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-4 py-4",children:i}),l.jsx("div",{className:"shrink-0 border-t border-border/60 px-4 py-2.5",children:a})]})]}),f&&g?l.jsx($pe,{open:d,onOpenChange:f,description:h,details:p,onConfirm:g}):null]})}function $pe({open:e,defaultOpen:t,onOpenChange:n,description:r,details:o,onConfirm:s}){const i=xl("interactive");return l.jsx(ff,{open:e,defaultOpen:t,onOpenChange:n,children:l.jsxs(Tu,{style:i.controlStyle,children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete control?"}),l.jsx(Ru,{children:r}),o]}),l.jsxs(Eu,{children:[l.jsx(Fu,{children:"Cancel"}),l.jsx(Au,{onClick:s,children:"Delete control"})]})]})})}function nxt({title:e,subtitle:t,onClose:n,titleAsDialogTitle:r}){const o="truncate text-[13px] font-medium text-foreground",s=r?l.jsx(yo,{className:o,title:e,children:e}):l.jsx("span",{className:o,title:e,children:e});return l.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b border-border/60 px-3",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l.jsx(m.SlidersHorizontal,{"aria-hidden":!0,className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),s,l.jsx("span",{className:"shrink-0 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})]}),l.jsx("button",{type:"button",onClick:n,"aria-label":"Close",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})}function rxt({control:e,onClose:t}){const n=m.useDashboardStore(d=>d.dashboard),{setDashboardControlsModel:r}=m.useDashboardActions(),o=v.useMemo(()=>Zgt({dashboard:n,controlId:e.id}),[n,e.id]),s=()=>{const d=(n.controls||[]).filter(h=>h.id!==e.id),f={...n.defaultControlValues||{}};delete f[e.id],r(d,f,{removedControlId:e.id}),t()},i=o.totalCards===0?`Delete "${e.label}"?`:`This control is used by ${o.totalCards} ${o.totalCards===1?"card":"cards"}. Deleting it will remove bindings and replace SQL references with NULL on affected cards.`,a=o.cardTitles.slice(0,3).join(", "),c=o.cardTitles.length>3,u=o.totalCards>0?l.jsxs("div",{className:"space-y-1 text-sm text-muted-foreground",children:[l.jsxs("p",{children:["Affected cards: ",a,c?` +${o.cardTitles.length-3} more`:""]}),o.sqlCards>0?l.jsxs("p",{children:["SQL references on ",o.sqlCards," ",o.sqlCards===1?"card":"cards"," will be replaced with `NULL`."]}):null,o.configCards>0?l.jsxs("p",{children:["Config bindings on ",o.configCards," ",o.configCards===1?"card":"cards"," will be removed."]}):null]}):void 0;return l.jsx($pe,{defaultOpen:!0,onOpenChange:d=>!d&&t(),description:i,details:u,onConfirm:s})}function zpe(e){return l.jsx(l.Fragment,{children:e.participants.filter(t=>t.matrixSpec&&e.selectedCardIds.includes(t.cardId)).map(t=>{var s;const n=m.getStructuralMatrixTargets(t,e.control.type),r=m.resolveStructuralMatrixTarget(t,e.control,(s=e.selected)==null?void 0:s[t.cardId]),o=n.some(i=>i.id===r);return l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"text-xs",children:[t.title,": Matrix target"]}),l.jsxs(m.Select,{value:r??"",onValueChange:i=>e.onChange(t.cardId,i),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":`${t.title}: Matrix target`,children:l.jsx(m.SelectValue,{placeholder:"Choose target"})}),l.jsxs(m.SelectContent,{children:[r&&!o&&l.jsx(m.SelectItem,{value:r,disabled:!0,children:"Missing target"}),n.map(i=>l.jsx(m.SelectItem,{value:i.id,children:i.label},i.id))]})]}),!o&&l.jsx("p",{role:"alert",className:"text-xs text-muted-foreground",children:"Select a Matrix target."})]},t.cardId)})})}function Bpe({onOpen:e,className:t}){return l.jsx("button",{type:"button",className:t??"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Control settings",onClick:n=>{n.stopPropagation(),e==null||e()},children:l.jsx(uf,{className:"h-3 w-3"})})}function oxt({control:e,triggerClassName:t}){const[n,r]=v.useState("closed");return n==="closed"?l.jsx(Bpe,{onOpen:()=>r("settings"),className:t}):n==="delete"?l.jsx(rxt,{control:e,onClose:()=>r("closed")}):l.jsx(sxt,{control:e,triggerClassName:t,onClose:()=>r("closed"),onDelete:()=>r("delete")})}function sxt({control:e,triggerClassName:t,onClose:n,onDelete:r}){const o=m.useDashboardStore(B=>B.dashboard),{setDashboardControlsModel:s}=m.useDashboardActions(),i=m.getPlacementOptionsForScope("dashboard"),a=m.getDefaultPlacement("dashboard"),{participants:c}=Ppe(m.getDashboardCards(o)),u=Ape(o),d=v.useMemo(()=>u[e.id]||[],[u,e.id]),f=m.isStructuralSelectorControlType(e.type)?m.getEligibleParticipantsForStructuralControl(c,e.type):[],h=m.resolveAuthoringControlDefaultValue({control:e,defaultValues:o.defaultControlValues||{}}),p=v.useCallback(B=>({...B,source:B.source.kind==="manual"?{kind:"manual",options:B.source.options.map($=>({...$,presentation:$.presentation?{...$.presentation}:void 0}))}:{...B.source}}),[]),g=v.useCallback(()=>({control:p(e),selectedCardIds:[...d],matrixTargetIds:Object.fromEntries(c.flatMap(B=>{const $=m.resolveStructuralMatrixTarget(B,e);return $?[[B.cardId,$]]:[]})),defaultValue:h}),[p,e,h,d,c]),[x,b]=v.useState(g),y=v.useRef(h),C=x.control,w=x.selectedCardIds,N=m.isStructuralSelectorControlType(C.type)?m.getCompatibleStructuralChoiceCatalog({controlType:C.type,participants:c,selectedCardIds:w}):{choices:[],fieldTargetMap:{},metricTargetMap:{}},S=C.type==="field_selector"?N.choices.map(B=>({option:B,target:N.fieldTargetMap[B.value]})):Array.from(new Map(c.flatMap(B=>B.fieldChoices.map($=>{var P;return[$.value,{option:$,target:(P=B.fieldTargetMap)==null?void 0:P[$.value]}]}))).values()),j=C.type==="metric_selector"?N.choices.map(B=>({option:B,target:N.metricTargetMap[B.value]})):Array.from(new Map(c.flatMap(B=>B.metricChoices.map($=>{var P;return[$.value,{option:$,target:(P=B.metricTargetMap)==null?void 0:P[$.value]}]}))).values()),k=v.useMemo(()=>(o.controls||[]).map(B=>B.id===e.id?C:B),[e.id,o.controls,C]),_=v.useMemo(()=>m.buildAuthoringPreviewControlValues({controls:k,defaultValues:o.defaultControlValues||{},overrides:[{controlId:e.id,value:void 0},{controlId:C.id,value:x.defaultValue}]}),[e.id,o.defaultControlValues,x.defaultValue,C.id,k]),T=B=>{b($=>{const P=B($.control);$.control.source.kind==="manual"&&P.source.kind==="sql_query"&&(y.current=$.defaultValue);const U=$.defaultValue===void 0&&$.control.source.kind==="sql_query"&&P.source.kind==="manual"?y.current:$.defaultValue,H=m.getNextEditedControlDefaultValue({previousControl:$.control,nextControl:P,currentDefaultValue:U});return P.source.kind==="manual"&&(y.current=H),{...$,control:P,defaultValue:H}})},I=B=>{if(!m.isStructuralSelectorControlType(C.type))return;const $=m.getCompatibleStructuralChoiceCatalog({controlType:C.type,participants:c,selectedCardIds:B}),P=m.reconcileStructuralControlChoices({control:C,choices:$.choices});b(U=>({...U,selectedCardIds:B,control:P,defaultValue:m.getNextEditedControlDefaultValue({previousControl:U.control,nextControl:P,currentDefaultValue:U.defaultValue})}))},D=B=>{if(!B.trim())return;const $=m.normalizeDashboardInputVariableName(B);$!==e.id&&Jue(o,{source:"dashboardControl",controlId:e.id}).includes($)||b(P=>P.control.id===$?P:{...P,control:{...P.control,id:$}})},E=()=>{y.current=h,b(g()),n()},R=()=>{const B={...o.defaultControlValues||{}};delete B[e.id];let $=x.control,P;const U=m.structuralControlBindingsChanged({control:e,cardIds:d,matrixTargetIds:g().matrixTargetIds},{control:$,cardIds:x.selectedCardIds,matrixTargetIds:x.matrixTargetIds});if(m.isStructuralSelectorControlType($.type)&&U){const q=m.getCompatibleStructuralChoiceCatalog({controlType:$.type,participants:c,selectedCardIds:x.selectedCardIds});$=m.reconcileStructuralControlChoices({control:$,choices:q.choices}),P=Object.fromEntries(d.filter(Y=>!x.selectedCardIds.includes(Y)).map(Y=>[Y,void 0])),x.selectedCardIds.length>0&&$.source.kind==="manual"&&$.source.options.length>0&&Object.assign(P,m.buildStructuralControlBindingsForParticipants({control:$,participants:c,selectedCardIds:x.selectedCardIds,matrixTargetIds:x.matrixTargetIds}))}!m.isStructuralSelectorControlType($.type)&&m.isStructuralSelectorControlType(e.type)&&(P=Object.fromEntries(d.map(q=>[q,void 0]))),$.initialValueStrategy==="saved_default"&&x.defaultValue!==void 0&&(B[$.id]=x.defaultValue),$={...$,defaultValue:B[$.id]},$=m.syncSqlQueryControlExecutionRequirement($,B[$.id]);const H=(o.controls||[]).map(q=>q.id===e.id?$:q),G={renamed:$.id!==e.id?{oldId:e.id,newId:$.id}:void 0,cardBindingsById:P,affectedBindingControlIds:m.isStructuralSelectorControlType($.type)?[$.id]:m.isStructuralSelectorControlType(e.type)?[e.id]:void 0};s(H,B,G),n()},F=m.isStructuralSelectorControlType(e.type),M=B=>{B||E()},O=l.jsx(Bpe,{className:t}),z=l.jsx(Ope,{control:C,defaultValue:x.defaultValue,defaultPlacement:a,placementOptions:i,previewControlDefinitions:k,previewControlValues:_,availableFieldChoices:S,availableMetricChoices:j,allowCardDefault:!0,structuralParticipantSelector:m.isStructuralSelectorControlType(C.type)?l.jsxs(l.Fragment,{children:[l.jsx(Ipe,{type:C.type,participants:f.map(B=>({cardId:B.cardId,title:B.title,choiceCount:C.type==="field_selector"?B.fieldChoices.length:B.metricChoices.length})),selectedCardIds:w,onChange:I}),l.jsx(zpe,{participants:c,selectedCardIds:w,control:e,selected:x.matrixTargetIds,onChange:(B,$)=>b(P=>({...P,matrixTargetIds:{...P.matrixTargetIds,[B]:$}}))})]}):null,onChangeControl:T,onChangeDefaultValue:B=>{C.source.kind==="manual"&&(y.current=B),b($=>({...$,defaultValue:B}))},onCommitControlId:D}),L=l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",onClick:r,children:"Delete"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:E,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:R,disabled:m.isStructuralSelectorControlType(C.type)&&!m.hasStructuralMatrixTargets({participants:c,selectedCardIds:w,control:e,selected:x.matrixTargetIds}),children:"Accept"})]})]}),V=C.label||"Control",A=m.getFriendlyTypeOption(C.type).label;return l.jsx(Lpe,{open:!0,onOpenChange:M,trigger:O,title:V,subtitle:A,description:"Update how this control appears and behaves in the dashboard toolbar.",body:z,footer:L,onClose:E,useDialog:F})}function ixt(e,t){return e.length===t.length&&e.every((n,r)=>{var o,s;return n.value===((o=t[r])==null?void 0:o.value)&&n.label===((s=t[r])==null?void 0:s.label)})}function axt(e){if(!(e.source.kind!=="sql_query"||e.type!=="enum"&&e.type!=="multi_enum"))return e.source}function lxt(e){return e.source.kind==="manual"?e.source.options:[]}function cxt({control:e,value:t,popoverOpen:n,controlDefinitionsOverride:r,controlValuesOverride:o,activeFiltersOverride:s}){const i=axt(e),a=v.useMemo(()=>{const w=zz(i);return w===null?null:`${e.id}:${e.type}:${w}`},[e.id,e.type,i]),c=i!==void 0&&(n||$z(t)),u=cC({controlId:e.id,source:i,enabled:c,controlDefinitionsOverride:r,controlValuesOverride:o,activeFiltersOverride:s}),[d,f]=v.useState(()=>({key:a,labels:new Map,options:[]})),h=u.options,p=c&&!u.isLoading&&!u.isFetching&&!u.isError,g=h.length>0||p;if(v.useEffect(()=>{if(!i){f(w=>w.key===null&&w.options.length===0?w:{key:null,labels:new Map,options:[]});return}f(w=>{const N=w.key===a;if(!g)return N?w:{key:a,labels:new Map,options:[]};const S=N?new Map(w.labels):new Map;let j=!N;for(const k of h)S.get(k.value)!==k.label&&(S.set(k.value,k.label),j=!0);return N&&!j&&ixt(w.options,h)?w:{key:a,labels:S,options:h}})},[h,g,a,i]),!i)return{options:lxt(e),labelByValue:void 0,isInitialLoading:!1,hasBlockingError:!1};const x=new Map(d.key===a?d.labels:void 0);for(const w of h)x.set(w.value,w.label);const b=[...g?h:d.key===a?d.options:[]],y=new Set(b.map(w=>w.value)),C=w=>{typeof w!="string"||w.length===0||y.has(w)||(y.add(w),b.push({value:w,label:x.get(w)??w}))};if(Array.isArray(t))for(const w of t)C(w);else C(t);return{options:b,labelByValue:x,isInitialLoading:u.isLoading&&b.length===0,hasBlockingError:u.isError&&b.length===0}}const uxt=24,dxt=/^\d{4}-\d{2}-\d{2}$/;function Vf(e,t=uxt){return e.length<=t?e:`${e.slice(0,t-1)}…`}function fxt(e,t,n,r){if(t==null||t==="")return null;if(e.type==="date")try{if(typeof t=="string"&&dxt.test(t)){const[s,i,a]=t.split("-").map(Number);return Lt.format(new Date(s,i-1,a),"MMM d, yyyy")}const o=t instanceof Date?t:new Date(t);return Number.isNaN(o.getTime())?null:Lt.formatInTimeZone(o,n,"MMM d, yyyy")}catch{return null}if(e.type==="multi_enum"&&Array.isArray(t)){if(t.length===0)return null;if(t.length===1){const o=L2(e,t[0],r);return o!==null?Vf(o):e.source.kind==="sql_query"?null:Vf(String(t[0]))}return`${t.length} selected`}if(e.type==="enum"){const o=L2(e,t,r);return o!==null?Vf(o):e.source.kind==="sql_query"?null:Vf(String(t))}if(Fde(e)){const o=L2(e,t,r);return Vf(o===null?String(t):o)}return e.type==="boolean"?t?"On":"Off":Vf(String(t))}function L2(e,t,n){const r=String(t);if(n!=null&&n.has(r))return n.get(r)??null;const o=e.source;if(!o)return null;if(o.kind==="manual"&&Array.isArray(o.options)){const a=o.options.find(c=>c.value===t);return(a==null?void 0:a.label)??null}const i=hxt(e,t).find(a=>a.value===t);return i?i.label:null}function hxt(e,t){const n=Lz(e);return!(t===Id.CONTROL_CARD_DEFAULT_VALUE||e.defaultValue===Id.CONTROL_CARD_DEFAULT_VALUE)||n.some(o=>o.value===MP.value)?n:[MP,...n]}function mxt(e){return e.type==="date"?Pv:m.SlidersHorizontal}function pxt(e){return e.type==="date"?360:e.type==="multi_enum"?300:e.type==="number"?240:280}function Vpe({control:e,value:t,isEditing:n=!1,dragListeners:r,dragAttributes:o,onChange:s,onUpdateControl:i,disabled:a=!1,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d,actions:f}){const h=xl("interactive"),[p,g]=v.useState(!1),x=vl(),b=cxt({control:e,value:t,popoverOpen:p,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d}),y=fxt(e,t,x,b.labelByValue),C=$z(t),w=y!==null,N=e.showLabel??!0,S=a||e.locked===!0,j=gxt(e,t,S),k=mxt(e);return l.jsxs("div",{className:"group/chip flex shrink-0 items-center gap-2",children:[n&&r&&l.jsx("span",{role:"button",tabIndex:-1,"aria-label":"Drag to reorder",className:"inline-flex h-7 cursor-grab items-center justify-center px-0.5 text-muted-foreground/50 transition-colors hover:text-muted-foreground active:cursor-grabbing",...r,...o,children:l.jsx(Iu,{className:"size-3"})}),l.jsxs(m.Popover,{open:p,onOpenChange:g,children:[l.jsxs("div",{className:m.cn("inline-flex h-7 items-stretch overflow-hidden rounded-control border border-border text-[12px] transition-colors",C?h.hasAppearance?"bg-accent/80 hover:bg-accent":"bg-muted/80 hover:bg-muted":h.hasAppearance?"bg-muted/40 hover:bg-accent/50":"bg-muted/40 hover:bg-muted/70"),style:h.chipStyle,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":w?`${e.label}: ${y}`:e.label,className:m.cn("inline-flex items-center gap-1.5 pl-2 focus:outline-none",C&&j||n?"pr-1":"pr-2"),children:[l.jsx(k,{className:m.cn("h-3 w-3 shrink-0",C?"text-muted-foreground":"text-muted-foreground/70")}),N&&l.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:e.label}),w&&l.jsxs(l.Fragment,{children:[N&&l.jsx("span",{className:"text-border","aria-hidden":"true",children:"·"}),l.jsx("span",{className:"max-w-[160px] truncate whitespace-nowrap font-medium text-foreground",children:y})]}),l.jsx(Re.ChevronDown,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"})]})}),C&&j&&l.jsx("button",{type:"button",onClick:_=>{_.preventDefault(),_.stopPropagation(),s(void 0)},"aria-label":`Clear ${e.label}`,className:"inline-flex w-6 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(Re.X,{className:"h-3 w-3"})}),n&&l.jsx("span",{className:"inline-flex shrink-0 items-center justify-center",children:f!==void 0?l.jsx("span",{className:"inline-flex items-center px-1",children:f}):l.jsx(oxt,{control:e,triggerClassName:"inline-flex h-full w-7 shrink-0 items-center justify-center text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"})})]}),l.jsx(m.PopoverContent,{align:"start",sideOffset:4,style:{width:pxt(e),...h.contentStyle},className:m.cn(YW(e)||ZW(e)?"p-1.5":"p-3"),onMouseDown:_=>_.stopPropagation(),onClick:_=>_.stopPropagation(),children:YW(e)?l.jsx(XW,{control:e,value:t,disabled:S,multi:!1,options:b.options,isInitialLoading:b.isInitialLoading,hasBlockingError:b.hasBlockingError,onChange:_=>{s(_),g(!1)}}):ZW(e)?l.jsx(XW,{control:e,value:t,disabled:S,multi:!0,options:b.options,isInitialLoading:b.isInitialLoading,hasBlockingError:b.hasBlockingError,onChange:_=>{g(!1),s(_)}}):l.jsx(RP,{control:e,value:t,onChange:s,showLabel:!1,disabled:S,controlDefinitionsOverride:c,controlValuesOverride:u,activeFiltersOverride:d})})]})]})}function YW(e){return e.type==="enum"&&(e.source.kind==="manual"||e.source.kind==="sql_query")}function ZW(e){return e.type==="multi_enum"&&(e.source.kind==="manual"||e.source.kind==="sql_query")}function XW({control:e,value:t,disabled:n,multi:r,options:o,isInitialLoading:s,hasBlockingError:i,onChange:a}){return s?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"Loading options…"}):i?l.jsx(Bue,{}):r?l.jsx(bxt,{control:e,options:o,value:t,disabled:n,onChange:a}):l.jsx(xxt,{control:e,options:o,value:t,disabled:n,onChange:a})}function gxt(e,t,n){return!n&&!e.requiredAtExecution&&$z(t)}function xxt({control:e,options:t,value:n,disabled:r,onChange:o}){return t.length===0?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"No options"}):l.jsx("div",{role:"radiogroup",className:"flex flex-col gap-0.5",children:t.map(s=>{const i=n===s.value;return l.jsxs("button",{type:"button",role:"radio","aria-checked":i,disabled:r,onClick:()=>{r||o(s.value)},className:m.cn("flex w-full items-center gap-2 rounded-[4px] px-1.5 py-1 text-left text-[13px] transition-colors",r?"cursor-not-allowed opacity-50":i?"bg-muted text-foreground hover:bg-foreground/[0.08]":"text-foreground hover:bg-muted"),children:[l.jsx($ue,{checked:i,className:m.cn("h-3.5 w-3.5",r&&"opacity-50")}),l.jsx("span",{className:"truncate",children:s.label})]},String(s.value))})})}function bxt({control:e,options:t,value:n,disabled:r,onChange:o}){const[s,i]=v.useState(""),[a,c]=v.useState(()=>QW(n)),[u,d]=v.useState(!1),f=v.useMemo(()=>QW(n),[n]),h=u?a:f,p=v.useMemo(()=>{const C=s.trim().toLowerCase();return C?t.filter(w=>w.label.toLowerCase().includes(C)||w.value.toLowerCase().includes(C)):t},[t,s]),g=v.useMemo(()=>new Set(h.map(C=>String(C))),[h]),x=()=>{if(r)return;const C=a.length===0&&!e.requiredAtExecution?void 0:a;o(C),d(!1)},b=()=>{r||e.requiredAtExecution||(c([]),d(!0))},y=C=>{if(r)return;const w=String(C),N=g.has(w);N&&h.length===1&&e.requiredAtExecution||(d(!0),c(()=>N?h.filter(S=>String(S)!==w):[...h,C]))};return t.length===0?l.jsx("p",{className:"px-2 py-2 text-[12px] text-muted-foreground",children:"No options"}):l.jsxs("div",{className:"flex min-w-0 flex-col",children:[l.jsxs("div",{className:"mb-1.5 flex h-7 shrink-0 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring",children:[l.jsx(Ft.Search,{className:"h-3 w-3 shrink-0 text-muted-foreground","aria-hidden":"true"}),l.jsx("input",{type:"text",value:s,onChange:C=>i(C.target.value),placeholder:`Search ${e.label.toLowerCase()}`,"aria-label":`Search ${e.label.toLowerCase()}`,className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),l.jsx("div",{role:"listbox","aria-multiselectable":"true",className:"-mx-0.5 max-h-[260px] overflow-y-auto px-0.5",children:p.length===0?l.jsx("div",{className:"px-2 py-6 text-center text-[12px] text-muted-foreground",children:s?"No matches":"No options"}):p.map(C=>{const w=g.has(String(C.value)),N=r||w&&h.length===1&&e.requiredAtExecution;return l.jsxs("button",{type:"button",role:"option","aria-selected":w,disabled:N,onClick:()=>y(C.value),className:m.cn("flex w-full items-center gap-2 rounded-[4px] px-1.5 py-1 text-left text-[13px] transition-colors",N?"cursor-not-allowed opacity-50":w?"bg-muted text-foreground hover:bg-foreground/[0.08]":"text-foreground hover:bg-muted"),children:[l.jsx("span",{"aria-hidden":"true",className:m.cn("inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded-[4px] border border-input bg-background text-primary",w&&"border-primary bg-primary text-primary-foreground",N&&"opacity-60"),children:w?l.jsx(m.Check,{className:"h-2.5 w-2.5",strokeWidth:3}):null}),l.jsx("span",{className:"truncate",children:C.label})]},String(C.value))})}),l.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-2 border-t border-border pt-1.5",children:[l.jsxs("span",{className:"px-0.5 text-[11px] text-muted-foreground",children:[l.jsx("span",{className:"tabular-nums text-foreground",children:h.length})," ","selected"]}),l.jsxs("div",{className:"flex items-center gap-1",children:[!e.requiredAtExecution&&(u||f.length>0)&&l.jsx("button",{type:"button",onClick:b,className:"inline-flex h-6 items-center rounded-control px-2 text-[12px] text-muted-foreground hover:bg-muted hover:text-foreground",children:"Clear"}),l.jsx("button",{type:"button",onClick:x,disabled:r||!u,className:"inline-flex h-6 items-center rounded-control bg-primary px-2 text-[12px] text-primary-foreground disabled:pointer-events-none disabled:opacity-50",children:"Apply"})]})]})]})}function QW(e){return Array.isArray(e)?e:e==null?[]:[e]}function yxt(e,t,n){if(t===n)return null;const r=e.indexOf(t),o=e.indexOf(n);return r===-1||o===-1?null:up(e,r,o)}function vxt({control:e,controls:t,reservedVariableNames:n=[],activeFiltersOverride:r,onUpdateControl:o,onRemoveControl:s}){const[i,a]=v.useState(!1),[c,u]=v.useState(!1),d=m.getPlacementOptionsForScope("dashboard"),f=m.getDefaultPlacement("dashboard"),h=v.useMemo(()=>Cxt(t),[t]),p=m.resolveAuthoringControlDefaultValue({control:e,defaultValues:h}),g=v.useCallback(z=>({...z,source:z.source.kind==="manual"?{kind:"manual",options:z.source.options.map(L=>({...L,presentation:L.presentation?{...L.presentation}:void 0}))}:{...z.source}}),[]),x=v.useCallback(()=>({control:g(e),defaultValue:p}),[g,e,p]),[b,y]=v.useState(x),C=v.useRef(p),w=b.control,N=v.useMemo(()=>t.map(z=>z.id===e.id?w:z),[e.id,t,w]),S=v.useMemo(()=>m.buildAuthoringPreviewControlValues({controls:N,defaultValues:h,overrides:[{controlId:e.id,value:void 0},{controlId:w.id,value:b.defaultValue}]}),[e.id,h,b.defaultValue,w.id,N]),j=z=>{y(L=>{const V=z(L.control);L.control.source.kind==="manual"&&V.source.kind==="sql_query"&&(C.current=L.defaultValue);const A=L.defaultValue===void 0&&L.control.source.kind==="sql_query"&&V.source.kind==="manual"?C.current:L.defaultValue,B=m.getNextEditedControlDefaultValue({previousControl:L.control,nextControl:V,currentDefaultValue:A});return V.source.kind==="manual"&&(C.current=B),{...L,control:V,defaultValue:B}})},k=z=>{if(!z.trim())return;const L=m.normalizeDashboardInputVariableName(z);L!==e.id&&(n.includes(L)||t.some(V=>V.id===L&&V.id!==e.id))||y(V=>V.control.id===L?V:{...V,control:{...V.control,id:L}})},_=()=>{C.current=p,y(x()),a(!1)},T=()=>{if(!o){_();return}const z=w.initialValueStrategy==="saved_default"?b.defaultValue:void 0,L=m.syncSqlQueryControlExecutionRequirement({...w,defaultValue:z});o(wxt(L)),a(!1)},I=z=>{if(z){C.current=p,y(x()),a(!0);return}_()},D=()=>{s==null||s(),u(!1),a(!1)},E=w.label||"Control",R=m.getFriendlyTypeOption(w.type).label,F=l.jsx("button",{type:"button",className:"rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Control settings",onClick:z=>z.stopPropagation(),children:l.jsx(uf,{className:"h-3 w-3"})}),M=l.jsx(Ope,{control:w,defaultValue:b.defaultValue,defaultPlacement:f,placementOptions:d,previewControlDefinitions:N,previewControlValues:S,allowControlIdEdit:!0,showPlacementSelect:!1,showViewerVisibilityToggle:!1,activeFiltersOverride:r,onChangeControl:j,onChangeDefaultValue:z=>{w.source.kind==="manual"&&(C.current=z),y(L=>({...L,defaultValue:z}))},onCommitControlId:k}),O=l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",className:"text-destructive hover:border-destructive/40 hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",onClick:()=>u(!0),children:"Delete"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(m.Button,{type:"button",variant:"outline",size:"xs",onClick:_,children:"Cancel"}),l.jsx(m.Button,{type:"button",size:"xs",onClick:T,children:"Accept"})]})]});return l.jsx(Lpe,{open:i,onOpenChange:I,trigger:F,title:E,subtitle:R,description:"Update how this control appears and behaves in the document toolbar.",body:M,footer:O,onClose:_,deleteDialogOpen:c,onDeleteDialogOpenChange:u,deleteDescription:`Delete "${e.label}" from this document sheet?`,onConfirmDelete:D})}function wxt(e){const t={...e};return delete t.placement,delete t.hidden,t}function Cxt(e){const t={};for(const n of e)n.defaultValue!==void 0&&(t[n.id]=n.defaultValue);return t}function Hpe({className:e,sheetId:t,inputs:n,dashboardInputsById:r,filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,onSetFilterValue:c,onSetFilterMode:u,onUpdateFilterInput:d,onUpdateControlInput:f,onRemoveFilterValue:h,onRemoveInput:p,onReorderInputs:g,controlValuesByInputId:x,onSetControlValue:b,actions:y,isEditing:C=!1}){const w=v.useMemo(()=>n.filter(oc).map(E=>E.control),[n]),N=m.useDashboardStore(E=>{var R;return((R=E.dashboard.filterLayout)==null?void 0:R.toolbarWrap)??!1}),S=C&&!!g,j=v.useMemo(()=>n.map(E=>E.id),[n]),k=bC(Em(cp,{activationConstraint:{distance:5}}));function _(E){const{active:R,over:F}=E;if(!F)return;const M=yxt(j,String(R.id),String(F.id));M&&(g==null||g(M))}const T=l.jsx("span",{className:"block shrink-0 text-[12px] text-muted-foreground",children:"None yet"}),I=n.map(E=>l.jsx(Sxt,{inputId:E.id,canReorder:S,children:R=>l.jsx(Nxt,{input:E,sheetId:t,dragHandle:R,dashboardInput:r.get(E.id),filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,documentControlDefinitions:w,onSetFilterValue:c,onSetFilterMode:u,onUpdateFilterInput:d,onUpdateControlInput:f,onRemoveFilterValue:h,onRemoveInput:p,reservedVariableNames:n.filter(F=>F.id!==E.id).map(F=>F.variableName),controlValuesByInputId:x,onSetControlValue:b,isEditing:C})},E.id)),D=N?l.jsxs(cO,{wrap:!0,className:"w-full gap-3 pr-0",children:[I.length>0?I:l.jsx(zk,{children:T}),y?l.jsx(zk,{children:y}):null]}):l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"min-w-0 overflow-x-auto overflow-y-hidden",children:l.jsx(cO,{empty:T,children:I})}),y?l.jsx("div",{className:"shrink-0 justify-self-end",children:y}):null]});return l.jsx("div",{className:m.cn("sticky top-0 z-30 shrink-0 gap-3 border-b bg-background/95 px-3 py-1.5 shadow-[0_1px_0_rgba(0,0,0,0.04)] backdrop-blur supports-[backdrop-filter]:bg-background/90",N?"flex min-h-10 items-start overflow-visible":"grid h-10 grid-cols-[minmax(0,1fr)_auto] items-center overflow-hidden",e),children:S?l.jsx(Sb,{sensors:k,collisionDetection:wb,onDragEnd:_,children:l.jsx(Nb,{items:j,strategy:FT,children:D})}):D})}function Sxt({inputId:e,canReorder:t,children:n}){const{attributes:r,listeners:o,setNodeRef:s,transform:i,transition:a,isDragging:c}=dp({id:e,disabled:!t});return t?l.jsx(zk,{ref:s,style:{transform:Pi.Translate.toString(i),transition:a,opacity:c?.5:1,zIndex:c?10:void 0},children:n({listeners:o,attributes:r})}):l.jsx(zk,{children:n(void 0)})}function Nxt({input:e,sheetId:t,dragHandle:n,dashboardInput:r,filterValuesByInputId:o,filterModesByInputId:s,documentFilterValues:i,documentControlValues:a,documentControlDefinitions:c,onSetFilterValue:u,onSetFilterMode:d,onUpdateFilterInput:f,onUpdateControlInput:h,onRemoveFilterValue:p,onRemoveInput:g,reservedVariableNames:x,controlValuesByInputId:b,onSetControlValue:y,isEditing:C}){if(e.kind==="control"){const D=Object.prototype.hasOwnProperty.call(b,e.id)?b[e.id]:a[e.control.id];return l.jsx(Vpe,{control:e.control,value:D,isEditing:C,dragListeners:C?n==null?void 0:n.listeners:void 0,dragAttributes:C?n==null?void 0:n.attributes:void 0,onChange:E=>y(e.id,E),onUpdateControl:E=>h==null?void 0:h(e.id,E),controlDefinitionsOverride:c,controlValuesOverride:a,activeFiltersOverride:i,actions:C?l.jsx(vxt,{control:e.control,controls:c,reservedVariableNames:x,activeFiltersOverride:i,onUpdateControl:E=>h==null?void 0:h(e.id,E),onRemoveControl:()=>g==null?void 0:g(e.id)}):null})}const w=e,N=Sx(w,o[w.id]),S=N?[N]:[],j=s[w.id]||Cpe(w.filter.operation),k=VT(w.filter.operation)?{...w.filter,operation:lO(j)}:w.filter,_=(r==null?void 0:r.kind)==="filter"?r:void 0;function T(D,E){const R={...w.filter,...D,operation:w.filter.operation};return f==null?void 0:f(w.id,R,E)}const I=_?{storageTarget:"dashboardInput",dashboardInput:_,sheetId:t,sheetKind:"document"}:{storageTarget:"card",sheetId:t,sheetKind:"document",inlineFilterValues:S,setInlineFilterValue:D=>u(w.id,D),removeInlineFilterValue:()=>p(w.id),setInlineFilterMode:(D,E)=>d(w.id,E),inputContext:Xle({filter:k,scope:{sheetId:t,sheetKind:"document"},values:i,controls:{definitions:c,values:a}})};return l.jsx(mz,{filter:k,isEditing:C,dragListeners:C?n==null?void 0:n.listeners:void 0,dragAttributes:C?n==null?void 0:n.attributes:void 0,settingsVariant:"document",inputVariableName:w.variableName,reservedInputVariableNames:x,onUpdateFilter:T,onRemoveFilter:()=>g==null?void 0:g(w.id),storageOptions:I})}function Bk(e,t,n){const r=new Set(t),o=[...n];return e.map(s=>r.has(s.id)?o.shift()??s.id:s.id)}function jxt({sections:e,inputs:t,selectedSectionId:n,onSelectSection:r,onDeleteSection:o,onReorderSection:s,onInsertSection:i}){const[a,c]=v.useState(null),[u,d]=v.useState(!1);return l.jsxs("aside",{"data-testid":"document-outline",className:"flex w-56 shrink-0 flex-col border-r bg-background",children:[l.jsxs("div",{className:"flex h-10 items-center justify-between border-b px-3",children:[l.jsxs("div",{className:"flex items-baseline gap-1.5",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Sections"}),l.jsxs("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground",children:["· ",e.length]})]}),i?l.jsxs(m.Popover,{open:u,onOpenChange:d,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Add section",className:"inline-flex h-6 items-center gap-1 rounded-[4px] px-1.5 text-[11px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[l.jsx(Ar,{className:"h-3 w-3"}),"Add"]})}),l.jsx(m.PopoverContent,{align:"end",side:"bottom",sideOffset:6,className:"w-48 p-1",children:ppe.map(f=>{const h=F0(f);return l.jsxs("button",{type:"button",onClick:()=>{i(f),d(!1)},className:"flex w-full items-center gap-2 rounded-[4px] px-2 py-1.5 text-left text-[12px] text-foreground transition-colors hover:bg-muted",children:[l.jsx(h,{className:"h-3.5 w-3.5 text-muted-foreground"}),wC[f]]},f)})})]}):null]}),l.jsx("div",{className:"flex-1 overflow-y-auto py-1",children:e.length===0?l.jsx("p",{className:"px-3 py-3 text-[12px] text-muted-foreground",children:"No sections yet"}):e.map(f=>{const h=F0(f.type),p=f.id===n,g=agt(f,t),x=lgt(f);return l.jsxs("div",{"data-testid":`document-outline-section-${f.id}`,"data-selected":p?"true":void 0,draggable:!0,onDragStart:b=>{c(f.id),b.dataTransfer.effectAllowed="move",b.dataTransfer.setData("application/x-semaphor-document-section",f.id)},onDragOver:b=>{!a||a===f.id||(b.preventDefault(),b.dataTransfer.dropEffect="move")},onDrop:b=>{b.preventDefault();const y=b.dataTransfer.getData("application/x-semaphor-document-section")||a;if(y&&y!==f.id){const C=b.currentTarget.getBoundingClientRect(),w=b.clientY<C.top+C.height/2?"before":"after";s(y,f.id,w)}c(null)},onDragEnd:()=>c(null),className:m.cn("group mx-1 flex w-[calc(100%-8px)] items-start rounded transition-colors",p?"bg-muted":"hover:bg-muted/70",a===f.id&&"opacity-40"),children:[l.jsxs("button",{type:"button",onClick:()=>r(f.id),className:"flex min-w-0 flex-1 items-start gap-2 rounded-l px-2 py-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[l.jsx(Iu,{className:"mt-0.5 h-3 w-3 shrink-0 cursor-grab text-muted-foreground/50"}),l.jsx(h,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("div",{className:m.cn("truncate text-[13px] leading-tight",p?"font-medium text-foreground":"text-foreground/90"),children:g}),x?l.jsx("div",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:x}):null]})]}),l.jsx("div",{className:"flex shrink-0 items-center pr-1 pt-2 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 group-data-[selected=true]:opacity-100",children:l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 text-muted-foreground hover:text-destructive","aria-label":`Delete ${g}`,onClick:b=>{b.stopPropagation(),o(f.id)},children:l.jsx(Re.X,{className:"h-3 w-3"})})})]},f.id)})})]})}const $2=[];function kxt({card:e,queryOptions:t,surfaceMode:n,previewRowLimit:r,onPreviewRowLimitChange:o}){const{authToken:s,tokenProps:i}=Mt(),a=m.useDashboardStore(re=>re.authToken),u=Zg(e)?n==="print"?"export-full-with-cap":"preview-window":void 0,d=u?u==="preview-window"&&r||WC(u):void 0,f=v.useMemo(()=>{if(u!=="preview-window")return"";const{paginationConfig:re,...te}=e;return JSON.stringify({card:te,queryOptions:t,surfaceMode:n})},[e,u,t,n]),h=v.useRef(null),p=v.useMemo(()=>u&&d?{...e,paginationConfig:{page:1,pageSize:d}}:e,[e,d,u]),g=v.useMemo(()=>({...t,...u?{documentTableDataPolicy:u}:{}}),[u,t]),x=yu(p,g),b=!!u&&x.isFetching&&(x.isPlaceholderData||x.dataUpdatedAt===0),y=b?void 0:x.data,C=v.useMemo(()=>Array.isArray(y==null?void 0:y.records)?y.records:$2,[y==null?void 0:y.records]),w=h.current,N=u==="preview-window"&&x.isFetching&&!x.error&&!y&&(w==null?void 0:w.identity)===f,S=N?w.records:C,j=N?w.data:y,k=N?w.pagination:b?void 0:x.pagination,_=N?w.comparisonMetadata:b?void 0:x.comparisonMetadata,T=N?w.queryRequestPayload:b?void 0:x.queryRequestPayload,I=N?w.dataUpdatedAt:x.dataUpdatedAt;v.useEffect(()=>{u!=="preview-window"||b||C.length===0||!y||(h.current={identity:f,data:y,pagination:x.pagination,comparisonMetadata:x.comparisonMetadata,queryRequestPayload:x.queryRequestPayload,records:C,dataUpdatedAt:x.dataUpdatedAt})},[x.comparisonMetadata,x.data,x.dataUpdatedAt,x.pagination,x.queryRequestPayload,y,b,u,f,C]);const D=typeof(k==null?void 0:k.totalCount)=="number"?k.totalCount:void 0,E=!u||typeof(k==null?void 0:k.totalCount)=="number",R=u==="export-full-with-cap"&&D!==void 0&&D>LD,F=v.useMemo(()=>JSON.stringify(x.queryKey),[x.queryKey]),M=u&&d&&D!==void 0&&!R&&u==="export-full-with-cap"?Math.max(1,Math.ceil(D/d)):1,O=u&&d&&E&&M>1?Array.from({length:M-1},(re,te)=>te+2):[],z=T,L=(s==null?void 0:s.accessToken)||(a==null?void 0:a.accessToken)||"",V=cf({queries:O.map(re=>({queryKey:["documentTableRows",F,I,re,d,i.apiServiceUrl],enabled:!!(u&&d&&z&&L&&E&&!R),queryFn:async()=>{const te={...z||{},pagination:{page:re,pageSize:d}};return delete te.tableTotalsRequest,m.postRequest(`${i.apiServiceUrl}/v1/query`,L,te)}}))}),A=V.map(re=>{var Q;const te=Array.isArray((Q=re.data)==null?void 0:Q.records)?re.data.records.length:0;return`${re.dataUpdatedAt}:${te}`}).join("|"),B=v.useMemo(()=>V.length===0?$2:V.flatMap(re=>{var te;return Array.isArray((te=re.data)==null?void 0:te.records)?re.data.records:$2}),[V.length,A]),$=v.useMemo(()=>u?B.length===0?S:[...S,...B]:S,[B,S,u]),P=V.map(re=>{var te,Q;return re.error?{error:m.getRequestErrorMessage(re.error,"Query failed",{preserveSyntheticMessage:!0}),sql:m.getRequestErrorSql(re.error)||""}:(te=re.data)!=null&&te.error?{error:m.getRequestErrorMessage(re.data,"Query failed"),sql:m.getRequestErrorSql(re.data)||(typeof((Q=re.data)==null?void 0:Q.errorSql)=="string"?re.data.errorSql:"")}:void 0}).find(Boolean),U=b&&!N?"":x.errorMessage,H=u&&T&&!x.isLoading&&!x.isPending&&!U&&!E?"Document table queries require backend pagination metadata.":"",G=R&&D!==void 0?`This table has ${D.toLocaleString()} rows. Paginated report export currently supports up to ${LD.toLocaleString()} rows. Add filters or reduce the result set before exporting.`:"",q=U||(P==null?void 0:P.error)||H||G,Y=x.errorSql||(P==null?void 0:P.sql)||"",W=[u??"single-query",I,A,$.length,D??"unknown",q].join(":"),ne=V.some(re=>re.isFetching),Z=V.some(re=>re.isLoading||re.isPending),K=u==="export-full-with-cap"&&!q&&M>1&&B.length+S.length<Math.min(D??0,LD),X=u==="preview-window"&&D!==void 0&&$.length<D,J=v.useCallback(()=>{u!=="preview-window"||!o||!d||o(Math.min(d+WC("preview-window"),D??d+WC("preview-window")))},[o,d,u,D]);return{data:j&&{...j,records:$},records:$,pagination:k,comparisonMetadata:_,queryRequestPayload:T,errorMessage:q,errorSql:Y,isLoading:!N&&x.isLoading||Z||K,isPending:!N&&x.isPending||Z||K,isFetching:x.isFetching||ne,isPreviewWindowIncomplete:X,loadedRowCount:$.length,totalRowCount:D,rowDataVersion:W,loadMorePreviewRows:X&&o?J:void 0}}function Ixt(e){return ww(e)}function _xt(e){var o,s,i,a;if(!Ixt(e)||!XI(e))return[];const t=(s=(o=e.preferences)==null?void 0:o.tablePrefs)==null?void 0:s.columnSettingsMap,n=(a=(i=e.preferences)==null?void 0:i.tablePrefs)==null?void 0:a.columnVisibility;let r=!1;return hL(e).flatMap(c=>oTe(c,n)?c.role!=="metric"&&!r?(r=!0,[XV(c,t)]):c.role==="metric"?[XV(c,t)]:[]:[])}function qpe(e){return sTe(e)}function Txt(e){return Sw(e)}function Dxt(e){return!!(e!=null&&e.columns.some(t=>t.behavior!=="label"))}function Ext(e){return iTe(e)}const Mxt={mode:"table-print"},Rxt={suppressSortControls:!0,renderPlainWrapper:!0,disableDashboardInteractions:!0};function Axt(e){return e.interactionConfig?{...e,interactionConfig:void 0}:e}function Fxt(e){return Array.from(e.querySelectorAll("tbody tr, tfoot tr"))}function Pxt({sectionElement:e,tableSurfaceElement:t,firstRowElement:n,lastRowElement:r,measurementScale:o}){const s=Number.isFinite(o)&&o>0?o:1,i=e.getBoundingClientRect(),a=t==null?void 0:t.getBoundingClientRect(),c=n.getBoundingClientRect(),u=r.getBoundingClientRect(),d=r.closest("table"),f=d?d.getBoundingClientRect().bottom:u.bottom,h=Math.max(0,(c.top-i.top)/s),p=Math.max(0,(Math.max(f,u.bottom)-u.bottom)/s),g=t?Oxt({sectionRect:i,tableSurfaceElement:t,tableSurfaceRect:a,measurementScale:s}):void 0;return{chromeHeightPx:Math.ceil(h+p),trailingChromePx:Math.ceil(p),...g!==void 0?{renderedMinHeightPx:g}:{}}}function Oxt({sectionRect:e,tableSurfaceElement:t,tableSurfaceRect:n,measurementScale:r}){const o=window.getComputedStyle(t),s=Number.parseFloat(o.minHeight||"0")||0;if(s<=0||!n)return;const i=Math.max(0,(n.top-e.top)/r);return Math.ceil(i+s)}function JW(e){return e==null?void 0:e.closest('[data-testid="document-page"]')}function Upe(e){return e==null?void 0:e.querySelector('[data-document-region="footer"]')}function Lxt(e){const t=Number.parseFloat(e.style.height||"")||Number.parseFloat(e.style.minHeight||"");if(t>0)return t;const n=window.getComputedStyle(e),r=Number.parseFloat(n.height||"")||Number.parseFloat(n.minHeight||"");return r>0?r:e.clientHeight}function $xt(e,t){return e?Math.abs(e.rowHeightPx-t.rowHeightPx)>1||Math.abs((e.averageRowHeightPx??e.rowHeightPx)-(t.averageRowHeightPx??t.rowHeightPx))>1||zxt(e.rowHeightsPx,t.rowHeightsPx)||Math.abs(e.chromeHeightPx-t.chromeHeightPx)>1||Math.abs((e.renderedMinHeightPx??0)-(t.renderedMinHeightPx??0))>1||e.rowsPerPage!==t.rowsPerPage:!0}function zxt(e,t){return!e&&!t?!1:!e||!t||e.length!==t.length?!0:e.some((n,r)=>{const o=t[r];return n===void 0||o===void 0?n!==o:Math.abs(n-o)>1})}const eG=40,HT=18,Bxt=120;function fu({section:e,totalRowCount:t=0,layoutMeasurement:n}){var g;const r=qxt(e),o=r!=="unsupported",s=!!(e.card.connectionId||(g=e.card.dataSource)!=null&&g.connectionId),i=Uxt(e,r),a=r==="table"?Kxt(e):[],c=a.length>0?1:0,u=Math.max(0,t),d=Vxt(e),f=n==null?void 0:n.rowHeightPx,h=n==null?void 0:n.averageRowHeightPx,p=n==null?void 0:n.rowHeightsPx;return{sectionId:e.id,kind:r,isSupported:o,hasConnection:s,hasRunnableQuery:i,isRunnable:o&&s&&i,totalRowCount:u,bodyRowCount:Math.max(0,u-c),trailingRowCount:c,visibleTotalsColumnIds:a,fallbackRowHeightPx:d,measuredRowHeightPx:f,measuredAverageRowHeightPx:h,measuredRowHeightsPx:p,effectiveRowHeightPx:Kpe({fallbackRowHeightPx:d,measuredRowHeightPx:f,measuredRowHeightsPx:p,totalRowCount:u}),chromeHeightPx:n==null?void 0:n.chromeHeightPx,renderedMinHeightPx:n==null?void 0:n.renderedMinHeightPx,measuredRowsPerPage:n==null?void 0:n.rowsPerPage,renderContract:Rxt}}function Vxt(e){return Math.max(eG,e.table.rowHeightPx??eG)}function Kpe({fallbackRowHeightPx:e,measuredRowHeightPx:t,measuredRowHeightsPx:n,totalRowCount:r}){return n&&r!==void 0&&!Hxt(n,r)?e:t!==void 0?Math.max(HT,t):e}function Hxt(e,t){if(e.length<t)return!1;for(let n=0;n<t;n+=1)if(e[n]===void 0)return!1;return!0}function qxt(e){return e.card.type==="table"||e.card.type==="pivotTable"?e.card.type:"unsupported"}function Uxt(e,t){var n;return t==="unsupported"?!1:t==="pivotTable"?lt.hasValidCardConfig(e.card.config):!!((n=e.card.sql)!=null&&n.trim()||lt.hasValidCardConfig(e.card.config))}function Kxt(e){return e.table.totalsRow?_xt(qpe(e.card)):[]}function qT({totalRowCount:e,fallbackRowHeightPx:t,layoutMeasurement:n}){const r=Math.max(0,e),o=Math.max(HT,t),s=n==null?void 0:n.rowHeightsPx;if(!s||s.length===0){if((n==null?void 0:n.rowHeightPx)!==void 0){const d=Vk(n.rowHeightPx)??o;return{kind:"uniform",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:d,measuredAverageRowHeightPx:n.averageRowHeightPx}}return{kind:"unmeasured",totalRowCount:r,fallbackRowHeightPx:o}}const i=Array.from({length:r},(d,f)=>Vk(s[f])),a=i.filter(d=>d!==void 0);if(a.length===0)return{kind:"unmeasured",totalRowCount:r,fallbackRowHeightPx:o};const c=Math.max(...a),u=n.averageRowHeightPx??Math.ceil(a.reduce((d,f)=>d+f,0)/a.length);return Qxt(i)?{kind:"complete",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:c,measuredAverageRowHeightPx:u,rowHeightsPx:i}:{kind:"sparse",totalRowCount:r,fallbackRowHeightPx:o,measuredRowHeightPx:c,measuredAverageRowHeightPx:u,rowHeightsPx:i}}function Wxt(e,t){const{rowHeightsPx:n,rowRangeStartIndex:r,rowRangeEndIndex:o,totalRowCount:s}=t;if(!n||r===void 0||o===void 0||s===void 0)return B2(e,z2(t));const i=Math.max(0,s),a=Math.min(Math.max(0,r),i),c=Math.min(Math.max(a,o),i),u=c-a,d=z2({...t,rowRangeStartIndex:a,rowRangeEndIndex:c,totalRowCount:i});if(u===i||u!==n.length)return B2(e,d);const f=(e==null?void 0:e.totalRowCount)===i||(e==null?void 0:e.totalRowCount)===void 0,h=Array.from({length:i},(p,g)=>{var x;return f?(x=e==null?void 0:e.rowHeightsPx)==null?void 0:x[g]:void 0});return n.forEach((p,g)=>{h[a+g]=Vk(p)}),B2(e,z2({...d,rowHeightsPx:h}))}function Wpe(e,t){return e.kind!=="unmeasured"&&e.kind!=="uniform"&&e.rowHeightsPx[t]!==void 0?e.rowHeightsPx[t]:e.kind==="uniform"?e.measuredRowHeightPx:e.fallbackRowHeightPx}function K4({rowMeasurementState:e,startIndex:t,endIndex:n}){let r=0;const o=Math.max(0,t),s=Math.min(Math.max(o,n),e.totalRowCount);for(let i=o;i<s;i+=1)r+=Wpe(e,i);return r}function Gxt({rowMeasurementState:e,startIndex:t,endIndex:n,chromeHeightPx:r,renderedMinHeightPx:o}){const s=K4({rowMeasurementState:e,startIndex:t,endIndex:n});return Math.max(r+s,Ype(o)??0)}function Yxt({rowMeasurementState:e,startIndex:t,endIndex:n,chromeHeightPx:r}){return r+K4({rowMeasurementState:e,startIndex:t,endIndex:n})}function Gpe({rowMeasurementState:e,startIndex:t,availableHeightPx:n}){if(!Number.isFinite(n)||n<=0)return 0;let r=0,o=Math.max(0,t);for(;o<e.totalRowCount;){const s=Wpe(e,o);if(s<=0||r+s>n)break;r+=s,o+=1}return o-Math.max(0,t)}function Zxt(e){return e.kind==="complete"||e.kind==="uniform"?e.measuredRowHeightPx:e.fallbackRowHeightPx}function Xxt({tableSlice:e}){return!e||e.pageIndex===0}function z2(e){var s;const t=(s=e.rowHeightsPx)==null?void 0:s.map(i=>Vk(i)),n=(t??[]).filter(i=>i!==void 0),r=n.length>0?Math.max(...n):Math.max(HT,e.rowHeightPx),o=n.length>0?Math.ceil(n.reduce((i,a)=>i+a,0)/n.length):e.averageRowHeightPx;return{...e,rowHeightPx:r,averageRowHeightPx:o,rowHeightsPx:t,renderedMinHeightPx:Ype(e.renderedMinHeightPx),canUpdateLayoutChrome:e.canUpdateLayoutChrome}}function B2(e,t){return!e||t.canUpdateLayoutChrome===void 0||t.canUpdateLayoutChrome?t:{...t,chromeHeightPx:e.chromeHeightPx,renderedMinHeightPx:e.renderedMinHeightPx,rowsPerPage:e.rowsPerPage}}function Ype(e){if(!(e===void 0||!Number.isFinite(e)||e<=0))return Math.ceil(e)}function Vk(e){if(!(e===void 0||!Number.isFinite(e)||e<=0))return Math.max(HT,Math.ceil(e))}function Qxt(e){return e.every(t=>t!==void 0)}const Jxt={colorScheme:"light","--semaphor-background":"0 0% 100%","--semaphor-foreground":"240 5.9% 10%","--semaphor-card":"0 0% 100%","--semaphor-card-foreground":"240 5.9% 10%","--semaphor-muted":"0 0% 98%","--semaphor-muted-foreground":"240 3.8% 46.1%","--semaphor-accent":"240 4.8% 95.9%","--semaphor-accent-foreground":"240 5.9% 10%","--semaphor-border":"240 5.9% 90%","--background":"0 0% 100%","--foreground":"240 5.9% 10%","--muted":"0 0% 98%","--muted-foreground":"240 3.8% 46.1%","--border":"240 5.9% 90%"},ebt=[],tbt={spacious:"[&_tbody_td]:!py-3 [&_tfoot_td]:!py-3 [&_tbody_td>div]:!leading-6",comfortable:"[&_tbody_td]:!py-2 [&_tfoot_td]:!py-2 [&_tbody_td>div]:!leading-5",standard:"[&_tbody_td]:!py-1.5 [&_tfoot_td]:!py-1.5 [&_tbody_td>div]:!leading-5",compact:"[&_tbody_td]:!py-1 [&_tfoot_td]:!py-1 [&_tbody_td>div]:!leading-5",dense:"[&_tbody_td]:!py-1 [&_tfoot_td]:!py-1 [&_tbody_td]:!text-[11px] [&_tfoot_td]:!text-[11px] [&_tbody_td>div]:!leading-4"};function nbt(e){const t=["full","outer"].includes(e.gridLines),n=t||e.gridLines==="top",r=t||e.gridLines==="right",o=t||e.gridLines==="bottom",s=t||e.gridLines==="left",i=["full","inner","horizontal"].includes(e.gridLines),a=["full","inner","vertical"].includes(e.gridLines);return m.cn("relative min-h-[var(--document-table-min-surface-height)] overflow-hidden rounded-none bg-white text-zinc-950",n?"border-t border-t-zinc-200":"border-t-0",r?"border-r border-r-zinc-200":"border-r-0",o?"border-b border-b-zinc-200":"border-b-0",s?"border-l border-l-zinc-200":"border-l-0","[&_.data-table-scroll-container]:!rounded-none [&_.data-table-scroll-container]:!border-0 [&_.data-table-scroll-container]:!bg-white","[&_table]:!bg-white","[&_tbody_td>div]:!text-[var(--document-table-cell-color)] [&_tbody_td]:!text-[var(--document-table-cell-color)]","[&_tbody_tr:hover]:!bg-white [&_tbody_tr]:h-[var(--document-table-row-height)] [&_tbody_tr]:!bg-white","[&_tfoot_td]:!bg-[var(--document-table-totals-bg)] [&_tfoot_td]:!text-[var(--document-table-totals-color)] [&_tfoot_td]:!font-[var(--document-table-totals-font-weight)]","[&_thead]:!bg-[var(--document-table-header-bg)] [&_thead_tr]:!bg-[var(--document-table-header-bg)]","[&_th]:!bg-[var(--document-table-header-bg)] [&_th]:!text-[var(--document-table-header-color)]",tbt[e.density],e.stripedRows&&"[&_tbody_tr:nth-child(even)]:!bg-zinc-50 [&_tbody_tr:nth-child(even):hover]:!bg-zinc-50","[&_table]:!border-0",i?"[&_tbody_tr]:!border-zinc-200 [&_th]:!border-b [&_th]:!border-zinc-200":"[&_tbody_tr]:!border-transparent [&_th]:!border-b-0",e.totalsStyle.borderTop?["[&_tfoot_td]:![border-top-color:var(--document-table-totals-border-color)]","[&_tfoot_td]:!border-[var(--document-table-totals-border-color)]",e.totalsStyle.borderTopStyle==="double"?"[&_tfoot_td]:!border-t-[3px] [&_tfoot_td]:!border-double":"[&_tfoot_td]:!border-t",e.totalsStyle.borderTopStyle==="dashed"&&"[&_tfoot_td]:!border-dashed",e.totalsStyle.borderTopStyle==="dotted"&&"[&_tfoot_td]:!border-dotted",e.totalsStyle.borderTopStyle==="solid"&&"[&_tfoot_td]:!border-solid"]:"[&_tfoot_td]:!border-t-0",a?"[&_td]:!border-r [&_td]:!border-zinc-200 [&_td:last-child]:!border-r-0 [&_th]:!border-r [&_th]:!border-zinc-200 [&_th:last-child]:!border-r-0 [&_tfoot_td]:!border-r [&_tfoot_td]:!border-zinc-200 [&_tfoot_td:last-child]:!border-r-0":"[&_td]:!border-r-0 [&_th]:!border-r-0 [&_tfoot_td]:!border-r-0")}function rbt({section:e,documentFilterValues:t=[],documentControlDefinitions:n=[],documentControlValues:r={},documentDashboardInputValues:o,missingRequiredInputLabels:s=[],isEditing:i=!0,surfaceMode:a="preview",tableSlice:c,initialRowsPerPageLimit:u,previewRowLimit:d,showInlineEditAction:f=!0,onEditTableSection:h,onTableRowCountChange:p,onTableResultColumnsChange:g,onTableLayoutMeasure:x,onTableLayoutInvalidate:b,onUpdateTableSection:y,onPreviewRowLimitChange:C,measurementScale:w=1}){const N=fu({section:e});return N.isRunnable?s.length>0?l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Required inputs missing",message:`Set ${s.join(", ")} to run this table.`,exportState:"blocked",isEditing:i,showInlineEditAction:f,onEditTableSection:h}):l.jsx(xT,{displayPreferences:Mxt,children:l.jsx(ui,{fallbackRender:({error:S})=>l.jsx("div",{...wx(S),children:l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table unavailable",message:"The table result could not be validated. Refresh or reconfigure the table.",exportState:"error",isEditing:i,showInlineEditAction:f,onEditTableSection:h})}),children:l.jsx(abt,{section:e,documentFilterValues:t,documentControlDefinitions:n,documentControlValues:r,documentDashboardInputValues:o,isEditing:i,surfaceMode:a,tableSlice:c,initialRowsPerPageLimit:u,previewRowLimit:d,showInlineEditAction:f,onEditTableSection:h,onTableRowCountChange:p,onTableResultColumnsChange:g,onTableLayoutMeasure:x,onTableLayoutInvalidate:b,onUpdateTableSection:y,onPreviewRowLimitChange:C,measurementScale:w})})}):l.jsx(hbt,{section:e,isEditing:i,reason:N.isSupported?void 0:"Unsupported table type",showInlineEditAction:f,onEditTableSection:h})}const Zpe=v.memo(rbt,obt);Zpe.displayName="DocumentTableSectionRenderer";function obt(e,t){return e.section===t.section&&e.documentFilterValues===t.documentFilterValues&&e.documentControlDefinitions===t.documentControlDefinitions&&e.documentControlValues===t.documentControlValues&&e.documentDashboardInputValues===t.documentDashboardInputValues&&sbt(e.missingRequiredInputLabels,t.missingRequiredInputLabels)&&e.isEditing===t.isEditing&&e.surfaceMode===t.surfaceMode&&e.initialRowsPerPageLimit===t.initialRowsPerPageLimit&&e.previewRowLimit===t.previewRowLimit&&e.showInlineEditAction===t.showInlineEditAction&&e.measurementScale===t.measurementScale&&ibt(e.tableSlice,t.tableSlice)&&e.onEditTableSection===t.onEditTableSection&&e.onTableRowCountChange===t.onTableRowCountChange&&e.onTableResultColumnsChange===t.onTableResultColumnsChange&&e.onTableLayoutMeasure===t.onTableLayoutMeasure&&e.onTableLayoutInvalidate===t.onTableLayoutInvalidate&&e.onUpdateTableSection===t.onUpdateTableSection&&e.onPreviewRowLimitChange===t.onPreviewRowLimitChange}function sbt(e,t){if(e===t)return!0;const n=e||[],r=t||[];return n.length===r.length&&n.every((o,s)=>o===r[s])}function ibt(e,t){return e===t?!0:!e||!t?!1:e.startIndex===t.startIndex&&e.endIndex===t.endIndex&&e.pageIndex===t.pageIndex&&e.pageCount===t.pageCount&&e.totalRows===t.totalRows&&e.rowsPerPage===t.rowsPerPage}function abt({section:e,documentFilterValues:t=[],documentControlDefinitions:n=[],documentControlValues:r={},documentDashboardInputValues:o,isEditing:s=!0,surfaceMode:i="preview",tableSlice:a,initialRowsPerPageLimit:c,previewRowLimit:u,showInlineEditAction:d=!0,onEditTableSection:f,onTableRowCountChange:h,onTableResultColumnsChange:p,onTableLayoutMeasure:g,onTableLayoutInvalidate:x,onUpdateTableSection:b,onPreviewRowLimitChange:y,measurementScale:C=1}){var pe,xe,Ie,be,ge,ee,ce,ae;const w=v.useMemo(()=>e.card.type==="table"&&e.table.totalsRow?qpe(e.card):e.card,[e.card,e.table.totalsRow]),N=v.useMemo(()=>Axt(w),[w]),S=v.useMemo(()=>H4(e),[e]),j=v.useMemo(()=>e.card.type==="table"&&e.table.totalsRow?Txt(w):void 0,[w,e.card.type,e.table.totalsRow]),k=Dxt(j),_=v.useMemo(()=>{const me=t.length>0,ve=n.length>0||Object.keys(r).length>0;return{runtimeContext:"documentSection",documentSectionId:e.id,...j?{tableTotalsRequest:j}:{},...me?{documentFilterValues:t}:{},...ve?{documentControlDefinitions:n,documentControlValues:r}:{},...o?{documentDashboardInputValues:o}:{}}},[t,n,r,o,e.id,j]),T=kxt({card:w,queryOptions:_,surfaceMode:i,previewRowLimit:u,onPreviewRowLimitChange:y}),I=T.records||ebt,D=v.useMemo(()=>hgt(I),[I]),E=v.useMemo(()=>gpe(e),[e]),R=w.type==="table"?fu({section:e}).trailingRowCount:0,F=v.useMemo(()=>fu({section:e,totalRowCount:w.type==="table"?I.length+R:0}),[w.type,R,I.length,e]),M=w.type==="table"&&I.length>0&&F.trailingRowCount>0,O=T.errorMessage?0:F.totalRowCount,z=M&&(a?a.endIndex>I.length:!c||F.totalRowCount<=c),L=M&&z,V=v.useMemo(()=>w.type==="table"&&!L?Ext(N):N,[w.type,N,L]),A=v.useCallback(me=>{b==null||b(e.id,ve=>{var Ue;const _e=(Ue=ve.card.preferences)==null?void 0:Ue.tablePrefs,De=typeof me=="function"?me((_e==null?void 0:_e.columnSizing)||{}):me;return{...ve,card:{...ve.card,preferences:{...ve.card.preferences,tablePrefs:{..._e,columnSizing:De}}}}})},[b,e.id]);let B=I;w.type==="table"&&a?B=I.slice(Math.min(a.startIndex,I.length),Math.min(a.endIndex,I.length)):w.type==="table"&&c&&(B=I.slice(0,c));const $=(T.isLoading||T.isPending||T.isFetching)&&I.length===0,P=i!=="print"&&T.isFetching&&I.length>0,U=i==="print"&&T.isLoading&&I.length>0;v.useEffect(()=>{w.type==="table"&&(h==null||h(e.id,O))},[w.type,h,e.id,O]),v.useEffect(()=>{var me;w.type==="table"&&(p==null||p(e.id,D,E,(me=T.data)==null?void 0:me.columnKeyMap))},[w.type,p,E,D,(pe=T.data)==null?void 0:pe.columnKeyMap,e.id]);const H=v.useMemo(()=>w.type!=="pivotTable"||T.errorMessage?{kind:"not_loaded"}:Jm({data:T.data,card:w}),[w,T.data,T.errorMessage]),G=Qm(w,H,T.comparisonMetadata),q=v.useMemo(()=>{if(w.type!=="pivotTable"||!G)return 0;const me=$L(G.data);return fu({section:e,totalRowCount:me.tableData.length+me.grandTotalRows.length}).totalRowCount},[w.type,G,e]);v.useEffect(()=>{w.type==="pivotTable"&&(h==null||h(e.id,q))},[w.type,h,G,q,e.id]);const Y=fgt(e),W=ugt(S),ne=v.useRef(null),Z=v.useRef(null),K=v.useRef({rowDataVersion:T.rowDataVersion,errorMessage:T.errorMessage}),[X,J]=v.useState(!1),[re,te]=v.useState(0),Q=ubt({tableSlice:a,initialRowsPerPageLimit:c,totalRowCount:w.type==="pivotTable"?q:O}),se=a?`${a.pageIndex}:${a.startIndex}:${a.endIndex}:${a.totalRows}`:"unsliced";if(v.useEffect(()=>{const me=K.current;K.current={rowDataVersion:T.rowDataVersion,errorMessage:T.errorMessage},!(me.rowDataVersion===T.rowDataVersion&&me.errorMessage===T.errorMessage)&&(x==null||x(e.id),te(ve=>ve+1))},[x,T.errorMessage,T.rowDataVersion,e.id]),lbt({sectionId:e.id,sectionRef:ne,tableSurfaceRef:Z,enabled:!X,measureKey:`${I.length}:${B.length}:${$?"loading":"ready"}:${W}:${se}:${re}`,measurementScale:C,fallbackRowHeightPx:Y,fallbackRowCount:Math.max(0,Q.endIndex-Q.startIndex),rowRangeStartIndex:Q.startIndex,rowRangeEndIndex:Q.endIndex,totalRowCount:Q.totalRowCount,canUpdateLayoutChrome:Xxt({tableSlice:a}),onTableLayoutMeasure:g}),T.errorMessage)return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table query failed",message:T.errorMessage,exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if($)return l.jsx(mbt,{section:e,isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(U)return l.jsx(nd,{section:e,icon:l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin text-zinc-400"}),title:"Preparing report table",message:"Rows are being acquired for the final document export.",exportState:"loading",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(L&&k&&!((xe=T.data)!=null&&xe.tableTotalsByColumnId)&&T.isFetching)return l.jsx(nd,{section:e,icon:l.jsx(m.LoaderCircle,{className:"h-4 w-4 animate-spin text-zinc-400"}),title:"Computing table totals",message:"Grand totals are being computed for this document table.",exportState:"loading",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(L&&k&&!((Ie=T.data)!=null&&Ie.tableTotalsByColumnId))return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Table totals unavailable",message:"Grand totals could not be computed for this document table.",exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});if(I.length===0&&w.type!=="pivotTable")return l.jsx(nd,{section:e,icon:l.jsx(m.Table2,{className:"h-4 w-4 text-zinc-300"}),title:e.title||w.title||"Table",message:"No records to display",exportState:"empty",isEditing:s,showInlineEditAction:d,onEditTableSection:f});let oe;if(w.type==="pivotTable"){if(!G)return l.jsx(nd,{section:e,icon:l.jsx(Br,{className:"h-4 w-4 text-amber-500"}),title:"Pivot table configuration unavailable",message:"Edit the table to confirm its rows, columns, and metrics.",exportState:"error",isEditing:s,showInlineEditAction:d,onEditTableSection:f});oe=l.jsx(pb,{card:N,data:fbt(G.data,a,c),options:G.options,suppressSortControls:F.renderContract.suppressSortControls,renderPlainWrapper:F.renderContract.renderPlainWrapper})}else oe=l.jsx(Zd,{card:V,data:B,resultColumns:(be=T.data)==null?void 0:be.columns,columnKeyMap:(ge=T.data)==null?void 0:ge.columnKeyMap,formattingFullRows:I,totalsData:L?I:void 0,totalsByColumnId:L?(ee=T.data)==null?void 0:ee.tableTotalsByColumnId:void 0,comparisonMetadata:T.comparisonMetadata,paginationMetadata:T.pagination,isLoading:$,columnSizing:(ae=(ce=V.preferences)==null?void 0:ce.tablePrefs)==null?void 0:ae.columnSizing,onColumnSizingChange:s&&i!=="print"?A:void 0,onColumnResizeStateChange:J,showColumnResizeHandles:s&&i!=="print",suppressSortControls:F.renderContract.suppressSortControls,suppressCellHoverCards:F.renderContract.disableDashboardInteractions});const fe=i!=="print"&&T.isPreviewWindowIncomplete&&(!a||a.endIndex>=I.length);return l.jsxs("div",{className:"relative",children:[l.jsxs("div",{ref:ne,className:"pt-3",children:[l.jsx(pbt,{section:e}),l.jsxs("div",{ref:Z,"data-document-table-section":"true",className:nbt(S),style:{...Jxt,"--document-table-row-height":`${Y}px`,"--document-table-min-surface-height":`${a?0:Bxt}px`,"--document-table-header-bg":S.headerBackgroundColor,"--document-table-header-color":S.headerTextColor,"--document-table-totals-bg":S.totalsStyle.backgroundColor,"--document-table-totals-color":S.totalsStyle.textColor,"--document-table-totals-border-color":S.totalsStyle.borderTopColor,"--document-table-totals-font-weight":String(dgt(S.totalsStyle.fontWeight)),"--document-table-cell-color":"#18181b"},children:[P?l.jsx(gbt,{}):null,oe]})]}),fe?l.jsx(xbt,{loadedRowCount:T.loadedRowCount,totalRowCount:T.totalRowCount,isFetching:T.isFetching,onLoadMore:T.loadMorePreviewRows}):null]})}function lbt({sectionId:e,sectionRef:t,tableSurfaceRef:n,enabled:r,measureKey:o,measurementScale:s,fallbackRowHeightPx:i,fallbackRowCount:a,rowRangeStartIndex:c,rowRangeEndIndex:u,totalRowCount:d,canUpdateLayoutChrome:f,onTableLayoutMeasure:h}){const p=v.useRef(null);v.useEffect(()=>{if(!r||!h)return;p.current=null;let g=null;const x=()=>{const I=t.current,D=n.current;if(!I||!D)return;const E=Number.isFinite(s)&&s>0?s:1,R=Y=>Y/E,F=Fxt(D),M=F.length>0?F.map(Y=>{const W=R(Y.getBoundingClientRect().height);return W>0?W:i}).filter(Y=>Y>0):Array.from({length:a},()=>i);if(M.length===0)return;const O=M.map(Y=>Math.ceil(Y)),z=Math.ceil(Math.max(...M)),L=M.reduce((Y,W)=>Y+W,0),V=Math.ceil(L/M.length),A=Math.ceil(R(I.getBoundingClientRect().height)),B=JW(I),$=F[0],P=F[F.length-1],U=$&&P?Pxt({sectionElement:I,tableSurfaceElement:D,firstRowElement:$,lastRowElement:P,measurementScale:E}):void 0;let H;if(B&&$&&P){const Y=B.getBoundingClientRect(),W=dbt(B,E,Y),ne=$.getBoundingClientRect(),Z=R(ne.top-Y.top),K=(U==null?void 0:U.trailingChromePx)??0,X=W-Z-K;H=Math.max(1,cbt(M,X))}const G=(U==null?void 0:U.chromeHeightPx)??Math.max(0,Math.ceil(A-L)),q={rowHeightPx:z,averageRowHeightPx:V,rowHeightsPx:O,rowRangeStartIndex:c,rowRangeEndIndex:u,totalRowCount:d,chromeHeightPx:G,renderedMinHeightPx:U==null?void 0:U.renderedMinHeightPx,canUpdateLayoutChrome:f,rowsPerPage:H};$xt(p.current,q)&&(p.current=q,h(e,q))},b=()=>{g!==null&&window.cancelAnimationFrame(g),g=window.requestAnimationFrame(()=>{g=null,x()})};if(b(),typeof ResizeObserver>"u")return()=>{g!==null&&window.cancelAnimationFrame(g)};const y=new ResizeObserver(b),C=typeof MutationObserver>"u"?null:new MutationObserver(b),w=new Set,N=I=>{!I||w.has(I)||(y.observe(I),w.add(I))},S=I=>{!I||!C||C.observe(I,{attributes:!0,characterData:!0,childList:!0,subtree:!0})},j=t.current,k=n.current,_=JW(j),T=Upe(_);return N(j),N(k),N(_),N(T),S(_),()=>{g!==null&&window.cancelAnimationFrame(g),y.disconnect(),C==null||C.disconnect()}},[r,s,o,h,e,t,n,i,a,c,u,d,f])}function cbt(e,t){if(!Number.isFinite(t)||t<=0)return 0;let n=0,r=0;for(const o of e){if(n+o>t)break;n+=o,r+=1}return r}function ubt({tableSlice:e,initialRowsPerPageLimit:t,totalRowCount:n}){const r=Math.max(0,n),o=Math.min((e==null?void 0:e.startIndex)??0,r),s=Math.min((e==null?void 0:e.endIndex)??t??r,r);return{startIndex:o,endIndex:Math.max(o,s),totalRowCount:r}}function dbt(e,t,n){const r=Upe(e);if(r)return(r.getBoundingClientRect().top-n.top)/t;const o=window.getComputedStyle(e),s=Number.parseFloat(o.paddingBottom||"0")||0;return Lxt(e)-s}function fbt(e,t,n){var f,h,p,g,x,b;const r=(t==null?void 0:t.startIndex)??0,o=(t==null?void 0:t.endIndex)??(n||void 0);if(o===void 0)return e;const s=((f=e.rowData)==null?void 0:f.length)??((h=e.rowHeaders)==null?void 0:h.length)??0,i=((p=e.grandTotalRows)==null?void 0:p.length)??0,a=Math.min(r,s),c=Math.min(o,s),u=Math.max(0,r-s),d=Math.max(0,Math.min(o-s,i));return{...e,rowData:(g=e.rowData)==null?void 0:g.slice(a,c),rowHeaders:((x=e.rowHeaders)==null?void 0:x.slice(a,c))??[],grandTotalRows:((b=e.grandTotalRows)==null?void 0:b.slice(u,d))??[]}}function hbt({section:e,isEditing:t,reason:n,showInlineEditAction:r,onEditTableSection:o}){return l.jsx("div",{className:"pt-3",children:l.jsxs("div",{className:"rounded border border-dashed border-zinc-200 px-4 py-8 text-center","data-document-render-error":"true",children:[l.jsx(m.Table2,{className:"mx-auto mb-2 h-5 w-5 text-zinc-300"}),l.jsx("p",{className:"text-[12px] font-medium text-zinc-600",children:e.title||e.card.title||"Table"}),n?l.jsx("p",{className:"mt-1 text-[11px] text-zinc-400",children:n}):null,r?l.jsx(W4,{section:e,isEditing:t,className:"mt-3",onEditTableSection:o}):null]})})}function mbt({section:e,isEditing:t,showInlineEditAction:n,onEditTableSection:r}){return l.jsx("div",{className:"pt-3","data-document-render-loading":"true",children:l.jsxs("div",{className:"relative h-[220px] overflow-hidden rounded",children:[l.jsx(Pz,{columns:5,rows:8}),n?l.jsx("div",{className:"absolute right-2 top-2 z-20",children:l.jsx(W4,{section:e,isEditing:t,onEditTableSection:r})}):null]})})}function nd({section:e,icon:t,title:n,message:r,exportState:o,isEditing:s,showInlineEditAction:i,onEditTableSection:a}){const c=o==="blocked"||o==="error",u=o==="loading";return l.jsx("div",{className:"pt-3",children:l.jsx("div",{className:"rounded border border-zinc-200 bg-zinc-50 px-4 py-5","data-document-render-error":c?"true":void 0,"data-document-render-loading":u?"true":void 0,children:l.jsxs("div",{className:"flex items-start gap-3",children:[l.jsx("div",{className:"mt-0.5 shrink-0",children:t}),l.jsxs("div",{className:"min-w-0 flex-1",children:[l.jsx("p",{className:"text-[12px] font-medium text-zinc-700",children:n}),l.jsx("p",{className:"mt-1 break-words text-[11px] text-zinc-500",children:r})]}),i?l.jsx(W4,{section:e,isEditing:s,onEditTableSection:a}):null]})})})}function pbt({section:e}){const t=e.title||e.card.title;return t?l.jsx("div",{className:"mb-2 min-w-0",children:t?l.jsx("p",{className:"whitespace-normal break-words text-[12px] font-semibold leading-4 text-zinc-800",children:t}):null}):null}function gbt(){return l.jsxs("div",{role:"status","aria-live":"polite",className:"pointer-events-none absolute right-2 top-2 z-10 inline-flex items-center gap-1.5 rounded-full border border-zinc-200 bg-white/95 px-2 py-1 text-[10px] font-medium text-zinc-500 shadow-sm",children:[l.jsx(m.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Updating..."]})}function xbt({loadedRowCount:e,totalRowCount:t,isFetching:n,onLoadMore:r}){const o=t===void 0?"unknown":t.toLocaleString();return l.jsxs("div",{className:"absolute left-0 top-full z-20 mt-2 flex max-w-full items-center gap-2 rounded border border-zinc-200 bg-white px-2 py-1 text-[11px] text-zinc-500 shadow-sm print:hidden",children:[l.jsxs("span",{className:"whitespace-nowrap",children:["Previewing ",e.toLocaleString()," of ",o," rows"]}),r?l.jsx(m.Button,{type:"button",variant:"outline",size:"sm",className:"h-6 rounded px-2 text-[11px]",disabled:n,onClick:r,children:n?"Loading...":"Load more pages"}):null]})}function W4({section:e,isEditing:t,className:n,onEditTableSection:r}){return t?l.jsxs(m.Button,{type:"button",variant:"outline",size:"sm",className:n?`h-8 gap-2 ${n}`:"h-8 gap-2",onClick:o=>{o.stopPropagation(),r==null||r(e)},children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Edit table"]}):null}const bbt={a4:{width:595,height:842},letter:{width:612,height:792}},ybt=96/72;function Xpe(e){return vbt(e)}function vbt(e){return wbt(e,{pointToPixelScale:ybt})}function wbt(e,{pointToPixelScale:t}){const n=bbt[e.size],r=e.orientation==="landscape"?n.height:n.width,o=e.orientation==="landscape"?n.width:n.height,s=e.margins,i=s.unit==="mm"?72/25.4:72,a=u=>Math.round(u*i*t),c={top:a(s.top),right:a(s.right),bottom:a(s.bottom),left:a(s.left)};return{width:Math.round(r*t),height:Math.round(o*t),padding:`${c.top}px ${c.right}px ${c.bottom}px ${c.left}px`,paddingPx:c}}const Cbt=16,Nx=78,Sbt=0,Nbt=0,jbt=72,kbt=40;function Ibt(e,t={}){var p;const n=t.tablePaginationBySectionId??{},r=t.pageMetricsMode??"preview",o=t.document?Jpe(t.document):Number.POSITIVE_INFINITY,s=[];let i=[],a=0,c=0,u;const d=(g,x=i,b=a,y=`document-page-${s.length+1}-${b}`,C=u)=>{s.push({id:y,startInsertIndex:b,sections:x,breakAfterSection:g,layoutError:C})},f=g=>{const x=s[s.length-1];return!x||x.breakAfterSection||x.sections.length===0?!1:(x.breakAfterSection=g,!0)};e.forEach((g,x)=>{if(g.type==="page_break"){i.length>0?d(g):f(g)||d(g),i=[],c=0,a=x+1;return}if(g.type==="table"){const C=n[g.id],w=(C==null?void 0:C.rowCount)??0,N=(C==null?void 0:C.rowsPerPage)??0,S=!!t.document,j=S&&N>0?Dbt(g,C,o-c):N;if(N>0&&(w>N||S&&i.length>0&&j>0&&w>j)&&C){!S&&i.length>0&&(d(),i=[],c=0,u=void 0,a=x),S&&i.length>0&&j<=0&&(d(),i=[],c=0,u=void 0,a=x);const _=G4(g,C),T=_bt({rowCount:w,rowsPerPage:N,footerRowCount:(C==null?void 0:C.footerRowCount)??0,firstRowsPerPage:S&&i.length>0?j:N,rowMeasurementState:_,capFirstRowsPerPage:S&&i.length>0&&C.measuredRowsPerPage!==void 0,firstRowsAvailableHeightPx:S&&i.length>0?vN(C,o-c):vN(C,o),fullRowsAvailableHeightPx:vN(C,o)});T.forEach((I,D)=>{const E=D===T.length-1,R={section:g,sectionIndex:x,tableSlice:{startIndex:I.startIndex,endIndex:I.endIndex,pageIndex:D,pageCount:T.length,totalRows:w,rowsPerPage:N}},F=Ebt(g,C,I.startIndex,I.endIndex);if(S&&D===0&&i.length>0){i.push(R),c+=F,E||(d(),i=[],c=0,u=void 0,a=x+1);return}if(E&&S){i=[R],c=F,u=void 0,a=x;return}d(void 0,[R],x,`document-page-table-${g.id}-${D+1}`,void 0)});return}}const b=t.document?Rbt({section:g,document:t.document,tablePagination:n[g.id],pageMetricsMode:r,textRenderContext:t.textRenderContext}):0;if(Number.isFinite(o)&&b>o){i.length>0&&(d(),i=[],c=0,u=void 0,a=x),d(void 0,[{section:g,sectionIndex:x}],x,`document-page-overflow-${g.id}`,`Section "${g.id}" exceeds the available page body height.`),i=[],c=0,u=void 0,a=x+1;return}i.length>0&&c+b>o&&(d(),i=[],c=0,u=void 0,a=x),i.push({section:g,sectionIndex:x}),c+=b}),(s.length===0||i.length>0||((p=e[e.length-1])==null?void 0:p.type)==="page_break")&&d();const h=s.length;return s.map((g,x)=>({...g,pageNumber:x+1,pageCount:h}))}function _bt({rowCount:e,rowsPerPage:t,footerRowCount:n=0,firstRowsPerPage:r,rowMeasurementState:o,capFirstRowsPerPage:s=!1,firstRowsAvailableHeightPx:i,fullRowsAvailableHeightPx:a}){const c=[];let u=0,d=Math.max(1,r);const f=Math.max(0,n),h=Math.max(0,e-f);for(;u<e;){const p=c.length===0?i:a,x=(o.kind==="sparse"||o.kind==="complete")&&Number.isFinite(p)?Gpe({rowMeasurementState:o,startIndex:u,availableHeightPx:p??0}):void 0,b=x!==void 0?Math.max(1,c.length===0&&s?Math.min(x,d):x):Math.max(1,d);let y;if(f===0||u>=h)y=Math.min(u+b,e);else{const C=h-u;if(C+f<=b&&K4({rowMeasurementState:o,startIndex:u,endIndex:e})<=(p??Number.POSITIVE_INFINITY))y=e;else{let w=Math.min(b,C);w===C&&f>0&&C>1&&(w-=1),y=u+Math.max(1,w)}}c.push({startIndex:u,endIndex:y}),u=y,d=t}return c}function Tbt({document:e,tableRowCountsBySectionId:t,tableLayoutMeasurementsBySectionId:n,shouldPaginateTables:r,pageMetricsMode:o="preview"}){if(!r)return{};const s={};for(const i of e.sections){if(!_v(i))continue;const a=t[i.id]??0;if(a<=0)continue;const c=n==null?void 0:n[i.id],u=fu({section:i,totalRowCount:a,layoutMeasurement:c}),d=qT({totalRowCount:u.totalRowCount,fallbackRowHeightPx:u.fallbackRowHeightPx,layoutMeasurement:c});s[i.id]={rowCount:u.totalRowCount,rowsPerPage:Qpe(e,u,o),footerRowCount:u.trailingRowCount,fallbackRowHeightPx:u.fallbackRowHeightPx,rowMeasurementState:d,rowHeightPx:u.measuredRowHeightPx,averageRowHeightPx:u.measuredAverageRowHeightPx,rowHeightsPx:u.measuredRowHeightsPx,chromeHeightPx:u.chromeHeightPx,renderedMinHeightPx:u.renderedMinHeightPx,measuredRowsPerPage:u.measuredRowsPerPage}}return s}function _v(e){return e.type!=="table"?!1:fu({section:e}).isRunnable}function Qpe(e,t,n="preview"){const o=Jpe(e)-(t.chromeHeightPx??Nx),s=Math.floor(o/t.effectiveRowHeightPx);return Math.max(1,s)}function Dbt(e,t,n){if(!Number.isFinite(n))return(t==null?void 0:t.rowsPerPage)??0;const r=vN(t,n),o=t&&G4(e,t),i=(o&&o.kind!=="unmeasured"?Gpe({rowMeasurementState:o,startIndex:0,availableHeightPx:r}):void 0)??Math.max(0,Math.floor(r/Hk(e,t)));return(t==null?void 0:t.measuredRowsPerPage)!==void 0?Math.max(0,Math.min(i,t.measuredRowsPerPage)):i}function Ebt(e,t,n,r){return Yxt({rowMeasurementState:t?G4(e,t):qT({totalRowCount:r,fallbackRowHeightPx:Hk(e,t)}),startIndex:n,endIndex:r,chromeHeightPx:(t==null?void 0:t.chromeHeightPx)??Nx})}function vN(e,t){return t-((e==null?void 0:e.chromeHeightPx)??Nx)}function Hk(e,t){if(t!=null&&t.rowMeasurementState)return Zxt(t.rowMeasurementState);const n=(t==null?void 0:t.fallbackRowHeightPx)??fu({section:e}).fallbackRowHeightPx;return Kpe({fallbackRowHeightPx:n,measuredRowHeightPx:t==null?void 0:t.rowHeightPx,measuredRowHeightsPx:t==null?void 0:t.rowHeightsPx,totalRowCount:t==null?void 0:t.rowCount})}function G4(e,t){return t.rowMeasurementState?t.rowMeasurementState:qT({totalRowCount:t.rowCount,fallbackRowHeightPx:Hk(e,t),layoutMeasurement:t.rowHeightPx!==void 0||t.rowHeightsPx?{rowHeightPx:t.rowHeightPx??Hk(e,t),averageRowHeightPx:t.averageRowHeightPx,rowHeightsPx:t.rowHeightsPx,chromeHeightPx:t.chromeHeightPx??Nx,renderedMinHeightPx:t.renderedMinHeightPx,rowsPerPage:t.rowsPerPage}:void 0})}function Jpe(e,t){const n=ege(e),r=tG(e.header,jbt),o=tG(e.footer,kbt);return n.height-n.paddingPx.top-n.paddingPx.bottom-r-o-Cbt}function Mbt(e,t){const n=ege(e);return n.width-n.paddingPx.left-n.paddingPx.right}function Rbt({section:e,document:t,tablePagination:n,pageMetricsMode:r,textRenderContext:o}){if(e.type==="spacer")return Math.max(8,e.heightPx);if(e.type==="text")return Abt(e,t,r,o);if(e.type==="table"){const s=fu({section:e,totalRowCount:(n==null?void 0:n.rowCount)??3,layoutMeasurement:n!=null&&n.rowHeightPx?{rowHeightPx:n.rowHeightPx,averageRowHeightPx:n.averageRowHeightPx,rowHeightsPx:n.rowHeightsPx,chromeHeightPx:n.chromeHeightPx??Nx,renderedMinHeightPx:n.renderedMinHeightPx,rowsPerPage:n.rowsPerPage}:void 0}),i=(n==null?void 0:n.rowCount)??3;return Gxt({rowMeasurementState:(n==null?void 0:n.rowMeasurementState)??qT({totalRowCount:i,fallbackRowHeightPx:s.effectiveRowHeightPx}),startIndex:0,endIndex:i,chromeHeightPx:(n==null?void 0:n.chromeHeightPx)??Nx,renderedMinHeightPx:n==null?void 0:n.renderedMinHeightPx})}return 0}function Abt(e,t,n,r){var c,u;const o=((c=e.style)==null?void 0:c.fontSize)??13,s=Math.ceil(o*((u=e.style)!=null&&u.fontSize?1.45:1.55)),i=Math.max(120,Mbt(t)-Sbt),a=Fbt({content:e.content,bodyWidthPx:i,fontSize:o,textRenderContext:r});return Nbt+a*s}function Fbt({content:e,bodyWidthPx:t,fontSize:n,textRenderContext:r}){const o=n*.54,s=r?upe(e,r):Pbt(e),i=Obt(s,o);return i.length===0?1:i.reduce((a,c)=>a+Math.max(1,Math.ceil(c/t)),0)}function Pbt(e){return e.map(t=>({type:t.type,value:t.type==="text"?t.value:"0".repeat(120),format:t.format}))}function Obt(e,t){const n=[0];for(const r of e){const o=Lbt(r);r.value.split(`
1322
1322
  `).forEach((i,a)=>{a>0&&n.push(0),n[n.length-1]+=i.length*t*o})}return n}function Lbt(e){var n,r;let t=1;return(n=e.format)!=null&&n.bold&&(t+=.08),(r=e.format)!=null&&r.italic&&(t+=.03),t}function ege(e,t){return Xpe(e.page)}function tG(e,t){return e!=null&&e.enabled?e.heightPx||t:0}const nG="application/x-semaphor-document-section";function $bt({sheetId:e,document:t,inputs:n,dashboardInputsById:r,textRenderContext:o,filterValuesByInputId:s,filterModesByInputId:i,documentFilterValues:a,documentControlDefinitions:c,documentControlValues:u,documentDashboardInputValues:d,missingRequiredInputLabels:f,onSetFilterValue:h,onSetFilterMode:p,onRemoveFilterValue:g,controlValuesByInputId:x,onSetControlValue:b,actions:y}){const[C,w]=v.useState({pageNumber:1,pageCount:1}),N=v.useCallback(j=>{w(k=>{const _=Math.max(1,k.pageCount),T=Math.min(_,Math.max(1,Math.round(j)));return k.pageNumber===T?k:{...k,pageNumber:T}})},[]),S=v.useCallback(j=>{w(k=>{const _=Math.max(k.pageCount,j,1),T=Math.min(k.pageNumber,_);return k.pageNumber===T&&k.pageCount===_?k:{pageNumber:T,pageCount:_}})},[]);return l.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden bg-muted/60 text-foreground",children:[n.length>0?l.jsx(Hpe,{sheetId:e,inputs:n,dashboardInputsById:r,filterValuesByInputId:s,filterModesByInputId:i,documentFilterValues:a,documentControlValues:u,onSetFilterValue:h,onSetFilterMode:p,onRemoveFilterValue:g,controlValuesByInputId:x,onSetControlValue:b,actions:y}):y?l.jsx("div",{className:"sticky top-0 z-30 flex min-h-11 shrink-0 justify-end border-b bg-background/95 px-4 py-2 shadow-[0_1px_0_rgba(0,0,0,0.04)] backdrop-blur supports-[backdrop-filter]:bg-background/90",children:y}):null,l.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[l.jsx("div",{className:"flex justify-center px-6 py-8",children:l.jsx(Y4,{document:t,inputs:n,textRenderContext:o,documentFilterValues:a,documentControlDefinitions:c,documentControlValues:u,documentDashboardInputValues:d,missingRequiredInputLabels:f,pageNumber:C.pageNumber,onPageCountChange:S})}),l.jsx(zbt,{pageNumber:C.pageNumber,pageCount:C.pageCount,onFirst:()=>N(1),onPrevious:()=>N(C.pageNumber-1),onNext:()=>N(C.pageNumber+1),onLast:()=>N(C.pageCount)})]})]})}function zbt({pageNumber:e,pageCount:t,onFirst:n,onPrevious:r,onNext:o,onLast:s}){return t<=1?null:l.jsxs("div",{className:"sticky bottom-4 z-20 mx-auto mt-[-44px] flex w-max items-center gap-1.5 rounded-full border border-zinc-200 bg-white/95 px-2.5 py-1 text-[12px] text-zinc-700 shadow-[0_8px_24px_rgba(0,0,0,0.14)] backdrop-blur",children:[l.jsx("button",{type:"button","aria-label":"First document page",className:"rounded px-1 text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35",disabled:e<=1,onClick:n,children:"<<"}),l.jsx("button",{type:"button","aria-label":"Previous document page",className:"rounded px-1 text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35",disabled:e<=1,onClick:r,children:"<"}),l.jsxs("span",{className:"min-w-[44px] text-center tabular-nums",children:[e," / ",t]}),l.jsx("button",{type:"button","aria-label":"Next document page",className:"rounded px-1 text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35",disabled:e>=t,onClick:o,children:">"}),l.jsx("button",{type:"button","aria-label":"Last document page",className:"rounded px-1 text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35",disabled:e>=t,onClick:s,children:">>"})]})}function Bbt({document:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a}){const c=e.page.size==="a4"?"A4":"Letter",u=e.page.orientation||"portrait";return l.jsxs("div",{"data-document-print-root":"true","data-document-render-error":a.length>0?"true":void 0,className:"bg-white text-foreground",children:[l.jsx("style",{children:`
1323
1323
  @page {
1324
1324
  size: ${c} ${u};
@@ -1359,10 +1359,10 @@ Include in the briefing:
1359
1359
  overflow: hidden !important;
1360
1360
  }
1361
1361
  }
1362
- `}),l.jsx("div",{"data-document-print-pages":"true",className:"flex justify-center",children:l.jsx(Y4,{document:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,surfaceMode:"print"})})]})}function Y4({document:e,inputs:t,textRenderContext:n,documentFilterValues:r=[],documentControlDefinitions:o=[],documentControlValues:s={},documentDashboardInputValues:i,missingRequiredInputLabels:a=[],isEditing:c=!1,selectedSectionId:u,activeAddIndex:d,onSelectSection:f,onToggleAddIndex:h,onInsertSection:p,onEditTableSection:g,onUpdateTableSection:x,onTableResultColumnsChange:b,onReorderSection:y,pageNumber:C,onPageCountChange:w,surfaceMode:N="preview",measurementScale:S=1}){var se,oe,fe,pe,xe,Ie;const[j,k]=v.useState({}),[_,T]=v.useState({}),[I,D]=v.useState({}),[E,R]=v.useState({}),[F,M]=v.useState(null),O=v.useCallback((be,ge)=>{k(ee=>ee[be]===ge?ee:{...ee,[be]:ge})},[]),z=v.useCallback((be,ge)=>{T(ee=>{const ce=ee[be],ae=Wxt(ce,ge);return ce&&Math.abs(ce.rowHeightPx-ae.rowHeightPx)<=1&&Math.abs((ce.averageRowHeightPx??ce.rowHeightPx)-(ae.averageRowHeightPx??ae.rowHeightPx))<=1&&Vbt(ce.rowHeightsPx,ae.rowHeightsPx)&&Math.abs(ce.chromeHeightPx-ae.chromeHeightPx)<=1&&Math.abs((ce.renderedMinHeightPx??0)-(ae.renderedMinHeightPx??0))<=1&&ce.rowsPerPage===ae.rowsPerPage?ee:{...ee,[be]:ae}})},[]),L=v.useCallback(be=>{T(ge=>{if(!ge[be])return ge;const{[be]:ee,...ce}=ge;return ce})},[]),V=v.useCallback((be,ge)=>{R(ee=>{const ce=Math.max(nL,Math.ceil(ge));return ee[be]===ce?ee:{...ee,[be]:ce}})},[]),A=v.useCallback((be,ge)=>{D(ee=>ee[be]===ge?ee:{...ee,[be]:ge})},[]),B=(se=e.header)==null?void 0:se.enabled,$=(oe=e.header)==null?void 0:oe.heightPx,P=(fe=e.header)==null?void 0:fe.layout,U=(pe=e.footer)==null?void 0:pe.enabled,H=(xe=e.footer)==null?void 0:xe.heightPx,G=(Ie=e.footer)==null?void 0:Ie.layout,q=v.useMemo(()=>Hbt(B,$,P),[B,$,P]),Y=v.useMemo(()=>qbt(U,H,G),[U,H,G]),W=v.useMemo(()=>({version:e.version,page:e.page,runtime:e.runtime,inputs:e.inputs,defaultInputValues:e.defaultInputValues,header:q,footer:Y,sections:e.sections,theme:e.theme}),[e.defaultInputValues,e.inputs,e.page,e.runtime,e.sections,e.theme,e.version,Y,q]);v.useEffect(()=>{T({})},[W.footer,W.header,W.page,W.sections,N]),v.useEffect(()=>{k(be=>{const ge=new Set(e.sections.filter(_v).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be}),T(be=>{const ge=new Set(e.sections.filter(_v).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be}),R(be=>{const ge=new Set(e.sections.filter(ae=>_v(ae)&&Zg(ae.card)).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be})},[e.sections]);const ne=v.useMemo(()=>Tbt({document:W,tableRowCountsBySectionId:j,tableLayoutMeasurementsBySectionId:_,shouldPaginateTables:a.length===0,pageMetricsMode:N}),[W,a.length,N,_,j]),Z=v.useMemo(()=>Ibt(W.sections,{document:W,tablePaginationBySectionId:ne,pageMetricsMode:N,textRenderContext:n}),[W,N,ne,n]);v.useEffect(()=>{w==null||w(Z.length)},[Z.length,w]),v.useEffect(()=>{if(N!=="print")return;const be=new Set(Z.map(ge=>ge.id));D(ge=>{const ee={};let ce=!1;for(const[ae,me]of Object.entries(ge))be.has(ae)?ee[ae]=me:ce=!0;return ce?ee:ge})},[Z,N]);const K=Z.some(be=>be.layoutError),X=N==="print"&&Object.values(I).some(Boolean),J=C===void 0?void 0:Math.min(Z.length,Math.max(1,C)),re=N==="print"||J===void 0?Z:Z[J-1]?[Z[J-1]]:[],te=v.useCallback(be=>{M(be)},[]),Q=v.useCallback(()=>{M(null)},[]);return l.jsx("div",{"data-testid":"document-page-stack","data-document-page-stack":"true","data-document-render-error":K||X?"true":void 0,className:"flex flex-col items-center gap-8",children:re.map(be=>l.jsx(Ubt,{page:be,document:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,selectedSectionId:u,activeAddIndex:d,onSelectSection:f,onToggleAddIndex:h,onInsertSection:p,onEditTableSection:g,onUpdateTableSection:x,onTableResultColumnsChange:b,onReorderSection:y,draggingSectionId:F,onSectionDragStart:te,onSectionDragEnd:Q,onTableRowCountChange:O,onTableLayoutMeasure:z,onTableLayoutInvalidate:L,tablePreviewRowLimitsBySectionId:E,onTablePreviewRowLimitChange:V,onPageOverflowChange:N==="print"?A:void 0,tableLayoutMeasurementsBySectionId:_,surfaceMode:N,measurementScale:S},be.id))})}function Vbt(e,t){return!e&&!t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return n===void 0||o===void 0?n===o:Math.abs(n-o)<=1})}function Hbt(e,t,n){if(!(e===void 0||!n))return{region:"header",enabled:e,heightPx:t,layout:n,blocks:[]}}function qbt(e,t,n){if(!(e===void 0||!n))return{region:"footer",enabled:e,heightPx:t,layout:n,blocks:[]}}function Ubt({page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}){return l.jsxs("div",{"data-document-page-item":"true","data-document-page-number":e.pageNumber,"data-document-page-count":e.pageCount,"data-document-layout-error":e.layoutError?"true":void 0,className:"flex flex-col items-center gap-2",children:[l.jsx(Kbt,{page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}),u&&e.breakAfterSection?l.jsx(Zbt,{selected:d===e.breakAfterSection.id,onSelect:()=>h==null?void 0:h(e.breakAfterSection.id)}):null]})}function Kbt({page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}){const M=v.useRef(null),O=Xpe(t.page),z={...r,meta:{...r.meta,pageNumber:e.pageNumber,pageCount:e.pageCount}},L=t.sections.length>0,V=e.sections[0];return V!=null&&V.tableSlice&&V.tableSlice.pageIndex>0,v.useEffect(()=>{var W,ne;if(!D||R!=="print"){D==null||D(e.id,!1);return}const A=M.current;if(!A)return;let B=null,$=null,P=null;const U=new Set,H=()=>{B!==null&&(typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(B):window.clearTimeout(B),B=null)},G=()=>{B=null;const Z=Math.ceil(A.scrollHeight)>Math.ceil(A.clientHeight)+1,K=Math.ceil(A.scrollWidth)>Math.ceil(A.clientWidth)+1;D(e.id,Z||K)},q=()=>{H(),B=typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(G):window.setTimeout(G,0)},Y=()=>{A.querySelectorAll("img").forEach(Z=>{U.has(Z)||(U.add(Z),Z.addEventListener("load",q),Z.addEventListener("error",q))})};return Y(),q(),typeof ResizeObserver<"u"&&($=new ResizeObserver(q),$.observe(A)),typeof MutationObserver<"u"&&(P=new MutationObserver(()=>{Y(),q()}),P.observe(A,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),(ne=(W=globalThis.document)==null?void 0:W.fonts)==null||ne.ready.then(q),()=>{H(),$==null||$.disconnect(),P==null||P.disconnect(),U.forEach(Z=>{Z.removeEventListener("load",q),Z.removeEventListener("error",q)})}},[D,e.id,e.sections,R]),l.jsxs("div",{ref:M,"data-testid":"document-page",className:"flex flex-col bg-white text-zinc-950 shadow-[0_1px_4px_rgba(0,0,0,0.08),0_0_0_1px_rgba(0,0,0,0.04)]",style:{boxSizing:"border-box",width:O.width,height:O.height,overflow:R==="print"?"hidden":void 0,padding:O.padding},onClick:A=>{u&&A.target===A.currentTarget&&(h==null||h(null),p==null||p(null))},children:[l.jsx(rG,{region:t.header,textRenderContext:z,isEditing:u}),l.jsx("div",{className:"min-h-0 flex-1 py-2",children:L?l.jsx(l.Fragment,{children:e.sections.length===0?l.jsx(Ybt,{isEditing:u}):e.sections.map(({section:A,sectionIndex:B,tableSlice:$})=>l.jsx(Wbt,{item:{section:A,sectionIndex:B,tableSlice:$},document:t,inputs:n,textRenderContext:z,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F},syt({sectionId:A.id,tableSlice:$})))}):u?l.jsx(Jbt,{onInsertSection:A=>g==null?void 0:g(A,0)}):null}),l.jsx(rG,{region:t.footer,textRenderContext:z,isEditing:u})]})}function Wbt({item:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,onSelectSection:f,onEditTableSection:h,onUpdateTableSection:p,onTableResultColumnsChange:g,onReorderSection:x,draggingSectionId:b,onSectionDragStart:y,onSectionDragEnd:C,onTableRowCountChange:w,onTableLayoutMeasure:N,onTableLayoutInvalidate:S,tablePreviewRowLimitsBySectionId:j,onTablePreviewRowLimitChange:k,tableLayoutMeasurementsBySectionId:_,surfaceMode:T,measurementScale:I}){const{section:D,sectionIndex:E}=e,R=D.type==="table"?_[D.id]:void 0,F=Gbt({document:t,item:e,tableLayoutMeasurement:R,surfaceMode:T});!e.tableSlice||(e.tableSlice.pageIndex,e.tableSlice.pageCount-1);const M=!!(e.tableSlice&&e.tableSlice.pageIndex>0),O=u&&!M,z=u;return l.jsx("div",{children:l.jsx(eyt,{section:D,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:O,selectionEnabled:z,selected:z&&d===D.id,onSelect:()=>f==null?void 0:f(D.id),onReorderSection:O?x:void 0,draggingSectionId:b,onSectionDragStart:y,onSectionDragEnd:C,onEditTableSection:h,onUpdateTableSection:p,onTableResultColumnsChange:g,surfaceMode:T,tableSlice:e.tableSlice,initialRowsPerPageLimit:F,onTableRowCountChange:w,onTableLayoutMeasure:N,onTableLayoutInvalidate:S,previewRowLimit:D.type==="table"?j[D.id]??nL:void 0,onPreviewRowLimitChange:D.type==="table"?L=>k==null?void 0:k(D.id,L):void 0,measurementScale:I})})}function Gbt({document:e,item:t,tableLayoutMeasurement:n,surfaceMode:r}){const{section:o}=t;if(!(o.type!=="table"||t.tableSlice||!_v(o)))return Qpe(e,fu({section:o,layoutMeasurement:n}),r)}function Ybt({isEditing:e}){return l.jsx("div",{className:"flex min-h-[160px] items-center justify-center text-[11px] text-zinc-300",children:e?"Empty page":null})}function Zbt({selected:e,onSelect:t}){return l.jsxs("button",{type:"button",className:m.cn("flex w-full items-center gap-2 rounded px-3 py-1.5 text-[10px] uppercase tracking-[0.08em] text-zinc-400 transition-colors",e?"bg-zinc-100 text-zinc-600":"hover:bg-zinc-100"),onClick:n=>{n.stopPropagation(),t()},children:[l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-300"}),"Page break",l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-300"})]})}function rG({region:e,textRenderContext:t,isEditing:n=!1}){if(!(e!=null&&e.enabled))return null;if(e.region==="header"){const d=m.getRegionImageBlock(e.blocks,"logo"),f=Xbt(d),h=m.getRegionTextBlock(e.blocks,"title"),p=m.getRegionTextBlock(e.blocks,"metadata"),g=Vy(h==null?void 0:h.content,t.inputs,n,t),x=Vy(p==null?void 0:p.content,t.inputs,n,t),b=jd(g),y=jd(x),C=!!(d!=null&&d.src||b||y),w=Qbt(g,x,{showVariableChips:n});return f==="left"?l.jsxs("div",{"data-document-region":"header",className:"flex items-center gap-3 border-b border-zinc-100",style:{minHeight:e.heightPx||72},children:[V2(d),l.jsx("div",{className:"min-w-0 flex-1",children:w}),!C&&n?l.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Header"}):null]}):l.jsxs("div",{"data-document-region":"header",className:"grid grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-zinc-100",style:{minHeight:e.heightPx||72},children:[l.jsxs("div",{className:"min-w-0",children:[w,!C&&n?l.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Header"}):null]}),l.jsx("div",{className:"flex justify-center",children:f==="center"?V2(d):null}),l.jsx("div",{className:"flex justify-end",children:f==="right"?V2(d):null})]})}const r=m.getRegionTextBlock(e.blocks,"note"),o=m.getRegionTextBlock(e.blocks,"pageInfo"),s=Vy(r==null?void 0:r.content,t.inputs,n,t),i=Vy(o==null?void 0:o.content,t.inputs,n,t),a=jd(s),c=jd(i),u=!!(a||c);return l.jsxs("div",{"data-document-region":"footer",className:"flex items-center justify-between border-t border-zinc-100 text-[10px] text-zinc-400",style:{minHeight:e.heightPx||40},children:[a?l.jsx("span",{children:P0(s,{showVariableChips:n})}):null,c?l.jsx("span",{className:"ml-auto tabular-nums",children:P0(i,{showVariableChips:n})}):null,!u&&n?l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Footer"}):null]})}function Xbt(e){return(e==null?void 0:e.area)==="center"||(e==null?void 0:e.area)==="right"?e.area:"left"}function V2(e){return e!=null&&e.src?l.jsx("img",{src:e.src,alt:e.alt||"",className:"max-h-10 shrink-0 object-contain",style:{width:e.widthPx||120}}):null}function Qbt(e,t,n={}){const r=jd(e),o=jd(t);return!r&&!o?null:l.jsxs("div",{className:"min-w-0",children:[r?l.jsx("div",{className:"whitespace-normal break-words text-[13px] font-semibold leading-5",children:P0(e,n)}):null,o?l.jsx("div",{className:"whitespace-normal break-words text-[11px] leading-4 text-zinc-500",children:P0(t,n)}):null]})}function Jbt({onInsertSection:e}){return l.jsxs("div",{className:"flex min-h-[360px] flex-col items-center justify-center py-16 text-center",children:[l.jsx("div",{className:"mb-4 flex h-10 w-10 items-center justify-center rounded-md border border-zinc-200 bg-zinc-50",children:l.jsx(li,{className:"h-5 w-5 text-zinc-400"})}),l.jsx("p",{className:"text-[14px] font-medium text-zinc-900",children:"Add your first section"}),l.jsx("div",{className:"mt-5 flex items-center gap-2",children:ppe.filter(t=>t!=="page_break").map(t=>{const n=F0(t);return l.jsxs(m.Button,{type:"button",variant:"outline",size:"sm",className:"h-8 gap-1.5 rounded px-3 text-[12px]",onClick:()=>e(t),children:[l.jsx(n,{className:"h-3.5 w-3.5"}),wC[t]]},t)})})]})}function eyt({section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,selectionEnabled:u=!1,selected:d,onSelect:f,onReorderSection:h,draggingSectionId:p,onSectionDragStart:g,onSectionDragEnd:x,onEditTableSection:b,onUpdateTableSection:y,onTableResultColumnsChange:C,surfaceMode:w,tableSlice:N,initialRowsPerPageLimit:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D}){const E=F0(e.type),[R,F]=v.useState(null);return c?l.jsxs("section",{className:m.cn("mb-0.5 overflow-hidden rounded transition-shadow",d?"ring-1 ring-zinc-300":"hover:ring-1 hover:ring-zinc-200",R==="before"&&"ring-2 ring-primary/60",R==="after"&&"ring-2 ring-primary/60"),onClick:M=>{M.stopPropagation(),f()},children:[l.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Select ${F2(e,t)} section`,draggable:!!h,className:m.cn("flex items-center gap-1.5 border-b px-3 py-1 outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-zinc-50":"bg-white"),onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),f())},onDragStart:M=>{M.dataTransfer.effectAllowed="move",M.dataTransfer.setData(nG,e.id),g==null||g(e.id)},onDragOver:M=>{if(h){if(!p||p===e.id){F(null);return}M.preventDefault(),M.dataTransfer.dropEffect="move",F(sG(M))}},onDragLeave:()=>F(null),onDragEnd:()=>{F(null),x==null||x()},onDrop:M=>{if(!h)return;M.preventDefault();const O=M.dataTransfer.getData(nG)||p,z=sG(M);F(null),x==null||x(),!(!O||O===e.id)&&h(O,e.id,z)},children:[l.jsx(Iu,{className:"h-3.5 w-3.5 cursor-grab text-zinc-300"}),l.jsx(E,{className:"h-3.5 w-3.5 shrink-0 text-zinc-400"}),l.jsx("span",{className:"flex-1 text-[11px] text-zinc-500",children:F2(e,t)}),e.type==="table"?l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-6 gap-1.5 px-2 text-[11px] text-zinc-600",onClick:M=>{M.stopPropagation(),b==null||b(e)},children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Edit table"]}):null]}),l.jsx(oG,{section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,surfaceMode:w,onEditTableSection:b,onUpdateTableSection:y,onTableResultColumnsChange:C,tableSlice:N,initialRowsPerPageLimit:S,showInlineEditAction:!c,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D})]}):l.jsx("section",{className:m.cn(u&&"rounded transition-shadow hover:ring-1 hover:ring-zinc-200",d&&"ring-1 ring-zinc-300"),role:u?"button":void 0,tabIndex:u?0:void 0,"aria-label":u?`Select ${F2(e,t)} section`:void 0,onClick:u?M=>{M.stopPropagation(),f()}:void 0,onKeyDown:u?M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),f())}:void 0,children:l.jsx(oG,{section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:!1,surfaceMode:w,onUpdateTableSection:y,tableSlice:N,initialRowsPerPageLimit:S,onTableRowCountChange:j,onTableResultColumnsChange:C,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D})})}function oG({section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c=!0,surfaceMode:u="preview",onEditTableSection:d,onUpdateTableSection:f,onTableResultColumnsChange:h,tableSlice:p,initialRowsPerPageLimit:g,showInlineEditAction:x=!0,onTableRowCountChange:b,onTableLayoutMeasure:y,onTableLayoutInvalidate:C,previewRowLimit:w,onPreviewRowLimitChange:N,measurementScale:S}){if(e.type==="text"){const j=Vy(e.content,t,c,n),k=jd(j);return l.jsx("div",{className:m.cn("whitespace-pre-wrap text-[13px] leading-5 text-zinc-800",c&&"px-3"),style:tyt(e.style),children:k?P0(j,{showVariableChips:c}):c?"Text":null})}return e.type==="table"?l.jsx(Zpe,{section:e,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,surfaceMode:u,onEditTableSection:d,onUpdateTableSection:f,tableSlice:p,initialRowsPerPageLimit:g,showInlineEditAction:x,onTableRowCountChange:b,onTableResultColumnsChange:h,onTableLayoutMeasure:y,onTableLayoutInvalidate:C,previewRowLimit:w,onPreviewRowLimitChange:N,measurementScale:S}):e.type==="spacer"?c?l.jsxs("div",{className:"relative",style:{height:Math.max(8,e.heightPx)},children:[l.jsx("div",{className:"absolute inset-x-0 top-1/2 border-t border-dashed border-zinc-200"}),l.jsxs("span",{className:"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white px-1.5 text-[10px] text-zinc-400",children:[e.heightPx,"px"]})]}):l.jsx("div",{style:{height:Math.max(8,e.heightPx)}}):e.type==="page_break"&&c?l.jsxs("div",{className:"flex items-center gap-2 px-3 py-4",children:[l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-200"}),l.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-zinc-400",children:"Page break"}),l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-200"})]}):null}function sG(e){const t=e.currentTarget.getBoundingClientRect(),n=t.top+t.height/2;return e.clientY>n?"after":"before"}function tyt(e){if(e)return{...e.fontSize?{fontSize:e.fontSize}:{},...e.fontSize?{lineHeight:1.45}:{},...e.fontWeight?{fontWeight:oyt(e.fontWeight)}:{},...e.color?{color:e.color}:{},...e.align?{textAlign:e.align}:{}}}function jd(e){return e.map(t=>t.value).join("")}function P0(e,t={}){return!t.showVariableChips&&e.every(n=>!n.format)?jd(e):e.map((n,r)=>l.jsx("span",{className:m.cn(t.showVariableChips&&n.type==="variable"&&"rounded-[2px] bg-emerald-50 px-0.5 font-mono text-[0.92em] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-200/80"),style:ryt(n),children:n.value},r))}function Vy(e,t,n,r){return n?nyt(e,t):upe(e,r)}function nyt(e,t){return(e||[]).map(n=>n.type==="text"?{type:"text",value:n.value,...n.format?{format:n.format}:{}}:{type:"variable",value:B4(n.ref,t),...n.format?{format:n.format}:{}})}function ryt(e){if(e.format)return{...e.format.bold?{fontWeight:700}:{},...e.format.italic?{fontStyle:"italic"}:{},...e.format.underline?{textDecoration:"underline"}:{}}}function oyt(e){switch(e){case"medium":return 500;case"semibold":return 600;default:return e}}function syt({sectionId:e,tableSlice:t}){return t?`${e}:${t.startIndex}-${t.endIndex}`:e}const iyt=Fse|Pse|Ose,iG="document-text-external-sync";function O0({content:e,inputs:t,multiline:n=!1,disabled:r=!1,onChange:o}){const s=v.useRef(e),i=v.useRef(t);v.useMemo(()=>pyt(e),[e]);const a=v.useMemo(()=>lge(e,t),[e,t]),c=v.useMemo(()=>ige(e||[],t),[e,t]),u=c.unresolvedTokens.length===0&&gyt(e,t)&&!xyt(e,c.content);v.useEffect(()=>{r||!u||o(c.content)},[r,o,c.content,u]);const d=v.useMemo(()=>({namespace:"DocumentTextEditor",nodes:[SC],onError(f){throw f},theme:{text:{bold:"font-semibold",italic:"italic",underline:"underline"}},editorState:()=>{tge(s.current||[],i.current,n)}}),[n]);return l.jsx(hae,{initialConfig:d,children:l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:m.cn("rounded border border-input bg-background focus-within:border-ring",r&&"bg-muted text-muted-foreground"),children:[r?null:l.jsx(lyt,{inputs:t}),l.jsx(Qae,{contentEditable:l.jsx(jae,{"aria-label":"Document text","aria-multiline":n,className:m.cn("min-h-8 w-full px-2 py-1.5 text-[12px] leading-5 outline-none",n?"min-h-28":"whitespace-nowrap",r&&"cursor-not-allowed")}),placeholder:null,ErrorBoundary:kae})]}),l.jsx(Pae,{}),l.jsx(cyt,{content:e||[],disabled:r,inputs:t,multiline:n,onChange:o,syncSignature:a}),c.unresolvedTokens.length>0?l.jsxs("p",{className:"text-[11px] leading-4 text-destructive",children:["Unresolved variable:"," ",c.unresolvedTokens.map(f=>f).join(", ")]}):null]})})}class SC extends vc{constructor(n,r,o){super(r,o);Se(this,"__ref");this.__ref=n}static getType(){return"document-variable"}static clone(n){const r=new SC(n.__ref,n.__text,n.__key);return r.__format=n.__format,r.__style=n.__style,r.__detail=n.__detail,r.__mode=n.__mode,r}static importJSON(n){return Z4(n.ref,n.text).setFormat(n.format).setStyle(n.style).setDetail(n.detail)}static importDOM(){return{}}getRef(){return this.getLatest().__ref}createDOM(n){const r=document.createElement("span");return r.className=cG(this),r.textContent=this.__text,r}updateDOM(n,r){return n.__text!==this.__text&&(r.textContent=this.__text),r.className=cG(this),!1}exportDOM(){return{element:document.createTextNode(`{{${this.__text}}}`)}}exportJSON(){return{...super.exportJSON(),ref:this.__ref,type:"document-variable",version:1}}isTextEntity(){return!0}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function Z4(e,t){return new SC(e,t).setMode("token")}function ayt(e){return e instanceof SC}function lyt({inputs:e}){const[t]=ca(),[n,r]=v.useState({}),o=v.useMemo(()=>Wpt(e),[e]),s=v.useCallback(()=>{const c=Dt();if(!ht(c)){r({});return}r({bold:c.hasFormat("bold"),italic:c.hasFormat("italic"),underline:c.hasFormat("underline")})},[]);v.useEffect(()=>oa(t.registerUpdateListener(({editorState:c})=>{c.read(s)})),[t,s]);const i=c=>{t.dispatchCommand(Wl,c)},a=c=>{t.focus(()=>{t.update(()=>{const u=Z4(c.ref,c.label),d=Dt();if(ht(d)){u.setFormat(d.format&iyt),W_([u,Dr(" ")]);return}const f=kr(),h=f.getLastChild();if(Ze(h))h.append(u,Dr(" "));else{const p=Vr();p.append(u,Dr(" ")),f.append(p)}})})};return l.jsxs("div",{className:"flex h-7 items-center gap-0.5 border-b border-border/60 px-1",children:[l.jsx(H2,{active:!!n.bold,ariaLabel:"Bold",onClick:()=>i("bold"),children:l.jsx(PZ,{className:"h-3 w-3"})}),l.jsx(H2,{active:!!n.italic,ariaLabel:"Italic",onClick:()=>i("italic"),children:l.jsx(rX,{className:"h-3 w-3"})}),l.jsx(H2,{active:!!n.underline,ariaLabel:"Underline",onClick:()=>i("underline"),children:l.jsx(pwe,{className:"h-3 w-3"})}),l.jsx("div",{className:"ml-auto",children:o.length>0?l.jsx(yyt,{choices:o,onInsert:a}):null})]})}function H2({active:e,ariaLabel:t,children:n,onClick:r}){return l.jsx("button",{type:"button","aria-label":t,title:t,onMouseDown:o=>o.preventDefault(),onClick:r,className:m.cn("inline-flex h-5 w-5 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",e&&"bg-muted text-foreground"),children:n})}function cyt({content:e,disabled:t,inputs:n,multiline:r,onChange:o,syncSignature:s}){const[i]=ca(),a=v.useRef(s);return v.useEffect(()=>{i.setEditable(!t)},[t,i]),v.useEffect(()=>{a.current!==s&&(i.update(()=>{tge(e,n,r)},{tag:iG}),a.current=s)},[e,i,n,r,s]),v.useEffect(()=>{if(!r)return i.registerCommand(h0,c=>(c==null||c.preventDefault(),!0),Q7)},[i,r]),v.useEffect(()=>{if(!r)return i.registerCommand(Lw,c=>{const u=dyt(c);if(!u||!/[\r\n]/.test(u))return!1;c.preventDefault();const d=rge(u),f=Dt();return ht(f)?f.insertText(d):W_([Dr(d)]),!0},Q7)},[i,r]),l.jsx(Uae,{ignoreSelectionChange:!0,onChange:(c,u,d)=>{d.has(iG)||c.read(()=>{const f=uyt(n,r),h=lge(f,n);a.current=h,o(f)})}})}function tge(e,t,n){const r=kr();r.clear();let o=Vr();r.append(o);for(const s of n?e:nge(e)){if(s.type==="variable"){const a=Z4(s.ref,B4(s.ref,t));lG(a,s.format),o.append(a);continue}s.value.split(`
1362
+ `}),l.jsx("div",{"data-document-print-pages":"true",className:"flex justify-center",children:l.jsx(Y4,{document:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,surfaceMode:"print"})})]})}function Y4({document:e,inputs:t,textRenderContext:n,documentFilterValues:r=[],documentControlDefinitions:o=[],documentControlValues:s={},documentDashboardInputValues:i,missingRequiredInputLabels:a=[],isEditing:c=!1,selectedSectionId:u,activeAddIndex:d,onSelectSection:f,onToggleAddIndex:h,onInsertSection:p,onEditTableSection:g,onUpdateTableSection:x,onTableResultColumnsChange:b,onReorderSection:y,pageNumber:C,onPageCountChange:w,surfaceMode:N="preview",measurementScale:S=1}){var se,oe,fe,pe,xe,Ie;const[j,k]=v.useState({}),[_,T]=v.useState({}),[I,D]=v.useState({}),[E,R]=v.useState({}),[F,M]=v.useState(null),O=v.useCallback((be,ge)=>{k(ee=>ee[be]===ge?ee:{...ee,[be]:ge})},[]),z=v.useCallback((be,ge)=>{T(ee=>{const ce=ee[be],ae=Wxt(ce,ge);return ce&&Math.abs(ce.rowHeightPx-ae.rowHeightPx)<=1&&Math.abs((ce.averageRowHeightPx??ce.rowHeightPx)-(ae.averageRowHeightPx??ae.rowHeightPx))<=1&&Vbt(ce.rowHeightsPx,ae.rowHeightsPx)&&Math.abs(ce.chromeHeightPx-ae.chromeHeightPx)<=1&&Math.abs((ce.renderedMinHeightPx??0)-(ae.renderedMinHeightPx??0))<=1&&ce.rowsPerPage===ae.rowsPerPage?ee:{...ee,[be]:ae}})},[]),L=v.useCallback(be=>{T(ge=>{if(!ge[be])return ge;const{[be]:ee,...ce}=ge;return ce})},[]),V=v.useCallback((be,ge)=>{R(ee=>{const ce=Math.max(nL,Math.ceil(ge));return ee[be]===ce?ee:{...ee,[be]:ce}})},[]),A=v.useCallback((be,ge)=>{D(ee=>ee[be]===ge?ee:{...ee,[be]:ge})},[]),B=(se=e.header)==null?void 0:se.enabled,$=(oe=e.header)==null?void 0:oe.heightPx,P=(fe=e.header)==null?void 0:fe.layout,U=(pe=e.footer)==null?void 0:pe.enabled,H=(xe=e.footer)==null?void 0:xe.heightPx,G=(Ie=e.footer)==null?void 0:Ie.layout,q=v.useMemo(()=>Hbt(B,$,P),[B,$,P]),Y=v.useMemo(()=>qbt(U,H,G),[U,H,G]),W=v.useMemo(()=>({version:e.version,page:e.page,runtime:e.runtime,inputs:e.inputs,defaultInputValues:e.defaultInputValues,header:q,footer:Y,sections:e.sections,theme:e.theme}),[e.defaultInputValues,e.inputs,e.page,e.runtime,e.sections,e.theme,e.version,Y,q]);v.useEffect(()=>{T({})},[W.footer,W.header,W.page,W.sections,N]),v.useEffect(()=>{k(be=>{const ge=new Set(e.sections.filter(_v).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be}),T(be=>{const ge=new Set(e.sections.filter(_v).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be}),R(be=>{const ge=new Set(e.sections.filter(ae=>_v(ae)&&Zg(ae.card)).map(ae=>ae.id));let ee=!1;const ce={};for(const[ae,me]of Object.entries(be))ge.has(ae)?ce[ae]=me:ee=!0;return ee?ce:be})},[e.sections]);const ne=v.useMemo(()=>Tbt({document:W,tableRowCountsBySectionId:j,tableLayoutMeasurementsBySectionId:_,shouldPaginateTables:a.length===0,pageMetricsMode:N}),[W,a.length,N,_,j]),Z=v.useMemo(()=>Ibt(W.sections,{document:W,tablePaginationBySectionId:ne,pageMetricsMode:N,textRenderContext:n}),[W,N,ne,n]);v.useEffect(()=>{w==null||w(Z.length)},[Z.length,w]),v.useEffect(()=>{if(N!=="print")return;const be=new Set(Z.map(ge=>ge.id));D(ge=>{const ee={};let ce=!1;for(const[ae,me]of Object.entries(ge))be.has(ae)?ee[ae]=me:ce=!0;return ce?ee:ge})},[Z,N]);const K=Z.some(be=>be.layoutError),X=N==="print"&&Object.values(I).some(Boolean),J=C===void 0?void 0:Math.min(Z.length,Math.max(1,C)),re=N==="print"||J===void 0?Z:Z[J-1]?[Z[J-1]]:[],te=v.useCallback(be=>{M(be)},[]),Q=v.useCallback(()=>{M(null)},[]);return l.jsx("div",{"data-testid":"document-page-stack","data-document-page-stack":"true","data-document-render-error":K||X?"true":void 0,className:"flex flex-col items-center gap-8",children:re.map(be=>l.jsx(Ubt,{page:be,document:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,selectedSectionId:u,activeAddIndex:d,onSelectSection:f,onToggleAddIndex:h,onInsertSection:p,onEditTableSection:g,onUpdateTableSection:x,onTableResultColumnsChange:b,onReorderSection:y,draggingSectionId:F,onSectionDragStart:te,onSectionDragEnd:Q,onTableRowCountChange:O,onTableLayoutMeasure:z,onTableLayoutInvalidate:L,tablePreviewRowLimitsBySectionId:E,onTablePreviewRowLimitChange:V,onPageOverflowChange:N==="print"?A:void 0,tableLayoutMeasurementsBySectionId:_,surfaceMode:N,measurementScale:S},be.id))})}function Vbt(e,t){return!e&&!t?!0:!e||!t||e.length!==t.length?!1:e.every((n,r)=>{const o=t[r];return n===void 0||o===void 0?n===o:Math.abs(n-o)<=1})}function Hbt(e,t,n){if(!(e===void 0||!n))return{region:"header",enabled:e,heightPx:t,layout:n,blocks:[]}}function qbt(e,t,n){if(!(e===void 0||!n))return{region:"footer",enabled:e,heightPx:t,layout:n,blocks:[]}}function Ubt({page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}){return l.jsxs("div",{"data-document-page-item":"true","data-document-page-number":e.pageNumber,"data-document-page-count":e.pageCount,"data-document-layout-error":e.layoutError?"true":void 0,className:"flex flex-col items-center gap-2",children:[l.jsx(Kbt,{page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}),u&&e.breakAfterSection?l.jsx(Zbt,{selected:d===e.breakAfterSection.id,onSelect:()=>h==null?void 0:h(e.breakAfterSection.id)}):null]})}function Kbt({page:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,onPageOverflowChange:D,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F}){const M=v.useRef(null),O=Xpe(t.page),z={...r,meta:{...r.meta,pageNumber:e.pageNumber,pageCount:e.pageCount}},L=t.sections.length>0,V=e.sections[0];return V!=null&&V.tableSlice&&V.tableSlice.pageIndex>0,v.useEffect(()=>{var W,ne;if(!D||R!=="print"){D==null||D(e.id,!1);return}const A=M.current;if(!A)return;let B=null,$=null,P=null;const U=new Set,H=()=>{B!==null&&(typeof window.cancelAnimationFrame=="function"?window.cancelAnimationFrame(B):window.clearTimeout(B),B=null)},G=()=>{B=null;const Z=Math.ceil(A.scrollHeight)>Math.ceil(A.clientHeight)+1,K=Math.ceil(A.scrollWidth)>Math.ceil(A.clientWidth)+1;D(e.id,Z||K)},q=()=>{H(),B=typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(G):window.setTimeout(G,0)},Y=()=>{A.querySelectorAll("img").forEach(Z=>{U.has(Z)||(U.add(Z),Z.addEventListener("load",q),Z.addEventListener("error",q))})};return Y(),q(),typeof ResizeObserver<"u"&&($=new ResizeObserver(q),$.observe(A)),typeof MutationObserver<"u"&&(P=new MutationObserver(()=>{Y(),q()}),P.observe(A,{attributes:!0,childList:!0,characterData:!0,subtree:!0})),(ne=(W=globalThis.document)==null?void 0:W.fonts)==null||ne.ready.then(q),()=>{H(),$==null||$.disconnect(),P==null||P.disconnect(),U.forEach(Z=>{Z.removeEventListener("load",q),Z.removeEventListener("error",q)})}},[D,e.id,e.sections,R]),l.jsxs("div",{ref:M,"data-testid":"document-page",className:"flex flex-col bg-white text-zinc-950 shadow-[0_1px_4px_rgba(0,0,0,0.08),0_0_0_1px_rgba(0,0,0,0.04)]",style:{boxSizing:"border-box",width:O.width,height:O.height,overflow:R==="print"?"hidden":void 0,padding:O.padding},onClick:A=>{u&&A.target===A.currentTarget&&(h==null||h(null),p==null||p(null))},children:[l.jsx(rG,{region:t.header,textRenderContext:z,isEditing:u}),l.jsx("div",{className:"min-h-0 flex-1 py-2",children:L?l.jsx(l.Fragment,{children:e.sections.length===0?l.jsx(Ybt,{isEditing:u}):e.sections.map(({section:A,sectionIndex:B,tableSlice:$})=>l.jsx(Wbt,{item:{section:A,sectionIndex:B,tableSlice:$},document:t,inputs:n,textRenderContext:z,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,activeAddIndex:f,onSelectSection:h,onToggleAddIndex:p,onInsertSection:g,onEditTableSection:x,onUpdateTableSection:b,onTableResultColumnsChange:y,onReorderSection:C,draggingSectionId:w,onSectionDragStart:N,onSectionDragEnd:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,tablePreviewRowLimitsBySectionId:T,onTablePreviewRowLimitChange:I,tableLayoutMeasurementsBySectionId:E,surfaceMode:R,measurementScale:F},syt({sectionId:A.id,tableSlice:$})))}):u?l.jsx(Jbt,{onInsertSection:A=>g==null?void 0:g(A,0)}):null}),l.jsx(rG,{region:t.footer,textRenderContext:z,isEditing:u})]})}function Wbt({item:e,document:t,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:u,selectedSectionId:d,onSelectSection:f,onEditTableSection:h,onUpdateTableSection:p,onTableResultColumnsChange:g,onReorderSection:x,draggingSectionId:b,onSectionDragStart:y,onSectionDragEnd:C,onTableRowCountChange:w,onTableLayoutMeasure:N,onTableLayoutInvalidate:S,tablePreviewRowLimitsBySectionId:j,onTablePreviewRowLimitChange:k,tableLayoutMeasurementsBySectionId:_,surfaceMode:T,measurementScale:I}){const{section:D,sectionIndex:E}=e,R=D.type==="table"?_[D.id]:void 0,F=Gbt({document:t,item:e,tableLayoutMeasurement:R,surfaceMode:T});!e.tableSlice||(e.tableSlice.pageIndex,e.tableSlice.pageCount-1);const M=!!(e.tableSlice&&e.tableSlice.pageIndex>0),O=u&&!M,z=u;return l.jsx("div",{children:l.jsx(eyt,{section:D,inputs:n,textRenderContext:r,documentFilterValues:o,documentControlDefinitions:s,documentControlValues:i,documentDashboardInputValues:a,missingRequiredInputLabels:c,isEditing:O,selectionEnabled:z,selected:z&&d===D.id,onSelect:()=>f==null?void 0:f(D.id),onReorderSection:O?x:void 0,draggingSectionId:b,onSectionDragStart:y,onSectionDragEnd:C,onEditTableSection:h,onUpdateTableSection:p,onTableResultColumnsChange:g,surfaceMode:T,tableSlice:e.tableSlice,initialRowsPerPageLimit:F,onTableRowCountChange:w,onTableLayoutMeasure:N,onTableLayoutInvalidate:S,previewRowLimit:D.type==="table"?j[D.id]??nL:void 0,onPreviewRowLimitChange:D.type==="table"?L=>k==null?void 0:k(D.id,L):void 0,measurementScale:I})})}function Gbt({document:e,item:t,tableLayoutMeasurement:n,surfaceMode:r}){const{section:o}=t;if(!(o.type!=="table"||t.tableSlice||!_v(o)))return Qpe(e,fu({section:o,layoutMeasurement:n}),r)}function Ybt({isEditing:e}){return l.jsx("div",{className:"flex min-h-[160px] items-center justify-center text-[11px] text-zinc-300",children:e?"Empty page":null})}function Zbt({selected:e,onSelect:t}){return l.jsxs("button",{type:"button",className:m.cn("flex w-full items-center gap-2 rounded px-3 py-1.5 text-[10px] uppercase tracking-[0.08em] text-zinc-400 transition-colors",e?"bg-zinc-100 text-zinc-600":"hover:bg-zinc-100"),onClick:n=>{n.stopPropagation(),t()},children:[l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-300"}),"Page break",l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-300"})]})}function rG({region:e,textRenderContext:t,isEditing:n=!1}){if(!(e!=null&&e.enabled))return null;if(e.region==="header"){const d=m.getRegionImageBlock(e.blocks,"logo"),f=Xbt(d),h=m.getRegionTextBlock(e.blocks,"title"),p=m.getRegionTextBlock(e.blocks,"metadata"),g=Vy(h==null?void 0:h.content,t.inputs,n,t),x=Vy(p==null?void 0:p.content,t.inputs,n,t),b=jd(g),y=jd(x),C=!!(d!=null&&d.src||b||y),w=Qbt(g,x,{showVariableChips:n});return f==="left"?l.jsxs("div",{"data-document-region":"header",className:"flex items-center gap-3 border-b border-zinc-100",style:{minHeight:e.heightPx||72},children:[V2(d),l.jsx("div",{className:"min-w-0 flex-1",children:w}),!C&&n?l.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Header"}):null]}):l.jsxs("div",{"data-document-region":"header",className:"grid grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-zinc-100",style:{minHeight:e.heightPx||72},children:[l.jsxs("div",{className:"min-w-0",children:[w,!C&&n?l.jsx("span",{className:"text-[11px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Header"}):null]}),l.jsx("div",{className:"flex justify-center",children:f==="center"?V2(d):null}),l.jsx("div",{className:"flex justify-end",children:f==="right"?V2(d):null})]})}const r=m.getRegionTextBlock(e.blocks,"note"),o=m.getRegionTextBlock(e.blocks,"pageInfo"),s=Vy(r==null?void 0:r.content,t.inputs,n,t),i=Vy(o==null?void 0:o.content,t.inputs,n,t),a=jd(s),c=jd(i),u=!!(a||c);return l.jsxs("div",{"data-document-region":"footer",className:"flex items-center justify-between border-t border-zinc-100 text-[10px] text-zinc-400",style:{minHeight:e.heightPx||40},children:[a?l.jsx("span",{children:P0(s,{showVariableChips:n})}):null,c?l.jsx("span",{className:"ml-auto tabular-nums",children:P0(i,{showVariableChips:n})}):null,!u&&n?l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-zinc-300",children:"Footer"}):null]})}function Xbt(e){return(e==null?void 0:e.area)==="center"||(e==null?void 0:e.area)==="right"?e.area:"left"}function V2(e){return e!=null&&e.src?l.jsx("img",{src:e.src,alt:e.alt||"",className:"max-h-10 shrink-0 object-contain",style:{width:e.widthPx||120}}):null}function Qbt(e,t,n={}){const r=jd(e),o=jd(t);return!r&&!o?null:l.jsxs("div",{className:"min-w-0",children:[r?l.jsx("div",{className:"whitespace-normal break-words text-[13px] font-semibold leading-5",children:P0(e,n)}):null,o?l.jsx("div",{className:"whitespace-normal break-words text-[11px] leading-4 text-zinc-500",children:P0(t,n)}):null]})}function Jbt({onInsertSection:e}){return l.jsxs("div",{className:"flex min-h-[360px] flex-col items-center justify-center py-16 text-center",children:[l.jsx("div",{className:"mb-4 flex h-10 w-10 items-center justify-center rounded-md border border-zinc-200 bg-zinc-50",children:l.jsx(li,{className:"h-5 w-5 text-zinc-400"})}),l.jsx("p",{className:"text-[14px] font-medium text-zinc-900",children:"Add your first section"}),l.jsx("div",{className:"mt-5 flex items-center gap-2",children:ppe.filter(t=>t!=="page_break").map(t=>{const n=F0(t);return l.jsxs(m.Button,{type:"button",variant:"outline",size:"sm",className:"h-8 gap-1.5 rounded border-zinc-200 bg-white px-3 text-[12px] text-zinc-700 hover:bg-zinc-50 hover:text-zinc-900",onClick:()=>e(t),children:[l.jsx(n,{className:"h-3.5 w-3.5"}),wC[t]]},t)})})]})}function eyt({section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,selectionEnabled:u=!1,selected:d,onSelect:f,onReorderSection:h,draggingSectionId:p,onSectionDragStart:g,onSectionDragEnd:x,onEditTableSection:b,onUpdateTableSection:y,onTableResultColumnsChange:C,surfaceMode:w,tableSlice:N,initialRowsPerPageLimit:S,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D}){const E=F0(e.type),[R,F]=v.useState(null);return c?l.jsxs("section",{className:m.cn("mb-0.5 overflow-hidden rounded transition-shadow",d?"ring-1 ring-zinc-300":"hover:ring-1 hover:ring-zinc-200",R==="before"&&"ring-2 ring-primary/60",R==="after"&&"ring-2 ring-primary/60"),onClick:M=>{M.stopPropagation(),f()},children:[l.jsxs("div",{role:"button",tabIndex:0,"aria-label":`Select ${F2(e,t)} section`,draggable:!!h,className:m.cn("flex items-center gap-1.5 border-b px-3 py-1 outline-none focus-visible:ring-2 focus-visible:ring-ring",d?"bg-zinc-50":"bg-white"),onKeyDown:M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),f())},onDragStart:M=>{M.dataTransfer.effectAllowed="move",M.dataTransfer.setData(nG,e.id),g==null||g(e.id)},onDragOver:M=>{if(h){if(!p||p===e.id){F(null);return}M.preventDefault(),M.dataTransfer.dropEffect="move",F(sG(M))}},onDragLeave:()=>F(null),onDragEnd:()=>{F(null),x==null||x()},onDrop:M=>{if(!h)return;M.preventDefault();const O=M.dataTransfer.getData(nG)||p,z=sG(M);F(null),x==null||x(),!(!O||O===e.id)&&h(O,e.id,z)},children:[l.jsx(Iu,{className:"h-3.5 w-3.5 cursor-grab text-zinc-300"}),l.jsx(E,{className:"h-3.5 w-3.5 shrink-0 text-zinc-400"}),l.jsx("span",{className:"flex-1 text-[11px] text-zinc-500",children:F2(e,t)}),e.type==="table"?l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-6 gap-1.5 px-2 text-[11px] text-zinc-600",onClick:M=>{M.stopPropagation(),b==null||b(e)},children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Edit table"]}):null]}),l.jsx(oG,{section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,surfaceMode:w,onEditTableSection:b,onUpdateTableSection:y,onTableResultColumnsChange:C,tableSlice:N,initialRowsPerPageLimit:S,showInlineEditAction:!c,onTableRowCountChange:j,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D})]}):l.jsx("section",{className:m.cn(u&&"rounded transition-shadow hover:ring-1 hover:ring-zinc-200",d&&"ring-1 ring-zinc-300"),role:u?"button":void 0,tabIndex:u?0:void 0,"aria-label":u?`Select ${F2(e,t)} section`:void 0,onClick:u?M=>{M.stopPropagation(),f()}:void 0,onKeyDown:u?M=>{(M.key==="Enter"||M.key===" ")&&(M.preventDefault(),f())}:void 0,children:l.jsx(oG,{section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:!1,surfaceMode:w,onUpdateTableSection:y,tableSlice:N,initialRowsPerPageLimit:S,onTableRowCountChange:j,onTableResultColumnsChange:C,onTableLayoutMeasure:k,onTableLayoutInvalidate:_,previewRowLimit:T,onPreviewRowLimitChange:I,measurementScale:D})})}function oG({section:e,inputs:t,textRenderContext:n,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c=!0,surfaceMode:u="preview",onEditTableSection:d,onUpdateTableSection:f,onTableResultColumnsChange:h,tableSlice:p,initialRowsPerPageLimit:g,showInlineEditAction:x=!0,onTableRowCountChange:b,onTableLayoutMeasure:y,onTableLayoutInvalidate:C,previewRowLimit:w,onPreviewRowLimitChange:N,measurementScale:S}){if(e.type==="text"){const j=Vy(e.content,t,c,n),k=jd(j);return l.jsx("div",{className:m.cn("whitespace-pre-wrap text-[13px] leading-5 text-zinc-800",c&&"px-3"),style:tyt(e.style),children:k?P0(j,{showVariableChips:c}):c?"Text":null})}return e.type==="table"?l.jsx(Zpe,{section:e,documentFilterValues:r,documentControlDefinitions:o,documentControlValues:s,documentDashboardInputValues:i,missingRequiredInputLabels:a,isEditing:c,surfaceMode:u,onEditTableSection:d,onUpdateTableSection:f,tableSlice:p,initialRowsPerPageLimit:g,showInlineEditAction:x,onTableRowCountChange:b,onTableResultColumnsChange:h,onTableLayoutMeasure:y,onTableLayoutInvalidate:C,previewRowLimit:w,onPreviewRowLimitChange:N,measurementScale:S}):e.type==="spacer"?c?l.jsxs("div",{className:"relative",style:{height:Math.max(8,e.heightPx)},children:[l.jsx("div",{className:"absolute inset-x-0 top-1/2 border-t border-dashed border-zinc-200"}),l.jsxs("span",{className:"absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 bg-white px-1.5 text-[10px] text-zinc-400",children:[e.heightPx,"px"]})]}):l.jsx("div",{style:{height:Math.max(8,e.heightPx)}}):e.type==="page_break"&&c?l.jsxs("div",{className:"flex items-center gap-2 px-3 py-4",children:[l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-200"}),l.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-zinc-400",children:"Page break"}),l.jsx("div",{className:"h-px flex-1 border-t border-dashed border-zinc-200"})]}):null}function sG(e){const t=e.currentTarget.getBoundingClientRect(),n=t.top+t.height/2;return e.clientY>n?"after":"before"}function tyt(e){if(e)return{...e.fontSize?{fontSize:e.fontSize}:{},...e.fontSize?{lineHeight:1.45}:{},...e.fontWeight?{fontWeight:oyt(e.fontWeight)}:{},...e.color?{color:e.color}:{},...e.align?{textAlign:e.align}:{}}}function jd(e){return e.map(t=>t.value).join("")}function P0(e,t={}){return!t.showVariableChips&&e.every(n=>!n.format)?jd(e):e.map((n,r)=>l.jsx("span",{className:m.cn(t.showVariableChips&&n.type==="variable"&&"rounded-[2px] bg-emerald-50 px-0.5 font-mono text-[0.92em] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-200/80"),style:ryt(n),children:n.value},r))}function Vy(e,t,n,r){return n?nyt(e,t):upe(e,r)}function nyt(e,t){return(e||[]).map(n=>n.type==="text"?{type:"text",value:n.value,...n.format?{format:n.format}:{}}:{type:"variable",value:B4(n.ref,t),...n.format?{format:n.format}:{}})}function ryt(e){if(e.format)return{...e.format.bold?{fontWeight:700}:{},...e.format.italic?{fontStyle:"italic"}:{},...e.format.underline?{textDecoration:"underline"}:{}}}function oyt(e){switch(e){case"medium":return 500;case"semibold":return 600;default:return e}}function syt({sectionId:e,tableSlice:t}){return t?`${e}:${t.startIndex}-${t.endIndex}`:e}const iyt=Fse|Pse|Ose,iG="document-text-external-sync";function O0({content:e,inputs:t,multiline:n=!1,disabled:r=!1,onChange:o}){const s=v.useRef(e),i=v.useRef(t);v.useMemo(()=>pyt(e),[e]);const a=v.useMemo(()=>lge(e,t),[e,t]),c=v.useMemo(()=>ige(e||[],t),[e,t]),u=c.unresolvedTokens.length===0&&gyt(e,t)&&!xyt(e,c.content);v.useEffect(()=>{r||!u||o(c.content)},[r,o,c.content,u]);const d=v.useMemo(()=>({namespace:"DocumentTextEditor",nodes:[SC],onError(f){throw f},theme:{text:{bold:"font-semibold",italic:"italic",underline:"underline"}},editorState:()=>{tge(s.current||[],i.current,n)}}),[n]);return l.jsx(hae,{initialConfig:d,children:l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:m.cn("rounded border border-input bg-background focus-within:border-ring",r&&"bg-muted text-muted-foreground"),children:[r?null:l.jsx(lyt,{inputs:t}),l.jsx(Qae,{contentEditable:l.jsx(jae,{"aria-label":"Document text","aria-multiline":n,className:m.cn("min-h-8 w-full px-2 py-1.5 text-[12px] leading-5 outline-none",n?"min-h-28":"whitespace-nowrap",r&&"cursor-not-allowed")}),placeholder:null,ErrorBoundary:kae})]}),l.jsx(Pae,{}),l.jsx(cyt,{content:e||[],disabled:r,inputs:t,multiline:n,onChange:o,syncSignature:a}),c.unresolvedTokens.length>0?l.jsxs("p",{className:"text-[11px] leading-4 text-destructive",children:["Unresolved variable:"," ",c.unresolvedTokens.map(f=>f).join(", ")]}):null]})})}class SC extends vc{constructor(n,r,o){super(r,o);Se(this,"__ref");this.__ref=n}static getType(){return"document-variable"}static clone(n){const r=new SC(n.__ref,n.__text,n.__key);return r.__format=n.__format,r.__style=n.__style,r.__detail=n.__detail,r.__mode=n.__mode,r}static importJSON(n){return Z4(n.ref,n.text).setFormat(n.format).setStyle(n.style).setDetail(n.detail)}static importDOM(){return{}}getRef(){return this.getLatest().__ref}createDOM(n){const r=document.createElement("span");return r.className=cG(this),r.textContent=this.__text,r}updateDOM(n,r){return n.__text!==this.__text&&(r.textContent=this.__text),r.className=cG(this),!1}exportDOM(){return{element:document.createTextNode(`{{${this.__text}}}`)}}exportJSON(){return{...super.exportJSON(),ref:this.__ref,type:"document-variable",version:1}}isTextEntity(){return!0}canInsertTextBefore(){return!1}canInsertTextAfter(){return!1}}function Z4(e,t){return new SC(e,t).setMode("token")}function ayt(e){return e instanceof SC}function lyt({inputs:e}){const[t]=ca(),[n,r]=v.useState({}),o=v.useMemo(()=>Wpt(e),[e]),s=v.useCallback(()=>{const c=Dt();if(!ht(c)){r({});return}r({bold:c.hasFormat("bold"),italic:c.hasFormat("italic"),underline:c.hasFormat("underline")})},[]);v.useEffect(()=>oa(t.registerUpdateListener(({editorState:c})=>{c.read(s)})),[t,s]);const i=c=>{t.dispatchCommand(Wl,c)},a=c=>{t.focus(()=>{t.update(()=>{const u=Z4(c.ref,c.label),d=Dt();if(ht(d)){u.setFormat(d.format&iyt),W_([u,Dr(" ")]);return}const f=kr(),h=f.getLastChild();if(Ze(h))h.append(u,Dr(" "));else{const p=Vr();p.append(u,Dr(" ")),f.append(p)}})})};return l.jsxs("div",{className:"flex h-7 items-center gap-0.5 border-b border-border/60 px-1",children:[l.jsx(H2,{active:!!n.bold,ariaLabel:"Bold",onClick:()=>i("bold"),children:l.jsx(PZ,{className:"h-3 w-3"})}),l.jsx(H2,{active:!!n.italic,ariaLabel:"Italic",onClick:()=>i("italic"),children:l.jsx(rX,{className:"h-3 w-3"})}),l.jsx(H2,{active:!!n.underline,ariaLabel:"Underline",onClick:()=>i("underline"),children:l.jsx(pwe,{className:"h-3 w-3"})}),l.jsx("div",{className:"ml-auto",children:o.length>0?l.jsx(yyt,{choices:o,onInsert:a}):null})]})}function H2({active:e,ariaLabel:t,children:n,onClick:r}){return l.jsx("button",{type:"button","aria-label":t,title:t,onMouseDown:o=>o.preventDefault(),onClick:r,className:m.cn("inline-flex h-5 w-5 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",e&&"bg-muted text-foreground"),children:n})}function cyt({content:e,disabled:t,inputs:n,multiline:r,onChange:o,syncSignature:s}){const[i]=ca(),a=v.useRef(s);return v.useEffect(()=>{i.setEditable(!t)},[t,i]),v.useEffect(()=>{a.current!==s&&(i.update(()=>{tge(e,n,r)},{tag:iG}),a.current=s)},[e,i,n,r,s]),v.useEffect(()=>{if(!r)return i.registerCommand(h0,c=>(c==null||c.preventDefault(),!0),Q7)},[i,r]),v.useEffect(()=>{if(!r)return i.registerCommand(Lw,c=>{const u=dyt(c);if(!u||!/[\r\n]/.test(u))return!1;c.preventDefault();const d=rge(u),f=Dt();return ht(f)?f.insertText(d):W_([Dr(d)]),!0},Q7)},[i,r]),l.jsx(Uae,{ignoreSelectionChange:!0,onChange:(c,u,d)=>{d.has(iG)||c.read(()=>{const f=uyt(n,r),h=lge(f,n);a.current=h,o(f)})}})}function tge(e,t,n){const r=kr();r.clear();let o=Vr();r.append(o);for(const s of n?e:nge(e)){if(s.type==="variable"){const a=Z4(s.ref,B4(s.ref,t));lG(a,s.format),o.append(a);continue}s.value.split(`
1363
1363
  `).forEach((a,c)=>{if(c>0&&(o=Vr(),r.append(o)),a.length===0)return;const u=Dr(a);lG(u,s.format),o.append(u)})}}function uyt(e,t){const n=[],r=[],o=kr(),s=()=>{r.length!==0&&(n.push(...sge(r,e).content),r.length=0)};o.getChildren().forEach((a,c)=>{c>0&&(s(),n.push({type:"text",value:`
1364
1364
  `})),oge(a,n,e,r,s)}),s();const i=UT(n);return t?i:nge(i)}function nge(e){const t=e.map(n=>n.type==="variable"?n:{...n,value:rge(n.value)});return UT(t)}function rge(e){return e.replace(/[\r\n]+/g," ")}function dyt(e){const t="clipboardData"in e?e.clipboardData:void 0;if(aG(t))return t.getData("text/plain");const n="dataTransfer"in e?e.dataTransfer:void 0;return aG(n)?n.getData("text/plain"):""}function aG(e){return typeof e=="object"&&e!==null&&"getData"in e&&typeof e.getData=="function"}function oge(e,t,n,r,o){if(ayt(e)){o();const s=uG(e);t.push({type:"variable",ref:e.getRef(),...s?{format:s}:{}});return}if(Et(e)){const s=e.getTextContent();if(!s)return;r.push({value:s,format:uG(e)});return}if(qh(e)){o(),t.push({type:"text",value:`
1365
- `});return}Ze(e)&&e.getChildren().forEach(s=>oge(s,t,n,r,o))}function sge(e,t){const n=e.map(i=>i.value).join(""),r=fyt(e),o=Kpt(n,t),s=[];for(const i of o.content){if(i.type==="variable"){const a=myt(r,i.sourceStart,i.sourceEnd);s.push({type:"variable",ref:i.ref,...a?{format:a}:{}});continue}hyt(s,n,r,i.sourceStart,i.sourceEnd)}return{content:UT(s),unresolvedTokens:o.unresolvedTokens}}function fyt(e){let t=0;return e.map(n=>{const r=t,o=r+n.value.length;return t=o,{...n,start:r,end:o}})}function hyt(e,t,n,r,o){for(const s of n){const i=Math.max(r,s.start),a=Math.min(o,s.end);i>=a||e.push({type:"text",value:t.slice(i,a),...s.format?{format:s.format}:{}})}}function myt(e,t,n){var o,s,i;const r={};for(const a of e)Math.max(t,a.start)>=Math.min(n,a.end)||(r.bold||(r.bold=(o=a.format)==null?void 0:o.bold),r.italic||(r.italic=(s=a.format)==null?void 0:s.italic),r.underline||(r.underline=(i=a.format)==null?void 0:i.underline));return r.bold||r.italic||r.underline?r:void 0}function lG(e,t){let n=0;t!=null&&t.bold&&(n|=Fse),t!=null&&t.italic&&(n|=Pse),t!=null&&t.underline&&(n|=Ose),e.setFormat(n)}function cG(e){return m.cn("rounded-[2px] bg-emerald-50 px-0.5 font-mono text-[0.92em] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-200/80",e.hasFormat("bold")&&"font-semibold",e.hasFormat("italic")&&"italic",e.hasFormat("underline")&&"underline")}function uG(e){const t={bold:e.hasFormat("bold"),italic:e.hasFormat("italic"),underline:e.hasFormat("underline")};return t.bold||t.italic||t.underline?t:void 0}function ige(e,t){const n=[],r=[],o=[],s=()=>{if(r.length===0)return;const i=sge(r,t);n.push(...i.content),o.push(...i.unresolvedTokens),r.length=0};for(const i of e){if(i.type==="variable"){s(),n.push(i);continue}r.push({value:i.value,format:i.format})}return s(),{content:UT(n),unresolvedTokens:o}}function UT(e){const t=[];for(const n of e){const r=t[t.length-1];if(n.type==="text"&&(r==null?void 0:r.type)==="text"&&age(n.format,r.format)){r.value+=n.value;continue}t.push(n)}return t}function age(e,t){return!!(e!=null&&e.bold)==!!(t!=null&&t.bold)&&!!(e!=null&&e.italic)==!!(t!=null&&t.italic)&&!!(e!=null&&e.underline)==!!(t!=null&&t.underline)}function pyt(e){return JSON.stringify(e||[])}function lge(e,t){return JSON.stringify({content:e||[],variableLabels:(e||[]).filter(n=>n.type==="variable").map(n=>B4(n.ref,t))})}function gyt(e,t){return e!=null&&e.some(n=>n.type==="text")?ige(e,t).content.some(n=>n.type==="variable"):!1}function xyt(e,t){const n=e||[],r=t||[];return n.length!==r.length?!1:n.every((o,s)=>{const i=r[s];return o.type!==i.type||!age(o.format,i.format)?!1:o.type==="text"&&i.type==="text"?o.value===i.value:o.type==="variable"&&i.type==="variable"?o.ref.source!==i.ref.source?!1:o.ref.source==="documentMeta"&&i.ref.source==="documentMeta"?o.ref.key===i.ref.key:o.ref.source==="input"&&i.ref.source==="input"&&o.ref.inputId===i.ref.inputId&&o.ref.export===i.ref.export:!1})}function byt(e){const t=new Map,n={key:"__document__",label:"Document",choices:[]};for(const o of e){if(o.ref.source==="documentMeta"){n.choices.push(o);continue}const s=o.label.split(".")[0];let i=t.get(s);i||(i={key:`input:${s}`,label:s,choices:[]},t.set(s,i)),i.choices.push(o)}const r=Array.from(t.values());return n.choices.length>0?[...r,n]:r}function yyt({choices:e,onInsert:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(""),i=v.useMemo(()=>byt(e),[e]),a=v.useMemo(()=>{const u=o.trim().toLowerCase();return u?i.map(d=>({...d,choices:d.choices.filter(f=>f.label.toLowerCase().includes(u)||f.token.toLowerCase().includes(u))})).filter(d=>d.choices.length>0):i},[i,o]);function c(u){t(u),s(""),r(!1)}return l.jsxs(m.Popover,{open:n,onOpenChange:r,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Insert variable",title:"Insert variable",className:"inline-flex h-5 items-center gap-0.5 rounded-[3px] border border-transparent px-1.5 text-[10px] font-medium text-muted-foreground transition-colors hover:border-border hover:bg-muted hover:text-foreground",children:[l.jsx(Ar,{className:"h-2.5 w-2.5"}),"Variable"]})}),l.jsxs(m.PopoverContent,{align:"end",side:"bottom",sideOffset:6,className:"w-72 p-0",children:[l.jsxs("div",{className:"flex items-center gap-2 border-b border-border/60 px-2.5 py-1.5",children:[l.jsx(Ft.Search,{className:"h-3 w-3 text-muted-foreground"}),l.jsx("input",{type:"text",value:o,onChange:u=>s(u.target.value),placeholder:"Search variables...",autoFocus:!0,className:"h-6 flex-1 bg-transparent text-[12px] outline-none placeholder:text-[hsl(var(--semaphor-placeholder-foreground))]"})]}),l.jsx("div",{className:"max-h-[280px] overflow-y-auto p-1",children:a.length===0?l.jsxs("div",{className:"px-2 py-3 text-[12px] text-muted-foreground",children:['No matches for "',o,'".']}):a.map(u=>l.jsxs("div",{className:"space-y-0.5 pb-1",children:[l.jsx("div",{className:"px-2 pb-0.5 pt-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:u.label}),u.choices.map(d=>l.jsx("button",{type:"button",onClick:()=>c(d),className:"flex w-full items-center justify-between gap-2 rounded-[4px] px-2 py-1 text-left transition-colors hover:bg-muted",children:l.jsx("span",{className:"truncate font-mono text-[11px] text-foreground",children:d.label})},d.token))]},u.key))})]})]})}function Go({label:e,children:t}){return l.jsxs("div",{children:[l.jsx("label",{className:"mb-1 block text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),t]})}function cge({label:e,enabled:t,onToggle:n}){return l.jsxs("label",{className:"flex h-8 cursor-pointer items-center justify-between gap-3 rounded-[5px] border border-border/60 bg-background px-2.5 text-[12px]",children:[l.jsx("span",{className:m.cn(t?"text-foreground":"text-muted-foreground"),children:e}),l.jsx(m.Switch,{size:"sm",checked:t,onCheckedChange:n})]})}function uge({columns:e,columnVisibility:t,onColumnVisibilityChange:n,onShowAllColumns:r,emptyMessage:o="Run the query or add fields to configure output columns.",helperText:s="Hidden columns stay available for conditional formatting triggers, but are omitted from table output and exports.",className:i}){const a=Object.values(t||{}).filter(c=>c===!1).length;return e.length===0?l.jsx("div",{className:m.cn("space-y-3",i),children:l.jsx("p",{className:"rounded-[6px] border border-dashed border-border/60 px-3 py-4 text-[12px] leading-5 text-muted-foreground",children:o})}):l.jsxs("div",{className:m.cn("space-y-3",i),children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsx("p",{className:"text-[12px] leading-5 text-muted-foreground",children:s}),l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"h-6 shrink-0 px-2 text-[11px]",disabled:a===0,onClick:r,children:"Show all"})]}),l.jsx("div",{className:"overflow-hidden rounded-[6px] border border-border/60 bg-background",children:l.jsx("div",{className:"max-h-[calc(100vh-260px)] divide-y divide-border/60 overflow-y-auto",children:e.map(c=>{const u=zoe(t,c.value);return l.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 px-3 py-2 transition-colors hover:bg-muted/40",children:[l.jsxs("span",{className:"min-w-0",children:[l.jsx("span",{className:"block truncate text-[13px] font-medium text-foreground",children:c.label}),c.label!==c.value?l.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:c.value}):null]}),l.jsx(m.Switch,{size:"xs",checked:u,"aria-label":`${u?"Hide":"Show"} ${c.label}`,onCheckedChange:d=>n(c.value,d)})]},c.value)})})})]})}const vyt=[null,"#fee2e2","#fef3c7","#dcfce7","#dbeafe","#ede9fe","#ffe4e6","#f4f4f5"],wyt=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function dge(e){return typeof e=="string"&&wyt.test(e)}function Cyt(e){const t=e.trim();return t?t.startsWith("#")?t:`#${t}`:""}function Syt(e,t="#000000"){if(dge(e)){if(e.length===7)return e;if(e.length===4){const n=e[1],r=e[2],o=e[3];return`#${n}${n}${r}${r}${o}${o}`}if(e.length===9)return e.slice(0,7)}return t}const Nyt=120;function Na({value:e,onChange:t,defaultValue:n,allowEmpty:r=!0,presets:o=vyt,ariaLabel:s,placeholder:i="#000000",id:a,className:c,disabled:u=!1}){const[d,f]=ie.useState(!1),[h,p]=ie.useState(e??""),[g,x]=ie.useState(e),b=ie.useRef(null),y=ie.useRef(void 0),C=ie.useRef(t);ie.useEffect(()=>{C.current=t},[t]),ie.useEffect(()=>{b.current===null&&(p(e??""),x(e))},[e]),ie.useEffect(()=>()=>{b.current!==null&&clearTimeout(b.current)},[]);const w=ie.useCallback(()=>{if(b.current===null)return;clearTimeout(b.current),b.current=null;const T=y.current;y.current=void 0,T!==void 0&&C.current(T)},[]),N=ie.useCallback(T=>{x(T),p(T),y.current=T,b.current!==null&&clearTimeout(b.current),b.current=setTimeout(()=>{const I=y.current;b.current=null,y.current=void 0,I!==void 0&&C.current(I)},Nyt)},[]),S=ie.useCallback(T=>{b.current!==null&&(clearTimeout(b.current),b.current=null,y.current=void 0),x(T),t(T)},[t]),j=g??e,k=n!==void 0&&(j??void 0)!==n,_=T=>{const I=Cyt(T);if(!I){if(r){S(void 0);return}p(e??"");return}if(dge(I)){S(I),p(I);return}p(e??"")};return l.jsxs("div",{className:m.cn("flex h-7 items-center gap-1.5",c),children:[l.jsxs(m.Popover,{open:d,onOpenChange:T=>{T||w(),f(T)},children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx("button",{type:"button",disabled:u,"aria-label":s?`Pick ${s}`:"Pick a color",className:m.cn("relative size-6 shrink-0 overflow-hidden rounded-[5px] border border-border/60 transition-colors","hover:border-border","focus-visible:border-ring focus-visible:outline-none",u&&"cursor-not-allowed opacity-50"),style:j?{backgroundColor:j}:{backgroundImage:"linear-gradient(to top right, transparent calc(50% - 0.5px), hsl(var(--border)) calc(50% - 0.5px), hsl(var(--border)) calc(50% + 0.5px), transparent calc(50% + 0.5px))"}})}),l.jsxs(m.PopoverContent,{align:"start",sideOffset:6,className:"z-[60] w-[220px] space-y-2.5 rounded-[6px] p-2.5",children:[l.jsx("div",{className:"flex flex-wrap items-center gap-1",children:o.map((T,I)=>{const D=T===null,E=(j??null)===T||T!==null&&(j==null?void 0:j.toLowerCase())===T.toLowerCase(),R=()=>{if(D){r&&S(void 0);return}S(T)};return D&&!r?null:l.jsx("button",{type:"button",onClick:R,"aria-label":D?"No color":T,className:m.cn("relative flex size-6 items-center justify-center rounded-[4px] border transition-colors",E?"border-foreground":"border-border/60 hover:border-border"),style:D?{backgroundImage:"linear-gradient(to top right, transparent calc(50% - 0.5px), hsl(var(--border)) calc(50% - 0.5px), hsl(var(--border)) calc(50% + 0.5px), transparent calc(50% + 0.5px))"}:{backgroundColor:T??void 0},children:E&&!D&&l.jsx(m.Check,{className:"size-3",strokeWidth:3,style:{color:"#fff",mixBlendMode:"difference"}})},`${T??"none"}-${I}`)})}),l.jsx("div",{className:"h-px bg-border/60"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{type:"color","aria-label":"Custom color",value:Syt(j),onChange:T=>N(T.target.value),onBlur:w,className:"h-7 w-10 shrink-0 cursor-pointer rounded-[5px] border border-border/60 bg-background p-0.5"}),l.jsx(m.Input,{size:"xs",value:h,onChange:T=>p(T.target.value),onBlur:T=>_(T.target.value),onKeyDown:T=>{T.key==="Enter"?(_(h),f(!1)):T.key==="Escape"&&(p(e??""),f(!1))},placeholder:i,className:m.cn("w-full font-mono text-[11px]",m.removeRing)})]}),l.jsxs("div",{className:"flex items-center justify-between pt-0.5",children:[k?l.jsxs("button",{type:"button",onClick:()=>S(n),className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[l.jsx(m.RotateCcw,{className:"size-3"}),"Reset to default"]}):l.jsx("span",{}),l.jsx("button",{type:"button",onClick:()=>{w(),f(!1)},className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground","aria-label":"Close color picker",children:"Done"})]})]})]}),l.jsx(m.Input,{size:"xs",id:a,"aria-label":s,value:h,onChange:T=>p(T.target.value),onBlur:T=>_(T.target.value),onKeyDown:T=>{T.key==="Enter"?(_(h),T.target.blur()):T.key==="Escape"&&(p(e??""),T.target.blur())},placeholder:i,disabled:u,className:m.cn("w-full font-mono text-[11px]",m.removeRing)}),k&&l.jsx("button",{type:"button",onClick:()=>S(n),"aria-label":"Reset color",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(m.RotateCcw,{className:"size-3"})})]})}function fge({style:e,onDensityChange:t,onStyleChange:n,totals:r,showFullStyle:o=!0,showBorderStyle:s=!0,extraSection:i,onReset:a,className:c}){const u=(r==null?void 0:r.enabled)??e.totalsStyle.enabled,d=!!r,f=!!(r!=null&&r.onStyleChange)&&(u||!(r!=null&&r.onEnabledChange)),h=vse[e.headerStyle],p=x=>{n({headerBackgroundColor:x===h.background?void 0:x})},g=x=>{n({headerTextColor:x===h.color?void 0:x})};return l.jsxs("div",{className:m.cn("space-y-5",c),children:[l.jsxs(C1,{label:"Layout",children:[l.jsx(Il,{label:"Density",children:l.jsxs(m.Select,{value:e.density,onValueChange:x=>t(x),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table density",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:gse.map(x=>l.jsx(m.SelectItem,{value:x,children:E4e[x]},x))})]})}),o&&l.jsx(S1,{label:"Wrap text",checked:e.wrapText,onCheckedChange:x=>n({wrapText:x})})]}),o&&l.jsxs(l.Fragment,{children:[l.jsxs(C1,{label:"Header",children:[l.jsx(S1,{label:"Wrap header",checked:e.headerWrapText,onCheckedChange:x=>n({headerWrapText:x})}),l.jsx(Il,{label:"Style",children:l.jsxs(m.Select,{value:e.headerStyle,onValueChange:x=>n({headerStyle:x}),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table header style",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:xse.map(x=>l.jsx(m.SelectItem,{value:x,children:M4e[x]},x))})]})}),l.jsx(Il,{label:"Background",children:l.jsx(Na,{value:e.headerBackgroundColor,onChange:p,defaultValue:h.background,allowEmpty:!1,ariaLabel:"Header background"})}),l.jsx(Il,{label:"Text",children:l.jsx(Na,{value:e.headerTextColor,onChange:g,defaultValue:h.color,allowEmpty:!1,ariaLabel:"Header text"})})]}),l.jsxs(C1,{label:"Rows",children:[s&&l.jsx(Il,{label:"Borders",children:l.jsxs(m.Select,{value:e.gridLines,onValueChange:x=>n({gridLines:x}),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table borders",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:bse.map(x=>l.jsx(m.SelectItem,{value:x,children:R4e[x]},x))})]})}),l.jsx(S1,{label:"Row striping",checked:e.stripedRows,onCheckedChange:x=>n({stripedRows:x})})]})]}),o&&d&&l.jsxs(C1,{label:"Totals",action:r!=null&&r.onEnabledChange?l.jsx(m.Switch,{size:"xs","aria-label":"Show totals row",checked:u,onCheckedChange:x=>{var b;return(b=r==null?void 0:r.onEnabledChange)==null?void 0:b.call(r,!!x)}}):null,children:[r!=null&&r.helperText?l.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:r.helperText}):null,f?l.jsxs(l.Fragment,{children:[l.jsx(Il,{label:"Background",children:l.jsx(Na,{value:e.totalsStyle.backgroundColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{backgroundColor:x})},defaultValue:ka.backgroundColor,allowEmpty:!1,ariaLabel:"Totals background"})}),l.jsx(Il,{label:"Text",children:l.jsx(Na,{value:e.totalsStyle.textColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{textColor:x})},defaultValue:ka.textColor,allowEmpty:!1,ariaLabel:"Totals text"})}),l.jsx(Il,{label:"Weight",children:l.jsxs(m.Select,{value:e.totalsStyle.fontWeight,onValueChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{fontWeight:x})},children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table totals weight",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:yse.map(x=>l.jsx(m.SelectItem,{value:x,children:A4e[x]},x))})]})}),l.jsx(S1,{label:"Top border",checked:e.totalsStyle.borderTop,onCheckedChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTop:x})}}),e.totalsStyle.borderTop?l.jsxs(l.Fragment,{children:[l.jsx(Il,{label:"Border style",children:l.jsxs(m.Select,{value:e.totalsStyle.borderTopStyle,onValueChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTopStyle:x})},children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table totals border style",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:F4e.map(x=>l.jsx(m.SelectItem,{value:x,children:P4e[x]},x))})]})}),l.jsx(Il,{label:"Border color",children:l.jsx(Na,{value:e.totalsStyle.borderTopColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTopColor:x})},defaultValue:ka.borderTopColor,allowEmpty:!1,ariaLabel:"Totals border color"})})]}):null]}):null]}),i,a?l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"w-full",onClick:a,children:"Reset appearance"}):null]})}function C1({label:e,action:t,children:n}){return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),t]}),l.jsx("div",{className:"space-y-2",children:n})]})}function Il({label:e,htmlFor:t,children:n}){return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("label",{htmlFor:t,className:"w-20 shrink-0 text-[12px] text-foreground",children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:n})]})}function S1({label:e,checked:t,onCheckedChange:n}){return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"w-20 shrink-0 text-[12px] text-foreground",children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:l.jsx(m.Switch,{size:"xs",checked:t,onCheckedChange:r=>n(!!r)})})]})}const wa="__semaphor_unassigned_trigger__";function hge(e){return e==="table"}function jyt(e){return e.label||e.alias||e.name||e.id||""}function kyt(e){return e.alias||e.name||e.id||e.label||""}function Iyt(e){var n,r,o;const t=((o=(r=(n=e==null?void 0:e.preferences)==null?void 0:n.tablePrefs)==null?void 0:r.conditionalFormatting)==null?void 0:o.rules)||[];return new Set(t.flatMap(s=>[s.condition.columnId,...s.target.columnIds||[],...s.target.applyToColumnIds||[]]).filter(s=>s&&s!==wa))}function uO(e,t,n){t&&t!==wa&&(e.has(t)||e.set(t,{value:t,label:n||m.toLabel(t)}))}function mge(e,t=[],n){const r=ZI(e,t,n),o=new Map(r.options.map(s=>[s.value,s]));return Iyt(e).forEach(s=>{const i=r.resolveColumnId(s);o.has(i)||uO(o,i,`${m.toLabel(s)} (unavailable)`)}),Array.from(o.values())}function pge(e,t=[]){const n=new Map;if(t.length>0)return t.forEach(s=>uO(n,s,s)),Array.from(n.values());const r=e==null?void 0:e.config;return[...(r==null?void 0:r.detailColumns)||[],...(r==null?void 0:r.groupByColumns)||[],...(r==null?void 0:r.metricColumns)||[],...(r==null?void 0:r.pivotByColumns)||[]].forEach(s=>{uO(n,kyt(s),jyt(s))}),Array.from(n.values())}function _yt(e,t){var n;return{...e,preferences:{...e.preferences,tablePrefs:{...(n=e.preferences)==null?void 0:n.tablePrefs,conditionalFormatting:t}}}}const gge=[{value:"gt",label:"Greater than"},{value:"gte",label:"Greater than or equal"},{value:"lt",label:"Less than"},{value:"lte",label:"Less than or equal"},{value:"eq",label:"Equals"},{value:"neq",label:"Does not equal"},{value:"between",label:"Between"},{value:"contains",label:"Contains"},{value:"blank",label:"Is blank"},{value:"notBlank",label:"Is not blank"}];function KT(e){return e===wa}function q2(e){return e!=null&&String(e).trim()!==""}function dG(e){return typeof e=="number"&&Number.isFinite(e)}function Tyt(e){return e.condition.kind==="comparison"||e.condition.kind==="between"||e.condition.kind==="contains"||e.condition.kind==="blank"?"comparison":e.condition.kind}function xge(e){return e.condition.kind==="blank"?e.condition.isBlank?"blank":"notBlank":e.condition.kind==="contains"?"contains":e.condition.kind==="between"?"between":e.condition.kind==="comparison"?e.condition.operator:"gt"}function dO(e){return e.condition.kind==="comparison"||e.condition.kind==="contains"?String(e.condition.value??""):e.condition.kind==="between"?String(e.condition.min??""):""}function Dyt(e){return e.condition.kind==="between"?String(e.condition.max??""):""}function hy(e){return typeof e=="number"&&Number.isFinite(e)?String(e):""}function my(e){if(!e.trim())return;const t=Number(e);return Number.isFinite(t)?t:void 0}function Eyt(e,t){const n=Number(e);return Number.isFinite(n)?n:t}function Myt(e){var n;if(KT(e.condition.columnId))return"Select a trigger column";const t=e.condition;return t.kind==="comparison"?`${(((n=gge.find(o=>o.value===t.operator))==null?void 0:n.label)??t.operator).toLowerCase()} ${t.value??""}`.trim():t.kind==="between"?`between ${t.min??"?"}...${t.max??"?"}`:t.kind==="contains"?`contains "${t.value??""}"`:t.kind==="blank"?t.isBlank?"is blank":"is not blank":t.kind==="topBottom"?`${t.direction} ${t.count}`:t.kind==="colorScale"?t.range==="manual"?`scale ${t.min??"auto"}...${t.max??"auto"}`:"scale (auto)":t.kind==="dataBar"?t.range==="manual"?`bar ${t.min??"auto"}...${t.max??"auto"}`:"bar (auto)":""}function bge(e){return KT(e.condition.columnId)?"":e.condition.columnId}function fO(e){const t=new Map;return e.forEach(n=>{const r=typeof n=="string"?{value:n,label:n}:n;!r.value||t.has(r.value)||t.set(r.value,{value:r.value,label:r.label||r.value})}),Array.from(t.values())}function Ryt(e,t){var r,o;const n=((o=(r=globalThis.crypto)==null?void 0:r.randomUUID)==null?void 0:o.call(r))??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return`cf-${e||"unassigned"}-${t}-${n}`}function ug(e){return e.condition.kind==="colorScale"||e.condition.kind==="dataBar"}function Ayt(e){return e==="colorScale"||e==="dataBar"}function Yh(e){if(KT(e.condition.columnId))return!1;switch(e.condition.kind){case"comparison":case"contains":return q2(e.condition.value);case"between":return q2(e.condition.min)&&q2(e.condition.max);case"blank":case"topBottom":return!0;case"colorScale":case"dataBar":return e.condition.range==="manual"?dG(e.condition.min)&&dG(e.condition.max):!0;default:return!1}}function Hy(e,t){return Yh(t)?e.enabled===!1&&!Yh(e)&&Yh(t)?{...t,enabled:!0}:t:{...t,enabled:!1}}function Fyt(e){return Yh(e)?e:{...e,enabled:!1}}function Pyt({columnId:e,columnLabel:t,existingRule:n,index:r,kind:o="comparison",operator:s="gt",value:i="",conditionColumnId:a}){var g,x,b,y,C;const c=a??(n==null?void 0:n.condition.columnId)??e,u=KT(c),d=Ayt(o),f=u?"":d?c:e||c;if(!f&&!c)return;const h={id:(n==null?void 0:n.id)??Ryt(u?"unassigned":f||c,o),name:(n==null?void 0:n.name)??`${u?"New formatting":t||f||"New formatting"} rule ${r+1}`,enabled:(n==null?void 0:n.enabled)??!u,target:{level:"cell",columnIds:!d&&((g=n==null?void 0:n.target.columnIds)!=null&&g.length)?n.target.columnIds:f?[f]:void 0,applyToColumnIds:n==null?void 0:n.target.applyToColumnIds,tableParts:["body"]},style:{backgroundColor:((x=n==null?void 0:n.style)==null?void 0:x.backgroundColor)??"#fee2e2",textColor:((b=n==null?void 0:n.style)==null?void 0:b.textColor)??"#b91c1c",fontWeight:(y=n==null?void 0:n.style)==null?void 0:y.fontWeight,italic:(C=n==null?void 0:n.style)==null?void 0:C.italic}},p=w=>n?Hy(n,w):Fyt(w);if(o==="topBottom"){const w=(n==null?void 0:n.condition.kind)==="topBottom"?n.condition:void 0;return p({...h,condition:{kind:"topBottom",columnId:c||wa,direction:(w==null?void 0:w.direction)??"top",count:(w==null?void 0:w.count)??10}})}if(o==="colorScale"){const w=(n==null?void 0:n.condition.kind)==="colorScale"?n.condition:void 0;return p({...h,style:void 0,condition:{kind:"colorScale",columnId:c||wa,range:(w==null?void 0:w.range)??"auto",min:w==null?void 0:w.min,mid:w==null?void 0:w.mid,max:w==null?void 0:w.max,colors:(w==null?void 0:w.colors)??{min:"#fee2e2",mid:"#fef3c7",max:"#dcfce7"}}})}if(o==="dataBar"){const w=(n==null?void 0:n.condition.kind)==="dataBar"?n.condition:void 0;return p({...h,style:void 0,condition:{kind:"dataBar",columnId:c||wa,range:(w==null?void 0:w.range)??"auto",min:w==null?void 0:w.min,max:w==null?void 0:w.max,color:(w==null?void 0:w.color)??"#3b82f6",showValue:(w==null?void 0:w.showValue)!==!1}})}if(s==="blank"||s==="notBlank")return p({...h,condition:{kind:"blank",columnId:c||wa,isBlank:s==="blank"}});if(s==="contains")return p({...h,condition:{kind:"contains",columnId:c||wa,value:String(i??"")}});if(s==="between"){const w=(n==null?void 0:n.condition.kind)==="between"?n.condition:void 0;return p({...h,condition:{kind:"between",columnId:c||wa,min:i,max:(w==null?void 0:w.max)??"",inclusive:(w==null?void 0:w.inclusive)!==!1}})}return p({...h,condition:{kind:"comparison",columnId:c||wa,operator:s,value:i}})}const Oyt=[{value:"comparison",label:"Compare"},{value:"topBottom",label:"Top/Bot."},{value:"colorScale",label:"Scale"},{value:"dataBar",label:"Data bar"}],Lyt=[{name:"none",bg:void 0,text:void 0},{name:"red",bg:"#fee2e2",text:"#b91c1c"},{name:"amber",bg:"#fef3c7",text:"#92400e"},{name:"emerald",bg:"#dcfce7",text:"#15803d"},{name:"sky",bg:"#dbeafe",text:"#1d4ed8"},{name:"zinc",bg:"#f4f4f5",text:"#52525b"}],$yt=["#fb923c","#22c55e","#3b82f6","#a855f7","#ec4899","#71717a"],zyt={emerald:["#fee2e2","#fef3c7","#dcfce7"],sky:["#fee2e2","#fef3c7","#dbeafe"],rose:["#dcfce7","#fef3c7","#fee2e2"],zinc:["#fef2f2","#f4f4f5","#e4e4e7"]};function Ap({value:e,onChange:t,options:n,ariaLabel:r}){return l.jsx("div",{role:"radiogroup","aria-label":r,className:"inline-flex h-7 w-fit max-w-full items-center rounded-[5px] border border-border/60 bg-background p-0.5",children:n.map(o=>{const s=o.value===e;return l.jsx("button",{type:"button",role:"radio","aria-checked":s,"aria-label":o.ariaLabel??String(o.label),disabled:o.disabled,onClick:()=>t(o.value),className:m.cn("inline-flex h-full items-center rounded-[4px] px-2 text-[11px] font-medium transition-colors",o.disabled?"cursor-not-allowed text-muted-foreground/40":s?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"),children:o.label},o.value)})})}function Byt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:Lyt.map(n=>{const r=(e??"none")===(n.bg??"none");return l.jsx("button",{type:"button",onClick:()=>t(n.bg,n.text),"aria-label":n.name,className:m.cn("flex h-6 w-6 items-center justify-center rounded-[4px] border transition-colors",r?"border-foreground":"border-border/60 hover:border-border"),style:{backgroundColor:n.bg??"transparent"},children:r&&l.jsx(m.Check,{className:"size-3",strokeWidth:3,style:{color:n.text??"currentColor"}})},n.name)})})}function Vyt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:Object.entries(zyt).map(([n,r])=>{const[o,s,i]=r,a=e.min===o&&e.max===i;return l.jsx("button",{type:"button","aria-label":n,onClick:()=>t({min:o,mid:s,max:i}),className:m.cn("flex h-6 w-7 items-center justify-center rounded-[4px] border transition-colors",a?"border-foreground":"border-border/60 hover:border-border"),style:{background:`linear-gradient(to right, ${o}, ${s}, ${i})`},children:a&&l.jsx(m.Check,{className:"size-3 text-foreground mix-blend-difference",strokeWidth:3,style:{color:"#fff"}})},n)})})}function Hyt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:$yt.map(n=>{const r=e===n;return l.jsx("button",{type:"button","aria-label":n,onClick:()=>t(n),className:m.cn("flex h-6 w-6 items-center justify-center rounded-[4px] border transition-colors",r?"border-foreground":"border-border/60 hover:border-border"),style:{backgroundColor:n},children:r&&l.jsx(m.Check,{className:"size-3 text-white",strokeWidth:3})},n)})})}function qyt({rule:e}){var o,s;const t=e.condition;if(t.kind==="colorScale")return l.jsx("span",{"aria-hidden":!0,className:"inline-block h-3 w-7 shrink-0 rounded-[3px] border border-border/60",style:{background:`linear-gradient(to right, ${t.colors.min}, ${t.colors.mid??t.colors.max}, ${t.colors.max})`}});if(t.kind==="dataBar")return l.jsx("span",{"aria-hidden":!0,className:"relative inline-block h-3 w-7 shrink-0 overflow-hidden rounded-[3px] border border-border/60 bg-muted",children:l.jsx("span",{className:"absolute inset-y-0 left-0 w-3/5",style:{backgroundColor:t.color}})});const n=(o=e.style)==null?void 0:o.backgroundColor,r=(s=e.style)==null?void 0:s.textColor;return l.jsx("span",{"aria-hidden":!0,className:"inline-flex h-3 w-7 shrink-0 items-center justify-center rounded-[3px] border border-border/60 text-[8px] font-bold leading-none",style:{backgroundColor:n??"transparent",color:r??"currentColor"},children:"Aa"})}function py({label:e,children:t}){return l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),l.jsx("div",{className:"flex flex-col gap-1.5",children:t})]})}function Ur({label:e,htmlFor:t,children:n,align:r="center"}){return l.jsxs("div",{className:m.cn("flex gap-2",r==="start"?"items-start":"items-center"),children:[l.jsx("label",{htmlFor:t,className:m.cn("w-20 shrink-0 text-[11px] text-muted-foreground",r==="start"&&"pt-1.5"),children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:n})]})}function _l({value:e,onValueChange:t,commitDelayMs:n=250,onBlur:r,onKeyDown:o,...s}){const[i,a]=v.useState(e),c=v.useRef(e),u=v.useRef(t);v.useEffect(()=>{u.current=t},[t]),v.useEffect(()=>{c.current=e,a(e)},[e]);const d=v.useCallback(f=>{f!==c.current&&(c.current=f,v.startTransition(()=>{u.current(f)}))},[]);return v.useEffect(()=>{if(i===c.current)return;const f=window.setTimeout(()=>d(i),n);return()=>window.clearTimeout(f)},[n,d,i]),l.jsx(m.Input,{...s,value:i,onChange:f=>a(f.target.value),onBlur:f=>{d(f.currentTarget.value),r==null||r(f)},onKeyDown:f=>{f.key==="Enter"&&d(f.currentTarget.value),o==null||o(f)}})}function yge({columnId:e,availableColumns:t=[],conditionalRules:n,onConditionalRulesChange:r,startRulesWithNoTrigger:o=!1,capabilities:s}){const[i,a]=v.useState(()=>n.length===1?new Set([n[0].id]):new Set);if(v.useEffect(()=>{a(I=>{const D=new Set(n.map(F=>F.id));let E=!1;const R=new Set(I);for(const F of R)D.has(F)||(R.delete(F),E=!0);return E?R:I})},[n]),!r)return null;const c=I=>{var E,R;const D=Pyt(I);if(D&&(s!=null&&s.separateApplyTargets)&&I.existingRule&&!ug(D)&&!ug(I.existingRule)&&(D.target=I.existingRule.target),D&&((E=I.existingRule)!=null&&E.target.matrix)&&(D.target={...D.target,matrix:I.existingRule.target.matrix}),D&&(s!=null&&s.targetScope)){const F=(R=I.existingRule)==null?void 0:R.target;D.target={...D.target,matrix:F==null?void 0:F.matrix,rowRoles:F?F.rowRoles:s.targetScope.defaultRowRoles,tableParts:F==null?void 0:F.tableParts,depth:F==null?void 0:F.depth,includeTotals:F==null?void 0:F.includeTotals,includeSubtotals:F==null?void 0:F.includeSubtotals}}return D},u=I=>{a(D=>{const E=new Set(D);return E.has(I)?E.delete(I):E.add(I),E})},d=(I,D)=>{r(n.map((E,R)=>E.id===I?D(E,R):E))},f=()=>{var D;const I=c({columnId:e,columnLabel:(D=fO(t).find(E=>E.value===e))==null?void 0:D.label,index:n.length,kind:"comparison",conditionColumnId:o?wa:void 0});I&&(a(E=>new Set(E).add(I.id)),r([...n,I]))},h=I=>{const D=n.findIndex(M=>M.id===I);if(D<0)return;const E=n[D],R={...E,id:`${E.id}-copy-${Date.now()}`,name:`${E.name??"Rule"} (copy)`},F=[...n];F.splice(D+1,0,R),a(M=>new Set(M).add(R.id)),r(F)},p=I=>{r(n.filter(D=>D.id!==I))},g=(I,D)=>{const E=n.findIndex(O=>O.id===I),R=E+D;if(E<0||R<0||R>=n.length)return;const F=[...n],[M]=F.splice(E,1);F.splice(R,0,M),r(F)},x=(I,D,E)=>{if(s&&!s.ruleKinds.includes(D))return;const R=c({columnId:e,existingRule:I,index:E,kind:D});R&&((s==null?void 0:s.automaticRanges)===!1&&(R.condition.kind==="colorScale"||R.condition.kind==="dataBar")&&(R.condition={...R.condition,range:"manual"},R.enabled=Yh(R)),r(n.map(F=>F.id===I.id?R:F)))},b=(I,D,E)=>{r(n.map(R=>R.id===I.id?c({columnId:e,existingRule:R,index:E,kind:"comparison",operator:D,value:dO(R)}):R))},y=(I,D,E)=>{r(n.map(R=>R.id===I.id?c({columnId:e,existingRule:R,index:E,kind:"comparison",operator:xge(R),value:D}):R))},C=(I,D)=>{d(I,E=>E.condition.kind==="between"?Hy(E,{...E,condition:{...E.condition,max:D}}):E)},w=(I,D)=>{d(I,E=>({...E,style:{...E.style,...D}}))},N=(I,D)=>{d(I,E=>E.condition.kind==="topBottom"?{...E,condition:{...E.condition,...D,count:D.count!==void 0?Math.max(1,Math.floor(D.count)):E.condition.count}}:E)},S=(I,D)=>{d(I,E=>E.condition.kind==="colorScale"?Hy(E,{...E,condition:{...E.condition,...D,colors:{...E.condition.colors,...D.colors}}}):E)},j=(I,D)=>{d(I,E=>E.condition.kind==="dataBar"?Hy(E,{...E,condition:{...E.condition,...D}}):E)},k=(I,D)=>{d(I,E=>{const R={...E,target:E.target.level==="cell"&&(!(s!=null&&s.separateApplyTargets)||ug(E))?{...E.target,columnIds:[D]}:E.target,condition:{...E.condition,columnId:D}};return s!=null&&s.separateApplyTargets&&(R.target={...R.target,conditionColumnId:D}),Hy(E,R)})},_=(I,D)=>{d(I,E=>{var M,O,z;if(ug(E)&&D==="row")return E;const R=bge(E),F=((M=E.target.columnIds)==null?void 0:M[0])||R||void 0;return{...E,target:D==="row"?{...E.target,level:"row",columnIds:void 0,applyToColumnIds:E.target.applyToColumnIds,tableParts:s!=null&&s.targetScope||(O=E.target.tableParts)!=null&&O.length?E.target.tableParts:["body"]}:{...E.target,level:"cell",columnIds:F?[F]:void 0,applyToColumnIds:void 0,tableParts:s!=null&&s.targetScope||(z=E.target.tableParts)!=null&&z.length?E.target.tableParts:["body"]}}})},T=n.filter(I=>I.enabled!==!1).length;return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex flex-col",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Conditional formatting"}),n.length>0&&l.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[T," enabled · ",n.length," total"]})]}),l.jsxs(m.Button,{type:"button",variant:"ghost",size:"xs",disabled:!e,onClick:f,className:"h-6 gap-1 px-2 text-[12px]",children:[l.jsx(Ar,{className:"size-3"}),"Add rule"]})]}),n.length===0?l.jsx("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"No conditional formatting rules for this column."}):l.jsx("ol",{className:"overflow-hidden rounded-[6px] border border-border/60",children:n.map((I,D)=>{const E=i.has(I.id);return l.jsxs("li",{className:"border-b border-border/60 bg-background last:border-b-0",children:[l.jsx(Uyt,{rule:I,index:D,expanded:E,isFirst:D===0,isLast:D===n.length-1,onToggleExpand:()=>u(I.id),onToggleEnabled:R=>d(I.id,F=>R&&!Yh(F)?F:{...F,enabled:R}),onMoveUp:()=>g(I.id,-1),onMoveDown:()=>g(I.id,1),onDuplicate:()=>h(I.id),onDelete:()=>p(I.id)}),E&&l.jsx(Kyt,{capabilities:s,onUpdateApplyColumn:R=>d(I.id,F=>({...F,target:{...F.target,columnIds:[R]}})),onUpdateTotals:R=>d(I.id,F=>({...F,target:{...F.target,tableParts:R?["body","subtotal","grandTotal"]:["body"],includeTotals:R,includeSubtotals:R}})),rule:I,index:D,onUpdateName:R=>d(I.id,F=>({...F,name:R})),onUpdateRuleKind:R=>x(I,R,D),onUpdateConditionalOperator:R=>b(I,R,D),onUpdateConditionalValue:R=>y(I,R,D),onUpdateConditionalMaxValue:R=>C(I.id,R),onUpdateStyle:R=>w(I.id,R),onUpdateTopBottom:R=>N(I.id,R),onUpdateColorScale:R=>S(I.id,R),onUpdateDataBar:R=>j(I.id,R),availableColumns:t,onUpdateConditionColumn:R=>k(I.id,R),onUpdateTargetLevel:R=>_(I.id,R)})]},I.id)})})]})}function Uyt({rule:e,index:t,expanded:n,isFirst:r,isLast:o,onToggleExpand:s,onToggleEnabled:i,onMoveUp:a,onMoveDown:c,onDuplicate:u,onDelete:d}){const f=Myt(e),h=e.enabled!==!1;return l.jsxs("div",{className:m.cn("flex items-stretch gap-1 px-2 py-1.5 transition-colors",n?"bg-muted/40 shadow-[inset_2px_0_0] shadow-foreground":"hover:bg-muted/40"),children:[l.jsxs("div",{className:"flex shrink-0 flex-col items-center gap-0.5 pt-1 text-muted-foreground",children:[l.jsx("button",{type:"button","aria-label":`Move rule ${t+1} up`,disabled:r,onClick:a,className:"rounded-[3px] p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-30 disabled:hover:bg-transparent",children:l.jsx(cs,{className:"size-3"})}),l.jsx("button",{type:"button","aria-label":`Move rule ${t+1} down`,disabled:o,onClick:c,className:"rounded-[3px] p-0.5 text-muted-foreground hover:bg-foreground/10 hover:text-foreground disabled:opacity-30 disabled:hover:bg-transparent",children:l.jsx(No,{className:"size-3"})})]}),l.jsx("button",{type:"button",onClick:s,"aria-expanded":n,"aria-label":`${n?"Collapse":"Expand"} rule ${t+1}`,className:"flex min-w-0 flex-1 items-start py-0.5 text-left",children:l.jsxs("span",{className:"min-w-0 flex-1",children:[l.jsxs("span",{className:"flex items-center gap-2",children:[l.jsxs("span",{className:"text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:["#",t+1]}),l.jsx("span",{className:m.cn("truncate text-[12px] font-medium",h?"text-foreground":"text-muted-foreground line-through"),children:e.name??`Rule ${t+1}`})]}),l.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-1.5",children:[l.jsx(qyt,{rule:e}),l.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:f})]})]})}),l.jsxs("div",{className:"flex shrink-0 items-start gap-1 pt-1",children:[l.jsx(m.Switch,{size:"xs","aria-label":h?`Disable rule ${t+1}`:`Enable rule ${t+1}`,checked:h,onCheckedChange:i}),l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":`Rule ${t+1} actions`,className:"inline-flex h-4 w-4 items-center justify-center rounded-[4px] text-muted-foreground hover:bg-muted hover:text-foreground",children:l.jsx(Lm,{className:"size-3"})})}),l.jsxs(_o,{align:"end",className:"min-w-[140px]",children:[l.jsxs(ln,{className:"gap-2 text-[12px]",onClick:u,children:[l.jsx(gu,{className:"size-3"}),"Duplicate"]}),l.jsxs(ln,{className:"gap-2 text-[12px] text-destructive focus:text-destructive",onClick:d,children:[l.jsx(Ra,{className:"size-3"}),"Delete"]})]})]})]})]})}function Kyt({capabilities:e,onUpdateApplyColumn:t,onUpdateTotals:n,rule:r,index:o,availableColumns:s,onUpdateName:i,onUpdateConditionColumn:a,onUpdateTargetLevel:c,onUpdateRuleKind:u,onUpdateConditionalOperator:d,onUpdateConditionalValue:f,onUpdateConditionalMaxValue:h,onUpdateStyle:p,onUpdateTopBottom:g,onUpdateColorScale:x,onUpdateDataBar:b}){var k,_,T,I,D;const y=Tyt(r),C=xge(r),w=r.id,N=bge(r),S=fO(s),j=!ug(r);return l.jsxs("div",{className:"space-y-3 border-t border-border/60 bg-muted/20 px-3 py-3",children:[l.jsx(Ur,{label:"Name",htmlFor:`cf-name-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-name-${w}`,value:r.name??"",onValueChange:i,className:`w-full ${m.removeRing}`,placeholder:`Rule ${o+1}`})}),l.jsxs(py,{label:"Target",children:[l.jsxs(Ur,{label:"Target",children:[l.jsx(Ap,{ariaLabel:"Formatting target",value:r.target.level,onChange:c,options:[{value:"cell",label:"Cell"},{value:"row",label:"Row",ariaLabel:j?"Row":"Row target is not available for this rule type",disabled:!j}]}),!j&&l.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Color scales and data bars format cells because their values are column-specific."})]}),l.jsx(Ur,{label:"Trigger",htmlFor:`cf-trigger-${w}`,children:l.jsxs(m.Select,{value:N||"",onValueChange:a,children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-trigger-${w}`,className:`w-full ${m.simpleRing}`,children:l.jsx(m.SelectValue,{placeholder:""})}),l.jsx(m.SelectContent,{children:(S.length?S:fO([N])).filter(E=>!!E.value).map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})})]}),(e==null?void 0:e.separateApplyTargets)&&l.jsxs(l.Fragment,{children:[r.target.level==="cell"&&!ug(r)&&l.jsx(Ur,{label:"Apply to column",htmlFor:`cf-apply-${w}`,children:l.jsxs(m.Select,{value:((k=r.target.columnIds)==null?void 0:k[0])??N,onValueChange:t,children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-apply-${w}`,children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:S.map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})}),!e.targetScope&&l.jsx(Ur,{label:"Include totals",htmlFor:`cf-totals-${w}`,children:l.jsx(m.Switch,{id:`cf-totals-${w}`,size:"xs",checked:r.target.includeTotals===!0&&r.target.includeSubtotals===!0,onCheckedChange:n})})]}),l.jsxs(py,{label:"Condition",children:[l.jsx(Ap,{ariaLabel:"Rule type",value:y,onChange:u,options:Oyt.filter(E=>!e||e.ruleKinds.includes(E.value))}),y==="comparison"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Operator",htmlFor:`cf-operator-${w}`,children:l.jsxs(m.Select,{value:C,onValueChange:E=>d(E),children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-operator-${w}`,className:`w-full ${m.simpleRing}`,children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:gge.map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})}),C==="between"?l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Min",htmlFor:`cf-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-value-${w}`,"aria-label":"Value",value:dO(r),onValueChange:f,className:`w-full ${m.removeRing}`,placeholder:"Minimum…"})}),l.jsx(Ur,{label:"Max",htmlFor:`cf-max-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-max-value-${w}`,value:Dyt(r),onValueChange:h,className:`w-full ${m.removeRing}`,placeholder:"Maximum…"})})]}):C!=="blank"&&C!=="notBlank"?l.jsx(Ur,{label:"Value",htmlFor:`cf-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-value-${w}`,value:dO(r),onValueChange:f,className:`w-full ${m.removeRing}`,placeholder:C==="contains"?"Text to match…":"Value…"})}):null]}),r.condition.kind==="topBottom"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Direction",children:l.jsx(Ap,{ariaLabel:"Direction",value:r.condition.direction,onChange:E=>g({direction:E}),options:[{value:"top",label:"Top"},{value:"bottom",label:"Bottom"}]})}),l.jsx(Ur,{label:"Count",htmlFor:`cf-count-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-count-${w}`,type:"number",min:1,value:String(r.condition.count),onValueChange:E=>g({count:Eyt(E,1)}),className:`w-full ${m.removeRing}`})})]}),r.condition.kind==="colorScale"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Range",children:l.jsx(Ap,{ariaLabel:"Range",value:r.condition.range,onChange:E=>x({range:E}),options:[...(e==null?void 0:e.automaticRanges)===!1?[]:[{value:"auto",label:"Auto"}],{value:"manual",label:"Manual"}]})}),r.condition.range==="manual"&&l.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[l.jsx(_l,{size:"xs",type:"number","aria-label":"Min",placeholder:"Min",value:hy(r.condition.min),onValueChange:E=>x({min:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Mid",placeholder:"Mid",value:hy(r.condition.mid),onValueChange:E=>x({mid:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Max",placeholder:"Max",value:hy(r.condition.max),onValueChange:E=>x({max:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`})]}),l.jsx(Ur,{label:"Palette",children:l.jsx(Vyt,{value:r.condition.colors,onChange:E=>x({colors:E})})})]}),r.condition.kind==="dataBar"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Range",children:l.jsx(Ap,{ariaLabel:"Range",value:r.condition.range,onChange:E=>b({range:E}),options:[...(e==null?void 0:e.automaticRanges)===!1?[]:[{value:"auto",label:"Auto"}],{value:"manual",label:"Manual"}]})}),r.condition.range==="manual"&&l.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[l.jsx(_l,{size:"xs",type:"number","aria-label":"Min",placeholder:"Min",value:hy(r.condition.min),onValueChange:E=>b({min:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Max",placeholder:"Max",value:hy(r.condition.max),onValueChange:E=>b({max:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`})]}),l.jsx(Ur,{label:"Show value",children:l.jsx(m.Switch,{size:"xs","aria-label":"Show cell value on data bar",checked:r.condition.showValue!==!1,onCheckedChange:E=>b({showValue:E})})})]})]}),(y==="comparison"||r.condition.kind==="topBottom")&&l.jsxs(py,{label:"Format",children:[l.jsx(Ur,{label:"Preset",children:l.jsx(Byt,{value:(_=r.style)==null?void 0:_.backgroundColor,onChange:(E,R)=>p({backgroundColor:E,textColor:R})})}),l.jsx(Ur,{label:"Fill",htmlFor:`cf-fill-${w}`,children:l.jsx(Na,{id:`cf-fill-${w}`,ariaLabel:"Fill Color",value:((T=r.style)==null?void 0:T.backgroundColor)||void 0,onChange:E=>p({backgroundColor:E}),defaultValue:"#fee2e2"})}),l.jsx(Ur,{label:"Text",htmlFor:`cf-text-${w}`,children:l.jsx(Na,{id:`cf-text-${w}`,ariaLabel:"Text Color",value:((I=r.style)==null?void 0:I.textColor)||void 0,onChange:E=>p({textColor:E}),defaultValue:"#b91c1c"})}),l.jsx(Ur,{label:"Weight",children:l.jsx(Ap,{ariaLabel:"Font weight",value:((D=r.style)==null?void 0:D.fontWeight)??"normal",onChange:E=>p({fontWeight:E==="normal"?void 0:E}),options:[{value:"normal",label:"R",ariaLabel:"Regular"},{value:"medium",label:"M",ariaLabel:"Medium"},{value:"bold",label:"B",ariaLabel:"Bold"}]})})]}),r.condition.kind==="colorScale"&&l.jsxs(py,{label:"Colors",children:[l.jsx(Ur,{label:"Low",htmlFor:`cf-low-color-${w}`,children:l.jsx(Na,{id:`cf-low-color-${w}`,ariaLabel:"Low color",value:r.condition.colors.min,onChange:E=>x({colors:{min:E??"#fee2e2"}}),defaultValue:"#fee2e2",allowEmpty:!1})}),l.jsx(Ur,{label:"Mid",htmlFor:`cf-mid-color-${w}`,children:l.jsx(Na,{id:`cf-mid-color-${w}`,ariaLabel:"Mid color",value:r.condition.colors.mid||void 0,onChange:E=>x({colors:{mid:E}}),defaultValue:"#fef3c7"})}),l.jsx(Ur,{label:"High",htmlFor:`cf-high-color-${w}`,children:l.jsx(Na,{id:`cf-high-color-${w}`,ariaLabel:"High color",value:r.condition.colors.max,onChange:E=>x({colors:{max:E??"#dcfce7"}}),defaultValue:"#dcfce7",allowEmpty:!1})})]}),r.condition.kind==="dataBar"&&l.jsxs(py,{label:"Bar color",children:[l.jsx(Ur,{label:"Preset",children:l.jsx(Hyt,{value:r.condition.color,onChange:E=>b({color:E})})}),l.jsx(Ur,{label:"Color",htmlFor:`cf-bar-color-${w}`,children:l.jsx(Na,{id:`cf-bar-color-${w}`,ariaLabel:"Bar color",value:r.condition.color,onChange:E=>b({color:E??"#3b82f6"}),defaultValue:"#3b82f6",allowEmpty:!1})})]})]})}function Wyt({field:e,dataSource:t,connectionId:n,connectionType:r,filterId:o}){const{qualifiedColumnName:s,qualifiedTableName:i}=Vme(e),a=m.getDataType(e.dataType),c=a==="date"?"between":"in",u=LO(e),d=$O(t,{connectionId:n,connectionType:r},e);return{id:o||lt.v4(),title:e.label||e.name,connectionId:n||(t==null?void 0:t.connectionId)||"",column:s,dataType:e.dataType,table:e.entityName||"",database:zY(t,d,e)||"",qualifiedTableName:i,operation:c,sql:"",fieldMeta:u,semanticContext:d,...a==="date"?{dateSelectionMode:"range"}:{type:"single"}}}function Gyt(e,t){return e.kind==="filter"&&qg(e.filter,t)}function WT(e){return m.getDataType(e.dataType)==="date"?["label","start","end","range"]:["label","value"]}function vge(e){return Yyt(e)?["label","value"]:["value"]}function Yyt(e){return e.type==="enum"||e.type==="multi_enum"||e.type==="field_selector"||e.type==="metric_selector"||e.type==="aggregation_selector"||e.type==="grain_selector"}function kb(e,t){return en.requireNormalizedDashboardInputs({inputs:e.inputs,dashboardFilters:e.filters}).filter(r=>m.doesDashboardInputApplyToTarget(r,{sheetId:t,sheetKind:"document"}))}function wge(e,t){const n=Zyt(e,t);return(e.inputs||[]).some(r=>m.doesDashboardInputApplyToTarget(r,{sheetId:t,sheetKind:"document"})||r.scope.kind==="documentSections"&&r.scope.sheetId===t||r.scope.kind==="cards"&&r.scope.cardIds.some(o=>n.has(o)))}function Zyt(e,t){var o,s,i;const n=new Set,r=(o=e.sheets)==null?void 0:o.find(a=>a.id===t);for(const a of((s=r==null?void 0:r.document)==null?void 0:s.sections)||[])(a.type==="table"||a.type==="chart")&&((i=a.card)!=null&&i.id)&&n.add(a.card.id);return n}function NC(e){const t={id:e.id,label:e.label,variableName:e.variableName,requiredAtExecution:!!e.requiredAtExecution,documentPlacement:"input_bar",description:e.description};return e.kind==="filter"?{...t,kind:"filter",filter:e.filter,exports:e.exports}:{...t,kind:"control",control:e.control,exports:e.exports}}function Xyt({field:e,existingInputs:t,sheetId:n,dataSource:r,connectionId:o,connectionType:s,inputId:i,filterId:a}){const c=e.label||e.name,u=Wyt({field:e,dataSource:r,connectionId:o,connectionType:s,filterId:a}),d=m.createUniqueDashboardInputVariableName(c,t);return{id:i||lt.v4(),kind:"filter",label:c,variableName:d,requiredAtExecution:!1,scope:{kind:"sheets",sheetIds:[n]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},filter:{...u,variableName:d},exports:WT(u)}}function Qyt({control:e,existingInputs:t,sheetId:n,inputId:r}){const o=m.createUniqueDashboardInputVariableNameFromName(e.id||e.label,t),s=e.id===o?e:{...e,id:o};return{id:r||lt.v4(),kind:"control",label:s.label,variableName:o,requiredAtExecution:s.requiredAtExecution,scope:{kind:"sheets",sheetIds:[n]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},control:s,exports:vge(s)}}function Cge({input:e,allInputs:t,label:n,variableName:r}){const o=(n==null?void 0:n.trim())||e.label,s=r===void 0?e.variableName:m.createUniqueDashboardInputVariableNameFromName(r,t.filter(a=>a.id!==e.id));if(e.kind==="filter"){if(!e.filter)throw new Error(`Referenced dashboard input '${e.id}' cannot be edited as a document input.`);const a={...e.filter,title:o,variableName:s};return{...e,label:o,variableName:s,filter:a,exports:WT(a)}}const i={...e.control,id:s,label:o};return{...e,label:o,variableName:s,requiredAtExecution:i.requiredAtExecution,control:i,exports:vge(i)}}function hO(e,t,n){return!t||!n||t===n?e:{...e,sections:e.sections.map(r=>r.type!=="table"&&r.type!=="chart"||!r.card?r:{...r,card:Jyt(r.card,t,n)})}}function Jyt(e,t,n){var s;const r=`[[param.${t}]]`,o=`[[param.${n}]]`;return{...e,...(s=e.sql)!=null&&s.includes(r)?{sql:e.sql.split(r).join(o)}:{},...e.controls?{controls:e.controls.map(i=>i.id===t?{...i,id:n}:i)}:{},...e.controlBindings?{controlBindings:e.controlBindings.map(i=>({...i,controlId:i.controlId===t?n:i.controlId,...i.target==="sql_param"&&i.paramId===t?{paramId:n}:{}}))}:{}}}function evt(e,t){return e.kind==="filter"&&Gyt(NC(e),t)}function tvt(e){var n;const t={};for(const r of e)r.kind==="filter"&&(t[r.id]=((n=r.slot)==null?void 0:n.status)==="cleared"?void 0:r.filterValue);return t}function nvt(e){var n;const t={};for(const r of e)r.kind==="control"&&((n=r.slot)==null?void 0:n.status)==="set"&&(t[r.id]=r.controlValue);return t}function rvt({dashboard:e,sheetId:t,filterValuesByInputId:n,controlValuesByInputId:r}){var i;const o=kb(e,t);let s={};for(const a of o)if(((i=a.compatibility)==null?void 0:i.source)==="documentInput"){if(a.kind==="filter"&&n&&Object.prototype.hasOwnProperty.call(n,a.id)){const c=n[a.id];s=m.setDashboardInputRuntimeSlot(s,a,{sheetId:t},c?{status:"set",value:{kind:"filter",filterValue:c}}:{status:"cleared"})}if(a.kind==="control"&&r&&Object.prototype.hasOwnProperty.call(r,a.id)){const c=r[a.id];s=m.setDashboardInputRuntimeSlot(s,a,{sheetId:t},c===void 0?{status:"cleared"}:{status:"set",value:{kind:"control",value:c}})}}return zR({dashboard:e,dashboardInputValues:s,sheetId:t})}const ovt=[],svt={},ivt={},avt={};function lvt(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}function cvt({sheet:e}){var Rt;const n=m.useDashboardStore(Pe=>{var Ge,at,kt;return(kt=(at=(Ge=Pe.dashboard)==null?void 0:Ge.sheets)==null?void 0:at.find(Wt=>Wt.id===e.id))==null?void 0:kt.document})||e.document||m.createDefaultDocumentDefinition(),r=m.useDashboardStore(Pe=>Pe.dashboard),o=m.useDashboardStore(Pe=>Pe.dashboardInputValues),s=m.useDashboardStore(Pe=>Pe.filterValues),i=m.useDashboardStore(Pe=>Pe.controlValues),a=m.useDashboardStore(Pe=>Pe.inlineFilterValuesMap),c=m.useDashboardStore(Pe=>Pe.cardControlValuesMap),u=v.useMemo(()=>kb(r,e.id),[r,e.id]),d=u.length>0,f=v.useMemo(()=>wge(r,e.id),[r,e.id]),h=v.useMemo(()=>d?u.map(NC):n.inputs||ovt,[n.inputs,u,d]),p=v.useMemo(()=>new Map(u.map(Pe=>[Pe.id,Pe])),[u]),g=v.useMemo(()=>new Map((r.inputs||[]).map(Pe=>[Pe.id,Pe])),[r.inputs]),x=v.useMemo(()=>h.filter(oc).map(Pe=>Pe.control),[h]),{authToken:b,tokenProps:y,documentInputValues:C,dashboardInputExecutionSnapshot:w,renderMode:N}=Mt(),{displayPreferences:S}=bl(),j=vl()??void 0,k=m.useDashboardStore(Pe=>Pe.isDashboardEditing),_=m.useDashboardStore(Pe=>Pe.isDownloadingPdf),T=Eee({displayMode:S.mode,renderMode:N}),I=T?"print":k?"edit":"view",{updateSheetDocument:D,setSelectedDocumentSectionId:E,setDocumentInspectorTab:R,setDocumentInputFilterValues:F,setDocumentInputFilterValue:M,setDocumentInputFilterModes:O,setDocumentInputFilterMode:z,removeDocumentInputFilterValue:L,setDocumentInputControlValues:V,setDocumentInputControlValue:A,upsertDashboardInput:B,updateFilterDashboardInputDefinition:$,removeDashboardInput:P,reorderDashboardInputs:U,setDashboardInputSlot:H,clearDashboardInputSlot:G}=m.useDashboardActions(),q=m.useDashboardStore(Pe=>Pe.documentInspectorTabsBySheetId[e.id]||"page"),Y=Tgt(),[W,ne]=v.useState(null),[Z,K]=v.useState(null),[X,J]=v.useState("edit"),[re,te]=v.useState({pageNumber:1,pageCount:1}),[Q,se]=v.useState({}),[oe,fe]=v.useState(!1),pe=Hr(),[xe,Ie]=v.useState(100),be=m.useDashboardStore(Pe=>Pe.documentInputRuntimeBySheetId[e.id]),ge=v.useMemo(()=>xpe(h,j),[h,j]),ee=v.useMemo(()=>bpe(h),[h]),ce=C!=null&&C.sheetId&&C.sheetId!==e.id?void 0:C,ae=ce==null?void 0:ce.filterValuesByInputId,me=ce==null?void 0:ce.controlValuesByInputId,ve=v.useMemo(()=>!w&&ce?rvt({dashboard:r,sheetId:e.id,filterValuesByInputId:ae,controlValuesByInputId:me}):void 0,[w,r,me,ce,ae,e.id]),_e=v.useMemo(()=>mgt(h),[h]),De=v.useMemo(()=>ype(h),[h]),Ue=v.useRef(De),Ne=v.useMemo(()=>m.resolveDashboardInputContext({dashboard:r,sheetId:e.id,sheetKind:"document",runtimeValues:{...ve?{dashboardInputValues:ve}:{dashboardInputValues:o},filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},mode:T?"print":"interactive",timezone:j}),[r,c,i,s,a,o,j,T,ve,e.id]),Oe=v.useMemo(()=>tvt(Ne.resolvedInputs),[Ne.resolvedInputs]),ye=v.useMemo(()=>nvt(Ne.resolvedInputs),[Ne.resolvedInputs]),Be=v.useMemo(()=>d?Oe:ce?ae||svt:(be==null?void 0:be.filterValuesByInputId)||ge,[ge,Oe,ce,ae,d,be==null?void 0:be.filterValuesByInputId]),he=v.useMemo(()=>wpe(Be,h),[Be,h]),ue=v.useMemo(()=>d?Dvt(h,Oe):(be==null?void 0:be.filterModesByInputId)||ivt,[Oe,h,d,be==null?void 0:be.filterModesByInputId]),de=v.useMemo(()=>d?ye:ce?me||avt:(be==null?void 0:be.controlValuesByInputId)||ee,[ee,ye,me,ce,d,be==null?void 0:be.controlValuesByInputId]),[Te,we]=v.useState({}),[Ee,Ke]=v.useState((w==null?void 0:w.generatedAt)||(ce==null?void 0:ce.generatedAt)||new Date().toISOString()),He=v.useMemo(()=>n.sections.find(Pe=>Pe.type==="table")||null,[n.sections]),qe=v.useMemo(()=>n.sections.find(Pe=>Pe.id===W)||null,[n.sections,W]),Je=(qe==null?void 0:qe.type)==="table"?qe:He,We=(Je==null?void 0:Je.id)||W||null;v.useEffect(()=>{E(e.id,We)},[We,E,e.id]),v.useEffect(()=>{const Pe=Ue.current;if(ce){ce.generatedAt&&Ke(Ge=>Ge===ce.generatedAt?Ge:ce.generatedAt),Ue.current=De;return}d||(F(e.id,pgt(Be,h,ge,De,Pe)),V(e.id,ggt(de,h,ee,De,Pe))),Ue.current=De},[de,_e,Be,h,ge,ee,De,ce,d,V,F,e.id]),v.useEffect(()=>{d||O(e.id,bgt(ue,h))},[ue,_e,h,d,O,e.id]);const bt=v.useCallback((Pe,Ge)=>{const at=h.find(fn=>fn.id===Pe),kt=at&&pl(at)?Sx(at,Ge):Ge;if(!kt)return;const Wt=p.get(Pe);if(Wt){H(Wt,{sheetId:e.id},{status:"set",value:{kind:"filter",filterValue:kt}});return}M(e.id,Pe,kt)},[p,h,H,M,e.id]),pt=v.useCallback((Pe,Ge)=>{const at=h.find(fn=>fn.id===Pe),kt=p.get(Pe);kt||z(e.id,Pe,Ge);const Wt=at&&pl(at)?Sx(at,Be[Pe]):Be[Pe];if(!(!Wt||!VT(Wt.operation))){if(kt){H(kt,{sheetId:e.id},{status:"set",value:{kind:"filter",filterValue:{...Wt,operation:lO(Ge)}}});return}M(e.id,Pe,{...Wt,operation:lO(Ge)})}},[Be,h,p,H,z,M,e.id]),Bt=v.useCallback(Pe=>{const Ge=p.get(Pe);if(Ge){G(Ge,{sheetId:e.id});return}L(e.id,Pe)},[G,p,L,e.id]),ut=v.useCallback((Pe,Ge,at)=>{const kt=p.get(Pe);return(kt==null?void 0:kt.kind)==="filter"&&kt.filter?$(Pe,Ge,{...at,...at!=null&&at.optionSettings?{optionSettings:{...at.optionSettings,target:at.optionSettings.target??{sheetId:e.id}}}:{},label:Ge.title||kt.label,...kt.definitionOrigin==="embedded"?{exports:WT(Ge)}:{}}):(D(e.id,Wt=>_vt(Wt,Pe,Ge,at)),{ok:!0})},[p,e.id,D,$]),$t=v.useCallback((Pe,Ge)=>{const at=p.get(Pe),kt=g.get(Pe);if((at==null?void 0:at.kind)==="control"&&(kt==null?void 0:kt.kind)==="control"){const Wt=Cge({input:{...kt,requiredAtExecution:Ge.requiredAtExecution,control:Ge},allInputs:r.inputs||[],label:Ge.label||at.label,variableName:Ge.id||at.variableName});B(Wt),Wt.kind==="control"&&at.control.id!==Wt.control.id&&D(e.id,fn=>hO(fn,at.control.id,Wt.control.id));return}D(e.id,Wt=>{const fn=(Wt.inputs||[]).find(qs=>qs.id===Pe&&oc(qs)),qr=Tvt(Wt,Pe,Ge);return fn&&fn.control.id!==Ge.id?hO(qr,fn.control.id,Ge.id):qr})},[r.inputs,p,g,e.id,D,B]),Fe=v.useCallback(Pe=>{if(p.has(Pe)){P(Pe);return}D(e.id,Ge=>({...Ge,inputs:(Ge.inputs||[]).filter(at=>at.id!==Pe)}))},[p,P,e.id,D]),ct=v.useCallback(Pe=>{if(d){const Ge=u.map(at=>at.id);U(Bk(r.inputs||[],Ge,Pe));return}D(e.id,Ge=>{const at=Ge.inputs||[];return{...Ge,inputs:Bk(at,at.map(kt=>kt.id),Pe).map(kt=>at.find(Wt=>Wt.id===kt)).filter(kt=>kt!==void 0)}})},[r.inputs,u,d,U,e.id,D]),It=v.useCallback((Pe,Ge)=>{const at=p.get(Pe);if(at){if(Ge===void 0){G(at,{sheetId:e.id});return}H(at,{sheetId:e.id},{status:"set",value:{kind:"control",value:Ge}});return}A(e.id,Pe,Ge)},[G,p,H,A,e.id]),yt=v.useCallback((Pe,Ge)=>{we(at=>Mvt(at[Pe]||[],Ge)?at:{...at,[Pe]:Ge})},[]);v.useEffect(()=>{const Pe=new Set(h.filter(oc).map(Ge=>Ge.id));we(Ge=>{const at=Object.fromEntries(Object.entries(Ge).filter(([kt])=>Pe.has(kt)));return Object.keys(at).length===Object.keys(Ge).length?Ge:at})},[h]);const vt=v.useMemo(()=>d?Ne.activeFilters:Cgt(Be,h,De,Ue.current),[Ne.activeFilters,Be,h,De,d]),mt=v.useMemo(()=>d?Ne.controlValues:Sgt(de,h,De,Ue.current),[Ne.controlValues,de,h,De,d]),St=v.useMemo(()=>d?Ne.missingRequiredInputs.map(Pe=>Pe.label):Spe(h,Be,de,De,Ue.current),[Ne.missingRequiredInputs,h,Be,de,De,d]),it=v.useMemo(()=>f?IZ({dashboard:r,sheetId:e.id,sheetKind:"document",sectionIds:n.sections.map(Pe=>Pe.id),mode:"document",runtimeValues:{dashboardInputValues:o,filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},timezone:j}):St,[r,c,i,s,a,o,n.sections,j,f,St,e.id]),nt=v.useMemo(()=>{var Pe;return Gpt({inputs:h,filterValuesByInputId:Be,controlValuesByInputId:de,controlOptionsByInputId:Te,generatedAt:Ee,timezone:j,generatedAtFormat:(Pe=n.runtime)==null?void 0:Pe.generatedAtFormat})},[h,Be,de,Te,Ee,j,(Rt=n.runtime)==null?void 0:Rt.generatedAtFormat]),gt=v.useCallback(Pe=>{D(e.id,Pe)},[e.id,D]),Vt=v.useCallback(Pe=>R(e.id,Pe),[R,e.id]),Me=v.useCallback((Pe,Ge,at,kt)=>{se(Wt=>{const fn=Wt[Pe];if(Ge.length===0){if((fn==null?void 0:fn.schemaSignature)===at||!fn)return Wt;const qr={...Wt};return delete qr[Pe],qr}return(fn==null?void 0:fn.schemaSignature)===at&&JSON.stringify(fn.columnKeyMap)===JSON.stringify(kt)&&lvt(fn.columns,Ge)?Wt:{...Wt,[Pe]:{schemaSignature:at,columns:Ge,columnKeyMap:kt}}})},[]),Qe=(Pe,Ge={})=>{ne(Pe),!Pe&&q==="section"?Vt("page"):Pe&&Ge.activateSectionInspector!==!1&&Vt("section"),K(null)},$e=(Pe,Ge)=>{const at=igt(Pe);gt(kt=>({...kt,sections:[...kt.sections.slice(0,Ge),at,...kt.sections.slice(Ge)]})),ne(at.id),Vt("section"),K(null),at.type==="table"&&Y(e.id,at)},le=Pe=>{W&&gt(Ge=>({...Ge,sections:Ge.sections.map(at=>at.id===W?Pe(at):at)}))},Ae=()=>{W&&Xe(W)},Xe=Pe=>{var kt;const Ge=Pe===W,at=n.sections.filter(Wt=>Wt.id!==Pe);gt(Wt=>({...Wt,sections:Wt.sections.filter(fn=>fn.id!==Pe)})),Ge&&(ne(((kt=at[0])==null?void 0:kt.id)||null),Vt(at[0]?"section":"page"))},Ot=(Pe,Ge,at)=>{Pe!==Ge&&(gt(kt=>{const Wt=kt.sections.findIndex(qo=>qo.id===Pe),fn=kt.sections.findIndex(qo=>qo.id===Ge);if(Wt===-1||fn===-1)return kt;const qr=[...kt.sections],[qs]=qr.splice(Wt,1),Us=at==="after"?fn+1:fn,Va=Wt<Us?Us-1:Us;return qr.splice(Math.min(Va,qr.length),0,qs),{...kt,sections:qr}}),ne(Pe))},qt=Pe=>{gt(Ge=>({...Ge,page:Pe}))},Pt=v.useCallback((Pe,Ge)=>{gt(at=>({...at,sections:at.sections.map(kt=>kt.id===Pe&&kt.type==="table"?Ge(kt):kt)}))},[gt]),Fn=Pe=>{gt(Ge=>({...Ge,header:Pe(Ge.header)}))},ft=Pe=>{gt(Ge=>({...Ge,footer:Pe(Ge.footer)}))},Tt=v.useCallback(Pe=>{Y(e.id,Pe,vt,x,mt,St)},[x,mt,vt,St,Y,e.id]),ke=v.useCallback(async()=>{if(!(y!=null&&y.apiServiceUrl)||!b){m.ue.error("Unable to export document PDF without an active session");return}if(it.length>0){m.ue.error(`Set ${it.join(", ")} before exporting`);return}const Pe=new Date().toISOString(),Ge=f?_Z({dashboard:r,sheetId:e.id,sheetKind:"document",sectionIds:n.sections.map(kt=>kt.id),mode:"document",runtimeValues:{dashboardInputValues:o,filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},generatedAt:Pe,timezone:j}).snapshot:void 0,at=m.ue.loading("Generating document PDF...");try{await NL(y.apiServiceUrl,b,{sheetId:e.id,title:e.title||"Document",pageSize:n.page.size,orientation:n.page.orientation,timezone:j,inputSnapshot:Ge,...Ge?{}:{inputValues:{sheetId:e.id,filterValuesByInputId:he,controlValuesByInputId:de,generatedAt:Pe}}}),m.ue.dismiss(at),m.ue.success("Document PDF downloaded")}catch(kt){m.ue.dismiss(at),m.ue.error("Failed to export document PDF",{description:r_(kt,"Please try again or contact support."),descriptionClassName:n_,closeButton:!0,duration:1/0}),console.error("Document PDF export error:",kt)}},[b,n.page.orientation,n.page.size,n.sections,r,c,i,s,a,o,de,he,j,it,f,e.id,e.title,y==null?void 0:y.apiServiceUrl]),Ve=l.jsxs("button",{type:"button",disabled:_||it.length>0,onClick:ke,title:it.length>0?`Set ${it.join(", ")} before exporting`:void 0,className:m.cn(U2,"disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent"),children:[_?l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):l.jsx(ac,{className:"h-3.5 w-3.5"}),"Export"]}),dt=X==="preview",_t=l.jsx("button",{type:"button",onClick:()=>{dt?J("edit"):(J("preview"),K(null))},"aria-pressed":dt,className:m.cn(U2,dt?"bg-primary text-primary-foreground hover:bg-primary/90":"text-foreground hover:bg-muted"),children:dt?"Exit preview":"Show preview"}),Xt=v.useCallback(Pe=>{te(Ge=>{const at=Math.max(1,Ge.pageCount),kt=Math.min(at,Math.max(1,Math.round(Pe)));return Ge.pageNumber===kt?Ge:{...Ge,pageNumber:kt}})},[]),wn=v.useCallback(Pe=>{te(Ge=>{const at=Math.max(Ge.pageCount,Pe,1),kt=Math.min(Ge.pageNumber,at);return Ge.pageNumber===kt&&Ge.pageCount===at?Ge:{pageNumber:kt,pageCount:at}})},[]),cn=v.useCallback(async()=>{fe(!0),Ke(new Date().toISOString());try{await pe.invalidateQueries({refetchType:"active",predicate:Pe=>{const Ge=Pe.queryKey;return Array.isArray(Ge)&&(Ge.includes("documentSection")||Ge[0]==="documentTableRows")}})}finally{fe(!1)}},[pe]),ot=l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:m.cn(U2,"font-normal text-foreground hover:bg-muted hover:text-foreground"),onClick:cn,disabled:oe,"aria-label":"Refresh report",children:[l.jsx(Ma,{className:m.cn("h-3.5 w-3.5",oe&&"animate-spin")}),"Refresh"]});return I==="print"?l.jsxs(l.Fragment,{children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx(Bbt,{document:n,inputs:h,textRenderContext:nt,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St})]}):I==="view"?l.jsxs(l.Fragment,{children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx($bt,{sheetId:e.id,document:n,inputs:h,dashboardInputsById:p,textRenderContext:nt,filterValuesByInputId:Be,filterModesByInputId:ue,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St,onSetFilterValue:bt,onSetFilterMode:pt,onRemoveFilterValue:Bt,controlValuesByInputId:de,onSetControlValue:It,actions:l.jsxs(fG,{children:[ot,l.jsx(K2,{}),Ve]})})]}):l.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-muted/60 text-foreground",children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx(jxt,{sections:n.sections,inputs:h,selectedSectionId:W,onSelectSection:Qe,onDeleteSection:Xe,onReorderSection:Ot,onInsertSection:Pe=>$e(Pe,n.sections.length)}),l.jsxs("main",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[l.jsx(Hpe,{sheetId:e.id,inputs:h,dashboardInputsById:p,filterValuesByInputId:Be,filterModesByInputId:ue,documentFilterValues:vt,documentControlValues:mt,onSetFilterValue:bt,onSetFilterMode:pt,onUpdateFilterInput:ut,onUpdateControlInput:$t,onRemoveFilterValue:Bt,onRemoveInput:Fe,onReorderInputs:ct,controlValuesByInputId:de,onSetControlValue:It,actions:l.jsxs(fG,{children:[ot,l.jsx(K2,{}),l.jsx(Rvt,{zoom:xe,onZoomChange:Ie}),l.jsx(K2,{}),_t]}),isEditing:!0}),l.jsxs("div",{className:"relative min-h-0 flex-1 overflow-auto",onClick:Pe=>{Pe.target===Pe.currentTarget&&Qe(null)},children:[l.jsx("div",{style:{zoom:xe/100},className:"flex justify-center px-6 py-8",children:l.jsx(Y4,{document:n,inputs:h,textRenderContext:nt,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St,isEditing:!dt,selectedSectionId:dt?void 0:W,activeAddIndex:dt?null:Z,onSelectSection:Qe,onToggleAddIndex:K,onInsertSection:$e,onEditTableSection:Tt,onUpdateTableSection:Pt,onTableResultColumnsChange:Me,onReorderSection:Ot,pageNumber:re.pageNumber,onPageCountChange:wn,measurementScale:xe/100})}),l.jsx(pvt,{pageNumber:re.pageNumber,pageCount:re.pageCount,onFirst:()=>Xt(1),onPrevious:()=>Xt(re.pageNumber-1),onNext:()=>Xt(re.pageNumber+1),onLast:()=>Xt(re.pageCount)})]})]}),l.jsx(uvt,{sheetId:e.id,tab:q,onTabChange:Vt,document:n,selectedSection:qe,inputSourceSection:Je,tableResultColumnCacheBySectionId:Q,onSelectSection:Qe,onUpdatePage:qt,onUpdateSelectedSection:le,onDeleteSelectedSection:Ae,onUpdateHeader:Fn,onUpdateFooter:ft,onEditTableSection:Tt})]})}function uvt({sheetId:e,tab:t,onTabChange:n,document:r,selectedSection:o,inputSourceSection:s,tableResultColumnCacheBySectionId:i,onSelectSection:a,onUpdatePage:c,onUpdateSelectedSection:u,onDeleteSelectedSection:d,onUpdateHeader:f,onUpdateFooter:h,onEditTableSection:p,actions:g}){const x=[{id:"page",label:"Page"},{id:"header",label:"Header"},{id:"footer",label:"Footer"},{id:"inputs",label:"Inputs"}],b=m.useDashboardStore(S=>S.dashboard),y=v.useMemo(()=>{const S=kb(b,e);return S.length>0?S.map(NC):r.inputs||[]},[b,r.inputs,e]),C=t==="section"&&o!=null,w=t==="section"?"page":t,N=v.useMemo(()=>{if((o==null?void 0:o.type)!=="table")return;const S=i[o.id];if(!S)return;const j=gpe(o);return S.schemaSignature===j?S:void 0},[o,i]);return l.jsxs("aside",{className:"flex w-[360px] shrink-0 flex-col border-l bg-background",children:[C?l.jsx(dvt,{section:o,onBack:()=>a(null),actions:g}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b px-3",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(zm,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Document"})]}),g]}),l.jsx("div",{className:"flex shrink-0 items-center gap-3 overflow-x-auto border-b px-3",children:x.map(S=>l.jsx("button",{type:"button",onClick:()=>n(S.id),className:m.cn("-mb-px border-b-2 py-2 text-[12px] transition-colors",w===S.id?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:S.label},S.id))})]}),l.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:C?l.jsx(hvt,{section:o,inputs:y,tableResultColumns:N==null?void 0:N.columns,tableColumnKeyMap:N==null?void 0:N.columnKeyMap,onUpdateSection:u,onEditTableSection:p}):w==="page"?l.jsx(mvt,{page:r.page,onUpdatePage:c}):w==="header"?l.jsx(wvt,{header:r.header,inputs:y,onUpdateHeader:f}):w==="footer"?l.jsx(Cvt,{footer:r.footer,inputs:y,onUpdateFooter:h}):w==="inputs"?l.jsx(Svt,{sheetId:e,document:r,selectedSection:s,inputCount:y.length,onSelectSection:S=>a(S,{activateSectionInspector:!1}),onEditTableSection:p}):null})]})}function dvt({section:e,onBack:t,actions:n}){const r=F0(e.type);return l.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b px-2",children:[l.jsx("button",{type:"button",onClick:t,"aria-label":"Back to document",className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(ow,{className:"h-3.5 w-3.5"})}),l.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[l.jsx(r,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"truncate text-[12px] font-medium text-foreground",children:wC[e.type]})]}),n]})}const fvt=[{value:"style",label:"Style"},{value:"columns",label:"Columns"},{value:"conditionalFormatting",label:"Conditional formatting"}];function hvt({section:e,inputs:t,tableResultColumns:n=[],tableColumnKeyMap:r,onUpdateSection:o,onEditTableSection:s}){var T,I,D,E,R,F,M,O,z;const[i,a]=v.useState("style");if(!e)return l.jsxs("div",{className:"flex flex-col items-center py-12 text-center",children:[l.jsx(li,{className:"mb-2 h-5 w-5 text-muted-foreground/50"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Select a section"})]});const c=L=>{o(V=>V.type!=="text"?V:{...V,style:{...V.style,...L}})},u=L=>{o(V=>{var H;if(V.type!=="table")return V;const A=(H=V.card.preferences)==null?void 0:H.tablePrefs,{density:B,...$}=L,P={...A==null?void 0:A.tableStyle,...$},U=B??(A==null?void 0:A.density);return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,...U?{density:U}:{},tableStyle:P}}},table:{...V.table,...B?{rowHeightPx:aO(B)}:{}}}})},d=L=>{o(V=>{var $;if(V.type!=="table")return V;const A=($=V.card.preferences)==null?void 0:$.tablePrefs,B=A==null?void 0:A.tableStyle;return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,tableStyle:{...B,totals:{...B==null?void 0:B.totals,...L}}}}}}})},f=()=>{o(L=>{var V;return L.type==="table"?{...L,table:{...L.table,repeatHeaderOnPageBreak:!0,rowHeightPx:aO(zf.density)},card:{...L.card,preferences:{...L.card.preferences,tablePrefs:{...(V=L.card.preferences)==null?void 0:V.tablePrefs,density:zf.density,tableStyle:{headerStyle:zf.headerStyle,headerWrapText:zf.headerWrapText,stripedRows:zf.stripedRows,gridLines:zf.gridLines,wrapText:zf.wrapText,totals:{enabled:Bf.enabled,backgroundColor:Bf.backgroundColor,textColor:Bf.textColor,fontWeight:Bf.fontWeight,borderTop:Bf.borderTop,borderTopStyle:Bf.borderTopStyle,borderTopColor:Bf.borderTopColor}}}}}}:L})},h=L=>{o(V=>{var P;if(V.type!=="table")return V;const A=(P=V.card.preferences)==null?void 0:P.tablePrefs,B=A==null?void 0:A.tableStyle;return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,tableStyle:{...B,totals:{...B==null?void 0:B.totals,enabled:L}}}}},table:{...V.table,totalsRow:L}}})},p=(L,V)=>{o(A=>{var $;if(A.type!=="table")return A;const B=($=A.card.preferences)==null?void 0:$.tablePrefs;return{...A,card:{...A.card,preferences:{...A.card.preferences,tablePrefs:{...B,columnVisibility:Boe(B==null?void 0:B.columnVisibility,L,V)}}}}})},g=()=>{o(L=>{var A;if(L.type!=="table")return L;const V=(A=L.card.preferences)==null?void 0:A.tablePrefs;return{...L,card:{...L.card,preferences:{...L.card.preferences,tablePrefs:{...V,columnVisibility:void 0}}}}})},x=e.type==="table"?dL(rL((I=(T=e.card.preferences)==null?void 0:T.tablePrefs)==null?void 0:I.conditionalFormatting),ZI(e.card,n,r)):{rules:[]},b=e.type==="table"&&hge(e.card.type),y=b?mge(e.card,n,r):[],C=e.type==="table"&&e.card.type==="table"?pge(e.card,n):[],w=b&&y.length>0,N=e.type==="table"&&e.card.type==="table",S=fvt.filter(L=>L.value==="style"||L.value==="columns"&&N||L.value==="conditionalFormatting"&&w),j=S.some(L=>L.value===i)?i:"style",k=((D=y[0])==null?void 0:D.value)??wa,_=L=>{o(V=>V.type==="table"?{...V,card:_yt(V.card,{version:1,rules:L})}:V)};return l.jsxs("div",{className:"space-y-4",children:[e.type==="text"&&l.jsxs(l.Fragment,{children:[l.jsx(Go,{label:"Content",children:l.jsx(O0,{content:e.content,inputs:t,multiline:!0,onChange:L=>o(V=>V.type==="text"?{...V,content:L}:V)})}),l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsx(Go,{label:"Size",children:l.jsxs(m.Select,{value:String(((E=e.style)==null?void 0:E.fontSize)||13),onValueChange:L=>c({fontSize:Number(L)}),children:[l.jsx(m.SelectTrigger,{size:"sm","aria-label":"Text size",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:[11,12,13,14,16,18,20,24].map(L=>l.jsxs(m.SelectItem,{value:String(L),children:[L,"px"]},L))})]})}),l.jsx(Go,{label:"Weight",children:l.jsxs(m.Select,{value:((R=e.style)==null?void 0:R.fontWeight)||"normal",onValueChange:L=>c({fontWeight:L}),children:[l.jsx(m.SelectTrigger,{size:"sm","aria-label":"Text weight",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"normal",children:"Regular"}),l.jsx(m.SelectItem,{value:"medium",children:"Medium"}),l.jsx(m.SelectItem,{value:"semibold",children:"Semibold"}),l.jsx(m.SelectItem,{value:"bold",children:"Bold"})]})]})})]}),l.jsx(Go,{label:"Alignment",children:l.jsx("div",{className:"inline-flex h-8 items-center rounded-md border bg-background p-0.5",children:["left","center","right"].map(L=>{var B;const V=L==="left"?L0e:L==="center"?O0e:$0e,A=((B=e.style)==null?void 0:B.align)||"left";return l.jsx(m.Button,{type:"button",variant:A===L?"secondary":"ghost",size:"icon",className:"h-6 w-7","aria-label":`Align ${L}`,onClick:()=>c({align:L}),children:l.jsx(V,{className:"h-3.5 w-3.5"})},L)})})}),l.jsx(Go,{label:"Color",children:l.jsx(yvt,{value:((F=e.style)==null?void 0:F.color)||"#27272a","aria-label":"Text color",onValueChange:L=>c({color:L})})})]}),e.type==="table"&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"inline-flex h-8 items-center rounded-md border bg-background p-0.5",children:S.map(L=>l.jsx(m.Button,{type:"button",variant:j===L.value?"secondary":"ghost",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>a(L.value),children:L.label},L.value))}),j==="style"?l.jsxs(l.Fragment,{children:[l.jsx(Go,{label:"Title",children:l.jsx(m.Input,{size:"xs",value:e.title||e.card.title,onChange:L=>o(V=>V.type==="table"?{...V,title:L.target.value,card:{...V.card,title:L.target.value}}:V)})}),l.jsx(fge,{style:H4(e),onDensityChange:L=>u({density:L}),onStyleChange:u,showFullStyle:e.card.type==="table",totals:e.card.type==="table"&&!((M=e.card.sql)!=null&&M.trim())?{enabled:e.table.totalsRow===!0,onEnabledChange:h,onStyleChange:d}:void 0,onReset:e.card.type==="table"?f:void 0})]}):j==="columns"?l.jsx(uge,{columns:C,columnVisibility:(z=(O=e.card.preferences)==null?void 0:O.tablePrefs)==null?void 0:z.columnVisibility,onColumnVisibilityChange:p,onShowAllColumns:g,emptyMessage:"Run the table query or add fields before hiding output columns."}):l.jsx(l.Fragment,{children:l.jsx(yge,{columnId:k,availableColumns:y,conditionalRules:x.rules,onConditionalRulesChange:_,startRulesWithNoTrigger:!0})}),l.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.jsxs(m.Button,{type:"button",variant:"secondary",size:"xs",className:"w-full gap-1.5",onClick:()=>s(e),children:[l.jsx(m.Table2,{className:"h-3 w-3"}),"Edit table"]})})]}),e.type==="spacer"&&l.jsx(Go,{label:"Height",children:l.jsx(X4,{"aria-label":"Spacer height",min:8,max:240,value:e.heightPx,onValueChange:L=>o(V=>V.type==="spacer"?{...V,heightPx:L}:V)})})]})}function mvt({page:e,onUpdatePage:t}){const n=(r,o)=>{t({...e,margins:{...e.margins,[r]:o}})};return l.jsxs("div",{className:"space-y-5",children:[l.jsx(Go,{label:"Page size",children:l.jsxs(m.Select,{value:e.size,onValueChange:r=>t({...e,size:r}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Page size",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"letter",children:"Letter"}),l.jsx(m.SelectItem,{value:"a4",children:"A4"})]})]})}),l.jsx(Go,{label:"Orientation",children:l.jsxs(m.Select,{value:e.orientation,onValueChange:r=>t({...e,orientation:r}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Orientation",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"portrait",children:"Portrait"}),l.jsx(m.SelectItem,{value:"landscape",children:"Landscape"})]})]})}),l.jsx(Go,{label:"Margins",children:l.jsx("div",{className:"grid grid-cols-2 gap-2",children:["top","bottom","left","right"].map(r=>l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"mb-1 block text-[10px] capitalize text-muted-foreground",children:r}),l.jsx(X4,{"aria-label":`${r} margin`,min:0,step:.125,value:e.margins[r],onValueChange:o=>n(r,o)})]},r))})})]})}function X4({value:e,onValueChange:t,min:n=0,max:r,step:o,disabled:s,"aria-label":i}){const[a,c]=v.useState(()=>String(e)),[u,d]=v.useState(!1);v.useEffect(()=>{u||c(String(e))},[u,e]);const f=v.useCallback((h,p=!1)=>{if(h.trim()===""){p&&c(String(e));return}const g=Number(h);if(!Number.isFinite(g)){p&&c(String(e));return}const x=p?Math.min(r??g,Math.max(n,g)):g;x<n||r!==void 0&&x>r||(t(x),p&&c(String(x)))},[r,n,t,e]);return l.jsx(m.Input,{"aria-label":i,size:"sm",type:"number",min:n,max:r,step:o,value:a,disabled:s,onFocus:()=>d(!0),onChange:h=>{c(h.target.value),f(h.target.value)},onBlur:()=>{d(!1),f(a,!0)}})}function pvt({pageNumber:e,pageCount:t,onFirst:n,onPrevious:r,onNext:o,onLast:s}){return t<=1?null:l.jsxs("div",{className:"sticky bottom-4 z-20 mx-auto mt-[-44px] flex w-max items-center gap-1.5 rounded-full border border-zinc-200 bg-white/95 px-2.5 py-1 text-[13px] text-zinc-700 shadow-[0_8px_24px_rgba(0,0,0,0.14)] backdrop-blur",children:[l.jsx("button",{type:"button","aria-label":"First document page",disabled:e<=1,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:n,children:l.jsx(GZ,{className:"h-3.5 w-3.5"})}),l.jsx("button",{type:"button","aria-label":"Previous document page",disabled:e<=1,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:r,children:l.jsx(Om,{className:"h-3.5 w-3.5"})}),l.jsxs("span",{className:"min-w-[44px] text-center text-[12px] tabular-nums",children:[e," / ",t]}),l.jsx("button",{type:"button","aria-label":"Next document page",disabled:e>=t,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:o,children:l.jsx(Ft.ChevronRight,{className:"h-3.5 w-3.5"})}),l.jsx("button",{type:"button","aria-label":"Last document page",disabled:e>=t,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:s,children:l.jsx(YZ,{className:"h-3.5 w-3.5"})})]})}const gvt=["#ffffff","#fafafa","#f4f4f5","#e4e4e7","#a1a1aa","#52525b","#27272a","#0f172a","#eff6ff","#eef2ff","#ecfdf5","#fefce8"];function xvt(e){return e.startsWith("#")?e.toLowerCase():`#${e.toLowerCase()}`}function bvt(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function yvt({value:e,onValueChange:t,"aria-label":n}){const[r,o]=v.useState(!1),[s,i]=v.useState(e.toUpperCase());v.useEffect(()=>{i(e.toUpperCase())},[e]);const a=v.useCallback(u=>{const d=xvt(u.trim());if(!bvt(d)){i(e.toUpperCase());return}if(d===e.toLowerCase()){i(d.toUpperCase());return}t(d)},[t,e]),c=e.toLowerCase();return l.jsxs(m.Popover,{open:r,onOpenChange:o,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":n,className:"flex h-7 w-full items-center gap-2 rounded-[5px] border border-input bg-background px-1.5 text-[12px] text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",children:[l.jsx("span",{"aria-hidden":"true",className:"h-4 w-4 shrink-0 rounded-[3px] border border-border/60",style:{backgroundColor:e}}),l.jsx("span",{className:"font-mono text-[11px] uppercase tracking-wide text-foreground",children:e.toUpperCase()}),l.jsx(Om,{"aria-hidden":"true",className:"ml-auto h-3 w-3 shrink-0 -rotate-90 text-muted-foreground/60"})]})}),l.jsxs(m.PopoverContent,{align:"start",sideOffset:4,className:"w-[224px] space-y-2 p-2",onMouseDown:u=>u.stopPropagation(),children:[l.jsx("div",{role:"radiogroup","aria-label":"Color presets",className:"grid grid-cols-6 gap-1",children:gvt.map(u=>{const d=u.toLowerCase()===c;return l.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":u,title:u.toUpperCase(),onClick:()=>{t(u),o(!1)},className:m.cn("relative flex h-7 w-7 items-center justify-center rounded-[4px] border border-border/60 transition-shadow",d&&"ring-1 ring-foreground ring-offset-1"),style:{backgroundColor:u},children:d&&l.jsx(m.Check,{"aria-hidden":"true",className:m.cn("h-3 w-3",vvt(u)?"text-zinc-900":"text-white"),strokeWidth:3})},u)})}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{"aria-hidden":"true",className:"text-[11px] font-medium uppercase tracking-[0.06em] text-muted-foreground",children:"Hex"}),l.jsx(m.Input,{size:"xs",value:s,onChange:u=>i(u.target.value.toUpperCase()),onBlur:u=>a(u.currentTarget.value),onKeyDown:u=>{u.key==="Enter"?u.currentTarget.blur():u.key==="Escape"&&(i(e.toUpperCase()),u.currentTarget.blur())},className:"font-mono text-[11px]"}),l.jsxs("label",{className:"relative inline-flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border border-border/60 bg-background hover:bg-muted/60",title:"Custom color",children:[l.jsx("span",{"aria-hidden":"true",className:"absolute inset-1 rounded-[3px]",style:{backgroundImage:"conic-gradient(from 0deg, #ef4444, #f59e0b, #84cc16, #06b6d4, #6366f1, #ec4899, #ef4444)"}}),l.jsx("input",{"aria-label":`${n??"Color"} (custom)`,type:"color",value:e,onChange:u=>t(u.target.value),className:"absolute inset-0 h-full w-full cursor-pointer opacity-0"})]})]})]})]})}function vvt(e){const t=e.replace("#","");if(t.length!==6)return!0;const n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return .2126*n+.7152*r+.0722*o>150}function wvt({header:e,inputs:t,onUpdateHeader:n}){const r=e?m.getRegionImageBlock(e.blocks,"logo"):void 0,o=e?m.getRegionTextBlock(e.blocks,"title"):void 0,s=e?m.getRegionTextBlock(e.blocks,"metadata"):void 0,i=(r==null?void 0:r.area)==="center"||(r==null?void 0:r.area)==="right"?r.area:"left",a=(u,d,f)=>{n(h=>{const p=h||m.createHeaderRegion();return{...p,enabled:!0,blocks:m.upsertTextRegionBlock(p.blocks,{id:`header_${u}`,role:u,area:d,content:f})}})},c=u=>{n(d=>{const f=d||m.createHeaderRegion(),h=m.getRegionImageBlock(f.blocks,"logo");return{...f,enabled:!0,blocks:m.upsertImageRegionBlock(f.blocks,{id:"header_logo",type:"image",role:"logo",area:"left",src:"",alt:"Logo",widthPx:120,...h,...u})}})};return e?l.jsxs("div",{className:"space-y-4",children:[l.jsx(cge,{label:"Enabled",enabled:!!(e!=null&&e.enabled),onToggle:u=>n(d=>Nge(d,m.createHeaderRegion,u))}),l.jsx(Go,{label:"Logo URL",children:l.jsx(m.Input,{"aria-label":"Logo URL",size:"sm",value:(r==null?void 0:r.src)||"",disabled:!(e!=null&&e.enabled),onChange:u=>c({src:u.target.value})})}),l.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_5rem] gap-2",children:[l.jsx(Go,{label:"Logo placement",children:l.jsxs(m.Select,{value:i,disabled:!(e!=null&&e.enabled),onValueChange:u=>c({area:u}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Logo placement",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"left",children:"Left"}),l.jsx(m.SelectItem,{value:"center",children:"Center"}),l.jsx(m.SelectItem,{value:"right",children:"Right"})]})]})}),l.jsx(Go,{label:"Width",children:l.jsx(X4,{"aria-label":"Logo width",min:24,max:320,step:4,value:(r==null?void 0:r.widthPx)||120,disabled:!(e!=null&&e.enabled),onValueChange:u=>c({widthPx:u})})})]}),l.jsx(Go,{label:"Logo alt text",children:l.jsx(m.Input,{"aria-label":"Logo alt text",size:"sm",value:(r==null?void 0:r.alt)||"",disabled:!(e!=null&&e.enabled),onChange:u=>c({alt:u.target.value})})}),l.jsx(Go,{label:"Title",children:l.jsx(O0,{content:o==null?void 0:o.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:u=>a("title","title",u)})}),l.jsx(Go,{label:"Metadata",children:l.jsx(O0,{content:s==null?void 0:s.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:u=>a("metadata","metadata",u)})})]}):l.jsx(Sge,{title:"No header",description:"Logo, title, and metadata.",actionLabel:"Add header",onAdd:()=>n(()=>m.createHeaderRegion())})}function Cvt({footer:e,inputs:t,onUpdateFooter:n}){const r=e?m.getRegionTextBlock(e.blocks,"note"):void 0,o=e?m.getRegionTextBlock(e.blocks,"pageInfo"):void 0,s=(i,a,c)=>{n(u=>{const d=u||m.createFooterRegion();return{...d,enabled:!0,blocks:m.upsertTextRegionBlock(d.blocks,{id:`footer_${i}`,role:i,area:a,content:c})}})};return e?l.jsxs("div",{className:"space-y-4",children:[l.jsx(cge,{label:"Enabled",enabled:!!(e!=null&&e.enabled),onToggle:i=>n(a=>Nge(a,m.createFooterRegion,i))}),l.jsx(Go,{label:"Note",children:l.jsx(O0,{content:r==null?void 0:r.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:i=>s("note","note",i)})}),l.jsx(Go,{label:"Page info",children:l.jsx(O0,{content:o==null?void 0:o.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:i=>s("pageInfo","pageInfo",i)})})]}):l.jsx(Sge,{title:"No footer",description:"Note and page info.",actionLabel:"Add footer",onAdd:()=>n(()=>Evt())})}function Sge({title:e,description:t,actionLabel:n,onAdd:r}){return l.jsxs("div",{className:"rounded border border-dashed border-border bg-muted/20 p-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx("p",{className:"text-[13px] font-medium text-foreground",children:e}),l.jsx("p",{className:"text-[12px] leading-4 text-muted-foreground",children:t})]}),l.jsx(m.Button,{type:"button",size:"sm",variant:"outline",className:"mt-4 h-8 w-full justify-center text-[12px]",onClick:r,children:n})]})}function Svt({sheetId:e,document:t,selectedSection:n,inputCount:r,onSelectSection:o,onEditTableSection:s}){const i=m.useDashboardStore(N=>N.dashboard),{upsertDashboardInput:a,updateFilterDashboardInputDefinition:c,removeDashboardInput:u,updateSheetDocument:d}=m.useDashboardActions(),f=(n==null?void 0:n.type)==="table"?n:null,h=v.useMemo(()=>kb(i,e),[i,e]),p=v.useMemo(()=>h.map(NC),[h]),g=v.useMemo(()=>new Map((i.inputs||[]).map(N=>[N.id,N])),[i.inputs]),x=t.sections.filter(N=>N.type==="table"),b=v.useCallback(N=>{var k,_;const S=f==null?void 0:f.card;if(!S||h.some(T=>evt(T,N)))return;const j=Xyt({field:N,existingInputs:i.inputs||[],sheetId:e,dataSource:S.dataSource,connectionId:((k=S.dataSource)==null?void 0:k.connectionId)||S.connectionId,connectionType:(_=S.dataSource)==null?void 0:_.connectionType});a(j)},[i.inputs,h,f==null?void 0:f.card,e,a]),y=v.useCallback(N=>{u(N)},[u]),C=v.useCallback((N,S)=>{const j=(i.inputs||[]).find(k=>k.id===N);j&&a({...j,requiredAtExecution:S,...j.kind==="control"?{control:{...j.control,requiredAtExecution:S}}:{}})},[i.inputs,a]),w=v.useCallback((N,S)=>{var T,I,D;const j=h.find(E=>E.id===N);if(!j)return;if(j.kind==="filter"&&j.definitionOrigin==="dashboardFilter"){c(j.id,{...j.filter,title:((T=S.label)==null?void 0:T.trim())||j.filter.title,variableName:S.variableName||j.filter.variableName},S.variableName===void 0?{label:((I=S.label)==null?void 0:I.trim())||j.label}:{variableName:S.variableName,label:((D=S.label)==null?void 0:D.trim())||j.label});return}const k=g.get(N);if(!k)return;const _=Cge({input:k,allInputs:i.inputs||[],...S});a(_),j.kind==="control"&&_.kind==="control"&&j.control.id!==_.control.id&&d(e,E=>hO(E,j.control.id,_.control.id))},[i.inputs,h,g,e,d,c,a]);return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("h3",{className:"text-[12px] font-medium text-foreground",children:"Document inputs"}),l.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:r})]}),l.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Add document-wide filter inputs from the selected table fields."})]}),l.jsx(Nvt,{selectedTableSection:f,tableSections:x,inputs:p,onSelectTable:o,onEditTableSection:s,onAddField:b}),l.jsx(kvt,{inputs:p,onUpdateMetadata:w,onRemove:y,onSetRequired:C})]})}function Nvt({selectedTableSection:e,tableSections:t,inputs:n,onSelectTable:r,onEditTableSection:o,onAddField:s}){return t.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center rounded-md border bg-muted/20 px-4 py-6 text-center",children:[l.jsx(li,{className:"mb-2 h-5 w-5 text-muted-foreground/50"}),l.jsx("h3",{className:"mb-1 text-[12px] font-medium text-foreground",children:"No table sections"}),l.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Add a document table before creating filter inputs."})]}):e?e.card?l.jsx(jvt,{section:e,inputs:n,onAddField:s}):l.jsxs("div",{className:"space-y-2 rounded-md border bg-muted/20 p-3 text-[12px] text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-2 text-foreground",children:[l.jsx(ps,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"font-medium",children:"Configure this table"})]}),l.jsx("p",{children:"Choose a data source before adding document inputs."}),l.jsxs(m.Button,{type:"button",variant:"secondary",size:"sm",className:"h-8 w-full gap-2",onClick:()=>o(e),children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Configure table"]})]}):l.jsxs("div",{className:"rounded-md border bg-background",children:[l.jsx("div",{className:"border-b px-2.5 py-2 text-[11px] font-medium text-muted-foreground",children:"Choose a table section"}),l.jsx("div",{className:"space-y-1 p-1.5",children:t.map(i=>{var a;return l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-full justify-start gap-2 px-2 text-xs",onClick:()=>r(i.id),children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),i.title||((a=i.card)==null?void 0:a.title)||"Table"]},i.id)})})]})}function jvt({section:e,inputs:t,onAddField:n}){var i,a;const r=m.useEditorStore(c=>{var u;return(u=c.card)==null?void 0:u.id}),{setCard:o}=m.useEditorActions(),s=v.useMemo(()=>t.filter(pl).map(c=>({id:c.filter.id,column:c.filter.column,title:c.filter.title,dataType:c.filter.dataType,table:c.filter.table||"",database:c.filter.database||"",qualifiedTableName:c.filter.qualifiedTableName,connectionId:c.filter.connectionId,operation:c.filter.operation,sql:c.filter.sql,fieldMeta:c.filter.fieldMeta,semanticContext:c.filter.semanticContext})),[t]);return v.useEffect(()=>{e.card&&o(e.card)},[e.card,o]),r!==((i=e.card)==null?void 0:i.id)?l.jsx("div",{className:"rounded border border-dashed p-4 text-[12px] text-muted-foreground",children:"Loading fields..."}):l.jsxs("div",{className:"flex flex-col overflow-hidden rounded-md border bg-background",children:[l.jsxs("div",{className:"border-b px-2.5 py-2 text-[12px] text-muted-foreground",children:["Fields from"," ",l.jsx("span",{className:"font-medium text-foreground",children:e.title||((a=e.card)==null?void 0:a.title)||"this table"})]}),l.jsx(cpe,{className:"h-[300px]",context:"document-filter",inlineFilters:s,onFieldSelect:n})]})}function kvt({inputs:e,onUpdateMetadata:t,onRemove:n,onSetRequired:r}){return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("p",{className:"text-[11px] font-medium text-muted-foreground",children:"Active inputs"}),e.length>0?l.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:e.length}):null]}),e.length===0?l.jsx("div",{className:"rounded-md border bg-muted/20 px-3 py-2 text-[11px] text-muted-foreground",children:"No document inputs yet."}):l.jsx("div",{className:"space-y-1",children:e.map(o=>l.jsx(Ivt,{input:o,onUpdateMetadata:s=>t(o.id,s),onRemove:()=>n(o.id),onSetRequired:s=>r(o.id,s)},o.id))})]})}function Ivt({input:e,onUpdateMetadata:t,onSetRequired:n,onRemove:r}){const[o,s]=v.useState(e.label);v.useEffect(()=>{s(e.label)},[e.id,e.label]);const i=v.useCallback(()=>{const c=o.trim();if(!c){s(e.label);return}c!==e.label&&t({label:c})},[e.label,o,t]),a=c=>{c.key==="Enter"&&(c.preventDefault(),c.currentTarget.blur())};return l.jsxs("div",{className:"rounded-md border bg-background px-2.5 py-2",children:[l.jsxs("div",{className:"flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[l.jsx(m.Input,{size:"xs",className:"h-6 min-w-0 border-0 bg-transparent px-0 py-0 text-[12px] font-medium shadow-none focus-visible:ring-0",value:o,onChange:c=>s(c.target.value),onBlur:i,onKeyDown:a,"aria-label":`${e.label} input label`}),l.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium uppercase text-muted-foreground",children:e.kind==="control"?"Control":"Filter"})]}),l.jsx(m.Input,{size:"xs",className:"h-6 min-w-0 rounded border bg-muted/20 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground shadow-none focus-visible:ring-0",value:`{{${e.variableName}}}`,readOnly:!0,"aria-label":`${e.label} input token`})]}),l.jsx("div",{className:"flex shrink-0 items-center gap-1",children:l.jsx(m.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 hover:bg-destructive/10 hover:text-destructive",onClick:r,"aria-label":`Remove ${e.label} document input`,children:l.jsx(Ra,{className:"h-3 w-3"})})})]}),l.jsxs("label",{className:"mt-2 flex items-center justify-between gap-2 border-t pt-1.5 text-[11px] text-muted-foreground",children:[l.jsx("span",{children:"Required"}),l.jsx(m.Switch,{size:"xs",checked:e.requiredAtExecution,onCheckedChange:n,"aria-label":`Required ${e.label}`})]})]})}function _vt(e,t,n,r){return{...e,inputs:(e.inputs||[]).map(o=>{if(o.id!==t||!pl(o))return o;const s={...o.filter,...n};return{...o,label:s.title||o.label,variableName:(r==null?void 0:r.variableName)||o.variableName,filter:s,exports:WT(s)}})}}function Tvt(e,t,n){return{...e,inputs:(e.inputs||[]).map(r=>r.id!==t||!oc(r)?r:{...r,label:n.label||r.label,requiredAtExecution:n.requiredAtExecution,control:n})}}function Dvt(e,t){return e.reduce((n,r)=>{if(!pl(r))return n;const o=t[r.id];return o&&VT(o.operation)&&(n[r.id]=Cpe(o.operation)),n},{})}function Nge(e,t,n){return e?{...e,enabled:n}:n?t():void 0}function Evt(){const e=m.createFooterRegion();return{...e,blocks:m.upsertTextRegionBlock(e.blocks,{id:"footer_pageInfo",role:"pageInfo",area:"pageInfo",content:[{type:"text",value:"Page "},{type:"variable",ref:{source:"documentMeta",key:"pageNumber"}},{type:"text",value:" of "},{type:"variable",ref:{source:"documentMeta",key:"pageCount"}}]})}}function Mvt(e,t){return e.length!==t.length?!1:e.every((n,r)=>{var o,s;return n.value===((o=t[r])==null?void 0:o.value)&&n.label===((s=t[r])==null?void 0:s.label)})}const Hf=[50,75,100,125,150],U2="inline-flex h-full items-center gap-1.5 rounded-none border-0 bg-transparent px-2 text-[12px] transition-colors";function fG({children:e}){return l.jsx("div",{className:"inline-flex h-7 shrink-0 items-center overflow-hidden rounded-[5px] border border-border bg-background text-foreground",children:e})}function K2(){return l.jsx("span",{"aria-hidden":"true",className:"h-full w-px bg-border"})}function Rvt({zoom:e,onZoomChange:t}){const n=Hf.indexOf(e),r=n>0,o=n>=0&&n<Hf.length-1;return l.jsxs("div",{className:"inline-flex h-full items-center gap-0.5 bg-transparent px-1",children:[l.jsx("button",{type:"button",disabled:!r,onClick:()=>{const s=Hf.indexOf(e);s>0&&t(Hf[s-1])},"aria-label":"Zoom out",className:"inline-flex h-5 w-5 items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-muted-foreground",children:l.jsx(Vc,{className:"h-3 w-3"})}),l.jsxs("span",{className:"min-w-[34px] px-1 text-center text-[11px] tabular-nums text-foreground",children:[e,"%"]}),l.jsx("button",{type:"button",disabled:!o,onClick:()=>{const s=Hf.indexOf(e);s>=0&&s<Hf.length-1&&t(Hf[s+1])},"aria-label":"Zoom in",className:"inline-flex h-5 w-5 items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-muted-foreground",children:l.jsx(Ar,{className:"h-3 w-3"})})]})}const Avt=zV.WidthProvider(zV.Responsive),Fvt=["input","textarea","select","button","a",'[role="button"]','[role="menuitem"]','[contenteditable="true"]',"[data-rgl-drag-cancel]",".data-table-scroll-container"].join(", ");function W2(e){if(!e)return null;let t=!1;const n={};for(const[r,o]of Object.entries(e))n[r]=o.map(s=>{const i=Number(s.w),a=Number(s.h);if(i===1&&a===1)return s;const c=s.minH!==void 0&&s.minH!==null,u=Number(s.minH),d=c&&Number.isFinite(u)?Math.max(1,u):void 0,f=Number.isFinite(a)?Math.max(1,a):1,h=d!==void 0?Math.max(d,f):f;if((h!==s.h||d!==s.minH)&&(t=!0),d===void 0){const{minH:p,...g}=s;return{...g,h}}return{...s,h,minH:d}});return t?n:null}function Pvt(){const{open:e}=xL();return e?l.jsx(Xht,{}):null}function hG({sheet:e}){return e.kind==="document"?l.jsx(cvt,{sheet:e}):l.jsx(Ovt,{sheet:e})}function Ovt({sheet:e}){var F,M;const t=m.useDashboardStore(O=>O.isDashboardEditing),n=m.useDashboardStore(O=>O.currentBreakpoint),r=m.useDashboardStore(O=>O.themeStyle),o=Pu(),s=v.useRef(0),i=v.useRef(!1),a=v.useRef(null),c=m.useDashboardStore(O=>O.selectedSheetId),u=e.layouts,d=v.useMemo(()=>W2(u),[u]),f=d||u,[h,p]=v.useState(f),g=v.useRef(f),x=e.frames,{setSheetLayouts:b,setCurrentBreakpoint:y}=m.useDashboardStore(O=>O.actions);v.useEffect(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},[e.id]),v.useEffect(()=>{i.current||nO(g.current,f)&&(g.current=f,p(f))},[f]),v.useEffect(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);function C(O){y(O)}const w=O=>{g.current=O,p(O)},N=O=>{a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{a.current=null,v.startTransition(()=>{b(e.id,O)})},0)};function S(O,z){if(!i.current){W2(z);const L=Qht(u,d);c===e.id&&L&&(w(L),N(L));return}}const j=()=>{i.current=!0},k=O=>{if(O&&c===e.id){const z={...g.current||f||{},[n]:O},V=W2(z)||z;w(V),nO(u,V)&&N(V)}i.current=!1};if(!c)return null;const _=(O,z)=>l.jsx(jge,{className:"after:content-none",ref:z,handleAxis:O});function T(){return x==null?void 0:x.map(O=>l.jsx("div",{role:"dashboard-frame-container",className:m.cn("group isolate overflow-hidden",r==null?void 0:r.dashboardCardContainer),children:l.jsx(ui,{FallbackComponent:({error:z,resetErrorBoundary:L})=>l.jsx(Xet,{error:z,resetErrorBoundary:L,frame:O}),children:l.jsx(idt,{frame:O})})},O.id))}const I=((F=r==null?void 0:r.gridLayout)==null?void 0:F.margin)??[10,10],D=o.gridMargin??I,E=o.gridContainerPadding??(o.gridMargin?I:void 0),R={...(r==null?void 0:r.cardBorderRadius)!==void 0?{"--placeholder-border-radius":`${r.cardBorderRadius}px`}:{},...o.gridStyle};return!x||x.length===0?l.jsx(fdt,{sheetId:e.id}):l.jsxs(ETe,{children:[l.jsx(Avt,{margin:D,containerPadding:E,isDraggable:t,draggableCancel:t?Fvt:void 0,resizeHandles:t?["s","w","e","n","sw","nw","se","ne"]:[],className:m.cn((M=r==null?void 0:r.gridLayout)==null?void 0:M.className),style:R,layouts:h,cols:{lg:48,md:36,sm:24,xs:12,xxs:6},rowHeight:1,onBreakpointChange:C,onLayoutChange:S,onDragStart:j,onDragStop:O=>k(O),onResizeStart:j,onResize:(O,z,L,V,A,B)=>{const $=Date.now();$-s.current>100&&(B.scrollIntoView({behavior:"auto",block:"nearest"}),s.current=$)},onResizeStop:(O,z,L,V,A,B)=>{B.scrollIntoView({behavior:"smooth",block:"nearest"}),k(O)},resizeHandle:_,children:T()}),l.jsx(Pvt,{})]})}const jge=v.forwardRef(({className:e,handleAxis:t,...n},r)=>{const o=m.useDashboardStore(s=>s.themeStyle);return o!=null&&o.cardBorderRadius,l.jsx("div",{ref:r,className:m.cn(`react-resizable-handle z-20 react-resizable-handle-${t} absolute border-foreground/40`,{"z-30 h-4 w-4":["sw","nw","se","ne"].includes(t),"bottom-0 left-0 cursor-sw-resize":t==="sw","left-0 top-0 cursor-nw-resize":t==="nw","bottom-0 right-0 cursor-se-resize":t==="se","right-0 top-0 cursor-ne-resize":t==="ne","!bottom-0 !left-0 !right-0 !h-2 !w-full cursor-ns-resize":t==="s","!left-0 !right-0 !top-0 !h-2 !w-full cursor-ns-resize":t==="n","!bottom-0 !right-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="e","!bottom-0 !left-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="w"},e),...n})});jge.displayName="ResizeHandle";const GT=v.createContext(null);GT.displayName="PanelGroupContext";const oo={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},Q4=10,Zh=v.useLayoutEffect,mG=ie.useId,Lvt=typeof mG=="function"?mG:()=>null;let $vt=0;function J4(e=null){const t=Lvt(),n=v.useRef(e||t||null);return n.current===null&&(n.current=""+$vt++),e??n.current}function kge({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:o,forwardedRef:s,id:i,maxSize:a,minSize:c,onCollapse:u,onExpand:d,onResize:f,order:h,style:p,tagName:g="div",...x}){const b=v.useContext(GT);if(b===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:C,getPanelSize:w,getPanelStyle:N,groupId:S,isPanelCollapsed:j,reevaluatePanelConstraints:k,registerPanel:_,resizePanel:T,unregisterPanel:I}=b,D=J4(i),E=v.useRef({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:o,maxSize:a,minSize:c},id:D,idIsFromProps:i!==void 0,order:h});v.useRef({didLogMissingDefaultSizeWarning:!1}),Zh(()=>{const{callbacks:F,constraints:M}=E.current,O={...M};E.current.id=D,E.current.idIsFromProps=i!==void 0,E.current.order=h,F.onCollapse=u,F.onExpand=d,F.onResize=f,M.collapsedSize=n,M.collapsible=r,M.defaultSize=o,M.maxSize=a,M.minSize=c,(O.collapsedSize!==M.collapsedSize||O.collapsible!==M.collapsible||O.maxSize!==M.maxSize||O.minSize!==M.minSize)&&k(E.current,O)}),Zh(()=>{const F=E.current;return _(F),()=>{I(F)}},[h,D,_,I]),v.useImperativeHandle(s,()=>({collapse:()=>{y(E.current)},expand:F=>{C(E.current,F)},getId(){return D},getSize(){return w(E.current)},isCollapsed(){return j(E.current)},isExpanded(){return!j(E.current)},resize:F=>{T(E.current,F)}}),[y,C,w,j,D,T]);const R=N(E.current,o);return v.createElement(g,{...x,children:e,className:t,id:D,style:{...R,...p},[oo.groupId]:S,[oo.panel]:"",[oo.panelCollapsible]:r||void 0,[oo.panelId]:D,[oo.panelSize]:parseFloat(""+R.flexGrow).toFixed(1)})}const Ige=v.forwardRef((e,t)=>v.createElement(kge,{...e,forwardedRef:t}));kge.displayName="Panel";Ige.displayName="forwardRef(Panel)";let mO=null,wN=-1,rd=null;function zvt(e,t){if(t){const n=(t&Mge)!==0,r=(t&Rge)!==0,o=(t&Age)!==0,s=(t&Fge)!==0;if(n)return o?"se-resize":s?"ne-resize":"e-resize";if(r)return o?"sw-resize":s?"nw-resize":"w-resize";if(o)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function Bvt(){rd!==null&&(document.head.removeChild(rd),mO=null,rd=null,wN=-1)}function G2(e,t){var n,r;const o=zvt(e,t);if(mO!==o){if(mO=o,rd===null&&(rd=document.createElement("style"),document.head.appendChild(rd)),wN>=0){var s;(s=rd.sheet)===null||s===void 0||s.removeRule(wN)}wN=(n=(r=rd.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${o} !important;}`))!==null&&n!==void 0?n:-1}}function _ge(e){return e.type==="keydown"}function Tge(e){return e.type.startsWith("pointer")}function Dge(e){return e.type.startsWith("mouse")}function YT(e){if(Tge(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Dge(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function Vvt(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Hvt(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function qvt(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:xG(e),b:xG(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Tn(r,"Stacking order can only be calculated for elements with a common ancestor");const o={a:gG(pG(n.a)),b:gG(pG(n.b))};if(o.a===o.b){const s=r.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===i.a)return 1;if(c===i.b)return-1}}return Math.sign(o.a-o.b)}const Uvt=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Kvt(e){var t;const n=getComputedStyle((t=Ege(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Wvt(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Kvt(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||Uvt.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function pG(e){let t=e.length;for(;t--;){const n=e[t];if(Tn(n,"Missing node"),Wvt(n))return n}return null}function gG(e){return e&&Number(getComputedStyle(e).zIndex)||0}function xG(e){const t=[];for(;e;)t.push(e),e=Ege(e);return t}function Ege(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Mge=1,Rge=2,Age=4,Fge=8,Gvt=Vvt()==="coarse";let al=[],Tg=!1,ah=new Map,ZT=new Map;const L0=new Set;function Yvt(e,t,n,r,o){var s;const{ownerDocument:i}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:o},c=(s=ah.get(i))!==null&&s!==void 0?s:0;return ah.set(i,c+1),L0.add(a),qk(),function(){var d;ZT.delete(e),L0.delete(a);const f=(d=ah.get(i))!==null&&d!==void 0?d:1;if(ah.set(i,f-1),qk(),f===1&&ah.delete(i),al.includes(a)){const h=al.indexOf(a);h>=0&&al.splice(h,1),tB(),o("up",!0,null)}}}function Zvt(e){const{target:t}=e,{x:n,y:r}=YT(e);Tg=!0,eB({target:t,x:n,y:r}),qk(),al.length>0&&(Uk("down",e),e.preventDefault(),Pge(t)||e.stopImmediatePropagation())}function Y2(e){const{x:t,y:n}=YT(e);if(Tg&&e.buttons===0&&(Tg=!1,Uk("up",e)),!Tg){const{target:r}=e;eB({target:r,x:t,y:n})}Uk("move",e),tB(),al.length>0&&e.preventDefault()}function Z2(e){const{target:t}=e,{x:n,y:r}=YT(e);ZT.clear(),Tg=!1,al.length>0&&(e.preventDefault(),Pge(t)||e.stopImmediatePropagation()),Uk("up",e),eB({target:t,x:n,y:r}),tB(),qk()}function Pge(e){let t=e;for(;t;){if(t.hasAttribute(oo.resizeHandle))return!0;t=t.parentElement}return!1}function eB({target:e,x:t,y:n}){al.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),L0.forEach(o=>{const{element:s,hitAreaMargins:i}=o,a=s.getBoundingClientRect(),{bottom:c,left:u,right:d,top:f}=a,h=Gvt?i.coarse:i.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=c+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&qvt(r,s)>0){let g=r,x=!1;for(;g&&!g.contains(s);){if(Hvt(g.getBoundingClientRect(),a)){x=!0;break}g=g.parentElement}if(x)return}al.push(o)}})}function X2(e,t){ZT.set(e,t)}function tB(){let e=!1,t=!1;al.forEach(r=>{const{direction:o}=r;o==="horizontal"?e=!0:t=!0});let n=0;ZT.forEach(r=>{n|=r}),e&&t?G2("intersection",n):e?G2("horizontal",n):t?G2("vertical",n):Bvt()}let Q2=new AbortController;function qk(){Q2.abort(),Q2=new AbortController;const e={capture:!0,signal:Q2.signal};L0.size&&(Tg?(al.length>0&&ah.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("contextmenu",Z2,e),r.addEventListener("pointerleave",Y2,e),r.addEventListener("pointermove",Y2,e))}),window.addEventListener("pointerup",Z2,e),window.addEventListener("pointercancel",Z2,e)):ah.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("pointerdown",Zvt,e),r.addEventListener("pointermove",Y2,e))}))}function Uk(e,t){L0.forEach(n=>{const{setResizeHandlerState:r}=n,o=al.includes(n);r(e,o,t)})}function Xvt(){const[e,t]=v.useState(0);return v.useCallback(()=>t(n=>n+1),[])}function Tn(e,t){if(!e)throw console.error(t),Error(t)}function Mm(e,t,n=Q4){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function Kc(e,t,n=Q4){return Mm(e,t,n)===0}function Wi(e,t,n){return Mm(e,t,n)===0}function Qvt(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const o=e[r],s=t[r];if(!Wi(o,s,n))return!1}return!0}function dg({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Tn(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:o=0,collapsible:s,maxSize:i=100,minSize:a=0}=r;if(Mm(n,a)<0)if(s){const c=(o+a)/2;Mm(n,c)<0?n=o:n=a}else n=a;return n=Math.min(i,n),n=parseFloat(n.toFixed(Q4)),n}function qy({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:o,trigger:s}){if(Wi(e,0))return t;const i=[...t],[a,c]=r;Tn(a!=null,"Invalid first pivot index"),Tn(c!=null,"Invalid second pivot index");let u=0;if(s==="keyboard"){{const f=e<0?c:a,h=n[f];Tn(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:x=0}=h;if(g){const b=t[f];if(Tn(b!=null,`Previous layout not found for panel index ${f}`),Wi(b,p)){const y=x-b;Mm(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:c,h=n[f];Tn(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:x=0}=h;if(g){const b=t[f];if(Tn(b!=null,`Previous layout not found for panel index ${f}`),Wi(b,x)){const y=b-p;Mm(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let h=e<0?c:a,p=0;for(;;){const x=t[h];Tn(x!=null,`Previous layout not found for panel index ${h}`);const y=dg({panelConstraints:n,panelIndex:h,size:100})-x;if(p+=y,h+=f,h<0||h>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-g:g}{let h=e<0?a:c;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(u),g=t[h];Tn(g!=null,`Previous layout not found for panel index ${h}`);const x=g-p,b=dg({panelConstraints:n,panelIndex:h,size:x});if(!Wi(g,b)&&(u+=g-b,i[h]=b,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(Qvt(o,i))return o;{const f=e<0?c:a,h=t[f];Tn(h!=null,`Previous layout not found for panel index ${f}`);const p=h+u,g=dg({panelConstraints:n,panelIndex:f,size:p});if(i[f]=g,!Wi(g,p)){let x=p-g,y=e<0?c:a;for(;y>=0&&y<n.length;){const C=i[y];Tn(C!=null,`Previous layout not found for panel index ${y}`);const w=C+x,N=dg({panelConstraints:n,panelIndex:y,size:w});if(Wi(C,N)||(x-=N-C,i[y]=N),Wi(x,0))break;e>0?y--:y++}}}const d=i.reduce((f,h)=>h+f,0);return Wi(d,100)?i:o}function Jvt({layout:e,panelsArray:t,pivotIndices:n}){let r=0,o=100,s=0,i=0;const a=n[0];Tn(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:p}=f,{maxSize:g=100,minSize:x=0}=p;h===a?(r=x,o=g):(s+=x,i+=g)});const c=Math.min(o,100-s),u=Math.max(r,100-i),d=e[a];return{valueMax:c,valueMin:u,valueNow:d}}function $0(e,t=document){return Array.from(t.querySelectorAll(`[${oo.resizeHandleId}][data-panel-group-id="${e}"]`))}function Oge(e,t,n=document){const o=$0(e,n).findIndex(s=>s.getAttribute(oo.resizeHandleId)===t);return o??null}function Lge(e,t,n){const r=Oge(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function $ge(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function XT(e,t=document){const n=t.querySelector(`[${oo.resizeHandleId}="${e}"]`);return n||null}function e0t(e,t,n,r=document){var o,s,i,a;const c=XT(t,r),u=$0(e,r),d=c?u.indexOf(c):-1,f=(o=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&o!==void 0?o:null,h=(i=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&i!==void 0?i:null;return[f,h]}function t0t({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:o,panelGroupElement:s,setLayout:i}){v.useRef({didWarnAboutMissingResizeHandle:!1}),Zh(()=>{if(!s)return;const a=$0(n,s);for(let c=0;c<o.length-1;c++){const{valueMax:u,valueMin:d,valueNow:f}=Jvt({layout:r,panelsArray:o,pivotIndices:[c,c+1]}),h=a[c];if(h!=null){const p=o[c];Tn(p,`No panel data found for index "${c}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((c,u)=>{c.removeAttribute("aria-controls"),c.removeAttribute("aria-valuemax"),c.removeAttribute("aria-valuemin"),c.removeAttribute("aria-valuenow")})}},[n,r,o,s]),v.useEffect(()=>{if(!s)return;const a=t.current;Tn(a,"Eager values not found");const{panelDataArray:c}=a,u=$ge(n,s);Tn(u!=null,`No group found for id "${n}"`);const d=$0(n,s);Tn(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute(oo.resizeHandleId);Tn(p,"Resize handle element has no handle id attribute");const[g,x]=e0t(n,p,c,s);if(g==null||x==null)return()=>{};const b=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const C=c.findIndex(w=>w.id===g);if(C>=0){const w=c[C];Tn(w,`No panel data found for index ${C}`);const N=r[C],{collapsedSize:S=0,collapsible:j,minSize:k=0}=w.constraints;if(N!=null&&j){const _=qy({delta:Wi(N,S)?k-S:S-N,initialLayout:r,panelConstraints:c.map(T=>T.constraints),pivotIndices:Lge(n,p,s),prevLayout:r,trigger:"keyboard"});r!==_&&i(_)}}break}}};return h.addEventListener("keydown",b),()=>{h.removeEventListener("keydown",b)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,o,i])}function bG(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function zge(e,t){const n=e==="horizontal",{x:r,y:o}=YT(t);return n?r:o}function n0t(e,t,n,r,o){const s=n==="horizontal",i=XT(t,o);Tn(i,`No resize handle element found for id "${t}"`);const a=i.getAttribute(oo.groupId);Tn(a,"Resize handle element has no group id attribute");let{initialCursorPosition:c}=r;const u=zge(n,e),d=$ge(a,o);Tn(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(u-c)/h*100}function r0t(e,t,n,r,o,s){if(_ge(e)){const i=n==="horizontal";let a=0;e.shiftKey?a=100:o!=null?a=o:a=10;let c=0;switch(e.key){case"ArrowDown":c=i?0:a;break;case"ArrowLeft":c=i?-a:0;break;case"ArrowRight":c=i?a:0;break;case"ArrowUp":c=i?0:-a;break;case"End":c=100;break;case"Home":c=-100;break}return c}else return r==null?0:n0t(e,t,n,r,s)}function o0t({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,o=100;for(let s=0;s<e.length;s++){const i=n[s];Tn(i,`Panel constraints not found for index ${s}`);const{defaultSize:a}=i;a!=null&&(r++,t[s]=a,o-=a)}for(let s=0;s<e.length;s++){const i=n[s];Tn(i,`Panel constraints not found for index ${s}`);const{defaultSize:a}=i;if(a!=null)continue;const c=e.length-r,u=o/c;r++,t[s]=u,o-=u}return t}function Fp(e,t,n){t.forEach((r,o)=>{const s=e[o];Tn(s,`Panel data not found for index ${o}`);const{callbacks:i,constraints:a,id:c}=s,{collapsedSize:u=0,collapsible:d}=a,f=n[c];if(f==null||r!==f){n[c]=r;const{onCollapse:h,onExpand:p,onResize:g}=i;g&&g(r,f),d&&(h||p)&&(p&&(f==null||Kc(f,u))&&!Kc(r,u)&&p(),h&&(f==null||!Kc(f,u))&&Kc(r,u)&&h())}})}function N1(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function s0t({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:o,precision:s=3}){const i=n[o];let a;return i==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=i.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function i0t(e,t=10){let n=null;return(...o)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...o)},t)}}function yG(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function Bge(e){return`react-resizable-panels:${e}`}function Vge(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:o,order:s}=t;return o?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function Hge(e,t){try{const n=Bge(e),r=t.getItem(n);if(r){const o=JSON.parse(r);if(typeof o=="object"&&o!=null)return o}}catch{}return null}function a0t(e,t,n){var r,o;const s=(r=Hge(e,n))!==null&&r!==void 0?r:{},i=Vge(t);return(o=s[i])!==null&&o!==void 0?o:null}function l0t(e,t,n,r,o){var s;const i=Bge(e),a=Vge(t),c=(s=Hge(e,o))!==null&&s!==void 0?s:{};c[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{o.setItem(i,JSON.stringify(c))}catch(u){console.error(u)}}function vG({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,i)=>s+i,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Wi(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=100/r*i;n[s]=a}let o=0;for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=dg({panelConstraints:t,panelIndex:s,size:i});i!=a&&(o+=i-a,n[s]=a)}if(!Wi(o,0))for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=i+o,c=dg({panelConstraints:t,panelIndex:s,size:a});if(i!==c&&(o-=c-i,n[s]=c,Wi(o,0)))break}return n}const c0t=100,Uy={getItem:e=>(yG(Uy),Uy.getItem(e)),setItem:(e,t)=>{yG(Uy),Uy.setItem(e,t)}},wG={};function qge({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:o,id:s=null,onLayout:i=null,keyboardResizeBy:a=null,storage:c=Uy,style:u,tagName:d="div",...f}){const h=J4(s),p=v.useRef(null),[g,x]=v.useState(null),[b,y]=v.useState([]),C=Xvt(),w=v.useRef({}),N=v.useRef(new Map),S=v.useRef(0),j=v.useRef({autoSaveId:e,direction:r,dragState:g,id:h,keyboardResizeBy:a,onLayout:i,storage:c}),k=v.useRef({layout:b,panelDataArray:[],panelDataArrayChanged:!1});v.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),v.useImperativeHandle(o,()=>({getId:()=>j.current.id,getLayout:()=>{const{layout:P}=k.current;return P},setLayout:P=>{const{onLayout:U}=j.current,{layout:H,panelDataArray:G}=k.current,q=vG({layout:P,panelConstraints:G.map(Y=>Y.constraints)});bG(H,q)||(y(q),k.current.layout=q,U&&U(q),Fp(G,q,w.current))}}),[]),Zh(()=>{j.current.autoSaveId=e,j.current.direction=r,j.current.dragState=g,j.current.id=h,j.current.onLayout=i,j.current.storage=c}),t0t({committedValuesRef:j,eagerValuesRef:k,groupId:h,layout:b,panelDataArray:k.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),v.useEffect(()=>{const{panelDataArray:P}=k.current;if(e){if(b.length===0||b.length!==P.length)return;let U=wG[e];U==null&&(U=i0t(l0t,c0t),wG[e]=U);const H=[...P],G=new Map(N.current);U(e,H,G,b,c)}},[e,b,c]),v.useEffect(()=>{});const _=v.useCallback(P=>{const{onLayout:U}=j.current,{layout:H,panelDataArray:G}=k.current;if(P.constraints.collapsible){const q=G.map(Z=>Z.constraints),{collapsedSize:Y=0,panelSize:W,pivotIndices:ne}=qf(G,P,H);if(Tn(W!=null,`Panel size not found for panel "${P.id}"`),!Kc(W,Y)){N.current.set(P.id,W);const K=Wp(G,P)===G.length-1?W-Y:Y-W,X=qy({delta:K,initialLayout:H,panelConstraints:q,pivotIndices:ne,prevLayout:H,trigger:"imperative-api"});N1(H,X)||(y(X),k.current.layout=X,U&&U(X),Fp(G,X,w.current))}}},[]),T=v.useCallback((P,U)=>{const{onLayout:H}=j.current,{layout:G,panelDataArray:q}=k.current;if(P.constraints.collapsible){const Y=q.map(J=>J.constraints),{collapsedSize:W=0,panelSize:ne=0,minSize:Z=0,pivotIndices:K}=qf(q,P,G),X=U??Z;if(Kc(ne,W)){const J=N.current.get(P.id),re=J!=null&&J>=X?J:X,Q=Wp(q,P)===q.length-1?ne-re:re-ne,se=qy({delta:Q,initialLayout:G,panelConstraints:Y,pivotIndices:K,prevLayout:G,trigger:"imperative-api"});N1(G,se)||(y(se),k.current.layout=se,H&&H(se),Fp(q,se,w.current))}}},[]),I=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{panelSize:G}=qf(H,P,U);return Tn(G!=null,`Panel size not found for panel "${P.id}"`),G},[]),D=v.useCallback((P,U)=>{const{panelDataArray:H}=k.current,G=Wp(H,P);return s0t({defaultSize:U,dragState:g,layout:b,panelData:H,panelIndex:G})},[g,b]),E=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{collapsedSize:G=0,collapsible:q,panelSize:Y}=qf(H,P,U);return Tn(Y!=null,`Panel size not found for panel "${P.id}"`),q===!0&&Kc(Y,G)},[]),R=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{collapsedSize:G=0,collapsible:q,panelSize:Y}=qf(H,P,U);return Tn(Y!=null,`Panel size not found for panel "${P.id}"`),!q||Mm(Y,G)>0},[]),F=v.useCallback(P=>{const{panelDataArray:U}=k.current;U.push(P),U.sort((H,G)=>{const q=H.order,Y=G.order;return q==null&&Y==null?0:q==null?-1:Y==null?1:q-Y}),k.current.panelDataArrayChanged=!0,C()},[C]);Zh(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:P,onLayout:U,storage:H}=j.current,{layout:G,panelDataArray:q}=k.current;let Y=null;if(P){const ne=a0t(P,q,H);ne&&(N.current=new Map(Object.entries(ne.expandToSizes)),Y=ne.layout)}Y==null&&(Y=o0t({panelDataArray:q}));const W=vG({layout:Y,panelConstraints:q.map(ne=>ne.constraints)});bG(G,W)||(y(W),k.current.layout=W,U&&U(W),Fp(q,W,w.current))}}),Zh(()=>{const P=k.current;return()=>{P.layout=[]}},[]);const M=v.useCallback(P=>{let U=!1;const H=p.current;return H&&window.getComputedStyle(H,null).getPropertyValue("direction")==="rtl"&&(U=!0),function(q){q.preventDefault();const Y=p.current;if(!Y)return()=>null;const{direction:W,dragState:ne,id:Z,keyboardResizeBy:K,onLayout:X}=j.current,{layout:J,panelDataArray:re}=k.current,{initialLayout:te}=ne??{},Q=Lge(Z,P,Y);let se=r0t(q,P,W,ne,K,Y);const oe=W==="horizontal";oe&&U&&(se=-se);const fe=re.map(Ie=>Ie.constraints),pe=qy({delta:se,initialLayout:te??J,panelConstraints:fe,pivotIndices:Q,prevLayout:J,trigger:_ge(q)?"keyboard":"mouse-or-touch"}),xe=!N1(J,pe);(Tge(q)||Dge(q))&&S.current!=se&&(S.current=se,!xe&&se!==0?oe?X2(P,se<0?Mge:Rge):X2(P,se<0?Age:Fge):X2(P,0)),xe&&(y(pe),k.current.layout=pe,X&&X(pe),Fp(re,pe,w.current))}},[]),O=v.useCallback((P,U)=>{const{onLayout:H}=j.current,{layout:G,panelDataArray:q}=k.current,Y=q.map(J=>J.constraints),{panelSize:W,pivotIndices:ne}=qf(q,P,G);Tn(W!=null,`Panel size not found for panel "${P.id}"`);const K=Wp(q,P)===q.length-1?W-U:U-W,X=qy({delta:K,initialLayout:G,panelConstraints:Y,pivotIndices:ne,prevLayout:G,trigger:"imperative-api"});N1(G,X)||(y(X),k.current.layout=X,H&&H(X),Fp(q,X,w.current))},[]),z=v.useCallback((P,U)=>{const{layout:H,panelDataArray:G}=k.current,{collapsedSize:q=0,collapsible:Y}=U,{collapsedSize:W=0,collapsible:ne,maxSize:Z=100,minSize:K=0}=P.constraints,{panelSize:X}=qf(G,P,H);X!=null&&(Y&&ne&&Kc(X,q)?Kc(q,W)||O(P,W):X<K?O(P,K):X>Z&&O(P,Z))},[O]),L=v.useCallback((P,U)=>{const{direction:H}=j.current,{layout:G}=k.current;if(!p.current)return;const q=XT(P,p.current);Tn(q,`Drag handle element not found for id "${P}"`);const Y=zge(H,U);x({dragHandleId:P,dragHandleRect:q.getBoundingClientRect(),initialCursorPosition:Y,initialLayout:G})},[]),V=v.useCallback(()=>{x(null)},[]),A=v.useCallback(P=>{const{panelDataArray:U}=k.current,H=Wp(U,P);H>=0&&(U.splice(H,1),delete w.current[P.id],k.current.panelDataArrayChanged=!0,C())},[C]),B=v.useMemo(()=>({collapsePanel:_,direction:r,dragState:g,expandPanel:T,getPanelSize:I,getPanelStyle:D,groupId:h,isPanelCollapsed:E,isPanelExpanded:R,reevaluatePanelConstraints:z,registerPanel:F,registerResizeHandle:M,resizePanel:O,startDragging:L,stopDragging:V,unregisterPanel:A,panelGroupElement:p.current}),[_,g,r,T,I,D,h,E,R,z,F,M,O,L,V,A]),$={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return v.createElement(GT.Provider,{value:B},v.createElement(d,{...f,children:t,className:n,id:s,ref:p,style:{...$,...u},[oo.group]:"",[oo.groupDirection]:r,[oo.groupId]:h}))}const Uge=v.forwardRef((e,t)=>v.createElement(qge,{...e,forwardedRef:t}));qge.displayName="PanelGroup";Uge.displayName="forwardRef(PanelGroup)";function Wp(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function qf(e,t,n){const r=Wp(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],i=n[r];return{...t.constraints,panelSize:i,pivotIndices:s}}function u0t({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){v.useEffect(()=>{if(e||n==null||r==null)return;const o=XT(t,r);if(o==null)return;const s=i=>{if(!i.defaultPrevented)switch(i.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{i.preventDefault(),n(i);break}case"F6":{i.preventDefault();const a=o.getAttribute(oo.groupId);Tn(a,`No group element found for id "${a}"`);const c=$0(a,r),u=Oge(a,t,r);Tn(u!==null,`No resize element found for id "${t}"`);const d=i.shiftKey?u>0?u-1:c.length-1:u+1<c.length?u+1:0;c[d].focus();break}}};return o.addEventListener("keydown",s),()=>{o.removeEventListener("keydown",s)}},[r,e,t,n])}function QT({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:o,onBlur:s,onClick:i,onDragging:a,onFocus:c,onPointerDown:u,onPointerUp:d,style:f={},tabIndex:h=0,tagName:p="div",...g}){var x,b;const y=v.useRef(null),C=v.useRef({onClick:i,onDragging:a,onPointerDown:u,onPointerUp:d});v.useEffect(()=>{C.current.onClick=i,C.current.onDragging=a,C.current.onPointerDown=u,C.current.onPointerUp=d});const w=v.useContext(GT);if(w===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:N,groupId:S,registerResizeHandle:j,startDragging:k,stopDragging:_,panelGroupElement:T}=w,I=J4(o),[D,E]=v.useState("inactive"),[R,F]=v.useState(!1),[M,O]=v.useState(null),z=v.useRef({state:D});Zh(()=>{z.current.state=D}),v.useEffect(()=>{if(n)O(null);else{const B=j(I);O(()=>B)}},[n,I,j]);const L=(x=r==null?void 0:r.coarse)!==null&&x!==void 0?x:15,V=(b=r==null?void 0:r.fine)!==null&&b!==void 0?b:5;v.useEffect(()=>{if(n||M==null)return;const B=y.current;Tn(B,"Element ref not attached");let $=!1;return Yvt(I,B,N,{coarse:L,fine:V},(U,H,G)=>{if(!H){E("inactive");return}switch(U){case"down":{E("drag"),$=!1,Tn(G,'Expected event to be defined for "down" action'),k(I,G);const{onDragging:q,onPointerDown:Y}=C.current;q==null||q(!0),Y==null||Y();break}case"move":{const{state:q}=z.current;$=!0,q!=="drag"&&E("hover"),Tn(G,'Expected event to be defined for "move" action'),M(G);break}case"up":{E("hover"),_();const{onClick:q,onDragging:Y,onPointerUp:W}=C.current;Y==null||Y(!1),W==null||W(),$||q==null||q();break}}})},[L,N,n,V,j,I,M,k,_]),u0t({disabled:n,handleId:I,resizeHandler:M,panelGroupElement:T});const A={touchAction:"none",userSelect:"none"};return v.createElement(p,{...g,children:e,className:t,id:o,onBlur:()=>{F(!1),s==null||s()},onFocus:()=>{F(!0),c==null||c()},ref:y,role:"separator",style:{...A,...f},tabIndex:h,[oo.groupDirection]:N,[oo.groupId]:S,[oo.resizeHandle]:"",[oo.resizeHandleActive]:D==="drag"?"pointer":R?"keyboard":void 0,[oo.resizeHandleEnabled]:!n,[oo.resizeHandleId]:I,[oo.resizeHandleState]:D})}QT.displayName="PanelResizeHandle";const Kge=({className:e,...t})=>l.jsx(Uge,{className:m.cn("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),pO=Ige,d0t=({withHandle:e,className:t,...n})=>l.jsx(QT,{className:m.cn("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&l.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:l.jsx(Iu,{className:"h-2.5 w-2.5"})})}),f0t=({withHandle:e,className:t,onTabClick:n,open:r,...o})=>l.jsx(QT,{className:m.cn("relative flex w-px items-start justify-end bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",{"justify-start":r},t),...o,children:e&&!1});function h0t(e={}){const{initialPosition:t="bottom-right"}=e,[n,r]=v.useState(t),[o,s]=v.useState(!1),[i,a]=v.useState(null),c=v.useRef(null),u=v.useRef(!1),d=v.useRef(null);v.useEffect(()=>()=>{d.current&&(d.current(),d.current=null)},[]);const f=v.useCallback(g=>{const x="touches"in g?g.touches[0].clientX:g.clientX,b="touches"in g?g.touches[0].clientY:g.clientY;c.current={x,y:b},u.current=!1,a({x,y:b});const y=(k,_,T)=>{if(!c.current)return;const I=Math.abs(k-c.current.x),D=Math.abs(_-c.current.y);(I>10||D>10)&&(u.current?T.cancelable&&T.preventDefault():(T.cancelable&&T.preventDefault(),u.current=!0,s(!0))),a({x:k,y:_})},C={passive:!1},w=k=>{y(k.clientX,k.clientY,k)},N=k=>{if(k.touches.length===0)return;const _=k.touches[0];y(_.clientX,_.clientY,k)},S=()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",j),document.removeEventListener("touchmove",N),document.removeEventListener("touchend",j),d.current=null},j=()=>{a(k=>{if(u.current&&k){const _=window.innerWidth,T=window.innerHeight,I=k.x<_/2,D=k.y<T/2;r(D&&I?"top-left":D&&!I?"top-right":!D&&I?"bottom-left":"bottom-right")}return null}),c.current=null,setTimeout(()=>{u.current=!1,s(!1)},100),S()};document.addEventListener("mousemove",w),document.addEventListener("mouseup",j),document.addEventListener("touchmove",N,C),document.addEventListener("touchend",j),d.current=S},[]),h=v.useCallback(()=>{if(o&&i)return{position:"fixed",left:0,top:0,right:"auto",bottom:"auto",transform:`translate(${i.x-24}px, ${i.y-24}px)`,transition:"none",willChange:"transform"}},[o,i]),p=v.useCallback(()=>({horizontal:n.includes("left")?"left-6":"right-6",vertical:n.includes("top")?"top-6":"bottom-6"}),[n]);return{position:n,isDragging:o,dragPosition:i,handleDragStart:f,isDraggingRef:u,getStyle:h,getPositionClasses:p}}function m0t({open:e,setOpen:t}){const n=m.useDashboardStore(s=>s.selectedSheetId),{deleteSheet:r}=m.useDashboardActions();function o(){n&&(r(n),t(!1))}return l.jsx(ff,{open:e,onOpenChange:t,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete Sheet"}),l.jsx(Ru,{children:"Are you sure you want to delete this sheet along with all its cards? This action cannot be undone."})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{children:"Cancel"}),l.jsx(Au,{className:"bg-destructive hover:bg-destructive/90",onClick:o,children:"Delete"})]})]})})}function Wge({placeholders:e,onClick:t}){return l.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:e==null?void 0:e.map(n=>l.jsxs("button",{type:"button",onClick:()=>t(n),className:"flex cursor-pointer flex-col items-start gap-1 rounded-control border border-border/60 bg-muted/30 px-2.5 py-2 text-left transition-colors hover:border-border hover:bg-muted/50",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:n.title}),l.jsx("span",{className:"text-[12px] leading-[1.45] text-foreground/80",children:n.subtitle})]},n.title))})}var Gge="vercel.ai.error",p0t=Symbol.for(Gge),Yge,g0t=class Zge extends Error{constructor({name:t,message:n,cause:r}){super(n),this[Yge]=!0,this.name=t,this.cause=r}static isInstance(t){return Zge.hasMarker(t,Gge)}static hasMarker(t,n){const r=Symbol.for(n);return t!=null&&typeof t=="object"&&r in t&&typeof t[r]=="boolean"&&t[r]===!0}};Yge=p0t;var rf=g0t;function Xge(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var Qge="AI_InvalidArgumentError",Jge=`vercel.ai.error.${Qge}`,x0t=Symbol.for(Jge),exe,b0t=class extends rf{constructor({message:e,cause:t,argument:n}){super({name:Qge,message:e,cause:t}),this[exe]=!0,this.argument=n}static isInstance(e){return rf.hasMarker(e,Jge)}};exe=x0t;var txe="AI_JSONParseError",nxe=`vercel.ai.error.${txe}`,y0t=Symbol.for(nxe),rxe,CG=class extends rf{constructor({text:e,cause:t}){super({name:txe,message:`JSON parsing failed: Text: ${e}.
1365
+ `});return}Ze(e)&&e.getChildren().forEach(s=>oge(s,t,n,r,o))}function sge(e,t){const n=e.map(i=>i.value).join(""),r=fyt(e),o=Kpt(n,t),s=[];for(const i of o.content){if(i.type==="variable"){const a=myt(r,i.sourceStart,i.sourceEnd);s.push({type:"variable",ref:i.ref,...a?{format:a}:{}});continue}hyt(s,n,r,i.sourceStart,i.sourceEnd)}return{content:UT(s),unresolvedTokens:o.unresolvedTokens}}function fyt(e){let t=0;return e.map(n=>{const r=t,o=r+n.value.length;return t=o,{...n,start:r,end:o}})}function hyt(e,t,n,r,o){for(const s of n){const i=Math.max(r,s.start),a=Math.min(o,s.end);i>=a||e.push({type:"text",value:t.slice(i,a),...s.format?{format:s.format}:{}})}}function myt(e,t,n){var o,s,i;const r={};for(const a of e)Math.max(t,a.start)>=Math.min(n,a.end)||(r.bold||(r.bold=(o=a.format)==null?void 0:o.bold),r.italic||(r.italic=(s=a.format)==null?void 0:s.italic),r.underline||(r.underline=(i=a.format)==null?void 0:i.underline));return r.bold||r.italic||r.underline?r:void 0}function lG(e,t){let n=0;t!=null&&t.bold&&(n|=Fse),t!=null&&t.italic&&(n|=Pse),t!=null&&t.underline&&(n|=Ose),e.setFormat(n)}function cG(e){return m.cn("rounded-[2px] bg-emerald-50 px-0.5 font-mono text-[0.92em] font-medium text-emerald-700 ring-1 ring-inset ring-emerald-200/80",e.hasFormat("bold")&&"font-semibold",e.hasFormat("italic")&&"italic",e.hasFormat("underline")&&"underline")}function uG(e){const t={bold:e.hasFormat("bold"),italic:e.hasFormat("italic"),underline:e.hasFormat("underline")};return t.bold||t.italic||t.underline?t:void 0}function ige(e,t){const n=[],r=[],o=[],s=()=>{if(r.length===0)return;const i=sge(r,t);n.push(...i.content),o.push(...i.unresolvedTokens),r.length=0};for(const i of e){if(i.type==="variable"){s(),n.push(i);continue}r.push({value:i.value,format:i.format})}return s(),{content:UT(n),unresolvedTokens:o}}function UT(e){const t=[];for(const n of e){const r=t[t.length-1];if(n.type==="text"&&(r==null?void 0:r.type)==="text"&&age(n.format,r.format)){r.value+=n.value;continue}t.push(n)}return t}function age(e,t){return!!(e!=null&&e.bold)==!!(t!=null&&t.bold)&&!!(e!=null&&e.italic)==!!(t!=null&&t.italic)&&!!(e!=null&&e.underline)==!!(t!=null&&t.underline)}function pyt(e){return JSON.stringify(e||[])}function lge(e,t){return JSON.stringify({content:e||[],variableLabels:(e||[]).filter(n=>n.type==="variable").map(n=>B4(n.ref,t))})}function gyt(e,t){return e!=null&&e.some(n=>n.type==="text")?ige(e,t).content.some(n=>n.type==="variable"):!1}function xyt(e,t){const n=e||[],r=t||[];return n.length!==r.length?!1:n.every((o,s)=>{const i=r[s];return o.type!==i.type||!age(o.format,i.format)?!1:o.type==="text"&&i.type==="text"?o.value===i.value:o.type==="variable"&&i.type==="variable"?o.ref.source!==i.ref.source?!1:o.ref.source==="documentMeta"&&i.ref.source==="documentMeta"?o.ref.key===i.ref.key:o.ref.source==="input"&&i.ref.source==="input"&&o.ref.inputId===i.ref.inputId&&o.ref.export===i.ref.export:!1})}function byt(e){const t=new Map,n={key:"__document__",label:"Document",choices:[]};for(const o of e){if(o.ref.source==="documentMeta"){n.choices.push(o);continue}const s=o.label.split(".")[0];let i=t.get(s);i||(i={key:`input:${s}`,label:s,choices:[]},t.set(s,i)),i.choices.push(o)}const r=Array.from(t.values());return n.choices.length>0?[...r,n]:r}function yyt({choices:e,onInsert:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(""),i=v.useMemo(()=>byt(e),[e]),a=v.useMemo(()=>{const u=o.trim().toLowerCase();return u?i.map(d=>({...d,choices:d.choices.filter(f=>f.label.toLowerCase().includes(u)||f.token.toLowerCase().includes(u))})).filter(d=>d.choices.length>0):i},[i,o]);function c(u){t(u),s(""),r(!1)}return l.jsxs(m.Popover,{open:n,onOpenChange:r,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Insert variable",title:"Insert variable",className:"inline-flex h-5 items-center gap-0.5 rounded-[3px] border border-transparent px-1.5 text-[10px] font-medium text-muted-foreground transition-colors hover:border-border hover:bg-muted hover:text-foreground",children:[l.jsx(Ar,{className:"h-2.5 w-2.5"}),"Variable"]})}),l.jsxs(m.PopoverContent,{align:"end",side:"bottom",sideOffset:6,className:"w-72 p-0",children:[l.jsxs("div",{className:"flex items-center gap-2 border-b border-border/60 px-2.5 py-1.5",children:[l.jsx(Ft.Search,{className:"h-3 w-3 text-muted-foreground"}),l.jsx("input",{type:"text",value:o,onChange:u=>s(u.target.value),placeholder:"Search variables...",autoFocus:!0,className:"h-6 flex-1 bg-transparent text-[12px] outline-none placeholder:text-[hsl(var(--semaphor-placeholder-foreground))]"})]}),l.jsx("div",{className:"max-h-[280px] overflow-y-auto p-1",children:a.length===0?l.jsxs("div",{className:"px-2 py-3 text-[12px] text-muted-foreground",children:['No matches for "',o,'".']}):a.map(u=>l.jsxs("div",{className:"space-y-0.5 pb-1",children:[l.jsx("div",{className:"px-2 pb-0.5 pt-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:u.label}),u.choices.map(d=>l.jsx("button",{type:"button",onClick:()=>c(d),className:"flex w-full items-center justify-between gap-2 rounded-[4px] px-2 py-1 text-left transition-colors hover:bg-muted",children:l.jsx("span",{className:"truncate font-mono text-[11px] text-foreground",children:d.label})},d.token))]},u.key))})]})]})}function Go({label:e,children:t}){return l.jsxs("div",{children:[l.jsx("label",{className:"mb-1 block text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),t]})}function cge({label:e,enabled:t,onToggle:n}){return l.jsxs("label",{className:"flex h-8 cursor-pointer items-center justify-between gap-3 rounded-[5px] border border-border/60 bg-background px-2.5 text-[12px]",children:[l.jsx("span",{className:m.cn(t?"text-foreground":"text-muted-foreground"),children:e}),l.jsx(m.Switch,{size:"sm",checked:t,onCheckedChange:n})]})}function uge({columns:e,columnVisibility:t,onColumnVisibilityChange:n,onShowAllColumns:r,emptyMessage:o="Run the query or add fields to configure output columns.",helperText:s="Hidden columns stay available for conditional formatting triggers, but are omitted from table output and exports.",className:i}){const a=Object.values(t||{}).filter(c=>c===!1).length;return e.length===0?l.jsx("div",{className:m.cn("space-y-3",i),children:l.jsx("p",{className:"rounded-[6px] border border-dashed border-border/60 px-3 py-4 text-[12px] leading-5 text-muted-foreground",children:o})}):l.jsxs("div",{className:m.cn("space-y-3",i),children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsx("p",{className:"text-[12px] leading-5 text-muted-foreground",children:s}),l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"h-6 shrink-0 px-2 text-[11px]",disabled:a===0,onClick:r,children:"Show all"})]}),l.jsx("div",{className:"overflow-hidden rounded-[6px] border border-border/60 bg-background",children:l.jsx("div",{className:"max-h-[calc(100vh-260px)] divide-y divide-border/60 overflow-y-auto",children:e.map(c=>{const u=zoe(t,c.value);return l.jsxs("label",{className:"flex cursor-pointer items-center justify-between gap-3 px-3 py-2 transition-colors hover:bg-muted/40",children:[l.jsxs("span",{className:"min-w-0",children:[l.jsx("span",{className:"block truncate text-[13px] font-medium text-foreground",children:c.label}),c.label!==c.value?l.jsx("span",{className:"block truncate text-[11px] text-muted-foreground",children:c.value}):null]}),l.jsx(m.Switch,{size:"xs",checked:u,"aria-label":`${u?"Hide":"Show"} ${c.label}`,onCheckedChange:d=>n(c.value,d)})]},c.value)})})})]})}const vyt=[null,"#fee2e2","#fef3c7","#dcfce7","#dbeafe","#ede9fe","#ffe4e6","#f4f4f5"],wyt=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;function dge(e){return typeof e=="string"&&wyt.test(e)}function Cyt(e){const t=e.trim();return t?t.startsWith("#")?t:`#${t}`:""}function Syt(e,t="#000000"){if(dge(e)){if(e.length===7)return e;if(e.length===4){const n=e[1],r=e[2],o=e[3];return`#${n}${n}${r}${r}${o}${o}`}if(e.length===9)return e.slice(0,7)}return t}const Nyt=120;function Na({value:e,onChange:t,defaultValue:n,allowEmpty:r=!0,presets:o=vyt,ariaLabel:s,placeholder:i="#000000",id:a,className:c,disabled:u=!1}){const[d,f]=ie.useState(!1),[h,p]=ie.useState(e??""),[g,x]=ie.useState(e),b=ie.useRef(null),y=ie.useRef(void 0),C=ie.useRef(t);ie.useEffect(()=>{C.current=t},[t]),ie.useEffect(()=>{b.current===null&&(p(e??""),x(e))},[e]),ie.useEffect(()=>()=>{b.current!==null&&clearTimeout(b.current)},[]);const w=ie.useCallback(()=>{if(b.current===null)return;clearTimeout(b.current),b.current=null;const T=y.current;y.current=void 0,T!==void 0&&C.current(T)},[]),N=ie.useCallback(T=>{x(T),p(T),y.current=T,b.current!==null&&clearTimeout(b.current),b.current=setTimeout(()=>{const I=y.current;b.current=null,y.current=void 0,I!==void 0&&C.current(I)},Nyt)},[]),S=ie.useCallback(T=>{b.current!==null&&(clearTimeout(b.current),b.current=null,y.current=void 0),x(T),t(T)},[t]),j=g??e,k=n!==void 0&&(j??void 0)!==n,_=T=>{const I=Cyt(T);if(!I){if(r){S(void 0);return}p(e??"");return}if(dge(I)){S(I),p(I);return}p(e??"")};return l.jsxs("div",{className:m.cn("flex h-7 items-center gap-1.5",c),children:[l.jsxs(m.Popover,{open:d,onOpenChange:T=>{T||w(),f(T)},children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsx("button",{type:"button",disabled:u,"aria-label":s?`Pick ${s}`:"Pick a color",className:m.cn("relative size-6 shrink-0 overflow-hidden rounded-[5px] border border-border/60 transition-colors","hover:border-border","focus-visible:border-ring focus-visible:outline-none",u&&"cursor-not-allowed opacity-50"),style:j?{backgroundColor:j}:{backgroundImage:"linear-gradient(to top right, transparent calc(50% - 0.5px), hsl(var(--border)) calc(50% - 0.5px), hsl(var(--border)) calc(50% + 0.5px), transparent calc(50% + 0.5px))"}})}),l.jsxs(m.PopoverContent,{align:"start",sideOffset:6,className:"z-[60] w-[220px] space-y-2.5 rounded-[6px] p-2.5",children:[l.jsx("div",{className:"flex flex-wrap items-center gap-1",children:o.map((T,I)=>{const D=T===null,E=(j??null)===T||T!==null&&(j==null?void 0:j.toLowerCase())===T.toLowerCase(),R=()=>{if(D){r&&S(void 0);return}S(T)};return D&&!r?null:l.jsx("button",{type:"button",onClick:R,"aria-label":D?"No color":T,className:m.cn("relative flex size-6 items-center justify-center rounded-[4px] border transition-colors",E?"border-foreground":"border-border/60 hover:border-border"),style:D?{backgroundImage:"linear-gradient(to top right, transparent calc(50% - 0.5px), hsl(var(--border)) calc(50% - 0.5px), hsl(var(--border)) calc(50% + 0.5px), transparent calc(50% + 0.5px))"}:{backgroundColor:T??void 0},children:E&&!D&&l.jsx(m.Check,{className:"size-3",strokeWidth:3,style:{color:"#fff",mixBlendMode:"difference"}})},`${T??"none"}-${I}`)})}),l.jsx("div",{className:"h-px bg-border/60"}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("input",{type:"color","aria-label":"Custom color",value:Syt(j),onChange:T=>N(T.target.value),onBlur:w,className:"h-7 w-10 shrink-0 cursor-pointer rounded-[5px] border border-border/60 bg-background p-0.5"}),l.jsx(m.Input,{size:"xs",value:h,onChange:T=>p(T.target.value),onBlur:T=>_(T.target.value),onKeyDown:T=>{T.key==="Enter"?(_(h),f(!1)):T.key==="Escape"&&(p(e??""),f(!1))},placeholder:i,className:m.cn("w-full font-mono text-[11px]",m.removeRing)})]}),l.jsxs("div",{className:"flex items-center justify-between pt-0.5",children:[k?l.jsxs("button",{type:"button",onClick:()=>S(n),className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:[l.jsx(m.RotateCcw,{className:"size-3"}),"Reset to default"]}):l.jsx("span",{}),l.jsx("button",{type:"button",onClick:()=>{w(),f(!1)},className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground transition-colors hover:text-foreground","aria-label":"Close color picker",children:"Done"})]})]})]}),l.jsx(m.Input,{size:"xs",id:a,"aria-label":s,value:h,onChange:T=>p(T.target.value),onBlur:T=>_(T.target.value),onKeyDown:T=>{T.key==="Enter"?(_(h),T.target.blur()):T.key==="Escape"&&(p(e??""),T.target.blur())},placeholder:i,disabled:u,className:m.cn("w-full font-mono text-[11px]",m.removeRing)}),k&&l.jsx("button",{type:"button",onClick:()=>S(n),"aria-label":"Reset color",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(m.RotateCcw,{className:"size-3"})})]})}function fge({style:e,onDensityChange:t,onStyleChange:n,totals:r,showFullStyle:o=!0,showBorderStyle:s=!0,extraSection:i,onReset:a,className:c}){const u=(r==null?void 0:r.enabled)??e.totalsStyle.enabled,d=!!r,f=!!(r!=null&&r.onStyleChange)&&(u||!(r!=null&&r.onEnabledChange)),h=vse[e.headerStyle],p=x=>{n({headerBackgroundColor:x===h.background?void 0:x})},g=x=>{n({headerTextColor:x===h.color?void 0:x})};return l.jsxs("div",{className:m.cn("space-y-5",c),children:[l.jsxs(C1,{label:"Layout",children:[l.jsx(Il,{label:"Density",children:l.jsxs(m.Select,{value:e.density,onValueChange:x=>t(x),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table density",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:gse.map(x=>l.jsx(m.SelectItem,{value:x,children:E4e[x]},x))})]})}),o&&l.jsx(S1,{label:"Wrap text",checked:e.wrapText,onCheckedChange:x=>n({wrapText:x})})]}),o&&l.jsxs(l.Fragment,{children:[l.jsxs(C1,{label:"Header",children:[l.jsx(S1,{label:"Wrap header",checked:e.headerWrapText,onCheckedChange:x=>n({headerWrapText:x})}),l.jsx(Il,{label:"Style",children:l.jsxs(m.Select,{value:e.headerStyle,onValueChange:x=>n({headerStyle:x}),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table header style",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:xse.map(x=>l.jsx(m.SelectItem,{value:x,children:M4e[x]},x))})]})}),l.jsx(Il,{label:"Background",children:l.jsx(Na,{value:e.headerBackgroundColor,onChange:p,defaultValue:h.background,allowEmpty:!1,ariaLabel:"Header background"})}),l.jsx(Il,{label:"Text",children:l.jsx(Na,{value:e.headerTextColor,onChange:g,defaultValue:h.color,allowEmpty:!1,ariaLabel:"Header text"})})]}),l.jsxs(C1,{label:"Rows",children:[s&&l.jsx(Il,{label:"Borders",children:l.jsxs(m.Select,{value:e.gridLines,onValueChange:x=>n({gridLines:x}),children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table borders",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:bse.map(x=>l.jsx(m.SelectItem,{value:x,children:R4e[x]},x))})]})}),l.jsx(S1,{label:"Row striping",checked:e.stripedRows,onCheckedChange:x=>n({stripedRows:x})})]})]}),o&&d&&l.jsxs(C1,{label:"Totals",action:r!=null&&r.onEnabledChange?l.jsx(m.Switch,{size:"xs","aria-label":"Show totals row",checked:u,onCheckedChange:x=>{var b;return(b=r==null?void 0:r.onEnabledChange)==null?void 0:b.call(r,!!x)}}):null,children:[r!=null&&r.helperText?l.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:r.helperText}):null,f?l.jsxs(l.Fragment,{children:[l.jsx(Il,{label:"Background",children:l.jsx(Na,{value:e.totalsStyle.backgroundColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{backgroundColor:x})},defaultValue:ka.backgroundColor,allowEmpty:!1,ariaLabel:"Totals background"})}),l.jsx(Il,{label:"Text",children:l.jsx(Na,{value:e.totalsStyle.textColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{textColor:x})},defaultValue:ka.textColor,allowEmpty:!1,ariaLabel:"Totals text"})}),l.jsx(Il,{label:"Weight",children:l.jsxs(m.Select,{value:e.totalsStyle.fontWeight,onValueChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{fontWeight:x})},children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table totals weight",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:yse.map(x=>l.jsx(m.SelectItem,{value:x,children:A4e[x]},x))})]})}),l.jsx(S1,{label:"Top border",checked:e.totalsStyle.borderTop,onCheckedChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTop:x})}}),e.totalsStyle.borderTop?l.jsxs(l.Fragment,{children:[l.jsx(Il,{label:"Border style",children:l.jsxs(m.Select,{value:e.totalsStyle.borderTopStyle,onValueChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTopStyle:x})},children:[l.jsx(m.SelectTrigger,{size:"xs","aria-label":"Table totals border style",className:"w-full",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:F4e.map(x=>l.jsx(m.SelectItem,{value:x,children:P4e[x]},x))})]})}),l.jsx(Il,{label:"Border color",children:l.jsx(Na,{value:e.totalsStyle.borderTopColor,onChange:x=>{var b;return(b=r==null?void 0:r.onStyleChange)==null?void 0:b.call(r,{borderTopColor:x})},defaultValue:ka.borderTopColor,allowEmpty:!1,ariaLabel:"Totals border color"})})]}):null]}):null]}),i,a?l.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"w-full",onClick:a,children:"Reset appearance"}):null]})}function C1({label:e,action:t,children:n}){return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),t]}),l.jsx("div",{className:"space-y-2",children:n})]})}function Il({label:e,htmlFor:t,children:n}){return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("label",{htmlFor:t,className:"w-20 shrink-0 text-[12px] text-foreground",children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:n})]})}function S1({label:e,checked:t,onCheckedChange:n}){return l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:"w-20 shrink-0 text-[12px] text-foreground",children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:l.jsx(m.Switch,{size:"xs",checked:t,onCheckedChange:r=>n(!!r)})})]})}const wa="__semaphor_unassigned_trigger__";function hge(e){return e==="table"}function jyt(e){return e.label||e.alias||e.name||e.id||""}function kyt(e){return e.alias||e.name||e.id||e.label||""}function Iyt(e){var n,r,o;const t=((o=(r=(n=e==null?void 0:e.preferences)==null?void 0:n.tablePrefs)==null?void 0:r.conditionalFormatting)==null?void 0:o.rules)||[];return new Set(t.flatMap(s=>[s.condition.columnId,...s.target.columnIds||[],...s.target.applyToColumnIds||[]]).filter(s=>s&&s!==wa))}function uO(e,t,n){t&&t!==wa&&(e.has(t)||e.set(t,{value:t,label:n||m.toLabel(t)}))}function mge(e,t=[],n){const r=ZI(e,t,n),o=new Map(r.options.map(s=>[s.value,s]));return Iyt(e).forEach(s=>{const i=r.resolveColumnId(s);o.has(i)||uO(o,i,`${m.toLabel(s)} (unavailable)`)}),Array.from(o.values())}function pge(e,t=[]){const n=new Map;if(t.length>0)return t.forEach(s=>uO(n,s,s)),Array.from(n.values());const r=e==null?void 0:e.config;return[...(r==null?void 0:r.detailColumns)||[],...(r==null?void 0:r.groupByColumns)||[],...(r==null?void 0:r.metricColumns)||[],...(r==null?void 0:r.pivotByColumns)||[]].forEach(s=>{uO(n,kyt(s),jyt(s))}),Array.from(n.values())}function _yt(e,t){var n;return{...e,preferences:{...e.preferences,tablePrefs:{...(n=e.preferences)==null?void 0:n.tablePrefs,conditionalFormatting:t}}}}const gge=[{value:"gt",label:"Greater than"},{value:"gte",label:"Greater than or equal"},{value:"lt",label:"Less than"},{value:"lte",label:"Less than or equal"},{value:"eq",label:"Equals"},{value:"neq",label:"Does not equal"},{value:"between",label:"Between"},{value:"contains",label:"Contains"},{value:"blank",label:"Is blank"},{value:"notBlank",label:"Is not blank"}];function KT(e){return e===wa}function q2(e){return e!=null&&String(e).trim()!==""}function dG(e){return typeof e=="number"&&Number.isFinite(e)}function Tyt(e){return e.condition.kind==="comparison"||e.condition.kind==="between"||e.condition.kind==="contains"||e.condition.kind==="blank"?"comparison":e.condition.kind}function xge(e){return e.condition.kind==="blank"?e.condition.isBlank?"blank":"notBlank":e.condition.kind==="contains"?"contains":e.condition.kind==="between"?"between":e.condition.kind==="comparison"?e.condition.operator:"gt"}function dO(e){return e.condition.kind==="comparison"||e.condition.kind==="contains"?String(e.condition.value??""):e.condition.kind==="between"?String(e.condition.min??""):""}function Dyt(e){return e.condition.kind==="between"?String(e.condition.max??""):""}function hy(e){return typeof e=="number"&&Number.isFinite(e)?String(e):""}function my(e){if(!e.trim())return;const t=Number(e);return Number.isFinite(t)?t:void 0}function Eyt(e,t){const n=Number(e);return Number.isFinite(n)?n:t}function Myt(e){var n;if(KT(e.condition.columnId))return"Select a trigger column";const t=e.condition;return t.kind==="comparison"?`${(((n=gge.find(o=>o.value===t.operator))==null?void 0:n.label)??t.operator).toLowerCase()} ${t.value??""}`.trim():t.kind==="between"?`between ${t.min??"?"}...${t.max??"?"}`:t.kind==="contains"?`contains "${t.value??""}"`:t.kind==="blank"?t.isBlank?"is blank":"is not blank":t.kind==="topBottom"?`${t.direction} ${t.count}`:t.kind==="colorScale"?t.range==="manual"?`scale ${t.min??"auto"}...${t.max??"auto"}`:"scale (auto)":t.kind==="dataBar"?t.range==="manual"?`bar ${t.min??"auto"}...${t.max??"auto"}`:"bar (auto)":""}function bge(e){return KT(e.condition.columnId)?"":e.condition.columnId}function fO(e){const t=new Map;return e.forEach(n=>{const r=typeof n=="string"?{value:n,label:n}:n;!r.value||t.has(r.value)||t.set(r.value,{value:r.value,label:r.label||r.value})}),Array.from(t.values())}function Ryt(e,t){var r,o;const n=((o=(r=globalThis.crypto)==null?void 0:r.randomUUID)==null?void 0:o.call(r))??`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return`cf-${e||"unassigned"}-${t}-${n}`}function ug(e){return e.condition.kind==="colorScale"||e.condition.kind==="dataBar"}function Ayt(e){return e==="colorScale"||e==="dataBar"}function Yh(e){if(KT(e.condition.columnId))return!1;switch(e.condition.kind){case"comparison":case"contains":return q2(e.condition.value);case"between":return q2(e.condition.min)&&q2(e.condition.max);case"blank":case"topBottom":return!0;case"colorScale":case"dataBar":return e.condition.range==="manual"?dG(e.condition.min)&&dG(e.condition.max):!0;default:return!1}}function Hy(e,t){return Yh(t)?e.enabled===!1&&!Yh(e)&&Yh(t)?{...t,enabled:!0}:t:{...t,enabled:!1}}function Fyt(e){return Yh(e)?e:{...e,enabled:!1}}function Pyt({columnId:e,columnLabel:t,existingRule:n,index:r,kind:o="comparison",operator:s="gt",value:i="",conditionColumnId:a}){var g,x,b,y,C;const c=a??(n==null?void 0:n.condition.columnId)??e,u=KT(c),d=Ayt(o),f=u?"":d?c:e||c;if(!f&&!c)return;const h={id:(n==null?void 0:n.id)??Ryt(u?"unassigned":f||c,o),name:(n==null?void 0:n.name)??`${u?"New formatting":t||f||"New formatting"} rule ${r+1}`,enabled:(n==null?void 0:n.enabled)??!u,target:{level:"cell",columnIds:!d&&((g=n==null?void 0:n.target.columnIds)!=null&&g.length)?n.target.columnIds:f?[f]:void 0,applyToColumnIds:n==null?void 0:n.target.applyToColumnIds,tableParts:["body"]},style:{backgroundColor:((x=n==null?void 0:n.style)==null?void 0:x.backgroundColor)??"#fee2e2",textColor:((b=n==null?void 0:n.style)==null?void 0:b.textColor)??"#b91c1c",fontWeight:(y=n==null?void 0:n.style)==null?void 0:y.fontWeight,italic:(C=n==null?void 0:n.style)==null?void 0:C.italic}},p=w=>n?Hy(n,w):Fyt(w);if(o==="topBottom"){const w=(n==null?void 0:n.condition.kind)==="topBottom"?n.condition:void 0;return p({...h,condition:{kind:"topBottom",columnId:c||wa,direction:(w==null?void 0:w.direction)??"top",count:(w==null?void 0:w.count)??10}})}if(o==="colorScale"){const w=(n==null?void 0:n.condition.kind)==="colorScale"?n.condition:void 0;return p({...h,style:void 0,condition:{kind:"colorScale",columnId:c||wa,range:(w==null?void 0:w.range)??"auto",min:w==null?void 0:w.min,mid:w==null?void 0:w.mid,max:w==null?void 0:w.max,colors:(w==null?void 0:w.colors)??{min:"#fee2e2",mid:"#fef3c7",max:"#dcfce7"}}})}if(o==="dataBar"){const w=(n==null?void 0:n.condition.kind)==="dataBar"?n.condition:void 0;return p({...h,style:void 0,condition:{kind:"dataBar",columnId:c||wa,range:(w==null?void 0:w.range)??"auto",min:w==null?void 0:w.min,max:w==null?void 0:w.max,color:(w==null?void 0:w.color)??"#3b82f6",showValue:(w==null?void 0:w.showValue)!==!1}})}if(s==="blank"||s==="notBlank")return p({...h,condition:{kind:"blank",columnId:c||wa,isBlank:s==="blank"}});if(s==="contains")return p({...h,condition:{kind:"contains",columnId:c||wa,value:String(i??"")}});if(s==="between"){const w=(n==null?void 0:n.condition.kind)==="between"?n.condition:void 0;return p({...h,condition:{kind:"between",columnId:c||wa,min:i,max:(w==null?void 0:w.max)??"",inclusive:(w==null?void 0:w.inclusive)!==!1}})}return p({...h,condition:{kind:"comparison",columnId:c||wa,operator:s,value:i}})}const Oyt=[{value:"comparison",label:"Compare"},{value:"topBottom",label:"Top/Bot."},{value:"colorScale",label:"Scale"},{value:"dataBar",label:"Data bar"}],Lyt=[{name:"none",bg:void 0,text:void 0},{name:"red",bg:"#fee2e2",text:"#b91c1c"},{name:"amber",bg:"#fef3c7",text:"#92400e"},{name:"emerald",bg:"#dcfce7",text:"#15803d"},{name:"sky",bg:"#dbeafe",text:"#1d4ed8"},{name:"zinc",bg:"#f4f4f5",text:"#52525b"}],$yt=["#fb923c","#22c55e","#3b82f6","#a855f7","#ec4899","#71717a"],zyt={emerald:["#fee2e2","#fef3c7","#dcfce7"],sky:["#fee2e2","#fef3c7","#dbeafe"],rose:["#dcfce7","#fef3c7","#fee2e2"],zinc:["#fef2f2","#f4f4f5","#e4e4e7"]};function Ap({value:e,onChange:t,options:n,ariaLabel:r}){return l.jsx("div",{role:"radiogroup","aria-label":r,className:"inline-flex h-7 w-fit max-w-full items-center rounded-[5px] border border-border/60 bg-background p-0.5",children:n.map(o=>{const s=o.value===e;return l.jsx("button",{type:"button",role:"radio","aria-checked":s,"aria-label":o.ariaLabel??String(o.label),disabled:o.disabled,onClick:()=>t(o.value),className:m.cn("inline-flex h-full items-center rounded-[4px] px-2 text-[11px] font-medium transition-colors",o.disabled?"cursor-not-allowed text-muted-foreground/40":s?"bg-foreground text-background":"text-muted-foreground hover:text-foreground"),children:o.label},o.value)})})}function Byt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:Lyt.map(n=>{const r=(e??"none")===(n.bg??"none");return l.jsx("button",{type:"button",onClick:()=>t(n.bg,n.text),"aria-label":n.name,className:m.cn("flex h-6 w-6 items-center justify-center rounded-[4px] border transition-colors",r?"border-foreground":"border-border/60 hover:border-border"),style:{backgroundColor:n.bg??"transparent"},children:r&&l.jsx(m.Check,{className:"size-3",strokeWidth:3,style:{color:n.text??"currentColor"}})},n.name)})})}function Vyt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:Object.entries(zyt).map(([n,r])=>{const[o,s,i]=r,a=e.min===o&&e.max===i;return l.jsx("button",{type:"button","aria-label":n,onClick:()=>t({min:o,mid:s,max:i}),className:m.cn("flex h-6 w-7 items-center justify-center rounded-[4px] border transition-colors",a?"border-foreground":"border-border/60 hover:border-border"),style:{background:`linear-gradient(to right, ${o}, ${s}, ${i})`},children:a&&l.jsx(m.Check,{className:"size-3 text-foreground mix-blend-difference",strokeWidth:3,style:{color:"#fff"}})},n)})})}function Hyt({value:e,onChange:t}){return l.jsx("div",{className:"flex items-center gap-1",children:$yt.map(n=>{const r=e===n;return l.jsx("button",{type:"button","aria-label":n,onClick:()=>t(n),className:m.cn("flex h-6 w-6 items-center justify-center rounded-[4px] border transition-colors",r?"border-foreground":"border-border/60 hover:border-border"),style:{backgroundColor:n},children:r&&l.jsx(m.Check,{className:"size-3 text-white",strokeWidth:3})},n)})})}function qyt({rule:e}){var o,s;const t=e.condition;if(t.kind==="colorScale")return l.jsx("span",{"aria-hidden":!0,className:"inline-block h-3 w-7 shrink-0 rounded-[3px] border border-border/60",style:{background:`linear-gradient(to right, ${t.colors.min}, ${t.colors.mid??t.colors.max}, ${t.colors.max})`}});if(t.kind==="dataBar")return l.jsx("span",{"aria-hidden":!0,className:"relative inline-block h-3 w-7 shrink-0 overflow-hidden rounded-[3px] border border-border/60 bg-muted",children:l.jsx("span",{className:"absolute inset-y-0 left-0 w-3/5",style:{backgroundColor:t.color}})});const n=(o=e.style)==null?void 0:o.backgroundColor,r=(s=e.style)==null?void 0:s.textColor;return l.jsx("span",{"aria-hidden":!0,className:"inline-flex h-3 w-7 shrink-0 items-center justify-center rounded-[3px] border border-border/60 text-[8px] font-bold leading-none",style:{backgroundColor:n??"transparent",color:r??"currentColor"},children:"Aa"})}function py({label:e,children:t}){return l.jsxs("div",{className:"flex flex-col gap-1.5",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:e}),l.jsx("div",{className:"flex flex-col gap-1.5",children:t})]})}function Ur({label:e,htmlFor:t,children:n,align:r="center"}){return l.jsxs("div",{className:m.cn("flex gap-2",r==="start"?"items-start":"items-center"),children:[l.jsx("label",{htmlFor:t,className:m.cn("w-20 shrink-0 text-[11px] text-muted-foreground",r==="start"&&"pt-1.5"),children:e}),l.jsx("div",{className:"min-w-0 flex-1",children:n})]})}function _l({value:e,onValueChange:t,commitDelayMs:n=250,onBlur:r,onKeyDown:o,...s}){const[i,a]=v.useState(e),c=v.useRef(e),u=v.useRef(t);v.useEffect(()=>{u.current=t},[t]),v.useEffect(()=>{c.current=e,a(e)},[e]);const d=v.useCallback(f=>{f!==c.current&&(c.current=f,v.startTransition(()=>{u.current(f)}))},[]);return v.useEffect(()=>{if(i===c.current)return;const f=window.setTimeout(()=>d(i),n);return()=>window.clearTimeout(f)},[n,d,i]),l.jsx(m.Input,{...s,value:i,onChange:f=>a(f.target.value),onBlur:f=>{d(f.currentTarget.value),r==null||r(f)},onKeyDown:f=>{f.key==="Enter"&&d(f.currentTarget.value),o==null||o(f)}})}function yge({columnId:e,availableColumns:t=[],conditionalRules:n,onConditionalRulesChange:r,startRulesWithNoTrigger:o=!1,capabilities:s}){const[i,a]=v.useState(()=>n.length===1?new Set([n[0].id]):new Set);if(v.useEffect(()=>{a(I=>{const D=new Set(n.map(F=>F.id));let E=!1;const R=new Set(I);for(const F of R)D.has(F)||(R.delete(F),E=!0);return E?R:I})},[n]),!r)return null;const c=I=>{var E,R;const D=Pyt(I);if(D&&(s!=null&&s.separateApplyTargets)&&I.existingRule&&!ug(D)&&!ug(I.existingRule)&&(D.target=I.existingRule.target),D&&((E=I.existingRule)!=null&&E.target.matrix)&&(D.target={...D.target,matrix:I.existingRule.target.matrix}),D&&(s!=null&&s.targetScope)){const F=(R=I.existingRule)==null?void 0:R.target;D.target={...D.target,matrix:F==null?void 0:F.matrix,rowRoles:F?F.rowRoles:s.targetScope.defaultRowRoles,tableParts:F==null?void 0:F.tableParts,depth:F==null?void 0:F.depth,includeTotals:F==null?void 0:F.includeTotals,includeSubtotals:F==null?void 0:F.includeSubtotals}}return D},u=I=>{a(D=>{const E=new Set(D);return E.has(I)?E.delete(I):E.add(I),E})},d=(I,D)=>{r(n.map((E,R)=>E.id===I?D(E,R):E))},f=()=>{var D;const I=c({columnId:e,columnLabel:(D=fO(t).find(E=>E.value===e))==null?void 0:D.label,index:n.length,kind:"comparison",conditionColumnId:o?wa:void 0});I&&(a(E=>new Set(E).add(I.id)),r([...n,I]))},h=I=>{const D=n.findIndex(M=>M.id===I);if(D<0)return;const E=n[D],R={...E,id:`${E.id}-copy-${Date.now()}`,name:`${E.name??"Rule"} (copy)`},F=[...n];F.splice(D+1,0,R),a(M=>new Set(M).add(R.id)),r(F)},p=I=>{r(n.filter(D=>D.id!==I))},g=(I,D)=>{const E=n.findIndex(O=>O.id===I),R=E+D;if(E<0||R<0||R>=n.length)return;const F=[...n],[M]=F.splice(E,1);F.splice(R,0,M),r(F)},x=(I,D,E)=>{if(s&&!s.ruleKinds.includes(D))return;const R=c({columnId:e,existingRule:I,index:E,kind:D});R&&((s==null?void 0:s.automaticRanges)===!1&&(R.condition.kind==="colorScale"||R.condition.kind==="dataBar")&&(R.condition={...R.condition,range:"manual"},R.enabled=Yh(R)),r(n.map(F=>F.id===I.id?R:F)))},b=(I,D,E)=>{r(n.map(R=>R.id===I.id?c({columnId:e,existingRule:R,index:E,kind:"comparison",operator:D,value:dO(R)}):R))},y=(I,D,E)=>{r(n.map(R=>R.id===I.id?c({columnId:e,existingRule:R,index:E,kind:"comparison",operator:xge(R),value:D}):R))},C=(I,D)=>{d(I,E=>E.condition.kind==="between"?Hy(E,{...E,condition:{...E.condition,max:D}}):E)},w=(I,D)=>{d(I,E=>({...E,style:{...E.style,...D}}))},N=(I,D)=>{d(I,E=>E.condition.kind==="topBottom"?{...E,condition:{...E.condition,...D,count:D.count!==void 0?Math.max(1,Math.floor(D.count)):E.condition.count}}:E)},S=(I,D)=>{d(I,E=>E.condition.kind==="colorScale"?Hy(E,{...E,condition:{...E.condition,...D,colors:{...E.condition.colors,...D.colors}}}):E)},j=(I,D)=>{d(I,E=>E.condition.kind==="dataBar"?Hy(E,{...E,condition:{...E.condition,...D}}):E)},k=(I,D)=>{d(I,E=>{const R={...E,target:E.target.level==="cell"&&(!(s!=null&&s.separateApplyTargets)||ug(E))?{...E.target,columnIds:[D]}:E.target,condition:{...E.condition,columnId:D}};return s!=null&&s.separateApplyTargets&&(R.target={...R.target,conditionColumnId:D}),Hy(E,R)})},_=(I,D)=>{d(I,E=>{var M,O,z;if(ug(E)&&D==="row")return E;const R=bge(E),F=((M=E.target.columnIds)==null?void 0:M[0])||R||void 0;return{...E,target:D==="row"?{...E.target,level:"row",columnIds:void 0,applyToColumnIds:E.target.applyToColumnIds,tableParts:s!=null&&s.targetScope||(O=E.target.tableParts)!=null&&O.length?E.target.tableParts:["body"]}:{...E.target,level:"cell",columnIds:F?[F]:void 0,applyToColumnIds:void 0,tableParts:s!=null&&s.targetScope||(z=E.target.tableParts)!=null&&z.length?E.target.tableParts:["body"]}}})},T=n.filter(I=>I.enabled!==!1).length;return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between",children:[l.jsxs("div",{className:"flex flex-col",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Conditional formatting"}),n.length>0&&l.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[T," enabled · ",n.length," total"]})]}),l.jsxs(m.Button,{type:"button",variant:"ghost",size:"xs",disabled:!e,onClick:f,className:"h-6 gap-1 px-2 text-[12px]",children:[l.jsx(Ar,{className:"size-3"}),"Add rule"]})]}),n.length===0?l.jsx("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"No conditional formatting rules for this column."}):l.jsx("ol",{className:"overflow-hidden rounded-[6px] border border-border/60",children:n.map((I,D)=>{const E=i.has(I.id);return l.jsxs("li",{className:"border-b border-border/60 bg-background last:border-b-0",children:[l.jsx(Uyt,{rule:I,index:D,expanded:E,isFirst:D===0,isLast:D===n.length-1,onToggleExpand:()=>u(I.id),onToggleEnabled:R=>d(I.id,F=>R&&!Yh(F)?F:{...F,enabled:R}),onMoveUp:()=>g(I.id,-1),onMoveDown:()=>g(I.id,1),onDuplicate:()=>h(I.id),onDelete:()=>p(I.id)}),E&&l.jsx(Kyt,{capabilities:s,onUpdateApplyColumn:R=>d(I.id,F=>({...F,target:{...F.target,columnIds:[R]}})),onUpdateTotals:R=>d(I.id,F=>({...F,target:{...F.target,tableParts:R?["body","subtotal","grandTotal"]:["body"],includeTotals:R,includeSubtotals:R}})),rule:I,index:D,onUpdateName:R=>d(I.id,F=>({...F,name:R})),onUpdateRuleKind:R=>x(I,R,D),onUpdateConditionalOperator:R=>b(I,R,D),onUpdateConditionalValue:R=>y(I,R,D),onUpdateConditionalMaxValue:R=>C(I.id,R),onUpdateStyle:R=>w(I.id,R),onUpdateTopBottom:R=>N(I.id,R),onUpdateColorScale:R=>S(I.id,R),onUpdateDataBar:R=>j(I.id,R),availableColumns:t,onUpdateConditionColumn:R=>k(I.id,R),onUpdateTargetLevel:R=>_(I.id,R)})]},I.id)})})]})}function Uyt({rule:e,index:t,expanded:n,isFirst:r,isLast:o,onToggleExpand:s,onToggleEnabled:i,onMoveUp:a,onMoveDown:c,onDuplicate:u,onDelete:d}){const f=Myt(e),h=e.enabled!==!1;return l.jsxs("div",{className:m.cn("flex items-stretch gap-1 px-2 py-1.5 transition-colors",n?"bg-muted/40 shadow-[inset_2px_0_0] shadow-foreground":"hover:bg-muted/40"),children:[l.jsxs("div",{className:"flex shrink-0 flex-col items-center gap-0.5 pt-1 text-muted-foreground",children:[l.jsx("button",{type:"button","aria-label":`Move rule ${t+1} up`,disabled:r,onClick:a,className:"rounded-[3px] p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-30 disabled:hover:bg-transparent",children:l.jsx(cs,{className:"size-3"})}),l.jsx("button",{type:"button","aria-label":`Move rule ${t+1} down`,disabled:o,onClick:c,className:"rounded-[3px] p-0.5 text-muted-foreground hover:bg-foreground/10 hover:text-foreground disabled:opacity-30 disabled:hover:bg-transparent",children:l.jsx(No,{className:"size-3"})})]}),l.jsx("button",{type:"button",onClick:s,"aria-expanded":n,"aria-label":`${n?"Collapse":"Expand"} rule ${t+1}`,className:"flex min-w-0 flex-1 items-start py-0.5 text-left",children:l.jsxs("span",{className:"min-w-0 flex-1",children:[l.jsxs("span",{className:"flex items-center gap-2",children:[l.jsxs("span",{className:"text-[10px] uppercase tracking-[0.08em] text-muted-foreground",children:["#",t+1]}),l.jsx("span",{className:m.cn("truncate text-[12px] font-medium",h?"text-foreground":"text-muted-foreground line-through"),children:e.name??`Rule ${t+1}`})]}),l.jsxs("span",{className:"mt-0.5 flex flex-wrap items-center gap-1.5",children:[l.jsx(qyt,{rule:e}),l.jsx("span",{className:"truncate text-[11px] text-muted-foreground",children:f})]})]})}),l.jsxs("div",{className:"flex shrink-0 items-start gap-1 pt-1",children:[l.jsx(m.Switch,{size:"xs","aria-label":h?`Disable rule ${t+1}`:`Enable rule ${t+1}`,checked:h,onCheckedChange:i}),l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":`Rule ${t+1} actions`,className:"inline-flex h-4 w-4 items-center justify-center rounded-[4px] text-muted-foreground hover:bg-muted hover:text-foreground",children:l.jsx(Lm,{className:"size-3"})})}),l.jsxs(_o,{align:"end",className:"min-w-[140px]",children:[l.jsxs(ln,{className:"gap-2 text-[12px]",onClick:u,children:[l.jsx(gu,{className:"size-3"}),"Duplicate"]}),l.jsxs(ln,{className:"gap-2 text-[12px] text-destructive focus:text-destructive",onClick:d,children:[l.jsx(Ra,{className:"size-3"}),"Delete"]})]})]})]})]})}function Kyt({capabilities:e,onUpdateApplyColumn:t,onUpdateTotals:n,rule:r,index:o,availableColumns:s,onUpdateName:i,onUpdateConditionColumn:a,onUpdateTargetLevel:c,onUpdateRuleKind:u,onUpdateConditionalOperator:d,onUpdateConditionalValue:f,onUpdateConditionalMaxValue:h,onUpdateStyle:p,onUpdateTopBottom:g,onUpdateColorScale:x,onUpdateDataBar:b}){var k,_,T,I,D;const y=Tyt(r),C=xge(r),w=r.id,N=bge(r),S=fO(s),j=!ug(r);return l.jsxs("div",{className:"space-y-3 border-t border-border/60 bg-muted/20 px-3 py-3",children:[l.jsx(Ur,{label:"Name",htmlFor:`cf-name-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-name-${w}`,value:r.name??"",onValueChange:i,className:`w-full ${m.removeRing}`,placeholder:`Rule ${o+1}`})}),l.jsxs(py,{label:"Target",children:[l.jsxs(Ur,{label:"Target",children:[l.jsx(Ap,{ariaLabel:"Formatting target",value:r.target.level,onChange:c,options:[{value:"cell",label:"Cell"},{value:"row",label:"Row",ariaLabel:j?"Row":"Row target is not available for this rule type",disabled:!j}]}),!j&&l.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Color scales and data bars format cells because their values are column-specific."})]}),l.jsx(Ur,{label:"Trigger",htmlFor:`cf-trigger-${w}`,children:l.jsxs(m.Select,{value:N||"",onValueChange:a,children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-trigger-${w}`,className:`w-full ${m.simpleRing}`,children:l.jsx(m.SelectValue,{placeholder:""})}),l.jsx(m.SelectContent,{children:(S.length?S:fO([N])).filter(E=>!!E.value).map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})})]}),(e==null?void 0:e.separateApplyTargets)&&l.jsxs(l.Fragment,{children:[r.target.level==="cell"&&!ug(r)&&l.jsx(Ur,{label:"Apply to column",htmlFor:`cf-apply-${w}`,children:l.jsxs(m.Select,{value:((k=r.target.columnIds)==null?void 0:k[0])??N,onValueChange:t,children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-apply-${w}`,children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:S.map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})}),!e.targetScope&&l.jsx(Ur,{label:"Include totals",htmlFor:`cf-totals-${w}`,children:l.jsx(m.Switch,{id:`cf-totals-${w}`,size:"xs",checked:r.target.includeTotals===!0&&r.target.includeSubtotals===!0,onCheckedChange:n})})]}),l.jsxs(py,{label:"Condition",children:[l.jsx(Ap,{ariaLabel:"Rule type",value:y,onChange:u,options:Oyt.filter(E=>!e||e.ruleKinds.includes(E.value))}),y==="comparison"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Operator",htmlFor:`cf-operator-${w}`,children:l.jsxs(m.Select,{value:C,onValueChange:E=>d(E),children:[l.jsx(m.SelectTrigger,{size:"xs",id:`cf-operator-${w}`,className:`w-full ${m.simpleRing}`,children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:gge.map(E=>l.jsx(m.SelectItem,{value:E.value,children:E.label},E.value))})]})}),C==="between"?l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Min",htmlFor:`cf-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-value-${w}`,"aria-label":"Value",value:dO(r),onValueChange:f,className:`w-full ${m.removeRing}`,placeholder:"Minimum…"})}),l.jsx(Ur,{label:"Max",htmlFor:`cf-max-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-max-value-${w}`,value:Dyt(r),onValueChange:h,className:`w-full ${m.removeRing}`,placeholder:"Maximum…"})})]}):C!=="blank"&&C!=="notBlank"?l.jsx(Ur,{label:"Value",htmlFor:`cf-value-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-value-${w}`,value:dO(r),onValueChange:f,className:`w-full ${m.removeRing}`,placeholder:C==="contains"?"Text to match…":"Value…"})}):null]}),r.condition.kind==="topBottom"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Direction",children:l.jsx(Ap,{ariaLabel:"Direction",value:r.condition.direction,onChange:E=>g({direction:E}),options:[{value:"top",label:"Top"},{value:"bottom",label:"Bottom"}]})}),l.jsx(Ur,{label:"Count",htmlFor:`cf-count-${w}`,children:l.jsx(_l,{size:"xs",id:`cf-count-${w}`,type:"number",min:1,value:String(r.condition.count),onValueChange:E=>g({count:Eyt(E,1)}),className:`w-full ${m.removeRing}`})})]}),r.condition.kind==="colorScale"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Range",children:l.jsx(Ap,{ariaLabel:"Range",value:r.condition.range,onChange:E=>x({range:E}),options:[...(e==null?void 0:e.automaticRanges)===!1?[]:[{value:"auto",label:"Auto"}],{value:"manual",label:"Manual"}]})}),r.condition.range==="manual"&&l.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[l.jsx(_l,{size:"xs",type:"number","aria-label":"Min",placeholder:"Min",value:hy(r.condition.min),onValueChange:E=>x({min:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Mid",placeholder:"Mid",value:hy(r.condition.mid),onValueChange:E=>x({mid:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Max",placeholder:"Max",value:hy(r.condition.max),onValueChange:E=>x({max:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`})]}),l.jsx(Ur,{label:"Palette",children:l.jsx(Vyt,{value:r.condition.colors,onChange:E=>x({colors:E})})})]}),r.condition.kind==="dataBar"&&l.jsxs(l.Fragment,{children:[l.jsx(Ur,{label:"Range",children:l.jsx(Ap,{ariaLabel:"Range",value:r.condition.range,onChange:E=>b({range:E}),options:[...(e==null?void 0:e.automaticRanges)===!1?[]:[{value:"auto",label:"Auto"}],{value:"manual",label:"Manual"}]})}),r.condition.range==="manual"&&l.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[l.jsx(_l,{size:"xs",type:"number","aria-label":"Min",placeholder:"Min",value:hy(r.condition.min),onValueChange:E=>b({min:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`}),l.jsx(_l,{size:"xs",type:"number","aria-label":"Max",placeholder:"Max",value:hy(r.condition.max),onValueChange:E=>b({max:my(E)}),className:`w-full text-right tabular-nums ${m.removeRing}`})]}),l.jsx(Ur,{label:"Show value",children:l.jsx(m.Switch,{size:"xs","aria-label":"Show cell value on data bar",checked:r.condition.showValue!==!1,onCheckedChange:E=>b({showValue:E})})})]})]}),(y==="comparison"||r.condition.kind==="topBottom")&&l.jsxs(py,{label:"Format",children:[l.jsx(Ur,{label:"Preset",children:l.jsx(Byt,{value:(_=r.style)==null?void 0:_.backgroundColor,onChange:(E,R)=>p({backgroundColor:E,textColor:R})})}),l.jsx(Ur,{label:"Fill",htmlFor:`cf-fill-${w}`,children:l.jsx(Na,{id:`cf-fill-${w}`,ariaLabel:"Fill Color",value:((T=r.style)==null?void 0:T.backgroundColor)||void 0,onChange:E=>p({backgroundColor:E}),defaultValue:"#fee2e2"})}),l.jsx(Ur,{label:"Text",htmlFor:`cf-text-${w}`,children:l.jsx(Na,{id:`cf-text-${w}`,ariaLabel:"Text Color",value:((I=r.style)==null?void 0:I.textColor)||void 0,onChange:E=>p({textColor:E}),defaultValue:"#b91c1c"})}),l.jsx(Ur,{label:"Weight",children:l.jsx(Ap,{ariaLabel:"Font weight",value:((D=r.style)==null?void 0:D.fontWeight)??"normal",onChange:E=>p({fontWeight:E==="normal"?void 0:E}),options:[{value:"normal",label:"R",ariaLabel:"Regular"},{value:"medium",label:"M",ariaLabel:"Medium"},{value:"bold",label:"B",ariaLabel:"Bold"}]})})]}),r.condition.kind==="colorScale"&&l.jsxs(py,{label:"Colors",children:[l.jsx(Ur,{label:"Low",htmlFor:`cf-low-color-${w}`,children:l.jsx(Na,{id:`cf-low-color-${w}`,ariaLabel:"Low color",value:r.condition.colors.min,onChange:E=>x({colors:{min:E??"#fee2e2"}}),defaultValue:"#fee2e2",allowEmpty:!1})}),l.jsx(Ur,{label:"Mid",htmlFor:`cf-mid-color-${w}`,children:l.jsx(Na,{id:`cf-mid-color-${w}`,ariaLabel:"Mid color",value:r.condition.colors.mid||void 0,onChange:E=>x({colors:{mid:E}}),defaultValue:"#fef3c7"})}),l.jsx(Ur,{label:"High",htmlFor:`cf-high-color-${w}`,children:l.jsx(Na,{id:`cf-high-color-${w}`,ariaLabel:"High color",value:r.condition.colors.max,onChange:E=>x({colors:{max:E??"#dcfce7"}}),defaultValue:"#dcfce7",allowEmpty:!1})})]}),r.condition.kind==="dataBar"&&l.jsxs(py,{label:"Bar color",children:[l.jsx(Ur,{label:"Preset",children:l.jsx(Hyt,{value:r.condition.color,onChange:E=>b({color:E})})}),l.jsx(Ur,{label:"Color",htmlFor:`cf-bar-color-${w}`,children:l.jsx(Na,{id:`cf-bar-color-${w}`,ariaLabel:"Bar color",value:r.condition.color,onChange:E=>b({color:E??"#3b82f6"}),defaultValue:"#3b82f6",allowEmpty:!1})})]})]})}function Wyt({field:e,dataSource:t,connectionId:n,connectionType:r,filterId:o}){const{qualifiedColumnName:s,qualifiedTableName:i}=Vme(e),a=m.getDataType(e.dataType),c=a==="date"?"between":"in",u=LO(e),d=$O(t,{connectionId:n,connectionType:r},e);return{id:o||lt.v4(),title:e.label||e.name,connectionId:n||(t==null?void 0:t.connectionId)||"",column:s,dataType:e.dataType,table:e.entityName||"",database:zY(t,d,e)||"",qualifiedTableName:i,operation:c,sql:"",fieldMeta:u,semanticContext:d,...a==="date"?{dateSelectionMode:"range"}:{type:"single"}}}function Gyt(e,t){return e.kind==="filter"&&qg(e.filter,t)}function WT(e){return m.getDataType(e.dataType)==="date"?["label","start","end","range"]:["label","value"]}function vge(e){return Yyt(e)?["label","value"]:["value"]}function Yyt(e){return e.type==="enum"||e.type==="multi_enum"||e.type==="field_selector"||e.type==="metric_selector"||e.type==="aggregation_selector"||e.type==="grain_selector"}function kb(e,t){return en.requireNormalizedDashboardInputs({inputs:e.inputs,dashboardFilters:e.filters}).filter(r=>m.doesDashboardInputApplyToTarget(r,{sheetId:t,sheetKind:"document"}))}function wge(e,t){const n=Zyt(e,t);return(e.inputs||[]).some(r=>m.doesDashboardInputApplyToTarget(r,{sheetId:t,sheetKind:"document"})||r.scope.kind==="documentSections"&&r.scope.sheetId===t||r.scope.kind==="cards"&&r.scope.cardIds.some(o=>n.has(o)))}function Zyt(e,t){var o,s,i;const n=new Set,r=(o=e.sheets)==null?void 0:o.find(a=>a.id===t);for(const a of((s=r==null?void 0:r.document)==null?void 0:s.sections)||[])(a.type==="table"||a.type==="chart")&&((i=a.card)!=null&&i.id)&&n.add(a.card.id);return n}function NC(e){const t={id:e.id,label:e.label,variableName:e.variableName,requiredAtExecution:!!e.requiredAtExecution,documentPlacement:"input_bar",description:e.description};return e.kind==="filter"?{...t,kind:"filter",filter:e.filter,exports:e.exports}:{...t,kind:"control",control:e.control,exports:e.exports}}function Xyt({field:e,existingInputs:t,sheetId:n,dataSource:r,connectionId:o,connectionType:s,inputId:i,filterId:a}){const c=e.label||e.name,u=Wyt({field:e,dataSource:r,connectionId:o,connectionType:s,filterId:a}),d=m.createUniqueDashboardInputVariableName(c,t);return{id:i||lt.v4(),kind:"filter",label:c,variableName:d,requiredAtExecution:!1,scope:{kind:"sheets",sheetIds:[n]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},filter:{...u,variableName:d},exports:WT(u)}}function Qyt({control:e,existingInputs:t,sheetId:n,inputId:r}){const o=m.createUniqueDashboardInputVariableNameFromName(e.id||e.label,t),s=e.id===o?e:{...e,id:o};return{id:r||lt.v4(),kind:"control",label:s.label,variableName:o,requiredAtExecution:s.requiredAtExecution,scope:{kind:"sheets",sheetIds:[n]},runtimeScope:"perSheet",presentation:{placement:"toolbar"},control:s,exports:vge(s)}}function Cge({input:e,allInputs:t,label:n,variableName:r}){const o=(n==null?void 0:n.trim())||e.label,s=r===void 0?e.variableName:m.createUniqueDashboardInputVariableNameFromName(r,t.filter(a=>a.id!==e.id));if(e.kind==="filter"){if(!e.filter)throw new Error(`Referenced dashboard input '${e.id}' cannot be edited as a document input.`);const a={...e.filter,title:o,variableName:s};return{...e,label:o,variableName:s,filter:a,exports:WT(a)}}const i={...e.control,id:s,label:o};return{...e,label:o,variableName:s,requiredAtExecution:i.requiredAtExecution,control:i,exports:vge(i)}}function hO(e,t,n){return!t||!n||t===n?e:{...e,sections:e.sections.map(r=>r.type!=="table"&&r.type!=="chart"||!r.card?r:{...r,card:Jyt(r.card,t,n)})}}function Jyt(e,t,n){var s;const r=`[[param.${t}]]`,o=`[[param.${n}]]`;return{...e,...(s=e.sql)!=null&&s.includes(r)?{sql:e.sql.split(r).join(o)}:{},...e.controls?{controls:e.controls.map(i=>i.id===t?{...i,id:n}:i)}:{},...e.controlBindings?{controlBindings:e.controlBindings.map(i=>({...i,controlId:i.controlId===t?n:i.controlId,...i.target==="sql_param"&&i.paramId===t?{paramId:n}:{}}))}:{}}}function evt(e,t){return e.kind==="filter"&&Gyt(NC(e),t)}function tvt(e){var n;const t={};for(const r of e)r.kind==="filter"&&(t[r.id]=((n=r.slot)==null?void 0:n.status)==="cleared"?void 0:r.filterValue);return t}function nvt(e){var n;const t={};for(const r of e)r.kind==="control"&&((n=r.slot)==null?void 0:n.status)==="set"&&(t[r.id]=r.controlValue);return t}function rvt({dashboard:e,sheetId:t,filterValuesByInputId:n,controlValuesByInputId:r}){var i;const o=kb(e,t);let s={};for(const a of o)if(((i=a.compatibility)==null?void 0:i.source)==="documentInput"){if(a.kind==="filter"&&n&&Object.prototype.hasOwnProperty.call(n,a.id)){const c=n[a.id];s=m.setDashboardInputRuntimeSlot(s,a,{sheetId:t},c?{status:"set",value:{kind:"filter",filterValue:c}}:{status:"cleared"})}if(a.kind==="control"&&r&&Object.prototype.hasOwnProperty.call(r,a.id)){const c=r[a.id];s=m.setDashboardInputRuntimeSlot(s,a,{sheetId:t},c===void 0?{status:"cleared"}:{status:"set",value:{kind:"control",value:c}})}}return zR({dashboard:e,dashboardInputValues:s,sheetId:t})}const ovt=[],svt={},ivt={},avt={};function lvt(e,t){return e.length===t.length&&e.every((n,r)=>n===t[r])}function cvt({sheet:e}){var Rt;const n=m.useDashboardStore(Pe=>{var Ge,at,kt;return(kt=(at=(Ge=Pe.dashboard)==null?void 0:Ge.sheets)==null?void 0:at.find(Wt=>Wt.id===e.id))==null?void 0:kt.document})||e.document||m.createDefaultDocumentDefinition(),r=m.useDashboardStore(Pe=>Pe.dashboard),o=m.useDashboardStore(Pe=>Pe.dashboardInputValues),s=m.useDashboardStore(Pe=>Pe.filterValues),i=m.useDashboardStore(Pe=>Pe.controlValues),a=m.useDashboardStore(Pe=>Pe.inlineFilterValuesMap),c=m.useDashboardStore(Pe=>Pe.cardControlValuesMap),u=v.useMemo(()=>kb(r,e.id),[r,e.id]),d=u.length>0,f=v.useMemo(()=>wge(r,e.id),[r,e.id]),h=v.useMemo(()=>d?u.map(NC):n.inputs||ovt,[n.inputs,u,d]),p=v.useMemo(()=>new Map(u.map(Pe=>[Pe.id,Pe])),[u]),g=v.useMemo(()=>new Map((r.inputs||[]).map(Pe=>[Pe.id,Pe])),[r.inputs]),x=v.useMemo(()=>h.filter(oc).map(Pe=>Pe.control),[h]),{authToken:b,tokenProps:y,documentInputValues:C,dashboardInputExecutionSnapshot:w,renderMode:N}=Mt(),{displayPreferences:S}=bl(),j=vl()??void 0,k=m.useDashboardStore(Pe=>Pe.isDashboardEditing),_=m.useDashboardStore(Pe=>Pe.isDownloadingPdf),T=Eee({displayMode:S.mode,renderMode:N}),I=T?"print":k?"edit":"view",{updateSheetDocument:D,setSelectedDocumentSectionId:E,setDocumentInspectorTab:R,setDocumentInputFilterValues:F,setDocumentInputFilterValue:M,setDocumentInputFilterModes:O,setDocumentInputFilterMode:z,removeDocumentInputFilterValue:L,setDocumentInputControlValues:V,setDocumentInputControlValue:A,upsertDashboardInput:B,updateFilterDashboardInputDefinition:$,removeDashboardInput:P,reorderDashboardInputs:U,setDashboardInputSlot:H,clearDashboardInputSlot:G}=m.useDashboardActions(),q=m.useDashboardStore(Pe=>Pe.documentInspectorTabsBySheetId[e.id]||"page"),Y=Tgt(),[W,ne]=v.useState(null),[Z,K]=v.useState(null),[X,J]=v.useState("edit"),[re,te]=v.useState({pageNumber:1,pageCount:1}),[Q,se]=v.useState({}),[oe,fe]=v.useState(!1),pe=Hr(),[xe,Ie]=v.useState(100),be=m.useDashboardStore(Pe=>Pe.documentInputRuntimeBySheetId[e.id]),ge=v.useMemo(()=>xpe(h,j),[h,j]),ee=v.useMemo(()=>bpe(h),[h]),ce=C!=null&&C.sheetId&&C.sheetId!==e.id?void 0:C,ae=ce==null?void 0:ce.filterValuesByInputId,me=ce==null?void 0:ce.controlValuesByInputId,ve=v.useMemo(()=>!w&&ce?rvt({dashboard:r,sheetId:e.id,filterValuesByInputId:ae,controlValuesByInputId:me}):void 0,[w,r,me,ce,ae,e.id]),_e=v.useMemo(()=>mgt(h),[h]),De=v.useMemo(()=>ype(h),[h]),Ue=v.useRef(De),Ne=v.useMemo(()=>m.resolveDashboardInputContext({dashboard:r,sheetId:e.id,sheetKind:"document",runtimeValues:{...ve?{dashboardInputValues:ve}:{dashboardInputValues:o},filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},mode:T?"print":"interactive",timezone:j}),[r,c,i,s,a,o,j,T,ve,e.id]),Oe=v.useMemo(()=>tvt(Ne.resolvedInputs),[Ne.resolvedInputs]),ye=v.useMemo(()=>nvt(Ne.resolvedInputs),[Ne.resolvedInputs]),Be=v.useMemo(()=>d?Oe:ce?ae||svt:(be==null?void 0:be.filterValuesByInputId)||ge,[ge,Oe,ce,ae,d,be==null?void 0:be.filterValuesByInputId]),he=v.useMemo(()=>wpe(Be,h),[Be,h]),ue=v.useMemo(()=>d?Dvt(h,Oe):(be==null?void 0:be.filterModesByInputId)||ivt,[Oe,h,d,be==null?void 0:be.filterModesByInputId]),de=v.useMemo(()=>d?ye:ce?me||avt:(be==null?void 0:be.controlValuesByInputId)||ee,[ee,ye,me,ce,d,be==null?void 0:be.controlValuesByInputId]),[Te,we]=v.useState({}),[Ee,Ke]=v.useState((w==null?void 0:w.generatedAt)||(ce==null?void 0:ce.generatedAt)||new Date().toISOString()),He=v.useMemo(()=>n.sections.find(Pe=>Pe.type==="table")||null,[n.sections]),qe=v.useMemo(()=>n.sections.find(Pe=>Pe.id===W)||null,[n.sections,W]),Je=(qe==null?void 0:qe.type)==="table"?qe:He,We=(Je==null?void 0:Je.id)||W||null;v.useEffect(()=>{E(e.id,We)},[We,E,e.id]),v.useEffect(()=>{const Pe=Ue.current;if(ce){ce.generatedAt&&Ke(Ge=>Ge===ce.generatedAt?Ge:ce.generatedAt),Ue.current=De;return}d||(F(e.id,pgt(Be,h,ge,De,Pe)),V(e.id,ggt(de,h,ee,De,Pe))),Ue.current=De},[de,_e,Be,h,ge,ee,De,ce,d,V,F,e.id]),v.useEffect(()=>{d||O(e.id,bgt(ue,h))},[ue,_e,h,d,O,e.id]);const bt=v.useCallback((Pe,Ge)=>{const at=h.find(fn=>fn.id===Pe),kt=at&&pl(at)?Sx(at,Ge):Ge;if(!kt)return;const Wt=p.get(Pe);if(Wt){H(Wt,{sheetId:e.id},{status:"set",value:{kind:"filter",filterValue:kt}});return}M(e.id,Pe,kt)},[p,h,H,M,e.id]),pt=v.useCallback((Pe,Ge)=>{const at=h.find(fn=>fn.id===Pe),kt=p.get(Pe);kt||z(e.id,Pe,Ge);const Wt=at&&pl(at)?Sx(at,Be[Pe]):Be[Pe];if(!(!Wt||!VT(Wt.operation))){if(kt){H(kt,{sheetId:e.id},{status:"set",value:{kind:"filter",filterValue:{...Wt,operation:lO(Ge)}}});return}M(e.id,Pe,{...Wt,operation:lO(Ge)})}},[Be,h,p,H,z,M,e.id]),Bt=v.useCallback(Pe=>{const Ge=p.get(Pe);if(Ge){G(Ge,{sheetId:e.id});return}L(e.id,Pe)},[G,p,L,e.id]),ut=v.useCallback((Pe,Ge,at)=>{const kt=p.get(Pe);return(kt==null?void 0:kt.kind)==="filter"&&kt.filter?$(Pe,Ge,{...at,...at!=null&&at.optionSettings?{optionSettings:{...at.optionSettings,target:at.optionSettings.target??{sheetId:e.id}}}:{},label:Ge.title||kt.label,...kt.definitionOrigin==="embedded"?{exports:WT(Ge)}:{}}):(D(e.id,Wt=>_vt(Wt,Pe,Ge,at)),{ok:!0})},[p,e.id,D,$]),$t=v.useCallback((Pe,Ge)=>{const at=p.get(Pe),kt=g.get(Pe);if((at==null?void 0:at.kind)==="control"&&(kt==null?void 0:kt.kind)==="control"){const Wt=Cge({input:{...kt,requiredAtExecution:Ge.requiredAtExecution,control:Ge},allInputs:r.inputs||[],label:Ge.label||at.label,variableName:Ge.id||at.variableName});B(Wt),Wt.kind==="control"&&at.control.id!==Wt.control.id&&D(e.id,fn=>hO(fn,at.control.id,Wt.control.id));return}D(e.id,Wt=>{const fn=(Wt.inputs||[]).find(qs=>qs.id===Pe&&oc(qs)),qr=Tvt(Wt,Pe,Ge);return fn&&fn.control.id!==Ge.id?hO(qr,fn.control.id,Ge.id):qr})},[r.inputs,p,g,e.id,D,B]),Fe=v.useCallback(Pe=>{if(p.has(Pe)){P(Pe);return}D(e.id,Ge=>({...Ge,inputs:(Ge.inputs||[]).filter(at=>at.id!==Pe)}))},[p,P,e.id,D]),ct=v.useCallback(Pe=>{if(d){const Ge=u.map(at=>at.id);U(Bk(r.inputs||[],Ge,Pe));return}D(e.id,Ge=>{const at=Ge.inputs||[];return{...Ge,inputs:Bk(at,at.map(kt=>kt.id),Pe).map(kt=>at.find(Wt=>Wt.id===kt)).filter(kt=>kt!==void 0)}})},[r.inputs,u,d,U,e.id,D]),It=v.useCallback((Pe,Ge)=>{const at=p.get(Pe);if(at){if(Ge===void 0){G(at,{sheetId:e.id});return}H(at,{sheetId:e.id},{status:"set",value:{kind:"control",value:Ge}});return}A(e.id,Pe,Ge)},[G,p,H,A,e.id]),yt=v.useCallback((Pe,Ge)=>{we(at=>Mvt(at[Pe]||[],Ge)?at:{...at,[Pe]:Ge})},[]);v.useEffect(()=>{const Pe=new Set(h.filter(oc).map(Ge=>Ge.id));we(Ge=>{const at=Object.fromEntries(Object.entries(Ge).filter(([kt])=>Pe.has(kt)));return Object.keys(at).length===Object.keys(Ge).length?Ge:at})},[h]);const vt=v.useMemo(()=>d?Ne.activeFilters:Cgt(Be,h,De,Ue.current),[Ne.activeFilters,Be,h,De,d]),mt=v.useMemo(()=>d?Ne.controlValues:Sgt(de,h,De,Ue.current),[Ne.controlValues,de,h,De,d]),St=v.useMemo(()=>d?Ne.missingRequiredInputs.map(Pe=>Pe.label):Spe(h,Be,de,De,Ue.current),[Ne.missingRequiredInputs,h,Be,de,De,d]),it=v.useMemo(()=>f?IZ({dashboard:r,sheetId:e.id,sheetKind:"document",sectionIds:n.sections.map(Pe=>Pe.id),mode:"document",runtimeValues:{dashboardInputValues:o,filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},timezone:j}):St,[r,c,i,s,a,o,n.sections,j,f,St,e.id]),nt=v.useMemo(()=>{var Pe;return Gpt({inputs:h,filterValuesByInputId:Be,controlValuesByInputId:de,controlOptionsByInputId:Te,generatedAt:Ee,timezone:j,generatedAtFormat:(Pe=n.runtime)==null?void 0:Pe.generatedAtFormat})},[h,Be,de,Te,Ee,j,(Rt=n.runtime)==null?void 0:Rt.generatedAtFormat]),gt=v.useCallback(Pe=>{D(e.id,Pe)},[e.id,D]),Vt=v.useCallback(Pe=>R(e.id,Pe),[R,e.id]),Me=v.useCallback((Pe,Ge,at,kt)=>{se(Wt=>{const fn=Wt[Pe];if(Ge.length===0){if((fn==null?void 0:fn.schemaSignature)===at||!fn)return Wt;const qr={...Wt};return delete qr[Pe],qr}return(fn==null?void 0:fn.schemaSignature)===at&&JSON.stringify(fn.columnKeyMap)===JSON.stringify(kt)&&lvt(fn.columns,Ge)?Wt:{...Wt,[Pe]:{schemaSignature:at,columns:Ge,columnKeyMap:kt}}})},[]),Qe=(Pe,Ge={})=>{ne(Pe),!Pe&&q==="section"?Vt("page"):Pe&&Ge.activateSectionInspector!==!1&&Vt("section"),K(null)},$e=(Pe,Ge)=>{const at=igt(Pe);gt(kt=>({...kt,sections:[...kt.sections.slice(0,Ge),at,...kt.sections.slice(Ge)]})),ne(at.id),Vt("section"),K(null),at.type==="table"&&Y(e.id,at)},le=Pe=>{W&&gt(Ge=>({...Ge,sections:Ge.sections.map(at=>at.id===W?Pe(at):at)}))},Ae=()=>{W&&Xe(W)},Xe=Pe=>{var kt;const Ge=Pe===W,at=n.sections.filter(Wt=>Wt.id!==Pe);gt(Wt=>({...Wt,sections:Wt.sections.filter(fn=>fn.id!==Pe)})),Ge&&(ne(((kt=at[0])==null?void 0:kt.id)||null),Vt(at[0]?"section":"page"))},Ot=(Pe,Ge,at)=>{Pe!==Ge&&(gt(kt=>{const Wt=kt.sections.findIndex(qo=>qo.id===Pe),fn=kt.sections.findIndex(qo=>qo.id===Ge);if(Wt===-1||fn===-1)return kt;const qr=[...kt.sections],[qs]=qr.splice(Wt,1),Us=at==="after"?fn+1:fn,Va=Wt<Us?Us-1:Us;return qr.splice(Math.min(Va,qr.length),0,qs),{...kt,sections:qr}}),ne(Pe))},qt=Pe=>{gt(Ge=>({...Ge,page:Pe}))},Pt=v.useCallback((Pe,Ge)=>{gt(at=>({...at,sections:at.sections.map(kt=>kt.id===Pe&&kt.type==="table"?Ge(kt):kt)}))},[gt]),Fn=Pe=>{gt(Ge=>({...Ge,header:Pe(Ge.header)}))},ft=Pe=>{gt(Ge=>({...Ge,footer:Pe(Ge.footer)}))},Tt=v.useCallback(Pe=>{Y(e.id,Pe,vt,x,mt,St)},[x,mt,vt,St,Y,e.id]),ke=v.useCallback(async()=>{if(!(y!=null&&y.apiServiceUrl)||!b){m.ue.error("Unable to export document PDF without an active session");return}if(it.length>0){m.ue.error(`Set ${it.join(", ")} before exporting`);return}const Pe=new Date().toISOString(),Ge=f?_Z({dashboard:r,sheetId:e.id,sheetKind:"document",sectionIds:n.sections.map(kt=>kt.id),mode:"document",runtimeValues:{dashboardInputValues:o,filterValues:s,controlValues:i,inlineFilterValuesMap:a,cardControlValuesMap:c},generatedAt:Pe,timezone:j}).snapshot:void 0,at=m.ue.loading("Generating document PDF...");try{await NL(y.apiServiceUrl,b,{sheetId:e.id,title:e.title||"Document",pageSize:n.page.size,orientation:n.page.orientation,timezone:j,inputSnapshot:Ge,...Ge?{}:{inputValues:{sheetId:e.id,filterValuesByInputId:he,controlValuesByInputId:de,generatedAt:Pe}}}),m.ue.dismiss(at),m.ue.success("Document PDF downloaded")}catch(kt){m.ue.dismiss(at),m.ue.error("Failed to export document PDF",{description:r_(kt,"Please try again or contact support."),descriptionClassName:n_,closeButton:!0,duration:1/0}),console.error("Document PDF export error:",kt)}},[b,n.page.orientation,n.page.size,n.sections,r,c,i,s,a,o,de,he,j,it,f,e.id,e.title,y==null?void 0:y.apiServiceUrl]),Ve=l.jsxs("button",{type:"button",disabled:_||it.length>0,onClick:ke,title:it.length>0?`Set ${it.join(", ")} before exporting`:void 0,className:m.cn(U2,"disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-transparent"),children:[_?l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):l.jsx(ac,{className:"h-3.5 w-3.5"}),"Export"]}),dt=X==="preview",_t=l.jsx("button",{type:"button",onClick:()=>{dt?J("edit"):(J("preview"),K(null))},"aria-pressed":dt,className:m.cn(U2,dt?"bg-primary text-primary-foreground hover:bg-primary/90":"text-foreground hover:bg-muted"),children:dt?"Exit preview":"Show preview"}),Xt=v.useCallback(Pe=>{te(Ge=>{const at=Math.max(1,Ge.pageCount),kt=Math.min(at,Math.max(1,Math.round(Pe)));return Ge.pageNumber===kt?Ge:{...Ge,pageNumber:kt}})},[]),wn=v.useCallback(Pe=>{te(Ge=>{const at=Math.max(Ge.pageCount,Pe,1),kt=Math.min(Ge.pageNumber,at);return Ge.pageNumber===kt&&Ge.pageCount===at?Ge:{pageNumber:kt,pageCount:at}})},[]),cn=v.useCallback(async()=>{fe(!0),Ke(new Date().toISOString());try{await pe.invalidateQueries({refetchType:"active",predicate:Pe=>{const Ge=Pe.queryKey;return Array.isArray(Ge)&&(Ge.includes("documentSection")||Ge[0]==="documentTableRows")}})}finally{fe(!1)}},[pe]),ot=l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:m.cn(U2,"font-normal text-foreground hover:bg-muted hover:text-foreground"),onClick:cn,disabled:oe,"aria-label":"Refresh report",children:[l.jsx(Ma,{className:m.cn("h-3.5 w-3.5",oe&&"animate-spin")}),"Refresh"]});return I==="print"?l.jsxs(l.Fragment,{children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx(Bbt,{document:n,inputs:h,textRenderContext:nt,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St})]}):I==="view"?l.jsxs(l.Fragment,{children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx($bt,{sheetId:e.id,document:n,inputs:h,dashboardInputsById:p,textRenderContext:nt,filterValuesByInputId:Be,filterModesByInputId:ue,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St,onSetFilterValue:bt,onSetFilterMode:pt,onRemoveFilterValue:Bt,controlValuesByInputId:de,onSetControlValue:It,actions:l.jsxs(fG,{children:[ot,l.jsx(K2,{}),Ve]})})]}):l.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-muted/60 text-foreground",children:[l.jsx(P2,{inputs:h,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,onOptionsChange:yt}),l.jsx(jxt,{sections:n.sections,inputs:h,selectedSectionId:W,onSelectSection:Qe,onDeleteSection:Xe,onReorderSection:Ot,onInsertSection:Pe=>$e(Pe,n.sections.length)}),l.jsxs("main",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:[l.jsx(Hpe,{sheetId:e.id,inputs:h,dashboardInputsById:p,filterValuesByInputId:Be,filterModesByInputId:ue,documentFilterValues:vt,documentControlValues:mt,onSetFilterValue:bt,onSetFilterMode:pt,onUpdateFilterInput:ut,onUpdateControlInput:$t,onRemoveFilterValue:Bt,onRemoveInput:Fe,onReorderInputs:ct,controlValuesByInputId:de,onSetControlValue:It,actions:l.jsxs(fG,{children:[ot,l.jsx(K2,{}),l.jsx(Rvt,{zoom:xe,onZoomChange:Ie}),l.jsx(K2,{}),_t]}),isEditing:!0}),l.jsxs("div",{className:"relative min-h-0 flex-1 overflow-auto",onClick:Pe=>{Pe.target===Pe.currentTarget&&Qe(null)},children:[l.jsx("div",{style:{zoom:xe/100},className:"px-6 py-8",children:l.jsx("div",{className:"mx-auto w-fit",children:l.jsx(Y4,{document:n,inputs:h,textRenderContext:nt,documentFilterValues:vt,documentControlDefinitions:x,documentControlValues:mt,documentDashboardInputValues:ve,missingRequiredInputLabels:St,isEditing:!dt,selectedSectionId:dt?void 0:W,activeAddIndex:dt?null:Z,onSelectSection:Qe,onToggleAddIndex:K,onInsertSection:$e,onEditTableSection:Tt,onUpdateTableSection:Pt,onTableResultColumnsChange:Me,onReorderSection:Ot,pageNumber:re.pageNumber,onPageCountChange:wn,measurementScale:xe/100})})}),l.jsx(pvt,{pageNumber:re.pageNumber,pageCount:re.pageCount,onFirst:()=>Xt(1),onPrevious:()=>Xt(re.pageNumber-1),onNext:()=>Xt(re.pageNumber+1),onLast:()=>Xt(re.pageCount)})]})]}),l.jsx(uvt,{sheetId:e.id,tab:q,onTabChange:Vt,document:n,selectedSection:qe,inputSourceSection:Je,tableResultColumnCacheBySectionId:Q,onSelectSection:Qe,onUpdatePage:qt,onUpdateSelectedSection:le,onDeleteSelectedSection:Ae,onUpdateHeader:Fn,onUpdateFooter:ft,onEditTableSection:Tt})]})}function uvt({sheetId:e,tab:t,onTabChange:n,document:r,selectedSection:o,inputSourceSection:s,tableResultColumnCacheBySectionId:i,onSelectSection:a,onUpdatePage:c,onUpdateSelectedSection:u,onDeleteSelectedSection:d,onUpdateHeader:f,onUpdateFooter:h,onEditTableSection:p,actions:g}){const x=[{id:"page",label:"Page"},{id:"header",label:"Header"},{id:"footer",label:"Footer"},{id:"inputs",label:"Inputs"}],b=m.useDashboardStore(S=>S.dashboard),y=v.useMemo(()=>{const S=kb(b,e);return S.length>0?S.map(NC):r.inputs||[]},[b,r.inputs,e]),C=t==="section"&&o!=null,w=t==="section"?"page":t,N=v.useMemo(()=>{if((o==null?void 0:o.type)!=="table")return;const S=i[o.id];if(!S)return;const j=gpe(o);return S.schemaSignature===j?S:void 0},[o,i]);return l.jsxs("aside",{className:"flex w-[360px] shrink-0 flex-col border-l bg-background",children:[C?l.jsx(dvt,{section:o,onBack:()=>a(null),actions:g}):l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"flex h-10 shrink-0 items-center justify-between gap-2 border-b px-3",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx(zm,{className:"h-3.5 w-3.5 text-muted-foreground"}),l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Document"})]}),g]}),l.jsx("div",{className:"flex shrink-0 items-center gap-3 overflow-x-auto border-b px-3",children:x.map(S=>l.jsx("button",{type:"button",onClick:()=>n(S.id),className:m.cn("-mb-px border-b-2 py-2 text-[12px] transition-colors",w===S.id?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:S.label},S.id))})]}),l.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:C?l.jsx(hvt,{section:o,inputs:y,tableResultColumns:N==null?void 0:N.columns,tableColumnKeyMap:N==null?void 0:N.columnKeyMap,onUpdateSection:u,onEditTableSection:p}):w==="page"?l.jsx(mvt,{page:r.page,onUpdatePage:c}):w==="header"?l.jsx(wvt,{header:r.header,inputs:y,onUpdateHeader:f}):w==="footer"?l.jsx(Cvt,{footer:r.footer,inputs:y,onUpdateFooter:h}):w==="inputs"?l.jsx(Svt,{sheetId:e,document:r,selectedSection:s,inputCount:y.length,onSelectSection:S=>a(S,{activateSectionInspector:!1}),onEditTableSection:p}):null})]})}function dvt({section:e,onBack:t,actions:n}){const r=F0(e.type);return l.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b px-2",children:[l.jsx("button",{type:"button",onClick:t,"aria-label":"Back to document",className:"inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-[4px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:l.jsx(ow,{className:"h-3.5 w-3.5"})}),l.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[l.jsx(r,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"truncate text-[12px] font-medium text-foreground",children:wC[e.type]})]}),n]})}const fvt=[{value:"style",label:"Style"},{value:"columns",label:"Columns"},{value:"conditionalFormatting",label:"Conditional formatting"}];function hvt({section:e,inputs:t,tableResultColumns:n=[],tableColumnKeyMap:r,onUpdateSection:o,onEditTableSection:s}){var T,I,D,E,R,F,M,O,z;const[i,a]=v.useState("style");if(!e)return l.jsxs("div",{className:"flex flex-col items-center py-12 text-center",children:[l.jsx(li,{className:"mb-2 h-5 w-5 text-muted-foreground/50"}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Select a section"})]});const c=L=>{o(V=>V.type!=="text"?V:{...V,style:{...V.style,...L}})},u=L=>{o(V=>{var H;if(V.type!=="table")return V;const A=(H=V.card.preferences)==null?void 0:H.tablePrefs,{density:B,...$}=L,P={...A==null?void 0:A.tableStyle,...$},U=B??(A==null?void 0:A.density);return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,...U?{density:U}:{},tableStyle:P}}},table:{...V.table,...B?{rowHeightPx:aO(B)}:{}}}})},d=L=>{o(V=>{var $;if(V.type!=="table")return V;const A=($=V.card.preferences)==null?void 0:$.tablePrefs,B=A==null?void 0:A.tableStyle;return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,tableStyle:{...B,totals:{...B==null?void 0:B.totals,...L}}}}}}})},f=()=>{o(L=>{var V;return L.type==="table"?{...L,table:{...L.table,repeatHeaderOnPageBreak:!0,rowHeightPx:aO(zf.density)},card:{...L.card,preferences:{...L.card.preferences,tablePrefs:{...(V=L.card.preferences)==null?void 0:V.tablePrefs,density:zf.density,tableStyle:{headerStyle:zf.headerStyle,headerWrapText:zf.headerWrapText,stripedRows:zf.stripedRows,gridLines:zf.gridLines,wrapText:zf.wrapText,totals:{enabled:Bf.enabled,backgroundColor:Bf.backgroundColor,textColor:Bf.textColor,fontWeight:Bf.fontWeight,borderTop:Bf.borderTop,borderTopStyle:Bf.borderTopStyle,borderTopColor:Bf.borderTopColor}}}}}}:L})},h=L=>{o(V=>{var P;if(V.type!=="table")return V;const A=(P=V.card.preferences)==null?void 0:P.tablePrefs,B=A==null?void 0:A.tableStyle;return{...V,card:{...V.card,preferences:{...V.card.preferences,tablePrefs:{...A,tableStyle:{...B,totals:{...B==null?void 0:B.totals,enabled:L}}}}},table:{...V.table,totalsRow:L}}})},p=(L,V)=>{o(A=>{var $;if(A.type!=="table")return A;const B=($=A.card.preferences)==null?void 0:$.tablePrefs;return{...A,card:{...A.card,preferences:{...A.card.preferences,tablePrefs:{...B,columnVisibility:Boe(B==null?void 0:B.columnVisibility,L,V)}}}}})},g=()=>{o(L=>{var A;if(L.type!=="table")return L;const V=(A=L.card.preferences)==null?void 0:A.tablePrefs;return{...L,card:{...L.card,preferences:{...L.card.preferences,tablePrefs:{...V,columnVisibility:void 0}}}}})},x=e.type==="table"?dL(rL((I=(T=e.card.preferences)==null?void 0:T.tablePrefs)==null?void 0:I.conditionalFormatting),ZI(e.card,n,r)):{rules:[]},b=e.type==="table"&&hge(e.card.type),y=b?mge(e.card,n,r):[],C=e.type==="table"&&e.card.type==="table"?pge(e.card,n):[],w=b&&y.length>0,N=e.type==="table"&&e.card.type==="table",S=fvt.filter(L=>L.value==="style"||L.value==="columns"&&N||L.value==="conditionalFormatting"&&w),j=S.some(L=>L.value===i)?i:"style",k=((D=y[0])==null?void 0:D.value)??wa,_=L=>{o(V=>V.type==="table"?{...V,card:_yt(V.card,{version:1,rules:L})}:V)};return l.jsxs("div",{className:"space-y-4",children:[e.type==="text"&&l.jsxs(l.Fragment,{children:[l.jsx(Go,{label:"Content",children:l.jsx(O0,{content:e.content,inputs:t,multiline:!0,onChange:L=>o(V=>V.type==="text"?{...V,content:L}:V)})}),l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsx(Go,{label:"Size",children:l.jsxs(m.Select,{value:String(((E=e.style)==null?void 0:E.fontSize)||13),onValueChange:L=>c({fontSize:Number(L)}),children:[l.jsx(m.SelectTrigger,{size:"sm","aria-label":"Text size",children:l.jsx(m.SelectValue,{})}),l.jsx(m.SelectContent,{children:[11,12,13,14,16,18,20,24].map(L=>l.jsxs(m.SelectItem,{value:String(L),children:[L,"px"]},L))})]})}),l.jsx(Go,{label:"Weight",children:l.jsxs(m.Select,{value:((R=e.style)==null?void 0:R.fontWeight)||"normal",onValueChange:L=>c({fontWeight:L}),children:[l.jsx(m.SelectTrigger,{size:"sm","aria-label":"Text weight",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"normal",children:"Regular"}),l.jsx(m.SelectItem,{value:"medium",children:"Medium"}),l.jsx(m.SelectItem,{value:"semibold",children:"Semibold"}),l.jsx(m.SelectItem,{value:"bold",children:"Bold"})]})]})})]}),l.jsx(Go,{label:"Alignment",children:l.jsx("div",{className:"inline-flex h-8 items-center rounded-md border bg-background p-0.5",children:["left","center","right"].map(L=>{var B;const V=L==="left"?L0e:L==="center"?O0e:$0e,A=((B=e.style)==null?void 0:B.align)||"left";return l.jsx(m.Button,{type:"button",variant:A===L?"secondary":"ghost",size:"icon",className:"h-6 w-7","aria-label":`Align ${L}`,onClick:()=>c({align:L}),children:l.jsx(V,{className:"h-3.5 w-3.5"})},L)})})}),l.jsx(Go,{label:"Color",children:l.jsx(yvt,{value:((F=e.style)==null?void 0:F.color)||"#27272a","aria-label":"Text color",onValueChange:L=>c({color:L})})})]}),e.type==="table"&&l.jsxs(l.Fragment,{children:[l.jsx("div",{className:"inline-flex h-8 items-center rounded-md border bg-background p-0.5",children:S.map(L=>l.jsx(m.Button,{type:"button",variant:j===L.value?"secondary":"ghost",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>a(L.value),children:L.label},L.value))}),j==="style"?l.jsxs(l.Fragment,{children:[l.jsx(Go,{label:"Title",children:l.jsx(m.Input,{size:"xs",value:e.title||e.card.title,onChange:L=>o(V=>V.type==="table"?{...V,title:L.target.value,card:{...V.card,title:L.target.value}}:V)})}),l.jsx(fge,{style:H4(e),onDensityChange:L=>u({density:L}),onStyleChange:u,showFullStyle:e.card.type==="table",totals:e.card.type==="table"&&!((M=e.card.sql)!=null&&M.trim())?{enabled:e.table.totalsRow===!0,onEnabledChange:h,onStyleChange:d}:void 0,onReset:e.card.type==="table"?f:void 0})]}):j==="columns"?l.jsx(uge,{columns:C,columnVisibility:(z=(O=e.card.preferences)==null?void 0:O.tablePrefs)==null?void 0:z.columnVisibility,onColumnVisibilityChange:p,onShowAllColumns:g,emptyMessage:"Run the table query or add fields before hiding output columns."}):l.jsx(l.Fragment,{children:l.jsx(yge,{columnId:k,availableColumns:y,conditionalRules:x.rules,onConditionalRulesChange:_,startRulesWithNoTrigger:!0})}),l.jsx("div",{className:"flex flex-col gap-1.5 pt-1",children:l.jsxs(m.Button,{type:"button",variant:"secondary",size:"xs",className:"w-full gap-1.5",onClick:()=>s(e),children:[l.jsx(m.Table2,{className:"h-3 w-3"}),"Edit table"]})})]}),e.type==="spacer"&&l.jsx(Go,{label:"Height",children:l.jsx(X4,{"aria-label":"Spacer height",min:8,max:240,value:e.heightPx,onValueChange:L=>o(V=>V.type==="spacer"?{...V,heightPx:L}:V)})})]})}function mvt({page:e,onUpdatePage:t}){const n=(r,o)=>{t({...e,margins:{...e.margins,[r]:o}})};return l.jsxs("div",{className:"space-y-5",children:[l.jsx(Go,{label:"Page size",children:l.jsxs(m.Select,{value:e.size,onValueChange:r=>t({...e,size:r}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Page size",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"letter",children:"Letter"}),l.jsx(m.SelectItem,{value:"a4",children:"A4"})]})]})}),l.jsx(Go,{label:"Orientation",children:l.jsxs(m.Select,{value:e.orientation,onValueChange:r=>t({...e,orientation:r}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Orientation",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"portrait",children:"Portrait"}),l.jsx(m.SelectItem,{value:"landscape",children:"Landscape"})]})]})}),l.jsx(Go,{label:"Margins",children:l.jsx("div",{className:"grid grid-cols-2 gap-2",children:["top","bottom","left","right"].map(r=>l.jsxs("label",{className:"block",children:[l.jsx("span",{className:"mb-1 block text-[10px] capitalize text-muted-foreground",children:r}),l.jsx(X4,{"aria-label":`${r} margin`,min:0,step:.125,value:e.margins[r],onValueChange:o=>n(r,o)})]},r))})})]})}function X4({value:e,onValueChange:t,min:n=0,max:r,step:o,disabled:s,"aria-label":i}){const[a,c]=v.useState(()=>String(e)),[u,d]=v.useState(!1);v.useEffect(()=>{u||c(String(e))},[u,e]);const f=v.useCallback((h,p=!1)=>{if(h.trim()===""){p&&c(String(e));return}const g=Number(h);if(!Number.isFinite(g)){p&&c(String(e));return}const x=p?Math.min(r??g,Math.max(n,g)):g;x<n||r!==void 0&&x>r||(t(x),p&&c(String(x)))},[r,n,t,e]);return l.jsx(m.Input,{"aria-label":i,size:"sm",type:"number",min:n,max:r,step:o,value:a,disabled:s,onFocus:()=>d(!0),onChange:h=>{c(h.target.value),f(h.target.value)},onBlur:()=>{d(!1),f(a,!0)}})}function pvt({pageNumber:e,pageCount:t,onFirst:n,onPrevious:r,onNext:o,onLast:s}){return t<=1?null:l.jsxs("div",{className:"sticky bottom-4 z-20 mx-auto mt-[-44px] flex w-max items-center gap-1.5 rounded-full border border-zinc-200 bg-white/95 px-2.5 py-1 text-[13px] text-zinc-700 shadow-[0_8px_24px_rgba(0,0,0,0.14)] backdrop-blur",children:[l.jsx("button",{type:"button","aria-label":"First document page",disabled:e<=1,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:n,children:l.jsx(GZ,{className:"h-3.5 w-3.5"})}),l.jsx("button",{type:"button","aria-label":"Previous document page",disabled:e<=1,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:r,children:l.jsx(Om,{className:"h-3.5 w-3.5"})}),l.jsxs("span",{className:"min-w-[44px] text-center text-[12px] tabular-nums",children:[e," / ",t]}),l.jsx("button",{type:"button","aria-label":"Next document page",disabled:e>=t,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:o,children:l.jsx(Ft.ChevronRight,{className:"h-3.5 w-3.5"})}),l.jsx("button",{type:"button","aria-label":"Last document page",disabled:e>=t,className:"inline-flex h-5 w-5 items-center justify-center rounded-full text-zinc-500 transition-colors hover:bg-zinc-100 hover:text-zinc-900 disabled:cursor-not-allowed disabled:opacity-35 disabled:hover:bg-transparent disabled:hover:text-zinc-500",onClick:s,children:l.jsx(YZ,{className:"h-3.5 w-3.5"})})]})}const gvt=["#ffffff","#fafafa","#f4f4f5","#e4e4e7","#a1a1aa","#52525b","#27272a","#0f172a","#eff6ff","#eef2ff","#ecfdf5","#fefce8"];function xvt(e){return e.startsWith("#")?e.toLowerCase():`#${e.toLowerCase()}`}function bvt(e){return/^#[0-9a-fA-F]{6}$/.test(e)}function yvt({value:e,onValueChange:t,"aria-label":n}){const[r,o]=v.useState(!1),[s,i]=v.useState(e.toUpperCase());v.useEffect(()=>{i(e.toUpperCase())},[e]);const a=v.useCallback(u=>{const d=xvt(u.trim());if(!bvt(d)){i(e.toUpperCase());return}if(d===e.toLowerCase()){i(d.toUpperCase());return}t(d)},[t,e]),c=e.toLowerCase();return l.jsxs(m.Popover,{open:r,onOpenChange:o,children:[l.jsx(m.PopoverTrigger,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":n,className:"flex h-7 w-full items-center gap-2 rounded-[5px] border border-input bg-background px-1.5 text-[12px] text-foreground transition-colors hover:bg-muted/40 focus-visible:border-ring focus-visible:outline-none",children:[l.jsx("span",{"aria-hidden":"true",className:"h-4 w-4 shrink-0 rounded-[3px] border border-border/60",style:{backgroundColor:e}}),l.jsx("span",{className:"font-mono text-[11px] uppercase tracking-wide text-foreground",children:e.toUpperCase()}),l.jsx(Om,{"aria-hidden":"true",className:"ml-auto h-3 w-3 shrink-0 -rotate-90 text-muted-foreground/60"})]})}),l.jsxs(m.PopoverContent,{align:"start",sideOffset:4,className:"w-[224px] space-y-2 p-2",onMouseDown:u=>u.stopPropagation(),children:[l.jsx("div",{role:"radiogroup","aria-label":"Color presets",className:"grid grid-cols-6 gap-1",children:gvt.map(u=>{const d=u.toLowerCase()===c;return l.jsx("button",{type:"button",role:"radio","aria-checked":d,"aria-label":u,title:u.toUpperCase(),onClick:()=>{t(u),o(!1)},className:m.cn("relative flex h-7 w-7 items-center justify-center rounded-[4px] border border-border/60 transition-shadow",d&&"ring-1 ring-foreground ring-offset-1"),style:{backgroundColor:u},children:d&&l.jsx(m.Check,{"aria-hidden":"true",className:m.cn("h-3 w-3",vvt(u)?"text-zinc-900":"text-white"),strokeWidth:3})},u)})}),l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{"aria-hidden":"true",className:"text-[11px] font-medium uppercase tracking-[0.06em] text-muted-foreground",children:"Hex"}),l.jsx(m.Input,{size:"xs",value:s,onChange:u=>i(u.target.value.toUpperCase()),onBlur:u=>a(u.currentTarget.value),onKeyDown:u=>{u.key==="Enter"?u.currentTarget.blur():u.key==="Escape"&&(i(e.toUpperCase()),u.currentTarget.blur())},className:"font-mono text-[11px]"}),l.jsxs("label",{className:"relative inline-flex h-7 w-7 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border border-border/60 bg-background hover:bg-muted/60",title:"Custom color",children:[l.jsx("span",{"aria-hidden":"true",className:"absolute inset-1 rounded-[3px]",style:{backgroundImage:"conic-gradient(from 0deg, #ef4444, #f59e0b, #84cc16, #06b6d4, #6366f1, #ec4899, #ef4444)"}}),l.jsx("input",{"aria-label":`${n??"Color"} (custom)`,type:"color",value:e,onChange:u=>t(u.target.value),className:"absolute inset-0 h-full w-full cursor-pointer opacity-0"})]})]})]})]})}function vvt(e){const t=e.replace("#","");if(t.length!==6)return!0;const n=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return .2126*n+.7152*r+.0722*o>150}function wvt({header:e,inputs:t,onUpdateHeader:n}){const r=e?m.getRegionImageBlock(e.blocks,"logo"):void 0,o=e?m.getRegionTextBlock(e.blocks,"title"):void 0,s=e?m.getRegionTextBlock(e.blocks,"metadata"):void 0,i=(r==null?void 0:r.area)==="center"||(r==null?void 0:r.area)==="right"?r.area:"left",a=(u,d,f)=>{n(h=>{const p=h||m.createHeaderRegion();return{...p,enabled:!0,blocks:m.upsertTextRegionBlock(p.blocks,{id:`header_${u}`,role:u,area:d,content:f})}})},c=u=>{n(d=>{const f=d||m.createHeaderRegion(),h=m.getRegionImageBlock(f.blocks,"logo");return{...f,enabled:!0,blocks:m.upsertImageRegionBlock(f.blocks,{id:"header_logo",type:"image",role:"logo",area:"left",src:"",alt:"Logo",widthPx:120,...h,...u})}})};return e?l.jsxs("div",{className:"space-y-4",children:[l.jsx(cge,{label:"Enabled",enabled:!!(e!=null&&e.enabled),onToggle:u=>n(d=>Nge(d,m.createHeaderRegion,u))}),l.jsx(Go,{label:"Logo URL",children:l.jsx(m.Input,{"aria-label":"Logo URL",size:"sm",value:(r==null?void 0:r.src)||"",disabled:!(e!=null&&e.enabled),onChange:u=>c({src:u.target.value})})}),l.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_5rem] gap-2",children:[l.jsx(Go,{label:"Logo placement",children:l.jsxs(m.Select,{value:i,disabled:!(e!=null&&e.enabled),onValueChange:u=>c({area:u}),children:[l.jsx(m.SelectTrigger,{"aria-label":"Logo placement",size:"sm",children:l.jsx(m.SelectValue,{})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"left",children:"Left"}),l.jsx(m.SelectItem,{value:"center",children:"Center"}),l.jsx(m.SelectItem,{value:"right",children:"Right"})]})]})}),l.jsx(Go,{label:"Width",children:l.jsx(X4,{"aria-label":"Logo width",min:24,max:320,step:4,value:(r==null?void 0:r.widthPx)||120,disabled:!(e!=null&&e.enabled),onValueChange:u=>c({widthPx:u})})})]}),l.jsx(Go,{label:"Logo alt text",children:l.jsx(m.Input,{"aria-label":"Logo alt text",size:"sm",value:(r==null?void 0:r.alt)||"",disabled:!(e!=null&&e.enabled),onChange:u=>c({alt:u.target.value})})}),l.jsx(Go,{label:"Title",children:l.jsx(O0,{content:o==null?void 0:o.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:u=>a("title","title",u)})}),l.jsx(Go,{label:"Metadata",children:l.jsx(O0,{content:s==null?void 0:s.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:u=>a("metadata","metadata",u)})})]}):l.jsx(Sge,{title:"No header",description:"Logo, title, and metadata.",actionLabel:"Add header",onAdd:()=>n(()=>m.createHeaderRegion())})}function Cvt({footer:e,inputs:t,onUpdateFooter:n}){const r=e?m.getRegionTextBlock(e.blocks,"note"):void 0,o=e?m.getRegionTextBlock(e.blocks,"pageInfo"):void 0,s=(i,a,c)=>{n(u=>{const d=u||m.createFooterRegion();return{...d,enabled:!0,blocks:m.upsertTextRegionBlock(d.blocks,{id:`footer_${i}`,role:i,area:a,content:c})}})};return e?l.jsxs("div",{className:"space-y-4",children:[l.jsx(cge,{label:"Enabled",enabled:!!(e!=null&&e.enabled),onToggle:i=>n(a=>Nge(a,m.createFooterRegion,i))}),l.jsx(Go,{label:"Note",children:l.jsx(O0,{content:r==null?void 0:r.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:i=>s("note","note",i)})}),l.jsx(Go,{label:"Page info",children:l.jsx(O0,{content:o==null?void 0:o.content,inputs:t,disabled:!(e!=null&&e.enabled),onChange:i=>s("pageInfo","pageInfo",i)})})]}):l.jsx(Sge,{title:"No footer",description:"Note and page info.",actionLabel:"Add footer",onAdd:()=>n(()=>Evt())})}function Sge({title:e,description:t,actionLabel:n,onAdd:r}){return l.jsxs("div",{className:"rounded border border-dashed border-border bg-muted/20 p-4",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsx("p",{className:"text-[13px] font-medium text-foreground",children:e}),l.jsx("p",{className:"text-[12px] leading-4 text-muted-foreground",children:t})]}),l.jsx(m.Button,{type:"button",size:"sm",variant:"outline",className:"mt-4 h-8 w-full justify-center text-[12px]",onClick:r,children:n})]})}function Svt({sheetId:e,document:t,selectedSection:n,inputCount:r,onSelectSection:o,onEditTableSection:s}){const i=m.useDashboardStore(N=>N.dashboard),{upsertDashboardInput:a,updateFilterDashboardInputDefinition:c,removeDashboardInput:u,updateSheetDocument:d}=m.useDashboardActions(),f=(n==null?void 0:n.type)==="table"?n:null,h=v.useMemo(()=>kb(i,e),[i,e]),p=v.useMemo(()=>h.map(NC),[h]),g=v.useMemo(()=>new Map((i.inputs||[]).map(N=>[N.id,N])),[i.inputs]),x=t.sections.filter(N=>N.type==="table"),b=v.useCallback(N=>{var k,_;const S=f==null?void 0:f.card;if(!S||h.some(T=>evt(T,N)))return;const j=Xyt({field:N,existingInputs:i.inputs||[],sheetId:e,dataSource:S.dataSource,connectionId:((k=S.dataSource)==null?void 0:k.connectionId)||S.connectionId,connectionType:(_=S.dataSource)==null?void 0:_.connectionType});a(j)},[i.inputs,h,f==null?void 0:f.card,e,a]),y=v.useCallback(N=>{u(N)},[u]),C=v.useCallback((N,S)=>{const j=(i.inputs||[]).find(k=>k.id===N);j&&a({...j,requiredAtExecution:S,...j.kind==="control"?{control:{...j.control,requiredAtExecution:S}}:{}})},[i.inputs,a]),w=v.useCallback((N,S)=>{var T,I,D;const j=h.find(E=>E.id===N);if(!j)return;if(j.kind==="filter"&&j.definitionOrigin==="dashboardFilter"){c(j.id,{...j.filter,title:((T=S.label)==null?void 0:T.trim())||j.filter.title,variableName:S.variableName||j.filter.variableName},S.variableName===void 0?{label:((I=S.label)==null?void 0:I.trim())||j.label}:{variableName:S.variableName,label:((D=S.label)==null?void 0:D.trim())||j.label});return}const k=g.get(N);if(!k)return;const _=Cge({input:k,allInputs:i.inputs||[],...S});a(_),j.kind==="control"&&_.kind==="control"&&j.control.id!==_.control.id&&d(e,E=>hO(E,j.control.id,_.control.id))},[i.inputs,h,g,e,d,c,a]);return l.jsxs("div",{className:"space-y-3",children:[l.jsxs("div",{className:"space-y-1",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("h3",{className:"text-[12px] font-medium text-foreground",children:"Document inputs"}),l.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:r})]}),l.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Add document-wide filter inputs from the selected table fields."})]}),l.jsx(Nvt,{selectedTableSection:f,tableSections:x,inputs:p,onSelectTable:o,onEditTableSection:s,onAddField:b}),l.jsx(kvt,{inputs:p,onUpdateMetadata:w,onRemove:y,onSetRequired:C})]})}function Nvt({selectedTableSection:e,tableSections:t,inputs:n,onSelectTable:r,onEditTableSection:o,onAddField:s}){return t.length===0?l.jsxs("div",{className:"flex flex-col items-center justify-center rounded-md border bg-muted/20 px-4 py-6 text-center",children:[l.jsx(li,{className:"mb-2 h-5 w-5 text-muted-foreground/50"}),l.jsx("h3",{className:"mb-1 text-[12px] font-medium text-foreground",children:"No table sections"}),l.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Add a document table before creating filter inputs."})]}):e?e.card?l.jsx(jvt,{section:e,inputs:n,onAddField:s}):l.jsxs("div",{className:"space-y-2 rounded-md border bg-muted/20 p-3 text-[12px] text-muted-foreground",children:[l.jsxs("div",{className:"flex items-center gap-2 text-foreground",children:[l.jsx(ps,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"font-medium",children:"Configure this table"})]}),l.jsx("p",{children:"Choose a data source before adding document inputs."}),l.jsxs(m.Button,{type:"button",variant:"secondary",size:"sm",className:"h-8 w-full gap-2",onClick:()=>o(e),children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),"Configure table"]})]}):l.jsxs("div",{className:"rounded-md border bg-background",children:[l.jsx("div",{className:"border-b px-2.5 py-2 text-[11px] font-medium text-muted-foreground",children:"Choose a table section"}),l.jsx("div",{className:"space-y-1 p-1.5",children:t.map(i=>{var a;return l.jsxs(m.Button,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-full justify-start gap-2 px-2 text-xs",onClick:()=>r(i.id),children:[l.jsx(m.Table2,{className:"h-3.5 w-3.5"}),i.title||((a=i.card)==null?void 0:a.title)||"Table"]},i.id)})})]})}function jvt({section:e,inputs:t,onAddField:n}){var i,a;const r=m.useEditorStore(c=>{var u;return(u=c.card)==null?void 0:u.id}),{setCard:o}=m.useEditorActions(),s=v.useMemo(()=>t.filter(pl).map(c=>({id:c.filter.id,column:c.filter.column,title:c.filter.title,dataType:c.filter.dataType,table:c.filter.table||"",database:c.filter.database||"",qualifiedTableName:c.filter.qualifiedTableName,connectionId:c.filter.connectionId,operation:c.filter.operation,sql:c.filter.sql,fieldMeta:c.filter.fieldMeta,semanticContext:c.filter.semanticContext})),[t]);return v.useEffect(()=>{e.card&&o(e.card)},[e.card,o]),r!==((i=e.card)==null?void 0:i.id)?l.jsx("div",{className:"rounded border border-dashed p-4 text-[12px] text-muted-foreground",children:"Loading fields..."}):l.jsxs("div",{className:"flex flex-col overflow-hidden rounded-md border bg-background",children:[l.jsxs("div",{className:"border-b px-2.5 py-2 text-[12px] text-muted-foreground",children:["Fields from"," ",l.jsx("span",{className:"font-medium text-foreground",children:e.title||((a=e.card)==null?void 0:a.title)||"this table"})]}),l.jsx(cpe,{className:"h-[300px]",context:"document-filter",inlineFilters:s,onFieldSelect:n})]})}function kvt({inputs:e,onUpdateMetadata:t,onRemove:n,onSetRequired:r}){return l.jsxs("div",{className:"space-y-2",children:[l.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l.jsx("p",{className:"text-[11px] font-medium text-muted-foreground",children:"Active inputs"}),e.length>0?l.jsx("span",{className:"rounded-full bg-muted px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-muted-foreground",children:e.length}):null]}),e.length===0?l.jsx("div",{className:"rounded-md border bg-muted/20 px-3 py-2 text-[11px] text-muted-foreground",children:"No document inputs yet."}):l.jsx("div",{className:"space-y-1",children:e.map(o=>l.jsx(Ivt,{input:o,onUpdateMetadata:s=>t(o.id,s),onRemove:()=>n(o.id),onSetRequired:s=>r(o.id,s)},o.id))})]})}function Ivt({input:e,onUpdateMetadata:t,onSetRequired:n,onRemove:r}){const[o,s]=v.useState(e.label);v.useEffect(()=>{s(e.label)},[e.id,e.label]);const i=v.useCallback(()=>{const c=o.trim();if(!c){s(e.label);return}c!==e.label&&t({label:c})},[e.label,o,t]),a=c=>{c.key==="Enter"&&(c.preventDefault(),c.currentTarget.blur())};return l.jsxs("div",{className:"rounded-md border bg-background px-2.5 py-2",children:[l.jsxs("div",{className:"flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"min-w-0 flex-1 space-y-1.5",children:[l.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[l.jsx(m.Input,{size:"xs",className:"h-6 min-w-0 border-0 bg-transparent px-0 py-0 text-[12px] font-medium shadow-none focus-visible:ring-0",value:o,onChange:c=>s(c.target.value),onBlur:i,onKeyDown:a,"aria-label":`${e.label} input label`}),l.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium uppercase text-muted-foreground",children:e.kind==="control"?"Control":"Filter"})]}),l.jsx(m.Input,{size:"xs",className:"h-6 min-w-0 rounded border bg-muted/20 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground shadow-none focus-visible:ring-0",value:`{{${e.variableName}}}`,readOnly:!0,"aria-label":`${e.label} input token`})]}),l.jsx("div",{className:"flex shrink-0 items-center gap-1",children:l.jsx(m.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 hover:bg-destructive/10 hover:text-destructive",onClick:r,"aria-label":`Remove ${e.label} document input`,children:l.jsx(Ra,{className:"h-3 w-3"})})})]}),l.jsxs("label",{className:"mt-2 flex items-center justify-between gap-2 border-t pt-1.5 text-[11px] text-muted-foreground",children:[l.jsx("span",{children:"Required"}),l.jsx(m.Switch,{size:"xs",checked:e.requiredAtExecution,onCheckedChange:n,"aria-label":`Required ${e.label}`})]})]})}function _vt(e,t,n,r){return{...e,inputs:(e.inputs||[]).map(o=>{if(o.id!==t||!pl(o))return o;const s={...o.filter,...n};return{...o,label:s.title||o.label,variableName:(r==null?void 0:r.variableName)||o.variableName,filter:s,exports:WT(s)}})}}function Tvt(e,t,n){return{...e,inputs:(e.inputs||[]).map(r=>r.id!==t||!oc(r)?r:{...r,label:n.label||r.label,requiredAtExecution:n.requiredAtExecution,control:n})}}function Dvt(e,t){return e.reduce((n,r)=>{if(!pl(r))return n;const o=t[r.id];return o&&VT(o.operation)&&(n[r.id]=Cpe(o.operation)),n},{})}function Nge(e,t,n){return e?{...e,enabled:n}:n?t():void 0}function Evt(){const e=m.createFooterRegion();return{...e,blocks:m.upsertTextRegionBlock(e.blocks,{id:"footer_pageInfo",role:"pageInfo",area:"pageInfo",content:[{type:"text",value:"Page "},{type:"variable",ref:{source:"documentMeta",key:"pageNumber"}},{type:"text",value:" of "},{type:"variable",ref:{source:"documentMeta",key:"pageCount"}}]})}}function Mvt(e,t){return e.length!==t.length?!1:e.every((n,r)=>{var o,s;return n.value===((o=t[r])==null?void 0:o.value)&&n.label===((s=t[r])==null?void 0:s.label)})}const Hf=[50,75,100,125,150],U2="inline-flex h-full items-center gap-1.5 rounded-none border-0 bg-transparent px-2 text-[12px] transition-colors";function fG({children:e}){return l.jsx("div",{className:"inline-flex h-7 shrink-0 items-center overflow-hidden rounded-[5px] border border-border bg-background text-foreground",children:e})}function K2(){return l.jsx("span",{"aria-hidden":"true",className:"h-full w-px bg-border"})}function Rvt({zoom:e,onZoomChange:t}){const n=Hf.indexOf(e),r=n>0,o=n>=0&&n<Hf.length-1;return l.jsxs("div",{className:"inline-flex h-full items-center gap-0.5 bg-transparent px-1",children:[l.jsx("button",{type:"button",disabled:!r,onClick:()=>{const s=Hf.indexOf(e);s>0&&t(Hf[s-1])},"aria-label":"Zoom out",className:"inline-flex h-5 w-5 items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-muted-foreground",children:l.jsx(Vc,{className:"h-3 w-3"})}),l.jsxs("span",{className:"min-w-[34px] px-1 text-center text-[11px] tabular-nums text-foreground",children:[e,"%"]}),l.jsx("button",{type:"button",disabled:!o,onClick:()=>{const s=Hf.indexOf(e);s>=0&&s<Hf.length-1&&t(Hf[s+1])},"aria-label":"Zoom in",className:"inline-flex h-5 w-5 items-center justify-center rounded-[3px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-muted-foreground",children:l.jsx(Ar,{className:"h-3 w-3"})})]})}const Avt=zV.WidthProvider(zV.Responsive),Fvt=["input","textarea","select","button","a",'[role="button"]','[role="menuitem"]','[contenteditable="true"]',"[data-rgl-drag-cancel]",".data-table-scroll-container"].join(", ");function W2(e){if(!e)return null;let t=!1;const n={};for(const[r,o]of Object.entries(e))n[r]=o.map(s=>{const i=Number(s.w),a=Number(s.h);if(i===1&&a===1)return s;const c=s.minH!==void 0&&s.minH!==null,u=Number(s.minH),d=c&&Number.isFinite(u)?Math.max(1,u):void 0,f=Number.isFinite(a)?Math.max(1,a):1,h=d!==void 0?Math.max(d,f):f;if((h!==s.h||d!==s.minH)&&(t=!0),d===void 0){const{minH:p,...g}=s;return{...g,h}}return{...s,h,minH:d}});return t?n:null}function Pvt(){const{open:e}=xL();return e?l.jsx(Xht,{}):null}function hG({sheet:e}){return e.kind==="document"?l.jsx(cvt,{sheet:e}):l.jsx(Ovt,{sheet:e})}function Ovt({sheet:e}){var F,M;const t=m.useDashboardStore(O=>O.isDashboardEditing),n=m.useDashboardStore(O=>O.currentBreakpoint),r=m.useDashboardStore(O=>O.themeStyle),o=Pu(),s=v.useRef(0),i=v.useRef(!1),a=v.useRef(null),c=m.useDashboardStore(O=>O.selectedSheetId),u=e.layouts,d=v.useMemo(()=>W2(u),[u]),f=d||u,[h,p]=v.useState(f),g=v.useRef(f),x=e.frames,{setSheetLayouts:b,setCurrentBreakpoint:y}=m.useDashboardStore(O=>O.actions);v.useEffect(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},[e.id]),v.useEffect(()=>{i.current||nO(g.current,f)&&(g.current=f,p(f))},[f]),v.useEffect(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]);function C(O){y(O)}const w=O=>{g.current=O,p(O)},N=O=>{a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{a.current=null,v.startTransition(()=>{b(e.id,O)})},0)};function S(O,z){if(!i.current){W2(z);const L=Qht(u,d);c===e.id&&L&&(w(L),N(L));return}}const j=()=>{i.current=!0},k=O=>{if(O&&c===e.id){const z={...g.current||f||{},[n]:O},V=W2(z)||z;w(V),nO(u,V)&&N(V)}i.current=!1};if(!c)return null;const _=(O,z)=>l.jsx(jge,{className:"after:content-none",ref:z,handleAxis:O});function T(){return x==null?void 0:x.map(O=>l.jsx("div",{role:"dashboard-frame-container",className:m.cn("group isolate overflow-hidden",r==null?void 0:r.dashboardCardContainer),children:l.jsx(ui,{FallbackComponent:({error:z,resetErrorBoundary:L})=>l.jsx(Xet,{error:z,resetErrorBoundary:L,frame:O}),children:l.jsx(idt,{frame:O})})},O.id))}const I=((F=r==null?void 0:r.gridLayout)==null?void 0:F.margin)??[10,10],D=o.gridMargin??I,E=o.gridContainerPadding??(o.gridMargin?I:void 0),R={...(r==null?void 0:r.cardBorderRadius)!==void 0?{"--placeholder-border-radius":`${r.cardBorderRadius}px`}:{},...o.gridStyle};return!x||x.length===0?l.jsx(fdt,{sheetId:e.id}):l.jsxs(ETe,{children:[l.jsx(Avt,{margin:D,containerPadding:E,isDraggable:t,draggableCancel:t?Fvt:void 0,resizeHandles:t?["s","w","e","n","sw","nw","se","ne"]:[],className:m.cn((M=r==null?void 0:r.gridLayout)==null?void 0:M.className),style:R,layouts:h,cols:{lg:48,md:36,sm:24,xs:12,xxs:6},rowHeight:1,onBreakpointChange:C,onLayoutChange:S,onDragStart:j,onDragStop:O=>k(O),onResizeStart:j,onResize:(O,z,L,V,A,B)=>{const $=Date.now();$-s.current>100&&(B.scrollIntoView({behavior:"auto",block:"nearest"}),s.current=$)},onResizeStop:(O,z,L,V,A,B)=>{B.scrollIntoView({behavior:"smooth",block:"nearest"}),k(O)},resizeHandle:_,children:T()}),l.jsx(Pvt,{})]})}const jge=v.forwardRef(({className:e,handleAxis:t,...n},r)=>{const o=m.useDashboardStore(s=>s.themeStyle);return o!=null&&o.cardBorderRadius,l.jsx("div",{ref:r,className:m.cn(`react-resizable-handle z-20 react-resizable-handle-${t} absolute border-foreground/40`,{"z-30 h-4 w-4":["sw","nw","se","ne"].includes(t),"bottom-0 left-0 cursor-sw-resize":t==="sw","left-0 top-0 cursor-nw-resize":t==="nw","bottom-0 right-0 cursor-se-resize":t==="se","right-0 top-0 cursor-ne-resize":t==="ne","!bottom-0 !left-0 !right-0 !h-2 !w-full cursor-ns-resize":t==="s","!left-0 !right-0 !top-0 !h-2 !w-full cursor-ns-resize":t==="n","!bottom-0 !right-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="e","!bottom-0 !left-0 !top-0 !h-full !w-2 cursor-ew-resize":t==="w"},e),...n})});jge.displayName="ResizeHandle";const GT=v.createContext(null);GT.displayName="PanelGroupContext";const oo={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},Q4=10,Zh=v.useLayoutEffect,mG=ie.useId,Lvt=typeof mG=="function"?mG:()=>null;let $vt=0;function J4(e=null){const t=Lvt(),n=v.useRef(e||t||null);return n.current===null&&(n.current=""+$vt++),e??n.current}function kge({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:o,forwardedRef:s,id:i,maxSize:a,minSize:c,onCollapse:u,onExpand:d,onResize:f,order:h,style:p,tagName:g="div",...x}){const b=v.useContext(GT);if(b===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:C,getPanelSize:w,getPanelStyle:N,groupId:S,isPanelCollapsed:j,reevaluatePanelConstraints:k,registerPanel:_,resizePanel:T,unregisterPanel:I}=b,D=J4(i),E=v.useRef({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:o,maxSize:a,minSize:c},id:D,idIsFromProps:i!==void 0,order:h});v.useRef({didLogMissingDefaultSizeWarning:!1}),Zh(()=>{const{callbacks:F,constraints:M}=E.current,O={...M};E.current.id=D,E.current.idIsFromProps=i!==void 0,E.current.order=h,F.onCollapse=u,F.onExpand=d,F.onResize=f,M.collapsedSize=n,M.collapsible=r,M.defaultSize=o,M.maxSize=a,M.minSize=c,(O.collapsedSize!==M.collapsedSize||O.collapsible!==M.collapsible||O.maxSize!==M.maxSize||O.minSize!==M.minSize)&&k(E.current,O)}),Zh(()=>{const F=E.current;return _(F),()=>{I(F)}},[h,D,_,I]),v.useImperativeHandle(s,()=>({collapse:()=>{y(E.current)},expand:F=>{C(E.current,F)},getId(){return D},getSize(){return w(E.current)},isCollapsed(){return j(E.current)},isExpanded(){return!j(E.current)},resize:F=>{T(E.current,F)}}),[y,C,w,j,D,T]);const R=N(E.current,o);return v.createElement(g,{...x,children:e,className:t,id:D,style:{...R,...p},[oo.groupId]:S,[oo.panel]:"",[oo.panelCollapsible]:r||void 0,[oo.panelId]:D,[oo.panelSize]:parseFloat(""+R.flexGrow).toFixed(1)})}const Ige=v.forwardRef((e,t)=>v.createElement(kge,{...e,forwardedRef:t}));kge.displayName="Panel";Ige.displayName="forwardRef(Panel)";let mO=null,wN=-1,rd=null;function zvt(e,t){if(t){const n=(t&Mge)!==0,r=(t&Rge)!==0,o=(t&Age)!==0,s=(t&Fge)!==0;if(n)return o?"se-resize":s?"ne-resize":"e-resize";if(r)return o?"sw-resize":s?"nw-resize":"w-resize";if(o)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function Bvt(){rd!==null&&(document.head.removeChild(rd),mO=null,rd=null,wN=-1)}function G2(e,t){var n,r;const o=zvt(e,t);if(mO!==o){if(mO=o,rd===null&&(rd=document.createElement("style"),document.head.appendChild(rd)),wN>=0){var s;(s=rd.sheet)===null||s===void 0||s.removeRule(wN)}wN=(n=(r=rd.sheet)===null||r===void 0?void 0:r.insertRule(`*{cursor: ${o} !important;}`))!==null&&n!==void 0?n:-1}}function _ge(e){return e.type==="keydown"}function Tge(e){return e.type.startsWith("pointer")}function Dge(e){return e.type.startsWith("mouse")}function YT(e){if(Tge(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Dge(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function Vvt(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Hvt(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function qvt(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:xG(e),b:xG(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Tn(r,"Stacking order can only be calculated for elements with a common ancestor");const o={a:gG(pG(n.a)),b:gG(pG(n.b))};if(o.a===o.b){const s=r.childNodes,i={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===i.a)return 1;if(c===i.b)return-1}}return Math.sign(o.a-o.b)}const Uvt=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Kvt(e){var t;const n=getComputedStyle((t=Ege(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Wvt(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Kvt(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||Uvt.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function pG(e){let t=e.length;for(;t--;){const n=e[t];if(Tn(n,"Missing node"),Wvt(n))return n}return null}function gG(e){return e&&Number(getComputedStyle(e).zIndex)||0}function xG(e){const t=[];for(;e;)t.push(e),e=Ege(e);return t}function Ege(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Mge=1,Rge=2,Age=4,Fge=8,Gvt=Vvt()==="coarse";let al=[],Tg=!1,ah=new Map,ZT=new Map;const L0=new Set;function Yvt(e,t,n,r,o){var s;const{ownerDocument:i}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:o},c=(s=ah.get(i))!==null&&s!==void 0?s:0;return ah.set(i,c+1),L0.add(a),qk(),function(){var d;ZT.delete(e),L0.delete(a);const f=(d=ah.get(i))!==null&&d!==void 0?d:1;if(ah.set(i,f-1),qk(),f===1&&ah.delete(i),al.includes(a)){const h=al.indexOf(a);h>=0&&al.splice(h,1),tB(),o("up",!0,null)}}}function Zvt(e){const{target:t}=e,{x:n,y:r}=YT(e);Tg=!0,eB({target:t,x:n,y:r}),qk(),al.length>0&&(Uk("down",e),e.preventDefault(),Pge(t)||e.stopImmediatePropagation())}function Y2(e){const{x:t,y:n}=YT(e);if(Tg&&e.buttons===0&&(Tg=!1,Uk("up",e)),!Tg){const{target:r}=e;eB({target:r,x:t,y:n})}Uk("move",e),tB(),al.length>0&&e.preventDefault()}function Z2(e){const{target:t}=e,{x:n,y:r}=YT(e);ZT.clear(),Tg=!1,al.length>0&&(e.preventDefault(),Pge(t)||e.stopImmediatePropagation()),Uk("up",e),eB({target:t,x:n,y:r}),tB(),qk()}function Pge(e){let t=e;for(;t;){if(t.hasAttribute(oo.resizeHandle))return!0;t=t.parentElement}return!1}function eB({target:e,x:t,y:n}){al.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),L0.forEach(o=>{const{element:s,hitAreaMargins:i}=o,a=s.getBoundingClientRect(),{bottom:c,left:u,right:d,top:f}=a,h=Gvt?i.coarse:i.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=c+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&qvt(r,s)>0){let g=r,x=!1;for(;g&&!g.contains(s);){if(Hvt(g.getBoundingClientRect(),a)){x=!0;break}g=g.parentElement}if(x)return}al.push(o)}})}function X2(e,t){ZT.set(e,t)}function tB(){let e=!1,t=!1;al.forEach(r=>{const{direction:o}=r;o==="horizontal"?e=!0:t=!0});let n=0;ZT.forEach(r=>{n|=r}),e&&t?G2("intersection",n):e?G2("horizontal",n):t?G2("vertical",n):Bvt()}let Q2=new AbortController;function qk(){Q2.abort(),Q2=new AbortController;const e={capture:!0,signal:Q2.signal};L0.size&&(Tg?(al.length>0&&ah.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("contextmenu",Z2,e),r.addEventListener("pointerleave",Y2,e),r.addEventListener("pointermove",Y2,e))}),window.addEventListener("pointerup",Z2,e),window.addEventListener("pointercancel",Z2,e)):ah.forEach((t,n)=>{const{body:r}=n;t>0&&(r.addEventListener("pointerdown",Zvt,e),r.addEventListener("pointermove",Y2,e))}))}function Uk(e,t){L0.forEach(n=>{const{setResizeHandlerState:r}=n,o=al.includes(n);r(e,o,t)})}function Xvt(){const[e,t]=v.useState(0);return v.useCallback(()=>t(n=>n+1),[])}function Tn(e,t){if(!e)throw console.error(t),Error(t)}function Mm(e,t,n=Q4){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function Kc(e,t,n=Q4){return Mm(e,t,n)===0}function Wi(e,t,n){return Mm(e,t,n)===0}function Qvt(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const o=e[r],s=t[r];if(!Wi(o,s,n))return!1}return!0}function dg({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Tn(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:o=0,collapsible:s,maxSize:i=100,minSize:a=0}=r;if(Mm(n,a)<0)if(s){const c=(o+a)/2;Mm(n,c)<0?n=o:n=a}else n=a;return n=Math.min(i,n),n=parseFloat(n.toFixed(Q4)),n}function qy({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:o,trigger:s}){if(Wi(e,0))return t;const i=[...t],[a,c]=r;Tn(a!=null,"Invalid first pivot index"),Tn(c!=null,"Invalid second pivot index");let u=0;if(s==="keyboard"){{const f=e<0?c:a,h=n[f];Tn(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:x=0}=h;if(g){const b=t[f];if(Tn(b!=null,`Previous layout not found for panel index ${f}`),Wi(b,p)){const y=x-b;Mm(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:c,h=n[f];Tn(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:x=0}=h;if(g){const b=t[f];if(Tn(b!=null,`Previous layout not found for panel index ${f}`),Wi(b,x)){const y=b-p;Mm(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let h=e<0?c:a,p=0;for(;;){const x=t[h];Tn(x!=null,`Previous layout not found for panel index ${h}`);const y=dg({panelConstraints:n,panelIndex:h,size:100})-x;if(p+=y,h+=f,h<0||h>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-g:g}{let h=e<0?a:c;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(u),g=t[h];Tn(g!=null,`Previous layout not found for panel index ${h}`);const x=g-p,b=dg({panelConstraints:n,panelIndex:h,size:x});if(!Wi(g,b)&&(u+=g-b,i[h]=b,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(Qvt(o,i))return o;{const f=e<0?c:a,h=t[f];Tn(h!=null,`Previous layout not found for panel index ${f}`);const p=h+u,g=dg({panelConstraints:n,panelIndex:f,size:p});if(i[f]=g,!Wi(g,p)){let x=p-g,y=e<0?c:a;for(;y>=0&&y<n.length;){const C=i[y];Tn(C!=null,`Previous layout not found for panel index ${y}`);const w=C+x,N=dg({panelConstraints:n,panelIndex:y,size:w});if(Wi(C,N)||(x-=N-C,i[y]=N),Wi(x,0))break;e>0?y--:y++}}}const d=i.reduce((f,h)=>h+f,0);return Wi(d,100)?i:o}function Jvt({layout:e,panelsArray:t,pivotIndices:n}){let r=0,o=100,s=0,i=0;const a=n[0];Tn(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:p}=f,{maxSize:g=100,minSize:x=0}=p;h===a?(r=x,o=g):(s+=x,i+=g)});const c=Math.min(o,100-s),u=Math.max(r,100-i),d=e[a];return{valueMax:c,valueMin:u,valueNow:d}}function $0(e,t=document){return Array.from(t.querySelectorAll(`[${oo.resizeHandleId}][data-panel-group-id="${e}"]`))}function Oge(e,t,n=document){const o=$0(e,n).findIndex(s=>s.getAttribute(oo.resizeHandleId)===t);return o??null}function Lge(e,t,n){const r=Oge(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function $ge(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function XT(e,t=document){const n=t.querySelector(`[${oo.resizeHandleId}="${e}"]`);return n||null}function e0t(e,t,n,r=document){var o,s,i,a;const c=XT(t,r),u=$0(e,r),d=c?u.indexOf(c):-1,f=(o=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&o!==void 0?o:null,h=(i=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&i!==void 0?i:null;return[f,h]}function t0t({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:o,panelGroupElement:s,setLayout:i}){v.useRef({didWarnAboutMissingResizeHandle:!1}),Zh(()=>{if(!s)return;const a=$0(n,s);for(let c=0;c<o.length-1;c++){const{valueMax:u,valueMin:d,valueNow:f}=Jvt({layout:r,panelsArray:o,pivotIndices:[c,c+1]}),h=a[c];if(h!=null){const p=o[c];Tn(p,`No panel data found for index "${c}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((c,u)=>{c.removeAttribute("aria-controls"),c.removeAttribute("aria-valuemax"),c.removeAttribute("aria-valuemin"),c.removeAttribute("aria-valuenow")})}},[n,r,o,s]),v.useEffect(()=>{if(!s)return;const a=t.current;Tn(a,"Eager values not found");const{panelDataArray:c}=a,u=$ge(n,s);Tn(u!=null,`No group found for id "${n}"`);const d=$0(n,s);Tn(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute(oo.resizeHandleId);Tn(p,"Resize handle element has no handle id attribute");const[g,x]=e0t(n,p,c,s);if(g==null||x==null)return()=>{};const b=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const C=c.findIndex(w=>w.id===g);if(C>=0){const w=c[C];Tn(w,`No panel data found for index ${C}`);const N=r[C],{collapsedSize:S=0,collapsible:j,minSize:k=0}=w.constraints;if(N!=null&&j){const _=qy({delta:Wi(N,S)?k-S:S-N,initialLayout:r,panelConstraints:c.map(T=>T.constraints),pivotIndices:Lge(n,p,s),prevLayout:r,trigger:"keyboard"});r!==_&&i(_)}}break}}};return h.addEventListener("keydown",b),()=>{h.removeEventListener("keydown",b)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,o,i])}function bG(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function zge(e,t){const n=e==="horizontal",{x:r,y:o}=YT(t);return n?r:o}function n0t(e,t,n,r,o){const s=n==="horizontal",i=XT(t,o);Tn(i,`No resize handle element found for id "${t}"`);const a=i.getAttribute(oo.groupId);Tn(a,"Resize handle element has no group id attribute");let{initialCursorPosition:c}=r;const u=zge(n,e),d=$ge(a,o);Tn(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(u-c)/h*100}function r0t(e,t,n,r,o,s){if(_ge(e)){const i=n==="horizontal";let a=0;e.shiftKey?a=100:o!=null?a=o:a=10;let c=0;switch(e.key){case"ArrowDown":c=i?0:a;break;case"ArrowLeft":c=i?-a:0;break;case"ArrowRight":c=i?a:0;break;case"ArrowUp":c=i?0:-a;break;case"End":c=100;break;case"Home":c=-100;break}return c}else return r==null?0:n0t(e,t,n,r,s)}function o0t({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,o=100;for(let s=0;s<e.length;s++){const i=n[s];Tn(i,`Panel constraints not found for index ${s}`);const{defaultSize:a}=i;a!=null&&(r++,t[s]=a,o-=a)}for(let s=0;s<e.length;s++){const i=n[s];Tn(i,`Panel constraints not found for index ${s}`);const{defaultSize:a}=i;if(a!=null)continue;const c=e.length-r,u=o/c;r++,t[s]=u,o-=u}return t}function Fp(e,t,n){t.forEach((r,o)=>{const s=e[o];Tn(s,`Panel data not found for index ${o}`);const{callbacks:i,constraints:a,id:c}=s,{collapsedSize:u=0,collapsible:d}=a,f=n[c];if(f==null||r!==f){n[c]=r;const{onCollapse:h,onExpand:p,onResize:g}=i;g&&g(r,f),d&&(h||p)&&(p&&(f==null||Kc(f,u))&&!Kc(r,u)&&p(),h&&(f==null||!Kc(f,u))&&Kc(r,u)&&h())}})}function N1(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function s0t({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:o,precision:s=3}){const i=n[o];let a;return i==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=i.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function i0t(e,t=10){let n=null;return(...o)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...o)},t)}}function yG(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function Bge(e){return`react-resizable-panels:${e}`}function Vge(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:o,order:s}=t;return o?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function Hge(e,t){try{const n=Bge(e),r=t.getItem(n);if(r){const o=JSON.parse(r);if(typeof o=="object"&&o!=null)return o}}catch{}return null}function a0t(e,t,n){var r,o;const s=(r=Hge(e,n))!==null&&r!==void 0?r:{},i=Vge(t);return(o=s[i])!==null&&o!==void 0?o:null}function l0t(e,t,n,r,o){var s;const i=Bge(e),a=Vge(t),c=(s=Hge(e,o))!==null&&s!==void 0?s:{};c[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{o.setItem(i,JSON.stringify(c))}catch(u){console.error(u)}}function vG({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,i)=>s+i,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Wi(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=100/r*i;n[s]=a}let o=0;for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=dg({panelConstraints:t,panelIndex:s,size:i});i!=a&&(o+=i-a,n[s]=a)}if(!Wi(o,0))for(let s=0;s<t.length;s++){const i=n[s];Tn(i!=null,`No layout data found for index ${s}`);const a=i+o,c=dg({panelConstraints:t,panelIndex:s,size:a});if(i!==c&&(o-=c-i,n[s]=c,Wi(o,0)))break}return n}const c0t=100,Uy={getItem:e=>(yG(Uy),Uy.getItem(e)),setItem:(e,t)=>{yG(Uy),Uy.setItem(e,t)}},wG={};function qge({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:o,id:s=null,onLayout:i=null,keyboardResizeBy:a=null,storage:c=Uy,style:u,tagName:d="div",...f}){const h=J4(s),p=v.useRef(null),[g,x]=v.useState(null),[b,y]=v.useState([]),C=Xvt(),w=v.useRef({}),N=v.useRef(new Map),S=v.useRef(0),j=v.useRef({autoSaveId:e,direction:r,dragState:g,id:h,keyboardResizeBy:a,onLayout:i,storage:c}),k=v.useRef({layout:b,panelDataArray:[],panelDataArrayChanged:!1});v.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),v.useImperativeHandle(o,()=>({getId:()=>j.current.id,getLayout:()=>{const{layout:P}=k.current;return P},setLayout:P=>{const{onLayout:U}=j.current,{layout:H,panelDataArray:G}=k.current,q=vG({layout:P,panelConstraints:G.map(Y=>Y.constraints)});bG(H,q)||(y(q),k.current.layout=q,U&&U(q),Fp(G,q,w.current))}}),[]),Zh(()=>{j.current.autoSaveId=e,j.current.direction=r,j.current.dragState=g,j.current.id=h,j.current.onLayout=i,j.current.storage=c}),t0t({committedValuesRef:j,eagerValuesRef:k,groupId:h,layout:b,panelDataArray:k.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),v.useEffect(()=>{const{panelDataArray:P}=k.current;if(e){if(b.length===0||b.length!==P.length)return;let U=wG[e];U==null&&(U=i0t(l0t,c0t),wG[e]=U);const H=[...P],G=new Map(N.current);U(e,H,G,b,c)}},[e,b,c]),v.useEffect(()=>{});const _=v.useCallback(P=>{const{onLayout:U}=j.current,{layout:H,panelDataArray:G}=k.current;if(P.constraints.collapsible){const q=G.map(Z=>Z.constraints),{collapsedSize:Y=0,panelSize:W,pivotIndices:ne}=qf(G,P,H);if(Tn(W!=null,`Panel size not found for panel "${P.id}"`),!Kc(W,Y)){N.current.set(P.id,W);const K=Wp(G,P)===G.length-1?W-Y:Y-W,X=qy({delta:K,initialLayout:H,panelConstraints:q,pivotIndices:ne,prevLayout:H,trigger:"imperative-api"});N1(H,X)||(y(X),k.current.layout=X,U&&U(X),Fp(G,X,w.current))}}},[]),T=v.useCallback((P,U)=>{const{onLayout:H}=j.current,{layout:G,panelDataArray:q}=k.current;if(P.constraints.collapsible){const Y=q.map(J=>J.constraints),{collapsedSize:W=0,panelSize:ne=0,minSize:Z=0,pivotIndices:K}=qf(q,P,G),X=U??Z;if(Kc(ne,W)){const J=N.current.get(P.id),re=J!=null&&J>=X?J:X,Q=Wp(q,P)===q.length-1?ne-re:re-ne,se=qy({delta:Q,initialLayout:G,panelConstraints:Y,pivotIndices:K,prevLayout:G,trigger:"imperative-api"});N1(G,se)||(y(se),k.current.layout=se,H&&H(se),Fp(q,se,w.current))}}},[]),I=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{panelSize:G}=qf(H,P,U);return Tn(G!=null,`Panel size not found for panel "${P.id}"`),G},[]),D=v.useCallback((P,U)=>{const{panelDataArray:H}=k.current,G=Wp(H,P);return s0t({defaultSize:U,dragState:g,layout:b,panelData:H,panelIndex:G})},[g,b]),E=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{collapsedSize:G=0,collapsible:q,panelSize:Y}=qf(H,P,U);return Tn(Y!=null,`Panel size not found for panel "${P.id}"`),q===!0&&Kc(Y,G)},[]),R=v.useCallback(P=>{const{layout:U,panelDataArray:H}=k.current,{collapsedSize:G=0,collapsible:q,panelSize:Y}=qf(H,P,U);return Tn(Y!=null,`Panel size not found for panel "${P.id}"`),!q||Mm(Y,G)>0},[]),F=v.useCallback(P=>{const{panelDataArray:U}=k.current;U.push(P),U.sort((H,G)=>{const q=H.order,Y=G.order;return q==null&&Y==null?0:q==null?-1:Y==null?1:q-Y}),k.current.panelDataArrayChanged=!0,C()},[C]);Zh(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:P,onLayout:U,storage:H}=j.current,{layout:G,panelDataArray:q}=k.current;let Y=null;if(P){const ne=a0t(P,q,H);ne&&(N.current=new Map(Object.entries(ne.expandToSizes)),Y=ne.layout)}Y==null&&(Y=o0t({panelDataArray:q}));const W=vG({layout:Y,panelConstraints:q.map(ne=>ne.constraints)});bG(G,W)||(y(W),k.current.layout=W,U&&U(W),Fp(q,W,w.current))}}),Zh(()=>{const P=k.current;return()=>{P.layout=[]}},[]);const M=v.useCallback(P=>{let U=!1;const H=p.current;return H&&window.getComputedStyle(H,null).getPropertyValue("direction")==="rtl"&&(U=!0),function(q){q.preventDefault();const Y=p.current;if(!Y)return()=>null;const{direction:W,dragState:ne,id:Z,keyboardResizeBy:K,onLayout:X}=j.current,{layout:J,panelDataArray:re}=k.current,{initialLayout:te}=ne??{},Q=Lge(Z,P,Y);let se=r0t(q,P,W,ne,K,Y);const oe=W==="horizontal";oe&&U&&(se=-se);const fe=re.map(Ie=>Ie.constraints),pe=qy({delta:se,initialLayout:te??J,panelConstraints:fe,pivotIndices:Q,prevLayout:J,trigger:_ge(q)?"keyboard":"mouse-or-touch"}),xe=!N1(J,pe);(Tge(q)||Dge(q))&&S.current!=se&&(S.current=se,!xe&&se!==0?oe?X2(P,se<0?Mge:Rge):X2(P,se<0?Age:Fge):X2(P,0)),xe&&(y(pe),k.current.layout=pe,X&&X(pe),Fp(re,pe,w.current))}},[]),O=v.useCallback((P,U)=>{const{onLayout:H}=j.current,{layout:G,panelDataArray:q}=k.current,Y=q.map(J=>J.constraints),{panelSize:W,pivotIndices:ne}=qf(q,P,G);Tn(W!=null,`Panel size not found for panel "${P.id}"`);const K=Wp(q,P)===q.length-1?W-U:U-W,X=qy({delta:K,initialLayout:G,panelConstraints:Y,pivotIndices:ne,prevLayout:G,trigger:"imperative-api"});N1(G,X)||(y(X),k.current.layout=X,H&&H(X),Fp(q,X,w.current))},[]),z=v.useCallback((P,U)=>{const{layout:H,panelDataArray:G}=k.current,{collapsedSize:q=0,collapsible:Y}=U,{collapsedSize:W=0,collapsible:ne,maxSize:Z=100,minSize:K=0}=P.constraints,{panelSize:X}=qf(G,P,H);X!=null&&(Y&&ne&&Kc(X,q)?Kc(q,W)||O(P,W):X<K?O(P,K):X>Z&&O(P,Z))},[O]),L=v.useCallback((P,U)=>{const{direction:H}=j.current,{layout:G}=k.current;if(!p.current)return;const q=XT(P,p.current);Tn(q,`Drag handle element not found for id "${P}"`);const Y=zge(H,U);x({dragHandleId:P,dragHandleRect:q.getBoundingClientRect(),initialCursorPosition:Y,initialLayout:G})},[]),V=v.useCallback(()=>{x(null)},[]),A=v.useCallback(P=>{const{panelDataArray:U}=k.current,H=Wp(U,P);H>=0&&(U.splice(H,1),delete w.current[P.id],k.current.panelDataArrayChanged=!0,C())},[C]),B=v.useMemo(()=>({collapsePanel:_,direction:r,dragState:g,expandPanel:T,getPanelSize:I,getPanelStyle:D,groupId:h,isPanelCollapsed:E,isPanelExpanded:R,reevaluatePanelConstraints:z,registerPanel:F,registerResizeHandle:M,resizePanel:O,startDragging:L,stopDragging:V,unregisterPanel:A,panelGroupElement:p.current}),[_,g,r,T,I,D,h,E,R,z,F,M,O,L,V,A]),$={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return v.createElement(GT.Provider,{value:B},v.createElement(d,{...f,children:t,className:n,id:s,ref:p,style:{...$,...u},[oo.group]:"",[oo.groupDirection]:r,[oo.groupId]:h}))}const Uge=v.forwardRef((e,t)=>v.createElement(qge,{...e,forwardedRef:t}));qge.displayName="PanelGroup";Uge.displayName="forwardRef(PanelGroup)";function Wp(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function qf(e,t,n){const r=Wp(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],i=n[r];return{...t.constraints,panelSize:i,pivotIndices:s}}function u0t({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){v.useEffect(()=>{if(e||n==null||r==null)return;const o=XT(t,r);if(o==null)return;const s=i=>{if(!i.defaultPrevented)switch(i.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{i.preventDefault(),n(i);break}case"F6":{i.preventDefault();const a=o.getAttribute(oo.groupId);Tn(a,`No group element found for id "${a}"`);const c=$0(a,r),u=Oge(a,t,r);Tn(u!==null,`No resize element found for id "${t}"`);const d=i.shiftKey?u>0?u-1:c.length-1:u+1<c.length?u+1:0;c[d].focus();break}}};return o.addEventListener("keydown",s),()=>{o.removeEventListener("keydown",s)}},[r,e,t,n])}function QT({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:o,onBlur:s,onClick:i,onDragging:a,onFocus:c,onPointerDown:u,onPointerUp:d,style:f={},tabIndex:h=0,tagName:p="div",...g}){var x,b;const y=v.useRef(null),C=v.useRef({onClick:i,onDragging:a,onPointerDown:u,onPointerUp:d});v.useEffect(()=>{C.current.onClick=i,C.current.onDragging=a,C.current.onPointerDown=u,C.current.onPointerUp=d});const w=v.useContext(GT);if(w===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:N,groupId:S,registerResizeHandle:j,startDragging:k,stopDragging:_,panelGroupElement:T}=w,I=J4(o),[D,E]=v.useState("inactive"),[R,F]=v.useState(!1),[M,O]=v.useState(null),z=v.useRef({state:D});Zh(()=>{z.current.state=D}),v.useEffect(()=>{if(n)O(null);else{const B=j(I);O(()=>B)}},[n,I,j]);const L=(x=r==null?void 0:r.coarse)!==null&&x!==void 0?x:15,V=(b=r==null?void 0:r.fine)!==null&&b!==void 0?b:5;v.useEffect(()=>{if(n||M==null)return;const B=y.current;Tn(B,"Element ref not attached");let $=!1;return Yvt(I,B,N,{coarse:L,fine:V},(U,H,G)=>{if(!H){E("inactive");return}switch(U){case"down":{E("drag"),$=!1,Tn(G,'Expected event to be defined for "down" action'),k(I,G);const{onDragging:q,onPointerDown:Y}=C.current;q==null||q(!0),Y==null||Y();break}case"move":{const{state:q}=z.current;$=!0,q!=="drag"&&E("hover"),Tn(G,'Expected event to be defined for "move" action'),M(G);break}case"up":{E("hover"),_();const{onClick:q,onDragging:Y,onPointerUp:W}=C.current;Y==null||Y(!1),W==null||W(),$||q==null||q();break}}})},[L,N,n,V,j,I,M,k,_]),u0t({disabled:n,handleId:I,resizeHandler:M,panelGroupElement:T});const A={touchAction:"none",userSelect:"none"};return v.createElement(p,{...g,children:e,className:t,id:o,onBlur:()=>{F(!1),s==null||s()},onFocus:()=>{F(!0),c==null||c()},ref:y,role:"separator",style:{...A,...f},tabIndex:h,[oo.groupDirection]:N,[oo.groupId]:S,[oo.resizeHandle]:"",[oo.resizeHandleActive]:D==="drag"?"pointer":R?"keyboard":void 0,[oo.resizeHandleEnabled]:!n,[oo.resizeHandleId]:I,[oo.resizeHandleState]:D})}QT.displayName="PanelResizeHandle";const Kge=({className:e,...t})=>l.jsx(Uge,{className:m.cn("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),pO=Ige,d0t=({withHandle:e,className:t,...n})=>l.jsx(QT,{className:m.cn("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&l.jsx("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:l.jsx(Iu,{className:"h-2.5 w-2.5"})})}),f0t=({withHandle:e,className:t,onTabClick:n,open:r,...o})=>l.jsx(QT,{className:m.cn("relative flex w-px items-start justify-end bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",{"justify-start":r},t),...o,children:e&&!1});function h0t(e={}){const{initialPosition:t="bottom-right"}=e,[n,r]=v.useState(t),[o,s]=v.useState(!1),[i,a]=v.useState(null),c=v.useRef(null),u=v.useRef(!1),d=v.useRef(null);v.useEffect(()=>()=>{d.current&&(d.current(),d.current=null)},[]);const f=v.useCallback(g=>{const x="touches"in g?g.touches[0].clientX:g.clientX,b="touches"in g?g.touches[0].clientY:g.clientY;c.current={x,y:b},u.current=!1,a({x,y:b});const y=(k,_,T)=>{if(!c.current)return;const I=Math.abs(k-c.current.x),D=Math.abs(_-c.current.y);(I>10||D>10)&&(u.current?T.cancelable&&T.preventDefault():(T.cancelable&&T.preventDefault(),u.current=!0,s(!0))),a({x:k,y:_})},C={passive:!1},w=k=>{y(k.clientX,k.clientY,k)},N=k=>{if(k.touches.length===0)return;const _=k.touches[0];y(_.clientX,_.clientY,k)},S=()=>{document.removeEventListener("mousemove",w),document.removeEventListener("mouseup",j),document.removeEventListener("touchmove",N),document.removeEventListener("touchend",j),d.current=null},j=()=>{a(k=>{if(u.current&&k){const _=window.innerWidth,T=window.innerHeight,I=k.x<_/2,D=k.y<T/2;r(D&&I?"top-left":D&&!I?"top-right":!D&&I?"bottom-left":"bottom-right")}return null}),c.current=null,setTimeout(()=>{u.current=!1,s(!1)},100),S()};document.addEventListener("mousemove",w),document.addEventListener("mouseup",j),document.addEventListener("touchmove",N,C),document.addEventListener("touchend",j),d.current=S},[]),h=v.useCallback(()=>{if(o&&i)return{position:"fixed",left:0,top:0,right:"auto",bottom:"auto",transform:`translate(${i.x-24}px, ${i.y-24}px)`,transition:"none",willChange:"transform"}},[o,i]),p=v.useCallback(()=>({horizontal:n.includes("left")?"left-6":"right-6",vertical:n.includes("top")?"top-6":"bottom-6"}),[n]);return{position:n,isDragging:o,dragPosition:i,handleDragStart:f,isDraggingRef:u,getStyle:h,getPositionClasses:p}}function m0t({open:e,setOpen:t}){const n=m.useDashboardStore(s=>s.selectedSheetId),{deleteSheet:r}=m.useDashboardActions();function o(){n&&(r(n),t(!1))}return l.jsx(ff,{open:e,onOpenChange:t,children:l.jsxs(Tu,{children:[l.jsxs(Du,{children:[l.jsx(Mu,{children:"Delete Sheet"}),l.jsx(Ru,{children:"Are you sure you want to delete this sheet along with all its cards? This action cannot be undone."})]}),l.jsxs(Eu,{children:[l.jsx(Fu,{children:"Cancel"}),l.jsx(Au,{className:"bg-destructive hover:bg-destructive/90",onClick:o,children:"Delete"})]})]})})}function Wge({placeholders:e,onClick:t}){return l.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:e==null?void 0:e.map(n=>l.jsxs("button",{type:"button",onClick:()=>t(n),className:"flex cursor-pointer flex-col items-start gap-1 rounded-control border border-border/60 bg-muted/30 px-2.5 py-2 text-left transition-colors hover:border-border hover:bg-muted/50",children:[l.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:n.title}),l.jsx("span",{className:"text-[12px] leading-[1.45] text-foreground/80",children:n.subtitle})]},n.title))})}var Gge="vercel.ai.error",p0t=Symbol.for(Gge),Yge,g0t=class Zge extends Error{constructor({name:t,message:n,cause:r}){super(n),this[Yge]=!0,this.name=t,this.cause=r}static isInstance(t){return Zge.hasMarker(t,Gge)}static hasMarker(t,n){const r=Symbol.for(n);return t!=null&&typeof t=="object"&&r in t&&typeof t[r]=="boolean"&&t[r]===!0}};Yge=p0t;var rf=g0t;function Xge(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var Qge="AI_InvalidArgumentError",Jge=`vercel.ai.error.${Qge}`,x0t=Symbol.for(Jge),exe,b0t=class extends rf{constructor({message:e,cause:t,argument:n}){super({name:Qge,message:e,cause:t}),this[exe]=!0,this.argument=n}static isInstance(e){return rf.hasMarker(e,Jge)}};exe=x0t;var txe="AI_JSONParseError",nxe=`vercel.ai.error.${txe}`,y0t=Symbol.for(nxe),rxe,CG=class extends rf{constructor({text:e,cause:t}){super({name:txe,message:`JSON parsing failed: Text: ${e}.
1366
1366
  Error message: ${Xge(t)}`,cause:t}),this[rxe]=!0,this.text=e}static isInstance(e){return rf.hasMarker(e,nxe)}};rxe=y0t;var oxe="AI_TypeValidationError",sxe=`vercel.ai.error.${oxe}`,v0t=Symbol.for(sxe),ixe,w0t=class gO extends rf{constructor({value:t,cause:n}){super({name:oxe,message:`Type validation failed: Value: ${JSON.stringify(t)}.
1367
1367
  Error message: ${Xge(n)}`,cause:n}),this[ixe]=!0,this.value=t}static isInstance(t){return rf.hasMarker(t,sxe)}static wrap({value:t,cause:n}){return gO.isInstance(n)&&n.value===t?n:new gO({value:t,cause:n})}};ixe=v0t;var Kk=w0t;class SG extends Error{constructor(t,n){super(t),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function J2(e){}function C0t(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:t=J2,onError:n=J2,onRetry:r=J2,onComment:o}=e;let s="",i=!0,a,c="",u="";function d(x){const b=i?x.replace(/^\xEF\xBB\xBF/,""):x,[y,C]=S0t(`${s}${b}`);for(const w of y)f(w);s=C,i=!1}function f(x){if(x===""){p();return}if(x.startsWith(":")){o&&o(x.slice(x.startsWith(": ")?2:1));return}const b=x.indexOf(":");if(b!==-1){const y=x.slice(0,b),C=x[b+1]===" "?2:1,w=x.slice(b+C);h(y,w,x);return}h(x,"",x)}function h(x,b,y){switch(x){case"event":u=b;break;case"data":c=`${c}${b}
1368
1368
  `;break;case"id":a=b.includes("\0")?void 0:b;break;case"retry":/^\d+$/.test(b)?r(parseInt(b,10)):n(new SG(`Invalid \`retry\` value: "${b}"`,{type:"invalid-retry",value:b,line:y}));break;default:n(new SG(`Unknown field "${x.length>20?`${x.slice(0,20)}…`:x}"`,{type:"unknown-field",field:x,value:b,line:y}));break}}function p(){c.length>0&&t({id:a,event:u||void 0,data:c.endsWith(`
@@ -1414,4 +1414,4 @@ Defaulting to \`null\`.`}var Ibe=Sbe,qjt=jbe;const gB=ie.forwardRef(({className:
1414
1414
  More info: ${o.docs}`:"",a=typeof o.message=="string"&&o.message.trim()?o.message.trim():typeof o.error=="string"&&o.error.trim()?o.error.trim():null;if(a){const c=s?` (code: ${s})`:"",u=s==="insufficient_quota"||a.toLowerCase().includes("quota")?`
1415
1415
 
1416
1416
  Semaphor supports bring-your-own OpenAI API keys. Add yours in Settings or drop a note to support@semaphor.cloud and we’ll help you get set up.`:"";return`${a}${c}${i}${u}`}return null};if(typeof e=="string"){const r=e.trim();if(!r)return"Something went wrong.";try{const o=JSON.parse(r),s=t(o);if(s)return s}catch{}return r}const n=t(e);if(n)return n;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function TB({errorMessage:e}){return l.jsxs("div",{className:"flex items-start gap-2 rounded-control border border-red-300 bg-red-50/60 p-2 text-[12px] text-red-700 dark:border-red-900/60 dark:bg-red-950/20 dark:text-red-300",children:[l.jsx(Br,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),l.jsx("span",{className:"whitespace-pre-wrap break-words leading-[1.55]",children:RIt(e)})]})}function AIt({error:e,resetErrorBoundary:t}){return l.jsxs("div",{className:"my-3 space-y-2 rounded-control border border-border/60 bg-muted/20 p-2.5",children:[l.jsx(TB,{errorMessage:e==null?void 0:e.message}),l.jsx("button",{type:"button",className:"text-[11px] font-medium text-muted-foreground underline underline-offset-2 hover:text-foreground",onClick:t,children:"Try again"})]})}function FIt({text:e,files:t}){return l.jsxs(iye,{who:"You",children:[e&&l.jsx("div",{className:"whitespace-pre-line text-[13px] leading-[1.55] text-foreground",children:e}),t&&t.length>0&&l.jsx("div",{className:"flex flex-wrap gap-2 pt-0.5",children:t.map(n=>l.jsx(Kjt,{file:n},n.id))})]})}function PIt({text:e}){const t=e.split("|"),n=t[0],r=t[1]||"{}",o=JSON.parse(r);return l.jsxs("div",{className:"space-y-1 text-xs",children:[l.jsxs("div",{children:[l.jsx("span",{className:"font-bold",children:"System Message:"})," ",n]}),l.jsxs("div",{className:"space-y-1",children:[l.jsx("span",{className:"font-mono text-xs",children:"Scope:"}),l.jsx(Lkt,{children:JSON.stringify(o,null,2)})]})]})}function aye(e,t){return!e||e.role!=="assistant"?!1:(e.parts??[]).some(r=>{if(!r)return!1;switch(r.type){case"text":return typeof r.text=="string"&&r.text.trim().length>0;case"reasoning":return typeof r.text=="string"&&r.text.trim().length>0||r.state==="streaming";case"error":return!0;default:return typeof r.type=="string"&&(r.type.startsWith("tool-")||r.type==="dynamic-tool")?_B(r,t):!1}})}function bY(){return l.jsx("span",{className:"relative grid h-2 w-2 shrink-0 place-items-center",children:l.jsx("span",{className:"absolute inset-0 animate-pulse rounded-full bg-muted-foreground/70"})})}function OIt({status:e,errorMessage:t,activeToolText:n}){return n?l.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[l.jsx(bY,{}),l.jsx("span",{children:n})]}):e==="submitted"||e==="streaming"?l.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-muted-foreground",children:[l.jsx(bY,{}),l.jsx("span",{children:e==="submitted"?"Thinking":"Generating"})]}):e==="error"?l.jsx(TB,{errorMessage:t}):null}function LIt(e){var t;return e?(t=[...e].reverse().find(n=>{var r;return n.role==="assistant"&&((r=n.parts)==null?void 0:r.some(o=>o.type==="text"&&typeof o.text=="string"&&o.text.trim().length>0))}))==null?void 0:t.id:void 0}function $It({message:e,messageIndex:t,messages:n,showTools:r=!1,onAddToDashboard:o,showSystemMessage:s=!1,handleRun:i,onQuickReply:a,disableQuickReplies:c=!1}){var y,C,w,N;const u=LIt(n),d=e.id===u;if(e.role==="user"){const S=((y=e.parts)==null?void 0:y.filter(T=>T.type==="text"))||[],j=((C=e.parts)==null?void 0:C.filter(T=>T.type==="file"))||[],k=S.map(T=>T.text).join(`
1417
- `).trim(),_=j.map((T,I)=>{var R,F;let D="",E;if((R=T.url)!=null&&R.startsWith("data:")){const M=T.url.match(/data:[^;]+;base64,(.+)/);M&&(D=M[1],(F=T.mediaType)!=null&&F.startsWith("image/")&&(E=T.url))}return{id:`${e.id||t}-file-${I}`,name:T.filename||`File ${I+1}`,size:0,type:T.mediaType||"application/octet-stream",data:D,preview:E}});return l.jsx(FIt,{text:k||void 0,files:_.length>0?_:void 0})}const f=((w=e.parts)==null?void 0:w.filter(S=>S.type==="reasoning"))||[],h=f.length>0,p=f.some(S=>S.state==="streaming"),g=f.filter(S=>S.text&&S.text.trim().length>0),x=h&&(g.length>0||p)?l.jsxs(Nu,{className:"space-y-2",defaultOpen:!1,children:[l.jsx(ju,{asChild:!0,children:l.jsxs("button",{type:"button",className:"group inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground",children:[l.jsx(Ft.ChevronRight,{className:"h-3 w-3 transition-transform duration-200 group-data-[state=open]:rotate-90"}),l.jsx("span",{className:p?"animate-pulse":"",children:p?"Reasoning":"Show reasoning"}),g.length>1&&l.jsxs("span",{className:"font-mono tabular-nums text-muted-foreground/70",children:["(",g.length," steps)"]})]})}),l.jsx(ku,{children:l.jsx("ol",{className:"space-y-2 border-l border-border/60 pl-3",children:g.map((S,j)=>l.jsxs("li",{className:"relative",children:[l.jsx("span",{className:"absolute -left-[15px] top-[3px] grid h-4 w-4 place-items-center rounded-full bg-muted font-mono text-[9px] text-muted-foreground",children:j+1}),l.jsx(uY,{className:"text-[12px] leading-[1.55] text-muted-foreground",text:S.text})]},`${e.id||t}-reasoning-${j}`))})})]},`${e.id||t}-reasoning`):null,b=(N=e.parts)==null?void 0:N.map((S,j)=>{var _;const k=`${e.id||t}-${j}`;switch(S.type){case"text":{const T=typeof S.text=="string"?S.text:JSON.stringify(S.text??"",null,2);if(e.role==="assistant"){const{cleanedText:I,quickReplies:D}=EIt(T),E=I.trim().length>0;return l.jsxs("div",{className:"space-y-2.5",children:[E&&l.jsx(uY,{text:I,handleRun:i,onAddToDashboard:o,messageId:e.id,messages:n}),D.length>0&&a&&d&&l.jsxs("div",{className:"space-y-1.5",children:[D.length>=3&&l.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Suggested next steps"}),l.jsx("div",{className:"flex flex-wrap gap-1",children:D.map(({label:R,value:F},M)=>l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Button,{size:"sm",variant:"outline",className:"h-6 max-w-[220px] rounded-control border-border/60 bg-background px-2 text-[11px] font-normal text-foreground/85 transition-colors hover:border-border hover:bg-muted/40 hover:text-foreground disabled:opacity-50",disabled:c,onClick:()=>a(F),children:l.jsx("span",{className:"truncate",children:R})})}),l.jsx(m.TooltipContent,{side:"top",align:"center",children:l.jsx("p",{className:"max-w-xs text-xs",children:F})})]},`${k}-qr-${M}`))})]})]},k)}return e.role==="system"&&s?l.jsx(PIt,{text:T},k):null}case"error":{const T=S,I=T.errorText??T.error??T.message;return l.jsx("div",{className:"my-4",children:l.jsx(TB,{errorMessage:I})},k)}case"reasoning":return null;default:return((_=S.type)!=null&&_.startsWith("tool-")||S.type==="dynamic-tool")&&_B(S,r)?l.jsx(ui,{FallbackComponent:({error:T,resetErrorBoundary:I})=>l.jsx(AIt,{error:T,resetErrorBoundary:I}),children:l.jsx(kIt,{part:S,idx:k,messageId:e.id,showTools:r,onAddToDashboard:o,messages:n})},k):null}});return e.role==="assistant"?aye(e,r)?l.jsxs(iye,{who:"Assistant",className:"space-y-2",children:[x,b]}):null:l.jsxs("div",{className:"space-y-2",children:[x,b]})}const zIt=8,BIt=24,VIt=20;function HIt(e,t,n,r){return e==="error"&&t?!0:r?!1:!!(n||e==="submitted"||e==="streaming")}function lye({messages:e,showTools:t=!1,showSystemMessage:n=!1,handleRun:r,onAddToDashboard:o,onQuickReply:s,disableQuickReplies:i=!1,status:a,errorMessage:c,activeToolText:u,className:d,rowContentClassName:f,statusClassName:h,latestButtonClassName:p,scrollToEndSignal:g=0}){const x=v.useRef(null),b=v.useRef(null),y=v.useRef(e.length),C=v.useRef(!1),w=v.useRef(null),N=v.useRef(!1),S=v.useRef(g),[j,k]=v.useState(!0),[_,T]=v.useState(0),[I,D]=v.useState(BIt);S.current!==g&&(S.current=g,N.current=!0);const E=e[e.length-1],R=aye(E,t),F=HIt(a,c,u,R),M=mm({count:e.length,getScrollElement:()=>x.current,estimateSize:V=>{const A=e[V];return(A==null?void 0:A.role)==="user"?88:180},getItemKey:V=>{const A=e[V];return(A==null?void 0:A.id)||`message-${V}`},anchorTo:"end",followOnAppend:!0,scrollEndThreshold:zIt,overscan:6,gap:20,paddingEnd:F?I+VIt:0,useAnimationFrameWithResizeObserver:!0,onChange:V=>{const A=V.isAtEnd();k(B=>B===A?B:A),A&&T(0)}}),O=v.useCallback((V="smooth")=>{w.current!==null&&cancelAnimationFrame(w.current),w.current=requestAnimationFrame(()=>{w.current=null,M.scrollToEnd({behavior:V})}),T(0),k(!0)},[M]);v.useLayoutEffect(()=>{C.current||(C.current=!0,O("auto"))},[O]),v.useLayoutEffect(()=>{N.current&&(N.current=!1,O("auto"))},[e.length,g,O]),v.useEffect(()=>{const V=y.current;y.current=e.length,e.length>V&&!M.isAtEnd()&&T(A=>A+e.length-V),e.length===0&&(T(0),k(!0),C.current=!1,N.current=!1)},[e.length,M]);const z=M.getVirtualItems(),L=M.getTotalSize();return v.useEffect(()=>()=>{w.current!==null&&cancelAnimationFrame(w.current)},[]),v.useLayoutEffect(()=>{const V=b.current;if(!V||!F)return;const A=()=>{const $=Math.ceil(V.getBoundingClientRect().height);$>0&&D(P=>P===$?P:$)};if(A(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(A);return B.observe(V),()=>B.disconnect()},[F,a,c,u]),l.jsxs(l.Fragment,{children:[l.jsx($u,{"data-role":"assistant-virtualized-scroll-area",ref:x,className:m.cn("min-h-0 min-w-0 flex-1 basis-0",d),children:l.jsxs("div",{className:"relative w-full",style:{height:L},children:[z.map(V=>{const A=e[V.index];return A?l.jsx("div",{ref:M.measureElement,"data-index":V.index,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${V.start}px)`},children:l.jsx("div",{className:m.cn("min-w-0",f),children:l.jsx($It,{message:A,messageIndex:V.index,messages:e,showTools:t,showSystemMessage:n,handleRun:r,onAddToDashboard:o,onQuickReply:s,disableQuickReplies:i})})},V.key):null}),F&&l.jsx("div",{ref:b,className:m.cn("absolute left-0 top-0 w-full",h),style:{transform:`translateY(${Math.max(L-I,0)}px)`},children:l.jsx("div",{className:m.cn("min-w-0",f),children:l.jsx(OIt,{status:a,errorMessage:c,activeToolText:u})})})]})}),!j&&l.jsxs("button",{type:"button",onClick:()=>O("smooth"),"aria-label":"Scroll to latest",className:m.cn("absolute right-4 z-10 inline-flex h-7 items-center gap-1.5 rounded-full border border-border bg-background px-2.5 text-[11px] text-foreground shadow-[0_1px_2px_rgba(0,0,0,0.08)] transition-colors hover:bg-muted/40",p),children:[l.jsx(No,{className:"h-3 w-3"}),"Latest",_>0&&l.jsx("span",{className:"grid h-4 min-w-[16px] place-items-center rounded-full bg-foreground px-1 font-mono text-[9px] tabular-nums text-background",children:_>9?"9+":_})]})]})}function qIt(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return"";const t=e;return(typeof t.userSql=="string"?t.userSql:"")||(typeof t.sourceSql=="string"?t.sourceSql:"")||(typeof t.sql=="string"?t.sql:"")}const UIt=[{title:"Show top 3 insights",subtitle:"from this dataset"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function KIt({open:e,setOpen:t,isFullscreen:n,onFullscreenChange:r,fullscreenContainer:o}){const[s,i]=v.useState(!1),[a,c]=v.useState(lt.isDevEnv),[u,d]=v.useState(!1),[f,h]=v.useState("auto"),[p,g]=v.useState(!1),[x,b]=v.useState(!1),[y,C]=v.useState(0),w=n??x,{isLocalDev:N,isConsoleMode:S}=Vm(),j=N||S||a,k=v.useRef(null);m.useDashboardStore(me=>me.dashboard.aiScopeTables),m.useDashboardStore(me=>me.isDashboardEditing);const _=m.useDashboardStore(me=>me.selectedSheetId),{setDataSource:T}=m.useEditorActions(),{setSelectedFrameId:I,setIsDashboardEditing:D}=m.useDashboardActions(),E=Rz(),{clearAssistantMessageContexts:R}=m.useAIActions(),{clearQueue:F}=m.useQueueActions(),{clearFileAttachments:M,getFileAttachments:O}=m.useFileActions(),z=m.useFileAttachments("dashboard"),L=m.useEditorStore(me=>me.card.dataSource),{assistantProfile:V}=gbe(),A=m.useDashboardStore(me=>me.handleOpenAssistantProfile),{selectedEntities:B,applyDashboardDefaultEntities:$}=_T("dashboard"),{sendMessage:P,isLoading:U,messages:H,setMessages:G,status:q,stop:Y,errorMessage:W,clearError:ne}=jjt({dynamicVisualMode:f}),Z=v.useCallback(()=>{C(me=>me+1)},[]),K=v.useCallback(me=>{r==null||r(me),n===void 0&&b(me)},[n,r]),X=v.useCallback(()=>{K(!w)},[w,K]);v.useEffect(()=>{if(!w)return;function me(ve){ve.key==="Escape"&&K(!1)}return window.addEventListener("keydown",me),()=>{window.removeEventListener("keydown",me)}},[w,K]);const[J,re]=v.useState(""),te=me=>{re(me.target.value)};async function Q({sql:me,cardTitle:ve,connectionId:_e,cardType:De,python:Ue,cardConfig:Ne,dataSource:Oe,customVisualPreferences:ye,visualizationMode:Be,dynamicCardPreferences:he}){if(!_)return;const ue=Be==="dynamic",de=lt.hasValidCardConfig(Ne),Te=_e||(Oe==null?void 0:Oe.connectionId)||"",we=Oe?{...Oe,connectionId:Te||Oe.connectionId,connectionType:Oe.connectionType||"",mode:Oe.mode||"database",selectedEntities:Oe.selectedEntities||[]}:Te?{connectionId:Te,connectionType:"",mode:"database",selectedEntities:[]}:jx,Ke=!(de&&(!ue||(he==null?void 0:he.provenance)==="card-config"||(he==null?void 0:he.provenance)==="query_spec")),He=Ke?qIt(me):"",qe=Ke?Ue:"",Je={id:lt.v4(),title:ve||"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}],chartOptions:{indexAxis:De==="horizontalBar"?"y":"x"},...ue&&{displayOptions:{showChrome:!1,allowScroll:!1}}},type:De,sql:He,python:qe,dataSource:we,config:Ne,connectionId:Te,visualizationMode:Be,dynamicCardPreferences:he,customCardPreferences:ye?{url:ye.url,componentName:ye.componentName,pluginChartType:ye.pluginChartType,settings:ye.settings,type:"component"}:void 0},We={id:lt.v4(),cards:[Je],activeCardId:Je.id};try{await E(_,We,"end"),D(!0),I(We.id)}catch(bt){console.error("Failed to add assistant visual to dashboard:",bt),m.ue.error(bt instanceof Error?bt.message:"Failed to prepare semantic metadata for the new visual")}}const se=me=>{me.preventDefault();const ve=J.trim();if(!ve&&z.length===0)return;const _e=[];ve&&_e.push({type:"text",text:ve}),z.forEach(De=>{De.data&&_e.push({type:"file",mediaType:De.type,filename:De.name,url:`data:${De.type};base64,${De.data}`})}),P({role:"user",parts:_e}),re(""),M("dashboard"),Z()};v.useEffect(()=>{var me;e&&((me=k.current)==null||me.focus())},[e]),Hbe({assistantType:"dashboard",status:q,isLoading:U,sendMessage:P});const{hasActiveTools:oe,activeToolText:fe}=qbe(H);function pe(me){const ve={role:"user",parts:[{type:"text",text:me.title+" "+me.subtitle}]};P(ve),Z()}function xe(me){P({role:"user",parts:[{type:"text",text:me}]}),Z()}function Ie(me){P({role:"user",parts:[{type:"text",text:me}]}),Z()}const be=v.useCallback(async()=>{const me=JSON.stringify(H??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(me),m.ue.success("Conversation copied")}catch(ve){console.error("Failed to copy conversation",ve),m.ue.error("Unable to copy conversation")}},[H]),ge=(J==null?void 0:J.length)===0&&(H==null?void 0:H.filter(me=>me.role==="user").length)===0;function ee(){return l.jsx("div",{"data-role":"header",className:"flex items-center gap-2",children:l.jsx("span",{className:"text-[13px] font-medium text-foreground",children:"Assistant"})})}function ce(){return l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx(ou,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:l.jsx(Lm,{className:"size-3.5"})})}),l.jsxs(_o,{align:"end",children:[l.jsx(Zi,{children:"Options"}),l.jsx(ii,{}),l.jsx(ed,{checked:s,onCheckedChange:i,children:"Token Usage"}),l.jsx(ed,{checked:a,onCheckedChange:c,children:"Tool Invocations"}),l.jsx(ed,{checked:u,onCheckedChange:d,children:"System Message"}),(N||S)&&l.jsxs(l.Fragment,{children:[l.jsx(ii,{}),l.jsx(Zi,{children:"Dynamic Visuals"}),l.jsx(ed,{checked:f==="auto",onCheckedChange:()=>h("auto"),children:"Auto"}),l.jsx(ed,{checked:f==="force",onCheckedChange:()=>h("force"),children:"Force Dynamic"}),l.jsx(ed,{checked:f==="off",onCheckedChange:()=>h("off"),children:"Disable Dynamic"})]})]})]})}const ae=l.jsxs("div",{"data-role":"dashboard-assistant",className:m.cn("relative flex h-full grow flex-col break-words bg-background",w&&"rounded-card border border-border/60 shadow-xl"),children:[l.jsxs("header",{"data-role":"header-section",className:"flex h-10 shrink-0 items-center gap-2 border-b border-border/60 px-3",children:[ee(),A&&l.jsxs("button",{type:"button",onClick:A,className:"inline-flex h-6 items-center gap-1 rounded-[4px] border border-border/60 bg-muted/40 px-1.5 text-[11px] text-muted-foreground transition-colors hover:border-border hover:text-foreground",title:"Edit assistant profile",children:[l.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/60"}),l.jsx("span",{className:"max-w-[180px] truncate",children:(V==null?void 0:V.name)||"Default profile"})]}),l.jsxs("div",{"data-role":"header-actions",className:"ml-auto flex items-center gap-0.5",children:[S&&ce(),j&&l.jsx(m.Button,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px] text-muted-foreground hover:text-foreground",onClick:be,children:"Copy Conversation"}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:w?"Exit fullscreen":"Expand",onClick:X,children:w?l.jsx(Ft.Minimize2,{className:"h-3.5 w-3.5"}):l.jsx(Ft.Maximize2,{className:"h-3.5 w-3.5"})}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:"New chat",onClick:()=>{const me=H.filter(ve=>ve.role==="assistant").map(ve=>ve.id).filter(ve=>!!ve);G([]),F("dashboard"),ne(),R(me)},children:l.jsx(r5,{className:"h-3.5 w-3.5"})}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:"Close",onClick:()=>{t(!1)},children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})]}),l.jsx(lye,{messages:H,showTools:a,showSystemMessage:u,onAddToDashboard:Q,onQuickReply:Ie,disableQuickReplies:U,status:q,errorMessage:W,activeToolText:U&&oe?fe:void 0,className:m.cn(w?"px-6 py-5":"px-3 py-3"),rowContentClassName:m.cn(w&&"mx-auto w-full max-w-[680px]"),latestButtonClassName:e?"bottom-[148px]":"hidden",scrollToEndSignal:y}),l.jsxs("div",{className:"shrink-0 space-y-2 border-t border-border/60 px-3 pb-3 pt-2",children:[!V&&ge&&l.jsx(Wge,{onClick:pe,placeholders:UIt}),ge&&V&&l.jsx(xbe,{seedQuestions:V.seedQuestions||[],handleSeedQuestionClick:xe}),l.jsx(Vbe,{assistantType:"dashboard"}),l.jsx(IB,{ref:k,setInput:re,stop:Y,input:J,handleInputChange:te,handleSubmit:me=>{se(me)},isLoading:U,status:q,assistantType:"dashboard",onFocus:()=>{}})]}),l.jsx(vB,{incomingSelectedEntities:B,open:p,onOpenChange:g,dataSource:L||jx,dialogMode:"aiContext",saveAsDashboardDefault:!0,onSaveSelectedEntities:me=>$()})]});return w&&o?Mr.createPortal(l.jsx(gb,{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background/95 px-4 pb-4 pt-[calc(var(--app-header-height,15px)+0.5rem)] backdrop-blur-sm",children:l.jsx("div",{className:"flex h-full w-full",children:ae})}),o):ae}function WIt(e){const t=e.current,{getSelectedFrame:n,setSelectedFrameId:r}=m.useDashboardActions(),o=Ide(),s=m.useDashboardStore(d=>d.dashboard.sheets),a=m.useDashboardStore(d=>d.selectedSheetId)??(s==null?void 0:s[0].id),c=m.useDashboardStore(d=>d.isDashboardEditing),u=m.useDashboardStore(d=>d.isVisualEditing);v.useEffect(()=>{if(!c||u)return;async function d(p){if(GIt(p.target))return;const g=p.ctrlKey||p.metaKey;g&&p.key==="c"?(await f(),m.ue.success("Card copied to clipboard"),p.preventDefault()):g&&p.key==="v"&&(await h(),p.preventDefault())}async function f(){try{const p=n();p&&await navigator.clipboard.writeText(JSON.stringify(p))}catch(p){console.error("Failed to copy text:",p)}}async function h(){if(!a)return null;try{const p=await navigator.clipboard.readText(),g=YIt(p);if(g!=null&&g.id){const x=Nde(g),b=x.cards.findIndex(y=>y.id===x.activeCardId);b!==-1&&(x.cards[b].title=`${x.cards[b].title} (Copy)`),await o(a,x),r(x.id),m.ue.success("Card pasted from clipboard")}return p}catch(p){return console.error("Failed to paste text:",p),null}}return t==null||t.addEventListener("keydown",d),()=>t==null?void 0:t.removeEventListener("keydown",d)},[o,n,r,a,c,u,t])}function GIt(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.closest("[contenteditable]");return t&&t.getAttribute("contenteditable")!=="false"?!0:!!e.closest('input, textarea, select, [role="textbox"]')}function YIt(e){try{const t=JSON.parse(e);return t&&typeof t=="object"&&typeof t.id=="string"&&Array.isArray(t.cards)?t:null}catch{return null}}function ZIt(e,t){switch(e.interactionMode){case"drillToDetail":XIt(e,t);break;case"drillThrough":QIt(e,t);break;case"drillToURL":JIt(e);break;case"inlineDrill":console.warn("Inline drill execution not yet implemented");break;case"clickFilter":case"drillDown":case"dynamicDrill":break;default:console.warn("Unknown interaction mode:",e.interactionMode)}}function XIt(e,t){var c;const{targetInsightId:n,contextMode:r,displayMode:o,filterGroups:s}=e;if(!n){console.warn("drillToDetail event missing targetInsightId");return}const i=r||"full";let a=[];switch(i){case"interactionFilters":a=s.flatMap(u=>u.filters);break;case"full":{const u=((c=t.getCurrentFilters)==null?void 0:c.call(t))||[],d=s.flatMap(f=>f.filters);a=[...u,...d];break}case"none":default:a=[];break}o==="replace-card"?t.replaceCardContent({cardId:e.sourceCardId,insightId:n,filters:a,contextMode:r}):t.openInsightModal({insightId:n,filters:a,contextMode:r})}function QIt(e,t){var u,d;const{targetDashboardId:n,contextMode:r="interactionFilters",filterGroups:o,sourceCardId:s}=e;if(!n){console.warn("[DrillThrough] Event missing targetDashboardId. This interaction needs to be reconfigured with a target dashboard.",e);return}const i=o.flatMap(f=>f.filters),a=((u=t.getCurrentDashboardId)==null?void 0:u.call(t))||"",c=(d=t.getCurrentDashboardTitle)==null?void 0:d.call(t);t.setGlobalDrillContext&&t.setGlobalDrillContext({filters:i,contextMode:r,sourceDashboardId:a,sourceDashboardTitle:c,targetDashboardId:n}),t.setPendingDrillThrough&&t.setPendingDrillThrough({targetDashboardId:n,sourceDashboardId:a,sourceDashboardTitle:c,filters:i,contextMode:r})}function JIt(e){const{url:t}=e;if(!t){console.warn("drillToURL event missing url");return}try{new URL(t)}catch(n){console.error("Invalid URL:",t,n);return}window.open(t,"_blank","noopener,noreferrer")}function e_t({open:e,onOpenChange:t,insightId:n,filters:r,filterDefinitions:o,contextMode:s,cardTitle:i,cardDescription:a}){return l.jsx(To,{open:e,onOpenChange:t,children:l.jsxs(bo,{className:"flex max-h-[90vh] max-w-[90vw] flex-col gap-0 overflow-hidden p-0",children:[l.jsxs($s,{className:"space-y-1 border-b border-border px-5 pb-3.5 pt-4 text-left",children:[l.jsx(yo,{className:"text-[15px] font-semibold tracking-tight",children:i||"Insight detail"}),l.jsx(Ho,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:a||"View detailed insight data with applied filters"})]}),l.jsx(Rde,{filters:r,filterDefinitions:o,contextMode:s}),l.jsx("div",{className:"h-[400px] min-h-0 flex-1 overflow-auto px-5 py-4",children:n?l.jsx(Khe,{insightId:n,filters:r,contextMode:s}):l.jsx("div",{className:"flex items-center justify-center p-12 text-[13px] text-muted-foreground",children:"No insight selected"})})]})})}function t_t(){const e=m.useInteractionStore(N=>N.interactionStates),t=m.useInteractionStore(N=>N.setInteractionState),n=m.useInteractionStore(N=>N.clearLastInteractionEvent),r=m.useInteractionStore(N=>N.replaceCardWithInsight),o=m.useInteractionStore(N=>N.setPendingDrillThrough),s=m.useInteractionStore(N=>N.pendingDrillThrough),i=m.useInteractionStore(N=>N.clearPendingDrillThrough),{setSelectedSheetId:a,navigateWithDrill:c}=m.useDashboardActions(),{selectDashboard:u}=Pm(),d=m.useDashboardStore(N=>N.dashboard),f=m.useDashboardStore(N=>N.filterValues),{data:h,isLoading:p}=wQ((s==null?void 0:s.targetDashboardId)||"",{enabled:!!(s!=null&&s.targetDashboardId)}),[g,x]=v.useState({open:!1,insightId:""}),b=Whe(g.insightId,{enabled:g.open&&!!g.insightId}),y=v.useRef(new Set),C=v.useMemo(()=>({setSelectedSheetId:a,openInsightModal:({insightId:N,filters:S,contextMode:j})=>{x({open:!0,insightId:N,filters:S,filterDefinitions:(d==null?void 0:d.filters)||[],contextMode:j})},replaceCardContent:({cardId:N,insightId:S,filters:j,contextMode:k})=>{r(N,S,j,k)},getCurrentFilters:()=>f||[],navigateWithDrill:c,getCurrentDashboardId:()=>(d==null?void 0:d.id)||"",getCurrentDashboardTitle:()=>d==null?void 0:d.title,setPendingDrillThrough:o,setGlobalDrillContext:({filters:N,contextMode:S,sourceDashboardId:j,sourceDashboardTitle:k,targetDashboardId:_})=>{const T={filters:N},I={sourceCardId:m.DRILL_CONTEXT_CARD_ID,interactionMode:"clickFilter",filterGroups:[T]},D={...m.createInitialInteractionState(),appliedClickFilters:[I],contextMode:S,sourceDashboardId:j,sourceDashboardTitle:k,targetDashboardId:_};t(m.DRILL_CONTEXT_CARD_ID,D)}}),[a,r,f,c,d,o,t]);v.useEffect(()=>{Object.entries(e).forEach(([N,S])=>{if(S!=null&&S.lastInteractionEvent){const j=S.lastInteractionEvent,k=`${N}-${j.interactionMode}-${j.sourceCardId}-${Date.now()}`;if(y.current.has(k))return;y.current.add(k);try{ZIt(j,C)}catch(_){console.error("Error executing interaction event:",_)}finally{n(N),setTimeout(()=>{y.current.delete(k)},5e3)}}})},[e,n,C]),v.useEffect(()=>{if(!(!s||!h||p))try{u(h),c(s.targetDashboardId,s.sourceDashboardId,s.sourceDashboardTitle,s.filters,s.contextMode),i()}catch(N){console.error("[DrillThrough] Error during automatic navigation:",N),i()}},[s,h,p,u,c,i]);const w=()=>{x({open:!1,insightId:""})};return l.jsxs(l.Fragment,{children:[l.jsx(e_t,{open:g.open,onOpenChange:w,insightId:g.insightId,filters:g.filters,filterDefinitions:g.filterDefinitions,contextMode:g.contextMode,cardTitle:b.title,cardDescription:b.description}),s&&p&&l.jsx("div",{className:"fixed inset-0 z-[51] flex items-center justify-center bg-background/80 backdrop-blur-sm",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-[6px] border border-border/60 bg-background px-4 py-3 shadow-sm",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("div",{className:"text-[12px] text-muted-foreground",children:"Loading dashboard..."})]})})]})}function n_t(e){return e.length===0?"":e.map(t=>{const n=t.field.label||t.field.name,r=t.operator,o=r_t(Fz(t));return r==="="?`${n} = ${o}`:`${n} ${r} ${o}`}).join(", ")}function r_t(e){return e==null?"null":Array.isArray(e)?e.join(", "):typeof e=="object"&&e.toString?e.toString():String(e)}function o_t(e){return e?`Back to ${e}`:"Back"}function s_t(){var y,C,w,N,S;const e=m.useInteractionStore(j=>j.interactionStates[m.DRILL_CONTEXT_CARD_ID]),t=m.useDashboardStore(j=>j.actions.goBackFromDrill),n=m.useDashboardStore(j=>j.actions.clearDrillContext),{selectDashboard:r}=Pm(),[o,s]=v.useState({x:16,y:16}),[i,a]=v.useState(!1),c=v.useRef({x:0,y:0});v.useEffect(()=>{if(!i)return;const j=_=>{s({x:_.clientX-c.current.x,y:_.clientY-c.current.y})},k=()=>{a(!1)};return document.addEventListener("mousemove",j),document.addEventListener("mouseup",k),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",k)}},[i]);const u=e==null?void 0:e.sourceDashboardId,d=e==null?void 0:e.sourceDashboardTitle,f=((N=(w=(C=(y=e==null?void 0:e.appliedClickFilters)==null?void 0:y[0])==null?void 0:C.filterGroups)==null?void 0:w[0])==null?void 0:N.filters)||[],h=u?{id:u,title:d||"Previous Dashboard",description:"",isPrivate:!1,isPublic:!1,version:"",createdBy:null,createdByTenantUser:"",tenantId:"",projectId:"",createdAt:"",updatedAt:"",lastModified:"",lastModifiedBy:"",createdByUser:null,createdByTenantUserRel:{name:"",email:""},permissions:{canEdit:!0,canShare:!0,canDelete:!0},ownership:{status:"private",isOwner:!0,sharedCount:0,createdBy:{type:"user",userId:"",name:"",email:""}}}:null;if(!e||!((S=e.appliedClickFilters)!=null&&S.length))return null;const p=()=>{if(!h){console.warn("[DrillBack] No source dashboard in context");return}try{t(),r(h)}catch(j){console.error("[DrillBack] Error during back navigation:",j)}},g=()=>{n()},x=j=>{j.target.closest("button")||(a(!0),c.current={x:j.clientX-o.x,y:j.clientY-o.y})};n_t(f);const b=o_t(d);return l.jsx("div",{className:"fixed z-50 max-w-md",style:{left:0,top:0,transform:`translate(${o.x}px, ${o.y}px)`,transition:i?"none":void 0},children:l.jsxs("div",{className:"select-none rounded-lg border bg-background/95 p-3 shadow-lg backdrop-blur-sm",onMouseDown:x,style:{cursor:i?"grabbing":"grab"},children:[l.jsxs("div",{className:"mb-3 flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Viewing:"}),l.jsx("div",{className:"flex flex-wrap gap-2",children:f.map((j,k)=>{const _=j.field.label||j.field.name,T=String(j.value);return l.jsxs(ki,{variant:"secondary",className:"pointer-events-none text-xs",children:[_," = ",T]},k)})})]}),l.jsx(m.Button,{variant:"ghost",size:"sm",onClick:g,className:"h-6 w-6 cursor-pointer p-0",title:"Clear drill context",children:l.jsx(Re.X,{className:"h-3 w-3"})})]}),l.jsx("div",{className:"flex items-center gap-2 border-t pt-2",children:l.jsxs(m.Button,{variant:"secondary",size:"sm",onClick:p,disabled:!h,className:"w-full cursor-pointer",children:[l.jsx(ow,{className:"mr-2 h-4 w-4"}),b]})})]})})}function i_t(e,t){return typeof e=="boolean"?e:typeof t=="boolean"?t:!1}function a_t({filter:e,isEditing:t=!1,disabled:n=!1,storageOptions:r,settingsVariant:o,inputVariableName:s,reservedInputVariableNames:i,isDashboardFilterReference:a,onUpdateFilter:c,onRemoveFilter:u}){const{attributes:d,listeners:f,setNodeRef:h,transform:p,transition:g,isDragging:x}=dp({id:`filter:${e.id}`,disabled:n||!t}),b={transform:Pi.Translate.toString(p),transition:g,opacity:x?.5:1,zIndex:x?10:void 0};return l.jsx("div",{ref:h,style:b,...d,children:l.jsx(mz,{filter:e,isEditing:t,dragListeners:t?f:void 0,storageOptions:r,settingsVariant:o,inputVariableName:s,reservedInputVariableNames:i,isDashboardFilterReference:a,onUpdateFilter:c,onRemoveFilter:u})})}const yY="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",l_t=[];function cye({open:e,onOpenChange:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(!1),[i,a]=v.useState({sheetSelection:"current",protectPdf:!1,password:""}),c=m.useDashboardStore(q=>{var Y;return(Y=q.dashboard)==null?void 0:Y.sheets}),u=m.useDashboardStore(q=>q.dashboard),d=m.useDashboardStore(q=>q.dashboardInputValues),f=m.useDashboardStore(q=>q.filterValues),h=m.useDashboardStore(q=>q.controlValues),p=m.useDashboardStore(q=>q.inlineFilterValuesMap),g=m.useDashboardStore(q=>q.cardControlValuesMap),x=m.useDashboardStore(q=>q.selectedSheetId),b=m.useDashboardStore(q=>q.selectedSheetId?q.documentInputRuntimeBySheetId[q.selectedSheetId]:void 0),y=m.useDashboardStore(q=>q.isDownloadingPdf),C=m.useDashboardStore(q=>q.reportContext),{authToken:w,tokenProps:N}=Mt(),S=c==null?void 0:c.find(q=>q.id===x),j=v.useMemo(()=>m.getDashboardExportSheets(c),[c]),k=m.isDocumentSheet(S),_=k&&S?S.document:void 0,T=v.useMemo(()=>k&&S?kb(u,S.id):[],[S,k,u]),I=T.length>0,D=v.useMemo(()=>k&&S?wge(u,S.id):!1,[S,k,u]),E=v.useMemo(()=>I?T.map(NC):(_==null?void 0:_.inputs)||l_t,[_,T,I]),R=C==null?void 0:C.calendar.tz,F=v.useMemo(()=>ype(E),[E]),M=v.useMemo(()=>xpe(E,R),[E,R]),O=v.useMemo(()=>bpe(E),[E]),z=b?b.filterValuesByInputId:M,L=v.useMemo(()=>wpe(z,E),[E,z]),V=b?b.controlValuesByInputId:O,A=v.useMemo(()=>k?D&&S&&_?IZ({dashboard:u,sheetId:S.id,sheetKind:"document",sectionIds:_.sections.map(q=>q.id),mode:"document",runtimeValues:{dashboardInputValues:d,filterValues:f,controlValues:h,inlineFilterValuesMap:p,cardControlValuesMap:g},timezone:R}):Spe(E,L,V,F,F):[],[_,E,S,k,u,g,h,f,p,d,V,L,F,R,D]),B=!!S,$=j.length>0,P=((c==null?void 0:c.length)||0)>1||k,U=i.sheetSelection==="current"&&(!B||k&&A.length>0)||i.sheetSelection==="all"&&!$;v.useEffect(()=>{e&&i.sheetSelection==="all"&&!$&&a(q=>({...q,sheetSelection:"current"}))},[$,e,i.sheetSelection]);const H=()=>{a({sheetSelection:"current",protectPdf:!1,password:""}),r(!1),t(!1)};async function G(){if(y){m.ue.error("A PDF export is already in progress");return}if(i.protectPdf&&!i.password){m.ue.error("Please enter a password to protect the PDF");return}if(i.sheetSelection==="current"&&!B){m.ue.error("No sheet is selected to export");return}if(i.sheetSelection==="all"&&!$){m.ue.error("No dashboard sheets are available to export");return}s(!0);const q=i.sheetSelection==="current"&&k,Y=q?i.protectPdf?"Generating protected document PDF... may take up to 60 seconds":"Generating document PDF... may take up to 60 seconds":i.sheetSelection==="all"?"Generating PDF for all dashboard sheets... This may take a while.":i.protectPdf?"Generating protected PDF... may take up to 60 seconds":"Generating PDF... may take up to 60 seconds",W=m.ue.loading(Y);try{if(q){if(!_||!S)throw new Error("Selected document sheet is missing document data");if(A.length>0){m.ue.dismiss(W),m.ue.error(`Set ${A.join(", ")} before exporting`);return}const Z=new Date().toISOString(),K=D?_Z({dashboard:u,sheetId:S.id,sheetKind:"document",sectionIds:_.sections.map(X=>X.id),mode:"document",runtimeValues:{dashboardInputValues:d,filterValues:f,controlValues:h,inlineFilterValuesMap:p,cardControlValuesMap:g},generatedAt:Z,timezone:R}).snapshot:void 0;await NL(N.apiServiceUrl,w,{sheetId:S.id,title:S.title||"Document",pageSize:_.page.size,orientation:_.page.orientation,timezone:R,password:i.protectPdf?i.password:void 0,inputSnapshot:K,...K?{}:{inputValues:{sheetId:S.id,filterValuesByInputId:L,controlValuesByInputId:V,generatedAt:Z}}})}else{const Z=$oe();await jte(N.apiServiceUrl,w,i.protectPdf?i.password:void 0,i.sheetSelection,Z)}m.ue.dismiss(W);const ne=q?i.protectPdf?"Protected document PDF downloaded successfully!":"Document PDF downloaded successfully!":i.sheetSelection==="all"?"Dashboard sheets PDF downloaded successfully!":i.protectPdf?"Protected PDF downloaded successfully!":"PDF downloaded successfully!";m.ue.success(ne,{duration:2e3}),H()}catch(ne){m.ue.dismiss(W),m.ue.error("Failed to download PDF",{description:r_(ne,"Please try again or contact support."),descriptionClassName:n_,closeButton:!0,duration:1/0,richColors:!0}),console.error("PDF download error:",ne)}finally{s(!1)}}return l.jsx(To,{open:e,onOpenChange:q=>{if(!q){H();return}t(!0)},children:l.jsxs(bo,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[l.jsxs($s,{children:[l.jsx(yo,{className:"text-[15px]",children:k?"Export document":"Export dashboard"}),l.jsx(Ho,{className:"text-[13px] leading-5",children:k?"Export this document sheet as a PDF document.":"Export this dashboard as a PDF document."})]}),l.jsxs("div",{className:"space-y-4 py-1",children:[P&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(m.Label,{className:yY,children:"Export scope"}),l.jsxs(cc,{value:i.sheetSelection,onValueChange:q=>a({...i,sheetSelection:q}),className:"gap-1.5",children:[l.jsxs(m.Label,{htmlFor:"scope-current",className:m.cn("flex cursor-pointer items-center gap-2 rounded-control px-1 py-1 text-[13px] font-normal hover:bg-muted/50",!B&&"cursor-not-allowed opacity-50 hover:bg-transparent"),children:[l.jsx(Ms,{value:"current",id:"scope-current",disabled:!B}),k?"This document":"This sheet"," (",(S==null?void 0:S.title)||"Current",")"]}),l.jsxs(m.Label,{htmlFor:"scope-all",className:m.cn("flex cursor-pointer items-center gap-2 rounded-control px-1 py-1 text-[13px] font-normal hover:bg-muted/50",!$&&"cursor-not-allowed opacity-50 hover:bg-transparent"),children:[l.jsx(Ms,{value:"all",id:"scope-all",disabled:!$}),"Dashboard sheets (",j.length," ",j.length===1?"sheet":"sheets",")"]})]}),k&&l.jsx("p",{className:"text-[12px] leading-5 text-muted-foreground",children:A.length>0?`Set ${A.join(", ")} before exporting this document.`:'"Dashboard sheets" includes dashboard sheets only. Choose "This document" to export the selected document.'})]}),l.jsx(m.Separator,{className:"bg-border/60"})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsxs(m.Label,{htmlFor:"protect-pdf",className:"flex cursor-pointer items-center gap-2 text-[13px] font-normal",children:[l.jsx(jn,{id:"protect-pdf",checked:i.protectPdf,onCheckedChange:q=>{a({...i,protectPdf:q,password:q?i.password:""}),q||r(!1)}}),l.jsx(iw,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Password protect PDF"]}),i.protectPdf&&l.jsxs("div",{className:"ml-6 space-y-1.5",children:[l.jsx(m.Label,{htmlFor:"pdf-password",className:yY,children:"Password"}),l.jsxs("div",{className:"relative",children:[l.jsx(m.Input,{id:"pdf-password",size:"xs",type:n?"text":"password",value:i.password,onChange:q=>a({...i,password:q.target.value}),placeholder:"Enter password",className:"pr-8",onKeyDown:q=>{q.key==="Enter"&&i.password&&G()}}),l.jsx("button",{type:"button",className:"absolute right-1 top-1/2 flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>r(!n),"aria-label":n?"Hide password":"Show password",children:n?l.jsx(uI,{className:"h-3.5 w-3.5"}):l.jsx(Ft.Eye,{className:"h-3.5 w-3.5"})})]}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Recipients will need this password to open the PDF."})]})]})]}),l.jsxs(ll,{children:[l.jsx(m.Button,{variant:"outline",size:"xs",onClick:H,disabled:o,children:"Cancel"}),l.jsx(m.Button,{size:"xs",onClick:G,disabled:o||y||U,children:o?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Exporting…"]}):l.jsxs(l.Fragment,{children:[l.jsx(ac,{className:"h-3.5 w-3.5"}),"Export"]})})]})]})})}function uye({iconClassName:e,open:t,onOpenChange:n}){const[r,o]=v.useState(!1),s=t!==void 0,i=s?t:r,a=u=>{s||o(u),n==null||n(u)},c=m.useDashboardStore(u=>u.isDownloadingPdf);return l.jsxs(l.Fragment,{children:[s?null:l.jsx(m.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:c,onClick:()=>a(!0),children:l.jsx(ac,{className:m.cn("size-4",e)})}),l.jsx(cye,{open:i,onOpenChange:a})]})}function c_t({control:e,value:t,isEditing:n=!1,onChange:r}){const{attributes:o,listeners:s,setNodeRef:i,transform:a,transition:c,isDragging:u}=dp({id:`control:${e.id}`,disabled:!n}),d={transform:Pi.Translate.toString(a),transition:c,opacity:u?.5:1,zIndex:u?10:void 0};return l.jsx("div",{ref:i,style:d,...o,children:l.jsx(Vpe,{control:e,value:t,isEditing:n,dragListeners:n?s:void 0,onChange:r})})}function vY(e){var t;return(((t=e.values)==null?void 0:t.length)??0)>0||e.operation==="is null"||e.operation==="is not null"}function wY(e,t){return[...e.map(n=>`filter:${n.id}`),...t.map(n=>`control:${n.id}`)]}function u_t(e,t,n){const r=new Set([...t.map(a=>`filter:${a.id}`),...n.map(a=>`control:${a.id}`)]);if(!(e!=null&&e.length))return wY(t,n);const o=e.filter(a=>r.has(a)),s=new Set(o),i=wY(t,n).filter(a=>!s.has(a));return[...o,...i]}function d_t(e,t){return m.getDashboardCardEntries({sheets:e.sheets||[]}).filter(n=>n.sheet.id===t).map(n=>n.card.id)}function f_t(e){return m.doesDashboardInputApplyToTarget(e.dashboardInput,{sheetId:e.selectedSheetId,sheetKind:"dashboard"})?!0:e.dashboardInput.scope.kind!=="cards"?!1:e.selectedSheetCardIds.some(t=>m.doesDashboardInputApplyToTarget(e.dashboardInput,{sheetId:e.selectedSheetId,cardId:t,sheetKind:"dashboard"}))}function uR(e){var t;return((t=e.compatibility)==null?void 0:t.source)!=="dashboardFilter"}function h_t(e){return dye(e).filter(t=>{var n,r;return t.filter.hide||t.filter.location==="frame"?!1:((n=t.compatibility)==null?void 0:n.source)==="dashboardFilter"?!0:(((r=t.presentation)==null?void 0:r.placement)||"toolbar")==="toolbar"})}function dye(e){if(!e.selectedSheetId)return[];const t=e.selectedSheetId,n=d_t(e.dashboard,t);return m.removeShadowedCompatibilityInputs(m.buildNormalizedDashboardInputs({dashboard:e.dashboard}).allInputs).filter(r=>!(r.kind!=="filter"||!f_t({dashboardInput:r,selectedSheetId:t,selectedSheetCardIds:n})))}function m_t(e,t){return"toolbar"}function p_t(){const e=xl("interactive"),t=m.useDashboardStore(Z=>Z.selectedSheetId),n=m.useDashboardStore(Z=>Z.dashboard.filters),r=m.useDashboardStore(Z=>Z.dashboard.filterLayout),o=m.useDashboardStore(Z=>Z.isDashboardEditing),s=m.useDashboardStore(Z=>Z.controlValues),i=m.useDashboardStore(Z=>Z.filterValues);m.useDashboardStore(Z=>Z.filteringCards);const a=m.useDashboardStore(Z=>Z.inlineFilterValuesMap),c=m.useDashboardStore(Z=>Z.dashboardInputValues),u=m.useInteractionStore(Z=>Z.clearAllClickFilters),d=m.useInteractionStore(Z=>Object.entries(Z.interactionStates).reduce((K,[X,J])=>{var re;return X===m.DRILL_CONTEXT_CARD_ID?K:K+(((re=J.appliedClickFilters)==null?void 0:re.length)??0)},0)),f=m.useDashboardStore(Z=>Z.actions.removeCardInlineFilterValue),{reorderFilters:h,clearDashboardInputSlot:p,reorderDashboardControls:g,removeDashboardInput:x,removeFilter:b,setControlValue:y,setFilterLayout:C,setFilterValues:w,setFilteringCards:N,updateFilterDashboardInputDefinition:S}=m.useDashboardActions(),j=bC(Em(cp,{activationConstraint:{distance:5}})),k=m.useDashboardStore(Z=>Z.dashboard),_=h_t({dashboard:k,selectedSheetId:t}).filter(Z=>m_t(Z.filter)==="toolbar"),T=dye({dashboard:k,selectedSheetId:t}),I=_.map(Z=>Z.filter),D=new Map(_.map(Z=>[`filter:${Z.filter.id}`,Z])),E=nnt(k),R=E.filter(Z=>!Z.hidden&&j0(Z)==="toolbar"),F=E.filter(Z=>!Z.hidden&&j0(Z)==="advanced"),M=u_t(r==null?void 0:r.toolbarItemOrder,I,R),O=new Map(I.map(Z=>[`filter:${Z.id}`,Z])),z=new Map(R.map(Z=>[`control:${Z.id}`,Z]));function L(Z){const{active:K,over:X}=Z;if(!X||K.id===X.id)return;const J=String(K.id),re=String(X.id),te=M.findIndex(be=>be===J),Q=M.findIndex(be=>be===re);if(te===-1||Q===-1)return;const se=up(M,te,Q);C({toolbarItemOrder:se});const oe=new Set((n||[]).map(be=>be.id)),fe=M.filter(be=>be.startsWith("filter:")).map(be=>be.replace("filter:","")).filter(be=>oe.has(be)),pe=se.filter(be=>be.startsWith("filter:")).map(be=>be.replace("filter:","")).filter(be=>oe.has(be)),xe=M.filter(be=>be.startsWith("control:")).map(be=>be.replace("control:","")),Ie=se.filter(be=>be.startsWith("control:")).map(be=>be.replace("control:",""));h(Bk(n||[],fe,pe)),g(Bk(k.controls||[],xe,Ie))}const V=(r==null?void 0:r.toolbarWrap)??!1,A=(r==null?void 0:r.showDownloadButton)??!1,B=T.filter(uR),$=T.filter(Z=>{if(uR(Z))return!1;const K=m.getDashboardInputRuntimeSlot(c,Z,{sheetId:t});return(K==null?void 0:K.status)==="set"||(K==null?void 0:K.status)==="cleared"}),P=new Set([...B,...$].map(Z=>Z.filter.id)),U=(i==null?void 0:i.filter(Z=>!P.has(Z.filterId)&&vY(Z)).length)??0,H=[...B,...$],G=H.filter(Z=>{const K=m.hydrateAuthoredDashboardInputSlot({dashboard:k,input:Z,runtimeValues:c,target:{sheetId:t}});return(K==null?void 0:K.status)==="set"&&K.value.kind==="filter"&&vY(K.value.filterValue)}).length,q=a?Object.values(a).reduce((Z,K)=>Z+((K==null?void 0:K.length)??0),0):0,Y=U+G+q+d,W=H.some(Z=>Z.forceSelection),ne=()=>{w([]),H.forEach(Z=>{p(Z,{sheetId:t})}),N([]),u(),a&&Object.entries(a).forEach(([Z,K])=>{K==null||K.forEach(X=>{f(Z,X.filterId)})})};return!I.length&&!R.length&&!F.length&&!A&&Y===0?null:l.jsx("div",{className:"z-20 bg-background/95 px-3 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/85",style:e.containerStyle,role:"toolbar","aria-label":"Dashboard filters and controls",children:l.jsx(Sb,{sensors:j,collisionDetection:wb,onDragEnd:L,children:l.jsxs("div",{className:m.cn("flex items-center",V?"flex-wrap":"w-0 min-w-full overflow-x-auto"),children:[l.jsx(Nb,{items:M,strategy:FT,children:l.jsx(cO,{className:"gap-3 pr-0",wrap:V,children:M.map(Z=>{const K=O.get(Z);if(K){const J=D.get(Z),re=J&&uR(J),te=re&&J.definitionOrigin==="dashboardFilter";return l.jsx(a_t,{filter:K,isEditing:o,storageOptions:re?{storageTarget:"dashboardInput",dashboardInput:J,sheetId:t??void 0,sheetKind:"dashboard"}:void 0,inputVariableName:re?J.variableName:void 0,isDashboardFilterReference:te,onUpdateFilter:re?(Q,se)=>S(J.id,Q,se):void 0,onRemoveFilter:re?()=>{if(J.definitionOrigin==="dashboardFilter"){b(K.id);return}w((i||[]).filter(Q=>Q.filterId!==K.id)),x(J.id)}:void 0},Z)}const X=z.get(Z);return X?l.jsx(c_t,{control:X,value:s==null?void 0:s[X.id],isEditing:o,onChange:J=>y(X.id,J)},Z):null})})}),F.length>0&&l.jsx(Bde,{title:"",controls:F,values:s,onChange:(Z,K)=>y(Z.id,K),immediatePlacement:"toolbar",advancedLabel:"More controls"}),Y>0&&l.jsxs("button",{type:"button",onClick:ne,"aria-label":W?"Reset filters":"Clear all filters",className:"ml-auto inline-flex h-7 shrink-0 items-center gap-1 rounded-control px-2 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[l.jsx(Re.X,{className:"h-3 w-3"}),W?"Reset filters":"Clear all",l.jsx("span",{className:"rounded-[3px] bg-muted px-1 text-[10px] tabular-nums text-muted-foreground",children:Y})]}),A&&l.jsx("div",{className:m.cn(Y>0?"ml-1.5":"ml-auto"),children:l.jsx(uye,{})})]})})})}function fye(){var ee,ce;const{showAssistant:e,tokenProps:t,renderMode:n}=Mt(),r=i_t((ee=t.config)==null?void 0:ee.showDashboardAssistant,e),{preferences:o}=Vm(),s=(ce=o==null?void 0:o.cardDisplay)==null?void 0:ce.mode,i=mf(s),a=Eee({displayMode:s,renderMode:n}),c=v.useRef(null),u=v.useRef(null),d=v.useRef(null),[f,h]=v.useState(!1),{handleDragStart:p,isDraggingRef:g,getStyle:x,getPositionClasses:b}=h0t({initialPosition:"bottom-right"}),y=Rh(ae=>ae.setFullscreen),C=Rh(ae=>ae.setPanelOpen),w=Rh(ae=>ae.setContainer),N=NJ("dashboard"),S=jJ(),j=kJ("dashboard"),k=N.isOpen,_=S==="dashboard",T=m.useDashboardStore(ae=>ae.isVisualEditing),I=m.useDashboardStore(ae=>ae.themeStyle),D=Pu(),E=m.useDashboardStore(ae=>{var me;return(me=ae.dashboard)==null?void 0:me.sheets}),R=m.useDashboardStore(ae=>ae.showFilters),F=m.useDashboardStore(ae=>ae.isDashboardEditing),M=m.useDashboardStore(ae=>ae.selectedSheetId),O=E==null?void 0:E.find(ae=>ae.id===M),z=m.useDashboardStore(ae=>{var me,ve,_e;return(_e=(ve=(me=ae.dashboard)==null?void 0:me.sheets)==null?void 0:ve.find(De=>De.id===ae.selectedSheetId))==null?void 0:_e.kind}),L=m.useDashboardStore(ae=>{var me,ve;return((ve=(me=ae.dashboard)==null?void 0:me.summary)==null?void 0:ve.position)||"top"}),V=z==="document",A=m.useDashboardStore(ae=>{var me;return(me=ae.dashboard)==null?void 0:me.id}),{getDefaultSheetId:B,setDefaultSheetId:$,clearDefaultSheetId:P}=mZ(A),[U,H]=v.useState(null),{setSelectedSheetId:G,setSheetTitle:q,addSheet:Y,setSheets:W,duplicateSheet:ne}=m.useDashboardActions();WIt(u);const{setActiveAssistantType:Z}=m.useAIActions();v.useEffect(()=>{if(A){const ae=B();H(ae)}},[A,B]),v.useEffect(()=>{k?Z("dashboard"):S==="dashboard"&&y(null)},[k,Z,S,y]),v.useEffect(()=>{var ae;k||(ae=c.current)==null||ae.resize(0)},[k]);function K(ae){var me,ve;ae?((me=c.current)==null||me.resize(40),C("dashboard",!0),y("dashboard"),Z("dashboard")):(C("dashboard",!1),y(null),(ve=c.current)==null||ve.resize(0),Z(null))}function X(ae="dashboard"){const me={id:lt.v4(),title:ae==="document"?"New Document":"New Sheet",...ae==="document"?{kind:ae,document:m.createDefaultDocumentDefinition()}:{}};Y(me),G(me.id)}function J(ae){const me=ne(ae);me&&(m.ue.success("Sheet duplicated"),requestAnimationFrame(()=>{var _e;const ve=(_e=d.current)==null?void 0:_e.querySelector(`[data-sheet-id="${me}"]`);ve==null||ve.focus(),ve==null||ve.scrollIntoView({block:"nearest",inline:"nearest"})}))}function re(ae,me){if(!A)return;U===ae?(P(),H(null),m.ue.success("Default sheet cleared")):($(ae),H(ae),m.ue.success(`"${me}" set as default sheet`))}function te(ae){var me;ae<1?(C("dashboard",!1),y(null),Z(null),(me=c.current)==null||me.resize(0)):(k||C("dashboard",!0),Z("dashboard"))}function Q(){return(I==null?void 0:I.canvasTheme)==="muted"||!(I!=null&&I.canvasTheme)?"hsl(var(--semaphor-muted))":(I==null?void 0:I.canvasTheme)==="clear"?"":I==null?void 0:I.canvasTheme}const se=(ae,me)=>{ae.dataTransfer.setData("tabIndex",me.toString())},oe=ae=>{ae.preventDefault()},fe=(ae,me)=>{const ve=ae.dataTransfer.getData("tabIndex");if(ve===me.toString())return;const _e=Array.from(E||[]),[De]=_e.splice(parseInt(ve),1);_e.splice(me,0,De),W(_e)},pe=r===!0&&!i&&!k&&!T&&!R;function xe(){if(E&&E.length>1||F)return l.jsx("div",{className:"relative flex w-full items-stretch",children:l.jsxs("div",{className:"relative min-w-0 flex-1",children:[l.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 left-0 z-10 w-4 bg-gradient-to-r from-background to-transparent"}),l.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 right-0 z-10 w-4 bg-gradient-to-l from-background to-transparent"}),l.jsxs(m.TabsList,{ref:d,className:"flex w-0 min-w-full items-stretch justify-start overflow-x-auto rounded-none bg-transparent p-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:[E==null?void 0:E.map((ae,me)=>{const ve=M===ae.id,_e=U===ae.id;return l.jsxs("div",{className:"relative flex shrink-0 items-center",children:[l.jsxs(m.TabsTrigger,{"data-sheet-id":ae.id,draggable:!0,onDragStart:De=>se(De,me),onDragOver:oe,onDrop:De=>fe(De,me),onClick:()=>G(ae.id),className:m.cn("group relative inline-flex h-9 shrink-0 items-center gap-1.5 rounded-none bg-transparent px-3 py-0 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-transparent hover:text-foreground data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none",F&&ve&&"pr-9","after:pointer-events-none after:absolute after:inset-x-2 after:-bottom-px after:h-0.5 after:bg-transparent data-[state=active]:after:bg-foreground"),value:ae.id,children:[ae.kind==="document"&&l.jsx(li,{className:"h-3 w-3 text-muted-foreground"}),l.jsx(ak,{enabled:F&&ve,text:ae.title,onSave:De=>q(ae.id,De),children:ae.title},ae.id),l.jsx("span",{role:"button",tabIndex:0,"aria-label":_e?"Clear default sheet":"Set as default sheet",title:_e?"Clear default sheet":"Set as default sheet",onClick:De=>{De.stopPropagation(),re(ae.id,ae.title||"Sheet")},onKeyDown:De=>{(De.key==="Enter"||De.key===" ")&&(De.preventDefault(),De.stopPropagation(),re(ae.id,ae.title||"Sheet"))},className:m.cn("inline-flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded-[3px] transition-opacity hover:bg-muted focus:outline-none focus-visible:ring-1 focus-visible:ring-foreground",ve||_e?"opacity-100":"opacity-0 group-hover:opacity-100"),children:l.jsx(hX,{className:m.cn("h-3 w-3 transition-colors",_e?"fill-current text-amber-500":"text-muted-foreground")})})]}),F&&ve&&l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":`Sheet actions for ${ae.title||"Sheet"}`,className:"absolute right-2 inline-flex h-4 w-4 items-center justify-center rounded-[4px] text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground",children:l.jsx(Ai,{className:"h-3 w-3"})})}),l.jsxs(_o,{align:"start",className:"w-44",children:[l.jsxs(ln,{onSelect:()=>J(ae.id),children:[l.jsx(gu,{className:"h-4 w-4"}),"Duplicate sheet"]}),l.jsxs(ln,{disabled:E.length<=1,onSelect:()=>h(!0),children:[l.jsx(Ra,{className:"h-4 w-4"}),"Delete sheet"]})]})]})]},ae.id)}),F&&l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Add sheet",className:"ml-1 inline-flex h-9 shrink-0 items-center gap-1 px-3 text-[12px] font-medium text-muted-foreground transition-colors hover:text-foreground",children:[l.jsx(Ar,{className:"h-3 w-3"}),"Sheet"]})}),l.jsxs(_o,{align:"start",className:"w-48",children:[l.jsxs(ln,{onSelect:()=>X("dashboard"),children:[l.jsx(zd,{className:"h-4 w-4 text-muted-foreground"}),"Dashboard sheet"]}),l.jsxs(ln,{onSelect:()=>X("document"),children:[l.jsx(li,{className:"h-4 w-4 text-muted-foreground"}),"Document"]})]})]})]})]})})}function Ie(){return l.jsx("div",{ref:u,style:{},className:"h-full min-h-0 grow",children:E==null?void 0:E.map(ae=>l.jsx(m.TabsContent,{style:{backgroundColor:Q(),...D.dashboardCanvasStyle},className:m.cn("mt-0 h-full min-h-0",{}),value:ae.id,children:l.jsx(hG,{sheet:ae})},ae.id))})}function be(){return l.jsxs(m.Tabs,{"data-role":"dashboard-tabs-container",className:m.cn("relative flex h-full flex-col",I==null?void 0:I.dashboardTabsContainer),onValueChange:ae=>{G(ae)},value:M||void 0,children:[xe(),L==="top"&&!V&&l.jsx(IP,{}),M&&!V&&l.jsx(p_t,{}),V?l.jsx("div",{"data-role":"dashboard-tabs-content",className:"min-h-0 flex-1 grow basis-0 overflow-hidden",children:Ie()}):l.jsx($u,{"data-role":"dashboard-tabs-content",className:"flex-1 grow basis-0 overflow-y-auto",children:Ie()}),L==="bottom"&&!V&&l.jsx(IP,{}),l.jsx(m0t,{open:f,setOpen:h})]})}const ge=v.useCallback(ae=>{w("dashboard",ae)},[w]);return E?a&&M&&!V?l.jsxs("div",{"data-document-render-error":"true",className:"bg-white p-8 text-sm text-zinc-700",children:['Requested document sheet "',M,'" was not found or is not a document sheet in the loaded dashboard.']}):a&&V&&O?l.jsx("div",{"data-role":"dashboard-document-print-content",className:"min-h-0 overflow-visible bg-white",children:l.jsx(hG,{sheet:O})}):l.jsxs(l.Fragment,{children:[l.jsx(t_t,{}),l.jsx(s_t,{}),l.jsxs("div",{className:"relative flex-1 basis-0 overflow-hidden",children:[l.jsxs(Kge,{className:m.cn("flex-1 basis-0 overflow-y-auto transition-opacity",_&&"pointer-events-none opacity-0"),direction:"horizontal",children:[l.jsx(pO,{children:be()}),r===!0&&l.jsxs(l.Fragment,{children:[l.jsx(f0t,{open:k,onTabClick:K,withHandle:!0,disabled:!k}),l.jsx(pO,{className:"flex grow","data-role":"dashboard-assistant-panel",onResize:te,defaultSize:k?40:0,ref:c,children:l.jsx("div",{className:"grow overflow-y-auto",children:l.jsx(KIt,{open:k,setOpen:K,isFullscreen:_,onFullscreenChange:ae=>y(ae?"dashboard":null),fullscreenContainer:j})})})]})]}),l.jsx("div",{ref:ge,className:m.cn("absolute inset-0",!_&&"pointer-events-none")}),pe&&l.jsx("div",{className:m.cn("absolute z-50 transition-all duration-300 ease-in-out",b().horizontal,b().vertical),style:x(),children:l.jsx(m.Button,{size:"sm",variant:"outline",className:"h-12 w-12 cursor-grab rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted active:cursor-grabbing",onClick:()=>{g.current||K(!0)},onMouseDown:p,onTouchStart:p,title:"Open Assistant (drag to move)",children:l.jsx(ewe,{className:"h-5 w-5"})})})]})]}):null}const hye=v.forwardRef(({appearance:e,organizationAppearance:t,tokenAppearance:n,reactAppearance:r,resolvedAppearance:o,systemMode:s,children:i,className:a,style:c,...u},d)=>l.jsx(fg.InternalAppearanceRuntimeProvider,{appearance:e,organizationAppearance:t,tokenAppearance:n,reactAppearance:r,resolvedAppearance:o,systemMode:s,children:l.jsx(gb,{...u,ref:d,className:a,style:c,children:i})}));hye.displayName="AppearanceProvider";const mye=v.createContext({openBrandStudioPreview:()=>{}}),g_t=mye.Provider;function x_t(){return v.useContext(mye)}function b_t({children:e,defaultTheme:t="system",storageKey:n="vite-ui-theme",...r}){const o=fg.normalizeTheme(t),[s,i]=v.useState(()=>y_t(n)||o),a=v.useCallback(u=>{const d=fg.normalizeTheme(u);v_t(n,d),i(d)},[n]),c=v.useMemo(()=>({theme:s,setTheme:a}),[s,a]);return l.jsx(fg.ThemeProviderContext.Provider,{...r,value:c,children:e})}function y_t(e){if(typeof window>"u")return null;try{const t=window.localStorage.getItem(e);if(!t)return null;const n=fg.normalizeTheme(t,"system");return n===t?n:null}catch{return null}}function v_t(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}const w_t=v.lazy(()=>Promise.resolve().then(()=>require("../brand-studio/index.cjs")).then(e=>({default:e.BrandStudioEditor})));function DB({appearance:e,children:t}){var D,E;const{authToken:n,id:r,tokenProps:o}=Mt(),s=ew(),i=(D=s.data)==null?void 0:D.organizationAppearance,a=(E=o.config)==null?void 0:E.appearance,[c,u]=v.useState(!1),[d,f]=v.useState(null),[h,p]=v.useState(null),[g,x]=v.useState(null),[b,y]=v.useState(null),C=`${o.apiServiceUrl??""}:${(n==null?void 0:n.accessToken)??""}`,w=Yn({queryKey:x5({resourceType:uo.DASHBOARD,apiServiceUrl:o.apiServiceUrl,accessToken:n==null?void 0:n.accessToken}),queryFn:async()=>m.getRequest(`${o.apiServiceUrl}/management/v1/dashboards`,(n==null?void 0:n.accessToken)||""),select:R=>(R==null?void 0:R.organizationAppearance)??null,enabled:!s.dashboardIdToFetch&&i===void 0&&!!(n!=null&&n.accessToken)});v.useEffect(()=>{i!==void 0&&y({scopeKey:C,appearance:i})},[i,C]),v.useEffect(()=>{w.data!==void 0&&y({scopeKey:C,appearance:w.data})},[w.data,C]);const N=(b==null?void 0:b.scopeKey)===C?b.appearance:null,S=i!==void 0?i:w.data!==void 0?w.data:N,j=v.useMemo(()=>Am.resolveAppearance({organizationAppearance:S,tokenAppearance:a,reactAppearance:e}),[e,S,a]),k=v.useCallback(()=>{f(g??h??j),u(!0)},[g,h,j]),_=v.useCallback(()=>{u(!1)},[]);v.useEffect(()=>{f(null),p(null),x(null),u(!1)},[r]);const T=v.useMemo(()=>({openBrandStudioPreview:k}),[k]),I=g??h??e;return l.jsx(b_t,{defaultTheme:"system",storageKey:"vite-ui-theme",children:l.jsx(g_t,{value:T,children:l.jsx(hye,{organizationAppearance:S,tokenAppearance:a,reactAppearance:I,style:{height:"100%",width:"100%"},children:l.jsxs(m.TooltipProvider,{delayDuration:0,children:[t,c&&l.jsx("aside",{"aria-label":"Brand Studio","aria-modal":"false",role:"dialog",className:"fixed bottom-0 right-0 top-0 z-50 flex w-[min(520px,100vw)] flex-col border-l border-border bg-background text-foreground shadow-sm",children:l.jsx(v.Suspense,{fallback:l.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Loading Brand Studio..."}),children:l.jsx(w_t,{appearance:d,onDraftChange:x,onSave:R=>{p(R),x(R),f(R)},onCancel:_})})})]})})})})}function pye({children:e,preferences:t}){const{currentUser:n}=hi(),r=v.useMemo(()=>{var o,s;return{preferences:t||{},isLocalDev:((o=t==null?void 0:t.uiMode)==null?void 0:o.developer)||!1,isConsoleMode:((s=t==null?void 0:t.uiMode)==null?void 0:s.console)||!1}},[t]);return l.jsx(mQ.Provider,{value:r,children:l.jsx(xT,{displayPreferences:t==null?void 0:t.cardDisplay,currentUser:n,children:e})})}function C_t(e=2e3,t=500){const n=Gve(),[r,o]=v.useState(!1),[s,i]=v.useState(!1),a=v.useRef(null);return v.useEffect(()=>{const c=setTimeout(()=>o(!0),e);return()=>clearTimeout(c)},[e]),v.useEffect(()=>{if(r){if(n>0){i(!1),a.current&&(clearTimeout(a.current),a.current=null);return}return a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{i(!0)},t),()=>{a.current&&clearTimeout(a.current)}}},[r,n,t]),s}function EB({delayMs:e=2e3,quietMs:t=500,componentType:n,componentId:r}){const o=C_t(e,t);return v.useEffect(()=>(o&&(window.__SEMAPHOR_READY__={ready:!0,type:n,componentId:r||null,timestamp:Date.now()}),()=>{window.__SEMAPHOR_READY__={ready:!1,type:n,componentId:r||null,timestamp:Date.now()}}),[o,n,r]),l.jsx("div",{id:"idle-check","aria-hidden":"true",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:o?"ready":""})}function gye(e){if(typeof window>"u")return null;const{preferences:t}=e;return l.jsx(ui,{FallbackComponent:pT,children:l.jsx(HO,{dashboardProps:e,children:l.jsxs(IT,{children:[l.jsx(EB,{componentType:"dashboard",componentId:e.id}),l.jsx(DB,{appearance:e.appearance,children:l.jsx(pye,{preferences:t,children:l.jsx("main",{className:"flex h-full flex-col",children:l.jsx(k5,{...e,type:"dashboard",children:l.jsx(fye,{})})})})})]})})})}function S_t(e=[]){const t=v.useRef(null),n=v.useRef(null),r=v.useRef(null),[o,s]=v.useState(),i=v.useCallback(()=>{var p,g,x;const a=((p=t.current)==null?void 0:p.clientWidth)??0,c=((g=r.current)==null?void 0:g.offsetWidth)??0,u=((x=n.current)==null?void 0:x.offsetWidth)??0,f=a-c-u-8,h=Math.max(f,0);s(b=>b===h?b:h)},[]);return v.useEffect(()=>{const a=t.current;if(!a||typeof ResizeObserver>"u")return;const c=new ResizeObserver(()=>i());return c.observe(a),i(),()=>c.disconnect()},[i,...e]),{headerRef:t,leftActionsRef:n,rightActionsRef:r,titleMaxWidth:o,updateAvailableWidth:i}}function N_t({filter:e}){var g;const t=m.useDashboardStore(x=>x.isDashboardEditing),{preferences:n}=Vm(),r=mf((g=n==null?void 0:n.cardDisplay)==null?void 0:g.mode),o=m.useDashboardStore(x=>x.filterValues),s=o==null?void 0:o.some(x=>x.filterId===e.id),{removeFilterValues:i,removeFilter:a,updateFilter:c}=m.useDashboardActions(),{headerRef:u,leftActionsRef:d,rightActionsRef:f,titleMaxWidth:h,updateAvailableWidth:p}=S_t([t,s,r]);return v.useEffect(()=>{p()},[e.title,p]),l.jsxs("div",{ref:u,className:"group mb-1 flex h-5 items-center justify-between",children:[l.jsxs("div",{className:"flex grow items-center gap-2 min-w-0",children:[l.jsx("div",{className:"min-w-0 flex-1",style:h!==void 0?{maxWidth:h}:void 0,children:l.jsx(m.Label,{className:"my-1 block w-full text-sm",children:l.jsx(Di,{value:e.title||e.column,onSave:x=>c({...e,title:x}),isEditable:t,placeholder:"Filter",displayClassName:"text-sm truncate",inputClassName:"text-sm"})})}),l.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",ref:d,children:[t&&l.jsx(hz,{filter:e,isEditing:t}),t&&l.jsx("button",{onClick:()=>{i(e.id),a(e.id)},className:"text-muted-foreground hover:text-foreground",children:l.jsx(Re.X,{className:"size-3.5"})})]})]}),l.jsx("div",{className:"hidden",ref:f})]})}function j_t(){const e=m.useDashboardStore(r=>r.dashboard.filters),t=m.useDashboardStore(r=>r.theme),n=e==null?void 0:e.filter(r=>r.hide);return n!=null&&n.length?l.jsx("div",{className:m.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":t==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":t==="dark"}),children:n==null?void 0:n.map(r=>l.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[l.jsx(N_t,{filter:r}),l.jsx(uT,{filter:r})]},r.id))}):null}function k_t(){var s;const e=m.useDashboardStore(i=>i.dashboard),t=m.useDashboardStore(i=>i.selectedSheetId),n=m.useDashboardStore(i=>i.isDashboardEditing),r=(s=e.sheets)==null?void 0:s.find(i=>i.id===t),o=m.isDocumentSheet(r);return l.jsx("div",{role:"dashboard-plus-main",className:"flex min-h-0 grow basis-0 overflow-hidden",children:l.jsxs("section",{className:"flex min-h-0 grow basis-0 flex-col overflow-hidden",children:[n&&!o&&l.jsx(j_t,{}),l.jsx(fye,{})]})})}const I_t=v.lazy(()=>Promise.resolve().then(()=>require("./dashboard-controls-BQFt_Om0.cjs"))),__t=v.lazy(()=>Promise.resolve().then(()=>require("./edit-dashboard-visual-kDqyZQZg.cjs"))),T_t=v.lazy(()=>Promise.resolve().then(()=>require("./dashboard-json-zT5RVUQH.cjs")));function D_t({showControls:e=!1,showFooter:t=!0,...n}){const r=m.useDashboardStore(a=>a.isVisualEditing),o=m.useDashboardStore(a=>a.showDashboardJSON),{appearance:s,preferences:i}=n;return l.jsx(ui,{FallbackComponent:pT,children:l.jsx(HO,{dashboardProps:n,children:l.jsxs(IT,{children:[l.jsx(EB,{componentType:"surfboard",componentId:n.id}),l.jsxs(DB,{appearance:s,children:[l.jsx(m.$e,{toastOptions:{classNames:{toast:"max-w-[calc(100vw-2rem)] overflow-x-hidden !items-start [--toast-close-button-end:0.5rem] [--toast-close-button-start:auto] [--toast-close-button-transform:translate(0,0)] sm:max-w-[44rem]",content:"min-w-0 flex-1",icon:"mt-0.5 shrink-0",title:"max-w-full break-words pr-8",description:"max-w-full break-words",closeButton:"!top-2 h-6 w-6 rounded-md border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground"}}}),l.jsxs(pye,{preferences:i,children:[o&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(T_t,{})}),l.jsxs("main",{className:"relative flex h-full w-full flex-col overflow-hidden",children:[e&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(I_t,{})}),l.jsx("div",{className:"flex grow overflow-hidden",children:l.jsx("div",{className:"flex min-w-0 flex-1",children:l.jsxs(k5,{...n,type:"dashboard",children:[r&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(__t,{})}),l.jsx(v.Activity,{mode:r?"hidden":"visible",children:l.jsx(k_t,{})})]})})})]})]})]})]})})})}const EO=[{value:"en-US",label:"English (United States)"},{value:"en-GB",label:"English (United Kingdom)"},{value:"de-DE",label:"German (Germany)"},{value:"fr-FR",label:"French (France)"},{value:"es-ES",label:"Spanish (Spain)"},{value:"it-IT",label:"Italian (Italy)"},{value:"nl-NL",label:"Dutch (Netherlands)"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"ja-JP",label:"Japanese (Japan)"},{value:"en-IN",label:"English (India)"},{value:"en-NZ",label:"English (New Zealand)"},{value:"mi-NZ",label:"Māori (New Zealand)"}],xye=new Set(["USD","EUR","GBP","CAD","AUD","JPY","CHF","INR","BRL","KWD"]),E_t=Yi.getSupportedCurrencyCodes(),M_t=E_t.filter(e=>!xye.has(e)),bye=[{value:"short",label:"Short"},{value:"medium",label:"Medium"},{value:"long",label:"Long"}],CY="2026-07-31",dR="2026-07-31T14:30:45";function MO(e){switch(e){case"viewer_user":return"user";case"viewer_tenant_user":return"tenant user";case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"session_initial":return"embedded session";case"system_default":return"system";default:return"another preference level"}}function fR(e){var t;return((t=bye.find(n=>n.value===e))==null?void 0:t.label)??e}function R_t(e){const t=EO.find(n=>n.value===e);return t?`${t.label} — ${t.value}`:e}function hR(e){return{short:e("short"),medium:e("medium"),long:e("long")}}function mR({id:e,label:t,value:n,inherited:r,inheritedSource:o,examples:s,disabled:i,onValueChange:a}){const c=n===void 0?`Inherited · ${fR(r)}`:fR(n);return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:e,className:"text-[11px] text-muted-foreground",children:t}),l.jsxs(m.Select,{value:n??"inherit",disabled:i,onValueChange:a,children:[l.jsx(m.SelectTrigger,{id:e,size:"xs",children:l.jsx(m.SelectValue,{children:c})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"inherit",className:"[&>span:last-child]:w-full",children:l.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-4",children:[l.jsxs("span",{children:["Inherited from ",MO(o)," ·"," ",fR(r)]}),l.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:s[r]})]})}),bye.map(u=>l.jsx(m.SelectItem,{value:u.value,className:"[&>span:last-child]:w-full",children:l.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-4",children:[l.jsx("span",{children:u.label}),l.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:s[u.value]})]})},u.value))]})]})]})}function A_t({value:e,inherited:t,inheritedSources:n,onChange:r,disabled:o}){var j,k,_,T;const s=v.useId(),i=v.useId(),a=v.useId(),c=v.useId(),u=v.useId(),f=(e.locale===void 0?void 0:Yi.canonicalizeSupportedLocale(e.locale))??t.locale,h=e.defaultCurrency??t.defaultCurrency,p={locale:f,dateStyle:e.dateStyle??t.dateStyle,dateTime:{dateStyle:((j=e.dateTime)==null?void 0:j.dateStyle)??t.dateTime.dateStyle,timeStyle:((k=e.dateTime)==null?void 0:k.timeStyle)??t.dateTime.timeStyle},defaultCurrency:h},g=new Intl.NumberFormat(f,{style:"currency",currency:h}).format(1e3),x=un.resolveRawTemporalFormat({preferences:p,calendar:{tz:"UTC"}}),b=un.formatRawTemporalValue({value:CY,metadata:{kind:"raw_temporal",valueKind:"date"},format:x}).text,y=un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:x}).text,C=hR(I=>un.formatRawTemporalValue({value:CY,metadata:{kind:"raw_temporal",valueKind:"date"},format:un.resolveRawTemporalFormat({preferences:{...p,dateStyle:I},calendar:{tz:"UTC"}})}).text),w=hR(I=>un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:un.resolveRawTemporalFormat({preferences:{...p,dateTime:{...p.dateTime,dateStyle:I}},calendar:{tz:"UTC"}})}).text),N=hR(I=>un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:un.resolveRawTemporalFormat({preferences:{...p,dateTime:{...p.dateTime,timeStyle:I}},calendar:{tz:"UTC"}})}).text),S=(I,D)=>{const E={...e.dateTime,[I]:D==="inherit"?void 0:D};r({...e,dateTime:E.dateStyle===void 0&&E.timeStyle===void 0?void 0:E})};return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:s,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Locale"}),l.jsxs(m.Select,{value:e.locale??"inherit",disabled:o,onValueChange:I=>r({...e,locale:I==="inherit"?void 0:I}),children:[l.jsx(m.SelectTrigger,{id:s,size:"xs",children:l.jsx(m.SelectValue,{children:e.locale===void 0?`Inherited · ${t.locale}`:R_t(e.locale)})}),l.jsxs(m.SelectContent,{children:[l.jsxs(m.SelectItem,{value:"inherit",children:["Inherited from ",MO(n.locale)," ·"," ",t.locale]}),e.locale&&!EO.some(I=>I.value===e.locale)&&l.jsx(m.SelectItem,{value:e.locale,children:e.locale}),EO.map(I=>l.jsxs(m.SelectItem,{value:I.value,children:[I.label," — ",I.value]},I.value))]})]})]}),l.jsxs("fieldset",{className:"space-y-2",children:[l.jsx("legend",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Date values"}),l.jsx(mR,{id:a,label:"Format",value:e.dateStyle,inherited:t.dateStyle,inheritedSource:n.dateStyle,examples:C,disabled:o,onValueChange:I=>r({...e,dateStyle:I==="inherit"?void 0:I})})]}),l.jsxs("fieldset",{className:"space-y-2",children:[l.jsx("legend",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Date & time values"}),l.jsx(mR,{id:c,label:"Date",value:(_=e.dateTime)==null?void 0:_.dateStyle,inherited:t.dateTime.dateStyle,inheritedSource:n.dateTime.dateStyle,examples:w,disabled:o,onValueChange:I=>S("dateStyle",I)}),l.jsx(mR,{id:u,label:"Time",value:(T=e.dateTime)==null?void 0:T.timeStyle,inherited:t.dateTime.timeStyle,inheritedSource:n.dateTime.timeStyle,examples:N,disabled:o,onValueChange:I=>S("timeStyle",I)})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:i,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default currency"}),l.jsxs(m.Select,{value:e.defaultCurrency??"inherit",disabled:o,onValueChange:I=>r({...e,defaultCurrency:I==="inherit"?void 0:I}),children:[l.jsx(m.SelectTrigger,{id:i,size:"xs",children:l.jsx(m.SelectValue,{children:e.defaultCurrency===void 0?`Inherited · ${t.defaultCurrency}`:e.defaultCurrency})}),l.jsxs(m.SelectContent,{children:[l.jsxs(m.SelectItem,{value:"inherit",children:["Inherited from ",MO(n.defaultCurrency)," ·"," ",t.defaultCurrency]}),[...xye].map(I=>l.jsx(m.SelectItem,{value:I,children:I},I)),M_t.map(I=>l.jsx(m.SelectItem,{value:I,children:I},I))]})]})]}),l.jsxs("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2",children:[l.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Preview"}),l.jsxs("dl",{className:"mt-1.5 space-y-1 text-[12px]",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Date"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:b})]}),l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Date & time"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:y})]}),l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Currency"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:g})]})]})]}),l.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Currency values are not converted. Date examples use a fixed reference value and the Gregorian calendar."})]})}const RO=new Set;function yye(e){return RO.add(e),()=>{RO.delete(e)}}function MB(){RO.forEach(e=>{e()})}var F_t=Object.defineProperty,P_t=(e,t,n)=>t in e?F_t(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,D1=(e,t,n)=>P_t(e,typeof t!="symbol"?t+"":t,n);const O_t={stringify:e=>e?"true":"false",parse:e=>/^[ty1-9]/i.test(e)},L_t={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{if(typeof window<"u"&&e in window)return window[e];if(typeof global<"u"&&e in global)return global[e]})();return typeof r=="function"?r.bind(n):void 0}},$_t={stringify:e=>JSON.stringify(e),parse:e=>JSON.parse(e)};function z_t(e){return e.replace(/([a-z0-9])([A-Z])/g,(t,n,r)=>`${n}-${r.toLowerCase()}`)}function vye(e){return e.replace(/[-:]([a-z])/g,(t,n)=>`${n.toUpperCase()}`)}const B_t={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{const o=vye(t);if(typeof n<"u"&&o in n.container)return n.container[o]})();return typeof r=="function"?r.bind(n):void 0}},V_t={stringify:e=>`${e}`,parse:e=>parseFloat(e)},H_t={stringify:e=>e,parse:e=>e},pR={string:H_t,number:V_t,boolean:O_t,function:L_t,method:B_t,json:$_t},vy=Symbol.for("r2wc.render"),E1=Symbol.for("r2wc.connected"),Uf=Symbol.for("r2wc.context"),zi=Symbol.for("r2wc.props");function q_t(e,t,n){var r,o,s;t.props||(t.props=e.propTypes?Object.keys(e.propTypes):[]),t.events||(t.events=[]);const i=Array.isArray(t.props)?t.props.slice():Object.keys(t.props),a=Array.isArray(t.events)?t.events.slice():Object.keys(t.events),c={},u={},d={},f={};for(const p of i){c[p]=Array.isArray(t.props)?"string":t.props[p];const g=z_t(p);d[p]=g,f[g]=p}for(const p of a)u[p]=Array.isArray(t.events)?{}:t.events[p];class h extends HTMLElement{constructor(){super(),D1(this,s,!0),D1(this,o),D1(this,r,{}),D1(this,"container"),t.shadow?this.container=this.attachShadow({mode:t.shadow}):this.container=this,this[zi].container=this.container;for(const g of i){const x=d[g],b=this.getAttribute(x),y=c[g],C=y?pR[y]:null;if(y==="method"){const w=vye(x);Object.defineProperty(this[zi].container,w,{enumerable:!0,configurable:!0,get(){return this[zi][w]},set(N){this[zi][w]=N,this[vy]()}}),this[zi][g]=C.parse(b,x,this)}C!=null&&C.parse&&b&&(this[zi][g]=C.parse(b,x,this))}for(const g of a)this[zi][g]=x=>{const b=g.replace(/^on/,"").toLowerCase();this.dispatchEvent(new CustomEvent(b,{detail:x,...u[g]}))}}static get observedAttributes(){return Object.keys(f)}connectedCallback(){this[E1]=!0,this[vy]()}disconnectedCallback(){this[E1]=!1,this[Uf]&&n.unmount(this[Uf]),delete this[Uf]}attributeChangedCallback(g,x,b){const y=f[g],C=c[y],w=C?pR[C]:null;y in c&&w!=null&&w.parse&&b&&(this[zi][y]=w.parse(b,g,this),this[vy]())}[(s=E1,o=Uf,r=zi,vy)](){this[E1]&&(this[Uf]?n.update(this[Uf],this[zi]):this[Uf]=n.mount(this.container,e,this[zi]))}}for(const p of i){const g=d[p],x=c[p];Object.defineProperty(h.prototype,p,{enumerable:!0,configurable:!0,get(){return this[zi][p]},set(b){this[zi][p]=b;const y=x?pR[x]:null;if(y!=null&&y.stringify){const C=y.stringify(b,g,this);this.getAttribute(g)!==C&&this.setAttribute(g,C)}else this[vy]()}})}return h}function U_t(e,t,n){const r=Gye.createRoot(e),o=v.createElement(t,n);return r.render(o),{root:r,ReactComponent:t}}function K_t({root:e,ReactComponent:t},n){const r=v.createElement(t,n);e.render(r)}function W_t({root:e}){e.unmount()}function G_t(e,t={}){return q_t(e,t,{mount:U_t,update:K_t,unmount:W_t})}const Y_t={id:"string",version:"string",authToken:"json",placeholders:"json",defaultFilterValues:"json",defaultControlValues:"json",controlContractOverrides:"json",documentInputValues:"json",dashboardInputExecutionSnapshot:"json",interactionExecutionSnapshot:"json",presentationExecutionSnapshot:"json",renderMode:"string",currentTheme:"string",customCards:"json",customStyle:"json",appearance:"json",onChartElementClicked:"function",onFilterValuesChange:"function",onEvent:"function",onDashboardLifecycleEvent:"function",onSave:"function",LoadingComponent:"function",ErrorComponent:"function",showAssistant:"boolean",showBriefings:"boolean",selectedSheetId:"string",eventHandlers:"json",preferences:"json"},Z_t=G_t(gye,{props:Y_t}),X_t=v.memo(function({context:t="editor"}={}){return l.jsxs("div",{"data-content":"fields-section",className:"flex h-full grow flex-col items-center overflow-hidden",children:[" ",l.jsx($4,{context:t})," "]})});var wye="Toggle",Cye=ie.forwardRef((e,t)=>{const{pressed:n,defaultPressed:r,onPressedChange:o,...s}=e,[i,a]=m.useControllableState({prop:n,onChange:o,defaultProp:r??!1,caller:wye});return l.jsx(m.Primitive.button,{type:"button","aria-pressed":i,"data-state":i?"on":"off","data-disabled":e.disabled?"":void 0,...s,ref:t,onClick:m.composeEventHandlers(e.onClick,()=>{e.disabled||a(!i)})})});Cye.displayName=wye;var Sye=Cye;const Q_t=m.cva("inline-flex items-center justify-center rounded-control text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}}),Nye=ie.forwardRef(({className:e,variant:t,size:n,...r},o)=>l.jsx(Sye,{ref:o,className:m.cn(Q_t({variant:t,size:n,className:e})),...r}));Nye.displayName=Sye.displayName;function RB(){var c,u;const e=m.useEditorStore(d=>d.card),t=m.useEditorStore(d=>d.frame),n=v.useMemo(()=>rt.findCustomVisualConfigCard(t,e),[t,e]),{manifest:r}=Sf(((c=n==null?void 0:n.customCardPreferences)==null?void 0:c.url)||""),o=v.useMemo(()=>{var d;return(d=r==null?void 0:r.visuals)==null?void 0:d.find(f=>{var h;return f.name===((h=n==null?void 0:n.customCardPreferences)==null?void 0:h.componentName)})},[r,(u=n==null?void 0:n.customCardPreferences)==null?void 0:u.componentName]),s=rt.resolveMultiInputType(n,o),i=v.useMemo(()=>rt.getCustomVisualInputCards({frame:t,configCard:n,isMultiInputVisual:s==="multiple"}),[t,n,s]),a=v.useMemo(()=>{const d=i.findIndex(f=>(f==null?void 0:f.id)===e.id);return d<0?-1:rt.getSlotIndexForCard(e,d)},[i,e]);return v.useMemo(()=>!n||s!=="multiple"||a<0?e.type:rt.getEffectiveCardTypeForSlot(e,a,o==null?void 0:o.slots)??e.type,[n,s,a,e,o==null?void 0:o.slots])}function jye({storeValue:e,defaultValue:t="",onStoreUpdate:n,delay:r=300}){const[o,s]=v.useState(e??t),i=v.useRef(null),a=v.useRef(o),c=v.useRef(e),u=v.useRef(!1),d=v.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null),u.current&&a.current!==(c.current??t)&&(n(a.current),c.current=a.current)},[t,n]);v.useEffect(()=>{if(e!==c.current){i.current&&(clearTimeout(i.current),i.current=null);const h=e??t;s(h),a.current=h,c.current=e,u.current=!1}},[e,t]),v.useEffect(()=>{if(u.current)return i.current=setTimeout(()=>{d()},r),()=>{i.current&&(clearTimeout(i.current),i.current=null)}},[r,d,o]),v.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const f=v.useCallback(h=>{const p=h??t;u.current=!0,a.current=p,s(p)},[t]);return{value:o,onChange:f,flush:d}}const J_t=300;function eTt({onExpand:e},t){const n=m.useEditorStore(w=>w.card.sql),r=m.useEditorStore(w=>w.sqlGen),o=m.useEditorStore(w=>w.card),s=RB(),{setCardSql:i,setSqlGen:a,setRunSql:c}=m.useEditorActions(),u=v.useMemo(()=>s!==o.type?{...o,type:s}:o,[o,s]),{queryKey:d}=Ax(u),f=Hr(),h=v.useRef(d);h.current=d;const p=v.useRef(r);p.current=r;const g=v.useCallback(w=>{i(w)},[i]),{value:x,onChange:b,flush:y}=jye({storeValue:n,defaultValue:"",onStoreUpdate:g,delay:J_t});v.useEffect(()=>yye(y),[y]);function C(w){b(w),m.isObjectEmpty(p.current)||a({})}return l.jsxs("div",{className:"relative h-full w-full",children:[l.jsx(m.CodeEditor,{ref:t,value:x??"",onValueChange:C,language:"sql-jinja",embedded:!0,hideLineNumbers:!0,wrapLines:!0,placeholder:"Write your SQL here",onKeyDown:w=>{w.key==="Enter"&&w.shiftKey&&(w.preventDefault(),MB(),setTimeout(()=>{f.removeQueries({queryKey:h.current,exact:!0}),c(!0)},0))}}),e?l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"absolute right-2.5 top-2 z-20 h-7 w-7 bg-background/80 p-0 text-muted-foreground backdrop-blur-sm transition-colors hover:bg-accent hover:text-foreground focus-visible:text-foreground",onClick:e,"aria-label":"Expand SQL editor",title:"Expand SQL editor",children:l.jsx(Ft.Maximize2,{className:"h-3.5 w-3.5",strokeWidth:1.75})}):null]})}const tTt=v.forwardRef(eTt),nTt=300;function rTt(e,t){const n=m.useEditorStore(g=>g.card.python),r=m.useEditorStore(g=>g.card),o=RB(),{setCardPython:s,setRunSql:i}=m.useEditorActions(),a=v.useMemo(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:c}=Ax(a),u=Hr(),d=v.useRef(c);d.current=c;const{value:f,onChange:h,flush:p}=jye({storeValue:n,defaultValue:rt.PYTHON_DEFAULT_CODE,onStoreUpdate:s,delay:nTt});return v.useEffect(()=>yye(p),[p]),l.jsx(m.CodeEditor,{ref:t,value:f??"",onValueChange:h,language:"python",embedded:!0,hideLineNumbers:!0,wrapLines:!0,className:"[&_.code-editor-pre]:!pt-2 [&_.code-editor-textarea]:!pt-2",onKeyDown:g=>{g.key==="Enter"&&g.shiftKey&&(g.preventDefault(),MB(),setTimeout(()=>{u.removeQueries({queryKey:d.current,exact:!0}),i(!0)},0))}})}const oTt=v.forwardRef(rTt),kye=new Set(["askForMoreInfo","getAvailableChartTypes","getChartSQLSyntax","getDomainRelationships","getTableColumns","getUserSql","validateCardConfigFormat"]),sTt=new Set(["createChartFromSql","createForecast","generateQueryConfig","getChartDataFromCardConfig","getChartDataFromSqlAndPython","getForecastDataFromSqlAndPython"]),iTt=Array.from(kye).join(", "),aTt=3,lTt="Self-heal",cTt=new Set(["SQL_PARSE_ERROR","SQL_EXPLAIN_ERROR"]);function uTt({card:e}){var $,P,U,H,G;const t=yc(),[n,r]=v.useState({}),{authToken:o}=Mt(),s=m.getTokenParams(o==null?void 0:o.accessToken),{compiledAppearance:i}=fi.useAppearance(),a=v.useMemo(()=>tC(i),[i]),c=m.useEditorStore(q=>q.frame),u=m.useEditorStore(q=>q.inlineFilterValuesMap[e.id]),d=m.useEditorStore(q=>q.actions.setCardInlineFilterValue),f=m.useEditorStore(q=>q.actions.removeCardInlineFilterValue),h=e,{getCard:p,manifest:g}=Sf((($=h.customCardPreferences)==null?void 0:$.url)||""),x=(P=g==null?void 0:g.visuals)==null?void 0:P.find(q=>{var Y;return q.name===((Y=h.customCardPreferences)==null?void 0:Y.componentName)}),b=rt.resolveMultiInputType(h,x)??"single",y=v.useMemo(()=>rt.getCustomVisualInputCards({frame:c,configCard:h,isMultiInputVisual:b==="multiple"}),[c,h,b]),C=v.useMemo(()=>{const q=y.findIndex(Y=>(Y==null?void 0:Y.id)===e.id);return q<0?-1:rt.getSlotIndexForCard(e,q)},[y,e]),w=v.useMemo(()=>b!=="multiple"||C<0?e.type:rt.getEffectiveCardTypeForSlot(e,C,x==null?void 0:x.slots)??e.type,[b,C,e,x==null?void 0:x.slots]),N=v.useMemo(()=>b==="multiple"?{...e,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:w!==e.type?{...e,type:w}:e,[e,w,b]),{data:S,effectiveCardConfig:j}=Ax(N),k=m.useInteractionStore(q=>q.interactionStates),_=m.useDashboardStore(q=>{var Y;return(Y=q.dashboard)==null?void 0:Y.id}),T=m.useDashboardStore(q=>q.dashboard.filters),I=m.useDashboardStore(q=>q.filterValues),D=m.useDashboardStore(q=>q.selectedSheetId),E=v.useMemo(()=>pz({card:e,sheetId:D||"",inlineFilterValues:u,setInlineFilterValue:q=>d(e.id,q),removeInlineFilterValue:q=>f(e.id,q)}),[e,D,u,d,f]),{cardFilters:R,cardFilterValues:F}=v.useMemo(()=>zI({card:e,interactionStates:k,currentDashboardId:_,filters:T,filterValues:I,selectedSheetId:D}),[e,k,_,T,I,D]),M=v.useCallback((q,Y)=>{const W=rt.normalizeMultiInputPayload(Y);r(ne=>({...ne,[q]:W}))},[]),O=(U=h.customCardPreferences)==null?void 0:U.componentName,z=O?p(O):null,L=sk((H=h.customCardPreferences)==null?void 0:H.settings,h),V=v.useMemo(()=>rt.buildSlotOrderedCards(y),[y]),A=v.useMemo(()=>V.map((q,Y)=>rt.getEffectiveCardTypeForSlot(q,Y,x==null?void 0:x.slots)),[V,x==null?void 0:x.slots]),B=v.useMemo(()=>bz(b==="multiple"?xz({slotOrderedCards:V,multiInputData:n,valueFormatPreferences:t}):[{card:e,cardConfig:j,columns:S==null?void 0:S.columns,columnKeyMap:S==null?void 0:S.columnKeyMap,valueFormatPreferences:t}]),[e,S==null?void 0:S.columnKeyMap,S==null?void 0:S.columns,j,n,V,b,t]);return O?l.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:l.jsxs(v.Suspense,{fallback:l.jsx(l.Fragment,{}),children:[z&&b==="single"&&l.jsx(z,{editing:!0,params:s,theme:a,settings:L,cardMetadata:rde({card:e,dataMetadata:S==null?void 0:S.metadata}),onDataChange:M,data:(S==null?void 0:S.records)||[],columns:(S==null?void 0:S.columns)||[],formatTemporalBucketValue:B,filters:R,filterValues:[...F||[],...u||[]],inlineFilters:E}),z&&b==="multiple"&&l.jsxs(l.Fragment,{children:[y.map((q,Y)=>{if(!q)return null;const W=rt.getSlotIndexForCard(q,Y),ne=rt.getEffectiveCardTypeForSlot(q,W,x==null?void 0:x.slots);return l.jsx(L$,{onDataChange:M,card:q,effectiveCardType:ne},`${q.id}-${W}`)}),l.jsx("div",{className:"flex flex-col gap-2",children:l.jsx(z,{editing:!0,onDataChange:M,...gz({configCard:h,slotOrderedCards:V,slotTypes:A,multiInputData:n,params:s,theme:a,chartSettings:L,filters:R,filterValues:[...F||[],...u||[]],inlineFilters:E,formatTemporalBucketValue:B})})})]})]},(G=h.customCardPreferences)==null?void 0:G.componentName)}):null}const dTt=v.memo(uTt),fTt=m.create()(m.persist((e,t)=>({starredCharts:[],isStarred:(n,r)=>t().starredCharts.some(o=>o.type===n&&o.id===r),toggleStar:n=>{e(r=>{const o=r.starredCharts.findIndex(s=>s.type===n.type&&s.id===n.id);return o>=0?{starredCharts:r.starredCharts.filter((s,i)=>i!==o)}:{starredCharts:[...r.starredCharts,n]}})},getStarredChart:(n,r)=>t().starredCharts.find(o=>o.type===n&&o.id===r)}),{name:"semaphor-starred-charts"}));var Iye=["PageUp","PageDown"],_ye=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Tye={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Db="Slider",[AO,hTt,mTt]=m.createCollection(Db),[Dye]=m.createContextScope(Db,[mTt]),[pTt,aD]=Dye(Db),Eye=ie.forwardRef((e,t)=>{const{name:n,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:u=[r],value:d,onValueChange:f=()=>{},onValueCommit:h=()=>{},inverted:p=!1,form:g,...x}=e,b=ie.useRef(new Set),y=ie.useRef(0),w=i==="horizontal"?gTt:xTt,[N=[],S]=m.useControllableState({prop:d,defaultProp:u,onChange:D=>{var R;(R=[...b.current][y.current])==null||R.focus(),f(D)}}),j=ie.useRef(N);function k(D){const E=CTt(N,D);I(D,E)}function _(D){I(D,y.current)}function T(){const D=j.current[y.current];N[y.current]!==D&&h(N)}function I(D,E,{commit:R}={commit:!1}){const F=kTt(s),M=ITt(Math.round((D-r)/s)*s+r,F),O=m.clamp(M,[r,o]);S((z=[])=>{const L=vTt(z,O,E);if(jTt(L,c*s)){y.current=L.indexOf(O);const V=String(L)!==String(z);return V&&R&&h(L),V?L:z}else return z})}return l.jsx(pTt,{scope:e.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:y,thumbs:b.current,values:N,orientation:i,form:g,children:l.jsx(AO.Provider,{scope:e.__scopeSlider,children:l.jsx(AO.Slot,{scope:e.__scopeSlider,children:l.jsx(w,{"aria-disabled":a,"data-disabled":a?"":void 0,...x,ref:t,onPointerDown:m.composeEventHandlers(x.onPointerDown,()=>{a||(j.current=N)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:k,onSlideMove:a?void 0:_,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&I(r,0,{commit:!0}),onEndKeyDown:()=>!a&&I(o,N.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:E})=>{if(!a){const M=Iye.includes(D.key)||D.shiftKey&&_ye.includes(D.key)?10:1,O=y.current,z=N[O],L=s*M*E;I(z+L,O,{commit:!0})}}})})})})});Eye.displayName=Db;var[Mye,Rye]=Dye(Db,{startEdge:"left",endEdge:"right",size:"width",direction:1}),gTt=ie.forwardRef((e,t)=>{const{min:n,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:u,...d}=e,[f,h]=ie.useState(null),p=m.useComposedRefs(t,w=>h(w)),g=ie.useRef(void 0),x=m.useDirection(o),b=x==="ltr",y=b&&!s||!b&&s;function C(w){const N=g.current||f.getBoundingClientRect(),S=[0,N.width],k=AB(S,y?[n,r]:[r,n]);return g.current=N,k(w-N.left)}return l.jsx(Mye,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:l.jsx(Aye,{dir:x,"data-orientation":"horizontal",...d,ref:p,style:{...d.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:w=>{const N=C(w.clientX);i==null||i(N)},onSlideMove:w=>{const N=C(w.clientX);a==null||a(N)},onSlideEnd:()=>{g.current=void 0,c==null||c()},onStepKeyDown:w=>{const S=Tye[y?"from-left":"from-right"].includes(w.key);u==null||u({event:w,direction:S?-1:1})}})})}),xTt=ie.forwardRef((e,t)=>{const{min:n,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...u}=e,d=ie.useRef(null),f=m.useComposedRefs(t,d),h=ie.useRef(void 0),p=!o;function g(x){const b=h.current||d.current.getBoundingClientRect(),y=[0,b.height],w=AB(y,p?[r,n]:[n,r]);return h.current=b,w(x-b.top)}return l.jsx(Mye,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1,children:l.jsx(Aye,{"data-orientation":"vertical",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const b=g(x.clientY);s==null||s(b)},onSlideMove:x=>{const b=g(x.clientY);i==null||i(b)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:x=>{const y=Tye[p?"from-bottom":"from-top"].includes(x.key);c==null||c({event:x,direction:y?-1:1})}})})}),Aye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...u}=e,d=aD(Db,n);return l.jsx(m.Primitive.span,{...u,ref:t,onKeyDown:m.composeEventHandlers(e.onKeyDown,f=>{f.key==="Home"?(i(f),f.preventDefault()):f.key==="End"?(a(f),f.preventDefault()):Iye.concat(_ye).includes(f.key)&&(c(f),f.preventDefault())}),onPointerDown:m.composeEventHandlers(e.onPointerDown,f=>{const h=f.target;h.setPointerCapture(f.pointerId),f.preventDefault(),d.thumbs.has(h)?h.focus():r(f)}),onPointerMove:m.composeEventHandlers(e.onPointerMove,f=>{f.target.hasPointerCapture(f.pointerId)&&o(f)}),onPointerUp:m.composeEventHandlers(e.onPointerUp,f=>{const h=f.target;h.hasPointerCapture(f.pointerId)&&(h.releasePointerCapture(f.pointerId),s(f))})})}),Fye="SliderTrack",Pye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=aD(Fye,n);return l.jsx(m.Primitive.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:t})});Pye.displayName=Fye;var FO="SliderRange",Oye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=aD(FO,n),s=Rye(FO,n),i=ie.useRef(null),a=m.useComposedRefs(t,i),c=o.values.length,u=o.values.map(h=>zye(h,o.min,o.max)),d=c>1?Math.min(...u):0,f=100-Math.max(...u);return l.jsx(m.Primitive.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...e.style,[s.startEdge]:d+"%",[s.endEdge]:f+"%"}})});Oye.displayName=FO;var PO="SliderThumb",Lye=ie.forwardRef((e,t)=>{const n=hTt(e.__scopeSlider),[r,o]=ie.useState(null),s=m.useComposedRefs(t,a=>o(a)),i=ie.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return l.jsx(bTt,{...e,ref:s,index:i})}),bTt=ie.forwardRef((e,t)=>{const{__scopeSlider:n,index:r,name:o,...s}=e,i=aD(PO,n),a=Rye(PO,n),[c,u]=ie.useState(null),d=m.useComposedRefs(t,C=>u(C)),f=c?i.form||!!c.closest("form"):!0,h=m.useSize(c),p=i.values[r],g=p===void 0?0:zye(p,i.min,i.max),x=wTt(r,i.values.length),b=h==null?void 0:h[a.size],y=b?STt(b,g,a.direction):0;return ie.useEffect(()=>{if(c)return i.thumbs.add(c),()=>{i.thumbs.delete(c)}},[c,i.thumbs]),l.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${y}px)`},children:[l.jsx(AO.ItemSlot,{scope:e.__scopeSlider,children:l.jsx(m.Primitive.span,{role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":i.min,"aria-valuenow":p,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:d,style:p===void 0?{display:"none"}:e.style,onFocus:m.composeEventHandlers(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),f&&l.jsx($ye,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:p},r)]})});Lye.displayName=PO;var yTt="RadioBubbleInput",$ye=ie.forwardRef(({__scopeSlider:e,value:t,...n},r)=>{const o=ie.useRef(null),s=m.useComposedRefs(o,r),i=m.usePrevious(t);return ie.useEffect(()=>{const a=o.current;if(!a)return;const c=window.HTMLInputElement.prototype,d=Object.getOwnPropertyDescriptor(c,"value").set;if(i!==t&&d){const f=new Event("input",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),l.jsx(m.Primitive.input,{style:{display:"none"},...n,ref:s,defaultValue:t})});$ye.displayName=yTt;function vTt(e=[],t,n){const r=[...e];return r[n]=t,r.sort((o,s)=>o-s)}function zye(e,t,n){const s=100/(n-t)*(e-t);return m.clamp(s,[0,100])}function wTt(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function CTt(e,t){if(e.length===1)return 0;const n=e.map(o=>Math.abs(o-t)),r=Math.min(...n);return n.indexOf(r)}function STt(e,t,n){const r=e/2,s=AB([0,50],[0,r]);return(r-s(t)*n)*n}function NTt(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function jTt(e,t){if(t>0){const n=NTt(e);return Math.min(...n)>=t}return!0}function AB(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function kTt(e){return(String(e).split(".")[1]||"").length}function ITt(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}var Bye=Eye,_Tt=Pye,TTt=Oye,DTt=Lye;const Vye=ie.forwardRef(({className:e,...t},n)=>l.jsxs(Bye,{ref:n,className:m.cn("relative flex w-full touch-none select-none items-center",e),...t,children:[l.jsx(_Tt,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:l.jsx(TTt,{className:"absolute h-full bg-primary"})}),l.jsx(DTt,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));Vye.displayName=Bye.displayName;exports.Accordion=ope;exports.AccordionContent=Lk;exports.AccordionItem=Pk;exports.AccordionTrigger=Ok;exports.AddDataPicker=vB;exports.AggregateTable=z_;exports.Alert=DL;exports.AlertDescription=EL;exports.AlertDialog=ff;exports.AlertDialogAction=Au;exports.AlertDialogCancel=Fu;exports.AlertDialogContent=Tu;exports.AlertDialogDescription=Ru;exports.AlertDialogFooter=Eu;exports.AlertDialogHeader=Du;exports.AlertDialogTitle=Mu;exports.AlertDialogTrigger=t1e;exports.AlertTitle=Yte;exports.ArrowDown=No;exports.ArrowDownIcon=OQe;exports.ArrowLeft=ow;exports.ArrowRight=sw;exports.ArrowUp=cs;exports.ArrowUpIcon=$Qe;exports.AssistantContextEntityControls=TO;exports.AssistantVirtualizedMessages=lye;exports.AxisConfigurator=Zm;exports.BackgroundRunPill=jut;exports.Badge=ki;exports.Bell=F1;exports.BookType=OZ;exports.BriefingAuthor=$he;exports.BriefingAuthorDialog=zhe;exports.BriefingUiCapabilitiesBoundary=Wut;exports.BriefingUiCapabilitiesProvider=IT;exports.BriefingsApiError=uC;exports.BulletChartIcon=eye;exports.CSS=Pi;exports.CalculatedFieldEditor=ape;exports.Calculator=$Z;exports.Calendar=Ya;exports.CalendarClock=ZO;exports.Card=FN;exports.CardContent=YO;exports.CardHeader=GO;exports.CardSummary=AP;exports.CardTitle=Ix;exports.ChartArea=BR;exports.ChartColumnIncreasing=BZ;exports.ChartColumnStacked=VZ;exports.ChartJsVisual=Yw;exports.ChartLine=HZ;exports.ChartNoAxesGantt=UZ;exports.ChartPie=KZ;exports.ChartScatter=WZ;exports.ChatInputWithContext=IB;exports.Checkbox=jn;exports.ChevronLeft=Om;exports.ChevronsUpDown=ZZ;exports.Circle=XO;exports.CircleAlert=ea;exports.CircleCheck=XZ;exports.CircleHelp=QZ;exports.Clock=JZ;exports.CodeHighlighter=Od;exports.CodeXml=P1;exports.Collapsible=Nu;exports.CollapsibleContent=ku;exports.CollapsibleTrigger=ju;exports.ColorField=Na;exports.Command=CB;exports.CommandEmpty=NB;exports.CommandGroup=jB;exports.CommandInput=zbe;exports.CommandItem=kB;exports.CommandList=SB;exports.CommandSeparator=Bbe;exports.ComparisonMetadataBadge=dse;exports.Container=k5;exports.ControlDefaultValueEditor=Epe;exports.ControlDefinitionOptionsEditor=Dpe;exports.ControlIdInput=kpe;exports.ControlVisibilitySettings=Wgt;exports.Copy=gu;exports.CopyButton=Pd;exports.CopyPlus=VR;exports.Cross2Icon=HQe;exports.CustomFilterPopover=hz;exports.CustomScrollArea=$u;exports.DEFAULT_HEATMAP_CUSTOM_RANGE=goe;exports.Dashboard=gye;exports.DashboardCard=Uhe;exports.DashboardCreateDialogBase=HQ;exports.DashboardExportDialog=cye;exports.DashboardPlus=D_t;exports.DashboardWC=Z_t;exports.DataTableConditionalFormattingSettings=yge;exports.DataTablePagination=E_;exports.Database=ps;exports.DateRangePicker=lz;exports.DefaultChatTransport=uB;exports.Dialog=To;exports.DialogContent=bo;exports.DialogDescription=Ho;exports.DialogFooter=ll;exports.DialogHeader=$s;exports.DialogTitle=yo;exports.DialogTrigger=zQ;exports.DisplayFormatPreferencesFields=A_t;exports.DisplayPreferencesProvider=xT;exports.DndContext=Sb;exports.Donut=eX;exports.Download=ac;exports.DownloadPdf=uye;exports.DragOverlay=Cme;exports.DropdownMenu=Bo;exports.DropdownMenuCheckboxItem=ed;exports.DropdownMenuContent=_o;exports.DropdownMenuItem=ln;exports.DropdownMenuLabel=Zi;exports.DropdownMenuRadioGroup=FCe;exports.DropdownMenuRadioItem=hQ;exports.DropdownMenuSeparator=ii;exports.DropdownMenuSub=g5;exports.DropdownMenuSubContent=gI;exports.DropdownMenuSubTrigger=pI;exports.DropdownMenuTrigger=Vo;exports.EMPTY_DATA_SOURCE=jx;exports.Editable=ak;exports.EditableText=Di;exports.EditorCustomVisual=dTt;exports.Ellipsis=Ai;exports.EllipsisVertical=Lm;exports.ErrorBoundary=ui;exports.ExportDialog=Fw;exports.ExportError=Lx;exports.ExternalLink=$d;exports.EyeOff=uI;exports.Fallback=pT;exports.FallbackVisual=aC;exports.FeedbackCategory=lf;exports.FeedbackDialog=q0;exports.FieldOptionList=PT;exports.FieldsList=$4;exports.FieldsSection=X_t;exports.FileCode=tX;exports.FileText=li;exports.Filter=xu;exports.FilterComponent=uT;exports.FilterInfo=DP;exports.FilterOptionList=dz;exports.FilterableFieldsPanel=cpe;exports.GRIP_REVEAL_CLASS=Xze;exports.Grid3x3=HR;exports.GripVertical=Iu;exports.HEATMAP_PRESET_PALETTES=rF;exports.Hash=_x;exports.House=nX;exports.HoverCard=ep;exports.HoverCardContent=wu;exports.HoverCardTrigger=Yd;exports.INLINE_ALLOWED_READ_ONLY_TOOLS=kye;exports.INLINE_ALLOWED_TOOL_LIST=iTt;exports.INLINE_BLOCKED_MUTATING_TOOLS=sTt;exports.IconButton=ou;exports.Inbox=dI;exports.InfoHover=Az;exports.InlineFilterBar=Ade;exports.KPICard=tf;exports.KeyboardSensor=yC;exports.Layers=zm;exports.LayoutDashboard=zd;exports.Link=JO;exports.LoadingDots=Cu;exports.MAX_SELF_HEAL_ATTEMPTS=aTt;exports.Map=iX;exports.Markdown=s4;exports.MatrixCardView=$_;exports.MatrixStructuralTargets=zpe;exports.MdStackedLineChart=Qbe;exports.MultiInputEmptyRenderer=L$;exports.PanelResizeHandle=QT;exports.Pause=aX;exports.PenLine=KR;exports.Pencil=WR;exports.PendingMessagesDisplay=Vbe;exports.PersistedDynamicVisual=gT;exports.PiChartPolar=Gbe;exports.PivotTableTanstack=pb;exports.Placeholders=Wge;exports.Play=lX;exports.Plus=Ar;exports.PointerSensor=cp;exports.Progress=gB;exports.PythonEditor=oTt;exports.RECOVERABLE_SQL_ERROR_CODES=cTt;exports.Radar=cX;exports.RadioGroup=cc;exports.RadioGroupItem=Ms;exports.RefreshCw=Ma;exports.ResizableHandle=d0t;exports.ResizablePanel=pO;exports.ResizablePanelGroup=Kge;exports.ResourceEditDialog=vJ;exports.ResourceType=uo;exports.Rows3=uX;exports.RunCompletionBanner=kut;exports.SELF_HEAL_TIMELINE_STEP=lTt;exports.SeedQuestions=xbe;exports.SemaphorContext=J0;exports.SemaphorContextProvider=HO;exports.SemaphorQueryClient=uZ;exports.SemaphorReadyIndicator=EB;exports.SemaphorStyleWrapper=gb;exports.Send=t5;exports.SendHorizontal=dX;exports.Settings=n5;exports.Settings2=uf;exports.Share2=fX;exports.ShareDialog=yJ;exports.Sheet=O3;exports.SheetContent=M_;exports.SheetDescription=A_;exports.SheetHeader=ese;exports.SheetTitle=R_;exports.SheetTrigger=Eze;exports.Slider=Vye;exports.SortableContext=Nb;exports.Sparkles=Ov;exports.SqlEditor=tTt;exports.Square=o5;exports.SquarePen=r5;exports.Star=hX;exports.StructuralParticipantSelector=Ipe;exports.SummaryCard=IP;exports.TABLE_PRESENTATION_DEFAULT_STYLE=Ad;exports.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE=ka;exports.TableBody=hm;exports.TableCell=hr;exports.TableColumnVisibilitySettings=uge;exports.TableHead=Ni;exports.TableHeader=Wx;exports.TablePresentationSettings=fge;exports.TableRow=io;exports.TableSkeleton=Pz;exports.TableVisual=Zd;exports.Tag=mX;exports.TbChartBubble=Ybe;exports.TbChartFunnel=Zbe;exports.TbChartTreemap=Xbe;exports.TextCard=xx;exports.Textarea=qm;exports.TiSortNumerically=Jbe;exports.Toggle=Nye;exports.Tornado=pX;exports.Trash2=Ra;exports.TriangleAlert=Br;exports.TypeGlyph=mC;exports.UXProvider=DB;exports.Undo2=gX;exports.User=i5;exports.Users=fI;exports.UsersRound=a5;exports.VisualErrorState=bde;exports.Zap=GR;exports.applyBriefingFormPatch=I0;exports.applyMatrixEditorResult=Tse;exports.areContextEntitiesEqual=mr;exports.arrayMove=up;exports.briefingFormDraftToCreateRequest=PP;exports.briefingFormDraftToUpdateRequest=bfe;exports.briefingToFormDraft=cg;exports.briefingTone=Er;exports.buildCardControlUsageById=Ygt;exports.buildCustomCardTheme=tC;exports.buildDashboardControlUsageById=Ggt;exports.buildDashboardSheetsInputExecutionSnapshot=WO;exports.buildDashboardStructuralParticipantIdsByControlId=Ape;exports.buildFilterFieldMeta=LO;exports.buildFilterSemanticContext=$O;exports.buildInlineFilterNodes=pz;exports.buildMultiInputCustomVisualProps=gz;exports.buildMultiInputTemporalPresentationInputs=xz;exports.calculateCardFilterValues=$I;exports.calculateContextAwareFilters=zI;exports.canEditLocalCalculatedFields=O4;exports.canUserAccessVisuals=aNe;exports.canUserCreateDashboards=CJ;exports.canUserEdit=oNe;exports.canUserManageDashboards=iNe;exports.canUserManageGroups=lNe;exports.canUserUseFilters=sNe;exports.cancelBriefingPreviewRun=ife;exports.cancelBriefingRun=lfe;exports.cancelExport=sDe;exports.chartSupportsDataLabels=hre;exports.chartSupportsLegend=dre;exports.chartTypes=iD;exports.cleanupKpiMetricComparisonMode=Fme;exports.cloneLinkedFrameWithSourceMapping=Ctt;exports.closestCenter=wb;exports.commitSharedCalculatedFields=Jf;exports.compileDashboardCardFilters=gw;exports.createAssistantConversationId=Zp;exports.createAssistantRequestId=pbe;exports.createBriefing=Qde;exports.createBriefingFormDraft=FP;exports.createChartConfig=Ux;exports.createCustomVisualTemporalBucketFormatter=bz;exports.createDashboardControlInputFromControl=Qyt;exports.createExplicitDashboardInputTargetContext=Xle;exports.createExport=kL;exports.currencyPresentationTargetKey=Ta;exports.dedup=ijt;exports.dedupeContextEntities=h4;exports.deleteBriefing=tfe;exports.deleteBriefingRun=cfe;exports.describeDataSourceConnections=R3e;exports.diagnoseCurrencyPresentationBindings=p0e;exports.doesStoredFilterMatchField=qg;exports.downloadDocumentPdf=NL;exports.downloadPdf=jte;exports.extractTableMetadata=I4;exports.fieldAlreadyExists=Soe;exports.flexRender=_i;exports.flushPendingEditorDrafts=MB;exports.formatDisplayFormula=Cmt;exports.formatFileSize=lDe;exports.getAutoDetectedChartIcon=lIt;exports.getBriefing=Xde;exports.getBriefingArtifact=knt;exports.getBriefingEvidence=Int;exports.getBriefingPreviewRun=sfe;exports.getBriefingRun=afe;exports.getCalculatedGlyphKind=_4;exports.getCardCurrencyPresentationFields=bZ;exports.getCardCurrencyPresentationTargets=cI;exports.getChartGridStyle=mEe;exports.getChartIconByType=cIt;exports.getColorForValue=gA;exports.getCoreRowModel=__;exports.getDefaultAxisConfig=CA;exports.getDefaultChartColors=Ym;exports.getDefaultDataLabelsConfig=Dw;exports.getDefaultLegendConfig=s3;exports.getDefaultRunningTotalPartitionByFieldIds=Iv;exports.getDisplayedKpiResultColumnKeys=Rw;exports.getDocumentSectionEditorCard=Igt;exports.getDocumentSheetDashboardInputs=kb;exports.getDownloadUrl=oDe;exports.getEntityIcon=tI;exports.getErrorMessage=tbe;exports.getExportStatus=rDe;exports.getExports=nDe;exports.getExpressionFieldKind=nf;exports.getFieldDisplayLabel=fo;exports.getFieldExpressionAnnotation=T4;exports.getFieldStateCopy=N3;exports.getFilterCount=Oz;exports.getFilterOptionValueIdentity=qn;exports.getFilterSourceDatabase=zY;exports.getGranularityOptionsForFieldType=jpe;exports.getKeys=Sr;exports.getMetricDisplayLabel=P3e;exports.getNewField=_oe;exports.getPaginationRowModel=T_;exports.getRoleBasedDisplayOverrides=wJ;exports.getRunningTotalOrderByCandidates=amt;exports.getSelectedDateFilterColumn=Tue;exports.getSemanticDomainLabel=Ebe;exports.getSortedRowModel=Qoe;exports.getTableConditionalFormattingColumnOptions=mge;exports.getTableOutputColumnOptions=pge;exports.handleAggregationChange=EP;exports.handleAggregationLabelChange=Mde;exports.hasFlatTableTotalsBehavior=Gm;exports.horizontalListSortingStrategy=FT;exports.inferSemanticDomainIdFromSelectedEntities=eI;exports.isActiveBriefingRunStatus=bk;exports.isBlockedFieldState=fm;exports.isCardSummaryVisibleOnCard=yz;exports.isCurrencyPresentationControl=h0e;exports.isDefaultColor=pTe;exports.isDevPaginationSwitchableCard=Loe;exports.isEligibleFlatTableTotalsCard=ww;exports.isExportComplete=aDe;exports.isExportInProgress=iDe;exports.isInAiScopeArray=sjt;exports.isManagedCalculatedExpressionField=il;exports.isMetricTransformEnabled=smt;exports.isPresentationCurrencyBinding=nw;exports.isPromiseLike=kO;exports.isRuleReadyToApply=Yh;exports.isSqlBackedKpi=Toe;exports.isStructuralControlBinding=f0e;exports.isSubtotalEnabledAggregateTable=k4;exports.isSupportedDocumentTableCardType=_gt;exports.isTableNumericPresentationCardType=qO;exports.isTableType=JDe;exports.isTerminalBriefingRunStatus=xk;exports.lastAssistantMessageIsCompleteWithToolCalls=Xxe;exports.listBriefingRuns=jnt;exports.listBriefingTenantSummaries=Nnt;exports.listBriefings=Snt;exports.merge=sc;exports.mergeAxisConfig=SA;exports.normalizeConditionalFormatting=rL;exports.normalizeContextFormatMode=Qee;exports.pauseBriefing=Jde;exports.pivotData=Nw;exports.polishBriefingText=ufe;exports.prepareFeedbackData=sD;exports.previewBriefingPlan=rfe;exports.remarkGfm=c4;exports.removeFromScopeArray=ajt;exports.resolveCurrencyPresentationTargetFormat=nte;exports.resolveDashboardBriefingsVisibility=Bhe;exports.resolveDashboardControlsVisibility=fNe;exports.resolveDashboardTitleEditability=dNe;exports.resolveDomainCalculatedFieldForEdit=Ppt;exports.resolveMatrixCardMeasures=lI;exports.resolvePendingPivotTableResultState=c$e;exports.resolveTableConditionalFormatting=dL;exports.resolveTableFormattingColumns=ZI;exports.resolveTablePresentationStyle=K3;exports.resumeBriefing=efe;exports.runBriefingNow=nfe;exports.runBriefingPreview=ofe;exports.sanitizeAIScope=ebe;exports.saveCalculatedFieldToCardScope=sO;exports.saveCalculatedFieldToSharedScope=lpe;exports.saveCalculatedFieldToSheetScope=iO;exports.seedSemanticMetricFormatDefaults=Ome;exports.setTableColumnVisibility=Boe;exports.setupEditorWithCard=e_;exports.showAllTableColumns=T$e;exports.showJoinRequiredNotification=lF;exports.sortByColumnsToSortState=Cse;exports.sortStateToSortByColumns=Sse;exports.sortableKeyboardCoordinates=v4;exports.supportsLiveNumericPresentation=tw;exports.supportsMetricTransformForMetric=Pme;exports.supportsTableConditionalFormatting=hge;exports.toEntityArray=sl;exports.updateBriefing=yT;exports.useActiveExports=bNe;exports.useActiveToolStatus=qbe;exports.useAddFrameWithFreshSemanticExecutionPayload=Rz;exports.useAddNewFrame=Qhe;exports.useAssistantContainer=kJ;exports.useAssistantContextEntities=_T;exports.useAssistantLayoutStore=Rh;exports.useAssistantPanel=NJ;exports.useAssistantProfile=gbe;exports.useAutoSubmitQueue=Hbe;exports.useBrandStudioPreview=x_t;exports.useBriefingRunPolling=LP;exports.useBriefingUiCapabilities=Vhe;exports.useCalendarContext=q3e;exports.useCard=X3e;exports.useCardNumericPresentation=wl;exports.useCardQueryContext=k_;exports.useCardSummary=vz;exports.useChartNumericPresentation=Kx;exports.useChat=Jxe;exports.useColumns=C4;exports.useCreateVisualWithFrame=oSe;exports.useCurrentUserInfo=hi;exports.useCustomVisual=Sf;exports.useCustomVisualsQuery=fz;exports.useDashboardAppearance=Pu;exports.useDashboardById=wQ;exports.useDashboardInteractionMode=_de;exports.useDashboardPreferences=Vm;exports.useDashboardQuery=ew;exports.useDashboardStructuralParticipants=Ppe;exports.useDashboardSummary=ude;exports.useDataColumns=$me;exports.useDateFilterHook=dYe;exports.useDefaultDashboardMutation=pQ;exports.useDisplayPreferences=bl;exports.useDroppable=wme;exports.useEditorAside=OT;exports.useEditorCardQuery=Ax;exports.useEffectiveEditorCardType=RB;exports.useEnsureReactGlobals=Yle;exports.useExportActions=IJ;exports.useExportStore=jI;exports.useFieldAvailabilityContext=j4;exports.useFieldManagement=Lme;exports.useFilterOptionBrowse=B$;exports.useFilterableFields=N4;exports.useFullscreenAssistant=jJ;exports.useGroupMembers=i1e;exports.useGroups=N5;exports.useHasDashboardId=_J;exports.useInProgressExportsCount=yNe;exports.useManagementActions=Pm;exports.useManagementStore=Ls;exports.useMatrixEditorCatalog=Rme;exports.useMatrixEditorRefresh=ABe;exports.useMatrixSourceCatalog=Pw;exports.useMutation=Os;exports.usePivotTableConfig=Qm;exports.usePluginQuery=Vue;exports.useQuery=Yn;exports.useQueryClient=Hr;exports.useReactTable=D_;exports.useResolveExistingFrameSemanticExecutionPayload=ktt;exports.useResolvedDefaultCurrency=_3;exports.useResolvedTemporalStylePreferences=yc;exports.useResolvedValueFormatLocale=I3;exports.useResourceManagement=y5;exports.useResourceUpdateState=CQ;exports.useScopedFields=Mme;exports.useSelectedVisual=n0e;exports.useSemanticDomains=xB;exports.useSemaphorContext=Mt;exports.useSensor=Em;exports.useSensors=bC;exports.useSortable=dp;exports.useStarredChartsStore=fTt;exports.useSurfaceAppearance=xl;exports.useTableQueryState=fse;exports.useTextFilterHook=HUe;exports.useTheme=BY;exports.useTimezone=vl;exports.useTopoJson=Mw;exports.useUnifiedUsers=SI;exports.useUpdateResource=xQ;exports.useUpdateVisualMutation=sSe;exports.useUserPreferences=qQ;exports.useVisualById=bI;exports.useVisualManagement=rSe;exports.validateBriefingFormDraft=OP;exports.validateEntityConsistency=aF;exports.validateFieldForChartType=Ame;exports.verticalListSortingStrategy=y4;
1417
+ `).trim(),_=j.map((T,I)=>{var R,F;let D="",E;if((R=T.url)!=null&&R.startsWith("data:")){const M=T.url.match(/data:[^;]+;base64,(.+)/);M&&(D=M[1],(F=T.mediaType)!=null&&F.startsWith("image/")&&(E=T.url))}return{id:`${e.id||t}-file-${I}`,name:T.filename||`File ${I+1}`,size:0,type:T.mediaType||"application/octet-stream",data:D,preview:E}});return l.jsx(FIt,{text:k||void 0,files:_.length>0?_:void 0})}const f=((w=e.parts)==null?void 0:w.filter(S=>S.type==="reasoning"))||[],h=f.length>0,p=f.some(S=>S.state==="streaming"),g=f.filter(S=>S.text&&S.text.trim().length>0),x=h&&(g.length>0||p)?l.jsxs(Nu,{className:"space-y-2",defaultOpen:!1,children:[l.jsx(ju,{asChild:!0,children:l.jsxs("button",{type:"button",className:"group inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground",children:[l.jsx(Ft.ChevronRight,{className:"h-3 w-3 transition-transform duration-200 group-data-[state=open]:rotate-90"}),l.jsx("span",{className:p?"animate-pulse":"",children:p?"Reasoning":"Show reasoning"}),g.length>1&&l.jsxs("span",{className:"font-mono tabular-nums text-muted-foreground/70",children:["(",g.length," steps)"]})]})}),l.jsx(ku,{children:l.jsx("ol",{className:"space-y-2 border-l border-border/60 pl-3",children:g.map((S,j)=>l.jsxs("li",{className:"relative",children:[l.jsx("span",{className:"absolute -left-[15px] top-[3px] grid h-4 w-4 place-items-center rounded-full bg-muted font-mono text-[9px] text-muted-foreground",children:j+1}),l.jsx(uY,{className:"text-[12px] leading-[1.55] text-muted-foreground",text:S.text})]},`${e.id||t}-reasoning-${j}`))})})]},`${e.id||t}-reasoning`):null,b=(N=e.parts)==null?void 0:N.map((S,j)=>{var _;const k=`${e.id||t}-${j}`;switch(S.type){case"text":{const T=typeof S.text=="string"?S.text:JSON.stringify(S.text??"",null,2);if(e.role==="assistant"){const{cleanedText:I,quickReplies:D}=EIt(T),E=I.trim().length>0;return l.jsxs("div",{className:"space-y-2.5",children:[E&&l.jsx(uY,{text:I,handleRun:i,onAddToDashboard:o,messageId:e.id,messages:n}),D.length>0&&a&&d&&l.jsxs("div",{className:"space-y-1.5",children:[D.length>=3&&l.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Suggested next steps"}),l.jsx("div",{className:"flex flex-wrap gap-1",children:D.map(({label:R,value:F},M)=>l.jsxs(m.Tooltip,{children:[l.jsx(m.TooltipTrigger,{asChild:!0,children:l.jsx(m.Button,{size:"sm",variant:"outline",className:"h-6 max-w-[220px] rounded-control border-border/60 bg-background px-2 text-[11px] font-normal text-foreground/85 transition-colors hover:border-border hover:bg-muted/40 hover:text-foreground disabled:opacity-50",disabled:c,onClick:()=>a(F),children:l.jsx("span",{className:"truncate",children:R})})}),l.jsx(m.TooltipContent,{side:"top",align:"center",children:l.jsx("p",{className:"max-w-xs text-xs",children:F})})]},`${k}-qr-${M}`))})]})]},k)}return e.role==="system"&&s?l.jsx(PIt,{text:T},k):null}case"error":{const T=S,I=T.errorText??T.error??T.message;return l.jsx("div",{className:"my-4",children:l.jsx(TB,{errorMessage:I})},k)}case"reasoning":return null;default:return((_=S.type)!=null&&_.startsWith("tool-")||S.type==="dynamic-tool")&&_B(S,r)?l.jsx(ui,{FallbackComponent:({error:T,resetErrorBoundary:I})=>l.jsx(AIt,{error:T,resetErrorBoundary:I}),children:l.jsx(kIt,{part:S,idx:k,messageId:e.id,showTools:r,onAddToDashboard:o,messages:n})},k):null}});return e.role==="assistant"?aye(e,r)?l.jsxs(iye,{who:"Assistant",className:"space-y-2",children:[x,b]}):null:l.jsxs("div",{className:"space-y-2",children:[x,b]})}const zIt=8,BIt=24,VIt=20;function HIt(e,t,n,r){return e==="error"&&t?!0:r?!1:!!(n||e==="submitted"||e==="streaming")}function lye({messages:e,showTools:t=!1,showSystemMessage:n=!1,handleRun:r,onAddToDashboard:o,onQuickReply:s,disableQuickReplies:i=!1,status:a,errorMessage:c,activeToolText:u,className:d,rowContentClassName:f,statusClassName:h,latestButtonClassName:p,scrollToEndSignal:g=0}){const x=v.useRef(null),b=v.useRef(null),y=v.useRef(e.length),C=v.useRef(!1),w=v.useRef(null),N=v.useRef(!1),S=v.useRef(g),[j,k]=v.useState(!0),[_,T]=v.useState(0),[I,D]=v.useState(BIt);S.current!==g&&(S.current=g,N.current=!0);const E=e[e.length-1],R=aye(E,t),F=HIt(a,c,u,R),M=mm({count:e.length,getScrollElement:()=>x.current,estimateSize:V=>{const A=e[V];return(A==null?void 0:A.role)==="user"?88:180},getItemKey:V=>{const A=e[V];return(A==null?void 0:A.id)||`message-${V}`},anchorTo:"end",followOnAppend:!0,scrollEndThreshold:zIt,overscan:6,gap:20,paddingEnd:F?I+VIt:0,useAnimationFrameWithResizeObserver:!0,onChange:V=>{const A=V.isAtEnd();k(B=>B===A?B:A),A&&T(0)}}),O=v.useCallback((V="smooth")=>{w.current!==null&&cancelAnimationFrame(w.current),w.current=requestAnimationFrame(()=>{w.current=null,M.scrollToEnd({behavior:V})}),T(0),k(!0)},[M]);v.useLayoutEffect(()=>{C.current||(C.current=!0,O("auto"))},[O]),v.useLayoutEffect(()=>{N.current&&(N.current=!1,O("auto"))},[e.length,g,O]),v.useEffect(()=>{const V=y.current;y.current=e.length,e.length>V&&!M.isAtEnd()&&T(A=>A+e.length-V),e.length===0&&(T(0),k(!0),C.current=!1,N.current=!1)},[e.length,M]);const z=M.getVirtualItems(),L=M.getTotalSize();return v.useEffect(()=>()=>{w.current!==null&&cancelAnimationFrame(w.current)},[]),v.useLayoutEffect(()=>{const V=b.current;if(!V||!F)return;const A=()=>{const $=Math.ceil(V.getBoundingClientRect().height);$>0&&D(P=>P===$?P:$)};if(A(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(A);return B.observe(V),()=>B.disconnect()},[F,a,c,u]),l.jsxs(l.Fragment,{children:[l.jsx($u,{"data-role":"assistant-virtualized-scroll-area",ref:x,className:m.cn("min-h-0 min-w-0 flex-1 basis-0",d),children:l.jsxs("div",{className:"relative w-full",style:{height:L},children:[z.map(V=>{const A=e[V.index];return A?l.jsx("div",{ref:M.measureElement,"data-index":V.index,className:"absolute left-0 top-0 w-full",style:{transform:`translateY(${V.start}px)`},children:l.jsx("div",{className:m.cn("min-w-0",f),children:l.jsx($It,{message:A,messageIndex:V.index,messages:e,showTools:t,showSystemMessage:n,handleRun:r,onAddToDashboard:o,onQuickReply:s,disableQuickReplies:i})})},V.key):null}),F&&l.jsx("div",{ref:b,className:m.cn("absolute left-0 top-0 w-full",h),style:{transform:`translateY(${Math.max(L-I,0)}px)`},children:l.jsx("div",{className:m.cn("min-w-0",f),children:l.jsx(OIt,{status:a,errorMessage:c,activeToolText:u})})})]})}),!j&&l.jsxs("button",{type:"button",onClick:()=>O("smooth"),"aria-label":"Scroll to latest",className:m.cn("absolute right-4 z-10 inline-flex h-7 items-center gap-1.5 rounded-full border border-border bg-background px-2.5 text-[11px] text-foreground shadow-[0_1px_2px_rgba(0,0,0,0.08)] transition-colors hover:bg-muted/40",p),children:[l.jsx(No,{className:"h-3 w-3"}),"Latest",_>0&&l.jsx("span",{className:"grid h-4 min-w-[16px] place-items-center rounded-full bg-foreground px-1 font-mono text-[9px] tabular-nums text-background",children:_>9?"9+":_})]})]})}function qIt(e){if(typeof e=="string")return e;if(!e||typeof e!="object")return"";const t=e;return(typeof t.userSql=="string"?t.userSql:"")||(typeof t.sourceSql=="string"?t.sourceSql:"")||(typeof t.sql=="string"?t.sql:"")}const UIt=[{title:"Show top 3 insights",subtitle:"from this dataset"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function KIt({open:e,setOpen:t,isFullscreen:n,onFullscreenChange:r,fullscreenContainer:o}){const[s,i]=v.useState(!1),[a,c]=v.useState(lt.isDevEnv),[u,d]=v.useState(!1),[f,h]=v.useState("auto"),[p,g]=v.useState(!1),[x,b]=v.useState(!1),[y,C]=v.useState(0),w=n??x,{isLocalDev:N,isConsoleMode:S}=Vm(),j=N||S||a,k=v.useRef(null);m.useDashboardStore(me=>me.dashboard.aiScopeTables),m.useDashboardStore(me=>me.isDashboardEditing);const _=m.useDashboardStore(me=>me.selectedSheetId),{setDataSource:T}=m.useEditorActions(),{setSelectedFrameId:I,setIsDashboardEditing:D}=m.useDashboardActions(),E=Rz(),{clearAssistantMessageContexts:R}=m.useAIActions(),{clearQueue:F}=m.useQueueActions(),{clearFileAttachments:M,getFileAttachments:O}=m.useFileActions(),z=m.useFileAttachments("dashboard"),L=m.useEditorStore(me=>me.card.dataSource),{assistantProfile:V}=gbe(),A=m.useDashboardStore(me=>me.handleOpenAssistantProfile),{selectedEntities:B,applyDashboardDefaultEntities:$}=_T("dashboard"),{sendMessage:P,isLoading:U,messages:H,setMessages:G,status:q,stop:Y,errorMessage:W,clearError:ne}=jjt({dynamicVisualMode:f}),Z=v.useCallback(()=>{C(me=>me+1)},[]),K=v.useCallback(me=>{r==null||r(me),n===void 0&&b(me)},[n,r]),X=v.useCallback(()=>{K(!w)},[w,K]);v.useEffect(()=>{if(!w)return;function me(ve){ve.key==="Escape"&&K(!1)}return window.addEventListener("keydown",me),()=>{window.removeEventListener("keydown",me)}},[w,K]);const[J,re]=v.useState(""),te=me=>{re(me.target.value)};async function Q({sql:me,cardTitle:ve,connectionId:_e,cardType:De,python:Ue,cardConfig:Ne,dataSource:Oe,customVisualPreferences:ye,visualizationMode:Be,dynamicCardPreferences:he}){if(!_)return;const ue=Be==="dynamic",de=lt.hasValidCardConfig(Ne),Te=_e||(Oe==null?void 0:Oe.connectionId)||"",we=Oe?{...Oe,connectionId:Te||Oe.connectionId,connectionType:Oe.connectionType||"",mode:Oe.mode||"database",selectedEntities:Oe.selectedEntities||[]}:Te?{connectionId:Te,connectionType:"",mode:"database",selectedEntities:[]}:jx,Ke=!(de&&(!ue||(he==null?void 0:he.provenance)==="card-config"||(he==null?void 0:he.provenance)==="query_spec")),He=Ke?qIt(me):"",qe=Ke?Ue:"",Je={id:lt.v4(),title:ve||"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}],chartOptions:{indexAxis:De==="horizontalBar"?"y":"x"},...ue&&{displayOptions:{showChrome:!1,allowScroll:!1}}},type:De,sql:He,python:qe,dataSource:we,config:Ne,connectionId:Te,visualizationMode:Be,dynamicCardPreferences:he,customCardPreferences:ye?{url:ye.url,componentName:ye.componentName,pluginChartType:ye.pluginChartType,settings:ye.settings,type:"component"}:void 0},We={id:lt.v4(),cards:[Je],activeCardId:Je.id};try{await E(_,We,"end"),D(!0),I(We.id)}catch(bt){console.error("Failed to add assistant visual to dashboard:",bt),m.ue.error(bt instanceof Error?bt.message:"Failed to prepare semantic metadata for the new visual")}}const se=me=>{me.preventDefault();const ve=J.trim();if(!ve&&z.length===0)return;const _e=[];ve&&_e.push({type:"text",text:ve}),z.forEach(De=>{De.data&&_e.push({type:"file",mediaType:De.type,filename:De.name,url:`data:${De.type};base64,${De.data}`})}),P({role:"user",parts:_e}),re(""),M("dashboard"),Z()};v.useEffect(()=>{var me;e&&((me=k.current)==null||me.focus())},[e]),Hbe({assistantType:"dashboard",status:q,isLoading:U,sendMessage:P});const{hasActiveTools:oe,activeToolText:fe}=qbe(H);function pe(me){const ve={role:"user",parts:[{type:"text",text:me.title+" "+me.subtitle}]};P(ve),Z()}function xe(me){P({role:"user",parts:[{type:"text",text:me}]}),Z()}function Ie(me){P({role:"user",parts:[{type:"text",text:me}]}),Z()}const be=v.useCallback(async()=>{const me=JSON.stringify(H??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(me),m.ue.success("Conversation copied")}catch(ve){console.error("Failed to copy conversation",ve),m.ue.error("Unable to copy conversation")}},[H]),ge=(J==null?void 0:J.length)===0&&(H==null?void 0:H.filter(me=>me.role==="user").length)===0;function ee(){return l.jsx("div",{"data-role":"header",className:"flex items-center gap-2",children:l.jsx("span",{className:"text-[13px] font-medium text-foreground",children:"Assistant"})})}function ce(){return l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx(ou,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:l.jsx(Lm,{className:"size-3.5"})})}),l.jsxs(_o,{align:"end",children:[l.jsx(Zi,{children:"Options"}),l.jsx(ii,{}),l.jsx(ed,{checked:s,onCheckedChange:i,children:"Token Usage"}),l.jsx(ed,{checked:a,onCheckedChange:c,children:"Tool Invocations"}),l.jsx(ed,{checked:u,onCheckedChange:d,children:"System Message"}),(N||S)&&l.jsxs(l.Fragment,{children:[l.jsx(ii,{}),l.jsx(Zi,{children:"Dynamic Visuals"}),l.jsx(ed,{checked:f==="auto",onCheckedChange:()=>h("auto"),children:"Auto"}),l.jsx(ed,{checked:f==="force",onCheckedChange:()=>h("force"),children:"Force Dynamic"}),l.jsx(ed,{checked:f==="off",onCheckedChange:()=>h("off"),children:"Disable Dynamic"})]})]})]})}const ae=l.jsxs("div",{"data-role":"dashboard-assistant",className:m.cn("relative flex h-full grow flex-col break-words bg-background",w&&"rounded-card border border-border/60 shadow-xl"),children:[l.jsxs("header",{"data-role":"header-section",className:"flex h-10 shrink-0 items-center gap-2 border-b border-border/60 px-3",children:[ee(),A&&l.jsxs("button",{type:"button",onClick:A,className:"inline-flex h-6 items-center gap-1 rounded-[4px] border border-border/60 bg-muted/40 px-1.5 text-[11px] text-muted-foreground transition-colors hover:border-border hover:text-foreground",title:"Edit assistant profile",children:[l.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground/60"}),l.jsx("span",{className:"max-w-[180px] truncate",children:(V==null?void 0:V.name)||"Default profile"})]}),l.jsxs("div",{"data-role":"header-actions",className:"ml-auto flex items-center gap-0.5",children:[S&&ce(),j&&l.jsx(m.Button,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px] text-muted-foreground hover:text-foreground",onClick:be,children:"Copy Conversation"}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:w?"Exit fullscreen":"Expand",onClick:X,children:w?l.jsx(Ft.Minimize2,{className:"h-3.5 w-3.5"}):l.jsx(Ft.Maximize2,{className:"h-3.5 w-3.5"})}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:"New chat",onClick:()=>{const me=H.filter(ve=>ve.role==="assistant").map(ve=>ve.id).filter(ve=>!!ve);G([]),F("dashboard"),ne(),R(me)},children:l.jsx(r5,{className:"h-3.5 w-3.5"})}),l.jsx(ou,{className:"grid h-6 w-6 place-items-center rounded-[4px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",tooltip:"Close",onClick:()=>{t(!1)},children:l.jsx(Re.X,{className:"h-3.5 w-3.5"})})]})]}),l.jsx(lye,{messages:H,showTools:a,showSystemMessage:u,onAddToDashboard:Q,onQuickReply:Ie,disableQuickReplies:U,status:q,errorMessage:W,activeToolText:U&&oe?fe:void 0,className:m.cn(w?"px-6 py-5":"px-3 py-3"),rowContentClassName:m.cn(w&&"mx-auto w-full max-w-[680px]"),latestButtonClassName:e?"bottom-[148px]":"hidden",scrollToEndSignal:y}),l.jsxs("div",{className:"shrink-0 space-y-2 border-t border-border/60 px-3 pb-3 pt-2",children:[!V&&ge&&l.jsx(Wge,{onClick:pe,placeholders:UIt}),ge&&V&&l.jsx(xbe,{seedQuestions:V.seedQuestions||[],handleSeedQuestionClick:xe}),l.jsx(Vbe,{assistantType:"dashboard"}),l.jsx(IB,{ref:k,setInput:re,stop:Y,input:J,handleInputChange:te,handleSubmit:me=>{se(me)},isLoading:U,status:q,assistantType:"dashboard",onFocus:()=>{}})]}),l.jsx(vB,{incomingSelectedEntities:B,open:p,onOpenChange:g,dataSource:L||jx,dialogMode:"aiContext",saveAsDashboardDefault:!0,onSaveSelectedEntities:me=>$()})]});return w&&o?Mr.createPortal(l.jsx(gb,{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background/95 px-4 pb-4 pt-[calc(var(--app-header-height,15px)+0.5rem)] backdrop-blur-sm",children:l.jsx("div",{className:"flex h-full w-full",children:ae})}),o):ae}function WIt(e){const t=e.current,{getSelectedFrame:n,setSelectedFrameId:r}=m.useDashboardActions(),o=Ide(),s=m.useDashboardStore(d=>d.dashboard.sheets),a=m.useDashboardStore(d=>d.selectedSheetId)??(s==null?void 0:s[0].id),c=m.useDashboardStore(d=>d.isDashboardEditing),u=m.useDashboardStore(d=>d.isVisualEditing);v.useEffect(()=>{if(!c||u)return;async function d(p){if(GIt(p.target))return;const g=p.ctrlKey||p.metaKey;g&&p.key==="c"?(await f(),m.ue.success("Card copied to clipboard"),p.preventDefault()):g&&p.key==="v"&&(await h(),p.preventDefault())}async function f(){try{const p=n();p&&await navigator.clipboard.writeText(JSON.stringify(p))}catch(p){console.error("Failed to copy text:",p)}}async function h(){if(!a)return null;try{const p=await navigator.clipboard.readText(),g=YIt(p);if(g!=null&&g.id){const x=Nde(g),b=x.cards.findIndex(y=>y.id===x.activeCardId);b!==-1&&(x.cards[b].title=`${x.cards[b].title} (Copy)`),await o(a,x),r(x.id),m.ue.success("Card pasted from clipboard")}return p}catch(p){return console.error("Failed to paste text:",p),null}}return t==null||t.addEventListener("keydown",d),()=>t==null?void 0:t.removeEventListener("keydown",d)},[o,n,r,a,c,u,t])}function GIt(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;const t=e.closest("[contenteditable]");return t&&t.getAttribute("contenteditable")!=="false"?!0:!!e.closest('input, textarea, select, [role="textbox"]')}function YIt(e){try{const t=JSON.parse(e);return t&&typeof t=="object"&&typeof t.id=="string"&&Array.isArray(t.cards)?t:null}catch{return null}}function ZIt(e,t){switch(e.interactionMode){case"drillToDetail":XIt(e,t);break;case"drillThrough":QIt(e,t);break;case"drillToURL":JIt(e);break;case"inlineDrill":console.warn("Inline drill execution not yet implemented");break;case"clickFilter":case"drillDown":case"dynamicDrill":break;default:console.warn("Unknown interaction mode:",e.interactionMode)}}function XIt(e,t){var c;const{targetInsightId:n,contextMode:r,displayMode:o,filterGroups:s}=e;if(!n){console.warn("drillToDetail event missing targetInsightId");return}const i=r||"full";let a=[];switch(i){case"interactionFilters":a=s.flatMap(u=>u.filters);break;case"full":{const u=((c=t.getCurrentFilters)==null?void 0:c.call(t))||[],d=s.flatMap(f=>f.filters);a=[...u,...d];break}case"none":default:a=[];break}o==="replace-card"?t.replaceCardContent({cardId:e.sourceCardId,insightId:n,filters:a,contextMode:r}):t.openInsightModal({insightId:n,filters:a,contextMode:r})}function QIt(e,t){var u,d;const{targetDashboardId:n,contextMode:r="interactionFilters",filterGroups:o,sourceCardId:s}=e;if(!n){console.warn("[DrillThrough] Event missing targetDashboardId. This interaction needs to be reconfigured with a target dashboard.",e);return}const i=o.flatMap(f=>f.filters),a=((u=t.getCurrentDashboardId)==null?void 0:u.call(t))||"",c=(d=t.getCurrentDashboardTitle)==null?void 0:d.call(t);t.setGlobalDrillContext&&t.setGlobalDrillContext({filters:i,contextMode:r,sourceDashboardId:a,sourceDashboardTitle:c,targetDashboardId:n}),t.setPendingDrillThrough&&t.setPendingDrillThrough({targetDashboardId:n,sourceDashboardId:a,sourceDashboardTitle:c,filters:i,contextMode:r})}function JIt(e){const{url:t}=e;if(!t){console.warn("drillToURL event missing url");return}try{new URL(t)}catch(n){console.error("Invalid URL:",t,n);return}window.open(t,"_blank","noopener,noreferrer")}function e_t({open:e,onOpenChange:t,insightId:n,filters:r,filterDefinitions:o,contextMode:s,cardTitle:i,cardDescription:a}){return l.jsx(To,{open:e,onOpenChange:t,children:l.jsxs(bo,{className:"flex max-h-[90vh] max-w-[90vw] flex-col gap-0 overflow-hidden p-0",children:[l.jsxs($s,{className:"space-y-1 border-b border-border px-5 pb-3.5 pt-4 text-left",children:[l.jsx(yo,{className:"text-[15px] font-semibold tracking-tight",children:i||"Insight detail"}),l.jsx(Ho,{className:"text-[12px] leading-[1.5] text-muted-foreground",children:a||"View detailed insight data with applied filters"})]}),l.jsx(Rde,{filters:r,filterDefinitions:o,contextMode:s}),l.jsx("div",{className:"h-[400px] min-h-0 flex-1 overflow-auto px-5 py-4",children:n?l.jsx(Khe,{insightId:n,filters:r,contextMode:s}):l.jsx("div",{className:"flex items-center justify-center p-12 text-[13px] text-muted-foreground",children:"No insight selected"})})]})})}function t_t(){const e=m.useInteractionStore(N=>N.interactionStates),t=m.useInteractionStore(N=>N.setInteractionState),n=m.useInteractionStore(N=>N.clearLastInteractionEvent),r=m.useInteractionStore(N=>N.replaceCardWithInsight),o=m.useInteractionStore(N=>N.setPendingDrillThrough),s=m.useInteractionStore(N=>N.pendingDrillThrough),i=m.useInteractionStore(N=>N.clearPendingDrillThrough),{setSelectedSheetId:a,navigateWithDrill:c}=m.useDashboardActions(),{selectDashboard:u}=Pm(),d=m.useDashboardStore(N=>N.dashboard),f=m.useDashboardStore(N=>N.filterValues),{data:h,isLoading:p}=wQ((s==null?void 0:s.targetDashboardId)||"",{enabled:!!(s!=null&&s.targetDashboardId)}),[g,x]=v.useState({open:!1,insightId:""}),b=Whe(g.insightId,{enabled:g.open&&!!g.insightId}),y=v.useRef(new Set),C=v.useMemo(()=>({setSelectedSheetId:a,openInsightModal:({insightId:N,filters:S,contextMode:j})=>{x({open:!0,insightId:N,filters:S,filterDefinitions:(d==null?void 0:d.filters)||[],contextMode:j})},replaceCardContent:({cardId:N,insightId:S,filters:j,contextMode:k})=>{r(N,S,j,k)},getCurrentFilters:()=>f||[],navigateWithDrill:c,getCurrentDashboardId:()=>(d==null?void 0:d.id)||"",getCurrentDashboardTitle:()=>d==null?void 0:d.title,setPendingDrillThrough:o,setGlobalDrillContext:({filters:N,contextMode:S,sourceDashboardId:j,sourceDashboardTitle:k,targetDashboardId:_})=>{const T={filters:N},I={sourceCardId:m.DRILL_CONTEXT_CARD_ID,interactionMode:"clickFilter",filterGroups:[T]},D={...m.createInitialInteractionState(),appliedClickFilters:[I],contextMode:S,sourceDashboardId:j,sourceDashboardTitle:k,targetDashboardId:_};t(m.DRILL_CONTEXT_CARD_ID,D)}}),[a,r,f,c,d,o,t]);v.useEffect(()=>{Object.entries(e).forEach(([N,S])=>{if(S!=null&&S.lastInteractionEvent){const j=S.lastInteractionEvent,k=`${N}-${j.interactionMode}-${j.sourceCardId}-${Date.now()}`;if(y.current.has(k))return;y.current.add(k);try{ZIt(j,C)}catch(_){console.error("Error executing interaction event:",_)}finally{n(N),setTimeout(()=>{y.current.delete(k)},5e3)}}})},[e,n,C]),v.useEffect(()=>{if(!(!s||!h||p))try{u(h),c(s.targetDashboardId,s.sourceDashboardId,s.sourceDashboardTitle,s.filters,s.contextMode),i()}catch(N){console.error("[DrillThrough] Error during automatic navigation:",N),i()}},[s,h,p,u,c,i]);const w=()=>{x({open:!1,insightId:""})};return l.jsxs(l.Fragment,{children:[l.jsx(e_t,{open:g.open,onOpenChange:w,insightId:g.insightId,filters:g.filters,filterDefinitions:g.filterDefinitions,contextMode:g.contextMode,cardTitle:b.title,cardDescription:b.description}),s&&p&&l.jsx("div",{className:"fixed inset-0 z-[51] flex items-center justify-center bg-background/80 backdrop-blur-sm",children:l.jsxs("div",{className:"flex flex-col items-center gap-2.5 rounded-[6px] border border-border/60 bg-background px-4 py-3 shadow-sm",children:[l.jsx(m.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"}),l.jsx("div",{className:"text-[12px] text-muted-foreground",children:"Loading dashboard..."})]})})]})}function n_t(e){return e.length===0?"":e.map(t=>{const n=t.field.label||t.field.name,r=t.operator,o=r_t(Fz(t));return r==="="?`${n} = ${o}`:`${n} ${r} ${o}`}).join(", ")}function r_t(e){return e==null?"null":Array.isArray(e)?e.join(", "):typeof e=="object"&&e.toString?e.toString():String(e)}function o_t(e){return e?`Back to ${e}`:"Back"}function s_t(){var y,C,w,N,S;const e=m.useInteractionStore(j=>j.interactionStates[m.DRILL_CONTEXT_CARD_ID]),t=m.useDashboardStore(j=>j.actions.goBackFromDrill),n=m.useDashboardStore(j=>j.actions.clearDrillContext),{selectDashboard:r}=Pm(),[o,s]=v.useState({x:16,y:16}),[i,a]=v.useState(!1),c=v.useRef({x:0,y:0});v.useEffect(()=>{if(!i)return;const j=_=>{s({x:_.clientX-c.current.x,y:_.clientY-c.current.y})},k=()=>{a(!1)};return document.addEventListener("mousemove",j),document.addEventListener("mouseup",k),()=>{document.removeEventListener("mousemove",j),document.removeEventListener("mouseup",k)}},[i]);const u=e==null?void 0:e.sourceDashboardId,d=e==null?void 0:e.sourceDashboardTitle,f=((N=(w=(C=(y=e==null?void 0:e.appliedClickFilters)==null?void 0:y[0])==null?void 0:C.filterGroups)==null?void 0:w[0])==null?void 0:N.filters)||[],h=u?{id:u,title:d||"Previous Dashboard",description:"",isPrivate:!1,isPublic:!1,version:"",createdBy:null,createdByTenantUser:"",tenantId:"",projectId:"",createdAt:"",updatedAt:"",lastModified:"",lastModifiedBy:"",createdByUser:null,createdByTenantUserRel:{name:"",email:""},permissions:{canEdit:!0,canShare:!0,canDelete:!0},ownership:{status:"private",isOwner:!0,sharedCount:0,createdBy:{type:"user",userId:"",name:"",email:""}}}:null;if(!e||!((S=e.appliedClickFilters)!=null&&S.length))return null;const p=()=>{if(!h){console.warn("[DrillBack] No source dashboard in context");return}try{t(),r(h)}catch(j){console.error("[DrillBack] Error during back navigation:",j)}},g=()=>{n()},x=j=>{j.target.closest("button")||(a(!0),c.current={x:j.clientX-o.x,y:j.clientY-o.y})};n_t(f);const b=o_t(d);return l.jsx("div",{className:"fixed z-50 max-w-md",style:{left:0,top:0,transform:`translate(${o.x}px, ${o.y}px)`,transition:i?"none":void 0},children:l.jsxs("div",{className:"select-none rounded-lg border bg-background/95 p-3 shadow-lg backdrop-blur-sm",onMouseDown:x,style:{cursor:i?"grabbing":"grab"},children:[l.jsxs("div",{className:"mb-3 flex items-start justify-between gap-2",children:[l.jsxs("div",{className:"flex flex-col gap-2",children:[l.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Viewing:"}),l.jsx("div",{className:"flex flex-wrap gap-2",children:f.map((j,k)=>{const _=j.field.label||j.field.name,T=String(j.value);return l.jsxs(ki,{variant:"secondary",className:"pointer-events-none text-xs",children:[_," = ",T]},k)})})]}),l.jsx(m.Button,{variant:"ghost",size:"sm",onClick:g,className:"h-6 w-6 cursor-pointer p-0",title:"Clear drill context",children:l.jsx(Re.X,{className:"h-3 w-3"})})]}),l.jsx("div",{className:"flex items-center gap-2 border-t pt-2",children:l.jsxs(m.Button,{variant:"secondary",size:"sm",onClick:p,disabled:!h,className:"w-full cursor-pointer",children:[l.jsx(ow,{className:"mr-2 h-4 w-4"}),b]})})]})})}function i_t(e,t){return typeof e=="boolean"?e:typeof t=="boolean"?t:!1}function a_t({filter:e,isEditing:t=!1,disabled:n=!1,storageOptions:r,settingsVariant:o,inputVariableName:s,reservedInputVariableNames:i,isDashboardFilterReference:a,onUpdateFilter:c,onRemoveFilter:u}){const{attributes:d,listeners:f,setNodeRef:h,transform:p,transition:g,isDragging:x}=dp({id:`filter:${e.id}`,disabled:n||!t}),b={transform:Pi.Translate.toString(p),transition:g,opacity:x?.5:1,zIndex:x?10:void 0};return l.jsx("div",{ref:h,style:b,...d,children:l.jsx(mz,{filter:e,isEditing:t,dragListeners:t?f:void 0,storageOptions:r,settingsVariant:o,inputVariableName:s,reservedInputVariableNames:i,isDashboardFilterReference:a,onUpdateFilter:c,onRemoveFilter:u})})}const yY="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",l_t=[];function cye({open:e,onOpenChange:t}){const[n,r]=v.useState(!1),[o,s]=v.useState(!1),[i,a]=v.useState({sheetSelection:"current",protectPdf:!1,password:""}),c=m.useDashboardStore(q=>{var Y;return(Y=q.dashboard)==null?void 0:Y.sheets}),u=m.useDashboardStore(q=>q.dashboard),d=m.useDashboardStore(q=>q.dashboardInputValues),f=m.useDashboardStore(q=>q.filterValues),h=m.useDashboardStore(q=>q.controlValues),p=m.useDashboardStore(q=>q.inlineFilterValuesMap),g=m.useDashboardStore(q=>q.cardControlValuesMap),x=m.useDashboardStore(q=>q.selectedSheetId),b=m.useDashboardStore(q=>q.selectedSheetId?q.documentInputRuntimeBySheetId[q.selectedSheetId]:void 0),y=m.useDashboardStore(q=>q.isDownloadingPdf),C=m.useDashboardStore(q=>q.reportContext),{authToken:w,tokenProps:N}=Mt(),S=c==null?void 0:c.find(q=>q.id===x),j=v.useMemo(()=>m.getDashboardExportSheets(c),[c]),k=m.isDocumentSheet(S),_=k&&S?S.document:void 0,T=v.useMemo(()=>k&&S?kb(u,S.id):[],[S,k,u]),I=T.length>0,D=v.useMemo(()=>k&&S?wge(u,S.id):!1,[S,k,u]),E=v.useMemo(()=>I?T.map(NC):(_==null?void 0:_.inputs)||l_t,[_,T,I]),R=C==null?void 0:C.calendar.tz,F=v.useMemo(()=>ype(E),[E]),M=v.useMemo(()=>xpe(E,R),[E,R]),O=v.useMemo(()=>bpe(E),[E]),z=b?b.filterValuesByInputId:M,L=v.useMemo(()=>wpe(z,E),[E,z]),V=b?b.controlValuesByInputId:O,A=v.useMemo(()=>k?D&&S&&_?IZ({dashboard:u,sheetId:S.id,sheetKind:"document",sectionIds:_.sections.map(q=>q.id),mode:"document",runtimeValues:{dashboardInputValues:d,filterValues:f,controlValues:h,inlineFilterValuesMap:p,cardControlValuesMap:g},timezone:R}):Spe(E,L,V,F,F):[],[_,E,S,k,u,g,h,f,p,d,V,L,F,R,D]),B=!!S,$=j.length>0,P=((c==null?void 0:c.length)||0)>1||k,U=i.sheetSelection==="current"&&(!B||k&&A.length>0)||i.sheetSelection==="all"&&!$;v.useEffect(()=>{e&&i.sheetSelection==="all"&&!$&&a(q=>({...q,sheetSelection:"current"}))},[$,e,i.sheetSelection]);const H=()=>{a({sheetSelection:"current",protectPdf:!1,password:""}),r(!1),t(!1)};async function G(){if(y){m.ue.error("A PDF export is already in progress");return}if(i.protectPdf&&!i.password){m.ue.error("Please enter a password to protect the PDF");return}if(i.sheetSelection==="current"&&!B){m.ue.error("No sheet is selected to export");return}if(i.sheetSelection==="all"&&!$){m.ue.error("No dashboard sheets are available to export");return}s(!0);const q=i.sheetSelection==="current"&&k,Y=q?i.protectPdf?"Generating protected document PDF... may take up to 60 seconds":"Generating document PDF... may take up to 60 seconds":i.sheetSelection==="all"?"Generating PDF for all dashboard sheets... This may take a while.":i.protectPdf?"Generating protected PDF... may take up to 60 seconds":"Generating PDF... may take up to 60 seconds",W=m.ue.loading(Y);try{if(q){if(!_||!S)throw new Error("Selected document sheet is missing document data");if(A.length>0){m.ue.dismiss(W),m.ue.error(`Set ${A.join(", ")} before exporting`);return}const Z=new Date().toISOString(),K=D?_Z({dashboard:u,sheetId:S.id,sheetKind:"document",sectionIds:_.sections.map(X=>X.id),mode:"document",runtimeValues:{dashboardInputValues:d,filterValues:f,controlValues:h,inlineFilterValuesMap:p,cardControlValuesMap:g},generatedAt:Z,timezone:R}).snapshot:void 0;await NL(N.apiServiceUrl,w,{sheetId:S.id,title:S.title||"Document",pageSize:_.page.size,orientation:_.page.orientation,timezone:R,password:i.protectPdf?i.password:void 0,inputSnapshot:K,...K?{}:{inputValues:{sheetId:S.id,filterValuesByInputId:L,controlValuesByInputId:V,generatedAt:Z}}})}else{const Z=$oe();await jte(N.apiServiceUrl,w,i.protectPdf?i.password:void 0,i.sheetSelection,Z)}m.ue.dismiss(W);const ne=q?i.protectPdf?"Protected document PDF downloaded successfully!":"Document PDF downloaded successfully!":i.sheetSelection==="all"?"Dashboard sheets PDF downloaded successfully!":i.protectPdf?"Protected PDF downloaded successfully!":"PDF downloaded successfully!";m.ue.success(ne,{duration:2e3}),H()}catch(ne){m.ue.dismiss(W),m.ue.error("Failed to download PDF",{description:r_(ne,"Please try again or contact support."),descriptionClassName:n_,closeButton:!0,duration:1/0,richColors:!0}),console.error("PDF download error:",ne)}finally{s(!1)}}return l.jsx(To,{open:e,onOpenChange:q=>{if(!q){H();return}t(!0)},children:l.jsxs(bo,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[l.jsxs($s,{children:[l.jsx(yo,{className:"text-[15px]",children:k?"Export document":"Export dashboard"}),l.jsx(Ho,{className:"text-[13px] leading-5",children:k?"Export this document sheet as a PDF document.":"Export this dashboard as a PDF document."})]}),l.jsxs("div",{className:"space-y-4 py-1",children:[P&&l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"space-y-2",children:[l.jsx(m.Label,{className:yY,children:"Export scope"}),l.jsxs(cc,{value:i.sheetSelection,onValueChange:q=>a({...i,sheetSelection:q}),className:"gap-1.5",children:[l.jsxs(m.Label,{htmlFor:"scope-current",className:m.cn("flex cursor-pointer items-center gap-2 rounded-control px-1 py-1 text-[13px] font-normal hover:bg-muted/50",!B&&"cursor-not-allowed opacity-50 hover:bg-transparent"),children:[l.jsx(Ms,{value:"current",id:"scope-current",disabled:!B}),k?"This document":"This sheet"," (",(S==null?void 0:S.title)||"Current",")"]}),l.jsxs(m.Label,{htmlFor:"scope-all",className:m.cn("flex cursor-pointer items-center gap-2 rounded-control px-1 py-1 text-[13px] font-normal hover:bg-muted/50",!$&&"cursor-not-allowed opacity-50 hover:bg-transparent"),children:[l.jsx(Ms,{value:"all",id:"scope-all",disabled:!$}),"Dashboard sheets (",j.length," ",j.length===1?"sheet":"sheets",")"]})]}),k&&l.jsx("p",{className:"text-[12px] leading-5 text-muted-foreground",children:A.length>0?`Set ${A.join(", ")} before exporting this document.`:'"Dashboard sheets" includes dashboard sheets only. Choose "This document" to export the selected document.'})]}),l.jsx(m.Separator,{className:"bg-border/60"})]}),l.jsxs("div",{className:"space-y-2",children:[l.jsxs(m.Label,{htmlFor:"protect-pdf",className:"flex cursor-pointer items-center gap-2 text-[13px] font-normal",children:[l.jsx(jn,{id:"protect-pdf",checked:i.protectPdf,onCheckedChange:q=>{a({...i,protectPdf:q,password:q?i.password:""}),q||r(!1)}}),l.jsx(iw,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Password protect PDF"]}),i.protectPdf&&l.jsxs("div",{className:"ml-6 space-y-1.5",children:[l.jsx(m.Label,{htmlFor:"pdf-password",className:yY,children:"Password"}),l.jsxs("div",{className:"relative",children:[l.jsx(m.Input,{id:"pdf-password",size:"xs",type:n?"text":"password",value:i.password,onChange:q=>a({...i,password:q.target.value}),placeholder:"Enter password",className:"pr-8",onKeyDown:q=>{q.key==="Enter"&&i.password&&G()}}),l.jsx("button",{type:"button",className:"absolute right-1 top-1/2 flex h-5 w-5 -translate-y-1/2 items-center justify-center rounded-control text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>r(!n),"aria-label":n?"Hide password":"Show password",children:n?l.jsx(uI,{className:"h-3.5 w-3.5"}):l.jsx(Ft.Eye,{className:"h-3.5 w-3.5"})})]}),l.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Recipients will need this password to open the PDF."})]})]})]}),l.jsxs(ll,{children:[l.jsx(m.Button,{variant:"outline",size:"xs",onClick:H,disabled:o,children:"Cancel"}),l.jsx(m.Button,{size:"xs",onClick:G,disabled:o||y||U,children:o?l.jsxs(l.Fragment,{children:[l.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Exporting…"]}):l.jsxs(l.Fragment,{children:[l.jsx(ac,{className:"h-3.5 w-3.5"}),"Export"]})})]})]})})}function uye({iconClassName:e,open:t,onOpenChange:n}){const[r,o]=v.useState(!1),s=t!==void 0,i=s?t:r,a=u=>{s||o(u),n==null||n(u)},c=m.useDashboardStore(u=>u.isDownloadingPdf);return l.jsxs(l.Fragment,{children:[s?null:l.jsx(m.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:c,onClick:()=>a(!0),children:l.jsx(ac,{className:m.cn("size-4",e)})}),l.jsx(cye,{open:i,onOpenChange:a})]})}function c_t({control:e,value:t,isEditing:n=!1,onChange:r}){const{attributes:o,listeners:s,setNodeRef:i,transform:a,transition:c,isDragging:u}=dp({id:`control:${e.id}`,disabled:!n}),d={transform:Pi.Translate.toString(a),transition:c,opacity:u?.5:1,zIndex:u?10:void 0};return l.jsx("div",{ref:i,style:d,...o,children:l.jsx(Vpe,{control:e,value:t,isEditing:n,dragListeners:n?s:void 0,onChange:r})})}function vY(e){var t;return(((t=e.values)==null?void 0:t.length)??0)>0||e.operation==="is null"||e.operation==="is not null"}function wY(e,t){return[...e.map(n=>`filter:${n.id}`),...t.map(n=>`control:${n.id}`)]}function u_t(e,t,n){const r=new Set([...t.map(a=>`filter:${a.id}`),...n.map(a=>`control:${a.id}`)]);if(!(e!=null&&e.length))return wY(t,n);const o=e.filter(a=>r.has(a)),s=new Set(o),i=wY(t,n).filter(a=>!s.has(a));return[...o,...i]}function d_t(e,t){return m.getDashboardCardEntries({sheets:e.sheets||[]}).filter(n=>n.sheet.id===t).map(n=>n.card.id)}function f_t(e){return m.doesDashboardInputApplyToTarget(e.dashboardInput,{sheetId:e.selectedSheetId,sheetKind:"dashboard"})?!0:e.dashboardInput.scope.kind!=="cards"?!1:e.selectedSheetCardIds.some(t=>m.doesDashboardInputApplyToTarget(e.dashboardInput,{sheetId:e.selectedSheetId,cardId:t,sheetKind:"dashboard"}))}function uR(e){var t;return((t=e.compatibility)==null?void 0:t.source)!=="dashboardFilter"}function h_t(e){return dye(e).filter(t=>{var n,r;return t.filter.hide||t.filter.location==="frame"?!1:((n=t.compatibility)==null?void 0:n.source)==="dashboardFilter"?!0:(((r=t.presentation)==null?void 0:r.placement)||"toolbar")==="toolbar"})}function dye(e){if(!e.selectedSheetId)return[];const t=e.selectedSheetId,n=d_t(e.dashboard,t);return m.removeShadowedCompatibilityInputs(m.buildNormalizedDashboardInputs({dashboard:e.dashboard}).allInputs).filter(r=>!(r.kind!=="filter"||!f_t({dashboardInput:r,selectedSheetId:t,selectedSheetCardIds:n})))}function m_t(e,t){return"toolbar"}function p_t(){const e=xl("interactive"),t=m.useDashboardStore(Z=>Z.selectedSheetId),n=m.useDashboardStore(Z=>Z.dashboard.filters),r=m.useDashboardStore(Z=>Z.dashboard.filterLayout),o=m.useDashboardStore(Z=>Z.isDashboardEditing),s=m.useDashboardStore(Z=>Z.controlValues),i=m.useDashboardStore(Z=>Z.filterValues);m.useDashboardStore(Z=>Z.filteringCards);const a=m.useDashboardStore(Z=>Z.inlineFilterValuesMap),c=m.useDashboardStore(Z=>Z.dashboardInputValues),u=m.useInteractionStore(Z=>Z.clearAllClickFilters),d=m.useInteractionStore(Z=>Object.entries(Z.interactionStates).reduce((K,[X,J])=>{var re;return X===m.DRILL_CONTEXT_CARD_ID?K:K+(((re=J.appliedClickFilters)==null?void 0:re.length)??0)},0)),f=m.useDashboardStore(Z=>Z.actions.removeCardInlineFilterValue),{reorderFilters:h,clearDashboardInputSlot:p,reorderDashboardControls:g,removeDashboardInput:x,removeFilter:b,setControlValue:y,setFilterLayout:C,setFilterValues:w,setFilteringCards:N,updateFilterDashboardInputDefinition:S}=m.useDashboardActions(),j=bC(Em(cp,{activationConstraint:{distance:5}})),k=m.useDashboardStore(Z=>Z.dashboard),_=h_t({dashboard:k,selectedSheetId:t}).filter(Z=>m_t(Z.filter)==="toolbar"),T=dye({dashboard:k,selectedSheetId:t}),I=_.map(Z=>Z.filter),D=new Map(_.map(Z=>[`filter:${Z.filter.id}`,Z])),E=nnt(k),R=E.filter(Z=>!Z.hidden&&j0(Z)==="toolbar"),F=E.filter(Z=>!Z.hidden&&j0(Z)==="advanced"),M=u_t(r==null?void 0:r.toolbarItemOrder,I,R),O=new Map(I.map(Z=>[`filter:${Z.id}`,Z])),z=new Map(R.map(Z=>[`control:${Z.id}`,Z]));function L(Z){const{active:K,over:X}=Z;if(!X||K.id===X.id)return;const J=String(K.id),re=String(X.id),te=M.findIndex(be=>be===J),Q=M.findIndex(be=>be===re);if(te===-1||Q===-1)return;const se=up(M,te,Q);C({toolbarItemOrder:se});const oe=new Set((n||[]).map(be=>be.id)),fe=M.filter(be=>be.startsWith("filter:")).map(be=>be.replace("filter:","")).filter(be=>oe.has(be)),pe=se.filter(be=>be.startsWith("filter:")).map(be=>be.replace("filter:","")).filter(be=>oe.has(be)),xe=M.filter(be=>be.startsWith("control:")).map(be=>be.replace("control:","")),Ie=se.filter(be=>be.startsWith("control:")).map(be=>be.replace("control:",""));h(Bk(n||[],fe,pe)),g(Bk(k.controls||[],xe,Ie))}const V=(r==null?void 0:r.toolbarWrap)??!1,A=(r==null?void 0:r.showDownloadButton)??!1,B=T.filter(uR),$=T.filter(Z=>{if(uR(Z))return!1;const K=m.getDashboardInputRuntimeSlot(c,Z,{sheetId:t});return(K==null?void 0:K.status)==="set"||(K==null?void 0:K.status)==="cleared"}),P=new Set([...B,...$].map(Z=>Z.filter.id)),U=(i==null?void 0:i.filter(Z=>!P.has(Z.filterId)&&vY(Z)).length)??0,H=[...B,...$],G=H.filter(Z=>{const K=m.hydrateAuthoredDashboardInputSlot({dashboard:k,input:Z,runtimeValues:c,target:{sheetId:t}});return(K==null?void 0:K.status)==="set"&&K.value.kind==="filter"&&vY(K.value.filterValue)}).length,q=a?Object.values(a).reduce((Z,K)=>Z+((K==null?void 0:K.length)??0),0):0,Y=U+G+q+d,W=H.some(Z=>Z.forceSelection),ne=()=>{w([]),H.forEach(Z=>{p(Z,{sheetId:t})}),N([]),u(),a&&Object.entries(a).forEach(([Z,K])=>{K==null||K.forEach(X=>{f(Z,X.filterId)})})};return!I.length&&!R.length&&!F.length&&!A&&Y===0?null:l.jsx("div",{className:"z-20 bg-background/95 px-3 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/85",style:e.containerStyle,role:"toolbar","aria-label":"Dashboard filters and controls",children:l.jsx(Sb,{sensors:j,collisionDetection:wb,onDragEnd:L,children:l.jsxs("div",{className:m.cn("flex items-center",V?"flex-wrap":"w-0 min-w-full overflow-x-auto"),children:[l.jsx(Nb,{items:M,strategy:FT,children:l.jsx(cO,{className:"gap-3 pr-0",wrap:V,children:M.map(Z=>{const K=O.get(Z);if(K){const J=D.get(Z),re=J&&uR(J),te=re&&J.definitionOrigin==="dashboardFilter";return l.jsx(a_t,{filter:K,isEditing:o,storageOptions:re?{storageTarget:"dashboardInput",dashboardInput:J,sheetId:t??void 0,sheetKind:"dashboard"}:void 0,inputVariableName:re?J.variableName:void 0,isDashboardFilterReference:te,onUpdateFilter:re?(Q,se)=>S(J.id,Q,se):void 0,onRemoveFilter:re?()=>{if(J.definitionOrigin==="dashboardFilter"){b(K.id);return}w((i||[]).filter(Q=>Q.filterId!==K.id)),x(J.id)}:void 0},Z)}const X=z.get(Z);return X?l.jsx(c_t,{control:X,value:s==null?void 0:s[X.id],isEditing:o,onChange:J=>y(X.id,J)},Z):null})})}),F.length>0&&l.jsx(Bde,{title:"",controls:F,values:s,onChange:(Z,K)=>y(Z.id,K),immediatePlacement:"toolbar",advancedLabel:"More controls"}),Y>0&&l.jsxs("button",{type:"button",onClick:ne,"aria-label":W?"Reset filters":"Clear all filters",className:"ml-auto inline-flex h-7 shrink-0 items-center gap-1 rounded-control px-2 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[l.jsx(Re.X,{className:"h-3 w-3"}),W?"Reset filters":"Clear all",l.jsx("span",{className:"rounded-[3px] bg-muted px-1 text-[10px] tabular-nums text-muted-foreground",children:Y})]}),A&&l.jsx("div",{className:m.cn(Y>0?"ml-1.5":"ml-auto"),children:l.jsx(uye,{})})]})})})}function fye(){var ee,ce;const{showAssistant:e,tokenProps:t,renderMode:n}=Mt(),r=i_t((ee=t.config)==null?void 0:ee.showDashboardAssistant,e),{preferences:o}=Vm(),s=(ce=o==null?void 0:o.cardDisplay)==null?void 0:ce.mode,i=mf(s),a=Eee({displayMode:s,renderMode:n}),c=v.useRef(null),u=v.useRef(null),d=v.useRef(null),[f,h]=v.useState(!1),{handleDragStart:p,isDraggingRef:g,getStyle:x,getPositionClasses:b}=h0t({initialPosition:"bottom-right"}),y=Rh(ae=>ae.setFullscreen),C=Rh(ae=>ae.setPanelOpen),w=Rh(ae=>ae.setContainer),N=NJ("dashboard"),S=jJ(),j=kJ("dashboard"),k=N.isOpen,_=S==="dashboard",T=m.useDashboardStore(ae=>ae.isVisualEditing),I=m.useDashboardStore(ae=>ae.themeStyle),D=Pu(),E=m.useDashboardStore(ae=>{var me;return(me=ae.dashboard)==null?void 0:me.sheets}),R=m.useDashboardStore(ae=>ae.showFilters),F=m.useDashboardStore(ae=>ae.isDashboardEditing),M=m.useDashboardStore(ae=>ae.selectedSheetId),O=E==null?void 0:E.find(ae=>ae.id===M),z=m.useDashboardStore(ae=>{var me,ve,_e;return(_e=(ve=(me=ae.dashboard)==null?void 0:me.sheets)==null?void 0:ve.find(De=>De.id===ae.selectedSheetId))==null?void 0:_e.kind}),L=m.useDashboardStore(ae=>{var me,ve;return((ve=(me=ae.dashboard)==null?void 0:me.summary)==null?void 0:ve.position)||"top"}),V=z==="document",A=m.useDashboardStore(ae=>{var me;return(me=ae.dashboard)==null?void 0:me.id}),{getDefaultSheetId:B,setDefaultSheetId:$,clearDefaultSheetId:P}=mZ(A),[U,H]=v.useState(null),{setSelectedSheetId:G,setSheetTitle:q,addSheet:Y,setSheets:W,duplicateSheet:ne}=m.useDashboardActions();WIt(u);const{setActiveAssistantType:Z}=m.useAIActions();v.useEffect(()=>{if(A){const ae=B();H(ae)}},[A,B]),v.useEffect(()=>{k?Z("dashboard"):S==="dashboard"&&y(null)},[k,Z,S,y]),v.useEffect(()=>{var ae;k||(ae=c.current)==null||ae.resize(0)},[k]);function K(ae){var me,ve;ae?((me=c.current)==null||me.resize(40),C("dashboard",!0),y("dashboard"),Z("dashboard")):(C("dashboard",!1),y(null),(ve=c.current)==null||ve.resize(0),Z(null))}function X(ae="dashboard"){const me={id:lt.v4(),title:ae==="document"?"New Document":"New Sheet",...ae==="document"?{kind:ae,document:m.createDefaultDocumentDefinition()}:{}};Y(me),G(me.id)}function J(ae){const me=ne(ae);me&&(m.ue.success("Sheet duplicated"),requestAnimationFrame(()=>{var _e;const ve=(_e=d.current)==null?void 0:_e.querySelector(`[data-sheet-id="${me}"]`);ve==null||ve.focus(),ve==null||ve.scrollIntoView({block:"nearest",inline:"nearest"})}))}function re(ae,me){if(!A)return;U===ae?(P(),H(null),m.ue.success("Default sheet cleared")):($(ae),H(ae),m.ue.success(`"${me}" set as default sheet`))}function te(ae){var me;ae<1?(C("dashboard",!1),y(null),Z(null),(me=c.current)==null||me.resize(0)):(k||C("dashboard",!0),Z("dashboard"))}function Q(){return(I==null?void 0:I.canvasTheme)==="muted"||!(I!=null&&I.canvasTheme)?"hsl(var(--semaphor-muted))":(I==null?void 0:I.canvasTheme)==="clear"?"":I==null?void 0:I.canvasTheme}const se=(ae,me)=>{ae.dataTransfer.setData("tabIndex",me.toString())},oe=ae=>{ae.preventDefault()},fe=(ae,me)=>{const ve=ae.dataTransfer.getData("tabIndex");if(ve===me.toString())return;const _e=Array.from(E||[]),[De]=_e.splice(parseInt(ve),1);_e.splice(me,0,De),W(_e)},pe=r===!0&&!i&&!k&&!T&&!R;function xe(){if(E&&E.length>1||F)return l.jsx("div",{className:"relative flex w-full items-stretch",children:l.jsxs("div",{className:"relative min-w-0 flex-1",children:[l.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 left-0 z-10 w-4 bg-gradient-to-r from-background to-transparent"}),l.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-y-0 right-0 z-10 w-4 bg-gradient-to-l from-background to-transparent"}),l.jsxs(m.TabsList,{ref:d,className:"flex w-0 min-w-full items-stretch justify-start overflow-x-auto rounded-none bg-transparent p-0 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:[E==null?void 0:E.map((ae,me)=>{const ve=M===ae.id,_e=U===ae.id;return l.jsxs("div",{className:"relative flex shrink-0 items-center",children:[l.jsxs(m.TabsTrigger,{"data-sheet-id":ae.id,draggable:!0,onDragStart:De=>se(De,me),onDragOver:oe,onDrop:De=>fe(De,me),onClick:()=>G(ae.id),className:m.cn("group relative inline-flex h-9 shrink-0 items-center gap-1.5 rounded-none bg-transparent px-3 py-0 text-[12px] font-medium text-muted-foreground transition-colors hover:bg-transparent hover:text-foreground data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none",F&&ve&&"pr-9","after:pointer-events-none after:absolute after:inset-x-2 after:-bottom-px after:h-0.5 after:bg-transparent data-[state=active]:after:bg-foreground"),value:ae.id,children:[ae.kind==="document"&&l.jsx(li,{className:"h-3 w-3 text-muted-foreground"}),l.jsx(ak,{enabled:F&&ve,text:ae.title,onSave:De=>q(ae.id,De),children:ae.title},ae.id),l.jsx("span",{role:"button",tabIndex:0,"aria-label":_e?"Clear default sheet":"Set as default sheet",title:_e?"Clear default sheet":"Set as default sheet",onClick:De=>{De.stopPropagation(),re(ae.id,ae.title||"Sheet")},onKeyDown:De=>{(De.key==="Enter"||De.key===" ")&&(De.preventDefault(),De.stopPropagation(),re(ae.id,ae.title||"Sheet"))},className:m.cn("inline-flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded-[3px] transition-opacity hover:bg-muted focus:outline-none focus-visible:ring-1 focus-visible:ring-foreground",ve||_e?"opacity-100":"opacity-0 group-hover:opacity-100"),children:l.jsx(hX,{className:m.cn("h-3 w-3 transition-colors",_e?"fill-current text-amber-500":"text-muted-foreground")})})]}),F&&ve&&l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":`Sheet actions for ${ae.title||"Sheet"}`,className:"absolute right-2 inline-flex h-4 w-4 items-center justify-center rounded-[4px] text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-foreground",children:l.jsx(Ai,{className:"h-3 w-3"})})}),l.jsxs(_o,{align:"start",className:"w-44",children:[l.jsxs(ln,{onSelect:()=>J(ae.id),children:[l.jsx(gu,{className:"h-4 w-4"}),"Duplicate sheet"]}),l.jsxs(ln,{disabled:E.length<=1,onSelect:()=>h(!0),children:[l.jsx(Ra,{className:"h-4 w-4"}),"Delete sheet"]})]})]})]},ae.id)}),F&&l.jsxs(Bo,{children:[l.jsx(Vo,{asChild:!0,children:l.jsxs("button",{type:"button","aria-label":"Add sheet",className:"ml-1 inline-flex h-9 shrink-0 items-center gap-1 px-3 text-[12px] font-medium text-muted-foreground transition-colors hover:text-foreground",children:[l.jsx(Ar,{className:"h-3 w-3"}),"Sheet"]})}),l.jsxs(_o,{align:"start",className:"w-48",children:[l.jsxs(ln,{onSelect:()=>X("dashboard"),children:[l.jsx(zd,{className:"h-4 w-4 text-muted-foreground"}),"Dashboard sheet"]}),l.jsxs(ln,{onSelect:()=>X("document"),children:[l.jsx(li,{className:"h-4 w-4 text-muted-foreground"}),"Document"]})]})]})]})]})})}function Ie(){return l.jsx("div",{ref:u,style:{},className:"h-full min-h-0 grow",children:E==null?void 0:E.map(ae=>l.jsx(m.TabsContent,{style:{backgroundColor:Q(),...D.dashboardCanvasStyle},className:m.cn("mt-0 h-full min-h-0",{}),value:ae.id,children:l.jsx(hG,{sheet:ae})},ae.id))})}function be(){return l.jsxs(m.Tabs,{"data-role":"dashboard-tabs-container",className:m.cn("relative flex h-full flex-col",I==null?void 0:I.dashboardTabsContainer),onValueChange:ae=>{G(ae)},value:M||void 0,children:[xe(),L==="top"&&!V&&l.jsx(IP,{}),M&&!V&&l.jsx(p_t,{}),V?l.jsx("div",{"data-role":"dashboard-tabs-content",className:"min-h-0 flex-1 grow basis-0 overflow-hidden",children:Ie()}):l.jsx($u,{"data-role":"dashboard-tabs-content",className:"flex-1 grow basis-0 overflow-y-auto",children:Ie()}),L==="bottom"&&!V&&l.jsx(IP,{}),l.jsx(m0t,{open:f,setOpen:h})]})}const ge=v.useCallback(ae=>{w("dashboard",ae)},[w]);return E?a&&M&&!V?l.jsxs("div",{"data-document-render-error":"true",className:"bg-white p-8 text-sm text-zinc-700",children:['Requested document sheet "',M,'" was not found or is not a document sheet in the loaded dashboard.']}):a&&V&&O?l.jsx("div",{"data-role":"dashboard-document-print-content",className:"min-h-0 overflow-visible bg-white",children:l.jsx(hG,{sheet:O})}):l.jsxs(l.Fragment,{children:[l.jsx(t_t,{}),l.jsx(s_t,{}),l.jsxs("div",{className:"relative flex-1 basis-0 overflow-hidden",children:[l.jsxs(Kge,{className:m.cn("flex-1 basis-0 overflow-y-auto transition-opacity",_&&"pointer-events-none opacity-0"),direction:"horizontal",children:[l.jsx(pO,{children:be()}),r===!0&&l.jsxs(l.Fragment,{children:[l.jsx(f0t,{open:k,onTabClick:K,withHandle:!0,disabled:!k}),l.jsx(pO,{className:"flex grow","data-role":"dashboard-assistant-panel",onResize:te,defaultSize:k?40:0,ref:c,children:l.jsx("div",{className:"grow overflow-y-auto",children:l.jsx(KIt,{open:k,setOpen:K,isFullscreen:_,onFullscreenChange:ae=>y(ae?"dashboard":null),fullscreenContainer:j})})})]})]}),l.jsx("div",{ref:ge,className:m.cn("absolute inset-0",!_&&"pointer-events-none")}),pe&&l.jsx("div",{className:m.cn("absolute z-50 transition-all duration-300 ease-in-out",b().horizontal,b().vertical),style:x(),children:l.jsx(m.Button,{size:"sm",variant:"outline",className:"h-12 w-12 cursor-grab rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted active:cursor-grabbing",onClick:()=>{g.current||K(!0)},onMouseDown:p,onTouchStart:p,title:"Open Assistant (drag to move)",children:l.jsx(ewe,{className:"h-5 w-5"})})})]})]}):null}const hye=v.forwardRef(({appearance:e,organizationAppearance:t,tokenAppearance:n,reactAppearance:r,resolvedAppearance:o,systemMode:s,children:i,className:a,style:c,...u},d)=>l.jsx(fg.InternalAppearanceRuntimeProvider,{appearance:e,organizationAppearance:t,tokenAppearance:n,reactAppearance:r,resolvedAppearance:o,systemMode:s,children:l.jsx(gb,{...u,ref:d,className:a,style:c,children:i})}));hye.displayName="AppearanceProvider";const mye=v.createContext({openBrandStudioPreview:()=>{}}),g_t=mye.Provider;function x_t(){return v.useContext(mye)}function b_t({children:e,defaultTheme:t="system",storageKey:n="vite-ui-theme",...r}){const o=fg.normalizeTheme(t),[s,i]=v.useState(()=>y_t(n)||o),a=v.useCallback(u=>{const d=fg.normalizeTheme(u);v_t(n,d),i(d)},[n]),c=v.useMemo(()=>({theme:s,setTheme:a}),[s,a]);return l.jsx(fg.ThemeProviderContext.Provider,{...r,value:c,children:e})}function y_t(e){if(typeof window>"u")return null;try{const t=window.localStorage.getItem(e);if(!t)return null;const n=fg.normalizeTheme(t,"system");return n===t?n:null}catch{return null}}function v_t(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(e,t)}catch{}}const w_t=v.lazy(()=>Promise.resolve().then(()=>require("../brand-studio/index.cjs")).then(e=>({default:e.BrandStudioEditor})));function DB({appearance:e,children:t}){var D,E;const{authToken:n,id:r,tokenProps:o}=Mt(),s=ew(),i=(D=s.data)==null?void 0:D.organizationAppearance,a=(E=o.config)==null?void 0:E.appearance,[c,u]=v.useState(!1),[d,f]=v.useState(null),[h,p]=v.useState(null),[g,x]=v.useState(null),[b,y]=v.useState(null),C=`${o.apiServiceUrl??""}:${(n==null?void 0:n.accessToken)??""}`,w=Yn({queryKey:x5({resourceType:uo.DASHBOARD,apiServiceUrl:o.apiServiceUrl,accessToken:n==null?void 0:n.accessToken}),queryFn:async()=>m.getRequest(`${o.apiServiceUrl}/management/v1/dashboards`,(n==null?void 0:n.accessToken)||""),select:R=>(R==null?void 0:R.organizationAppearance)??null,enabled:!s.dashboardIdToFetch&&i===void 0&&!!(n!=null&&n.accessToken)});v.useEffect(()=>{i!==void 0&&y({scopeKey:C,appearance:i})},[i,C]),v.useEffect(()=>{w.data!==void 0&&y({scopeKey:C,appearance:w.data})},[w.data,C]);const N=(b==null?void 0:b.scopeKey)===C?b.appearance:null,S=i!==void 0?i:w.data!==void 0?w.data:N,j=v.useMemo(()=>Am.resolveAppearance({organizationAppearance:S,tokenAppearance:a,reactAppearance:e}),[e,S,a]),k=v.useCallback(()=>{f(g??h??j),u(!0)},[g,h,j]),_=v.useCallback(()=>{u(!1)},[]);v.useEffect(()=>{f(null),p(null),x(null),u(!1)},[r]);const T=v.useMemo(()=>({openBrandStudioPreview:k}),[k]),I=g??h??e;return l.jsx(b_t,{defaultTheme:"system",storageKey:"vite-ui-theme",children:l.jsx(g_t,{value:T,children:l.jsx(hye,{organizationAppearance:S,tokenAppearance:a,reactAppearance:I,style:{height:"100%",width:"100%"},children:l.jsxs(m.TooltipProvider,{delayDuration:0,children:[t,c&&l.jsx("aside",{"aria-label":"Brand Studio","aria-modal":"false",role:"dialog",className:"fixed bottom-0 right-0 top-0 z-50 flex w-[min(520px,100vw)] flex-col border-l border-border bg-background text-foreground shadow-sm",children:l.jsx(v.Suspense,{fallback:l.jsx("div",{className:"flex h-full items-center justify-center text-[12px] text-muted-foreground",children:"Loading Brand Studio..."}),children:l.jsx(w_t,{appearance:d,onDraftChange:x,onSave:R=>{p(R),x(R),f(R)},onCancel:_})})})]})})})})}function pye({children:e,preferences:t}){const{currentUser:n}=hi(),r=v.useMemo(()=>{var o,s;return{preferences:t||{},isLocalDev:((o=t==null?void 0:t.uiMode)==null?void 0:o.developer)||!1,isConsoleMode:((s=t==null?void 0:t.uiMode)==null?void 0:s.console)||!1}},[t]);return l.jsx(mQ.Provider,{value:r,children:l.jsx(xT,{displayPreferences:t==null?void 0:t.cardDisplay,currentUser:n,children:e})})}function C_t(e=2e3,t=500){const n=Gve(),[r,o]=v.useState(!1),[s,i]=v.useState(!1),a=v.useRef(null);return v.useEffect(()=>{const c=setTimeout(()=>o(!0),e);return()=>clearTimeout(c)},[e]),v.useEffect(()=>{if(r){if(n>0){i(!1),a.current&&(clearTimeout(a.current),a.current=null);return}return a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{i(!0)},t),()=>{a.current&&clearTimeout(a.current)}}},[r,n,t]),s}function EB({delayMs:e=2e3,quietMs:t=500,componentType:n,componentId:r}){const o=C_t(e,t);return v.useEffect(()=>(o&&(window.__SEMAPHOR_READY__={ready:!0,type:n,componentId:r||null,timestamp:Date.now()}),()=>{window.__SEMAPHOR_READY__={ready:!1,type:n,componentId:r||null,timestamp:Date.now()}}),[o,n,r]),l.jsx("div",{id:"idle-check","aria-hidden":"true",style:{position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:0},children:o?"ready":""})}function gye(e){if(typeof window>"u")return null;const{preferences:t}=e;return l.jsx(ui,{FallbackComponent:pT,children:l.jsx(HO,{dashboardProps:e,children:l.jsxs(IT,{children:[l.jsx(EB,{componentType:"dashboard",componentId:e.id}),l.jsx(DB,{appearance:e.appearance,children:l.jsx(pye,{preferences:t,children:l.jsx("main",{className:"flex h-full flex-col",children:l.jsx(k5,{...e,type:"dashboard",children:l.jsx(fye,{})})})})})]})})})}function S_t(e=[]){const t=v.useRef(null),n=v.useRef(null),r=v.useRef(null),[o,s]=v.useState(),i=v.useCallback(()=>{var p,g,x;const a=((p=t.current)==null?void 0:p.clientWidth)??0,c=((g=r.current)==null?void 0:g.offsetWidth)??0,u=((x=n.current)==null?void 0:x.offsetWidth)??0,f=a-c-u-8,h=Math.max(f,0);s(b=>b===h?b:h)},[]);return v.useEffect(()=>{const a=t.current;if(!a||typeof ResizeObserver>"u")return;const c=new ResizeObserver(()=>i());return c.observe(a),i(),()=>c.disconnect()},[i,...e]),{headerRef:t,leftActionsRef:n,rightActionsRef:r,titleMaxWidth:o,updateAvailableWidth:i}}function N_t({filter:e}){var g;const t=m.useDashboardStore(x=>x.isDashboardEditing),{preferences:n}=Vm(),r=mf((g=n==null?void 0:n.cardDisplay)==null?void 0:g.mode),o=m.useDashboardStore(x=>x.filterValues),s=o==null?void 0:o.some(x=>x.filterId===e.id),{removeFilterValues:i,removeFilter:a,updateFilter:c}=m.useDashboardActions(),{headerRef:u,leftActionsRef:d,rightActionsRef:f,titleMaxWidth:h,updateAvailableWidth:p}=S_t([t,s,r]);return v.useEffect(()=>{p()},[e.title,p]),l.jsxs("div",{ref:u,className:"group mb-1 flex h-5 items-center justify-between",children:[l.jsxs("div",{className:"flex grow items-center gap-2 min-w-0",children:[l.jsx("div",{className:"min-w-0 flex-1",style:h!==void 0?{maxWidth:h}:void 0,children:l.jsx(m.Label,{className:"my-1 block w-full text-sm",children:l.jsx(Di,{value:e.title||e.column,onSave:x=>c({...e,title:x}),isEditable:t,placeholder:"Filter",displayClassName:"text-sm truncate",inputClassName:"text-sm"})})}),l.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",ref:d,children:[t&&l.jsx(hz,{filter:e,isEditing:t}),t&&l.jsx("button",{onClick:()=>{i(e.id),a(e.id)},className:"text-muted-foreground hover:text-foreground",children:l.jsx(Re.X,{className:"size-3.5"})})]})]}),l.jsx("div",{className:"hidden",ref:f})]})}function j_t(){const e=m.useDashboardStore(r=>r.dashboard.filters),t=m.useDashboardStore(r=>r.theme),n=e==null?void 0:e.filter(r=>r.hide);return n!=null&&n.length?l.jsx("div",{className:m.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":t==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":t==="dark"}),children:n==null?void 0:n.map(r=>l.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[l.jsx(N_t,{filter:r}),l.jsx(uT,{filter:r})]},r.id))}):null}function k_t(){var s;const e=m.useDashboardStore(i=>i.dashboard),t=m.useDashboardStore(i=>i.selectedSheetId),n=m.useDashboardStore(i=>i.isDashboardEditing),r=(s=e.sheets)==null?void 0:s.find(i=>i.id===t),o=m.isDocumentSheet(r);return l.jsx("div",{role:"dashboard-plus-main",className:"flex min-h-0 grow basis-0 overflow-hidden",children:l.jsxs("section",{className:"flex min-h-0 grow basis-0 flex-col overflow-hidden",children:[n&&!o&&l.jsx(j_t,{}),l.jsx(fye,{})]})})}const I_t=v.lazy(()=>Promise.resolve().then(()=>require("./dashboard-controls-DlxeddZN.cjs"))),__t=v.lazy(()=>Promise.resolve().then(()=>require("./edit-dashboard-visual-X3OCnivL.cjs"))),T_t=v.lazy(()=>Promise.resolve().then(()=>require("./dashboard-json-DhS4yJfc.cjs")));function D_t({showControls:e=!1,showFooter:t=!0,...n}){const r=m.useDashboardStore(a=>a.isVisualEditing),o=m.useDashboardStore(a=>a.showDashboardJSON),{appearance:s,preferences:i}=n;return l.jsx(ui,{FallbackComponent:pT,children:l.jsx(HO,{dashboardProps:n,children:l.jsxs(IT,{children:[l.jsx(EB,{componentType:"surfboard",componentId:n.id}),l.jsxs(DB,{appearance:s,children:[l.jsx(m.$e,{toastOptions:{classNames:{toast:"max-w-[calc(100vw-2rem)] overflow-x-hidden !items-start [--toast-close-button-end:0.5rem] [--toast-close-button-start:auto] [--toast-close-button-transform:translate(0,0)] sm:max-w-[44rem]",content:"min-w-0 flex-1",icon:"mt-0.5 shrink-0",title:"max-w-full break-words pr-8",description:"max-w-full break-words",closeButton:"!top-2 h-6 w-6 rounded-md border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground"}}}),l.jsxs(pye,{preferences:i,children:[o&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(T_t,{})}),l.jsxs("main",{className:"relative flex h-full w-full flex-col overflow-hidden",children:[e&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(I_t,{})}),l.jsx("div",{className:"flex grow overflow-hidden",children:l.jsx("div",{className:"flex min-w-0 flex-1",children:l.jsxs(k5,{...n,type:"dashboard",children:[r&&l.jsx(v.Suspense,{fallback:null,children:l.jsx(__t,{})}),l.jsx(v.Activity,{mode:r?"hidden":"visible",children:l.jsx(k_t,{})})]})})})]})]})]})]})})})}const EO=[{value:"en-US",label:"English (United States)"},{value:"en-GB",label:"English (United Kingdom)"},{value:"de-DE",label:"German (Germany)"},{value:"fr-FR",label:"French (France)"},{value:"es-ES",label:"Spanish (Spain)"},{value:"it-IT",label:"Italian (Italy)"},{value:"nl-NL",label:"Dutch (Netherlands)"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"ja-JP",label:"Japanese (Japan)"},{value:"en-IN",label:"English (India)"},{value:"en-NZ",label:"English (New Zealand)"},{value:"mi-NZ",label:"Māori (New Zealand)"}],xye=new Set(["USD","EUR","GBP","CAD","AUD","JPY","CHF","INR","BRL","KWD"]),E_t=Yi.getSupportedCurrencyCodes(),M_t=E_t.filter(e=>!xye.has(e)),bye=[{value:"short",label:"Short"},{value:"medium",label:"Medium"},{value:"long",label:"Long"}],CY="2026-07-31",dR="2026-07-31T14:30:45";function MO(e){switch(e){case"viewer_user":return"user";case"viewer_tenant_user":return"tenant user";case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"session_initial":return"embedded session";case"system_default":return"system";default:return"another preference level"}}function fR(e){var t;return((t=bye.find(n=>n.value===e))==null?void 0:t.label)??e}function R_t(e){const t=EO.find(n=>n.value===e);return t?`${t.label} — ${t.value}`:e}function hR(e){return{short:e("short"),medium:e("medium"),long:e("long")}}function mR({id:e,label:t,value:n,inherited:r,inheritedSource:o,examples:s,disabled:i,onValueChange:a}){const c=n===void 0?`Inherited · ${fR(r)}`:fR(n);return l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:e,className:"text-[11px] text-muted-foreground",children:t}),l.jsxs(m.Select,{value:n??"inherit",disabled:i,onValueChange:a,children:[l.jsx(m.SelectTrigger,{id:e,size:"xs",children:l.jsx(m.SelectValue,{children:c})}),l.jsxs(m.SelectContent,{children:[l.jsx(m.SelectItem,{value:"inherit",className:"[&>span:last-child]:w-full",children:l.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-4",children:[l.jsxs("span",{children:["Inherited from ",MO(o)," ·"," ",fR(r)]}),l.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:s[r]})]})}),bye.map(u=>l.jsx(m.SelectItem,{value:u.value,className:"[&>span:last-child]:w-full",children:l.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-4",children:[l.jsx("span",{children:u.label}),l.jsx("span",{className:"shrink-0 tabular-nums text-muted-foreground",children:s[u.value]})]})},u.value))]})]})]})}function A_t({value:e,inherited:t,inheritedSources:n,onChange:r,disabled:o}){var j,k,_,T;const s=v.useId(),i=v.useId(),a=v.useId(),c=v.useId(),u=v.useId(),f=(e.locale===void 0?void 0:Yi.canonicalizeSupportedLocale(e.locale))??t.locale,h=e.defaultCurrency??t.defaultCurrency,p={locale:f,dateStyle:e.dateStyle??t.dateStyle,dateTime:{dateStyle:((j=e.dateTime)==null?void 0:j.dateStyle)??t.dateTime.dateStyle,timeStyle:((k=e.dateTime)==null?void 0:k.timeStyle)??t.dateTime.timeStyle},defaultCurrency:h},g=new Intl.NumberFormat(f,{style:"currency",currency:h}).format(1e3),x=un.resolveRawTemporalFormat({preferences:p,calendar:{tz:"UTC"}}),b=un.formatRawTemporalValue({value:CY,metadata:{kind:"raw_temporal",valueKind:"date"},format:x}).text,y=un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:x}).text,C=hR(I=>un.formatRawTemporalValue({value:CY,metadata:{kind:"raw_temporal",valueKind:"date"},format:un.resolveRawTemporalFormat({preferences:{...p,dateStyle:I},calendar:{tz:"UTC"}})}).text),w=hR(I=>un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:un.resolveRawTemporalFormat({preferences:{...p,dateTime:{...p.dateTime,dateStyle:I}},calendar:{tz:"UTC"}})}).text),N=hR(I=>un.formatRawTemporalValue({value:dR,metadata:{kind:"raw_temporal",valueKind:"wall_datetime"},format:un.resolveRawTemporalFormat({preferences:{...p,dateTime:{...p.dateTime,timeStyle:I}},calendar:{tz:"UTC"}})}).text),S=(I,D)=>{const E={...e.dateTime,[I]:D==="inherit"?void 0:D};r({...e,dateTime:E.dateStyle===void 0&&E.timeStyle===void 0?void 0:E})};return l.jsxs("div",{className:"space-y-4",children:[l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:s,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Locale"}),l.jsxs(m.Select,{value:e.locale??"inherit",disabled:o,onValueChange:I=>r({...e,locale:I==="inherit"?void 0:I}),children:[l.jsx(m.SelectTrigger,{id:s,size:"xs",children:l.jsx(m.SelectValue,{children:e.locale===void 0?`Inherited · ${t.locale}`:R_t(e.locale)})}),l.jsxs(m.SelectContent,{children:[l.jsxs(m.SelectItem,{value:"inherit",children:["Inherited from ",MO(n.locale)," ·"," ",t.locale]}),e.locale&&!EO.some(I=>I.value===e.locale)&&l.jsx(m.SelectItem,{value:e.locale,children:e.locale}),EO.map(I=>l.jsxs(m.SelectItem,{value:I.value,children:[I.label," — ",I.value]},I.value))]})]})]}),l.jsxs("fieldset",{className:"space-y-2",children:[l.jsx("legend",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Date values"}),l.jsx(mR,{id:a,label:"Format",value:e.dateStyle,inherited:t.dateStyle,inheritedSource:n.dateStyle,examples:C,disabled:o,onValueChange:I=>r({...e,dateStyle:I==="inherit"?void 0:I})})]}),l.jsxs("fieldset",{className:"space-y-2",children:[l.jsx("legend",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Date & time values"}),l.jsx(mR,{id:c,label:"Date",value:(_=e.dateTime)==null?void 0:_.dateStyle,inherited:t.dateTime.dateStyle,inheritedSource:n.dateTime.dateStyle,examples:w,disabled:o,onValueChange:I=>S("dateStyle",I)}),l.jsx(mR,{id:u,label:"Time",value:(T=e.dateTime)==null?void 0:T.timeStyle,inherited:t.dateTime.timeStyle,inheritedSource:n.dateTime.timeStyle,examples:N,disabled:o,onValueChange:I=>S("timeStyle",I)})]}),l.jsxs("div",{className:"space-y-1.5",children:[l.jsx(m.Label,{htmlFor:i,className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Default currency"}),l.jsxs(m.Select,{value:e.defaultCurrency??"inherit",disabled:o,onValueChange:I=>r({...e,defaultCurrency:I==="inherit"?void 0:I}),children:[l.jsx(m.SelectTrigger,{id:i,size:"xs",children:l.jsx(m.SelectValue,{children:e.defaultCurrency===void 0?`Inherited · ${t.defaultCurrency}`:e.defaultCurrency})}),l.jsxs(m.SelectContent,{children:[l.jsxs(m.SelectItem,{value:"inherit",children:["Inherited from ",MO(n.defaultCurrency)," ·"," ",t.defaultCurrency]}),[...xye].map(I=>l.jsx(m.SelectItem,{value:I,children:I},I)),M_t.map(I=>l.jsx(m.SelectItem,{value:I,children:I},I))]})]})]}),l.jsxs("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2",children:[l.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Preview"}),l.jsxs("dl",{className:"mt-1.5 space-y-1 text-[12px]",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Date"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:b})]}),l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Date & time"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:y})]}),l.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[l.jsx("dt",{className:"text-muted-foreground",children:"Currency"}),l.jsx("dd",{className:"text-right font-medium text-foreground",children:g})]})]})]}),l.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Currency values are not converted. Date examples use a fixed reference value and the Gregorian calendar."})]})}const RO=new Set;function yye(e){return RO.add(e),()=>{RO.delete(e)}}function MB(){RO.forEach(e=>{e()})}var F_t=Object.defineProperty,P_t=(e,t,n)=>t in e?F_t(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,D1=(e,t,n)=>P_t(e,typeof t!="symbol"?t+"":t,n);const O_t={stringify:e=>e?"true":"false",parse:e=>/^[ty1-9]/i.test(e)},L_t={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{if(typeof window<"u"&&e in window)return window[e];if(typeof global<"u"&&e in global)return global[e]})();return typeof r=="function"?r.bind(n):void 0}},$_t={stringify:e=>JSON.stringify(e),parse:e=>JSON.parse(e)};function z_t(e){return e.replace(/([a-z0-9])([A-Z])/g,(t,n,r)=>`${n}-${r.toLowerCase()}`)}function vye(e){return e.replace(/[-:]([a-z])/g,(t,n)=>`${n.toUpperCase()}`)}const B_t={stringify:e=>e.name,parse:(e,t,n)=>{const r=(()=>{const o=vye(t);if(typeof n<"u"&&o in n.container)return n.container[o]})();return typeof r=="function"?r.bind(n):void 0}},V_t={stringify:e=>`${e}`,parse:e=>parseFloat(e)},H_t={stringify:e=>e,parse:e=>e},pR={string:H_t,number:V_t,boolean:O_t,function:L_t,method:B_t,json:$_t},vy=Symbol.for("r2wc.render"),E1=Symbol.for("r2wc.connected"),Uf=Symbol.for("r2wc.context"),zi=Symbol.for("r2wc.props");function q_t(e,t,n){var r,o,s;t.props||(t.props=e.propTypes?Object.keys(e.propTypes):[]),t.events||(t.events=[]);const i=Array.isArray(t.props)?t.props.slice():Object.keys(t.props),a=Array.isArray(t.events)?t.events.slice():Object.keys(t.events),c={},u={},d={},f={};for(const p of i){c[p]=Array.isArray(t.props)?"string":t.props[p];const g=z_t(p);d[p]=g,f[g]=p}for(const p of a)u[p]=Array.isArray(t.events)?{}:t.events[p];class h extends HTMLElement{constructor(){super(),D1(this,s,!0),D1(this,o),D1(this,r,{}),D1(this,"container"),t.shadow?this.container=this.attachShadow({mode:t.shadow}):this.container=this,this[zi].container=this.container;for(const g of i){const x=d[g],b=this.getAttribute(x),y=c[g],C=y?pR[y]:null;if(y==="method"){const w=vye(x);Object.defineProperty(this[zi].container,w,{enumerable:!0,configurable:!0,get(){return this[zi][w]},set(N){this[zi][w]=N,this[vy]()}}),this[zi][g]=C.parse(b,x,this)}C!=null&&C.parse&&b&&(this[zi][g]=C.parse(b,x,this))}for(const g of a)this[zi][g]=x=>{const b=g.replace(/^on/,"").toLowerCase();this.dispatchEvent(new CustomEvent(b,{detail:x,...u[g]}))}}static get observedAttributes(){return Object.keys(f)}connectedCallback(){this[E1]=!0,this[vy]()}disconnectedCallback(){this[E1]=!1,this[Uf]&&n.unmount(this[Uf]),delete this[Uf]}attributeChangedCallback(g,x,b){const y=f[g],C=c[y],w=C?pR[C]:null;y in c&&w!=null&&w.parse&&b&&(this[zi][y]=w.parse(b,g,this),this[vy]())}[(s=E1,o=Uf,r=zi,vy)](){this[E1]&&(this[Uf]?n.update(this[Uf],this[zi]):this[Uf]=n.mount(this.container,e,this[zi]))}}for(const p of i){const g=d[p],x=c[p];Object.defineProperty(h.prototype,p,{enumerable:!0,configurable:!0,get(){return this[zi][p]},set(b){this[zi][p]=b;const y=x?pR[x]:null;if(y!=null&&y.stringify){const C=y.stringify(b,g,this);this.getAttribute(g)!==C&&this.setAttribute(g,C)}else this[vy]()}})}return h}function U_t(e,t,n){const r=Gye.createRoot(e),o=v.createElement(t,n);return r.render(o),{root:r,ReactComponent:t}}function K_t({root:e,ReactComponent:t},n){const r=v.createElement(t,n);e.render(r)}function W_t({root:e}){e.unmount()}function G_t(e,t={}){return q_t(e,t,{mount:U_t,update:K_t,unmount:W_t})}const Y_t={id:"string",version:"string",authToken:"json",placeholders:"json",defaultFilterValues:"json",defaultControlValues:"json",controlContractOverrides:"json",documentInputValues:"json",dashboardInputExecutionSnapshot:"json",interactionExecutionSnapshot:"json",presentationExecutionSnapshot:"json",renderMode:"string",currentTheme:"string",customCards:"json",customStyle:"json",appearance:"json",onChartElementClicked:"function",onFilterValuesChange:"function",onEvent:"function",onDashboardLifecycleEvent:"function",onSave:"function",LoadingComponent:"function",ErrorComponent:"function",showAssistant:"boolean",showBriefings:"boolean",selectedSheetId:"string",eventHandlers:"json",preferences:"json"},Z_t=G_t(gye,{props:Y_t}),X_t=v.memo(function({context:t="editor"}={}){return l.jsxs("div",{"data-content":"fields-section",className:"flex h-full grow flex-col items-center overflow-hidden",children:[" ",l.jsx($4,{context:t})," "]})});var wye="Toggle",Cye=ie.forwardRef((e,t)=>{const{pressed:n,defaultPressed:r,onPressedChange:o,...s}=e,[i,a]=m.useControllableState({prop:n,onChange:o,defaultProp:r??!1,caller:wye});return l.jsx(m.Primitive.button,{type:"button","aria-pressed":i,"data-state":i?"on":"off","data-disabled":e.disabled?"":void 0,...s,ref:t,onClick:m.composeEventHandlers(e.onClick,()=>{e.disabled||a(!i)})})});Cye.displayName=wye;var Sye=Cye;const Q_t=m.cva("inline-flex items-center justify-center rounded-control text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}}),Nye=ie.forwardRef(({className:e,variant:t,size:n,...r},o)=>l.jsx(Sye,{ref:o,className:m.cn(Q_t({variant:t,size:n,className:e})),...r}));Nye.displayName=Sye.displayName;function RB(){var c,u;const e=m.useEditorStore(d=>d.card),t=m.useEditorStore(d=>d.frame),n=v.useMemo(()=>rt.findCustomVisualConfigCard(t,e),[t,e]),{manifest:r}=Sf(((c=n==null?void 0:n.customCardPreferences)==null?void 0:c.url)||""),o=v.useMemo(()=>{var d;return(d=r==null?void 0:r.visuals)==null?void 0:d.find(f=>{var h;return f.name===((h=n==null?void 0:n.customCardPreferences)==null?void 0:h.componentName)})},[r,(u=n==null?void 0:n.customCardPreferences)==null?void 0:u.componentName]),s=rt.resolveMultiInputType(n,o),i=v.useMemo(()=>rt.getCustomVisualInputCards({frame:t,configCard:n,isMultiInputVisual:s==="multiple"}),[t,n,s]),a=v.useMemo(()=>{const d=i.findIndex(f=>(f==null?void 0:f.id)===e.id);return d<0?-1:rt.getSlotIndexForCard(e,d)},[i,e]);return v.useMemo(()=>!n||s!=="multiple"||a<0?e.type:rt.getEffectiveCardTypeForSlot(e,a,o==null?void 0:o.slots)??e.type,[n,s,a,e,o==null?void 0:o.slots])}function jye({storeValue:e,defaultValue:t="",onStoreUpdate:n,delay:r=300}){const[o,s]=v.useState(e??t),i=v.useRef(null),a=v.useRef(o),c=v.useRef(e),u=v.useRef(!1),d=v.useCallback(()=>{i.current&&(clearTimeout(i.current),i.current=null),u.current&&a.current!==(c.current??t)&&(n(a.current),c.current=a.current)},[t,n]);v.useEffect(()=>{if(e!==c.current){i.current&&(clearTimeout(i.current),i.current=null);const h=e??t;s(h),a.current=h,c.current=e,u.current=!1}},[e,t]),v.useEffect(()=>{if(u.current)return i.current=setTimeout(()=>{d()},r),()=>{i.current&&(clearTimeout(i.current),i.current=null)}},[r,d,o]),v.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const f=v.useCallback(h=>{const p=h??t;u.current=!0,a.current=p,s(p)},[t]);return{value:o,onChange:f,flush:d}}const J_t=300;function eTt({onExpand:e},t){const n=m.useEditorStore(w=>w.card.sql),r=m.useEditorStore(w=>w.sqlGen),o=m.useEditorStore(w=>w.card),s=RB(),{setCardSql:i,setSqlGen:a,setRunSql:c}=m.useEditorActions(),u=v.useMemo(()=>s!==o.type?{...o,type:s}:o,[o,s]),{queryKey:d}=Ax(u),f=Hr(),h=v.useRef(d);h.current=d;const p=v.useRef(r);p.current=r;const g=v.useCallback(w=>{i(w)},[i]),{value:x,onChange:b,flush:y}=jye({storeValue:n,defaultValue:"",onStoreUpdate:g,delay:J_t});v.useEffect(()=>yye(y),[y]);function C(w){b(w),m.isObjectEmpty(p.current)||a({})}return l.jsxs("div",{className:"relative h-full w-full",children:[l.jsx(m.CodeEditor,{ref:t,value:x??"",onValueChange:C,language:"sql-jinja",embedded:!0,hideLineNumbers:!0,wrapLines:!0,placeholder:"Write your SQL here",onKeyDown:w=>{w.key==="Enter"&&w.shiftKey&&(w.preventDefault(),MB(),setTimeout(()=>{f.removeQueries({queryKey:h.current,exact:!0}),c(!0)},0))}}),e?l.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"absolute right-2.5 top-2 z-20 h-7 w-7 bg-background/80 p-0 text-muted-foreground backdrop-blur-sm transition-colors hover:bg-accent hover:text-foreground focus-visible:text-foreground",onClick:e,"aria-label":"Expand SQL editor",title:"Expand SQL editor",children:l.jsx(Ft.Maximize2,{className:"h-3.5 w-3.5",strokeWidth:1.75})}):null]})}const tTt=v.forwardRef(eTt),nTt=300;function rTt(e,t){const n=m.useEditorStore(g=>g.card.python),r=m.useEditorStore(g=>g.card),o=RB(),{setCardPython:s,setRunSql:i}=m.useEditorActions(),a=v.useMemo(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:c}=Ax(a),u=Hr(),d=v.useRef(c);d.current=c;const{value:f,onChange:h,flush:p}=jye({storeValue:n,defaultValue:rt.PYTHON_DEFAULT_CODE,onStoreUpdate:s,delay:nTt});return v.useEffect(()=>yye(p),[p]),l.jsx(m.CodeEditor,{ref:t,value:f??"",onValueChange:h,language:"python",embedded:!0,hideLineNumbers:!0,wrapLines:!0,className:"[&_.code-editor-pre]:!pt-2 [&_.code-editor-textarea]:!pt-2",onKeyDown:g=>{g.key==="Enter"&&g.shiftKey&&(g.preventDefault(),MB(),setTimeout(()=>{u.removeQueries({queryKey:d.current,exact:!0}),i(!0)},0))}})}const oTt=v.forwardRef(rTt),kye=new Set(["askForMoreInfo","getAvailableChartTypes","getChartSQLSyntax","getDomainRelationships","getTableColumns","getUserSql","validateCardConfigFormat"]),sTt=new Set(["createChartFromSql","createForecast","generateQueryConfig","getChartDataFromCardConfig","getChartDataFromSqlAndPython","getForecastDataFromSqlAndPython"]),iTt=Array.from(kye).join(", "),aTt=3,lTt="Self-heal",cTt=new Set(["SQL_PARSE_ERROR","SQL_EXPLAIN_ERROR"]);function uTt({card:e}){var $,P,U,H,G;const t=yc(),[n,r]=v.useState({}),{authToken:o}=Mt(),s=m.getTokenParams(o==null?void 0:o.accessToken),{compiledAppearance:i}=fi.useAppearance(),a=v.useMemo(()=>tC(i),[i]),c=m.useEditorStore(q=>q.frame),u=m.useEditorStore(q=>q.inlineFilterValuesMap[e.id]),d=m.useEditorStore(q=>q.actions.setCardInlineFilterValue),f=m.useEditorStore(q=>q.actions.removeCardInlineFilterValue),h=e,{getCard:p,manifest:g}=Sf((($=h.customCardPreferences)==null?void 0:$.url)||""),x=(P=g==null?void 0:g.visuals)==null?void 0:P.find(q=>{var Y;return q.name===((Y=h.customCardPreferences)==null?void 0:Y.componentName)}),b=rt.resolveMultiInputType(h,x)??"single",y=v.useMemo(()=>rt.getCustomVisualInputCards({frame:c,configCard:h,isMultiInputVisual:b==="multiple"}),[c,h,b]),C=v.useMemo(()=>{const q=y.findIndex(Y=>(Y==null?void 0:Y.id)===e.id);return q<0?-1:rt.getSlotIndexForCard(e,q)},[y,e]),w=v.useMemo(()=>b!=="multiple"||C<0?e.type:rt.getEffectiveCardTypeForSlot(e,C,x==null?void 0:x.slots)??e.type,[b,C,e,x==null?void 0:x.slots]),N=v.useMemo(()=>b==="multiple"?{...e,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:w!==e.type?{...e,type:w}:e,[e,w,b]),{data:S,effectiveCardConfig:j}=Ax(N),k=m.useInteractionStore(q=>q.interactionStates),_=m.useDashboardStore(q=>{var Y;return(Y=q.dashboard)==null?void 0:Y.id}),T=m.useDashboardStore(q=>q.dashboard.filters),I=m.useDashboardStore(q=>q.filterValues),D=m.useDashboardStore(q=>q.selectedSheetId),E=v.useMemo(()=>pz({card:e,sheetId:D||"",inlineFilterValues:u,setInlineFilterValue:q=>d(e.id,q),removeInlineFilterValue:q=>f(e.id,q)}),[e,D,u,d,f]),{cardFilters:R,cardFilterValues:F}=v.useMemo(()=>zI({card:e,interactionStates:k,currentDashboardId:_,filters:T,filterValues:I,selectedSheetId:D}),[e,k,_,T,I,D]),M=v.useCallback((q,Y)=>{const W=rt.normalizeMultiInputPayload(Y);r(ne=>({...ne,[q]:W}))},[]),O=(U=h.customCardPreferences)==null?void 0:U.componentName,z=O?p(O):null,L=sk((H=h.customCardPreferences)==null?void 0:H.settings,h),V=v.useMemo(()=>rt.buildSlotOrderedCards(y),[y]),A=v.useMemo(()=>V.map((q,Y)=>rt.getEffectiveCardTypeForSlot(q,Y,x==null?void 0:x.slots)),[V,x==null?void 0:x.slots]),B=v.useMemo(()=>bz(b==="multiple"?xz({slotOrderedCards:V,multiInputData:n,valueFormatPreferences:t}):[{card:e,cardConfig:j,columns:S==null?void 0:S.columns,columnKeyMap:S==null?void 0:S.columnKeyMap,valueFormatPreferences:t}]),[e,S==null?void 0:S.columnKeyMap,S==null?void 0:S.columns,j,n,V,b,t]);return O?l.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:l.jsxs(v.Suspense,{fallback:l.jsx(l.Fragment,{}),children:[z&&b==="single"&&l.jsx(z,{editing:!0,params:s,theme:a,settings:L,cardMetadata:rde({card:e,dataMetadata:S==null?void 0:S.metadata}),onDataChange:M,data:(S==null?void 0:S.records)||[],columns:(S==null?void 0:S.columns)||[],formatTemporalBucketValue:B,filters:R,filterValues:[...F||[],...u||[]],inlineFilters:E}),z&&b==="multiple"&&l.jsxs(l.Fragment,{children:[y.map((q,Y)=>{if(!q)return null;const W=rt.getSlotIndexForCard(q,Y),ne=rt.getEffectiveCardTypeForSlot(q,W,x==null?void 0:x.slots);return l.jsx(L$,{onDataChange:M,card:q,effectiveCardType:ne},`${q.id}-${W}`)}),l.jsx("div",{className:"flex flex-col gap-2",children:l.jsx(z,{editing:!0,onDataChange:M,...gz({configCard:h,slotOrderedCards:V,slotTypes:A,multiInputData:n,params:s,theme:a,chartSettings:L,filters:R,filterValues:[...F||[],...u||[]],inlineFilters:E,formatTemporalBucketValue:B})})})]})]},(G=h.customCardPreferences)==null?void 0:G.componentName)}):null}const dTt=v.memo(uTt),fTt=m.create()(m.persist((e,t)=>({starredCharts:[],isStarred:(n,r)=>t().starredCharts.some(o=>o.type===n&&o.id===r),toggleStar:n=>{e(r=>{const o=r.starredCharts.findIndex(s=>s.type===n.type&&s.id===n.id);return o>=0?{starredCharts:r.starredCharts.filter((s,i)=>i!==o)}:{starredCharts:[...r.starredCharts,n]}})},getStarredChart:(n,r)=>t().starredCharts.find(o=>o.type===n&&o.id===r)}),{name:"semaphor-starred-charts"}));var Iye=["PageUp","PageDown"],_ye=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Tye={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Db="Slider",[AO,hTt,mTt]=m.createCollection(Db),[Dye]=m.createContextScope(Db,[mTt]),[pTt,aD]=Dye(Db),Eye=ie.forwardRef((e,t)=>{const{name:n,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:u=[r],value:d,onValueChange:f=()=>{},onValueCommit:h=()=>{},inverted:p=!1,form:g,...x}=e,b=ie.useRef(new Set),y=ie.useRef(0),w=i==="horizontal"?gTt:xTt,[N=[],S]=m.useControllableState({prop:d,defaultProp:u,onChange:D=>{var R;(R=[...b.current][y.current])==null||R.focus(),f(D)}}),j=ie.useRef(N);function k(D){const E=CTt(N,D);I(D,E)}function _(D){I(D,y.current)}function T(){const D=j.current[y.current];N[y.current]!==D&&h(N)}function I(D,E,{commit:R}={commit:!1}){const F=kTt(s),M=ITt(Math.round((D-r)/s)*s+r,F),O=m.clamp(M,[r,o]);S((z=[])=>{const L=vTt(z,O,E);if(jTt(L,c*s)){y.current=L.indexOf(O);const V=String(L)!==String(z);return V&&R&&h(L),V?L:z}else return z})}return l.jsx(pTt,{scope:e.__scopeSlider,name:n,disabled:a,min:r,max:o,valueIndexToChangeRef:y,thumbs:b.current,values:N,orientation:i,form:g,children:l.jsx(AO.Provider,{scope:e.__scopeSlider,children:l.jsx(AO.Slot,{scope:e.__scopeSlider,children:l.jsx(w,{"aria-disabled":a,"data-disabled":a?"":void 0,...x,ref:t,onPointerDown:m.composeEventHandlers(x.onPointerDown,()=>{a||(j.current=N)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:k,onSlideMove:a?void 0:_,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&I(r,0,{commit:!0}),onEndKeyDown:()=>!a&&I(o,N.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:E})=>{if(!a){const M=Iye.includes(D.key)||D.shiftKey&&_ye.includes(D.key)?10:1,O=y.current,z=N[O],L=s*M*E;I(z+L,O,{commit:!0})}}})})})})});Eye.displayName=Db;var[Mye,Rye]=Dye(Db,{startEdge:"left",endEdge:"right",size:"width",direction:1}),gTt=ie.forwardRef((e,t)=>{const{min:n,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:u,...d}=e,[f,h]=ie.useState(null),p=m.useComposedRefs(t,w=>h(w)),g=ie.useRef(void 0),x=m.useDirection(o),b=x==="ltr",y=b&&!s||!b&&s;function C(w){const N=g.current||f.getBoundingClientRect(),S=[0,N.width],k=AB(S,y?[n,r]:[r,n]);return g.current=N,k(w-N.left)}return l.jsx(Mye,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:l.jsx(Aye,{dir:x,"data-orientation":"horizontal",...d,ref:p,style:{...d.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:w=>{const N=C(w.clientX);i==null||i(N)},onSlideMove:w=>{const N=C(w.clientX);a==null||a(N)},onSlideEnd:()=>{g.current=void 0,c==null||c()},onStepKeyDown:w=>{const S=Tye[y?"from-left":"from-right"].includes(w.key);u==null||u({event:w,direction:S?-1:1})}})})}),xTt=ie.forwardRef((e,t)=>{const{min:n,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...u}=e,d=ie.useRef(null),f=m.useComposedRefs(t,d),h=ie.useRef(void 0),p=!o;function g(x){const b=h.current||d.current.getBoundingClientRect(),y=[0,b.height],w=AB(y,p?[r,n]:[n,r]);return h.current=b,w(x-b.top)}return l.jsx(Mye,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1,children:l.jsx(Aye,{"data-orientation":"vertical",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:x=>{const b=g(x.clientY);s==null||s(b)},onSlideMove:x=>{const b=g(x.clientY);i==null||i(b)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:x=>{const y=Tye[p?"from-bottom":"from-top"].includes(x.key);c==null||c({event:x,direction:y?-1:1})}})})}),Aye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...u}=e,d=aD(Db,n);return l.jsx(m.Primitive.span,{...u,ref:t,onKeyDown:m.composeEventHandlers(e.onKeyDown,f=>{f.key==="Home"?(i(f),f.preventDefault()):f.key==="End"?(a(f),f.preventDefault()):Iye.concat(_ye).includes(f.key)&&(c(f),f.preventDefault())}),onPointerDown:m.composeEventHandlers(e.onPointerDown,f=>{const h=f.target;h.setPointerCapture(f.pointerId),f.preventDefault(),d.thumbs.has(h)?h.focus():r(f)}),onPointerMove:m.composeEventHandlers(e.onPointerMove,f=>{f.target.hasPointerCapture(f.pointerId)&&o(f)}),onPointerUp:m.composeEventHandlers(e.onPointerUp,f=>{const h=f.target;h.hasPointerCapture(f.pointerId)&&(h.releasePointerCapture(f.pointerId),s(f))})})}),Fye="SliderTrack",Pye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=aD(Fye,n);return l.jsx(m.Primitive.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:t})});Pye.displayName=Fye;var FO="SliderRange",Oye=ie.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=aD(FO,n),s=Rye(FO,n),i=ie.useRef(null),a=m.useComposedRefs(t,i),c=o.values.length,u=o.values.map(h=>zye(h,o.min,o.max)),d=c>1?Math.min(...u):0,f=100-Math.max(...u);return l.jsx(m.Primitive.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...e.style,[s.startEdge]:d+"%",[s.endEdge]:f+"%"}})});Oye.displayName=FO;var PO="SliderThumb",Lye=ie.forwardRef((e,t)=>{const n=hTt(e.__scopeSlider),[r,o]=ie.useState(null),s=m.useComposedRefs(t,a=>o(a)),i=ie.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return l.jsx(bTt,{...e,ref:s,index:i})}),bTt=ie.forwardRef((e,t)=>{const{__scopeSlider:n,index:r,name:o,...s}=e,i=aD(PO,n),a=Rye(PO,n),[c,u]=ie.useState(null),d=m.useComposedRefs(t,C=>u(C)),f=c?i.form||!!c.closest("form"):!0,h=m.useSize(c),p=i.values[r],g=p===void 0?0:zye(p,i.min,i.max),x=wTt(r,i.values.length),b=h==null?void 0:h[a.size],y=b?STt(b,g,a.direction):0;return ie.useEffect(()=>{if(c)return i.thumbs.add(c),()=>{i.thumbs.delete(c)}},[c,i.thumbs]),l.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${y}px)`},children:[l.jsx(AO.ItemSlot,{scope:e.__scopeSlider,children:l.jsx(m.Primitive.span,{role:"slider","aria-label":e["aria-label"]||x,"aria-valuemin":i.min,"aria-valuenow":p,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:d,style:p===void 0?{display:"none"}:e.style,onFocus:m.composeEventHandlers(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),f&&l.jsx($ye,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:p},r)]})});Lye.displayName=PO;var yTt="RadioBubbleInput",$ye=ie.forwardRef(({__scopeSlider:e,value:t,...n},r)=>{const o=ie.useRef(null),s=m.useComposedRefs(o,r),i=m.usePrevious(t);return ie.useEffect(()=>{const a=o.current;if(!a)return;const c=window.HTMLInputElement.prototype,d=Object.getOwnPropertyDescriptor(c,"value").set;if(i!==t&&d){const f=new Event("input",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),l.jsx(m.Primitive.input,{style:{display:"none"},...n,ref:s,defaultValue:t})});$ye.displayName=yTt;function vTt(e=[],t,n){const r=[...e];return r[n]=t,r.sort((o,s)=>o-s)}function zye(e,t,n){const s=100/(n-t)*(e-t);return m.clamp(s,[0,100])}function wTt(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function CTt(e,t){if(e.length===1)return 0;const n=e.map(o=>Math.abs(o-t)),r=Math.min(...n);return n.indexOf(r)}function STt(e,t,n){const r=e/2,s=AB([0,50],[0,r]);return(r-s(t)*n)*n}function NTt(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function jTt(e,t){if(t>0){const n=NTt(e);return Math.min(...n)>=t}return!0}function AB(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function kTt(e){return(String(e).split(".")[1]||"").length}function ITt(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}var Bye=Eye,_Tt=Pye,TTt=Oye,DTt=Lye;const Vye=ie.forwardRef(({className:e,...t},n)=>l.jsxs(Bye,{ref:n,className:m.cn("relative flex w-full touch-none select-none items-center",e),...t,children:[l.jsx(_Tt,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:l.jsx(TTt,{className:"absolute h-full bg-primary"})}),l.jsx(DTt,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}));Vye.displayName=Bye.displayName;exports.Accordion=ope;exports.AccordionContent=Lk;exports.AccordionItem=Pk;exports.AccordionTrigger=Ok;exports.AddDataPicker=vB;exports.AggregateTable=z_;exports.Alert=DL;exports.AlertDescription=EL;exports.AlertDialog=ff;exports.AlertDialogAction=Au;exports.AlertDialogCancel=Fu;exports.AlertDialogContent=Tu;exports.AlertDialogDescription=Ru;exports.AlertDialogFooter=Eu;exports.AlertDialogHeader=Du;exports.AlertDialogTitle=Mu;exports.AlertDialogTrigger=t1e;exports.AlertTitle=Yte;exports.ArrowDown=No;exports.ArrowDownIcon=OQe;exports.ArrowLeft=ow;exports.ArrowRight=sw;exports.ArrowUp=cs;exports.ArrowUpIcon=$Qe;exports.AssistantContextEntityControls=TO;exports.AssistantVirtualizedMessages=lye;exports.AxisConfigurator=Zm;exports.BackgroundRunPill=jut;exports.Badge=ki;exports.Bell=F1;exports.BookType=OZ;exports.BriefingAuthor=$he;exports.BriefingAuthorDialog=zhe;exports.BriefingUiCapabilitiesBoundary=Wut;exports.BriefingUiCapabilitiesProvider=IT;exports.BriefingsApiError=uC;exports.BulletChartIcon=eye;exports.CSS=Pi;exports.CalculatedFieldEditor=ape;exports.Calculator=$Z;exports.Calendar=Ya;exports.CalendarClock=ZO;exports.Card=FN;exports.CardContent=YO;exports.CardHeader=GO;exports.CardSummary=AP;exports.CardTitle=Ix;exports.ChartArea=BR;exports.ChartColumnIncreasing=BZ;exports.ChartColumnStacked=VZ;exports.ChartJsVisual=Yw;exports.ChartLine=HZ;exports.ChartNoAxesGantt=UZ;exports.ChartPie=KZ;exports.ChartScatter=WZ;exports.ChatInputWithContext=IB;exports.Checkbox=jn;exports.ChevronLeft=Om;exports.ChevronsUpDown=ZZ;exports.Circle=XO;exports.CircleAlert=ea;exports.CircleCheck=XZ;exports.CircleHelp=QZ;exports.Clock=JZ;exports.CodeHighlighter=Od;exports.CodeXml=P1;exports.Collapsible=Nu;exports.CollapsibleContent=ku;exports.CollapsibleTrigger=ju;exports.ColorField=Na;exports.Command=CB;exports.CommandEmpty=NB;exports.CommandGroup=jB;exports.CommandInput=zbe;exports.CommandItem=kB;exports.CommandList=SB;exports.CommandSeparator=Bbe;exports.ComparisonMetadataBadge=dse;exports.Container=k5;exports.ControlDefaultValueEditor=Epe;exports.ControlDefinitionOptionsEditor=Dpe;exports.ControlIdInput=kpe;exports.ControlVisibilitySettings=Wgt;exports.Copy=gu;exports.CopyButton=Pd;exports.CopyPlus=VR;exports.Cross2Icon=HQe;exports.CustomFilterPopover=hz;exports.CustomScrollArea=$u;exports.DEFAULT_HEATMAP_CUSTOM_RANGE=goe;exports.Dashboard=gye;exports.DashboardCard=Uhe;exports.DashboardCreateDialogBase=HQ;exports.DashboardExportDialog=cye;exports.DashboardPlus=D_t;exports.DashboardWC=Z_t;exports.DataTableConditionalFormattingSettings=yge;exports.DataTablePagination=E_;exports.Database=ps;exports.DateRangePicker=lz;exports.DefaultChatTransport=uB;exports.Dialog=To;exports.DialogContent=bo;exports.DialogDescription=Ho;exports.DialogFooter=ll;exports.DialogHeader=$s;exports.DialogTitle=yo;exports.DialogTrigger=zQ;exports.DisplayFormatPreferencesFields=A_t;exports.DisplayPreferencesProvider=xT;exports.DndContext=Sb;exports.Donut=eX;exports.Download=ac;exports.DownloadPdf=uye;exports.DragOverlay=Cme;exports.DropdownMenu=Bo;exports.DropdownMenuCheckboxItem=ed;exports.DropdownMenuContent=_o;exports.DropdownMenuItem=ln;exports.DropdownMenuLabel=Zi;exports.DropdownMenuRadioGroup=FCe;exports.DropdownMenuRadioItem=hQ;exports.DropdownMenuSeparator=ii;exports.DropdownMenuSub=g5;exports.DropdownMenuSubContent=gI;exports.DropdownMenuSubTrigger=pI;exports.DropdownMenuTrigger=Vo;exports.EMPTY_DATA_SOURCE=jx;exports.Editable=ak;exports.EditableText=Di;exports.EditorCustomVisual=dTt;exports.Ellipsis=Ai;exports.EllipsisVertical=Lm;exports.ErrorBoundary=ui;exports.ExportDialog=Fw;exports.ExportError=Lx;exports.ExternalLink=$d;exports.EyeOff=uI;exports.Fallback=pT;exports.FallbackVisual=aC;exports.FeedbackCategory=lf;exports.FeedbackDialog=q0;exports.FieldOptionList=PT;exports.FieldsList=$4;exports.FieldsSection=X_t;exports.FileCode=tX;exports.FileText=li;exports.Filter=xu;exports.FilterComponent=uT;exports.FilterInfo=DP;exports.FilterOptionList=dz;exports.FilterableFieldsPanel=cpe;exports.GRIP_REVEAL_CLASS=Xze;exports.Grid3x3=HR;exports.GripVertical=Iu;exports.HEATMAP_PRESET_PALETTES=rF;exports.Hash=_x;exports.House=nX;exports.HoverCard=ep;exports.HoverCardContent=wu;exports.HoverCardTrigger=Yd;exports.INLINE_ALLOWED_READ_ONLY_TOOLS=kye;exports.INLINE_ALLOWED_TOOL_LIST=iTt;exports.INLINE_BLOCKED_MUTATING_TOOLS=sTt;exports.IconButton=ou;exports.Inbox=dI;exports.InfoHover=Az;exports.InlineFilterBar=Ade;exports.KPICard=tf;exports.KeyboardSensor=yC;exports.Layers=zm;exports.LayoutDashboard=zd;exports.Link=JO;exports.LoadingDots=Cu;exports.MAX_SELF_HEAL_ATTEMPTS=aTt;exports.Map=iX;exports.Markdown=s4;exports.MatrixCardView=$_;exports.MatrixStructuralTargets=zpe;exports.MdStackedLineChart=Qbe;exports.MultiInputEmptyRenderer=L$;exports.PanelResizeHandle=QT;exports.Pause=aX;exports.PenLine=KR;exports.Pencil=WR;exports.PendingMessagesDisplay=Vbe;exports.PersistedDynamicVisual=gT;exports.PiChartPolar=Gbe;exports.PivotTableTanstack=pb;exports.Placeholders=Wge;exports.Play=lX;exports.Plus=Ar;exports.PointerSensor=cp;exports.Progress=gB;exports.PythonEditor=oTt;exports.RECOVERABLE_SQL_ERROR_CODES=cTt;exports.Radar=cX;exports.RadioGroup=cc;exports.RadioGroupItem=Ms;exports.RefreshCw=Ma;exports.ResizableHandle=d0t;exports.ResizablePanel=pO;exports.ResizablePanelGroup=Kge;exports.ResourceEditDialog=vJ;exports.ResourceType=uo;exports.Rows3=uX;exports.RunCompletionBanner=kut;exports.SELF_HEAL_TIMELINE_STEP=lTt;exports.SeedQuestions=xbe;exports.SemaphorContext=J0;exports.SemaphorContextProvider=HO;exports.SemaphorQueryClient=uZ;exports.SemaphorReadyIndicator=EB;exports.SemaphorStyleWrapper=gb;exports.Send=t5;exports.SendHorizontal=dX;exports.Settings=n5;exports.Settings2=uf;exports.Share2=fX;exports.ShareDialog=yJ;exports.Sheet=O3;exports.SheetContent=M_;exports.SheetDescription=A_;exports.SheetHeader=ese;exports.SheetTitle=R_;exports.SheetTrigger=Eze;exports.Slider=Vye;exports.SortableContext=Nb;exports.Sparkles=Ov;exports.SqlEditor=tTt;exports.Square=o5;exports.SquarePen=r5;exports.Star=hX;exports.StructuralParticipantSelector=Ipe;exports.SummaryCard=IP;exports.TABLE_PRESENTATION_DEFAULT_STYLE=Ad;exports.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE=ka;exports.TableBody=hm;exports.TableCell=hr;exports.TableColumnVisibilitySettings=uge;exports.TableHead=Ni;exports.TableHeader=Wx;exports.TablePresentationSettings=fge;exports.TableRow=io;exports.TableSkeleton=Pz;exports.TableVisual=Zd;exports.Tag=mX;exports.TbChartBubble=Ybe;exports.TbChartFunnel=Zbe;exports.TbChartTreemap=Xbe;exports.TextCard=xx;exports.Textarea=qm;exports.TiSortNumerically=Jbe;exports.Toggle=Nye;exports.Tornado=pX;exports.Trash2=Ra;exports.TriangleAlert=Br;exports.TypeGlyph=mC;exports.UXProvider=DB;exports.Undo2=gX;exports.User=i5;exports.Users=fI;exports.UsersRound=a5;exports.VisualErrorState=bde;exports.Zap=GR;exports.applyBriefingFormPatch=I0;exports.applyMatrixEditorResult=Tse;exports.areContextEntitiesEqual=mr;exports.arrayMove=up;exports.briefingFormDraftToCreateRequest=PP;exports.briefingFormDraftToUpdateRequest=bfe;exports.briefingToFormDraft=cg;exports.briefingTone=Er;exports.buildCardControlUsageById=Ygt;exports.buildCustomCardTheme=tC;exports.buildDashboardControlUsageById=Ggt;exports.buildDashboardSheetsInputExecutionSnapshot=WO;exports.buildDashboardStructuralParticipantIdsByControlId=Ape;exports.buildFilterFieldMeta=LO;exports.buildFilterSemanticContext=$O;exports.buildInlineFilterNodes=pz;exports.buildMultiInputCustomVisualProps=gz;exports.buildMultiInputTemporalPresentationInputs=xz;exports.calculateCardFilterValues=$I;exports.calculateContextAwareFilters=zI;exports.canEditLocalCalculatedFields=O4;exports.canUserAccessVisuals=aNe;exports.canUserCreateDashboards=CJ;exports.canUserEdit=oNe;exports.canUserManageDashboards=iNe;exports.canUserManageGroups=lNe;exports.canUserUseFilters=sNe;exports.cancelBriefingPreviewRun=ife;exports.cancelBriefingRun=lfe;exports.cancelExport=sDe;exports.chartSupportsDataLabels=hre;exports.chartSupportsLegend=dre;exports.chartTypes=iD;exports.cleanupKpiMetricComparisonMode=Fme;exports.cloneLinkedFrameWithSourceMapping=Ctt;exports.closestCenter=wb;exports.commitSharedCalculatedFields=Jf;exports.compileDashboardCardFilters=gw;exports.createAssistantConversationId=Zp;exports.createAssistantRequestId=pbe;exports.createBriefing=Qde;exports.createBriefingFormDraft=FP;exports.createChartConfig=Ux;exports.createCustomVisualTemporalBucketFormatter=bz;exports.createDashboardControlInputFromControl=Qyt;exports.createExplicitDashboardInputTargetContext=Xle;exports.createExport=kL;exports.currencyPresentationTargetKey=Ta;exports.dedup=ijt;exports.dedupeContextEntities=h4;exports.deleteBriefing=tfe;exports.deleteBriefingRun=cfe;exports.describeDataSourceConnections=R3e;exports.diagnoseCurrencyPresentationBindings=p0e;exports.doesStoredFilterMatchField=qg;exports.downloadDocumentPdf=NL;exports.downloadPdf=jte;exports.extractTableMetadata=I4;exports.fieldAlreadyExists=Soe;exports.flexRender=_i;exports.flushPendingEditorDrafts=MB;exports.formatDisplayFormula=Cmt;exports.formatFileSize=lDe;exports.getAutoDetectedChartIcon=lIt;exports.getBriefing=Xde;exports.getBriefingArtifact=knt;exports.getBriefingEvidence=Int;exports.getBriefingPreviewRun=sfe;exports.getBriefingRun=afe;exports.getCalculatedGlyphKind=_4;exports.getCardCurrencyPresentationFields=bZ;exports.getCardCurrencyPresentationTargets=cI;exports.getChartGridStyle=mEe;exports.getChartIconByType=cIt;exports.getColorForValue=gA;exports.getCoreRowModel=__;exports.getDefaultAxisConfig=CA;exports.getDefaultChartColors=Ym;exports.getDefaultDataLabelsConfig=Dw;exports.getDefaultLegendConfig=s3;exports.getDefaultRunningTotalPartitionByFieldIds=Iv;exports.getDisplayedKpiResultColumnKeys=Rw;exports.getDocumentSectionEditorCard=Igt;exports.getDocumentSheetDashboardInputs=kb;exports.getDownloadUrl=oDe;exports.getEntityIcon=tI;exports.getErrorMessage=tbe;exports.getExportStatus=rDe;exports.getExports=nDe;exports.getExpressionFieldKind=nf;exports.getFieldDisplayLabel=fo;exports.getFieldExpressionAnnotation=T4;exports.getFieldStateCopy=N3;exports.getFilterCount=Oz;exports.getFilterOptionValueIdentity=qn;exports.getFilterSourceDatabase=zY;exports.getGranularityOptionsForFieldType=jpe;exports.getKeys=Sr;exports.getMetricDisplayLabel=P3e;exports.getNewField=_oe;exports.getPaginationRowModel=T_;exports.getRoleBasedDisplayOverrides=wJ;exports.getRunningTotalOrderByCandidates=amt;exports.getSelectedDateFilterColumn=Tue;exports.getSemanticDomainLabel=Ebe;exports.getSortedRowModel=Qoe;exports.getTableConditionalFormattingColumnOptions=mge;exports.getTableOutputColumnOptions=pge;exports.handleAggregationChange=EP;exports.handleAggregationLabelChange=Mde;exports.hasFlatTableTotalsBehavior=Gm;exports.horizontalListSortingStrategy=FT;exports.inferSemanticDomainIdFromSelectedEntities=eI;exports.isActiveBriefingRunStatus=bk;exports.isBlockedFieldState=fm;exports.isCardSummaryVisibleOnCard=yz;exports.isCurrencyPresentationControl=h0e;exports.isDefaultColor=pTe;exports.isDevPaginationSwitchableCard=Loe;exports.isEligibleFlatTableTotalsCard=ww;exports.isExportComplete=aDe;exports.isExportInProgress=iDe;exports.isInAiScopeArray=sjt;exports.isManagedCalculatedExpressionField=il;exports.isMetricTransformEnabled=smt;exports.isPresentationCurrencyBinding=nw;exports.isPromiseLike=kO;exports.isRuleReadyToApply=Yh;exports.isSqlBackedKpi=Toe;exports.isStructuralControlBinding=f0e;exports.isSubtotalEnabledAggregateTable=k4;exports.isSupportedDocumentTableCardType=_gt;exports.isTableNumericPresentationCardType=qO;exports.isTableType=JDe;exports.isTerminalBriefingRunStatus=xk;exports.lastAssistantMessageIsCompleteWithToolCalls=Xxe;exports.listBriefingRuns=jnt;exports.listBriefingTenantSummaries=Nnt;exports.listBriefings=Snt;exports.merge=sc;exports.mergeAxisConfig=SA;exports.normalizeConditionalFormatting=rL;exports.normalizeContextFormatMode=Qee;exports.pauseBriefing=Jde;exports.pivotData=Nw;exports.polishBriefingText=ufe;exports.prepareFeedbackData=sD;exports.previewBriefingPlan=rfe;exports.remarkGfm=c4;exports.removeFromScopeArray=ajt;exports.resolveCurrencyPresentationTargetFormat=nte;exports.resolveDashboardBriefingsVisibility=Bhe;exports.resolveDashboardControlsVisibility=fNe;exports.resolveDashboardTitleEditability=dNe;exports.resolveDomainCalculatedFieldForEdit=Ppt;exports.resolveMatrixCardMeasures=lI;exports.resolvePendingPivotTableResultState=c$e;exports.resolveTableConditionalFormatting=dL;exports.resolveTableFormattingColumns=ZI;exports.resolveTablePresentationStyle=K3;exports.resumeBriefing=efe;exports.runBriefingNow=nfe;exports.runBriefingPreview=ofe;exports.sanitizeAIScope=ebe;exports.saveCalculatedFieldToCardScope=sO;exports.saveCalculatedFieldToSharedScope=lpe;exports.saveCalculatedFieldToSheetScope=iO;exports.seedSemanticMetricFormatDefaults=Ome;exports.setTableColumnVisibility=Boe;exports.setupEditorWithCard=e_;exports.showAllTableColumns=T$e;exports.showJoinRequiredNotification=lF;exports.sortByColumnsToSortState=Cse;exports.sortStateToSortByColumns=Sse;exports.sortableKeyboardCoordinates=v4;exports.supportsLiveNumericPresentation=tw;exports.supportsMetricTransformForMetric=Pme;exports.supportsTableConditionalFormatting=hge;exports.toEntityArray=sl;exports.updateBriefing=yT;exports.useActiveExports=bNe;exports.useActiveToolStatus=qbe;exports.useAddFrameWithFreshSemanticExecutionPayload=Rz;exports.useAddNewFrame=Qhe;exports.useAssistantContainer=kJ;exports.useAssistantContextEntities=_T;exports.useAssistantLayoutStore=Rh;exports.useAssistantPanel=NJ;exports.useAssistantProfile=gbe;exports.useAutoSubmitQueue=Hbe;exports.useBrandStudioPreview=x_t;exports.useBriefingRunPolling=LP;exports.useBriefingUiCapabilities=Vhe;exports.useCalendarContext=q3e;exports.useCard=X3e;exports.useCardNumericPresentation=wl;exports.useCardQueryContext=k_;exports.useCardSummary=vz;exports.useChartNumericPresentation=Kx;exports.useChat=Jxe;exports.useColumns=C4;exports.useCreateVisualWithFrame=oSe;exports.useCurrentUserInfo=hi;exports.useCustomVisual=Sf;exports.useCustomVisualsQuery=fz;exports.useDashboardAppearance=Pu;exports.useDashboardById=wQ;exports.useDashboardInteractionMode=_de;exports.useDashboardPreferences=Vm;exports.useDashboardQuery=ew;exports.useDashboardStructuralParticipants=Ppe;exports.useDashboardSummary=ude;exports.useDataColumns=$me;exports.useDateFilterHook=dYe;exports.useDefaultDashboardMutation=pQ;exports.useDisplayPreferences=bl;exports.useDroppable=wme;exports.useEditorAside=OT;exports.useEditorCardQuery=Ax;exports.useEffectiveEditorCardType=RB;exports.useEnsureReactGlobals=Yle;exports.useExportActions=IJ;exports.useExportStore=jI;exports.useFieldAvailabilityContext=j4;exports.useFieldManagement=Lme;exports.useFilterOptionBrowse=B$;exports.useFilterableFields=N4;exports.useFullscreenAssistant=jJ;exports.useGroupMembers=i1e;exports.useGroups=N5;exports.useHasDashboardId=_J;exports.useInProgressExportsCount=yNe;exports.useManagementActions=Pm;exports.useManagementStore=Ls;exports.useMatrixEditorCatalog=Rme;exports.useMatrixEditorRefresh=ABe;exports.useMatrixSourceCatalog=Pw;exports.useMutation=Os;exports.usePivotTableConfig=Qm;exports.usePluginQuery=Vue;exports.useQuery=Yn;exports.useQueryClient=Hr;exports.useReactTable=D_;exports.useResolveExistingFrameSemanticExecutionPayload=ktt;exports.useResolvedDefaultCurrency=_3;exports.useResolvedTemporalStylePreferences=yc;exports.useResolvedValueFormatLocale=I3;exports.useResourceManagement=y5;exports.useResourceUpdateState=CQ;exports.useScopedFields=Mme;exports.useSelectedVisual=n0e;exports.useSemanticDomains=xB;exports.useSemaphorContext=Mt;exports.useSensor=Em;exports.useSensors=bC;exports.useSortable=dp;exports.useStarredChartsStore=fTt;exports.useSurfaceAppearance=xl;exports.useTableQueryState=fse;exports.useTextFilterHook=HUe;exports.useTheme=BY;exports.useTimezone=vl;exports.useTopoJson=Mw;exports.useUnifiedUsers=SI;exports.useUpdateResource=xQ;exports.useUpdateVisualMutation=sSe;exports.useUserPreferences=qQ;exports.useVisualById=bI;exports.useVisualManagement=rSe;exports.validateBriefingFormDraft=OP;exports.validateEntityConsistency=aF;exports.validateFieldForChartType=Ame;exports.verticalListSortingStrategy=y4;