react-semaphor 0.1.503 → 0.1.505

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 (1469) 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-COqlnnQ2.js → dashboard-briefing-launcher-BBVlEuJl.js} +9 -9
  12. package/dist/chunks/{dashboard-briefing-launcher-CHMQi0pU.cjs → dashboard-briefing-launcher-R-CLgW59.cjs} +1 -1
  13. package/dist/chunks/{dashboard-controls-D8z05ZfX.cjs → dashboard-controls-Dn0c-Jgk.cjs} +1 -1
  14. package/dist/chunks/{dashboard-controls-Bp6XzVvx.js → dashboard-controls-XHwfYtUp.js} +11 -11
  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-Dw7kHCe5.js → dashboard-json-C9De0xQW.js} +7 -7
  18. package/dist/chunks/{dashboard-json-DcvkxkL3.cjs → dashboard-json-DU9vM9ea.cjs} +1 -1
  19. package/dist/chunks/{edit-dashboard-visual-D5vvLzkS.js → edit-dashboard-visual-DBrMclKq.js} +5068 -5089
  20. package/dist/chunks/edit-dashboard-visual-tNmK5bv7.cjs +172 -0
  21. package/dist/chunks/{editor-action-buttons-DYiJr5u3.js → editor-action-buttons-CQLAY7ew.js} +6 -6
  22. package/dist/chunks/{editor-action-buttons-BsWibSiV.cjs → editor-action-buttons-DdL6ijh_.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-C3rUIii0.cjs → index-2ahqRcel.cjs} +173 -173
  28. package/dist/chunks/{index-BVIet238.js → index-BVr4fcCB.js} +11 -11
  29. package/dist/chunks/{index-Bh3SlWJS.cjs → index-BlYf8gNa.cjs} +1 -1
  30. package/dist/chunks/{index-ZKSLtc9_.js → index-DfVIKxCM.js} +15830 -15735
  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-BZvi_3DV.cjs → report-preferences-dialog-Bt6UB734.cjs} +1 -1
  58. package/dist/chunks/{report-preferences-dialog-BXaILrOK.js → report-preferences-dialog-DVuwK7P1.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-Dej7zCoP.cjs → switch-BytP6QY8.cjs} +26 -26
  66. package/dist/chunks/{switch-DWM8d-UR.js → switch-DHGiC0aU.js} +1810 -1785
  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 -10878
  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 -27074
  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 -10910
  1465. package/dist/types/types.d.ts +2 -12279
  1466. package/dist/types/value-format-preferences.d.ts +2 -129
  1467. package/package.json +3 -2
  1468. package/dist/chunks/edit-dashboard-visual-olfXEK5D.cjs +0 -172
  1469. package/dist/chunks/validators-D2F_uxxP.cjs +0 -1
@@ -1,172 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("react"),a=require("./index-C3rUIii0.cjs"),le=require("./x-B6ghREd2.cjs"),t=require("./switch-Dej7zCoP.cjs"),je=require("./constants-DNgpRMaX.cjs"),st=require("./validators-D2F_uxxP.cjs");require("./matrix-operation-contract-thtFuUYf.cjs");const $t=require("../value-format-preferences/index.cjs"),Ze=require("./field-aggregations-mlkON_QA.cjs"),Ke=require("./search-BqqhaMx9.cjs"),pt=require("./editor-action-buttons-BsWibSiV.cjs"),wt=require("./calculated-field-identity-CtYhhZoG.cjs");require("zod");const xe=require("./index-Bh3SlWJS.cjs"),hr=require("react-dom");require("./appearance-runtime-provider-Ca8rxO86.cjs");const pr=require("./appearance-context-tNjvTJj3.cjs");require("./index-C8XCKzB6.cjs");require("./matrix-continuation-6nhDy-lF.cjs");require("./color-CyB5o13F.cjs");const fr=require("./matrix-control-sources-a67fwoOO.cjs"),ht=require("./matrix-definition-CKVi4VVg.cjs"),sa=require("./raw-temporal-DYoPBY6B.cjs"),In=require("./metric-comparison-CAqV6VnZ.cjs"),na=require("./matrix-formatter-CWtdnbfv.cjs"),gr=require("./semantic-format-C7Goni6h.cjs"),br=require("./palette-BN-jYtaK.cjs");function jr(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(n,r,o.get?o:{enumerable:!0,get:()=>s[r]})}}return n.default=s,Object.freeze(n)}const os=jr(v);/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const vr=le.createLucideIcon("ArrowDownAZ",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const yr=le.createLucideIcon("ArrowUpAZ",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const aa=le.createLucideIcon("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const ra=le.createLucideIcon("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);/**
22
- * @license lucide-react v0.453.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const ks=le.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
27
- * @license lucide-react v0.453.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const Cr=le.createLucideIcon("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
32
- * @license lucide-react v0.453.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const Nr=le.createLucideIcon("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
37
- * @license lucide-react v0.453.0 - ISC
38
- *
39
- * This source code is licensed under the ISC license.
40
- * See the LICENSE file in the root directory of this source tree.
41
- */const Sr=le.createLucideIcon("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
42
- * @license lucide-react v0.453.0 - ISC
43
- *
44
- * This source code is licensed under the ISC license.
45
- * See the LICENSE file in the root directory of this source tree.
46
- */const wr=le.createLucideIcon("Fullscreen",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]]);/**
47
- * @license lucide-react v0.453.0 - ISC
48
- *
49
- * This source code is licensed under the ISC license.
50
- * See the LICENSE file in the root directory of this source tree.
51
- */const Tr=le.createLucideIcon("GitCompareArrows",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]);/**
52
- * @license lucide-react v0.453.0 - ISC
53
- *
54
- * This source code is licensed under the ISC license.
55
- * See the LICENSE file in the root directory of this source tree.
56
- */const Er=le.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
57
- * @license lucide-react v0.453.0 - ISC
58
- *
59
- * This source code is licensed under the ISC license.
60
- * See the LICENSE file in the root directory of this source tree.
61
- */const Ir=le.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
62
- * @license lucide-react v0.453.0 - ISC
63
- *
64
- * This source code is licensed under the ISC license.
65
- * See the LICENSE file in the root directory of this source tree.
66
- */const Dn=le.createLucideIcon("ListFilter",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/**
67
- * @license lucide-react v0.453.0 - ISC
68
- *
69
- * This source code is licensed under the ISC license.
70
- * See the LICENSE file in the root directory of this source tree.
71
- */const Dr=le.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
72
- * @license lucide-react v0.453.0 - ISC
73
- *
74
- * This source code is licensed under the ISC license.
75
- * See the LICENSE file in the root directory of this source tree.
76
- */const kr=le.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
77
- * @license lucide-react v0.453.0 - ISC
78
- *
79
- * This source code is licensed under the ISC license.
80
- * See the LICENSE file in the root directory of this source tree.
81
- */const hs=le.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
82
- * @license lucide-react v0.453.0 - ISC
83
- *
84
- * This source code is licensed under the ISC license.
85
- * See the LICENSE file in the root directory of this source tree.
86
- */const ps=le.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
87
- * @license lucide-react v0.453.0 - ISC
88
- *
89
- * This source code is licensed under the ISC license.
90
- * See the LICENSE file in the root directory of this source tree.
91
- */const Mr=le.createLucideIcon("Paintbrush",[["path",{d:"m14.622 17.897-10.68-2.913",key:"vj2p1u"}],["path",{d:"M18.376 2.622a1 1 0 1 1 3.002 3.002L17.36 9.643a.5.5 0 0 0 0 .707l.944.944a2.41 2.41 0 0 1 0 3.408l-.944.944a.5.5 0 0 1-.707 0L8.354 7.348a.5.5 0 0 1 0-.707l.944-.944a2.41 2.41 0 0 1 3.408 0l.944.944a.5.5 0 0 0 .707 0z",key:"18tc5c"}],["path",{d:"M9 8c-1.804 2.71-3.97 3.46-6.583 3.948a.507.507 0 0 0-.302.819l7.32 8.883a1 1 0 0 0 1.185.204C12.735 20.405 16 16.792 16 15",key:"ytzfxy"}]]);/**
92
- * @license lucide-react v0.453.0 - ISC
93
- *
94
- * This source code is licensed under the ISC license.
95
- * See the LICENSE file in the root directory of this source tree.
96
- */const Ar=le.createLucideIcon("PanelRightClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]);/**
97
- * @license lucide-react v0.453.0 - ISC
98
- *
99
- * This source code is licensed under the ISC license.
100
- * See the LICENSE file in the root directory of this source tree.
101
- */const Lr=le.createLucideIcon("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
102
- * @license lucide-react v0.453.0 - ISC
103
- *
104
- * This source code is licensed under the ISC license.
105
- * See the LICENSE file in the root directory of this source tree.
106
- */const Es=le.createLucideIcon("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]);/**
107
- * @license lucide-react v0.453.0 - ISC
108
- *
109
- * This source code is licensed under the ISC license.
110
- * See the LICENSE file in the root directory of this source tree.
111
- */const Fr=le.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
112
- * @license lucide-react v0.453.0 - ISC
113
- *
114
- * This source code is licensed under the ISC license.
115
- * See the LICENSE file in the root directory of this source tree.
116
- */const Rr=le.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
117
- * @license lucide-react v0.453.0 - ISC
118
- *
119
- * This source code is licensed under the ISC license.
120
- * See the LICENSE file in the root directory of this source tree.
121
- */const Pr=le.createLucideIcon("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
122
- * @license lucide-react v0.453.0 - ISC
123
- *
124
- * This source code is licensed under the ISC license.
125
- * See the LICENSE file in the root directory of this source tree.
126
- */const Or=le.createLucideIcon("SquareFunction",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3",key:"m1af9g"}],["path",{d:"M9 11.2h5.7",key:"3zgcl2"}]]);/**
127
- * @license lucide-react v0.453.0 - ISC
128
- *
129
- * This source code is licensed under the ISC license.
130
- * See the LICENSE file in the root directory of this source tree.
131
- */const Vr=le.createLucideIcon("SquareSplitVertical",[["path",{d:"M5 8V5c0-1 1-2 2-2h10c1 0 2 1 2 2v3",key:"1pi83i"}],["path",{d:"M19 16v3c0 1-1 2-2 2H7c-1 0-2-1-2-2v-3",key:"ido5k7"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);/**
132
- * @license lucide-react v0.453.0 - ISC
133
- *
134
- * This source code is licensed under the ISC license.
135
- * See the LICENSE file in the root directory of this source tree.
136
- */const Br=le.createLucideIcon("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);/**
137
- * @license lucide-react v0.453.0 - ISC
138
- *
139
- * This source code is licensed under the ISC license.
140
- * See the LICENSE file in the root directory of this source tree.
141
- */const _r=le.createLucideIcon("TrendingUp",[["polyline",{points:"22 7 13.5 15.5 8.5 10.5 2 17",key:"126l90"}],["polyline",{points:"16 7 22 7 22 13",key:"kwv8wd"}]]);function Yr({open:s,onOpenChange:n}){const[r,o]=v.useState([]),{updateDataSource:c}=t.useEditorActions(),{selectedEntities:d}=a.useAssistantContextEntities("dashboard");v.useEffect(()=>{s&&o([])},[s]);const i=p=>{o(j=>j.some(f=>a.areContextEntitiesEqual(f,p))?j.filter(f=>!a.areContextEntitiesEqual(f,p)):[...j,p])},l=()=>{o([...d])},u=()=>{o([])},x=()=>{if(r.length===0)return;const p=r[0],j=p.connectionId||"",N=p.connectionType||"",g=r.some(D=>D.type==="dataset")?"semanticDomain":"database";c({connectionId:j,connectionType:N,mode:g,selectedEntities:r}),n(!1)},m=p=>"label"in p&&p.label?p.label:p.name,b=p=>{if("description"in p&&p.description)return p.description;const j=[];return p.database&&j.push(p.database),p.schema&&j.push(p.schema),p.name&&j.push(p.name),j.join(".")},h=p=>r.some(j=>a.areContextEntitiesEqual(j,p));return d.length===0?e.jsx(a.Dialog,{open:s,onOpenChange:n,children:e.jsxs(a.DialogContent,{className:"max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"No Data Available"}),e.jsx(a.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(a.DialogFooter,{children:e.jsx(t.Button,{onClick:()=>n(!1),children:"Close"})})]})}):e.jsx(a.Dialog,{open:s,onOpenChange:n,children:e.jsxs(a.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(a.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{variant:"outline",size:"sm",onClick:l,disabled:r.length===d.length,children:"Select All"}),e.jsx(t.Button,{variant:"outline",size:"sm",onClick:u,disabled:r.length===0,children:"Clear All"})]}),e.jsxs(a.Badge,{variant:"secondary",children:[r.length," of ",d.length," selected"]})]}),e.jsx(t.Separator,{}),e.jsx(t.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:d.map((p,j)=>e.jsxs("div",{className:t.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",h(p)&&"border-primary bg-primary/5"),children:[e.jsx(a.Checkbox,{checked:h(p),onCheckedChange:()=>i(p)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:a.getEntityIcon(p.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:m(p)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:b(p)})]}),e.jsx(a.Badge,{variant:"outline",className:"text-xs",children:p.type})]},`${p.type}-${p.name}-${j}`))})})]}),e.jsx(a.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(t.Button,{onClick:x,disabled:r.length===0,children:["Select"," ",r.length>0?`(${r.length})`:""]})]})})})]})})}function kn(){return{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}}function zr({initialJoinPlan:s,availableDataSources:n}){const[r,o]=v.useState(()=>Ze.normalizeJoinPlanEntityReferences(s,n)),[c,d]=v.useState(new Set),i=()=>{const M=r.joins.length>0?Math.max(...r.joins.map(F=>F.sequence))+1:1,A={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:M,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};o({...r,joins:[...r.joins,A]}),d(new Set([...c,A.id]))},l=M=>{o({...r,joins:r.joins.filter(A=>A.id!==M)}),d(new Set([...c].filter(A=>A!==M)))},u=(M,A)=>{var L,T,R,y,B;const F=r.joins.find(P=>P.id===M);if(!F)return;const I={...F,...A};if((L=I.source)!=null&&L.name&&((T=I.target)!=null&&T.name)&&I.source.name===I.target.name){t.ue.error("Self-joins are not yet supported",{description:`Joining ${I.source.name} to itself is not currently supported. Please select a different target table.`});return}const C=r.joins.filter(P=>{var O;return P.id!==M&&P.target.name===((O=I.target)==null?void 0:O.name)});if((R=I.target)!=null&&R.name&&C.length>0){t.ue.error("Duplicate join targets are not supported",{description:`The table ${I.target.name} is already used as a target in another join. Each table can only be joined once.`});return}const E=r.joins.map(P=>P.id===M?I:P);if((y=I.source)!=null&&y.name&&((B=I.target)!=null&&B.name)&&I.joinKeyGroups[0].keys.length===0){const P=n.find(z=>{var q;return z.name===((q=I.source)==null?void 0:q.name)}),O=n.find(z=>{var q;return z.name===((q=I.target)==null?void 0:q.name)}),V={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(P==null?void 0:P.name)||"",entityName:(P==null?void 0:P.name)||"",entityType:(P==null?void 0:P.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(O==null?void 0:O.name)||"",entityName:(O==null?void 0:O.name)||"",entityType:(O==null?void 0:O.type)||"table"},operator:"="},_=[...I.joinKeyGroups];_[0]={..._[0],keys:[V]},I.joinKeyGroups=_,E[E.findIndex(z=>z.id===M)]=I}o({...r,joins:E})};return{joinPlan:r,expandedJoins:c,setJoinPlan:o,addJoin:i,removeJoin:l,updateJoin:u,moveJoinUp:M=>{const A=r.joins.findIndex(F=>F.id===M);if(A>0){const F=[...r.joins],I={...F[A]},C={...F[A-1]};F[A]=C,F[A-1]=I,F.forEach((L,T)=>{L.sequence=T+1});const E={...r,joins:F};o(E)}},moveJoinDown:M=>{const A=r.joins.findIndex(F=>F.id===M);if(A<r.joins.length-1){const F=[...r.joins],I={...F[A]},C={...F[A+1]};F[A]=C,F[A+1]=I,F.forEach((L,T)=>{L.sequence=T+1});const E={...r,joins:F};o(E)}},toggleJoinExpansion:M=>{const A=new Set(c);A.has(M)?A.delete(M):A.add(M),d(A)},getAvailableSourceEntities:M=>{if(r.joins.length===0)return n;const A=r.joins.findIndex(I=>I.id===M);if(A===0)return n.filter(I=>I.name===r.baseEntity.name);const F=new Set;return r.baseEntity.name&&F.add(r.baseEntity.name),r.joins.slice(0,A).forEach(I=>{F.add(I.source.name),F.add(I.target.name)}),n.filter(I=>F.has(I.name))},getAvailableTargetEntities:M=>n.filter(A=>A.name!==M),addJoinKeyGroup:M=>{const A=r.joins.find(I=>I.id===M);if(!A)return;const F=[...A.joinKeyGroups,kn()];u(M,{joinKeyGroups:F})},updateGroupOperator:(M,A,F)=>{const I=r.joins.find(E=>E.id===M);if(!I)return;const C=[...I.joinKeyGroups];C[A]={...C[A],operator:F},u(M,{joinKeyGroups:C})},removeJoinKeyGroup:(M,A)=>{const F=r.joins.find(C=>C.id===M);if(!F)return;const I=[...F.joinKeyGroups];I.splice(A,1),u(M,{joinKeyGroups:I})},addJoinKey:(M,A)=>{const F=r.joins.find(T=>T.id===M);if(!F)return;const I=n.find(T=>T.name===F.source.name),C=n.find(T=>T.name===F.target.name),E=[...F.joinKeyGroups];E[A]||(E[A]=kn());const L={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(I==null?void 0:I.name)||"",entityName:(I==null?void 0:I.name)||"",entityType:(I==null?void 0:I.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(C==null?void 0:C.name)||"",entityName:(C==null?void 0:C.name)||"",entityType:(C==null?void 0:C.type)||"table"},operator:"="};E[A]={...E[A],keys:[...E[A].keys,L]},u(M,{joinKeyGroups:E})},updateJoinKey:(M,A,F,I,C)=>{const E=r.joins.find(B=>B.id===M);if(!E)return;const L=n.find(B=>B.name===E.source.name),T=n.find(B=>B.name===E.target.name),R=[...E.joinKeyGroups],y=R[A].keys[F];I==="sourceColumnName"&&L?R[A].keys[F]={...y,source:{...y.source,name:C}}:I==="targetColumnName"&&T?R[A].keys[F]={...y,target:{...y.target,name:C}}:I==="operator"&&(R[A].keys[F]={...y,operator:C}),u(M,{joinKeyGroups:R})},removeJoinKey:(M,A,F)=>{const I=r.joins.find(E=>E.id===M);if(!I)return;const C=[...I.joinKeyGroups];C[A].keys.splice(F,1),u(M,{joinKeyGroups:C})},generateSQLPreview:()=>{const M=[...r.joins].sort((I,C)=>I.sequence-C.sequence),A=r.baseEntity;if(!A.name)return"SELECT * FROM table -- Please select a base entity";let F=`SELECT *
142
- FROM ${A.name}`;return M.forEach(I=>{const C=n.find(T=>T.name===I.target.name);if(!C)return;const E=I.joinKeyGroups.filter(T=>T.keys&&T.keys.length>0).map(T=>{const R=T.keys.filter(y=>{var B,P,O,V;return((B=y.source)==null?void 0:B.name)&&((P=y.target)==null?void 0:P.name)&&((O=y.source)==null?void 0:O.entityName)&&((V=y.target)==null?void 0:V.entityName)}).map(y=>`${y.source.entityName}.${y.source.name} ${y.operator} ${y.target.entityName}.${y.target.name}`);return R.length>1?`(${R.join(` ${T.operator} `)})`:R[0]}).filter(Boolean),L=E.length>1?E.join(" OR "):E[0]||"condition_here";F+=`
143
- ${I.joinType} JOIN ${C.name}
144
- ON ${L}`}),F},isValidConfiguration:()=>!(!r.baseEntity.name||r.joins.some(I=>!I.source.name||!I.target.name)||r.joins.some(I=>I.joinKeyGroups.some(C=>C.keys.length===0))||r.joins.some(I=>I.joinKeyGroups.some(C=>C.keys.some(E=>!E.source.name||!E.target.name||!E.operator))))}}const qr=[{value:"LEFT",label:"Keep rows without a match"},{value:"INNER",label:"Only matching rows"},{value:"RIGHT",label:"Keep all target rows"},{value:"FULL",label:"Keep all rows"}],$r={one_to_one:"One to one",one_to_many:"One to many",many_to_one:"Many to one",many_to_many:"Many to many"},Kr={one_to_one:"1 : 1",one_to_many:"1 : N",many_to_one:"N : 1",many_to_many:"N : N"},Ur=["=","<",">","<=",">="];function Gr({joinPlan:s,availableDataSources:n,onSave:r,onRemove:o,onCancel:c}){const{columnGroups:d}=a.useColumns(),i=d.filter(O=>O.entityName!==je.CALCULATED_FIELDS_GROUP_NAME),{joinPlan:l,expandedJoins:u,setJoinPlan:x,addJoin:m,removeJoin:b,updateJoin:h,moveJoinUp:p,moveJoinDown:j,toggleJoinExpansion:N,getAvailableSourceEntities:f,getAvailableTargetEntities:g,addJoinKeyGroup:k,updateGroupOperator:D,removeJoinKeyGroup:w,addJoinKey:S,updateJoinKey:M,removeJoinKey:A,generateSQLPreview:F,isValidConfiguration:I}=zr({initialJoinPlan:s,availableDataSources:n}),[C,E]=v.useState(new Set),[L,T]=v.useState(!1),R=O=>{const V=i.find(_=>_.entityName===O);return(V==null?void 0:V.columns)||[]},y=O=>E(V=>{const _=new Set(V);return _.has(O)?_.delete(O):_.add(O),_}),B=[];l.baseEntity.name&&B.push(l.baseEntity.name);for(const O of[...l.joins].sort((V,_)=>V.sequence-_.sequence))O.target.name&&!B.includes(O.target.name)&&B.push(O.target.name);const P=O=>{const V=O.joinKeyGroups.flatMap(q=>q.keys),_=V.find(q=>{var Y,$;return((Y=q.source)==null?void 0:Y.name)&&(($=q.target)==null?void 0:$.name)});if(!_)return null;const z=V.length>1?` +${V.length-1}`:"";return`${_.source.name} ${_.operator||"="} ${_.target.name}${z}`};return e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Start from"}),e.jsxs(t.Select,{value:l.baseEntity.name,onValueChange:O=>{const V=n.find(_=>_.name===O);x({...l,baseEntity:{connectionId:(V==null?void 0:V.connectionId)||"",connectionType:(V==null?void 0:V.connectionType)||"none",type:(V==null?void 0:V.type)||"table",name:O,database:V==null?void 0:V.database,schema:V==null?void 0:V.schema}})},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select the dataset to start from..."})}),e.jsx(t.SelectContent,{children:n.map(O=>e.jsx(t.SelectItem,{value:O.name,className:"text-[12px]",children:O.name},O.name))})]}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Every other dataset connects back to this one."})]}),B.length>0&&e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Join path"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:B.map((O,V)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[V>0&&e.jsx(a.ArrowRight,{className:"h-3 w-3 text-muted-foreground"}),e.jsxs("span",{className:`inline-flex max-w-[220px] items-center gap-1.5 rounded-[4px] border px-2 py-1 leading-none ${V===0?"border-border bg-muted font-medium text-foreground":"border-border/60 text-muted-foreground"}`,children:[e.jsx(a.Database,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 truncate text-[11.5px] leading-none",children:O}),V===0&&e.jsx("span",{className:"shrink-0 text-[9.5px] uppercase leading-none tracking-[0.06em] text-muted-foreground",children:"BASE"})]})]},O))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["How datasets connect (",l.joins.length,")"]}),e.jsxs(t.Button,{variant:"outline",size:"xs",className:"gap-1.5",onClick:m,children:[e.jsx(a.Plus,{className:"h-3.5 w-3.5"}),"Add join"]})]}),l.joins.length===0?e.jsxs("div",{className:"rounded-[6px] border border-dashed border-border px-4 py-8 text-center",children:[e.jsx("p",{className:"text-[12.5px] font-medium text-foreground",children:"No joins yet"}),e.jsxs("p",{className:"mx-auto mt-1 max-w-[360px] text-[11.5px] leading-relaxed text-muted-foreground",children:["Add a join to connect another dataset to"," ",l.baseEntity.name||"your base dataset","."]})]}):e.jsx("div",{className:"max-h-[340px] space-y-1.5 overflow-y-auto",children:l.joins.map(O=>{var U;const V=n.find(H=>H.name===O.source.name),_=n.find(H=>H.name===O.target.name),z=u.has(O.id),q=C.has(O.id)||O.joinKeyGroups.length>1||O.joinKeyGroups.some(H=>H.operator!=="AND"),Y=P(O),$=O.relationshipCardinality;return e.jsxs("div",{className:`rounded-[6px] border ${z?"border-border":"border-border/60"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>N(O.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[z?e.jsx(le.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Ke.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12.5px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:O.source.name||"source"}),e.jsx(a.ArrowRight,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:O.target.name||"target"})]}),Y&&e.jsx("code",{className:"hidden max-w-[180px] shrink-0 truncate rounded-[4px] bg-muted px-1.5 py-0.5 font-mono text-[10.5px] text-muted-foreground lg:inline-block",children:Y})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>p(O.id),disabled:O.sequence===1,"aria-label":"Move join earlier",children:e.jsx(Hr,{})}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>j(O.id),disabled:O.sequence===l.joins.length,"aria-label":"Move join later",children:e.jsx(Qr,{})}),e.jsxs(t.Button,{variant:"ghost",size:"sm",className:"h-6 gap-1 px-1.5 text-[11px] font-medium text-muted-foreground",onClick:()=>N(O.id),children:[e.jsx(a.Pencil,{className:"h-3 w-3"}),z?"Editing":"Edit"]}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground",onClick:()=>b(O.id),"aria-label":"Remove join",children:e.jsx(le.X,{className:"h-3.5 w-3.5"})})]})]}),z&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 pb-4 pt-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"From"}),e.jsxs(t.Select,{value:O.source.name,onValueChange:H=>{const te=n.find(X=>X.name===H);h(O.id,{source:{connectionId:(te==null?void 0:te.connectionId)||"",connectionType:(te==null?void 0:te.connectionType)||"none",type:(te==null?void 0:te.type)||"table",name:H,database:te==null?void 0:te.database,schema:te==null?void 0:te.schema}})},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select source..."})}),e.jsx(t.SelectContent,{children:f(O.id).map(H=>e.jsx(t.SelectItem,{value:H.name,className:"text-[12px]",children:H.name},H.name))})]})]}),e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"To"}),e.jsxs(t.Select,{value:O.target.name,onValueChange:H=>{const te=n.find(X=>X.name===H);h(O.id,{target:{connectionId:(te==null?void 0:te.connectionId)||"",connectionType:(te==null?void 0:te.connectionType)||"none",type:(te==null?void 0:te.type)||"table",name:H,database:te==null?void 0:te.database,schema:te==null?void 0:te.schema}})},disabled:!O.source.name,children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select target..."})}),e.jsx(t.SelectContent,{children:O.source.name?g(O.source.name).map(H=>e.jsx(t.SelectItem,{value:H.name,className:"text-[12px]",children:H.name},H.name)):null})]})]}),e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"When a row has no match"}),e.jsxs(t.Select,{value:O.joinType,onValueChange:H=>h(O.id,{joinType:H}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:qr.map(H=>e.jsx(t.SelectItem,{value:H.value,className:"text-[12px]",children:e.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:H.label}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tracking-[0.04em] text-muted-foreground",children:H.value})]})},H.value))})]})]})]}),$&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-[5px] border border-border/60 bg-muted/40 px-2.5 py-1.5 text-[11.5px]",children:[e.jsx("span",{className:"shrink-0 rounded-[3px] bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground",children:Kr[$]}),e.jsx("span",{className:"text-muted-foreground",children:$r[$]}),e.jsxs("span",{className:"truncate text-muted-foreground/70",children:["(",O.source.name||"source"," →"," ",O.target.name||"target",")"]})]}),O.source.name&&O.target.name&&V&&_&&e.jsx("div",{className:"space-y-2",children:q?e.jsx(Jr,{join:O,getColumnsForEntity:R,addJoinKey:S,addJoinKeyGroup:k,updateGroupOperator:D,removeJoinKeyGroup:w,updateJoinKey:M,removeJoinKey:A,canCollapse:O.joinKeyGroups.length<=1&&O.joinKeyGroups.every(H=>H.operator==="AND"),onCollapse:()=>y(O.id)}):e.jsxs(e.Fragment,{children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Match on"}),(U=O.joinKeyGroups[0])!=null&&U.keys.length?e.jsx("div",{className:"min-w-0 space-y-1.5",children:O.joinKeyGroups[0].keys.map((H,te)=>e.jsx(oa,{join:O,groupIndex:0,keyIndex:te,conditionKey:H,getColumnsForEntity:R,updateJoinKey:M,removeJoinKey:A,showRemove:O.joinKeyGroups[0].keys.length>1},H.id||te))}):e.jsx("p",{className:"rounded-[5px] border border-border/60 px-3 py-2 text-[11.5px] text-muted-foreground",children:"No match condition yet. Add one to define how these connect."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>S(O.id,0),children:[e.jsx(a.Plus,{className:"h-3 w-3"})," Add condition"]}),e.jsxs("button",{type:"button",onClick:()=>y(O.id),className:"inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground hover:text-foreground",children:[e.jsx(a.Settings2,{className:"h-3 w-3"}),"Advanced"]})]})]})})]})]},O.id)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>T(O=>!O),className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground hover:text-foreground",children:[L?e.jsx(le.ChevronDown,{className:"h-3 w-3"}):e.jsx(Ke.ChevronRight,{className:"h-3 w-3"}),"View SQL"]}),L&&e.jsx("div",{className:"rounded-[5px] border border-border/60 bg-muted/40 p-3",children:e.jsx("code",{className:"block whitespace-pre-wrap break-all font-mono text-[11px] text-muted-foreground",children:F()})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-border pt-4",children:[e.jsxs(t.Button,{variant:"ghost",size:"xs",className:"gap-1.5 text-muted-foreground",onClick:()=>{o(),c()},children:[e.jsx(a.Trash2,{className:"h-3.5 w-3.5"}),"Remove all"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{variant:"outline",size:"xs",onClick:c,children:"Cancel"}),e.jsxs(t.Button,{size:"xs",className:"gap-1.5",onClick:()=>r(l),disabled:!I(),children:["Save joins",e.jsx(a.ArrowRight,{className:"h-3.5 w-3.5"})]})]})]})]})}function Hr(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m18 15-6-6-6 6"})})}function Qr(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}function oa({join:s,groupIndex:n,keyIndex:r,conditionKey:o,getColumnsForEntity:c,updateJoinKey:d,removeJoinKey:i,showRemove:l,showOperator:u=!1}){const x=u||(o.operator||"=")!=="=";return e.jsxs("div",{className:"flex items-center gap-2 rounded-[5px] border border-border/60 p-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs(t.Select,{value:o.source.name,onValueChange:m=>d(s.id,n,r,"sourceColumnName",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 font-mono text-[11px]",children:e.jsx(t.SelectValue,{placeholder:"Source column"})}),e.jsx(t.SelectContent,{children:c(s.source.name).map(m=>e.jsx(t.SelectItem,{value:m.name,children:e.jsxs("span",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx("span",{className:"font-mono",children:m.name}),m.dataType&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:m.dataType})]})},m.name))})]})}),x?e.jsx("div",{className:"w-16 shrink-0",children:e.jsxs(t.Select,{value:o.operator,onValueChange:m=>d(s.id,n,r,"operator",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 justify-center px-1 font-mono text-[11px]",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ur.map(m=>e.jsx(t.SelectItem,{value:m,children:m},m))})]})}):e.jsx("span",{className:"shrink-0 px-1 font-mono text-[12px] text-muted-foreground",children:"="}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs(t.Select,{value:o.target.name,onValueChange:m=>d(s.id,n,r,"targetColumnName",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 font-mono text-[11px]",children:e.jsx(t.SelectValue,{placeholder:"Target column"})}),e.jsx(t.SelectContent,{children:c(s.target.name).map(m=>e.jsx(t.SelectItem,{value:m.name,children:e.jsxs("span",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx("span",{className:"font-mono",children:m.name}),m.dataType&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:m.dataType})]})},m.name))})]})}),l&&e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>i(s.id,n,r),"aria-label":"Remove condition",children:e.jsx(le.X,{className:"h-3.5 w-3.5"})})]})}function Jr({join:s,getColumnsForEntity:n,addJoinKey:r,addJoinKeyGroup:o,updateGroupOperator:c,removeJoinKeyGroup:d,updateJoinKey:i,removeJoinKey:l,canCollapse:u,onCollapse:x}){return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(t.Label,{className:"flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(a.Settings2,{className:"h-3 w-3"}),"Advanced conditions"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("button",{type:"button",onClick:x,className:"text-[11px] font-medium text-muted-foreground hover:text-foreground",children:"Use simple"}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>o(s.id),children:[e.jsx(a.Plus,{className:"h-3 w-3"})," Add OR group"]})]})]}),s.joinKeyGroups.map((m,b)=>e.jsxs("div",{className:"space-y-2 rounded-[5px] border border-border/60 p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-[11px] font-medium text-foreground",children:["Group ",b+1]}),b>0&&e.jsx("span",{className:"rounded-[3px] bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:"OR with previous"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:"within group"}),e.jsxs(t.Select,{value:m.operator,onValueChange:h=>c(s.id,b,h),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-[76px] text-[11px]",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"AND",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground",onClick:()=>d(s.id,b),"aria-label":"Remove group",children:e.jsx(a.Trash2,{className:"h-3.5 w-3.5"})})]})]}),m.keys.length===0?e.jsx("p",{className:"rounded-[5px] border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}):e.jsx("div",{className:"min-w-0 space-y-1.5",children:m.keys.map((h,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[p>0&&e.jsx("span",{className:"w-9 shrink-0 text-center text-[10px] font-medium text-muted-foreground",children:m.operator}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(oa,{join:s,groupIndex:b,keyIndex:p,conditionKey:h,getColumnsForEntity:n,updateJoinKey:i,removeJoinKey:l,showRemove:!0,showOperator:!0})})]},h.id||p))}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>r(s.id,b),children:[e.jsx(a.Plus,{className:"h-3 w-3"})," Add condition"]})]},m.id))]})}function la({children:s,open:n,onOpenChange:r,joinPlan:o,availableDataSources:c,onRemove:d,onSave:i,onCancel:l}){return e.jsxs(a.Dialog,{open:n,onOpenChange:r,children:[e.jsxs(a.DialogContent,{className:"max-h-[88vh] w-[calc(100vw-2rem)] max-w-4xl overflow-y-auto overflow-x-hidden",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"How datasets connect"}),e.jsx(a.DialogDescription,{className:"text-[12px] text-muted-foreground",children:"Datasets joined together so a card can use fields from all of them."})]}),e.jsx(Gr,{joinPlan:o,availableDataSources:c,onSave:i,onCancel:l,onRemove:d})]}),s]})}function Wr({joins:s,baseEntityId:n,availableDataSources:r,generateSQLPreview:o}){return e.jsxs("div",{className:"my-2 max-h-[400px] divide-y divide-border overflow-y-auto",children:[s.length>0&&e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const c=[...s].sort((i,l)=>i.sequence-l.sequence),d=r.find(i=>i.name===n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(a.Badge,{variant:"secondary",className:"text-xs",children:d==null?void 0:d.type}),e.jsx("span",{className:"text-xs font-medium",children:d==null?void 0:d.name}),e.jsx(a.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),c.map(i=>{const l=r.find(u=>u.name===i.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(a.Badge,{variant:"outline",className:"text-xs",children:i.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(a.Badge,{variant:"secondary",className:"text-xs",children:l==null?void 0:l.type}),e.jsx("span",{className:"text-xs font-medium",children:l==null?void 0:l.name})]})]},i.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",s.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...s].sort((c,d)=>c.sequence-d.sequence).map((c,d)=>{const i=r.find(x=>x.name===c.source.name),l=r.find(x=>x.name===c.target.name),u=c.joinKeyGroups.reduce((x,m)=>x+m.keys.length,0);return e.jsxs("div",{className:"rounded-md bg-muted p-2 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:d+1}),e.jsx(a.Badge,{variant:"outline",className:"shrink-0 text-xs",children:c.joinType}),e.jsxs(a.Badge,{variant:"outline",className:"ml-auto shrink-0 text-xs",children:[u," condition",u>1?"s":""]})]}),e.jsxs("div",{className:"mt-1 truncate pl-1 text-xs text-muted-foreground",children:[i==null?void 0:i.name," → ",l==null?void 0:l.name]})]},c.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:o()})})]})]})}function Xr({open:s,onOpenChange:n,variant:r="button"}={}){var k;const o=t.useEditorStore(D=>D.card),{autoJoinMetadata:c}=a.useEditorCardQuery(o),d=t.useEditorStore(D=>D.actions.updateCardConfig),i=je.getAuthoredCardJoinPlan(o)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[l,u]=v.useState(!1),x=s!==void 0,m=x?s:l,b=x?n:u,h=((k=o==null?void 0:o.dataSource)==null?void 0:k.selectedEntities)||[],p=D=>{d(o.id,je.withAuthoredCardJoinPlan(o,D)),b(!1)},j=()=>{d(o.id,je.withAuthoredCardJoinPlan(o,void 0))},N=()=>{b(!1)},f=()=>{const D=[...i.joins].sort((M,A)=>M.sequence-A.sequence),w=i.baseEntity;if(!w.name)return"SELECT * FROM table -- Please select a base entity";let S=`SELECT *
145
- FROM ${w.name}`;return D.forEach(M=>{const A=h.find(C=>C.name===M.target.name);if(!A)return;const F=M.joinKeyGroups.filter(C=>C.keys&&C.keys.length>0).map(C=>{const E=C.keys.filter(L=>{var T,R,y,B;return((T=L.source)==null?void 0:T.name)&&((R=L.target)==null?void 0:R.name)&&((y=L.source)==null?void 0:y.entityName)&&((B=L.target)==null?void 0:B.entityName)}).map(L=>`${L.source.entityName}.${L.source.name} ${L.operator} ${L.target.entityName}.${L.target.name}`);return E.length>1?`(${E.join(` ${C.operator} `)})`:E[0]}).filter(Boolean),I=F.length>1?F.join(" OR "):F[0]||"condition_here";S+=`
146
- ${M.joinType} JOIN ${A.name}
147
- ON ${I}`}),S};if(h.length<2)return null;const g=i.joins.length>0&&e.jsx(t.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(Wr,{joins:i.joins,baseEntityId:i.baseEntity.name,availableDataSources:h,generateSQLPreview:f})});return e.jsxs(e.Fragment,{children:[e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:r==="badge"?e.jsxs(a.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:D=>{D.stopPropagation(),b(!0)},children:[e.jsx(a.Link,{className:"h-3 w-3"}),i.joins.length]}):e.jsxs("button",{type:"button",onClick:()=>b(!0),className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(a.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:i.joins.length===0?"Configure joins":`${i.joins.length} ${i.joins.length===1?"join":"joins"}`}),(c==null?void 0:c.autoResolved)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(a.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})}),g]})}),e.jsx(la,{open:m,onOpenChange:b,joinPlan:i,availableDataSources:h,onSave:p,onCancel:N,onRemove:j,children:e.jsx("div",{})})]})}function Zr(){var B,P,O,V;const[s,n]=v.useState(!1),[r,o]=v.useState(!1),[c,d]=v.useState(!1),i=t.useEditorStore(_=>_.card.dataSource),l=t.useEditorStore(_=>_.card),u=t.useEditorStore(_=>_.isDevMode),{updateCardConfig:x,updateDataSource:m}=t.useEditorActions(),{autoJoinMetadata:b}=a.useEditorCardQuery(l),{semanticDomains:h}=a.useSemanticDomains(),p=v.useMemo(()=>new Map(h.map(_=>[_.id,_.label||_.name])),[h]),N={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...i,selectedEntities:(i==null?void 0:i.selectedEntities)||[]},f=a.toEntityArray(N.selectedEntities),g=f.length,k=a.useFieldAvailabilityContext(l),D=v.useMemo(()=>t.getAuthoredCardFieldList(l),[l]),w=v.useMemo(()=>a.describeDataSourceConnections({...k,selectedFields:D,dataSourceEntities:f}),[k,D,f]),S=g===0?"Choose dataset":g===1?eo(f[0],p):`${g} datasets`,M=je.getAuthoredCardJoinPlan(l),A=((B=M==null?void 0:M.joins)==null?void 0:B.length)??0,F=Ze.findOrphanedJoinPlanEntities(M,f),I=F.length>0,C=!u&&(g>1||A>0),E=!!(b!=null&&b.autoResolved);((O=(P=b==null?void 0:b.resolvedJoinPlan)==null?void 0:P.joins)==null?void 0:O.length)??((V=b==null?void 0:b.relationshipsUsed)==null||V.length);const L=A>0?`${A} join${A===1?"":"s"}`:g<2?null:E?"auto":null,T=_=>{const z=f.filter(q=>!a.areContextEntitiesEqual(q,_));l&&Ze.findOrphanedJoinPlanEntities(M,z).length>0&&x(l.id,je.withAuthoredCardJoinPlan(l,void 0)),m({...N,...N.mode==="semanticDomain"?{semanticDomainId:a.inferSemanticDomainIdFromSelectedEntities(z)}:{},selectedEntities:z})},R=()=>{l&&x(l.id,je.withAuthoredCardJoinPlan(l,void 0))},y=()=>{m({...N,selectedEntities:a.dedupeContextEntities([...f,...F])})};return e.jsxs(e.Fragment,{children:[e.jsxs(t.Popover,{open:s,onOpenChange:n,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(a.Database,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:S}),L&&e.jsxs("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:["· ",L]}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"rotate-180")})]})}),e.jsx(t.PopoverContent,{align:"start",sideOffset:4,className:"w-[320px] overflow-hidden rounded-control border border-border bg-popover p-0 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 pb-1.5 pt-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Datasets"}),e.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:g})]}),g===0?e.jsx("div",{className:"px-3 pb-2 text-[12px] text-muted-foreground",children:"No datasets selected."}):e.jsx("ul",{className:"mb-1",children:f.map((_,z)=>{const q=w[z],$=(q?a.isBlockedFieldState(q.state):!1)?a.getFieldStateCopy(q==null?void 0:q.state).tag:null;return e.jsxs("li",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-muted/50",children:[e.jsx(a.Database,{className:"mt-[3px] h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] text-foreground",children:Ms(_)}),e.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:so(_,p)}),$&&q&&e.jsx("p",{title:[q.reason,q.action].filter(Boolean).join(" "),className:"text-[10px] font-medium leading-[1.4] text-destructive",children:$})]}),e.jsx("button",{type:"button",onClick:()=>T(_),"aria-label":`Remove ${to(_,p)}`,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(le.X,{className:"h-3 w-3"})})]},`${_.connectionId}-${_.name}-${z}`)})}),e.jsxs("button",{type:"button",onClick:()=>{n(!1),o(!0)},className:"flex w-full items-center gap-1.5 px-3 py-1.5 text-left text-[12px] text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx(a.Plus,{className:"h-3 w-3"}),"Add dataset"]})]}),C&&e.jsxs("div",{className:"border-t border-border/60 px-3 py-2.5",children:[e.jsx("div",{className:"mb-1.5 flex items-center justify-between",children:e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Join"})}),I?e.jsxs("div",{className:"space-y-2 rounded-control border border-amber-300/70 bg-amber-50/70 p-2.5 text-[11px] text-amber-950 dark:border-amber-700/70 dark:bg-amber-950/20 dark:text-amber-100",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.TriangleAlert,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium",children:[A," saved"," ",A===1?"join":"joins"," need attention"]}),e.jsxs("p",{className:"mt-0.5 leading-relaxed text-amber-900/80 dark:text-amber-100/80",children:[F.map(_=>_.name).join(", ")," ","is no longer selected, but the saved join still affects this card."]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:R,className:"rounded-control border border-amber-500/60 bg-background px-2 py-1 text-[11px] font-medium text-foreground transition-colors hover:bg-amber-100 dark:bg-background dark:hover:bg-amber-950/60",children:"Remove saved join"}),e.jsx("button",{type:"button",onClick:y,className:"rounded-control px-1 py-1 text-[11px] font-medium text-amber-900 transition-colors hover:underline dark:text-amber-100",children:"Re-add dataset"})]})]}):e.jsxs("button",{type:"button",onClick:()=>{n(!1),d(!0)},className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(a.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:A>0?`${A} ${A===1?"join":"joins"}`:"Configure joins"}),E&&A===0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(a.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})]}),e.jsx("div",{className:"flex items-center justify-end border-t border-border/60 px-2 py-1.5",children:e.jsx("button",{type:"button",onClick:()=>n(!1),className:"inline-flex h-6 items-center rounded-control px-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:"Done"})})]})})]}),e.jsx(a.AddDataPicker,{incomingSelectedEntities:(i==null?void 0:i.selectedEntities)||[],dialogMode:"dataSource",open:r,onOpenChange:o,dataSource:N}),C&&!I&&e.jsx("div",{className:"hidden",children:e.jsx(Xr,{open:c,onOpenChange:d})})]})}function Ms(s){return"label"in s&&s.label?s.label:s.name||"Dataset"}function eo(s,n){const r=Ms(s),o=a.getSemanticDomainLabel(s,n);return o?`${r} · ${o}`:r}function to(s,n){const r=Ms(s),o=a.getSemanticDomainLabel(s,n);return o?`${r} from ${o}`:r}function so(s,n){const r=a.getSemanticDomainLabel(s,n);if(r)return r;const o=[];return s.connectionType&&o.push(String(s.connectionType)),s.database&&o.push(s.database),s.schema&&o.push(s.schema),o.join(" · ")}function ia({isVisible:s}){pt.useSyncLegacyEditorState();const[n,r]=v.useState(!1);return e.jsxs("div",{className:t.cn("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",{"w-[290px]":s,"min-w-[290px]":s,"w-0 border-r-0":!s,"min-w-0":!s}),children:[e.jsx("div",{className:"px-4 pt-4",children:e.jsx(Zr,{})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(a.FieldsSection,{})}),e.jsx(Yr,{open:n,onOpenChange:r})]})}function no(s){const{request:n,mode:r="draft",currentSql:o,selectedTableName:c,selectedSchemaName:d,selectedDatabaseName:i}=s,l=[i?`Database: ${i}`:"",d?`Schema: ${d}`:"",c?`Table: ${c}`:""].filter(Boolean);return["You are an expert SQL writing assistant embedded in a query editor.",`Write SQL only. You may call only read-only tools when needed: ${a.INLINE_ALLOWED_TOOL_LIST}.`,"Do not call mutation tools or chart-creation tools; those require Full Assistant.","Return exactly one SQL statement inside a single ```sql fenced block.","After the code block, optionally include one short sentence.",r==="refine"&&o?"Mode: Refine existing SQL. Keep the current query structure and only apply the requested changes unless the current query is invalid.":"Mode: Draft new SQL from the request.",l.length>0?`Context:
148
- ${l.join(`
149
- `)}`:"",o?r==="refine"?`Current SQL (must refine):
150
- ${o}`:`Current SQL (revise if useful):
151
- ${o}`:"",`User request:
152
- ${n}`].filter(Boolean).join(`
153
-
154
- `)}function ao(s){const{request:n,failedSql:r,errorMessage:o,errorCode:c,selectedDatabaseName:d,selectedSchemaName:i,selectedTableName:l,contextEntityLabels:u}=s,x=[d?`Database: ${d}`:"",i?`Schema: ${i}`:"",l?`Table: ${l}`:"",u.length>0?`Selected context entities: ${u.join(", ")}`:""].filter(Boolean);return["You are fixing SQL after validation failed.","Return one read-only SQL statement in a single ```sql fenced block.","Do not call mutation tools.",x.length>0?`Context:
155
- ${x.join(`
156
- `)}`:"",`Original user request:
157
- ${n}`,`Previous SQL draft:
158
- ${r}`,`Validation failure${c?` (${c})`:""}:
159
- ${o}`].filter(Boolean).join(`
160
-
161
- `)}function ro(s,n){typeof window>"u"||window.dispatchEvent(new CustomEvent("semaphor:inline-query-writer",{detail:{event:s,...n,timestamp:Date.now()}}))}const fs={runId:0,phase:"idle",attempt:0,activeStep:"",timelineSteps:[],lastValidation:null,finalOutcome:"idle",hasTools:!1};function oo(s){if(typeof s=="string"&&(s==="SQL_EMPTY"||s==="SQL_PARSE_ERROR"||s==="SQL_MULTI_STATEMENT"||s==="SQL_READ_ONLY_VIOLATION"||s==="SQL_EXPLAIN_ERROR"||s==="SQL_CONNECTION_ERROR"))return s}function Mn(s){let n=0;for(let r=0;r<s.length;r+=1)n=(n<<5)-n+s.charCodeAt(r),n|=0;return String(n)}function An(s){return s==="getTableColumns"?"Discovering columns":s==="getDomainRelationships"?"Resolving relationships":s==="getChartSQLSyntax"?"Reviewing SQL syntax":s==="getUserSql"?"Inspecting current query":"Analyzing context"}function lo(s,n){return s===a.SELF_HEAL_TIMELINE_STEP&&n>0?`${a.SELF_HEAL_TIMELINE_STEP} ${n}/${a.MAX_SELF_HEAL_ATTEMPTS}`:s}function as(s){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${s}-${crypto.randomUUID()}`:`${s}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Ln(s){var n;for(let r=s.length-1;r>=0;r-=1){const o=s[r];if(o.role!=="user")continue;const c=(n=o.metadata)==null?void 0:n.inlineRunToken;if(typeof c=="string"&&c.length>0)return c}}function io(s){if(!s)return"";const n=s.trim(),r=s.match(/```sql\s*([\s\S]*?)```/i);if(r!=null&&r[1])return r[1].trim();const o=s.match(/```[\w-]*\s*([\s\S]*?)```/i);return o!=null&&o[1]?o[1].trim():/^(select|with|insert|update|delete)\b/i.test(n)?n:""}function Fn(s){for(let n=s.length-1;n>=0;n-=1){const r=s[n];if(!(r.role!=="assistant"||!Array.isArray(r.parts)))for(let o=r.parts.length-1;o>=0;o-=1){const c=r.parts[o];if((c==null?void 0:c.type)!=="text"||typeof(c==null?void 0:c.text)!="string")continue;const d=io(c.text);if(d)return d}}return""}function co({currentSql:s,currentPython:n,selectedDatabaseName:r,selectedSchemaName:o,selectedTableName:c,onApplySql:d,onOpenFullAssistant:i}){var es,ts;const{authToken:l,tokenProps:u}=a.useSemaphorContext(),x=(es=a.useDashboardQuery().data)==null?void 0:es.assistantProfileId,m=t.useEditorStore(Q=>Q.isDevMode),b=t.useEditorStore(Q=>Q.selectedConnectionId),h=t.useEditorStore(Q=>{var ee;return(ee=Q.card.dataSource)==null?void 0:ee.selectedEntities}),p=t.useAIInteractionStore(Q=>Q.currentAIContext.selectedEntities),j=p.length,{setCurrentAIContext:N}=t.useAIActions(),[f,g]=v.useState(""),[k,D]=v.useState(""),[w,S]=v.useState(""),[M,A]=v.useState("draft"),[F,I]=v.useState("draft"),[C,E]=v.useState(""),[L,T]=v.useState(!1),[R,y]=v.useState({status:"idle"}),[B,P]=v.useState(fs),[O,V]=v.useState(!1),[_,z]=v.useState(()=>as("inline-query-session")),q=v.useRef(null),Y=v.useRef(null),$=v.useRef(null),U=v.useRef(0),H=v.useRef(0),te=v.useRef(as("inline-run-token")),X=v.useRef(_),se=v.useRef(new Set),ue=v.useRef(new Map),fe=v.useRef(0),be=v.useRef(""),ge=v.useRef(!1),Pe=v.useRef(!1),Oe=v.useRef(fs),Ae=v.useRef(!1),Ie=v.useRef(null),_e=v.useRef(()=>{}),Ye=(ts=u.apiServiceUrl)==null?void 0:ts.replace(/\/$/,""),Ve=Ye?`${Ye}/v1/sql/validate`:"/v1/sql/validate",Le=v.useCallback(Q=>{P(ee=>{const J=Q(ee);return Oe.current=J,J})},[]),De=v.useCallback((Q,ee)=>{Le(J=>J.runId===Q?ee(J):J)},[Le]),ae=v.useCallback(Q=>H.current===Q&&!se.current.has(Q),[]),K=v.useCallback((Q,ee,J)=>{De(Q,Te=>{const Ee=Te.timelineSteps.includes(ee)?Te.timelineSteps:[...Te.timelineSteps,ee];return{...Te,phase:(J==null?void 0:J.phase)||Te.phase,attempt:typeof(J==null?void 0:J.attempt)=="number"?J.attempt:Te.attempt,activeStep:ee,timelineSteps:Ee,finalOutcome:(J==null?void 0:J.finalOutcome)||Te.finalOutcome,hasTools:J!=null&&J.hasTools?!0:Te.hasTools}})},[De]),ie=v.useCallback(()=>{const Q=H.current+1,ee=as("inline-run-token"),J=as("inline-query-session");return H.current=Q,te.current=ee,X.current=J,z(J),se.current=new Set,ue.current=new Map,fe.current=0,be.current="",Ae.current=!1,Le(()=>({runId:Q,phase:"drafting",attempt:0,activeStep:"Drafting SQL",timelineSteps:["Drafting SQL"],lastValidation:null,finalOutcome:"drafting",hasTools:!1})),{runId:Q,runToken:ee,chatSessionId:J}},[Le]),Se=v.useCallback(()=>{if(ge.current||Pe.current||j>0)return;const Q=h||[];if(Q.length===0)return;const ee=t.useAIInteractionStore.getState().currentAIContext;N({...ee,selectedEntities:Q}),Pe.current=!0},[j,h,N]),re=v.useCallback(()=>{ge.current=!0},[]),he=v.useCallback((Q,ee,J)=>{ro(Q,{runId:ee,attemptCount:typeof(J==null?void 0:J.attemptCount)=="number"?J.attemptCount:fe.current,errorCode:J==null?void 0:J.errorCode,hasTools:typeof(J==null?void 0:J.hasTools)=="boolean"?J.hasTools:B.hasTools,entityCount:j,finalOutcome:(J==null?void 0:J.finalOutcome)||B.finalOutcome})},[j,B.finalOutcome,B.hasTools]),ze=v.useCallback((Q,ee)=>{const J=$.current;if(!J)return;const Te={inlineRunToken:ee};J({role:"user",parts:[{type:"text",text:Q}],metadata:Te},{metadata:Te})},[]);v.useEffect(()=>{const Q=Ie.current;!Q||Q.sessionId!==_||(Ie.current=null,ze(Q.message,Q.runToken))},[_,ze]);const Z=_,Re=v.useCallback(async({toolCall:Q})=>{var ye,$e,ut,We,Be,mt;if(Z!==X.current)return;const ee=String(Q.toolName||"").trim();if(!ee)return;const J=H.current;if(!ae(J)){(ye=Y.current)==null||ye.call(Y,{tool:ee,toolCallId:Q.toolCallId,output:{status:"error",message:"Inline run is no longer active; ignoring tool output."}});return}if(ee==="getUserSql"){K(J,An(ee),{hasTools:!0}),he("inline_tool_step",J,{hasTools:!0}),($e=Y.current)==null||$e.call(Y,{tool:ee,toolCallId:Q.toolCallId,output:{status:"success",sql:s||"",python:n||""}});return}const Te=a.INLINE_BLOCKED_MUTATING_TOOLS.has(ee),Ee=a.INLINE_ALLOWED_READ_ONLY_TOOLS.has(ee);if(Te||!Ee){(ut=Y.current)==null||ut.call(Y,{tool:ee,toolCallId:Q.toolCallId,output:{status:"error",message:"This action is unavailable in inline draft mode. Open Full Assistant for this action."}});return}const ke=An(ee);K(J,ke,{phase:B.phase==="self-healing"?"self-healing":"drafting",hasTools:!0}),he("inline_tool_step",J,{hasTools:!0});const Ge=((We=Q.input)==null?void 0:We.sql)??((Be=Q.args)==null?void 0:Be.sql);typeof Ge=="string"&&Ge.trim().length>0&&(Ae.current=!1,S(Ge.trim())),(mt=Y.current)==null||mt.call(Y,{tool:ee,toolCallId:Q.toolCallId,output:{status:"success",message:"Read-only tool result received."}})},[n,s,he,B.phase,ae,Z,K]),me=v.useCallback(({message:Q,messages:ee})=>{if(Z!==X.current)return;const J=Ln(ee);if(!J||J!==te.current)return;const Te=H.current;if(!ae(Te))return;const Ee=Fn([Q])||Fn(ee);if(Ee){Ae.current=!1,S(Ee.trim());return}Ae.current&&Oe.current.phase==="self-healing"&&_e.current(Te)},[ae,Z]),qe=v.useCallback(Q=>{if(Z!==X.current)return;const ee=H.current;ae(ee)&&Ae.current&&Oe.current.phase==="self-healing"&&_e.current(ee)},[ae,Z]),{setMessages:Fe,sendMessage:Ue,addToolResult:we,status:oe,stop:ne,error:de,clearError:ve}=a.useChat({id:_,transport:new a.DefaultChatTransport({api:`${u.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${l==null?void 0:l.accessToken}`}),body:()=>{const Q=t.useAIInteractionStore.getState();return{assistantId:"editor-assistant",assistantProfileId:x,isDevMode:m,aiContext:Q.currentAIContext,reasoningEffort:Q.reasoningEffort,showReasoning:!1}},credentials:"omit",prepareSendMessagesRequest:({messages:Q,body:ee,requestMetadata:J})=>{const Te=J==null?void 0:J.inlineRunToken,Ee=Ln(Q);return{body:{...ee,inlineRunToken:Te||Ee,messages:t.cleanupIncompleteMessages(Q)}}}}),onToolCall:Re,onFinish:me,onError:qe,sendAutomaticallyWhen:a.lastAssistantMessageIsCompleteWithToolCalls});Y.current=we,$.current=Ue;const pe=!["ready","error"].includes(oe),Qe=(de==null?void 0:de.message)||"Unable to generate a SQL draft right now. Try again.",Me=v.useCallback(Q=>{const ee=H.current,J=Oe.current.phase;if(!(J==="drafting"||J==="self-healing"||J==="validating")){Q==="stopped"&&pe&&ne();return}se.current.add(ee),Ae.current=!1,U.current+=1,be.current="",y({status:"idle"}),S(""),ve(),Fe([]),De(ee,Ee=>({...Ee,phase:"idle",activeStep:"",finalOutcome:"cancelled"})),he("inline_self_heal_stopped",ee,{finalOutcome:"cancelled"}),(pe||Q==="stopped")&&ne()},[ve,he,pe,Fe,ne,De]),ft=v.useCallback(async(Q,ee)=>{var Te;if(!ae(ee))return null;const J=U.current+1;U.current=J,K(ee,"Validating SQL",{phase:"validating"}),y({status:"validating"});try{const Ee=await t.postRequestRegular(Ve,(l==null?void 0:l.accessToken)||"",{sql:Q,connectionId:b||void 0});if(U.current!==J||!ae(ee))return null;if((Ee==null?void 0:Ee.valid)===!0)return y({status:"valid",message:"SQL validation passed."}),De(ee,ye=>({...ye,phase:"ready",finalOutcome:"validated",lastValidation:{valid:!0}})),he("inline_draft_validated",ee,{finalOutcome:"validated"}),{status:"valid"};const ke=oo(Ee==null?void 0:Ee.errorCode)||"UNKNOWN",Ge=typeof(Ee==null?void 0:Ee.error)=="string"&&Ee.error||typeof((Te=Ee==null?void 0:Ee.details)==null?void 0:Te.error)=="string"&&Ee.details.error||"SQL validation failed. Please revise the query draft.";return y({status:"invalid",message:Ge,errorCode:ke}),De(ee,ye=>({...ye,lastValidation:{valid:!1,error:Ge,errorCode:ke}})),he("inline_validation_failed",ee,{errorCode:ke,finalOutcome:"validation_failed"}),{status:"invalid",error:Ge,errorCode:ke}}catch(Ee){if(U.current!==J||!ae(ee))return null;const ke=t.getRequestErrorMessage(Ee,"Validation service unavailable. You can still replace and run.");return y({status:"error",message:ke,errorCode:"SQL_CONNECTION_ERROR"}),De(ee,Ge=>({...Ge,phase:"error",finalOutcome:"error",lastValidation:{valid:!1,error:ke,errorCode:"SQL_CONNECTION_ERROR"}})),{status:"error",error:ke,errorCode:"SQL_CONNECTION_ERROR"}}},[l==null?void 0:l.accessToken,he,ae,b,Ve,De,K]),it=v.useCallback((Q,ee,J,Te)=>{let Ee=J,ke="validation_failed",Ge="Validating SQL";ee==="attempt_limit"?(Ee=`Couldn't auto-fix after ${a.MAX_SELF_HEAL_ATTEMPTS} attempts. ${J}`,ke="self_heal_exhausted",Ge=`Auto-fix stopped (${a.MAX_SELF_HEAL_ATTEMPTS} attempts)`):ee==="duplicate"&&(Ee=`Auto-fix stopped (repeated validation failure). ${J}`,ke="self_heal_duplicate_stopped",Ge="Auto-fix stopped (repeated failure)"),y({status:"invalid",message:Ee,errorCode:Te}),K(Q,Ge,{phase:"error",finalOutcome:ke}),De(Q,ye=>({...ye,phase:"error",finalOutcome:ke,lastValidation:{valid:!1,error:Ee,errorCode:Te}})),ee!=="terminal"&&he("inline_self_heal_stopped",Q,{errorCode:Te,finalOutcome:ke}),Ae.current=!1},[he,De,K]),Ut=v.useCallback(Q=>{const ee="Auto-fix stopped (no SQL returned). Open Full Assistant to continue.",J="self_heal_no_draft";y({status:"invalid",message:ee,errorCode:"UNKNOWN"}),K(Q,"Auto-fix stopped (no SQL returned)",{phase:"error",finalOutcome:J}),De(Q,Te=>({...Te,phase:"error",finalOutcome:J,lastValidation:{valid:!1,error:ee,errorCode:"UNKNOWN"}})),he("inline_self_heal_stopped",Q,{errorCode:"UNKNOWN",finalOutcome:J}),Ae.current=!1},[he,De,K]);_e.current=Ut,v.useEffect(()=>{const Q=w.trim(),ee=H.current;if(!Q){if(U.current+=1,be.current="",Oe.current.phase==="error")return;y({status:"idle"});return}if(!ae(ee)||pe)return;const J=`${ee}:${fe.current}:${Mn(Q)}`;if(be.current===J)return;be.current=J;let Te=!1;return(async()=>{const ke=await ft(Q,ee);if(!ke||Te||!ae(ee)||ke.status!=="invalid")return;if(!a.RECOVERABLE_SQL_ERROR_CODES.has(ke.errorCode)){it(ee,"terminal",ke.error,ke.errorCode);return}const Ge=`${Mn(Q)}::${ke.errorCode}`,ye=(ue.current.get(Ge)||0)+1;if(ue.current.set(Ge,ye),ye>=2){it(ee,"duplicate",ke.error,ke.errorCode);return}if(fe.current>=a.MAX_SELF_HEAL_ATTEMPTS){it(ee,"attempt_limit",ke.error,ke.errorCode);return}const $e=fe.current+1;fe.current=$e,K(ee,a.SELF_HEAL_TIMELINE_STEP,{phase:"self-healing",attempt:$e}),he("inline_self_heal_attempt",ee,{attemptCount:$e,errorCode:ke.errorCode}),Ae.current=!0,ve(),Fe([]),S("");const ut=p.map(Be=>{const mt=Be!=null&&Be.database?`${Be.database}.`:"",vt=Be!=null&&Be.schema?`${Be.schema}.`:"",ss=(Be==null?void 0:Be.name)||"unknown";return`${mt}${vt}${ss}`}),We=ao({request:k,failedSql:Q,errorMessage:ke.error,errorCode:ke.errorCode,selectedDatabaseName:r||"",selectedSchemaName:o||"",selectedTableName:c||"",contextEntityLabels:ut});ze(We,te.current)})(),()=>{Te=!0}},[ve,p,he,pe,ae,k,w,r,o,c,ze,Fe,it,K,ft]);const rt=(s==null?void 0:s.trim())||"",Tt=v.useCallback((Q="draft")=>{if(pe)return;const ee=f.trim();if(!ee)return;const J=Q==="refine"&&rt?"refine":"draft",Te=J==="refine"?rt:"",Ee=rt,{runId:ke,runToken:Ge,chatSessionId:ye}=ie();he("inline_draft_started",ke,{attemptCount:0,hasTools:!1,finalOutcome:"drafting"}),Se(),ve(),D(ee),S(""),A(J),E(Te),T(!1),y({status:"idle"}),U.current+=1,Fe([]),V(!0);const $e=no({request:ee,mode:J,currentSql:Ee,selectedTableName:c||"",selectedSchemaName:o||"",selectedDatabaseName:r||""});Ie.current={sessionId:ye,message:$e,runToken:Ge}},[ie,ve,rt,he,pe,f,Se,r,o,c,Fe]),tt=v.useCallback(Q=>{const ee=w.trim();ee&&(d(ee,Q),Q||V(!1))},[d,w]),gt=w.trim().length>0,Gt=["valid","invalid","error"].includes(R.status),ot=gt&&Gt,Ht=R.status==="invalid",ct=R.status==="validating",bt=gt&&k.length>0&&k===f.trim(),Rt=rt.length>0,Et=f.trim().length>0,Pt=bt&&M==="draft",jt=bt&&M==="refine"&&C===rt,dt=F==="refine"&&!Rt?"draft":F,It=(dt==="refine"?jt:Pt)?"Open composer preview":"Generate composer SQL",Jt=f.trim().length>0||k.trim().length>0||gt||R.status!=="idle"||B.timelineSteps.length>0,lt=v.useCallback((Q="draft")=>{if(pe)return;if((Q==="refine"?jt:Pt)&&!O){Se(),V(!0);return}Tt(Q)},[Pt,jt,Tt,pe,O,Se]),Ot=v.useCallback(()=>{Se(),V(!0)},[Se]),Wt=v.useCallback(Q=>{Me("cancelled"),g(Q)},[Me]),Xt=v.useCallback(()=>{pe||(Me("cancelled"),Ae.current=!1,U.current+=1,be.current="",fe.current=0,g(""),D(""),S(""),A("draft"),I("draft"),E(""),T(!1),y({status:"idle"}),ve(),Fe([]),Le(Q=>({...fs,runId:Q.runId})))},[Me,ve,pe,Fe,Le]),Zt=v.useCallback(Q=>{Q||Me("cancelled"),V(Q)},[Me]),Vt=B.timelineSteps.findIndex(Q=>Q===B.activeStep),Bt=B.phase==="self-healing"?"Fixing validation issue":B.phase==="validating"?"Validating SQL":B.activeStep||"Drafting SQL",Dt=R.status==="valid"?{label:"Validation passed",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",detail:R.message}:R.status==="invalid"?{label:"Validation failed",className:"border-destructive/40 bg-destructive/10 text-destructive",detail:R.message}:R.status==="error"?{label:"Validation unavailable",className:"border-border/60 bg-muted/20 text-muted-foreground",detail:R.message}:null;return e.jsxs("div",{ref:q,className:"relative flex h-7 min-w-0 flex-1 items-center",children:[e.jsx(t.Input,{value:f,onChange:Q=>Wt(Q.target.value),onFocus:Ot,onClick:Ot,onKeyDown:Q=>{Q.key==="Enter"&&(Q.preventDefault(),lt(dt))},placeholder:"Ask AI to generate SQL…","aria-label":"Ask AI to generate SQL",className:["h-7 rounded-[5px] border border-border/60 bg-background pl-3 text-[12px] shadow-none placeholder:text-muted-foreground/70 focus-visible:border-ring focus-visible:ring-0",Et?"pr-[56px]":"pr-3"].join(" ")}),e.jsxs(t.Popover,{open:O,onOpenChange:Zt,children:[e.jsx(t.PopoverAnchor,{asChild:!0,children:e.jsx("div",{className:"pointer-events-none absolute inset-0"})}),e.jsxs("div",{className:"absolute right-1 flex items-center gap-1",children:[Et&&e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:Q=>{Q.preventDefault(),Me("cancelled"),g("")},disabled:pe,"aria-label":"Clear input",title:"Clear input",children:e.jsx(le.X,{className:"size-3.5"})}),Et&&e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0",onClick:Q=>{if(Q.preventDefault(),pe){Me("stopped");return}lt(dt)},"aria-label":pe?"Stop AI generation":It,title:pe?"Stop AI generation":It,children:pe?e.jsx(a.Square,{className:"size-3 fill-current"}):e.jsx(a.SendHorizontal,{className:"size-3.5"})})]}),e.jsx(t.PopoverContent,{align:"start",alignOffset:0,side:"bottom",sideOffset:8,className:"w-[min(92vw,var(--radix-popover-trigger-width))] max-w-[760px] p-2.5",onOpenAutoFocus:Q=>{Q.preventDefault()},onInteractOutside:Q=>{var J;const ee=Q.target;ee&&((J=q.current)!=null&&J.contains(ee))&&Q.preventDefault()},children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"inline-flex h-7 items-center rounded-[5px] border border-border/60 bg-background p-0.5",children:[e.jsx(t.Button,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",dt==="draft"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>{I("draft"),T(!1)},children:"Draft New"}),e.jsx(t.Button,{type:"button",variant:"ghost",className:["h-6 rounded-[4px] px-2 text-[12px]",dt==="refine"?"bg-accent text-foreground":"text-muted-foreground hover:text-foreground"].join(" "),onClick:()=>I("refine"),disabled:!Rt,children:"Refine"})]}),e.jsx(a.AssistantContextEntityControls,{mode:"full",compact:!0,inlineLayout:!0,inlineTriggerFirst:!0,triggerVariant:"outline",triggerIconOnly:!1,triggerLabel:"Context",onSelectionChange:re})]}),e.jsxs("div",{className:"flex shrink-0 items-center",children:[pe&&e.jsx(t.Button,{variant:"ghost",size:"xs",onClick:()=>{Me("stopped")},children:"Stop"}),!pe&&e.jsx(t.Button,{variant:"ghost",size:"xs",onClick:Xt,disabled:!Jt,children:"Clear"})]})]}),B.timelineSteps.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[B.timelineSteps.map((Q,ee)=>{const J=Q===B.activeStep&&["drafting","validating","self-healing"].includes(B.phase),Te=!J&&Vt>=0&&ee<Vt;return e.jsx("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",J?"border-foreground/30 bg-foreground/10 text-foreground":Te?"border-border/60 bg-muted/20 text-muted-foreground":"border-border/50 bg-background text-muted-foreground/80"].join(" "),children:lo(Q,B.attempt)},`${Q}-${ee}`)}),Dt&&e.jsx(t.TooltipProvider,{delayDuration:150,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Dt.className].join(" "),children:Dt.label})}),e.jsx(t.TooltipContent,{side:"top",align:"start",className:"max-w-[680px] whitespace-pre-wrap break-words text-xs",children:Dt.detail})]})})]}),(pe||B.phase==="self-healing"||R.status==="validating")&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border/60 bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:[e.jsx(t.LoaderCircle,{className:"size-3.5 animate-spin"}),Bt]}),de&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:Qe}),M==="refine"&&C&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-[5px] border border-border/60 bg-muted/20 px-2.5 py-1.5 text-[11px]",children:[e.jsx("span",{className:"text-muted-foreground",children:"Refining editor SQL"}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"xs",onClick:()=>T(Q=>!Q),children:L?"Hide base SQL":"View base SQL"})]}),L&&e.jsx("div",{className:"max-h-[120px] overflow-auto rounded-[5px] border border-border/60",children:e.jsx(t.CodeEditor,{value:C,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Base SQL"})})]}),ot?e.jsxs("div",{className:"space-y-1",children:[M==="refine"&&e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Refined SQL"}),e.jsx("div",{className:"max-h-[200px] overflow-auto rounded-[5px] border border-border/60",children:e.jsx(t.CodeEditor,{value:w,onValueChange:()=>{},language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Drafted SQL"})})]}):gt?e.jsx("div",{className:"rounded-[5px] border border-dashed border-border/70 px-3 py-2 text-[11px] text-muted-foreground",children:"Validating SQL draft before preview."}):!pe&&e.jsx("div",{className:"rounded-[5px] border border-dashed border-border/70 px-3 py-2 text-[11px] text-muted-foreground",children:Rt?"Choose Draft New or Refine Current, then press Enter or click send.":"Describe what you want to query, then press Enter or click send to generate a SQL preview."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-1.5",children:[e.jsx(t.Button,{variant:"outline",size:"xs",onClick:i,children:"Open Full Assistant"}),e.jsx(t.Button,{variant:"secondary",size:"xs",disabled:pe||!ot,onClick:()=>tt(!1),children:"Replace SQL"}),e.jsx(t.Button,{size:"xs",disabled:pe||!ot||ct||Ht,onClick:()=>tt(!0),children:"Replace & Run"})]})]})})]})]})}function uo({activeEditor:s,showPythonEditor:n,isRunning:r,sqlEditor:o,pythonEditor:c,onActiveEditorChange:d,onOpenChange:i,onRun:l}){const u=s??"sql";return e.jsx(a.Dialog,{open:s!==null,onOpenChange:i,children:e.jsx(a.DialogContent,{showCloseButton:!1,className:"flex h-[min(88vh,860px)] w-[min(1280px,calc(100vw-2rem))] max-w-none flex-col gap-0 overflow-hidden p-0",children:e.jsxs(t.Tabs,{value:u,onValueChange:x=>d(x),className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs(a.DialogHeader,{className:"flex-row items-center justify-between space-y-0 border-b border-border/60 px-4 py-3 text-left",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-4",children:[e.jsx(a.DialogTitle,{className:"shrink-0 text-sm",children:"Query editor"}),e.jsxs(t.TabsList,{size:"xs",children:[e.jsx(t.TabsTrigger,{value:"sql",children:"SQL"}),n?e.jsx(t.TabsTrigger,{value:"python",children:"Python"}):null]}),e.jsx(a.DialogDescription,{className:"sr-only",children:"Expanded SQL and Python query editor"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs(t.Button,{type:"button",size:"xs",onClick:l,disabled:r,children:[r?e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(a.Play,{className:"h-3.5 w-3.5"}),"Run"]}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>i(!1),"aria-label":"Collapse query editor",title:"Collapse editor",children:e.jsx(Ke.Minimize2,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(t.TabsContent,{value:"sql",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:o}),n?e.jsx(t.TabsContent,{value:"python",forceMount:!0,className:"mt-0 min-h-0 flex-1 data-[state=inactive]:hidden",children:c}):null]})})})}function Rn(s,n){return s.current.cardId!==n&&(s.current={cardId:n,snapshots:{}}),s.current}function mo({cardId:s,expandedEditor:n,showPythonEditor:r}){const o=v.useRef(null),c=v.useRef(null),d=v.useRef(null),i=v.useRef(null),l=v.useRef({cardId:s,snapshots:{}}),u=v.useCallback(x=>{var N,f;const m=x==="inline"?o:d,b=x==="inline"?c:i,h=(N=m.current)==null?void 0:N.captureSession(),p=(f=b.current)==null?void 0:f.captureSession(),j=Rn(l,s);h&&(j.snapshots.sql=h),p&&(j.snapshots.python=p)},[s]);return v.useEffect(()=>{var j,N;const x=Rn(l,s),m=n===null?o:d,b=n===null?c:i,{sql:h,python:p}=x.snapshots;h&&((j=m.current)==null||j.restoreSession(h)),r&&p&&((N=b.current)==null||N.restoreSession(p))},[s,n,r]),{inlineSqlEditorRef:o,inlinePythonEditorRef:c,expandedSqlEditorRef:d,expandedPythonEditorRef:i,captureEditorSessions:u}}function xo({value:s}){const[n,r]=v.useState(!1),o=v.useRef(null);v.useEffect(()=>()=>{o.current&&clearTimeout(o.current)},[]);const c=async()=>{var d;try{if(!((d=navigator.clipboard)!=null&&d.writeText))throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(s),r(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>r(!1),1200)}catch{t.ue.error("Failed to copy")}};return e.jsxs("button",{type:"button","aria-label":`Copy ${s}`,onClick:c,className:"group inline-flex w-full cursor-pointer items-center justify-start rounded-[3px] bg-muted/35 px-2 py-1.5 text-left font-mono text-[11px] text-foreground transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{children:s}),n?e.jsx(t.Check,{"aria-hidden":"true",className:"ml-auto size-3.5 shrink-0 text-emerald-600/80 dark:text-emerald-400/80",strokeWidth:1.75}):e.jsx(a.Copy,{"aria-hidden":"true",className:"ml-auto size-3.5 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-muted-foreground group-focus-visible:text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"sr-only","aria-live":"polite",children:n?"Copied to clipboard":""})]})}function ho({hint:s}){const[n,r]=v.useState(!1),o=v.useRef(null),c=v.useRef(null),d=()=>{o.current&&(clearTimeout(o.current),o.current=null)},i=()=>{c.current&&(clearTimeout(c.current),c.current=null)};v.useEffect(()=>()=>{d(),i()},[]);const l=x=>{x.pointerType!=="touch"&&(i(),!n&&(d(),o.current=setTimeout(()=>r(!0),200)))},u=x=>{x.pointerType!=="touch"&&(d(),i(),c.current=setTimeout(()=>r(!1),150))};return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{type:"button",variant:"ghost",size:"xs","aria-label":"Dashboard filters off",onPointerEnter:l,onPointerLeave:u,onFocus:()=>{d(),i(),r(!0)},className:"h-7 w-7 shrink-0 gap-1.5 border border-amber-300/60 bg-amber-50/60 px-0 text-amber-800 hover:bg-amber-100/70 hover:text-amber-900 @[1550px]:w-auto @[1550px]:px-2 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-300 dark:hover:bg-amber-500/15 dark:hover:text-amber-200",children:[e.jsx(pt.FilterX,{className:"h-3.5 w-3.5",strokeWidth:1.75}),e.jsx("span",{className:"hidden @[1550px]:inline",children:"Dashboard filters off"})]})}),e.jsxs(t.PopoverContent,{align:"start",collisionPadding:8,onPointerEnter:x=>{x.pointerType!=="touch"&&i()},onPointerLeave:u,onOpenAutoFocus:x=>x.preventDefault(),className:"w-72 space-y-2.5 p-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[13px] font-medium",children:"Dashboard filters aren’t applied"}),e.jsx("p",{className:"text-[12px] leading-relaxed text-muted-foreground",children:s.description})]}),e.jsx(xo,{value:s.helper}),e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/filters",target:"_blank",rel:"noreferrer",className:"inline-flex text-[12px] font-medium text-foreground underline-offset-4 hover:underline",children:"Learn more ↗"})]})]})}function po({renderCommandBarEnd:s}={}){var he,ze;const n=a.useQueryClient(),[r,o]=v.useState(!1),[c,d]=v.useState(!1),i=pt.useEditorClearAction(),[l,u]=v.useState(null),x=t.useEditorStore(Z=>Z.frame),m=t.useEditorStore(Z=>Z.card),{inlineSqlEditorRef:b,inlinePythonEditorRef:h,expandedSqlEditorRef:p,expandedPythonEditorRef:j,captureEditorSessions:N}=mo({cardId:m.id,expandedEditor:l,showPythonEditor:r});t.useEditorStore(Z=>Z.isShowingVisual),t.useEditorStore(Z=>Z.selectedConnectionId),t.useEditorStore(Z=>Z.tempQueryData);const f=t.useEditorStore(Z=>Z.selectedDatabaseName);t.useEditorStore(Z=>Z.selectedDatamodelId);const g=t.useEditorStore(Z=>Z.selectedSchemaName);t.useEditorStore(Z=>Z.showAIDialog);const k=t.useEditorStore(Z=>Z.selectedTableName),D=t.useDashboardStore(Z=>{var Re,me;return((me=(Re=Z.dashboard)==null?void 0:Re.filters)==null?void 0:me.length)??0}),w=t.useEditorStore(Z=>Z.inlineFilterValuesMap[(m==null?void 0:m.id)??""]),S=v.useMemo(()=>xe.findCustomVisualConfigCard(x,m),[x,m]),{manifest:M}=a.useCustomVisual(((he=S==null?void 0:S.customCardPreferences)==null?void 0:he.url)||""),A=v.useMemo(()=>{var Z;return(Z=M==null?void 0:M.visuals)==null?void 0:Z.find(Re=>{var me;return Re.name===((me=S==null?void 0:S.customCardPreferences)==null?void 0:me.componentName)})},[M,(ze=S==null?void 0:S.customCardPreferences)==null?void 0:ze.componentName]),F=xe.resolveMultiInputType(S,A),I=v.useMemo(()=>xe.getCustomVisualInputCards({frame:x,configCard:S,isMultiInputVisual:F==="multiple"}),[x,S,F]),C=v.useMemo(()=>{const Z=I.findIndex(Re=>(Re==null?void 0:Re.id)===(m==null?void 0:m.id));return Z<0?-1:xe.getSlotIndexForCard(m,Z)},[I,m]),E=v.useMemo(()=>!S||F!=="multiple"||C<0?m.type:xe.getEffectiveCardTypeForSlot(m,C,A==null?void 0:A.slots)??m.type,[S,F,C,m,A==null?void 0:A.slots]),L=v.useMemo(()=>E!==m.type?{...m,type:E}:m,[m,E]),T=v.useMemo(()=>D===0?null:wt.getDashboardFilterSubscriptionHint(m==null?void 0:m.sql),[m==null?void 0:m.sql,D]),R=v.useRef(!0),{setCardCustomCfg:y,setQueryResultColumns:B,setCardSql:P,setTempQueryData:O,setPythonStdOut:V,setCardPreferences:_,setCardType:z,setCardPython:q,setShowAIDialog:Y,setCard:$,updateCardInFrame:U}=t.useEditorActions();t.useEditorStore(Z=>Z.onSave),t.useEditorStore(Z=>Z.onClose),t.useEditorStore(Z=>Z.actions.setSqlGen);const H=t.useEditorStore(Z=>Z.runSql),te=t.useEditorStore(Z=>Z.actions.setRunSql),X=t.useEditorStore(Z=>Z.actions.setIsSqlRunning),{data:se,isLoading:ue,isFetching:fe,isSuccess:be,isError:ge,error:Pe,errorSql:Oe,queryKey:Ae,refetch:Ie,errorMessage:_e}=a.useEditorCardQuery(L),Ye=v.useRef(Ae);Ye.current=Ae,v.useEffect(()=>{if(se)if(se.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),V((se==null?void 0:se.output)||""),se.records.length>0){const{keys:Z}=a.getKeys(se.records);B(m.type==="kpi"?a.getDisplayedKpiResultColumnKeys(se.records).slice(0,1):Z)}else B([])},[m.type,se,B,V]),v.useEffect(()=>{(ue||fe)&&(X(!0),B([])),(ge||be)&&X(!1),ge&&(B([]),V(""))},[ue,fe,se,V,ge,be,X,B,Pe]),v.useEffect(()=>{H&&(n.getQueryData(Ae)||Ie(),te(!1))},[H,Ie,te,Ae,n]);const Ve=v.useRef(Ie);Ve.current=Ie,v.useEffect(()=>{if(R.current){R.current=!1;return}Ve.current()},[w]);function Le(Z,Re){P(Z),Re&&te(!0)}function De(){a.flushPendingEditorDrafts(),setTimeout(()=>{n.removeQueries({queryKey:Ye.current,exact:!0}),te(!0)},0)}function ae(Z){a.flushPendingEditorDrafts(),N("inline"),u(Z)}function K(Z){a.flushPendingEditorDrafts(),N("expanded"),u(Z)}function ie(Z){Z||(a.flushPendingEditorDrafts(),N("expanded"),u(null))}function Se(){return e.jsxs(a.ResizablePanelGroup,{className:"flex grow gap-2",direction:"vertical",role:"editor-resizable-group",children:[e.jsx(a.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:e.jsx("div",{id:"sql-container",className:"relative flex w-full overflow-hidden bg-background",children:l===null?e.jsx(a.SqlEditor,{ref:b,onExpand:()=>ae("sql")},`inline-sql-${m.id}`):null})}),r&&e.jsxs(e.Fragment,{children:[e.jsxs(a.PanelResizeHandle,{className:"group/divider relative my-1 flex h-6 w-full shrink-0 cursor-row-resize items-center gap-3 px-1 outline-none",children:[e.jsx("span",{className:"h-px flex-1 bg-border transition-colors group-hover/divider:bg-foreground/30"}),e.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 whitespace-nowrap text-[10px] text-muted-foreground",children:[e.jsx(a.ArrowDown,{className:"h-3 w-3",strokeWidth:1.75}),e.jsx("span",{className:"font-medium uppercase tracking-[0.08em]",children:"Post-process with Python"}),e.jsx("span",{"aria-hidden":!0,className:"text-border",children:"·"}),e.jsx("code",{className:"hidden font-mono text-[10px] tracking-normal text-foreground/80 sm:inline",children:"def process(df) → df"}),e.jsx("span",{"aria-hidden":!0,className:"hidden text-border md:inline",children:"·"}),e.jsx("span",{className:"hidden font-mono text-[10px] uppercase tracking-[0.08em] md:inline",children:"Python 3.11"})]}),e.jsx("span",{className:"h-px flex-1 bg-border transition-colors group-hover/divider:bg-foreground/30"}),e.jsx("button",{type:"button","aria-label":"Expand Python editor",title:"Expand Python editor",onClick:Z=>{Z.stopPropagation(),ae("python")},onPointerDown:Z=>Z.stopPropagation(),className:"inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:bg-muted focus-visible:text-foreground focus-visible:outline-none",children:e.jsx(Ke.Maximize2,{className:"h-3 w-3",strokeWidth:1.75})}),e.jsx("button",{type:"button","aria-label":"Close Python editor",onClick:Z=>{Z.stopPropagation(),o(!1)},onPointerDown:Z=>Z.stopPropagation(),className:"inline-flex h-5 w-5 shrink-0 cursor-pointer items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(le.X,{className:"h-3 w-3",strokeWidth:1.75})})]}),e.jsx(a.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:e.jsx("div",{id:"python-container",className:"relative flex w-full flex-col overflow-hidden bg-background",children:e.jsx("div",{className:"relative flex flex-1",children:l===null?e.jsx(a.PythonEditor,{ref:h},`inline-python-${m.id}`):null})})})]})]})}function re(){const Z={query:e.jsx(a.DropdownMenuCheckboxItem,{checked:r,onCheckedChange:Re=>o(Re===!0),children:"Python post-processor"}),reset:e.jsxs(a.DropdownMenuItem,{onSelect:i,children:[e.jsx(t.RotateCcw,{className:"h-3.5 w-3.5"}),"Reset editor"]})};return e.jsx("div",{role:"editor-controls",className:"flex w-full flex-wrap items-center gap-2 px-4 pb-2 pt-3 @container",children:e.jsxs("div",{className:"flex w-full min-w-0 flex-nowrap items-center gap-2 overflow-hidden",children:[e.jsxs(t.Button,{title:"Shift + Enter",disabled:ue||fe,onClick:De,className:"shrink-0",size:"xs",children:[ue||fe?e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(a.Play,{className:"h-3.5 w-3.5"}),"Run"]}),e.jsxs(a.Toggle,{pressed:r,onPressedChange:Re=>o(Re),title:r?"Remove Python post-processor":"Add a Python step to post-process the SQL result",className:"h-7 w-7 shrink-0 gap-1.5 rounded-control px-0 text-[12px] @[1450px]:w-auto @[1450px]:px-2.5",size:"sm",variant:"outline",children:[e.jsx("span",{className:"inline-flex h-3 w-3 items-center justify-center rounded-[2px] bg-muted font-mono text-[8px] font-bold text-muted-foreground",children:"Py"}),e.jsx("span",{className:"hidden @[1450px]:inline",children:"Python"}),r?e.jsx(t.Check,{className:"hidden h-3 w-3 @[1450px]:block",strokeWidth:1.75}):e.jsx(a.Plus,{className:"hidden h-3 w-3 text-muted-foreground @[1450px]:block",strokeWidth:1.75})]}),T&&e.jsx(ho,{hint:T}),e.jsx("div",{className:"hidden min-w-[220px] flex-1 @[950px]:flex",children:e.jsx(co,{currentSql:m==null?void 0:m.sql,currentPython:m==null?void 0:m.python,selectedDatabaseName:f,selectedSchemaName:g,selectedTableName:k,onApplySql:Le,onOpenFullAssistant:()=>Y(!0)})}),e.jsx(t.Button,{variant:"outline",size:"xs",className:"min-w-0 shrink @[950px]:hidden",onClick:()=>Y(!0),children:e.jsx("span",{className:"truncate",children:"Generate SQL"})}),s==null?void 0:s(Z)]})})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"flex shrink-0 flex-col gap-1.5 px-4 pb-3 pt-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:t.cn("min-w-0",c&&"flex-1"),children:e.jsx(a.EditableText,{value:m.title,onSave:Z=>$({...m,title:Z}),onEditingChange:d,isEditable:!0,placeholder:"Add title",displayClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]",inputClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]"})}),e.jsx(a.InfoHover,{card:m})]}),e.jsx(a.EditableText,{value:(m.description||"").trim(),onSave:Z=>$({...m,description:Z.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})]}),e.jsx("div",{className:"relative flex grow overflow-y-scroll",children:Se()}),re(),e.jsx(uo,{activeEditor:l,showPythonEditor:r,isRunning:ue||fe,sqlEditor:e.jsx(a.SqlEditor,{ref:p},`expanded-sql-${m.id}`),pythonEditor:e.jsx(a.PythonEditor,{ref:j},`expanded-python-${m.id}`),onActiveEditorChange:K,onOpenChange:ie,onRun:De})]})}function fo(s){const n=t.useDashboardStore(f=>f.dashboard),r=t.useDashboardStore(f=>f.dashboard.filters),o=t.useDashboardStore(f=>f.filterValues),c=t.useDashboardStore(f=>f.selectedSheetId),d=t.useDashboardStore(f=>f.dashboardInputValues),i=t.useDashboardStore(f=>f.controlValues),l=t.useDashboardStore(f=>f.inlineFilterValuesMap),u=t.useDashboardStore(f=>f.cardControlValuesMap),x=t.useDashboardStore(f=>f.actions.getCard(s)),m=t.useEditorStore(f=>f.editorContext),b=t.useEditorStore(f=>f.card),p=(m==null?void 0:m.type)==="documentSection"&&m.cardId===s?m:void 0,j=p?b:x;if(t.requiresDashboardInputResolution({dashboard:n,dashboardInputValues:d})&&j){const f=t.resolveDashboardInputContext({dashboard:n,sheetId:p?p.sheetId:c,sheetKind:p?"document":void 0,sectionId:p?p.sectionId:void 0,card:j,runtimeValues:{dashboardInputValues:d,filterValues:o,controlValues:i,inlineFilterValuesMap:l,cardControlValuesMap:u},mode:p?"editor":"interactive"}),g=go(f.inputs);return{cardFilters:f.inputs.flatMap(k=>k.kind==="filter"&&!g.has(k.filter.id)?[k.filter]:[]),cardFilterValues:f.activeFilters.filter(k=>!g.has(k.filterId))}}return p?{cardFilters:[],cardFilterValues:p.documentFilterValues||[]}:a.calculateCardFilterValues(r,o,c,s)}function go(s){return new Set(s.flatMap(n=>{var r;return n.kind==="filter"&&((r=n.compatibility)==null?void 0:r.source)==="cardInlineFilter"?[n.filter.id]:[]}))}function bo(s,n){var d;let r=0,o=0;const c=Math.min(s.length,50);for(let i=0;i<c;i++){const l=(d=s[i])==null?void 0:d[n];if(!(l==null||l==="")){if(o++,typeof l=="number"||typeof l=="bigint")r++;else if(typeof l=="boolean")return"boolean"}}return o===0?"null":r/o>.7?"number":"text"}function jo(s){if(s===null)return"null";if(s===void 0)return"";if(typeof s=="number"||typeof s=="bigint"||typeof s=="boolean")return String(s);if(typeof s=="string")return s;try{return JSON.stringify(s)}catch{return String(s)}}function vo({data:s,card:n,paginationMetadata:r,onPaginationChange:o,onPageSizePreferenceChange:c,onSortChange:d,isLoading:i}){var T,R,y,B,P,O;const{updateEnableDevModePagination:l,setRunSql:u}=t.useEditorActions(),x=v.useMemo(()=>Object.keys(s[0]??{}),[s]),m=n.sql&&!((R=(T=n.preferences)==null?void 0:T.tablePrefs)!=null&&R.enableDevModePagination)?(B=(y=n.preferences)==null?void 0:y.tablePrefs)==null?void 0:B.pageSize:void 0,b=v.useMemo(()=>{var V;return a.sortByColumnsToSortState((V=n.config)==null?void 0:V.sortByColumns)},[(P=n.config)==null?void 0:P.sortByColumns]),{canSort:h,canUseLocalSorting:p,handlePaginationChange:j,handleSortChange:N,pagination:f,paginationMode:g,sorting:k}=a.useTableQueryState({card:n,dataLength:s.length,onPaginationChange:o,onSortChange:d,pageSize:m,paginationMetadata:r,sortState:b}),D=v.useMemo(()=>k.filter(V=>x.includes(V.id)),[k,x]),w=v.useMemo(()=>{const V={};for(const _ of x)V[_]=bo(s,_);return V},[x,s]),S=v.useMemo(()=>x.map(V=>{const z=w[V]==="number";return{accessorKey:V,enableSorting:h,header:({column:q})=>{const Y=q.getIsSorted();return e.jsxs("div",{className:t.cn("flex min-w-0 select-none items-center gap-1.5 transition-colors",q.getCanSort()&&"cursor-pointer hover:text-foreground",z&&"justify-end"),onClick:()=>q.getCanSort()&&q.toggleSorting(q.getIsSorted()==="asc"),children:[e.jsx("span",{className:"min-w-0 truncate",title:V,children:V}),Y==="asc"?e.jsx(a.ArrowUpIcon,{className:"h-3.5 w-3.5 shrink-0 text-foreground"}):Y==="desc"?e.jsx(a.ArrowDownIcon,{className:"h-3.5 w-3.5 shrink-0 text-foreground"}):q.getCanSort()?e.jsx(a.ChevronsUpDown,{className:"h-3 w-3 shrink-0 opacity-0 transition-opacity group-hover/header:opacity-50"}):null]})},cell:({getValue:q})=>{const Y=q(),$=Y===null;return e.jsx("div",{className:t.cn("overflow-hidden truncate whitespace-nowrap leading-5",z&&"text-right tabular-nums",$&&"italic text-muted-foreground/50"),children:jo(Y)})}}}),[h,w,x]),M=Math.max(S.length,1),A=a.useReactTable({data:s,columns:S,getCoreRowModel:a.getCoreRowModel(),getPaginationRowModel:g==="client"?a.getPaginationRowModel():void 0,onSortingChange:N,getSortedRowModel:p?a.getSortedRowModel():void 0,onPaginationChange:g==="disabled"?void 0:j,manualPagination:g==="server"||g==="disabled",manualSorting:!p,pageCount:g==="server"&&r?r.pageCount:void 0,state:{sorting:D,pagination:f}}),F=g==="server"&&r?r.totalCount:s.length,I=a.isDevPaginationSwitchableCard(n),C=g!=="disabled"&&(g==="server"||I||F>10),E=g==="server"||F>10,L=x.length>0?`${x.length*144}px`:"100%";return e.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col",children:[i&&e.jsx("div",{className:"absolute inset-0 z-20 flex items-center justify-center bg-background/50",children:e.jsx(t.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),e.jsxs(a.CustomScrollArea,{className:"relative min-h-0 w-full grow overflow-auto rounded-none border-0 bg-transparent text-foreground",children:[e.jsxs("table",{className:"w-full text-sm [border-spacing:0]",style:{minWidth:L},children:[e.jsx(a.TableHeader,{className:"sticky top-0 z-10 bg-muted [&_tr]:border-b-0",children:A.getHeaderGroups().map(V=>e.jsx(a.TableRow,{className:"border-b-0 hover:bg-transparent",children:V.headers.map(_=>{const q=w[_.id]==="number";return e.jsx(a.TableHead,{className:t.cn("group/header relative h-auto border-b border-transparent bg-muted/95 px-4 py-2 align-middle text-[10px] font-medium tracking-[0.08em] text-muted-foreground after:absolute after:bottom-0 after:left-0 after:right-0 after:h-px after:bg-border/60",q&&"text-right"),children:_.isPlaceholder?null:a.flexRender(_.column.columnDef.header,_.getContext())},_.id)})},V.id))}),e.jsx(a.TableBody,{children:(O=A.getRowModel().rows)!=null&&O.length?A.getRowModel().rows.map(V=>e.jsx(a.TableRow,{className:"border-b border-border/40 transition-colors","data-state":V.getIsSelected()&&"selected",children:V.getVisibleCells().map(_=>{const q=w[_.column.id]==="number";return e.jsx(a.TableCell,{className:t.cn("overflow-hidden px-4 py-2 text-[13px] text-foreground/90",q&&"text-right"),children:a.flexRender(_.column.columnDef.cell,_.getContext())},_.id)})},V.id)):e.jsx(a.TableRow,{children:e.jsx(a.TableCell,{colSpan:M,className:"h-auto py-12 text-center text-[13px] text-muted-foreground",children:"No results."})})})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]}),e.jsx("div",{className:"shrink-0 border-t border-border/60 bg-background text-[13px]",children:C?e.jsx(a.DataTablePagination,{totalColumns:x.length,pageCount:g==="server"&&r?r.pageCount:A.getPageCount(),pageIndex:A.getState().pagination.pageIndex,pageSize:A.getState().pagination.pageSize,rowCount:F,selectedRowCount:0,setPageIndex:A.setPageIndex,setPageSize:A.setPageSize,canPreviousPage:g==="server"&&r?r.hasPrevPage:A.getCanPreviousPage(),canNextPage:g==="server"&&r?r.hasNextPage:A.getCanNextPage(),previousPage:A.previousPage,nextPage:A.nextPage,onPageSizePreferenceChange:c,onClearSelection:()=>{},paginationMode:g,showPaginationControls:E,onPaginationModeChange:I?V=>{A.setPageIndex(0),l(V==="server"),u(!0)}:void 0,showExport:!1}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[F.toLocaleString()," ",F===1?"row":"rows"," · ",x.length," ",x.length===1?"column":"columns"]}),D.length>0&&e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["Sorted by"," ",e.jsx("span",{className:"font-medium text-foreground/70",children:D[0].id})," ",D[0].desc?"↓":"↑"]})]})})]})}const Pn=[{value:"table",label:"Table"},{value:"aggregateTable",label:"Hierarchical"},{value:"pivotTable",label:"Pivot"},{value:"detailTable",label:"Detail"}];function yo({className:s}){const n=t.useEditorStore(p=>p.card),r=t.useEditorStore(p=>p.frame),o=t.useEditorStore(p=>p.editorContext),c=a.useEffectiveEditorCardType(),{setCard:d,updateCardInFrame:i}=t.useEditorActions(),l=(o==null?void 0:o.type)==="documentSection"?Pn.filter(p=>["table","pivotTable"].includes(p.value)):Pn,u=["table","aggregateTable","pivotTable","detailTable"].includes(c),x=je.hasValidCardConfig(n.config,n.type),m=xe.isCustomVisualConfigCard(n,r.cards);if(!u||!x||m)return e.jsx("div",{"aria-hidden":"true",className:t.cn("invisible flex items-center gap-5",s),children:e.jsx("span",{className:"-mb-px flex h-9 items-center border-b-2 border-transparent text-[12px]",children:"Placeholder"})});const b=p=>{if(p===c||m)return;const j=p,N=n.config??{},f=h(c,j,N),g={...n,type:j,config:f};d(g),i(g)},h=(p,j,N)=>{var g;if(p===j)return N;if(j==="detailTable"){const k=M=>M==null?void 0:M.toLowerCase().replace(/\s+/g,"").trim(),D=(M,A)=>{const F=[k(M.label),k(M.qualifiedFieldName),k(M.name)].filter(Boolean),I=[k(A.label),k(A.qualifiedFieldName),k(A.name)].filter(Boolean);return F.some(C=>I.includes(C))},w=(N.groupByColumns||[]).map(M=>({...M,role:"detail"})),S=((g=N.sortByColumns)==null?void 0:g.filter(M=>w.some(A=>D(M,A))))??[];return{...N,detailTableBackup:{groupByColumns:N.groupByColumns,metricColumns:N.metricColumns,pivotByColumns:N.pivotByColumns,sortByColumns:N.sortByColumns,rowAggregates:N.rowAggregates,columnAggregates:N.columnAggregates},detailColumns:w,groupByColumns:[],metricColumns:[],pivotByColumns:[],sortByColumns:S,rowAggregates:[],columnAggregates:[]}}let f=N;if(p==="detailTable")if(N.detailTableBackup)f={...N,...N.detailTableBackup,detailColumns:[],detailTableBackup:void 0};else{const k=(N.detailColumns||[]).map(D=>({...D,role:"groupby"}));f={...N,groupByColumns:k,detailColumns:[]}}return j==="aggregateTable"?{...f,pivotByColumns:[]}:f};return e.jsx("div",{role:"tablist",className:t.cn("flex items-center gap-5",s),children:l.map(p=>{const j=c===p.value;return e.jsx("button",{type:"button",role:"tab","aria-selected":j,onClick:()=>b(p.value),className:t.cn("-mb-px flex h-9 items-center border-b-2 text-[12px] transition-colors",j?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:p.label},p.value)})})}const Co=1200;function No(s){var o;const n=s.target;if(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)return n.selectionStart!==n.selectionEnd;const r=(o=s.currentTarget.ownerDocument.defaultView)==null?void 0:o.getSelection();return!!(r&&!r.isCollapsed)}function As({text:s,children:n,className:r,as:o="button",disabled:c,onClick:d,onCopy:i,...l}){const[u,x]=v.useState(!1),m=v.useRef(void 0);v.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const b=()=>{m.current&&(clearTimeout(m.current),m.current=void 0),x(!1)},h=()=>{m.current&&clearTimeout(m.current),x(!0),m.current=setTimeout(()=>{x(!1),m.current=void 0},Co)},p=async()=>{try{let g=!1;i?g=await i():typeof s=="string"&&navigator.clipboard&&(await navigator.clipboard.writeText(s),g=!0),g&&h()}catch(g){console.error("Failed to copy text",g)}},j=g=>{d==null||d(g),!(g.defaultPrevented||No(g))&&p()},N=t.cn("group/copy-on-click relative block w-full cursor-pointer rounded-control text-left transition-[background-color,box-shadow] duration-150","hover:bg-muted/30 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring motion-reduce:transition-none",c&&"cursor-default opacity-60",r),f=o==="div"?e.jsx("div",{...l,"aria-disabled":c||void 0,className:N,onClick:c?void 0:j,onBlur:b,onMouseLeave:b,children:n}):e.jsx("button",{type:"button",className:N,disabled:c,onClick:j,onBlur:b,onMouseLeave:b,...l,children:n});return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{open:u,onOpenChange:g=>{g||b()},children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:f}),e.jsx(t.TooltipContent,{side:"top",children:"Copied!"})]})})}const On={async writeTextToClipboard(s){return typeof navigator>"u"||!navigator.clipboard?!1:(await navigator.clipboard.writeText(s),!0)}},Ft="h-6 gap-1 px-2 text-[11px] [&_svg]:h-3 [&_svg]:w-3";function ca({children:s,className:n}){return e.jsx("div",{className:t.cn("flex max-h-full min-h-0 flex-1 flex-col pt-3",n),children:s})}function da({children:s,className:n}){return e.jsx("div",{className:t.cn("flex min-h-7 shrink-0 flex-wrap items-center justify-between gap-x-3 gap-y-1 px-3",n),children:s})}function ua({children:s,className:n}){return e.jsx("div",{className:t.cn("ml-auto flex min-w-0 flex-wrap items-center justify-end gap-1.5",n),children:s})}const rs=50;function So(s){return`Copy ${s}`}const wo=[{target:"queryRequest",label:"Query request"},{target:"queryResponse",label:"Query response"},{target:"cardConfig",label:"Card config"},{target:"dataSource",label:"Data source"},{target:"columns",label:"Columns"},{target:"dashboardFilters",label:"Dashboard filters"},{target:"cardMetadata",label:"Card metadata"}];function Vn(s){try{return JSON.stringify(s,null,2)}catch(n){return console.error("Unable to stringify debug payload",n),null}}function Mt(s){switch(s){case"queryRequest":return"Query request";case"queryResponse":return"Query response";case"cardConfig":return"Card config";case"dataSource":return"Data source";case"cardMetadata":return"Card metadata";case"columns":return"Columns";case"dashboardFilters":return"Dashboard filters";default:return"Payload"}}function To(s){if(!s||typeof s!="object")return{value:s};const n=s.records;return!Array.isArray(n)||n.length<=rs?{value:s}:{value:{...s,records:n.slice(0,rs),previewMeta:{truncatedRecords:!0,displayedRecords:rs,totalRecords:n.length}},truncationMessage:`Preview showing first ${rs} records of ${n.length}. Copy actions include full payload.`}}function ma({isOpen:s,onClick:n}){return e.jsxs(t.Button,{onClick:n,variant:"outline",size:"xs",className:Ft,"aria-expanded":s,children:[e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 transition-transform",s&&"rotate-180")}),s?"Hide card details":"Card details"]})}function xa({debugPayloads:s,className:n}){const[r,o]=v.useState(null),c=t.useEditorStore(D=>D.card),d=t.useEditorStore(D=>D.frame),i=t.useDashboardStore(D=>D.selectedSheetId),l=t.useDashboardStore(D=>{var w;return(w=D.dashboard)==null?void 0:w.id}),u=v.useMemo(()=>({cardId:c.id||null,frameId:d.id||null,sheetId:i||null,dashboardId:l||null}),[c.id,d.id,i,l]),x=v.useMemo(()=>({queryRequest:s==null?void 0:s.queryRequest,queryResponse:s==null?void 0:s.queryResponse,cardConfig:c.config,dataSource:c.dataSource,columns:s==null?void 0:s.columns,dashboardFilters:s==null?void 0:s.dashboardFilters,cardMetadata:u}),[s==null?void 0:s.queryRequest,s==null?void 0:s.queryResponse,s==null?void 0:s.columns,s==null?void 0:s.dashboardFilters,c.config,c.dataSource,u]),m=!!s,b=v.useMemo(()=>[{label:"Card ID",value:c.id||""},{label:"Frame ID",value:d.id||""},{label:"Sheet ID",value:i||""},{label:"Dashboard ID",value:l||""}],[c.id,d.id,i,l]),h=D=>x[D]!==void 0,p=v.useMemo(()=>{if(!r)return null;const D=x[r];if(D===void 0)return null;const w=r==="queryResponse"?To(D):{value:D},S=Vn(w.value);return S?{target:r,title:Mt(r),json:S,truncationMessage:w.truncationMessage}:null},[r,x]),j=p?p.title:"Inspect payload",N=async D=>{const w=x[D];if(w===void 0)return t.ue.error(`No ${Mt(D).toLowerCase()} available`),!1;const S=Vn(w);if(!S)return t.ue.error(`Unable to serialize ${Mt(D).toLowerCase()}`),!1;try{return await On.writeTextToClipboard(S)?(t.ue.success(`${Mt(D)} copied`),!0):(t.ue.error("Clipboard is not available"),!1)}catch(M){return console.error("Failed to copy debug payload",M),t.ue.error(`Unable to copy ${Mt(D).toLowerCase()}`),!1}},f=async()=>p?N(p.target):!1,g=async D=>{if(!D.value)return!1;try{return await On.writeTextToClipboard(D.value)?!0:(t.ue.error("Clipboard is not available"),!1)}catch(w){return console.error("Failed to copy card detail",w),t.ue.error(`Unable to copy ${D.label}`),!1}},k=D=>{if(x[D]===void 0){t.ue.error(`No ${Mt(D).toLowerCase()} available`);return}o(D)};return e.jsxs("div",{className:t.cn("mb-2 min-w-0 px-3",n),children:[e.jsx("div",{className:"grid grid-cols-1 gap-x-6 gap-y-1 md:grid-cols-2",children:b.map(D=>e.jsxs(As,{text:D.value,"aria-label":So(D.label),title:D.value?`Copy ${D.label}`:"N/A",disabled:!D.value,onCopy:()=>g(D),className:"min-w-0 py-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:D.label}),e.jsx("code",{className:"mt-1 block truncate font-mono text-[12px] leading-5 text-foreground",children:D.value||"N/A"})]},D.label))}),m&&e.jsxs("div",{className:"mt-2 border-t border-border/60 pt-2",children:[e.jsxs("div",{className:"flex min-h-7 items-center justify-between gap-3",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Diagnostics"}),e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"xs",className:Ft,children:[e.jsx(Ke.Eye,{}),j,e.jsx(le.ChevronDown,{})]})}),e.jsx(a.DropdownMenuContent,{align:"end",className:"w-48 p-1",children:wo.map(D=>e.jsx(a.DropdownMenuItem,{disabled:!h(D.target),onSelect:()=>k(D.target),className:t.cn("h-7 rounded-control px-2 text-[12px] font-normal leading-4",r===D.target&&"bg-accent"),children:D.label},`preview-${D.target}`))})]})]}),p&&e.jsxs("div",{className:"mt-2 space-y-2 border-t border-border/60 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"truncate text-[12px] font-medium text-foreground",children:p.title}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(a.CopyButton,{text:p.json,className:"h-6 w-6 rounded-control px-0 text-muted-foreground",ariaLabel:"Copy diagnostics payload",onCopy:f}),e.jsx(t.Button,{variant:"ghost",size:"xs",className:"h-6 px-2 text-[11px]",onClick:()=>o(null),children:"Close"})]})]}),p.truncationMessage&&e.jsx("p",{className:"text-[12px] leading-5 text-muted-foreground",children:p.truncationMessage}),e.jsx("div",{className:"max-h-80 overflow-auto rounded-[5px] border border-border/60 bg-background p-1",children:e.jsx(t.CodeEditor,{value:p.json,language:"json",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:`${p.title} JSON`})})]})]})]})}const Eo=()=>{};function ha({sql:s,label:n,ariaLabel:r,copyAriaLabel:o,headerActions:c,trailingHeaderActions:d,collapsible:i=!1,defaultOpen:l=!1,children:u,className:x,headerClassName:m,bodyClassName:b}){const h=v.useId(),[p,j]=v.useState(l),N=!i||p;return e.jsxs("div",{className:t.cn("flex min-h-0 flex-col overflow-hidden",x),children:[e.jsxs(da,{className:m,children:[i?e.jsxs("button",{type:"button",onClick:()=>j(f=>!f),"aria-expanded":p,"aria-controls":N?h:void 0,className:"-ml-1 flex min-w-0 items-center gap-1 rounded-control px-1 py-0.5 text-[12px] text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-3 w-3 shrink-0 transition-transform",p&&"rotate-90")}),e.jsx("span",{className:"truncate",children:n})]}):e.jsx("span",{className:"text-[12px] text-muted-foreground",children:n}),N?e.jsxs(ua,{children:[c,d]}):null]}),N?e.jsxs("div",{id:h,className:t.cn("min-h-[80px] overflow-auto px-1 py-1",b),children:[u,e.jsx(As,{as:"div",text:s,title:o,className:"min-h-[80px] [&_pre]:!cursor-pointer [&_textarea]:!cursor-pointer",children:e.jsx(t.CodeEditor,{value:s,onValueChange:Eo,language:"sql",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:r})})]}):null]})}function pa({error:s,errorSql:n,errorTitle:r="Error details",errorMessageClassName:o,fillAvailableSqlHeight:c=!1,onOpenInEditor:d,onDebugWithAssistant:i,onSendFeedback:l,showFeedbackButton:u=!0,showCardDetails:x=!1,defaultSqlExpanded:m=!1,debugPayloads:b,className:h,embedded:p=!1}){const j=v.useId(),[N,f]=v.useState(!1),g=p?"px-3":"px-0",k=!!i,D=!!(d&&n),w=x,S=!!(u&&l),M=k||D||w?e.jsxs(e.Fragment,{children:[i?e.jsx(t.Button,{variant:"ghost",size:"xs",className:Ft,onClick:i,children:"Debug with Assistant"}):null,d&&n?e.jsx(t.Button,{variant:"outline",size:"xs",className:Ft,onClick:d,children:"Open in SQL editor"}):null,x?e.jsx(ma,{isOpen:N,onClick:()=>f(F=>!F)}):null]}):null,A=S?e.jsx(t.Button,{type:"button",variant:"ghost",size:"xs",className:t.cn(Ft,"text-muted-foreground"),onClick:l,children:"Report issue"}):null;return e.jsxs(ca,{className:t.cn("w-full",h),children:[e.jsxs(da,{className:g,children:[e.jsx("span",{id:j,className:"min-w-0 truncate text-[13px] font-medium text-foreground",children:r}),M||A?e.jsxs(ua,{children:[M,A]}):null]}),e.jsx(As,{text:s,"aria-label":"Copy error message",title:"Copy error message",className:t.cn("max-h-60 overflow-auto",g,o),children:e.jsx("span",{role:"alert","aria-labelledby":j,children:e.jsx("p",{className:"whitespace-pre-wrap break-all text-[12px] leading-[1.55] text-muted-foreground",children:s})})}),x&&N?e.jsx(xa,{debugPayloads:b,className:"mt-2"}):null,n?e.jsx(ha,{sql:n,label:"Failed query",ariaLabel:"Failed SQL query",copyAriaLabel:"Copy failed query",collapsible:!0,defaultOpen:m,headerClassName:g,className:t.cn("mt-1",c&&"min-h-7 flex-1"),bodyClassName:t.cn("max-h-80",c&&"min-h-0 max-h-none flex-1")}):null]})}function cs({className:s,...n}){return e.jsx(pa,{...n,className:t.cn("!pt-0",s)})}function Io(s){const{className:n,...r}=s;return e.jsx(pa,{...r,embedded:!0,className:t.cn("overflow-auto",n)})}function Ls(s,n){const r=t.useEditorStore(x=>x.card),o=t.useEditorStore(x=>x.isDevMode),{switchEditorMode:c,setRunSql:d,runAssistant:i}=t.useEditorActions(),l=()=>{const x=n||r.sql||r.python||"";c("dev",{sqlToLoad:x}),setTimeout(()=>{d(!0)},100)},u=()=>{const x=`Can you help me debug this query?
162
-
163
- Error:
164
-
165
- ${s}
166
-
167
- Error SQL:
168
-
169
- ${n||r.sql||r.python}
170
-
171
- `;i(x)};return{isDevMode:o,handleOpenInEditor:!o&&je.supportsSqlEditor(r.type)?l:void 0,handleDebugWithAssistant:o?u:void 0}}function fa(s,n){const[r,o]=v.useState(!1),c=t.useEditorStore(m=>m.card),d=t.useDashboardStore(m=>m.dashboard.filters),{currentUser:i}=a.useCurrentUserInfo(),{tokenProps:l}=v.useContext(a.SemaphorContext),u=v.useCallback(()=>{o(!0)},[]),x=v.useMemo(()=>{const m=typeof window<"u"?window.location.href:"",b=typeof navigator<"u"?navigator.userAgent:"",h=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:a.FeedbackCategory.QUERY_GENERATION,user:i,tokenContext:l,systemState:{cardConfig:c.config,dataSource:c.dataSource,dashboardFilters:d,errorMessage:s||void 0,errorSql:n||c.sql||c.python,generatedSql:n||c.sql},metadata:{url:m,userAgent:b,timestamp:new Date().toISOString(),viewport:h}}},[i,l,c,d,s,n]);return{feedbackDialogOpen:r,setFeedbackDialogOpen:o,handleSendFeedback:u,feedbackPayload:x}}const Do="__editor_sql__",ko="__editor_python__";function Mo(s){var r;const n=xe.normalizeDashboardCardPythonCode(s.python||"");return{sql:(r=s.sql)!=null&&r.trim()?Do:"",python:n.trim()?ko:""}}function ga({className:s,style:n,...r}){var Z,Re,me,qe,Fe,Ue,we;const o=t.useEditorStore(oe=>oe.card),c=a.useDashboardAppearance(),i=t.useEditorStore(oe=>oe.isDevMode)?!1:((Z=o.customCardPreferences)==null?void 0:Z.showCardHeader)??!0,l=((me=(Re=o.preferences)==null?void 0:Re.displayOptions)==null?void 0:me.showInlineFilterBar)??!0,u=t.useEditorStore(oe=>oe.frame),x=t.useEditorStore(oe=>oe.inlineFilterValuesMap[o.id]),m=t.useDashboardStore(oe=>oe.dashboard.filters),b=t.useDashboardStore(oe=>oe.selectedSheetId),h=t.useEditorStore(oe=>oe.actions.setRunSql),p=t.useEditorStore(oe=>oe.actions.setCardInlineFilterValue),j=t.useEditorStore(oe=>oe.actions.removeCardInlineFilterValue),{updateFilter:N}=t.useDashboardActions(),f=m==null?void 0:m.find(oe=>oe.id===u.filterId),g=v.useMemo(()=>xe.findCustomVisualConfigCard(u,o),[u,o]),{manifest:k}=a.useCustomVisual(((qe=g==null?void 0:g.customCardPreferences)==null?void 0:qe.url)||""),D=v.useMemo(()=>{var oe;return(oe=k==null?void 0:k.visuals)==null?void 0:oe.find(ne=>{var de;return ne.name===((de=g==null?void 0:g.customCardPreferences)==null?void 0:de.componentName)})},[k,(Fe=g==null?void 0:g.customCardPreferences)==null?void 0:Fe.componentName]),w=xe.resolveMultiInputType(g,D),S=v.useMemo(()=>xe.getCustomVisualInputCards({frame:u,configCard:g,isMultiInputVisual:w==="multiple"}),[u,g,w]),M=v.useMemo(()=>{const oe=S.findIndex(ne=>(ne==null?void 0:ne.id)===(o==null?void 0:o.id));return oe<0?-1:xe.getSlotIndexForCard(o,oe)},[S,o]),A=v.useMemo(()=>!g||w!=="multiple"||M<0?o.type:xe.getEffectiveCardTypeForSlot(o,M,D==null?void 0:D.slots)??o.type,[g,w,M,o,D==null?void 0:D.slots]),F=A??o.type,I=v.useMemo(()=>F===o.type?o:{...o,type:F},[o,F]),C=I.type==="table"||I.type==="matrixTable"||I.type==="pivotTable"||I.type==="aggregateTable"||I.type==="detailTable",E=v.useMemo(()=>A!==o.type?{...o,type:A}:o,[o,A]),{data:L,isLoading:T,isFetching:R,errorMessage:y,errorSql:B,pagination:P}=a.useEditorCardQuery(E),O=!!y,{handleOpenInEditor:V,handleDebugWithAssistant:_}=Ls(y,B||o.sql||o.python),{feedbackDialogOpen:z,setFeedbackDialogOpen:q,handleSendFeedback:Y,feedbackPayload:$}=fa(y,B||o.sql||o.python),U=v.useMemo(()=>(L==null?void 0:L.records)||[],[L==null?void 0:L.records]),{setCard:H,updateCardInFrame:te}=t.useEditorActions(),{data:X}=a.useTopoJson(I),se=I.id,ue=I.config,fe=I.interactionConfig,be=I.controls,ge=I.controlBindings,Pe=I.customCfg,Oe=I.preferences,Ae=I.queryConfig,Ie=Mo({sql:I.sql,python:I.python}),_e=Ie.sql,Ye=Ie.python,Ve=L==null?void 0:L.records,Le=v.useMemo(()=>({id:se,type:F,config:ue,interactionConfig:fe,preferences:Oe,controls:be,controlBindings:ge,sql:_e,python:Ye}),[se,F,ue,fe,Oe,be,ge,_e,Ye]),De=v.useMemo(()=>F==="pivotTable"?a.resolvePendingPivotTableResultState({data:L,card:I,isPending:T||R}):{kind:"not_loaded"},[I,F,L,R,T]),ae=a.usePivotTableConfig(I,De,(Ue=L==null?void 0:L.metadata)==null?void 0:Ue.comparisonMetadata),K=(oe,ne)=>{var ve,pe;const de={...o,paginationConfig:{page:oe+1,pageSize:ne}};H(de),te(de),o.sql&&((pe=(ve=o.preferences)==null?void 0:ve.tablePrefs)!=null&&pe.enableDevModePagination)&&h(!0)},ie=oe=>{var ve,pe,Qe,Me,ft;const ne=a.sortStateToSortByColumns(oe,(ve=o.config)==null?void 0:ve.metricColumns,(pe=o.config)==null?void 0:pe.groupByColumns,(Qe=o.config)==null?void 0:Qe.detailColumns),de={...o,config:{...o.config||{},sortByColumns:ne}};H(de),te(de),o.sql&&((ft=(Me=o.preferences)==null?void 0:Me.tablePrefs)!=null&&ft.enableDevModePagination)&&h(!0)},Se=a.useChartNumericPresentation(Le,Ve||void 0),re=v.useMemo(()=>{var oe;return!se||!Ve?null:a.createChartConfig({card:Le,data:Ve,cardType:F,queryConfig:Ae,customCfg:Pe,preferences:Oe,topoJson:X,comparisonMetadata:(oe=L==null?void 0:L.metadata)==null?void 0:oe.comparisonMetadata,numericPresentation:Se,resultColumns:L==null?void 0:L.columns,columnKeyMap:L==null?void 0:L.columnKeyMap})},[Le,se,Pe,Oe,Ae,Ve,L==null?void 0:L.columns,L==null?void 0:L.columnKeyMap,(we=L==null?void 0:L.metadata)==null?void 0:we.comparisonMetadata,F,Se,X]);function he(oe){return e.jsx(a.ErrorBoundary,{FallbackComponent:a.FallbackVisual,children:e.jsx(a.EditorCustomVisual,{card:oe})})}function ze(){var oe;if(I.type==="matrixTable")return e.jsx(a.MatrixCardView,{card:I,frame:u,mode:"editor"});if(L!=null&&L.records&&(L==null?void 0:L.records.length)===0&&!T&&!R&&F!=="pivotTable")return y?e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto",children:e.jsx(cs,{error:y,errorSql:B||o.sql||o.python,onOpenInEditor:V,onDebugWithAssistant:_,onSendFeedback:Y,showFeedbackButton:!0})}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(a.Inbox,{className:"h-8 w-8 text-muted-foreground/40"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"No results to display"})]});if((T||R)&&(!(L!=null&&L.records)||L.records.length===0))return F==="table"||F==="detailTable"?e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(a.TableSkeleton,{})}):e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!I.id)return null;if(F==="custom")return he(o);if(!["table","matrixTable","pivotTable","aggregateTable","detailTable","custom"].includes(F)&&re)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:T||R?e.jsx(e.Fragment,{}):e.jsx(a.ChartJsVisual,{cfg:re})});if(F==="table"||F==="detailTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(a.TableVisual,{card:I,data:U,resultColumns:L==null?void 0:L.columns,columnKeyMap:L==null?void 0:L.columnKeyMap,totalsByColumnId:L==null?void 0:L.tableTotalsByColumnId,comparisonMetadata:(oe=L==null?void 0:L.metadata)==null?void 0:oe.comparisonMetadata,paginationMetadata:P,onPaginationChange:K,onSortChange:ie,isLoading:T||R})});if(F==="pivotTable"&&ae)return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(a.PivotTableTanstack,{card:I,data:ae.data,options:ae.options,onAggregationChange:ne=>{const de=a.handleAggregationChange(ne,o.config),ve={...o,config:de};H(ve),te(ve)},onAggregationLabelChange:ne=>{const de=a.handleAggregationLabelChange(ne,o.config),ve={...o,config:de};H(ve),te(ve)}})});if(F==="aggregateTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(a.AggregateTable,{card:I,data:(L==null?void 0:L.records)||[],resultColumns:L==null?void 0:L.columns,columnKeyMap:L==null?void 0:L.columnKeyMap,groupByColumns:L==null?void 0:L.groupByColumns,pivotSchema:L==null?void 0:L.pivotSchema,paginationMetadata:P,onPaginationChange:K,onAggregationChange:ne=>{const de=a.handleAggregationChange(ne,o.config),ve={...o,config:de};H(ve),te(ve)},isLoading:T||R})})}return e.jsxs(a.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none bg-card text-card-foreground",s),style:{...c.cardFrameStyle,...n},...r,children:[(T||R)&&(L==null?void 0:L.records)&&L.records.length>0&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),i&&e.jsxs(a.CardHeader,{className:t.cn("flex flex-row items-start justify-between gap-4 px-4 pb-3 pt-3"),style:c.cardGutterStyle,children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.CardTitle,{className:"min-w-0 text-[17px] font-semibold leading-tight tracking-[-0.005em]",children:e.jsx(a.EditableText,{value:o.title,onSave:oe=>H({...o,title:oe}),isEditable:!0,placeholder:"Add title",displayClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]",inputClassName:"text-[17px] font-semibold leading-tight tracking-[-0.005em]"})}),e.jsx(a.InfoHover,{card:o}),e.jsx(pt.VisualBadge,{}),e.jsx("div",{className:"ml-auto",children:e.jsx(yo,{})})]}),e.jsx("div",{className:"min-w-0",children:e.jsx(a.EditableText,{value:(o.description||"").trim(),onSave:oe=>H({...o,description:oe.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-[12px] leading-snug text-muted-foreground",inputClassName:"text-[12px] leading-snug"})})]}),f&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Label,{className:"my-1",children:e.jsx(a.EditableText,{value:f.title||f.column,onSave:oe=>N({...f,title:oe}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(a.FilterComponent,{filter:f})]})]}),l&&o.inlineFilters&&o.inlineFilters.length>0&&e.jsx("div",{className:"px-4 pb-2",style:c.cardGutterStyle,children:e.jsx(a.InlineFilterBar,{card:o,sheetId:b||"",inlineFilterValues:x,setInlineFilterValue:oe=>p(o.id,oe),removeInlineFilterValue:oe=>j(o.id,oe)})}),e.jsxs(a.CardContent,{className:t.cn("flex min-h-0 grow flex-col",C?O?"px-4 pb-0 pt-2":"p-0 [&_.data-table-scroll-container]:border-0 [&_.data-table-scroll-container]:bg-transparent":O?"px-4 py-0":"px-4"),style:C&&!O?void 0:c.cardGutterStyle,children:[e.jsx("div",{className:"min-h-0 flex-1 grow basis-0",children:ze()}),a.isCardSummaryVisibleOnCard(I)&&e.jsx("div",{className:t.cn("pt-3",C&&"px-4"),children:e.jsx(a.CardSummary,{card:I,mode:"editor",records:L==null?void 0:L.records})})]}),e.jsx(a.FeedbackDialog,{open:z,onOpenChange:q,feedbackData:$,showDebugInfo:!0})]})}function Bn(s){var n,r;return JSON.stringify({...s,data:{...s.data,datasets:(r=(n=s.data)==null?void 0:n.datasets)==null?void 0:r.map(o=>{const c={...o};return Object.keys(c).forEach(d=>{d.startsWith("semaphor")&&delete c[d]}),{...c,data:[]}})}},null,2)}const gs=({language:s,value:n,onChange:r,readonly:o})=>e.jsx(t.CodeEditor,{className:"h-full w-full text-xs",language:s,value:n,onValueChange:r,readOnly:o,embedded:!0}),Ao=()=>e.jsxs(a.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(a.DialogTitle,{children:"Customize Card"})}),e.jsxs(a.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),Lo=({customCode:s,cardCustomCfgString:n,mergedConfig:r,onConfigChange:o,onCodeChange:c})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(gs,{language:"json",value:r,onChange:o})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(gs,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(gs,{language:"javascript",value:s,onChange:c})})]}),Fo=({error:s,hasCardCustomConfig:n,onReset:r,onApply:o,onClose:c})=>e.jsxs(a.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!n,onClick:r,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:o,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:c,variant:"outline",children:"Close"})]});function Ro({triggerVariant:s="icon",className:n,label:r="Customize Visual"}={}){const[o,c]=v.useState(!1),[d,i]=v.useState(""),[l,u]=v.useState(""),[x,m]=v.useState(""),[b,h]=v.useState(""),p=t.useEditorStore(C=>C.card),j=a.useEffectiveEditorCardType(),N=t.useEditorStore(C=>C.card.customCfg),f=N?JSON.stringify(N,null,2):"",g=v.useMemo(()=>j!==p.type?{...p,type:j}:p,[p,j]),{data:k}=a.useEditorCardQuery(g),{data:D}=a.useTopoJson(p),w=a.useChartNumericPresentation(p,k==null?void 0:k.records),{setCardCustomCfg:S,setCustomVisualCode:M}=t.useEditorActions(),A=()=>{var E,L,T;if(!((E=k==null?void 0:k.records)!=null&&E.length))return;const C=a.createChartConfig({card:p,data:k.records,cardType:p.type,queryConfig:p.queryConfig,preferences:p.preferences,topoJson:D,comparisonMetadata:(L=k==null?void 0:k.metadata)==null?void 0:L.comparisonMetadata,numericPresentation:w,resultColumns:k==null?void 0:k.columns,columnKeyMap:k==null?void 0:k.columnKeyMap});if(C){i(Bn(C)),m(((T=p.preferences)==null?void 0:T.customVisualCode)||"");const R=a.merge(C,N);u(Bn(R))}},F=()=>{try{if(x&&M(x),l){const C=JSON.parse(l),E=wt.getObjectDiff(JSON.parse(d),C);S(E),h("")}}catch{h("Invalid JSON configuration")}},I=Object.keys(N||{}).length===0;return e.jsxs(a.Dialog,{open:o,onOpenChange:c,children:[e.jsx(a.DialogTrigger,{asChild:!0,children:s==="menu"?e.jsxs(t.Button,{variant:"ghost",onClick:A,className:t.cn("h-7 w-full justify-start gap-2 px-2 text-[13px] font-normal",I?"":"text-green-600 hover:text-green-700",n),children:[e.jsx(a.Settings,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:r})]}):e.jsx(a.IconButton,{tooltip:"Customize Visual",onClick:A,className:t.cn(I?"":"text-green-600 hover:text-green-700",n),children:e.jsx(a.Settings,{className:"h-4 w-4"})})}),e.jsxs(a.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Ao,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(a.ErrorBoundary,{FallbackComponent:a.FallbackVisual,children:e.jsx(ga,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Lo,{customCode:x,cardCustomCfgString:f,mergedConfig:l,onConfigChange:C=>u(C??""),onCodeChange:C=>m(C??"")})]}),e.jsx(Fo,{error:b,hasCardCustomConfig:!!N,onReset:()=>{u(d),S(null)},onApply:F,onClose:()=>c(!1)})]})]})}function Po(s){let n=0;for(let o=0;o<s.length;o++)n=s.charCodeAt(o)+((n<<5)-n);return`hsl(${Math.abs(n%360)}, 65%, 45%)`}function Oo(s){const n=s.trim().split(/\s+/);return n.length>1?(n[0][0]+n[1][0]).toUpperCase():s.slice(0,2).toUpperCase()}function Fs({chartType:s,chartName:n,isCustom:r=!1,className:o="h-6 w-6"}){if(!r&&s)return a.getChartIconByType(s,o);const c=a.getAutoDetectedChartIcon(n);if(c)return v.cloneElement(c,{className:o});const d=Oo(n),i=Po(n);return e.jsx("div",{className:t.cn("flex items-center justify-center rounded text-white font-semibold text-xs",o),style:{backgroundColor:i},children:d})}function Vo({isStarred:s,onClick:n,className:r}){const o=c=>{c.stopPropagation(),c.preventDefault(),n(c)};return e.jsx("button",{type:"button",onClick:o,className:t.cn("flex items-center justify-center rounded-control p-0.5 transition-all","hover:bg-muted/80",r),"aria-label":s?"Remove from favorites":"Add to favorites",children:e.jsx(a.Star,{className:t.cn("h-3.5 w-3.5 transition-colors",s?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-foreground")})})}function _n({chartType:s,chartName:n,isCustom:r=!1,pluginName:o,isStarred:c,showStar:d=!0,isSelected:i=!1,onSelect:l,onToggleStar:u}){return e.jsxs("div",{className:"group relative",children:[d&&e.jsx("div",{className:t.cn("absolute left-1 top-1 z-10 transition-opacity",c?"opacity-100":"opacity-0 group-focus-within:opacity-100 group-hover:opacity-100"),children:e.jsx(Vo,{isStarred:c,onClick:()=>u()})}),r&&o&&e.jsx("div",{className:"absolute right-1 top-1 z-10",children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"flex items-center justify-center",children:e.jsx(t.Info,{className:"h-3 w-3 text-muted-foreground"})})}),e.jsx(t.TooltipContent,{side:"top",children:o})]})}),e.jsxs("button",{type:"button",onClick:l,"aria-pressed":i,className:t.cn("flex w-full flex-col items-center justify-center gap-1.5 rounded-control border border-input bg-background px-2 py-2.5 transition-colors","hover:border-foreground/30 hover:bg-muted/40",i&&"border-foreground/50 bg-muted/50 hover:border-foreground/50"),children:[e.jsx(Fs,{chartType:s,chartName:n,isCustom:r,className:"h-4 w-4 text-foreground/80"}),e.jsx("span",{title:n,className:"line-clamp-2 text-center text-[11px] text-foreground/80",children:n})]})]})}function ba(s,n){return s==="matrixTable"?!n.isDevMode:!0}function zt(s,n){return s==="matrixTable"?!1:ba(s,n)}const Bo=[{id:"table",name:"Table"},{id:"bar",name:"Bar Chart"},{id:"line",name:"Line Chart"},{id:"area",name:"Area Chart"},{id:"combo",name:"Combo Chart"},{id:"stackedBar",name:"Stacked Bar"},{id:"stackedArea",name:"Stacked Area"},{id:"stackedLine",name:"Stacked Line"},{id:"scatter",name:"Scatter"},{id:"bubble",name:"Bubble"},{id:"pie",name:"Pie Chart"},{id:"doughnut",name:"Doughnut"},{id:"funnel",name:"Funnel"},{id:"radar",name:"Radar"},{id:"polarArea",name:"Polar Area"},{id:"tornado",name:"Tornado"},{id:"range",name:"Range"},{id:"bullet",name:"Bullet Chart"},{id:"treemap",name:"Treemap"},{id:"heatmap",name:"Heatmap"},{id:"kpi",name:"KPI"},{id:"text",name:"Text"},{id:"map",name:"Map"},{id:"matrixTable",name:"Matrix Table"}];function _o(s){return Bo.filter(n=>ba(n.id,s))}function ja({onChartSelect:s,onClose:n}){const[r,o]=v.useState(""),{starredCharts:c,isStarred:d,toggleStar:i}=a.useStarredChartsStore(),{data:l=[],isLoading:u}=a.useCustomVisualsQuery(),{setCardType:x,setCardPreferences:m,setIsDevMode:b}=t.useEditorStore(E=>E.actions),h=t.useEditorStore(E=>E.card),p=t.useEditorStore(E=>E.isDevMode),{setCardCustomCfg:j,setCustomCardPreferences:N,setVisualizationMode:f,setQueryConfig:g,replaceFrameCards:k,clearModeDrafts:D,initializeModeDrafts:w}=t.useEditorActions(),S=v.useMemo(()=>{const E=_o({isDevMode:p});if(!r)return E;const L=r.toLowerCase();return E.filter(T=>T.name.toLowerCase().includes(L))},[p,r]),M=v.useMemo(()=>{const E=l.filter(T=>T.componentType==="chart"&&T.pluginType!=="standard");if(!r)return E;const L=r.toLowerCase();return E.filter(T=>T.name.toLowerCase().includes(L))},[l,r]),A=E=>{j(null),m({}),f("builtin"),x(E),["custom","text","map"].includes(E)&&(b(!0),g(void 0)),s==null||s(E),n==null||n()},F=E=>{j(null),m({}),f("builtin"),g(void 0);const L=xe.resolveMultiInputTypeFromVisual(E);if(L==="multiple"&&E.slots&&E.slots.length>0){D();const R=xe.createCardsFromSlots(E.slots,E,h);k(R),R[0]&&w(R[0]),n==null||n();return}else x("custom"),N({type:"component",visualType:L,url:E.url,componentName:E.name,icon:E.icon,pluginChartType:E.chartType,minInputs:E.minInputs,maxInputs:E.maxInputs});s==null||s("custom",E),n==null||n()},I=E=>{const L={type:"default",id:E.id,name:E.name};i(L)},C=E=>{const L={type:"custom",id:E.name,url:E.url,icon:E.icon,name:E.name};i(L)};return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"mb-2 flex h-7 items-center gap-1.5 rounded-control border border-input bg-background px-2 focus-within:border-ring",children:[e.jsx(Ke.Search,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Search charts",value:r,onChange:E=>o(E.target.value),className:"h-full w-full bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"})]}),e.jsxs("div",{className:"max-h-[360px] overflow-y-auto pr-1",children:[S.length>0&&e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:S.map(E=>e.jsx(_n,{chartType:E.id,chartName:E.name,isCustom:!1,isStarred:d("default",E.id),onSelect:()=>A(E.id),onToggleStar:()=>I(E)},E.id))}),M.length>0&&e.jsxs(e.Fragment,{children:[S.length>0&&e.jsxs("div",{className:"my-3 flex items-center gap-1.5",children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Custom charts"}),e.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:M.length})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:M.map((E,L)=>e.jsx(_n,{chartName:E.name,isCustom:!0,pluginName:E.pluginName,isStarred:d("custom",E.name),onSelect:()=>F(E),onToggleStar:()=>C(E)},`${E.url}-${E.name}-${L}`))})]}),u&&e.jsx("div",{className:"mt-3 py-4 text-center text-[11px] text-muted-foreground",children:"Loading custom charts…"}),S.length===0&&M.length===0&&!u&&e.jsx("div",{className:"py-8 text-center text-[11px] text-muted-foreground",children:"No charts found"})]})]})}function Yo({selectedChart:s,onChartChange:n}){var M,A,F,I;const r=t.useEditorStore(C=>C.card),o=t.useEditorStore(C=>C.frame),c=t.useEditorStore(C=>C.isDevMode),{replaceFrameCards:d,clearModeDrafts:i,initializeModeDrafts:l,setIsDevMode:u}=t.useEditorActions(),x=v.useMemo(()=>xe.findCustomVisualConfigCard(o,r),[o,r]),{manifest:m}=a.useCustomVisual(((M=x==null?void 0:x.customCardPreferences)==null?void 0:M.url)||""),b=v.useMemo(()=>{var C;return(C=m==null?void 0:m.visuals)==null?void 0:C.find(E=>{var L;return E.name===((L=x==null?void 0:x.customCardPreferences)==null?void 0:L.componentName)})},[m,(A=x==null?void 0:x.customCardPreferences)==null?void 0:A.componentName]),h=xe.resolveMultiInputType(x,b)==="multiple",p=a.useEffectiveEditorCardType(),j=h?p:s??r.type,N=(F=r==null?void 0:r.customCardPreferences)==null?void 0:F.componentName,f=(I=x==null?void 0:x.customCardPreferences)==null?void 0:I.componentName,g=h&&!!f,k=v.useMemo(()=>{const C=a.chartTypes.find(E=>E.id===j);return C?C.label:j==="custom"?N||"Custom Visual":"Select chart type"},[j,N]),D=v.useMemo(()=>{const C=a.chartTypes.find(E=>E.id===j);if(C){const E=C.icon;return e.jsx(E,{className:"h-4 w-4"})}if(j==="custom"&&N){const E=a.getAutoDetectedChartIcon(N);return E||e.jsx(Fs,{chartName:N,isCustom:!0,className:"h-4 w-4"})}return e.jsx(Fr,{className:"h-4 w-4"})},[j,N]);return{displayChartType:j,displayLabel:k,displayIcon:D,showBadge:g,badgeLabel:f,isMultiInputContext:h,handleChartSelect:C=>{n==null||n(C)},handleClearCustomVisual:C=>{C.stopPropagation();const E={...r,type:"bar",sql:"",python:"",config:void 0,queryConfig:void 0,customCfg:void 0,preferences:{},customCardPreferences:void 0,title:"Chart",tabTitle:"Chart",description:void 0,info:void 0};d([E]),i(),l(E),c&&u(!0),n==null||n("bar")}}}function zo({selectedChart:s,onChartChange:n,variant:r="ghost",className:o}){const[c,d]=v.useState(!1),{displayLabel:i,displayIcon:l,showBadge:u,badgeLabel:x,handleChartSelect:m,handleClearCustomVisual:b}=Yo({selectedChart:s,onChartChange:n}),h=r==="header";return e.jsxs("div",{className:t.cn("relative w-full",o),children:[e.jsxs(t.Popover,{open:c,onOpenChange:d,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:h?e.jsxs("button",{type:"button",role:"combobox","aria-expanded":c,className:"flex h-9 w-full items-center justify-between gap-2 border-b border-border bg-card px-3 text-left transition-colors hover:bg-muted/50 focus:outline-none focus-visible:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[l,e.jsx("span",{className:"truncate text-[12px] font-medium text-foreground",children:i})]}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}):e.jsxs(t.Button,{size:"xs",variant:r,role:"combobox","aria-expanded":c,className:t.cn("w-full justify-between gap-2",r==="ghost"&&"border border-border/70 bg-background text-foreground/90",r==="outline"&&"border-border/70 bg-background text-foreground/90",r==="secondary"&&"text-foreground"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[l,e.jsx("span",{className:"truncate",children:i})]}),e.jsx(le.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-70"})]})}),e.jsx(t.PopoverContent,{className:"w-[360px] p-3",align:"start",onOpenAutoFocus:p=>p.preventDefault(),children:e.jsx(ja,{onChartSelect:p=>m(p),onClose:()=>d(!1)})})]}),u&&e.jsxs("div",{className:"absolute right-10 top-1/2 z-10 flex max-w-[140px] -translate-y-1/2 items-center gap-1 rounded-full border bg-background py-0.5 pl-2 pr-1 text-[10px] text-muted-foreground shadow-sm",title:x,children:[e.jsx(a.Layers,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate",children:x}),e.jsx("button",{onClick:b,className:"rounded-full p-0.5 hover:bg-muted",title:"Clear custom visual",children:e.jsx(le.X,{className:"h-2.5 w-2.5"})})]})]})}const Lt={table:t.Table2,matrixTable:a.Grid3x3,bar:a.ChartColumnIncreasing,line:a.ChartLine,stackedBar:a.ChartColumnStacked,stackedLine:a.MdStackedLineChart,scatter:a.ChartScatter,bubble:a.TbChartBubble,pie:a.ChartPie,doughnut:a.Donut,kpi:a.TiSortNumerically,treemap:a.TbChartTreemap,bullet:a.BulletChartIcon,funnel:a.TbChartFunnel,tornado:a.Tornado,heatmap:a.Grid3x3,range:a.ChartNoAxesGantt,radar:a.Radar,polarArea:a.PiChartPolar,text:a.BookType,map:a.Map},qt={table:"Table",matrixTable:"Matrix Table",bar:"Bar Chart",line:"Line Chart",stackedBar:"Stacked Bar",stackedLine:"Stacked Line",scatter:"Scatter",bubble:"Bubble",pie:"Pie Chart",doughnut:"Donut",kpi:"KPI",treemap:"Treemap",bullet:"Bullet",funnel:"Funnel",tornado:"Tornado",heatmap:"Heatmap",range:"Range",radar:"Radar",polarArea:"Polar Area",text:"Text",map:"Map"},va=[{id:"table"},{id:"bar"},{id:"line"},{id:"pie"},{id:"kpi"},{id:"doughnut"}],ya=6;function qo({selectedChart:s,onChartChange:n}){var D,w;const[r,o]=v.useState(!1),c=t.useEditorStore(S=>S.card),{setCardType:d,setCardPreferences:i}=t.useEditorStore(S=>S.actions),{setCardCustomCfg:l,setCustomCardPreferences:u,setQueryConfig:x,replaceFrameCards:m,clearModeDrafts:b,initializeModeDrafts:h}=t.useEditorActions(),{starredCharts:p}=a.useStarredChartsStore(),{data:j=[]}=a.useCustomVisualsQuery(),N=t.useEditorStore(S=>S.isDevMode),f=v.useMemo(()=>{const S=p.filter(I=>I.type==="default"?zt(I.id,{isDevMode:N}):j.some(C=>C.name===I.id)),M=new Set(S.map(I=>I.id)),A=va.filter(I=>!M.has(I.id)&&zt(I.id,{isDevMode:N}));return[...S.map(I=>({id:I.id,label:I.name,icon:I.type==="default"?Lt[I.id]:void 0,isCustom:I.type==="custom",url:I.url})),...A.map(I=>({id:I.id,label:qt[I.id]??I.id,icon:Lt[I.id],isCustom:!1}))].slice(0,ya)},[p,j,N]),g=s==="custom"&&((D=c==null?void 0:c.customCardPreferences)==null?void 0:D.componentName);return f.some(S=>{var M;return S.isCustom?g&&((M=c==null?void 0:c.customCardPreferences)==null?void 0:M.componentName)===S.id:s===S.id})||(s==="custom"?(w=c==null?void 0:c.customCardPreferences)!=null&&w.componentName:qt[s]),e.jsxs("div",{className:"px-4 pb-3 pt-4",children:[e.jsx("p",{className:"pb-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Chart type"}),e.jsx(Ca,{selectedChart:s,onChartChange:n,compactMore:!0})]})}function Ca({selectedChart:s,onChartChange:n,compactMore:r=!1,responsiveCompact:o=!1}){var F,I;const[c,d]=v.useState(!1),i=t.useEditorStore(C=>C.card),{setCardType:l,setCardPreferences:u}=t.useEditorStore(C=>C.actions),{setCardCustomCfg:x,setCustomCardPreferences:m,setQueryConfig:b,replaceFrameCards:h,clearModeDrafts:p,initializeModeDrafts:j}=t.useEditorActions(),{starredCharts:N}=a.useStarredChartsStore(),{data:f=[]}=a.useCustomVisualsQuery(),g=t.useEditorStore(C=>C.isDevMode),k=((F=i==null?void 0:i.customCardPreferences)==null?void 0:F.componentName)??null,D=v.useMemo(()=>{const C=N.filter(y=>y.type==="default"?zt(y.id,{isDevMode:g}):f.some(B=>B.name===y.id)),E=new Set(C.map(y=>y.id)),L=va.filter(y=>!E.has(y.id)&&zt(y.id,{isDevMode:g})),T=[...C.map(y=>({id:y.id,label:y.name,icon:y.type==="default"?Lt[y.id]:void 0,isCustom:y.type==="custom",url:y.url})),...L.map(y=>({id:y.id,label:qt[y.id]??y.id,icon:Lt[y.id],isCustom:!1}))];if(!T.some(y=>y.isCustom?s==="custom"&&y.id===k:y.id===s))if(s==="custom"&&k){const y=f.find(B=>B.name===k);y&&T.unshift({id:y.name,label:y.name,icon:void 0,isCustom:!0,url:y.url})}else s&&Lt[s]&&zt(s,{isDevMode:g})&&T.unshift({id:s,label:qt[s]??s,icon:Lt[s],isCustom:!1});return T.slice(0,ya)},[N,f,s,k,g]),w=s==="custom"&&k,S=C=>{if(C.isCustom){const E=f.find(R=>R.name===C.id);if(!E)return;x(null),u({}),b(void 0);const L=xe.resolveMultiInputTypeFromVisual(E);if(L==="multiple"&&E.slots&&E.slots.length>0){p();const R=xe.createCardsFromSlots(E.slots,E,i);h(R),R[0]&&j(R[0]);return}l("custom"),m({type:"component",visualType:L,url:E.url,componentName:E.name,icon:E.icon,pluginChartType:E.chartType,minInputs:E.minInputs,maxInputs:E.maxInputs}),n("custom");return}n(C.id)},M=D.some(C=>{var E;return C.isCustom?w&&((E=i==null?void 0:i.customCardPreferences)==null?void 0:E.componentName)===C.id:s===C.id}),A=M?"More":s==="custom"?((I=i==null?void 0:i.customCardPreferences)==null?void 0:I.componentName)||"Custom":qt[s]||"More";return e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"inline-flex h-7 items-center overflow-hidden rounded-control border border-input bg-background",children:[D.map(C=>{var T;const E=C.icon,L=C.isCustom?w&&((T=i==null?void 0:i.customCardPreferences)==null?void 0:T.componentName)===C.id:s===C.id;return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:()=>S(C),"aria-label":C.label,"aria-pressed":!!L,className:t.cn("flex h-full w-7 items-center justify-center text-foreground/65 transition-colors hover:bg-muted/50 hover:text-foreground",o&&!L&&"hidden @[800px]:flex",L&&"bg-foreground/[0.08] font-medium text-foreground"),children:[E?e.jsx(E,{className:"h-3.5 w-3.5"}):e.jsx(Fs,{chartName:C.label,isCustom:!0,className:"h-3.5 w-3.5"}),e.jsx("span",{className:"sr-only",children:C.label})]})}),e.jsx(t.TooltipContent,{side:"bottom",children:C.label})]},`${C.isCustom?"custom":"default"}-${C.id}`)}),e.jsxs(t.Popover,{open:c,onOpenChange:d,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs("button",{type:"button","aria-label":r?"More chart types":A,className:t.cn("inline-flex h-full items-center gap-1 border-l border-input transition-colors hover:bg-muted/50",r?"w-7 justify-center":"px-2 text-[12px]",!r&&(M?"text-muted-foreground":"text-foreground")),children:[!r&&e.jsx("span",{className:"truncate",children:A}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180"),strokeWidth:1.75})]})}),e.jsx(t.PopoverContent,{className:"w-[360px] p-3",align:"end",onOpenAutoFocus:C=>C.preventDefault(),children:e.jsx(ja,{onChartSelect:C=>{n(C),d(!1)},onClose:()=>d(!1)})})]})]})})}function $o(){const s=t.useEditorStore(u=>{var x,m;return(m=(x=u.card.preferences)==null?void 0:x.chartOptions)==null?void 0:m.indexAxis}),n=t.useEditorStore(u=>u.card.type),{setChartOrientation:r,setCardPreferences:o}=t.useEditorStore(u=>u.actions),c=u=>{if(r(u),n!=="bullet")return;const x=u==="y"?"horizontal":"vertical",m=t.useEditorStore.getState().card.preferences,b={...m||{},bulletConfig:{...(m==null?void 0:m.bulletConfig)||{},orientation:x}};o(b)};function d(){const u=s??"x",x=()=>{c(u==="x"?"y":"x")};return e.jsx(a.IconButton,{onClick:x,tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:u==="x"?e.jsx(ps,{className:"h-3.5 w-3.5"}):e.jsx(hs,{className:"h-3.5 w-3.5"})})}function i(){const u=()=>{c(s==="y"||s===void 0?"x":"y")};return e.jsx(a.IconButton,{onClick:u,tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:s==="y"||s===void 0?e.jsx(ps,{className:"h-3.5 w-3.5"}):e.jsx(hs,{className:"h-3.5 w-3.5"})})}function l(){const u=s??"y",x=()=>{c(u==="y"?"x":"y")};return e.jsx(a.IconButton,{onClick:x,tooltip:"Chart Orientation",className:"h-7 w-7 px-0",children:u==="y"?e.jsx(hs,{className:"h-3.5 w-3.5"}):e.jsx(ps,{className:"h-3.5 w-3.5"})})}return e.jsx(e.Fragment,{children:n==="funnel"?i():n==="bullet"?l():d()})}function Rs({className:s,triggerVariant:n="icon",label:r="Display options"}){var f,g,k,D,w,S,M,A,F,I;const o=t.useEditorStore(C=>C.card),{setCardPreferences:c,updateCardInFrame:d,setCard:i}=t.useEditorActions(),[l,u]=v.useState(!1),x=((g=(f=o.preferences)==null?void 0:f.displayOptions)==null?void 0:g.showFilterInfo)??!0,m=((D=(k=o.preferences)==null?void 0:k.displayOptions)==null?void 0:D.showCardToolbar)??!0,b=((S=(w=o.preferences)==null?void 0:w.displayOptions)==null?void 0:S.showChrome)??!0,h=((A=(M=o.preferences)==null?void 0:M.displayOptions)==null?void 0:A.allowScroll)??!0,p=((I=(F=o.preferences)==null?void 0:F.displayOptions)==null?void 0:I.showInlineFilterBar)??!0,j=(C,E)=>{var R;const L={...o.preferences,displayOptions:{...(R=o.preferences)==null?void 0:R.displayOptions,[C]:E}};c(L);const T={...o,preferences:L};i(T),d(T)},N=[{option:"showFilterInfo",label:"Filter info",hint:"Badge",checked:x},{option:"showCardToolbar",label:"Card toolbar",hint:"Hover actions",checked:m},{option:"showChrome",label:"Card chrome",hint:"Frame and padding",checked:b},{option:"allowScroll",label:"Allow scroll",hint:"Content scroll",checked:h},{option:"showInlineFilterBar",label:"Inline filter bar",hint:"On-card filters",checked:p}];return e.jsx("div",{className:t.cn("flex items-center",s),children:e.jsxs(a.DropdownMenu,{modal:!1,open:l,onOpenChange:u,children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:n==="menu"?e.jsxs(t.Button,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[e.jsx(Ke.Eye,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{children:r})]}):e.jsx(a.IconButton,{className:"h-7 w-7 p-0",tooltip:"Display Options",children:e.jsx(t.SlidersHorizontal,{className:"h-3.5 w-3.5"})})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx("p",{className:"px-2 pb-1.5 pt-1 text-[11px] text-muted-foreground",children:"Changes apply to dashboard view only"}),N.map(C=>e.jsxs(a.DropdownMenuCheckboxItem,{checked:C.checked,onCheckedChange:E=>j(C.option,E),onSelect:E=>E.preventDefault(),className:"[&_svg]:h-3.5 [&_svg]:w-3.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate",children:C.label}),e.jsx("span",{className:"ml-3 shrink-0 text-[11px] text-muted-foreground",children:C.hint})]},C.option))]})]})})}function Na(s,n){var u,x;const r=s.qualifiedFieldName||s.name,o=s.qualifiedFieldName?s.qualifiedFieldName.split(".").slice(0,-1).join("."):s.qualifiedEntityName||s.entityName,c=n.connectionId||((u=n.dataSource)==null?void 0:u.connectionId)||"",d=a.buildFilterFieldMeta(s),i=a.buildFilterSemanticContext(n.dataSource,{connectionId:c,connectionType:(x=n.dataSource)==null?void 0:x.connectionType},s),l=a.getFilterSourceDatabase(n.dataSource,i,s)||"";return{column:r,title:a.getFieldDisplayLabel(s),dataType:s.dataType,...s.nativeDataType?{nativeDataType:s.nativeDataType}:{},table:s.entityName||"",database:l,qualifiedTableName:o,connectionId:c,operation:"in",sql:"",fieldMeta:d,semanticContext:i}}function Ps({className:s,triggerVariant:n="icon",label:r="Inline filters"}){const[o,c]=v.useState(!1),d=t.useEditorStore(S=>S.card),i=t.useEditorStore(S=>S.selectedConnectionId),{tokenProps:l}=a.useSemaphorContext(),{setCard:u}=t.useEditorActions(),x=t.useDashboardStore(S=>S.actions.removeCardInlineFilterValue),m=t.useDashboardStore(S=>S.actions.setCardInlineFilterValue),b=t.useEditorStore(S=>S.actions.removeCardInlineFilterValue),h=t.useEditorStore(S=>S.actions.setCardInlineFilterValue),p=t.useDashboardStore(S=>S.isVisualEditing),j=(d==null?void 0:d.inlineFilters)||[],N=a.useTimezone()??void 0;function f(S){if(j.find(F=>a.doesStoredFilterMatchField(F,S)))return;const A={id:je.v4(),...Na(S,{dataSource:d==null?void 0:d.dataSource,connectionId:i}),width:250};u({...d,inlineFilters:[...j,A]})}function g(S){const M=j.filter(A=>A.id!==S);u({...d,inlineFilters:M}),p?b(d.id,S):x(d.id,S)}function k(S,M){const A=j.map(E=>E.id===S?{...E,...M}:E);if(u({...d,inlineFilters:A}),!(Object.prototype.hasOwnProperty.call(M,"defaultValues")||Object.prototype.hasOwnProperty.call(M,"defaultDateFilter")))return;const I=A.find(E=>E.id===S);if(!I)return;const C=t.buildFilterValueFromDefaults(I,N);C?p?h(d.id,C):m(d.id,C):p?b(d.id,S):x(d.id,S)}if(!["bar","line","pie","doughnut","table","detailTable","stackedBar","stackedLine","horizontalBar","radar","polarArea","scatter","bubble","funnel","aggregateTable","custom"].includes(d==null?void 0:d.type))return null;const w=n==="menu";return e.jsx("div",{className:t.cn("flex items-center gap-1",w&&"w-full",s),children:e.jsxs(t.Popover,{open:o,onOpenChange:c,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:w?e.jsxs(t.Button,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[e.jsx(Dn,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{children:r}),j.length>0&&e.jsx("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:j.length})]}):e.jsxs(a.IconButton,{tooltip:"Add Inline Filter",className:t.cn("relative h-7 w-7 px-0",{"text-primary":j.length>0}),children:[e.jsx(Dn,{className:"h-3.5 w-3.5"}),j.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] font-medium text-primary-foreground",children:j.length})]})}),e.jsx(t.PopoverContent,{align:"end",className:t.cn("w-80 p-0",w&&"z-[60]"),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"border-b px-4 py-3",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Inline Filters"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"On-card filters for fast, focused exploration."})]}),e.jsx("div",{className:"flex h-[320px] min-h-0 flex-col overflow-hidden",children:e.jsx(a.DndContext,{collisionDetection:a.closestCenter,children:e.jsx(a.SortableContext,{items:[],strategy:a.verticalListSortingStrategy,children:e.jsx(a.FieldsList,{context:"inline-filter",onFieldSelect:f,inlineFilters:j})})})}),j.length>0&&e.jsxs("div",{className:"border-t px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Active Filters"}),e.jsx("div",{className:"space-y-1",children:j.map(S=>e.jsx(Ko,{filter:S,onUpdate:M=>k(S.id,M),onRemove:()=>g(S.id)},S.id))})]})]})})]})})}function Ko({filter:s,onUpdate:n,onRemove:r}){return e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-muted px-2 py-1.5 text-sm",children:[e.jsx("span",{className:"truncate",title:s.column,children:s.title}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(a.CustomFilterPopover,{filter:s,variant:"inline",onAccept:o=>n(o),trigger:e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",title:"Configure filter",children:e.jsx(a.Settings2,{className:"h-3 w-3"})})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 hover:bg-destructive/10 hover:text-destructive",onClick:r,children:e.jsx(le.X,{className:"h-3 w-3"})})]})]})}const Uo={metric_selector:"Displayed metric",field_selector:"Group by field",aggregation_selector:"Aggregation",grain_selector:"Time grain"};function Go(s,n){return s&&typeof s=="object"&&"label"in s&&typeof s.label=="string"&&s.label.trim().length>0?s.label:n||null}const Ho={metric_selector:"config_metric_selector",field_selector:"config_field_selector",aggregation_selector:"config_aggregation",grain_selector:"config_grain"};function ls(s,n){return`${s}:${n}`}function Qo(s,n,r,o,c){const d=new Set(r.filter(l=>l.target!=="sql_param"&&l.target!=="presentation_currency").map(l=>ls(l.controlId,l.target))),i=n.map(l=>{const u=t.getCompatibleBindingTargetOptions({card:s,control:l,matrixSpec:o,resolveDataType:c}).map(h=>h.value),x=Ho[l.type],b=[...x&&u.includes(x)?[x]:[],...u.filter(h=>h!==x)].find(h=>!d.has(ls(l.id,h)));return b?{controlId:l.id,target:b}:null}).find(Boolean);return i?{controlId:i.controlId,target:i.target,mapping:{}}:null}function Jo({card:s,dashboardControls:n,bindings:r,onChange:o,availableFieldChoices:c,matrixFieldCatalog:d=[],availableMetricChoices:i,suppressTransientStaleState:l=!1,matrixSpec:u,matrixPresentation:x}){const m=v.useMemo(()=>x??(u?ht.createMatrixConfig(u).presentation:void 0),[u,x]);function b(I){return!u||!m?[]:wt.getMatrixBindingTargets(u,I,f).map(C=>({id:C.id,label:C.kind==="measure"?`${ht.getMatrixMeasureLabel(C.measure,m)} (${C.measure.aggregate})`:`${C.axis==="rows"?"Rows":"Columns"}: ${ht.getMatrixLevelLabel(C.level,m)}`}))}const h=[...n,...s.controls||[]],[p,j]=v.useState({}),N=wt.extractSqlParamReferences({sql:s.sql,controlBindings:s.controlBindings});function f(I){return u?je.matrixAuthoringDataType(I,u.source,d):I.dataType}const g=t.getBindingTargetSuggestions(s,u,f),k=new Set(r.map(I=>ls(I.controlId,I.target))),D=h.some(I=>t.getCompatibleBindingTargetOptions({card:s,control:I,matrixSpec:u,resolveDataType:f}).some(C=>!k.has(ls(I.id,C.value)))),w=l?0:r.reduce((I,C)=>{const E=S(C.target),L=Object.values(C.mapping).filter(T=>{const R=C.target==="config_metric_selector"||C.target==="config_field_selector"?typeof T=="string"?T:T==null?void 0:T.id:typeof T=="string"?T:void 0;return typeof R=="string"&&!E.some(y=>y.value===R)}).length;return I+L},0);function S(I){var C,E,L,T;switch(I){case"config_metric_selector":return i?i.filter(R=>!!R.target).map(R=>({value:R.target.id,label:R.target.label||R.option.label,target:R.target})):u&&m?b(I).map(R=>({value:R.id,label:R.label,target:{kind:"matrix_instance",id:R.id}})):((E=(C=s.config)==null?void 0:C.metricColumns)==null?void 0:E.map(R=>({value:R.id,label:R.label||R.id,target:R})))||[];case"config_field_selector":return c?c.filter(R=>!!R.target).map(R=>({value:R.target.id,label:R.target.label||R.option.label,target:R.target})):u&&m?b(I).map(R=>({value:R.id,label:R.label,target:{kind:"matrix_instance",id:R.id}})):((T=(L=s.config)==null?void 0:L.groupByColumns)==null?void 0:T.map(R=>({value:R.id,label:R.label||R.id,target:R})))||[];case"config_aggregation":return(g.config_aggregation||[]).map(R=>({value:R,label:R}));case"config_grain":return(g.config_grain||[]).map(R=>({value:R,label:R.charAt(0).toUpperCase()+R.slice(1)}));default:return[]}}const M=(I,C)=>{o(r.map((E,L)=>L!==I?E:C(E)))},A=I=>{o(r.filter((C,E)=>E!==I))},F=()=>{const I=Qo(s,h,r,u,f);I&&o([...r,I])};if(typeof s.sql=="string"&&s.sql.trim().length>0){const I=N.map(({controlId:C,paramId:E})=>{const L=h.find(T=>T.id===C);return L?{id:C,paramId:E,label:L.label,reference:`[[param.${E}]]`}:{id:C,paramId:E,label:C,reference:`[[param.${E}]]`}});return e.jsx("div",{className:"space-y-2",children:I.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"This card is currently using raw SQL. Reference a control directly in the SQL editor with syntax like `[[param.metric]]`."}):I.map(C=>e.jsx("div",{className:"rounded-md border p-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:C.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Referenced in SQL"})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted/40 px-2 py-1",children:[e.jsx("code",{className:"text-xs",children:C.reference}),e.jsx(a.CopyButton,{text:C.reference,ariaLabel:`Copy ${C.reference}`})]})]})},`${C.id}:${C.paramId}`))})}return e.jsxs("div",{className:"space-y-4",children:[w>0?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950",children:[e.jsx(a.CircleAlert,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("span",{children:[w," ",w===1?"mapping needs":"mappings need"," attention before save. Replace each missing target or choose Not mapped."]})]}):null,r.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"This card is not using any controls yet."}):r.map((I,C)=>{const E=g[I.target]||[],L=h.find(Y=>Y.id===I.controlId),T=L?t.ensureManualSource(L):null,R=(T==null?void 0:T.source.kind)==="manual"?T.source.options:[],y=S(I.target),B=b(I.target),P=I.matrixTargetId!==void 0&&!B.some(Y=>Y.id===I.matrixTargetId),O=Array.from(new Set([...R.map(Y=>Y.value),...Object.keys(I.mapping)])).map(Y=>{const $=R.find(U=>U.value===Y);return{value:Y,label:($==null?void 0:$.label)||Y}}),V=`${I.controlId}-${I.target}-${C}`,_=p[V]??C===0,z=Object.keys(I.mapping).length,q=L!=null&&L.type?Uo[L.type]||L.type:null;return e.jsxs(a.Collapsible,{open:_,onOpenChange:Y=>j($=>({...$,[V]:Y})),className:"rounded-md border",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 p-3",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 text-left",children:[_?e.jsx(le.ChevronDown,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(Ke.ChevronRight,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:(L==null?void 0:L.label)||"Control"}),q?e.jsx(a.Badge,{variant:"secondary",className:"shrink-0 text-[11px] font-normal text-muted-foreground",children:q}):null]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:z>0?`${z} mapped`:"No mappings yet"})]})]})}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>A(C),children:e.jsx(a.Trash2,{className:"h-4 w-4"})})]}),e.jsxs(a.CollapsibleContent,{className:"space-y-3 border-t px-3 pb-3 pt-2",children:[u?e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",htmlFor:`matrix-target-${V}`,children:"Matrix target"}),e.jsxs(t.Select,{value:I.matrixTargetId??"__none__",onValueChange:Y=>M(C,$=>{const{matrixTargetId:U,...H}=$;return Y==="__none__"?H:{...H,matrixTargetId:Y}}),children:[e.jsx(t.SelectTrigger,{id:`matrix-target-${V}`,"aria-label":"Matrix target",children:e.jsx(t.SelectValue,{placeholder:"Choose target"})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"__none__",children:B.length===1?`Automatic: ${B[0].label}`:"Choose target"}),P?e.jsx(t.SelectItem,{value:I.matrixTargetId,disabled:!0,children:"Missing target"}):null,B.map(Y=>e.jsx(t.SelectItem,{value:Y.id,children:Y.label},Y.id))]})]}),P?e.jsx("p",{role:"alert",className:"text-xs text-amber-700",children:"The saved Matrix target is no longer available."}):B.length===0?e.jsx("p",{role:"alert",className:"text-xs text-muted-foreground",children:"No eligible Matrix target."}):!I.matrixTargetId&&B.length>1?e.jsx("p",{role:"alert",className:"text-xs text-amber-700",children:"Select a Matrix target."}):null]}):null,O.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"Add choices to this control first so you can decide what each choice changes in the card."}):y.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"No matching targets are available for this binding yet."}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs",children:"Map each choice"}),e.jsx("div",{className:"space-y-2",children:O.map(Y=>{const $=I.mapping[Y.value],U=I.target==="config_metric_selector"||I.target==="config_field_selector"?typeof $=="string"?$:$==null?void 0:$.id:typeof $=="string"?$:void 0,H=!l&&typeof U=="string"&&!y.some(se=>se.value===U),te=Go($,U),X=U&&H?[...y,{value:U,label:"Needs remap",target:$}]:y;return e.jsxs("div",{className:"grid gap-2 rounded-md border p-2 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-[11px] text-muted-foreground",children:"Viewer picks"}),e.jsx("div",{className:"rounded-md bg-muted/50 px-3 py-2 text-sm",children:Y.label})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-[11px] text-muted-foreground",children:"Switch to"}),e.jsxs(t.Select,{value:U||"__none__",onValueChange:se=>M(C,ue=>{if(ue.target==="config_metric_selector"){const be={...ue.mapping};if(se==="__none__")delete be[Y.value];else{const ge=X.find(Pe=>Pe.value===se);ge!=null&&ge.target?be[Y.value]=ge.target:delete be[Y.value]}return{...ue,mapping:be}}if(ue.target==="config_field_selector"){const be={...ue.mapping};if(se==="__none__")delete be[Y.value];else{const ge=X.find(Pe=>Pe.value===se);ge!=null&&ge.target?be[Y.value]=ge.target:delete be[Y.value]}return{...ue,mapping:be}}const fe={...ue.mapping};return se==="__none__"?delete fe[Y.value]:fe[Y.value]=se,{...ue,mapping:fe}}),children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Choose what this should use"})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"__none__",children:"Not mapped"}),X.map(se=>e.jsx(t.SelectItem,{value:se.value,children:se.label},se.value))]})]}),H?e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-amber-700",children:[e.jsx(a.CircleAlert,{className:"h-3 w-3 shrink-0"}),e.jsxs("span",{children:["Needs remap",te?` · Previously: ${te}`:""]})]}):null]})]},`${I.controlId}-${I.target}-${Y.value}`)})}),E.length>0&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Available choices for this card: ",E.join(", ")]})]})]})]},V)}),D?e.jsxs(t.Button,{type:"button",variant:"outline",size:"sm",onClick:F,children:[e.jsx(a.Plus,{className:"mr-2 h-4 w-4"}),"Add another control response"]}):null]})}function Wo(s,n,r){const{eligibleTargets:o}=a.getCardCurrencyPresentationTargets(s,n,r),c=a.getCardCurrencyPresentationFields(s),d=new Map(c.map(l=>[l.id,l])),i=new Map(a.resolveMatrixCardMeasures(s,r).map(l=>[l.measureId,l.label]));return o.map(l=>{var u;return{key:a.currencyPresentationTargetKey(l),label:l.kind==="metric"?((u=d.get(l.metricId))==null?void 0:u.label)||l.metricId:l.kind==="column"?l.columnKey:i.get(l.measureId)||l.measureId,target:l}})}function Xo(s){return s?s.kind==="metric"?s.metricId:s.kind==="column"?s.columnKey:s.measureId:"invalid target"}function Zo({matrixCatalog:s,card:n,dashboardControls:r,resultColumnKeys:o=[],bindings:c,onChange:d}){const i=[...r,...n.controls||[]],l=i.filter(a.isCurrencyPresentationControl),u=v.useMemo(()=>Wo(n,o,s),[n,o,s]),x=v.useMemo(()=>a.getCardCurrencyPresentationTargets(n,o,s),[n,o,s]),m=a.diagnoseCurrencyPresentationBindings({bindings:c,controls:i,...x}),{preferences:b,resolveBoundCurrency:h}=a.useCardNumericPresentation(n,o,s),[p,j]=v.useState(""),[N,f]=v.useState(""),g=u.find(w=>w.key===N),k=!!(p&&g)&&!c.some(w=>w.presentationTarget&&g&&a.currencyPresentationTargetKey(w.presentationTarget)===g.key),D=w=>{if(!b)return;const S=a.resolveCurrencyPresentationTargetFormat({card:n,target:w,resultColumnKeys:o,valueFormatPreferences:b,boundCurrency:h(w),matrixCatalog:s});if(S)return sa.formatNumericCanonical(1e3,S)};return l.length===0&&c.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a manual enum whose options are ISO currency codes to enable presentation currency bindings."}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h5",{className:"text-xs font-medium",children:"Currency presentation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Change only the display currency for an explicit metric or column."})]}),c.map((w,S)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-control border border-border/60 px-2 py-1.5 text-xs",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[w.controlId," →"," ",Xo(w.presentationTarget),w.presentationTarget?` · ${D(w.presentationTarget)??"unavailable"}`:null]}),e.jsx(t.Button,{variant:"ghost",size:"xs",onClick:()=>d(c.filter((M,A)=>A!==S)),children:e.jsx(a.Trash2,{className:"h-3.5 w-3.5"})})]},`${w.controlId}:${JSON.stringify(w.presentationTarget)}`)),m.length>0?e.jsx("div",{className:"space-y-1 text-xs text-destructive",children:m.map((w,S)=>e.jsxs("p",{children:[w.controlId?`${w.controlId}: `:"",w.code.split("_").join(" ")]},`${w.controlId||"binding"}:${w.code}:${S}`))}):null,e.jsxs("div",{className:"grid grid-cols-[1fr_1fr_auto] gap-2",children:[e.jsxs(t.Select,{value:p,onValueChange:j,children:[e.jsx(t.SelectTrigger,{size:"xs",children:e.jsx(t.SelectValue,{placeholder:"Currency control"})}),e.jsx(t.SelectContent,{children:l.map(w=>e.jsx(t.SelectItem,{value:w.id,children:w.label},w.id))})]}),e.jsxs(t.Select,{value:N,onValueChange:f,children:[e.jsx(t.SelectTrigger,{size:"xs",children:e.jsx(t.SelectValue,{placeholder:"Target"})}),e.jsx(t.SelectContent,{children:u.map(w=>e.jsx(t.SelectItem,{value:w.key,children:w.label},w.key))})]}),e.jsx(t.Button,{variant:"outline",size:"xs",disabled:!k,onClick:()=>{g&&(d([...c,{controlId:p,target:"presentation_currency",presentationTarget:g.target}]),f(""))},children:e.jsx(a.Plus,{className:"h-3.5 w-3.5"})})]})]})}const el=[];function Os({className:s,triggerVariant:n="icon",label:r="Controls"}){var V,_,z;const{handleOpenChange:o,preventPassiveDismissDuringCreate:c,resolvedOpen:d,setIsCreateFlowActive:i}=pt.useCreateFlowOverlayState({}),l=t.useEditorStore(q=>q.card),u=t.useEditorStore(q=>q.frame),x=t.useEditorStore(q=>q.queryResultColumns),m=t.useDashboardStore(q=>q.dashboard),h=t.useDashboardStore(q=>q.dashboard.controls)||el,{setCard:p,updateCardInFrame:j}=t.useEditorActions(),[N,f]=v.useState(null);v.useEffect(()=>{d&&!N&&(l!=null&&l.id)&&f(l.id)},[l==null?void 0:l.id,d,N]),v.useEffect(()=>{!d&&N!==null&&f(null)},[d,N]);const g=v.useMemo(()=>N?(u==null?void 0:u.cards.find(q=>q.id===N))||((l==null?void 0:l.id)===N?l:void 0):l,[l,u==null?void 0:u.cards,N]),k=(g==null?void 0:g.type)==="matrixTable"?(V=g.config)==null?void 0:V.matrix:void 0,D=v.useMemo(()=>d&&k?fr.matrixCatalogSources(k.spec,g==null?void 0:g.controlBindings):[],[d,k,g==null?void 0:g.controlBindings]),w=a.useMatrixSourceCatalog(D),S=v.useMemo(()=>w.catalog.map(q=>({...q.field,dataType:st.normalizeAnalyticsCatalogDataType(q.resolvedField.dataType)})),[w.catalog]),M=(g==null?void 0:g.controls)||[],A=g?t.collectDashboardControlIds(m,{excludeCardId:g.id}):h.map(q=>q.id),F=((g==null?void 0:g.controlBindings)||[]).filter(a.isStructuralControlBinding),I=((g==null?void 0:g.controlBindings)||[]).filter(a.isPresentationCurrencyBinding),C=a.buildCardControlUsageById({card:g,controls:M}),E={choices:t.getFieldSelectorChoicesForCard(g),targetMap:Object.fromEntries((((_=g==null?void 0:g.config)==null?void 0:_.groupByColumns)||[]).map(q=>[q.id,q]))},L={choices:t.getMetricSelectorChoicesForCard(g),targetMap:Object.fromEntries((((z=g==null?void 0:g.config)==null?void 0:z.metricColumns)||[]).map(q=>[q.id,q]))},T=E.choices.map(q=>({option:q,target:E.targetMap[q.value]})),R=L.choices.map(q=>({option:q,target:L.targetMap[q.value]})),y=(q,Y)=>{if(!g)return;const $=(Y==null?void 0:Y.type)==="rename"?t.applyControlMutationToCard(g,{type:"rename",oldId:Y.oldId,newId:Y.newId}):(Y==null?void 0:Y.type)==="remove"?t.applyControlMutationToCard(g,{type:"remove",controlId:Y.controlId}):g,U={...$,controls:q,controlBindings:t.syncStructuralBindingsWithControls($.controlBindings,q)};j(U),(l==null?void 0:l.id)===U.id&&p(U)},B=q=>{if(!g)return;const Y={...g,controlBindings:[...t.mergeConfigBindingsWithSqlParamBindings(q,(g.controlBindings||[]).filter($=>!a.isPresentationCurrencyBinding($))),...I]};j(Y),(l==null?void 0:l.id)===Y.id&&p(Y)},P=q=>{if(!g)return;const Y={...g,controlBindings:[...(g.controlBindings||[]).filter($=>!a.isPresentationCurrencyBinding($)),...q]};j(Y),(l==null?void 0:l.id)===Y.id&&p(Y)},O=n==="menu";return e.jsx("div",{className:t.cn("flex items-center gap-1",O&&"w-full",s),children:e.jsxs(t.Popover,{modal:!0,open:d,onOpenChange:o,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:O?e.jsxs(t.Button,{variant:"ghost",className:"h-auto w-full justify-start gap-2 rounded-sm px-2 py-1.5 text-[13px] font-normal",children:[e.jsx(t.SlidersHorizontal,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{children:r}),M.length+F.length>0&&e.jsx("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:M.length+F.length})]}):e.jsxs(a.IconButton,{tooltip:"Configure Controls",className:t.cn("relative h-7 w-7 px-0",{"text-primary":M.length>0||F.length>0}),children:[e.jsx(t.SlidersHorizontal,{className:"h-3.5 w-3.5"}),M.length+F.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-medium text-primary-foreground",children:M.length+F.length})]})}),e.jsxs(t.PopoverContent,{className:t.cn("flex max-h-[85vh] w-[560px] max-w-[95vw] flex-col",O&&"z-[60]"),align:"end",onEscapeKeyDown:c,onPointerDownOutside:c,children:[e.jsxs("div",{className:"space-y-1 border-b pb-4",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Card-only controls"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add controls that belong only to this card, or decide how this card should respond to shared dashboard controls."}),g!=null&&g.sql?e.jsx("p",{className:"text-xs text-muted-foreground",children:"SQL cards reference controls explicitly with syntax like `[[param.wac_type]]`."}):null]}),e.jsx("div",{className:"flex-1 overflow-y-auto pt-5",children:e.jsxs("div",{className:"space-y-5 pr-1",children:[e.jsx(pt.ControlDefinitionListEditor,{scope:"card",card:g,controls:M,reservedControlIds:A,usageByControlId:C,availableFieldChoices:T,availableMetricChoices:R,onCreateFlowActiveChange:i,onChange:(q,Y,$)=>y(q,$),emptyMessage:"No card-scoped controls yet."}),e.jsxs("div",{className:"space-y-1 border-t pt-4",children:[e.jsx("h4",{className:"text-sm font-medium",children:"How this card uses controls"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose what each control changes in this card."})]}),g?e.jsxs(e.Fragment,{children:[e.jsx(Jo,{card:g,dashboardControls:h,bindings:F,onChange:B,availableFieldChoices:k?void 0:T,availableMetricChoices:k?void 0:R,matrixSpec:k==null?void 0:k.spec,matrixPresentation:k==null?void 0:k.presentation,matrixFieldCatalog:S,suppressTransientStaleState:!!(k&&w.pending)}),e.jsx("div",{className:"border-t pt-4",children:e.jsx(Zo,{matrixCatalog:w.catalog,card:g,dashboardControls:h,resultColumnKeys:x,bindings:I,onChange:P})})]}):null]})})]})]})})}function Sa({showOrientation:s=!0,showGridStyle:n=!0,showInlineFilters:r=!0,showControls:o=!0,showDisplayOptions:c=!0}={}){const d=t.useEditorStore(p=>p.card),i=t.useEditorStore(p=>{var j,N;return(N=(j=p.card)==null?void 0:j.preferences)==null?void 0:N.chartOptions}),l=a.getChartGridStyle(i),{setChartGrid:u}=t.useEditorActions();function x(){const p=["xy","none","x","y"],N=(p.indexOf(l)+1)%p.length;u(p[N])}const m=s&&["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(d.type),b=n&&!["pie","doughnut","funnel","radar","polarArea","table","aggregateTable","pivotTable","detailTable","custom","kpi","text","map"].includes(d.type);return m||b||r||o||c?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[m&&e.jsx(e.Fragment,{children:e.jsx($o,{})}),b&&e.jsxs(a.IconButton,{tooltip:"Grid Style",onClick:x,className:"h-7 w-7 px-0",children:[(l==="xy"||!l)&&e.jsx(a.Grid3x3,{className:"h-3.5 w-3.5"}),l==="x"&&e.jsx(ks,{className:"h-3.5 w-3.5"}),l==="y"&&e.jsx(a.Rows3,{className:"h-3.5 w-3.5"}),l==="none"&&e.jsx(a.Square,{className:"h-3.5 w-3.5"})]}),r&&e.jsx(Ps,{}),o&&e.jsx(Os,{}),c&&e.jsx(Rs,{})]}):null}function tl({errorMessage:s,errorSql:n,onOpenInEditor:r,onDebugWithAssistant:o}){const{feedbackDialogOpen:c,setFeedbackDialogOpen:d,handleSendFeedback:i,feedbackPayload:l}=fa(s,n);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:e.jsx(cs,{error:s,errorSql:n,errorMessageClassName:"max-h-40",fillAvailableSqlHeight:!0,className:"max-h-none",onOpenInEditor:r,onDebugWithAssistant:o,onSendFeedback:i,showFeedbackButton:!0})}),e.jsx(a.FeedbackDialog,{open:c,onOpenChange:d,feedbackData:l,showDebugInfo:!0})]})}function sl({isPreviewMode:s,onPreviewToggle:n,configCard:r}){var B,P,O,V,_;const o=t.useEditorStore(z=>z.frame),c=t.useEditorStore(z=>z.card),d=t.useEditorStore(z=>z.editorContext),i=(d==null?void 0:d.type)==="documentSection",{setFrame:l,setActiveTabCardId:u,setCard:x,updateCardInFrame:m,clearModeDrafts:b,initializeModeDrafts:h}=t.useEditorActions(),{manifest:p}=a.useCustomVisual(((B=r==null?void 0:r.customCardPreferences)==null?void 0:B.url)||""),j=(P=p==null?void 0:p.visuals)==null?void 0:P.find(z=>{var q;return z.name===((q=r==null?void 0:r.customCardPreferences)==null?void 0:q.componentName)}),f=xe.resolveMultiInputType(r,j)==="multiple",g=(j==null?void 0:j.minInputs)??((O=r==null?void 0:r.customCardPreferences)==null?void 0:O.minInputs)??1,k=(j==null?void 0:j.maxInputs)??((V=r==null?void 0:r.customCardPreferences)==null?void 0:V.maxInputs),D=v.useMemo(()=>xe.getCustomVisualInputCards({frame:o,configCard:r,isMultiInputVisual:f}),[o,r,f]),w=f?D.filter(Boolean).length:o.cards.length,S=i?!1:k?w<k:!0,M=w>Math.max(g||1,1),A=!!((_=r==null?void 0:r.customCardPreferences)!=null&&_.dataInputCardIds),F=(z,q)=>{z.dataTransfer.setData("tabIndex",q.toString())},I=z=>{z.preventDefault()},C=(z,q)=>{const Y=z.dataTransfer.getData("tabIndex");if(Y===q.toString())return;const $=Array.from(o.cards),[U]=$.splice(parseInt(Y),1);$.splice(q,0,U),l({...o,cards:$})};function E(z){const q=(r==null?void 0:r.id)===z;if(!(A&&q?o.cards.length>1:M))return;let $=o.cards.filter(X=>X.id!==z);f&&!A&&($=xe.reindexSlotCards($));const U=$[0],H={...o,cards:$,activeCardId:U.id},te=z===c.id;te&&b(),l(H),u(U.id),x(U),te&&h(U)}function L(z,q){if(!S)return;const Y={...o,cards:[...o.cards,q],activeCardId:z.id};l(Y),u(q.id)}function T(){if(i)return;if(f&&(r==null?void 0:r.id)===c.id){R(c);return}const z={...c,id:je.v4(),title:`${c.title} Copy`,tabTitle:`${c.tabTitle||c.title} Copy`,customCardPreferences:c.customCardPreferences?{...c.customCardPreferences,slotIndex:f?Math.max(-1,...D.map((q,Y)=>xe.getSlotIndexForCard(q,Y)))+1:c.customCardPreferences.slotIndex}:void 0};L(c,z)}function R(z){var te;if(i||!S)return;let q=f?"table":"bar",Y="Title",$="";const U=f?Math.max(-1,...D.map((X,se)=>xe.getSlotIndexForCard(X,se)))+1:w;if(f&&((te=j==null?void 0:j.slots)!=null&&te.length)){const X=xe.getSlotDefinitionForIndex(j.slots,U);X&&(q=xe.getSlotExpectedChartType(X),Y=X.label||`Tab ${U+1}`,$=X.description||"")}const H={dataSource:z.dataSource,connectionId:z.connectionId,lastSelectedDatabase:z.lastSelectedDatabase,lastSelectedSchema:z.lastSelectedSchema,lastSelectedTable:z.lastSelectedTable,lastSelectedDatamodelId:z.lastSelectedDatamodelId,id:je.v4(),title:Y,tabTitle:Y,description:$,preferences:{onClickFilter:[{columnIndex:0,expression:""}],...q==="text"?{textVisualOptions:{richContent:t.createEmptyRichContent()}}:{}},type:q,sql:"",data:[],mode:"explorer",...f&&{customCardPreferences:{slotIndex:U}}};L(z,H)}function y(z,q){return z.cards.length===1&&(q.displayTab===!0||q.displayTab===void 0)||z.activeCardId!==q.id&&(q.displayTab===!0||q.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const Y=q.displayTab===void 0?!1:!q.displayTab;x({...q,displayTab:Y}),m({...q,displayTab:Y})},children:q.displayTab===!0||q.displayTab===void 0?e.jsx(Ke.Eye,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"}):e.jsx(a.EyeOff,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})}return e.jsx(t.TabsList,{variant:"underline",className:"group flex h-9 shrink-0 items-center justify-start gap-1 overflow-x-auto rounded-none border-b-0 border-t border-border bg-background px-4",children:e.jsxs("div",{className:"flex items-center gap-1",children:[o.cards.map((z,q)=>{var te,X;const Y=f?xe.getSlotIndexForCard(z,q):-1,$=f&&((te=j==null?void 0:j.slots)!=null&&te.length)&&Y>=0?xe.getSlotDefinitionForIndex(j.slots,Y):null,U=$?(Array.isArray($.expectedType)?$.expectedType[0]:$.expectedType)||"table":z.type,H=f&&((X=j==null?void 0:j.slots)==null?void 0:X.length)&&j.slots.every(se=>typeof se.position=="number"||typeof se.position=="string"&&!se.position.includes("+"));return e.jsxs(t.TabsTrigger,{draggable:!f&&!i,onDragStart:f||i?void 0:se=>F(se,q),onDragOver:f||i?void 0:I,onDrop:f||i?void 0:se=>C(se,q),className:t.cn("inline-flex h-6 shrink-0 items-center gap-1.5 rounded-[5px] border px-2 text-[12px] font-normal text-muted-foreground transition-colors","mb-0 border-transparent pb-0","hover:bg-muted/40 hover:text-foreground","data-[state=active]:border-border data-[state=active]:bg-card data-[state=active]:text-foreground"),value:z.id,children:[f&&$?e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:a.getChartIconByType(U,"size-3.5")}),e.jsx("span",{children:$.label||`Tab ${Y+1}`})]})}),e.jsx(t.TooltipContent,{side:"bottom",className:"w-64 p-3 text-left",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium",children:$.label}),$.description&&e.jsx("p",{className:"whitespace-normal break-words text-xs text-muted-foreground",children:$.description}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[$.expectedType&&e.jsx("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Array.isArray($.expectedType)?$.expectedType.join(" / "):$.expectedType}),$.required&&e.jsx("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"Required"})]})]})})]})}):e.jsxs(e.Fragment,{children:[y(o,z),e.jsx(a.Editable,{enabled:o.activeCardId===z.id,text:z.tabTitle||z.title,onSave:se=>{x({...c,tabTitle:se}),m({...c,tabTitle:se})},children:z.tabTitle||z.title},z.id)]}),!i&&o.activeCardId===z.id&&!H&&e.jsx(a.CopyPlus,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:se=>{se.stopPropagation(),T()}}),!i&&o.activeCardId===z.id&&(A&&(r==null?void 0:r.id)===z.id?o.cards.length>1:M)&&e.jsx(le.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground",onClick:()=>E(z.id)})]},z.id)}),!i&&e.jsx(a.IconButton,{tooltip:"Add Card",className:"h-6 w-6 rounded-[5px] p-0 text-muted-foreground hover:bg-muted hover:text-foreground",onClick:()=>R(c),disabled:!S,children:e.jsx(a.Plus,{className:"h-3 w-3"})}),f&&e.jsxs(a.Toggle,{pressed:s,onPressedChange:n,size:"sm",className:"ml-1 h-6 gap-1 rounded-[5px] px-2 text-[11px] data-[state=on]:bg-muted data-[state=on]:text-foreground","aria-label":"Toggle preview",children:[s?e.jsx(a.EyeOff,{className:"h-3 w-3"}):e.jsx(Ke.Eye,{className:"h-3 w-3"}),e.jsx("span",{children:"Preview"})]})]})})}function St({renderCardOverride:s,alwaysRenderOverride:n=!1}={}){var qe,Fe,Ue,we,oe;const r=a.useResolvedTemporalStylePreferences(),o=t.useEditorStore(ne=>ne.frame),c=t.useEditorStore(ne=>ne.card),[d,i]=v.useState(!1),l=v.useMemo(()=>xe.findCustomVisualConfigCard(o,c),[o,c]),u=t.useEditorStore(ne=>ne.isSqlRunning);t.useEditorStore(ne=>ne.isDevMode);const{setFrame:x,setActiveTabCardId:m,setCard:b,setRunSql:h,mergeDraftsIntoCard:p,clearModeDrafts:j,initializeModeDrafts:N}=t.useEditorActions(),[f,g]=v.useState({}),[k,D]=v.useState(()=>new Set),{authToken:w}=a.useSemaphorContext(),S=t.getTokenParams(w==null?void 0:w.accessToken),{compiledAppearance:M}=pr.useAppearance(),A=v.useMemo(()=>a.buildCustomCardTheme(M),[M]),{getCard:F,manifest:I,isLoading:C}=a.useCustomVisual(((qe=l==null?void 0:l.customCardPreferences)==null?void 0:qe.url)||""),E=(Fe=l==null?void 0:l.customCardPreferences)==null?void 0:Fe.componentName,L=E?F(E):null,T=(Ue=I==null?void 0:I.visuals)==null?void 0:Ue.find(ne=>ne.name===E),R=xe.resolveMultiInputType(l,T),y=d&&R==="multiple"&&!!l,B=v.useMemo(()=>xe.getCustomVisualInputCards({frame:o,configCard:l,isMultiInputVisual:!0}).map(de=>(de==null?void 0:de.id)===c.id?c:de),[o,l,c]),P=v.useMemo(()=>xe.buildSlotOrderedCards(B),[B]),O=v.useMemo(()=>{const ne=B.findIndex(de=>(de==null?void 0:de.id)===c.id);return ne<0?-1:xe.getSlotIndexForCard(c,ne)},[B,c]),V=v.useMemo(()=>!l||R!=="multiple"||O<0?c.type:xe.getEffectiveCardTypeForSlot(c,O,T==null?void 0:T.slots)??c.type,[l,R,O,c,T==null?void 0:T.slots]),_=v.useMemo(()=>y?{...c,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:V!==c.type?{...c,type:V}:c,[c,V,y]),{data:z,dataUpdatedAt:q,isLoading:Y,isFetching:$,isError:U,errorMessage:H,errorSql:te,queryKey:X}=a.useEditorCardQuery(_),se=JSON.stringify(X),{handleOpenInEditor:ue,handleDebugWithAssistant:fe}=Ls(H,te||c.sql||c.python),be=c.type==="text"&&((oe=(we=c.preferences)==null?void 0:we.textVisualOptions)==null?void 0:oe.isDynamicText)===!0&&!!H,ge=v.useCallback((ne,de)=>{const ve=xe.normalizeMultiInputPayload(de);g(pe=>({...pe,[ne]:ve}))},[]),Pe=v.useCallback((ne,de)=>{D(ve=>{const pe=new Set(ve);return de?pe.add(ne):pe.delete(ne),pe})},[]),Oe=k.size>0,Ae=v.useMemo(()=>P.map((ne,de)=>xe.getEffectiveCardTypeForSlot(ne,de,T==null?void 0:T.slots)),[P,T==null?void 0:T.slots]),Ie=v.useMemo(()=>a.createCustomVisualTemporalBucketFormatter(a.buildMultiInputTemporalPresentationInputs({slotOrderedCards:P,multiInputData:f,valueFormatPreferences:r})),[f,P,r]),_e=t.useInteractionStore(ne=>ne.interactionStates),Ye=t.useDashboardStore(ne=>{var de;return(de=ne.dashboard)==null?void 0:de.id}),Ve=t.useDashboardStore(ne=>ne.dashboard.filters),Le=t.useDashboardStore(ne=>ne.filterValues),De=t.useDashboardStore(ne=>ne.selectedSheetId),ae=t.useEditorStore(ne=>ne.inlineFilterValuesMap[(l==null?void 0:l.id)||""]),K=t.useEditorStore(ne=>ne.actions.setCardInlineFilterValue),ie=t.useEditorStore(ne=>ne.actions.removeCardInlineFilterValue),Se=v.useMemo(()=>l?a.buildInlineFilterNodes({card:l,sheetId:De||"",inlineFilterValues:ae,setInlineFilterValue:ne=>K(l.id,ne),removeInlineFilterValue:ne=>ie(l.id,ne)}):[],[l,De,ae,K,ie]),{cardFilters:re,cardFilterValues:he}=v.useMemo(()=>l?a.calculateContextAwareFilters({card:l,interactionStates:_e,currentDashboardId:Ye,filters:Ve,filterValues:Le,selectedSheetId:De}):{cardFilters:[],cardFilterValues:[]},[l,_e,Ye,Ve,Le,De]);function ze(ne){const de=o.cards.find(ve=>ve.id===ne);de&&(a.flushPendingEditorDrafts(),p(),Z(ne),m(ne),j(),N(de))}function Z(ne){const de=t.useEditorStore.getState().card,ve=t.useEditorStore.getState().frame,pe={...ve,cards:ve.cards.map(Me=>Me.id===de.id?de:Me),activeCardId:ne};x(pe);const Qe=pe.cards.find(Me=>Me.id===ne);Qe.sql&&h(!0),b(Qe)}function Re(){return C?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading manifest"})}):L?e.jsxs("div",{className:"relative flex h-full flex-col pl-2 pr-4",children:[B.map((de,ve)=>{if(!de)return null;const pe=xe.getSlotIndexForCard(de,ve),Qe=xe.getEffectiveCardTypeForSlot(de,pe,T==null?void 0:T.slots);return e.jsx(a.MultiInputEmptyRenderer,{onLoadingStatus:Pe,onDataChange:ge,card:de,effectiveCardType:Qe},`${de.id}-${pe}`)}),Oe&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading preview"})}),e.jsx("div",{className:t.cn("flex h-full min-h-0 flex-1 flex-col gap-2",Oe&&"opacity-50"),children:e.jsx(v.Suspense,{fallback:e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(a.LoadingDots,{size:"md",color:"muted"})}),children:e.jsx(L,{editing:!0,...a.buildMultiInputCustomVisualProps({configCard:l,slotOrderedCards:P,slotTypes:Ae,multiInputData:f,params:S,theme:A,filters:re,filterValues:[...he||[],...ae||[]],inlineFilters:Se,formatTemporalBucketValue:Ie})})})})]}):e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a component to preview the multi-input visual."})}function me(){var ne;return y?Re():s&&(n||!Y&&!$&&!U&&!H)?s({card:c,data:z,isLoading:Y,isFetching:$,isError:U}):c.type==="kpi"?Y||$?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):H?e.jsx(tl,{errorMessage:H,errorSql:te||c.sql||c.python,onOpenInEditor:ue,onDebugWithAssistant:fe}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"w-1/2 space-y-3",children:[e.jsx("div",{className:"rounded-md border border-border",children:e.jsx(a.KPICard,{card:c,data:z==null?void 0:z.records,isPending:Y||$,isError:U,comparisonMetadata:(ne=z==null?void 0:z.metadata)==null?void 0:ne.comparisonMetadata})}),a.isCardSummaryVisibleOnCard(c)&&e.jsx(a.CardSummary,{card:c,mode:"editor",records:z==null?void 0:z.records})]})}):c.type==="text"?Y||$?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):be?e.jsx("div",{className:"flex h-full min-h-0 flex-col overflow-auto px-4 py-0",children:e.jsx(cs,{error:H,errorSql:te||c.sql||c.python,onOpenInEditor:ue,onDebugWithAssistant:fe,showFeedbackButton:!1})}):e.jsx("div",{className:"flex h-full min-h-0 flex-col px-4 py-4",children:e.jsx(a.TextCard,{isLoading:u,card:c,data:z==null?void 0:z.records})}):e.jsx(a.ErrorBoundary,{FallbackComponent:a.FallbackVisual,resetKeys:[se,q,$],children:e.jsx(ga,{className:"grow border-none shadow-none"})})}return e.jsxs(t.Tabs,{onValueChange:ze,value:o.activeCardId,className:"flex min-h-0 flex-1 flex-col",children:[y?e.jsx("div",{className:"mt-0 min-h-0 flex-1 overflow-hidden",children:me()}):o.cards.map(ne=>e.jsx(t.TabsContent,{className:"mt-0 min-h-0 flex-1 overflow-hidden focus-visible:ring-0 focus-visible:ring-offset-0",value:ne.id,children:me()},ne.id)),e.jsx(sl,{isPreviewMode:y,onPreviewToggle:i,configCard:l})]})}function nl({onClick:s,className:n}){return e.jsxs(t.Button,{type:"button",size:"sm",variant:"outline",className:t.cn("h-8 gap-1.5 px-3 text-xs",n),onClick:s,children:[e.jsx(t.SlidersHorizontal,{className:"h-3.5 w-3.5 shrink-0"}),"Customize"]})}function wa({fallbackPreview:s,records:n,title:r,isInspectorOpen:o,onInspectorOpenChange:c}){var T;const d=t.useEditorStore(R=>R.card),i=t.useEditorStore(R=>R.actions.setCard),l=t.useEditorStore(R=>R.actions.updateCardInFrame),u=t.normalizeDynamicRendererSource((T=d.dynamicCardPreferences)==null?void 0:T.rendererCode),[x,m]=v.useState(u),[b,h]=v.useState(u);v.useEffect(()=>{m(u),h(u)},[u,d.id]);const p=v.useMemo(()=>t.normalizeDynamicRendererSource(x),[x]),j=v.useMemo(()=>t.validateDynamicRendererSource(p),[p]),N=!!u,f=v.useMemo(()=>{var R;return t.buildCardWithVisualizationMode(d,b?"dynamic":"builtin",{rendererCode:b||void 0,artifactId:((R=d.dynamicCardPreferences)==null?void 0:R.artifactId)||d.id,title:r||d.title})},[d,b,r]),g=!!b,k=p!==b,D=b!==u,w=!p||!j.valid||k||D,S=p?j.valid?k?"Unapplied changes":"Pending save":"Needs attention":"Draft",M=!p||k||D?"outline":"destructive",A=p?j.valid?k?"The preview still reflects the last applied code until you apply this draft.":D?"Preview reflects pending changes. Accept changes to save them.":"":j.error||"Visual code is invalid.":"Paste visual code or generate one before saving this card.";function F(){if(!j.valid){t.ue.error(j.error||"Visual code is invalid.");return}h(p),t.ue.success("Dynamic preview updated.")}function I(){m(b)}function C(){var y;const R=t.buildCardWithVisualizationMode(d,b?"dynamic":"builtin",{rendererCode:b||void 0,artifactId:((y=d.dynamicCardPreferences)==null?void 0:y.artifactId)||je.v4(),title:r||d.title});i(R),l(R),c(!1),t.ue.success(b?"Dynamic visual changes saved.":"Dynamic visual cleared.")}function E(){m(u),h(u),c(!1)}function L(){m(""),h("")}return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsx("div",{className:"min-h-0 flex-1 bg-background px-2",children:N?e.jsx(a.PersistedDynamicVisual,{card:d,records:n,title:r,layoutMode:"fill",fallback:s},u||"applied-empty"):e.jsxs("div",{className:"flex h-full min-h-[280px] flex-col items-center justify-center gap-3 rounded-md border border-dashed border-border/70 bg-muted/20 px-6 text-center",children:[e.jsx("div",{className:"flex size-10 items-center justify-center rounded-full border bg-background",children:e.jsx(a.CodeXml,{className:"text-muted-foreground"})}),e.jsxs("div",{className:"flex max-w-md flex-col gap-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"No applied dynamic visual yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Open Customize, paste visual code, and apply it to preview the renderer here."})]}),e.jsx(nl,{onClick:()=>c(!0)})]})}),e.jsx(a.Dialog,{open:o,onOpenChange:R=>{if(!R){E();return}c(!0)},children:e.jsxs(a.DialogContent,{className:"flex h-[min(88vh,860px)] max-w-[min(1280px,calc(100vw-2rem))] flex-col gap-0 overflow-hidden p-0",children:[e.jsx(a.DialogHeader,{className:"border-b px-6 py-4 pr-20 text-left",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 pr-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx(a.DialogTitle,{children:"Dynamic Visual Editor"}),e.jsx(a.DialogDescription,{children:"Adjust the preview and visual code here. Query editing stays in the normal editor controls."})]}),w&&e.jsx(a.Badge,{className:"mr-4 shrink-0",variant:M,children:S})]})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsxs(a.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(a.ResizablePanel,{defaultSize:54,minSize:38,children:e.jsx("div",{className:"flex h-full min-h-0 flex-col",children:e.jsx("div",{className:"min-h-0 flex-1 bg-background p-4",children:g?e.jsx(a.PersistedDynamicVisual,{card:f,records:n,title:r,layoutMode:"fill",fallback:s},b||"preview-empty"):e.jsx("div",{className:"flex h-full min-h-[280px] items-center justify-center rounded-md border border-dashed border-border/70 bg-muted/20 px-6 text-center text-sm text-muted-foreground",children:"Apply valid visual code to preview the dynamic visual here."})})})}),e.jsx(a.ResizableHandle,{withHandle:!0}),e.jsx(a.ResizablePanel,{defaultSize:46,minSize:30,children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(a.CodeXml,{className:"h-4 w-4 text-muted-foreground"}),"Visual Code"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.AlertDialog,{children:[e.jsx(a.AlertDialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{type:"button",size:"sm",variant:"ghost",className:"h-8 gap-1.5 px-2.5 text-xs",disabled:!N&&!p,children:[e.jsx(le.X,{className:"h-3.5 w-3.5 shrink-0"}),"Clear"]})}),e.jsxs(a.AlertDialogContent,{children:[e.jsxs(a.AlertDialogHeader,{children:[e.jsx(a.AlertDialogTitle,{children:"Clear dynamic visual?"}),e.jsx(a.AlertDialogDescription,{children:"This removes the saved dynamic renderer and switches the card back to built-in mode. The underlying query and built-in chart type will remain."})]}),e.jsxs(a.AlertDialogFooter,{children:[e.jsx(a.AlertDialogCancel,{children:"Cancel"}),e.jsx(a.AlertDialogAction,{className:"bg-foreground text-background hover:bg-foreground/90",onClick:L,children:"Clear"})]})]})]}),e.jsxs(t.Button,{type:"button",size:"sm",variant:"outline",className:"h-8 gap-1.5 px-2.5 text-xs",onClick:I,disabled:!k,children:[e.jsx(t.RotateCcw,{className:"h-3.5 w-3.5 shrink-0"}),"Reset"]}),e.jsxs(t.Button,{type:"button",size:"sm",className:"h-8 gap-1.5 px-3 text-xs",onClick:F,disabled:!k||!j.valid,children:[e.jsx(a.Play,{className:"h-3.5 w-3.5 shrink-0"}),"Apply to Preview"]})]})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 p-4",children:[A&&e.jsx("p",{className:t.cn("text-xs",j.valid?"text-muted-foreground":"text-destructive"),children:A}),e.jsx("div",{className:t.cn("min-h-0 flex-1 overflow-hidden rounded-md border",!j.valid&&p&&"border-destructive"),children:e.jsx(t.CodeEditor,{value:x,onValueChange:R=>m(R||""),language:"javascript",embedded:!0})})]})]})})]})}),e.jsxs(a.DialogFooter,{className:"border-t px-6 py-4 sm:justify-between",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:A||"Preview changes here before saving them."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{type:"button",variant:"outline",size:"sm",className:"h-8 px-3 text-xs",onClick:E,children:"Cancel"}),e.jsx(t.Button,{type:"button",size:"sm",className:"h-8 px-3 text-xs",onClick:C,disabled:!D,children:"Accept changes"})]})]})]})})]})}function Ta({onCustomize:s}){const n=t.useEditorStore(x=>x.card),r=t.useEditorStore(x=>x.frame),o=t.useEditorStore(x=>x.actions.setIsShowingVisual),{setVisualizationMode:c,setDynamicCardPreferences:d}=t.useEditorActions(),l=t.getVisualizationMode(n)==="dynamic";if(r.cards.length!==1||t.isCustomVisualizationCard(n))return null;const u=x=>{var m;x==="dynamic"&&!n.dynamicCardPreferences&&d(t.createEmptyDynamicCardPreferences(n.type,(m=n.preferences)==null?void 0:m.displayOptions)),c(x),o(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs(a.DropdownMenuItem,{onSelect:x=>{x.preventDefault(),u(l?"builtin":"dynamic")},className:"justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.CodeXml,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{children:"Dynamic"})]}),e.jsx(t.Switch,{size:"xs",checked:l,onCheckedChange:x=>u(x?"dynamic":"builtin"),onClick:x=>x.stopPropagation()})]}),l&&s?e.jsxs(a.DropdownMenuItem,{onSelect:x=>{x.preventDefault(),s()},children:[e.jsx(t.SlidersHorizontal,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Customize visual"]}):null]})}function Ea({sql:s,showCardDetails:n=!1,debugPayloads:r,className:o}){const[c,d]=v.useState(!1),i=t.useEditorStore(b=>b.isDevMode),l=t.useEditorStore(b=>b.card.type),{switchEditorMode:u,setRunSql:x}=t.useEditorActions(),m=()=>{u("dev",{sqlToLoad:s}),setTimeout(()=>{x(!0)},100)};return e.jsx(ca,{className:t.cn("overflow-hidden",o),children:e.jsx(ha,{sql:s,label:"Generated query",ariaLabel:"Executed SQL",copyAriaLabel:"Copy generated query",headerActions:i?void 0:e.jsxs(e.Fragment,{children:[je.supportsSqlEditor(l)&&e.jsx(t.Button,{onClick:m,variant:"outline",size:"xs",className:Ft,children:"Open in SQL editor"}),n&&e.jsx(ma,{isOpen:c,onClick:()=>d(b=>!b)})]}),className:"min-h-0",bodyClassName:"max-h-[min(420px,calc(var(--radix-hover-card-content-available-height,100vh)-3rem))]",children:c&&n&&e.jsx(xa,{debugPayloads:r})})})}function bs({children:s,visualAsideControl:n,mode:r="both",inlineToolbar:o=!1,overflowActions:c,isDynamicInspectorOpen:d,onDynamicInspectorOpenChange:i}){var Re;const l=a.useQueryClient(),u=t.useEditorStore(me=>me.frame),x=t.useEditorStore(me=>me.card),m=t.useEditorStore(me=>me.isDevMode),b=t.useEditorStore(me=>me.editorContext),h=(b==null?void 0:b.type)==="documentSection",p=t.useEditorStore(me=>me.isShowingVisual),j=t.useEditorStore(me=>me.actions.setIsShowingVisual),N=t.useDashboardStore(me=>me.isVisualEditing),{isConsoleMode:f}=a.useDashboardPreferences(),g=t.useEditorStore(me=>me.pythonStdOut),k=t.useEditorStore(me=>me.actions.setRunSql),D=a.useEffectiveEditorCardType(),w=D==="table"||D==="detailTable"||D==="matrixTable",M=t.supportsRegularTableSettings(D)&&!!(n!=null&&n.onOpen),F=t.getVisualizationMode(x)==="dynamic",[I,C]=v.useState(!1),E=d??I,L=i??C,{setFrame:T,setCard:R,setActiveTabCardId:y,mergeDraftsIntoCard:B,clearModeDrafts:P,initializeModeDrafts:O,updatePageSize:V,updateCardInFrame:_,setCardType:z}=t.useEditorActions(),q=v.useMemo(()=>D!==x.type?{...x,type:D}:x,[x,D]),{data:Y,isLoading:$,isFetching:U,errorMessage:H,errorSql:te,refetch:X,queryKey:se,pagination:ue}=a.useEditorCardQuery(q),fe=v.useRef(se);fe.current=se;const{handleDebugWithAssistant:be}=Ls(H,te),ge=v.useMemo(()=>(Y==null?void 0:Y.records)||[],[Y==null?void 0:Y.records]),{cardFilterValues:Pe}=fo((x==null?void 0:x.id)??""),[Oe,Ae]=v.useState(!1),Ie=a.useMatrixEditorRefresh(x),[_e,Ye]=v.useState();v.useEffect(()=>{U||Ae(!1)},[U]);const Ve=()=>{var me;if(Ie){(me=Ie.refresh)==null||me.call(Ie);return}if(Ae(!0),m){a.flushPendingEditorDrafts(),setTimeout(()=>{l.removeQueries({queryKey:fe.current,exact:!0}),k(!0)},0);return}X()};v.useEffect(()=>{w&&!p&&!m&&!f&&j(!0)},[f,m,w,p,j]);function Le(me,qe){var we,oe;const Fe={...x,paginationConfig:{page:me+1,pageSize:qe}};R(Fe);const Ue={...u,cards:u.cards.map(ne=>ne.id===x.id?Fe:ne)};T(Ue),x.sql&&((oe=(we=x.preferences)==null?void 0:we.tablePrefs)!=null&&oe.enableDevModePagination)&&k(!0)}function De(me){var we,oe,ne,de,ve;const qe=a.sortStateToSortByColumns(me,(we=x.config)==null?void 0:we.metricColumns,(oe=x.config)==null?void 0:oe.groupByColumns,(ne=x.config)==null?void 0:ne.detailColumns),Fe={...x,config:{...x.config||{},sortByColumns:qe}};R(Fe);const Ue={...u,cards:u.cards.map(pe=>pe.id===x.id?Fe:pe)};T(Ue),x.sql&&((ve=(de=x.preferences)==null?void 0:de.tablePrefs)!=null&&ve.enableDevModePagination)&&k(!0)}const ae=Array.isArray(Y==null?void 0:Y.records)?Y.records:[],K=ae.length>0;function ie(){var qe;if(!K)return;const me=JSON.stringify(ae,null,2);typeof navigator>"u"||!((qe=navigator.clipboard)!=null&&qe.writeText)||navigator.clipboard.writeText(me).catch(Fe=>{console.error("Failed to copy JSON",Fe)})}function Se(){if(!K)return;const me=JSON.stringify(ae,null,2),qe=new Blob([me],{type:"application/json"}),Fe=URL.createObjectURL(qe),Ue=document.createElement("a");Ue.href=Fe,Ue.download=`${x.title}.json`,Ue.click()}function re(){if(!K)return;const qe=[Object.keys(ae.reduce((oe,ne)=>({...oe,...ne}),{})).join(","),...ae.map(oe=>Object.values(oe).join(","))].join(`
172
- `),Fe=new Blob([qe],{type:"text/csv"}),Ue=URL.createObjectURL(Fe),we=document.createElement("a");we.href=Ue,we.download=`${x.title}.csv`,we.click()}if(!x)return e.jsx(e.Fragment,{children:"No Active Card"});const he=r==="both"||r==="toolbar",ze=r==="both"||r==="canvas",Z=!$&&!U&&!H&&(Y!=null&&Y.sql)?e.jsx("div",{className:"inline-flex shrink-0 items-center text-[11px] text-muted-foreground",children:e.jsxs(a.HoverCard,{openDelay:200,children:[e.jsx(a.HoverCardTrigger,{asChild:!0,children:o?e.jsx(a.IconButton,{className:"h-7 w-7 shrink-0 px-0",buttonProps:{"aria-label":"View executed SQL"},children:e.jsx(Nr,{className:"h-3.5 w-3.5",strokeWidth:1.75})}):e.jsx("button",{type:"button",className:"cursor-pointer text-[11px] underline-offset-4 hover:text-foreground hover:underline",children:"Executed SQL"})}),e.jsx(a.HoverCardContent,{align:"end",collisionPadding:16,className:"w-[500px] overflow-hidden p-0",children:e.jsx(Ea,{sql:Y.sql})})]})}):null;return e.jsxs("div",{className:t.cn("relative isolate flex flex-col",o?"ml-auto min-w-0 shrink-0":r==="toolbar"?"h-auto pb-1":t.cn("h-full",!w&&"pt-2")),children:[he&&e.jsxs("div",{className:t.cn("z-10 mb-0 flex items-center",o?"min-w-0 shrink-0 gap-1.5":"min-h-10 gap-2 px-4"),children:[o?Z:null,p&&e.jsx("div",{className:t.cn("flex items-center",o?"shrink-0":"grow gap-4"),children:e.jsx("div",{className:"flex items-center gap-3",children:!h&&!F&&e.jsx(Ca,{selectedChart:x.type,onChartChange:me=>z(me),compactMore:!0,responsiveCompact:o})})}),!p&&!o&&e.jsx("div",{className:"grow"}),e.jsxs("div",{className:t.cn("flex items-center text-muted-foreground",o?"gap-1.5":"gap-2"),children:[s,o?null:Z,Pe&&Pe.length>0&&e.jsxs(a.HoverCard,{openDelay:200,children:[e.jsx(a.HoverCardTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"xs",className:"h-7 gap-1.5 px-2",children:[e.jsx(a.Filter,{className:"h-3.5 w-3.5",strokeWidth:1.75}),e.jsx(a.Badge,{variant:"secondary",className:"h-4 min-w-4 rounded-[4px] px-1 text-[10px] font-medium",children:Pe.length})]})}),e.jsxs(a.HoverCardContent,{align:"end",className:"flex max-h-[400px] w-[500px] flex-col overflow-hidden p-0",children:[e.jsx("div",{className:"shrink-0 border-b border-border px-3 py-2 text-[13px] font-medium",children:"Active Dashboard Filters"}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx(t.CodeEditor,{value:JSON.stringify(Pe,null,2),onValueChange:()=>{},language:"json",readOnly:!0,embedded:!0,wrapLines:!0,dense:!0,hideLineNumbers:!0,ariaLabel:"Active dashboard filters JSON"})})]})]}),!F&&e.jsx("div",{className:o?"hidden @[1250px]:flex":"",children:e.jsx(Sa,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1})}),(n==null?void 0:n.show)&&e.jsxs(t.Button,{type:"button",variant:"ghost",size:"xs","aria-pressed":n.isOpen,onClick:n.onToggle,className:t.cn("h-7 shrink-0 gap-1.5 text-[12px]",o?"hidden w-7 px-0 @[850px]:inline-flex @[1350px]:w-auto @[1350px]:px-2":"px-2",n.isOpen&&"bg-accent text-accent-foreground"),children:[e.jsx(a.Settings2,{className:"h-3.5 w-3.5",strokeWidth:1.75}),e.jsx("span",{className:o?"hidden @[1350px]:inline":"",children:"Settings"})]}),e.jsx(a.IconButton,{tooltip:"Refresh",disabled:$||U,className:t.cn("h-7 w-7 px-0",o&&"hidden @[1150px]:inline-flex"),onClick:Ve,children:e.jsx(Es,{className:t.cn("h-3.5 w-3.5",{"animate-spin":(Ie==null?void 0:Ie.isFetching)??Oe})})}),e.jsxs(a.DropdownMenu,{modal:!1,children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsx(a.IconButton,{tooltip:"More Options",className:"h-7 w-7 px-0","aria-label":"More options",children:e.jsx(a.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(a.DropdownMenuContent,{align:"end",collisionPadding:8,className:"max-h-[var(--radix-dropdown-menu-content-available-height)] w-56 overflow-y-auto overscroll-contain",children:[(o||(c==null?void 0:c.reset))&&e.jsxs(e.Fragment,{children:[o&&e.jsxs(a.DropdownMenuItem,{disabled:$||U,onSelect:Ve,children:[e.jsx(Es,{className:"h-3.5 w-3.5"}),"Refresh result"]}),c==null?void 0:c.reset,e.jsx(a.DropdownMenuSeparator,{})]}),e.jsx(a.DropdownMenuLabel,{children:"Export"}),Ie?e.jsxs(a.DropdownMenuItem,{disabled:$||U||!Ie.hasDelivery,title:Ie.hasDelivery?void 0:"Available once the preview has loaded.",onSelect:()=>Ye(Ie.readDelivery()),className:"gap-2 text-[13px]",children:[e.jsx(a.Download,{className:"h-3.5 w-3.5"}),"Download"]}):e.jsxs(e.Fragment,{children:[e.jsxs(a.DropdownMenuItem,{disabled:!K,onSelect:re,className:"gap-2 text-[13px]",children:[e.jsx(a.Download,{className:"h-3.5 w-3.5"}),"Download CSV"]}),e.jsxs(a.DropdownMenuItem,{disabled:!K,onSelect:Se,className:"gap-2 text-[13px]",children:[e.jsx(Sr,{className:"h-3.5 w-3.5"}),"Download JSON"]}),e.jsxs(a.DropdownMenuItem,{disabled:!K,onSelect:ie,className:"gap-2 text-[13px]",children:[e.jsx(a.Copy,{className:"h-3.5 w-3.5"}),"Copy JSON"]})]}),e.jsx(a.DropdownMenuSeparator,{}),(c==null?void 0:c.query)&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuLabel,{children:"Query"}),c.query,e.jsx(a.DropdownMenuSeparator,{})]}),(o&&(n==null?void 0:n.show)||m||f)&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuLabel,{children:"Output"}),o&&(n==null?void 0:n.show)&&e.jsx(a.DropdownMenuCheckboxItem,{checked:n.isOpen,onCheckedChange:()=>n.onToggle(),children:"Settings"}),(m||f)&&e.jsx(a.DropdownMenuCheckboxItem,{checked:!p,onCheckedChange:me=>j(me!==!0),children:"Show raw results"}),e.jsx(a.DropdownMenuSeparator,{})]}),e.jsx(a.DropdownMenuLabel,{children:"Customize"}),!F&&!["table","detailTable","custom"].includes(x.type)&&N&&e.jsx(Ro,{triggerVariant:"menu",className:"w-full"}),e.jsx(Ps,{triggerVariant:"menu",className:"w-full"}),e.jsx(Os,{triggerVariant:"menu",className:"w-full"}),e.jsx(Rs,{triggerVariant:"menu",className:"w-full"}),M&&e.jsxs(a.DropdownMenuItem,{onSelect:()=>{var me;return(me=n==null?void 0:n.onOpen)==null?void 0:me.call(n,"style")},className:"gap-2 text-[13px]",children:[e.jsx(Mr,{className:"h-3.5 w-3.5"}),"Table settings"]}),e.jsx(a.DropdownMenuSeparator,{}),e.jsx(Ta,{onCustomize:()=>L(!0)})]})]}),_e&&e.jsx(a.ExportDialog,{isOpen:!0,onClose:()=>Ye(void 0),card:x,frame:u,matrix:_e})]})]}),ze&&(p?F?e.jsx(St,{alwaysRenderOverride:!0,renderCardOverride:()=>e.jsx(wa,{fallbackPreview:e.jsx(St,{}),records:ge,title:x.title,isInspectorOpen:E,onInspectorOpenChange:L})}):e.jsx(St,{}):e.jsxs(a.ResizablePanelGroup,{className:t.cn(g&&"py-2 pl-2 pr-6"),direction:"horizontal",children:[g&&e.jsxs(e.Fragment,{children:[e.jsx(a.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:g&&e.jsx(al,{})}),e.jsx(a.ResizableHandle,{})]}),e.jsxs(a.ResizablePanel,{id:"2",order:2,minSize:10,className:t.cn("relative flex h-full min-h-0 w-full flex-1 basis-0",{"py-2 pl-2 pr-6":g}),children:[Array.isArray(Y==null?void 0:Y.records)&&!H&&(m?e.jsx(vo,{data:Y.records,card:q,paginationMetadata:ue,onPaginationChange:Le,onPageSizePreferenceChange:V,onSortChange:De,isLoading:$||U}):Y.records.length>0?e.jsx(a.TableVisual,{card:x,data:ge,resultColumns:Y==null?void 0:Y.columns,columnKeyMap:Y==null?void 0:Y.columnKeyMap,totalsByColumnId:Y==null?void 0:Y.tableTotalsByColumnId,comparisonMetadata:(Re=Y==null?void 0:Y.metadata)==null?void 0:Re.comparisonMetadata,paginationMetadata:ue,onPaginationChange:Le,onSortChange:De,isLoading:$||U}):null),H&&e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto",children:e.jsx(cs,{error:H,errorSql:te||x.sql||x.python,onDebugWithAssistant:be,showFeedbackButton:!1})})]})]}))]})}function al(){const s=t.useEditorStore(r=>r.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(t.ScrollArea,{className:"overflow-y-auto pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function et({value:s,onCommit:n,type:r="text",placeholder:o,className:c}){const[d,i]=v.useState(s),l=v.useRef(!1);v.useEffect(()=>{i(s)},[s]);const u=()=>{if(l.current){l.current=!1;return}d!==s&&n(d)},x=m=>{if(m.key==="Enter"){m.currentTarget.blur();return}m.key==="Escape"&&(l.current=!0,i(s),m.currentTarget.blur())};return e.jsx(t.Input,{type:r,placeholder:o,value:d,onChange:m=>i(m.target.value),onBlur:u,onKeyDown:x,className:c})}function xt({defaultValue:s,label:n,options:r,value:o,onValueChange:c,className:d,icon:i,showPlaceholderLabel:l=!0}){return e.jsxs(t.Select,{defaultValue:s,value:o,onValueChange:c,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",d),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{children:i}),l&&e.jsx(t.SelectValue,{placeholder:n})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:n}),r.map(u=>e.jsx(t.SelectItem,{value:u.value,children:u.label},u.value))]})})]})}function rl(s,n){return xe.getSlotDefinitionForIndex(s,n)||null}function _t(s){if(typeof s=="number")return`Tab ${s+1}`;const n=s.match(/^(\d+)-(\d+)$/);if(n){const[,o,c]=n;return`Tabs ${Number(o)+1}-${Number(c)+1}`}const r=s.match(/^(\d+)\+$/);return r?`Tabs ${Number(r[1])+1}+`:`Tab ${s}`}function ol(s){return s?Array.isArray(s)?s:[s]:[]}function js(s){var o,c;if(!s)return!1;if(s.type==="text")return!!((o=s.description)!=null&&o.trim());const n=!!((c=s.sql)!=null&&c.trim()),r=je.hasValidCardConfig(s.config);return n||r}function ll({slots:s,cards:n,minInputs:r}){const o=[],c=n.filter(Boolean).length;return r&&c<r&&o.push({type:"too-few-inputs",message:`This visual requires at least ${r} tab${r===1?"":"s"}.`}),!s||s.length===0||(s.forEach(d=>{if(!d.required)return;if(typeof d.position=="number"){const u=n[d.position];js(u)||o.push({type:"missing-required",message:`${_t(d.position)} ("${d.label}") is required but has no data configured.`});return}const i=d.position.match(/^(\d+)-(\d+)$/);if(i){const[,u,x]=i.map(Number);for(let m=u;m<=x;m+=1){const b=n[m];if(!js(b)){o.push({type:"missing-required",message:`${_t(m)} ("${d.label}") is required but has no data configured.`});break}}return}const l=d.position.match(/^(\d+)\+$/);if(l){const u=Number(l[1]);if(n.length<=u){o.push({type:"missing-required",message:`${_t(u)} ("${d.label}") is required but has no data configured.`});return}for(let x=u;x<n.length;x+=1){const m=n[x];if(!js(m)){o.push({type:"missing-required",message:`${_t(x)} ("${d.label}") is required but has no data configured.`});break}}}}),n.forEach((d,i)=>{if(!d)return;const l=rl(s,i);if(!l||!l.expectedType)return;const u=ol(l.expectedType);u.length!==0&&(u.includes(d.type)||o.push({type:"wrong-type",message:`${_t(i)} ("${l.label}") expects ${u.join(", ")}, but is configured as ${d.type}.`}))})),o}const il={table:({children:s})=>e.jsx("table",{className:"my-3 w-full border-collapse overflow-hidden rounded-md border border-border text-sm",children:s}),thead:({children:s})=>e.jsx("thead",{className:"bg-muted",children:s}),th:({children:s})=>e.jsx("th",{className:"border border-border px-3 py-2 text-left font-medium",children:s}),td:({children:s})=>e.jsx("td",{className:"border border-border px-3 py-2",children:s}),code:({children:s,className:n})=>(n==null?void 0:n.includes("language-"))?e.jsx("pre",{className:"my-3 overflow-x-auto rounded-md bg-muted p-3 text-xs",children:e.jsx("code",{children:s})}):e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:s}),pre:({children:s})=>e.jsx(e.Fragment,{children:s})};function Ia(){var L,T,R;const s=t.useEditorStore(y=>y.card.customCardPreferences),{data:n}=a.usePluginQuery(),r=(n==null?void 0:n.plugins)||[],o=t.useEditorStore(y=>y.card),c=t.useEditorStore(y=>y.frame),{setCustomCardPreferences:d}=t.useEditorActions(),i=v.useMemo(()=>xe.findCustomVisualConfigCard(c,o),[c,o]),l=i==null?void 0:i.customCardPreferences,{components:u,manifest:x}=a.useCustomVisual((l==null?void 0:l.url)||(s==null?void 0:s.url)||""),m=(L=x==null?void 0:x.visuals)==null?void 0:L.find(y=>y.name===((l==null?void 0:l.componentName)||(s==null?void 0:s.componentName))),h=xe.resolveMultiInputType(i||o,m)==="multiple",p=!!i&&i.id===o.id,j=(m==null?void 0:m.minInputs)??((T=i==null?void 0:i.customCardPreferences)==null?void 0:T.minInputs),N=(m==null?void 0:m.maxInputs)??((R=i==null?void 0:i.customCardPreferences)==null?void 0:R.maxInputs),f=v.useMemo(()=>xe.getCustomVisualInputCards({frame:c,configCard:i||o,isMultiInputVisual:h}),[c,i,o,h]),g=v.useMemo(()=>xe.buildSlotOrderedCards(f),[f]),k=v.useMemo(()=>g.map((y,B)=>{if(!y)return null;const P=xe.getSlotIndexForCard(y,B),O=xe.getEffectiveCardTypeForSlot(y,P,m==null?void 0:m.slots);return{...y,type:O??y.type}}),[g,m==null?void 0:m.slots]),D=v.useMemo(()=>ll({slots:m==null?void 0:m.slots,cards:k,minInputs:j}),[m==null?void 0:m.slots,k,j]),w=v.useMemo(()=>{const y=f.findIndex(B=>(B==null?void 0:B.id)===o.id);return y<0?-1:xe.getSlotIndexForCard(o,y)},[f,o]);function S(y){if(typeof y=="number")return`Tab ${y+1}`;const B=y.match(/^(\d+)-(\d+)$/);if(B){const[,O,V]=B;return`Tabs ${Number(O)+1}-${Number(V)+1}`}const P=y.match(/^(\d+)\+$/);return P?`Tabs ${Number(P[1])+1}+`:`Tab ${y}`}function M(y){return y?(Array.isArray(y)?y:[y]).join(", "):null}function A(y,B,P=[],O="",V,_,z){const q=F({key:B,defaultValue:O,settingsValue:_,sourceCard:z});return y==="input"?e.jsx(et,{className:`h-8 w-full ${t.removeRing}`,value:String(q??""),onCommit:Y=>{I({key:B,value:Y,settingsField:V,settingsValue:_,sourceCard:z})}},B):y==="select"?e.jsx(xt,{className:"h-8 w-full",label:"",options:P,value:String(q!==void 0?q:O??""),onValueChange:Y=>{I({key:B,value:Y,settingsField:V,settingsValue:_,sourceCard:z})}}):null}function F({key:y,defaultValue:B,settingsValue:P,sourceCard:O}){const V=P==null?void 0:P[y];return V!==void 0?V:y==="title"&&(O==null?void 0:O.title)!==void 0?O.title:y==="description"&&(O==null?void 0:O.description)!==void 0?O.description:B}function I({key:y,value:B,settingsField:P,settingsValue:O,sourceCard:V}){const _={...O||{}},z=y==="title"&&(V==null?void 0:V.title)!==void 0,q=y==="description"&&(V==null?void 0:V.description)!==void 0;z&&B===String((V==null?void 0:V.title)??"")||q&&B===String((V==null?void 0:V.description)??"")?delete _[y]:_[y]=B,d({...s||{},[P]:_})}function C({settingsSchema:y,settingsField:B,settingsValue:P,sourceCard:O,headerLabel:V}){const _=Object.entries(y||{});return e.jsxs("div",{className:"space-y-3",children:[V&&e.jsx(t.Label,{children:V}),_.map(([z,q])=>{var Y;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{children:q.title}),((Y=q.docs)==null?void 0:Y.description)&&e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx(t.Info,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground"})}),e.jsx(t.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsx("p",{className:"text-xs",children:q.docs.description})})]})})]}),A(q.ui,z,q.options,q.defaultValue,B,P,O)]},z)})]})}function E(){return e.jsxs(e.Fragment,{children:[h&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Slot Guide"}),e.jsx("div",{className:"space-y-3 rounded-md border border-border bg-muted/40 px-3 py-2 text-xs",children:m!=null&&m.slots&&m.slots.length>0?e.jsx("div",{className:"space-y-3",children:m.slots.map((y,B)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-foreground",children:[e.jsx("span",{className:"font-medium",children:S(y.position)}),e.jsx("span",{className:"text-muted-foreground",children:"•"}),e.jsx("span",{className:"font-medium",children:y.label})]}),y.description&&e.jsx("p",{className:"text-muted-foreground",children:y.description}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-muted-foreground",children:[M(y.expectedType)&&e.jsxs("span",{children:["Expected: ",M(y.expectedType)]}),y.required&&e.jsx("span",{children:"Required"})]})]},`${y.label}-${B}`))}):e.jsxs("div",{className:"space-y-1 text-muted-foreground",children:[e.jsx("p",{children:"This visual renders all tabs in a flexible layout. Add as many tabs as needed."}),(j||N)&&e.jsxs("p",{children:[j?`Min ${j} tabs`:"",j&&N?" • ":"",N?`Max ${N} tabs`:""]})]})})]}),h&&D.length>0&&e.jsx(a.Alert,{className:"mt-3 border-yellow-500/40 bg-yellow-500/10 text-yellow-900 dark:text-yellow-100",children:e.jsx(a.AlertDescription,{children:e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs",children:D.map((y,B)=>e.jsx("li",{children:y.message},`${y.type}-${B}`))})})}),m&&!h&&m.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:C({settingsSchema:m.settings,settingsField:"settings",settingsValue:s==null?void 0:s.settings,sourceCard:o})})}),m&&h&&(m.settings||m.slotSettings)&&e.jsxs("div",{className:"mt-4 space-y-4",children:[p&&m.settings&&e.jsx("div",{className:"px-2",children:C({settingsSchema:m.settings,settingsField:"settings",settingsValue:s==null?void 0:s.settings,sourceCard:i||o,headerLabel:"Global Settings"})}),m.slotSettings&&e.jsx("div",{className:"px-2",children:C({settingsSchema:m.slotSettings,settingsField:"slotSettings",settingsValue:s==null?void 0:s.slotSettings,sourceCard:o,headerLabel:(()=>{const y=o.tabTitle||o.title,B=w>=0?w:0,P=p?"Slot 0":`Slot ${B}`;return y?`${P}: ${y} Settings`:`${P} Settings`})()})})]})]})}return e.jsxs(a.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"",children:[e.jsxs(a.AccordionItem,{value:"plugin-settings",children:[e.jsx(a.AccordionTrigger,{children:"Plugin"}),e.jsx(a.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[(!h||p)&&e.jsx(xt,{icon:e.jsx(ra,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:r,value:(l==null?void 0:l.url)||"",onValueChange:y=>d({...s||{url:"",componentName:""},url:y})}),h&&!p&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Switch to the config tab to change the plugin or component."})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&(!h||p)&&e.jsx(e.Fragment,{children:u&&e.jsx(xt,{icon:e.jsx(Cr,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(u==null?void 0:u.map(y=>({value:y.name,label:y.name})))||[],value:s.componentName||"",onValueChange:y=>{var O;const B=(O=x==null?void 0:x.visuals)==null?void 0:O.find(V=>V.name===y),P=u==null?void 0:u.find(V=>V.name===y);d({...s,componentName:y,visualType:(B==null?void 0:B.visualType)||(P==null?void 0:P.type)||"single",minInputs:B==null?void 0:B.minInputs,maxInputs:B==null?void 0:B.maxInputs,pluginChartType:B==null?void 0:B.chartType})}})})]})})]}),((l==null?void 0:l.componentName)||(s==null?void 0:s.componentName))&&e.jsxs(a.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(a.AccordionTrigger,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:(m==null?void 0:m.name)||"Settings"}),(m==null?void 0:m.docs)&&e.jsxs(a.HoverCard,{openDelay:0,closeDelay:100,children:[e.jsx(a.HoverCardTrigger,{asChild:!0,onClick:y=>y.stopPropagation(),children:e.jsx(t.Info,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground transition-colors hover:text-foreground"})}),e.jsx(a.HoverCardContent,{side:"right",align:"start",className:"max-h-[40vh] w-[500px] overflow-y-auto text-left",children:e.jsxs("div",{className:"space-y-4 text-left",children:[m.docs.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m.docs.description}),m.docs.dataSchema&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Data Schema"}),e.jsx("div",{className:"prose prose-sm dark:prose-invert prose-pre:bg-muted prose-pre:text-xs max-w-none",children:e.jsx(a.Markdown,{remarkPlugins:[a.remarkGfm],components:il,children:m.docs.dataSchema})})]}),(()=>{var B;const y=(B=m.docs)==null?void 0:B.useCases;return!y||y.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Use Cases"}),e.jsx("ul",{className:"space-y-1 text-sm",children:y.map((P,O)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-1 text-primary",children:"•"}),e.jsx("span",{children:P})]},O))})]})})()]})})]})]})}),e.jsx(a.AccordionContent,{children:E()})]})]})}function is(s){return s==="currency"?2:s==="percent"?1:s==="scientific"?2:0}function Da(s,n,r){if(!n||n==="auto")return{type:"auto"};if(n==="duration")return{type:"duration",multiplyBy:void 0,percentValueMode:void 0,durationInputUnit:s.durationInputUnit||"second",durationDisplayStyle:s.durationDisplayStyle||"compact",durationLargestUnit:s.durationLargestUnit||"day",durationSmallestUnit:s.durationSmallestUnit||"second",durationMaxUnits:s.durationMaxUnits};const o={...s,type:n,multiplyBy:n==="percent"?s.multiplyBy:void 0,percentValueMode:n==="percent"?s.percentValueMode:void 0,durationInputUnit:void 0,durationDisplayStyle:void 0,durationLargestUnit:void 0,durationSmallestUnit:void 0,durationMaxUnits:void 0};return n&&["number","currency","percent","scientific"].includes(n)&&s.decimalPlaces===void 0&&s.minimumFractionDigits===void 0&&s.maximumFractionDigits===void 0&&!(n==="currency"&&(r!=null&&r.preserveSparseCurrency))?ka(o,is(n)):o}function cl(s,n){return{...s,decimalPlaces:void 0,minimumFractionDigits:n,maximumFractionDigits:n}}function Yn(s){const n=s.decimalPlaces;return{...s,currency:void 0,decimalPlaces:void 0,minimumFractionDigits:s.minimumFractionDigits??n,maximumFractionDigits:s.maximumFractionDigits??n}}function dl(s,n){const r=s.type||"auto";return r==="auto"?s:r==="duration"?{type:"duration",prefix:s.prefix,suffix:s.suffix,negativeInParentheses:s.negativeInParentheses,durationInputUnit:s.durationInputUnit||"second",durationDisplayStyle:s.durationDisplayStyle||"compact",durationLargestUnit:s.durationLargestUnit||"day",durationSmallestUnit:s.durationSmallestUnit||"second",durationMaxUnits:s.durationMaxUnits}:Da(s,r,n)}function ka(s,n){return{...s,decimalPlaces:n,minimumFractionDigits:n,maximumFractionDigits:n}}const At="__report_default__",ul=["auto","number","currency","percent","scientific","date","duration"],zn=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"GBP",label:"GBP - British Pound"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"CHF",label:"CHF - Swiss Franc"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"},{value:"HKD",label:"HKD - Hong Kong Dollar"},{value:"SGD",label:"SGD - Singapore Dollar"},{value:"NZD",label:"NZD - New Zealand Dollar"},{value:"SEK",label:"SEK - Swedish Krona"},{value:"NOK",label:"NOK - Norwegian Krone"},{value:"DKK",label:"DKK - Danish Krone"},{value:"KRW",label:"KRW - South Korean Won"},{value:"INR",label:"INR - Indian Rupee"},{value:"RUB",label:"RUB - Russian Ruble"},{value:"BRL",label:"BRL - Brazilian Real"},{value:"MXN",label:"MXN - Mexican Peso"},{value:"TRY",label:"TRY - Turkish Lira"},{value:"ZAR",label:"ZAR - South African Rand"},{value:"SAR",label:"SAR - Saudi Riyal"},{value:"AED",label:"AED - UAE Dirham"},{value:"ARS",label:"ARS - Argentine Peso"},{value:"CLP",label:"CLP - Chilean Peso"},{value:"COP",label:"COP - Colombian Peso"},{value:"THB",label:"THB - Thai Baht"},{value:"IDR",label:"IDR - Indonesian Rupiah"},{value:"MYR",label:"MYR - Malaysian Ringgit"},{value:"PHP",label:"PHP - Philippine Peso"},{value:"PLN",label:"PLN - Polish Zloty"},{value:"NGN",label:"NGN - Nigerian Naira"},{value:"KES",label:"KES - Kenyan Shilling"},{value:"GHS",label:"GHS - Ghanaian Cedi"},{value:"ZMW",label:"ZMW - Zambian Kwacha"},{value:"ZWL",label:"ZWL - Zimbabwean Dollar"},{value:"EGP",label:"EGP - Egyptian Pound"},{value:"MAD",label:"MAD - Moroccan Dirham"},{value:"UAH",label:"UAH - Ukrainian Hryvnia"},{value:"HUF",label:"HUF - Hungarian Forint"},{value:"CZK",label:"CZK - Czech Koruna"},{value:"RON",label:"RON - Romanian Leu"},{value:"PKR",label:"PKR - Pakistani Rupee"},{value:"BDT",label:"BDT - Bangladeshi Taka"},{value:"VND",label:"VND - Vietnamese Dong"},{value:"TWD",label:"TWD - New Taiwan Dollar"},{value:"ILS",label:"ILS - Israeli New Shekel"}],qn=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"en-IN",label:"English (India)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"},{value:"ja-JP",label:"Japanese"},{value:"ko-KR",label:"Korean"},{value:"ru-RU",label:"Russian"},{value:"ar-SA",label:"Arabic"},{value:"hi-IN",label:"Hindi"},{value:"nl-NL",label:"Dutch"},{value:"sv-SE",label:"Swedish"}],vs=[{value:"millisecond",label:"Milliseconds"},{value:"second",label:"Seconds"},{value:"minute",label:"Minutes"},{value:"hour",label:"Hours"},{value:"day",label:"Days"}],ml=[{value:"compact",label:"Compact (6min 32s)"},{value:"digital",label:"Digital (6:32)"},{value:"long",label:"Long (6 minutes 32 seconds)"}],xl=s=>s.charAt(0).toUpperCase()+s.slice(1);function hl(s,n){try{return sa.resolveCurrencyFractionDigits(s,n).maximumFractionDigits??is("currency")}catch{return is("currency")}}function Kt({formatOptions:s={},onFormatOptionsChange:n,showTitle:r=!0,title:o="NUMBER FORMAT",maxDecimalPlaces:c=10,reportDefaults:d,showAutoFormat:i=!0,showLocaleOverride:l=!0}){var E,L;const u=s.type||"auto",x=dl(s,{preserveSparseCurrency:!!d}),m=T=>{T.stopPropagation()},b=(T,R)=>{n({...x,[T]:R})},h=x.decimalPlaces??x.maximumFractionDigits??x.minimumFractionDigits,p=s.currency??(d==null?void 0:d.currency)??"USD",j=s.locale??(d==null?void 0:d.locale)??"en-US",N=u==="currency"?hl(j,p):void 0,f=h??N??is(u),g=u==="currency"&&x.decimalPlaces===void 0&&x.minimumFractionDigits===void 0&&x.maximumFractionDigits===void 0,[k,D]=v.useState(()=>String(f)),[w,S]=v.useState(()=>x.multiplyBy!==void 0?String(x.multiplyBy):""),M=T=>{const R=Da(s,T,{preserveSparseCurrency:!!d});n(d&&T==="currency"&&s.type!=="currency"?Yn(R):R)},A=T=>d&&u==="currency"?cl(x,T):ka(x,T),F=((E=zn.find(T=>T.value===(d==null?void 0:d.currency)))==null?void 0:E.label)??(d==null?void 0:d.currency),I=((L=qn.find(T=>T.value===(d==null?void 0:d.locale)))==null?void 0:L.label)??(d==null?void 0:d.locale),C=u==="number"||u==="currency"||u==="percent"||u==="scientific";return v.useEffect(()=>{D(String(f))},[f]),v.useEffect(()=>{S(x.multiplyBy!==void 0?String(x.multiplyBy):"")},[x.multiplyBy]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[r&&e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:o}),e.jsxs(t.Select,{value:u,onValueChange:T=>M(T),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ul.filter(T=>i||T!=="auto").map(T=>e.jsx(t.SelectItem,{value:T,className:"text-xs",children:T==="auto"?"Auto (Default)":xl(T)},T))})]})]}),u!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent","scientific"].includes(u)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Decimals"}),e.jsxs("div",{className:"flex-1",children:[e.jsx(t.Input,{type:"text",inputMode:"numeric",min:"0",max:c,placeholder:"0",value:k,onClick:m,onPointerDown:m,onKeyDown:m,onChange:T=>{const R=T.target.value.replace(/[^\d]/g,"");D(R),R!==""&&n(A(Math.max(0,Math.min(c,parseInt(R,10)))))},onBlur:()=>{if(k!=="")return;const T=f;D(String(T)),n(A(T))},className:"h-8 text-xs"}),g&&e.jsx("p",{className:"mt-1 text-[10px] text-muted-foreground",children:"Currency default"})]})]}),u==="currency"&&e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Currency"}),e.jsxs(t.Select,{value:s.currency||(d?At:"USD"),onValueChange:T=>{if(T===At){n(Yn(x));return}b("currency",T)},children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[d&&e.jsxs(t.SelectItem,{value:At,className:"text-xs",children:["Report default — ",F]}),zn.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))]})]})]})}),["number","currency"].includes(u)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(t.Switch,{size:"sm",checked:s.useSuffix??!1,onClick:T=>T.stopPropagation(),onCheckedChange:T=>b("useSuffix",T)})]}),l&&u!=="duration"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Locale"}),e.jsxs(t.Select,{value:s.locale||(d&&C?At:"en-US"),onValueChange:T=>b("locale",T===At?void 0:T),children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[d&&C&&e.jsxs(t.SelectItem,{value:At,className:"text-xs",children:["Report default — ",I]}),qn.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))]})]})]}),u==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Prefix"}),e.jsx("div",{className:"flex-1",children:e.jsx(t.Input,{placeholder:"e.g., $",value:s.prefix||"",onClick:m,onPointerDown:m,onKeyDown:m,onChange:T=>b("prefix",T.target.value),className:"h-8 text-xs"})})]}),u==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Suffix"}),e.jsx("div",{className:"flex-1",children:e.jsx(t.Input,{placeholder:"e.g., units",value:s.suffix||"",onClick:m,onPointerDown:m,onKeyDown:m,onChange:T=>b("suffix",T.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(u)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Negative in ()"}),e.jsx(t.Switch,{size:"sm",checked:s.negativeInParentheses??!1,onClick:T=>T.stopPropagation(),onCheckedChange:T=>b("negativeInParentheses",T)})]}),u==="percent"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Multiply By"}),e.jsx("div",{className:"flex-1",children:e.jsx(t.Input,{type:"text",inputMode:"decimal",placeholder:"100",value:w,onClick:m,onPointerDown:m,onKeyDown:m,onChange:T=>{const R=T.target.value.replace(/[^0-9.]/g,"");S(R),b("multiplyBy",R?parseFloat(R):void 0)},className:"h-8 text-xs"})})]}),u==="date"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Format"}),e.jsx("div",{className:"flex-1",children:e.jsx(t.Input,{type:"text",placeholder:"MM/DD/YYYY",value:s.dateFormat||"",onClick:m,onPointerDown:m,onKeyDown:m,onChange:T=>b("dateFormat",T.target.value),className:"h-8 text-xs"})})]}),u==="duration"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Value Is"}),e.jsxs(t.Select,{value:s.durationInputUnit||"second",onValueChange:T=>b("durationInputUnit",T),children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:vs.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Display"}),e.jsxs(t.Select,{value:s.durationDisplayStyle||"compact",onValueChange:T=>b("durationDisplayStyle",T),children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ml.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Smallest"}),e.jsxs(t.Select,{value:s.durationSmallestUnit||"second",onValueChange:T=>b("durationSmallestUnit",T),children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:vs.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-20 text-xs text-muted-foreground",children:"Largest"}),e.jsxs(t.Select,{value:s.durationLargestUnit||"day",onValueChange:T=>b("durationLargestUnit",T),children:[e.jsx(t.SelectTrigger,{className:"h-8 flex-1 text-xs",onClick:m,onPointerDown:m,onKeyDown:m,children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:vs.map(T=>e.jsx(t.SelectItem,{value:T.value,className:"text-xs",children:T.label},T.value))})]})]})]})]})]})}function $n({colorRanges:s,setColorRanges:n}){const r={start:-1/0,end:100,color:""};function o(i,l,u){const x=[...s];x[i]={...x[i],[l]:u},n(x)}function c(i){const l=[...s];l.splice(i,1),n(l)}function d(){n([...s,r])}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{children:"Color Range"}),e.jsx(t.Button,{onClick:d,variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(a.Plus,{className:"size-3"})})]}),s.map((i,l)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(t.Input,{onChange:u=>o(l,"start",u.target.value),value:i.start,className:t.cn(`h-7 ${t.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(t.Input,{value:i.end,onChange:u=>o(l,"end",u.target.value),className:t.cn(`h-7 ${t.removeRing}`)}),e.jsx(t.Input,{onChange:u=>o(l,"color",u.target.value),value:i.color,className:t.cn(`h-7 min-w-14 p-0 ${t.removeRing}`),type:"color",list:"presetColors"}),e.jsxs("datalist",{id:"presetColors",children:[e.jsx("option",{children:je.colors.green[600]}),e.jsx("option",{children:je.colors.red[500]}),e.jsx("option",{children:je.colors.yellow[400]}),e.jsx("option",{children:je.colors.orange[500]})]}),e.jsx(t.Button,{onClick:()=>c(l),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(le.X,{className:"size-3"})})]},l))]})}const pl=[];function fl(s){return(s==null?void 0:s.enabled)===!1||typeof(s==null?void 0:s.enabled)=="string"&&s.enabled.trim().toLowerCase()==="false"}function gl(s){var r;const n=t.fromPersistedKpiFormatOptions((r=s==null?void 0:s.kpiVisualOptions)==null?void 0:r.formatOptions)||(s!=null&&s.formatNumber?t.fromLegacyFormatNumber(s==null?void 0:s.formatNumber):void 0);return t.toTFormatOptions(n,{preserveOmittedProperties:!0})||{type:"number",minimumFractionDigits:0,maximumFractionDigits:0}}function Kn(s){return{enabled:!0,colorRanges:s==null?void 0:s.colorRanges}}function bl(){var h,p,j,N;const s=t.useEditorStore(f=>f.card),n=t.useEditorStore(f=>f.actions.setCardPreferences),r=t.useEditorStore(f=>{var g,k;return((k=(g=f.card.preferences)==null?void 0:g.formatNumber)==null?void 0:k.colorRanges)??pl}),o=t.useEditorStore(f=>f.actions.setColorRanges),c=a.useResolvedValueFormatLocale()??$t.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES.locale,d=a.useResolvedDefaultCurrency()??$t.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES.defaultCurrency,i=!a.isSqlBackedKpi(s)&&je.hasValidCardConfig(s.config),l=gl(s.preferences),u=!!t.fromPersistedKpiFormatOptions((p=(h=s.preferences)==null?void 0:h.kpiVisualOptions)==null?void 0:p.formatOptions),x=!fl((j=s.preferences)==null?void 0:j.formatNumber)&&(u||!!((N=s.preferences)!=null&&N.formatNumber)),m=f=>{const g=t.useEditorStore.getState().card.preferences??{};n({...g,formatNumber:Kn(g.formatNumber),kpiVisualOptions:{...g.kpiVisualOptions,formatOptions:f}})},b=f=>{const g=t.useEditorStore.getState().card.preferences??{};if(f){n({...g,formatNumber:Kn(g.formatNumber),kpiVisualOptions:{...g.kpiVisualOptions,formatOptions:l}});return}n({...g,formatNumber:{...g.formatNumber,enabled:!1}})};return i?e.jsx($n,{colorRanges:r,setColorRanges:o}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(a.Checkbox,{id:"query-kpi-format-number",checked:x,onCheckedChange:f=>b(f===!0)}),e.jsx(t.Label,{htmlFor:"query-kpi-format-number",className:"text-xs",children:"Format number"})]}),x&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Kt,{formatOptions:l,onFormatOptionsChange:m,showTitle:!1,showAutoFormat:!1,reportDefaults:{currency:d,locale:c}}),e.jsx(t.Separator,{className:"my-3"}),e.jsx($n,{colorRanges:r,setColorRanges:o})]})]})}const jl={combo:{label:"Combo Chart",query:"SELECT x-axis, metric-1, metric-2, ... FROM table",fields:[{name:"x-axis",type:"category",description:"dimension"},{name:"metric-1, metric-2",type:"number",description:"can be bar, line, or area"}],description:"Combo charts allow mixing bar and line series with optional dual Y-axis for metrics with different scales.",docsUrl:"https://docs.semaphor.cloud/docs/charts/combo"},area:{label:"Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Area charts display quantitative data with filled areas under the line.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedArea:{label:"Stacked Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Stacked area charts show how multiple series contribute to a total over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},bar:{label:"Bar Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., city, product"},{name:"Y-axis",type:"number",description:"e.g., sales, count"}],description:"Bar charts compare values across categories using horizontal or vertical bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},line:{label:"Line Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, month"},{name:"Y-axis",type:"number",description:"e.g., revenue, count"}],description:"Line charts show trends over time or continuous data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedBar:{label:"Stacked Bar Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., month"},{name:"Stack-by",type:"category",description:"e.g., product type"},{name:"Y-axis",type:"number",description:"e.g., sales"}],description:"Stacked bar charts show how parts contribute to a whole across categories.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},stackedLine:{label:"Stacked Line Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date"},{name:"Stack-by",type:"category",description:"e.g., region"},{name:"Y-axis",type:"number",description:"e.g., revenue"}],description:"Stacked line charts show cumulative trends over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},pie:{label:"Pie Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Pie charts show proportions of a whole.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},doughnut:{label:"Doughnut Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Doughnut charts show proportions with a hollow center.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},polarArea:{label:"Polar Area Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., skill, metric"},{name:"Measure",type:"number",description:"e.g., score, value"}],description:"Polar area charts compare values using sectors of equal angle but varying radius.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},radar:{label:"Radar Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., attribute, skill"},{name:"Measure",type:"number",description:"e.g., score, rating"}],description:"Radar charts display multivariate data on axes starting from the same point.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},funnel:{label:"Funnel Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., stage name"},{name:"Measure",type:"number",description:"e.g., count, value"}],description:"Funnel charts visualize progressive reduction of data through stages.",docsUrl:"https://docs.semaphor.cloud/docs/charts/funnel"},bubble:{label:"Bubble Chart",query:"SELECT label, [group], x-axis, y-axis, radius FROM table",fields:[{name:"Label",type:"category",description:"e.g., city"},{name:"Group",type:"category",description:"e.g., region",optional:!0},{name:"X-axis",type:"number",description:"e.g., population"},{name:"Y-axis",type:"number",description:"e.g., income"},{name:"Radius",type:"number",description:"e.g., area"}],description:"Bubble charts display three dimensions of data using position and size.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},scatter:{label:"Scatter Chart",query:"SELECT label, [group], x-axis, y-axis FROM table",fields:[{name:"Label",type:"category",description:"e.g., item name"},{name:"Group",type:"category",description:"e.g., type",optional:!0},{name:"X-axis",type:"number",description:"e.g., price"},{name:"Y-axis",type:"number",description:"e.g., quantity"}],description:"Scatter charts show relationships between two numeric variables.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},tornado:{label:"Tornado Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Tornado charts compare two groups across categories using back-to-back bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},pyramid:{label:"Pyramid Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Population pyramids show age and gender distribution.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},range:{label:"Range Chart",query:"SELECT y-axis, label, range-from, range-to, range-value FROM table",fields:[{name:"Y-axis",type:"category",description:"e.g., category"},{name:"Label",type:"category",description:"e.g., range name"},{name:"Range-from",type:"number",description:"start value"},{name:"Range-to",type:"number",description:"end value"},{name:"Range-value",type:"number",description:"e.g., midpoint"}],description:"Range charts display data ranges with start and end values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/range"},heatmap:{label:"Heatmap",query:"SELECT x-axis, y-axis, value FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., day"},{name:"Y-axis",type:"category",description:"e.g., hour"},{name:"Value",type:"number",description:"e.g., count, intensity"}],description:"Heatmaps visualize data density using color intensity.",docsUrl:"https://docs.semaphor.cloud/docs/charts/heatmap"},bullet:{label:"Bullet Chart",query:"SELECT label, actual, target, [ranges] FROM table",fields:[{name:"Label",type:"category",description:"e.g., metric name"},{name:"Actual",type:"number",description:"current value"},{name:"Target",type:"number",description:"goal value"},{name:"Ranges",type:"number",description:"threshold values",optional:!0}],description:"Bullet charts compare actual performance against targets.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bullet"},text:{label:"Text Visual",query:"SELECT text FROM table LIMIT 1",fields:[{name:"Text",type:"string",description:"content to display"}],description:"Text visuals display dynamic text content from your data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/text"},kpi:{label:"KPI",query:"SELECT current, previous FROM table",fields:[{name:"Current",type:"number",description:"current value"},{name:"Previous",type:"number",description:"comparison value"}],description:"KPI visuals display key performance indicators with comparison values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/kpi"},map:{label:"Map Chart",query:"SELECT country, value FROM table",fields:[{name:"Country/Region",type:"category",description:"geographic identifier"},{name:"Value",type:"number",description:"e.g., population, sales"}],description:"Map charts visualize geographic data using color intensity.",docsUrl:"https://docs.semaphor.cloud/docs/charts/map"},table:{label:"Table",query:"SELECT column1, column2, ... FROM table",fields:[{name:"Columns",type:"category",description:"any data columns"}],description:"Tables display data in rows and columns.",docsUrl:"https://docs.semaphor.cloud/docs/charts/table"},detailTable:{label:"Detail Table",query:"SELECT column1, column2, ... FROM table ORDER BY column1 DESC",fields:[{name:"Columns",type:"category",description:"columns to display (no aggregation)"}],description:"Detail tables display raw records without aggregation. Ideal for event logs, transaction history, and audit trails.",docsUrl:"https://docs.semaphor.cloud/docs/charts/detail-table"}};function Ma(s){return jl[s]}function vl({chartType:s,showDocsLink:n=!0}){const r=Ma(s);return r?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Query Format"}),e.jsx("code",{className:"block rounded-md bg-muted/50 px-3 py-2 font-mono text-xs text-foreground",children:r.query})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("div",{className:"rounded-md border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Field"}),e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Description"})]})}),e.jsx("tbody",{children:r.fields.map((o,c)=>e.jsxs("tr",{className:c<r.fields.length-1?"border-b":"",children:[e.jsxs("td",{className:"px-2.5 py-1.5 font-medium text-foreground",children:[o.name,o.optional&&e.jsx("span",{className:"ml-1 text-muted-foreground",children:"?"})]}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-muted-foreground",children:o.type}),e.jsx("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:o.description||"—"})]},o.name))})]})})]}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:r.description}),n&&r.docsUrl&&e.jsxs("a",{href:r.docsUrl,target:"_blank",rel:"noopener noreferrer",onClick:o=>o.stopPropagation(),className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline",children:["View documentation",e.jsx(a.ExternalLink,{className:"h-3 w-3"})]})]}):null}function yl({chartType:s}){return Ma(s)?e.jsxs(a.HoverCard,{openDelay:200,children:[e.jsx(a.HoverCardTrigger,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded bg-muted px-2 py-0.5 font-mono text-[10px] font-semibold uppercase tracking-wider text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground",children:"SQL"})}),e.jsx(a.HoverCardContent,{className:"w-80 p-4",side:"left",align:"start",sideOffset:8,children:e.jsx(vl,{chartType:s})})]}):null}function Vs({chartType:s,suffix:n="Configuration"}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xs font-medium",children:n}),e.jsx(yl,{chartType:s})]})}function Cl(){const s=t.useEditorStore(c=>!je.hasValidCardConfig(c.card.config)),n=t.useEditorStore(c=>{var d,i;return((i=(d=c.card.preferences)==null?void 0:d.kpiVisualOptions)==null?void 0:i.queryComparisonPolarity)??In.DEFAULT_METRIC_COMPARISON_POLARITY}),r=t.useEditorStore(c=>c.actions.setCardPreferences),o=c=>{const d=t.useEditorStore.getState().card.preferences??{},i={...d.kpiVisualOptions,queryComparisonPolarity:c===In.DEFAULT_METRIC_COMPARISON_POLARITY?void 0:c};r({...d,kpiVisualOptions:i})};return e.jsxs("div",{className:"space-y-6 px-6 py-4",children:[e.jsx(Vs,{chartType:"kpi"}),e.jsx("section",{children:e.jsx(bl,{})}),s&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx(t.Label,{htmlFor:"query-kpi-favorable-direction",className:"text-xs",children:"Favorable direction"}),e.jsxs(t.Select,{value:n,onValueChange:c=>o(c),children:[e.jsx(t.SelectTrigger,{id:"query-kpi-favorable-direction",className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"higher_is_better",children:"Higher is better"}),e.jsx(t.SelectItem,{value:"lower_is_better",children:"Lower is better"}),e.jsx(t.SelectItem,{value:"neutral",children:"Neutral"})]})]}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Applies when the query returns current and comparison values."})]})]})}function Un({children:s,summary:n,open:r,className:o}){return e.jsxs("details",{open:r,className:t.cn("space-y-4 [&_summary>svg]:open:-rotate-180",o),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(t.Label,{children:n}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function Nl(){const[s,n]=v.useState([]),r=t.useEditorStore(x=>x.card.preferences),{setFilterOnClickColumnIndex:o,setCardPreferences:c}=t.useEditorStore(x=>x.actions),d=t.useEditorStore(x=>x.queryResultColumns);t.useEditorStore(x=>{var m;return(m=x.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),v.useEffect(()=>{d&&n(new Array(d.length).fill(!1))},[d]);function i(x,m){var b,h;m?r!=null&&r.onClickFilter&&((b=r==null?void 0:r.onClickFilter)==null?void 0:b.length)>0?c({...r,onClickFilter:[...r.onClickFilter,{columnIndex:x,expression:""}]}):c({...r,onClickFilter:[{columnIndex:x,expression:""}]}):(c({...r,onClickFilter:(h=r==null?void 0:r.onClickFilter)==null?void 0:h.filter(p=>p.columnIndex!==x)}),n(p=>{const j=[...p];return j[x]=!1,j}))}function l(x,m){var h;const b=(h=r==null?void 0:r.onClickFilter)==null?void 0:h.map(p=>p.columnIndex===x?{...p,expression:m.target.value}:p);c({...r,onClickFilter:b})}function u(x){var m,b,h,p;if(s!=null&&s[x]||(b=(m=r==null?void 0:r.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===x))!=null&&b.expression)return e.jsx(t.Input,{value:(p=(h=r==null?void 0:r.onClickFilter)==null?void 0:h.find(j=>j.columnIndex===x))==null?void 0:p.expression,onChange:j=>l(x,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsx("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:d==null?void 0:d.map((x,m)=>{var b,h;return e.jsx("div",{className:"group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(a.Checkbox,{checked:!!((b=r==null?void 0:r.onClickFilter)!=null&&b.find(p=>p.columnIndex===m)),onCheckedChange:p=>i(m,p)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsx("div",{className:"flex items-center gap-2",children:((h=r==null?void 0:r.onClickFilter)==null?void 0:h.find(p=>p.columnIndex===m))&&e.jsx(a.Pencil,{onClick:()=>{n(p=>{const j=[...p];return j[m]=!p[m],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(m)]})},x)})})}const Sl=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],wl=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Tl=wl.map(s=>({label:s,value:s}));function El(){var u,x,m,b,h,p,j,N,f,g,k,D,w,S,M,A,F,I;const s=t.useEditorStore(C=>C.card),n=(x=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.topoJsonUrl,[r,o]=v.useState(((b=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:b.customTopoJsonUrl)||""),{setCardPreferences:c}=t.useEditorActions(),{data:d}=a.useTopoJson(s),i=Object.keys((d==null?void 0:d.objects)||{}).map(C=>({label:C,value:C}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx(Vs,{chartType:"map"}),e.jsx(Un,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(xt,{className:"h-9",options:l,onValueChange:C=>{console.log("value",C),c({...s.preferences,mapVisualOptions:{topoJsonUrl:C}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(t.Input,{onChange:C=>{o(C.target.value)},onBlur:()=>{var C;console.log("onBlur",r),c({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,customTopoJsonUrl:r}})},value:r,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(xt,{className:"h-9",options:i,value:((p=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:p.objectKey)||"",label:"Map Object",onValueChange:C=>{var E;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,objectKey:C}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(xt,{className:"h-9",options:Sl,value:((N=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:N.projection)||"",label:"Projection",onValueChange:C=>{var E;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projection:C}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(xt,{className:"h-9",options:Tl,value:((g=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:C=>{var E;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,colorScale:C}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(Un,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((D=(k=s.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:C=>{var E;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionScale:Number(C.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((M=(S=(w=s.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:M[0])||0,onChange:C=>{var E,L,T,R;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[Number(C.target.value),((R=(T=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:R[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((I=(F=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:I[1])||0,onChange:C=>{var E,L,T,R;c({...s.preferences,mapVisualOptions:{...(E=s.preferences)==null?void 0:E.mapVisualOptions,projectionOffset:[((R=(T=(L=s.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:R[0])||0,Number(C.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(Nl,{})]})}function Je({label:s,value:n,options:r,onChange:o,disabled:c}){const d=v.useId();return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(t.Label,{htmlFor:d,className:"text-xs",children:s}),e.jsxs(t.Select,{value:n,onValueChange:o,disabled:c,children:[e.jsx(t.SelectTrigger,{id:d,"aria-label":s,className:"h-8 min-w-0 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:r.map(i=>e.jsx(t.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]})}function Nt({label:s,value:n,onChange:r,type:o="text",min:c,max:d}){const i=v.useId();return e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(t.Label,{htmlFor:i,className:"text-xs",children:s}),e.jsx(t.Input,{id:i,className:"h-8 text-xs",type:o,min:c,max:d,value:n,onChange:l=>r(l.target.value)})]})}function Bs({label:s,checked:n,onChange:r}){const o=v.useId();return e.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-2 py-1",children:[e.jsx(t.Label,{className:"text-xs",htmlFor:o,children:s}),e.jsx(t.Switch,{id:o,size:"xs",checked:n,onCheckedChange:r})]})}function Il({label:s,disabled:n,onClick:r,children:o}){return e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":s,title:s,disabled:n,onClick:r,children:o})}function Gn({label:s,value:n,onChange:r}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Bs,{label:s,checked:n.visible,onChange:o=>r({...n,visible:o})}),e.jsx(Je,{label:`${s} position`,value:n.position,options:[{value:"before",label:"Before"},{value:"after",label:"After"}],onChange:o=>r({...n,position:o})}),e.jsx(Nt,{label:`${s} label`,value:n.label??"",onChange:o=>r({...n,label:o||void 0})})]})}function Is({value:s,onChange:n,cardType:r,showTitle:o=!0,title:c="NUMBER FORMAT",showLocaleOverride:d=!0}){const i=a.supportsLiveNumericPresentation(r),l=a.useResolvedValueFormatLocale(),u=a.useResolvedDefaultCurrency(),x=t.toTFormatOptions(gr.fromSemanticFormat(s,{preserveOmittedProperties:!0}),{preserveOmittedProperties:!0})||{},m=b=>{const h=t.fromTFormatOptions(b,{preserveOmittedProperties:!0});if(!d&&h&&"locale"in h){const{locale:p,...j}=h;n(j)}else n(h)};return e.jsx(Kt,{formatOptions:x,onFormatOptionsChange:m,showTitle:o,title:c,showLocaleOverride:d,reportDefaults:i?{currency:u??$t.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES.defaultCurrency,locale:l??$t.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES.locale}:void 0})}function Dl(s){switch(s==null?void 0:s.type){case"date":case"datetime":return{...s,type:"date"};case"number":case"currency":case"percent":case"percentage":case"scientific":case"duration":case"string":return s;default:return}}function Aa(s,n,r){const o=(r==null?void 0:r.length)&&r.every((c,d)=>{var i;return((i=s[d])==null?void 0:i.id)===c.levelId&&c.member.kind==="value"});return new Map([...n!=null&&n.length?[[st.matrixPathKey(n),n]]:[],...o?[[st.matrixPathKey(r),r]]:[]])}function kl({axis:s,level:n,value:r,change:o,scopeSelection:c}){const d=r.spec.sorts.find(h=>h.axis===s&&h.levelId===n.id&&h.scope.kind==="level"),i=r.spec.rankings.find(h=>h.axis===s&&h.levelId===n.id),l=s==="rows"?"columns":"rows",u=Aa(r.spec[l],i==null?void 0:i.oppositePath,l==="rows"?c==null?void 0:c.rowPath:c==null?void 0:c.columnPath),x=r.spec.measures.map(h=>({value:h.id,label:ht.getMatrixMeasureLabel(h,r.presentation)})),m=h=>{const p=r.spec.sorts.filter(j=>!(j.axis===s&&j.levelId===n.id&&j.scope.kind==="level"));o({kind:"sorts",sorts:h?[...p,{axis:s,levelId:n.id,scope:{kind:"level"},target:{kind:"member"},direction:"asc",nulls:"last",...d,...h}]:p})},b=h=>{if(h&&!r.spec.measures.length)return;const p=r.spec.rankings.filter(j=>!(j.axis===s&&j.levelId===n.id));o({kind:"rankings",rankings:h?[...p,{id:je.v4(),axis:s,levelId:n.id,direction:"top",count:10,measureId:r.spec.measures[0].id,oppositePath:[],others:!1,...i,...h}]:p})};return e.jsxs("div",{className:"space-y-2 border-t pt-2",children:[e.jsx(Je,{label:"Sort by",value:d?d.target.kind==="member"?"member":d.target.measureId:"default",options:[{value:"default",label:"Default"},{value:"member",label:"Member"},...x],onChange:h=>m(h==="default"?void 0:{target:h==="member"?{kind:"member"}:{kind:"measure",measureId:h,oppositePath:[]}})}),d&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{label:"Sort direction",value:d.direction,options:[{value:"asc",label:"Ascending"},{value:"desc",label:"Descending"}],onChange:h=>m({direction:h})}),e.jsx(Je,{label:"Null order",value:d.nulls,options:[{value:"first",label:"First"},{value:"last",label:"Last"}],onChange:h=>m({nulls:h})})]}),e.jsx(Je,{label:"Ranking",disabled:!r.spec.measures.length,value:(i==null?void 0:i.direction)??"none",options:[{value:"none",label:"None"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"}],onChange:h=>b(h==="none"?void 0:{direction:h})}),i&&e.jsxs(e.Fragment,{children:[e.jsx(Nt,{label:"Ranking count",type:"number",min:1,value:i.count,onChange:h=>{h&&Number.isSafeInteger(Number(h))&&Number(h)>0&&b({count:Number(h)})}}),e.jsx(Je,{label:"Rank by measure",value:i.measureId,options:x,onChange:h=>b({measureId:h})}),e.jsx(Bs,{label:"Include Others",checked:i.others,onChange:h=>b({others:h})}),e.jsx(Je,{label:"Ranking context",value:i.oppositePath.length?st.matrixPathKey(i.oppositePath):"total",options:[{value:"total",label:"Grand total"},...[...u].map(([h,p])=>({value:h,label:p.map((j,N)=>na.matrixMemberLabel(p.slice(0,N+1))).join(" / ")}))],onChange:h=>b({oppositePath:h==="total"?[]:[...u.get(h)]})})]})]})}function Ml({value:s,change:n,scopeSelection:r}){var f,g,k;const[o,c]=v.useState(((f=s.presentation.conditionalFormatting)==null?void 0:f.rules)??[]),[d,i]=v.useState(s.spec),[l,u]=v.useState(""),x=JSON.stringify(s.presentation.conditionalFormatting??{version:1,rules:[]}),m=v.useRef(x);x!==m.current&&(m.current=x,JSON.stringify(st.matrixConditionalFormattingSchema.safeParse({version:1,rules:o}).data??null)!==x&&c(((g=s.presentation.conditionalFormatting)==null?void 0:g.rules)??[]));const b=o.filter(a.isRuleReadyToApply);v.useEffect(()=>{const D=st.matrixConditionalFormattingSchema.safeParse({version:1,rules:b});if(!D.success)return;const w=JSON.stringify(D.data);w!==m.current&&(m.current=w,n({kind:"presentation",presentation:{...s.presentation,conditionalFormatting:D.data}}))},[b,n,s.presentation]);const h=o.find(D=>!a.isRuleReadyToApply(D)),p=st.matrixConditionalFormattingSchema.safeParse({version:1,rules:b}),j=h?`${h.name||"the new rule"} is incomplete`:p.success?"":((k=p.error.issues[0])==null?void 0:k.message)??"the rule is incomplete";if(d!==s.spec){const D=[],w=wt.retainMatrixConditionalFormatting(d,s.spec,{version:1,rules:o},D);i(s.spec),D.length&&(c((w==null?void 0:w.rules)??[]),u("Removed rules whose measure, level or member path changed."))}const N=s.spec.measures[0];return N?e.jsxs("div",{className:"min-w-0 space-y-2",children:[l&&e.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:l}),j&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not applied yet: ",j]}),e.jsx(a.DataTableConditionalFormattingSettings,{columnId:N.id,availableColumns:s.spec.measures.map(D=>({value:D.id,label:ht.getMatrixMeasureLabel(D,s.presentation)})),conditionalRules:o,onConditionalRulesChange:c,capabilities:{ruleKinds:["comparison","colorScale","dataBar"],automaticRanges:!1,separateApplyTargets:!0,targetScope:{defaultRowRoles:["member"]}}}),o.map((D,w)=>{var C;const S=D.target.matrix,M=(S==null?void 0:S.axis)==="columns"?"rows":"columns",A=M==="rows"?r==null?void 0:r.rowPath:r==null?void 0:r.columnPath,F=Aa(s.spec[M],S==null?void 0:S.oppositePath,A),I=E=>c(L=>L.map(T=>T.id===D.id?{...T,target:{...T.target,matrix:E}}:T));return e.jsxs("fieldset",{className:"min-w-0 space-y-2 border-t pt-2",children:[e.jsxs("legend",{className:"text-xs font-medium",children:[D.name||`Rule ${w+1}`," scope"]}),e.jsx(Je,{label:"Cell role",value:((C=D.target.rowRoles)==null?void 0:C.length)===1?D.target.rowRoles[0]:"all",options:[{value:"all",label:"All roles"},{value:"member",label:"Detail"},{value:"subtotal",label:"Subtotal"},{value:"grand_total",label:"Grand total"},{value:"others",label:"Others"}],onChange:E=>c(L=>L.map(T=>{if(T.id!==D.id)return T;const{tableParts:R,includeTotals:y,includeSubtotals:B,...P}=T.target;return{...T,target:{...P,rowRoles:E==="all"?void 0:[E]}}}))}),e.jsx(Je,{label:"Rule axis",value:(S==null?void 0:S.axis)??"all",options:[{value:"all",label:"All cells"},{value:"rows",label:"Rows"},{value:"columns",label:"Columns"}],onChange:E=>I(E==="all"?void 0:{axis:E})}),S&&e.jsxs(e.Fragment,{children:[e.jsx(Je,{label:"Rule level",value:S.levelId??"all",options:[{value:"all",label:"All levels"},...s.spec[S.axis].map(E=>({value:E.id,label:ht.getMatrixLevelLabel(E,s.presentation)}))],onChange:E=>I({...S,levelId:E==="all"?void 0:E})}),e.jsx(Je,{label:"Opposite members",value:S.oppositePath===void 0?"all":S.oppositePath.length?st.matrixPathKey(S.oppositePath):"total",options:[{value:"all",label:"All members"},{value:"total",label:"Grand total"},...[...F].map(([E,L])=>({value:E,label:L.map((T,R)=>na.matrixMemberLabel(L.slice(0,R+1))).join(" / ")}))],onChange:E=>I({...S,oppositePath:E==="all"?void 0:E==="total"?[]:[...F.get(E)]})})]})]},D.id)})]}):e.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"No metrics available"})}function Al({section:s,value:n,availableFields:r,bindings:o,scopeSelection:c,onChange:d}){const[i,l]=v.useState([]),[u,x]=v.useState(""),m=N=>je.matrixAuthoringDataType(N,n.spec.source,r),b=N=>{try{const f=wt.updateMatrixConfig(n,N,o,m,!0);x(""),l(f.notices),d(f.config,f.notices,f.removedBindings,f.bindings)}catch(f){x(f instanceof Error?f.message:"Invalid Matrix settings.")}},h=N=>b({kind:"presentation",presentation:{...n.presentation,...N}}),p=(N,f,g)=>{const k={...n.presentation[N]};if(g===void 0)delete k[f];else{const D=st.semaphorValueFormatSchema.safeParse(g);if(!D.success){x(D.error.message);return}k[f]=D.data}h({[N]:k})},j=(N,f)=>{const g=n.presentation[f][N];return e.jsx(Is,{showLocaleOverride:!1,cardType:"matrixTable",value:Dl(g),onChange:k=>p(f,N,k)})};return e.jsxs("aside",{"aria-label":"Matrix authoring",className:"min-w-0 text-foreground",children:[u&&e.jsx("p",{role:"alert",className:"break-words p-3 text-xs text-destructive",children:u}),i.length>0&&e.jsxs("div",{role:"status",className:"border-b p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("strong",{children:"Updated references"}),e.jsx(Il,{label:"Dismiss cleanup notices",onClick:()=>l([]),children:e.jsx(le.X,{className:"size-3.5"})})]}),e.jsx("ul",{className:"space-y-1",children:i.map((N,f)=>e.jsx("li",{children:N.message},`${N.kind}-${N.id}-${f}`))})]}),s.kind!=="conditional-formatting"&&["rows","columns"].filter(N=>s.kind!=="field"||n.spec[N].some(f=>f.id===s.id)).map(N=>e.jsxs("section",{"aria-label":s.kind==="field"?`Field ${s.id}`:N==="rows"?"Rows":"Columns",className:(s==null?void 0:s.kind)==="field"?"space-y-2":"space-y-2 border-b p-3",children:[(s==null?void 0:s.kind)!=="field"&&e.jsx("h2",{className:"text-xs font-semibold",children:N==="rows"?"Rows":"Columns"}),n.spec[N].filter(f=>s.kind==="field"&&f.id===s.id).map(f=>{const g=ht.getMatrixLevelLabel(f,n.presentation),k=F=>b({kind:"structure",[N]:n.spec[N].map(I=>I.id===f.id?F:I)}),D=m(f.field),w=D==="date"||D==="datetime",S=n.presentation.levelFormats[f.id],M=(S==null?void 0:S.type)==="temporal_bucket"?S:Ze.AUTOMATIC_TEMPORAL_BUCKET_FORMAT,A=f.grain?Ze.getTemporalBucketAuthoringSelection(M,f.grain):void 0;return e.jsxs("div",{className:(s==null?void 0:s.kind)==="field"?"min-w-0":"min-w-0 border-b pb-2",children:[e.jsx("div",{className:"flex min-w-0 items-center justify-between gap-1",children:e.jsx("span",{className:"truncate text-xs font-medium",title:g,children:g})}),e.jsxs("details",{open:(s==null?void 0:s.kind)==="field"?!0:void 0,children:[e.jsxs("summary",{className:`cursor-pointer py-1 text-xs text-muted-foreground ${(s==null?void 0:s.kind)==="field"?"hidden":""}`,children:[g," settings"]}),e.jsxs("div",{className:(s==null?void 0:s.kind)==="field"?"space-y-2 pt-2":"space-y-2 py-2",children:[e.jsx(Nt,{label:"Level label",value:n.presentation.levelLabels[f.id]??"",onChange:F=>{const I={...n.presentation.levelLabels};F?I[f.id]=F:delete I[f.id],h({levelLabels:I})}}),e.jsx(Je,{label:"Axis",value:N,options:[{value:"rows",label:"Rows"},{value:"columns",label:"Columns"}],onChange:F=>{F!==N&&b(wt.moveMatrixLevel(n.spec,f.id,F))}}),w&&e.jsx(Je,{label:"Time grain",value:f.grain??"none",options:[{value:"none",label:"No grouping"},...a.getGranularityOptionsForFieldType(D).map(F=>({value:F,label:F}))],onChange:F=>k({...f,grain:F==="none"?void 0:F})}),f.grain?e.jsxs(e.Fragment,{children:[e.jsx(Je,{label:"Date format",value:A.value,options:Ze.getTemporalBucketAuthoringOptions(f.grain,M),onChange:F=>p("levelFormats",f.id,F==="auto"?void 0:Ze.resolveTemporalBucketAuthoringFormat(f.grain,F,A.customPattern))}),A.value==="custom"&&e.jsx(Nt,{label:"Date pattern",value:A.customPattern,onChange:F=>{F.trim()&&p("levelFormats",f.id,{type:"temporal_bucket",presentation:{mode:"pattern",pattern:F}})}})]}):j(f.id,"levelFormats"),e.jsx(Gn,{label:"Subtotal",value:n.presentation.totals[N].levels[f.id],onChange:F=>h({totals:{...n.presentation.totals,[N]:{...n.presentation.totals[N],levels:{...n.presentation.totals[N].levels,[f.id]:F}}}})}),e.jsx(kl,{axis:N,level:f,value:n,change:b,scopeSelection:c})]})]})]},f.id)}),(s==null?void 0:s.kind)!=="field"&&e.jsxs("details",{children:[e.jsxs("summary",{className:"cursor-pointer py-1 text-xs text-muted-foreground",children:[N==="rows"?"Row":"Column"," totals and expansion"]}),e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx(Gn,{label:"Grand total",value:n.presentation.totals[N].grand,onChange:f=>h({totals:{...n.presentation.totals,[N]:{...n.presentation.totals[N],grand:f}}})}),e.jsx(Je,{label:"Default expanded levels",value:String(Math.min(n.defaultView[N].depth,Math.max(0,n.spec[N].length-1))),options:Array.from({length:Math.max(1,n.spec[N].length)},(f,g)=>({value:String(g),label:g===0?"Collapsed":String(g)})),onChange:f=>b({kind:"defaults",defaultView:{...n.defaultView,[N]:{...n.defaultView[N],depth:Number(f)}}})})]})]})]},N)),s.kind==="field"&&n.spec.measures.some(N=>N.id===s.id)&&e.jsx("section",{"aria-label":"Values",className:"space-y-2",children:n.spec.measures.filter(N=>N.id===s.id).map(N=>{const f=ht.getMatrixMeasureLabel(N,n.presentation);return e.jsxs("div",{className:(s==null?void 0:s.kind)==="field"?"min-w-0":"min-w-0 border-b pb-2",children:[e.jsx("div",{className:"flex min-w-0 items-center justify-between gap-1",children:e.jsxs("span",{className:"truncate text-xs font-medium",title:f,children:[f,N.kind==="aggregate"?` (${N.aggregate})`:""]})}),e.jsxs("details",{open:(s==null?void 0:s.kind)==="field"?!0:void 0,children:[e.jsxs("summary",{className:`cursor-pointer py-1 text-xs text-muted-foreground ${(s==null?void 0:s.kind)==="field"?"hidden":""}`,children:[f," settings"]}),e.jsxs("div",{className:(s==null?void 0:s.kind)==="field"?"space-y-2 pt-2":"space-y-2 py-2",children:[e.jsx(Nt,{label:"Measure label",value:n.presentation.measureLabels[N.id]??"",onChange:g=>{const k={...n.presentation.measureLabels};g?k[N.id]=g:delete k[N.id],h({measureLabels:k})}}),N.kind==="aggregate"&&e.jsx(Je,{label:"Aggregation",value:N.aggregate,options:Ze.getFieldAggregationOptions(m(N.field)).filter(g=>st.matrixAggregateSchema.safeParse(g.value).success).map(({value:g})=>({value:g,label:g})),onChange:g=>b({kind:"structure",measures:n.spec.measures.map(k=>k.id===N.id?{...N,aggregate:st.matrixAggregateSchema.parse(g)}:k)})}),j(N.id,"measureFormats")]})]})]},N.id)})}),s.kind==="table"&&e.jsxs("section",{"aria-label":"Presentation",className:"space-y-2 border-b p-3",children:[e.jsx("h2",{className:"text-xs font-semibold",children:"Presentation"}),e.jsx(Je,{label:"Row layout",value:n.presentation.layout.kind,options:[{value:"compact",label:"Compact"},{value:"tabular",label:"Tabular"}],onChange:N=>h({layout:N==="compact"?{kind:"compact"}:{kind:"tabular",repeatLabels:!1}})}),n.presentation.layout.kind==="tabular"&&e.jsx(Bs,{label:"Repeat row labels",checked:n.presentation.layout.repeatLabels,onChange:N=>h({layout:{kind:"tabular",repeatLabels:N}})}),e.jsx(Nt,{label:"Empty cell text",value:n.presentation.absence.emptyText,onChange:N=>h({absence:{...n.presentation.absence,emptyText:N}})}),e.jsx(Nt,{label:"Null cell text",value:n.presentation.absence.nullText,onChange:N=>h({absence:{...n.presentation.absence,nullText:N}})})]}),s.kind==="conditional-formatting"&&e.jsxs("section",{"aria-label":"Conditional formatting",className:"min-w-0 space-y-2 p-3",children:[e.jsx("h2",{className:"text-xs font-semibold",children:"Conditional formatting"}),e.jsx(Ml,{value:n,change:b,scopeSelection:c})]})]})}function Ds({fieldId:s,section:n="table"}){const r=t.useEditorStore(l=>l.card),o=t.useEditorStore(l=>l.actions.updateCard),c=t.useEditorStore(l=>l.matrixSelection),d=a.useMatrixEditorCatalog(r),i=je.readMatrixEditorConfig(r);return i.status==="invalid"?e.jsx("div",{role:"alert",className:"p-3 text-xs text-destructive",children:"Invalid Matrix configuration. Repair or reset the card definition."}):i.status==="absent"?e.jsx("div",{className:"p-3 text-xs text-muted-foreground",children:"No fields selected"}):e.jsx(Al,{value:i.config,section:s?{kind:"field",id:s}:{kind:n},scopeSelection:(c==null?void 0:c.cardId)===r.id?c.coordinate:void 0,bindings:r.controlBindings,availableFields:d.catalog.map(l=>({...l.field,dataType:st.normalizeAnalyticsCatalogDataType(l.resolvedField.dataType)})),onChange:(l,u,x,m)=>{const b=a.applyMatrixEditorResult(r,{config:l,notices:u,bindings:m});o(r.id,b.card)}})}const Ll={green:"#16a34a",red:"#dc2626",neutral:"#6b7280"};function Fl(s){return s&&(Ll[s]??s)}function La({value:s,onChange:n,showPosition:r=!1}){const o=s.colors||{};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Calculated as"}),e.jsxs(t.Select,{value:s.displayMode||"difference",onValueChange:c=>n({displayMode:c}),children:[e.jsx(t.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"difference",children:"Difference"}),e.jsx(t.SelectItem,{value:"percent_change",children:"Percent change"}),e.jsx(t.SelectItem,{value:"both",children:"Both"}),e.jsx(t.SelectItem,{value:"ratio",children:"Ratio (current ÷ comparison)"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(t.Label,{htmlFor:"comparison-precision",className:"text-xs",children:"Percent/ratio precision"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"0 through 6 decimals"})]}),e.jsx(t.Input,{id:"comparison-precision",type:"number",min:0,max:6,step:1,value:s.precision??"",placeholder:"Default",onChange:c=>{if(c.target.value===""){n({precision:void 0});return}const d=Number(c.target.value);Number.isInteger(d)&&d>=0&&d<=6&&n({precision:d})},className:"h-7 w-16 text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Indicator"}),e.jsxs(t.Select,{value:s.indicatorStyle||"arrow_badge",onValueChange:c=>n({indicatorStyle:c}),children:[e.jsx(t.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"arrow_badge",children:"Arrow + badge"}),e.jsx(t.SelectItem,{value:"arrow",children:"Arrow"}),e.jsx(t.SelectItem,{value:"badge",children:"Badge"}),e.jsx(t.SelectItem,{value:"none",children:"None"})]})]})]}),r&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Position"}),e.jsxs(t.Select,{value:s.position||"right",onValueChange:c=>n({position:c}),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"right",children:"Right"}),e.jsx(t.SelectItem,{value:"left",children:"Left"}),e.jsx(t.SelectItem,{value:"top",children:"Top"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{htmlFor:"comparison-color",className:"text-xs",children:"Use sentiment color"}),e.jsx(t.Switch,{id:"comparison-color",size:"xs",checked:s.showColor!==!1,onCheckedChange:c=>n({showColor:c})})]}),s.showColor!==!1&&e.jsx("div",{className:"space-y-1.5",children:[["increase","Increase","#16a34a"],["decrease","Decrease","#dc2626"],["neutral","No change","#6b7280"]].map(([c,d,i])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-24 shrink-0 text-xs text-muted-foreground",children:d}),e.jsx(a.ColorField,{value:Fl(o[c]||i),onChange:l=>n({colors:{...o,[c]:l||i}}),defaultValue:i,ariaLabel:`${d} color`,allowEmpty:!1})]},c))}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{htmlFor:"comparison-conditional-label",className:"text-xs",children:"Different label per direction"}),e.jsx(t.Switch,{id:"comparison-conditional-label",size:"xs",checked:s.conditionalLabel===!0,onCheckedChange:c=>n({conditionalLabel:c})})]}),s.conditionalLabel?e.jsx("div",{className:"space-y-1.5",children:[["increase","Increase"],["decrease","Decrease"],["neutral","No change"]].map(([c,d])=>{var i;return e.jsx(t.Input,{"aria-label":`${d} label`,value:((i=s.conditionalLabels)==null?void 0:i[c])||d,onChange:l=>n({conditionalLabels:{...s.conditionalLabels,[c]:l.target.value}}),className:"h-7 text-xs"},c)})}):e.jsx(t.Input,{"aria-label":"Comparison label",value:s.labelName||"",onChange:c=>n({labelName:c.target.value}),placeholder:"Previous",className:"h-7 text-xs"})]})}function Rl(){var b,h,p,j,N;const s=t.useEditorStore(f=>f.card),{setCardPreferences:n}=t.useEditorActions(),r=a.useEffectiveEditorCardType(),o=((b=s.config)==null?void 0:b.metricColumns)||[],c=o.length===2&&(((h=s.config)==null?void 0:h.groupByColumns)||[]).length===0,d=o.some(f=>{var g;return((g=f.comparison)==null?void 0:g.mode)==="explicit"});if(!t.COMPARISON_PRESENTATION_SUPPORTED_CHART_TYPES.includes(r))return null;const l=((p=s.preferences)==null?void 0:p.comparisonPresentation)||{},u=f=>n({...s.preferences,comparisonPresentation:{...l,...f}}),x=r==="kpi"&&((j=s.preferences)==null?void 0:j.metricPairComparisonEnabled)===!0,m=d||x;return e.jsxs(a.AccordionItem,{value:"comparison",className:"border-none",children:[e.jsx(a.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-[12px] hover:no-underline [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Tr,{className:"h-3.5 w-3.5 text-foreground/60"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(a.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(t.Label,{htmlFor:"inherit-global-date-comparison",className:"text-xs",children:"Inherit Global Date comparison"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Author-set metric comparisons still take precedence."})]}),e.jsx(t.Switch,{id:"inherit-global-date-comparison",size:"xs",checked:((N=s.preferences)==null?void 0:N.inheritGlobalComparison)!==!1,onCheckedChange:f=>{const g={...s.preferences};f?delete g.inheritGlobalComparison:g.inheritGlobalComparison=!1,n(g)}})]}),r==="kpi"&&c&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{htmlFor:"enable-metric-pair-comparison",className:"text-xs",children:"Enable metric comparison"}),e.jsx(t.Switch,{id:"enable-metric-pair-comparison",size:"xs",checked:x,onCheckedChange:f=>n({...s.preferences,metricPairComparisonEnabled:f})})]}),d&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{htmlFor:"show-explicit-comparison",className:"text-xs",children:"Show comparison"}),e.jsx(t.Switch,{id:"show-explicit-comparison",size:"xs",checked:l.showComparison!==!1,onCheckedChange:f=>u({showComparison:f})})]}),m&&e.jsx(La,{value:l,onChange:u,showPosition:r==="kpi"&&c})]})]})}function Fa({cardType:s,queryResultColumns:n,focusSection:r,focusRequestId:o}){var q,Y,$;const c=t.useEditorStore(U=>U.card),d=t.useEditorStore(U=>U.queryResultColumns),i=t.useEditorStore(U=>{var H;return(H=U.card)==null?void 0:H.preferences}),l=i==null?void 0:i.tablePrefs,u=t.useEditorStore(U=>U.actions.setCardPreferences),x=t.useEditorStore(U=>U.actions.updateTableConditionalFormatting),m=((q=c.config)==null?void 0:q.metricColumns)||[],b=s??c.type,h=n??d,p=c.type===b?c:{...c,type:b},j=a.getTableConditionalFormattingColumnOptions(p,h),N=a.getTableOutputColumnOptions(p,h),f=b==="matrixTable"||a.supportsTableConditionalFormatting(b),g=b==="table",k=b==="table",D=((Y=j[0])==null?void 0:Y.value)||"",w=a.normalizeConditionalFormatting(($=i==null?void 0:i.tablePrefs)==null?void 0:$.conditionalFormatting),S=a.resolveTablePresentationStyle(l),M=a.isEligibleFlatTableTotalsCard(p),A=a.hasFlatTableTotalsBehavior(p),[F,I]=v.useState("style");v.useEffect(()=>{if(r==="style"){I("style");return}if(r==="columns"&&k){I("columns");return}r==="conditional-formatting"&&f&&I("conditional-formatting")},[k,f,o,r]);const C=m.some(U=>{var H;return((H=U.comparison)==null?void 0:H.mode)==="explicit"}),E=(i==null?void 0:i.comparisonPresentation)||{},L=U=>{u({...i,comparisonPresentation:{...E,...U}})},T=U=>{x({version:1,rules:U})},R=U=>{u({...i,tablePrefs:{...l,density:U}})},y=U=>{u({...i,tablePrefs:{...l,tableStyle:{...l==null?void 0:l.tableStyle,...U}}})},B=U=>{var H;y({totals:{...(H=l==null?void 0:l.tableStyle)==null?void 0:H.totals,...U}})},P=U=>{var H;u({...i,tablePrefs:{...l,tableStyle:{...l==null?void 0:l.tableStyle,totals:{...(H=l==null?void 0:l.tableStyle)==null?void 0:H.totals,enabled:U}}}})},O=(U,H)=>{u({...i,tablePrefs:{...l,columnVisibility:a.setTableColumnVisibility(l==null?void 0:l.columnVisibility,U,H)}})},V=()=>{u({...i,tablePrefs:{...l,columnVisibility:a.showAllTableColumns()}})},_=()=>{u({...i,tablePrefs:{...l,density:a.TABLE_PRESENTATION_DEFAULT_STYLE.density,tableStyle:{headerStyle:a.TABLE_PRESENTATION_DEFAULT_STYLE.headerStyle,headerWrapText:a.TABLE_PRESENTATION_DEFAULT_STYLE.headerWrapText,stripedRows:a.TABLE_PRESENTATION_DEFAULT_STYLE.stripedRows,wrapText:a.TABLE_PRESENTATION_DEFAULT_STYLE.wrapText,totals:{enabled:M?A:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.enabled,backgroundColor:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.backgroundColor,textColor:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.textColor,fontWeight:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.fontWeight,borderTop:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.borderTop,borderTopStyle:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.borderTopStyle,borderTopColor:a.TABLE_PRESENTATION_DEFAULT_TOTALS_STYLE.borderTopColor}}}})},z=C?e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Comparison"}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(t.Label,{htmlFor:"show-table-comparison",className:"text-xs",children:"Show comparison"}),e.jsx(t.Switch,{id:"show-table-comparison",size:"xs",checked:E.showComparison!==!1,onCheckedChange:U=>L({showComparison:U})})]}),e.jsx(La,{value:E,onChange:L})]}):null;return e.jsx("div",{className:"px-4 py-3",children:e.jsxs(t.Tabs,{value:F,onValueChange:U=>I(U),className:"space-y-4",children:[e.jsxs(t.TabsList,{variant:"underline",children:[e.jsx(t.TabsTrigger,{value:"style",children:"Appearance"}),k?e.jsx(t.TabsTrigger,{value:"columns",children:"Columns"}):null,e.jsx(t.TabsTrigger,{value:"conditional-formatting",disabled:!f,children:"Conditional formatting"})]}),e.jsxs(t.TabsContent,{value:"style",className:"mt-0",children:[e.jsx(a.TablePresentationSettings,{style:S,onDensityChange:R,onStyleChange:y,showFullStyle:g,showBorderStyle:!1,totals:g&&M?{enabled:A,onEnabledChange:P,onStyleChange:B}:void 0,extraSection:z,onReset:g?_:void 0}),b==="matrixTable"&&e.jsx(Ds,{section:"table"})]}),e.jsx(t.TabsContent,{value:"columns",className:"mt-0",children:k?e.jsx(a.TableColumnVisibilitySettings,{columns:N,columnVisibility:l==null?void 0:l.columnVisibility,onColumnVisibilityChange:O,onShowAllColumns:V}):e.jsx("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"Column visibility is available for table cards."})}),e.jsx(t.TabsContent,{value:"conditional-formatting",className:"mt-0",children:b==="matrixTable"?e.jsx(Ds,{section:"conditional-formatting"}):f?D?e.jsx(a.DataTableConditionalFormattingSettings,{columnId:D,availableColumns:j,conditionalRules:w.rules,onConditionalRulesChange:T,startRulesWithNoTrigger:!0}):e.jsx("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"Run the query to configure conditional formatting."}):e.jsx("p",{className:"py-6 text-center text-[12px] text-muted-foreground",children:"Conditional formatting is available for table cards."})})]})})}function Pl(){var c;const s=t.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=t.useEditorStore(d=>d.actions),r=(c=s==null?void 0:s.textVisualOptions)!=null&&c.isDynamicText?"dynamic":"static";function o(d){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:d==="dynamic"}})}return e.jsx(t.Tabs,{value:r,onValueChange:o,children:e.jsxs(t.TabsList,{variant:"underline",children:[e.jsx(t.TabsTrigger,{value:"static",children:"Static"}),e.jsx(t.TabsTrigger,{value:"dynamic",children:"Dynamic"})]})})}function Ol(){return e.jsxs("div",{className:"space-y-2 px-6 py-4",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Text mode"}),e.jsx(Pl,{}),e.jsx("p",{className:"pt-1 text-[12px] leading-[1.55] text-muted-foreground",children:"Static text is authored inline. Dynamic text reads from the first cell of the card's query."})]})}function Vl({color:s,onColorChange:n,onClose:r}){const[o,c]=v.useState(0),[d,i]=v.useState(100),[l,u]=v.useState(50),[x,m]=v.useState(s);v.useEffect(()=>{const f=Hn(s);if(f){const g=Qn(f.r,f.g,f.b);c(g.h),i(g.s),u(g.l),m(s)}},[s]);const b=f=>{c(f),p(f,d,l)},h=f=>{const g=f.currentTarget.getBoundingClientRect(),k=Math.max(0,Math.min(1,(f.clientX-g.left)/g.width)),D=Math.max(0,Math.min(1,(f.clientY-g.top)/g.height)),w=k*100,S=(1-D)*100;i(w),u(S),p(o,w,S)},p=(f,g,k)=>{const D=_l(f,g,k),w=Bl(D.r,D.g,D.b);m(w)},j=f=>{if(m(f),/^#[0-9A-Fa-f]{6}$/.test(f)){const g=Hn(f);if(g){const k=Qn(g.r,g.g,g.b);c(k.h),i(k.s),u(k.l)}}},N=()=>{/^#[0-9A-Fa-f]{6}$/.test(x)&&(n(x),r())};return e.jsxs("div",{className:"p-4 space-y-4 w-[320px]",children:[e.jsxs("div",{className:"relative h-[200px] rounded cursor-crosshair",style:{background:`hsl(${o}, 100%, 50%)`},onClick:h,onMouseMove:f=>{f.buttons===1&&h(f)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${d}%`,top:`${100-l}%`,backgroundColor:x}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:o,onChange:f=>b(Number(f.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"HEX"}),e.jsx(t.Input,{value:x,onChange:f=>j(f.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:s}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:x}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(t.Button,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(t.Button,{onClick:N,children:"OK"})]})]})}function Hn(s){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function Bl(s,n,r){return"#"+((1<<24)+(s<<16)+(n<<8)+r).toString(16).slice(1)}function Qn(s,n,r){s/=255,n/=255,r/=255;const o=Math.max(s,n,r),c=Math.min(s,n,r);let d=0,i=0;const l=(o+c)/2;if(o!==c){const u=o-c;switch(i=l>.5?u/(2-o-c):u/(o+c),o){case s:d=((n-r)/u+(n<r?6:0))/6;break;case n:d=((r-s)/u+2)/6;break;case r:d=((s-n)/u+4)/6;break}}return{h:Math.round(d*360),s:Math.round(i*100),l:Math.round(l*100)}}function _l(s,n,r){s/=360,n/=100,r/=100;let o,c,d;if(n===0)o=c=d=r;else{const i=(x,m,b)=>(b<0&&(b+=1),b>1&&(b-=1),b<.16666666666666666?x+(m-x)*6*b:b<.5?m:b<.6666666666666666?x+(m-x)*(.6666666666666666-b)*6:x),l=r<.5?r*(1+n):r+n-r*n,u=2*r-l;o=i(u,l,s+1/3),c=i(u,l,s),d=i(u,l,s-1/3)}return{r:Math.round(o*255),g:Math.round(c*255),b:Math.round(d*255)}}const Yl=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function zl(){var S,M,A,F,I,C,E,L,T,R;const s=t.useEditorStore(y=>y.card),n=t.useEditorStore(y=>{var B;return(B=y.card)==null?void 0:B.preferences}),r=a.useEffectiveEditorCardType(),{setCardPreferences:o,updateCardInFrame:c}=t.useEditorActions(),d=v.useMemo(()=>r!==s.type?{...s,type:r}:s,[s,r]),{data:i}=a.useEditorCardQuery(d),[l,u]=v.useState({}),[x,m]=v.useState(null),[b,h]=v.useState(null),p=v.useMemo(()=>{var O,V,_,z,q,Y,$;if(!(i!=null&&i.records)||i.records.length===0)return[];const y=r==="stackedBar"||r==="stackedLine",B=r==="bar"||r==="line"||r==="horizontalBar"||r==="bullet"||r==="combo"||r==="area"||r==="stackedArea",P=((O=s==null?void 0:s.config)==null?void 0:O.pivotByColumns)&&s.config.pivotByColumns.length>0;if((y||B)&&P){if(i.pivotSchema&&Array.isArray(i.pivotSchema)){const U=new Set;return i.pivotSchema.forEach(H=>{H.alias&&U.add(H.alias)}),Array.from(U)}if(i.records.length>0){const U=i.records[0],H=Object.keys(U),te=new Set;(V=s==null?void 0:s.config)!=null&&V.groupByColumns&&s.config.groupByColumns.forEach(ue=>{te.add(ue.label||ue.name),te.add(ue.alias||ue.name)});const X=new Set;return(_=s==null?void 0:s.config)!=null&&_.metricColumns&&s.config.metricColumns.forEach(ue=>{const fe=ue.alias||ue.name;X.add(fe),X.add(`${fe}_count`),X.add(`${fe}_sum`),X.add(`${fe}_avg`),X.add(`${fe}_min`),X.add(`${fe}_max`);const be=ue.entityName||ue.qualifiedEntityName;be&&(X.add(`${be}_${fe}`),X.add(`${be}_${fe}_count`))}),H.filter(ue=>!te.has(ue)&&!X.has(ue))}}if((B||y)&&!P&&((q=(z=s==null?void 0:s.config)==null?void 0:z.metricColumns)!=null&&q.length))return s.config.metricColumns.map(U=>U.alias||U.label||U.name);if(($=(Y=s==null?void 0:s.config)==null?void 0:Y.groupByColumns)!=null&&$.length){const U=s.config.groupByColumns[0],H=U.label||U.name,te=new Set;return i.records.forEach(X=>{const se=X[H];se!=null&&te.add(String(se))}),Array.from(te)}return[]},[i,(S=s==null?void 0:s.config)==null?void 0:S.groupByColumns,(M=s==null?void 0:s.config)==null?void 0:M.pivotByColumns,(A=s==null?void 0:s.config)==null?void 0:A.metricColumns,r]),j=v.useMemo(()=>a.getDefaultChartColors(),[]);v.useEffect(()=>{const y={};p.forEach((B,P)=>{y[B]=a.getColorForValue(B,P,n==null?void 0:n.colorConfig)}),u(y)},[p,n==null?void 0:n.colorConfig,j]);const N=(y,B)=>{const P={...l,[y]:B};u(P);const O={...n||{},colorConfig:{segments:P}};o(O);const V={...s,preferences:O};c(V)},f=(y,B)=>{var q;const P=j[B%j.length],{[y]:O,...V}=((q=n==null?void 0:n.colorConfig)==null?void 0:q.segments)||{},_={...n||{},colorConfig:{segments:V}};o(_);const z={...s,preferences:_};c(z),u(Y=>({...Y,[y]:P}))};if(!p.length||!((s==null?void 0:s.type)==="stackedBar"||(s==null?void 0:s.type)==="stackedLine"?((I=(F=s==null?void 0:s.config)==null?void 0:F.groupByColumns)==null?void 0:I.length)||((E=(C=s==null?void 0:s.config)==null?void 0:C.pivotByColumns)==null?void 0:E.length):(T=(L=s==null?void 0:s.config)==null?void 0:L.groupByColumns)==null?void 0:T.length)||["table","kpi","text","custom","heatmap"].includes(r))return null;const D=()=>{const y={...n||{},colorConfig:{segments:{}}};o(y);const B={...s,preferences:y};c(B);const P={};p.forEach((O,V)=>{P[O]=a.getColorForValue(O,V,void 0)}),u(P)},w=Object.keys(((R=n==null?void 0:n.colorConfig)==null?void 0:R.segments)||{}).length>0;return e.jsxs(a.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(br.Palette,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Colors"})]})}),e.jsx(a.AccordionContent,{className:"",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"flex items-center justify-between",children:w&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:D,children:[e.jsx(t.RotateCcw,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:p.map((y,B)=>{const P=a.isDefaultColor(l[y],B),O=!P;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(t.Popover,{open:x===y,onOpenChange:V=>m(V?y:null),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:l[y]}})}),e.jsx(t.PopoverContent,{align:"start",className:"w-auto p-3",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Theme Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:j.slice(0,10).map((V,_)=>e.jsxs("button",{className:t.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",l[y]===V?"border-gray-900":"border-transparent"),style:{backgroundColor:V},onClick:()=>{N(y,V),m(null)},children:[_===B%j.length&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-white/90 px-0.5 text-[8px] font-bold text-gray-900 shadow-sm",children:"D"})}),e.jsx("span",{className:"sr-only",children:V})]},`default-${_}`))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Popular Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Yl.map((V,_)=>e.jsx("button",{className:t.cn("h-5 w-5 rounded border transition-all hover:scale-110",l[y]===V?"border-2 border-gray-900":V==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:V},onClick:()=>{N(y,V),m(null)},children:e.jsx("span",{className:"sr-only",children:V})},`preset-${_}`))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[e.jsx("button",{className:"text-sm font-medium text-blue-600 hover:text-blue-700",onClick:()=>{h({value:y,color:l[y]}),m(null)},children:"Custom color"}),!P&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{f(y,B),m(null)},children:[e.jsx(t.RotateCcw,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:y}),O&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},y)})}),b&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>h(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Vl,{color:b.color,onColorChange:y=>{N(b.value,y),h(null)},onClose:()=>h(null)})})]})]})})]})}function at({value:s,onSave:n,placeholder:r="",type:o="text",className:c=""}){const[d,i]=v.useState(s??""),[l,u]=v.useState(!1);v.useEffect(()=>{i(s??"")},[s]);const x=()=>{n(d),u(!1)},m=()=>{i(s??""),u(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${c}`,children:[e.jsx(t.Input,{placeholder:r,type:o,value:l?d:s??"",onChange:b=>{i(b.target.value),u(!0)},onFocus:()=>u(!0),onClick:b=>b.stopPropagation(),className:"h-8 text-xs",onPointerDown:b=>b.stopPropagation(),onKeyDown:b=>{b.stopPropagation(),b.key==="Enter"&&l&&d!==s?x():b.key==="Escape"&&m()},"aria-label":r||"Edit field"}),l&&d!==s&&e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm edit",onClick:x,children:e.jsx(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:m,children:e.jsx(le.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function ys({axis:s,label:n,type:r,config:o,onChange:c,defaultTitle:d,hidePosition:i}){var j,N,f,g,k,D,w,S,M,A,F,I,C,E;const l=a.normalizeContextFormatMode({formatMode:o==null?void 0:o.formatMode,formatOptions:o==null?void 0:o.formatOptions}),u=(L,T)=>{c({...o??{},[L]:T})},x=(L,T)=>{var P,O,V,_;const R=L==="enabled"&&T===!0,y=(P=o==null?void 0:o.name)==null?void 0:P.text,B=R&&!y&&d;c({...o??{},name:{...o==null?void 0:o.name,enabled:L==="enabled"?T:((O=o==null?void 0:o.name)==null?void 0:O.enabled)??!1,text:L==="text"?T:B?d:y,fontSize:L==="fontSize"?T:(V=o==null?void 0:o.name)==null?void 0:V.fontSize,fontWeight:L==="fontWeight"?T:(_=o==null?void 0:o.name)==null?void 0:_.fontWeight}})},m=(L,T)=>{var R,y;c({...o??{},labels:{enabled:L==="enabled"?T:((R=o==null?void 0:o.labels)==null?void 0:R.enabled)??!0,rotation:L==="rotation"?T:(y=o==null?void 0:o.labels)==null?void 0:y.rotation}})},b=(L,T)=>{c({...o??{},scale:{...o==null?void 0:o.scale,[L]:T===""?"auto":Number(T)}})},h=s==="x"?["auto","top","bottom"]:["auto","left","right"],p=["auto","0","45","90","-45","-90"];return e.jsxs(a.AccordionItem,{value:`${s}-axis`,className:"border-b-0",children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(a.AccordionTrigger,{className:"flex grow items-center justify-between gap-3 py-2 text-[12px] font-medium hover:no-underline",children:e.jsx("div",{className:"flex grow items-center justify-between gap-2",children:e.jsx("span",{children:n})})}),e.jsx(t.Switch,{size:"sm",checked:(o==null?void 0:o.enabled)!==!1,onCheckedChange:L=>u("enabled",L),onClick:L=>L.stopPropagation()})]}),e.jsxs(a.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Checkbox,{id:`${s}-title-enabled`,checked:((j=o==null?void 0:o.name)==null?void 0:j.enabled)??!1,onCheckedChange:L=>x("enabled",L===!0)}),e.jsx(t.Label,{htmlFor:`${s}-title-enabled`,className:"text-xs font-medium cursor-pointer",children:"TITLE"})]}),((N=o==null?void 0:o.name)==null?void 0:N.enabled)&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(at,{placeholder:`${n} title`,value:((f=o==null?void 0:o.name)==null?void 0:f.text)||"",onSave:L=>x("text",L),className:""}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Size"}),e.jsx("div",{className:"w-14",children:e.jsx(at,{type:"number",placeholder:"12",value:String(((g=o==null?void 0:o.name)==null?void 0:g.fontSize)||12),onSave:L=>x("fontSize",Number(L)||12),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Weight"}),e.jsxs(t.Select,{value:((k=o==null?void 0:o.name)==null?void 0:k.fontWeight)||"normal",onValueChange:L=>x("fontWeight",L),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-20 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(t.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]})]})]})]}),!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"POSITION"}),e.jsxs(t.Select,{value:(o==null?void 0:o.position)||"auto",onValueChange:L=>u("position",L),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:h.map(L=>e.jsx(t.SelectItem,{value:L,className:"text-xs",children:L==="auto"?"Auto (Default)":t.titleCase(L)},L))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(t.Switch,{size:"sm",checked:((D=o==null?void 0:o.labels)==null?void 0:D.enabled)!==!1,onCheckedChange:L=>m("enabled",L)})]}),((w=o==null?void 0:o.labels)==null?void 0:w.enabled)!==!1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Rotation"}),e.jsxs(t.Select,{value:String(((S=o==null?void 0:o.labels)==null?void 0:S.rotation)||"auto"),onValueChange:L=>m("rotation",L==="auto"?"auto":Number(L)),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:p.map(L=>e.jsx(t.SelectItem,{value:L,className:"text-xs",children:L==="auto"?"Auto (Default)":`${L}°`},L))})]})]})]}),r==="value"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"FORMAT"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Inherit from the bound metric by default."})]}),e.jsx(t.Switch,{size:"sm",checked:l==="override",onCheckedChange:L=>c({...o,formatMode:L?"override":"inherit"})})]}),l==="override"&&e.jsx(Kt,{formatOptions:(o==null?void 0:o.formatOptions)||{},onFormatOptionsChange:L=>c({...o,formatMode:"override",formatOptions:L}),showTitle:!1})]}),r==="value"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"SCALE"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),e.jsx("div",{className:"flex-1",children:e.jsx(at,{type:"number",placeholder:"auto",value:((M=o==null?void 0:o.scale)==null?void 0:M.min)==="auto"||((A=o==null?void 0:o.scale)==null?void 0:A.min)===void 0?"":String(o.scale.min),onSave:L=>b("min",L),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),e.jsx("div",{className:"flex-1",children:e.jsx(at,{type:"number",placeholder:"auto",value:((F=o==null?void 0:o.scale)==null?void 0:F.max)==="auto"||((I=o==null?void 0:o.scale)==null?void 0:I.max)===void 0?"":String(o.scale.max),onSave:L=>b("max",L),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),e.jsx("div",{className:"flex-1",children:e.jsx(at,{type:"number",placeholder:"auto",value:((C=o==null?void 0:o.scale)==null?void 0:C.stepSize)==="auto"||((E=o==null?void 0:o.scale)==null?void 0:E.stepSize)===void 0?"":String(o.scale.stepSize),onSave:L=>b("stepSize",L),className:""})})]})]})]})]})]})}function Cs(s,n,r){var d,i,l;if(s==="x"){const u=(i=(d=n==null?void 0:n.config)==null?void 0:d.groupByColumns)==null?void 0:i[0];return(u==null?void 0:u.label)||(u==null?void 0:u.name)||""}const o=((l=n==null?void 0:n.config)==null?void 0:l.metricColumns)||[],c=(r==null?void 0:r.datasetOptions)||[];if(s==="y"){const u=o.filter((x,m)=>{const b=c.find(h=>h.idx===m);return!b||b.yAxisId!=="y2"});return u.length===1&&(u[0].label||u[0].name)||""}if(s==="y2"){const u=o.filter((x,m)=>{const b=c.find(h=>h.idx===m);return(b==null?void 0:b.yAxisId)==="y2"});return u.length===1&&(u[0].label||u[0].name)||""}return""}function ql(){const s=t.useEditorStore(u=>u.card),n=t.useEditorStore(u=>{var x;return(x=u.card)==null?void 0:x.preferences}),{setCardPreferences:r,updateCardInFrame:o}=t.useEditorActions(),c=a.useEffectiveEditorCardType();if(!s||["tornado","pyramid","kpi","treemap"].includes(c))return null;const d=a.AxisConfigurator.getAxisInfo(c,n);if(!d.hasXAxis&&!d.hasYAxis)return null;const i=(u,x)=>{let m;u==="x"?m="xAxisConfig":u==="y"?m="yAxisConfig":m="secondaryYAxisConfig";const b={...n||{},[m]:x};r(b);const h={...s,preferences:b};o(h)},l=d.hasY2Axis&&c==="combo";return e.jsxs(a.AccordionItem,{value:"axes",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.SlidersHorizontal,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Axes"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsxs(a.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[d.hasXAxis&&e.jsx(ys,{axis:"x",label:"X-Axis",type:d.xAxisType,config:a.mergeAxisConfig(a.getDefaultAxisConfig(c,"x"),n==null?void 0:n.xAxisConfig),onChange:u=>i("x",u),defaultTitle:Cs("x",s,n)}),d.hasYAxis&&e.jsx(ys,{axis:"y",label:l?"Y-Axis (Left)":"Y-Axis",type:d.yAxisType,config:a.mergeAxisConfig(a.getDefaultAxisConfig(c,"y"),n==null?void 0:n.yAxisConfig),onChange:u=>i("y",u),defaultTitle:Cs("y",s,n)}),l&&e.jsx(ys,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:a.mergeAxisConfig({enabled:!0,position:"right"},n==null?void 0:n.secondaryYAxisConfig),onChange:u=>i("y2",u),defaultTitle:Cs("y2",s,n),hidePosition:!0})]})})]})}function $l(){const s=t.useEditorStore(b=>b.card),n=a.useEffectiveEditorCardType(),r=t.useEditorStore(b=>{var h,p,j,N;return(N=(j=(p=(h=b.card)==null?void 0:h.preferences)==null?void 0:p.chartOptions)==null?void 0:j.plugins)==null?void 0:N.legend}),{setLegendOptions:o}=t.useEditorActions();if(!s||!a.chartSupportsLegend(n))return null;const c=a.getDefaultLegendConfig(n),d=(c==null?void 0:c.display)??!0,i=(c==null?void 0:c.position)??"top",l=(c==null?void 0:c.align)??"center",u=(b,h)=>{const p={...r,[b]:h};o(p)},x=["top","bottom","left","right"],m=["start","center","end"];return e.jsxs(a.AccordionItem,{value:"legend",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Er,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Legend"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(t.Switch,{size:"sm",checked:(r==null?void 0:r.display)??d,onCheckedChange:b=>u("display",b)})]}),((r==null?void 0:r.display)??d)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(t.Select,{value:(r==null?void 0:r.position)||i,onValueChange:b=>u("position",b),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:x.map(b=>e.jsx(t.SelectItem,{value:b,className:"text-xs",children:t.titleCase(b)},b))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Alignment"}),e.jsxs(t.Select,{value:(r==null?void 0:r.align)||l,onValueChange:b=>u("align",b),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:m.map(b=>e.jsx(t.SelectItem,{value:b,className:"text-xs",children:t.titleCase(b)},b))})]})]})]})]})})]})}function Kl(){var T,R,y,B,P,O,V;const s=t.useEditorStore(_=>_.card),n=a.useEffectiveEditorCardType(),r=t.useEditorStore(_=>{var z,q;return(q=(z=_.card)==null?void 0:z.preferences)==null?void 0:q.dataLabelsConfig}),o=t.useEditorStore(_=>{var z;return(z=_.card)==null?void 0:z.preferences}),{setCardPreferences:c,updateCardInFrame:d}=t.useEditorActions();if(!s||!a.chartSupportsDataLabels(n))return null;const i=n==="bullet"?((T=o==null?void 0:o.bulletConfig)==null?void 0:T.orientation)??(((R=o==null?void 0:o.chartOptions)==null?void 0:R.indexAxis)==="x"?"vertical":"horizontal"):void 0,l=i!=null?i==="horizontal":((y=o==null?void 0:o.chartOptions)==null?void 0:y.indexAxis)==="y",u=n==="stackedBar"||n==="stackedLine",x=n==="pie"||n==="doughnut"||n==="polarArea"||n==="funnel",m=n==="bubble"||n==="scatter",b=(P=(B=o==null?void 0:o.chartOptions)==null?void 0:B.plugins)==null?void 0:P.datalabels,h=(b==null?void 0:b.display)!==!1&&((b==null?void 0:b.anchor)||(b==null?void 0:b.align)),p=a.getDefaultDataLabelsConfig(n,s.preferences),j=r??p,N=(p==null?void 0:p.enabled)??h??!1,f=(r==null?void 0:r.enabled)!==void 0?r.enabled:N,g=(_,z)=>{const $={...p??{},...r??{},[_]:z};_==="enabled"&&($.display=z,z&&m&&!$.position&&($.position="bottom")),_==="position"&&m&&($.position="bottom"),_==="formatMode"&&z==="inherit"&&($.format=void 0,$.formatOptions=void 0);const U={...s.preferences||{},dataLabelsConfig:$};c(U);const H={...s,preferences:U};d(H)},k=(_,z)=>{const q=r??{},$={...p??{},...q,font:{...q.font||{},[_]:z}},U={...s.preferences||{},dataLabelsConfig:$};c(U);const H={...s,preferences:U};d(H)},D=()=>{const _=n;return _==="stackedBar"||_==="stackedLine"||_==="pie"||_==="doughnut"?"center":l?"right":"top"},w=n!=="treemap"&&n!=="heatmap",S=n!=="treemap",M=D();let A=[];if(w)if(m)A=["bottom"];else if(u||x)A=["center"];else{const _=l?["center","left","right"]:["center","top","bottom"];A=["auto",...n==="bullet"?_:_.filter(q=>q!==M),"custom"]}const F=()=>t.titleCase(M),I=["center","start","end"],C=["center","start","end","top","bottom"],E=(j==null?void 0:j.formatMode)||(j!=null&&j.format&&!["auto"].includes(j.format)?"override":"inherit"),L=(j==null?void 0:j.format)==="none";return e.jsxs(a.AccordionItem,{value:"data-labels",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Br,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Data Labels"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(t.Switch,{size:"sm",checked:f,onCheckedChange:_=>g("enabled",_)})]}),f&&e.jsxs(e.Fragment,{children:[w&&!u&&!x&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(t.Select,{value:m?(j==null?void 0:j.position)||"bottom":(j==null?void 0:j.position)||"auto",onValueChange:_=>g("position",_),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:A.map(_=>e.jsx(t.SelectItem,{value:_,className:"text-xs",children:_==="auto"?F():_==="custom"?"Custom (Advanced)":t.titleCase(_)},_))})]})]}),u&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Show Total"}),e.jsx(t.Switch,{size:"sm",checked:(r==null?void 0:r.showTotal)??!1,onCheckedChange:_=>g("showTotal",_)})]}),(j==null?void 0:j.position)==="custom"&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),e.jsxs(t.Select,{value:(j==null?void 0:j.anchor)||"center",onValueChange:_=>g("anchor",_),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:I.map(_=>e.jsx(t.SelectItem,{value:_,className:"text-xs",children:t.titleCase(_)},_))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-16",children:"Align"}),e.jsxs(t.Select,{value:String((j==null?void 0:j.align)||"center"),onValueChange:_=>g("align",_),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:C.map(_=>e.jsx(t.SelectItem,{value:_,className:"text-xs",children:t.titleCase(_)},_))})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Format"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Keep this off to inherit from the bound metric."})]}),e.jsx(t.Switch,{size:"sm",checked:E==="override",onCheckedChange:_=>g("formatMode",_?"override":"inherit")})]}),E==="override"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Raw Value"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Show the unformatted numeric value."})]}),e.jsx(t.Switch,{size:"sm",checked:L,onCheckedChange:_=>{const z=r??{},Y={...p??{},...z,formatMode:"override",format:_?"none":void 0,formatOptions:_?void 0:z.formatOptions},$={...s.preferences||{},dataLabelsConfig:Y};c($),d({...s,preferences:$})}})]}),!L&&e.jsx(Kt,{formatOptions:(j==null?void 0:j.formatOptions)||{},onFormatOptionsChange:_=>{const Y={...p??{},...r??{},formatMode:"override",format:_.type&&_.type!=="auto"?_.type:void 0,formatOptions:_},$={...s.preferences||{},dataLabelsConfig:Y};c($),d({...s,preferences:$})},showTitle:!1})]})]}),S&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Appearance"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-20",children:"Size"}),e.jsx("div",{className:"flex-1",children:e.jsx(at,{type:"number",placeholder:"12",value:String(((O=j==null?void 0:j.font)==null?void 0:O.size)||12),onSave:_=>k("size",Number(_)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(t.Select,{value:((V=j==null?void 0:j.font)==null?void 0:V.weight)||"normal",onValueChange:_=>k("weight",_),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(t.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-20",children:"Color"}),e.jsxs(t.Select,{value:(j==null?void 0:j.color)==="auto"||!(j!=null&&j.color)?"auto":"custom",onValueChange:_=>{_==="auto"&&g("color","auto")},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),e.jsx(t.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),e.jsx("div",{className:"flex-1",children:e.jsx(at,{type:"number",placeholder:"0",value:String((j==null?void 0:j.rotation)||0),onSave:_=>g("rotation",Number(_)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Ul(){var d;const s=t.useEditorStore(i=>{var l;return(l=i.card)==null?void 0:l.type}),n=t.useEditorStore(i=>{var l;return(l=i.card)==null?void 0:l.preferences}),{setCardPreferences:r}=t.useEditorActions();if(s!=="treemap")return null;const o=((d=n==null?void 0:n.chartOptions)==null?void 0:d.treemapColorMode)??"branch",c=i=>{const l={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,treemapColorMode:i}};r(l)};return e.jsxs(a.AccordionItem,{value:"treemap-color-mode",className:"border-none",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.TbChartTreemap,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Treemap Colors"})]})}),e.jsx(a.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:e.jsxs(a.RadioGroup,{value:o,onValueChange:i=>c(i??"branch"),className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(a.RadioGroupItem,{id:"treemap-color-branch",value:"branch"}),e.jsxs(t.Label,{htmlFor:"treemap-color-branch",className:"flex flex-col text-sm font-normal leading-tight",children:[e.jsx("span",{className:"font-medium",children:"Shade by value (default)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Keeps parent hue and adjusts lightness based on the node's share within the branch."})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(a.RadioGroupItem,{id:"treemap-color-category",value:"category"}),e.jsxs(t.Label,{htmlFor:"treemap-color-category",className:"flex flex-col text-sm font-normal leading-tight",children:[e.jsx("span",{className:"font-medium",children:"Single color per category"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Applies the top-level color to all descendants without lightening/darkening."})]})]})]})})]})}const Gl=Object.keys(a.HEATMAP_PRESET_PALETTES);function Hl(){const s=t.useEditorStore(h=>h.card),n=t.useEditorStore(h=>{var p;return(p=h.card)==null?void 0:p.preferences}),{setCardPreferences:r}=t.useEditorActions(),o=(s==null?void 0:s.type)==="heatmap",c=(n==null?void 0:n.heatmapConfig)||{},d=c.colorPalette??"green",i=c.legendPosition??"bottom",l=v.useMemo(()=>c.colorRange&&c.colorRange[0]&&c.colorRange[1]?[c.colorRange[0],c.colorRange[1]]:[...a.DEFAULT_HEATMAP_CUSTOM_RANGE],[c.colorRange]),u=h=>{const p={...c,...h};p.colorPalette!=="custom"?delete p.colorRange:(!p.colorRange||!p.colorRange[0]||!p.colorRange[1])&&(p.colorRange=[...a.DEFAULT_HEATMAP_CUSTOM_RANGE]),r({...n||{},heatmapConfig:p})},x=h=>{u({colorPalette:h,colorRange:h==="custom"?c.colorRange??[...a.DEFAULT_HEATMAP_CUSTOM_RANGE]:void 0})},m=(h,p)=>{const j=[...l];j[h]=p,u({colorPalette:"custom",colorRange:j})},b=h=>{u({legendPosition:h})};return o?e.jsxs(a.AccordionItem,{value:"heatmap-color-config",className:"border-none",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Grid3x3,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Heatmap Settings"})]})}),e.jsxs(a.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[e.jsxs(a.RadioGroup,{value:d,onValueChange:h=>x(h??"blue"),className:"space-y-3",children:[Gl.map(h=>{const p=a.HEATMAP_PRESET_PALETTES[h];return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(a.RadioGroupItem,{id:`heatmap-${h}`,value:h}),e.jsxs(t.Label,{htmlFor:`heatmap-${h}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:p.label}),e.jsx("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${p.start}, ${p.end})`}})]})]},h)}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.RadioGroupItem,{id:"heatmap-custom",value:"custom"}),e.jsx(t.Label,{htmlFor:"heatmap-custom",className:"text-sm font-medium",children:"Custom colors"})]}),d==="custom"&&e.jsxs("div",{className:"flex flex-col gap-2 pl-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.ColorField,{value:l[0],onChange:h=>m(0,h??"#000000"),ariaLabel:"Start color",allowEmpty:!1}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Start color"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.ColorField,{value:l[1],onChange:h=>m(1,h??"#000000"),ariaLabel:"End color",allowEmpty:!1}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"End color"})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Color scale position"}),e.jsxs(t.Select,{value:i,onValueChange:h=>b(h??"bottom"),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["top","bottom","left","right"].map(h=>e.jsx(t.SelectItem,{value:h,className:"text-xs",children:h[0].toUpperCase()+h.slice(1)},h))})]})]})]})]}):null}const Jn=["poor","satisfactory","good"];function Wn(s){if(!s)return;const n={...s};return n.targetMetricKey||delete n.targetMetricKey,n.comparativeMetricKey||delete n.comparativeMetricKey,!n.targetValue&&n.targetValue!==0&&delete n.targetValue,(!n.rangeKeys||Object.keys(n.rangeKeys).length===0)&&delete n.rangeKeys,(!n.ranges||Object.keys(n.ranges).length===0)&&delete n.ranges,(!n.rangeLabels||Object.keys(n.rangeLabels).length===0)&&delete n.rangeLabels,n}function Ql(){var T,R;const s=t.useEditorStore(y=>y.card.preferences),n=t.useEditorStore(y=>y.card),r=t.useEditorStore(y=>y.isDevMode),{setCardPreferences:o,setChartOrientation:c}=t.useEditorActions(),d=v.useMemo(()=>(s==null?void 0:s.bulletConfig)||{},[s==null?void 0:s.bulletConfig]),l=je.hasValidCardConfig(n==null?void 0:n.config)&&!r,[u,x]=v.useState(d.showRanges??!1),[m,b]=v.useState(d.rangesArePercentages??!1),h=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!l,[p,j]=v.useState(h);v.useEffect(()=>{x(d.showRanges??!1)},[d.showRanges]),v.useEffect(()=>{b(d.rangesArePercentages??!1)},[d.rangesArePercentages]);const N=d.targetValue===void 0?"":String(d.targetValue);v.useEffect(()=>{const y=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!l;j(y)},[d.disableAutoComparative,d.comparativeMetricKey,l]);const f=v.useMemo(()=>{var y,B;return((B=(y=n==null?void 0:n.config)==null?void 0:y.metricColumns)==null?void 0:B.map(P=>{const O=P.label||P.name||P.alias||"";return{value:O,label:O}}))||[]},[(T=n==null?void 0:n.config)==null?void 0:T.metricColumns]);v.useEffect(()=>{var q,Y;if(!s||f.length===0)return;const y={};let B=!1;const P=(q=f[1])==null?void 0:q.value;!d.targetMetricKey&&P&&(y.targetMetricKey=P,B=!0);const O=(Y=f[2])==null?void 0:Y.value;!d.comparativeMetricKey&&!d.disableAutoComparative&&O&&(y.comparativeMetricKey=O,B=!0);const V=f.slice(3),_={...d.rangeKeys||{}};let z=!1;if(Jn.forEach(($,U)=>{!_[$]&&V[U]&&(_[$]=V[U].value,z=!0)}),z&&(y.rangeKeys=_,B=!0,d.showRanges===void 0&&(y.showRanges=!0)),B){const $=Wn({...d,...y});o({...s,bulletConfig:$})}},[f,d,s,o]);const g=y=>{const B=Wn({...d,...y});o({...s,bulletConfig:B})},k=(y,B)=>{const P={...d.rangeKeys||{},[y]:B.trim()};B.trim()||delete P[y],g({rangeKeys:Object.keys(P).length>0?P:void 0})},D=(y,B)=>{const P=B===""?void 0:Number(B),O={...d.ranges||{}};P===void 0||Number.isNaN(P)?delete O[y]:O[y]=P,g({ranges:Object.keys(O).length?O:void 0})},w=y=>{if(y===""){g({targetValue:void 0});return}const B=Number(y);g({targetValue:Number.isNaN(B)?void 0:B})},S=(y,B)=>{const P=B.trim(),O={...d.rangeLabels||{}};P?O[y]=P:delete O[y],g({rangeLabels:Object.keys(O).length>0?O:void 0})},M=y=>{x(y),g({showRanges:y})},A=y=>{b(y),g({rangesArePercentages:y})},F=d.orientation||(((R=s==null?void 0:s.chartOptions)==null?void 0:R.indexAxis)==="y"?"horizontal":"vertical"),I=y=>{g({orientation:y}),c(y==="horizontal"?"y":"x")},C=[{value:"__none",label:"None"},...f.map(y=>({value:y.value,label:y.label}))],E=C,L=y=>{if(j(y),!y){g({comparativeMetricKey:void 0,disableAutoComparative:!0});return}if(!l){g({disableAutoComparative:!1});return}if(d.comparativeMetricKey)g({disableAutoComparative:!1});else{const B=f.find(P=>P.value!==d.targetMetricKey);g({comparativeMetricKey:B==null?void 0:B.value,disableAutoComparative:!1})}};return e.jsxs(a.AccordionItem,{value:"bullet-config",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.BulletChartIcon,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Bullet Chart"})]})}),e.jsxs(a.AccordionContent,{className:"space-y-6 border-t border-border/50 py-4",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"ORIENTATION"}),e.jsxs(t.Select,{value:F,onValueChange:y=>I(y),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"horizontal",className:"text-xs",children:"Horizontal"}),e.jsx(t.SelectItem,{value:"vertical",className:"text-xs",children:"Vertical"})]})]})]}),l&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"TARGET METRIC"}),e.jsxs(t.Select,{value:d.targetMetricKey||"__none",onValueChange:y=>g({targetMetricKey:y==="__none"?void 0:y}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select metric"})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"__none",className:"text-xs",children:"None"}),f.map(y=>e.jsx(t.SelectItem,{value:y.value,className:"text-xs",children:y.label},y.value))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),l?e.jsxs(t.Select,{value:d.comparativeMetricKey||"__none",onValueChange:y=>g({comparativeMetricKey:y==="__none"?void 0:y,disableAutoComparative:y==="__none"}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select metric"})}),e.jsx(t.SelectContent,{children:C.map(y=>e.jsx(t.SelectItem,{value:y.value,className:"text-xs",children:y.label},y.value))})]}):e.jsxs("div",{className:"space-y-2 rounded-md border border-border/50 p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between font-medium",children:[e.jsx("span",{children:"Show comparative"}),e.jsx(t.Switch,{size:"sm",checked:p,onCheckedChange:y=>L(y)})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Comparative values are auto-detected from the third metric in your results."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"TARGET VALUE (FALLBACK)"}),e.jsx(et,{type:"number",className:"h-8 text-xs",value:N,onCommit:w,placeholder:"Optional numeric fallback"})]})]}),e.jsxs("section",{className:"space-y-4 rounded-md border border-border/60 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"QUALITATIVE RANGES"}),e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{delayDuration:200,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground",children:e.jsx(t.Info,{className:"h-3.5 w-3.5"})})}),e.jsx(t.TooltipContent,{side:"top",children:"Use columns or static values for Poor / Average / Good."})]})})]}),e.jsx("div",{className:"flex items-center gap-2 text-xs font-medium",children:e.jsx(t.Switch,{size:"sm",checked:u,onCheckedChange:M})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsx("input",{type:"checkbox",checked:m,disabled:!u,onChange:y=>A(y.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),e.jsx("span",{children:"Use % of value"})]})]}),u&&e.jsx("div",{className:"space-y-3",children:Jn.map(y=>{var B,P,O,V,_;return e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/40 p-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(t.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[y," LABEL"]}),e.jsx(et,{placeholder:`Display label (${y})`,value:((B=d.rangeLabels)==null?void 0:B[y])||"",onCommit:z=>S(y,z),className:"h-8 text-xs"})]}),l?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(t.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[y," COLUMN"]}),e.jsxs(t.Select,{value:((P=d.rangeKeys)==null?void 0:P[y])||"__none",onValueChange:z=>{z==="__none"?k(y,""):k(y,z)},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select column"})}),e.jsx(t.SelectContent,{children:E.map(z=>e.jsx(t.SelectItem,{value:z.value,className:"text-xs",children:z.label},z.value))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(t.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[y," COLUMN KEY"]}),e.jsx(et,{placeholder:"Column key",value:((O=d.rangeKeys)==null?void 0:O[y])||"",onCommit:z=>k(y,z),className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(t.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[y," VALUE"]}),e.jsx(et,{type:"number",placeholder:m?"0.80":"Static value",value:((V=d.ranges)==null?void 0:V[y])===void 0?"":String((_=d.ranges)==null?void 0:_[y]),onCommit:z=>D(y,z),className:"h-8 text-xs"})]})]},y)})})]})]})]})}function Xn(s){if(!s)return;const n={...s};if(n.xMetricKey||delete n.xMetricKey,n.yMetricKey||delete n.yMetricKey,n.radiusMetricKey||delete n.radiusMetricKey,n.labelKey||delete n.labelKey,n.groupKey||delete n.groupKey,n.enableGrouping===void 0&&delete n.enableGrouping,n.radiusScale||delete n.radiusScale,n.fixedRadius===void 0&&delete n.fixedRadius,n.minRadius===void 0&&delete n.minRadius,n.maxRadius===void 0&&delete n.maxRadius,Object.keys(n).length!==0)return n}function Jl(){var S,M,A,F,I,C,E,L,T,R,y,B;const s=t.useEditorStore(P=>P.card.preferences),n=t.useEditorStore(P=>P.card),r=a.useEffectiveEditorCardType(),o=t.useEditorStore(P=>P.isDevMode),{setCardPreferences:c,updateCardInFrame:d}=t.useEditorActions(),i=r==="bubble",l=r==="scatter",u=v.useMemo(()=>(s==null?void 0:s.bubbleScatterConfig)||{},[s==null?void 0:s.bubbleScatterConfig]),m=je.hasValidCardConfig(n==null?void 0:n.config)&&!o,b=v.useMemo(()=>{var P,O;return((O=(P=n==null?void 0:n.config)==null?void 0:P.metricColumns)==null?void 0:O.map(V=>{const _=V.label||V.name||V.alias||"";return{value:_,label:_}}))||[]},[(S=n==null?void 0:n.config)==null?void 0:S.metricColumns]),h=v.useMemo(()=>{var P,O;return((O=(P=n==null?void 0:n.config)==null?void 0:P.groupByColumns)==null?void 0:O.map(V=>{const _=V.label||V.name||V.alias||"";return{value:_,label:_}}))||[]},[(M=n==null?void 0:n.config)==null?void 0:M.groupByColumns]),p=v.useMemo(()=>u.enableGrouping!==void 0?u.enableGrouping:!o&&h.length>=2,[u.enableGrouping,o,h.length]),[j,N]=v.useState(p);v.useEffect(()=>{N(p)},[p]);const f=P=>{const O={...s||{},bubbleScatterConfig:P};c(O),n&&d({...n,preferences:O})},g=P=>{c(P),n&&d({...n,preferences:P})};v.useEffect(()=>{if(!s||b.length===0)return;const P={};let O=!1;if(!u.xMetricKey&&b[0]&&(P.xMetricKey=b[0].value,O=!0),!u.yMetricKey&&b[1]&&(P.yMetricKey=b[1].value,O=!0),i&&!u.radiusMetricKey&&b[2]&&(P.radiusMetricKey=b[2].value,O=!0),!u.labelKey&&h[0]&&(P.labelKey=h[0].value,O=!0),p&&!u.groupKey&&h[1]&&(P.groupKey=h[1].value,P.enableGrouping=!0,O=!0),O){const V=Xn({...u,...P});f(V)}},[b,h,u,s,c,i,p]);const k=P=>{const O=Xn({...u,...P});f(O)},D=P=>{N(P),k({enableGrouping:P,groupKey:P?u.groupKey:void 0})};if(!i&&!l)return null;const w=i?a.Circle:a.ChartScatter;return e.jsxs(a.AccordionItem,{value:"bubble-scatter-config",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{className:"h-3.5 w-3.5 text-foreground/60"}),e.jsxs("span",{children:[i?"Bubble":"Scatter"," Configuration"]})]})}),e.jsxs(a.AccordionContent,{className:"space-y-4 px-1 pb-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs font-medium text-muted-foreground",children:["Dimensions",e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(t.Info,{className:"h-3 w-3"})}),e.jsx(t.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsx("p",{children:"Label identifies each point. Group creates separate series in the legend."})})]})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Label Column"}),m?e.jsxs(t.Select,{value:u.labelKey||"",onValueChange:P=>k({labelKey:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select label column"})}),e.jsx(t.SelectContent,{children:h.map(P=>e.jsx(t.SelectItem,{value:P.value,children:P.label},P.value))})]}):e.jsx(et,{className:"h-8 text-xs",placeholder:"Column name for labels",value:u.labelKey||"",onCommit:P=>k({labelKey:P})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Group points into series"}),e.jsx(t.Switch,{size:"sm",checked:j,onCheckedChange:D})]}),j&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Group By"}),m?e.jsxs(t.Select,{value:u.groupKey||"",onValueChange:P=>k({groupKey:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select group column"})}),e.jsx(t.SelectContent,{children:h.map(P=>e.jsx(t.SelectItem,{value:P.value,children:P.label},P.value))})]}):e.jsx(et,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:u.groupKey||"",onCommit:P=>k({groupKey:P})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Metrics"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"X Axis"}),m?e.jsxs(t.Select,{value:u.xMetricKey||"",onValueChange:P=>k({xMetricKey:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select X metric"})}),e.jsx(t.SelectContent,{children:b.map(P=>e.jsx(t.SelectItem,{value:P.value,children:P.label},P.value))})]}):e.jsx(et,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:u.xMetricKey||"",onCommit:P=>k({xMetricKey:P})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Y Axis"}),m?e.jsxs(t.Select,{value:u.yMetricKey||"",onValueChange:P=>k({yMetricKey:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select Y metric"})}),e.jsx(t.SelectContent,{children:b.map(P=>e.jsx(t.SelectItem,{value:P.value,children:P.label},P.value))})]}):e.jsx(et,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:u.yMetricKey||"",onCommit:P=>k({yMetricKey:P})})]}),i&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Radius"}),m?e.jsxs(t.Select,{value:u.radiusMetricKey||"",onValueChange:P=>k({radiusMetricKey:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select radius metric"})}),e.jsx(t.SelectContent,{children:b.map(P=>e.jsx(t.SelectItem,{value:P.value,children:P.label},P.value))})]}):e.jsx(et,{className:"h-8 text-xs",placeholder:"Column name for radius",value:u.radiusMetricKey||"",onCommit:P=>k({radiusMetricKey:P})})]})]}),i&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Radius Settings"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Scale Mode"}),e.jsxs(t.Select,{value:u.radiusScale||"sqrt",onValueChange:P=>k({radiusScale:P}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"sqrt",children:"Square Root (area-proportional)"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"fixed",children:"Fixed Size"})]})]})]}),u.radiusScale!=="fixed"&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Min Radius"}),e.jsx(et,{className:"h-8 text-xs",type:"number",placeholder:"5",value:((A=u.minRadius)==null?void 0:A.toString())||"",onCommit:P=>k({minRadius:P?Number(P):void 0})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Max Radius"}),e.jsx(et,{className:"h-8 text-xs",type:"number",placeholder:"30",value:((F=u.maxRadius)==null?void 0:F.toString())||"",onCommit:P=>k({maxRadius:P?Number(P):void 0})})]})]}),u.radiusScale==="fixed"&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(t.Label,{className:"text-xs",children:["Fixed Radius: ",u.fixedRadius||10]}),e.jsx(a.Slider,{value:[u.fixedRadius||10],onValueChange:([P])=>k({fixedRadius:P}),min:3,max:30,step:1,className:"py-2"})]})]}),l&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Point Settings"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(t.Label,{className:"text-xs",children:["Point Size: ",u.fixedRadius||5]}),e.jsx(a.Slider,{value:[u.fixedRadius||5],onValueChange:([P])=>k({fixedRadius:P}),min:2,max:15,step:1,className:"py-2"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Axis Titles"}),e.jsx(t.Switch,{size:"sm",checked:((C=(I=s==null?void 0:s.xAxisConfig)==null?void 0:I.name)==null?void 0:C.enabled)??!1,onCheckedChange:P=>{var _,z,q,Y;const O=u.xMetricKey||"X Axis",V=u.yMetricKey||"Y Axis";g({...s??{},xAxisConfig:{...s==null?void 0:s.xAxisConfig,name:{enabled:P,text:((z=(_=s==null?void 0:s.xAxisConfig)==null?void 0:_.name)==null?void 0:z.text)||O}},yAxisConfig:{...s==null?void 0:s.yAxisConfig,name:{enabled:P,text:((Y=(q=s==null?void 0:s.yAxisConfig)==null?void 0:q.name)==null?void 0:Y.text)||V}}})}})]}),((L=(E=s==null?void 0:s.xAxisConfig)==null?void 0:E.name)==null?void 0:L.enabled)&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"X Title"}),e.jsx(et,{className:"h-8 text-xs",placeholder:u.xMetricKey||"X Axis",value:((R=(T=s==null?void 0:s.xAxisConfig)==null?void 0:T.name)==null?void 0:R.text)||"",onCommit:P=>{var O;g({...s??{},xAxisConfig:{...s==null?void 0:s.xAxisConfig,name:{...(O=s==null?void 0:s.xAxisConfig)==null?void 0:O.name,enabled:!0,text:P||u.xMetricKey||"X Axis"}}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs",children:"Y Title"}),e.jsx(et,{className:"h-8 text-xs",placeholder:u.yMetricKey||"Y Axis",value:((B=(y=s==null?void 0:s.yAxisConfig)==null?void 0:y.name)==null?void 0:B.text)||"",onCommit:P=>{var O;g({...s??{},yAxisConfig:{...s==null?void 0:s.yAxisConfig,name:{...(O=s==null?void 0:s.yAxisConfig)==null?void 0:O.name,enabled:!0,text:P||u.yMetricKey||"Y Axis"}}})}})]})]})]})]})]})}const Wl=[{value:"percentOfTotal",label:"% of Total",description:"Each stage shows percentage of the sum of all values"},{value:"percentOfFirst",label:"% of Stage 1",description:"First stage = 100%, others relative to first stage"}];function Xl(){const s=t.useEditorStore(h=>h.card),n=t.useEditorStore(h=>{var p;return(p=h.card)==null?void 0:p.preferences}),{setCardPreferences:r}=t.useEditorActions(),o=(s==null?void 0:s.type)==="funnel",c=(n==null?void 0:n.funnelConfig)||{},d=c.percentMode??"percentOfTotal",i=c.shrinkFraction??1,l=c.labelThreshold??0,u=h=>{const p={...c,...h};r({...n||{},funnelConfig:p})},x=h=>{u({percentMode:h})},m=h=>{u({shrinkFraction:h[0]})},b=h=>{u({labelThreshold:h[0]})};return o?e.jsxs(a.AccordionItem,{value:"funnel-config",className:"border-none",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Filter,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Funnel Settings"})]})}),e.jsxs(a.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"PERCENTAGE MODE"}),e.jsx(a.RadioGroup,{value:d,onValueChange:h=>x(h),className:"space-y-2",children:Wl.map(h=>e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(a.RadioGroupItem,{id:`funnel-${h.value}`,value:h.value,className:"mt-0.5"}),e.jsxs(t.Label,{htmlFor:`funnel-${h.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:h.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:h.description})]})]},h.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"SEGMENT SHRINK"}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Same Width"}),e.jsx(a.Slider,{value:[i],onValueChange:m,min:0,max:1,step:.1,className:"flex-1"}),e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Full Shrink"})]}),e.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:["Current: ",Math.round(i*100),"%"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"LABEL VISIBILITY THRESHOLD"}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Show All"}),e.jsx(a.Slider,{value:[l],onValueChange:b,min:0,max:25,step:1,className:"flex-1"}),e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Hide Small"})]}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:l===0?"Showing all labels":`Hide labels below ${l}%`})]})]})]}):null}function ds(){const s=t.useEditorStore(i=>i.card),{data:n,comparisonMetadata:r}=a.useEditorCardQuery(s),{keys:o}=a.getKeys((n==null?void 0:n.records)||[],r),c=o.slice(1).filter(i=>!je.METADATA_KEYS.includes(i));let d=c;if(["stackedBar","stackedLine"].includes(s.type)){const i=a.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:o[0],pivotKey:o[1],valueKey:o[2]}),{keys:l}=a.getKeys(i);d=l.slice(1)}return{transformedMetricKeys:d,dimensionKeys:o.slice(0,1),keys:o,defaultMetricKeys:c}}const Zl=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],ei=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}],ti=["center","start","end"],si=["center","start","end","top","bottom"];function us({config:s,onChange:n,isHorizontal:r=!1,showAutoFormat:o=!0,positionOptions:c,showAppearance:d=!0}){var j,N,f,g,k,D;const i=c??(r?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),l=o?["auto","number","currency","percent","none"]:["number","currency","percent","none"],u=(w,S)=>{const M={...s,[w]:S};n(M)},x=(w,S)=>{const M={...s,font:{...(s==null?void 0:s.font)||{},[w]:S}};n(M)},m=(w,S)=>{const M={...s,formatOptions:{...(s==null?void 0:s.formatOptions)||{},[w]:S}};n(M)},b=()=>r?"Right":"Top",h=s||{},p=h.format||(o?"auto":"number");return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Position"}),e.jsxs(t.Select,{value:h.position||"auto",onValueChange:w=>u("position",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:i.map(w=>e.jsx(t.SelectItem,{value:w,className:"text-xs",children:w==="auto"?b():w==="custom"?"Custom (Advanced)":t.titleCase(w)},w))})]})]}),h.position==="custom"&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Anchor"}),e.jsxs(t.Select,{value:h.anchor||"center",onValueChange:w=>u("anchor",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ti.map(w=>e.jsx(t.SelectItem,{value:w,className:"text-xs",children:t.titleCase(w)},w))})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Align"}),e.jsxs(t.Select,{value:String(h.align||"center"),onValueChange:w=>u("align",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:si.map(w=>e.jsx(t.SelectItem,{value:w,className:"text-xs",children:t.titleCase(w)},w))})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Format"}),e.jsxs(t.Select,{value:p,onValueChange:w=>u("format",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:l.map(w=>e.jsx(t.SelectItem,{value:w,className:"text-xs",children:w==="auto"&&o?"Auto (Use Axis)":w==="none"?"None (Raw Value)":t.titleCase(w)},w))})]})]}),!["auto","none"].includes(p)&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(p)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Decimals"}),e.jsx("div",{className:"w-16",children:e.jsx(at,{type:"number",placeholder:"0",value:String(((j=h.formatOptions)==null?void 0:j.decimalPlaces)??(p==="currency"?2:p==="percent"?1:0)),onSave:w=>m("decimalPlaces",Number(w)),className:""})})]}),p==="currency"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Currency"}),e.jsxs(t.Select,{value:((N=h.formatOptions)==null?void 0:N.currency)||"USD",onValueChange:w=>m("currency",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Zl.map(w=>e.jsx(t.SelectItem,{value:w.value,className:"text-xs",children:w.label},w.value))})]})]}),["number","currency"].includes(p)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Abbreviate (K, M, B)"}),e.jsx(t.Switch,{size:"sm",checked:((f=h.formatOptions)==null?void 0:f.useSuffix)??!1,onCheckedChange:w=>m("useSuffix",w)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Locale"}),e.jsxs(t.Select,{value:((g=h.formatOptions)==null?void 0:g.locale)||"en-US",onValueChange:w=>m("locale",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ei.map(w=>e.jsx(t.SelectItem,{value:w.value,className:"text-xs",children:w.label},w.value))})]})]})]}),d&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Appearance"}),e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Size"}),e.jsx("div",{className:"w-16",children:e.jsx(at,{type:"number",placeholder:"12",value:String(((k=h.font)==null?void 0:k.size)||12),onSave:w=>x("size",Number(w)),className:""})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Weight"}),e.jsxs(t.Select,{value:((D=h.font)==null?void 0:D.weight)||"normal",onValueChange:w=>x("weight",w),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(t.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Color"}),e.jsxs(t.Select,{value:h.color==="auto"||!h.color?"auto":"custom",onValueChange:w=>{w==="auto"&&u("color","auto")},children:[e.jsx(t.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Contrast)"}),e.jsx(t.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs",children:"Rotation"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-12",children:e.jsx(at,{type:"number",placeholder:"0",value:String(h.rotation||0),onSave:w=>u("rotation",Number(w)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]})}const ni=[{type:"bar",icon:a.ChartColumnIncreasing,label:"Bar"},{type:"line",icon:a.ChartLine,label:"Line"}],ai=[0,1,2,3,4,5,6,8,10],ri=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],oi=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function li(){return t.useEditorStore(n=>{var r;return(r=n.card)==null?void 0:r.type})!=="combo"?null:e.jsxs(a.AccordionItem,{value:"combo-series",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsx(ii,{})})]})}function ii(){const{transformedMetricKeys:s}=ds();return s.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:s.map((n,r)=>e.jsx(ci,{metricKey:n,idx:r},n))})}function ci({metricKey:s,idx:n}){var g;const[r,o]=v.useState(!1),c=t.useEditorStore(k=>{var D;return(D=k.card)==null?void 0:D.preferences}),d=t.useEditorStore(k=>{var D,w;return(w=(D=k.card)==null?void 0:D.preferences)==null?void 0:w.datasetOptions}),i=d==null?void 0:d.find(k=>k.idx===n),{setCardPreferences:l}=t.useEditorStore(k=>k.actions),u=(i==null?void 0:i.type)||"bar",x=(i==null?void 0:i.yAxisId)||"y",m=((g=i==null?void 0:i.dataLabels)==null?void 0:g.enabled)??!1,b=u==="line"?a.ChartLine:a.ChartColumnIncreasing;function h(k){const D={idx:n,type:u,yAxisId:x,dataLabels:i==null?void 0:i.dataLabels,...k};if(!i)l({...c||{},datasetOptions:[...d||[],D]});else{const w=d==null?void 0:d.map(S=>S.idx===n?{...S,...D}:S);l({...c||{},datasetOptions:w})}}function p(k){h({type:k})}function j(k){h({yAxisId:k})}function N(k){h({dataLabels:{...i==null?void 0:i.dataLabels,enabled:k}})}function f(k){h({dataLabels:k})}return e.jsx(a.Collapsible,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:s,children:s})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("span",{className:t.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(b,{className:"h-3 w-3"}),u==="line"?"Line":"Bar"]}),e.jsx("span",{className:t.cn("rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:x==="y2"?"Y2":"Y1"})]})]})}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"flex items-end gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Chart Type"}),e.jsx("div",{className:"flex gap-2",children:ni.map(({type:k,icon:D,label:w})=>{const S=u===k;return e.jsxs("button",{onClick:()=>p(k),className:t.cn("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",S?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[e.jsx(D,{className:"h-3.5 w-3.5 text-foreground/60"}),e.jsx("span",{children:w})]},k)})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Axis"}),e.jsxs(t.Select,{value:x,onValueChange:k=>j(k),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-20 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"y",className:"text-xs",children:"Y1 (Left)"}),e.jsx(t.SelectItem,{value:"y2",className:"text-xs",children:"Y2 (Right)"})]})]})]})]}),u==="line"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(t.Select,{value:(i==null?void 0:i.lineStyle)||"solid",onValueChange:k=>h({lineStyle:k}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:oi.map(({value:k,label:D})=>e.jsx(t.SelectItem,{value:k,className:"text-xs",children:D},k))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(t.Select,{value:String((i==null?void 0:i.pointRadius)??3),onValueChange:k=>h({pointRadius:Number(k)}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ai.map(k=>e.jsx(t.SelectItem,{value:String(k),className:"text-xs",children:k===0?"None":k},k))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(t.Select,{value:(i==null?void 0:i.pointStyle)||"circle",onValueChange:k=>h({pointStyle:k}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ri.map(({value:k,label:D})=>e.jsx(t.SelectItem,{value:k,className:"text-xs",children:D},k))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(t.Switch,{size:"sm",checked:m,onCheckedChange:N})]}),m&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(us,{config:i==null?void 0:i.dataLabels,onChange:f,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const Ns=[{value:"origin",label:"Origin (X-axis)",description:"Fill to the X-axis (y=0)"},{value:"start",label:"Start (Top)",description:"Fill to the top of chart area"},{value:"end",label:"End (Bottom)",description:"Fill to the bottom of chart area"},{value:"-1",label:"Previous Series",description:"Fill to the series below"},{value:"+1",label:"Next Series",description:"Fill to the series above"},{value:"false",label:"No Fill (Line)",description:"Show as line without fill"}],di=[0,1,2,3,4,5,6,8,10],ui=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],mi=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function xi(s){return s==null?"origin":s===!1?"false":s}function hi(){const s=t.useEditorStore(n=>{var r;return(r=n.card)==null?void 0:r.type});return s!=="area"&&s!=="stackedArea"?null:e.jsxs(a.AccordionItem,{value:"area-series",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsx(pi,{})})]})}function pi(){const{transformedMetricKeys:s}=ds();return s.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:s.map((n,r)=>e.jsx(fi,{metricKey:n,idx:r},n))})}function fi({metricKey:s,idx:n}){var N;const[r,o]=v.useState(!1),c=t.useEditorStore(f=>{var g;return(g=f.card)==null?void 0:g.preferences}),d=t.useEditorStore(f=>{var g,k;return(k=(g=f.card)==null?void 0:g.preferences)==null?void 0:k.datasetOptions}),i=d==null?void 0:d.find(f=>f.idx===n),{setCardPreferences:l}=t.useEditorStore(f=>f.actions),u=xi(i==null?void 0:i.fill),x=((N=i==null?void 0:i.dataLabels)==null?void 0:N.enabled)??!1,m=Ns.find(f=>f.value===u)||Ns[0];function b(f){const g={idx:n,fill:u,dataLabels:i==null?void 0:i.dataLabels,...f};if(!i)l({...c||{},datasetOptions:[...d||[],g]});else{const k=d==null?void 0:d.map(D=>D.idx===n?{...D,...g}:D);l({...c||{},datasetOptions:k})}}function h(f){b({fill:f==="false"?!1:f})}function p(f){b({dataLabels:{...i==null?void 0:i.dataLabels,enabled:f}})}function j(f){b({dataLabels:f})}return e.jsx(a.Collapsible,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:s,children:s})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:e.jsxs("span",{className:t.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(a.ChartArea,{className:"h-3 w-3"}),m.label.split(" ")[0]]})})]})}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Fill Target"}),e.jsxs(t.Select,{value:u,onValueChange:f=>h(f),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ns.map(f=>e.jsx(t.SelectItem,{value:f.value,className:"text-xs",children:e.jsx("div",{className:"flex flex-col",children:e.jsx("span",{children:f.label})})},f.value))})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(t.Select,{value:(i==null?void 0:i.lineStyle)||"solid",onValueChange:f=>b({lineStyle:f}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:mi.map(({value:f,label:g})=>e.jsx(t.SelectItem,{value:f,className:"text-xs",children:g},f))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(t.Select,{value:String((i==null?void 0:i.pointRadius)??3),onValueChange:f=>b({pointRadius:Number(f)}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:di.map(f=>e.jsx(t.SelectItem,{value:String(f),className:"text-xs",children:f===0?"None":f},f))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(t.Select,{value:(i==null?void 0:i.pointStyle)||"circle",onValueChange:f=>b({pointStyle:f}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ui.map(({value:f,label:g})=>e.jsx(t.SelectItem,{value:f,className:"text-xs",children:g},f))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(t.Switch,{size:"sm",checked:x,onCheckedChange:p})]}),x&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(us,{config:i==null?void 0:i.dataLabels,onChange:j,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const gi=[0,1,2,3,4,5,6,8,10],bi=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Ss=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function ji(){return t.useEditorStore(n=>{var r;return(r=n.card)==null?void 0:r.type})!=="line"?null:e.jsxs(a.AccordionItem,{value:"line-series",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsx(vi,{})})]})}function vi(){const{transformedMetricKeys:s}=ds();return s.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:s.map((n,r)=>e.jsx(yi,{metricKey:n,idx:r},n))})}function yi({metricKey:s,idx:n}){var f;const[r,o]=v.useState(!1),c=t.useEditorStore(g=>{var k;return(k=g.card)==null?void 0:k.preferences}),d=t.useEditorStore(g=>{var k,D;return(D=(k=g.card)==null?void 0:k.preferences)==null?void 0:D.datasetOptions}),i=d==null?void 0:d.find(g=>g.idx===n),{setCardPreferences:l}=t.useEditorStore(g=>g.actions),u=(i==null?void 0:i.lineStyle)||"solid",x=(i==null?void 0:i.pointRadius)??3,m=(i==null?void 0:i.pointStyle)||"circle",b=((f=i==null?void 0:i.dataLabels)==null?void 0:f.enabled)??!1,h=Ss.find(g=>g.value===u)||Ss[0];function p(g){const k={idx:n,lineStyle:u,pointRadius:x,pointStyle:m,dataLabels:i==null?void 0:i.dataLabels,...g};if(!i)l({...c||{},datasetOptions:[...d||[],k]});else{const D=d==null?void 0:d.map(w=>w.idx===n?{...w,...k}:w);l({...c||{},datasetOptions:D})}}function j(g){p({dataLabels:{...i==null?void 0:i.dataLabels,enabled:g}})}function N(g){p({dataLabels:g})}return e.jsx(a.Collapsible,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:s,children:s})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:e.jsxs("span",{className:t.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(_r,{className:"h-3 w-3"}),h.label.split(" ")[0]]})})]})}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(t.Select,{value:u,onValueChange:g=>p({lineStyle:g}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ss.map(({value:g,label:k})=>e.jsx(t.SelectItem,{value:g,className:"text-xs",children:k},g))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(t.Select,{value:String(x),onValueChange:g=>p({pointRadius:Number(g)}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:gi.map(g=>e.jsx(t.SelectItem,{value:String(g),className:"text-xs",children:g===0?"None":g},g))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(t.Select,{value:m,onValueChange:g=>p({pointStyle:g}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:bi.map(({value:g,label:k})=>e.jsx(t.SelectItem,{value:g,className:"text-xs",children:k},g))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(t.Switch,{size:"sm",checked:b,onCheckedChange:j})]}),b&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(us,{config:i==null?void 0:i.dataLabels,onChange:N,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const Ci=[0,2,4,6,8,10,12,16,20];function Ni(){const s=t.useEditorStore(n=>{var r;return(r=n.card)==null?void 0:r.type});return!s||!["bar","horizontalBar","stackedBar"].includes(s)?null:e.jsxs(a.AccordionItem,{value:"bar-series",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsx(Si,{})})]})}function Si(){const{transformedMetricKeys:s}=ds();return s.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:s.map((n,r)=>e.jsx(wi,{metricKey:n,idx:r},n))})}function wi({metricKey:s,idx:n}){var j;const[r,o]=v.useState(!1),c=t.useEditorStore(N=>{var f;return(f=N.card)==null?void 0:f.type}),d=t.useEditorStore(N=>{var f;return(f=N.card)==null?void 0:f.preferences}),i=t.useEditorStore(N=>{var f,g;return(g=(f=N.card)==null?void 0:f.preferences)==null?void 0:g.datasetOptions}),l=i==null?void 0:i.find(N=>N.idx===n),{setCardPreferences:u}=t.useEditorStore(N=>N.actions),x=(l==null?void 0:l.borderRadius)??0,m=((j=l==null?void 0:l.dataLabels)==null?void 0:j.enabled)??!1;function b(N){const f={idx:n,borderRadius:x,dataLabels:l==null?void 0:l.dataLabels,...N};if(!l)u({...d||{},datasetOptions:[...i||[],f]});else{const g=i==null?void 0:i.map(k=>k.idx===n?{...k,...f}:k);u({...d||{},datasetOptions:g})}}function h(N){b({dataLabels:{...l==null?void 0:l.dataLabels,enabled:N}})}function p(N){b({dataLabels:N})}return e.jsx(a.Collapsible,{open:r,onOpenChange:o,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:s,children:s})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:x>0&&e.jsxs("span",{className:t.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(t.ChartColumn,{className:"h-3 w-3"}),"r:",x]})})]})}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Bar Style"}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Corner Radius"}),e.jsxs(t.Select,{value:String(x),onValueChange:N=>b({borderRadius:Number(N)}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ci.map(N=>e.jsx(t.SelectItem,{value:String(N),className:"text-xs",children:N===0?"None":`${N}px`},N))})]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(t.Switch,{size:"sm",checked:m,onCheckedChange:h})]}),m&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(us,{config:l==null?void 0:l.dataLabels,onChange:p,isHorizontal:c==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const Ti=[0,1,2,3,4,5,6,8,10],Ei=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Ii=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Di(){const s=t.useEditorStore(l=>l.card),n=t.useEditorStore(l=>{var u;return(u=l.card)==null?void 0:u.preferences}),r=a.useEffectiveEditorCardType(),o=n==null?void 0:n.lineStyleConfig,{setCardPreferences:c,updateCardInFrame:d}=t.useEditorActions();if(!s||!["line","area","stackedArea"].includes(r))return null;const i=(l,u)=>{const x={...n||{},lineStyleConfig:{...o,[l]:u}};c(x),d({...s,preferences:x})};return e.jsxs(a.AccordionItem,{value:"line-style",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pr,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Line Style"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Default styles for all series. Override per-series in the Series section."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Line Pattern"}),e.jsxs(t.Select,{value:(o==null?void 0:o.lineStyle)||"solid",onValueChange:l=>i("lineStyle",l),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ii.map(({value:l,label:u})=>e.jsx(t.SelectItem,{value:l,className:"text-xs",children:u},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Point Size"}),e.jsxs(t.Select,{value:String((o==null?void 0:o.pointRadius)??3),onValueChange:l=>i("pointRadius",Number(l)),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ti.map(l=>e.jsx(t.SelectItem,{value:String(l),className:"text-xs",children:l===0?"None":l},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Point Shape"}),e.jsxs(t.Select,{value:(o==null?void 0:o.pointStyle)||"circle",onValueChange:l=>i("pointStyle",l),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ei.map(({value:l,label:u})=>e.jsx(t.SelectItem,{value:l,className:"text-xs",children:u},l))})]})]})]})})]})}const ki=[0,2,4,6,8,10,12,16,20],Mi=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}],Ai=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}];function Li(){const s=t.useEditorStore(l=>l.card),n=t.useEditorStore(l=>{var u;return(u=l.card)==null?void 0:u.preferences}),r=a.useEffectiveEditorCardType(),o=n==null?void 0:n.barStyleConfig,{setCardPreferences:c,updateCardInFrame:d}=t.useEditorActions();if(!s||!["bar","horizontalBar","stackedBar"].includes(r))return null;const i=(l,u)=>{const x={...n||{},barStyleConfig:{...o,[l]:u}};c(x),d({...s,preferences:x})};return e.jsxs(a.AccordionItem,{value:"bar-style",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.ChartColumn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Bar Style"})]})}),e.jsx(a.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Default styles for all bars. Override per-series in the Series section."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Corner Radius"}),e.jsxs(t.Select,{value:String((o==null?void 0:o.borderRadius)??0),onValueChange:l=>i("borderRadius",Number(l)),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:ki.map(l=>e.jsx(t.SelectItem,{value:String(l),className:"text-xs",children:l===0?"None":`${l}px`},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Bar Width"}),e.jsxs(t.Select,{value:String((o==null?void 0:o.barPercentage)??.9),onValueChange:l=>i("barPercentage",Number(l)),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Mi.map(({value:l,label:u})=>e.jsx(t.SelectItem,{value:l,className:"text-xs",children:u},l))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-xs font-medium",children:"Category Width"}),e.jsxs(t.Select,{value:String((o==null?void 0:o.categoryPercentage)??.8),onValueChange:l=>i("categoryPercentage",Number(l)),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Ai.map(({value:l,label:u})=>e.jsx(t.SelectItem,{value:l,className:"text-xs",children:u},l))})]})]})]})})]})}function Fi(){const s=t.useEditorStore(r=>{var o,c;return(c=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:c.sortChart}),{setSortChart:n}=t.useEditorActions();return e.jsxs(a.AccordionItem,{value:"stacked-sort",children:[e.jsx(a.AccordionTrigger,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(aa,{className:"h-3.5 w-3.5 text-foreground/60"}),"Sort"]})}),e.jsx(a.AccordionContent,{className:"space-y-4 px-1",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort Order"}),e.jsx(xt,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"Ascending",value:"asc"},{label:"Descending",value:"desc"}],value:s||"none",onValueChange:r=>{n(r)}})]})})]})}const Ri=["kpi"],ws=2;function Ct(s){return typeof s=="string"?s.trim().toLowerCase():((s==null?void 0:s.id)||(s==null?void 0:s.qualifiedFieldName)||(s==null?void 0:s.name)||(s==null?void 0:s.label)||"").trim().toLowerCase()}function Pi(s){if(!(s!=null&&s.name)||!(s!=null&&s.dataType)||s.role==="metric")return!1;const n=t.getDataType(s.dataType);return["date","string","boolean"].includes(n)}function Oi(s){return{...s,role:"groupby"}}function Vi(){var k,D;const s=t.useEditorStore(w=>w.card),n=t.useEditorStore(w=>w.actions.updateCardConfig),r=a.useEffectiveEditorCardType(),{scopedFields:o}=a.useScopedFields(),c=((k=s.config)==null?void 0:k.metricColumns)||[],d=((D=s.config)==null?void 0:D.summary)||{},i=d.breakdownDimensions||[],l=i.length>0,u=Ri.includes(r),x=c.length>0,m=d.enabled===!0,b=u&&x,h=Array.from(new Map(o.filter(Pi).map(w=>[Ct(w),Oi(w)])).values()),p=new Set(h.map(w=>Ct(w))),j=new Set(i.map(w=>Ct(w)).filter(w=>w&&p.has(w)));if(!u)return null;const N=w=>{n(s.id,{summary:{...d,...w}})},f=(w,S)=>{const M=Ct(w),A=h.filter(I=>j.has(Ct(I))),F=S?j.has(M)?A:[...A,w].slice(0,ws):A.filter(I=>Ct(I)!==M);N({breakdownDimensions:F,...F.length>0?{showOnCard:!0}:{}})},g=w=>{if(!w){N({enabled:!1,showOnCard:!1,includeInDashboardSummary:!1});return}N({enabled:!0,showOnCard:d.showOnCard??!0,includeInDashboardSummary:d.includeInDashboardSummary??!0})};return e.jsxs(a.AccordionItem,{value:"summary",className:"border-none",children:[e.jsxs(a.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-[12px] hover:no-underline [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[e.jsx(a.FileText,{className:"h-3.5 w-3.5 text-foreground/60"}),e.jsx("span",{children:"Summary"})]}),e.jsx(t.Switch,{size:"xs",checked:m,disabled:!b,onClick:w=>w.stopPropagation(),onPointerDown:w=>w.stopPropagation(),onCheckedChange:g,"aria-label":"Enable summary"})]}),e.jsx(a.AccordionContent,{className:"pb-4 pt-2",children:e.jsxs("div",{className:t.cn("space-y-3 transition-opacity",!m&&"opacity-60"),children:[!b&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:x?"Summary is not supported for this card type.":"Add at least one metric to enable summary."}),!l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Checkbox,{id:"summary-show-on-card",checked:d.showOnCard===!0,disabled:!m,onCheckedChange:w=>N({showOnCard:w===!0})}),e.jsx(t.Label,{htmlFor:"summary-show-on-card",className:"cursor-pointer text-xs",children:"Show summary on card"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Checkbox,{id:"summary-include-rollup",checked:d.includeInDashboardSummary===!0,disabled:!m,onCheckedChange:w=>N({includeInDashboardSummary:w===!0})}),e.jsx(t.Label,{htmlFor:"summary-include-rollup",className:"cursor-pointer text-xs",children:"Include in dashboard summary"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Breakdown Dimensions"}),e.jsxs("span",{className:"text-[11px] tabular-nums text-muted-foreground",children:[i.length,"/",ws]})]}),h.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No dimension fields available for breakdown."}):e.jsx("ul",{className:"max-h-40 space-y-1 overflow-y-auto",children:h.map(w=>{const S=Ct(w),M=j.has(S),A=j.size>=ws,F=!m||!M&&A;return e.jsxs("li",{className:"flex items-center gap-2 text-xs",children:[e.jsx(a.Checkbox,{id:`summary-breakdown-${S}`,checked:M,disabled:F,onCheckedChange:I=>f(w,I===!0)}),e.jsx(t.Label,{htmlFor:`summary-breakdown-${S}`,className:"cursor-pointer text-xs",children:w.label||w.name})]},S)})})]})]})})]})}const Bi=new Set(["area","bar","bubble","bullet","combo","doughnut","funnel","horizontalBar","line","pie","polarArea","radar","scatter","stackedArea","stackedBar","stackedLine","tornado"]);function _i(){const s=t.useEditorStore(u=>u.card),n=t.useEditorStore(u=>{var x;return(x=u.card)==null?void 0:x.preferences}),r=a.useEffectiveEditorCardType(),{setCardPreferences:o,updateCardInFrame:c}=t.useEditorActions();if(!s||!Bi.has(r||""))return null;const d=n==null?void 0:n.tooltipConfig,i=(d==null?void 0:d.formatMode)||(d==null?void 0:d.mode)||"inherit",l=u=>{const x={...n||{},tooltipConfig:{...d||{},...u}};o(x),c({...s,preferences:x})};return e.jsxs(a.AccordionItem,{value:"tooltip-format",className:"border-b-0",children:[e.jsx(a.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-[12px] font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Info,{className:"h-3.5 w-3.5 text-foreground/60"}),e.jsx("span",{children:"Tooltip Format"})]})}),e.jsxs(a.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Override metric format"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Keep this off to inherit from each metric."})]}),e.jsx(t.Switch,{size:"sm",checked:i==="override",onCheckedChange:u=>l({formatMode:u?"override":"inherit",mode:u?"override":"inherit"})})]}),i==="override"&&e.jsx(Kt,{formatOptions:(d==null?void 0:d.formatOptions)||{},onFormatOptionsChange:u=>l({formatMode:"override",mode:"override",formatOptions:u}),showTitle:!1})]})]})}function Ra({mode:s}){const n=t.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.type});return t.isTableChartType(n)?null:e.jsxs(e.Fragment,{children:[n==="combo"&&e.jsx(li,{}),(n==="area"||n==="stackedArea")&&e.jsx(hi,{}),n==="line"&&e.jsx(ji,{}),(n==="bar"||n==="horizontalBar"||n==="stackedBar")&&e.jsx(Ni,{}),e.jsx(Di,{}),e.jsx(Li,{}),e.jsx(Ul,{}),s==="config"&&e.jsx(Rl,{}),s==="config"&&e.jsx(Vi,{}),e.jsx(Hl,{}),n==="bullet"&&e.jsx(Ql,{}),n==="funnel"&&e.jsx(Xl,{}),(n==="bubble"||n==="scatter")&&e.jsx(Jl,{}),(n==="stackedBar"||n==="stackedLine")&&e.jsx(Fi,{}),e.jsx(zl,{}),e.jsx(ql,{}),e.jsx($l,{}),e.jsx(Kl,{}),e.jsx(_i,{})]})}function Yi(){const s=t.useEditorStore(r=>r.card),n=s==null?void 0:s.type;return n?e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx(Vs,{chartType:n}),e.jsx(a.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:e.jsx(Ra,{mode:"dev"})})]}):null}function zi({focusSection:s,focusRequestId:n}){const r=t.useEditorStore(i=>i.card),o=r.type;if(t.getVisualizationMode(r)==="dynamic")return e.jsx("div",{className:"p-6",children:e.jsxs(a.Alert,{children:[e.jsx(t.Info,{className:"h-4 w-4"}),e.jsx(a.AlertTitle,{children:"Dynamic mode manages presentation"}),e.jsx(a.AlertDescription,{children:"Built-in chart settings are hidden while this card is in dynamic mode. Query and data edits still apply, and the dynamic visual editor in the main panel controls the rendered output."})]})});function d(){if(t.supportsRegularTableSettings(o))return e.jsx(Fa,{cardType:o,focusSection:s,focusRequestId:n});switch(o){case"kpi":return e.jsx(Cl,{});case"map":return e.jsx(El,{});case"custom":return e.jsx("div",{className:"px-6 py-2",children:e.jsx(Ia,{})});case"text":return e.jsx(Ol,{});default:return e.jsx(Yi,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[d(),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Zn=32;function qi(){const s=v.useRef(null),n=v.useRef(null),r=t.useEditorStore(g=>g.isShowingVisual),o=t.useEditorStore(g=>g.isDevMode),c=t.useEditorStore(g=>g.showAIDialog),[d,i]=v.useState(!1),[l,u]=v.useState({section:null,id:0}),x=r&&!c,m=x&&(!o||d),b=o&&x,h=()=>i(g=>!g),p=g=>{g&&u(k=>({section:g,id:k.id+1})),o&&i(!0)};v.useEffect(()=>{var g,k,D,w;c?((g=s.current)==null||g.resize(0),(k=n.current)==null||k.resize(0)):((D=s.current)==null||D.resize(Zn),(w=n.current)==null||w.resize(25))},[c]);const[j,N]=v.useState(!1),f=x?{show:b,isOpen:m,onToggle:h,onOpen:p}:void 0;return e.jsxs(a.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(a.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:50,children:e.jsx("div",{className:"flex min-w-0 flex-1 flex-col",children:e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.jsx(po,{renderCommandBarEnd:g=>e.jsx(bs,{mode:"toolbar",inlineToolbar:!0,overflowActions:g,visualAsideControl:f,isDynamicInspectorOpen:j,onDynamicInspectorOpenChange:N})})})})}),e.jsx(a.ResizableHandle,{}),e.jsx(a.ResizablePanel,{role:"visual-section",minSize:0,defaultSize:50,children:m?e.jsxs(a.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(a.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(bs,{mode:"canvas",visualAsideControl:f,isDynamicInspectorOpen:j,onDynamicInspectorOpenChange:N})}),!c&&e.jsx(a.ResizableHandle,{}),e.jsx(a.ResizablePanel,{ref:s,className:"flex",defaultSize:Zn,maxSize:45,children:e.jsx(zi,{focusSection:l.section,focusRequestId:l.id})})]}):e.jsx(bs,{mode:"canvas",visualAsideControl:f,isDynamicInspectorOpen:j,onDynamicInspectorOpenChange:N})})]})}function $i(s){var ae;t.useAIInteractionStore(K=>K.currentAIContext);const[n,r]=v.useState(""),[o,c]=v.useState(null),{authToken:d,tokenProps:i}=a.useSemaphorContext(),l=t.useEditorStore(K=>K.card.id),u=t.useEditorStore(K=>{var ie;return(ie=K==null?void 0:K.card)==null?void 0:ie.sql}),x=t.useEditorStore(K=>K.isDevMode),m=t.useEditorStore(K=>{var ie;return(ie=K==null?void 0:K.card)==null?void 0:ie.python}),{setCardPython:b,setCardSql:h,setRunSql:p,switchCardType:j,setQueryConfig:N}=t.useEditorActions(),f=t.useEditorStore(K=>K.currentAssitantScope)||[],g=t.useEditorStore(K=>K.userInputForAI),k=t.useEditorStore(K=>K.triggerAIRun),D=t.useEditorStore(K=>K.card),w=t.useEditorStore(K=>K.selectedDatabaseName),S=t.useEditorStore(K=>K.selectedTableName),M=t.useEditorStore(K=>K.selectedConnectionId),A=t.useEditorStore(K=>K.selectedSchemaName),F=t.useDashboardStore(K=>K.dashboard.aiScopeTables),{errorMessage:I,refetch:C,data:E}=a.useEditorCardQuery(D),{setTriggerAIRun:L,setCurrentAssitantScope:T,setCardConfig:R}=t.useEditorActions(),{selectedDatamodelName:y,connectionType:B,selectedDatamodelId:P}=a.useEditorAside(),O=(ae=a.useDashboardQuery().data)==null?void 0:ae.assistantProfileId,V=v.useRef(a.createAssistantConversationId()),_=v.useRef(null),z=v.useRef(l),q=v.useRef(!1),Y=()=>{const K=_.current;K&&(_.current=null,V.current=a.createAssistantConversationId(),K==="clear"&&U([]))},{messages:$,setMessages:U,regenerate:H,error:te,sendMessage:X,status:se,addToolResult:ue,stop:fe,clearError:be}=a.useChat({transport:new a.DefaultChatTransport({api:`${i.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${d==null?void 0:d.accessToken}`}),body:()=>{const K=t.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",assistantProfileId:O,conversationId:V.current,assistantRequestId:a.createAssistantRequestId(),isDevMode:x,aiContext:K.currentAIContext,reasoningEffort:K.reasoningEffort,showReasoning:K.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:K,body:ie})=>({body:{...ie,messages:t.cleanupIncompleteMessages(K)}})}),onError:K=>{var ie;if(q.current=!1,K.name==="AbortError"||(ie=K.message)!=null&&ie.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)"),Y();return}console.error("[Editor Assistant] Stream error:",K),Y()},onToolCall:Ae,onFinish({isAbort:K,isDisconnect:ie,isError:Se}){q.current=!1,r(""),console.log(K?"[Editor Assistant] Stream aborted by user":ie?"[Editor Assistant] Stream disconnected (network error)":Se?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully"),Y()}}),ge=v.useCallback(K=>{q.current=!0;try{const ie=X(K);return a.isPromiseLike(ie)?ie.catch(Se=>{throw q.current=!1,Se}):ie}catch(ie){throw q.current=!1,ie}},[X]),Pe=v.useCallback(()=>{q.current=!0;try{const K=H();return a.isPromiseLike(K)?K.catch(ie=>{throw q.current=!1,ie}):K}catch(K){throw q.current=!1,K}},[H]),Oe=K=>{let ie=!1;U(Se=>{const re=typeof K=="function"?K(Se):K;if(re.length===0){if(q.current)return _.current="clear",ie=!0,Se;_.current=null,V.current=a.createAssistantConversationId()}return re}),ie&&fe()};v.useEffect(()=>{if(z.current!==l){if(z.current=l,q.current){_.current!=="clear"&&(_.current="rotate"),fe();return}_.current=null,V.current=a.createAssistantConversationId()}},[l,fe]),v.useEffect(()=>{k&&g&&(ge({role:"user",parts:[{type:"text",text:g}]}),L(!1))},[k,g,ge,L]);async function Ae({toolCall:K}){var ie,Se,re,he,ze,Z,Re,me,qe,Fe,Ue,we,oe,ne,de,ve;if(["createChartFromSql","createForecast"].includes(K.toolName)){const pe=((ie=K.input)==null?void 0:ie.sql)??((Se=K.args)==null?void 0:Se.sql),Qe=((re=K.input)==null?void 0:re.python)??((he=K.args)==null?void 0:he.python),Me=((ze=K.input)==null?void 0:ze.chartType)??((Z=K.args)==null?void 0:Z.chartType);j(Me),h(pe),b(Qe),p(!0),ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(K.toolName==="getUserSql"){if(!u){ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"error",message:"No SQL found"}});return}ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"success",sql:u,python:m||""}})}else if(K.toolName==="generateQueryConfig"){r("Generating query config...");const pe=((Re=K.input)==null?void 0:Re.chartType)??((me=K.args)==null?void 0:me.chartType),Qe=((qe=K.input)==null?void 0:qe.queryConfig)??((Fe=K.args)==null?void 0:Fe.queryConfig);((Ue=K.input)==null?void 0:Ue.cardConfig)??((we=K.args)==null||we.cardConfig),j(pe),R(Qe),h(void 0),b(void 0);const Me=await C();if((oe=Me==null?void 0:Me.data)!=null&&oe.error){ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"error",queryConfig:Qe,message:(ne=Me==null?void 0:Me.data)==null?void 0:ne.error.message}});return}if((de=Me==null?void 0:Me.data)!=null&&de.records){ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"success",queryConfig:Qe,message:"The data has been visualized"}});return}ue({tool:K.toolName,toolCallId:K.toolCallId,output:{status:"success",queryConfig:Qe,message:"The data has been visualized",records:(ve=Me==null?void 0:Me.data)==null?void 0:ve.records}})}else r("Analyzing...")}function Ie(K){const ie=a.removeFromScopeArray(f,K);_e(ie)}function _e(K){const ie=a.sanitizeAIScope(K);T(ie),U(Se=>[...Se,{id:crypto.randomUUID(),role:"system",parts:[{type:"text",text:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(ie)}`}]}])}function Ye(){const K={databaseName:w||"",schemaName:A||"",tableName:S||"",datamodelId:P||"",datamodelName:t.resolveDatamodelName(y),connectionId:M||"",connectionType:B||""},ie=a.dedup([...f,K]);_e(ie)}function Ve(){const K={databaseName:w||"",schemaName:A||"",tableName:S||"",datamodelName:t.resolveDatamodelName(y),connectionId:M||"",connectionType:B||"",datamodelId:P||""};if(!a.isInAiScopeArray([...F||[],...f],K)||f.length===0){const Se=a.dedup([...F||[],...f,K]).filter(re=>re.connectionId===K.connectionId);_e(Se)}}const Le=!["ready","error"].includes(se),De=a.getErrorMessage(te);return{messages:$,setMessages:Oe,sendMessage:ge,regenerate:Pe,isLoading:Le,handleSetAIScope:Ve,handleAddCurrentTableToScope:Ye,removeFromCurrentSelections:Ie,currentAssitantScope:f,setCurrentAssitantScope:T,stop:fe,status:se,toolStatus:n,llmUsage:o,onFinish:s,errorMessage:De,clearError:be}}const Ki=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function ea({isFullscreen:s,onFullscreenChange:n,fullscreenContainer:r}){const o=v.useRef(null),c=v.useRef(!1),[d,i]=v.useState(!1),[l,u]=v.useState(je.isDevEnv),[x,m]=v.useState(!1),[b,h]=v.useState(!1),[p,j]=v.useState(!1),[N,f]=v.useState(0),g=s??p,k=t.useCurrentAIContext(),{setCurrentAIContext:D,setHasEditorEntitySelectionOverride:w}=t.useAIActions(),{clearQueue:S}=t.useQueueActions(),{clearFileAttachments:M}=t.useFileActions(),A=t.useFileAttachments("editor"),{selectedEntities:F}=a.useAssistantContextEntities("editor"),I=t.useEditorStore(re=>re.card.id),C=t.useEditorStore(re=>re.card.dataSource),E=t.useEditorStore(re=>{var he;return(he=re.card.dataSource)==null?void 0:he.selectedEntities}),L=t.useEditorStore(re=>re.actions.setCardSql),T=t.useEditorStore(re=>re.actions.setRunSql),R=t.useEditorStore(re=>re.showAIDialog),y=t.useDashboardStore(re=>re.handleOpenAssistantProfile),{setShowAIDialog:B,setCardPython:P}=t.useEditorActions(),{assistantProfile:O}=a.useAssistantProfile(),{messages:V,setMessages:_,sendMessage:z,isLoading:q,stop:Y,status:$,llmUsage:U,errorMessage:H,clearError:te}=$i(),[X,se]=v.useState(""),ue=re=>{se(re.target.value)},fe=re=>{re.preventDefault();const he=X.trim();if(!he&&A.length===0)return;const ze=[];he&&ze.push({type:"text",text:he}),A.forEach(Z=>{Z.data&&ze.push({type:"file",mediaType:Z.type,filename:Z.name,url:`data:${Z.type};base64,${Z.data}`})}),z({role:"user",parts:ze}),se(""),M("editor"),be()},be=v.useCallback(()=>{f(re=>re+1)},[]);v.useEffect(()=>{var re;R&&!c.current&&((re=o.current)==null||re.focus()),c.current=R},[R]),v.useEffect(()=>{R&&(w(!1),D({selectedEntities:E||[]}))},[I,E,D,w,R]),a.useAutoSubmitQueue({assistantType:"editor",status:$,isLoading:q,sendMessage:z});const{hasActiveTools:ge,activeToolText:Pe}=a.useActiveToolStatus(V),Oe=v.useCallback(re=>{n==null||n(re),s===void 0&&j(re)},[s,n]);v.useEffect(()=>{if(!g)return;function re(he){he.key==="Escape"&&Oe(!1)}return window.addEventListener("keydown",re),()=>{window.removeEventListener("keydown",re)}},[g,Oe]);const Ae=v.useCallback(re=>{z({role:"user",parts:[{type:"text",text:re}]}),be()},[be,z]),Ie=v.useCallback(async()=>{const re=JSON.stringify(V??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(re),t.ue.success("Conversation copied")}catch(he){console.error("Failed to copy conversation",he),t.ue.error("Unable to copy conversation")}},[V]),_e=v.useCallback(()=>{Oe(!g)},[g,Oe]);function Ye(re,he){he==="sql"?(L(re),T(!0)):he==="python"&&(P(re),T(!0))}function Ve(){k.selectedEntities.length===0&&D({selectedEntities:F})}function Le(re){Ve();const he={role:"user",parts:[{type:"text",text:re.title+" "+re.subtitle}]};z(he),be()}function De(re){Ve(),z({role:"user",parts:[{type:"text",text:re}]}),be()}function ae(){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",size:"xs",variant:"ghost","aria-label":"Assistant options",children:e.jsx(a.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(a.DropdownMenuContent,{align:"end",children:[e.jsx(a.DropdownMenuLabel,{children:"Options"}),e.jsx(a.DropdownMenuSeparator,{}),e.jsx(a.DropdownMenuCheckboxItem,{checked:d,onCheckedChange:i,children:"Token usage"}),e.jsx(a.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:u,children:"Tool invocations"}),e.jsx(a.DropdownMenuCheckboxItem,{checked:x,onCheckedChange:m,children:"System message"})]})]})}function K(){return e.jsx("div",{"data-role":"header",className:"flex min-w-0 items-center",children:e.jsx("div",{className:"truncate text-[13px] font-medium",children:"Assistant"})})}const ie=(X==null?void 0:X.length)===0&&(V==null?void 0:V.filter(re=>re.role==="user").length)===0,Se=e.jsxs("div",{"data-role":"editor-assistant",className:t.cn("flex h-full w-full flex-col justify-between px-6 py-4",g&&"rounded-card border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-center justify-between gap-2",children:[K(),y&&e.jsx(t.Button,{variant:"outline",size:"xs",className:"min-w-0 shrink",onClick:y,children:e.jsx("span",{className:"truncate",children:(O==null?void 0:O.name)||"Default profile"})}),e.jsxs("div",{"data-role":"header-actions",className:"flex shrink-0 items-center gap-1.5",children:[ae(),l&&e.jsx(t.Button,{variant:"ghost",size:"xs",className:"text-muted-foreground hover:text-foreground",onClick:Ie,children:"Copy conversation"}),e.jsx(a.IconButton,{tooltip:g?"Exit fullscreen":"Expand",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:_e,children:g?e.jsx(Ke.Minimize2,{className:"h-3.5 w-3.5"}):e.jsx(Ke.Maximize2,{className:"h-3.5 w-3.5"})}),e.jsx(a.IconButton,{className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",tooltip:"New chat",onClick:()=>{_([]),S("editor"),te()},children:e.jsx(a.SquarePen,{className:"h-3.5 w-3.5"})}),e.jsx(a.IconButton,{tooltip:"Close",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>{B(!1)},children:e.jsx(le.X,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(a.AssistantVirtualizedMessages,{messages:V,showTools:l,handleRun:Ye,showSystemMessage:x,onQuickReply:Ae,disableQuickReplies:q,status:$,errorMessage:H,activeToolText:q&&ge?Pe:void 0,className:"mt-2 w-full grow px-0 py-2 pr-3",latestButtonClassName:R?"bottom-24 right-8":"hidden",scrollToEndSignal:N}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[ie&&!O&&e.jsx(a.Placeholders,{onClick:Le,placeholders:Ki}),e.jsx("div",{children:ie&&O&&e.jsx(a.SeedQuestions,{seedQuestions:O.seedQuestions||[],handleSeedQuestionClick:De})})]}),e.jsx(a.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(a.ChatInputWithContext,{ref:o,setInput:se,stop:Y,input:X,handleInputChange:ue,handleSubmit:re=>{Ve(),fe(re)},isLoading:q,status:$,assistantType:"editor",onFocus:()=>{}})]}),U&&d&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",U.inputTokens," prompt tokens, ",U.outputTokens," ","completion tokens, ",U.totalTokens," total tokens"]})}),e.jsx(a.AddDataPicker,{incomingSelectedEntities:F,open:b,onOpenChange:h,dataSource:C||a.EMPTY_DATA_SOURCE,dialogMode:"aiContext",onSaveSelectedEntities:re=>{w(!0),D({...k,selectedEntities:re})}})]});return g&&r?hr.createPortal(e.jsx(a.SemaphorStyleWrapper,{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:e.jsx("div",{className:"flex h-full w-full",children:Se})}),r):Se}function _s({children:s,className:n,delayDuration:r}){return e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{delayDuration:r,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:t.cn("overflow-hidden text-ellipsis whitespace-nowrap",n),children:s})}),e.jsx(t.TooltipContent,{children:s})]})})}function Pa({id:s,label:n,dataType:r,calculated:o,open:c,onOpenChange:d,onRemove:i,sortDirection:l,onSortDirectionChange:u,badge:x,children:m}){const{attributes:b,listeners:h,setNodeRef:p,transform:j,transition:N,isDragging:f}=a.useSortable({id:s});return e.jsxs(t.Popover,{modal:!0,open:c,onOpenChange:d,children:[e.jsxs("div",{ref:p,style:{transform:a.CSS.Transform.toString(j),transition:N},className:t.cn("group flex h-7 w-full items-center gap-1.5 rounded-control border bg-background px-1.5 transition-colors",c?"border-foreground/30 bg-muted/40":"border-border hover:bg-muted/40",f&&"z-50 scale-95 opacity-50"),children:[e.jsx("button",{type:"button",...b,...h,"aria-label":`Drag ${n}`,className:t.cn(a.GRIP_REVEAL_CLASS,"text-muted-foreground hover:text-foreground"),onClick:g=>g.stopPropagation(),children:e.jsx(a.GripVertical,{className:"h-3 w-3"})}),e.jsx(a.TypeGlyph,{dataType:r,calculated:o}),e.jsx(_s,{className:"block w-0 min-w-0 flex-1 text-[12px] text-foreground",children:n}),x,u&&e.jsx("button",{type:"button","aria-label":l==="asc"?"Switch to descending":"Switch to ascending",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground",onClick:g=>{g.stopPropagation(),u(l==="asc"?"desc":"asc")},children:l==="asc"?e.jsx(a.ArrowUp,{className:"h-3 w-3"}):e.jsx(a.ArrowDown,{className:"h-3 w-3"})}),m&&e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":"Field configuration",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-muted hover:text-foreground data-[state=open]:bg-muted",onClick:g=>g.stopPropagation(),children:e.jsx(a.Ellipsis,{className:"h-3 w-3"})})}),e.jsx("button",{type:"button","aria-label":"Remove",className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 hover:bg-muted hover:text-foreground group-focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:g=>{g.stopPropagation(),i()},children:e.jsx(le.X,{className:"h-3 w-3"})})]}),m&&e.jsx(t.PopoverContent,{align:"start",sideOffset:6,className:"w-[320px] p-0",children:e.jsx("div",{className:"max-h-[480px] space-y-3 overflow-y-auto p-3",children:m})})]})}function Oa(s,n,r){if(!n)return!1;const o=n.qualifiedFieldName,c=n.qualifiedEntityName,d=c&&n.name?`${c}.${n.name}`:o;return s.some(i=>{if(!(t.getDataType(i.dataType||"")==="date"))return!1;const u=a.getSelectedDateFilterColumn(i,r),x=u.split("."),m=x[x.length-1]||u,b=x.length>1?x.slice(0,-1).join("."):void 0,h=i.qualifiedTableName||b,p=h?`${h}.${m}`:void 0;return o?p?p===d||p.endsWith(`.${o}`):m===n.name:p?p===d:m===n.name})}function Ui({dashboard:s,dateGroupByField:n,dashboardInputValues:r,sheetId:o,card:c,timezone:d}){var x;if(!s||!n)return!1;const i=(x=s.inputs)==null?void 0:x.filter(m=>m.kind==="filter"&&!m.compatibility);if(!(i!=null&&i.length))return!1;const l={...s,inputs:i,controls:[]};return t.resolveDashboardInputContext({dashboard:l,sheetId:o,card:c,sheetKind:"dashboard",runtimeValues:{dashboardInputValues:r},mode:"editor",timezone:d}).resolvedInputs.some(m=>m.kind!=="filter"||!m.filter||!m.filterValue?!1:Oa([m.filter],n,[m.filterValue]))}function Gi(s){switch(s){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM-DD HH:mm",label:"2024-01-15 14:30 (YYYY-MM-DD HH:mm)"},{value:"YYYY-MM-DD HH:mm:ss",label:"2024-01-15 14:30:45 (YYYY-MM-DD HH:mm:ss)"},{value:"YYYY-MM-DD HH:mm Z",label:"2024-01-15 14:30 +00:00 (YYYY-MM-DD HH:mm Z)"},{value:"YYYY-MM-DD HH:mm:ss Z",label:"2024-01-15 14:30:45 +00:00 (YYYY-MM-DD HH:mm:ss Z)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];case"hour":return[{value:"YYYY-MM-DD HH:mm",label:"2024-01-15 14:00 (YYYY-MM-DD HH:mm)"},{value:"YYYY-MM-DD HH:mm Z",label:"2024-01-15 14:00 +00:00 (YYYY-MM-DD HH:mm Z)"},{value:"custom",label:"Custom Format..."}];case"minute":return[{value:"YYYY-MM-DD HH:mm",label:"2024-01-15 14:30 (YYYY-MM-DD HH:mm)"},{value:"YYYY-MM-DD HH:mm:ss",label:"2024-01-15 14:30:00 (YYYY-MM-DD HH:mm:ss)"},{value:"YYYY-MM-DD HH:mm Z",label:"2024-01-15 14:30 +00:00 (YYYY-MM-DD HH:mm Z)"},{value:"custom",label:"Custom Format..."}];case"second":return[{value:"YYYY-MM-DD HH:mm:ss",label:"2024-01-15 14:30:45 (YYYY-MM-DD HH:mm:ss)"},{value:"YYYY-MM-DD HH:mm:ss Z",label:"2024-01-15 14:30:45 +00:00 (YYYY-MM-DD HH:mm:ss Z)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM-DD HH:mm",label:"2024-01-15 14:30 (YYYY-MM-DD HH:mm)"},{value:"YYYY-MM-DD HH:mm:ss",label:"2024-01-15 14:30:45 (YYYY-MM-DD HH:mm:ss)"},{value:"YYYY-MM-DD HH:mm Z",label:"2024-01-15 14:30 +00:00 (YYYY-MM-DD HH:mm Z)"},{value:"YYYY-MM-DD HH:mm:ss Z",label:"2024-01-15 14:30:45 +00:00 (YYYY-MM-DD HH:mm:ss Z)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}}function Hi({aliasTemplate:s,onAliasTemplateChange:n}){var u;const[r,o]=v.useState(s),[c,d]=v.useState(!1),i=(u=t.useEditorStore(x=>{var m;return(m=x.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:u[0],l=i?`e.g. Min Sales in {{${i.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Input,{placeholder:l,value:c?r:s,onChange:x=>{o(x.target.value),d(!0)},onFocus:()=>d(!0),onPointerDown:x=>x.stopPropagation(),className:"h-8 text-xs",onKeyDown:x=>{x.key==="Enter"&&c&&r!==s?(n(r),d(!1)):x.key==="Escape"&&(o(s),d(!1))},"aria-label":"Edit alias template"}),c&&r!==s&&e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{n(r),d(!1)},children:e.jsx(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{o(s),d(!1)},children:e.jsx(le.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Qi({valueAliases:s,onValueAliasesChange:n}){const[r,o]=v.useState(null),[c,d]=v.useState(""),[i,l]=v.useState(""),u=()=>{n({...s,"":""})},x=b=>{const h={...s};delete h[b],n(h)},m=b=>{const h={...s};delete h[b],h[c]=i,n(h),o(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(s).map(([b,h],p)=>e.jsx("div",{className:"flex items-center gap-2",children:r===b?e.jsxs(e.Fragment,{children:[e.jsx(t.Input,{placeholder:"Value key",value:c,onChange:j=>d(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?m(b):j.key==="Escape"&&o(null)},"aria-label":"Edit value alias key"}),e.jsx(t.Input,{placeholder:"Alias label",value:i,onChange:j=>l(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?m(b):j.key==="Escape"&&o(null)},"aria-label":"Edit value alias label"}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>m(b),children:e.jsx(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>o(null),children:e.jsx(le.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Input,{placeholder:"Value key",value:b,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{o(b),d(b),l(h)},"aria-label":"Edit value alias key"}),e.jsx(t.Input,{placeholder:"Alias label",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{o(b),d(b),l(h)},"aria-label":"Edit value alias label"}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>x(b),"aria-label":"Remove value alias",children:e.jsx(le.X,{className:"h-3 w-3"})})]})},b+p)),e.jsxs(t.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:u,children:[e.jsx(a.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Ji({idx:s}){var l;const n=t.useEditorStore(u=>{var x;return(x=u.card)==null?void 0:x.preferences}),r=t.useEditorStore(u=>{var x;return(x=u.card.preferences)==null?void 0:x.datasetOptions}),o=t.useEditorStore(u=>u.actions.setCardPreferences),c=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,d=r==null?void 0:r.find(u=>u.idx===s);function i(u,x){(u==="end"||u==="start")&&je.getContrastColor(je.getCanvasBackgroundColor());const m={display:u!=="none",align:u,anchor:u,clamp:!0};if(!d)o({...n,datasetOptions:[...r||[],{idx:x,datalabels:m}]});else{const b={...d};b.datalabels=m;const h=r==null?void 0:r.map(p=>p.idx===x?b:p);o({...n,datasetOptions:h})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(a.Tag,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(t.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>i("none",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(le.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>i("start",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ir,{className:t.cn("h-4 w-4",{"rotate-90":c==="y"})})}),e.jsx("button",{onClick:()=>i("center",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(kr,{className:t.cn("h-4 w-4",{"rotate-90":c==="y"})})}),e.jsx("button",{onClick:()=>i("end",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Dr,{className:t.cn("h-4 w-4",{"rotate-90":c==="y"})})})]})})]})}function Wi(s,n=30){return s.length>n?s.slice(0,n)+"...":s}function Xi({col:s,idx:n,className:r,iconClassName:o,children:c}){const d=t.useEditorStore(m=>{var b;return(b=m.card)==null?void 0:b.preferences}),i=t.useEditorStore(m=>{var b,h;return(h=(b=m.card)==null?void 0:b.preferences)==null?void 0:h.datasetOptions}),l=i==null?void 0:i.find(m=>m.idx===n),{setCardPreferences:u}=t.useEditorStore(m=>m.actions);function x(m){if(!l)u({...d,datasetOptions:[...i||[],{idx:n,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const b={...l};b.type=m==="area"?"line":m,b.fill=m==="area"?"origin":"";const h=i==null?void 0:i.map(p=>p.idx===n?b:p);u({...d,datasetOptions:h})}}return e.jsxs("div",{className:t.cn("group flex items-center justify-between gap-2 rounded-md",r),children:[c||e.jsx(_s,{className:"max-w-[100px]",title:s,children:Wi(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.ChartColumnIncreasing,{onClick:()=>x("bar"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",o)}),e.jsx(a.ChartLine,{onClick:()=>x("line"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",o)}),e.jsx(a.ChartArea,{onClick:()=>x("area"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",o)}),e.jsx(Ji,{idx:n})]})]})}function Zi(){const s=t.useEditorStore(l=>l.card.type),n=t.useEditorStore(l=>l.isDevMode),r=t.useEditorStore(l=>l.card.preferences),{setCardPreferences:o}=t.useEditorStore(l=>l.actions);function c(l){var m;const u={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},x={...r,chartOptions:{...r==null?void 0:r.chartOptions,plugins:{...(m=r==null?void 0:r.chartOptions)==null?void 0:m.plugins,...u}}};o(x)}function d(){var l,u,x;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((x=(u=(l=r==null?void 0:r.chartOptions)==null?void 0:l.plugins)==null?void 0:u.datalabels)==null?void 0:x.anchor)||"none",onValueChange:c,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function i(){var l,u,x;return e.jsx("div",{children:e.jsxs(t.Select,{value:((x=(u=(l=r==null?void 0:r.chartOptions)==null?void 0:l.plugins)==null?void 0:u.datalabels)==null?void 0:x.anchor)||"none",onValueChange:c,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectItem,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{className:"text-xs",value:"start",children:"Start"}),e.jsx(t.SelectItem,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{className:"text-xs",value:"end",children:"End"})]})})]})})}return e.jsx(e.Fragment,{children:n?d():i()})}function ec({column:s}){const n=t.useEditorStore(u=>u.card.type),r=t.useEditorStore(u=>{var x,m;return(m=(x=u.card)==null?void 0:x.config)==null?void 0:m.metricColumns}),o=(r==null?void 0:r.map(u=>u.label))||[],c=o==null?void 0:o.find(u=>u===s.label||u===s.name),d=c?o.indexOf(c):-1;function i(){return e.jsx("div",{className:"pr-1",children:c&&e.jsx(Xi,{idx:d,col:c,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function l(){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Data Labels"}),e.jsx(Zi,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&i(),["pie","doughnut"].includes(n)&&l()]})}function tc({field:s,searchQuery:n="",limit:r=500}){const{authToken:o,tokenProps:c}=a.useSemaphorContext(),d=t.useDashboardStore(m=>{var b;return((b=m.reportContext)==null?void 0:b.calendar)??null}),i=t.useEditorStore(m=>m.card),l=i==null?void 0:i.dataSource,u=["attribute-values",s.entityName,s.name,n,r,d],x=a.useQuery({queryKey:u,queryFn:async()=>{if(!(l!=null&&l.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const m={groupByColumns:[{...s,role:"groupby"}],metricColumns:[],filters:n?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:s,operator:"contains",value:n}],groups:[]}:void 0,rowLimit:r},b={connection_id:l.connectionId,cardConfig:m,cardDataSource:l,cache_config:t.getCacheConfig({card:i}),calendarContext:d};console.log("requestBody",b);const h=await t.postRequestRegular(`${c.apiServiceUrl}/v1/query`,(o==null?void 0:o.accessToken)||"",b);if(h!=null&&h.error)return console.error("Error fetching attribute values:",h.error),[];const p=s.name;return((h==null?void 0:h.records)||[]).map(N=>{const f=N[p]||N[s.alias||p]||N[s.label];return{id:f||"",value:f||"",label:String(f||"(empty)")}})}catch(m){return console.error("Error fetching attribute values:",m),[]}},enabled:!!s&&!!(l!=null&&l.connectionId)&&!!d,staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:x.data||[],isLoading:x.isLoading,isFetching:x.isFetching,isError:x.isError,error:x.error,refetch:x.refetch}}const sc=new Set;function Va({open:s,onOpenChange:n,availableFields:r,existingFilters:o,editingCondition:c,onSave:d}){const i=!!c,[l,u]=v.useState(i?"values":"fields"),[x,m]=v.useState(""),[b,h]=v.useState({id:(c==null?void 0:c.id)||je.v4(),field:(c==null?void 0:c.field)||null,selectedValues:c?Array.isArray(c.value)?c.value:[c.value]:[]}),p=r.filter(D=>{var S;return i?!1:!((S=o==null?void 0:o.conditions)==null?void 0:S.some(M=>M.field.id===D.id))}),j=D=>{h({...b,field:D}),u("values")},N=()=>{if(b.field&&b.selectedValues.length>0){const D={id:b.id,field:b.field,operator:"in",value:b.selectedValues};let w;if(i){const S=((o==null?void 0:o.conditions)||[]).map(M=>M.id===c.id?D:M);w={...o,conditions:S}}else{const S=(o==null?void 0:o.conditions)||[];w={id:(o==null?void 0:o.id)||je.v4(),logicalOperator:"AND",negate:!1,conditions:[...S,D],groups:[]}}d(w),n(!1)}},f=()=>{if(!i||!c)return;const D=((o==null?void 0:o.conditions)||[]).filter(w=>w.id!==c.id);if(D.length>0){const w={...o,conditions:D};d(w)}else d(void 0);n(!1)},g=D=>{h({...b,selectedValues:D})},k=()=>{i&&c?(h({id:c.id,field:c.field,selectedValues:Array.isArray(c.value)?c.value:[c.value]}),u("values")):(h({id:je.v4(),field:null,selectedValues:[]}),u("fields")),m("")};return v.useEffect(()=>{s&&k()},[s,i,c]),e.jsx(a.Dialog,{open:s,onOpenChange:n,children:e.jsxs(a.DialogContent,{className:"max-w-2xl",children:[e.jsx(a.DialogHeader,{children:e.jsx(a.DialogTitle,{children:i?`Edit Filter: ${b.field?a.getFieldDisplayLabel(b.field):""}`:l==="fields"?"Select Field to Filter":`Select Values for ${b.field?a.getFieldDisplayLabel(b.field):""}`})}),e.jsxs("div",{className:"space-y-4",children:[!i&&(o==null?void 0:o.conditions)&&o.conditions.length>0&&l==="fields"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:o.conditions.map(D=>e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[e.jsxs("span",{className:"font-medium",children:[a.getFieldDisplayLabel(D.field),":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(D.value)?`${D.value.length} values`:String(D.value)})]},D.id))})]}),l==="fields"&&!i?e.jsx("div",{className:"flex flex-col",children:e.jsx(a.FieldOptionList,{fields:p,selectedIds:sc,onSelect:j,query:x,onQueryChange:m,density:"compact",listLabel:"Filterable fields",listClassName:"max-h-[400px]",autoFocusSearch:!0,emptyMessage:x?`No fields found matching "${x}"`:r.length>0?"All available fields are already filtered":void 0})}):e.jsx(nc,{field:b.field,selectedValues:b.selectedValues,onValuesChange:g,onBack:i?void 0:()=>u("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:i?e.jsx(t.Button,{variant:"destructive",onClick:f,children:"Delete Filter"}):e.jsx(t.Button,{variant:"outline",onClick:k,children:"Reset"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(t.Button,{onClick:N,disabled:!b.field||b.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function nc({field:s,selectedValues:n,onValuesChange:r,onBack:o}){const[c,d]=v.useState(""),{values:i,isLoading:l,isFetching:u}=tc({field:s,searchQuery:c,limit:500}),x=c?i.filter(h=>String(h.value).toLowerCase().includes(c.toLowerCase())):i,m=h=>{const p=n.includes(h);r(p?n.filter(j=>j!==h):[...n,h])},b=()=>{n.length===x.length&&x.length>0?r([]):r(x.map(h=>h.value))};return e.jsxs("div",{className:"space-y-4",children:[o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",onClick:o,children:"← Back"}),e.jsxs(t.Label,{className:"text-sm font-medium",children:["Select values for ",a.getFieldDisplayLabel(s)]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Ke.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(t.Input,{placeholder:"Search values...",value:c,onChange:h=>d(h.target.value),className:"pl-10"})]}),l||u?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(t.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(a.Checkbox,{checked:n.length===x.length&&x.length>0,onCheckedChange:b}),e.jsxs(t.Label,{className:"text-sm",children:["Select All (",x.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:x.map(h=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>m(h.value),children:[e.jsx(a.Checkbox,{checked:n.includes(h.value),onCheckedChange:()=>m(h.value)}),e.jsx(_s,{className:"text-sm",children:h.label})]},h.id))})]})]})}function ac(s,n){return s==="pivotBy"&&(n==="table"||n==="pivotTable")}const rc=[];function oc({field:s,zone:n,index:r,sortDirection:o,onSortDirectionChange:c,hasPivotColumns:d=!1,cardType:i}){var Hs,Qs,Js,Ws,Xs,Zs,en,tn,sn,nn,an,rn,on,ln,cn,dn,un,mn,xn,hn,pn,fn,gn,bn,jn,vn,yn,Cn,Nn,Sn,wn,Tn,En;const l=t.useEditorStore(G=>G.card),u=t.useEditorStore(G=>G.frame),x=t.useDashboardStore(G=>G.isVisualEditing),m=t.useDashboardStore(G=>G.selectedSheetId),b=t.useDashboardStore(G=>G.actions.updateSheetCalculatedFields),h=t.useDashboardStore(G=>G.actions.updateDashboardCalculatedFields),j=t.useDashboardStore(G=>{var Ce;return G.visualEditPendingDashboardCalculatedFields??((Ce=G.dashboard)==null?void 0:Ce.calculatedFields)})??rc,{scopedFields:N,valuePickFilterableFields:f,isLoading:g,hasError:k}=a.useFilterableFields(),{userContext:D}=a.useCurrentUserInfo(),{tokenProps:w}=a.useSemaphorContext(),S=a.canEditLocalCalculatedFields(D),M=a.useTimezone()??void 0,A=a.useResolvedTemporalStylePreferences()??$t.DEFAULT_RESOLVED_VALUE_FORMAT_PREFERENCES,{updateLabel:F,handleAggregationChange:I,handleDetailDateFormatChange:C,handleDimensionFormatChange:E,handleTemporalBucketFormatChange:L,handleGranularityChange:T,handleAliasTemplateChange:R,handlePivotMemberOrderChange:y,handleValueAliasesChange:B,handleMetricFormatChange:P,removeField:O,handleMetricComparisonChange:V,handleMetricComparisonSpecChange:_,handleMetricComparisonPolarityChange:z,handleMetricWindowTransformChange:q,handleMetricWindowOrderByChange:Y,handleMetricWindowDirectionChange:$,handleMetricWindowPartitionToggle:U,handleMetricMovingAverageWindowSizeChange:H,handleMetricMovingAverageMinPeriodsChange:te,handleMetricPreviousPeriodDeltaModeChange:X,handleMetricPercentOfTotalScopeChange:se,handleMetricPercentOfTotalOutputChange:ue,handleMetricTargetValueChange:fe}=a.useFieldManagement(l),[be,ge]=v.useState(!1),[Pe,Oe]=v.useState(()=>{var G;return!!((G=s.parameters)!=null&&G.windowTransform)}),[Ae,Ie]=v.useState(!1),[_e,Ye]=v.useState(!1),[Ve,Le]=v.useState(null),De=v.useMemo(()=>{const G=ce=>ce!=null&&ce.startsWith("card-source-")?ce.replace("card-source-",""):ce,Ce=G(s.id),W=N.find(ce=>{if(s.qualifiedFieldName&&ce.qualifiedFieldName&&ce.qualifiedFieldName===s.qualifiedFieldName||s.qualifiedEntityName&&ce.qualifiedEntityName&&ce.qualifiedEntityName===s.qualifiedEntityName&&ce.name===s.name)return!0;const Ne=G(ce.id);return!!(Ce&&Ne&&Ce===Ne)});return{dataType:(W==null?void 0:W.dataType)||s.dataType,resolvedFromScopedField:!!W}},[s.dataType,s.id,s.name,s.qualifiedEntityName,s.qualifiedFieldName,N]),ae=a.getGranularityOptionsForFieldType(De.dataType),K=v.useMemo(()=>t.readTemporalBucketAuthoringState({fieldId:s.id,dataType:s.dataType,granularity:s.granularity,format:s.format,dateFormat:s.dateFormat,customFormat:s.customFormat,semanticTemporalPresentation:s.semanticTemporalPresentation}),[s.customFormat,s.dataType,s.dateFormat,s.format,s.id,s.granularity,s.semanticTemporalPresentation]),ie=n==="groupBy"?K.ok&&ae.includes(K.granularity)?K.granularity:void 0:ae.includes(s.granularity)?s.granularity:"day",Se=K.ok?K.selection:{value:"auto",customPattern:"",format:Ze.AUTOMATIC_TEMPORAL_BUCKET_FORMAT},[re,he]=v.useState(n==="groupBy"?Se.value:s.dateFormat||"YYYY-MM-DD"),[ze,Z]=v.useState(n==="groupBy"?Se.customPattern:s.customFormat||""),Re=re==="custom",[me,qe]=v.useState(s.aliasTemplate||""),[Fe,Ue]=v.useState(s.valueAliases||{}),[we,oe]=v.useState((Hs=s.parameters)==null?void 0:Hs.filters),ne=G=>{var W;if(n==="groupBy"&&!ie)return;const Ce=ie??"day";if(G==="custom"){const ce=n==="groupBy"?Ze.getTemporalBucketAuthoringOptions(Ce,Se.format,A).find(He=>He.value==="custom"):void 0,Ne=n==="groupBy"?ze||(((W=ce==null?void 0:ce.format)==null?void 0:W.presentation.mode)==="pattern"?ce.format.presentation.pattern:""):ze;he(G),Z(Ne),n==="groupBy"&&L(r,Ze.resolveTemporalBucketAuthoringFormat(Ce,G,Ne))}else he(G),n==="groupBy"?L(r,Ze.resolveTemporalBucketAuthoringFormat(Ce,G)):n==="detailColumns"&&C(r,G,"")},de=G=>{if(n==="groupBy"&&!ie)return;const Ce=ie??"day";Z(G),n==="groupBy"?L(r,Ze.resolveTemporalBucketAuthoringFormat(Ce,"custom",G)):n==="detailColumns"&&C(r,"custom",G)},ve=G=>{if(n==="groupBy"){const Ce=Ze.reconcileTemporalBucketAuthoringFormat(Se.format,G),W=t.readTemporalBucketAuthoringSelection({fieldId:s.id,dataType:s.dataType,granularity:G,format:Ce,semanticTemporalPresentation:s.semanticTemporalPresentation});he(W.value),Z(W.customPattern),T(r,G)}},pe=G=>{qe(G),n==="metrics"&&R(r,G)},Qe=G=>{n==="pivotBy"&&y(r,G)},Me=G=>{Ue(G),n==="metrics"&&B(r,G)},ft=G=>{F(n,r,G)},it=a.getExpressionFieldKind(s);a.getFieldExpressionAnnotation(s);const Ut=a.isManagedCalculatedExpressionField(s),rt=s.role==="metric"&&Ut,Tt=Ut&&(it==="user_calculated"||it==="inline_expression"&&s.fieldScope!=="domain"),tt=Tt?t.resolveLocalCalculatedFieldScope({field:s,sheetFields:(u==null?void 0:u.calculatedFields)||[],dashboardFields:j}):void 0,gt=Tt&&(tt==null?void 0:tt.scope)==="sheet",Gt=Tt&&(tt==null?void 0:tt.scope)==="dashboard",ot=it==="domain_calculated"||s.fieldScope==="domain",Ht=ot?a.resolveDomainCalculatedFieldForEdit(s,N):void 0,ct=ot?"domain":gt?"sheet":Gt?"dashboard":"card",bt=ot?Ht||s:(gt||Gt)&&(tt!=null&&tt.matchedField)?tt.matchedField:s,Rt=ot?Ht?"effective":g?"loading":k?"unavailable":"unverified":void 0,Et=G=>{var Ce;if(oe(G),n==="metrics"){const W={...s,parameters:{...s.parameters,filters:G}},ce=[...((Ce=l.config)==null?void 0:Ce.metricColumns)||[]];ce[r]=W,t.useEditorStore.getState().actions.updateCardConfig(l.id,{metricColumns:ce})}Ie(!1)},Pt=()=>{O(n,r)},jt=t.getDataType(De.dataType||s.dataType),dt=jt==="date",Qt=i==="kpi",It=n==="detailColumns",Jt=(Qs=l.config)==null?void 0:Qs.metricColumns,lt=(Js=l.config)==null?void 0:Js.groupByColumns,Ot=t.useDashboardStore(G=>G.dashboard),Wt=t.useDashboardStore(G=>{var Ce;return(Ce=G.dashboard)==null?void 0:Ce.filters}),Xt=t.useDashboardStore(G=>G.filterValues),Zt=t.useDashboardStore(G=>G.dashboardInputValues),Vt=t.useDashboardStore(G=>G.semanticExecutionPayload),Bt=n==="groupBy"&&ie?Ze.getTemporalBucketAuthoringOptions(ie,Se.format,A):n==="detailColumns"?Gi(ie??"day"):[],Dt=Re?"custom":!ie&&n==="groupBy"?void 0:Bt.some(G=>G.value===re)?re:((Ws=Bt[0])==null?void 0:Ws.value)??"YYYY-MM-DD",es=!!i&&t.COMPARISON_SUPPORTED_CHART_TYPES.includes(i),ts=!!i&&t.COMPARISON_TARGET_SUPPORTED_CHART_TYPES.includes(i),Q=v.useMemo(()=>lt==null?void 0:lt.find(G=>t.getDataType(G.dataType||"")==="date"),[lt]),ee=v.useMemo(()=>t.resolveCardPrimaryDateField({card:l,cardConfig:l.config||{},semanticExecutionPayload:Vt}),[l,Vt]),J=v.useMemo(()=>Q||(ee?{...ee,id:`semantic-primary:${ee.entityId}:${ee.name}`,label:ee.name,role:"groupby",granularity:ee.defaultGranularity||"day"}:void 0),[Q,ee]),Te=je.getAuthoredCardFilters(l),Ee=v.useMemo(()=>{if(!J)return!1;const G=Te;if(!G)return!1;const Ce=ce=>{const Ne=ce.field;return Ne?J.id&&Ne.id===J.id||J.qualifiedFieldName&&Ne.qualifiedFieldName===J.qualifiedFieldName?!0:Ne.name===J.name:!1},W=ce=>ce.conditions.some(He=>t.getDataType(He.field.dataType||"")==="date"&&Ce(He))?!0:ce.groups.some(He=>W(He));return W(G)},[Te,J]),ke=v.useMemo(()=>Oa(Wt||[],J,Xt)||Ui({dashboard:Ot,dateGroupByField:J,dashboardInputValues:Zt,sheetId:m,card:l,timezone:M}),[l,Ot,Wt,Xt,Zt,J,m,M]),Ge=Ee||ke,ye=s,$e=((Xs=ye.comparison)==null?void 0:Xs.mode)==="explicit"?ye.comparison.spec:void 0,ut=((en=(Zs=ye.parameters)==null?void 0:Zs.windowTransform)==null?void 0:en.function)||"none",We=a.isMetricTransformEnabled(ye),Be=We?ut:null,mt=a.supportsMetricTransformForMetric({cardType:i||"table",cardConfig:l.config||{},metric:ye,transformMode:Be||"running_total"}),vt=((tn=ye.comparison)==null?void 0:tn.mode)==="explicit",ss=a.getRunningTotalOrderByCandidates(lt||[]),kt=((an=(nn=(sn=ye.parameters)==null?void 0:sn.windowTransform)==null?void 0:nn.orderBy)==null?void 0:an.fieldId)||"",$a=((ln=(on=(rn=ye.parameters)==null?void 0:rn.windowTransform)==null?void 0:on.orderBy)==null?void 0:ln.direction)||"asc",qs=ss.find(G=>G.id===kt),ms=Be==="running_total"||Be==="moving_average"||Be==="previous_period_delta",Ka=We&&ms&&!!qs&&t.getDataType(qs.dataType||"")!=="date",Ua=a.getDefaultRunningTotalPartitionByFieldIds({cardType:i||"table",cardConfig:l.config||{},orderByFieldId:kt||void 0}),Ga=new Set(((dn=(cn=ye.parameters)==null?void 0:cn.windowTransform)==null?void 0:dn.partitionByFieldIds)||Ua),Ha=i==="pivotTable"||a.isSubtotalEnabledAggregateTable(i||"table",l.config||{}),$s=[...(lt||[]).filter(G=>G.id&&(!ms||G.id!==kt)),...Ha?(((un=l.config)==null?void 0:un.pivotByColumns)||[]).filter(G=>G.id):[]],Ks=((hn=(xn=(mn=ye.parameters)==null?void 0:mn.windowTransform)==null?void 0:xn.movingAverage)==null?void 0:hn.windowSize)||7,Qa=((gn=(fn=(pn=ye.parameters)==null?void 0:pn.windowTransform)==null?void 0:fn.movingAverage)==null?void 0:gn.minPeriods)||1,Ja=((vn=(jn=(bn=ye.parameters)==null?void 0:bn.windowTransform)==null?void 0:jn.previousPeriodDelta)==null?void 0:vn.mode)||"absolute",Us=((Nn=(Cn=(yn=ye.parameters)==null?void 0:yn.windowTransform)==null?void 0:Cn.percentOfTotal)==null?void 0:Nn.scope)||"grand_total",Wa=((Tn=(wn=(Sn=ye.parameters)==null?void 0:Sn.windowTransform)==null?void 0:wn.percentOfTotal)==null?void 0:Tn.output)||"percent",Xa=v.useMemo(()=>(Jt||[]).some(()=>!1),[Jt]);v.useEffect(()=>{We&&Oe(!0)},[We]);const Za=n!=="pivotBy"&&n!=="sortBy",er=ac(n,i),tr=s.memberOrder??"auto",sr=dt&&n==="groupBy"&&(!Qt||Xa),nr=!Qt&&dt&&(n==="groupBy"||It),ar=n==="metrics",rr=!Qt&&jt==="number"&&(n==="groupBy"||It)&&a.isTableNumericPresentationCardType(i),ns=es&&!l.sql&&!l.python&&n==="metrics",or=()=>{const G=s,Ce=n==="metrics"&&rt;return e.jsxs("div",{className:"space-y-1",children:[!Ce&&e.jsx("div",{title:`${s.entityName}.${s.name}`,onPointerDown:W=>{W.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-muted-foreground/80",children:`${s.entityName}.${s.name}`}),Ce&&G.calculatedFormula&&e.jsxs("div",{title:a.formatDisplayFormula(G.calculatedFormula),onPointerDown:W=>{W.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap rounded bg-muted/50 px-1.5 py-0.5 font-mono text-xs text-primary",children:["= ",a.formatDisplayFormula(G.calculatedFormula)]})]})},lr=()=>Za?e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(at,{value:s.label??"",onSave:ft,placeholder:"Display label...",type:"text"})]}):null,ir=()=>n!=="sortBy"?null:e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Order"}),e.jsxs(t.Select,{value:o||"asc",onValueChange:G=>c(G),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{className:"text-xs",value:"asc",children:"Ascending"}),e.jsx(t.SelectItem,{className:"text-xs",value:"desc",children:"Descending"})]})]})]}),cr=()=>er?e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot column order"}),e.jsxs(t.Select,{value:tr,onValueChange:G=>Qe(G),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{className:"text-xs",value:"auto",children:"Auto"}),e.jsx(t.SelectItem,{className:"text-xs",value:"asc",children:"Ascending"}),e.jsx(t.SelectItem,{className:"text-xs",value:"desc",children:"Descending"})]})]})]}):null,Gs=()=>sr?e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),e.jsxs(t.Select,{value:ie,onValueChange:ve,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select granularity..."})}),e.jsx(t.SelectContent,{children:ae.map(G=>e.jsx(t.SelectItem,{className:"text-xs",value:G,children:t.toTitleCase(G)},G))})]})]}):null,dr=()=>nr?e.jsxs(e.Fragment,{children:[Gs(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(t.Select,{value:Dt,onValueChange:ne,disabled:n==="groupBy"&&!ie,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select date format..."})}),e.jsx(t.SelectContent,{children:Bt.map(G=>e.jsx(t.SelectItem,{className:"text-xs",value:G.value,children:G.label},G.value))})]}),Re&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(t.Input,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:ze,onChange:G=>{G.stopPropagation(),de(G.target.value)},onClick:G=>G.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}):null,ur=()=>rr?e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Number Format"}),e.jsx(Is,{value:s.format,onChange:G=>E(It?"detailColumns":"groupBy",r,G),cardType:i,showTitle:!1})]}):null,mr=()=>{var Ce;if(!ar)return null;const G=rt;return e.jsxs(e.Fragment,{children:[G&&S&&!ot&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Formula"}),e.jsxs(t.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>Ye(!0),children:[e.jsx(a.Pencil,{className:"mr-2 h-3 w-3"}),"Edit Formula"]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(t.Select,{value:s.aggregate,onValueChange:W=>{I(r,W)},disabled:G,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select function..."})}),e.jsx(t.SelectContent,{children:Ze.getFieldAggregationOptions(s.dataType).map(W=>e.jsx(t.SelectItem,{className:"text-xs",value:W.value,children:W.label},W.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Number Format"}),e.jsx(Is,{value:ye.format,onChange:W=>P(r,W),cardType:i,showTitle:!1})]}),e.jsx(a.Collapsible,{open:Pe,onOpenChange:Oe,children:e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/20 p-2.5",children:[e.jsx(a.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between rounded-sm px-0.5 py-0.5 text-left",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Metric Transform"}),e.jsxs("div",{className:"flex items-center text-[11px] text-muted-foreground",children:[!Pe&&e.jsx("span",{className:"mr-2",children:We?t.toTitleCase(ut.replace(/_/g," ")):"None"}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 transition-transform",Pe?"rotate-180":"")})]})]})}),e.jsxs(a.CollapsibleContent,{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Transform"}),e.jsxs(t.Select,{value:We?ut:"none",onValueChange:W=>q(r,W),disabled:!mt.supported&&!We,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select transform..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"none",children:"None"}),e.jsx(t.SelectItem,{value:"running_total",disabled:vt,children:"Running Total"}),e.jsx(t.SelectItem,{value:"moving_average",disabled:vt,children:"Moving Average"}),e.jsx(t.SelectItem,{value:"previous_period_delta",disabled:vt,children:"Previous Period Delta"}),e.jsx(t.SelectItem,{value:"percent_of_total",disabled:vt,children:"Percent of Total"})]})]}),!mt.supported&&!We&&e.jsx("div",{className:"text-xs text-muted-foreground",children:mt.reason}),vt&&!We&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Disable comparison to enable metric transforms."})]}),We&&e.jsxs(e.Fragment,{children:[ms&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Order By"}),e.jsxs(t.Select,{value:kt,onValueChange:W=>Y(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select order field..."})}),e.jsx(t.SelectContent,{children:ss.filter(W=>!!W.id).map(W=>e.jsx(t.SelectItem,{value:W.id,className:"text-xs",children:W.label||W.name},W.id))})]}),!kt&&e.jsx("div",{className:"text-xs text-amber-700",children:"No date trend detected. Select an order field."}),Ka&&e.jsx("div",{className:"text-xs text-amber-700",children:"No date trend detected. The transform will follow the selected order field."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Direction"}),e.jsxs(t.Select,{value:$a,onValueChange:W=>$(r,W),disabled:!kt,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select direction..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{className:"text-xs",value:"asc",children:"Ascending"}),e.jsx(t.SelectItem,{className:"text-xs",value:"desc",children:"Descending"})]})]})]})]}),Be==="moving_average"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Window Size"}),e.jsx(t.Input,{type:"number",min:1,className:"h-8 text-xs",value:Ks,onChange:W=>H(r,Number(W.target.value))}),e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Min Periods"}),e.jsx(t.Input,{type:"number",min:1,max:Ks,className:"h-8 text-xs",value:Qa,onChange:W=>te(r,Number(W.target.value))})]}),Be==="previous_period_delta"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),e.jsxs(t.Select,{value:Ja,onValueChange:W=>X(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select output..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"absolute",children:"Absolute Delta"}),e.jsx(t.SelectItem,{value:"percent",children:"Percent Delta"})]})]})]}),Be==="percent_of_total"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Scope"}),e.jsxs(t.Select,{value:Us,onValueChange:W=>se(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select scope..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"grand_total",children:"Grand Total"}),e.jsx(t.SelectItem,{value:"partition_total",children:"Partition Total"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),e.jsxs(t.Select,{value:Wa,onValueChange:W=>ue(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select output..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"percent",children:"Percent"}),e.jsx(t.SelectItem,{value:"fraction",children:"Fraction"})]})]})]})]}),(Be==="running_total"||Be==="moving_average"||Be==="previous_period_delta"||Be==="percent_of_total"&&Us==="partition_total")&&$s.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Reset By"}),e.jsx("div",{className:"space-y-1",children:$s.map(W=>{const ce=!!W.id&&Ga.has(W.id);return e.jsxs("button",{type:"button",onClick:()=>W.id&&U(r,W.id),className:t.cn("flex h-7 w-full items-center justify-between rounded border px-2 text-xs",ce?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground"),children:[e.jsx("span",{children:W.label||W.name}),ce?e.jsx(t.Check,{className:"h-3 w-3"}):null]},W.id)})})]})]})]})]})}),ns&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(t.Select,{value:ye.comparison?ye.comparison.mode==="off"?"off":ye.comparison.spec.kind:"inherit",disabled:We,onValueChange:W=>V(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select comparison type..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"inherit",children:"Inherit dashboard comparison (default)"}),e.jsx(t.SelectItem,{value:"off",children:"Off"}),(()=>{const W=!J||!Ge,ce=J?Ge?void 0:"Add a date filter to enable":"Configure a semantic primary date or add a date axis",Ne=(He,Xe)=>e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx(t.SelectItem,{value:He,disabled:W,title:ce,children:Xe})}),W&&ce&&e.jsx(t.TooltipContent,{side:"right",children:ce})]})});return e.jsxs(e.Fragment,{children:[Ne("previous_period","Previous Period"),Ne("previous_year","Previous Year")]})})(),ts&&e.jsx(t.SelectItem,{value:"target",children:"Target"})]})]}),!ye.comparison&&e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Dashboard comparison is not available yet. This metric will follow it when a viewer sets it."})]}),ns&&$e&&($e.kind==="previous_period"||$e.kind==="previous_year")&&e.jsxs("div",{className:"space-y-2 rounded border border-border/60 p-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:$e.kind==="previous_year"?"Years back":"Periods back"}),e.jsx(t.Input,{type:"number",min:1,step:1,value:$e.kind==="previous_year"?$e.offsetYears||1:$e.offsetPeriods||1,onChange:W=>{const ce=Number(W.target.value);!Number.isSafeInteger(ce)||ce<=0||($e.kind==="previous_year"?_(r,{...$e,offsetYears:ce===1?void 0:ce}):_(r,{...$e,offsetPeriods:ce===1?void 0:ce}))},className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Alignment"}),e.jsxs(t.Select,{value:$e.alignment||"calendar",onValueChange:W=>_(r,{...$e,alignment:W==="calendar"?void 0:W}),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"calendar",children:"Calendar"}),e.jsx(t.SelectItem,{value:"weekday",children:"Match weekdays"})]})]})]}),e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"To date"}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Match the elapsed portion of an incomplete current window."})]}),e.jsx(t.Switch,{size:"xs",checked:$e.toDate===!0,onCheckedChange:W=>_(r,{...$e,toDate:W?!0:void 0})})]}),e.jsxs("p",{className:"text-[11px] leading-4 text-muted-foreground",children:["Anchored to"," ",e.jsx("span",{className:"text-foreground",children:(J==null?void 0:J.label)||(J==null?void 0:J.name)}),". The resolved comparison dates appear after the card runs."]})]}),ns&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Favorable direction"}),e.jsxs(t.Select,{value:t.getMetricComparisonPolarity(ye),disabled:!!ye.semanticComparisonPolarity,onValueChange:W=>z(r,W),children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"higher_is_better",children:"Higher is better"}),e.jsx(t.SelectItem,{value:"lower_is_better",children:"Lower is better"}),e.jsx(t.SelectItem,{value:"neutral",children:"Neutral"})]})]}),ye.semanticComparisonPolarity&&e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Governed by this metric's semantic definition."})]}),ns&&((Ce=ye.comparison)==null?void 0:Ce.mode)==="explicit"&&ye.comparison.spec.kind==="target"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(t.Input,{type:"number",value:ye.comparison.spec.targetValue!==void 0&&ye.comparison.spec.targetValue!==null?String(ye.comparison.spec.targetValue):"",onChange:W=>{const ce=W.target.value;if(ce===""){fe(r,void 0);return}const Ne=Number(ce);fe(r,Number.isFinite(Ne)?Ne:void 0)},className:"h-8 text-xs",placeholder:"Enter target value..."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(we==null?void 0:we.conditions)&&we.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:we.conditions.map(W=>e.jsxs("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{Le(W),Ie(!0)},children:[e.jsxs("span",{className:"font-medium",children:[W.field.label,":"]}),e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(W.value)?W.value.length===1?String(W.value[0]):W.value.length<=2?W.value.join(", "):`${W.value.slice(0,2).join(", ")} +${W.value.length-2}`:String(W.value)})}),Array.isArray(W.value)&&W.value.length>1&&e.jsx(t.TooltipContent,{side:"top",className:"max-w-[300px]",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"mb-1 font-medium",children:["Selected values (",W.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:W.value.map((ce,Ne)=>e.jsx("div",{children:String(ce)},Ne))})]})})]})}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:ce=>{var He;ce.stopPropagation();const Ne=we.conditions.filter(Xe=>Xe.id!==W.id);if(Ne.length>0){const Xe={...we,conditions:Ne};Et(Xe)}else if(oe(void 0),n==="metrics"){const Xe={...s,parameters:{...s.parameters,filters:void 0}},nt=[...((He=l.config)==null?void 0:He.metricColumns)||[]];nt[r]=Xe,t.useEditorStore.getState().actions.updateCardConfig(l.id,{metricColumns:nt})}},children:e.jsx(le.X,{className:"h-3 w-3"})})]},W.id))}),e.jsxs(t.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{Le(null),Ie(!0)},children:[e.jsx(a.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(ec,{column:s}),d&&e.jsxs(e.Fragment,{children:[e.jsx(Hi,{aliasTemplate:me,onAliasTemplateChange:pe}),e.jsx(Qi,{valueAliases:Fe,onValueAliasesChange:Me})]})]})};we!=null&&we.conditions&&we.conditions.length>0;const xr=n!=="sortBy";return e.jsxs(e.Fragment,{children:[e.jsx(Pa,{id:s.id,label:a.getMetricDisplayLabel(s),dataType:jt,calculated:a.getCalculatedGlyphKind(s),open:be,onOpenChange:ge,onRemove:Pt,sortDirection:o,onSortDirectionChange:n==="sortBy"?c:void 0,badge:e.jsx(e.Fragment,{children:n==="metrics"&&((En=we==null?void 0:we.conditions)==null?void 0:En.length)&&!be&&e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex shrink-0 items-center gap-1 rounded-[3px] bg-primary/10 px-1 text-[10px] tabular-nums text-primary/90",children:[e.jsx(a.Filter,{className:"h-2.5 w-2.5"}),e.jsx("span",{children:we.conditions.length})]})}),e.jsx(t.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:we.conditions.map(G=>e.jsxs("div",{children:[G.field.label,":"," ",Array.isArray(G.value)?`${G.value.length} values`:String(G.value)]},G.id))})})]})})}),children:xr&&e.jsxs(e.Fragment,{children:[or(),ir(),cr(),lr(),i==="kpi"&&Gs(),dr(),ur(),mr()]})}),Ae&&e.jsx(Va,{open:Ae,onOpenChange:G=>{Ie(G),G||Le(null)},availableFields:f,existingFilters:we,editingCondition:Ve,onSave:G=>{var Ce;if(G)Et(G);else if(oe(void 0),n==="metrics"){const W={...s,parameters:{...s.parameters,filters:void 0}},ce=[...((Ce=l.config)==null?void 0:Ce.metricColumns)||[]];ce[r]=W,t.useEditorStore.getState().actions.updateCardConfig(l.id,{metricColumns:ce})}Le(null)}}),_e&&n==="metrics"&&rt&&e.jsx(a.CalculatedFieldEditor,{open:_e,onOpenChange:Ye,availableFields:N,existingField:bt,existingFieldScope:ct,domainDefinitionStatus:Rt,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:G=>{if(G.role!=="metric")return;const{card:Ce,frame:W,actions:ce}=t.useEditorStore.getState(),Ne=ct==="dashboard"?j:W.calculatedFields||[],{cardConfigPatch:He,nextStoredFields:Xe,nextSharedFields:nt}=a.saveCalculatedFieldToCardScope({cardConfig:Ce.config,storedFields:Ce.calculatedFields||[],sharedFields:Ne,updatedField:G,editingField:bt,previousScope:ct});Object.keys(He).length&&ce.updateCardConfig(l.id,He),ce.updateCard(l.id,{calculatedFields:Xe}),ct==="dashboard"&&nt!==Ne?h(nt):nt!==Ne&&a.commitSharedCalculatedFields({nextSharedFields:nt,currentSharedFields:Ne,isVisualEditing:x,selectedSheetId:m,updateFrame:ce.updateFrame,updateSheetCalculatedFields:b})},onSaveToSheet:G=>{if(G.role!=="metric")return;const{card:Ce,frame:W,actions:ce}=t.useEditorStore.getState(),Ne=s,He=W.calculatedFields||[],{cardConfigPatch:Xe,nextStoredFields:nt,nextSheetFields:xs,nextDashboardFields:yt}=a.saveCalculatedFieldToSheetScope({cardConfig:Ce.config,storedFields:Ce.calculatedFields||[],sheetFields:He,dashboardFields:j,updatedField:{...G,id:Ne.id,aliasTemplate:Ne.aliasTemplate,valueAliases:Ne.valueAliases,parameters:Ne.parameters,customFormat:Ne.customFormat},editingField:bt,previousScope:ct});a.commitSharedCalculatedFields({nextSharedFields:xs,currentSharedFields:He,isVisualEditing:x,selectedSheetId:m,updateFrame:ce.updateFrame,updateSheetCalculatedFields:b}),yt&&yt!==j&&h(yt),Object.keys(Xe).length&&ce.updateCardConfig(l.id,Xe),ce.updateCard(l.id,{calculatedFields:nt})},onSaveToDashboard:G=>{if(G.role!=="metric")return;const{card:Ce,frame:W,actions:ce}=t.useEditorStore.getState(),Ne=s,He=W.calculatedFields||[],{cardConfigPatch:Xe,nextStoredFields:nt,nextSharedFields:xs,nextSheetFields:yt}=a.saveCalculatedFieldToSharedScope({cardConfig:Ce.config,storedFields:Ce.calculatedFields||[],sharedFields:j,sheetFields:He,updatedField:{...G,id:Ne.id,aliasTemplate:Ne.aliasTemplate,valueAliases:Ne.valueAliases,parameters:Ne.parameters,customFormat:Ne.customFormat},editingField:bt,previousScope:ct});h(xs),yt&&yt!==He&&a.commitSharedCalculatedFields({nextSharedFields:yt,currentSharedFields:He,isVisualEditing:x,selectedSheetId:m,updateFrame:ce.updateFrame,updateSheetCalculatedFields:b}),Object.keys(Xe).length&&ce.updateCardConfig(l.id,Xe),ce.updateCard(l.id,{calculatedFields:nt})},cardId:l.id})]})}function lc({field:s,onRemove:n}){const[r,o]=v.useState(!1);return e.jsx(Pa,{id:s.id,label:a.getMetricDisplayLabel(s),dataType:s.dataType,calculated:a.getCalculatedGlyphKind(s),open:r,onOpenChange:o,onRemove:n,children:e.jsx(Ds,{fieldId:s.id})})}function ic({concept:s}){const{title:n,description:r}=cc[s];return e.jsxs(a.HoverCard,{openDelay:150,closeDelay:50,children:[e.jsx(a.HoverCardTrigger,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":`What does ${n} mean?`,className:"inline-flex h-3 w-3 shrink-0 items-center justify-center text-muted-foreground/70 transition-colors hover:text-foreground",children:e.jsx(a.CircleHelp,{className:"h-3 w-3"})})}),e.jsxs(a.HoverCardContent,{side:"right",align:"start",sideOffset:8,className:"w-[260px] space-y-2 rounded-control border border-border bg-popover p-3 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[12px] font-semibold text-foreground",children:n}),e.jsx("p",{className:"text-[11px] leading-[1.45] text-muted-foreground",children:r})]}),s!=="detailColumns"&&e.jsx(dc,{highlight:s})]})]})}const cc={groupBy:{title:"Rows",description:"Each unique value becomes a row. Use for the dimensions you want stacked vertically."},pivotBy:{title:"Pivot Columns",description:"Each unique value spreads across as a column, splitting your metrics horizontally."},metrics:{title:"Metrics",description:"The aggregated numbers (sum, count, avg…) that fill the cells of your chart or table."},detailColumns:{title:"Columns",description:"Raw column values with no aggregation — the underlying detail rows from the database."}};function dc({highlight:s}){const n=s==="pivotBy",r=s==="groupBy",o=s==="metrics",c="bg-foreground/[0.06] font-medium text-foreground dark:bg-foreground/[0.12]";return e.jsx("div",{className:"overflow-hidden rounded-control border border-border",children:e.jsxs("table",{className:"w-full text-[10px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border bg-muted/40",children:[e.jsx("th",{className:"px-1.5 py-1 text-left font-normal text-muted-foreground"}),["North","South","East"].map(d=>e.jsx("th",{className:t.cn("px-1.5 py-1 text-center font-normal text-muted-foreground",n&&c),children:d},d))]})}),e.jsx("tbody",{children:ta.map((d,i)=>e.jsxs("tr",{className:t.cn(i!==ta.length-1&&"border-b border-border/60"),children:[e.jsx("td",{className:t.cn("px-1.5 py-1 text-left text-muted-foreground",r&&c),children:d.label}),d.values.map((l,u)=>e.jsx("td",{className:t.cn("px-1.5 py-1 text-right font-mono tabular-nums text-muted-foreground",o&&c),children:l},u))]},d.label))})]})})}const ta=[{label:"Electronics",values:["2,300","1,800","3,400"]},{label:"Clothing",values:["1,300","620","480"]}],uc={groupBy:a.Rows3,pivotBy:ks,metrics:Rr,detailColumns:t.Table2,sortBy:aa};function Yt({onRemoveField:s,zone:n,fields:r,label:o,placeholder:c,shouldShow:d,hasPivotColumns:i=!1,activeField:l=null}){const{isOver:u,setNodeRef:x}=a.useDroppable({id:n}),{updateSortByColumn:m}=t.useEditorActions(),b=t.useEditorStore(k=>k.card),h=t.useEditorStore(k=>k.card.type),p=r.length>0,j=v.useMemo(()=>!l||!u?!0:a.validateFieldForChartType(l,n,h).isValid,[l,u,n,h]),N=(k,D)=>{var S;!((S=b.config)!=null&&S.sortByColumns)||b.config.sortByColumns.findIndex(M=>M.id===k)===-1||m(b.id,k,{direction:D})};if(n==="sortBy"&&d===!1)return null;const f=n!=="sortBy"&&h!=="kpi",g=uc[n]||a.Plus;return e.jsxs("div",{className:"w-full",role:"group","aria-label":o,children:[e.jsx(t.Label,{className:"mb-1 block text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:o}),e.jsx("div",{ref:x,className:t.cn("rounded-control transition-colors",{"border border-foreground/40 bg-muted/50":u&&j,"border border-destructive/40 bg-destructive/5":u&&!j,"border border-dashed border-border/50 bg-background":!u&&!p}),children:r.length===0?e.jsxs("div",{className:"flex h-9 items-center justify-center gap-1.5 text-[11px] text-muted-foreground/80",children:[e.jsx(g,{className:"h-3 w-3 shrink-0 text-muted-foreground/60"}),e.jsx("span",{children:c}),f&&e.jsx(ic,{concept:n})]}):e.jsx(a.SortableContext,{id:n,items:r.map(k=>k.id),strategy:a.verticalListSortingStrategy,children:e.jsx("div",{className:"space-y-1",children:r.map((k,D)=>{const S=k.direction;return h==="matrixTable"?e.jsx(lc,{field:k,onRemove:()=>s(n,D)},k.id):e.jsx(oc,{field:k,zone:n,index:D,sortDirection:S,onSortDirectionChange:M=>N(k.id,M),hasPivotColumns:i,cardType:h},k.id)})})})})]})}const mc=[];function xc({onRemoveField:s,onResetFields:n,groupByFields:r,pivotByFields:o,metricsFields:c,sortByFields:d,detailFields:i,activeField:l}){var U,H,te;const[u,x]=v.useState(!1);t.useEditorStore(X=>{var se;return!!((se=X.card.customCardPreferences)!=null&&se.url)});const m=t.useEditorStore(X=>X.card),b=t.useEditorStore(X=>X.frame),h=xe.findCustomVisualConfigCard(b,m),{manifest:p}=a.useCustomVisual(((U=h==null?void 0:h.customCardPreferences)==null?void 0:U.url)||""),j=(H=p==null?void 0:p.visuals)==null?void 0:H.find(X=>{var se;return X.name===((se=h==null?void 0:h.customCardPreferences)==null?void 0:se.componentName)}),N=xe.resolveMultiInputType(h,j)==="multiple";N&&((te=h==null?void 0:h.customCardPreferences)!=null&&te.url);const f=xe.getConfigSlotExpectedType(j==null?void 0:j.slots);t.useEditorStore(X=>X.actions.updateCardConfig);const g=t.useEditorStore(X=>X.actions.updateCard),k=t.useEditorStore(X=>X.actions.updateFrame),D=t.useDashboardStore(X=>X.isVisualEditing),w=t.useDashboardStore(X=>X.selectedSheetId),S=t.useDashboardStore(X=>X.actions.updateSheetCalculatedFields),M=t.useDashboardStore(X=>X.actions.updateDashboardCalculatedFields),F=t.useDashboardStore(X=>{var se;return X.visualEditPendingDashboardCalculatedFields??((se=X.dashboard)==null?void 0:se.calculatedFields)})??mc,{scopedFields:I}=a.useScopedFields(),{userContext:C}=a.useCurrentUserInfo(),E=N&&(h==null?void 0:h.id)===m.id&&f?f:m==null?void 0:m.type,L=E==="detailTable",T=r.length>0||c.length>0||i.length>0,R=!L&&(E!=="kpi"||c.length<=2),y=!L,B=!L&&E!=="kpi",P=E!=="kpi"&&E!=="matrixTable"&&T,O=L,V="Drop sort fields here",_=a.canEditLocalCalculatedFields(C),z=["pie","doughnut","polar","funnel","aggregateTable","bubble","scatter"].includes(E),q=B&&!z,Y=()=>E==="kpi"?{label:"Trend By",placeholder:"Drop trend field here"}:{label:"Rows",placeholder:"Drop dimensions here"},$=()=>E==="kpi"?{label:"Metric",placeholder:"Drop metric here"}:{label:"Metrics",placeholder:"Drop metrics here"};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between bg-background px-4 py-2",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:"Fields"}),T&&e.jsx("button",{type:"button","aria-label":"Reset all field selections",onClick:n,className:"text-[11px] text-muted-foreground transition-colors hover:text-foreground",children:"Reset"})]}),e.jsxs("div",{className:"space-y-3 px-4 pb-6 pt-3",children:[R&&e.jsx(Yt,{zone:"groupBy",onRemoveField:s,fields:r,label:Y().label,placeholder:Y().placeholder,activeField:l}),q&&e.jsx(Yt,{zone:"pivotBy",onRemoveField:s,fields:o,label:"Pivot Columns",placeholder:"Drop pivot fields here",activeField:l}),y&&e.jsx(Yt,{zone:"metrics",onRemoveField:s,fields:c,label:$().label,placeholder:$().placeholder,hasPivotColumns:o.length>0,activeField:l}),O&&e.jsx(Yt,{zone:"detailColumns",onRemoveField:s,fields:i,label:"Columns",placeholder:"Drop columns here"}),c.length>=1&&_&&e.jsxs(t.Button,{variant:"outline",size:"sm",onClick:()=>x(!0),className:"mt-1.5 w-full justify-start border-border/60 border-dashed bg-background text-xs text-foreground/70 hover:bg-muted/40 hover:text-foreground",children:[e.jsx(a.Calculator,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),P&&e.jsx(Yt,{zone:"sortBy",onRemoveField:s,fields:d,label:"Sort By",placeholder:V,activeField:l})]}),e.jsx(a.CalculatedFieldEditor,{open:u,onOpenChange:x,availableFields:I,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:X=>{if(X.role!=="metric")return;const{nextStoredFields:se}=a.saveCalculatedFieldToCardScope({storedFields:m.calculatedFields||[],sharedFields:b.calculatedFields||[],updatedField:X,previousScope:"card"});g(m.id,{calculatedFields:se})},onSaveToSheet:X=>{if(X.role!=="metric")return;const se=b.calculatedFields||[],{nextSheetFields:ue}=a.saveCalculatedFieldToSheetScope({storedFields:m.calculatedFields||[],sheetFields:se,updatedField:X,previousScope:"sheet"});a.commitSharedCalculatedFields({nextSharedFields:ue,currentSharedFields:se,isVisualEditing:D,selectedSheetId:w,updateFrame:k,updateSheetCalculatedFields:S})},onSaveToDashboard:X=>{if(X.role!=="metric")return;const{nextSharedFields:se}=a.saveCalculatedFieldToSharedScope({storedFields:m.calculatedFields||[],sharedFields:F,updatedField:X,previousScope:"dashboard"});M(se)},cardId:m.id})]})}function hc(){var k,D,w;const s=t.useEditorStore(S=>{var M;return(M=S.card)==null?void 0:M.type}),n=s==="kpi",[r,o]=v.useState(n),[c,d]=v.useState(!1),i=t.useEditorStore(S=>{var M;return!!((M=S.card.customCardPreferences)!=null&&M.url)}),l=t.useEditorStore(S=>S.card),u=t.useEditorStore(S=>S.frame),x=xe.findCustomVisualConfigCard(u,l),{manifest:m}=a.useCustomVisual(((k=x==null?void 0:x.customCardPreferences)==null?void 0:k.url)||""),b=(D=m==null?void 0:m.visuals)==null?void 0:D.find(S=>{var M;return S.name===((M=x==null?void 0:x.customCardPreferences)==null?void 0:M.componentName)}),p=xe.resolveMultiInputType(x,b)==="multiple"&&!!((w=x==null?void 0:x.customCardPreferences)!=null&&w.url),j=!i||p,N=i||p,f=n?"KPI Settings":"Chart Settings",g=j&&!t.isTableChartType(s);return v.useEffect(()=>{n&&o(!0)},[n]),!g&&!N?null:e.jsxs("div",{className:"shrink-0 border-t border-border bg-background",children:[g&&r&&e.jsx("div",{className:t.cn("overflow-y-auto border-b border-border px-4",n?"max-h-[72vh]":"max-h-[50vh]"),children:e.jsx(a.Accordion,{type:"single",collapsible:!0,className:"w-full divide-y divide-border/60 [&_h3]:sticky [&_h3]:top-0 [&_h3]:z-10 [&_h3]:bg-background",children:e.jsx(Ra,{mode:"config"})})}),g&&e.jsxs("button",{type:"button",onClick:()=>o(S=>!S),className:"flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(a.Settings2,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:f})]}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 text-muted-foreground transition-transform",r&&"rotate-180"),strokeWidth:1.75})]}),N&&c&&e.jsx("div",{className:"max-h-[40vh] overflow-y-auto border-b border-t border-border px-4",children:e.jsx(Ia,{})}),N&&e.jsxs("button",{type:"button",onClick:()=>d(S=>!S),className:t.cn("flex w-full items-center justify-between px-4 py-2.5 text-left transition-colors hover:bg-muted/50",g&&"border-t border-border"),children:[e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(ra,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-foreground/70",children:"Component settings"})]}),e.jsx(le.ChevronDown,{className:t.cn("h-3 w-3 text-muted-foreground transition-transform",c&&"rotate-180"),strokeWidth:1.75})]})]})}function pc({onEditJoins:s}){const n=t.useEditorStore(u=>u.card),{autoJoinMetadata:r}=a.useEditorCardQuery(n);if(!(r!=null&&r.autoResolved))return null;const{resolvedJoinPlan:o}=r,c=(o==null?void 0:o.joins)||[];if(c.length===0)return null;const d=u=>!u||u.length===0?"No conditions":u.map(x=>{var p,j,N,f;const m=`${(p=x.source)==null?void 0:p.entityName}.${(j=x.source)==null?void 0:j.name}`,b=`${(N=x.target)==null?void 0:N.entityName}.${(f=x.target)==null?void 0:f.name}`,h=x.operator||"=";return`${m} ${h} ${b}`}).join(" AND "),i=u=>!u.joinKeyGroups||u.joinKeyGroups.length===0?"No conditions defined":u.joinKeyGroups.length===1?d(u.joinKeyGroups[0].keys):u.joinKeyGroups.map((x,m)=>({id:m,operator:x.operator,condition:d(x.keys)})),l=e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("button",{type:"button",className:"shrink-0 cursor-help rounded-control px-1 font-mono text-[10px] tabular-nums text-muted-foreground/70 transition-colors hover:bg-muted hover:text-foreground","aria-label":`${c.length} resolved ${c.length===1?"join":"joins"}`,children:c.length})}),e.jsx(t.TooltipContent,{side:"bottom",align:"start",className:"max-w-md border border-border bg-popover p-2 text-popover-foreground shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:e.jsx("div",{className:"space-y-2",children:c.map((u,x)=>{const m=i(u),b=Array.isArray(m);return e.jsxs("div",{className:"rounded-md border border-border bg-background p-2 text-foreground",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-medium text-foreground",children:u.source.name}),e.jsx(a.ArrowRight,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:u.target.name})]}),e.jsx("span",{className:"shrink-0 rounded-[3px] border border-border px-1 font-mono text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:u.joinType})]}),e.jsx("div",{className:"mt-1 space-y-1",children:b?m.map(h=>e.jsxs("div",{className:"rounded bg-muted/30 px-2 py-1",children:[e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:h.condition}),h.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",h.operator,")"]})]},h.id)):e.jsx("div",{className:"rounded bg-muted/30 px-2 py-1",children:e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:m})})})]},u.id||x)})})})]})});return e.jsxs("div",{className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted",children:[e.jsx(a.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:"Resolved joins"}),l,s&&e.jsx("button",{type:"button",onClick:s,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:border-ring","aria-label":"Edit resolved joins",children:e.jsx(a.SquarePen,{className:"h-3 w-3",strokeWidth:1.75})})]})}function fc({onRemoveField:s,onResetFields:n,selectedChart:r,onChartChange:o,isVisible:c=!0,onToggleVisibility:d,groupByFields:i,pivotByFields:l,metricsFields:u,sortByFields:x,detailFields:m,activeField:b}){var I;const[h,p]=v.useState(!1),j=t.useEditorStore(C=>C.card),N=t.useEditorStore(C=>C.editorContext),f=t.useEditorStore(C=>C.actions.updateCardConfig),g=(N==null?void 0:N.type)==="documentSection",{autoJoinMetadata:k}=a.useEditorCardQuery(j),D=je.getAuthoredCardJoinPlan(j)||(k!=null&&k.autoResolved?k.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),w=((I=j==null?void 0:j.dataSource)==null?void 0:I.selectedEntities)||[],S=C=>{f(j.id,je.withAuthoredCardJoinPlan(j,C)),p(!1)},M=()=>{f(j.id,je.withAuthoredCardJoinPlan(j,void 0)),p(!1)},A=()=>{p(!1)},F=()=>{p(!0)};return c?e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[325px] min-w-[325px] shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",children:[!g&&e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(qo,{selectedChart:r,onChartChange:o})}),d&&e.jsx("div",{className:"px-2 pt-4",children:e.jsx(a.IconButton,{tooltip:"Hide chart configuration","aria-label":"Hide chart configuration",onClick:d,className:"h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:e.jsx(a.ChevronLeft,{className:"h-4 w-4",strokeWidth:1.75})})})]}),e.jsxs(t.ScrollArea,{className:"min-h-0 w-full flex-1 basis-0 border-t border-border [&>[data-radix-scroll-area-viewport]]:overscroll-none [&>[data-radix-scroll-area-viewport]>div]:!block [&>[data-radix-scroll-area-viewport]>div]:w-full",children:[e.jsx("div",{className:"px-4 pt-4 empty:hidden",children:e.jsx(pc,{onEditJoins:F})}),e.jsx(xc,{onRemoveField:s,onResetFields:n,groupByFields:i,pivotByFields:l,metricsFields:u,sortByFields:x,detailFields:m,activeField:b})]}),e.jsx(hc,{}),e.jsx(la,{open:h,onOpenChange:p,joinPlan:D,availableDataSources:w,onSave:S,onCancel:A,onRemove:M,children:e.jsx("div",{})})]}):e.jsx("div",{"data-content":"Chart Configuration Panel (collapsed)",className:"flex w-9 shrink-0 flex-col items-center border-r border-border bg-background transition-all duration-300 ease-in-out",children:d&&e.jsx(a.IconButton,{tooltip:"Show chart configuration","aria-label":"Show chart configuration",onClick:d,className:"mt-3 h-7 w-7 rounded-[5px] p-0 text-muted-foreground hover:text-foreground",children:e.jsx(Ke.ChevronRight,{className:"h-4 w-4",strokeWidth:1.75})})})}function gc({initialFilters:s,availableFields:n}={}){const[r,o]=v.useState(s||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});t.useEditorStore(w=>w.card.dataSource);const{filterableFields:c,isLoading:d}=a.useFilterableFields(),i=n||c||[],l={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=w=>{const S=M=>{if(M.id===w){const A=i[0]||l,F=t.getDataType(A.dataType)==="date";return{...M,conditions:[...M.conditions,{id:`condition-${Date.now()}`,field:A,operator:F?"between":"=",value:F?[]:""}]}}return{...M,groups:M.groups.map(S)}};o(S(r))},x=w=>{const S=M=>{if(M.id===w){const A=i[0]||l,F=t.getDataType(A.dataType)==="date";return{...M,groups:[...M.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:A,operator:F?"between":"=",value:F?[]:""}],groups:[]}]}}return{...M,groups:M.groups.map(S)}};o(S(r))},m=(w,S)=>{const M=A=>A.id===w?{...A,conditions:A.conditions.filter(F=>F.id!==S)}:{...A,groups:A.groups.map(M)};o(M(r))},b=(w,S)=>{const M=A=>A.id===w?{...A,groups:A.groups.filter(F=>F.id!==S)}:{...A,groups:A.groups.map(M)};o(M(r))},h=(w,S,M,A)=>{if(M==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const F=I=>I.id===w?{...I,conditions:I.conditions.map(C=>C.id===S?{...C,[M]:A}:C)}:{...I,groups:I.groups.map(F)};o(F(r))},p=(w,S,M)=>{const A=F=>F.id===w?{...F,conditions:F.conditions.map(I=>I.id===S?{...I,...M}:I)}:{...F,groups:F.groups.map(A)};o(A(r))},j=(w,S)=>{const M=A=>A.id===w?{...A,logicalOperator:S}:{...A,groups:A.groups.map(M)};o(M(r))},N=(w,S)=>{const M=A=>A.id===w?{...A,negate:S}:{...A,groups:A.groups.map(M)};o(M(r))},f=(w,S,M)=>{const A=F=>F.id===w?{...F,conditions:a.arrayMove(F.conditions,S,M)}:{...F,groups:F.groups.map(A)};o(A(r))},g=(w,S,M)=>{const A=F=>F.id===w?{...F,groups:a.arrayMove(F.groups,S,M)}:{...F,groups:F.groups.map(A)};o(A(r))},k=w=>{if(!w||w.conditions.length===0&&w.groups.length===0)return"-- No filters defined";const S=A=>{let F="";typeof A.field=="object"?F=A.field.entityName?`${A.field.entityName}.${A.field.name}`:A.field.name:F=String(A.field);const I=A.operator;let C=A.value;if(A.field.dataType==="string"&&!["in","not in"].includes(A.operator))typeof C=="string"?C=`'${C}'`:Array.isArray(C)&&(C=`'${C.join(", ")}'`);else if(A.field.dataType==="date"||A.field.dataType==="datetime"||A.field.dataType==="timestamp")if(A.operator==="between"&&Array.isArray(C)&&C.length===2){const E=C[0]?`'${C[0]}'`:"NULL",L=C[1]?`'${C[1]}'`:"NULL";return`${F} BETWEEN ${E} AND ${L}`}else if((A.operator==="in"||A.operator==="not in")&&Array.isArray(C)){const E=C.map(L=>L?`'${L}'`:"NULL").join(", ");return`${F} ${I} (${E})`}else typeof C=="string"||C instanceof Date?C=`'${C}'`:Array.isArray(C)&&C.length>0&&(C=`'${C[0]}'`);else if(["in","not in"].includes(A.operator)){let E=[];Array.isArray(C)?E=C.map(L=>typeof L=="string"?`'${L}'`:String(L)):typeof C=="string"?E=C.split(",").map(L=>{const T=L.trim();return A.field.dataType==="string"?`'${T}'`:T}):typeof C=="number"&&(E=[String(C)]),C=`(${E.join(", ")})`}switch(I){case"contains":return typeof C=="string"?`${F} LIKE '%${C.replace(/'/g,"")}'`:`${F} LIKE '%${String(C)}'`;case"startsWith":return typeof C=="string"?`${F} LIKE '${C.replace(/'/g,"")}%'`:`${F} LIKE '${String(C)}%'`;case"endsWith":return typeof C=="string"?`${F} LIKE '%${C.replace(/'/g,"")}'`:`${F} LIKE '%${String(C)}'`;case"isNull":return`${F} IS NULL`;case"isNotNull":return`${F} IS NOT NULL`;default:return`${F} ${I} ${C}`}},M=A=>{const F=A.conditions.map(S),I=A.groups.map(T=>M(T)),C=[...F,...I].filter(Boolean);if(C.length===0)return"";const E=C.join(` ${A.logicalOperator} `),L=C.length>1?`(${E})`:E;return A.negate?`NOT ${L}`:L};return M(w)},D=r.conditions.length>0||r.groups.length>0;return{currentFilters:r,setCurrentFilters:o,availableFields:i,isLoading:d,addCondition:u,addGroup:x,removeCondition:m,removeGroup:b,updateCondition:h,updateConditionFields:p,updateGroupOperator:j,updateGroupNegate:N,reorderConditions:f,reorderGroups:g,generateSQLPreview:k,hasAnyFilters:D}}function bc({children:s,className:n,delayDuration:r}){return e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{delayDuration:r,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:t.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",n),children:s})}),e.jsx(t.TooltipContent,{children:s})]})})}function jc({value:s,onValueChange:n,availableFields:r,placeholder:o="Select field",className:c}){const[d,i]=v.useState(!1),l=v.useMemo(()=>new Set(s?[s.id]:[]),[s]),u=s?a.getFieldDisplayLabel(s):null;return e.jsxs(t.Popover,{modal:!0,open:d,onOpenChange:i,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":d,title:s?`${s.entityName}.${s.name}`:void 0,className:t.cn("min-w-0 justify-between gap-1.5 font-normal",!s&&"text-muted-foreground",c),children:[u?e.jsx(bc,{className:"w-auto min-w-0 flex-1 text-left text-[12px]",children:u}):e.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:o}),e.jsx(a.ChevronsUpDown,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"flex w-80 flex-col rounded-control p-1.5",align:"start",onOpenAutoFocus:x=>{var m,b;x.preventDefault(),(b=(m=x.currentTarget)==null?void 0:m.querySelector('input[type="text"]'))==null||b.focus()},children:e.jsx(a.FieldOptionList,{fields:r,selectedIds:l,onSelect:x=>{n(x),i(!1)},density:"compact",listLabel:"Fields",listClassName:"max-h-80"})})]})}function Ba(s){const n=t.useEditorStore(i=>i.card.dataSource),r=t.useEditorStore(i=>i.card.connectionId),o=t.useEditorStore(i=>i.selectedConnectionId),c=v.useMemo(()=>({id:`card-filter-option:${s.id}`,...Na(s,{dataSource:n,connectionId:o||(n==null?void 0:n.connectionId)||r})}),[r,n,s,o]),d=v.useMemo(()=>a.createExplicitDashboardInputTargetContext({filter:c}),[c]);return a.useFilterOptionBrowse(c,{inputContext:d,currentSelectionPolicy:"exclude"})}function vc({field:s,selected:n,onChange:r,placeholder:o="Select values…",className:c}){const[d,i]=os.useState(!1),l=Ba(s),u=os.useMemo(()=>new Set(n.map(h=>a.getFilterOptionValueIdentity(h))),[n]),x=h=>{var p,j;return((j=(p=l.allRecords.find(N=>a.getFilterOptionValueIdentity(N.value)===a.getFilterOptionValueIdentity(h)))==null?void 0:p.label)==null?void 0:j.toString())??h},m=h=>{r(n.filter(p=>p!==h))},b=h=>{i(h),!h&&l.query&&l.setQuery("")};return e.jsx("div",{className:t.cn("w-full",c),children:e.jsxs(t.Popover,{open:d,onOpenChange:b,modal:!0,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":d,className:"h-auto min-h-7 w-full justify-between gap-1.5 px-2 py-0.5 font-normal",children:[e.jsx("div",{className:"flex min-w-0 flex-1 flex-wrap gap-1",children:n.length>0?n.map(h=>{const p=x(h);return e.jsxs("span",{className:"inline-flex max-w-full items-center gap-1 rounded-[4px] border border-border/70 bg-muted/40 px-1.5 py-0.5 text-[11px] leading-[14px] text-foreground",children:[e.jsx("span",{className:"truncate",children:p}),e.jsx("span",{role:"button",tabIndex:0,"aria-label":`Remove ${p}`,className:"shrink-0 rounded-[2px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-1 focus-visible:ring-ring",onKeyDown:j=>{j.key==="Enter"&&m(h)},onMouseDown:j=>{j.preventDefault(),j.stopPropagation()},onClick:j=>{j.stopPropagation(),m(h)},children:e.jsx(le.X,{className:"h-3 w-3"})})]},h)}):e.jsx("span",{className:"truncate text-muted-foreground",children:o})}),e.jsx(le.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:h=>{var p,j;h.preventDefault(),(j=(p=h.currentTarget)==null?void 0:p.querySelector('input[type="text"]'))==null||j.focus()},children:e.jsx(a.FilterOptionList,{records:l.displayRecords,selectedIdentities:u,onToggle:h=>{const p=String(h.value);n.includes(p)?m(p):r([...n,p])},browse:l,searchPlaceholder:`Search ${(s.label||s.name).toLowerCase()}`,listLabel:s.label||s.name,density:"compact"})})]})})}function yc({field:s,value:n,onChange:r,placeholder:o="Select value…",className:c}){var b,h;const[d,i]=os.useState(!1),l=Ba(s),u=os.useMemo(()=>new Set(n?[a.getFilterOptionValueIdentity(n)]:[]),[n]),x=n?((h=(b=l.allRecords.find(p=>a.getFilterOptionValueIdentity(p.value)===a.getFilterOptionValueIdentity(n)))==null?void 0:b.label)==null?void 0:h.toString())??n:"",m=p=>{i(p),!p&&l.query&&l.setQuery("")};return e.jsxs(t.Popover,{open:d,onOpenChange:m,modal:!0,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":d,className:t.cn("min-w-0 flex-1 justify-between gap-1.5 px-2 font-normal",c),children:[e.jsx("span",{className:t.cn("truncate",!n&&"text-muted-foreground"),children:n?x:o}),e.jsx(le.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] min-w-[240px] rounded-control p-1.5",align:"start",onOpenAutoFocus:p=>{var j,N;p.preventDefault(),(N=(j=p.currentTarget)==null?void 0:j.querySelector('input[type="text"]'))==null||N.focus()},children:e.jsx(a.FilterOptionList,{records:l.displayRecords,selectedIdentities:u,onToggle:p=>{r(String(p.value)),m(!1)},selectionMode:"single",browse:l,searchPlaceholder:`Search ${(s.label||s.name).toLowerCase()}`,listLabel:s.label||s.name,density:"compact"})})]})}function Cc({value:s,operator:n,onChange:r,className:o}){const c=a.useTimezone(),d=n==="between"||n==="not between",i=v.useMemo(()=>{if(!(!s||!d)&&Array.isArray(s)&&s.length===2){const b=s[0]?new Date(s[0]):void 0,h=s[1]?new Date(s[1]):void 0;if(b&&h)return{from:b,to:h}}},[s,d]),l=v.useMemo(()=>{if(!s||d)return;const b=Array.isArray(s)?s[0]:s;if(!b)return;const h=new Date(b);if(!isNaN(h.getTime()))return h},[s,d]),u=b=>n==="<="||n===">"?t.endOfDayInTimezone(b,c):t.startOfDayInTimezone(b,c),x=b=>{if(!b){r([]);return}if(b.from&&b.to){r([b.from.toISOString(),b.to.toISOString()]);return}r([])},m=b=>{if(!b){r("");return}const h=u(b);r(h.toISOString())};return e.jsx(a.DateRangePicker,{value:d?i:void 0,selectionMode:d?"range":"single",singleValue:d?void 0:l,onChange:x,onSingleChange:m,timezone:c,showRelativeTab:d,className:t.cn("min-w-0",o),buttonClassName:"h-7 text-[12px] [&>span]:text-[12px]",placeholder:"Select date…"})}const Ys=["contains","startsWith","endsWith","like","not like"],Nc=["=","!=",">",">=","<","<=",...Ys,"in","not in","isNull","isNotNull"],Sc=["=","!=",...Ys,"in","not in","isNull","isNotNull"],wc=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],Tc=["=","!=","isNull","isNotNull"],Ec=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],Ic={"=":"Equals","!=":"Not equals",">":"Greater than",">=":"Greater than or equal","<":"Less than","<=":"Less than or equal",contains:"Contains",startsWith:"Starts with",endsWith:"Ends with",like:"Like","not like":"Not like",in:"In","not in":"Not in",between:"Between",isNull:"Is null",isNotNull:"Is not null","not between":"Not between"};function Ts(s){return Ic[s]||t.titleCase(s)}function Dc(s){switch(s){case"string":return Sc;case"number":return wc;case"boolean":return Tc;case"date":return Ec;default:return Nc}}const _a="w-[68px] shrink-0",zs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Ya({value:s,onValueChange:n,"aria-label":r}){return e.jsxs(t.Select,{value:s,onValueChange:o=>n(o),children:[e.jsx(t.SelectTrigger,{size:"xs","aria-label":r,className:t.cn(_a,"font-medium"),children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{className:"min-w-[var(--radix-select-trigger-width)]",children:[e.jsx(t.SelectItem,{value:"AND",className:"text-[12px] font-medium",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",className:"text-[12px] font-medium",children:"OR"})]})]})}function za({condition:s,index:n,groupId:r,groupLogicalOperator:o,onUpdateCondition:c,onRemoveCondition:d,onUpdateGroupOperator:i,availableFields:l,updateConditionFields:u}){const{attributes:x,listeners:m,setNodeRef:b,transform:h,transition:p,isDragging:j}=a.useSortable({id:s.id}),N={transform:a.CSS.Transform.toString(h),transition:p},f=t.getDataType(s.field.dataType),g=s.operator==="isNull"||s.operator==="isNotNull",k=s.operator==="in"||s.operator==="not in";return e.jsxs("div",{ref:b,style:N,className:t.cn("flex items-center gap-2 rounded-control px-1.5 py-1 transition-colors hover:bg-muted/40",j&&"z-50 opacity-50"),children:[e.jsx("button",{type:"button",...x,...m,"aria-label":"Drag to reorder condition",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:e.jsx(a.GripVertical,{className:"h-3.5 w-3.5"})}),n>0?e.jsx(Ya,{value:o,onValueChange:D=>i(r,D),"aria-label":"Logical operator"}):e.jsx("span",{className:t.cn(_a,"text-center",zs),children:"Where"}),e.jsx(jc,{value:s.field,onValueChange:D=>{const w=D,S=t.getDataType(w.dataType)==="date";u(r,s.id,{field:w,value:"",operator:S?"between":"="})},availableFields:l,placeholder:"Select field",className:"w-60 shrink-0"}),e.jsxs(t.Select,{value:s.operator,onValueChange:D=>{D==="in"||D==="not in"?u(r,s.id,{operator:D,value:[]}):D==="isNull"||D==="isNotNull"?u(r,s.id,{operator:D,value:null}):D==="between"||D==="not between"?u(r,s.id,{operator:D,value:[]}):u(r,s.id,{operator:D,value:""})},children:[e.jsx(t.SelectTrigger,{size:"xs","aria-label":"Operator",className:"w-40 shrink-0",children:e.jsx(t.SelectValue,{children:s.operator?Ts(s.operator):""})}),e.jsx(t.SelectContent,{children:Dc(f).map(D=>e.jsx(t.SelectItem,{value:D,children:Ts(D)},D))})]}),g?e.jsx("div",{className:"min-w-0 flex-1"}):f==="string"?k?e.jsx(vc,{field:s.field,selected:Array.isArray(s.value)&&s.value.every(D=>typeof D=="string")?s.value:[],onChange:D=>u(r,s.id,{value:D}),placeholder:"Select values…",className:"min-w-0 flex-1"}):Ys.includes(s.operator)?e.jsx(t.Input,{size:"xs",value:typeof s.value=="string"?s.value:"",onChange:D=>u(r,s.id,{value:D.target.value}),className:"min-w-0 flex-1",placeholder:`${Ts(s.operator)}…`}):e.jsx(yc,{field:s.field,value:typeof s.value=="string"?s.value:"",onChange:D=>u(r,s.id,{value:D}),placeholder:"Select value…",className:"min-w-0 flex-1"}):f==="boolean"?e.jsxs(t.Select,{value:typeof s.value=="boolean"?String(s.value):"",onValueChange:D=>u(r,s.id,{value:D==="true"}),children:[e.jsx(t.SelectTrigger,{size:"xs",className:"min-w-0 flex-1",children:e.jsx(t.SelectValue,{placeholder:"Select value…"})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"true",children:"True"}),e.jsx(t.SelectItem,{value:"false",children:"False"})]})]}):f==="date"?e.jsx(Cc,{value:s.value,operator:s.operator,onChange:D=>u(r,s.id,{value:D}),className:"min-w-0 flex-1"}):e.jsx(t.Input,{size:"xs",value:typeof s.value=="string"||typeof s.value=="number"?s.value:"",onChange:D=>c(r,s.id,"value",D.target.value),className:"min-w-0 flex-1",placeholder:k?"value1, value2, value3":"Value"}),e.jsx(t.Button,{variant:"ghost",size:"xs","aria-label":"Remove condition",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground hover:text-foreground",onClick:()=>d(r,s.id),children:e.jsx(le.X,{className:"h-3.5 w-3.5"})})]})}function qa({onAddCondition:s,onAddGroup:n}){return e.jsxs("div",{className:"mt-2 flex items-center gap-1.5",children:[e.jsxs(t.Button,{type:"button",size:"xs",variant:"outline",className:"gap-1.5",onClick:s,children:[e.jsx(a.Plus,{className:"h-3 w-3"}),"Add condition"]}),n&&e.jsxs(t.Button,{type:"button",size:"xs",variant:"ghost",className:"gap-1.5 text-muted-foreground hover:text-foreground",onClick:n,children:[e.jsx(a.Plus,{className:"h-3 w-3"}),"Add group"]})]})}function kc({group:s,depth:n,parentGroupId:r,onUpdateGroupOperator:o,onUpdateGroupNegate:c,onRemoveGroup:d,onUpdateCondition:i,onUpdateField:l,onRemoveCondition:u,onReorderConditions:x,onReorderGroups:m,onAddCondition:b,onAddGroup:h,availableFields:p,renderFilterGroup:j,updateConditionFields:N}){const{attributes:f,listeners:g,setNodeRef:k,transform:D,transition:w,isDragging:S}=a.useSortable({id:s.id}),M={transform:a.CSS.Transform.toString(D),transition:w},A=I=>{const{active:C,over:E}=I;if(E&&C.id!==E.id){const L=s.conditions.findIndex(R=>R.id===C.id),T=s.conditions.findIndex(R=>R.id===E.id);L!==-1&&T!==-1&&x(s.id,L,T)}},F=I=>{const{active:C,over:E}=I;if(E&&C.id!==E.id&&r){const L=s.groups.findIndex(R=>R.id===C.id),T=s.groups.findIndex(R=>R.id===E.id);L!==-1&&T!==-1&&m(r,L,T)}};return e.jsxs("div",{ref:k,style:M,className:t.cn(n>0&&"mt-2 overflow-hidden rounded-[6px] border border-border/60",S&&"z-50 opacity-50"),children:[n>0&&e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/60 bg-muted/40 px-2 py-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",...f,...g,"aria-label":"Drag to reorder group",className:"flex h-7 w-5 shrink-0 cursor-grab items-center justify-center rounded-control text-muted-foreground/60 hover:text-foreground focus-visible:outline-none active:cursor-grabbing",children:e.jsx(a.GripVertical,{className:"h-3.5 w-3.5"})}),e.jsx(t.Button,{type:"button",variant:s.negate?"default":"outline",size:"xs","aria-pressed":s.negate,className:"px-2",onClick:()=>c(s.id,!s.negate),children:"NOT"}),e.jsx(Ya,{value:s.logicalOperator,onValueChange:I=>o(s.id,I),"aria-label":"Group logical operator"}),e.jsx("span",{className:zs,children:"Group"})]}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"xs","aria-label":"Remove group",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>r&&d(r,s.id),children:e.jsx(a.Trash2,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:t.cn(n>0&&"p-2"),children:[e.jsx(a.DndContext,{sensors:a.useSensors(a.useSensor(a.PointerSensor),a.useSensor(a.KeyboardSensor,{coordinateGetter:a.sortableKeyboardCoordinates})),collisionDetection:a.closestCenter,onDragEnd:A,children:e.jsx(a.SortableContext,{items:s.conditions.map(I=>I.id),strategy:a.verticalListSortingStrategy,children:e.jsx("div",{className:"space-y-0.5",children:s.conditions.map((I,C)=>e.jsx(za,{condition:I,index:C,groupId:s.id,groupLogicalOperator:s.logicalOperator,onUpdateCondition:i,onUpdateField:l,onRemoveCondition:u,onUpdateGroupOperator:o,availableFields:p,updateConditionFields:N},I.id))})})}),e.jsx(a.DndContext,{sensors:a.useSensors(a.useSensor(a.PointerSensor),a.useSensor(a.KeyboardSensor,{coordinateGetter:a.sortableKeyboardCoordinates})),collisionDetection:a.closestCenter,onDragEnd:F,children:e.jsx(a.SortableContext,{items:s.groups.map(I=>I.id),strategy:a.verticalListSortingStrategy,children:s.groups.map(I=>j(I,n+1,s.id))})}),s.conditions.length===0&&s.groups.length===0&&e.jsx("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}),e.jsx(qa,{onAddCondition:()=>b(s.id),onAddGroup:()=>h(s.id)})]})]})}function Mc({filters:s,availableFields:n,onSave:r,onClearAll:o,onCancel:c}){const{currentFilters:d,availableFields:i,isLoading:l,addCondition:u,addGroup:x,removeCondition:m,removeGroup:b,updateCondition:h,updateConditionFields:p,updateGroupOperator:j,updateGroupNegate:N,reorderConditions:f,reorderGroups:g,generateSQLPreview:k,hasAnyFilters:D,setCurrentFilters:w}=gc({initialFilters:s,availableFields:n}),S=a.useSensors(a.useSensor(a.PointerSensor),a.useSensor(a.KeyboardSensor,{coordinateGetter:a.sortableKeyboardCoordinates})),[M,A]=v.useState(!1),F=(E,L,T)=>{const R=y=>y.id===E?{...y,conditions:y.conditions.map(B=>B.id===L?{...B,field:T,dataType:T.dataType}:B)}:{...y,groups:y.groups.map(R)};w(R(d))},I=(E,L=0,T)=>{if(L===0){const R=E.conditions.length===0&&E.groups.length===0;return e.jsxs("div",{children:[e.jsx(a.DndContext,{sensors:S,collisionDetection:a.closestCenter,onDragEnd:y=>{const{active:B,over:P}=y;if(P&&B.id!==P.id){const O=E.conditions.findIndex(_=>_.id===B.id),V=E.conditions.findIndex(_=>_.id===P.id);O!==-1&&V!==-1&&f(E.id,O,V)}},children:e.jsx(a.SortableContext,{items:E.conditions.map(y=>y.id),strategy:a.verticalListSortingStrategy,children:e.jsx("div",{className:"space-y-0.5",children:E.conditions.map((y,B)=>e.jsx(za,{condition:y,index:B,groupId:E.id,groupLogicalOperator:E.logicalOperator,onUpdateCondition:h,onUpdateField:F,onRemoveCondition:m,onUpdateGroupOperator:j,availableFields:i,updateConditionFields:p},y.id))})})}),e.jsx(a.DndContext,{sensors:S,collisionDetection:a.closestCenter,onDragEnd:y=>{const{active:B,over:P}=y;if(P&&B.id!==P.id){const O=E.groups.findIndex(_=>_.id===B.id),V=E.groups.findIndex(_=>_.id===P.id);O!==-1&&V!==-1&&g(E.id,O,V)}},children:e.jsx(a.SortableContext,{items:E.groups.map(y=>y.id),strategy:a.verticalListSortingStrategy,children:E.groups.map(y=>I(y,L+1,E.id))})}),R&&e.jsx("p",{className:"rounded-control border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No filters yet. Add a condition to limit the rows this card shows."}),e.jsx(qa,{onAddCondition:()=>u(E.id),onAddGroup:M?()=>x(E.id):void 0})]},E.id)}return e.jsx(kc,{group:E,depth:L,parentGroupId:T,onUpdateGroupOperator:j,onUpdateGroupNegate:N,onRemoveGroup:b,onUpdateCondition:h,onUpdateField:F,onRemoveCondition:m,onReorderConditions:f,onReorderGroups:g,onAddCondition:u,onAddGroup:x,availableFields:i,renderFilterGroup:I,updateConditionFields:p},E.id)},C=a.getFilterCount(s);return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-3",children:[l?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-[12px] text-muted-foreground",children:[e.jsx(t.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Loading columns…"]}):I(d),e.jsxs("div",{className:"mt-3 flex items-center gap-2 border-t border-border/60 pt-3",children:[e.jsx(t.Switch,{size:"xs",id:"advanced-mode",checked:M,onCheckedChange:E=>A(E)}),e.jsx(t.Label,{htmlFor:"advanced-mode",className:"text-[12px] font-normal leading-none text-foreground",children:"Advanced mode"}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:"Nest conditions in groups"})]}),D&&e.jsxs("div",{className:"mt-3 border-t border-border/60 pt-3",children:[e.jsx("div",{className:t.cn("mb-1.5",zs),children:"Where clause"}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words rounded-[6px] border border-border bg-muted/40 px-3 py-2 font-mono text-[12px] leading-[1.55] text-foreground",children:k(d)})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-2 border-t border-border px-3 py-2.5",children:[e.jsx("div",{children:C>0&&e.jsx(t.Button,{size:"xs",variant:"ghost",className:"text-muted-foreground hover:text-foreground",onClick:o,children:"Clear all"})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(t.Button,{size:"xs",variant:"ghost",onClick:c,children:"Cancel"}),e.jsx(t.Button,{size:"xs",onClick:()=>r(D?d:null),children:"Apply filters"})]})]})]})}function Ac({cardId:s,filters:n,onFiltersChange:r,onClearFilters:o,availableFields:c,isOpen:d,onOpenChange:i}){const l=x=>{r(s,x),i(!1)},u=()=>{o(s),i(!1)};return e.jsxs(a.Dialog,{modal:!1,open:d,onOpenChange:i,children:[d&&e.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-zinc-950/40 backdrop-blur-sm"}),e.jsxs(a.DialogContent,{className:"flex max-h-[80vh] w-[min(880px,92vw)] max-w-none flex-col gap-0 overflow-hidden p-0 [&>button:last-child]:top-3",onInteractOutside:x=>{x.preventDefault()},children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-border pl-3 pr-10",children:[e.jsx(a.Filter,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx(a.DialogTitle,{className:"truncate text-[13px] font-medium",children:"Card filters"}),e.jsx(a.DialogDescription,{className:"sr-only",children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(Mc,{filters:n,availableFields:c,onSave:l,onCancel:()=>i(!1),onClearAll:u})]})]})}function Lc({activeCardId:s,sourceFields:n,getFieldsForContainer:r,setFieldsForContainer:o,moveField:c}){const[d,i]=v.useState(null),l=t.useEditorStore(f=>f.card),u=t.useEditorStore(f=>f.actions.updateCardConfig),x=t.useEditorStore(f=>f.actions.setCardPreferences),m=a.useFieldAvailabilityContext(l),b=[...n,...r("groupBy"),...r("pivotBy"),...r("metrics"),...r("sortBy"),...r("detailColumns")],h=v.useCallback(f=>f.startsWith("card-source-")?"source":f.startsWith("card-")?null:f.startsWith("source-")||n.find(g=>g.id===f)?"source":r("groupBy").find(g=>g.id===f)?"groupBy":r("metrics").find(g=>g.id===f)?"metrics":r("pivotBy").find(g=>g.id===f)?"pivotBy":r("sortBy").find(g=>g.id===f)?"sortBy":r("detailColumns").find(g=>g.id===f)?"detailColumns":null,[n,r]),p=v.useCallback(f=>{i(f.active.id)},[]),j=v.useCallback(f=>{const{active:g,over:k}=f;if(!k||!s){i(null);return}const D=g.id,w=k.id,S=h(D),M=h(w)||w;if(D===w){i(null);return}const A=S==="source"?n.find(F=>F.id===D):S?r(S).find(F=>F.id===D):void 0;if(A&&S&&(c!=null&&c({field:A,from:S,to:M,...w!==M?{beforeId:w}:{}}))){i(null);return}if(M==="sortBy"){if(S==="source"){const F=n.find(C=>C.id===D);if(!F){i(null);return}if(!(r("groupBy").some(C=>C.name===F.name&&C.qualifiedEntityName===F.qualifiedEntityName)||r("metrics").some(C=>C.name===F.name&&C.qualifiedEntityName===F.qualifiedEntityName)||r("detailColumns").some(C=>C.name===F.name&&C.qualifiedEntityName===F.qualifiedEntityName))){i(null);return}}else if(S==="pivotBy"){i(null);return}else if(S!=="groupBy"&&S!=="metrics"&&S!=="sortBy"&&S!=="detailColumns"){i(null);return}}if(S==="source"&&M==="sortBy"){const F=[...n].find(L=>L.id===D);if(!F){i(null);return}const I=r("sortBy");if(a.fieldAlreadyExists(F,I)){i(null);return}const C=a.validateFieldForChartType(F,"sortBy",l.type);if(!C.isValid){t.ue.error("Invalid Field Type",{description:C.reason,position:"top-center",duration:3e3}),i(null);return}const E=a.getNewField(F,"sortBy",I);i(null),o("sortBy",[...I,E]);return}if(S==="source"&&M!=="source"&&M!=="sortBy"){const F=[...n].find(y=>y.id===D);if(!F){i(null);return}const I=[...r("groupBy"),...r("pivotBy"),...r("metrics"),...r("sortBy"),...r("detailColumns")],C=a.validateEntityConsistency(F,I,m);if(!C.isValid){C.showError&&a.showJoinRequiredNotification(C.fieldState),i(null);return}const E=r(M);if(a.fieldAlreadyExists(F,E)){i(null);return}const L=a.validateFieldForChartType(F,M,l.type);if(!L.isValid){t.ue.error("Invalid Field Type",{description:L.reason,position:"top-center",duration:3e3}),i(null);return}const T=a.getNewField(F,M,E),R=[...E,T];if(i(null),o(M,R),M==="metrics"&&s){const y=a.seedSemanticMetricFormatDefaults(l,T,l.preferences);y&&x(y),a.cleanupKpiMetricComparisonMode(l.type,l.config,u,s,R)}return}if(S&&M&&S!=="source"&&M!=="source"&&S!==M){const F=r(S),I=r(M),C=F.find(y=>y.id===D);if(!C){i(null);return}const E=a.validateFieldForChartType(C,M,l.type);if(!E.isValid){t.ue.error("Invalid Field Type",{description:E.reason,position:"top-center",duration:3e3}),i(null);return}const L=a.getNewField(C,M,I);if(i(null),M==="sortBy"){a.fieldAlreadyExists(C,I)||o(M,[...I,L]);return}const T=F.filter(y=>y.id!==D),R=[...I,L];if(o(S,T),o(M,R),M==="metrics"&&s){const y=a.seedSemanticMetricFormatDefaults(l,L,l.preferences);y&&x(y),a.cleanupKpiMetricComparisonMode(l.type,l.config,u,s,R)}return}if(S&&M&&S===M&&S!=="source"){const F=r(S),I=F.findIndex(E=>E.id===D),C=F.findIndex(E=>E.id===w);if(I!==C){const E=a.arrayMove(F,I,C);o(S,E)}}i(null)},[s,n,r,o,c,h,m,l,u,x]),N=d?b.find(f=>f.id===d):null;return{activeId:d,activeField:N,handleDragStart:p,handleDragEnd:j}}function Fc({activeView:s,onViewChange:n,splitViewEnabled:r,hasQueryError:o=!1}){const c=t.useEditorStore(x=>x.card),{config:d}=v.useContext(a.SemaphorContext).tokenProps,i=(d==null?void 0:d.showInfoTab)!==!1,l=()=>r?!1:t.getVisualizationMode(c)==="dynamic"?!0:!["table","pivotTable","aggregateTable","detailTable"].includes(c.type),u=[{id:"chart",label:"Chart"}];return l()&&u.push({id:"table",label:"Results"}),i&&u.push({id:"info",label:o?"Error":"Info",isError:o}),e.jsx(t.Tabs,{value:s,onValueChange:x=>n(x),children:e.jsx(t.TabsList,{variant:"underline",className:"gap-5 border-b-0",children:u.map(x=>e.jsx(t.TabsTrigger,{value:x.id,className:t.cn("px-0 text-[13px]",x.isError&&"text-destructive hover:text-destructive focus-visible:text-destructive data-[state=active]:border-destructive data-[state=active]:text-destructive"),children:x.label},x.id))})})}const Rc=[{value:"10",label:"Top 10"},{value:"20",label:"Top 20"},{value:"50",label:"Top 50"},{value:"100",label:"Top 100"},{value:"200",label:"Top 200"},{value:"500",label:"Top 500"},{value:"1000",label:"Top 1000"}];function Pc(){var u,x;const s=t.useEditorStore(m=>m.card),{updateRowLimit:n}=t.useEditorActions(),[r,o]=v.useState(!1),[c,d]=v.useState(""),i=m=>{if(m==="custom"){o(!0);return}o(!1),n(s.id,parseInt(m))},l=m=>{const b=m.target.value;d(b),b&&!isNaN(parseInt(b))&&n(s.id,parseInt(b))};return e.jsx("div",{className:"flex items-center gap-2",children:r?e.jsx(t.Input,{type:"number",value:c,onChange:l,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(t.Select,{value:((x=(u=s.config)==null?void 0:u.rowLimit)==null?void 0:x.toString())||"100",onValueChange:i,children:[e.jsxs(t.SelectTrigger,{className:"mb-0.5 h-auto w-auto gap-1.5 border-none bg-transparent px-0.5 pb-2.5 pt-0 text-[13px] font-normal text-muted-foreground shadow-none transition-colors hover:text-foreground focus:ring-0 focus:ring-offset-0 [&>svg]:hidden",children:[e.jsx(a.Filter,{className:"h-3 w-3",strokeWidth:1.75}),e.jsx(t.SelectValue,{placeholder:"Select limit"})]}),e.jsx(t.SelectContent,{children:Rc.map(m=>e.jsx(t.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function Oc({card:s,queryData:n,isLoading:r,isFetching:o,pagination:c,onPaginationChange:d,onSortChange:i,sortState:l,splitViewEnabled:u,isDynamicInspectorOpen:x,onDynamicInspectorOpenChange:m}){var j,N;const b=v.useMemo(()=>(n==null?void 0:n.records)||[],[n==null?void 0:n.records]),h=t.getVisualizationMode(s)==="dynamic",p=e.jsx(St,{alwaysRenderOverride:!0,renderCardOverride:()=>e.jsx(wa,{fallbackPreview:e.jsx(St,{}),records:b,title:s.title,isInspectorOpen:x,onInspectorOpenChange:m})});return h?u?e.jsxs(a.ResizablePanelGroup,{direction:"vertical",className:"h-full min-h-0 w-full",children:[e.jsx(a.ResizablePanel,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col pb-3",children:p}),e.jsx(a.ResizableHandle,{withHandle:!0}),e.jsx(a.ResizablePanel,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 px-4 py-4",children:[(r||o)&&(n==null?void 0:n.records)&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),(n==null?void 0:n.records)&&e.jsx(a.TableVisual,{card:s,data:b,resultColumns:n==null?void 0:n.columns,columnKeyMap:n==null?void 0:n.columnKeyMap,totalsByColumnId:n==null?void 0:n.tableTotalsByColumnId,comparisonMetadata:(j=n==null?void 0:n.metadata)==null?void 0:j.comparisonMetadata,paginationMetadata:c,onPaginationChange:d,isLoading:r||o,onSortChange:i,sortState:l})]})})]}):p:!u||["table","pivotTable","aggregateTable","detailTable"].includes(s.type)?e.jsx(St,{}):e.jsxs(a.ResizablePanelGroup,{direction:"vertical",className:"h-full min-h-0 w-full",children:[e.jsx(a.ResizablePanel,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col pb-3",children:e.jsx(St,{})}),e.jsx(a.ResizableHandle,{withHandle:!0}),e.jsx(a.ResizablePanel,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 py-4 pl-2 pr-4",children:[(r||o)&&(n==null?void 0:n.records)&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),(n==null?void 0:n.records)&&e.jsx(a.TableVisual,{card:s,data:b,resultColumns:n==null?void 0:n.columns,columnKeyMap:n==null?void 0:n.columnKeyMap,totalsByColumnId:n==null?void 0:n.tableTotalsByColumnId,comparisonMetadata:(N=n==null?void 0:n.metadata)==null?void 0:N.comparisonMetadata,paginationMetadata:c,onPaginationChange:d,isLoading:r||o,onSortChange:i,sortState:l})]})})]})}function Vc(s,n){const[r,o]=v.useState(()=>{const c=localStorage.getItem(s);return c?JSON.parse(c):n});return v.useEffect(()=>{localStorage.setItem(s,JSON.stringify(r))},[r,s]),[r,o]}const Bc="semaphor-split-view-enabled";function _c(){return Vc(Bc,!0)}function Yc({showInfoTab:s}){return e.jsx(a.VisualErrorState,{className:"min-h-[240px]",description:s?"See the Error tab for details and troubleshooting options.":"Contact your administrator for help resolving this issue."})}function zc({card:s,effectiveCardType:n=s.type,queryResultColumns:r}){return t.supportsRegularTableSettings(n)?e.jsxs(a.Sheet,{modal:!1,children:[e.jsx(a.SheetTrigger,{asChild:!0,children:e.jsx(a.IconButton,{tooltip:"Table settings",className:"h-7 w-7 rounded-[5px] p-0",buttonProps:{type:"button","aria-label":"Table settings"},children:e.jsx(a.Settings2,{className:"h-3.5 w-3.5",strokeWidth:1.75})})}),e.jsxs(a.SheetContent,{side:"right",hideOverlay:!0,className:"flex w-[420px] flex-col gap-0 p-0 sm:max-w-[420px]",children:[e.jsx(a.SheetTitle,{className:"sr-only",children:"Table settings"}),e.jsx(a.SheetDescription,{className:"sr-only",children:"Configure table presentation and conditional formatting."}),e.jsxs("div",{className:"border-b px-4 py-3",children:[e.jsx("div",{className:"text-[13px] font-semibold text-foreground",children:"Table settings"}),e.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Settings apply to this table and document exports that reuse it."})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:e.jsx(Fa,{cardType:n,queryResultColumns:r,focusSection:"style"})})]})]}):null}function qc({className:s,visible:n}){const r=t.useDashboardStore(l=>l.selectedFrameId),o=a.useManagementStore(l=>l.selectedVisual),c=t.useEditorStore(l=>l.frame),i=!!!(c!=null&&c.visualId||o!=null&&o.id)&&!!r;return!n||i?null:e.jsx("div",{className:t.cn("flex",s),children:e.jsx(pt.VisualBadge,{showLabel:!0,className:"h-6 w-fit px-2 py-0.5 text-[11px]"})})}function $c({activeView:s,onViewChange:n,onFiltersClick:r,activeCard:o,columns:c}){var De;const d=t.useEditorStore(ae=>ae.card),i=t.useEditorStore(ae=>ae.editorContext),l=t.useEditorStore(ae=>ae.inlineFilterValuesMap[(o==null?void 0:o.id)||""]),u=t.useEditorStore(ae=>ae.actions.removeCardInlineFilterValue),x=t.useDashboardStore(ae=>ae.filterValues),m=t.useDashboardStore(ae=>ae.selectedSheetId),{updateCardConfig:b,setCard:h,updateCardInFrame:p,setShowAIDialog:j}=t.useEditorActions(),N=t.useEditorStore(ae=>ae.showAIDialog),f=t.useEditorStore(ae=>ae.isDevMode),g=t.useDashboardStore(ae=>ae.isVisualEditing),[k,D]=v.useState(!1),[w,S]=v.useState(!1),[M,A]=v.useState(!1),[F,I]=v.useState(null),{config:C}=v.useContext(a.SemaphorContext).tokenProps,E=(C==null?void 0:C.showInfoTab)!==!1,L=(C==null?void 0:C.showQueryDebugTools)!==!1,[T,R]=_c();t.useEditorStore(ae=>{var K;return!!((K=ae.card.customCardPreferences)!=null&&K.url)});const B=t.getVisualizationMode(d)==="dynamic",P=(i==null?void 0:i.type)==="documentSection",O=a.useEffectiveEditorCardType(),{data:V,errorMessage:_,isLoading:z,isFetching:q,errorSql:Y,pagination:$,refetch:U,comparisonMetadata:H,queryRequestPayload:te,resolvedPrimaryDateField:X}=a.useEditorCardQuery(o),se=v.useMemo(()=>(V==null?void 0:V.records)||[],[V==null?void 0:V.records]),ue=v.useMemo(()=>!q&&se.length>0?Object.keys(se[0]):[],[q,se]),[fe,be]=v.useState(!1),ge=a.useMatrixEditorRefresh(o),Pe=t.useEditorStore(ae=>ae.frame),[Oe,Ae]=v.useState();v.useEffect(()=>{q||be(!1)},[q]);const Ie=()=>{const ae=!T;ae&&s==="table"&&n("chart"),R(ae)},_e=(ae,K)=>{const ie={...o,paginationConfig:{page:ae+1,pageSize:K}};h(ie),p(ie)},Ye=ae=>{if(!d.config)return;const K=a.sortStateToSortByColumns(ae,d.config.metricColumns,d.config.groupByColumns,d.config.detailColumns);b(d.id,{...d.config,sortByColumns:K})},Ve=v.useMemo(()=>{var ae;return a.sortByColumnsToSortState((ae=d.config)==null?void 0:ae.sortByColumns)},[(De=d.config)==null?void 0:De.sortByColumns]),Le=a.getFilterCount(je.getAuthoredCardFilters(o)||null);return e.jsx("div",{className:t.cn("relative flex w-0 grow flex-col",{"border-l":N&&g}),children:e.jsxs("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col",children:[e.jsxs("div",{className:"flex h-11 items-center gap-3 border-b border-border px-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[s==="chart"&&N&&!P&&!B&&e.jsx("div",{className:"w-[200px]",children:e.jsx(zo,{variant:f?"secondary":"ghost"})}),e.jsxs("div",{className:"flex h-11 items-end gap-5 self-stretch",children:[e.jsx(Fc,{activeView:s,onViewChange:n,splitViewEnabled:T,hasQueryError:!!_}),!a.isTableType(O)&&e.jsx(Pc,{})]}),O==="kpi"&&e.jsx(qc,{visible:!0,className:"self-center"}),H&&d.type!=="table"&&e.jsx(a.ComparisonMetadataBadge,{metadata:H,variant:"compact"}),N&&e.jsx(pt.EditorClearButton,{})]}),e.jsxs("div",{className:"flex grow items-center justify-end gap-1",children:[e.jsx(a.FilterInfo,{cardId:o.id,cardFilters:je.getAuthoredCardFilters(o),cardFilterCount:Le,onFiltersClick:r,inlineFilters:o.inlineFilters,inlineFilterValues:l,sheetId:m||"",removeInlineFilterValue:ae=>u(o.id,ae),resolvedPrimaryDateField:X}),s==="chart"&&e.jsx(zc,{card:o,effectiveCardType:O,queryResultColumns:ue}),s==="chart"&&!B&&e.jsx(Sa,{showInlineFilters:!1,showControls:!1,showDisplayOptions:!1}),e.jsx(a.IconButton,{tooltip:"Refresh",className:"h-7 w-7 rounded-[5px] p-0",disabled:z||q,onClick:()=>{var ae;if(ge){(ae=ge.refresh)==null||ae.call(ge);return}be(!0),U()},children:e.jsx(Es,{className:t.cn("h-3.5 w-3.5",{"animate-spin":(ge==null?void 0:ge.isFetching)??fe})})}),s==="chart"&&e.jsxs(a.DropdownMenu,{modal:!1,children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsx(a.IconButton,{tooltip:"More Options",className:"h-7 w-7 rounded-[5px] p-0","aria-label":"More options",children:e.jsx(a.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxs(a.DropdownMenuItem,{onSelect:r,children:[e.jsx(a.Filter,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Card filters",Le>0&&e.jsx("span",{className:"ml-auto text-[11px] tabular-nums text-muted-foreground",children:Le})]}),e.jsx(Ps,{triggerVariant:"menu",className:"w-full"}),e.jsx(Os,{triggerVariant:"menu",className:"w-full"}),e.jsx(Rs,{triggerVariant:"menu",className:"w-full"}),e.jsxs(a.DropdownMenuItem,{onClick:Ie,children:[T?e.jsx(wr,{className:"h-3.5 w-3.5 text-muted-foreground"}):e.jsx(Vr,{className:"h-3.5 w-3.5 text-muted-foreground"}),T?"Hide results table":"Show results table"]}),ge&&e.jsxs(a.DropdownMenuItem,{disabled:ge.isFetching||!ge.hasDelivery,title:ge.hasDelivery?void 0:"Available once the preview has loaded.",onClick:()=>Ae(ge.readDelivery()),children:[e.jsx(a.Download,{className:"h-3.5 w-3.5 text-muted-foreground"}),"Download"]}),e.jsx(Ta,{onCustomize:()=>A(!0)})]})]})]})]}),e.jsxs("div",{className:"flex min-h-0 grow flex-col",children:[s==="chart"?_?e.jsx(Yc,{showInfoTab:E}):e.jsx("div",{className:"flex grow flex-col",children:e.jsx(Oc,{card:o,queryData:V,isLoading:z,isFetching:q,pagination:$,onPaginationChange:_e,onSortChange:Ye,sortState:Ve,splitViewEnabled:T,isDynamicInspectorOpen:M,onDynamicInspectorOpenChange:A})}):null,s==="table"&&(V==null?void 0:V.records)&&e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 px-4 py-4",children:[(z||q)&&(V==null?void 0:V.records)&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(a.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),e.jsx(a.TableVisual,{card:o,data:se,resultColumns:V.columns,columnKeyMap:V.columnKeyMap,totalsByColumnId:V==null?void 0:V.tableTotalsByColumnId,comparisonMetadata:H,paginationMetadata:$,onPaginationChange:_e,isLoading:z||q,onSortChange:Ye,sortState:Ve})]}),s==="info"&&E&&e.jsx("div",{className:"flex min-h-0 flex-1 flex-col pb-2",children:e.jsx("div",{className:"flex min-h-0 flex-1 flex-col rounded-md bg-background px-1",children:_?e.jsx(Io,{error:_,errorSql:Y,showCardDetails:!0,defaultSqlExpanded:!0,debugPayloads:L?{queryRequest:te,queryResponse:V,columns:c,dashboardFilters:x}:void 0,onSendFeedback:()=>{const ae=a.prepareFeedbackData(a.FeedbackCategory.QUERY_GENERATION,{cardConfig:d.config,dataSource:o.dataSource,dashboardFilters:x,errorMessage:_,errorSql:Y,generatedSql:V==null?void 0:V.sql});I(ae),S(!0)},onOpenInEditor:()=>{j(!0),setTimeout(()=>{const ae=t.useEditorStore.getState().actions;ae.setIsDevMode(!0),ae.setCardSql(Y||""),setTimeout(()=>{ae.setRunSql(!0)},100)},100)}}):(V==null?void 0:V.sql)&&e.jsx(Ea,{sql:V.sql,showCardDetails:!0,debugPayloads:L?{queryRequest:te,queryResponse:V,columns:c,dashboardFilters:x}:void 0})})})]}),Oe&&o&&Pe&&e.jsx(a.ExportDialog,{isOpen:!0,onClose:()=>Ae(void 0),card:o,frame:Pe,matrix:Oe}),F&&e.jsx(a.FeedbackDialog,{open:w,onOpenChange:S,feedbackData:F})]})})}function Kc({activeField:s}){const[n,r]=v.useState(!0);if(v.useEffect(()=>{s&&r(!0)},[s]),!s)return null;const o=a.getCalculatedGlyphKind(s);return e.jsxs("div",{className:`flex h-7 max-w-[300px] items-center gap-2 rounded-[5px] border border-border bg-popover px-3 text-[13px] text-foreground/90 shadow-[0_4px_12px_rgba(0,0,0,0.08)] transition-all duration-150 ${n?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(a.TypeGlyph,{dataType:s.dataType,calculated:o}),e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:s.label||s.name})]})}const Uc=()=>{const s=console.error;console.error=(...o)=>{o.length>0&&typeof o[0]=="string"&&o[0].includes("ResizeObserver loop completed with undelivered notifications")||s.apply(console,o)};const n=o=>{if(o.message&&(o.message.includes("ResizeObserver loop completed with undelivered notifications")||o.message.includes("ResizeObserver loop limit exceeded")))return o.preventDefault(),o.stopPropagation(),!1},r=o=>{var c;if((c=o.reason)!=null&&c.message&&(o.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||o.reason.message.includes("ResizeObserver loop limit exceeded")))return o.preventDefault(),!1};return window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",r,!0),()=>{console.error=s,window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",r,!0)}};function Gc({column:s,isSelected:n,onSelect:r,availableFields:o,width:c,onWidthChange:d}){var V,_;const i=t.useEditorStore(z=>z.card),{updateCardConfig:l,removeGroupByColumn:u,removeMetricColumn:x,updateFilters:m}=t.useEditorActions(),[b,h]=v.useState(!1),[p,j]=v.useState(!1),N=v.useRef(null),f=v.useCallback(z=>{z.preventDefault(),z.stopPropagation(),j(!0),N.current={startX:z.clientX,startWidth:c||150};const q=$=>{if(!N.current)return;const U=$.clientX-N.current.startX,H=Math.max(80,N.current.startWidth+U);d==null||d(s.id,H)},Y=()=>{j(!1),N.current=null,document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",Y)};document.addEventListener("mousemove",q),document.addEventListener("mouseup",Y)},[c,s.id,d]),g=je.getAuthoredCardFilters(i),k=(V=g==null?void 0:g.conditions)==null?void 0:V.some(z=>z.field.name===s.name&&z.field.qualifiedEntityName===s.qualifiedEntityName),D=z=>{z?m(i.id,z):l(i.id,{filters:void 0})},{attributes:w,listeners:S,setNodeRef:M,transform:A,transition:F,isDragging:I}=a.useSortable({id:s.id}),C={transform:a.CSS.Transform.toString(A),transition:F},E=t.getDataType(s.dataType),L=Hc(E),T=()=>{var Y;const z=((Y=i==null?void 0:i.config)==null?void 0:Y.sortByColumns)||[],q=z.findIndex($=>$.name===s.name);if(q!==-1){const $=[...z];$[q]={...$[q],direction:"asc"},l(i.id,{sortByColumns:$})}else l(i.id,{sortByColumns:[...z,{...s,id:`sort-${s.id}`,role:"sortby",direction:"asc"}]})},R=()=>{var Y;const z=((Y=i==null?void 0:i.config)==null?void 0:Y.sortByColumns)||[],q=z.findIndex($=>$.name===s.name);if(q!==-1){const $=[...z];$[q]={...$[q],direction:"desc"},l(i.id,{sortByColumns:$})}else l(i.id,{sortByColumns:[...z,{...s,id:`sort-${s.id}`,role:"sortby",direction:"desc"}]})},y=()=>{var Y;const z=((Y=i==null?void 0:i.config)==null?void 0:Y.groupByColumns)||[];if(!z.some($=>$.name===s.name)){const $={...s,id:`groupby-${s.id}-${Date.now()}`,role:"groupby"};l(i.id,{groupByColumns:[...z,$]})}},B=z=>{var $;const q=(($=i==null?void 0:i.config)==null?void 0:$.metricColumns)||[];if(!q.some(U=>U.name===s.name&&U.aggregate===z)){const U={...s,id:`metric-${s.id}-${z}-${Date.now()}`,label:`${z} of ${s.label||s.name}`,role:"metric",aggregate:z,aggregateOrigin:"explicit"};l(i.id,{metricColumns:[...q,U]})}},P=()=>{s.role==="groupby"?u(i.id,s.id):s.role==="metric"&&x(i.id,s.id)},O={...C,width:c?`${c}px`:void 0,minWidth:c?`${c}px`:"120px"};return e.jsxs("th",{ref:M,style:O,className:t.cn("group relative border-r border-border bg-background px-1 py-0",I&&"opacity-50",n&&"bg-primary/10",p&&"select-none"),children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{...w,...S,className:"cursor-grab p-1 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100 active:cursor-grabbing",children:e.jsx(a.GripVertical,{className:"h-3 w-3"})}),e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{onClick:r,className:t.cn("flex flex-1 items-center justify-between gap-1 rounded px-2 py-2 text-left text-sm font-medium transition-colors hover:bg-muted/50",n&&"bg-primary/10"),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(L,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:s.label||s.name}),s.role==="metric"&&s.aggregate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",s.aggregate,")"]}),k&&e.jsx(a.Filter,{className:"h-3 w-3 text-primary"})]}),e.jsx(le.ChevronDown,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsxs(a.DropdownMenuContent,{align:"start",className:"w-48",children:[e.jsxs(a.DropdownMenuItem,{onClick:()=>h(!0),children:[e.jsx(a.Filter,{className:t.cn("mr-2 h-4 w-4",k&&"text-primary")}),k?"Edit Filter":"Filter"]}),e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:T,children:[e.jsx(yr,{className:"mr-2 h-4 w-4"}),"Sort A → Z"]}),e.jsxs(a.DropdownMenuItem,{onClick:R,children:[e.jsx(vr,{className:"mr-2 h-4 w-4"}),"Sort Z → A"]}),e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuSub,{children:[e.jsxs(a.DropdownMenuSubTrigger,{children:[e.jsx(a.Calculator,{className:"mr-2 h-4 w-4"}),"Summarize"]}),e.jsxs(a.DropdownMenuSubContent,{children:[e.jsx(a.DropdownMenuItem,{onClick:()=>B("SUM"),children:"Sum"}),e.jsx(a.DropdownMenuItem,{onClick:()=>B("AVG"),children:"Average"}),e.jsx(a.DropdownMenuItem,{onClick:()=>B("COUNT"),children:"Count"}),e.jsx(a.DropdownMenuItem,{onClick:()=>B("DISTINCT"),children:"Count Distinct"}),e.jsx(a.DropdownMenuItem,{onClick:()=>B("MIN"),children:"Min"}),e.jsx(a.DropdownMenuItem,{onClick:()=>B("MAX"),children:"Max"})]})]}),e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:y,children:[e.jsx(a.Rows3,{className:"mr-2 h-4 w-4"}),"Group by this column"]}),e.jsxs(a.DropdownMenuItem,{disabled:!0,children:[e.jsx(ks,{className:"mr-2 h-4 w-4"}),"Pivot by this column"]}),e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{disabled:!0,children:[e.jsx(a.EyeOff,{className:"mr-2 h-4 w-4"}),"Hide column"]}),e.jsxs(a.DropdownMenuItem,{onClick:P,className:"text-destructive focus:text-destructive",children:[e.jsx(a.Trash2,{className:"mr-2 h-4 w-4"}),"Remove column"]})]})]})]}),e.jsx("div",{onMouseDown:f,className:t.cn("absolute right-0 top-0 h-full w-1 cursor-col-resize bg-transparent hover:bg-primary/50",p&&"bg-primary")}),e.jsx(Va,{open:b,onOpenChange:h,availableFields:o.length>0?o:[s],existingFilters:g,editingCondition:k?(_=g==null?void 0:g.conditions)==null?void 0:_.find(z=>z.field.name===s.name&&z.field.qualifiedEntityName===s.qualifiedEntityName):void 0,onSave:D})]})}function Hc(s){switch(s){case"number":return a.Hash;case"date":return a.Calendar;case"string":default:return t.Type}}function Qc({selectedColumn:s,onColumnSelect:n,isLoading:r=!1,sourceFields:o=[],filterableFields:c=o}){var I,C,E,L;const d=t.useEditorStore(T=>T.card),{updateCardConfig:i}=t.useEditorActions(),[l,u]=v.useState(null),[x,m]=v.useState({}),[b,h]=v.useState(!1),p=v.useMemo(()=>{var y,B;const T=((y=d==null?void 0:d.config)==null?void 0:y.groupByColumns)||[],R=((B=d==null?void 0:d.config)==null?void 0:B.metricColumns)||[];return[...T,...R]},[(I=d==null?void 0:d.config)==null?void 0:I.groupByColumns,(C=d==null?void 0:d.config)==null?void 0:C.metricColumns]),j=v.useMemo(()=>{const T=new Set(p.map(R=>`${R.qualifiedEntityName}.${R.name}`));return o.filter(R=>!T.has(`${R.qualifiedEntityName}.${R.name}`))},[o,p]),{data:N,isLoading:f}=a.useEditorCardQuery(d),g=(N==null?void 0:N.records)||[],k=v.useCallback((T,R)=>{m(y=>({...y,[T]:R}))},[]),D=v.useCallback(T=>{var P,O;const R=t.getDataType(T.dataType),y=((P=d==null?void 0:d.config)==null?void 0:P.groupByColumns)||[],B=((O=d==null?void 0:d.config)==null?void 0:O.metricColumns)||[];if(R==="number"){const V=a.getNewField(T,"metrics",[...y,...B]);i(d.id,{metricColumns:[...B,V]})}else{const V=a.getNewField(T,"groupBy",[...y,...B]);i(d.id,{groupByColumns:[...y,V]})}h(!1)},[(E=d==null?void 0:d.config)==null?void 0:E.groupByColumns,(L=d==null?void 0:d.config)==null?void 0:L.metricColumns,d.id,i]),w=a.useSensors(a.useSensor(a.PointerSensor,{activationConstraint:{distance:8}})),S=T=>{u(T.active.id)},M=T=>{const{active:R,over:y}=T;if(u(null),!y||R.id===y.id)return;const B=p.findIndex(O=>O.id===R.id),P=p.findIndex(O=>O.id===y.id);if(B!==-1&&P!==-1){const O=a.arrayMove(p,B,P),V=O.filter(z=>z.role==="groupby"),_=O.filter(z=>z.role==="metric");i(d.id,{groupByColumns:V,metricColumns:_})}},A=l?p.find(T=>T.id===l):null,F=T=>{let R="";for(;T>=0;)R=String.fromCharCode(T%26+65)+R,T=Math.floor(T/26)-1;return R};return r?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(t.LoaderCircle,{className:"h-5 w-5 animate-spin text-muted-foreground/60"})}):p.length===0?e.jsx("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8 text-center",children:e.jsxs("div",{className:"rounded-lg border-2 border-dashed border-muted-foreground/25 p-12",children:[e.jsx("h3",{className:"text-lg font-medium text-muted-foreground",children:"No columns selected"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground/75",children:"Select columns from the panel on the right to build your table"})]})}):e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs(a.DndContext,{sensors:w,collisionDetection:a.closestCenter,onDragStart:S,onDragEnd:M,children:[e.jsxs("table",{className:"w-full border-collapse",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"sticky left-0 z-20 w-12 border-r border-border bg-muted/50 px-2 py-1 text-center text-xs font-medium text-muted-foreground"}),e.jsx(a.SortableContext,{items:p.map(T=>T.id),strategy:a.horizontalListSortingStrategy,children:p.map((T,R)=>e.jsx("th",{style:{width:x[T.id]?`${x[T.id]}px`:void 0,minWidth:x[T.id]?`${x[T.id]}px`:"120px"},className:"border-r border-border bg-muted/30 px-2 py-1 text-center text-xs font-medium text-muted-foreground",children:F(R)},`letter-${T.id}`))}),e.jsx("th",{className:"w-10 border-r border-border bg-muted/30 px-2 py-1"})]}),e.jsxs("tr",{className:"border-b-2 border-border bg-background",children:[e.jsx("th",{className:"sticky left-0 z-20 w-12 border-r border-border bg-muted/50 px-2 py-2 text-center text-xs font-medium text-muted-foreground",children:"#"}),e.jsx(a.SortableContext,{items:p.map(T=>T.id),strategy:a.horizontalListSortingStrategy,children:p.map(T=>e.jsx(Gc,{column:T,isSelected:(s==null?void 0:s.id)===T.id,onSelect:()=>n(T),availableFields:c,width:x[T.id],onWidthChange:k},T.id))}),e.jsx("th",{className:"w-10 border-r border-border bg-background px-1 py-2",children:e.jsxs(t.Popover,{open:b,onOpenChange:h,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",title:"Add column",children:e.jsx(a.Plus,{className:"h-4 w-4"})})}),e.jsx(t.PopoverContent,{className:"w-[280px] p-0",align:"start",children:e.jsxs(a.Command,{children:[e.jsx(a.CommandInput,{placeholder:"Search columns..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No columns available."}),e.jsx(a.CommandGroup,{heading:"Available Columns",children:j.map(T=>{const R=t.getDataType(T.dataType),y=R==="number"?a.Hash:R==="date"?a.Calendar:t.Type;return e.jsxs(a.CommandItem,{value:T.label||T.name,onSelect:()=>D(T),children:[e.jsx(y,{className:"mr-2 h-3.5 w-3.5 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm",children:T.label||T.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:T.entityName})]})]},T.id)})})]})]})})]})})]})]}),e.jsx("tbody",{children:f?e.jsx("tr",{children:e.jsx("td",{colSpan:p.length+2,className:"h-32 text-center",children:e.jsx(t.LoaderCircle,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})})}):g.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:p.length+2,className:"h-32 text-center text-muted-foreground",children:"No data available"})}):g.slice(0,100).map((T,R)=>e.jsxs("tr",{className:t.cn("border-b border-border transition-colors hover:bg-muted/50",R%2===0?"bg-background":"bg-muted/20"),children:[e.jsx("td",{className:"sticky left-0 z-10 w-12 border-r border-border bg-muted/50 px-2 py-2 text-center text-xs font-medium text-muted-foreground",children:R+1}),p.map(y=>{const B=T[y.name]??T[y.label??""];return e.jsx("td",{style:{width:x[y.id]?`${x[y.id]}px`:void 0,minWidth:x[y.id]?`${x[y.id]}px`:"120px"},className:t.cn("border-r border-border px-3 py-2 text-sm",(s==null?void 0:s.id)===y.id&&"bg-primary/5"),children:e.jsx("span",{className:"block truncate",children:Jc(B,y)})},`${R}-${y.id}`)}),e.jsx("td",{className:"w-10 border-r border-border"})]},R))})]}),e.jsx(a.DragOverlay,{children:A&&e.jsx("div",{className:"rounded border border-primary bg-background px-3 py-2 text-sm font-medium shadow-lg",children:A.label||A.name})})]})}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["Showing ",Math.min(g.length,100)," of ",g.length," rows"]}),e.jsxs("span",{children:[p.length," columns"]})]})]})}function Jc(s,n){if(s==null)return"—";if(typeof s=="number")return n.role==="metric"?new Intl.NumberFormat("en-US",{minimumFractionDigits:0,maximumFractionDigits:2}).format(s):s.toString();if(s instanceof Date||typeof s=="string"&&!isNaN(Date.parse(s))){const r=new Date(s);if(!isNaN(r.getTime()))return r.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}return String(s)}function Wc({entityGroups:s,isLoading:n=!1}){var D,w;const r=t.useEditorStore(S=>S.card),{updateCardConfig:o,removeGroupByColumn:c,removeMetricColumn:d}=t.useEditorActions(),[i,l]=v.useState(!0),[u,x]=v.useState(""),[m,b]=v.useState(new Set),h=((D=r==null?void 0:r.config)==null?void 0:D.groupByColumns)||[],p=((w=r==null?void 0:r.config)==null?void 0:w.metricColumns)||[],j=S=>{const M=new Set(m);M.has(S)?M.delete(S):M.add(S),b(M)},N=S=>h.some(M=>M.name===S.name&&M.qualifiedEntityName===S.qualifiedEntityName)||p.some(M=>M.name===S.name&&M.qualifiedEntityName===S.qualifiedEntityName),f=(S,M)=>{if(M)if(t.getDataType(S.dataType)==="number"){const F=a.getNewField(S,"metrics",[...h,...p]);o(r.id,{metricColumns:[...p,F]})}else{const F=a.getNewField(S,"groupBy",[...h,...p]);o(r.id,{groupByColumns:[...h,F]})}else{const A=h.findIndex(I=>I.name===S.name&&I.qualifiedEntityName===S.qualifiedEntityName),F=p.findIndex(I=>I.name===S.name&&I.qualifiedEntityName===S.qualifiedEntityName);A!==-1&&c(r.id,h[A].id),F!==-1&&d(r.id,p[F].id)}},g=S=>{if(!u)return S;const M=u.toLowerCase();return S.filter(A=>A.name.toLowerCase().includes(M)||A.label&&A.label.toLowerCase().includes(M))},k=S=>{switch(t.getDataType(S)){case"number":return a.Hash;case"date":return a.Calendar;default:return t.Type}};return i?e.jsxs("div",{className:"flex h-full w-72 flex-col border-l border-border bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Columns"}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>l(!1),title:"Close panel",children:e.jsx(Ar,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"border-b border-border p-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(Ke.Search,{className:"absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(t.Input,{placeholder:"Search columns...",value:u,onChange:S=>x(S.target.value),className:"h-8 pl-8 text-sm"})]})}),(h.length>0||p.length>0)&&e.jsxs("div",{className:"border-b border-border",children:[h.length>0&&e.jsxs(a.Collapsible,{defaultOpen:!0,children:[e.jsxs(a.CollapsibleTrigger,{className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium hover:bg-muted/50",children:[e.jsx(Ke.ChevronRight,{className:"h-3.5 w-3.5 transition-transform duration-200 [[data-state=open]>&]:rotate-90"}),e.jsx(a.Rows3,{className:"h-3.5 w-3.5 text-blue-500"}),e.jsx("span",{children:"Groupings"}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:h.length})]}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:h.map(S=>{const M=k(S.dataType);return e.jsxs("div",{className:"group flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[e.jsx(a.GripVertical,{className:"h-3 w-3 cursor-grab text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"}),e.jsx(M,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:S.label||S.name}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(r.id,S.id),children:e.jsx(le.X,{className:"h-3 w-3"})})]},S.id)})})})]}),p.length>0&&e.jsxs(a.Collapsible,{defaultOpen:!0,children:[e.jsxs(a.CollapsibleTrigger,{className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium hover:bg-muted/50",children:[e.jsx(Ke.ChevronRight,{className:"h-3.5 w-3.5 transition-transform duration-200 [[data-state=open]>&]:rotate-90"}),e.jsx(a.Calculator,{className:"h-3.5 w-3.5 text-green-500"}),e.jsx("span",{children:"Metrics"}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:p.length})]}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:p.map(S=>{const M=k(S.dataType);return e.jsxs("div",{className:"group flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[e.jsx(a.GripVertical,{className:"h-3 w-3 cursor-grab text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"}),e.jsx(M,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:S.label||S.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:S.aggregate}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>d(r.id,S.id),children:e.jsx(le.X,{className:"h-3 w-3"})})]},S.id)})})})]})]}),e.jsx(t.ScrollArea,{className:"flex-1",children:e.jsx("div",{className:"p-2",children:n?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent"})}):s.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No columns available"}):s.map(S=>{const M=g(S.columns);if(M.length===0)return null;const A=m.has(S.entityId)||u.length>0;return e.jsxs(a.Collapsible,{open:A,onOpenChange:()=>j(S.entityId),children:[e.jsxs(a.CollapsibleTrigger,{className:"flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm font-medium hover:bg-muted/50",children:[e.jsx(Ke.ChevronRight,{className:t.cn("h-3.5 w-3.5 transition-transform duration-200",A&&"rotate-90")}),e.jsx(t.Table2,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-left",children:S.label||S.entityName}),e.jsx("span",{className:"text-xs text-muted-foreground",children:M.length})]}),e.jsx(a.CollapsibleContent,{children:e.jsx("div",{className:"ml-4 space-y-0.5 border-l border-border pl-2",children:M.map(F=>{const I=k(F.dataType),C=N(F);return e.jsxs("label",{className:t.cn("flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm transition-colors hover:bg-muted/50",C&&"bg-primary/5"),children:[e.jsx(a.Checkbox,{checked:C,onCheckedChange:E=>f(F,E),className:"h-3.5 w-3.5"}),e.jsx(I,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:F.label||F.name})]},F.id)})})})]},S.entityId)})})})]}):e.jsx("div",{className:"flex h-full items-start border-l border-border bg-muted/30 p-2",children:e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>l(!0),title:"Open panel",children:e.jsx(Lr,{className:"h-4 w-4"})})})}const Xc=[{name:"SUM",description:"Sum of values",syntax:"SUM([column])"},{name:"AVG",description:"Average of values",syntax:"AVG([column])"},{name:"COUNT",description:"Count of rows",syntax:"COUNT([column])"},{name:"COUNTD",description:"Count distinct values",syntax:"COUNTD([column])"},{name:"MIN",description:"Minimum value",syntax:"MIN([column])"},{name:"MAX",description:"Maximum value",syntax:"MAX([column])"},{name:"IF",description:"Conditional logic",syntax:"IF(condition, then, else)"},{name:"CASE",description:"Multiple conditions",syntax:"CASE WHEN ... THEN ... END"},{name:"CONCAT",description:"Concatenate text",syntax:"CONCAT([col1], [col2])"},{name:"ROUND",description:"Round number",syntax:"ROUND([column], decimals)"},{name:"FLOOR",description:"Round down",syntax:"FLOOR([column])"},{name:"CEIL",description:"Round up",syntax:"CEIL([column])"},{name:"ABS",description:"Absolute value",syntax:"ABS([column])"},{name:"DATEPART",description:"Extract date part",syntax:"DATEPART(year, [date])"},{name:"DATEDIFF",description:"Difference between dates",syntax:"DATEDIFF(day, [date1], [date2])"}];function Zc({value:s,onChange:n,onSubmit:r,onCancel:o,selectedColumn:c,availableColumns:d}){const[i,l]=v.useState(!1),[u,x]=v.useState("column"),m=v.useRef(null);v.useEffect(()=>{const j=N=>{N.key==="Escape"&&s?o():N.key==="Enter"&&s&&!i&&r(s)};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[s,o,r,i]);const b=j=>{const N=`[${j.label||j.name}]`,f=m.current;if(f){const g=f.selectionStart||0,k=f.selectionEnd||0,D=s.slice(0,g)+N+s.slice(k);n(D),setTimeout(()=>{f.setSelectionRange(g+N.length,g+N.length),f.focus()},0)}else n(s+N);l(!1)},h=j=>{const N=m.current;if(N){const f=N.selectionStart||0,g=N.selectionEnd||0,k=s.slice(0,f)+j.syntax+s.slice(g);n(k),setTimeout(()=>{N.setSelectionRange(f+j.name.length+1,f+j.syntax.length-1),N.focus()},0)}else n(s+j.syntax);l(!1)},p=j=>{switch(t.getDataType(j)){case"number":return a.Hash;case"date":return a.Calendar;default:return t.Type}};return e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-muted/30 px-3 py-1.5",children:[e.jsx("div",{className:"flex min-w-[100px] items-center justify-center rounded border border-border bg-background px-2 py-1 text-xs font-medium text-muted-foreground",children:c?e.jsx("span",{className:"truncate",children:c.label||c.name}):e.jsx("span",{children:"—"})}),e.jsxs(t.Popover,{open:i&&u==="function",onOpenChange:j=>{l(j),j&&x("function")},children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",title:"Insert function",children:e.jsx(Or,{className:"h-4 w-4"})})}),e.jsx(t.PopoverContent,{className:"w-[300px] p-0",align:"start",children:e.jsxs(a.Command,{children:[e.jsx(a.CommandInput,{placeholder:"Search functions..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No functions found."}),e.jsx(a.CommandGroup,{heading:"Functions",children:Xc.map(j=>e.jsx(a.CommandItem,{value:j.name,onSelect:()=>h(j),children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-sm font-medium",children:j.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:j.description})]}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground/75",children:j.syntax})]})},j.name))})]})]})})]}),e.jsxs(t.Popover,{open:i&&u==="column",onOpenChange:j=>{l(j),j&&x("column")},children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-xs text-muted-foreground hover:text-foreground",title:"Insert column reference",children:[e.jsx("span",{children:"Columns"}),e.jsx(le.ChevronDown,{className:"h-3 w-3"})]})}),e.jsx(t.PopoverContent,{className:"w-[250px] p-0",align:"start",children:e.jsxs(a.Command,{children:[e.jsx(a.CommandInput,{placeholder:"Search columns..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No columns found."}),e.jsx(a.CommandGroup,{heading:"Available Columns",children:d.map(j=>{const N=p(j.dataType);return e.jsxs(a.CommandItem,{value:j.label||j.name,onSelect:()=>b(j),children:[e.jsx(N,{className:"mr-2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:j.label||j.name})]},j.id)})})]})]})})]}),e.jsx("div",{className:"relative flex-1",children:e.jsx(t.Input,{ref:m,value:s,onChange:j=>n(j.target.value),placeholder:"Enter a formula or select a column...",className:"h-7 border-border bg-background font-mono text-sm"})}),s&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:o,title:"Cancel (Esc)",children:e.jsx(le.X,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-green-600 hover:bg-green-600/10 hover:text-green-600",onClick:()=>r(s),title:"Apply (Enter)",children:e.jsx(t.Check,{className:"h-4 w-4"})})]})]})}function ed({className:s}){var p,j,N,f;const n=t.useEditorStore(g=>g.card),[r,o]=v.useState(null),[c,d]=v.useState(""),{columns:i=[],columnGroups:l=[],isLoading:u}=a.useColumns(),{valuePickFilterableFields:x=[]}=a.useFilterableFields();(p=n==null?void 0:n.config)!=null&&p.groupByColumns,(j=n==null?void 0:n.config)!=null&&j.metricColumns,(N=n==null?void 0:n.config)!=null&&N.groupByColumns,(f=n==null?void 0:n.config)!=null&&f.pivotByColumns;const m=g=>{o(g),d(g?`[${g.label||g.name}]`:"")},b=g=>{console.log("Formula submitted:",g),d(""),o(null)},h=()=>{d(""),o(null)};return e.jsxs("div",{className:t.cn("flex h-full w-full flex-col",s),children:[e.jsx(Zc,{value:c,onChange:d,onSubmit:b,onCancel:h,selectedColumn:r,availableColumns:i}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx(Qc,{selectedColumn:r,onColumnSelect:m,isLoading:u,sourceFields:i,filterableFields:x})}),e.jsx(Wc,{entityGroups:l,isLoading:u})]})]})}function td(){const[s,n]=v.useState("chart"),[r,o]=v.useState(!1),[c,d]=v.useState(!0),[i,l]=v.useState(!0),u=t.useEditorStore(Y=>Y.showAIDialog),x=t.useDashboardStore(Y=>Y.isVisualEditing),{setCardType:m}=t.useEditorActions(),b=t.useEditorStore(Y=>Y.card.type);v.useEffect(()=>Uc(),[]);const h=Y=>{m(Y)},p=t.useEditorStore(Y=>Y.frame),j=t.useEditorStore(Y=>Y.card);t.useEditorStore(Y=>Y.activeTabCardId),t.useEditorStore(Y=>Y.actions.getAvailableFields);const{addCard:N,removeCard:f,updateCard:g,setActiveCard:k,updateFilters:D,clearFilters:w}=t.useEditorActions(),{columnFields:S=[],scopedFields:M=[],filterableFields:A=[]}=a.useFilterableFields(),F=a.useSensors(a.useSensor(a.PointerSensor,{activationConstraint:{distance:8}})),I=j,{getFieldsForContainer:C,setFieldsForContainer:E,moveField:L,removeField:T,resetFields:R}=a.useFieldManagement(I,M),{activeField:y,handleDragStart:B,handleDragEnd:P}=Lc({activeCardId:p.activeCardId,sourceFields:M,getFieldsForContainer:C,setFieldsForContainer:E,moveField:L}),O=(Y,$)=>{$&&D(Y,$)},V=Y=>{w(Y)},_=A,z=Y=>{if(!Y)return 0;let $=Y.conditions.length;return Y.groups.forEach(U=>{$+=z(U)}),$},q=z(je.getAuthoredCardFilters(I)||null);return e.jsxs(a.DndContext,{sensors:F,collisionDetection:a.closestCenter,onDragStart:B,onDragEnd:P,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ia,{isVisible:c,onToggleVisibility:()=>d(!c)}),e.jsx("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:b==="tableBuilder"?e.jsx(ed,{className:"flex-1"}):e.jsxs(e.Fragment,{children:[!u&&e.jsx(fc,{onRemoveField:T,onResetFields:R,selectedChart:b,onChartChange:h,groupByFields:C("groupBy"),pivotByFields:C("pivotBy"),metricsFields:C("metrics"),sortByFields:C("sortBy"),detailFields:C("detailColumns"),activeField:y,isVisible:i,onToggleVisibility:()=>l(!i)}),e.jsx($c,{selectedChart:b,activeView:s,onViewChange:n,onFiltersClick:()=>o(!0),filterCount:q,activeCard:I,columns:S,getFieldsForContainer:C,cards:p.cards,activeCardId:p.activeCardId,addCard:N,setActiveCard:k})]})}),!c&&x&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(t.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>d(!0),title:"Show Data Source Panel",children:e.jsx(a.Database,{className:"h-4 w-4"})})})]}),I&&e.jsx(Ac,{cardId:I.id,filters:je.getAuthoredCardFilters(I)||null,onFiltersChange:O,onClearFilters:V,availableFields:_,isOpen:r,onOpenChange:o}),e.jsx(a.DragOverlay,{dropAnimation:null,children:e.jsx(Kc,{activeField:y||null})})]})}function sd({authToken:s,onSave:n,onClose:r}){const o=v.useRef(null),c=t.useEditorStore(A=>A.showAIDialog),d=t.useEditorStore(A=>A.isDevMode),i=a.useAssistantLayoutStore(A=>A.setFullscreen),l=a.useAssistantLayoutStore(A=>A.setPanelOpen),u=a.useAssistantLayoutStore(A=>A.setContainer),x=a.useAssistantPanel("editor"),m=a.useFullscreenAssistant(),b=a.useAssistantContainer("editor"),h=m==="editor",p=a.useDashboardAppearance(),j=v.useCallback(A=>{u("editor",A)},[u]),{setAuthToken:N}=t.useDashboardActions(),{setShowAIDialog:f,setOnSave:g,setOnClose:k}=t.useEditorActions(),{setActiveAssistantType:D}=t.useAIActions();v.useEffect(()=>{n&&g(n),r&&k(r)},[n,g,r,k]),v.useEffect(()=>{s&&s.accessToken&&N(s)},[s,N]),v.useEffect(()=>{var A,F;c?((A=o.current)==null||A.resize(40),l("editor",!0),D("editor")):((F=o.current)==null||F.resize(0),l("editor",!1),m==="editor"&&i(null),D(null))},[c,l,D,i,m]);function w(A){var F;A<1?(f(!1),l("editor",!1),m==="editor"&&i(null),D(null),(F=o.current)==null||F.resize(0)):(c||(f(!0),D("editor")),x.isOpen||l("editor",!0))}function S(){return e.jsxs(e.Fragment,{children:[e.jsx(ia,{isVisible:!0,onToggleVisibility:()=>{}}),e.jsxs("div",{className:"relative flex grow",children:[e.jsxs(a.ResizablePanelGroup,{"data-content":"editor-main",className:t.cn("grow transition-opacity",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(a.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(qi,{})}),e.jsx(a.ResizableHandle,{disabled:!c}),e.jsx(a.ResizablePanel,{"data-role":"editor-assistant-panel",ref:o,onResize:w,defaultSize:x.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(ea,{isFullscreen:h,onFullscreenChange:A=>i(A?"editor":null),fullscreenContainer:b})})})]}),e.jsx("div",{ref:j,className:t.cn("absolute inset-0",!h&&"pointer-events-none")})]})]})}function M(){return e.jsxs("div",{className:"relative flex h-full grow",children:[e.jsxs(a.ResizablePanelGroup,{"data-content":"explorer",className:t.cn("flex grow transition-opacity",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(a.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(td,{})}),e.jsx(a.ResizableHandle,{disabled:!c}),e.jsx(a.ResizablePanel,{"data-role":"editor-assistant-panel",ref:o,onResize:w,defaultSize:x.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(ea,{isFullscreen:h,onFullscreenChange:A=>i(A?"editor":null),fullscreenContainer:b})})})]}),e.jsx("div",{ref:j,className:t.cn("absolute inset-0",!h&&"pointer-events-none")})]})}return e.jsx(a.ErrorBoundary,{FallbackComponent:a.Fallback,children:d?e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:p.dashboardContainerStyle,children:S()}):e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",style:p.dashboardContainerStyle,children:M()})})}function nd(){t.useDashboardStore(p=>p.selectedCardId);const s=t.useDashboardStore(p=>p.selectedSheetId),n=t.useDashboardStore(p=>p.dashboard),{setIsVisualEditing:r,setSelectedSheetId:o}=t.useDashboardStore(p=>p.actions),c=t.useEditorStore(p=>p.editorContext),{clearEditorContext:d}=t.useEditorStore(p=>p.actions),i=a.useDashboardAppearance(),l=t.useDashboardStore(p=>p.isVisualEditing),u=t.useDashboardStore(p=>p.actions.updateFrame),x=t.useDashboardStore(p=>p.actions.updateDocumentSectionCard),m=a.useResolveExistingFrameSemanticExecutionPayload();async function b(p){var k,D,w;if((c==null?void 0:c.type)==="documentSection"){const S=a.getDocumentSectionEditorCard(p,c.cardId);if(!S){t.ue.error("No document section card found");return}if(!a.isSupportedDocumentTableCardType(S)){t.ue.error("Document table sections support Table and Pivot Table");return}x(c.sheetId,c.sectionId,S,{calculatedFields:p.calculatedFields}),d(),r(!1);return}const j=s?(k=n==null?void 0:n.sheets)==null?void 0:k.some(S=>{var M;return S.id===s&&((M=S.frames)==null?void 0:M.some(A=>A.id===p.id))}):!1,N=(w=(D=n==null?void 0:n.sheets)==null?void 0:D.find(S=>{var M;return(M=S.frames)==null?void 0:M.some(A=>A.id===p.id)}))==null?void 0:w.id,f=j?s:N||null;if(!f)return;const g=t.findDashboardFrameById(n,p.id);try{const S=await m(p,{previousFrame:g});u(f,p,{semanticExecutionPayload:S}),s!==f&&o(f),r(!1)}catch(S){console.error("Failed to resolve semantic metadata on save:",S),t.ue.error(S instanceof Error?S.message:"Failed to resolve semantic metadata for this visual")}}function h(){d(),r(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!l}),style:i.dashboardContainerStyle,children:e.jsx(sd,{onSave:b,onClose:h})})}exports.default=nd;