react-semaphor 0.1.560 → 0.1.562

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 (168) hide show
  1. package/dist/analytics-protocol/index.js +450 -423
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/assistant-protocol/index.js +5 -5
  4. package/dist/brand-studio/index.js +9 -9
  5. package/dist/briefings/index.js +5 -5
  6. package/dist/chunks/{analytics-base-schemas-CHLxsPfX.js → analytics-base-schemas-BaIQrEzX.js} +221 -188
  7. package/dist/chunks/{assistant-chat-Bu2fFm_I.js → assistant-chat-R_yT8xH4.js} +116 -117
  8. package/dist/chunks/bookmark-impact-D4Kl4amw.js +75 -0
  9. package/dist/chunks/bookmark-state-CWeoGbrx.js +743 -0
  10. package/dist/chunks/{braces-Da41xfUd.js → braces-DzgoQC64.js} +1 -1
  11. package/dist/chunks/{comparison-window-caption-4FNkMrzE.js → comparison-window-caption-D1EUXzaR.js} +550 -425
  12. package/dist/chunks/{context-BgPDzLHZ.js → context-R31TSL5V.js} +1 -1
  13. package/dist/chunks/{dashboard-_MeBuy67.js → dashboard-Bp1y5oun.js} +1 -1
  14. package/dist/chunks/{dashboard-briefing-launcher-CEi4Pr_v.js → dashboard-briefing-launcher-S5FB3aUW.js} +236 -236
  15. package/dist/chunks/dashboard-controls-CfC_6Ztn.js +2277 -0
  16. package/dist/chunks/{dashboard-json-B1mU_OMa.js → dashboard-json-gYZT7ZQY.js} +5 -5
  17. package/dist/chunks/dates-DFY7Gfss.js +91 -0
  18. package/dist/chunks/{edit-dashboard-visual-0CJN31Y3.js → edit-dashboard-visual-u7OI_g8Q.js} +7119 -7198
  19. package/dist/chunks/filter-reach-copy-CvV7W5dd.js +3965 -0
  20. package/dist/chunks/{filter-value-text-CRC-K_l_.js → filter-value-text-CPwFkrMz.js} +11 -10
  21. package/dist/chunks/global-date-filter-utils-N1kcsOFE.js +16722 -0
  22. package/dist/chunks/{index-DtHidOPV.js → index-CNGkfUp4.js} +269 -264
  23. package/dist/chunks/{layout-grid-BvsH4RY2.js → layout-grid-BM65viQh.js} +1 -1
  24. package/dist/chunks/{list-filter-Dg0otx5E.js → list-filter-BoeLBfL3.js} +1 -1
  25. package/dist/chunks/{matrix-analytical-definition-CM18W8w6.js → matrix-analytical-definition-hEucouWM.js} +4 -4
  26. package/dist/chunks/{matrix-card-HPskLaPy.js → matrix-card-CCh9JjP1.js} +3 -3
  27. package/dist/chunks/{matrix-member-presentation-Bbrfrke4.js → matrix-member-presentation-DsAUbuoL.js} +1 -1
  28. package/dist/chunks/{matrix-operation-contract-WPv4R-H_.js → matrix-operation-contract-DsLdFdSa.js} +365 -349
  29. package/dist/chunks/{metric-comparison-ljMKYZKa.js → metric-comparison-Bnso1cm1.js} +6 -6
  30. package/dist/chunks/{model-change-Ccn1zaxl.js → model-change-T1cRkh3m.js} +1 -1
  31. package/dist/chunks/{palette-Bsh376zO.js → palette-p1XSJFgB.js} +1 -1
  32. package/dist/chunks/pivot-result-contract-expectations-B53jqszr.js +56 -0
  33. package/dist/chunks/{pivot-result-identity-vS9TSh4f.js → pivot-result-identity-Dq5jm-EC.js} +1 -1
  34. package/dist/chunks/{zoned-wall-clock-B1n_WjW3.js → raw-temporal-value-Bqz8wc7L.js} +97 -46
  35. package/dist/chunks/{report-preferences-dialog-BV8L0SeS.js → report-preferences-dialog-C4RAR8u5.js} +68 -63
  36. package/dist/chunks/{report-runtime-context-BZQh9ywy.js → report-runtime-context-BITkNSDa.js} +2 -2
  37. package/dist/chunks/resolve-dashboard-input-context-DaDrZGuA.js +8214 -0
  38. package/dist/chunks/{save-B5EAsgQF.js → save-CHV1B1fL.js} +1 -1
  39. package/dist/chunks/{saved-dashboard-context-n2Wn11cV.js → saved-dashboard-context-DFYBrE6O.js} +93 -94
  40. package/dist/chunks/{selection-filter-compiler-BKXmyLrS.js → selection-filter-compiler-CUDRnUxc.js} +19 -18
  41. package/dist/chunks/{selection-reducer-D0YnaAD9.js → selection-reducer-Bz5aywT4.js} +1 -1
  42. package/dist/chunks/{semaphor-ready-indicator-XLBLOJ2V.js → semaphor-ready-indicator-Cfuafnem.js} +38188 -40344
  43. package/dist/chunks/{shelf-drop-preview-context-DHMa54a-.js → shelf-drop-preview-context-BR2GEYog.js} +81 -82
  44. package/dist/chunks/{source-entity-resolution-dUG5VWRm.js → source-entity-resolution-DdDVXFB8.js} +6 -6
  45. package/dist/chunks/{switch-ByxH4M7t.js → switch-BW4yXSYs.js} +3 -3
  46. package/dist/chunks/{table-export-sheet-C_GdeTYU.js → table-export-sheet-bSXxGn-v.js} +1 -1
  47. package/dist/chunks/temporal-input-presentation-sk9gqLi6.js +4960 -0
  48. package/dist/chunks/{token-types-CQtXUVMy.js → token-types-BUK06hU2.js} +1 -1
  49. package/dist/chunks/{upload-wbR-NVzq.js → upload-BnmuyPqW.js} +1 -1
  50. package/dist/chunks/{use-create-flow-overlay-state-CEBaLOKC.js → use-create-flow-overlay-state-DyzhWvRJ.js} +6 -6
  51. package/dist/chunks/{validators-CXTneCA4.js → validators-BIM0FE31.js} +774 -895
  52. package/dist/dashboard/index.js +2 -2
  53. package/dist/dashboard-authoring/index.js +2477 -2685
  54. package/dist/data-app-sdk/index.js +30 -30
  55. package/dist/data-app-sdk-adapters/index.js +3 -3
  56. package/dist/data-app-sdk-validation/index.js +25 -25
  57. package/dist/format-utils/index.js +274 -267
  58. package/dist/index.js +59 -59
  59. package/dist/report-runtime-context/index.js +2 -2
  60. package/dist/style.css +1 -1
  61. package/dist/surfboard/index.js +2 -2
  62. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  63. package/dist/types/components/dashboard/dashboard-create-dialog.d.ts +23 -0
  64. package/dist/types/components/dashboard/summary-number-formatter.d.ts +6 -0
  65. package/dist/types/components/index.d.ts +1 -2
  66. package/dist/types/components/surfboard/filter/types.d.ts +3 -1
  67. package/dist/types/index.js +50 -51
  68. package/dist/types/lib/formatters/kpi-number-formatter.d.ts +41 -0
  69. package/dist/types/lib/formatters/raw-temporal-presentation.d.ts +59 -2
  70. package/dist/types/lib/interactions/get-click-context-from-matrix.d.ts +5 -0
  71. package/dist/types/lib/interactions/get-click-context-from-table.d.ts +45 -0
  72. package/dist/types/lib/print/print-inputs.d.ts +2 -1
  73. package/dist/types/lib/query-context/assemble-card-query.d.ts +2 -0
  74. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +5 -0
  75. package/dist/types/lib/selection/selection-from-click-context.d.ts +41 -0
  76. package/dist/types/lib/stores/editor-store.d.ts +9 -1
  77. package/dist/types/lib/stores/table-actions.d.ts +0 -2
  78. package/dist/types/lib/types/common-types.d.ts +6 -0
  79. package/dist/types/lib/types/explorer-types.d.ts +7 -1
  80. package/dist/types/lib/types/interaction-types.d.ts +3 -1
  81. package/dist/types/lib/types/token-types.d.ts +0 -1
  82. package/dist/types/shared/analytics-protocol/analytics-base-schemas.d.ts +13 -1
  83. package/dist/types/shared/analytics-protocol/contracts.d.ts +9 -40
  84. package/dist/types/shared/analytics-protocol/measure-aggregation-profile.d.ts +12 -0
  85. package/dist/types/shared/analytics-protocol/selection-contract.d.ts +12 -2
  86. package/dist/types/shared/analytics-protocol/validators.d.ts +1 -2
  87. package/dist/types/shared/assistant-protocol/context.d.ts +8 -8
  88. package/dist/types/shared/dashboard-authoring/card-formats/sql-date-pattern.d.ts +7 -1
  89. package/dist/types/shared/dashboard-authoring/card-settings/apply-card-settings.d.ts +11 -0
  90. package/dist/types/shared/dashboard-authoring/card-settings/card-display-write.d.ts +76 -0
  91. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +14 -0
  92. package/dist/types/shared/dashboard-authoring/card-settings/carry-column-settings.d.ts +3 -0
  93. package/dist/types/shared/dashboard-authoring/card-settings/column-format-write.d.ts +8 -0
  94. package/dist/types/shared/dashboard-authoring/card-settings/column-names.d.ts +51 -0
  95. package/dist/types/shared/dashboard-authoring/card-settings/column-polarity-write.d.ts +5 -0
  96. package/dist/types/shared/dashboard-authoring/card-settings/column-sources.d.ts +14 -0
  97. package/dist/types/shared/dashboard-authoring/card-settings/confirm-class.d.ts +9 -0
  98. package/dist/types/shared/dashboard-authoring/card-settings/highlight-inputs.d.ts +19 -0
  99. package/dist/types/shared/dashboard-authoring/card-settings/index.d.ts +17 -0
  100. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +117 -0
  101. package/dist/types/shared/dashboard-authoring/card-settings/read-card-settings.d.ts +10 -0
  102. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-highlights.d.ts +14 -0
  103. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-settings.d.ts +59 -0
  104. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +51 -0
  105. package/dist/types/shared/dashboard-authoring/card-settings/views.d.ts +30 -0
  106. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +6 -0
  107. package/dist/types/shared/dashboard-authoring/changes/card-types.d.ts +32 -0
  108. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +3402 -4313
  109. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +49 -8
  110. package/dist/types/shared/dashboard-authoring/changes/field-ref.d.ts +91 -0
  111. package/dist/types/shared/dashboard-authoring/changes/read-card-query.d.ts +7 -0
  112. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +52 -2
  113. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-create.d.ts +26 -0
  114. package/dist/types/shared/dashboard-authoring/click-to-filter-settings.d.ts +2 -1
  115. package/dist/types/shared/dashboard-authoring/conditional-formatting/kpi.d.ts +1 -8
  116. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +20 -20
  117. package/dist/types/shared/dashboard-authoring/detail-date-presentation.d.ts +9 -0
  118. package/dist/types/shared/dashboard-authoring/index.d.ts +11 -6
  119. package/dist/types/shared/dashboard-authoring/kpi-figure.d.ts +123 -0
  120. package/dist/types/shared/dashboard-authoring/measure-calculations/apply.d.ts +8 -0
  121. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +16 -0
  122. package/dist/types/shared/dashboard-authoring/measure-calculations/dates.d.ts +41 -0
  123. package/dist/types/shared/dashboard-authoring/measure-calculations/index.d.ts +17 -0
  124. package/dist/types/shared/dashboard-authoring/measure-calculations/options.d.ts +63 -0
  125. package/dist/types/shared/dashboard-authoring/measure-calculations/read.d.ts +16 -0
  126. package/dist/types/shared/dashboard-authoring/measure-calculations/resolve.d.ts +79 -0
  127. package/dist/types/shared/dashboard-authoring/measure-calculations/schemas.d.ts +934 -0
  128. package/dist/types/shared/dashboard-authoring/measure-calculations/sentences.d.ts +4 -0
  129. package/dist/types/shared/dashboard-authoring/measure-calculations/set.d.ts +11 -0
  130. package/dist/types/shared/dashboard-authoring/measure-calculations/transform.d.ts +63 -0
  131. package/dist/types/shared/dashboard-authoring/measure-calculations/window-transforms.d.ts +60 -0
  132. package/dist/types/shared/dashboard-authoring/new-card.d.ts +12 -1
  133. package/dist/types/shared/dashboard-authoring/operations/apply-dashboard-operations.d.ts +2 -1
  134. package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +46 -0
  135. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +73 -3
  136. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +21 -3
  137. package/dist/types/shared/dashboard-authoring/text-card-words/blocks.d.ts +58 -0
  138. package/dist/types/shared/dashboard-authoring/text-card-words/index.d.ts +55 -0
  139. package/dist/types/shared/dashboard-authoring/text-card-words/rich-content.d.ts +18 -0
  140. package/dist/types/shared/dashboard-viewer/bookmark-impact.d.ts +33 -0
  141. package/dist/types/shared/format-utils/document-print.d.ts +82 -0
  142. package/dist/types/shared/format-utils/formatters/matrix-formatter.d.ts +8 -1
  143. package/dist/types/shared/format-utils/index.d.ts +1 -0
  144. package/dist/types/shared/format-utils/raw-temporal.d.ts +18 -7
  145. package/dist/types/shared/temporal/index.d.ts +1 -0
  146. package/dist/types/shared/temporal/raw-temporal-equality.d.ts +19 -0
  147. package/dist/types/shared/temporal/raw-temporal-value.d.ts +29 -0
  148. package/dist/types/shared/temporal/zoned-wall-clock.d.ts +6 -0
  149. package/package.json +2 -2
  150. package/dist/chunks/bookmark-state-BFY9oNmr.js +0 -111
  151. package/dist/chunks/custom-visual-inputs-Dz-enUNR.js +0 -292
  152. package/dist/chunks/dashboard-controls-Bi7fyG-4.js +0 -2339
  153. package/dist/chunks/document-dashboard-inputs-CkWfDB8c.js +0 -3010
  154. package/dist/chunks/filter-reach-copy-BF4w4kI2.js +0 -3738
  155. package/dist/chunks/global-date-filter-utils-D8365uPH.js +0 -12889
  156. package/dist/chunks/pivot-result-contract-expectations-Bl5suy4-.js +0 -1832
  157. package/dist/chunks/raw-temporal-presentation-BHm7s-hz.js +0 -540
  158. package/dist/chunks/resolve-dashboard-input-context-CAMiWvyR.js +0 -5280
  159. package/dist/chunks/table-settings-Imz0FgWi.js +0 -637
  160. package/dist/chunks/temporal-input-presentation-uvNK_tM0.js +0 -3228
  161. package/dist/types/components/dashboard/ai-dashboard-create-dialog.d.ts +0 -38
  162. package/dist/types/components/dashboard/dashboard-create-template.d.ts +0 -10
  163. package/dist/types/lib/hooks/use-dashboard-authoring.d.ts +0 -49
  164. package/dist/types/shared/dashboard-authoring/artifact-compiler.d.ts +0 -6
  165. package/dist/types/shared/dashboard-authoring/contracts.d.ts +0 -106
  166. package/dist/types/shared/dashboard-authoring/protocol-adapter.d.ts +0 -7
  167. package/dist/types/shared/dashboard-authoring/source-matching.d.ts +0 -34
  168. package/dist/types/shared/dashboard-authoring/validators.d.ts +0 -2
