react-semaphor 0.1.559 → 0.1.561

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