@@ -0,0 +1,3965 @@
1
+ import { a9 as Pn, aa as An, ab as Rn, ac as Et, ad as En, ae as Vn, af as Kn, ag as Ln, ah as Bn, ai as Vt, aj as $n, ak as qn, al as zn, am as Ie, an as Un, ao as jn, ap as Gn, k as Wn, aq as Hn, H as Qn, L as Yn, ar as Jn, as as Xn } from "./resolve-dashboard-input-context-DaDrZGuA.js";
2
+ import { eW as Kt, bo as de, eX as Zn, eY as er, eZ as tr, e_ as nr, W as j, e$ as Lt, bq as rr, f0 as ir, f1 as Ke, ao as Le, f2 as ar, bs as or, f3 as sr, f4 as lr, R as Be, f5 as cr, bz as ur, X as dr, f6 as fr, S as mr, f7 as S, a$ as $e, f8 as Q, f9 as _, fa as pr, fb as hr, fc as dt, fd as gr, fe as ft, ff as yr, aL as T, fg as Bt, aX as qe, fh as br, fi as vr, ch as $t, fj as qt, fk as zt, eQ as Ut, fl as mt, a5 as G, fm as ze, fn as pt, fo as Ue, fp as ht, fq as gt, eT as Fr, c1 as je, fr as Cr, fs as Ir, ft as xr, fu as ee, c4 as yt, fv as Sr, ab as jt, ac as Gt, d as wr, c8 as Tr, fw as Dr, c9 as kr, fx as Mr, fy as Or, fz as Nr, fA as _r, j as Wt, fB as Pr, fC as Ar, fD as Rr, fE as Oe, fF as Er, fG as xe, d3 as Ht, fH as bt, fI as Vr, cD as Kr, d6 as vt, d5 as Lr, fJ as Br, d_ as $r, e0 as qr, aA as zr, e3 as Ur, ad as Ft, aQ as jr, ew as Gr, fK as Wr, fL as Hr, co as Ct } from "./global-date-filter-utils-N1kcsOFE.js";
3
+ import { H as Qt, f as Qr, e as Yr, G as Yt, aA as Jr, v as Xr, a_ as Jt, aX as Ne, aV as $, aY as Zr, a$ as ei } from "./validators-BIM0FE31.js";
4
+ import { r as Se } from "./matrix-operation-contract-DsLdFdSa.js";
5
+ import { r as ti, C as ni } from "./metric-comparison-Bnso1cm1.js";
6
+ import { t as It } from "./analytics-base-schemas-BaIQrEzX.js";
7
+ import "zod";
8
+ import { b as W, i as R, aI as ri, aJ as ii, m as ai, h as oi, d as _e, e as si, Q as N, ae as li, al as ci, c as ui, ag as di, W as fi, w as mi, a4 as pi } from "./temporal-input-presentation-sk9gqLi6.js";
9
+ import "../value-format-preferences/index.js";
10
+ import { y as hi, z as ge } from "./bookmark-state-CWeoGbrx.js";
11
+ import { g as gi } from "./_commonjsHelpers-DimLPMtv.js";
12
+ import "./index-CuHybtft.js";
13
+ import "./index-CJW5BdWT.js";
14
+ import "./context-R31TSL5V.js";
15
+ import { a as yi } from "./source-entity-resolution-DdDVXFB8.js";
16
+ import { R as bi } from "./matrix-analytical-definition-hEucouWM.js";
17
+ import { r as Pe } from "./pivot-result-identity-Dq5jm-EC.js";
18
+ import { r as Xt } from "./applied-constraints-DU-wndZ7.js";
19
+ const vi = /\{\{-?\s*filters\s*\|\s*where\s*-?\}\}/i, Fi = /\{\{-?\s*filters\s*\|\s*and\s*-?\}\}/i, Ci = /\bwhere\b/i;
20
+ function Ii(e) {
21
+ return e != null && e.trim() ? vi.test(e) || Fi.test(e) : !1;
22
+ }
23
+ function Ho(e) {
24
+ return !(e != null && e.trim()) || Ii(e) ? null : Ci.test(e) ? {
25
+ helper: "{{ filters | and }}",
26
+ description: "For queries with an existing WHERE clause."
27
+ } : {
28
+ helper: "{{ filters | where }}",
29
+ description: "For queries without a WHERE clause."
30
+ };
31
+ }
32
+ function xi(e, t) {
33
+ if (!(typeof e != "number" || typeof t != "number"))
34
+ return e === t ? t : void 0;
35
+ }
36
+ function K(e, t) {
37
+ const n = W(e, t);
38
+ if (n) {
39
+ if (n.type === "date")
40
+ return {
41
+ type: "date",
42
+ locale: n.locale,
43
+ dateFormat: n.pattern,
44
+ ...n.dialect ? { dateDialect: n.dialect } : {},
45
+ ...n.preset ? { datePreset: n.preset } : {},
46
+ timezone: n.timezone,
47
+ sourceTimezone: n.sourceTimezone,
48
+ relative: n.relative,
49
+ prefix: n.prefix,
50
+ suffix: n.suffix
51
+ };
52
+ if (n.type === "duration")
53
+ return {
54
+ type: "duration",
55
+ durationInputUnit: n.inputUnit,
56
+ durationDisplayStyle: n.outputStyle,
57
+ durationLargestUnit: n.largestUnit,
58
+ durationSmallestUnit: n.smallestUnit,
59
+ durationMaxUnits: n.maxUnits,
60
+ prefix: n.prefix,
61
+ suffix: n.suffix,
62
+ negativeInParentheses: n.negativeStyle === "parentheses"
63
+ };
64
+ if (R(n))
65
+ return {
66
+ type: n.type,
67
+ locale: n.locale,
68
+ currency: n.type === "currency" ? n.currency : void 0,
69
+ decimalPlaces: t != null && t.preserveOmittedProperties ? void 0 : xi(
70
+ n.minimumFractionDigits,
71
+ n.maximumFractionDigits
72
+ ),
73
+ minimumFractionDigits: n.minimumFractionDigits,
74
+ maximumFractionDigits: n.maximumFractionDigits,
75
+ useGrouping: n.useGrouping,
76
+ prefix: n.prefix,
77
+ suffix: n.suffix,
78
+ useSuffix: !!n.compact,
79
+ negativeInParentheses: n.negativeStyle === "parentheses",
80
+ ...n.signDisplay ? { signDisplay: n.signDisplay } : {},
81
+ multiplyBy: n.type === "percent" ? n.scale ?? (n.percentValueMode === "whole" ? 1 : 100) : n.scale,
82
+ percentValueMode: n.type === "percent" ? n.percentValueMode : void 0
83
+ };
84
+ }
85
+ }
86
+ function Zt(e, t) {
87
+ const n = W(e, t);
88
+ return (n == null ? void 0 : n.type) === "duration" ? {
89
+ style: "duration",
90
+ duration: {
91
+ inputUnit: n.inputUnit,
92
+ outputStyle: n.outputStyle,
93
+ largestUnit: n.largestUnit,
94
+ smallestUnit: n.smallestUnit,
95
+ maxUnits: n.maxUnits
96
+ },
97
+ prefix: n.prefix,
98
+ suffix: n.suffix,
99
+ negativeStyle: n.negativeStyle
100
+ } : !n || !R(n) ? void 0 : {
101
+ style: n.type === "currency" ? "currency" : n.type === "percent" ? "percent" : n.type === "scientific" ? "scientific" : "decimal",
102
+ currency: n.type === "currency" && n.currency || (t != null && t.preserveOmittedProperties ? void 0 : "USD"),
103
+ locale: n.locale || (t != null && t.preserveOmittedProperties ? void 0 : ri),
104
+ minimumFractionDigits: n.minimumFractionDigits ?? (t != null && t.preserveOmittedProperties ? void 0 : 0),
105
+ maximumFractionDigits: n.maximumFractionDigits ?? (t != null && t.preserveOmittedProperties ? void 0 : 2),
106
+ useGrouping: typeof n.useGrouping == "boolean" ? n.useGrouping : !0,
107
+ percentValueMode: n.type === "percent" ? n.percentValueMode || "fraction" : "whole",
108
+ scale: n.scale,
109
+ compact: n.compact,
110
+ negativeStyle: n.negativeStyle,
111
+ ...n.signDisplay ? { signDisplay: n.signDisplay } : {},
112
+ prefix: n.prefix,
113
+ suffix: n.suffix
114
+ };
115
+ }
116
+ const xt = [10, 20, 50, 100, 500, 1e3], Si = 50;
117
+ function wi(e) {
118
+ return e && e > 0 ? e : Si;
119
+ }
120
+ function Qo(e) {
121
+ const t = wi(e), n = [...xt];
122
+ return xt.includes(
123
+ t
124
+ ) || (n.push(t), n.sort((r, i) => r - i)), n;
125
+ }
126
+ function Yo(e) {
127
+ var t, n;
128
+ return !!((e.type === "table" || e.type === "detailTable") && e.sql && !Kt(e.config) && !((n = (t = e.preferences) == null ? void 0 : t.tablePrefs) != null && n.forceClientPagination));
129
+ }
130
+ function Ti(e, t) {
131
+ var r, i, a, o;
132
+ if (t === "table-print")
133
+ return "disabled";
134
+ if ((i = (r = e.preferences) == null ? void 0 : r.tablePrefs) != null && i.forceClientPagination)
135
+ return "client";
136
+ const n = Kt(e.config);
137
+ return e.sql && !n ? (o = (a = e.preferences) == null ? void 0 : a.tablePrefs) != null && o.enableDevModePagination ? "server" : "client" : n && Pn(e) ? "server" : "client";
138
+ }
139
+ const en = Object.freeze({}), Jo = {
140
+ access: "session-only",
141
+ printMode: !1,
142
+ baseline: null,
143
+ applied: null,
144
+ appliedBookmark: null,
145
+ tableSettings: en,
146
+ notices: [],
147
+ isFavorite: !1,
148
+ fetchedAt: 0
149
+ };
150
+ function Xo(e) {
151
+ return !e.viewer.printMode && e.viewer.access !== "session-only" && !!e.viewer.baseline && !!e.viewerStateClient && !e.isDashboardEditing;
152
+ }
153
+ function Di(e) {
154
+ return e.isDashboardEditing ? en : e.viewer.tableSettings;
155
+ }
156
+ function ki(e, t) {
157
+ return Di(e)[t];
158
+ }
159
+ function Zo(e, t, n) {
160
+ if (!(n.isEditorPreview || e.isDashboardEditing) && hi(e.dashboard, t))
161
+ return { settings: ki(e, t) };
162
+ }
163
+ function Mi(e) {
164
+ var t;
165
+ return An({
166
+ card: e.card,
167
+ paginationMode: Ti(e.card) === "server" ? "server" : "client",
168
+ result: {
169
+ keys: e.keys ?? Rn(e.records),
170
+ rows: e.records,
171
+ columns: e.resultColumns,
172
+ columnKeyMap: e.columnKeyMap,
173
+ comparisonMetadata: e.comparisonMetadata
174
+ },
175
+ settings: (t = e.viewerTable) == null ? void 0 : t.settings,
176
+ projection: "export"
177
+ });
178
+ }
179
+ function Oi(e) {
180
+ if (e)
181
+ return K(
182
+ W(e, { preserveOmittedProperties: !0 }),
183
+ { preserveOmittedProperties: !0 }
184
+ );
185
+ }
186
+ function Ni(e) {
187
+ if (e.type === "percent") {
188
+ const { multiplyBy: t, percentValueMode: n, ...r } = e, i = t === 100 ? "fraction" : t === 1 ? "whole" : t === void 0 ? n : void 0;
189
+ if (i || t === void 0)
190
+ return It(
191
+ de({ ...r, ...i ? { percentValueMode: i } : {} }, { preserveOmittedProperties: !0 })
192
+ );
193
+ }
194
+ return It(
195
+ de(e, { preserveOmittedProperties: !0 })
196
+ );
197
+ }
198
+ const ye = Oi, es = Ni, _i = () => ({
199
+ urlTemplate: "{value}",
200
+ // Default: use cell value as-is
201
+ labelType: "value",
202
+ // Default: show cell value as label
203
+ staticLabel: "",
204
+ labelColumn: "",
205
+ openInNewTab: !0
206
+ // Default: open in new tab (current behavior)
207
+ }), Ge = () => ({
208
+ type: "none",
209
+ inheritMetricFormat: !0,
210
+ textAlign: "left",
211
+ // The table's one width rule (card appearance P2-21).
212
+ width: tr,
213
+ minWidth: er,
214
+ maxWidth: Zn,
215
+ textOverflow: "ellipsis",
216
+ textWrap: "default",
217
+ numberFormat: {
218
+ style: "decimal",
219
+ currency: "USD",
220
+ locale: "en-US",
221
+ minimumFractionDigits: 0,
222
+ maximumFractionDigits: 2,
223
+ useGrouping: !0,
224
+ percentValueMode: "whole"
225
+ },
226
+ dateFormat: {
227
+ format: "MM/dd/yyyy",
228
+ useCustomFormat: !1,
229
+ customFormat: "yyyy-MM-dd'T'HH:mm:ss",
230
+ useRelativeTime: !1,
231
+ timezone: "auto",
232
+ // Default to auto (use context or browser timezone for display)
233
+ sourceTimezone: "auto"
234
+ // Default to auto (use explicit timezone if present, otherwise assume UTC)
235
+ },
236
+ linkFormat: _i()
237
+ });
238
+ function ts(e, t, n, r) {
239
+ return t && t !== "auto" ? t : n;
240
+ }
241
+ const ns = (e) => !e || e === "auto" ? "local time" : {
242
+ "America/New_York": "Eastern Time",
243
+ "America/Chicago": "Central Time",
244
+ "America/Denver": "Mountain Time",
245
+ "America/Los_Angeles": "Pacific Time",
246
+ "Europe/London": "London Time",
247
+ "Europe/Paris": "Central European Time",
248
+ "Asia/Tokyo": "Japan Time",
249
+ "Asia/Shanghai": "China Time",
250
+ UTC: "UTC"
251
+ }[e] || e;
252
+ function tn(e, t) {
253
+ const n = typeof e.decimalPlaces == "number", r = typeof e.minimumFractionDigits == "number" ? e.minimumFractionDigits : n ? e.decimalPlaces : t.min, i = typeof e.maximumFractionDigits == "number" ? e.maximumFractionDigits : n ? e.decimalPlaces : t.max;
254
+ return {
255
+ minimumFractionDigits: r,
256
+ maximumFractionDigits: Math.max(r, i)
257
+ };
258
+ }
259
+ function fe(e, t) {
260
+ const n = tn(e, t), r = typeof e.suffix == "string" && e.suffix.length > 0;
261
+ return {
262
+ style: "decimal",
263
+ locale: e.locale,
264
+ currency: e.currency,
265
+ minimumFractionDigits: n.minimumFractionDigits,
266
+ maximumFractionDigits: n.maximumFractionDigits,
267
+ useGrouping: e.useGrouping,
268
+ // Preserve legacy behavior: explicit custom suffix should not trigger compacting.
269
+ useSuffix: !!(e.useSuffix && !r),
270
+ prefix: e.prefix,
271
+ suffix: e.suffix,
272
+ negativeInParentheses: e.negativeInParentheses,
273
+ multiplyBy: e.multiplyBy,
274
+ percentValueMode: e.percentValueMode
275
+ };
276
+ }
277
+ function We(e, t = "auto", n = {}) {
278
+ if (t === "auto" && (t = Vi(e, n)), (t === "number" || t === "currency" || t === "percent" || t === "scientific") && n.signDisplay && n.signDisplay !== "auto" && Number.isFinite(Number(e))) {
279
+ const i = typeof n.multiplyBy == "number" && Number.isFinite(n.multiplyBy) ? n.multiplyBy : 1, a = Number(e) * i, o = ii(a, n.signDisplay), s = We(o.value === a ? e : -Number(e), t, { ...n, signDisplay: void 0 });
280
+ if (!o.plus) return s;
281
+ const l = n.prefix ?? "";
282
+ return l && s.startsWith(l) ? `${l}+${s.slice(l.length)}` : `+${s}`;
283
+ }
284
+ switch (t) {
285
+ case "number":
286
+ return nn(e, n);
287
+ case "currency":
288
+ return rn(e, n);
289
+ case "percent":
290
+ return Pi(e, n);
291
+ case "date":
292
+ return Ai(e, n);
293
+ case "scientific":
294
+ return Ri(e, n);
295
+ case "duration":
296
+ return Ei(e, n);
297
+ default:
298
+ return String(e);
299
+ }
300
+ }
301
+ function nn(e, t = {}) {
302
+ return e < 0 && !!t.prefix && !t.negativeInParentheses ? `-${_e(
303
+ Math.abs(e),
304
+ fe(t, {
305
+ min: 0,
306
+ max: 0
307
+ })
308
+ )}` : _e(
309
+ e,
310
+ fe(t, {
311
+ min: 0,
312
+ max: 0
313
+ })
314
+ );
315
+ }
316
+ function rn(e, t = {}) {
317
+ return si(e, {
318
+ ...fe(t, {
319
+ min: 2,
320
+ max: 2
321
+ }),
322
+ style: "currency",
323
+ currency: t.currency || "USD"
324
+ });
325
+ }
326
+ function Pi(e, t = {}) {
327
+ const n = tn(t, { min: 1, max: 1 }), i = typeof t.multiplyBy == "number" && Number.isFinite(t.multiplyBy) ? t.multiplyBy : t.percentValueMode === "whole" ? 1 : 100, a = e * i;
328
+ return _e(a, {
329
+ locale: t.locale,
330
+ minimumFractionDigits: n.minimumFractionDigits,
331
+ maximumFractionDigits: n.maximumFractionDigits,
332
+ useGrouping: t.useGrouping,
333
+ prefix: t.prefix,
334
+ suffix: t.suffix || "%",
335
+ negativeInParentheses: t.negativeInParentheses,
336
+ useSuffix: !1
337
+ });
338
+ }
339
+ function Ai(e, t = {}) {
340
+ const { locale: n = "en-US" } = t;
341
+ try {
342
+ const r = new Date(e);
343
+ return isNaN(r.getTime()) ? String(e) : new Intl.DateTimeFormat(n, {
344
+ dateStyle: "short"
345
+ }).format(r);
346
+ } catch {
347
+ return String(e);
348
+ }
349
+ }
350
+ function Ri(e, t = {}) {
351
+ return oi(
352
+ e,
353
+ fe(t, { min: 2, max: 2 })
354
+ );
355
+ }
356
+ function Ei(e, t = {}) {
357
+ return ai(e, {
358
+ inputUnit: t.durationInputUnit,
359
+ outputStyle: t.durationDisplayStyle,
360
+ largestUnit: t.durationLargestUnit,
361
+ smallestUnit: t.durationSmallestUnit,
362
+ maxUnits: t.durationMaxUnits,
363
+ prefix: t.prefix,
364
+ suffix: t.suffix,
365
+ negativeInParentheses: t.negativeInParentheses
366
+ });
367
+ }
368
+ function Vi(e, t) {
369
+ return t.currency ? "currency" : typeof e == "string" && !isNaN(Date.parse(e)) ? "date" : "number";
370
+ }
371
+ function rs(e, t = {}) {
372
+ return (n) => We(n, e, t);
373
+ }
374
+ function Ki({
375
+ number: e,
376
+ decimalPlaces: t = 0,
377
+ useSuffix: n = !1,
378
+ customSuffix: r = "",
379
+ currency: i = "",
380
+ locale: a = "en-US"
381
+ }) {
382
+ if (i) {
383
+ const o = rn(e, {
384
+ currency: i,
385
+ decimalPlaces: t,
386
+ locale: a,
387
+ useSuffix: n && !r
388
+ });
389
+ return n && r ? `${o}${r}` : o;
390
+ }
391
+ return nn(e, {
392
+ decimalPlaces: t,
393
+ useSuffix: n && !r,
394
+ suffix: r,
395
+ locale: a
396
+ });
397
+ }
398
+ var Li = function e(t, n) {
399
+ if (t === n) return !0;
400
+ if (t && n && typeof t == "object" && typeof n == "object") {
401
+ if (t.constructor !== n.constructor) return !1;
402
+ var r, i, a;
403
+ if (Array.isArray(t)) {
404
+ if (r = t.length, r != n.length) return !1;
405
+ for (i = r; i-- !== 0; )
406
+ if (!e(t[i], n[i])) return !1;
407
+ return !0;
408
+ }
409
+ if (t.constructor === RegExp) return t.source === n.source && t.flags === n.flags;
410
+ if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === n.valueOf();
411
+ if (t.toString !== Object.prototype.toString) return t.toString() === n.toString();
412
+ if (a = Object.keys(t), r = a.length, r !== Object.keys(n).length) return !1;
413
+ for (i = r; i-- !== 0; )
414
+ if (!Object.prototype.hasOwnProperty.call(n, a[i])) return !1;
415
+ for (i = r; i-- !== 0; ) {
416
+ var o = a[i];
417
+ if (!(o === "_owner" && t.$$typeof) && !e(t[o], n[o]))
418
+ return !1;
419
+ }
420
+ return !0;
421
+ }
422
+ return t !== t && n !== n;
423
+ };
424
+ const me = /* @__PURE__ */ gi(Li);
425
+ function He(e, t) {
426
+ var n;
427
+ if (t.id)
428
+ return (n = e.sql) != null && n.trim() ? { kind: "column", columnKey: t.id } : { kind: "metric", metricId: t.id };
429
+ }
430
+ function an(e) {
431
+ const t = e.context.preferences;
432
+ if (!t)
433
+ return e.authoredFormat;
434
+ const n = He(e.card, e.metric);
435
+ return N(
436
+ e.authoredFormat,
437
+ t,
438
+ n ? e.context.resolveBoundCurrency(n) : void 0
439
+ );
440
+ }
441
+ function Bi(e) {
442
+ const t = j(e.card)[e.columnKey], n = (t == null ? void 0 : t.type) === "number" ? En(
443
+ { dataType: "number", format: void 0 },
444
+ t
445
+ ) : void 0, r = n == null ? void 0 : n.authoredFormat, i = R(r) ? an({
446
+ card: e.card,
447
+ metric: {
448
+ id: e.columnKey
449
+ },
450
+ context: e.context,
451
+ authoredFormat: r
452
+ }) : void 0;
453
+ return {
454
+ id: e.columnKey,
455
+ name: e.columnKey,
456
+ label: e.columnKey,
457
+ alias: e.columnKey,
458
+ dataType: "number",
459
+ role: "metric",
460
+ format: i
461
+ };
462
+ }
463
+ function is(e) {
464
+ const t = new Set(
465
+ nr(e.records)
466
+ ), n = new Set(
467
+ e.renderedMetricKeys || e.resultKeys
468
+ ), r = j(e.card);
469
+ return e.resultKeys.filter(
470
+ (i) => {
471
+ var a;
472
+ return n.has(i) && (t.has(i) || ((a = r[i]) == null ? void 0 : a.type) === "number");
473
+ }
474
+ );
475
+ }
476
+ function as(e) {
477
+ var a, o;
478
+ const { card: t, context: n } = e;
479
+ if (!(n != null && n.preferences) || !Lt(t.type))
480
+ return t;
481
+ const r = n.preferences, i = (a = t.sql) != null && a.trim() ? e.resultMetricKeys.map(
482
+ (s) => Bi({
483
+ card: t,
484
+ columnKey: s,
485
+ context: n
486
+ })
487
+ ) : (((o = t.config) == null ? void 0 : o.metricColumns) || []).map((s) => {
488
+ const l = Et(t, s), c = l.authoredFormat;
489
+ if (!R(c))
490
+ return s;
491
+ const u = He(t, s), f = u ? n.resolveBoundCurrency(u) : void 0;
492
+ return l.source === "inferred" && !f ? s : {
493
+ ...s,
494
+ format: l.source === "inferred" ? N(
495
+ c,
496
+ r,
497
+ f
498
+ ) : an({
499
+ card: t,
500
+ metric: s,
501
+ context: n,
502
+ authoredFormat: c
503
+ })
504
+ };
505
+ });
506
+ return {
507
+ ...t,
508
+ config: {
509
+ ...t.config || {},
510
+ metricColumns: i
511
+ }
512
+ };
513
+ }
514
+ function be(e) {
515
+ var l;
516
+ const { card: t, context: n, formatOptions: r } = e, i = n == null ? void 0 : n.preferences;
517
+ if (!t || !i || !Lt(t.type))
518
+ return r;
519
+ if (!r) {
520
+ const c = e.metrics.filter(
521
+ (f) => !!f
522
+ ), u = c.some(
523
+ (f) => R(f.format)
524
+ );
525
+ return c.length < 2 || !u ? r : K(
526
+ N({ type: "number" }, i),
527
+ { preserveOmittedProperties: !0 }
528
+ );
529
+ }
530
+ if ((l = t.sql) != null && l.trim()) {
531
+ const c = e.metrics.filter(
532
+ (f) => !!f
533
+ ), u = c.filter(
534
+ (f) => R(f.format)
535
+ );
536
+ if (u.length === 0)
537
+ return r;
538
+ if (u.length !== c.length)
539
+ return K(
540
+ N({ type: "number" }, i),
541
+ { preserveOmittedProperties: !0 }
542
+ );
543
+ }
544
+ const a = de(r, {
545
+ preserveOmittedProperties: !0
546
+ });
547
+ if (!R(a))
548
+ return r;
549
+ const o = e.metrics.flatMap((c) => {
550
+ if (!c)
551
+ return [];
552
+ const u = He(t, c);
553
+ return [
554
+ N(
555
+ a,
556
+ i,
557
+ u ? n.resolveBoundCurrency(u) : void 0
558
+ )
559
+ ];
560
+ });
561
+ if (o.length === 0)
562
+ return K(
563
+ N(a, i),
564
+ { preserveOmittedProperties: !0 }
565
+ );
566
+ const [s] = o;
567
+ if (o.some((c) => !me(c, s))) {
568
+ const c = N(
569
+ {
570
+ ...a,
571
+ type: "number",
572
+ currency: void 0
573
+ },
574
+ i
575
+ );
576
+ return K(c, {
577
+ preserveOmittedProperties: !0
578
+ });
579
+ }
580
+ return K(s, {
581
+ preserveOmittedProperties: !0
582
+ });
583
+ }
584
+ function Ae(e) {
585
+ return e ? Object.entries(e).some(([t, n]) => n == null || n === "" ? !1 : t === "type" ? n !== "auto" : !0) : !1;
586
+ }
587
+ function on(e) {
588
+ if (e)
589
+ return e.alias || e.label || e.name;
590
+ }
591
+ function Re(e, t) {
592
+ var r;
593
+ return (((r = e == null ? void 0 : e.config) == null ? void 0 : r.metricColumns) || []).find((i) => {
594
+ const a = on(i);
595
+ return t.metricId && i.id === t.metricId || t.metricAlias && a === t.metricAlias || t.metricAlias && i.alias === t.metricAlias || t.columnId && a === t.columnId || t.columnId && i.alias === t.columnId || t.columnId && i.label === t.columnId || t.columnId && i.name === t.columnId;
596
+ });
597
+ }
598
+ function ie(e, t) {
599
+ var r, i;
600
+ const n = rr(e, t);
601
+ if (!(n && ((i = (r = e == null ? void 0 : e.config) == null ? void 0 : r.groupByColumns) != null && i.includes(n)) && !ir(n)))
602
+ return n;
603
+ }
604
+ function $i(e) {
605
+ return !!e && !(e != null && e.format) && Qt(e == null ? void 0 : e.dataType) === "number";
606
+ }
607
+ const qi = {
608
+ style: "decimal"
609
+ };
610
+ function sn(e) {
611
+ if (!e)
612
+ return;
613
+ const t = Ge();
614
+ return {
615
+ ...t,
616
+ ...e,
617
+ inheritMetricFormat: e.numberFormat ? e.inheritMetricFormat : e.inheritMetricFormat ?? t.inheritMetricFormat,
618
+ numberFormat: {
619
+ ...qi,
620
+ ...e.numberFormat
621
+ },
622
+ dateFormat: {
623
+ ...t.dateFormat,
624
+ ...e.dateFormat
625
+ },
626
+ linkFormat: {
627
+ ...t.linkFormat,
628
+ ...e.linkFormat
629
+ }
630
+ };
631
+ }
632
+ function os(e) {
633
+ return Object.fromEntries(
634
+ Object.entries(e || {}).map(([t, n]) => [
635
+ t,
636
+ sn(n)
637
+ ])
638
+ );
639
+ }
640
+ function oe(e) {
641
+ return !!(e && typeof e == "object" && !Array.isArray(e) && Object.getPrototypeOf(e) === Object.prototype);
642
+ }
643
+ function ln(e, t, n) {
644
+ if (!oe(n))
645
+ return n;
646
+ const r = oe(e) ? e : {}, i = oe(t) ? t : {}, a = {};
647
+ for (const o of Object.keys(n)) {
648
+ const s = n[o];
649
+ if (s === void 0)
650
+ continue;
651
+ const l = Object.prototype.hasOwnProperty.call(
652
+ r,
653
+ o
654
+ ), c = i[o];
655
+ if (l && me(s, c)) {
656
+ a[o] = r[o];
657
+ continue;
658
+ }
659
+ if (!l && me(s, c))
660
+ continue;
661
+ const u = ln(
662
+ r[o],
663
+ c,
664
+ s
665
+ );
666
+ oe(u) && Object.keys(u).length === 0 && !l || (a[o] = u);
667
+ }
668
+ return a;
669
+ }
670
+ function ss(e) {
671
+ let t = ln(
672
+ e.persisted,
673
+ e.baseline,
674
+ e.next
675
+ );
676
+ if (e.enforceDeclaredSqlTemporalFormat && e.next.type === "date" && !e.next.dateFormat.useRelativeTime && e.next.dateFormat.useCustomFormat) {
677
+ const n = e.next.dateFormat.customFormat;
678
+ if (!(n != null && n.trim()))
679
+ throw new li(
680
+ "invalid_raw_temporal_format",
681
+ "Custom table date formatting requires a non-empty pattern."
682
+ );
683
+ ci({
684
+ dialect: "date_fns",
685
+ pattern: n,
686
+ valueKind: e.rawTemporalValueKind
687
+ }), t = {
688
+ ...t,
689
+ dateFormat: {
690
+ ...t.dateFormat,
691
+ useCustomFormat: !0,
692
+ customFormat: n
693
+ }
694
+ };
695
+ }
696
+ return e.next.type === "number" && !me(e.next.numberFormat, e.baseline.numberFormat) && t.numberFormat ? {
697
+ ...t,
698
+ type: "number",
699
+ inheritMetricFormat: e.next.inheritMetricFormat ?? !1
700
+ } : e.next.type === "number" && e.baseline.inheritMetricFormat === !0 && e.next.inheritMetricFormat === !1 ? {
701
+ ...t,
702
+ type: "number",
703
+ inheritMetricFormat: !1
704
+ } : e.forcePersistDateType && e.next.type === "date" ? {
705
+ ...t,
706
+ type: "date"
707
+ } : t;
708
+ }
709
+ function zi(e, t) {
710
+ const n = e || Ge(), r = !t;
711
+ return {
712
+ ...n,
713
+ type: "number",
714
+ textAlign: n.type === "none" ? "right" : n.textAlign,
715
+ numberFormat: {
716
+ style: "decimal",
717
+ minimumFractionDigits: r ? n.numberFormat.minimumFractionDigits : void 0,
718
+ maximumFractionDigits: r ? n.numberFormat.maximumFractionDigits : void 0,
719
+ useGrouping: n.numberFormat.useGrouping
720
+ }
721
+ };
722
+ }
723
+ function we(e) {
724
+ if (e)
725
+ return e.trim().toLowerCase();
726
+ }
727
+ const cn = /\s*(?:\((?:previous|last year|start|target|comparison)\)|δ)\s*$/i;
728
+ function Ui(e) {
729
+ const t = e == null ? void 0 : e.trim();
730
+ return t ? t.replace(cn, "").trim() || t : void 0;
731
+ }
732
+ function ji(e) {
733
+ const t = e == null ? void 0 : e.trim();
734
+ return t ? cn.test(t) : !1;
735
+ }
736
+ function Gi(e, t) {
737
+ return t.metricAlias ? e.find(
738
+ (n) => ti(n) === t.metricAlias
739
+ ) : t.metricId ? e.find((n) => n.id === t.metricId) : void 0;
740
+ }
741
+ function Wi(e) {
742
+ var b;
743
+ const {
744
+ card: t,
745
+ metricId: n,
746
+ metricAlias: r,
747
+ datasetIndex: i,
748
+ datasetLabel: a,
749
+ metricKey: o
750
+ } = e, s = ((b = t == null ? void 0 : t.config) == null ? void 0 : b.metricColumns) || [];
751
+ if (r || n)
752
+ return Gi(s, {
753
+ metricAlias: r,
754
+ metricId: n
755
+ });
756
+ const l = [o, a], c = l.some(
757
+ (p) => ji(p)
758
+ ), u = l.filter(
759
+ (p) => !!p
760
+ );
761
+ for (const p of u) {
762
+ const y = Re(t, {
763
+ columnId: p,
764
+ metricAlias: p
765
+ });
766
+ if (y)
767
+ return y;
768
+ }
769
+ const f = u.map((p) => we(p)).filter((p) => !!p), d = u.map((p) => Ui(p)).filter((p) => !!p);
770
+ for (const p of d) {
771
+ const y = Re(t, {
772
+ columnId: p,
773
+ metricAlias: p
774
+ });
775
+ if (y)
776
+ return y;
777
+ }
778
+ if (s.length === 1)
779
+ return s[0];
780
+ if (!c && typeof i == "number" && i >= 0 && i < s.length)
781
+ return s[i];
782
+ const m = d.map((p) => we(p)).filter((p) => !!p), h = [
783
+ ...f,
784
+ ...m
785
+ ];
786
+ if (h.length !== 0)
787
+ return s.find((p) => {
788
+ const y = [
789
+ p.alias,
790
+ p.label,
791
+ p.name,
792
+ on(p)
793
+ ].map((C) => we(C)).filter((C) => !!C);
794
+ return h.some(
795
+ (C) => y.includes(C)
796
+ );
797
+ });
798
+ }
799
+ function Hi(e) {
800
+ const t = W(e == null ? void 0 : e.format);
801
+ return K(t);
802
+ }
803
+ function St(e, t) {
804
+ if (t)
805
+ return Re(e, {
806
+ columnId: t,
807
+ metricAlias: t
808
+ });
809
+ }
810
+ function wt(e) {
811
+ const t = de(e);
812
+ if (t)
813
+ return JSON.stringify(t);
814
+ }
815
+ function Qi(e, t) {
816
+ const n = wt(e), r = wt(t);
817
+ return !!(n && r && n === r);
818
+ }
819
+ function Yi(e) {
820
+ if (e.length === 0)
821
+ return;
822
+ const t = e.map(
823
+ (o) => Hi(o)
824
+ );
825
+ if (!t.every(
826
+ (o) => Ae(o)
827
+ ))
828
+ return;
829
+ const r = t, [i] = r;
830
+ return r.every(
831
+ (o) => Qi(i, o)
832
+ ) ? i : void 0;
833
+ }
834
+ function ve(e) {
835
+ if (Ae(e.overrideFormatOptions))
836
+ return {
837
+ formatOptions: e.overrideFormatOptions || void 0,
838
+ source: "override"
839
+ };
840
+ const t = Yi(
841
+ e.metrics || []
842
+ );
843
+ return Ae(t) ? {
844
+ formatOptions: t,
845
+ source: "metric"
846
+ } : {
847
+ formatOptions: void 0,
848
+ source: "auto"
849
+ };
850
+ }
851
+ function un(e) {
852
+ var l, c, u;
853
+ const { card: t, chartType: n, axis: r, preferences: i } = e, a = ((l = t == null ? void 0 : t.config) == null ? void 0 : l.metricColumns) || [], o = (i == null ? void 0 : i.datasetOptions) || [];
854
+ if (!a.length)
855
+ return [];
856
+ if (n === "combo")
857
+ return r === "x" ? [] : a.filter((f, d) => {
858
+ const m = o.find((b) => b.idx === d);
859
+ return ((m == null ? void 0 : m.yAxisId) === "y2" ? "y2" : "y") === r;
860
+ });
861
+ if (n === "bubble" || n === "scatter") {
862
+ if (r === "y2")
863
+ return [];
864
+ const f = St(
865
+ t,
866
+ (c = i == null ? void 0 : i.bubbleScatterConfig) == null ? void 0 : c.xMetricKey
867
+ ) || a[0], d = St(
868
+ t,
869
+ (u = i == null ? void 0 : i.bubbleScatterConfig) == null ? void 0 : u.yMetricKey
870
+ ) || a[1] || a[0];
871
+ return r === "x" ? f ? [f] : [] : d ? [d] : [];
872
+ }
873
+ const s = Le(n, i);
874
+ return n === "radar" ? r === "y" ? a : [] : r !== s ? [] : a;
875
+ }
876
+ function Qe(e) {
877
+ const { card: t, chartType: n, axis: r, preferences: i, axisConfig: a } = e, o = un({
878
+ card: t,
879
+ chartType: n,
880
+ axis: r,
881
+ preferences: i
882
+ }), s = ve({
883
+ overrideFormatOptions: ye(a == null ? void 0 : a.valueFormat),
884
+ metrics: o
885
+ });
886
+ return {
887
+ ...s,
888
+ formatOptions: be({
889
+ card: t,
890
+ metrics: o,
891
+ formatOptions: s.formatOptions,
892
+ context: e.numericPresentation
893
+ })
894
+ };
895
+ }
896
+ function Ji(e) {
897
+ const { preferences: t, metric: n } = e, r = t == null ? void 0 : t.tooltipConfig, i = ve({
898
+ overrideFormatOptions: ye(r == null ? void 0 : r.valueFormat),
899
+ metrics: n ? [n] : []
900
+ });
901
+ return {
902
+ ...i,
903
+ formatOptions: be({
904
+ card: e.card,
905
+ metrics: e.metric ? [e.metric] : [],
906
+ formatOptions: i.formatOptions,
907
+ context: e.numericPresentation
908
+ })
909
+ };
910
+ }
911
+ function Ye(e, t, n) {
912
+ return t === Le(n, e) ? ar(n, e) : t === "x" ? e == null ? void 0 : e.xAxisConfig : t === "y2" ? e == null ? void 0 : e.secondaryYAxisConfig : e == null ? void 0 : e.yAxisConfig;
913
+ }
914
+ function Je(e) {
915
+ const { chartType: t, preferences: n } = e;
916
+ return t === "bubble" || t === "scatter" ? "y" : Le(t, n);
917
+ }
918
+ function dn(e) {
919
+ switch (e) {
920
+ case "pie":
921
+ case "doughnut":
922
+ case "polarArea":
923
+ case "funnel":
924
+ case "treemap":
925
+ case "heatmap":
926
+ return !1;
927
+ default:
928
+ return !0;
929
+ }
930
+ }
931
+ function ls(e) {
932
+ const { card: t, chartType: n, preferences: r, metric: i } = e, a = Ji({
933
+ card: t,
934
+ preferences: r,
935
+ metric: i,
936
+ numericPresentation: e.numericPresentation
937
+ });
938
+ if (a.source === "override")
939
+ return a;
940
+ const o = e.axis || Je({ chartType: n, preferences: r }), s = Qe({
941
+ card: t,
942
+ chartType: n,
943
+ axis: o,
944
+ preferences: r,
945
+ axisConfig: Ye(r, o, n),
946
+ numericPresentation: e.numericPresentation
947
+ });
948
+ return s.source === "override" ? s : a;
949
+ }
950
+ function cs(e) {
951
+ const { card: t, chartType: n, preferences: r, dataLabelsConfig: i } = e, a = n || (t == null ? void 0 : t.type), o = Je({
952
+ chartType: a,
953
+ preferences: r
954
+ }), s = un({
955
+ card: t,
956
+ chartType: a,
957
+ axis: o,
958
+ preferences: r
959
+ }), l = ve({
960
+ overrideFormatOptions: ye(i == null ? void 0 : i.valueFormat),
961
+ metrics: s
962
+ }), c = {
963
+ ...l,
964
+ formatOptions: be({
965
+ card: t,
966
+ metrics: s,
967
+ formatOptions: l.formatOptions,
968
+ context: e.numericPresentation
969
+ })
970
+ };
971
+ if (c.source === "override" || !dn(a))
972
+ return c;
973
+ const u = Qe({
974
+ card: t,
975
+ chartType: a,
976
+ axis: o,
977
+ preferences: r,
978
+ axisConfig: Ye(
979
+ r,
980
+ o,
981
+ a
982
+ ),
983
+ numericPresentation: e.numericPresentation
984
+ });
985
+ return u.source === "override" ? u : c;
986
+ }
987
+ function Xi(e) {
988
+ const { preferences: t, dataLabelsConfig: n, metric: r } = e, i = ve({
989
+ overrideFormatOptions: ye(n == null ? void 0 : n.valueFormat),
990
+ metrics: r ? [r] : []
991
+ });
992
+ return {
993
+ ...i,
994
+ formatOptions: be({
995
+ card: e.card,
996
+ metrics: e.metric ? [e.metric] : [],
997
+ formatOptions: i.formatOptions,
998
+ context: e.numericPresentation
999
+ })
1000
+ };
1001
+ }
1002
+ function us(e) {
1003
+ var o, s;
1004
+ const t = Wi({
1005
+ card: e.card,
1006
+ metricId: e.metricId,
1007
+ metricAlias: e.metricAlias,
1008
+ datasetIndex: e.datasetIndex,
1009
+ datasetLabel: e.datasetLabel,
1010
+ metricKey: e.metricKey
1011
+ }), n = Xi({
1012
+ card: e.card,
1013
+ preferences: e.preferences,
1014
+ dataLabelsConfig: e.dataLabelsConfig,
1015
+ metric: t,
1016
+ numericPresentation: e.numericPresentation
1017
+ });
1018
+ if (n.source === "override")
1019
+ return n;
1020
+ const r = (o = e.card) == null ? void 0 : o.type;
1021
+ if (!dn(r))
1022
+ return n;
1023
+ let i = Je({
1024
+ chartType: r,
1025
+ preferences: e.preferences
1026
+ });
1027
+ if (r === "combo" && typeof e.datasetIndex == "number") {
1028
+ const c = (((s = e.preferences) == null ? void 0 : s.datasetOptions) || []).find(
1029
+ (u) => u.idx === e.datasetIndex
1030
+ );
1031
+ i = (c == null ? void 0 : c.yAxisId) === "y2" ? "y2" : "y";
1032
+ }
1033
+ const a = Qe({
1034
+ card: e.card,
1035
+ chartType: r,
1036
+ axis: i,
1037
+ preferences: e.preferences,
1038
+ axisConfig: Ye(
1039
+ e.preferences,
1040
+ i,
1041
+ r
1042
+ ),
1043
+ numericPresentation: e.numericPresentation
1044
+ });
1045
+ return a.source === "override" ? a : n;
1046
+ }
1047
+ function ds(e) {
1048
+ return (e == null ? void 0 : e.rawValue) === !0;
1049
+ }
1050
+ function Zi(e) {
1051
+ const t = e == null ? void 0 : e.numberFormat;
1052
+ if (!t)
1053
+ return;
1054
+ if (t.style === "duration")
1055
+ return K(Ke(t), {
1056
+ preserveOmittedProperties: !0
1057
+ });
1058
+ const n = t.style === "currency" ? "currency" : t.style === "percent" ? "percent" : t.style === "scientific" ? "scientific" : "number", r = t.minimumFractionDigits, i = t.maximumFractionDigits;
1059
+ return {
1060
+ type: n,
1061
+ currency: n === "currency" ? t.currency : void 0,
1062
+ locale: t.locale,
1063
+ decimalPlaces: r === i ? i : void 0,
1064
+ minimumFractionDigits: r,
1065
+ maximumFractionDigits: i,
1066
+ useGrouping: t.useGrouping,
1067
+ percentValueMode: n === "percent" ? t.percentValueMode : void 0,
1068
+ multiplyBy: t.scale,
1069
+ useSuffix: t.compact,
1070
+ negativeInParentheses: t.negativeStyle === "parentheses",
1071
+ prefix: t.prefix,
1072
+ suffix: t.suffix
1073
+ };
1074
+ }
1075
+ function ea(e, t, n = !1) {
1076
+ const r = n ? { preserveOmittedProperties: !0 } : void 0, i = W(e == null ? void 0 : e.format, r), a = Zt(
1077
+ i,
1078
+ r
1079
+ );
1080
+ if (!a)
1081
+ return;
1082
+ const o = t || Ge(), s = n ? void 0 : o.numberFormat, l = o.type && o.type !== "none";
1083
+ return {
1084
+ ...o,
1085
+ type: l ? o.type : "number",
1086
+ // A column's own format (an override) shows as its own, not the measure's
1087
+ // (column formats CF-D20, ledger P5-42).
1088
+ inheritMetricFormat: (e == null ? void 0 : e.formatOrigin) === "override" ? !1 : o.inheritMetricFormat ?? !0,
1089
+ textAlign: l ? o.textAlign : "right",
1090
+ numberFormat: {
1091
+ ...s,
1092
+ ...a
1093
+ }
1094
+ };
1095
+ }
1096
+ function fn(e) {
1097
+ var D;
1098
+ const {
1099
+ card: t,
1100
+ columnId: n,
1101
+ persistedSettings: r,
1102
+ resolvedSettings: i,
1103
+ fallbackSettings: a,
1104
+ metricId: o,
1105
+ metricAlias: s,
1106
+ fieldId: l,
1107
+ fieldRole: c,
1108
+ columnKeyMap: u,
1109
+ valueFormatPreferences: f,
1110
+ boundCurrency: d,
1111
+ preserveOmittedProperties: m
1112
+ } = e, h = r ?? j(t)[n], b = !((D = t == null ? void 0 : t.sql) != null && D.trim()) || Vn(h), p = b ? f : null, y = b ? d : void 0, C = i ?? sn(h);
1113
+ if (C && C.inheritMetricFormat !== !0)
1114
+ return Tt(
1115
+ C,
1116
+ p,
1117
+ y
1118
+ );
1119
+ const v = ie(t, {
1120
+ columnId: n,
1121
+ metricId: o,
1122
+ metricAlias: s,
1123
+ columnKeyMap: u,
1124
+ fieldId: l,
1125
+ fieldRole: c
1126
+ }), g = ea(
1127
+ v,
1128
+ C || a,
1129
+ m ?? !!f
1130
+ ), I = !g && p && $i(v) ? zi(
1131
+ C || a,
1132
+ y
1133
+ ) : void 0;
1134
+ return Tt(
1135
+ g || I || C || a,
1136
+ p,
1137
+ y
1138
+ );
1139
+ }
1140
+ function Tt(e, t, n) {
1141
+ if (!e || e.type !== "number" || !t)
1142
+ return e;
1143
+ const r = e.numberFormat, i = r ? Ke(r, {
1144
+ preserveOmittedProperties: !0
1145
+ }) : { type: "number" };
1146
+ if (!i || !R(i))
1147
+ return e;
1148
+ const a = N(
1149
+ i,
1150
+ t,
1151
+ n
1152
+ ), o = Zt(a, {
1153
+ preserveOmittedProperties: !0
1154
+ });
1155
+ return o ? {
1156
+ ...e,
1157
+ numberFormat: {
1158
+ ...r,
1159
+ ...o
1160
+ }
1161
+ } : e;
1162
+ }
1163
+ function pe(e) {
1164
+ if (!e.valueFormatPreferences)
1165
+ return;
1166
+ const t = fn(e);
1167
+ if (!t || t.type !== "number")
1168
+ return;
1169
+ const n = Ke(t.numberFormat, {
1170
+ preserveOmittedProperties: !0
1171
+ });
1172
+ if (!(!n || !ui(n)))
1173
+ return n;
1174
+ }
1175
+ function ta(e) {
1176
+ var r, i;
1177
+ if (!e.presentation.preferences)
1178
+ return;
1179
+ const t = ie(e.card, {
1180
+ columnId: e.columnId,
1181
+ metricId: e.metricId,
1182
+ metricAlias: e.metricAlias,
1183
+ columnKeyMap: e.columnKeyMap
1184
+ });
1185
+ if (e.comparisonValueKind === "percent_change" || e.comparisonValueKind === "ratio") {
1186
+ const a = pe({
1187
+ card: e.card,
1188
+ columnId: e.columnId,
1189
+ persistedSettings: e.persistedSettings,
1190
+ resolvedSettings: e.resolvedSettings,
1191
+ fallbackSettings: e.fallbackSettings,
1192
+ metricId: e.metricId,
1193
+ columnKeyMap: e.columnKeyMap,
1194
+ metricAlias: e.metricAlias ?? (t == null ? void 0 : t.alias),
1195
+ valueFormatPreferences: e.presentation.preferences
1196
+ }), o = or(e.comparisonPrecision) ?? (R(a) ? a.maximumFractionDigits : void 0) ?? (e.comparisonValueKind === "percent_change" ? 1 : 2);
1197
+ return e.comparisonValueKind === "percent_change" ? {
1198
+ type: "percent",
1199
+ locale: e.presentation.preferences.locale,
1200
+ percentValueMode: "fraction",
1201
+ minimumFractionDigits: o,
1202
+ maximumFractionDigits: o
1203
+ } : {
1204
+ type: "number",
1205
+ locale: e.presentation.preferences.locale,
1206
+ minimumFractionDigits: o,
1207
+ maximumFractionDigits: o,
1208
+ suffix: "×"
1209
+ };
1210
+ }
1211
+ const n = Kn({
1212
+ card: e.card,
1213
+ columnKey: e.columnId,
1214
+ metricId: e.metricId ?? (t && !((i = (r = e.card.config) == null ? void 0 : r.groupByColumns) != null && i.includes(t)) ? t.id : void 0)
1215
+ });
1216
+ return pe({
1217
+ card: e.card,
1218
+ columnId: e.columnId,
1219
+ persistedSettings: e.persistedSettings,
1220
+ resolvedSettings: e.resolvedSettings,
1221
+ fallbackSettings: e.fallbackSettings,
1222
+ metricId: e.metricId,
1223
+ columnKeyMap: e.columnKeyMap,
1224
+ metricAlias: e.metricAlias ?? (t == null ? void 0 : t.alias),
1225
+ valueFormatPreferences: e.presentation.preferences,
1226
+ boundCurrency: n ? e.presentation.resolveBoundCurrency(n) : void 0
1227
+ });
1228
+ }
1229
+ function na(e) {
1230
+ var s, l, c, u, f;
1231
+ if (e.card.type === "matrixTable" && e.target.kind === "matrix_measure") {
1232
+ const d = e.target, m = Ln(e.card, e.matrixCatalog).find(
1233
+ (b) => b.measureId === d.measureId
1234
+ ), h = m == null ? void 0 : m.canonical;
1235
+ return h && (h.type === "number" || h.type === "currency") ? N(
1236
+ h,
1237
+ e.valueFormatPreferences,
1238
+ e.boundCurrency
1239
+ ) : void 0;
1240
+ }
1241
+ if (e.target.kind === "matrix_measure")
1242
+ return;
1243
+ if (e.card.type === "kpi") {
1244
+ const d = e.target.kind === "metric" ? e.target.metricId : void 0;
1245
+ if (d && !((l = (s = e.card.config) == null ? void 0 : s.metricColumns) != null && l.some(
1246
+ (b) => b.id === d
1247
+ )))
1248
+ return;
1249
+ const m = Bn(e.card, {
1250
+ ...d ? { column: { kind: "field", fieldId: d } } : {},
1251
+ resultColumnKey: e.target.kind === "column" ? e.target.columnKey : void 0
1252
+ }), h = m.authoredFormat;
1253
+ return m.currencyBindable && h && R(h) ? N(
1254
+ h,
1255
+ e.valueFormatPreferences,
1256
+ e.boundCurrency
1257
+ ) : void 0;
1258
+ }
1259
+ if (!((c = e.card.sql) != null && c.trim()) && !sr(e.card.type) && e.target.kind === "metric") {
1260
+ const d = e.target.metricId, m = (f = (u = e.card.config) == null ? void 0 : u.metricColumns) == null ? void 0 : f.find(
1261
+ (p) => p.id === d
1262
+ );
1263
+ if (!m)
1264
+ return;
1265
+ const h = Et(
1266
+ e.card,
1267
+ m
1268
+ ), b = h.authoredFormat;
1269
+ return h.currencyBindable && b && R(b) ? N(
1270
+ b,
1271
+ e.valueFormatPreferences,
1272
+ e.boundCurrency
1273
+ ) : void 0;
1274
+ }
1275
+ const n = j(e.card), r = e.target.kind === "metric" ? e.target.metricId : void 0, i = e.target.kind === "column" ? [e.target.columnKey] : [
1276
+ ...e.resultColumnKeys || [],
1277
+ ...Object.keys(n),
1278
+ e.target.metricId
1279
+ ], a = e.target.kind === "column" ? e.target.columnKey : i.find(
1280
+ (d) => {
1281
+ var m;
1282
+ return ((m = ie(e.card, {
1283
+ columnId: d
1284
+ })) == null ? void 0 : m.id) === r;
1285
+ }
1286
+ ) || r, o = pe({
1287
+ card: e.card,
1288
+ columnId: a,
1289
+ metricId: r,
1290
+ persistedSettings: n[a],
1291
+ valueFormatPreferences: e.valueFormatPreferences,
1292
+ boundCurrency: e.boundCurrency
1293
+ });
1294
+ return R(o) ? o : void 0;
1295
+ }
1296
+ function fs(e) {
1297
+ var n, r;
1298
+ const t = e.persistedSettings ?? j(e.card)[e.columnId];
1299
+ if (!t && !e.resolvedSettings || (t == null ? void 0 : t.inheritMetricFormat) === !0 || ((n = e.resolvedSettings) == null ? void 0 : n.inheritMetricFormat) === !0) {
1300
+ const i = W(
1301
+ (r = ie(e.card, {
1302
+ columnId: e.columnId,
1303
+ metricId: e.metricId,
1304
+ metricAlias: e.metricAlias,
1305
+ columnKeyMap: e.columnKeyMap
1306
+ })) == null ? void 0 : r.format,
1307
+ { preserveOmittedProperties: !0 }
1308
+ );
1309
+ if ((i == null ? void 0 : i.type) === "date" || (i == null ? void 0 : i.type) === "duration")
1310
+ return K(i, {
1311
+ preserveOmittedProperties: !0
1312
+ });
1313
+ }
1314
+ return Zi(
1315
+ fn({
1316
+ ...e,
1317
+ persistedSettings: t
1318
+ })
1319
+ );
1320
+ }
1321
+ function ms(e) {
1322
+ const { value: t, formatOptions: n, preferences: r } = e;
1323
+ return n != null && n.type && n.type !== "auto" ? We(t, n.type, n) : Ki({
1324
+ number: t,
1325
+ decimalPlaces: 0,
1326
+ useSuffix: !1,
1327
+ customSuffix: "",
1328
+ locale: "en-US",
1329
+ currency: ""
1330
+ });
1331
+ }
1332
+ function ra(e) {
1333
+ return lr({
1334
+ ...e,
1335
+ activation: Be({
1336
+ card: e.card,
1337
+ cardConfig: e.cardConfig
1338
+ })
1339
+ });
1340
+ }
1341
+ function ps(e) {
1342
+ return cr({
1343
+ activation: Be({
1344
+ card: e.card,
1345
+ cardConfig: e.cardConfig
1346
+ }),
1347
+ result: e.result,
1348
+ expectedResultOwner: e.expectedResultOwner
1349
+ });
1350
+ }
1351
+ function ia(e) {
1352
+ const t = Vt(e.card, e.effectiveCardConfig), n = Mi({
1353
+ card: t,
1354
+ records: e.rows,
1355
+ keys: e.rows.length === 0 ? e.resultKeys : void 0,
1356
+ columnKeyMap: e.result.columnKeyMap,
1357
+ resultColumns: e.result.resultColumns,
1358
+ comparisonMetadata: e.result.comparisonMetadata,
1359
+ viewerTable: e.file.viewerTable
1360
+ });
1361
+ return e.rows.length === 0 && !e.resultKeys || n.visibleKeys.length === 0 ? null : {
1362
+ view: n,
1363
+ formatOptions: {
1364
+ useFormattedValues: e.file.useFormattedValues,
1365
+ timezone: e.reportContext.calendar.tz,
1366
+ delimiter: e.file.delimiter,
1367
+ csvEncoding: e.file.csvEncoding,
1368
+ includeHeaders: e.file.includeHeaders,
1369
+ columnSettings: j(e.card),
1370
+ visibleColumns: [...n.visibleKeys],
1371
+ columnLabels: Object.fromEntries(n.visibleKeys.map((r) => [r, n.labels[r] ?? r]))
1372
+ }
1373
+ };
1374
+ }
1375
+ function aa(e) {
1376
+ var n;
1377
+ const t = (n = e.preferences) == null ? void 0 : n.comparisonPresentation;
1378
+ return {
1379
+ ...ni,
1380
+ ...t,
1381
+ ...t != null && t.conditionalLabels ? { conditionalLabels: { ...t.conditionalLabels } } : {},
1382
+ ...t != null && t.colors ? { colors: { ...t.colors } } : {}
1383
+ };
1384
+ }
1385
+ function oa(e) {
1386
+ const t = Vt(e.card, e.effectiveCardConfig), { cardId: n, ...r } = e.requestPayloadBase, i = e.formatOptions.visibleColumns ?? [], a = [
1387
+ ...i,
1388
+ ...Object.keys(e.formatOptions.columnSettings ?? {})
1389
+ ], o = $n(
1390
+ e.card,
1391
+ i,
1392
+ e.effectiveCardConfig
1393
+ ), s = qn(
1394
+ e.card,
1395
+ e.effectiveCardConfig,
1396
+ o
1397
+ ), l = zn(
1398
+ t,
1399
+ a
1400
+ ), c = new Set(
1401
+ l.eligibleTargets.map(Ie)
1402
+ ), u = (v) => c.has(Ie(v)) ? jn({
1403
+ bindings: r.controlBindings,
1404
+ controls: [
1405
+ ...r.controlDefinitions ?? [],
1406
+ ...r.cardControlDefinitions ?? []
1407
+ ],
1408
+ values: r.controlValues,
1409
+ target: v,
1410
+ knownTargets: l.knownTargets,
1411
+ eligibleTargets: l.eligibleTargets
1412
+ }).currency : void 0, f = Un({
1413
+ card: e.card,
1414
+ comparisonMetadata: e.comparisonMetadata,
1415
+ columnKeyMap: e.columnKeyMap
1416
+ }), d = Be({
1417
+ card: e.card,
1418
+ cardConfig: e.effectiveCardConfig
1419
+ }), m = ra({
1420
+ card: e.card,
1421
+ cardConfig: e.effectiveCardConfig,
1422
+ columns: e.resultColumns,
1423
+ columnKeyMap: e.columnKeyMap,
1424
+ resultRowCount: e.totalRows,
1425
+ valueFormatPreferences: e.reportContext.valueFormat
1426
+ }), h = (d == null ? void 0 : d.fields) ?? [], b = new Map(
1427
+ h.map((v) => [
1428
+ `${v.role}:${v.id}`,
1429
+ v
1430
+ ])
1431
+ ), p = /* @__PURE__ */ new Map();
1432
+ if (e.card.type === "detailTable" && r.resultOwner === "config") {
1433
+ const v = e.resultColumns || [];
1434
+ if (v.filter(
1435
+ (g) => g.rawTemporal
1436
+ ).length > 0) {
1437
+ if (!e.columnKeyMap)
1438
+ throw new Error(
1439
+ "Canonical raw temporal export requires an authoritative columnKeyMap."
1440
+ );
1441
+ const g = ur({
1442
+ cardType: e.card.type,
1443
+ resultOwner: r.resultOwner,
1444
+ effectiveCardConfig: e.effectiveCardConfig,
1445
+ result: {
1446
+ records: [],
1447
+ columns: v,
1448
+ columnKeyMap: e.columnKeyMap
1449
+ },
1450
+ preferences: e.reportContext.valueFormat,
1451
+ calendar: e.reportContext.calendar
1452
+ });
1453
+ if (g.kind === "invalid") throw g.error;
1454
+ if (g.kind === "loaded_empty" || g.kind === "loaded_valid")
1455
+ for (const [I, M] of g.presentation.byColumnKey)
1456
+ p.set(I, M.format);
1457
+ }
1458
+ } else if (r.resultOwner === "freeform" && r.sql.trim() && !r.python.trim())
1459
+ for (const [v, F] of Object.entries(
1460
+ j(e.card)
1461
+ )) {
1462
+ if (F.type !== "date") continue;
1463
+ const g = dr(F.dateFormat);
1464
+ g && p.set(
1465
+ v,
1466
+ di({
1467
+ format: g,
1468
+ preferences: e.reportContext.valueFormat,
1469
+ calendar: e.reportContext.calendar
1470
+ })
1471
+ );
1472
+ }
1473
+ const y = [
1474
+ ...new Set(a)
1475
+ ].flatMap((v) => {
1476
+ var z, U, V;
1477
+ if (m.byColumnKey.has(v) || p.has(v))
1478
+ return [];
1479
+ const F = f.columnPresentationOwners.get(v), g = {
1480
+ ...fr(t, v, {
1481
+ columnKeyMap: e.columnKeyMap,
1482
+ resultColumns: e.resultColumns
1483
+ }),
1484
+ ...F ? { metricId: F.metricId, metricAlias: F.metricAlias } : {}
1485
+ }, I = (z = t.sql) != null && z.trim() ? void 0 : ie(t, g), M = I ? { kind: "metric", metricId: I.id } : { kind: "column", columnKey: v }, D = c.has(
1486
+ Ie(M)
1487
+ ), P = u(M), q = j(t)[v], H = {
1488
+ dashboardId: e.dashboardId,
1489
+ cardId: t.id
1490
+ }, E = { kind: "column", columnKey: v }, O = I && (!q || q.inheritMetricFormat === !0) ? W(I.format, {
1491
+ preserveOmittedProperties: !0
1492
+ }) : void 0;
1493
+ if ((O == null ? void 0 : O.type) === "date")
1494
+ return [
1495
+ {
1496
+ scope: H,
1497
+ target: E,
1498
+ format: {
1499
+ type: "date",
1500
+ locale: O.locale ?? e.reportContext.valueFormat.locale,
1501
+ ...O.pattern ? { pattern: O.pattern } : {},
1502
+ ...O.timezone ? { timezone: O.timezone } : {},
1503
+ ...O.sourceTimezone ? { sourceTimezone: O.sourceTimezone } : {}
1504
+ }
1505
+ }
1506
+ ];
1507
+ const k = (F ? ta({
1508
+ card: t,
1509
+ columnId: v,
1510
+ columnKeyMap: e.columnKeyMap,
1511
+ persistedSettings: q,
1512
+ metricId: F.metricId,
1513
+ metricAlias: F.metricAlias,
1514
+ comparisonValueKind: F.kind,
1515
+ comparisonPrecision: (V = (U = t.preferences) == null ? void 0 : U.comparisonPresentation) == null ? void 0 : V.precision,
1516
+ presentation: {
1517
+ preferences: e.reportContext.valueFormat,
1518
+ resolveBoundCurrency: u
1519
+ }
1520
+ }) : void 0) ?? (D ? na({
1521
+ card: t,
1522
+ target: M,
1523
+ resultColumnKeys: a,
1524
+ valueFormatPreferences: e.reportContext.valueFormat,
1525
+ boundCurrency: P
1526
+ }) : void 0) ?? pe({
1527
+ card: t,
1528
+ ...g,
1529
+ persistedSettings: q,
1530
+ valueFormatPreferences: e.reportContext.valueFormat
1531
+ }), X = (k == null ? void 0 : k.type) === "duration" ? k : k ? N(
1532
+ k,
1533
+ e.reportContext.valueFormat,
1534
+ P
1535
+ ) : N(
1536
+ {
1537
+ type: "number",
1538
+ minimumFractionDigits: 0,
1539
+ maximumFractionDigits: 3
1540
+ },
1541
+ e.reportContext.valueFormat
1542
+ );
1543
+ return [
1544
+ X.type === "duration" ? { scope: H, target: E, format: X } : { scope: H, target: E, format: X }
1545
+ ];
1546
+ });
1547
+ y.push(
1548
+ ...[...m.byColumnKey.values()].map((v) => {
1549
+ const F = b.get(
1550
+ `${v.role ?? "groupby"}:${v.fieldId}`
1551
+ );
1552
+ if (!F)
1553
+ throw new Error(
1554
+ `Unable to resolve temporal export field "${v.fieldId}".`
1555
+ );
1556
+ return {
1557
+ scope: {
1558
+ dashboardId: e.dashboardId,
1559
+ cardId: e.card.id
1560
+ },
1561
+ target: { kind: "column", columnKey: v.columnKey },
1562
+ format: mr(
1563
+ F,
1564
+ {
1565
+ dateStyle: e.reportContext.valueFormat.dateStyle,
1566
+ dateTime: { ...e.reportContext.valueFormat.dateTime }
1567
+ },
1568
+ e.reportContext.valueFormat.locale
1569
+ )
1570
+ };
1571
+ })
1572
+ ), y.push(
1573
+ ...[...p].map(([v, F]) => ({
1574
+ scope: { dashboardId: e.dashboardId, cardId: e.card.id },
1575
+ target: { kind: "column", columnKey: v },
1576
+ format: F
1577
+ }))
1578
+ );
1579
+ const C = fi({
1580
+ reportContext: e.reportContext,
1581
+ resolvedFormats: y
1582
+ });
1583
+ return {
1584
+ formatOptions: {
1585
+ ...e.formatOptions,
1586
+ ...o ? { tableTotalsLabelColumnKey: o } : {},
1587
+ comparisonPresentation: aa(e.card),
1588
+ presentationExecutionSnapshot: C
1589
+ },
1590
+ ...s ? { tableTotalsRequest: s } : {}
1591
+ };
1592
+ }
1593
+ function sa(e) {
1594
+ const t = Wn(
1595
+ e.card,
1596
+ e.requestPayloadBase
1597
+ ), { cardId: n, ...r } = t.requestPayloadBase, i = oa(e);
1598
+ return {
1599
+ type: "card",
1600
+ dashboardId: e.dashboardId,
1601
+ cardId: e.card.id,
1602
+ title: e.title,
1603
+ connection_id: t.connectionId,
1604
+ ...r,
1605
+ ...i.tableTotalsRequest ? { tableTotalsRequest: i.tableTotalsRequest } : {},
1606
+ totalRows: e.totalRows,
1607
+ format: e.format,
1608
+ formatOptions: i.formatOptions
1609
+ };
1610
+ }
1611
+ function hs(e) {
1612
+ const { card: t, result: n } = e;
1613
+ if (t.type !== "table" && t.type !== "detailTable")
1614
+ return { status: "refused", reason: "not_a_table" };
1615
+ const r = n.modelFormats ? mi(e.effectiveCardConfig ?? t.config, n) : e.effectiveCardConfig;
1616
+ if (Gn({ card: t, comparisonMetadata: n.comparisonMetadata }))
1617
+ return { status: "refused", reason: "comparison_metadata_missing" };
1618
+ const i = ia({
1619
+ card: t,
1620
+ effectiveCardConfig: r,
1621
+ rows: e.rows,
1622
+ resultKeys: n.resultColumns.map((a) => a.key),
1623
+ result: n,
1624
+ reportContext: e.reportContext,
1625
+ file: e.file
1626
+ });
1627
+ return i ? {
1628
+ status: "ready",
1629
+ request: sa({
1630
+ card: t,
1631
+ dashboardId: e.dashboardId,
1632
+ title: e.title,
1633
+ reportContext: e.reportContext,
1634
+ totalRows: n.totalRows,
1635
+ format: e.file.format,
1636
+ formatOptions: i.formatOptions,
1637
+ comparisonMetadata: n.comparisonMetadata,
1638
+ requestPayloadBase: e.query,
1639
+ resultColumns: [...n.resultColumns],
1640
+ columnKeyMap: n.columnKeyMap,
1641
+ effectiveCardConfig: r
1642
+ })
1643
+ } : { status: "refused", reason: "columns_unresolved" };
1644
+ }
1645
+ function la(e, t, n) {
1646
+ if (Qr(
1647
+ Yr(t),
1648
+ e.aggregateOrigin
1649
+ ))
1650
+ return { aggregate: void 0, aggregateOrigin: void 0 };
1651
+ const r = n === "selection" && e.role === "metric" ? t.aggregate : void 0;
1652
+ return {
1653
+ aggregate: e.aggregate ?? r,
1654
+ aggregateOrigin: e.aggregate ? e.aggregateOrigin : r ? t.aggregateOrigin : void 0
1655
+ };
1656
+ }
1657
+ function ca(e, t, n) {
1658
+ var r, i, a, o, s, l;
1659
+ if (n === "domain")
1660
+ return {
1661
+ filters: (r = t.parameters) == null ? void 0 : r.filters,
1662
+ windowTransform: (i = e.parameters) == null ? void 0 : i.windowTransform
1663
+ };
1664
+ if (!(!e.parameters && !t.parameters))
1665
+ return {
1666
+ filters: ((a = e.parameters) == null ? void 0 : a.filters) ?? ((o = t.parameters) == null ? void 0 : o.filters),
1667
+ windowTransform: ((s = e.parameters) == null ? void 0 : s.windowTransform) ?? ((l = t.parameters) == null ? void 0 : l.windowTransform)
1668
+ };
1669
+ }
1670
+ function gs(e, t, n) {
1671
+ const r = e;
1672
+ return {
1673
+ id: e.id,
1674
+ role: e.role,
1675
+ // Result-column names belong to the selection's consumer (for example,
1676
+ // range bounds). They do not identify or redefine the catalog calculation.
1677
+ ...n === "selection" && e.alias ? { alias: e.alias } : {},
1678
+ granularity: e.granularity ?? t.granularity,
1679
+ ...la(e, t, n),
1680
+ ...e.role === "metric" ? {
1681
+ aliasTemplate: r.aliasTemplate,
1682
+ valueAliases: r.valueAliases,
1683
+ comparison: r.comparison,
1684
+ comparisonPolarity: r.comparisonPolarity,
1685
+ parameters: ca(
1686
+ r,
1687
+ t,
1688
+ "domain"
1689
+ )
1690
+ } : {},
1691
+ ...ua(e)
1692
+ };
1693
+ }
1694
+ function ua(e) {
1695
+ const t = {
1696
+ ...e.labelOrigin === "override" ? { label: e.label, labelOrigin: e.labelOrigin } : {},
1697
+ ...e.formatOrigin === "override" ? { format: e.format, formatOrigin: e.formatOrigin } : {}
1698
+ };
1699
+ switch (e.role) {
1700
+ case "pivotby":
1701
+ return {
1702
+ ...t,
1703
+ memberOrder: e.memberOrder
1704
+ };
1705
+ case "sortby":
1706
+ return {
1707
+ ...t,
1708
+ direction: e.direction
1709
+ };
1710
+ default:
1711
+ return t;
1712
+ }
1713
+ }
1714
+ const da = "table";
1715
+ function ys({ preferences: e, ...t }) {
1716
+ return {
1717
+ ...t,
1718
+ type: da,
1719
+ preferences: e ?? { onClickFilter: [{ columnIndex: 0, expression: "" }] },
1720
+ sql: "",
1721
+ data: []
1722
+ };
1723
+ }
1724
+ function bs(e) {
1725
+ return {
1726
+ id: e.id,
1727
+ title: e.title,
1728
+ ...e.description ? { description: e.description } : {},
1729
+ type: "text",
1730
+ preferences: { textVisualOptions: { richContent: e.richContent } },
1731
+ data: []
1732
+ };
1733
+ }
1734
+ function fa(e, t) {
1735
+ const n = e.sheets ?? [], r = n.findIndex((o) => o.id === t.sheetId), i = n[r];
1736
+ if (!i)
1737
+ throw new S("sheet_not_found", `No sheet ${t.sheetId} on this dashboard.`);
1738
+ if ($e(i))
1739
+ throw new S(
1740
+ "sheet_not_a_grid",
1741
+ "This sheet is a document: it has no grid to arrange.",
1742
+ "Arrange a grid sheet; Document sheets are laid out in the editor."
1743
+ );
1744
+ const a = Q(i, { kind: "arrange", keepOrder: t.keepOrder === !0 });
1745
+ return {
1746
+ dashboard: { ...e, sheets: n.map((o, s) => s === r ? a : o) },
1747
+ clauses: [_.arranged(i.title || "the dashboard", t.keepOrder === !0, !(i.frames ?? []).length)]
1748
+ };
1749
+ }
1750
+ function ma(e) {
1751
+ return !!(e && Object.prototype.hasOwnProperty.call(e, "calculatedFields"));
1752
+ }
1753
+ function Y(...e) {
1754
+ return pr(e.flatMap((t) => t || []));
1755
+ }
1756
+ function te(e, t) {
1757
+ return {
1758
+ ...e,
1759
+ fieldScope: t
1760
+ };
1761
+ }
1762
+ function Xe(e) {
1763
+ return ((e == null ? void 0 : e.calculatedFields) || []).filter((t) => t.fieldScope === "sheet").map((t) => te(t, "sheet"));
1764
+ }
1765
+ function mn(e) {
1766
+ return ((e == null ? void 0 : e.calculatedFields) || []).filter((t) => !t.fieldScope).map((t) => te(t, "sheet"));
1767
+ }
1768
+ function pa(e) {
1769
+ return e ? [
1770
+ ...(e.calculatedFields || []).filter(
1771
+ (t) => t.fieldScope === "dashboard"
1772
+ ),
1773
+ ...(e.frames || []).flatMap((t) => t.calculatedFields || [])
1774
+ ].map((t) => te(t, "dashboard")) : [];
1775
+ }
1776
+ function ha(e) {
1777
+ if (e !== void 0)
1778
+ return Y(
1779
+ e.map((t) => te(t, "dashboard"))
1780
+ );
1781
+ }
1782
+ function vs(e) {
1783
+ var r;
1784
+ const t = [], n = (e.sheets || []).map((i) => {
1785
+ var a;
1786
+ return t.push(...pa(i)), {
1787
+ ...i,
1788
+ calculatedFields: Y(
1789
+ Xe(i),
1790
+ mn(i)
1791
+ ),
1792
+ frames: (a = i.frames) == null ? void 0 : a.map(
1793
+ (o) => o.calculatedFields === void 0 ? o : { ...o, calculatedFields: void 0 }
1794
+ )
1795
+ };
1796
+ });
1797
+ return {
1798
+ ...e,
1799
+ calculatedFields: ha(
1800
+ Y(
1801
+ (r = e.calculatedFields) == null ? void 0 : r.map(
1802
+ (i) => te(i, "dashboard")
1803
+ ),
1804
+ t
1805
+ )
1806
+ ),
1807
+ sheets: n
1808
+ };
1809
+ }
1810
+ function Dt(e, t) {
1811
+ var i;
1812
+ if (!((i = e == null ? void 0 : e.frames) != null && i.length))
1813
+ return [];
1814
+ const n = t ? e.frames.find((a) => a.id === t) : void 0, r = e.frames.filter(
1815
+ (a) => !t || a.id !== t
1816
+ );
1817
+ return Y(
1818
+ n == null ? void 0 : n.calculatedFields,
1819
+ ...r.map((a) => a.calculatedFields)
1820
+ );
1821
+ }
1822
+ function Fs(e, t) {
1823
+ return e ? Xe(e) : [];
1824
+ }
1825
+ function Cs(e, t) {
1826
+ if (!e)
1827
+ return [];
1828
+ const n = Xe(e), r = mn(e), i = Y(
1829
+ n,
1830
+ r
1831
+ );
1832
+ return ma(e) ? i.length === 0 ? [] : r.length === 0 ? i : Y(
1833
+ i,
1834
+ Dt(e, t)
1835
+ ) : Dt(e, t);
1836
+ }
1837
+ function ga(e) {
1838
+ if (e !== void 0)
1839
+ return Y(
1840
+ e.map((t) => te(t, "sheet"))
1841
+ );
1842
+ }
1843
+ function Is(e) {
1844
+ const { field: t, sheetFields: n = [], dashboardFields: r = [] } = e, i = (s) => s.find(
1845
+ (l) => hr(l, t, {
1846
+ allowComparableFallback: !0
1847
+ })
1848
+ );
1849
+ if (t.fieldScope === "sheet")
1850
+ return { scope: "sheet", matchedField: i(n) };
1851
+ if (t.fieldScope === "dashboard")
1852
+ return { scope: "dashboard", matchedField: i(r) };
1853
+ const a = i(n);
1854
+ if (a)
1855
+ return { scope: "sheet", matchedField: a };
1856
+ const o = i(r);
1857
+ return o ? { scope: "dashboard", matchedField: o } : { scope: "card" };
1858
+ }
1859
+ function ya(e, t) {
1860
+ var C, v, F;
1861
+ const n = (e.sheets ?? []).findIndex((g) => g.id === t.sheetId), r = (C = e.sheets) == null ? void 0 : C[n];
1862
+ if (!(r != null && r.frames))
1863
+ throw new S("sheet_not_found", `No sheet ${t.sheetId} with frames on this dashboard.`);
1864
+ const { frame: i } = t, a = r.frames.findIndex((g) => g.id === i.id);
1865
+ if (a === -1)
1866
+ throw new S("frame_not_found", `No frame ${i.id} on sheet ${t.sheetId}.`);
1867
+ const o = r.frames[a], s = dt(r), l = (g) => g.calculatedFields === void 0 ? g : { ...g, calculatedFields: void 0 }, c = t.rewrittenFrames, u = c && c.length > 0 ? (() => {
1868
+ const g = c.map((I) => I.id === i.id ? i : I);
1869
+ return g.some((I) => I.id === i.id) ? g : [i, ...g];
1870
+ })() : [i], f = new Map(u.map((g) => [g.id, g])), d = Q(r, { kind: "frame_updated", frame: i, resizeForNewKind: t.resizeLayouts });
1871
+ let m = /* @__PURE__ */ new Set();
1872
+ const h = gr.produce(e, (g) => {
1873
+ const I = g.sheets[n];
1874
+ d.layouts !== r.layouts && (I.layouts = ft(d.layouts)), d.customizedBreakpoints !== r.customizedBreakpoints && (I.customizedBreakpoints = d.customizedBreakpoints), t.sheetCalculatedFields !== void 0 && (I.calculatedFields = ga(t.sheetCalculatedFields)), I.frames = I.frames.map((D) => {
1875
+ const P = f.get(D.id);
1876
+ return P ? ft(l(P)) : D.calculatedFields === void 0 ? D : { ...D, calculatedFields: void 0 };
1877
+ });
1878
+ const M = dt(I);
1879
+ m = new Set([...s].filter((D) => !M.has(D))), yr(g, m), t.dashboardCalculatedFields && (g.calculatedFields = t.dashboardCalculatedFields);
1880
+ }), b = h.sheets[n].frames.find((g) => g.id === i.id), p = [
1881
+ ...m.size ? [{ kind: "cards_removed", cardIds: [...m] }] : [],
1882
+ { kind: "frame_committed", sheetId: t.sheetId, before: o, after: b }
1883
+ ], y = ((v = i.cards) == null ? void 0 : v.find((g) => g.id === i.activeCardId)) ?? ((F = i.cards) == null ? void 0 : F[0]);
1884
+ return { dashboard: h, runtimeEffects: p, clauses: [_.committed(y == null ? void 0 : y.title)] };
1885
+ }
1886
+ function ba(e, t) {
1887
+ const n = { ...e }, r = [];
1888
+ return t.title !== void 0 && t.title !== e.title && (n.title = t.title, r.push(_.plain("dashboard", `renames the dashboard to ${T(t.title)}`))), t.description === null && e.description ? (delete n.description, r.push(_.plain("dashboard", "removes the dashboard's description"))) : typeof t.description == "string" && t.description !== e.description && (n.description = t.description, r.push(_.plain("dashboard", "changes the dashboard's description"))), { dashboard: n, clauses: r.length ? r : [_.plain("dashboard", "changes nothing on the dashboard")] };
1889
+ }
1890
+ function va(e, t, n) {
1891
+ const r = e.sheets ?? [], i = r.findIndex((s) => s.id === t), a = r[i];
1892
+ if (!a) throw new S("sheet_not_found", `No sheet ${t} on this dashboard.`);
1893
+ if ($e(a))
1894
+ throw new S("sheet_not_a_grid", `"${a.title}" is a Document sheet.`, "Document sheets are changed in the editor.");
1895
+ const o = n.map((s) => {
1896
+ const l = (a.frames ?? []).find((c) => c.cards.some((u) => u.id === s));
1897
+ if (!l)
1898
+ throw new S("card_not_found", `No card ${s} on ${br(a)}.`, "Read the outline again and use its card ids.");
1899
+ return l.cards.find((c) => c.id === s);
1900
+ });
1901
+ return { sheets: r, sheetIndex: i, sheet: a, cards: o };
1902
+ }
1903
+ const le = (e, t) => (e.frames ?? []).find((n) => n.cards.some((r) => r.id === t));
1904
+ function Ee(e) {
1905
+ const { visualId: t, ...n } = e;
1906
+ return n;
1907
+ }
1908
+ const pn = (e) => e.cards.find((t) => t.id === e.activeCardId) ?? e.cards[0], Te = (e) => _.plain("detached", `makes ${e} local to this report; it no longer follows its library visual`);
1909
+ function Fa(e, t) {
1910
+ var h;
1911
+ const { sheets: n, sheetIndex: r, sheet: i, cards: a } = va(e, t.sheetId, t.cardIds), o = le(i, t.cardIds[0]).id;
1912
+ let s = i;
1913
+ const l = [];
1914
+ for (const b of t.cardIds.slice(1)) {
1915
+ const p = le(s, b);
1916
+ if (p.id === o) continue;
1917
+ const y = Bt(p, b);
1918
+ if (!y.cards.length) {
1919
+ p.visualId && l.push(Te(T(p.cards[0].title))), s = Q(s, { kind: "frame_removed", frameId: p.id });
1920
+ continue;
1921
+ }
1922
+ p.visualId && l.push(Te(`the tile of ${T((h = pn(y)) == null ? void 0 : h.title)}`)), s = Q(s, { kind: "frame_updated", frame: p.visualId ? Ee(y) : y, resizeForNewKind: !0 });
1923
+ }
1924
+ const c = le(s, t.cardIds[0]), u = new Set(t.cardIds), f = {
1925
+ ...c,
1926
+ cards: [...a, ...c.cards.filter((b) => !u.has(b.id))],
1927
+ activeCardId: t.cardIds[0]
1928
+ };
1929
+ c.visualId && l.push(Te("the tabs")), s = Q(s, { kind: "frame_updated", frame: c.visualId ? Ee(f) : f, resizeForNewKind: !0 });
1930
+ const d = a.map((b) => T(b.title)), m = [...new Map(l.map((b) => [b.lead, b])).values()];
1931
+ return {
1932
+ dashboard: { ...e, sheets: n.map((b, p) => p === r ? s : b) },
1933
+ clauses: [_.plain("layout", `puts ${qe(d)} in one spot as tabs, ${d[0]} first`), ...m],
1934
+ detached: m.length > 0
1935
+ };
1936
+ }
1937
+ function Ca(e, t) {
1938
+ var u;
1939
+ const n = e.sheets ?? [], r = n.findIndex((f) => !$e(f) && (f.frames ?? []).some((d) => d.cards.some((m) => m.id === t.cardId)));
1940
+ if (r < 0)
1941
+ throw new S("card_not_found", `No card ${t.cardId} on this dashboard.`, "Read the outline again and use its card ids.");
1942
+ if (n.some((f) => (f.frames ?? []).some((d) => d.id === t.newFrameId)))
1943
+ throw new S("frame_id_taken", `A frame with id ${t.newFrameId} is already on this dashboard.`);
1944
+ const i = n[r], a = le(i, t.cardId), o = a.cards.find((f) => f.id === t.cardId);
1945
+ if (a.cards.length < 2)
1946
+ throw new S("frame_not_found", `${T(o.title)} already has its own spot.`);
1947
+ const s = Bt(a, t.cardId);
1948
+ let l = Q(i, {
1949
+ kind: "frame_updated",
1950
+ frame: a.visualId ? Ee(s) : s,
1951
+ resizeForNewKind: !0
1952
+ });
1953
+ l = Q(l, {
1954
+ kind: "frame_added",
1955
+ frame: { id: t.newFrameId, cards: [o], activeCardId: o.id },
1956
+ placement: { position: { beside: a.id } }
1957
+ });
1958
+ const c = !!a.visualId;
1959
+ return {
1960
+ dashboard: { ...e, sheets: n.map((f, d) => d === r ? l : f) },
1961
+ clauses: [
1962
+ _.plain("layout", `gives ${T(o.title)} its own spot beside ${T((u = pn(s)) == null ? void 0 : u.title)}`),
1963
+ ...c ? [_.plain("detached", "makes both spots local to this report; they no longer follow their library visual")] : []
1964
+ ],
1965
+ detached: c
1966
+ };
1967
+ }
1968
+ const Ia = "MMM D, YYYY [at] h:mm A";
1969
+ function xa() {
1970
+ return {
1971
+ version: 1,
1972
+ page: {
1973
+ size: "letter",
1974
+ orientation: "portrait",
1975
+ margins: {
1976
+ top: 0.5,
1977
+ right: 0.5,
1978
+ bottom: 0.5,
1979
+ left: 0.5,
1980
+ unit: "in"
1981
+ }
1982
+ },
1983
+ runtime: {
1984
+ generatedAtFormat: Ia
1985
+ },
1986
+ inputs: [],
1987
+ sections: []
1988
+ };
1989
+ }
1990
+ function xs() {
1991
+ return {
1992
+ region: "header",
1993
+ enabled: !0,
1994
+ heightPx: 72,
1995
+ layout: { type: "preset", preset: "mvp_header" },
1996
+ blocks: []
1997
+ };
1998
+ }
1999
+ function Ss() {
2000
+ return {
2001
+ region: "footer",
2002
+ enabled: !0,
2003
+ heightPx: 40,
2004
+ layout: { type: "preset", preset: "mvp_footer" },
2005
+ blocks: []
2006
+ };
2007
+ }
2008
+ function Sa(e) {
2009
+ return [{ type: "text", value: e }];
2010
+ }
2011
+ function ws(e, t = []) {
2012
+ return (e == null ? void 0 : e.map((n) => n.type === "text" ? n.value : wa(n.ref, t)).join("")) || "";
2013
+ }
2014
+ function wa(e, t) {
2015
+ if (e.source === "documentMeta")
2016
+ return t.some(
2017
+ (i) => i.variableName === e.key
2018
+ ) ? `{{document.${e.key}}}` : `{{${e.key}}}`;
2019
+ const n = t.find((r) => r.id === e.inputId);
2020
+ return `{{${(n == null ? void 0 : n.variableName) || e.inputId}.${e.export}}}`;
2021
+ }
2022
+ function Ts(e, t) {
2023
+ return e.find(
2024
+ (n) => n.type === "text" && n.role === t
2025
+ );
2026
+ }
2027
+ function Ds(e, t) {
2028
+ return e.find(
2029
+ (n) => n.type === "image" && n.role === t
2030
+ );
2031
+ }
2032
+ function ks(e, t) {
2033
+ const n = {
2034
+ ...t,
2035
+ type: "text",
2036
+ content: typeof t.content == "string" ? Sa(t.content) : t.content
2037
+ };
2038
+ return hn(e, n);
2039
+ }
2040
+ function Ms(e, t) {
2041
+ return hn(e, t);
2042
+ }
2043
+ function hn(e, t) {
2044
+ const n = e.findIndex((r) => r.id === t.id);
2045
+ return n === -1 ? [...e, t] : e.map(
2046
+ (r, i) => i === n ? t : r
2047
+ );
2048
+ }
2049
+ function Ta(e, t) {
2050
+ const n = e.sheets ?? [], { id: r, title: i, kind: a } = t.sheet;
2051
+ if (n.some((s) => s.id === r))
2052
+ throw new S("sheet_id_taken", `A sheet with id ${r} is already on this dashboard.`);
2053
+ const o = a === "document" ? { id: r, title: i, kind: a, document: xa() } : { id: r, title: i };
2054
+ return {
2055
+ dashboard: { ...e, sheets: [...n, o] },
2056
+ created: [{ kind: "sheet", id: r, title: i, ...t.changeIndex !== void 0 ? { changeIndex: t.changeIndex } : {} }],
2057
+ clauses: [_.plain("sheet", `adds the sheet ${T(i)}`)]
2058
+ };
2059
+ }
2060
+ function Da(e, t) {
2061
+ const n = e.sheets ?? [], r = n.findIndex((a) => a.id === t.sheetId);
2062
+ if (r < 0)
2063
+ throw new S("sheet_not_found", `No sheet ${t.sheetId} on this dashboard.`);
2064
+ const i = n[r];
2065
+ return {
2066
+ dashboard: { ...e, sheets: n.map((a, o) => o === r ? { ...a, title: t.title } : a) },
2067
+ clauses: [_.plain("sheet", `renames the sheet ${T(i.title)} to ${T(t.title)}`)]
2068
+ };
2069
+ }
2070
+ function ka(e, t, n) {
2071
+ var a;
2072
+ if (!e || !t || t.customFilterPreferences) return;
2073
+ const r = t.defaultDateFilter;
2074
+ return (t.dateSelectionMode === "day" ? Cr(r) : t.dateSelectionMode === "months" && (Ir(r) || xr(r) && r.unit === "month" && (r.mode === "previous" || r.mode === "this" && !r.toDate && !r.boundary))) && ((a = ee(t, n)) == null ? void 0 : a.valueType) === "date" ? !0 : void 0;
2075
+ }
2076
+ function Os(e) {
2077
+ const t = e.createId ?? Ut, n = t(), r = Hn({
2078
+ field: e.field,
2079
+ dataSource: e.dataSource,
2080
+ connectionId: e.connectionId,
2081
+ connectionType: e.connectionType,
2082
+ filterId: t()
2083
+ });
2084
+ return Ma({
2085
+ filter: e.label ? { ...r, title: e.label } : r,
2086
+ label: e.label || e.field.label || e.field.name,
2087
+ scope: e.scope,
2088
+ existingInputs: e.existingInputs,
2089
+ createId: () => n
2090
+ });
2091
+ }
2092
+ function Ma(e) {
2093
+ const t = e.createId ?? Ut, n = e.label || e.filter.title || e.filter.column || e.filter.id, r = vr(n, [
2094
+ ...e.existingInputs
2095
+ ]), i = {
2096
+ ...$t(e.filter),
2097
+ variableName: r
2098
+ };
2099
+ return {
2100
+ id: t(),
2101
+ kind: "filter",
2102
+ label: n,
2103
+ variableName: r,
2104
+ requiredAtExecution: !1,
2105
+ scope: e.scope,
2106
+ runtimeScope: "shared",
2107
+ presentation: zt(i),
2108
+ filter: i,
2109
+ exports: qt(i)
2110
+ };
2111
+ }
2112
+ function Oa(e, t, n, r = { calendar: null }) {
2113
+ var tt, nt, rt, it, at, ot, st, lt;
2114
+ const i = G(e), a = i.findFilterInput(t), o = (w, x) => ({
2115
+ ok: !1,
2116
+ issues: [
2117
+ {
2118
+ code: "invalidSettings",
2119
+ message: w,
2120
+ ref: t,
2121
+ ...a ? { inputId: a.input.id } : {},
2122
+ ...x ? { contractIssue: x } : {}
2123
+ }
2124
+ ]
2125
+ });
2126
+ if (!a)
2127
+ return {
2128
+ ok: !1,
2129
+ issues: [
2130
+ {
2131
+ code: "inputNotFound",
2132
+ ref: t,
2133
+ message: "This filter no longer exists on the dashboard."
2134
+ }
2135
+ ]
2136
+ };
2137
+ if (a.origin !== "embeddedInput")
2138
+ return o("This filter can not be edited here.");
2139
+ const s = a.input, l = s.filter;
2140
+ if (((tt = n.mapping) == null ? void 0 : tt.kind) === "save") {
2141
+ if (!n.mapping.draft.acceptance.ok)
2142
+ return { ok: !1, issues: n.mapping.draft.acceptance.issues };
2143
+ if (n.mapping.draft.inputId !== s.id)
2144
+ return o("The card mapping was prepared for another filter.");
2145
+ }
2146
+ const c = n.definition ? $t(n.definition) : l;
2147
+ if (c.kind === "global-date" && n.scope && !Na(n.scope))
2148
+ return o("The Global Date filter applies to regular tabs only.");
2149
+ const u = (nt = r.calendar) == null ? void 0 : nt.tz, f = n.definition !== void 0, d = n.forceSelection !== void 0 || f ? ka(
2150
+ n.forceSelection ?? s.forceSelection,
2151
+ c,
2152
+ u
2153
+ ) : s.forceSelection ? !0 : void 0, m = (Array.isArray(e.inputs) ? e.inputs : []).filter((w) => w.id !== s.id), h = n.variableName !== void 0 ? Fr(n.variableName, [
2154
+ ...m,
2155
+ ...i.inputs.filter((w) => w.input.id !== s.id).map((w) => w.input)
2156
+ ]) : s.variableName, b = f && (l.title || l.column) !== (c.title || c.column), p = n.label ?? (b ? c.title || c.column || c.id : void 0), y = f && l.hide !== c.hide, C = f && l.toolbarWidth !== c.toolbarWidth, v = (w) => {
2157
+ var ct, ut;
2158
+ const x = { ...w };
2159
+ if (p !== void 0 && (x.label = p), n.variableName !== void 0 && (x.variableName = h), n.scope && (x.scope = n.scope), y || C) {
2160
+ const Ce = zt(c);
2161
+ x.presentation = { ...w.presentation }, y && (x.presentation.placement = Ce.placement), C && (Ce.widthPx === void 0 ? delete x.presentation.widthPx : x.presentation.widthPx = Ce.widthPx);
2162
+ }
2163
+ return (n.forceSelection !== void 0 || f) && (d ? x.forceSelection = d : delete x.forceSelection), n.requiredAtExecution !== void 0 && (n.requiredAtExecution ? x.requiredAtExecution = !0 : delete x.requiredAtExecution), De(x, "optionSource", n.optionSource), De(x, "optionDependencies", n.optionDependencies), De(x, "optionPopulation", n.optionPopulation), ((ct = n.mapping) == null ? void 0 : ct.kind) === "save" && n.mapping.draft.acceptance.ok ? x.application = n.mapping.draft.acceptance.application : ((ut = n.mapping) == null ? void 0 : ut.kind) === "remove" && delete x.application, x;
2164
+ }, F = n.label !== void 0 && n.label !== s.label && n.label !== c.title ? n.label : void 0, g = f || n.variableName !== void 0 || F !== void 0, I = (w) => ({
2165
+ ...w,
2166
+ ...n.variableName !== void 0 ? { variableName: h } : {},
2167
+ ...F !== void 0 ? { title: F } : {}
2168
+ }), M = Array.isArray(e.inputs) ? [...e.inputs] : [], D = M.findIndex((w) => w.id === s.id), P = M[D];
2169
+ if (D < 0 || (P == null ? void 0 : P.kind) !== "filter" || !P.filter)
2170
+ return o("This filter can not be edited here.");
2171
+ const q = v(
2172
+ g ? {
2173
+ ...P,
2174
+ filter: I(c)
2175
+ } : P
2176
+ );
2177
+ f && (q.exports = qt(c)), M[D] = q;
2178
+ const H = je({
2179
+ inputs: [q],
2180
+ dashboardFilters: []
2181
+ });
2182
+ if (!H.ok)
2183
+ return o(
2184
+ ((rt = H.issues[0]) == null ? void 0 : rt.message) ?? "These settings could not be saved.",
2185
+ H.issues[0]
2186
+ );
2187
+ let E = { ...e, inputs: M };
2188
+ const O = G(E), k = O.findFilterInput({ filterId: c.id });
2189
+ if (!k)
2190
+ return o(
2191
+ ((it = O.issues[0]) == null ? void 0 : it.message) ?? "These settings could not be saved."
2192
+ );
2193
+ const X = n.variableName !== void 0 || n.scope !== void 0 ? _a(E, k.input) : void 0;
2194
+ if (X)
2195
+ return o(
2196
+ `Another filter on the same cards is already named "${X}". Choose another name.`
2197
+ );
2198
+ const z = [], U = {
2199
+ id: k.input.id,
2200
+ runtimeScope: k.input.runtimeScope
2201
+ };
2202
+ let V = {
2203
+ defaultInputValues: E.defaultInputValues,
2204
+ dashboardInputValues: {}
2205
+ };
2206
+ const _n = ((at = n.values) == null ? void 0 : at.target) ?? {}, A = Ra(
2207
+ l,
2208
+ c,
2209
+ {
2210
+ defaultValueChanged: (ot = n.values) == null ? void 0 : ot.defaultChanged,
2211
+ selectionIdentityChanged: (st = n.values) == null ? void 0 : st.selectionIdentityChanged,
2212
+ ...((lt = n.values) == null ? void 0 : lt.defaultComparisonSelection) !== void 0 ? {
2213
+ defaultComparisonChanged: !0,
2214
+ defaultComparisonSelection: n.values.defaultComparisonSelection ?? void 0
2215
+ } : {}
2216
+ },
2217
+ _n,
2218
+ r.calendar ?? void 0
2219
+ );
2220
+ if (A.defaultValueChanged || A.selectionIdentityChanged || A.defaultComparisonChanged) {
2221
+ const w = gn({
2222
+ state: { ...V, dashboardInputValues: {} },
2223
+ input: U,
2224
+ settings: A
2225
+ });
2226
+ V = { ...V, defaultInputValues: w.defaultInputValues }, A.selectionIdentityChanged && z.push({
2227
+ kind: "clear",
2228
+ inputId: U.id,
2229
+ target: A.target
2230
+ }), A.defaultValueChanged && z.push({
2231
+ kind: "resetToDefault",
2232
+ inputId: U.id,
2233
+ target: A.target,
2234
+ ...A.defaultFilterValue ? { filterValue: A.defaultFilterValue } : {}
2235
+ }), A.defaultComparisonChanged && z.push({
2236
+ kind: "setDefaultComparison",
2237
+ inputId: U.id,
2238
+ target: A.target
2239
+ });
2240
+ }
2241
+ if (n.scope && k.input.runtimeScope !== "shared") {
2242
+ const w = Pa(
2243
+ E,
2244
+ s,
2245
+ k.input,
2246
+ V.defaultInputValues
2247
+ );
2248
+ V = {
2249
+ ...V,
2250
+ defaultInputValues: w.defaultInputValues
2251
+ }, z.push(
2252
+ ...w.dropped.map((x) => ({
2253
+ kind: "dropTargetSlot",
2254
+ inputId: U.id,
2255
+ target: x
2256
+ }))
2257
+ );
2258
+ }
2259
+ return E = Aa(E, V), {
2260
+ ok: !0,
2261
+ dashboard: E,
2262
+ inputId: k.input.id,
2263
+ valueEffects: z
2264
+ };
2265
+ }
2266
+ function Ns(e) {
2267
+ let t = mt({
2268
+ dashboard: e.before,
2269
+ runtimeValues: e.dashboardInputValues,
2270
+ calendar: e.calendar
2271
+ });
2272
+ const n = G(e.after), r = (i) => {
2273
+ var a;
2274
+ return (a = n.findFilterInput({ inputId: i })) == null ? void 0 : a.input;
2275
+ };
2276
+ for (const i of e.effects)
2277
+ switch (i.kind) {
2278
+ case "resetToDefault":
2279
+ case "clear":
2280
+ case "setDefaultComparison": {
2281
+ const a = r(i.inputId);
2282
+ if (!a) break;
2283
+ t = gn({
2284
+ state: { dashboardInputValues: t },
2285
+ input: a,
2286
+ settings: {
2287
+ target: i.target,
2288
+ defaultValueChanged: i.kind === "resetToDefault",
2289
+ defaultFilterValue: i.kind === "resetToDefault" ? i.filterValue : void 0,
2290
+ selectionIdentityChanged: i.kind === "clear",
2291
+ defaultComparisonChanged: i.kind === "setDefaultComparison"
2292
+ }
2293
+ }).dashboardInputValues;
2294
+ break;
2295
+ }
2296
+ case "dropTargetSlot": {
2297
+ const a = r(i.inputId);
2298
+ if (!a) break;
2299
+ t = ze(
2300
+ t,
2301
+ a,
2302
+ i.target
2303
+ );
2304
+ break;
2305
+ }
2306
+ }
2307
+ return mt({
2308
+ dashboard: e.after,
2309
+ runtimeValues: t,
2310
+ calendar: e.calendar
2311
+ });
2312
+ }
2313
+ function Na(e) {
2314
+ var t;
2315
+ return e.kind !== "documentSections" && (e.kind !== "allSheets" || ((t = e.sheetKinds) == null ? void 0 : t.length) === 1 && e.sheetKinds[0] === "dashboard");
2316
+ }
2317
+ function De(e, t, n) {
2318
+ n !== void 0 && (n === null ? delete e[t] : e[t] = n);
2319
+ }
2320
+ function _a(e, t) {
2321
+ const n = [
2322
+ ...G(e).inputs.map((i) => i.input),
2323
+ ...(Array.isArray(e.inputs) ? e.inputs : []).filter(
2324
+ (i) => i.kind === "control"
2325
+ )
2326
+ ].filter(
2327
+ (i) => i.id !== t.id && i.variableName === t.variableName
2328
+ );
2329
+ if (!n.length) return;
2330
+ const r = yt(e, t);
2331
+ return n.some(
2332
+ (i) => [...yt(e, i)].some(
2333
+ (a) => r.has(a)
2334
+ )
2335
+ ) ? t.variableName : void 0;
2336
+ }
2337
+ function Pa(e, t, n, r) {
2338
+ var u, f;
2339
+ const i = [], a = jt(e), o = (d) => kt(t, d, a), s = (d) => kt(n, d, a), l = [];
2340
+ if (n.runtimeScope === "perSheet")
2341
+ for (const d of a.values())
2342
+ l.push({ sheetId: d.sheetId, sheetKind: d.sheetKind });
2343
+ else if (n.runtimeScope === "perCard")
2344
+ for (const d of ge(e))
2345
+ l.push({
2346
+ sheetId: d.sheetId,
2347
+ cardId: d.cardId,
2348
+ sheetKind: (u = a.get(d.sheetId)) == null ? void 0 : u.sheetKind
2349
+ });
2350
+ else if (n.runtimeScope === "perDocumentSection")
2351
+ for (const d of e.sheets ?? [])
2352
+ for (const m of ((f = d.document) == null ? void 0 : f.sections) ?? [])
2353
+ l.push({
2354
+ sheetId: d.id,
2355
+ sectionId: m.id,
2356
+ sheetKind: "document"
2357
+ });
2358
+ let c = r;
2359
+ for (const d of l) {
2360
+ if (s(d)) continue;
2361
+ const m = !!(c && Ue(c, n, d));
2362
+ if (m && (c = ze(c, n, d)), m || o(d)) {
2363
+ const { sheetKind: h, ...b } = d;
2364
+ i.push(b);
2365
+ }
2366
+ }
2367
+ return { defaultInputValues: c, dropped: i };
2368
+ }
2369
+ function kt(e, t, n) {
2370
+ if (e.runtimeScope === "perSheet" && t.sheetId && !t.cardId && !t.sectionId) {
2371
+ const r = n.get(t.sheetId);
2372
+ return r ? Gt(e, r) : !1;
2373
+ }
2374
+ return wr(e, t);
2375
+ }
2376
+ function Aa(e, t) {
2377
+ const n = { ...e };
2378
+ return t.defaultInputValues && Object.keys(t.defaultInputValues).length ? n.defaultInputValues = t.defaultInputValues : e.defaultInputValues !== void 0 && delete n.defaultInputValues, n;
2379
+ }
2380
+ function Ra(e, t, n, r, i) {
2381
+ const a = !!(n != null && n.defaultValueChanged || n != null && n.selectionIdentityChanged) || Sr(e, t);
2382
+ return {
2383
+ ...n,
2384
+ target: (n == null ? void 0 : n.target) ?? r,
2385
+ defaultValueChanged: a,
2386
+ defaultFilterValue: a ? ee(t, i) : void 0
2387
+ };
2388
+ }
2389
+ function gn(e) {
2390
+ const { settings: t } = e;
2391
+ if (!t) return e.state;
2392
+ const n = e.input;
2393
+ let r = e.state.dashboardInputValues, i = e.state.defaultInputValues;
2394
+ if (t.selectionIdentityChanged && (r = pt(
2395
+ r,
2396
+ n,
2397
+ t.target,
2398
+ { status: "cleared" }
2399
+ )), t.defaultValueChanged) {
2400
+ const a = Ue(
2401
+ i,
2402
+ n,
2403
+ t.target
2404
+ );
2405
+ let o = ze(
2406
+ i || {},
2407
+ n,
2408
+ t.target
2409
+ );
2410
+ t.defaultFilterValue ? o = ht(
2411
+ o,
2412
+ n,
2413
+ t.target,
2414
+ {
2415
+ status: "set",
2416
+ value: {
2417
+ kind: "filter",
2418
+ filterValue: t.defaultFilterValue
2419
+ },
2420
+ ...a != null && a.comparisonSelection ? { comparisonSelection: a.comparisonSelection } : {}
2421
+ }
2422
+ ) : a != null && a.comparisonSelection && (o = ht(
2423
+ o,
2424
+ n,
2425
+ t.target,
2426
+ { comparisonSelection: a.comparisonSelection }
2427
+ )), i = Object.keys(o).length ? o : void 0, r = pt(
2428
+ r,
2429
+ n,
2430
+ t.target,
2431
+ t.defaultFilterValue ? {
2432
+ status: "set",
2433
+ value: {
2434
+ kind: "filter",
2435
+ filterValue: t.defaultFilterValue
2436
+ }
2437
+ } : { status: "cleared" }
2438
+ );
2439
+ }
2440
+ return t.defaultComparisonChanged && (i = gt(
2441
+ i || {},
2442
+ n,
2443
+ t.target,
2444
+ t.defaultComparisonSelection
2445
+ ), Object.keys(i).length || (i = void 0), r = gt(
2446
+ r,
2447
+ n,
2448
+ t.target,
2449
+ void 0
2450
+ )), {
2451
+ ...e.state,
2452
+ dashboardInputValues: r,
2453
+ defaultInputValues: i
2454
+ };
2455
+ }
2456
+ const J = (e) => Array.isArray(e.inputs) ? e.inputs : [];
2457
+ function Fe(e, t) {
2458
+ const n = J(e).find((r) => r.id === t);
2459
+ if (!n || n.kind !== "filter")
2460
+ throw new S("filter_not_found", `No filter ${t} on this dashboard.`, "Read the outline again and use its filter ids.");
2461
+ return n;
2462
+ }
2463
+ function yn(e, t) {
2464
+ var n;
2465
+ return (n = ge(e).find((r) => r.cardId === t)) == null ? void 0 : n.card.title;
2466
+ }
2467
+ function Ea(e, t, n) {
2468
+ const r = G(e), i = r.findFilterInput({ inputId: t });
2469
+ return i ? r.reachedCards({ inputId: t }).filter(
2470
+ (a) => ["bound", "automatic", "sql", "relationshipApplied"].includes(
2471
+ Qn(i.input, a.card, n).reach
2472
+ )
2473
+ ).length : 0;
2474
+ }
2475
+ function Va(e, t) {
2476
+ const n = G(e), r = n.findFilterInput({ inputId: t });
2477
+ return r ? n.reachedCards({ inputId: t }).filter((i) => Yn(r.input, i.card) === "relationship").length : 0;
2478
+ }
2479
+ function bn(e, t) {
2480
+ if (t.scope.kind === "allSheets") return "every sheet";
2481
+ if (t.scope.kind !== "sheets") return "its cards";
2482
+ const n = [...jt(e).values()].filter((r) => Gt(t, r));
2483
+ return qe(n.map((r) => {
2484
+ var i, a;
2485
+ return ((a = (i = e.sheets) == null ? void 0 : i.find((o) => o.id === r.sheetId)) == null ? void 0 : a.title) ?? r.sheetId;
2486
+ }));
2487
+ }
2488
+ const vn = (e) => {
2489
+ var t;
2490
+ return ((t = e.filter) == null ? void 0 : t.type) === "single" ? "single select" : "multi select";
2491
+ };
2492
+ function Fn(e) {
2493
+ var t, n, r;
2494
+ if ((n = (t = e.filter) == null ? void 0 : t.defaultValues) != null && n.length) return `default ${e.filter.defaultValues.join(", ")}`;
2495
+ if ((r = e.filter) != null && r.defaultDateFilter) return "a default period";
2496
+ }
2497
+ function ae(e) {
2498
+ return _.plain("filter", e);
2499
+ }
2500
+ function Ka(e, t) {
2501
+ const { input: n } = t, r = J(e);
2502
+ if (r.some((l) => l.id === n.id))
2503
+ throw new S("filter_id_taken", `A filter with id ${n.id} is already on this dashboard.`);
2504
+ if (G(e).findFilterInput({ filterId: n.filter.id }))
2505
+ throw new S("filter_id_taken", `A filter definition with id ${n.filter.id} is already on this dashboard.`);
2506
+ const i = { ...e, inputs: [...r, n] }, a = Ea(i, n.id), o = Va(i, n.id), s = [vn(n), Fn(n)].filter(Boolean).join(", ");
2507
+ return {
2508
+ dashboard: i,
2509
+ created: [
2510
+ {
2511
+ kind: "filter",
2512
+ id: n.id,
2513
+ title: n.label,
2514
+ ...t.changeIndex !== void 0 ? { changeIndex: t.changeIndex } : {}
2515
+ }
2516
+ ],
2517
+ clauses: [
2518
+ ae(
2519
+ `adds the filter ${T(n.label)} (${s}) to ${bn(i, n)}; it filters ${a} card${a === 1 ? "" : "s"}${o ? ` and may filter ${o} more through the domain's relationships` : ""}`
2520
+ )
2521
+ ]
2522
+ };
2523
+ }
2524
+ function La(e, t, n) {
2525
+ const r = Oa(e, { inputId: t.filterId }, t.settings, {
2526
+ calendar: n.calendar
2527
+ });
2528
+ if (!r.ok) {
2529
+ const [o] = r.issues;
2530
+ throw new S(
2531
+ (o == null ? void 0 : o.code) === "inputNotFound" ? "filter_not_found" : "filter_invalid",
2532
+ (o == null ? void 0 : o.message) ?? "These filter settings could not be saved.",
2533
+ (o == null ? void 0 : o.code) === "inputNotFound" ? "Read the outline again and use its filter ids." : "Change the filter settings and propose again.",
2534
+ { issues: r.issues }
2535
+ );
2536
+ }
2537
+ const i = J(e).find((o) => o.id === r.inputId), a = J(r.dashboard).find((o) => o.id === r.inputId);
2538
+ return {
2539
+ dashboard: r.dashboard,
2540
+ runtimeEffects: [{ kind: "filter_value", effects: r.valueEffects }],
2541
+ clauses: [ae(`changes the filter ${T((i == null ? void 0 : i.label) ?? a.label)}: ${Ba(r.dashboard, i, a)}`)]
2542
+ };
2543
+ }
2544
+ function Ba(e, t, n) {
2545
+ var o, s, l, c, u, f;
2546
+ if (!t) return "updates its settings";
2547
+ const r = [];
2548
+ t.label !== n.label && r.push(`renames it ${T(n.label)}`), (((o = t.filter) == null ? void 0 : o.type) ?? "multiple") !== (((s = n.filter) == null ? void 0 : s.type) ?? "multiple") && r.push(`makes it ${vn(n)}`);
2549
+ const i = JSON.stringify([((l = t.filter) == null ? void 0 : l.defaultValues) ?? null, ((c = t.filter) == null ? void 0 : c.defaultDateFilter) ?? null]), a = JSON.stringify([((u = n.filter) == null ? void 0 : u.defaultValues) ?? null, ((f = n.filter) == null ? void 0 : f.defaultDateFilter) ?? null]);
2550
+ if (i !== a) {
2551
+ const d = Fn(n);
2552
+ r.push(d ? `sets its ${d.replace(/^default /, "default to ").replace(/^a default period$/, "default period")}` : "removes its default");
2553
+ }
2554
+ return JSON.stringify(t.scope) !== JSON.stringify(n.scope) && r.push(`applies it to ${bn(e, n)}`), r.length ? qe(r) : "keeps its settings";
2555
+ }
2556
+ function $a(e, t) {
2557
+ const n = Fe(e, t);
2558
+ return {
2559
+ dashboard: {
2560
+ ...e,
2561
+ inputs: J(e).filter((i) => i.id !== t),
2562
+ defaultInputValues: Dr(e.defaultInputValues, t)
2563
+ },
2564
+ runtimeEffects: [{ kind: "input_removed", inputId: t }],
2565
+ clauses: [ae(`removes the filter ${T(n.label)}`)]
2566
+ };
2567
+ }
2568
+ function qa(e, t, n) {
2569
+ var o;
2570
+ if (!ge(e).some((s) => s.cardId === n))
2571
+ throw new S("card_not_found", `No card ${n} on this dashboard.`, "Read the outline again and use its card ids.");
2572
+ const r = kr(t.scope, n);
2573
+ if (!r)
2574
+ throw new S(
2575
+ "filter_invalid",
2576
+ "This filter applies to Document sections, so it can't leave out one card.",
2577
+ "Change it in the editor."
2578
+ );
2579
+ const i = { ...t, scope: r }, a = je({ inputs: [i], dashboardFilters: [] });
2580
+ if (!a.ok)
2581
+ throw new S("filter_invalid", ((o = a.issues[0]) == null ? void 0 : o.message) ?? "This filter could not be saved.", "Change it in the editor.");
2582
+ return {
2583
+ ...e,
2584
+ inputs: J(e).map((s) => s.id === t.id ? i : s)
2585
+ };
2586
+ }
2587
+ function Cn(e, t, n, r, i) {
2588
+ var u, f;
2589
+ const a = Fe(e, t);
2590
+ if (!ge(e).some((d) => d.cardId === n))
2591
+ throw new S("card_not_found", `No card ${n} on this dashboard.`, "Read the outline again and use its card ids.");
2592
+ const o = [...((u = a.application) == null ? void 0 : u.cards) ?? []], s = o.findIndex((d) => d.cardId === n);
2593
+ s >= 0 ? o[s] = r : o.push(r);
2594
+ const l = {
2595
+ ...a,
2596
+ ...i ? { scope: i } : {},
2597
+ application: { ...a.application ?? { kind: "cardMappings" }, cards: o }
2598
+ }, c = je({ inputs: [l], dashboardFilters: [] });
2599
+ if (!c.ok)
2600
+ throw new S(
2601
+ "filter_invalid",
2602
+ ((f = c.issues[0]) == null ? void 0 : f.message) ?? "This filter mapping could not be saved.",
2603
+ "Change the mapping and propose again."
2604
+ );
2605
+ return {
2606
+ ...e,
2607
+ inputs: J(e).map((d) => d.id === t ? l : d)
2608
+ };
2609
+ }
2610
+ function za(e) {
2611
+ switch (e.kind) {
2612
+ case "field":
2613
+ return `by ${e.field.name}`;
2614
+ case "relationship":
2615
+ return "through a chosen relationship path";
2616
+ default:
2617
+ return String(e.kind);
2618
+ }
2619
+ }
2620
+ function Ua(e, t) {
2621
+ const n = Fe(e, t.filterId), r = { ...t.binding, kind: "bound", cardId: t.cardId }, i = Tr(n.scope, t.cardId), a = i !== n.scope;
2622
+ return {
2623
+ dashboard: Cn(e, t.filterId, t.cardId, r, a ? i : void 0),
2624
+ clauses: [
2625
+ ae(
2626
+ `makes ${T(n.label)} filter ${T(yn(e, t.cardId))} ${za(r.target)}${a ? ", which it used to leave out" : ""}`
2627
+ )
2628
+ ]
2629
+ };
2630
+ }
2631
+ function ja(e, t) {
2632
+ var i;
2633
+ const n = Fe(e, t.filterId);
2634
+ return {
2635
+ dashboard: ((i = n.filter) == null ? void 0 : i.kind) === "global-date" ? qa(e, n, t.cardId) : Cn(e, t.filterId, t.cardId, { kind: "excluded", cardId: t.cardId }),
2636
+ clauses: [ae(`stops ${T(n.label)} from filtering ${T(yn(e, t.cardId))}`)]
2637
+ };
2638
+ }
2639
+ function _s(e, t, n) {
2640
+ let r = e;
2641
+ const i = [], a = [], o = [], s = [];
2642
+ let l = !1;
2643
+ for (const [u, f] of t.entries()) {
2644
+ let d;
2645
+ try {
2646
+ d = Ga(r, f, n);
2647
+ } catch (m) {
2648
+ if (!(m instanceof S)) throw m;
2649
+ return {
2650
+ ok: !1,
2651
+ failedAt: {
2652
+ index: u,
2653
+ op: f.op,
2654
+ code: m.code,
2655
+ message: m.message,
2656
+ ...m.fix ? { fix: m.fix } : {},
2657
+ ...m.details ? { details: m.details } : {}
2658
+ }
2659
+ };
2660
+ }
2661
+ r = d.dashboard, i.push(...d.created ?? []);
2662
+ for (const m of d.touched ?? []) a.includes(m) || a.push(m);
2663
+ o.push(...d.runtimeEffects ?? []), s.push({ index: u, changeIndex: f.changeIndex, clauses: d.clauses }), l || (l = d.detached === !0);
2664
+ }
2665
+ const c = new Set(i.map((u) => u.id));
2666
+ return {
2667
+ ok: !0,
2668
+ dashboard: r,
2669
+ created: i,
2670
+ touched: a.filter((u) => !c.has(u)),
2671
+ descriptions: Wa(s),
2672
+ runtimeEffects: o,
2673
+ detaches: l
2674
+ };
2675
+ }
2676
+ function Ga(e, t, n) {
2677
+ switch (t.op) {
2678
+ case "card.add":
2679
+ return Nr(e, t);
2680
+ case "card.remove":
2681
+ return Or(e, t.cardId);
2682
+ case "card.update":
2683
+ return Z(Mr(e, t.cardId, t.update), [t.cardId]);
2684
+ case "layout.arrange":
2685
+ return fa(e, t);
2686
+ case "frame.commit":
2687
+ return Z(ya(e, t.commit), [t.commit.frame.activeCardId]);
2688
+ case "filter.add":
2689
+ return Ka(e, t);
2690
+ case "filter.update":
2691
+ return La(e, t, n);
2692
+ case "filter.remove":
2693
+ return $a(e, t.filterId);
2694
+ case "filter.bind":
2695
+ return Z(Ua(e, t), [t.cardId]);
2696
+ case "filter.exclude":
2697
+ return Z(ja(e, t), [t.cardId]);
2698
+ case "dashboard.update":
2699
+ return ba(e, t);
2700
+ case "sheet.add":
2701
+ return Ta(e, t);
2702
+ case "sheet.update":
2703
+ return Da(e, t);
2704
+ case "layout.tabs":
2705
+ return Z(Fa(e, t), t.cardIds.slice(0, 1));
2706
+ case "layout.untab":
2707
+ return Z(Ca(e, t), [t.cardId]);
2708
+ }
2709
+ }
2710
+ function Z(e, t) {
2711
+ return { ...e, touched: t.filter(Boolean) };
2712
+ }
2713
+ function Wa(e) {
2714
+ const t = [];
2715
+ for (const n of e) {
2716
+ const r = n.changeIndex === void 0 ? void 0 : t.find((i) => i.changeIndex === n.changeIndex);
2717
+ if (r) {
2718
+ r.operations.push(n.index), r.clauses.push(...n.clauses);
2719
+ continue;
2720
+ }
2721
+ t.push({
2722
+ ...n.changeIndex !== void 0 ? { changeIndex: n.changeIndex } : {},
2723
+ operations: [n.index],
2724
+ sentence: "",
2725
+ clauses: [...n.clauses]
2726
+ });
2727
+ }
2728
+ return t.map(({ clauses: n, ...r }) => ({
2729
+ ...r,
2730
+ sentence: _r(Ha(n))
2731
+ }));
2732
+ }
2733
+ function Ha(e) {
2734
+ let t = !1;
2735
+ return e.filter((n) => n.kind !== "detached" ? !0 : t ? !1 : (t = !0, !0));
2736
+ }
2737
+ function Mt(e) {
2738
+ return Object.fromEntries(
2739
+ Object.entries(e).filter(
2740
+ (t) => typeof t[1] == "string" && t[1].length > 0
2741
+ )
2742
+ );
2743
+ }
2744
+ function re(e) {
2745
+ return e.kind === "semantic" ? [
2746
+ e.kind,
2747
+ e.domainId,
2748
+ e.datasetId || "",
2749
+ e.datasetName || "",
2750
+ e.connectionId || ""
2751
+ ].join(":") : [
2752
+ e.kind,
2753
+ e.connectionId,
2754
+ e.databaseName || "",
2755
+ e.schemaName || "",
2756
+ e.tableName
2757
+ ].join(":");
2758
+ }
2759
+ function Qa(e, t) {
2760
+ if (e.kind === "semantic")
2761
+ return {
2762
+ status: "ready",
2763
+ request: Mt({
2764
+ connection_id: e.connectionId,
2765
+ domain_id: e.domainId,
2766
+ dataset_id: Jr(e),
2767
+ dataset_name: e.datasetName
2768
+ })
2769
+ };
2770
+ const n = yi({
2771
+ source: e,
2772
+ capabilities: t
2773
+ });
2774
+ return n.kind === "incompatible_capabilities" ? {
2775
+ status: "unavailable",
2776
+ message: "Connection capabilities are unavailable for field metadata."
2777
+ } : n.kind === "missing_coordinates" ? {
2778
+ status: "unavailable",
2779
+ message: `Source is missing required field-metadata coordinates: ${n.missing.join(", ")}.`
2780
+ } : {
2781
+ status: "ready",
2782
+ request: Mt({
2783
+ connection_id: e.connectionId,
2784
+ datamodel_id: "",
2785
+ database_name: n.coordinates.databaseName,
2786
+ schema_name: n.coordinates.schemaName,
2787
+ table_name: n.coordinates.tableName
2788
+ })
2789
+ };
2790
+ }
2791
+ function Ps(e, t = /* @__PURE__ */ new Map()) {
2792
+ const n = /* @__PURE__ */ new Map();
2793
+ for (const { card: r } of e) {
2794
+ const i = Wt(r), a = i.kind === "config" ? i.executableSources : i.kind === "sql" ? i.pinnedCatalogSources.map((o) => o.source) : [];
2795
+ for (const o of a) {
2796
+ const s = re(o);
2797
+ if (!n.has(s)) {
2798
+ const l = Qa(
2799
+ o,
2800
+ o.connectionId ? t.get(o.connectionId) : void 0
2801
+ );
2802
+ n.set(s, {
2803
+ key: s,
2804
+ source: o,
2805
+ ...l
2806
+ });
2807
+ }
2808
+ }
2809
+ }
2810
+ return Array.from(n.values());
2811
+ }
2812
+ function Ya(e, t) {
2813
+ if (e.kind !== "semantic" || !e.connectionId) return;
2814
+ const n = (t.qualifiedEntityName || "").split(".").map((i) => i.trim()).filter(Boolean), r = n.at(-1);
2815
+ if (r)
2816
+ return {
2817
+ kind: "physical",
2818
+ connectionId: e.connectionId,
2819
+ tableName: r,
2820
+ ...n.length > 1 ? { schemaName: n.at(-2) } : {},
2821
+ ...n.length > 2 ? { databaseName: n.at(-3) } : {}
2822
+ };
2823
+ }
2824
+ function ce(e, t) {
2825
+ let n = e.get(t);
2826
+ return n || (n = { fields: /* @__PURE__ */ new Map(), fieldConflicts: /* @__PURE__ */ new Set() }, e.set(t, n)), n;
2827
+ }
2828
+ function In(e, t) {
2829
+ e.sourceLabel === void 0 ? e.sourceLabel = t : e.sourceLabel !== t && (e.sourceLabelConflict = !0);
2830
+ }
2831
+ function Ve(e, t, n) {
2832
+ for (const r of t) {
2833
+ const i = r == null ? void 0 : r.trim();
2834
+ if (!i) continue;
2835
+ const a = Yt(i), o = e.fields.get(a);
2836
+ o === void 0 ? e.fields.set(a, n) : o !== n && e.fieldConflicts.add(a);
2837
+ }
2838
+ }
2839
+ function xn(e, t) {
2840
+ t.sourceLabel && In(e, t.sourceLabel), t.sourceLabelConflict && (e.sourceLabelConflict = !0);
2841
+ for (const [n, r] of t.fields)
2842
+ Ve(e, [n], r);
2843
+ for (const n of t.fieldConflicts ?? [])
2844
+ e.fieldConflicts.add(n);
2845
+ }
2846
+ function Sn(e) {
2847
+ return e.kind === "semantic" && (e.label || e.datasetName || "").trim() || void 0;
2848
+ }
2849
+ function As(e, t) {
2850
+ var r, i;
2851
+ const n = /* @__PURE__ */ new Map();
2852
+ for (const [a, o] of e) {
2853
+ if (o.status !== "ready") continue;
2854
+ const s = t == null ? void 0 : t.get(a), l = s ? Sn(s) : void 0;
2855
+ for (const c of o.columns) {
2856
+ const u = (r = c.column_name) == null ? void 0 : r.trim(), f = (i = c.label) == null ? void 0 : i.trim(), d = s ? Ya(s, c) : void 0;
2857
+ d && l && In(
2858
+ ce(n, re(d)),
2859
+ l
2860
+ ), !(!u || !f || f === u) && (Ve(
2861
+ ce(n, a),
2862
+ [u, c.sourceField],
2863
+ f
2864
+ ), d && Ve(
2865
+ ce(n, re(d)),
2866
+ [c.sourceField, u],
2867
+ f
2868
+ ));
2869
+ }
2870
+ }
2871
+ return n;
2872
+ }
2873
+ function Rs(...e) {
2874
+ const t = /* @__PURE__ */ new Map();
2875
+ for (const n of e)
2876
+ for (const [r, i] of n ?? [])
2877
+ xn(ce(t, r), i);
2878
+ return t;
2879
+ }
2880
+ function Ze(e) {
2881
+ return [e.databaseName, e.schemaName, e.tableName].filter(Boolean).join(".");
2882
+ }
2883
+ function Ja(e) {
2884
+ return e.split(":").slice(2).filter(Boolean).join(".");
2885
+ }
2886
+ function wn(e, t) {
2887
+ const n = re(t), r = e.get(n);
2888
+ if (t.kind !== "physical") return r;
2889
+ const i = `physical:${t.connectionId}:`, a = Ze(t), o = {
2890
+ fields: /* @__PURE__ */ new Map(),
2891
+ fieldConflicts: /* @__PURE__ */ new Set()
2892
+ };
2893
+ let s = !1;
2894
+ for (const [l, c] of e)
2895
+ l.startsWith(i) && (l !== n && !bi(a, Ja(l)) || (xn(o, c), s = !0));
2896
+ return s ? o : void 0;
2897
+ }
2898
+ function Xa(e, t) {
2899
+ var i;
2900
+ if (!e) return;
2901
+ const n = Yt(t.name), r = wn(e, t.source);
2902
+ return r && !((i = r.fieldConflicts) != null && i.has(n)) ? r.fields.get(n) : void 0;
2903
+ }
2904
+ function Za(e, t) {
2905
+ if (t.kind === "semantic")
2906
+ return Sn(t) || t.datasetId || "Dataset";
2907
+ const n = e ? wn(e, t) : void 0;
2908
+ return n != null && n.sourceLabel && !n.sourceLabelConflict ? n.sourceLabel : Ze(t);
2909
+ }
2910
+ function Es(e, t) {
2911
+ const n = Xa(e, t);
2912
+ return {
2913
+ name: t.name,
2914
+ ...n ? { label: n } : {},
2915
+ entityName: Za(e, t.source),
2916
+ ...t.source.kind === "physical" ? { qualifiedEntityName: Ze(t.source) } : {},
2917
+ dataType: t.dataType
2918
+ };
2919
+ }
2920
+ function eo(e, t) {
2921
+ var i, a;
2922
+ const n = (i = t.column_name) == null ? void 0 : i.trim(), r = Qt(t.data_type);
2923
+ if (!(!n || r === "unknown"))
2924
+ return {
2925
+ kind: "field",
2926
+ field: {
2927
+ name: n,
2928
+ source: { ...e },
2929
+ dataType: r,
2930
+ ...(a = t.sourceField) != null && a.trim() ? { sourceField: t.sourceField.trim() } : {}
2931
+ }
2932
+ };
2933
+ }
2934
+ function Vs(e) {
2935
+ const t = {};
2936
+ for (const { card: n } of e.cards) {
2937
+ const r = Wt(n), i = r.kind === "config" ? r.executableSources : r.kind === "sql" ? r.pinnedCatalogSources.map((s) => s.source) : [];
2938
+ if (!i.length) continue;
2939
+ const a = [];
2940
+ let o;
2941
+ for (const s of i) {
2942
+ const l = e.metadataBySourceKey.get(
2943
+ re(s)
2944
+ );
2945
+ if (!l || l.status === "unavailable") {
2946
+ o = (l == null ? void 0 : l.status) === "unavailable" ? l.message : "Field metadata is not available yet.";
2947
+ break;
2948
+ }
2949
+ for (const c of l.columns) {
2950
+ const u = eo(s, c);
2951
+ u && a.push(u);
2952
+ }
2953
+ }
2954
+ t[n.id] = o ? { status: "metadataUnavailable", message: o } : { status: "ready", targets: a };
2955
+ }
2956
+ return t;
2957
+ }
2958
+ function Ks(e) {
2959
+ const { dashboard: t, target: n, calendar: r } = e, i = Dn(n), a = Tn(t, n, r);
2960
+ return {
2961
+ value: a,
2962
+ mode: Jn(
2963
+ Xn(a == null ? void 0 : a.operation) ? a.operation : i.operation
2964
+ )
2965
+ };
2966
+ }
2967
+ function Tn(e, t, n) {
2968
+ var r;
2969
+ switch (t.kind) {
2970
+ case "dashboardInput": {
2971
+ const i = Ar({
2972
+ dashboard: e,
2973
+ input: t.input,
2974
+ target: t.scope,
2975
+ calendar: n
2976
+ });
2977
+ return (i == null ? void 0 : i.status) === "set" && i.value.kind === "filter" ? i.value.filterValue : void 0;
2978
+ }
2979
+ case "dashboardFilter": {
2980
+ const i = (r = e.defaultFilterValues) == null ? void 0 : r.find(
2981
+ (a) => a.filterId === t.filter.id
2982
+ );
2983
+ return i ? Pr({
2984
+ filterDefinitions: [t.filter],
2985
+ filterValues: [i]
2986
+ })[0] : ee(t.filter, n);
2987
+ }
2988
+ case "definition":
2989
+ return ee(t.filter, n);
2990
+ }
2991
+ }
2992
+ function Dn(e) {
2993
+ return e.kind === "dashboardInput" ? e.input.filter : e.filter;
2994
+ }
2995
+ function Ls(e) {
2996
+ var a;
2997
+ const { dashboard: t, filter: n, input: r, scope: i } = e;
2998
+ return r && (t.inputs || []).some((o) => o.id === r.id) ? { kind: "dashboardInput", input: r, scope: i } : ((a = G(t).findFilterInput({ filterId: n.id })) == null ? void 0 : a.origin) === "toolbarFilter" ? { kind: "dashboardFilter", filter: n } : { kind: "definition", filter: n };
2999
+ }
3000
+ function Bs(e) {
3001
+ const { dashboard: t, target: n, calendar: r } = e, i = Dn(n), a = Rr(i), o = to(t, n);
3002
+ if (!o) return a;
3003
+ if (o === "cleared")
3004
+ return {
3005
+ operation: i.operation,
3006
+ defaultValues: void 0,
3007
+ defaultDateFilter: void 0
3008
+ };
3009
+ const s = Tn(t, n, r);
3010
+ if (!s || no(s, ee(i, r)))
3011
+ return a;
3012
+ if (s.valueType === "date") {
3013
+ const l = Xr(
3014
+ "relativeMeta" in s ? s.relativeMeta : void 0
3015
+ ) ?? ro(i, s, r);
3016
+ return l ? {
3017
+ operation: s.operation,
3018
+ defaultValues: i.defaultValues,
3019
+ defaultDateFilter: l
3020
+ } : a;
3021
+ }
3022
+ return {
3023
+ operation: s.operation,
3024
+ defaultValues: s.values,
3025
+ defaultDateFilter: i.defaultDateFilter
3026
+ };
3027
+ }
3028
+ function to(e, t) {
3029
+ var n;
3030
+ if (t.kind === "dashboardInput") {
3031
+ const r = Ue(
3032
+ e.defaultInputValues,
3033
+ t.input,
3034
+ t.scope
3035
+ );
3036
+ return (r == null ? void 0 : r.status) === "set" || (r == null ? void 0 : r.status) === "cleared" ? r.status : void 0;
3037
+ }
3038
+ if (t.kind === "dashboardFilter")
3039
+ return (n = e.defaultFilterValues) != null && n.some(
3040
+ (r) => r.filterId === t.filter.id
3041
+ ) ? "set" : void 0;
3042
+ }
3043
+ function no(e, t) {
3044
+ return !!(t && e.operation === t.operation && Oe(Ot(e), Ot(t)) && Oe(
3045
+ "relativeMeta" in e ? e.relativeMeta : void 0,
3046
+ "relativeMeta" in t ? t.relativeMeta : void 0
3047
+ ));
3048
+ }
3049
+ function Ot(e) {
3050
+ return e.values.map(
3051
+ (t) => t instanceof Date ? t.getTime() : t
3052
+ );
3053
+ }
3054
+ function ro(e, t, n) {
3055
+ const r = Er(n == null ? void 0 : n.tz), i = xe(t.values[0], r);
3056
+ if (!i) return;
3057
+ const [a, o, s] = new Intl.DateTimeFormat("en-CA", {
3058
+ timeZone: r,
3059
+ year: "numeric",
3060
+ month: "2-digit",
3061
+ day: "2-digit"
3062
+ }).format(i).split("-").map(Number), l = [
3063
+ {
3064
+ mode: "fixed",
3065
+ unit: "day",
3066
+ date: `${a}-${String(o).padStart(2, "0")}-${String(s).padStart(2, "0")}`
3067
+ },
3068
+ { mode: "fixed", unit: "month", year: a, month: o - 1 }
3069
+ ], c = t.values.map(
3070
+ (u) => {
3071
+ var f;
3072
+ return (f = xe(u, r)) == null ? void 0 : f.getTime();
3073
+ }
3074
+ );
3075
+ return l.find((u) => {
3076
+ const f = ee(
3077
+ { ...e, defaultDateFilter: u },
3078
+ n
3079
+ );
3080
+ return (f == null ? void 0 : f.operation) === t.operation && Oe(
3081
+ f.values.map(
3082
+ (d) => {
3083
+ var m;
3084
+ return (m = xe(d, r)) == null ? void 0 : m.getTime();
3085
+ }
3086
+ ),
3087
+ c
3088
+ );
3089
+ });
3090
+ }
3091
+ function io(e) {
3092
+ const t = W(e.format);
3093
+ if ((t == null ? void 0 : t.type) === "temporal_bucket") {
3094
+ if (!e.granularity) return {};
3095
+ const n = pi(
3096
+ t,
3097
+ e.granularity
3098
+ );
3099
+ return n ? {
3100
+ granularity: e.granularity,
3101
+ semanticTemporalPresentation: {
3102
+ granularity: e.granularity,
3103
+ format: n
3104
+ }
3105
+ } : {};
3106
+ }
3107
+ return {
3108
+ ...e.granularity ? { granularity: e.granularity } : {},
3109
+ ...t ? { format: t } : {}
3110
+ };
3111
+ }
3112
+ function ao(e, t) {
3113
+ var i, a;
3114
+ const n = ((i = e.nativeDataType) == null ? void 0 : i.trim()) || ((a = e.native_data_type) == null ? void 0 : a.trim());
3115
+ return n || ((e.dataTypeProvenance || t) === "physical" ? e.data_type : void 0);
3116
+ }
3117
+ function kn(e) {
3118
+ const t = (e.label ?? "").trim();
3119
+ return t ? e.derivedLabel === void 0 ? !0 : t !== e.derivedLabel.trim() : !1;
3120
+ }
3121
+ function et(e) {
3122
+ return kn(e) ? e.label.trim() : e.name || (e.label ?? "").trim();
3123
+ }
3124
+ function Nt(e) {
3125
+ return et(e).toLowerCase().trim();
3126
+ }
3127
+ function oo(e, t) {
3128
+ return Nt(e).localeCompare(Nt(t), void 0, {
3129
+ numeric: !0,
3130
+ sensitivity: "base"
3131
+ });
3132
+ }
3133
+ function ne(e) {
3134
+ return String(e ?? "").toLowerCase().replace(/[\s_\-.]+/g, "");
3135
+ }
3136
+ function $s(e, t) {
3137
+ const n = ne(t);
3138
+ return n ? [
3139
+ et(e),
3140
+ e.label,
3141
+ e.name,
3142
+ e.description,
3143
+ e.entityName,
3144
+ e.qualifiedEntityName,
3145
+ e.entityName && e.name ? `${e.entityName}.${e.name}` : "",
3146
+ e.dataType
3147
+ ].some(
3148
+ (i) => !!i && ne(i).includes(n)
3149
+ ) : !0;
3150
+ }
3151
+ function _t(e, t) {
3152
+ const n = ne(t);
3153
+ if (!n) return 0;
3154
+ const r = ne(et(e));
3155
+ return r.startsWith(n) ? 0 : r.includes(n) ? 1 : [e.label, e.name].filter(Boolean).map(ne).some((a) => a.includes(n)) ? 2 : 3;
3156
+ }
3157
+ function qs(e, t, n) {
3158
+ return _t(e, n) - _t(t, n) || oo(e, t);
3159
+ }
3160
+ function so(e, t) {
3161
+ var a;
3162
+ const n = e.type === "dataset" ? (a = t.find((o) => o.entityName)) == null ? void 0 : a.entityName : void 0, r = n || e.name, i = bt(
3163
+ e.type === "dataset" && n ? { ...e, name: n } : e
3164
+ );
3165
+ return {
3166
+ entityId: e.id || e.name,
3167
+ entityType: e.type,
3168
+ entityName: r,
3169
+ label: e.label,
3170
+ description: e.description,
3171
+ qualifiedEntityName: i,
3172
+ columns: t.map((o) => {
3173
+ var m;
3174
+ const s = e.type === "dataset" ? o.entityName || r : e.name, l = o.qualifiedEntityName || (e.type === "dataset" && s ? bt({ ...e, name: s }) : i), c = ao(
3175
+ o,
3176
+ e.type === "dataset" ? "semantic" : "physical"
3177
+ ), u = (m = o.label) != null && m.trim() ? o.label : void 0, f = u ? void 0 : Vr(o.column_name);
3178
+ return {
3179
+ id: Kr(s, o.column_name),
3180
+ name: o.column_name,
3181
+ qualifiedFieldName: o.qualifiedFieldName || o.column_name,
3182
+ dataType: o.data_type,
3183
+ ...c ? { nativeDataType: c } : {},
3184
+ label: u ?? f ?? o.column_name,
3185
+ ...f !== void 0 ? { derivedLabel: f } : {},
3186
+ description: o.description || "",
3187
+ qualifiedEntityName: l,
3188
+ entityId: o.entityId || e.id || e.id || s,
3189
+ entityName: s,
3190
+ entityType: o.entityType || e.type,
3191
+ role: o.role,
3192
+ expression: o.expression,
3193
+ calculatedFormula: o.calculatedFormula,
3194
+ calculationRepresentation: o.calculationRepresentation,
3195
+ derivedField: o.derivedField,
3196
+ fieldScope: o.fieldScope,
3197
+ source: o.source,
3198
+ sourceField: o.sourceField,
3199
+ calculatedFieldOrigin: o.calculatedFieldOrigin,
3200
+ aggregateOrigin: o.aggregateOrigin,
3201
+ labelOrigin: o.labelOrigin,
3202
+ formatOrigin: o.formatOrigin,
3203
+ ...io(o),
3204
+ aggregate: o.aggregate
3205
+ };
3206
+ })
3207
+ };
3208
+ }
3209
+ function lo(e) {
3210
+ return e.map((t) => ({
3211
+ ...t,
3212
+ id: Ht({ ...t }),
3213
+ fieldScope: "domain"
3214
+ }));
3215
+ }
3216
+ function co(e) {
3217
+ return e.flatMap(
3218
+ (t) => t.columns.map((n) => {
3219
+ const r = kn(n) ? n.label : void 0, i = r ? void 0 : n.derivedLabel ?? Br(n.name), a = r ?? i ?? n.name;
3220
+ return {
3221
+ ...n,
3222
+ id: n.id || `${t.entityId}-${n.name}`,
3223
+ name: n.name,
3224
+ qualifiedFieldName: n.qualifiedFieldName || n.name,
3225
+ dataType: n.dataType,
3226
+ qualifiedEntityName: n.qualifiedEntityName || t.qualifiedEntityName,
3227
+ label: a,
3228
+ ...i !== void 0 ? { derivedLabel: i } : {},
3229
+ description: n.description,
3230
+ entityId: n.entityId || t.entityId,
3231
+ entityName: n.entityName || t.entityName,
3232
+ entityType: n.entityType || t.entityType
3233
+ };
3234
+ })
3235
+ );
3236
+ }
3237
+ function zs(e) {
3238
+ const t = e.map((r) => so(r.target, r.columns || [])).filter((r) => {
3239
+ var i;
3240
+ return ((i = r == null ? void 0 : r.columns) == null ? void 0 : i.length) > 0;
3241
+ }), n = lo(e.flatMap((r) => r.calculatedFields || []));
3242
+ if (n.length > 0) {
3243
+ const r = /* @__PURE__ */ new Map();
3244
+ n.forEach((i) => {
3245
+ const a = Ht(i);
3246
+ r.has(a) || r.set(a, i);
3247
+ }), t.unshift({
3248
+ entityId: Lr,
3249
+ entityType: "dataset",
3250
+ entityName: vt,
3251
+ label: "Calculated Fields",
3252
+ description: "Domain-level calculated metrics and dimensions",
3253
+ qualifiedEntityName: vt,
3254
+ columns: Array.from(r.values())
3255
+ });
3256
+ }
3257
+ return { columnGroups: t, columns: co(t) };
3258
+ }
3259
+ function uo(e, t) {
3260
+ var i;
3261
+ const n = (i = t.columnKeyMap) == null ? void 0 : i.byRole;
3262
+ if (!n) return;
3263
+ const r = Object.values(n).flatMap((a) => {
3264
+ const o = a == null ? void 0 : a[e];
3265
+ return o ? [o] : [];
3266
+ });
3267
+ if (r.length === 1)
3268
+ return r[0].outputKey ?? r[0].rawKey;
3269
+ }
3270
+ function fo(e, t) {
3271
+ var r;
3272
+ const n = (r = t.resultColumns) == null ? void 0 : r.find((i) => {
3273
+ const a = i.pivotIdentity;
3274
+ return (a == null ? void 0 : a.metricId) === e.metricId && a.members.length === e.members.length && a.members.every(
3275
+ (o, s) => o.fieldId === e.members[s].fieldId && o.value === e.members[s].value
3276
+ );
3277
+ });
3278
+ return n == null ? void 0 : n.key;
3279
+ }
3280
+ function Pt(e, t) {
3281
+ var n;
3282
+ switch (e.kind) {
3283
+ case "field":
3284
+ return uo(e.fieldId, t);
3285
+ case "pivot":
3286
+ return fo(e, t);
3287
+ case "result":
3288
+ return !t.keys || t.keys.includes(e.key) ? e.key : void 0;
3289
+ case "sqlKpiValue":
3290
+ return (n = t.keys) == null ? void 0 : n[0];
3291
+ case "matrixMeasure":
3292
+ return e.measureId;
3293
+ case "matrixLevel":
3294
+ return;
3295
+ }
3296
+ }
3297
+ function Us(e, t) {
3298
+ return e.flatMap((n) => {
3299
+ var s, l;
3300
+ const r = Pt(n.condition.column, t);
3301
+ if (r === void 0) return [];
3302
+ const i = (s = n.target.columns) == null ? void 0 : s.flatMap((c) => {
3303
+ const u = Pt(c, t);
3304
+ return u === void 0 ? [] : [u];
3305
+ });
3306
+ if ((l = n.target.columns) != null && l.length && !(i != null && i.length)) return [];
3307
+ const { columns: a, ...o } = n.target;
3308
+ return [
3309
+ {
3310
+ ...n,
3311
+ condition: { ...n.condition, column: r },
3312
+ target: i ? { ...o, columns: i } : o
3313
+ }
3314
+ ];
3315
+ });
3316
+ }
3317
+ function js(e, t, n) {
3318
+ var o, s, l, c, u;
3319
+ const r = $r(e);
3320
+ if (r.includes("matrixMeasure"))
3321
+ return (s = (o = e.config) == null ? void 0 : o.matrix) != null && s.spec.measures.some((f) => f.id === t) ? { kind: "matrixMeasure", measureId: t } : void 0;
3322
+ if (r.includes("sqlKpiValue")) return { kind: "sqlKpiValue" };
3323
+ if (r.includes("result"))
3324
+ return !n.keys || n.keys.includes(t) ? { kind: "result", key: t } : void 0;
3325
+ const i = r.includes("pivot") ? (c = (l = n.resultColumns) == null ? void 0 : l.find((f) => f.key === t)) == null ? void 0 : c.pivotIdentity : void 0;
3326
+ if (i)
3327
+ return {
3328
+ kind: "pivot",
3329
+ metricId: i.metricId,
3330
+ members: i.members.map((f) => ({ fieldId: f.fieldId, value: f.value }))
3331
+ };
3332
+ if (!r.includes("field")) return;
3333
+ const a = Object.values(((u = n.columnKeyMap) == null ? void 0 : u.byRole) ?? {}).flatMap(
3334
+ (f) => Object.entries(f ?? {}).flatMap(
3335
+ ([d, m]) => (m.outputKey ?? m.rawKey) === t ? [d] : []
3336
+ )
3337
+ );
3338
+ return a.length === 1 ? { kind: "field", fieldId: a[0] } : void 0;
3339
+ }
3340
+ function he(e, t) {
3341
+ const n = (a) => {
3342
+ if ($(a)) return a.value;
3343
+ const o = typeof a == "string" ? Zr(a.trim()) ?? B(a) : B(a);
3344
+ if (o === null) return null;
3345
+ try {
3346
+ return ei(String(o));
3347
+ } catch {
3348
+ return null;
3349
+ }
3350
+ }, r = n(e), i = n(t);
3351
+ return r === null || i === null ? null : Jt(r, i);
3352
+ }
3353
+ function At(e, t, n) {
3354
+ const r = mo(e);
3355
+ if (r === null) return null;
3356
+ if (typeof r == "number" && typeof t == "number" && typeof n == "number") {
3357
+ const h = ho(r, t, n);
3358
+ return { ratio: h, midpointComparison: Math.sign(h - 0.5) };
3359
+ }
3360
+ if ([t, n].some((h) => typeof h == "number" && !Number.isFinite(h))) return null;
3361
+ const i = [r, t, n].map((h) => {
3362
+ const b = typeof h == "number" ? Ne(String(h)) : h.value, [p, y = ""] = b.split(".");
3363
+ return { coefficient: p + y, scale: y.length };
3364
+ }), a = Math.max(...i.map((h) => h.scale)), [o, s, l] = i.map(
3365
+ (h) => BigInt(h.coefficient) * 10n ** BigInt(a - h.scale)
3366
+ ), c = l - s, u = o - s;
3367
+ if (c <= 0n)
3368
+ return {
3369
+ ratio: o >= l ? 1 : 0,
3370
+ midpointComparison: o >= l ? 1 : -1
3371
+ };
3372
+ const f = u * 2n - c, d = f < 0n ? -1 : f > 0n ? 1 : 0;
3373
+ return { ratio: u <= 0n ? 0 : u >= c ? 1 : Number(u * 1000000000n / c) / 1e9, midpointComparison: d };
3374
+ }
3375
+ function Gs(e) {
3376
+ return !!e && typeof e == "object" && !Array.isArray(e);
3377
+ }
3378
+ function Ws(e) {
3379
+ return e.enabled !== !1;
3380
+ }
3381
+ function Hs(e) {
3382
+ return e.kind === "topBottom" || e.kind === "colorScale" && e.range === "auto" || e.kind === "dataBar" && e.range === "auto";
3383
+ }
3384
+ function B(e) {
3385
+ if (typeof e == "number")
3386
+ return Number.isFinite(e) ? e : null;
3387
+ if (typeof e == "string" && e.trim() !== "") {
3388
+ const t = Number(e);
3389
+ return Number.isFinite(t) ? t : null;
3390
+ }
3391
+ return null;
3392
+ }
3393
+ function mo(e) {
3394
+ return $(e) ? e : B(e);
3395
+ }
3396
+ function Qs(e) {
3397
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
3398
+ for (const r of e)
3399
+ $(r) ? n.add(r.value) : t.add(r);
3400
+ return {
3401
+ has: (r) => $(r) ? n.has(r.value) : t.has(r)
3402
+ };
3403
+ }
3404
+ function Rt(e, t) {
3405
+ return typeof e == "number" && typeof t == "number" ? Math.sign(e - t) : Jt(
3406
+ typeof e == "number" ? Ne(String(e)) : e.value,
3407
+ typeof t == "number" ? Ne(String(t)) : t.value
3408
+ );
3409
+ }
3410
+ function po(e) {
3411
+ return e == null || e === "";
3412
+ }
3413
+ function ho(e, t, n) {
3414
+ return !Number.isFinite(e) || !Number.isFinite(t) || !Number.isFinite(n) ? 0 : n === t ? e >= n ? 1 : 0 : Math.max(0, Math.min(1, (e - t) / (n - t)));
3415
+ }
3416
+ function go(e) {
3417
+ switch (e) {
3418
+ case "bold":
3419
+ return 700;
3420
+ case "semibold":
3421
+ return 600;
3422
+ case "medium":
3423
+ return 500;
3424
+ case "normal":
3425
+ return 400;
3426
+ default:
3427
+ return;
3428
+ }
3429
+ }
3430
+ function yo(e) {
3431
+ return e ? On({
3432
+ fontWeight: go(e.fontWeight),
3433
+ fontStyle: e.italic ? "italic" : void 0,
3434
+ color: e.textColor,
3435
+ backgroundColor: e.backgroundColor,
3436
+ textDecoration: e.textDecoration
3437
+ }) : {};
3438
+ }
3439
+ function Mn(...e) {
3440
+ return Object.assign(
3441
+ {},
3442
+ ...e.filter((t) => !!t).map(On)
3443
+ );
3444
+ }
3445
+ function On(e) {
3446
+ return Object.fromEntries(
3447
+ Object.entries(e).filter(([, t]) => t !== void 0)
3448
+ );
3449
+ }
3450
+ function bo(e, t, n) {
3451
+ if ($(e) || $(n)) {
3452
+ const s = he(e, n);
3453
+ if (s === null) return t === "neq";
3454
+ switch (t) {
3455
+ case "eq":
3456
+ return s === 0;
3457
+ case "neq":
3458
+ return s !== 0;
3459
+ case "gt":
3460
+ return s > 0;
3461
+ case "gte":
3462
+ return s >= 0;
3463
+ case "lt":
3464
+ return s < 0;
3465
+ case "lte":
3466
+ return s <= 0;
3467
+ }
3468
+ }
3469
+ const r = B(e), i = B(n), a = r ?? String(e ?? ""), o = i ?? String(n ?? "");
3470
+ switch (t) {
3471
+ case "eq":
3472
+ return a === o;
3473
+ case "neq":
3474
+ return a !== o;
3475
+ case "gt":
3476
+ return a > o;
3477
+ case "gte":
3478
+ return a >= o;
3479
+ case "lt":
3480
+ return a < o;
3481
+ case "lte":
3482
+ return a <= o;
3483
+ }
3484
+ }
3485
+ function vo(e, t, n, r) {
3486
+ var a;
3487
+ const i = t[e.column];
3488
+ switch (e.kind) {
3489
+ case "comparison":
3490
+ return bo(i, e.operator, e.value);
3491
+ case "between": {
3492
+ if ([i, e.min, e.max].some($)) {
3493
+ const c = he(i, e.min), u = he(i, e.max);
3494
+ return c === null || u === null ? !1 : e.inclusive === !1 ? c > 0 && u < 0 : c >= 0 && u <= 0;
3495
+ }
3496
+ const o = B(i), s = B(e.min), l = B(e.max);
3497
+ return o === null || s === null || l === null ? !1 : e.inclusive === !1 ? o > s && o < l : o >= s && o <= l;
3498
+ }
3499
+ case "blank":
3500
+ return po(i) === e.isBlank;
3501
+ case "contains": {
3502
+ const o = $(i) ? i.value : String(i ?? ""), s = e.value, l = e.caseSensitive ? o : o.toLocaleLowerCase(), c = e.caseSensitive ? s : s.toLocaleLowerCase();
3503
+ return e.exact ? l === c : l.includes(c);
3504
+ }
3505
+ case "topBottom":
3506
+ return ((a = n.topBottom[r]) == null ? void 0 : a.has(i)) ?? !1;
3507
+ case "colorScale":
3508
+ case "dataBar":
3509
+ return !n.unavailableRuleIds.has(r);
3510
+ }
3511
+ }
3512
+ function Fo(e, t) {
3513
+ var n;
3514
+ return !((n = e.target.tableParts) != null && n.length) || e.target.tableParts.includes(t);
3515
+ }
3516
+ function Co(e, t) {
3517
+ const n = e.target.columns;
3518
+ return e.target.level === "row" ? !(n != null && n.length) || n.includes(t) : n != null && n.length ? n.includes(t) : t === e.condition.column;
3519
+ }
3520
+ function Io(e, t, n) {
3521
+ var r, i;
3522
+ if (e.condition.kind === "colorScale") {
3523
+ const a = n.numericRanges[e.id];
3524
+ if (!a) return {};
3525
+ const o = t[e.condition.column], s = At(
3526
+ o,
3527
+ a.min,
3528
+ a.max
3529
+ );
3530
+ if (!s)
3531
+ return {};
3532
+ const l = a.mid, c = l !== void 0 && $(o) ? he(o, l) : l === void 0 ? null : Math.sign(B(o) - l);
3533
+ return { cellStyle: { backgroundColor: l !== void 0 && e.condition.colors.mid ? c < 0 ? e.condition.colors.min : c === 0 ? e.condition.colors.mid : e.condition.colors.max : s.midpointComparison < 0 ? e.condition.colors.min : e.condition.colors.max } };
3534
+ }
3535
+ if (e.condition.kind === "dataBar") {
3536
+ const a = n.numericRanges[e.id];
3537
+ if (!a) return {};
3538
+ const o = e.condition.range === "auto" && Rt(a.min, 0) > 0 && Rt(a.max, 0) > 0 ? 0 : a.min, s = At(
3539
+ t[e.condition.column],
3540
+ o,
3541
+ a.max
3542
+ );
3543
+ return s ? {
3544
+ overlay: {
3545
+ kind: "dataBar",
3546
+ color: e.condition.color,
3547
+ ratio: s.ratio,
3548
+ showValue: e.condition.showValue !== !1
3549
+ }
3550
+ } : {};
3551
+ }
3552
+ return {
3553
+ cellStyle: Mn(
3554
+ yo(e.style),
3555
+ (r = e.style) != null && r.textColor ? { color: e.style.textColor } : void 0
3556
+ ),
3557
+ overlay: (i = e.style) != null && i.icon ? {
3558
+ kind: "icon",
3559
+ icon: e.style.icon
3560
+ } : void 0
3561
+ };
3562
+ }
3563
+ function xo(e) {
3564
+ const t = {
3565
+ matchedRuleIds: []
3566
+ };
3567
+ for (const n of e.rules) {
3568
+ if (n.target.matrix !== void 0 || n.enabled === !1 || !Fo(n, e.tablePart) || !Co(n, e.columnKey) || !vo(n.condition, e.row, e.range, n.id))
3569
+ continue;
3570
+ const r = Io(n, e.row, e.range), i = n.target.level === "row" ? "rowStyle" : "cellStyle";
3571
+ t[i] = Mn(
3572
+ t[i],
3573
+ r.cellStyle
3574
+ ), r.overlay && (t.overlay = r.overlay), t.matchedRuleIds.push(n.id);
3575
+ }
3576
+ return t;
3577
+ }
3578
+ const se = Object.freeze({}), ke = "value";
3579
+ function So() {
3580
+ return { numericRanges: {}, topBottom: {}, unavailableRuleIds: /* @__PURE__ */ new Set() };
3581
+ }
3582
+ function Ys(e, t) {
3583
+ var l;
3584
+ const n = qr(e);
3585
+ if (!n.length) return se;
3586
+ const r = (l = zr(e)) == null ? void 0 : l.value;
3587
+ if (!r) return se;
3588
+ const i = (c) => Ft(c) === Ft(r), a = n.filter((c) => i(c.condition.column)).map((c) => Ur(c, (u) => i(u) ? ke : ""));
3589
+ if (!a.length) return se;
3590
+ const o = xo({
3591
+ rules: a,
3592
+ row: { [ke]: t },
3593
+ columnKey: ke,
3594
+ range: So(),
3595
+ tablePart: "body"
3596
+ }), s = { ...o.rowStyle, ...o.cellStyle };
3597
+ return s.color || s.backgroundColor ? { ...s.color ? { color: s.color } : {}, ...s.backgroundColor ? { backgroundColor: s.backgroundColor } : {} } : se;
3598
+ }
3599
+ function Js(e, t) {
3600
+ var i, a;
3601
+ const n = (i = t == null ? void 0 : t.find(
3602
+ (o) => o.filterId === e.id
3603
+ )) == null ? void 0 : i.name, r = /* @__PURE__ */ new Set([
3604
+ e.column,
3605
+ ...((a = e.targetColumns) == null ? void 0 : a.map((o) => o.column)) ?? []
3606
+ ]);
3607
+ return n && r.has(n) ? n : e.column;
3608
+ }
3609
+ function Xs(e, t, n) {
3610
+ const r = jr({ card: e, stated: t, context: n });
3611
+ return r.ok ? { ok: !0, card: r.update ? Gr(e, r.update).card : e, warnings: r.warnings } : r;
3612
+ }
3613
+ function Zs({
3614
+ resolvedCardConfig: e,
3615
+ card: t,
3616
+ row: n,
3617
+ columnKeyMap: r,
3618
+ temporalPresentation: i,
3619
+ rawTemporalPresentation: a
3620
+ }) {
3621
+ const o = e || t.config, { groupByColumns: s = [], metricColumns: l = [], detailColumns: c = [] } = o || {}, u = t.type === "detailTable", f = u ? "detail" : "groupby", d = u ? c : s, m = u ? [] : l, h = [];
3622
+ for (const p of d) {
3623
+ const y = r ? Pe(r, p.id, f) : void 0, C = (y == null ? void 0 : y.outputKey) || (y == null ? void 0 : y.rawKey) || p.label, v = n.getValue(C), F = i == null ? void 0 : i.byColumnKey.get(C);
3624
+ if (v == null && F)
3625
+ h.push({
3626
+ field: p,
3627
+ operator: "isNull",
3628
+ value: null,
3629
+ ...F ? { label: "(Blank)", temporalBucket: F.metadata } : {}
3630
+ });
3631
+ else if (v != null) {
3632
+ const g = F || a == null ? void 0 : a.byColumnKey.get(C);
3633
+ h.push({
3634
+ field: p,
3635
+ operator: "=",
3636
+ value: String(v),
3637
+ // Convert to string for consistency
3638
+ ...F ? {
3639
+ label: Hr({
3640
+ value: String(v),
3641
+ presentation: F
3642
+ }),
3643
+ temporalBucket: F.metadata
3644
+ } : {},
3645
+ ...g ? {
3646
+ label: Wr({ value: String(v), presentation: g }).label,
3647
+ rawTemporal: { ...g.metadata, tz: g.format.calendarTimezone }
3648
+ } : {}
3649
+ });
3650
+ }
3651
+ }
3652
+ if (h.length === 0)
3653
+ return;
3654
+ const b = [];
3655
+ for (const p of m) {
3656
+ const y = r ? Pe(r, p.id, "metric") : void 0, C = n.getValue(
3657
+ (y == null ? void 0 : y.outputKey) || (y == null ? void 0 : y.rawKey) || p.label
3658
+ );
3659
+ C != null && b.push({
3660
+ field: p,
3661
+ value: Number(C)
3662
+ // Convert to number for metrics
3663
+ });
3664
+ }
3665
+ return {
3666
+ conditions: h,
3667
+ // Only include metrics if we have at least one
3668
+ metrics: b.length > 0 ? b : void 0
3669
+ };
3670
+ }
3671
+ function el({
3672
+ resolvedCardConfig: e,
3673
+ card: t,
3674
+ columnId: n,
3675
+ columnKeyMap: r
3676
+ }) {
3677
+ const i = e || t.config, a = t.type === "detailTable", o = a ? "detail" : "groupby";
3678
+ return ((a ? i == null ? void 0 : i.detailColumns : i == null ? void 0 : i.groupByColumns) || []).find((l) => {
3679
+ const c = r ? Pe(r, l.id, o) : void 0;
3680
+ return ((c == null ? void 0 : c.outputKey) || (c == null ? void 0 : c.rawKey) || l.label) === n;
3681
+ });
3682
+ }
3683
+ const wo = {
3684
+ noFields: "There is nothing to filter by here.",
3685
+ clickedColumnNotFilterable: "This column cannot filter other cards.",
3686
+ noChosenColumns: "This column is not set up to filter other cards.",
3687
+ fieldNotFilterable: "This value cannot filter other cards.",
3688
+ unsupportedCondition: "This value cannot filter other cards."
3689
+ };
3690
+ function Me(e) {
3691
+ return { status: "unavailable", code: e, reason: wo[e] };
3692
+ }
3693
+ function tl(e) {
3694
+ const t = e.conditions.filter(
3695
+ (s) => s.field.role !== "metric"
3696
+ );
3697
+ if (!t.length) return Me("noFields");
3698
+ const n = (s) => {
3699
+ if (s.operator !== "=" && s.operator !== "isNull")
3700
+ return "unsupportedCondition";
3701
+ const l = Ct(
3702
+ s.field,
3703
+ e.sourceIndex
3704
+ );
3705
+ if (!l) return "fieldNotFilterable";
3706
+ const c = s.operator === "isNull" || s.value === null;
3707
+ return {
3708
+ field: l,
3709
+ operator: c ? "isNull" : "=",
3710
+ value: c ? null : s.value,
3711
+ ...s.label ? { label: s.label } : {},
3712
+ ...s.temporalBucket ? { temporalBucket: s.temporalBucket } : {},
3713
+ ...s.rawTemporal ? { rawTemporal: s.rawTemporal } : {}
3714
+ };
3715
+ }, r = e.settings.fields, i = [];
3716
+ if (r.kind === "wholeRow")
3717
+ for (const s of t) {
3718
+ const l = n(s);
3719
+ if (typeof l == "string") return Me(l);
3720
+ i.push(l);
3721
+ }
3722
+ else {
3723
+ const s = r.kind === "clickedCell" && e.clickedField ? Ct(e.clickedField, e.sourceIndex) : void 0, l = r.kind === "chosenColumns" ? r.clickedFieldKeys : s ? [Se(s)] : [];
3724
+ for (const c of t) {
3725
+ const u = n(c);
3726
+ typeof u != "string" && l.includes(Se(u.field)) && i.push(u);
3727
+ }
3728
+ if (!i.length)
3729
+ return Me(
3730
+ r.kind === "clickedCell" ? "clickedColumnNotFilterable" : "noChosenColumns"
3731
+ );
3732
+ }
3733
+ const a = /* @__PURE__ */ new Set();
3734
+ return { status: "ready", tuple: { conditions: i.filter((s) => {
3735
+ const l = Se(s.field);
3736
+ return a.has(l) ? !1 : (a.add(l), !0);
3737
+ }) } };
3738
+ }
3739
+ function nl(e, t) {
3740
+ const n = e.answers.relationshipIds;
3741
+ return !n || !t ? !n && !t : n.length === t.length && n.every((r, i) => t[i] === r);
3742
+ }
3743
+ const To = /* @__PURE__ */ new Set([
3744
+ "dataset_not_reachable",
3745
+ "field_not_resolvable",
3746
+ "missing_metadata",
3747
+ "unsupported_calculated_filter",
3748
+ "relationship_unsupported",
3749
+ "relationship_missing",
3750
+ "relationship_ambiguous"
3751
+ ]);
3752
+ function L(e) {
3753
+ return !!e && typeof e == "object" && !Array.isArray(e);
3754
+ }
3755
+ function Do(e) {
3756
+ if (L(e))
3757
+ switch (e.status) {
3758
+ case "applied": {
3759
+ const t = Xt(e.route);
3760
+ return t ? { status: "applied", route: t } : void 0;
3761
+ }
3762
+ case "skipped":
3763
+ return typeof e.reason == "string" && To.has(e.reason) ? { status: "skipped", reason: e.reason } : void 0;
3764
+ case "needsPath":
3765
+ return { status: "needsPath" };
3766
+ case "blocked":
3767
+ return typeof e.message == "string" ? { status: "blocked", message: e.message } : void 0;
3768
+ case "kept":
3769
+ return { status: "kept" };
3770
+ case "notRelationship":
3771
+ return { status: "notRelationship" };
3772
+ default:
3773
+ return;
3774
+ }
3775
+ }
3776
+ function Nn(e) {
3777
+ if (e !== void 0)
3778
+ return Array.isArray(e) && e.length > 0 && e.every((t) => typeof t == "string" && t.length > 0) ? e : null;
3779
+ }
3780
+ function ko(e) {
3781
+ if (!L(e)) return;
3782
+ const t = Xt(e.route), n = e.target;
3783
+ if (!(!t || !L(n) || n.kind !== "relationship" || !L(n.field) || typeof n.field.name != "string" || !L(n.field.source) || n.field.source.kind !== "semantic" || !Nn(n.relationshipIds)))
3784
+ return { route: t, target: n };
3785
+ }
3786
+ function rl(e) {
3787
+ if (!L(e) || !Array.isArray(e.previews)) return { previews: [] };
3788
+ const t = [];
3789
+ for (const r of e.previews) {
3790
+ if (!L(r) || typeof r.cardId != "string" || !r.cardId || !L(r.answers)) continue;
3791
+ const i = Nn(r.answers.relationshipIds), a = Do(r.outcome), o = Array.isArray(r.paths) ? r.paths.map(ko) : [];
3792
+ i === null || !a || !o.every(Boolean) || a.status === "needsPath" && o.length < 2 || t.push({
3793
+ cardId: r.cardId,
3794
+ answers: i ? { relationshipIds: i } : {},
3795
+ outcome: a,
3796
+ paths: o
3797
+ });
3798
+ }
3799
+ const n = L(e.manageRelationships) && typeof e.manageRelationships.href == "string" ? { href: e.manageRelationships.href } : void 0;
3800
+ return { previews: t, ...n ? { manageRelationships: n } : {} };
3801
+ }
3802
+ const ue = (e) => (e == null ? void 0 : e.label) || (e == null ? void 0 : e.name) || "";
3803
+ function Mo(e) {
3804
+ return !e || /s$/i.test(e) ? e : /[^aeiou]y$/i.test(e) ? `${e.slice(0, -1)}ies` : `${e}s`;
3805
+ }
3806
+ function il(e) {
3807
+ if (e.direction === "to_many") {
3808
+ const n = ue(e.matchingDataset ?? e.datasets[e.datasets.length - 1]);
3809
+ return `${e.base ? Mo(ue(e.base)) : "Rows"} with at least one matching ${n}`;
3810
+ }
3811
+ return `through ${(e.datasets.length > 1 ? e.datasets.slice(0, -1) : e.datasets).map(ue).join(", ")}`;
3812
+ }
3813
+ const al = "The relationship this card used changed; choose it again";
3814
+ function ol(e, t) {
3815
+ switch (e) {
3816
+ case "relationship_missing":
3817
+ return t ? `Not related to ${ue(t)}` : "Not related to this card";
3818
+ case "relationship_ambiguous":
3819
+ return "Connects through more than one path";
3820
+ case "relationship_unsupported":
3821
+ return "Can't be applied to this card";
3822
+ case "dataset_not_reachable":
3823
+ case "field_not_resolvable":
3824
+ case "missing_metadata":
3825
+ case "unsupported_calculated_filter":
3826
+ return "No matching field on this card";
3827
+ default:
3828
+ return String(e);
3829
+ }
3830
+ }
3831
+ export {
3832
+ vs as $,
3833
+ Us as A,
3834
+ js as B,
3835
+ xo as C,
3836
+ Ys as D,
3837
+ Xs as E,
3838
+ nl as F,
3839
+ rl as G,
3840
+ Mo as H,
3841
+ il as I,
3842
+ ol as J,
3843
+ et as K,
3844
+ na as L,
3845
+ Oi as M,
3846
+ da as N,
3847
+ Ni as O,
3848
+ ye as P,
3849
+ es as Q,
3850
+ al as R,
3851
+ Is as S,
3852
+ Sa as T,
3853
+ Fs as U,
3854
+ Y as V,
3855
+ Jo as W,
3856
+ me as X,
3857
+ ha as Y,
3858
+ ga as Z,
3859
+ xa as _,
3860
+ ys as a,
3861
+ Xa as a$,
3862
+ Ns as a0,
3863
+ ki as a1,
3864
+ Ti as a2,
3865
+ Di as a3,
3866
+ ps as a4,
3867
+ Qe as a5,
3868
+ rs as a6,
3869
+ cs as a7,
3870
+ ds as a8,
3871
+ us as a9,
3872
+ Qo as aA,
3873
+ Zt as aB,
3874
+ _i as aC,
3875
+ Ge as aD,
3876
+ ts as aE,
3877
+ ns as aF,
3878
+ pe as aG,
3879
+ ie as aH,
3880
+ Yo as aI,
3881
+ el as aJ,
3882
+ ss as aK,
3883
+ ka as aL,
3884
+ ws as aM,
3885
+ $s as aN,
3886
+ kn as aO,
3887
+ Es as aP,
3888
+ Za as aQ,
3889
+ re as aR,
3890
+ Ze as aS,
3891
+ Ps as aT,
3892
+ Vs as aU,
3893
+ As as aV,
3894
+ Qa as aW,
3895
+ ao as aX,
3896
+ Bs as aY,
3897
+ Ls as aZ,
3898
+ Rs as a_,
3899
+ We as aa,
3900
+ Wi as ab,
3901
+ ls as ac,
3902
+ fs as ad,
3903
+ Ki as ae,
3904
+ Ji as af,
3905
+ Xi as ag,
3906
+ ms as ah,
3907
+ K as ai,
3908
+ Re as aj,
3909
+ Hi as ak,
3910
+ is as al,
3911
+ as as am,
3912
+ os as an,
3913
+ fn as ao,
3914
+ Gs as ap,
3915
+ Mn as aq,
3916
+ yo as ar,
3917
+ Ws as as,
3918
+ Hs as at,
3919
+ mo as au,
3920
+ Rt as av,
3921
+ Qs as aw,
3922
+ Zo as ax,
3923
+ ra as ay,
3924
+ wi as az,
3925
+ Os as b,
3926
+ Cs as b0,
3927
+ ma as b1,
3928
+ Gi as b2,
3929
+ qs as b3,
3930
+ _t as b4,
3931
+ Ia as b5,
3932
+ io as b6,
3933
+ ne as b7,
3934
+ Ds as b8,
3935
+ Ts as b9,
3936
+ xs as ba,
3937
+ Ms as bb,
3938
+ ks as bc,
3939
+ Ss as bd,
3940
+ Xo as be,
3941
+ bs as c,
3942
+ _s as d,
3943
+ eo as e,
3944
+ Ma as f,
3945
+ Js as g,
3946
+ Oa as h,
3947
+ Zs as i,
3948
+ Ii as j,
3949
+ Ho as k,
3950
+ ia as l,
3951
+ oa as m,
3952
+ sa as n,
3953
+ hs as o,
3954
+ la as p,
3955
+ ca as q,
3956
+ Ks as r,
3957
+ tl as s,
3958
+ gs as t,
3959
+ ua as u,
3960
+ so as v,
3961
+ lo as w,
3962
+ co as x,
3963
+ zs as y,
3964
+ Pt as z
3965
+ };