react-semaphor 0.1.564 → 0.1.566

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 (138) hide show
  1. package/DATA_APP_SDK.md +3 -3
  2. package/README.md +2 -2
  3. package/dist/analytics-protocol/index.js +8 -8
  4. package/dist/assistant-context/index.js +3 -2
  5. package/dist/brand-studio/index.js +28 -29
  6. package/dist/briefings/index.js +53 -49
  7. package/dist/chunks/{assistant-chat-D1BEEHUF.js → assistant-chat-DNKAYSQL.js} +204 -204
  8. package/dist/chunks/{bookmark-impact-XOsVUAqW.js → bookmark-impact-BeUbq0jc.js} +2 -2
  9. package/dist/chunks/bookmark-state-ByODVqee.js +1613 -0
  10. package/dist/chunks/card-filter-builder-SXaRWbKr.js +4100 -0
  11. package/dist/chunks/{switch-BW4yXSYs.js → code-editor-DJNOsgJH.js} +463 -442
  12. package/dist/chunks/{comparison-window-caption-D1EUXzaR.js → comparison-window-caption-CMLb3mut.js} +451 -419
  13. package/dist/chunks/{dashboard-DfYsASNd.js → dashboard-Cni7nGhg.js} +1 -1
  14. package/dist/chunks/dashboard-briefing-launcher-CXeXRTem.js +4910 -0
  15. package/dist/chunks/{dashboard-controls-CJ8Dz50D.js → dashboard-controls-CsqKybrf.js} +685 -675
  16. package/dist/chunks/{dashboard-json-D3uZxGO-.js → dashboard-json-WWmw3Piu.js} +4 -4
  17. package/dist/chunks/{dates-EvDtT25n.js → dates-DJRUS-he.js} +12 -12
  18. package/dist/chunks/{edit-dashboard-visual-CgHJXBQv.js → edit-dashboard-visual-BrIEaBhc.js} +7724 -10341
  19. package/dist/chunks/filter-reach-copy-D5LqgrUf.js +4667 -0
  20. package/dist/chunks/{filter-value-text-CPwFkrMz.js → filter-value-text-7zhmth1S.js} +2 -2
  21. package/dist/chunks/{index-CAgf2x4E.js → index-Bq9UbCGk.js} +653 -574
  22. package/dist/chunks/{layout-grid-BM65viQh.js → layout-grid-0hIlqEtk.js} +1 -1
  23. package/dist/chunks/{list-filter-BoeLBfL3.js → list-filter-DkgoCeBm.js} +1 -1
  24. package/dist/chunks/{matrix-analytical-definition-hEucouWM.js → matrix-analytical-definition-C9xB_T84.js} +18 -18
  25. package/dist/chunks/{matrix-card-CCh9JjP1.js → matrix-card-BSUeSXpD.js} +2 -2
  26. package/dist/chunks/{matrix-member-presentation-DsAUbuoL.js → matrix-member-presentation-DZNgQpUq.js} +1 -1
  27. package/dist/chunks/{matrix-operation-contract-DsLdFdSa.js → matrix-operation-contract-Eb6elidS.js} +1 -1
  28. package/dist/chunks/{metric-comparison-Bnso1cm1.js → metric-comparison-ChXUFaZu.js} +1 -1
  29. package/dist/chunks/{palette-p1XSJFgB.js → palette-4vf2BEEg.js} +1 -1
  30. package/dist/chunks/{pivot-result-contract-expectations-B53jqszr.js → pivot-result-contract-expectations-Ddh1rNz5.js} +4 -4
  31. package/dist/chunks/{pivot-result-identity-Dq5jm-EC.js → pivot-result-identity-BlbLrqaC.js} +1 -1
  32. package/dist/chunks/{report-preferences-dialog-DMqxSU4X.js → report-preferences-dialog-CeHioJwL.js} +122 -131
  33. package/dist/chunks/{report-runtime-context-BITkNSDa.js → report-runtime-context-DnA_PiKo.js} +1 -1
  34. package/dist/chunks/resolve-dashboard-input-context-CwS-2r-b.js +21419 -0
  35. package/dist/chunks/{save-CHV1B1fL.js → save-D6pHmSSP.js} +1 -1
  36. package/dist/chunks/saved-dashboard-context-c-MZZTx2.js +629 -0
  37. package/dist/chunks/{selection-reducer-Bz5aywT4.js → selection-reducer-OaJ-N5uN.js} +1 -1
  38. package/dist/chunks/{semaphor-ready-indicator-CFeCIuaw.js → semaphor-ready-indicator-B2NpYRE-.js} +81034 -80950
  39. package/dist/chunks/{shelf-drop-preview-context-cEyVkKTF.js → shelf-drop-preview-context-DM7yypwC.js} +407 -407
  40. package/dist/chunks/{source-entity-resolution-DdDVXFB8.js → source-entity-resolution-DF6GulDn.js} +1 -1
  41. package/dist/chunks/stored-dashboard-DTWc2pzt.js +5026 -0
  42. package/dist/chunks/{table-export-sheet-bSXxGn-v.js → table-export-sheet--DUKWk6o.js} +1 -1
  43. package/dist/chunks/{temporal-input-presentation-sk9gqLi6.js → temporal-input-presentation--2r9BLr0.js} +392 -377
  44. package/dist/chunks/{token-types-BUK06hU2.js → token-types-C8JymO8s.js} +1 -1
  45. package/dist/chunks/{upload-BnmuyPqW.js → upload-Cf3wXZT8.js} +1 -1
  46. package/dist/chunks/{validators-BIM0FE31.js → validators-wtjw0aw6.js} +7 -7
  47. package/dist/chunks/variable-draft-DFizFCJu.js +241 -0
  48. package/dist/dashboard/index.js +2 -2
  49. package/dist/dashboard-authoring/index.js +2324 -1796
  50. package/dist/data-app-sdk/index.js +4 -4
  51. package/dist/data-app-sdk-adapters/index.js +2 -2
  52. package/dist/data-app-sdk-validation/index.js +5 -5
  53. package/dist/format-utils/index.js +174 -167
  54. package/dist/index.js +189 -187
  55. package/dist/pdf-export-policy/index.js +80 -28
  56. package/dist/pdf-table-layout/index.js +65 -65
  57. package/dist/report-runtime-context/index.js +1 -1
  58. package/dist/style.css +1 -1
  59. package/dist/surfboard/index.js +2 -2
  60. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  61. package/dist/types/briefings/delivery-outcome.d.ts +37 -0
  62. package/dist/types/briefings/index.d.ts +2 -0
  63. package/dist/types/briefings/run-outcomes.d.ts +6 -0
  64. package/dist/types/components/briefings/briefing-author/run-model.d.ts +9 -0
  65. package/dist/types/components/dashboard-variables/data-variables-menu.d.ts +8 -0
  66. package/dist/types/components/dashboard-variables/variable-editor-host.d.ts +1 -0
  67. package/dist/types/components/index.d.ts +2 -0
  68. package/dist/types/index.js +5 -5
  69. package/dist/types/lib/dashboard-inputs/build-normalized-dashboard-inputs.d.ts +62 -0
  70. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +33 -2
  71. package/dist/types/lib/dashboard-inputs/filter-settings.d.ts +7 -2
  72. package/dist/types/lib/dashboard-inputs/prepare-loaded-dashboard.d.ts +4 -2
  73. package/dist/types/lib/dashboard-variables/data-text.d.ts +33 -0
  74. package/dist/types/lib/dashboard-variables/types.d.ts +207 -0
  75. package/dist/types/lib/document/document-edits.d.ts +16 -1
  76. package/dist/types/lib/document/document-panel-target.d.ts +1 -1
  77. package/dist/types/lib/document/document-section-query-options.d.ts +29 -0
  78. package/dist/types/lib/document/document-table-data-policy.d.ts +0 -1
  79. package/dist/types/lib/hooks/use-dashboard-frame-query.d.ts +92 -0
  80. package/dist/types/lib/query-context/build-card-query-context.d.ts +6 -0
  81. package/dist/types/lib/query-context/dashboard-filter-mapping-resolution.d.ts +15 -3
  82. package/dist/types/lib/query-context/describe-card-execution-snapshot.d.ts +1 -0
  83. package/dist/types/lib/query-context/use-semantic-execution-payload-for-cards.d.ts +24 -0
  84. package/dist/types/lib/stores/dashboard-store.d.ts +36 -0
  85. package/dist/types/lib/text-variables/temporal-input-text.d.ts +28 -0
  86. package/dist/types/lib/text-variables/text-variable-types.d.ts +72 -0
  87. package/dist/types/lib/types/common-types.d.ts +155 -51
  88. package/dist/types/lib/utils/card-definition.d.ts +2 -2
  89. package/dist/types/shared/assistant-context/index.d.ts +1 -1
  90. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +51 -1
  91. package/dist/types/shared/dashboard-authoring/card-query-request.d.ts +7 -1
  92. package/dist/types/shared/dashboard-authoring/card-settings/resolve-card-highlights.d.ts +10 -0
  93. package/dist/types/shared/dashboard-authoring/changes/card-query-part.d.ts +1 -0
  94. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +1087 -430
  95. package/dist/types/shared/dashboard-authoring/changes/diagnostics.d.ts +20 -1
  96. package/dist/types/shared/dashboard-authoring/changes/resolve-dashboard-changes.d.ts +1 -1
  97. package/dist/types/shared/dashboard-authoring/conditional-formatting/kpi.d.ts +10 -0
  98. package/dist/types/shared/dashboard-authoring/conditional-formatting/schema.d.ts +40 -40
  99. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +16 -16
  100. package/dist/types/shared/dashboard-authoring/dashboard-card-source-index.d.ts +1 -0
  101. package/dist/types/shared/dashboard-authoring/dashboard-filter-sql-subscription.d.ts +24 -0
  102. package/dist/types/shared/dashboard-authoring/dashboard-filter-targets.d.ts +29 -0
  103. package/dist/types/shared/dashboard-authoring/dashboard-input-scope.d.ts +7 -4
  104. package/dist/types/shared/dashboard-authoring/dashboard-variable-card.d.ts +159 -0
  105. package/dist/types/shared/dashboard-authoring/dashboard-variable-changes.d.ts +61 -0
  106. package/dist/types/shared/dashboard-authoring/document-section-cards.d.ts +7 -0
  107. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +2 -0
  108. package/dist/types/shared/dashboard-authoring/filter-model/read-dashboard-filter-model.d.ts +10 -0
  109. package/dist/types/shared/dashboard-authoring/index.d.ts +6 -0
  110. package/dist/types/shared/dashboard-authoring/measure-calculations/comparison.d.ts +2 -0
  111. package/dist/types/shared/dashboard-authoring/operations/operation-sentences.d.ts +1 -1
  112. package/dist/types/shared/dashboard-authoring/operations/operation-types.d.ts +50 -3
  113. package/dist/types/shared/dashboard-authoring/outline/outline-dashboard.d.ts +48 -1
  114. package/dist/types/shared/dashboard-authoring/outline/outline-filters.d.ts +22 -6
  115. package/dist/types/shared/dashboard-authoring/text-card-words/blocks.d.ts +87 -13
  116. package/dist/types/shared/dashboard-authoring/text-card-words/chip-colors.d.ts +23 -0
  117. package/dist/types/shared/dashboard-authoring/text-card-words/index.d.ts +90 -8
  118. package/dist/types/shared/dashboard-authoring/text-card-words/rich-content.d.ts +31 -3
  119. package/dist/types/shared/dashboard-authoring/text-card-words/variable-words.d.ts +8 -0
  120. package/dist/types/shared/dashboard-authoring/variable-draft.d.ts +125 -0
  121. package/dist/types/shared/dashboard-authoring/variable-editability.d.ts +24 -0
  122. package/dist/types/shared/dashboard-authoring/variable-references.d.ts +39 -0
  123. package/dist/types/shared/format-utils/document-print.d.ts +4 -2
  124. package/dist/types/shared/format-utils/index.d.ts +1 -0
  125. package/dist/types/shared/format-utils/pdf-capacity-lines.d.ts +17 -0
  126. package/dist/types/shared/format-utils/pdf-delivery.d.ts +8 -1
  127. package/dist/types/shared/format-utils/pdf-export-policy.d.ts +74 -6
  128. package/dist/types/shared/format-utils/presentation-execution.d.ts +9 -0
  129. package/package.json +2 -2
  130. package/src/data-app-sdk/README.md +3 -3
  131. package/dist/chunks/bookmark-state-CWeoGbrx.js +0 -743
  132. package/dist/chunks/braces-DzgoQC64.js +0 -23
  133. package/dist/chunks/dashboard-briefing-launcher-lvYfJoUQ.js +0 -3878
  134. package/dist/chunks/filter-reach-copy-Cmb05jlE.js +0 -3965
  135. package/dist/chunks/global-date-filter-utils-ruJYwjgZ.js +0 -16733
  136. package/dist/chunks/resolve-dashboard-input-context-i_jCSYae.js +0 -8214
  137. package/dist/chunks/saved-dashboard-context-Dg3oDmH_.js +0 -564
  138. package/dist/chunks/use-create-flow-overlay-state-Dl6DCxh8.js +0 -1436
@@ -0,0 +1,5026 @@
1
+ import { gP as io, cs as so, bU as ao, aQ as lo, b9 as co, f as uo, bM as fo, M as oe, gQ as po, gR as Ne, d_ as Et, e1 as mo, bD as go, gS as yo, at as bo, fE as Bt, fG as Co, gT as _t, O as ho, fI as Io, cT as ve, s as _, fz as Fe, n as Le, gU as vo, cN as Rt, cP as Kt, cy as Fo, cS as So, cQ as mt, cR as To, b as Do, cA as Mo, cM as Vo, cK as ko, a2 as K, gd as Po, gV as Se, gW as qt, gX as xo, gY as je, gr as Te, gZ as wo, g_ as ze, g$ as Oo, h0 as Ao, h1 as Eo, h2 as Bo, h3 as _o, l as Ge, h4 as Ro, k as ee, r as Ko, h as qo, h5 as $, gG as He, h6 as me, h7 as Nt, h8 as No, h9 as Lo, ha as jo, g4 as zo, hb as Go, hc as Ho, e as Uo, hd as $o, he as Lt, $ as jt, hf as Qo, hg as Wo, hh as Yo, hi as zt, j as Ue, cj as Jo, a3 as Zo, o as Gt, ci as Xo, go as er, q as tr, t as gt, C as nr, hj as or, hk as rr, ck as ir, hl as sr } from "./resolve-dashboard-input-context-CwS-2r-b.js";
2
+ import { av as ar, H as re, a1 as lr, R as cr, I as Oe, S as ur, am as yt, q as Ht, aa as dr, v as fr } from "./validators-wtjw0aw6.js";
3
+ import { v as Ut } from "./matrix-operation-contract-Eb6elidS.js";
4
+ import { S as $e } from "./analytics-base-schemas-BaIQrEzX.js";
5
+ import { ZodError as pr } from "zod";
6
+ import "./index-CuHybtft.js";
7
+ import { canonicalizeSupportedCurrencyCode as $t } from "../value-format-preferences/index.js";
8
+ import "./_commonjsHelpers-DimLPMtv.js";
9
+ import { b as ge, r as mr, aW as gr, i as yr, aD as br, aA as bt } from "./temporal-input-presentation--2r9BLr0.js";
10
+ import { aA as Qt, aB as Wt, aC as ke, _ as Cr, aD as Yt, aE as Jt, az as Zt, aF as Xt, n as hr, u as en, t as j, aG as tn, k as nn, C as Ae, aH as H, y as ie, i as on, l as Ir, s as vr, B as Qe, aI as Fr, ag as Sr, D as rn, A as Tr, ay as Ct, M as sn, N as an, H as ln } from "./bookmark-state-ByODVqee.js";
11
+ import "./index-RNaTnE3m.js";
12
+ import "./context-R31TSL5V.js";
13
+ import { i as We, b as cn, r as Dr } from "./matrix-card-BSUeSXpD.js";
14
+ import { D as Mr } from "./report-runtime-context-DnA_PiKo.js";
15
+ import { r as Q, C as Vr } from "./metric-comparison-ChXUFaZu.js";
16
+ import { p as kr, d as Pr } from "./pivot-result-contract-expectations-Ddh1rNz5.js";
17
+ import { isPdfTableCardType as xr, PDF_CAPACITY as wr } from "../pdf-export-policy/index.js";
18
+ import { c as Or } from "./selection-filter-compiler-CUDRnUxc.js";
19
+ import { a as Ar, f as Er, b as Br } from "./matrix-analytical-definition-C9xB_T84.js";
20
+ import { r as _r } from "./pivot-result-identity-BlbLrqaC.js";
21
+ const Rr = (e, t) => {
22
+ const n = {};
23
+ if (e === null || t === null)
24
+ return t;
25
+ const o = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]);
26
+ for (const r of o) {
27
+ if (!(r in e) && r in t) {
28
+ n[r] = t[r];
29
+ continue;
30
+ }
31
+ if (r in e && !(r in t)) {
32
+ n[r] = void 0;
33
+ continue;
34
+ }
35
+ const i = e[r], s = t[r];
36
+ if (!Ee(i, s))
37
+ if (Array.isArray(i) && Array.isArray(s))
38
+ n[r] = s;
39
+ else if (ht(i) && ht(s)) {
40
+ const a = Rr(i, s);
41
+ Object.keys(a).length > 0 && (n[r] = a);
42
+ } else
43
+ n[r] = s;
44
+ }
45
+ return n;
46
+ }, Ee = (e, t) => {
47
+ if (e === t) return !0;
48
+ if (e && t && typeof e == "object" && typeof t == "object") {
49
+ if (Array.isArray(e) && Array.isArray(t))
50
+ return e.length !== t.length ? !1 : e.every((r, i) => Ee(r, t[i]));
51
+ const n = Object.keys(e), o = Object.keys(t);
52
+ return n.length !== o.length ? !1 : n.every((r) => Ee(e[r], t[r]));
53
+ }
54
+ return !1;
55
+ }, ht = (e) => e !== null && typeof e == "object" && !Array.isArray(e), ye = (e) => {
56
+ if (e === null || typeof e != "object")
57
+ return e;
58
+ if (e instanceof Date)
59
+ return new Date(e);
60
+ if (e instanceof RegExp)
61
+ return new RegExp(e);
62
+ if (Array.isArray(e))
63
+ return e.map((n) => ye(n));
64
+ const t = {};
65
+ for (const n in e)
66
+ Object.prototype.hasOwnProperty.call(e, n) && (t[n] = ye(e[n]));
67
+ return t;
68
+ }, Kr = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
69
+ function qr(e) {
70
+ return typeof e == "string" && Kr.test(e);
71
+ }
72
+ function Nr(e) {
73
+ if (!qr(e))
74
+ throw TypeError("Invalid UUID");
75
+ let t;
76
+ const n = new Uint8Array(16);
77
+ return n[0] = (t = parseInt(e.slice(0, 8), 16)) >>> 24, n[1] = t >>> 16 & 255, n[2] = t >>> 8 & 255, n[3] = t & 255, n[4] = (t = parseInt(e.slice(9, 13), 16)) >>> 8, n[5] = t & 255, n[6] = (t = parseInt(e.slice(14, 18), 16)) >>> 8, n[7] = t & 255, n[8] = (t = parseInt(e.slice(19, 23), 16)) >>> 8, n[9] = t & 255, n[10] = (t = parseInt(e.slice(24, 36), 16)) / 1099511627776 & 255, n[11] = t / 4294967296 & 255, n[12] = t >>> 24 & 255, n[13] = t >>> 16 & 255, n[14] = t >>> 8 & 255, n[15] = t & 255, n;
78
+ }
79
+ function Lr(e) {
80
+ e = unescape(encodeURIComponent(e));
81
+ const t = [];
82
+ for (let n = 0; n < e.length; ++n)
83
+ t.push(e.charCodeAt(n));
84
+ return t;
85
+ }
86
+ const jr = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", zr = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
87
+ function Gr(e, t, n) {
88
+ function o(r, i, s, a) {
89
+ var c;
90
+ if (typeof r == "string" && (r = Lr(r)), typeof i == "string" && (i = Nr(i)), ((c = i) === null || c === void 0 ? void 0 : c.length) !== 16)
91
+ throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
92
+ let l = new Uint8Array(16 + r.length);
93
+ if (l.set(i), l.set(r, i.length), l = n(l), l[6] = l[6] & 15 | t, l[8] = l[8] & 63 | 128, s) {
94
+ a = a || 0;
95
+ for (let u = 0; u < 16; ++u)
96
+ s[a + u] = l[u];
97
+ return s;
98
+ }
99
+ return io(l);
100
+ }
101
+ try {
102
+ o.name = e;
103
+ } catch {
104
+ }
105
+ return o.DNS = jr, o.URL = zr, o;
106
+ }
107
+ function Hr(e, t, n, o) {
108
+ switch (e) {
109
+ case 0:
110
+ return t & n ^ ~t & o;
111
+ case 1:
112
+ return t ^ n ^ o;
113
+ case 2:
114
+ return t & n ^ t & o ^ n & o;
115
+ case 3:
116
+ return t ^ n ^ o;
117
+ }
118
+ }
119
+ function Pe(e, t) {
120
+ return e << t | e >>> 32 - t;
121
+ }
122
+ function Ur(e) {
123
+ const t = [1518500249, 1859775393, 2400959708, 3395469782], n = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
124
+ if (typeof e == "string") {
125
+ const s = unescape(encodeURIComponent(e));
126
+ e = [];
127
+ for (let a = 0; a < s.length; ++a)
128
+ e.push(s.charCodeAt(a));
129
+ } else Array.isArray(e) || (e = Array.prototype.slice.call(e));
130
+ e.push(128);
131
+ const o = e.length / 4 + 2, r = Math.ceil(o / 16), i = new Array(r);
132
+ for (let s = 0; s < r; ++s) {
133
+ const a = new Uint32Array(16);
134
+ for (let c = 0; c < 16; ++c)
135
+ a[c] = e[s * 64 + c * 4] << 24 | e[s * 64 + c * 4 + 1] << 16 | e[s * 64 + c * 4 + 2] << 8 | e[s * 64 + c * 4 + 3];
136
+ i[s] = a;
137
+ }
138
+ i[r - 1][14] = (e.length - 1) * 8 / Math.pow(2, 32), i[r - 1][14] = Math.floor(i[r - 1][14]), i[r - 1][15] = (e.length - 1) * 8 & 4294967295;
139
+ for (let s = 0; s < r; ++s) {
140
+ const a = new Uint32Array(80);
141
+ for (let m = 0; m < 16; ++m)
142
+ a[m] = i[s][m];
143
+ for (let m = 16; m < 80; ++m)
144
+ a[m] = Pe(a[m - 3] ^ a[m - 8] ^ a[m - 14] ^ a[m - 16], 1);
145
+ let c = n[0], l = n[1], u = n[2], d = n[3], f = n[4];
146
+ for (let m = 0; m < 80; ++m) {
147
+ const g = Math.floor(m / 20), p = Pe(c, 5) + Hr(g, l, u, d) + f + t[g] + a[m] >>> 0;
148
+ f = d, d = u, u = Pe(l, 30) >>> 0, l = c, c = p;
149
+ }
150
+ n[0] = n[0] + c >>> 0, n[1] = n[1] + l >>> 0, n[2] = n[2] + u >>> 0, n[3] = n[3] + d >>> 0, n[4] = n[4] + f >>> 0;
151
+ }
152
+ return [n[0] >> 24 & 255, n[0] >> 16 & 255, n[0] >> 8 & 255, n[0] & 255, n[1] >> 24 & 255, n[1] >> 16 & 255, n[1] >> 8 & 255, n[1] & 255, n[2] >> 24 & 255, n[2] >> 16 & 255, n[2] >> 8 & 255, n[2] & 255, n[3] >> 24 & 255, n[3] >> 16 & 255, n[3] >> 8 & 255, n[3] & 255, n[4] >> 24 & 255, n[4] >> 16 & 255, n[4] >> 8 & 255, n[4] & 255];
153
+ }
154
+ const $r = Gr("v5", 80, Ur), It = /\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g, vt = /\bparam\s*\(\s*(['"])([^'"]+)\1/g;
155
+ function Qr(e) {
156
+ const t = [];
157
+ let n = 0;
158
+ for (; n < e.length; ) {
159
+ const o = e.indexOf("{{", n), r = e.indexOf("{%", n);
160
+ let i = -1, s = "";
161
+ if (o === -1 ? (i = r, s = "%}") : r === -1 || o < r ? (i = o, s = "}}") : (i = r, s = "%}"), i === -1)
162
+ break;
163
+ const a = e.indexOf(s, i + 2);
164
+ if (a === -1) {
165
+ n = i + 2;
166
+ continue;
167
+ }
168
+ t.push(e.slice(i + 2, a)), n = a + 2;
169
+ }
170
+ return t;
171
+ }
172
+ function un(e) {
173
+ var o, r;
174
+ if (!e)
175
+ return [];
176
+ const t = /* @__PURE__ */ new Set();
177
+ let n;
178
+ for (It.lastIndex = 0; (n = It.exec(e)) !== null; ) {
179
+ const i = (o = n[1]) == null ? void 0 : o.trim();
180
+ i && t.add(i);
181
+ }
182
+ for (const i of Qr(e))
183
+ for (vt.lastIndex = 0; (n = vt.exec(i)) !== null; ) {
184
+ const s = (r = n[2]) == null ? void 0 : r.trim();
185
+ s && t.add(s);
186
+ }
187
+ return Array.from(t);
188
+ }
189
+ function Ye(e) {
190
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
191
+ for (const o of e.controlBindings || [])
192
+ t.add(o.controlId), o.target === "sql_param" && n.set(o.paramId, o.controlId);
193
+ for (const o of un(e.sql))
194
+ t.add(n.get(o) ?? o);
195
+ return Array.from(t);
196
+ }
197
+ function Wr(e) {
198
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
199
+ for (const o of e.controlBindings || [])
200
+ o.target === "sql_param" && n.set(o.paramId, o.controlId);
201
+ for (const o of un(e.sql))
202
+ t.set(o, {
203
+ paramId: o,
204
+ controlId: n.get(o) ?? o
205
+ });
206
+ return Array.from(t.values());
207
+ }
208
+ function Yr(e, t) {
209
+ var r;
210
+ const n = (r = e.controlBindings) == null ? void 0 : r.map((i) => ({
211
+ ...i,
212
+ controlId: t.get(i.controlId) ?? i.controlId
213
+ })), o = Wr(e).flatMap(
214
+ ({ paramId: i, controlId: s }) => {
215
+ var c;
216
+ const a = t.get(s);
217
+ return !a || a === s || (c = e.controlBindings) != null && c.some(
218
+ (l) => l.target === "sql_param" && l.paramId === i
219
+ ) ? [] : [{ target: "sql_param", paramId: i, controlId: a }];
220
+ }
221
+ );
222
+ return o.length ? [...n ?? [], ...o] : n;
223
+ }
224
+ function dn(e, t) {
225
+ var s, a;
226
+ const n = ke(e) ?? e, o = n.source === "dashboardInputAlias" ? (s = t.inputAliases) == null ? void 0 : s[n.variableName] : void 0, r = n.source === "dashboardInputAlias" && o ? ke(o) ?? ke({ ...o, export: n.export ?? "label" }) ?? n : n, i = n.source === "dashboardInputAlias" && r !== n ? { ...r, export: n.export ?? "label" } : r;
227
+ return i.source === "input" ? {
228
+ ...i,
229
+ inputId: ((a = t.inputIds) == null ? void 0 : a[i.inputId]) ?? i.inputId
230
+ } : i;
231
+ }
232
+ function Jr(e, t) {
233
+ var r;
234
+ const n = {};
235
+ for (const i of [
236
+ "cardIds",
237
+ "sheetIds",
238
+ "inputIds",
239
+ "controlIds",
240
+ "filterIds"
241
+ ]) {
242
+ const s = { ...t[i] };
243
+ for (const [a, c] of Object.entries((e == null ? void 0 : e[i]) ?? {}))
244
+ s[a] = ((r = t[i]) == null ? void 0 : r[c]) ?? c;
245
+ Object.keys(s).length && (n[i] = s);
246
+ }
247
+ const o = { ...t.inputAliases };
248
+ for (const [i, s] of Object.entries((e == null ? void 0 : e.inputAliases) ?? {}))
249
+ o[i] = dn(s, t);
250
+ return Object.keys(o).length && (n.inputAliases = o), n;
251
+ }
252
+ function Ya(e, t) {
253
+ var r, i, s, a;
254
+ const n = ye(Qt(e));
255
+ n.controlBindings = Yr(
256
+ e,
257
+ new Map(Object.entries(t.controlIds ?? {}))
258
+ );
259
+ for (const c of n.controls ?? [])
260
+ c.id = ((r = t.controlIds) == null ? void 0 : r[c.id]) ?? c.id;
261
+ for (const c of n.inlineFilters ?? [])
262
+ c.id = ((i = t.filterIds) == null ? void 0 : i[c.id]) ?? c.id;
263
+ const o = (c) => {
264
+ var u, d;
265
+ if (!c || typeof c != "object") return;
266
+ if (Array.isArray(c)) {
267
+ c.forEach(o);
268
+ return;
269
+ }
270
+ const l = c;
271
+ if (Object.assign(
272
+ l,
273
+ Wt(
274
+ l,
275
+ (f) => f && typeof f == "object" ? dn(f, t) : f
276
+ )
277
+ ), typeof l.entityId == "string") {
278
+ const f = l.entityId;
279
+ l.fieldScope === "card" && (l.entityId = ((u = t.cardIds) == null ? void 0 : u[f]) ?? f), l.fieldScope === "sheet" && (l.entityId = ((d = t.sheetIds) == null ? void 0 : d[f]) ?? f);
280
+ }
281
+ for (const [f, m] of Object.entries(l))
282
+ f !== "linkedReferenceOverrides" && o(m);
283
+ };
284
+ o(n), n.clickToFilter && (n.clickToFilter = so(n.clickToFilter, t));
285
+ for (const c of Object.values(
286
+ ((s = n.customCardPreferences) == null ? void 0 : s.dataInputCardIds) ?? {}
287
+ ))
288
+ c.cardId = ((a = t.cardIds) == null ? void 0 : a[c.cardId]) ?? c.cardId;
289
+ return n;
290
+ }
291
+ const Zr = "9677efdd-86ec-4afb-b9bb-5ead8b5442af";
292
+ function Xr(e) {
293
+ let t = 0;
294
+ return () => $r(`${e}#${t++}`, Zr);
295
+ }
296
+ const ei = [
297
+ { code: "matrix_definition_incomplete", label: "Matrix definition" }
298
+ ], ti = [
299
+ { code: "connection_type_unresolved", label: "Connection type" }
300
+ ], X = (e) => !Array.isArray(e) || e.length === 0;
301
+ function ni(e) {
302
+ var i;
303
+ const t = e.config ?? {};
304
+ if ((i = e.sql) != null && i.trim() || !X(t.pivotByColumns)) return "matrixTable";
305
+ const n = !X(t.groupByColumns), o = !X(t.metricColumns), r = e.type === "pivotTable" && (n || o) && X(t.rowAggregates) && X(t.columnAggregates);
306
+ return n && !o || r ? "table" : "matrixTable";
307
+ }
308
+ function oi(e) {
309
+ var r;
310
+ const t = e.dataSource;
311
+ if (!t || (r = t.connectionType) != null && r.trim()) return e;
312
+ const n = ar(fo(t.selectedEntities));
313
+ if (!n) return e;
314
+ const o = Array.isArray(t.selectedEntities) ? t.selectedEntities.map((i) => i && typeof i == "object" && "connectionType" in i && !String(i.connectionType ?? "").trim() ? { ...i, connectionType: n } : i) : t.selectedEntities;
315
+ return { ...e, dataSource: { ...t, connectionType: n, selectedEntities: o } };
316
+ }
317
+ function fn(e) {
318
+ var s, a;
319
+ const t = e;
320
+ if (!ao(t)) return { status: "not_legacy", card: e };
321
+ const n = oi(t), o = ni(t) === "table" ? lo(n, "table") : co(n, "matrixTable", { createId: Xr(t.id) });
322
+ if (o.status !== "changed") throw new Error(`Card ${t.id} could not leave ${t.type}.`);
323
+ const r = o.card.type === "matrixTable" && uo(o.card).status !== "ready", i = !!n.dataSource && !((a = (s = n.dataSource) == null ? void 0 : s.connectionType) != null && a.trim());
324
+ return {
325
+ status: "routed",
326
+ card: o.card,
327
+ gaps: [
328
+ ...o.gaps,
329
+ ...r ? ei : [],
330
+ ...i ? ti : []
331
+ ]
332
+ };
333
+ }
334
+ function Ja(e) {
335
+ if (!e.cards) return e;
336
+ const t = e.cards.map((n) => fn(n).card);
337
+ return t.every((n, o) => n === e.cards[o]) ? e : { ...e, cards: t };
338
+ }
339
+ function ri(e) {
340
+ const t = [];
341
+ return { dashboard: Cr(e, (o, r) => {
342
+ const i = fn(o);
343
+ return i.status === "routed" && i.gaps.length && t.push({ location: r, gaps: i.gaps }), i.card;
344
+ }), routedWithGaps: t };
345
+ }
346
+ function ii(e, t) {
347
+ return e.name === t.name && e.qualifiedEntityName === t.qualifiedEntityName;
348
+ }
349
+ function si(e, t, n) {
350
+ var r, i;
351
+ if (n.sortPolicy === "dropUnrelatedSorts") {
352
+ const s = new Set(
353
+ (e.metricColumns || []).map((a) => a.id)
354
+ );
355
+ return {
356
+ ...e,
357
+ groupByColumns: [t],
358
+ sortByColumns: (e.sortByColumns || []).filter(
359
+ (a) => a.id === t.id || s.has(a.id)
360
+ )
361
+ };
362
+ }
363
+ const o = (r = e.groupByColumns) == null ? void 0 : r[0];
364
+ return {
365
+ ...e,
366
+ groupByColumns: [t],
367
+ sortByColumns: (i = e.sortByColumns) == null ? void 0 : i.map(
368
+ (s) => o && ii(s, o) ? {
369
+ ...t,
370
+ role: "sortby",
371
+ direction: s.direction
372
+ } : s
373
+ )
374
+ };
375
+ }
376
+ function Za(e) {
377
+ switch (e) {
378
+ case "previous_period":
379
+ return "Previous";
380
+ case "previous_year":
381
+ return "Last Year";
382
+ case "target":
383
+ return "Target";
384
+ default:
385
+ return "Comparison";
386
+ }
387
+ }
388
+ function pn(e, t, n) {
389
+ var o;
390
+ if (((o = n == null ? void 0 : n.output) == null ? void 0 : o.availability.status) === "available" && n.output.comparisonColumnKey)
391
+ return n.output.comparisonColumnKey;
392
+ }
393
+ function ai(e, t) {
394
+ return `${e} Δ`;
395
+ }
396
+ function Xa(e, t) {
397
+ return Yt(e, t);
398
+ }
399
+ function li(e, t) {
400
+ return e.rawKey === t.rawKey && e.outputKey === t.outputKey;
401
+ }
402
+ function mn(e) {
403
+ var a;
404
+ const { card: t, columnKeyMap: n, metricAlias: o, metricId: r } = e;
405
+ if (!(t != null && t.config) || !n || !o || oe(t) !== "config")
406
+ return;
407
+ const i = (a = n.byMetricAlias) == null ? void 0 : a[o];
408
+ if (!i) return;
409
+ const s = (t.config.metricColumns || []).filter((c) => {
410
+ var u;
411
+ if (r && c.id !== r) return !1;
412
+ const l = (u = n.byMetricAlias) == null ? void 0 : u[Q(c)];
413
+ return !!(l && li(i, l));
414
+ });
415
+ return s.length === 1 ? s[0] : void 0;
416
+ }
417
+ function el(e, t) {
418
+ return t ? { ...e, config: t } : e;
419
+ }
420
+ function ci(e) {
421
+ return [
422
+ e.alias,
423
+ e.name,
424
+ e.qualifiedFieldName,
425
+ e.id
426
+ ].filter((t) => !!t);
427
+ }
428
+ function W(e) {
429
+ return e != null && e.config ? oe(e) === "config" : !1;
430
+ }
431
+ function ui(e, t, n, o) {
432
+ if (t === -1 || n === -1 || t === n)
433
+ return null;
434
+ const r = [...e], [i] = r.splice(t, 1), s = o === "before" ? n > t ? n - 1 : n : n > t ? n : n + 1;
435
+ return r.splice(s, 0, i), r;
436
+ }
437
+ function xe(e, t, n) {
438
+ if (!(e != null && e.length)) return null;
439
+ const o = e.findIndex(
440
+ (i) => n(i).includes(t.draggingColumnId)
441
+ ), r = e.findIndex(
442
+ (i) => n(i).includes(t.targetColumnId)
443
+ );
444
+ return ui(e, o, r, t.side);
445
+ }
446
+ function we(e, t, n) {
447
+ return n ? {
448
+ ...e ?? {},
449
+ [t]: n
450
+ } : null;
451
+ }
452
+ function tl(e, t, n) {
453
+ if (!W(e) || !n) return null;
454
+ const o = e.config;
455
+ return e.type === "detailTable" ? we(
456
+ o,
457
+ "detailColumns",
458
+ xe(
459
+ o == null ? void 0 : o.detailColumns,
460
+ t,
461
+ (r) => pe(r, "detail", n)
462
+ )
463
+ ) : we(
464
+ o,
465
+ "groupByColumns",
466
+ xe(
467
+ o == null ? void 0 : o.groupByColumns,
468
+ t,
469
+ (r) => pe(r, "groupby", n)
470
+ )
471
+ ) ?? we(
472
+ o,
473
+ "metricColumns",
474
+ xe(
475
+ o == null ? void 0 : o.metricColumns,
476
+ t,
477
+ (r) => pe(r, "metric", n)
478
+ )
479
+ );
480
+ }
481
+ function di(e) {
482
+ var t, n, o, r, i, s;
483
+ return W(e) ? e.type === "detailTable" ? !!((n = (t = e.config) == null ? void 0 : t.detailColumns) != null && n.length) : !!((r = (o = e.config) == null ? void 0 : o.groupByColumns) != null && r.length || (s = (i = e.config) == null ? void 0 : i.metricColumns) != null && s.length) : !1;
484
+ }
485
+ function nl(e, t) {
486
+ return di(e) && !!t;
487
+ }
488
+ function pe(e, t, n) {
489
+ if (!n) return [];
490
+ const o = t === "metric" ? [
491
+ Q(e),
492
+ e.alias
493
+ ].filter((i) => !!i).flatMap((i) => {
494
+ var a;
495
+ const s = (a = n.byMetricAlias) == null ? void 0 : a[i];
496
+ return s ? [s] : [];
497
+ }) : [], r = _r(
498
+ n,
499
+ e.id,
500
+ t
501
+ );
502
+ return [...o, r].flatMap((i) => [i == null ? void 0 : i.outputKey, i == null ? void 0 : i.rawKey]).filter((i) => !!i);
503
+ }
504
+ function se(e, t, n, o) {
505
+ const r = pe(
506
+ e,
507
+ t,
508
+ o
509
+ );
510
+ return o ? r.find(
511
+ (i) => n.includes(i)
512
+ ) : ci(e).find(
513
+ (i) => n.includes(i)
514
+ );
515
+ }
516
+ function gn(e, t, n) {
517
+ if (!W(t) || !n)
518
+ return;
519
+ const o = t.type === "detailTable" ? [{ role: "detail", fields: t.config.detailColumns }] : [
520
+ { role: "groupby", fields: t.config.groupByColumns },
521
+ { role: "metric", fields: t.config.metricColumns }
522
+ ];
523
+ for (const { role: r, fields: i } of o)
524
+ for (const s of i || [])
525
+ if (se(
526
+ s,
527
+ r,
528
+ [e],
529
+ n
530
+ ) === e && typeof s.label == "string" && s.label.length > 0)
531
+ return s.label;
532
+ }
533
+ function fi(e, t) {
534
+ if (!e) return;
535
+ const n = JSON.stringify(t), o = t.every((r) => r !== null) ? t.join("__") : void 0;
536
+ return e[n] || (o ? e[o] : void 0);
537
+ }
538
+ function pi(e, t, n) {
539
+ if (!e) return;
540
+ let o = e, r = !1;
541
+ return t.forEach((i, s) => {
542
+ const a = n[s] ?? "";
543
+ [
544
+ i.entityName ? `{{${i.entityName}.${i.name}}}` : void 0,
545
+ `{{${i.name}}}`
546
+ ].filter((l) => !!l).forEach((l) => {
547
+ o.includes(l) && (o = o.split(l).join(a), r = !0);
548
+ });
549
+ }), r && o.trim() ? o : void 0;
550
+ }
551
+ function mi(e) {
552
+ const t = (e.card.config.metricColumns || []).filter(
553
+ (n) => n.id === e.metricId && Q(n) === e.metricAlias
554
+ );
555
+ return t.length === 1 ? t[0] : mn({
556
+ card: e.card,
557
+ columnKeyMap: e.columnKeyMap,
558
+ metricAlias: e.metricAlias,
559
+ metricId: e.metricId
560
+ });
561
+ }
562
+ function Je(e) {
563
+ var s;
564
+ const t = (s = e.resultColumn) == null ? void 0 : s.pivotIdentity, n = e.card.config.pivotByColumns || [];
565
+ if (!t || n.length === 0 || t.members.length !== n.length || t.members.some(
566
+ (a, c) => {
567
+ var l;
568
+ return a.fieldId !== ((l = n[c]) == null ? void 0 : l.id);
569
+ }
570
+ ))
571
+ return;
572
+ const o = e.card.config.metricColumns || [], r = mi({
573
+ card: e.card,
574
+ columnKeyMap: e.columnKeyMap,
575
+ metricId: t.metricId,
576
+ metricAlias: t.metricAlias
577
+ }), i = o.length === 0 && t.metricId === $e;
578
+ if (!(!r && !i))
579
+ return {
580
+ resultColumn: e.resultColumn,
581
+ identity: t,
582
+ pivotFields: n,
583
+ authoredMetrics: o,
584
+ authoredMetric: r
585
+ };
586
+ }
587
+ function gi(e) {
588
+ const {
589
+ columnId: t,
590
+ card: n,
591
+ columnKeyMap: o,
592
+ resultColumns: r,
593
+ temporalPresentation: i,
594
+ metricLabelOverride: s
595
+ } = e;
596
+ if (!W(n) || n.type !== "table")
597
+ return;
598
+ const a = Je({
599
+ resultColumn: r == null ? void 0 : r.find((I) => I.key === t),
600
+ card: n,
601
+ columnKeyMap: o
602
+ });
603
+ if (!a) return;
604
+ const { identity: c, pivotFields: l, authoredMetrics: u, authoredMetric: d } = a, m = kr({
605
+ members: c.members,
606
+ resolveTemporalFormat: (I) => {
607
+ var v;
608
+ return (v = po({
609
+ presentation: i,
610
+ fieldId: I,
611
+ role: "pivotby"
612
+ })) == null ? void 0 : v.resolved.format;
613
+ }
614
+ }).memberLabels.map(
615
+ (I) => I || "(Blank)"
616
+ ), g = c.members.map((I) => I.value), p = fi(d == null ? void 0 : d.valueAliases, g) || pi(
617
+ d == null ? void 0 : d.aliasTemplate,
618
+ l,
619
+ m
620
+ ), y = p ? [p] : m, b = s || (u.length > 1 ? (d == null ? void 0 : d.label) || (d == null ? void 0 : d.name) : void 0);
621
+ return [...y, ...b ? [b] : []].join(" / ");
622
+ }
623
+ function L(e, t, n, o) {
624
+ return e != null && e.length ? e.map(
625
+ (r) => se(
626
+ r,
627
+ n,
628
+ t,
629
+ o
630
+ )
631
+ ).filter((r) => !!r) : [];
632
+ }
633
+ function Ft(e, t, n, o) {
634
+ if (!W(t) || !o) return e;
635
+ const r = [], i = (s) => {
636
+ s && e.includes(s) && !r.includes(s) && r.push(s);
637
+ };
638
+ return t.type === "detailTable" ? L(
639
+ t.config.detailColumns,
640
+ e,
641
+ "detail",
642
+ o
643
+ ).forEach(i) : (L(
644
+ t.config.groupByColumns,
645
+ e,
646
+ "groupby",
647
+ o
648
+ ).forEach(i), L(
649
+ t.config.metricColumns,
650
+ e,
651
+ "metric",
652
+ o
653
+ ).forEach((s) => {
654
+ i(s), i(n == null ? void 0 : n(s));
655
+ })), e.forEach(i), r;
656
+ }
657
+ function yi(e, t) {
658
+ var f, m, g;
659
+ const { keys: n, card: o, columnKeyMap: r, resultColumns: i } = e;
660
+ if (!((f = o.config.pivotByColumns) != null && f.length)) return null;
661
+ if (!r || !(i != null && i.length)) return [...n];
662
+ const s = n.every(
663
+ (p) => i.some((y) => y.key === p)
664
+ ), a = [
665
+ ...L(
666
+ o.config.groupByColumns,
667
+ n,
668
+ "groupby",
669
+ r
670
+ ),
671
+ ...L(
672
+ o.config.metricColumns,
673
+ n,
674
+ "metric",
675
+ r
676
+ )
677
+ ].length === (((m = o.config.groupByColumns) == null ? void 0 : m.length) || 0) + (((g = o.config.metricColumns) == null ? void 0 : g.length) || 0);
678
+ if (!s || !a)
679
+ return [...n];
680
+ const c = i.filter(
681
+ (p) => p.pivotIdentity && n.includes(p.key)
682
+ );
683
+ if (c.some(
684
+ (p) => !Je({
685
+ resultColumn: p,
686
+ card: o,
687
+ columnKeyMap: r
688
+ })
689
+ ))
690
+ return [...n];
691
+ const l = c.map((p) => p.key);
692
+ if (l.length === 0) return [...n];
693
+ const u = [], d = (p) => {
694
+ p && n.includes(p) && !u.includes(p) && u.push(p);
695
+ };
696
+ return L(
697
+ o.config.groupByColumns,
698
+ n,
699
+ "groupby",
700
+ r
701
+ ).forEach(d), l.forEach(d), L(
702
+ o.config.metricColumns,
703
+ n,
704
+ "metric",
705
+ r
706
+ ).forEach((p) => {
707
+ d(p), d(t(p));
708
+ }), n.forEach(d), u;
709
+ }
710
+ function bi(e) {
711
+ var c;
712
+ const { keys: t, card: n, comparisonMetadata: o, columnKeyMap: r, resultColumns: i } = e;
713
+ if ((n == null ? void 0 : n.type) !== "table")
714
+ return Ft(
715
+ t,
716
+ n,
717
+ void 0,
718
+ r
719
+ );
720
+ const s = /* @__PURE__ */ new Map();
721
+ (((c = n.config) == null ? void 0 : c.metricColumns) || []).forEach((l) => {
722
+ const { comparisonKind: u, metadata: d } = Jt(o, l);
723
+ if (u === "none") return;
724
+ const f = l.label || l.name, m = se(
725
+ l,
726
+ "metric",
727
+ t,
728
+ r
729
+ );
730
+ if (!m) return;
731
+ const g = pn(
732
+ f,
733
+ u,
734
+ d
735
+ );
736
+ g && s.set(m, g);
737
+ });
738
+ const a = (l) => s.get(l) ?? null;
739
+ if (W(n)) {
740
+ const l = yi(
741
+ { keys: t, card: n, columnKeyMap: r, resultColumns: i },
742
+ a
743
+ );
744
+ if (l) return l;
745
+ }
746
+ return Ft(
747
+ t,
748
+ n,
749
+ a,
750
+ r
751
+ );
752
+ }
753
+ function be(e) {
754
+ return e == null ? void 0 : e.map(
755
+ ({
756
+ format: t,
757
+ formatOrigin: n,
758
+ semanticTemporalPresentation: o,
759
+ ...r
760
+ }) => r
761
+ );
762
+ }
763
+ function Ce(e) {
764
+ if (!e)
765
+ return;
766
+ const {
767
+ format: t,
768
+ formatOrigin: n,
769
+ semanticTemporalPresentation: o,
770
+ ...r
771
+ } = e;
772
+ return te(r);
773
+ }
774
+ function yn(e, t) {
775
+ return e == null ? void 0 : e.map(
776
+ (n) => Et(te(be([n])[0]), n.format, t)
777
+ );
778
+ }
779
+ function Ci(e, t) {
780
+ return e == null ? void 0 : e.map(
781
+ (n) => mo(te(be([n])[0]), n.format, t)
782
+ );
783
+ }
784
+ function hi(e, t) {
785
+ const { dateFormat: n, customFormat: o, ...r } = Ce(e.field);
786
+ return {
787
+ ...e,
788
+ field: t ? r : Et(Ce(e.field), e.field.format, "raw")
789
+ };
790
+ }
791
+ function De(e, t = !1) {
792
+ if (e)
793
+ return {
794
+ ...e,
795
+ conditions: e.conditions.map((n) => hi(n, t)),
796
+ groups: e.groups.map((n) => De(n, t))
797
+ };
798
+ }
799
+ function te(e) {
800
+ var n, o;
801
+ const t = { ...e };
802
+ return (n = t.calculatedFormula) != null && n.inputFields && (t.calculatedFormula = {
803
+ ...t.calculatedFormula,
804
+ inputFields: t.calculatedFormula.inputFields.map(
805
+ (r) => Ce(r)
806
+ )
807
+ }), (o = t.parameters) != null && o.filters && (t.parameters = {
808
+ ...t.parameters,
809
+ filters: De(t.parameters.filters)
810
+ }), t;
811
+ }
812
+ function Ii(e, t) {
813
+ return t.cardType === "detailTable" || !go(t.cardType) || t.temporalResultOwner !== "config" ? yn(e, "grouped") : e == null ? void 0 : e.map((n) => {
814
+ const o = yo(n), r = Ce(o ?? n);
815
+ if (!o)
816
+ return r;
817
+ const { dateFormat: i, customFormat: s, ...a } = r;
818
+ return a;
819
+ });
820
+ }
821
+ function bn(e, t) {
822
+ if (!e)
823
+ return;
824
+ const n = { type: t.cardType, config: e };
825
+ return Ne(n) ? vi(n, t) : e.matrix === void 0 ? {} : { matrix: e.matrix };
826
+ }
827
+ function vi(e, t = {}) {
828
+ var i, s, a;
829
+ const n = e.config;
830
+ if (!n) return;
831
+ const o = { ...t, cardType: e.type };
832
+ return {
833
+ ...n,
834
+ groupByColumns: Ii(n.groupByColumns, o),
835
+ metricColumns: (i = be(n.metricColumns)) == null ? void 0 : i.map(
836
+ te
837
+ ),
838
+ pivotByColumns: yn(n.pivotByColumns, "grouped"),
839
+ sortByColumns: (s = be(n.sortByColumns)) == null ? void 0 : s.map(
840
+ te
841
+ ),
842
+ detailColumns: Ci(n.detailColumns, (a = o.dataSource) == null ? void 0 : a.connectionType),
843
+ filters: De(n.filters)
844
+ };
845
+ }
846
+ function he(e) {
847
+ return (e == null ? void 0 : e.type) === "number" || (e == null ? void 0 : e.type) === "currency";
848
+ }
849
+ function Fi(e) {
850
+ return (e == null ? void 0 : e.type) === "number";
851
+ }
852
+ function Si(e) {
853
+ var n;
854
+ if (!Fi(e))
855
+ return !1;
856
+ const t = (n = e == null ? void 0 : e.numberFormat) == null ? void 0 : n.style;
857
+ return t === void 0 || t === "decimal" || t === "currency";
858
+ }
859
+ function Ti(e, t) {
860
+ const n = t == null ? void 0 : t.type;
861
+ if (n && n !== "none" && n !== "number")
862
+ return { currencyBindable: !1 };
863
+ const o = n === "number" ? t != null && t.numberFormat ? Co(t.numberFormat, {
864
+ preserveOmittedProperties: !0
865
+ }) : { type: "number" } : void 0, r = ge(e.format, {
866
+ preserveOmittedProperties: !0
867
+ }), i = re(e.dataType) === "number" ? { type: "number" } : void 0, a = (t == null ? void 0 : t.inheritMetricFormat) === !1 || !!(t != null && t.numberFormat) && (t == null ? void 0 : t.inheritMetricFormat) !== !0 ? o : r || i || o;
868
+ return {
869
+ authoredFormat: a,
870
+ currencyBindable: he(a)
871
+ };
872
+ }
873
+ function Di(e, t) {
874
+ const n = ge(t.format, {
875
+ preserveOmittedProperties: !0
876
+ }), o = re(t.dataType) === "number" ? { type: "number" } : void 0, r = n || o;
877
+ return {
878
+ authoredFormat: r,
879
+ source: n ? "semantic" : o ? "inferred" : void 0,
880
+ currencyBindable: he(r)
881
+ };
882
+ }
883
+ function Be(e, t = {}) {
884
+ var c, l, u;
885
+ const n = t.column ?? ((c = bo(e)) == null ? void 0 : c.value);
886
+ if ((n == null ? void 0 : n.kind) === "sqlKpiValue") {
887
+ const d = t.resultColumnKey ? {
888
+ kind: "column",
889
+ columnKey: t.resultColumnKey
890
+ } : void 0, f = ge(
891
+ mr({ card: e, column: { kind: "sqlKpiValue" }, surface: "kpiValue" }).format,
892
+ { preserveOmittedProperties: !0 }
893
+ );
894
+ return {
895
+ target: d,
896
+ authoredFormat: f,
897
+ ...f ? { source: "stored" } : {},
898
+ currencyBindable: !!d && he(f)
899
+ };
900
+ }
901
+ const o = n ? (u = (l = e.config) == null ? void 0 : l.metricColumns) == null ? void 0 : u.find((d) => d.id === n.fieldId) : void 0, r = o != null && o.id ? {
902
+ kind: "metric",
903
+ metricId: o.id
904
+ } : void 0, i = ge(o == null ? void 0 : o.format, {
905
+ preserveOmittedProperties: !0
906
+ }), s = re(o == null ? void 0 : o.dataType) === "number" ? { type: "number" } : void 0, a = i || s;
907
+ return {
908
+ target: r,
909
+ authoredFormat: a,
910
+ ...i ? { source: "stored" } : s ? { source: "inferred" } : {},
911
+ currencyBindable: Bt(e.type) && !!r && he(a)
912
+ };
913
+ }
914
+ function Cn(e, t, n) {
915
+ var r;
916
+ const o = n(e, t);
917
+ return ((r = e.derivedField) == null ? void 0 : r.format) ?? (o == null ? void 0 : o.format) ?? (o == null ? void 0 : o.resolvedField.format);
918
+ }
919
+ function hn(e, t, n) {
920
+ return e.kind === "calculated" ? e.definition.format : Cn(e.field, t, n);
921
+ }
922
+ function ol(e, t) {
923
+ const n = _t(t), o = (r, i) => Object.fromEntries(r.flatMap((s) => {
924
+ const a = i(s);
925
+ return a ? [[s.id, a]] : [];
926
+ }));
927
+ return {
928
+ measureFormats: o(e.measures, (r) => hn(r, e.source, n)),
929
+ levelFormats: o([...e.rows, ...e.columns], (r) => Cn(r.field, e.source, n))
930
+ };
931
+ }
932
+ function In(e, t = []) {
933
+ const n = We(e);
934
+ if (n.status !== "ready") return [];
935
+ const { spec: o, presentation: r } = n.config, i = _t(t);
936
+ return o.measures.map((s) => {
937
+ var m;
938
+ const a = s.kind === "aggregate" ? i(s.field, o.source) : void 0, c = gr(r.measureFormats[s.id], hn(s, o.source, i)), l = s.kind === "calculated" ? s.definition.dataType : ["MIN", "MAX"].includes(s.aggregate) ? ((m = s.field.derivedField) == null ? void 0 : m.dataType) ?? (a == null ? void 0 : a.resolvedField.dataType) ?? s.field.dataType : "number", u = re(l) === "number", d = s.kind === "calculated" || !!(a || s.field.derivedField || s.field.name === "*"), f = c && yr(c) ? c : !c && u && d ? { type: "number" } : void 0;
939
+ return { measureId: s.id, label: br(s, r), canonical: f };
940
+ });
941
+ }
942
+ function Mi(e) {
943
+ var t, n;
944
+ return e.type === "detailTable" ? ((t = e.config) == null ? void 0 : t.detailColumns) || [] : ((n = e.config) == null ? void 0 : n.metricColumns) || [];
945
+ }
946
+ function vn(e) {
947
+ return new Set(
948
+ Zt(e).flatMap(
949
+ (t) => (t.controlBindings || []).filter(ve).map((n) => n.controlId)
950
+ )
951
+ );
952
+ }
953
+ function Vi(e, t) {
954
+ const n = [
955
+ t.id,
956
+ t.alias,
957
+ t.label,
958
+ t.name,
959
+ t.qualifiedFieldName
960
+ ].filter((i) => !!i);
961
+ for (const i of n)
962
+ if (e[i])
963
+ return e[i];
964
+ const o = new Set(
965
+ n.map((i) => i.trim().toLowerCase())
966
+ ), r = Object.entries(e).find(
967
+ ([i]) => o.has(i.trim().toLowerCase())
968
+ );
969
+ return r == null ? void 0 : r[1];
970
+ }
971
+ function St(e) {
972
+ return [
973
+ ...new Map(
974
+ e.map((t) => [
975
+ U(t),
976
+ t
977
+ ])
978
+ ).values()
979
+ ];
980
+ }
981
+ function ki(e, t = [], n) {
982
+ var M;
983
+ const o = !!((M = e.sql) != null && M.trim()), r = Bt(e.type), i = o && r && e.type !== "kpi" && e.type !== "matrixTable", s = Mi(e), a = ho(e), c = !o && e.type === "kpi" ? s.map(
984
+ (h) => Be(e, {
985
+ column: { kind: "field", fieldId: h.id }
986
+ })
987
+ ) : [], l = !o && e.type === "matrixTable" ? In(e, n) : [], u = (o ? [] : s).map(
988
+ (h) => ({
989
+ kind: "metric",
990
+ metricId: h.id
991
+ })
992
+ ), d = l.map(
993
+ (h) => ({
994
+ kind: "matrix_measure",
995
+ measureId: h.measureId
996
+ })
997
+ ), f = l.filter((h) => {
998
+ var w, A;
999
+ return ((w = h.canonical) == null ? void 0 : w.type) === "number" || ((A = h.canonical) == null ? void 0 : A.type) === "currency";
1000
+ }).map(
1001
+ (h) => ({
1002
+ kind: "matrix_measure",
1003
+ measureId: h.measureId
1004
+ })
1005
+ ), m = e.type === "matrixTable" ? [] : e.type === "kpi" ? c.filter((h) => h.currencyBindable).flatMap(
1006
+ (h) => h.target ? [h.target] : []
1007
+ ) : (o || !r ? [] : s).filter(
1008
+ (h) => (Io(e.type) ? Ti(
1009
+ h,
1010
+ Vi(a, h)
1011
+ ) : Di(e, h)).currencyBindable
1012
+ ).map(
1013
+ (h) => ({
1014
+ kind: "metric",
1015
+ metricId: h.id
1016
+ })
1017
+ ), g = [...new Set(t)], p = (i ? g : []).map(
1018
+ (h) => ({
1019
+ kind: "column",
1020
+ columnKey: h
1021
+ })
1022
+ ), y = (i ? g : []).filter(
1023
+ (h) => Si(
1024
+ a[h]
1025
+ )
1026
+ ).map(
1027
+ (h) => ({
1028
+ kind: "column",
1029
+ columnKey: h
1030
+ })
1031
+ ), b = (o && e.type === "kpi" ? g.slice(0, 1) : []).map(
1032
+ (h) => ({
1033
+ kind: "column",
1034
+ columnKey: h
1035
+ })
1036
+ ), I = o && e.type === "kpi" ? Be(e, {
1037
+ resultColumnKey: g[0]
1038
+ }) : void 0, v = r && (I != null && I.currencyBindable) ? b : [];
1039
+ return {
1040
+ knownTargets: St([
1041
+ ...e.type === "matrixTable" ? d : u,
1042
+ ...p,
1043
+ ...b
1044
+ ]),
1045
+ eligibleTargets: St([
1046
+ ...m,
1047
+ ...f,
1048
+ ...y,
1049
+ ...v
1050
+ ])
1051
+ };
1052
+ }
1053
+ function rl(e, t) {
1054
+ const n = Be(e, {
1055
+ resultColumnKey: t
1056
+ });
1057
+ return n.currencyBindable ? n.target : void 0;
1058
+ }
1059
+ function il(e) {
1060
+ var t;
1061
+ return (t = e.card.sql) != null && t.trim() ? { kind: "column", columnKey: e.columnKey } : e.metricId ? { kind: "metric", metricId: e.metricId } : void 0;
1062
+ }
1063
+ function U(e) {
1064
+ return e.kind === "metric" ? `metric:${e.metricId}` : e.kind === "column" ? `column:${e.columnKey}` : `matrix_measure:${e.measureId}`;
1065
+ }
1066
+ function Pi(e) {
1067
+ if (!e || typeof e != "object" || Array.isArray(e))
1068
+ return;
1069
+ const t = e;
1070
+ if (t.kind === "metric" && typeof t.metricId == "string" && t.metricId.trim())
1071
+ return { kind: "metric", metricId: t.metricId };
1072
+ if (t.kind === "column" && typeof t.columnKey == "string" && t.columnKey.trim())
1073
+ return { kind: "column", columnKey: t.columnKey };
1074
+ if (t.kind === "matrix_measure" && typeof t.measureId == "string" && t.measureId.trim())
1075
+ return { kind: "matrix_measure", measureId: t.measureId };
1076
+ }
1077
+ function Tt(e) {
1078
+ const t = $t(e);
1079
+ return typeof e == "string" && e === t ? t : void 0;
1080
+ }
1081
+ function Fn(e) {
1082
+ if (e.type !== "enum" || e.source.kind !== "manual")
1083
+ return { diagnostic: "invalid_control_type" };
1084
+ const t = e.source.options.map(
1085
+ (n) => Tt(n.value)
1086
+ );
1087
+ if (t.length === 0 || t.some((n) => !n))
1088
+ return { diagnostic: "invalid_currency_option" };
1089
+ if (e.requiredAtExecution) {
1090
+ const n = e.initialValueStrategy === "saved_default" ? Tt(e.defaultValue) : void 0;
1091
+ if (!n || !t.includes(n))
1092
+ return { diagnostic: "invalid_control_default" };
1093
+ }
1094
+ return {
1095
+ control: e,
1096
+ currencies: t
1097
+ };
1098
+ }
1099
+ function sl(e) {
1100
+ return "control" in Fn(e);
1101
+ }
1102
+ function Sn(e) {
1103
+ const t = vn(e.dashboard);
1104
+ if (t.size === 0)
1105
+ return {
1106
+ definitions: e.definitions || [],
1107
+ values: e.values || {}
1108
+ };
1109
+ const n = new Set(
1110
+ [...t].filter(
1111
+ (o) => !e.referencedControlIds.has(o)
1112
+ )
1113
+ );
1114
+ return {
1115
+ definitions: (e.definitions || []).filter(
1116
+ (o) => !n.has(o.id)
1117
+ ),
1118
+ values: Object.fromEntries(
1119
+ Object.entries(e.values || {}).filter(
1120
+ ([o]) => !n.has(o)
1121
+ )
1122
+ )
1123
+ };
1124
+ }
1125
+ function al(e) {
1126
+ return Sn({
1127
+ ...e,
1128
+ referencedControlIds: new Set(
1129
+ Ye({
1130
+ sql: e.filterSql,
1131
+ controlBindings: []
1132
+ })
1133
+ )
1134
+ });
1135
+ }
1136
+ function ll(e) {
1137
+ var t;
1138
+ return Sn({
1139
+ ...e,
1140
+ referencedControlIds: new Set(
1141
+ Ye({
1142
+ sql: (t = e.source) == null ? void 0 : t.sql,
1143
+ controlBindings: []
1144
+ })
1145
+ )
1146
+ });
1147
+ }
1148
+ function Tn(e) {
1149
+ return {
1150
+ knownKeys: new Set(
1151
+ e.knownTargets.map(U)
1152
+ ),
1153
+ eligibleKeys: new Set(
1154
+ e.eligibleTargets.map(U)
1155
+ ),
1156
+ controlsById: new Map(
1157
+ (e.controls || []).map((t) => [t.id, t])
1158
+ )
1159
+ };
1160
+ }
1161
+ function Dn(e, t) {
1162
+ if (!e || typeof e != "object" || e.target !== "presentation_currency")
1163
+ return {};
1164
+ const n = e, o = typeof n.controlId == "string" && n.controlId.trim() ? n.controlId : void 0;
1165
+ if (!o)
1166
+ return { diagnostic: { code: "invalid_binding_shape" } };
1167
+ const r = Pi(
1168
+ n.presentationTarget
1169
+ );
1170
+ if (!r)
1171
+ return {
1172
+ diagnostic: { code: "missing_target", controlId: o }
1173
+ };
1174
+ const i = U(r);
1175
+ if (!t.knownKeys.has(i))
1176
+ return {
1177
+ diagnostic: { code: "stale_target", controlId: o }
1178
+ };
1179
+ if (!t.eligibleKeys.has(i))
1180
+ return {
1181
+ diagnostic: { code: "inapplicable_target", controlId: o }
1182
+ };
1183
+ const s = t.controlsById.get(o);
1184
+ if (!s)
1185
+ return {
1186
+ diagnostic: { code: "missing_control", controlId: o }
1187
+ };
1188
+ const a = Fn(s);
1189
+ return "diagnostic" in a ? {
1190
+ diagnostic: { code: a.diagnostic, controlId: o }
1191
+ } : {
1192
+ binding: {
1193
+ controlId: o,
1194
+ presentationTarget: r,
1195
+ control: a.control,
1196
+ currencies: a.currencies
1197
+ }
1198
+ };
1199
+ }
1200
+ function cl(e) {
1201
+ const t = Tn(e);
1202
+ return (e.bindings || []).flatMap((n) => {
1203
+ const o = Dn(n, t);
1204
+ return "diagnostic" in o ? [o.diagnostic] : [];
1205
+ });
1206
+ }
1207
+ function xi(e) {
1208
+ var r;
1209
+ const t = [], n = U(e.target), o = Tn(e);
1210
+ for (const i of e.bindings || []) {
1211
+ const s = Dn(i, o);
1212
+ if ("diagnostic" in s) {
1213
+ t.push(s.diagnostic);
1214
+ continue;
1215
+ }
1216
+ const a = s.binding;
1217
+ if (!a || U(
1218
+ a.presentationTarget
1219
+ ) !== n) continue;
1220
+ const l = $t(
1221
+ (r = e.values) == null ? void 0 : r[a.control.id]
1222
+ );
1223
+ if (!(!l || !a.currencies.includes(l)))
1224
+ return { currency: l, diagnostics: t };
1225
+ }
1226
+ return { diagnostics: t };
1227
+ }
1228
+ function wi(e, t, n, o) {
1229
+ const r = { ...e, config: { ...e.config, matrix: t } }, i = ki(r, [], o), s = In(r, o), a = { ...t.presentation.measureFormats };
1230
+ for (const c of s) {
1231
+ const l = { kind: "matrix_measure", measureId: c.measureId }, { currency: u } = xi({
1232
+ ...n,
1233
+ ...i,
1234
+ bindings: e.controlBindings,
1235
+ target: l
1236
+ });
1237
+ if (!u || !c.canonical) continue;
1238
+ const { locale: d, ...f } = c.canonical;
1239
+ a[c.measureId] = { ...f, type: "currency", currency: u };
1240
+ }
1241
+ return { ...t.presentation, measureFormats: a };
1242
+ }
1243
+ function Oi(e, t) {
1244
+ if (!e || typeof e != "object" || !("kind" in e))
1245
+ return e;
1246
+ switch (e.kind) {
1247
+ case "manual":
1248
+ return {
1249
+ kind: "manual",
1250
+ ...t != null && t.includePresentation ? {
1251
+ options: e.options.map((n) => ({
1252
+ value: n.value,
1253
+ label: n.label,
1254
+ presentation: n.presentation
1255
+ }))
1256
+ } : {
1257
+ optionValues: e.options.map((n) => n.value).sort()
1258
+ }
1259
+ };
1260
+ case "dataset_values":
1261
+ return {
1262
+ kind: "dataset_values",
1263
+ fieldId: e.fieldId,
1264
+ connectionId: e.connectionId || ""
1265
+ };
1266
+ case "field_allowlist":
1267
+ return {
1268
+ kind: "field_allowlist",
1269
+ fieldIds: [...e.fieldIds].sort()
1270
+ };
1271
+ case "metric_allowlist":
1272
+ return {
1273
+ kind: "metric_allowlist",
1274
+ metricIds: [...e.metricIds].sort()
1275
+ };
1276
+ case "sql_query":
1277
+ return {
1278
+ kind: "sql_query",
1279
+ connectionId: e.connectionId,
1280
+ sql: e.sql,
1281
+ valueColumn: e.valueColumn,
1282
+ labelColumn: e.labelColumn
1283
+ };
1284
+ default:
1285
+ return e;
1286
+ }
1287
+ }
1288
+ function Ai(e, t) {
1289
+ return {
1290
+ id: e.id,
1291
+ scope: e.scope,
1292
+ type: e.type,
1293
+ source: Oi(e.source, t),
1294
+ initialValueStrategy: e.initialValueStrategy,
1295
+ defaultValue: e.defaultValue,
1296
+ requiredAtExecution: e.requiredAtExecution,
1297
+ ...t != null && t.includePresentation ? {
1298
+ label: e.label,
1299
+ helpText: e.helpText,
1300
+ hidden: e.hidden,
1301
+ locked: e.locked,
1302
+ placement: e.placement,
1303
+ showLabel: e.showLabel,
1304
+ toolbarWidth: e.toolbarWidth
1305
+ } : {}
1306
+ };
1307
+ }
1308
+ function Ei(e, t) {
1309
+ return e.target === "sql_param" || e.target === "presentation_currency" ? e : e.target === "config_field_selector" && !(t != null && t.includePresentation) ? {
1310
+ ...e,
1311
+ mapping: Object.fromEntries(
1312
+ Object.entries(e.mapping).sort(([n], [o]) => n.localeCompare(o)).map(([n, o]) => {
1313
+ if ("kind" in o) return [n, o];
1314
+ const r = { ...o };
1315
+ return delete r.format, delete r.dateFormat, delete r.customFormat, delete r.semanticTemporalPresentation, [n, r];
1316
+ })
1317
+ )
1318
+ } : {
1319
+ ...e,
1320
+ mapping: Object.fromEntries(
1321
+ Object.entries(e.mapping).sort(([n], [o]) => n.localeCompare(o)).map(([n, o]) => [
1322
+ n,
1323
+ o && typeof o == "object" && !Array.isArray(o) ? Object.fromEntries(
1324
+ Object.entries(o).sort(
1325
+ ([r], [i]) => r.localeCompare(i)
1326
+ )
1327
+ ) : o
1328
+ ])
1329
+ )
1330
+ };
1331
+ }
1332
+ function Dt(e = [], t) {
1333
+ return [...e].map((n) => Ai(n, t)).sort(
1334
+ (n, o) => n.id.localeCompare(o.id) || n.scope.localeCompare(o.scope) || n.type.localeCompare(o.type)
1335
+ );
1336
+ }
1337
+ function Bi(e = [], t) {
1338
+ return e.filter(
1339
+ (n) => (t == null ? void 0 : t.includePresentation) || !ve(n)
1340
+ ).map((n) => Ei(n, t)).sort(
1341
+ (n, o) => _(n).localeCompare(_(o))
1342
+ );
1343
+ }
1344
+ function _i(e, t) {
1345
+ return e ? _({
1346
+ controlDefinitions: Dt(e.controlDefinitions, t),
1347
+ cardControlDefinitions: Dt(
1348
+ e.cardControlDefinitions,
1349
+ t
1350
+ ),
1351
+ controlBindings: Bi(e.controlBindings, t)
1352
+ }) : "__none__";
1353
+ }
1354
+ const Ri = ["table", "detailTable"], Mt = (e) => Ri.includes(e.type), Ki = "calendar-context";
1355
+ function qi(e) {
1356
+ const { id: t, label: n, field: o, ...r } = e;
1357
+ return {
1358
+ ...r,
1359
+ field: Ze(
1360
+ o
1361
+ )
1362
+ };
1363
+ }
1364
+ function Me(e) {
1365
+ if (!e)
1366
+ return;
1367
+ const { id: t, conditions: n, groups: o, ...r } = e;
1368
+ return {
1369
+ ...r,
1370
+ conditions: n.map(qi),
1371
+ groups: o.map((i) => Me(i))
1372
+ };
1373
+ }
1374
+ function Ze(e) {
1375
+ var o, r;
1376
+ const { label: t, ...n } = e;
1377
+ return {
1378
+ ...n,
1379
+ ...(o = e.calculatedFormula) != null && o.inputFields ? {
1380
+ calculatedFormula: {
1381
+ ...e.calculatedFormula,
1382
+ inputFields: e.calculatedFormula.inputFields.map(
1383
+ Ze
1384
+ )
1385
+ }
1386
+ } : {},
1387
+ ...(r = e.parameters) != null && r.filters ? {
1388
+ parameters: {
1389
+ ...e.parameters,
1390
+ filters: Me(
1391
+ e.parameters.filters
1392
+ )
1393
+ }
1394
+ } : {}
1395
+ };
1396
+ }
1397
+ function Ni(e) {
1398
+ const t = (n) => n == null ? void 0 : n.map(Ze);
1399
+ return {
1400
+ ...e,
1401
+ groupByColumns: t(e.groupByColumns),
1402
+ metricColumns: t(e.metricColumns),
1403
+ pivotByColumns: t(e.pivotByColumns),
1404
+ sortByColumns: t(e.sortByColumns),
1405
+ detailColumns: t(e.detailColumns),
1406
+ filters: e.filters ? Me(e.filters) : void 0
1407
+ };
1408
+ }
1409
+ function Li(e, t, n) {
1410
+ if (!e)
1411
+ return JSON.stringify(e);
1412
+ if (n === "matrixTable" && e.matrix) return _(Ar(e.matrix.spec));
1413
+ const { matrix: o, ...r } = e, i = t ? Ni(r) : r;
1414
+ return JSON.stringify({
1415
+ ...i,
1416
+ filters: Me(i.filters)
1417
+ });
1418
+ }
1419
+ function ji(e) {
1420
+ if (!e)
1421
+ return null;
1422
+ const { format: t, ...n } = e;
1423
+ return n;
1424
+ }
1425
+ function zi(e, t) {
1426
+ const n = /* @__PURE__ */ new Map();
1427
+ for (const r of (t == null ? void 0 : t.controlDefinitions) || [])
1428
+ n.set(r.id, r.type);
1429
+ for (const r of (t == null ? void 0 : t.cardControlDefinitions) || [])
1430
+ n.set(r.id, r.type);
1431
+ const o = Object.fromEntries(
1432
+ Object.entries(e || {}).map(([r, i]) => n.get(r) === "multi_enum" && Array.isArray(i) ? [
1433
+ r,
1434
+ [...i].sort(
1435
+ (s, a) => _(s).localeCompare(_(a))
1436
+ )
1437
+ ] : [r, i])
1438
+ );
1439
+ return _(o);
1440
+ }
1441
+ function Gi(e, {
1442
+ finalFiltersKey: t,
1443
+ cardFilterValues: n,
1444
+ controlValues: o,
1445
+ controlDefinitions: r,
1446
+ cardControlDefinitions: i,
1447
+ controlBindings: s,
1448
+ queryRelevantConfig: a,
1449
+ resolvedPrimaryDateField: c,
1450
+ globalDateComparison: l,
1451
+ calendarContext: u
1452
+ }) {
1453
+ const { filterColumns: d, ...f } = e.queryConfig || {}, m = d == null ? void 0 : d.filter(
1454
+ (v) => {
1455
+ var M, h;
1456
+ return (h = (M = e.queryConfig) == null ? void 0 : M.filters) == null ? void 0 : h.some((w) => w.filterColumnName === v.name);
1457
+ }
1458
+ ), g = (e == null ? void 0 : e.sql) || "", p = Le((e == null ? void 0 : e.python) || ""), y = ["table", "detailTable", "matrixTable"].includes(
1459
+ e.type
1460
+ ) ? "table" : e.type === "kpi" ? "kpi" : "chart", b = a || bn(e.config, { cardType: e.type, dataSource: e.dataSource }), I = vo.includes(
1461
+ e.type
1462
+ );
1463
+ return [
1464
+ "query",
1465
+ e == null ? void 0 : e.id,
1466
+ y,
1467
+ g,
1468
+ p,
1469
+ JSON.stringify(n),
1470
+ zi(o, {
1471
+ controlDefinitions: r,
1472
+ cardControlDefinitions: i
1473
+ }),
1474
+ _i({
1475
+ controlDefinitions: r,
1476
+ cardControlDefinitions: i,
1477
+ controlBindings: s
1478
+ }),
1479
+ _(
1480
+ ji(c)
1481
+ ),
1482
+ _(l ?? null),
1483
+ Ki,
1484
+ _(u),
1485
+ JSON.stringify(f),
1486
+ JSON.stringify(m),
1487
+ Li(
1488
+ b,
1489
+ I,
1490
+ e.type
1491
+ ),
1492
+ t
1493
+ ];
1494
+ }
1495
+ function Hi(e, t, n) {
1496
+ var a, c, l;
1497
+ const o = Gi(e, t), r = _(o), i = ((a = n == null ? void 0 : n.resolvePaginationConfig) == null ? void 0 : a.call(n, r)) ?? e.paginationConfig, s = Mt(e) && Fe(e.config) || Mt(e) && e.sql && ((l = (c = e.preferences) == null ? void 0 : c.tablePrefs) == null ? void 0 : l.enableDevModePagination);
1498
+ return {
1499
+ queryKey: [
1500
+ ...o,
1501
+ s ? JSON.stringify(i) : ""
1502
+ ],
1503
+ queryInputIdentity: r,
1504
+ paginationConfig: i
1505
+ };
1506
+ }
1507
+ function Ui(e, t, n, o) {
1508
+ return Hi(
1509
+ e,
1510
+ {
1511
+ finalFiltersKey: t.finalFiltersKey,
1512
+ cardFilterValues: t.cardFilterValues,
1513
+ controlValues: t.controlValues,
1514
+ controlDefinitions: t.controlDefinitions,
1515
+ cardControlDefinitions: t.cardControlDefinitions,
1516
+ controlBindings: t.controlBindings,
1517
+ queryRelevantConfig: t.queryRelevantConfig,
1518
+ resolvedPrimaryDateField: t.resolvedPrimaryDateField || void 0,
1519
+ globalDateComparison: t.globalDateComparison,
1520
+ calendarContext: n
1521
+ },
1522
+ o
1523
+ );
1524
+ }
1525
+ function Mn(e) {
1526
+ const t = {
1527
+ ...Vr,
1528
+ ...e.presentation
1529
+ }, n = t.displayMode, {
1530
+ bookkeepingKeys: o,
1531
+ comparisonColumnKeys: r,
1532
+ deltaColumnKeys: i,
1533
+ percentChangeColumnKeys: s,
1534
+ ratioColumnKeys: a
1535
+ } = Xt(e.comparisonMetadata), c = /* @__PURE__ */ new Set();
1536
+ t.showComparison && (n === "difference" || n === "both") && i.forEach((f) => c.add(f)), t.showComparison && (n === "percent_change" || n === "both") && s.forEach((f) => c.add(f)), t.showComparison && n === "ratio" && a.forEach((f) => c.add(f));
1537
+ const l = new Set(o);
1538
+ t.showComparison || r.forEach((f) => l.add(f)), [i, s, a].forEach(
1539
+ (f) => f.forEach((m) => {
1540
+ c.has(m) || l.add(m);
1541
+ })
1542
+ );
1543
+ const u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
1544
+ return Object.entries(e.comparisonMetadata || {}).forEach(
1545
+ ([f, m]) => {
1546
+ var b;
1547
+ const g = m.output;
1548
+ if (!g || g.outputId !== f || g.availability.status !== "available")
1549
+ return;
1550
+ const p = ((b = e.resolveMetricName) == null ? void 0 : b.call(e, {
1551
+ metricId: g.metricId,
1552
+ metricAlias: g.metricAlias
1553
+ })) || m.displayName || g.metricId, y = m.displayLabel || "Comparison";
1554
+ g.comparisonColumnKey && (u.set(
1555
+ g.comparisonColumnKey,
1556
+ `${p} (${y})`
1557
+ ), d.set(g.comparisonColumnKey, {
1558
+ metricId: g.metricId,
1559
+ metricAlias: g.metricAlias,
1560
+ kind: "comparison"
1561
+ })), g.deltaColumnKey && c.has(g.deltaColumnKey) && (u.set(g.deltaColumnKey, `${p} Difference`), d.set(g.deltaColumnKey, {
1562
+ metricId: g.metricId,
1563
+ metricAlias: g.metricAlias,
1564
+ kind: "delta"
1565
+ })), g.percentChangeColumnKey && c.has(g.percentChangeColumnKey) && (u.set(
1566
+ g.percentChangeColumnKey,
1567
+ `${p} Percent Change`
1568
+ ), d.set(g.percentChangeColumnKey, {
1569
+ metricId: g.metricId,
1570
+ metricAlias: g.metricAlias,
1571
+ kind: "percent_change"
1572
+ })), g.ratioColumnKey && c.has(g.ratioColumnKey) && (u.set(
1573
+ g.ratioColumnKey,
1574
+ `${p} Ratio (current ÷ comparison)`
1575
+ ), d.set(g.ratioColumnKey, {
1576
+ metricId: g.metricId,
1577
+ metricAlias: g.metricAlias,
1578
+ kind: "ratio"
1579
+ }));
1580
+ }
1581
+ ), {
1582
+ excludedKeys: l,
1583
+ selectedDerivedKeys: c,
1584
+ columnLabels: u,
1585
+ columnPresentationOwners: d
1586
+ };
1587
+ }
1588
+ function ul(e) {
1589
+ var t, n;
1590
+ return Mn({
1591
+ comparisonMetadata: e.comparisonMetadata,
1592
+ presentation: (n = (t = e.card) == null ? void 0 : t.preferences) == null ? void 0 : n.comparisonPresentation,
1593
+ resolveMetricName: ({ metricId: o, metricAlias: r }) => {
1594
+ var i;
1595
+ return (i = mn({
1596
+ card: e.card,
1597
+ columnKeyMap: e.columnKeyMap,
1598
+ metricId: o,
1599
+ metricAlias: r
1600
+ })) == null ? void 0 : i.label;
1601
+ }
1602
+ });
1603
+ }
1604
+ function dl(e) {
1605
+ var n;
1606
+ return (((n = e.card.config) == null ? void 0 : n.metricColumns) || []).filter(
1607
+ (o) => {
1608
+ var r;
1609
+ return ((r = o.comparison) == null ? void 0 : r.mode) === "explicit";
1610
+ }
1611
+ ).some(
1612
+ (o) => !Yt(e.comparisonMetadata, o)
1613
+ );
1614
+ }
1615
+ function Xe(e) {
1616
+ const t = e.config ?? {};
1617
+ return e.type === "detailTable" ? [{ role: "detail", fields: t.detailColumns ?? [] }] : [
1618
+ { role: "groupby", fields: t.groupByColumns ?? [] },
1619
+ { role: "metric", fields: t.metricColumns ?? [] },
1620
+ { role: "detail", fields: t.detailColumns ?? [] }
1621
+ ];
1622
+ }
1623
+ function et(e, t) {
1624
+ if (e.id)
1625
+ return t === "metric" ? {
1626
+ kind: "metric",
1627
+ metricId: e.id,
1628
+ metricAlias: Q(e)
1629
+ } : { kind: "dimension", role: t, fieldId: e.id };
1630
+ }
1631
+ function Vt(e) {
1632
+ const t = /* @__PURE__ */ new Map();
1633
+ for (const n of e) t.set(n, (t.get(n) ?? 0) + 1);
1634
+ return t;
1635
+ }
1636
+ function $i(e, t) {
1637
+ var d, f;
1638
+ const n = [...t.keys], o = new Set(n), r = t.columnKeyMap, i = Xe(e).flatMap(
1639
+ ({ role: m, fields: g }) => g.flatMap((p) => {
1640
+ const y = et(p, m);
1641
+ return y ? [
1642
+ {
1643
+ identity: y,
1644
+ columnId: j(y),
1645
+ field: p,
1646
+ // Identity comes from result metadata (PLAN B2): no key map, no address.
1647
+ outputKey: r ? se(p, m, n, r) : void 0
1648
+ }
1649
+ ] : [];
1650
+ })
1651
+ ), s = Vt(i.map((m) => m.columnId)), a = Vt(
1652
+ i.flatMap(
1653
+ (m) => m.outputKey ? [m.outputKey] : []
1654
+ )
1655
+ ), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
1656
+ for (const m of i) {
1657
+ if (s.get(m.columnId) !== 1) continue;
1658
+ const g = m.outputKey && a.get(m.outputKey) === 1 ? m.outputKey : void 0;
1659
+ c.set(m.columnId, {
1660
+ columnId: m.columnId,
1661
+ identity: m.identity,
1662
+ field: m.field,
1663
+ baseKey: g,
1664
+ // Today's header for the column's own key; a metric shown only as pivot
1665
+ // members is named by its field.
1666
+ authorLabel: g ? gn(g, e, r) ?? g : m.field.label || m.field.name || m.columnId
1667
+ }), g && l.set(g, { columnId: m.columnId, part: "base" });
1668
+ }
1669
+ const u = e.config;
1670
+ if (e.type === "table" && ((d = u == null ? void 0 : u.pivotByColumns) != null && d.length) && ((f = t.columns) != null && f.length)) {
1671
+ const m = e;
1672
+ for (const g of t.columns) {
1673
+ if (!g.pivotIdentity || !o.has(g.key) || l.has(g.key))
1674
+ continue;
1675
+ const p = Je({
1676
+ resultColumn: g,
1677
+ card: m,
1678
+ columnKeyMap: r
1679
+ });
1680
+ if (!p) continue;
1681
+ const y = {
1682
+ kind: "metric",
1683
+ metricId: p.identity.metricId,
1684
+ metricAlias: p.identity.metricAlias
1685
+ }, b = j(y);
1686
+ if (p.authoredMetric) {
1687
+ if (!c.has(b))
1688
+ continue;
1689
+ } else {
1690
+ if (p.identity.metricId !== $e)
1691
+ continue;
1692
+ c.has(b) || c.set(b, { columnId: b, identity: y, authorLabel: "Count" });
1693
+ }
1694
+ l.set(g.key, { columnId: b, part: "pivot-member" });
1695
+ }
1696
+ }
1697
+ for (const [m, g] of Object.entries(
1698
+ t.comparisonMetadata ?? {}
1699
+ )) {
1700
+ const p = g.output;
1701
+ if (p.outputId !== m || p.availability.status !== "available")
1702
+ continue;
1703
+ const y = j({
1704
+ kind: "metric",
1705
+ metricId: p.metricId,
1706
+ metricAlias: p.metricAlias
1707
+ });
1708
+ if (c.has(y))
1709
+ for (const b of [
1710
+ p.comparisonColumnKey,
1711
+ p.deltaColumnKey,
1712
+ p.percentChangeColumnKey,
1713
+ p.ratioColumnKey
1714
+ ])
1715
+ b && !l.has(b) && l.set(b, { columnId: y, part: "comparison" });
1716
+ }
1717
+ return { entries: c, owners: l };
1718
+ }
1719
+ function Qi(e) {
1720
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
1721
+ for (const o of e.keys) {
1722
+ const r = { kind: "result", key: o }, i = j(r);
1723
+ t.set(i, {
1724
+ columnId: i,
1725
+ identity: r,
1726
+ baseKey: o,
1727
+ authorLabel: o
1728
+ }), n.set(o, { columnId: i, part: "base" });
1729
+ }
1730
+ return { entries: t, owners: n };
1731
+ }
1732
+ function fl(e) {
1733
+ const t = /* @__PURE__ */ new Set();
1734
+ for (const n of e ?? [])
1735
+ if (n && typeof n == "object")
1736
+ for (const o of Object.keys(n)) t.add(o);
1737
+ return [...t];
1738
+ }
1739
+ function Wi(e, t) {
1740
+ if (e.toLowerCase() !== "count") return !1;
1741
+ const n = t == null ? void 0 : t.find((o) => (o == null ? void 0 : o[e]) != null);
1742
+ return n ? typeof n[e] == "number" : !1;
1743
+ }
1744
+ function Yi(e, t, n, o) {
1745
+ var c, l, u, d;
1746
+ let r = [...t.keys], i = /* @__PURE__ */ new Map();
1747
+ const s = t.comparisonMetadata;
1748
+ if (n === "screen") {
1749
+ const f = Xt(s);
1750
+ r = r.filter((g) => !f.internalKeys.has(g));
1751
+ const m = e.type === "table" ? (c = e.preferences) == null ? void 0 : c.comparisonPresentation : void 0;
1752
+ tn(m) || (r = r.filter((g) => !f.comparisonColumnKeys.has(g)));
1753
+ } else {
1754
+ const f = Mn({
1755
+ comparisonMetadata: s,
1756
+ presentation: (l = e.preferences) == null ? void 0 : l.comparisonPresentation,
1757
+ resolveMetricName: o
1758
+ });
1759
+ r = r.filter((m) => !f.excludedKeys.has(m)), i = f.columnLabels;
1760
+ }
1761
+ const a = e.config;
1762
+ return e.type === "table" && !((u = a == null ? void 0 : a.metricColumns) != null && u.length) && ((d = a == null ? void 0 : a.groupByColumns) != null && d.length) && !e.sql && (r = r.filter((f) => !Wi(f, t.rows))), {
1763
+ keys: bi({
1764
+ keys: r,
1765
+ card: e,
1766
+ comparisonMetadata: s,
1767
+ columnKeyMap: t.columnKeyMap,
1768
+ resultColumns: t.columns
1769
+ }),
1770
+ exportLabels: i
1771
+ };
1772
+ }
1773
+ function Ji(e, t, n) {
1774
+ var r, i;
1775
+ const o = /* @__PURE__ */ new Map();
1776
+ if (e.type !== "table" || !tn((r = e.preferences) == null ? void 0 : r.comparisonPresentation))
1777
+ return o;
1778
+ for (const s of ((i = e.config) == null ? void 0 : i.metricColumns) ?? []) {
1779
+ const { comparisonKind: a, metadata: c } = Jt(
1780
+ t.comparisonMetadata,
1781
+ s
1782
+ );
1783
+ if (a === "none" || !se(
1784
+ s,
1785
+ "metric",
1786
+ [...n],
1787
+ t.columnKeyMap
1788
+ )) continue;
1789
+ const u = pn(
1790
+ s.label || s.name,
1791
+ a,
1792
+ c
1793
+ );
1794
+ u && o.set(u, { metric: s, kind: a });
1795
+ }
1796
+ return o;
1797
+ }
1798
+ function Zi(e) {
1799
+ const t = Xe(e);
1800
+ return [
1801
+ ...t.filter((n) => n.role === "metric"),
1802
+ ...t.filter((n) => n.role !== "metric")
1803
+ ];
1804
+ }
1805
+ function Xi(e, t, n) {
1806
+ if (!t.length) return [];
1807
+ const o = Zi(e), r = [], i = /* @__PURE__ */ new Set();
1808
+ for (const s of t) {
1809
+ const a = Er(o, s);
1810
+ if (!a) continue;
1811
+ const c = o[a.group], l = et(c.fields[a.index], c.role);
1812
+ if (!l) continue;
1813
+ const u = j(l);
1814
+ !n.has(u) || i.has(u) || (i.add(u), r.push({
1815
+ columnId: u,
1816
+ direction: s.direction === "desc" ? "desc" : "asc"
1817
+ }));
1818
+ }
1819
+ return r;
1820
+ }
1821
+ function es(e, t) {
1822
+ return e ? "query" : t === "server" ? "page-only" : "browser";
1823
+ }
1824
+ function Vn(e, t) {
1825
+ var n, o, r;
1826
+ return !!t && ((r = (o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.columnVisibility) == null ? void 0 : r[t]) === !1;
1827
+ }
1828
+ function ts(e) {
1829
+ return e.type !== "table" && e.type !== "detailTable" ? "card-type" : en(e) ? void 0 : "author-disabled";
1830
+ }
1831
+ function _e(e, t) {
1832
+ const n = [], o = /* @__PURE__ */ new Map();
1833
+ for (const r of e) {
1834
+ const i = t(r), s = i ? `column:${i.columnId}` : `key:${r}`;
1835
+ let a = o.get(s);
1836
+ a || (a = { id: s, columnId: i == null ? void 0 : i.columnId, keys: [] }, o.set(s, a), n.push(a)), a.keys.push(r);
1837
+ }
1838
+ return n;
1839
+ }
1840
+ function ue(e, t, n) {
1841
+ const o = _e(e, t), r = new Set(n), i = new Map(
1842
+ o.flatMap(
1843
+ (a) => a.columnId ? [[a.columnId, a]] : []
1844
+ )
1845
+ ), s = n.flatMap((a) => {
1846
+ const c = i.get(a);
1847
+ return c ? [c] : [];
1848
+ });
1849
+ return o.forEach((a, c) => {
1850
+ if (a.columnId && r.has(a.columnId)) return;
1851
+ const l = c > 0 ? o[c - 1] : void 0, u = l ? s.indexOf(l) + 1 : 0;
1852
+ s.splice(u, 0, a);
1853
+ }), s.flatMap((a) => a.keys);
1854
+ }
1855
+ function ns(e) {
1856
+ return e != null && e.pivotIdentity ? JSON.stringify(e.pivotIdentity.members.map((t) => t.value)) : void 0;
1857
+ }
1858
+ function os(e, t, n, o) {
1859
+ const r = e.findIndex(
1860
+ (l) => {
1861
+ var u;
1862
+ return ((u = t(l)) == null ? void 0 : u.part) === "pivot-member";
1863
+ }
1864
+ );
1865
+ if (r === -1) return ue(e, t, n);
1866
+ let i = r;
1867
+ e.forEach((l, u) => {
1868
+ var d;
1869
+ ((d = t(l)) == null ? void 0 : d.part) === "pivot-member" && (i = u);
1870
+ });
1871
+ const s = new Map(
1872
+ (o ?? []).map((l) => [l.key, l])
1873
+ ), a = [];
1874
+ let c;
1875
+ for (const l of e.slice(r, i + 1)) {
1876
+ const u = ns(s.get(l)) ?? `key:${l}`;
1877
+ (!a.length || u !== c) && a.push([]), a[a.length - 1].push(l), c = u;
1878
+ }
1879
+ return [
1880
+ ...ue(e.slice(0, r), t, n),
1881
+ ...a.flatMap((l) => ue(l, t, n)),
1882
+ ...ue(e.slice(i + 1), t, n)
1883
+ ];
1884
+ }
1885
+ function pl(e) {
1886
+ if (oe(e) !== "config") return;
1887
+ const t = /* @__PURE__ */ new Set();
1888
+ for (const { role: n, fields: o } of Xe(e))
1889
+ for (const r of o) {
1890
+ const i = et(r, n);
1891
+ i && t.add(j(i));
1892
+ }
1893
+ return t;
1894
+ }
1895
+ function ml(e) {
1896
+ const t = nn(e);
1897
+ return (t == null ? void 0 : t.kind) === "metric" && t.metricId === $e;
1898
+ }
1899
+ function gl(e) {
1900
+ var ut, dt, ft, pt;
1901
+ const { card: t, result: n } = e, o = e.projection ?? "screen", r = oe(t) === "config", i = ts(t), s = i === "card-type" ? void 0 : i === "author-disabled" ? (ut = e.settings) != null && ut.sort ? { sort: e.settings.sort } : void 0 : e.settings, a = es(r, e.paginationMode), c = n.columnKeyMap, l = r ? $i(t, n) : Qi(n), u = (C) => {
1902
+ var S, V;
1903
+ return C && ((V = (S = s == null ? void 0 : s.labels) == null ? void 0 : S[C]) == null ? void 0 : V.trim()) || void 0;
1904
+ }, d = (C) => j({ kind: "metric", ...C }), { keys: f, exportLabels: m } = Yi(
1905
+ t,
1906
+ n,
1907
+ o,
1908
+ (C) => {
1909
+ var V;
1910
+ const S = d(C);
1911
+ return u(l.entries.has(S) ? S : void 0) ?? ((V = l.entries.get(S)) == null ? void 0 : V.authorLabel);
1912
+ }
1913
+ ), g = (C) => Vn(t, C), p = (C) => {
1914
+ const S = l.owners.get(C);
1915
+ if (!S || i === "card-type") return;
1916
+ const V = l.entries.get(S.columnId);
1917
+ if (!(!V || V.baseKey && g(V.baseKey)))
1918
+ return S;
1919
+ }, y = f.filter((C) => !g(C)), I = _e(y, p).flatMap(
1920
+ (C) => C.columnId ? [C.columnId] : []
1921
+ ), v = new Set(I), M = r ? Xi(
1922
+ t,
1923
+ ((dt = t.config) == null ? void 0 : dt.sortByColumns) ?? [],
1924
+ l.entries
1925
+ ).filter((C) => v.has(C.columnId)) : [], h = [
1926
+ ...(s == null ? void 0 : s.order) ?? [],
1927
+ ...(s == null ? void 0 : s.hidden) ?? [],
1928
+ ...Object.keys((s == null ? void 0 : s.labels) ?? {}),
1929
+ ...((s == null ? void 0 : s.sort) ?? []).map((C) => C.columnId)
1930
+ ], w = [
1931
+ ...new Set(h.filter((C) => !v.has(C)))
1932
+ ];
1933
+ let A;
1934
+ if (s != null && s.sort && a !== "page-only") {
1935
+ const C = s.sort.filter(
1936
+ (S) => v.has(S.columnId)
1937
+ );
1938
+ A = C.length || !s.sort.length ? C : void 0;
1939
+ }
1940
+ const T = hr(
1941
+ s ? {
1942
+ order: (ft = s.order) == null ? void 0 : ft.filter(
1943
+ (C) => v.has(C)
1944
+ ),
1945
+ hidden: (pt = s.hidden) == null ? void 0 : pt.filter(
1946
+ (C) => v.has(C)
1947
+ ),
1948
+ labels: Object.fromEntries(
1949
+ Object.entries(s.labels ?? {}).filter(
1950
+ ([C]) => v.has(C)
1951
+ )
1952
+ ),
1953
+ sort: A
1954
+ } : void 0
1955
+ ), F = T == null ? void 0 : T.order, k = F ? os(y, p, F, n.columns) : y, O = F ? [...k, ...f.filter(g)] : f, x = _e(k, p).flatMap(
1956
+ (C) => C.columnId ? [C.columnId] : []
1957
+ ), D = new Set((T == null ? void 0 : T.hidden) ?? []);
1958
+ x.length && x.every((C) => D.has(C)) && D.delete(x[0]);
1959
+ const P = o === "screen" ? Ji(t, n, f) : /* @__PURE__ */ new Map(), E = (C, S) => {
1960
+ const V = u(S == null ? void 0 : S.columnId);
1961
+ if ((S == null ? void 0 : S.part) === "base" && V) return V;
1962
+ const N = P.get(C);
1963
+ if (N)
1964
+ return ai(
1965
+ ((S == null ? void 0 : S.part) === "comparison" ? V : void 0) ?? (N.metric.label || N.metric.name),
1966
+ N.kind
1967
+ );
1968
+ const J = m.get(C);
1969
+ if (J) return J;
1970
+ const Z = gi({
1971
+ columnId: C,
1972
+ card: t,
1973
+ columnKeyMap: c,
1974
+ resultColumns: n.columns,
1975
+ // No temporal presentation: a flat table never formats pivot members
1976
+ // as dates (its temporal activation covers group columns only).
1977
+ metricLabelOverride: (S == null ? void 0 : S.part) === "pivot-member" ? V : void 0
1978
+ });
1979
+ return Z || (gn(C, t, c) ?? C);
1980
+ }, R = O.map((C) => {
1981
+ var V;
1982
+ const S = p(C);
1983
+ return {
1984
+ outputKey: C,
1985
+ ...S ? { columnId: S.columnId } : {},
1986
+ part: (S == null ? void 0 : S.part) ?? ((V = l.owners.get(C)) == null ? void 0 : V.part) ?? "base",
1987
+ visible: !g(C) && !(S && D.has(S.columnId)),
1988
+ label: E(C, S)
1989
+ };
1990
+ }), z = Object.fromEntries(
1991
+ R.map((C) => [C.outputKey, C.label])
1992
+ ), Y = a === "page-only" ? [] : a === "query" ? M : (T == null ? void 0 : T.sort) ?? [], Ve = new Map(
1993
+ Y.map((C) => [C.columnId, C.direction])
1994
+ ), ro = Y.flatMap((C) => {
1995
+ var V;
1996
+ const S = (V = l.entries.get(C.columnId)) == null ? void 0 : V.baseKey;
1997
+ return S && y.includes(S) ? [{ outputKey: S, desc: C.direction === "desc" }] : [];
1998
+ }), ct = !i && !!(T != null && T.order || T != null && T.hidden || T != null && T.labels);
1999
+ let ce;
2000
+ if (i)
2001
+ ce = { available: !1, reason: i };
2002
+ else if (!x.length)
2003
+ ce = { available: !1, reason: "no-addressable-columns" };
2004
+ else {
2005
+ const C = new Set(F ?? []), S = x.filter(
2006
+ (V) => !D.has(V)
2007
+ ).length;
2008
+ ce = {
2009
+ available: !0,
2010
+ canReset: ct,
2011
+ items: x.map((V) => {
2012
+ const N = l.entries.get(V), J = D.has(V), Z = Ve.get(V);
2013
+ return {
2014
+ columnId: V,
2015
+ label: u(V) ?? N.authorLabel,
2016
+ authorLabel: N.authorLabel,
2017
+ hidden: J,
2018
+ isNew: F !== void 0 && !C.has(V),
2019
+ canHide: !J && S > 1,
2020
+ ...Z ? { sort: Z } : {}
2021
+ };
2022
+ })
2023
+ };
2024
+ }
2025
+ return {
2026
+ columns: R,
2027
+ visibleKeys: R.filter((C) => C.visible).map((C) => C.outputKey),
2028
+ labels: z,
2029
+ sortMode: a,
2030
+ clientSort: ro,
2031
+ panel: ce,
2032
+ ...T ? { settings: T } : {},
2033
+ dropped: w,
2034
+ isCustomized: ct,
2035
+ canSort: i !== "card-type" && a !== "page-only",
2036
+ author: { order: I }
2037
+ };
2038
+ }
2039
+ function yl(e, t) {
2040
+ var n;
2041
+ return (n = kn(e, t)) == null ? void 0 : n.field;
2042
+ }
2043
+ function kn(e, t) {
2044
+ const n = nn(t), o = e.config;
2045
+ if (!n || !o) return;
2046
+ let r = [], i;
2047
+ if (n.kind === "dimension")
2048
+ i = n.role, r = ((n.role === "detail" ? o.detailColumns : o.groupByColumns) ?? []).filter((a) => a.id === n.fieldId);
2049
+ else if (n.kind === "metric")
2050
+ i = "metric", r = (o.metricColumns ?? []).filter(
2051
+ (s) => s.id === n.metricId && Q(s) === n.metricAlias
2052
+ );
2053
+ else
2054
+ return;
2055
+ return r.length === 1 ? { field: r[0], role: i } : void 0;
2056
+ }
2057
+ function rs(e, t) {
2058
+ const n = t == null ? void 0 : t.sort;
2059
+ if (!n || !e.config || e.type !== "table" && e.type !== "detailTable" || oe(e) !== "config")
2060
+ return e.config;
2061
+ const o = n.flatMap((r) => {
2062
+ const i = kn(e, r.columnId);
2063
+ if (!i) return [];
2064
+ const s = Br(i.field, i.role);
2065
+ return Vn(e, s) ? [] : [
2066
+ {
2067
+ ...i.field,
2068
+ alias: s,
2069
+ role: "sortby",
2070
+ direction: r.direction
2071
+ }
2072
+ ];
2073
+ });
2074
+ return n.length > 0 && o.length === 0 ? e.config : { ...e.config, sortByColumns: o };
2075
+ }
2076
+ function is(e) {
2077
+ if (!e.name)
2078
+ return;
2079
+ const t = e.entityName && e.entityName !== "SEMAPHOR_CALCULATED_FIELD" ? e.entityName : void 0;
2080
+ if (e.role === "metric") {
2081
+ let n = "aggregate" in e && typeof e.aggregate == "string" ? e.aggregate : "metric";
2082
+ if ("expression" in e && typeof e.expression == "string") {
2083
+ const o = e.expression.match(
2084
+ /^(COUNT|SUM|AVG|MIN|MAX|MEDIAN|DISTINCT)\s*\(/i
2085
+ );
2086
+ n = o ? o[1].toLowerCase() : "expr";
2087
+ } else
2088
+ n = n.toLowerCase();
2089
+ return t && t !== e.name ? `${t}_${e.name}_${n}` : `${e.name}_${n}`;
2090
+ }
2091
+ return t && t !== e.name ? `${t}_${e.name}` : e.name;
2092
+ }
2093
+ function ae(e) {
2094
+ return Array.from(
2095
+ new Set(
2096
+ [
2097
+ e.id,
2098
+ e.alias,
2099
+ e.label,
2100
+ e.name,
2101
+ e.qualifiedFieldName,
2102
+ is(e)
2103
+ ].map((t) => typeof t == "string" ? t.trim() : "").filter(Boolean)
2104
+ )
2105
+ );
2106
+ }
2107
+ function tt(e, t) {
2108
+ const n = t ?? e.config, o = (n == null ? void 0 : n.detailColumns) || [], r = (n == null ? void 0 : n.groupByColumns) || [], i = (n == null ? void 0 : n.metricColumns) || [];
2109
+ return [
2110
+ ...o.map((s) => ({ ...s, role: "detail" })),
2111
+ ...r.map((s) => ({ ...s, role: "groupby" })),
2112
+ ...i.map((s) => ({ ...s, role: "metric" }))
2113
+ ].filter((s) => !!s.id);
2114
+ }
2115
+ function bl(e, t) {
2116
+ return t ? !ae(e).some(
2117
+ (n) => t[n] === !1
2118
+ ) : !0;
2119
+ }
2120
+ function Cl(e, t) {
2121
+ for (const n of ae(e))
2122
+ if (t != null && t[n])
2123
+ return n;
2124
+ return e.label || e.name || e.alias || e.id;
2125
+ }
2126
+ function nt(e) {
2127
+ var t;
2128
+ return e.type === "table" && !((t = e.sql) != null && t.trim()) && !!e.config;
2129
+ }
2130
+ function Pn(e) {
2131
+ var t, n, o, r;
2132
+ return ((r = (o = (n = (t = e.preferences) == null ? void 0 : t.tablePrefs) == null ? void 0 : n.tableStyle) == null ? void 0 : o.totals) == null ? void 0 : r.enabled) === !0;
2133
+ }
2134
+ function xn(e) {
2135
+ return nt(e) ? Pn(e) : !1;
2136
+ }
2137
+ function ss(e, t, n) {
2138
+ if (!xn(e))
2139
+ return;
2140
+ const o = tt(e, n).filter((r) => r.role !== "metric").map((r) => new Set(ae(r)));
2141
+ return t.find(
2142
+ (r) => o.some((i) => i.has(r))
2143
+ );
2144
+ }
2145
+ function hl({
2146
+ card: e,
2147
+ effectiveCardConfig: t,
2148
+ visibleColumnIds: n,
2149
+ totalsByColumnId: o
2150
+ }) {
2151
+ if (!xn(e) || !o || Object.keys(o).length === 0)
2152
+ return;
2153
+ const r = ss(
2154
+ e,
2155
+ n,
2156
+ t
2157
+ ), i = new Set(
2158
+ tt(e, t).filter((s) => s.role !== "metric").flatMap(ae)
2159
+ );
2160
+ return Object.fromEntries(
2161
+ n.map((s) => [
2162
+ s,
2163
+ s === r ? "Total" : i.has(s) || !Object.prototype.hasOwnProperty.call(o, s) ? null : o[s]
2164
+ ])
2165
+ );
2166
+ }
2167
+ function Il(e) {
2168
+ var t, n, o, r, i, s;
2169
+ return nt(e) ? {
2170
+ ...e,
2171
+ preferences: {
2172
+ ...e.preferences,
2173
+ tablePrefs: {
2174
+ ...(t = e.preferences) == null ? void 0 : t.tablePrefs,
2175
+ tableStyle: {
2176
+ ...(o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.tableStyle,
2177
+ totals: {
2178
+ ...(s = (i = (r = e.preferences) == null ? void 0 : r.tablePrefs) == null ? void 0 : i.tableStyle) == null ? void 0 : s.totals,
2179
+ enabled: !0
2180
+ }
2181
+ }
2182
+ }
2183
+ }
2184
+ } : e;
2185
+ }
2186
+ function as(e, t, n) {
2187
+ if (!nt(e) || !Pn(e))
2188
+ return;
2189
+ const o = tt(e, t), r = new Set(
2190
+ Pr(
2191
+ o.filter((c) => c.role === "metric")
2192
+ )
2193
+ ), i = o.filter((c) => c.role !== "metric"), s = n && i.find(
2194
+ (c) => ae(c).includes(n)
2195
+ ) || i[0], a = [];
2196
+ for (const c of o) {
2197
+ if (c === s) {
2198
+ a.push({
2199
+ fieldId: c.id,
2200
+ role: c.role,
2201
+ behavior: "label",
2202
+ label: "Total"
2203
+ });
2204
+ continue;
2205
+ }
2206
+ if (c.role === "metric") {
2207
+ const l = Q(c);
2208
+ a.push({
2209
+ fieldId: c.id,
2210
+ role: c.role,
2211
+ behavior: "sum",
2212
+ ...r.has(l) ? { metricAlias: l } : {}
2213
+ });
2214
+ }
2215
+ }
2216
+ return a.length ? {
2217
+ source: "documentFlatTable",
2218
+ columns: a
2219
+ } : void 0;
2220
+ }
2221
+ function vl(e) {
2222
+ var t, n, o, r, i, s;
2223
+ return {
2224
+ ...e,
2225
+ preferences: {
2226
+ ...e.preferences,
2227
+ tablePrefs: {
2228
+ ...(t = e.preferences) == null ? void 0 : t.tablePrefs,
2229
+ tableStyle: {
2230
+ ...(o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.tableStyle,
2231
+ totals: {
2232
+ ...(s = (i = (r = e.preferences) == null ? void 0 : r.tablePrefs) == null ? void 0 : i.tableStyle) == null ? void 0 : s.totals,
2233
+ enabled: !1
2234
+ }
2235
+ }
2236
+ }
2237
+ }
2238
+ };
2239
+ }
2240
+ const ls = 500, cs = 250;
2241
+ function Re(e) {
2242
+ return e.type === "table" || e.type === "detailTable";
2243
+ }
2244
+ function us(e) {
2245
+ var t, n, o;
2246
+ return !!((t = e.sql) != null && t.trim() && Re(e) && ((o = (n = e.preferences) == null ? void 0 : n.tablePrefs) != null && o.enableDevModePagination));
2247
+ }
2248
+ function Fl(e) {
2249
+ return e === "export-full-with-cap" ? ls : cs;
2250
+ }
2251
+ function ds({
2252
+ card: e,
2253
+ isTablePrintMode: t,
2254
+ isDocumentSectionRuntime: n,
2255
+ documentTableDataPolicy: o
2256
+ }) {
2257
+ var c, l;
2258
+ const r = n && o !== void 0 && Re(e), i = t && !r, s = Fe(e.config) && Re(e) && !e.sql, a = r ? us(e) : !!(e.sql && ((l = (c = e.preferences) == null ? void 0 : c.tablePrefs) != null && l.enableDevModePagination));
2259
+ return !i && (s || a);
2260
+ }
2261
+ function fs(e) {
2262
+ var t, n, o;
2263
+ return ((t = e.paginationConfig) == null ? void 0 : t.pageSize) || ((o = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : o.pageSize) || 50;
2264
+ }
2265
+ function Sl({
2266
+ current: e,
2267
+ defaultPageSize: t,
2268
+ queryInputIdentity: n
2269
+ }) {
2270
+ return (e == null ? void 0 : e.queryInputIdentity) === n ? {
2271
+ page: e.page,
2272
+ pageSize: e.pageSize
2273
+ } : {
2274
+ page: 1,
2275
+ pageSize: (e == null ? void 0 : e.pageSize) ?? t
2276
+ };
2277
+ }
2278
+ function Tl(e, t, n) {
2279
+ return (e == null ? void 0 : e.queryInputIdentity) === n && e.page === t.page && e.pageSize === t.pageSize;
2280
+ }
2281
+ function Dl(e, t) {
2282
+ return !e || !t || e.page === t.page && e.pageSize === t.pageSize ? e : {
2283
+ ...e,
2284
+ page: t.page,
2285
+ pageSize: t.pageSize,
2286
+ hasPrevPage: t.page > 1
2287
+ };
2288
+ }
2289
+ function ps(e) {
2290
+ return { page: 1, pageSize: fs(e) };
2291
+ }
2292
+ function ms(e) {
2293
+ var s, a, c, l, u;
2294
+ const { card: t } = e, n = ds({
2295
+ card: t,
2296
+ isTablePrintMode: ((s = e.display) == null ? void 0 : s.isTablePrintMode) ?? !1,
2297
+ isDocumentSectionRuntime: !!e.documentSection,
2298
+ documentTableDataPolicy: (a = e.documentSection) == null ? void 0 : a.documentTableDataPolicy
2299
+ }), { page: o } = e, r = e.tableTotalsRequest ?? (e.documentSection ? void 0 : as(t, e.finalConfig)), i = !!((c = e.display) != null && c.deliveryStrict && e.display.isTablePrintMode && !e.documentSection && xr(t.type));
2300
+ return {
2301
+ ...r ? { tableTotalsRequest: r } : {},
2302
+ ...i ? { sourceRowProbe: { limit: wr.maxTableRows } } : {},
2303
+ ...n ? {
2304
+ pagination: {
2305
+ page: (o == null ? void 0 : o.page) || 1,
2306
+ pageSize: (o == null ? void 0 : o.pageSize) || ((u = (l = t.preferences) == null ? void 0 : l.tablePrefs) == null ? void 0 : u.pageSize) || 50
2307
+ }
2308
+ } : {}
2309
+ };
2310
+ }
2311
+ function gs(e, t = {}) {
2312
+ var r, i, s;
2313
+ const n = ((r = e.connectionId) == null ? void 0 : r.trim()) || void 0;
2314
+ if (t.editorDevMode) return n;
2315
+ const o = ((s = (i = e.dataSource) == null ? void 0 : i.connectionId) == null ? void 0 : s.trim()) || void 0;
2316
+ return e.sql ? n || o : o || n;
2317
+ }
2318
+ function ys(e, t) {
2319
+ var n;
2320
+ return {
2321
+ connectionId: t,
2322
+ connectionType: ((n = e.dataSource) == null ? void 0 : n.connectionType) || "unknown",
2323
+ mode: "database",
2324
+ selectedEntities: []
2325
+ };
2326
+ }
2327
+ function Ml(e, t, n = {}) {
2328
+ const o = gs(e, n);
2329
+ if (!o)
2330
+ throw new Error("No connection ID found for card");
2331
+ const r = t.cardDataSource || e.dataSource;
2332
+ return {
2333
+ connectionId: o,
2334
+ requestPayloadBase: {
2335
+ ...t,
2336
+ cardDataSource: n.liveDataSource ? r : r || ys(e, o)
2337
+ }
2338
+ };
2339
+ }
2340
+ const bs = /* @__PURE__ */ new Set([
2341
+ "day",
2342
+ "week",
2343
+ "month",
2344
+ "quarter",
2345
+ "year",
2346
+ "hour",
2347
+ "minute",
2348
+ "second"
2349
+ ]);
2350
+ function Cs(e) {
2351
+ let t = e.spec;
2352
+ const n = Rt(
2353
+ e.controlDefinitions || [],
2354
+ e.cardControlDefinitions || []
2355
+ ), o = (e.controlBindings || []).filter(
2356
+ (p) => p.target !== "sql_param"
2357
+ ), r = o.filter(
2358
+ (p) => p.target === "config_metric_selector" || p.target === "config_field_selector"
2359
+ ), i = o.filter(
2360
+ (p) => p.target === "config_grain" || p.target === "config_aggregation"
2361
+ ), s = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
2362
+ let c;
2363
+ const l = () => {
2364
+ if (c) return c;
2365
+ const p = e.catalog, y = /* @__PURE__ */ new Map();
2366
+ for (const b of p) {
2367
+ const I = y.get(b.id) ?? [];
2368
+ y.set(b.id, [...I, b]);
2369
+ }
2370
+ return c = { refs: p, byId: y }, c;
2371
+ }, u = (p, y) => {
2372
+ throw new Vo(p, {
2373
+ code: ko,
2374
+ ...y ? { controlId: y } : {}
2375
+ });
2376
+ }, d = (p, y) => {
2377
+ var I;
2378
+ if (p.derivedField) return p.derivedField.dataType;
2379
+ const b = l().refs.filter((v) => v.field.name === p.name && Oe(v.field.source ?? e.spec.source, p.source ?? e.spec.source));
2380
+ return b.length > 1 ? u("The selected field is ambiguous in the authorized Matrix field catalog.", y) : re(((I = b[0]) == null ? void 0 : I.field.dataType) ?? p.dataType);
2381
+ }, f = (p, y) => Fo(p, y.target, (b) => d(b, y.controlId)), m = lr.safeParse(t);
2382
+ if (!m.success) return u(m.error.message);
2383
+ t = m.data;
2384
+ const g = [...r, ...i].map((p) => {
2385
+ const y = Kt({ binding: p, definitions: n, controlValues: e.controlValues }), b = !p.matrixTargetId && y !== void 0 && y !== Ae ? f(m.data, p) : [];
2386
+ return {
2387
+ binding: p,
2388
+ selectedValue: y,
2389
+ targetId: p.matrixTargetId ?? (b.length === 1 ? b[0].id : void 0)
2390
+ };
2391
+ });
2392
+ for (const { binding: p, targetId: y, selectedValue: b } of g) {
2393
+ if (b === void 0 || b === Ae)
2394
+ continue;
2395
+ const I = (F) => u(F, p.controlId), v = p.target === "config_metric_selector" || p.target === "config_aggregation", M = f(t, p);
2396
+ (!y || !M.some((F) => F.id === y)) && I("Choose a valid Matrix level or measure target for this control.");
2397
+ const h = `${p.target}:${y}`;
2398
+ s.has(h) && I("Multiple controls cannot replace the same Matrix target."), s.add(h);
2399
+ const w = (F) => {
2400
+ const k = (l().byId.get(F.id) ?? []).filter((x) => !F.source || Oe(F.source, x.field.source ?? e.spec.source));
2401
+ if (k.length !== 1) return I(k.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
2402
+ const O = ur.safeParse(k[0].field);
2403
+ return O.success ? O.data : I(O.error.message);
2404
+ }, A = p.target === "config_metric_selector" || p.target === "config_field_selector" ? p.mapping[b] : void 0, T = A && typeof A == "object" && "kind" in A && A.kind === "matrix_instance" ? A.id : void 0;
2405
+ if (v) {
2406
+ a.set(y, p.controlId);
2407
+ const F = T === void 0 ? void 0 : m.data.measures.find(
2408
+ (D) => D.id === T && D.kind === "aggregate"
2409
+ );
2410
+ T !== void 0 && !F && I("The selected Matrix aggregate measure is no longer available.");
2411
+ const k = p.target === "config_metric_selector" && !F ? So({ binding: p, selectedValue: b }) : void 0, O = ((F == null ? void 0 : F.kind) === "aggregate" ? F.aggregate : k == null ? void 0 : k.aggregate) ?? (p.target === "config_aggregation" ? mt({ binding: p, selectedValue: b }) : void 0), x = O === void 0 ? void 0 : cr.safeParse(O);
2412
+ x && !x.success && I("This aggregation is not supported by Matrix."), t = {
2413
+ ...t,
2414
+ measures: t.measures.map(
2415
+ (D) => D.id !== y || D.kind !== "aggregate" ? D : {
2416
+ ...D,
2417
+ ...k ? { field: w(k) } : {},
2418
+ ...(F == null ? void 0 : F.kind) === "aggregate" ? { field: F.field } : {},
2419
+ aggregate: x != null && x.success ? x.data : D.aggregate
2420
+ }
2421
+ )
2422
+ };
2423
+ } else {
2424
+ const F = T === void 0 ? void 0 : [...m.data.rows, ...m.data.columns].find(
2425
+ (D) => D.id === T
2426
+ );
2427
+ T !== void 0 && !F && I("The selected Matrix level is no longer available.");
2428
+ const k = p.target === "config_field_selector" && !F ? To({ binding: p, selectedValue: b }) : void 0, O = p.target === "config_grain" ? mt({ binding: p, selectedValue: b }) : F ? F.grain : k == null ? void 0 : k.granularity;
2429
+ O !== void 0 && !bs.has(O) && I("This time grain is not supported by Matrix.");
2430
+ const x = (D) => D.map((P) => {
2431
+ if (P.id !== y) return P;
2432
+ const E = (F == null ? void 0 : F.field) ?? (k ? w(k) : P.field), R = d(E, p.controlId), z = O ?? (k && yt(R) ? P.grain : void 0);
2433
+ return z && !yt(R) && I("A time grain requires a temporal Matrix level."), { ...P, field: E, grain: z };
2434
+ });
2435
+ t = {
2436
+ ...t,
2437
+ rows: x(t.rows),
2438
+ columns: x(t.columns)
2439
+ };
2440
+ }
2441
+ }
2442
+ for (const [p, y] of Array.from(a)) {
2443
+ const b = t.measures.find((v) => v.id === p);
2444
+ if (!b || b.kind !== "aggregate") continue;
2445
+ const I = d(b.field, y);
2446
+ Do(I).some((v) => v.value === b.aggregate) || u(`Aggregation '${b.aggregate}' is not eligible for this Matrix field datatype.`, y);
2447
+ }
2448
+ try {
2449
+ return Mo(m.data, t);
2450
+ } catch (p) {
2451
+ if (p instanceof pr) return u(p.message);
2452
+ throw p;
2453
+ }
2454
+ }
2455
+ function wn(e, t) {
2456
+ const n = [], o = (r) => {
2457
+ if (r.source) {
2458
+ const i = dr.safeParse(r.source);
2459
+ if (i.success) n.push(i.data);
2460
+ else if (t) throw i.error;
2461
+ }
2462
+ r.derivedField && Object.values(r.derivedField.inputs).forEach((i) => o(i.field));
2463
+ };
2464
+ for (const r of e) {
2465
+ if (r.target !== "config_field_selector" && r.target !== "config_metric_selector") continue;
2466
+ const i = t == null ? void 0 : t.get(r), s = t ? i && i !== Ae ? [r.mapping[i]] : [] : Object.values(r.mapping);
2467
+ for (const a of s)
2468
+ a && "role" in a && o(a);
2469
+ }
2470
+ return n;
2471
+ }
2472
+ function hs(e, t = [], n = []) {
2473
+ return Ht([...cn(e), ...wn(t), ...n]);
2474
+ }
2475
+ function Is(e, t = {}) {
2476
+ const n = t.controlBindings ?? [], o = Rt(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), r = new Map(n.filter((i) => i.target === "config_field_selector" || i.target === "config_metric_selector").map((i) => [i, Kt({ binding: i, definitions: o, controlValues: t.controlValues })]));
2477
+ return Ht([...cn(e), ...wn(n, r)]);
2478
+ }
2479
+ function vs(e, t) {
2480
+ return {
2481
+ id: t,
2482
+ field: e.field,
2483
+ operator: e.operator,
2484
+ value: e.value,
2485
+ label: e.label,
2486
+ temporalBucket: e.temporalBucket,
2487
+ ...e.rawTemporal ? { rawTemporal: e.rawTemporal } : {}
2488
+ };
2489
+ }
2490
+ function Fs(e, t) {
2491
+ return Ne(e) ? Ss(e, t) : e.config ?? {};
2492
+ }
2493
+ function Ss(e, t) {
2494
+ var o;
2495
+ const n = (o = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : o.toField;
2496
+ return n ? si(e.config ?? {}, n, {
2497
+ sortPolicy: "retargetDimensionSort"
2498
+ }) : e.config ?? {};
2499
+ }
2500
+ function Ts(e, t) {
2501
+ const n = (e == null ? void 0 : e.steps) ?? [];
2502
+ if (n.length !== 0)
2503
+ return {
2504
+ id: `${t}-drill-root`,
2505
+ logicalOperator: "AND",
2506
+ negate: !1,
2507
+ conditions: [],
2508
+ groups: n.map((o, r) => ({
2509
+ id: `breadcrumb-${r}`,
2510
+ logicalOperator: "OR",
2511
+ negate: !1,
2512
+ conditions: [],
2513
+ groups: [
2514
+ {
2515
+ id: `breadcrumb-${r}-group-0`,
2516
+ logicalOperator: "AND",
2517
+ negate: !1,
2518
+ conditions: o.conditions.map(
2519
+ (i) => vs(
2520
+ i,
2521
+ `${i.field.id}-${i.value}`
2522
+ )
2523
+ ),
2524
+ groups: []
2525
+ }
2526
+ ]
2527
+ }))
2528
+ };
2529
+ }
2530
+ function ot(e) {
2531
+ return e === "in" || e === "not in";
2532
+ }
2533
+ function rt(e) {
2534
+ return e === "not in" ? "exclude" : "include";
2535
+ }
2536
+ function Ds(e) {
2537
+ return e === "exclude" ? "not in" : "in";
2538
+ }
2539
+ function Vl(e) {
2540
+ var n;
2541
+ const t = (n = e.liveValue) == null ? void 0 : n.operation;
2542
+ return ot(t) ? rt(t) : e.pendingMode ?? e.authoredMode;
2543
+ }
2544
+ function Ms(e) {
2545
+ var o;
2546
+ let t = !1;
2547
+ const n = (o = e.inputs) == null ? void 0 : o.map((r) => {
2548
+ if (r.kind !== "filter" || !r.filter) return r;
2549
+ const i = Vs(
2550
+ r.filter,
2551
+ new Set(ks(e.defaultInputValues, r))
2552
+ );
2553
+ return i === r.filter ? r : (t = !0, { ...r, filter: i });
2554
+ });
2555
+ return t ? { ...e, inputs: n } : e;
2556
+ }
2557
+ function Vs(e, t) {
2558
+ if (t.size !== 1 || !ot(e.operation))
2559
+ return e;
2560
+ const [n] = t;
2561
+ return rt(e.operation) === n ? e : { ...e, operation: Ds(n) };
2562
+ }
2563
+ function ks(e, t) {
2564
+ var r;
2565
+ const n = (i) => Object.values(i ?? {}).map((s) => s[t.id]);
2566
+ return (t.runtimeScope === "shared" ? [(r = e == null ? void 0 : e.shared) == null ? void 0 : r[t.id]] : t.runtimeScope === "perSheet" ? n(e == null ? void 0 : e.bySheetId) : t.runtimeScope === "perCard" ? n(e == null ? void 0 : e.byCardId) : t.runtimeScope === "perDocumentSection" ? n(e == null ? void 0 : e.byDocumentSectionId) : []).flatMap(
2567
+ (i) => (i == null ? void 0 : i.status) === "set" && i.value.kind === "filter" ? Ps(i.value.filterValue) : []
2568
+ );
2569
+ }
2570
+ function Ps(e) {
2571
+ return ot(e.operation) ? [rt(e.operation)] : [];
2572
+ }
2573
+ function kl(e) {
2574
+ const t = Qt(e), o = K(t).issues.length ? t : Pa(t);
2575
+ return ri(Ms(o)).dashboard;
2576
+ }
2577
+ function it(e, t) {
2578
+ const n = {};
2579
+ for (const o of Zt(e)) {
2580
+ if (!o.inlineFilters || o.inlineFilters.length === 0)
2581
+ continue;
2582
+ const r = [];
2583
+ for (const i of o.inlineFilters) {
2584
+ const s = Po(i, t);
2585
+ s && r.push(s);
2586
+ }
2587
+ r.length > 0 && (n[o.id] = r);
2588
+ }
2589
+ return n;
2590
+ }
2591
+ function ne(e) {
2592
+ const t = Se(e ?? {}), n = [];
2593
+ for (const [o, r] of Object.entries(t.shared ?? {}))
2594
+ n.push({ scope: "shared", target: null, inputId: o, slot: r });
2595
+ for (const o of ["bySheetId", "byCardId"])
2596
+ for (const [r, i] of Object.entries(t[o] ?? {}))
2597
+ for (const [s, a] of Object.entries(i))
2598
+ n.push({ scope: o, target: r, inputId: s, slot: a });
2599
+ return n;
2600
+ }
2601
+ function Ie(e, t, n) {
2602
+ const o = e;
2603
+ if (t.scope === "shared") {
2604
+ o.shared = { ...o.shared, [t.inputId]: n };
2605
+ return;
2606
+ }
2607
+ const r = { ...o[t.scope] ?? {} };
2608
+ r[t.target] = { ...r[t.target], [t.inputId]: n }, o[t.scope] = r;
2609
+ }
2610
+ function On(e, t, n) {
2611
+ const o = qt(
2612
+ e,
2613
+ t.controlOverrides,
2614
+ { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
2615
+ );
2616
+ return {
2617
+ adHocFilterValues: [...t.adHocFilterValues],
2618
+ controlValues: o.dashboardControlValues,
2619
+ cardControlValuesMap: o.cardControlValuesMap,
2620
+ dashboardInputValues: t.dashboardInputValues,
2621
+ inlineFilterValuesMap: t.inlineFilterValuesMap ?? it(e, n)
2622
+ };
2623
+ }
2624
+ function st(e, t, n) {
2625
+ return An(
2626
+ e,
2627
+ On(e, t, n),
2628
+ n
2629
+ );
2630
+ }
2631
+ function Pl(e, t, n) {
2632
+ return An(e, t, n);
2633
+ }
2634
+ function An(e, t, n) {
2635
+ const o = e.sheets ?? [], r = o.filter((a) => (a.kind ?? "dashboard") === "dashboard").map((a) => a.id), i = o.filter((a) => a.kind === "document"), s = r.length ? wo({
2636
+ dashboard: e,
2637
+ sheetIds: r,
2638
+ mode: "dashboard",
2639
+ runtimeValues: t,
2640
+ transientContexts: void 0,
2641
+ calendar: n ?? null
2642
+ }).snapshot.dashboardInputValues : {};
2643
+ return i.reduce(
2644
+ (a, c) => {
2645
+ var l;
2646
+ return ze(
2647
+ a,
2648
+ Oo({
2649
+ dashboard: e,
2650
+ sheetId: c.id,
2651
+ sheetKind: "document",
2652
+ mode: "document",
2653
+ sectionIds: (((l = c.document) == null ? void 0 : l.sections) ?? []).map(
2654
+ (u) => u.id
2655
+ ),
2656
+ runtimeValues: t,
2657
+ transientContexts: void 0,
2658
+ calendar: n ?? null
2659
+ }).snapshot.dashboardInputValues
2660
+ );
2661
+ },
2662
+ s
2663
+ );
2664
+ }
2665
+ function En(e, t) {
2666
+ const n = {}, o = {}, r = /* @__PURE__ */ new Map();
2667
+ for (const i of ne(t)) {
2668
+ const s = e.get(i.inputId), { slot: a } = i, c = () => a.status === "set" && a.value.kind === "filter" ? a.value.filterValue : a.status === "cleared" ? null : void 0;
2669
+ if ((s == null ? void 0 : s.source) === "cardInlineFilter") {
2670
+ const l = c();
2671
+ if (l !== void 0) {
2672
+ const u = r.get(s.cardId) ?? /* @__PURE__ */ new Map();
2673
+ u.set(s.filterId, l), r.set(s.cardId, u);
2674
+ }
2675
+ } else if ((s == null ? void 0 : s.source) === "dashboardControl" || (s == null ? void 0 : s.source) === "cardControl")
2676
+ a.status === "set" && a.value.kind === "control" ? o[s.controlId] = a.value.value : a.status === "cleared" && (o[s.controlId] = void 0);
2677
+ else {
2678
+ Ie(n, i, a);
2679
+ continue;
2680
+ }
2681
+ a.comparisonSelection && Ie(n, i, {
2682
+ comparisonSelection: a.comparisonSelection
2683
+ });
2684
+ }
2685
+ return {
2686
+ runtime: Se(n),
2687
+ controlValues: o,
2688
+ inlineFilterValues: r
2689
+ };
2690
+ }
2691
+ function xs(e, t) {
2692
+ if (!t.size) return [...e];
2693
+ const n = e.filter((r) => !t.has(r.filterId)), o = [...t.values()].filter(
2694
+ (r) => r !== null
2695
+ );
2696
+ return Ao(n, o);
2697
+ }
2698
+ function Bn(e, t, n) {
2699
+ if (!Object.keys(n).length) return t;
2700
+ const o = qt(
2701
+ e,
2702
+ t,
2703
+ { hasExplicitRuntimeOverrides: t !== void 0 }
2704
+ );
2705
+ return {
2706
+ ...xo({
2707
+ dashboardValues: o.dashboardControlValues,
2708
+ cardValuesMap: o.cardControlValuesMap
2709
+ }),
2710
+ ...n
2711
+ };
2712
+ }
2713
+ function ws(e, t) {
2714
+ if (!t.size) return;
2715
+ const n = Object.fromEntries(
2716
+ Object.entries(e).map(([o, r]) => [o, [...r]])
2717
+ );
2718
+ for (const [o, r] of t)
2719
+ n[o] = xs(n[o] ?? [], r);
2720
+ return n;
2721
+ }
2722
+ function Os(e, t, n) {
2723
+ const o = new Map(
2724
+ H(e).map(({ card: s }) => [
2725
+ s.id,
2726
+ new Map((s.inlineFilters ?? []).map((a) => [a.id, a]))
2727
+ ])
2728
+ );
2729
+ let r = !1;
2730
+ const i = Object.fromEntries(
2731
+ Object.entries(t).map(([s, a]) => [s, [...a]])
2732
+ );
2733
+ for (const [s, a] of Object.entries(n)) {
2734
+ const c = o.get(s), l = (a ?? []).filter((u) => {
2735
+ const d = c == null ? void 0 : c.get(u.filterId);
2736
+ return d ? je(d, u) : !1;
2737
+ });
2738
+ Te(l, i[s] ?? []) || (r = !0), i[s] = l;
2739
+ }
2740
+ return r ? i : void 0;
2741
+ }
2742
+ function xl(e) {
2743
+ const { dashboard: t, capture: n, calendar: o } = e, r = oo(t, n.filterValues, {
2744
+ calendar: o
2745
+ }), i = n.dashboardInputExecutionSnapshot, s = n.controlValues, a = {
2746
+ ...On(
2747
+ t,
2748
+ {
2749
+ adHocFilterValues: r.adHocFilterValues,
2750
+ controlOverrides: s,
2751
+ // The snapshot replays exactly over the listed values.
2752
+ dashboardInputValues: i ? ze(
2753
+ r.slots,
2754
+ Bo({
2755
+ dashboard: t,
2756
+ dashboardInputValues: i.dashboardInputValues,
2757
+ sheetId: i.sheetId,
2758
+ cardId: i.cardId
2759
+ })
2760
+ ) : r.slots
2761
+ },
2762
+ o
2763
+ ),
2764
+ cardViewState: i ? Eo(i.cardViewState) : {}
2765
+ }, c = i ? _o(i.transientContexts) : void 0;
2766
+ return {
2767
+ runtimeValues: a,
2768
+ controlOverrides: s,
2769
+ ...c != null && c.length ? { transientContexts: c } : {}
2770
+ };
2771
+ }
2772
+ function wl(e, t) {
2773
+ const { controlContractOverrides: n, cardId: o } = t;
2774
+ if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof o != "string" || o.trim().length === 0))
2775
+ return e;
2776
+ const r = ie(e, o);
2777
+ return r && (n.cardControlDefinitions !== void 0 && (r.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (r.controlBindings = n.controlBindings)), e;
2778
+ }
2779
+ const As = ["bySheetId", "byCardId", "byDocumentSectionId"];
2780
+ function Es(e, t) {
2781
+ const n = K(e);
2782
+ let o = !1;
2783
+ const r = (s) => {
2784
+ if (!s) return s;
2785
+ const a = Object.entries(s).filter(([c, l]) => {
2786
+ var d;
2787
+ if (l.status !== "set" || l.value.kind !== "filter") return !0;
2788
+ const u = (d = n.findFilterInput({ inputId: c })) == null ? void 0 : d.input.filter;
2789
+ return !u || je(u, l.value.filterValue) ? !0 : (o = !0, !1);
2790
+ });
2791
+ return Object.fromEntries(a);
2792
+ }, i = {
2793
+ ...t,
2794
+ ...t.shared ? { shared: r(t.shared) } : {}
2795
+ };
2796
+ for (const s of As) {
2797
+ const a = t[s];
2798
+ a && (i[s] = Object.fromEntries(
2799
+ Object.entries(a).map(([c, l]) => [c, r(l) ?? {}])
2800
+ ));
2801
+ }
2802
+ return o ? i : t;
2803
+ }
2804
+ function Bs(e) {
2805
+ var t, n;
2806
+ return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
2807
+ }
2808
+ function le(e, t) {
2809
+ var n;
2810
+ return !!t && !!((n = e.sheets) != null && n.some((o) => o.id === t));
2811
+ }
2812
+ function Ol(e) {
2813
+ const { dashboard: t, host: n, calendar: o } = e, r = oo(t, n.filterValues, {
2814
+ calendar: o
2815
+ }).slots, i = n.controlValues, s = le(t, n.selectedSheetId) ? n.selectedSheetId : Bs(t);
2816
+ return {
2817
+ hostInputValues: r,
2818
+ controlOverrides: i,
2819
+ selectedSheetId: s,
2820
+ hostSelectedSheetId: n.selectedSheetId ?? null,
2821
+ materializedInputs: e.materializeInputs === !1 ? {} : st(
2822
+ t,
2823
+ {
2824
+ adHocFilterValues: [],
2825
+ controlOverrides: i,
2826
+ dashboardInputValues: r
2827
+ },
2828
+ o
2829
+ )
2830
+ };
2831
+ }
2832
+ function _n(e) {
2833
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
2834
+ for (const r of Ge(e))
2835
+ r.kind === "filter" && r.filter ? t.set(r.id, r.filter) : r.kind === "control" && n.add(r.id), r.compatibility && o.set(r.id, r.compatibility);
2836
+ return { filterInputs: t, controlInputIds: n, compatibility: o };
2837
+ }
2838
+ function Rn(e, t) {
2839
+ const n = Ut(t);
2840
+ if (!n) return;
2841
+ const o = ie(e, n);
2842
+ return o ? Ro(o, e) ? "applies" : "not-eligible" : "removed";
2843
+ }
2844
+ function Al(e, t) {
2845
+ const n = Rn(e, t);
2846
+ return n ? n === "applies" : Ge(e).some(
2847
+ (o) => o.id === t
2848
+ );
2849
+ }
2850
+ function Kn(e, t, n, o) {
2851
+ if (!n) return {};
2852
+ const r = new Set((e.sheets ?? []).map((l) => l.id)), i = new Set(
2853
+ H(e).map(({ card: l }) => l.id)
2854
+ ), s = K(e), a = (l) => {
2855
+ var d;
2856
+ if (!l) return;
2857
+ const u = {};
2858
+ for (const [f, m] of Object.entries(l)) {
2859
+ const g = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((d = s.findFilterInput({ inputId: f })) == null ? void 0 : d.input.id) ?? f;
2860
+ if (g !== f && l[g]) continue;
2861
+ const p = Rn(e, g);
2862
+ if (p) {
2863
+ if (p !== "applies") {
2864
+ o.push({
2865
+ kind: "setting-no-longer-applies",
2866
+ target: "selection",
2867
+ id: g,
2868
+ reason: p
2869
+ });
2870
+ continue;
2871
+ }
2872
+ u[g] = m;
2873
+ continue;
2874
+ }
2875
+ const y = t.filterInputs.get(g);
2876
+ if (!y && !t.controlInputIds.has(g)) {
2877
+ o.push({
2878
+ kind: "setting-no-longer-applies",
2879
+ target: "input",
2880
+ id: g,
2881
+ reason: "removed"
2882
+ });
2883
+ continue;
2884
+ }
2885
+ if (y && m.status === "set" && m.value.kind === "filter" && !je(y, m.value.filterValue)) {
2886
+ o.push({
2887
+ kind: "setting-no-longer-applies",
2888
+ target: "input",
2889
+ id: g,
2890
+ reason: "incompatible"
2891
+ });
2892
+ continue;
2893
+ }
2894
+ u[g] = m;
2895
+ }
2896
+ return Object.keys(u).length ? u : void 0;
2897
+ }, c = (l, u) => {
2898
+ if (!l) return;
2899
+ const d = {};
2900
+ for (const [f, m] of Object.entries(l)) {
2901
+ if (!u(f)) {
2902
+ for (const p of Object.keys(m))
2903
+ o.push({
2904
+ kind: "setting-no-longer-applies",
2905
+ target: "input",
2906
+ id: p,
2907
+ reason: "removed"
2908
+ });
2909
+ continue;
2910
+ }
2911
+ const g = a(m);
2912
+ g && (d[f] = g);
2913
+ }
2914
+ return d;
2915
+ };
2916
+ return Se({
2917
+ shared: a(n.shared),
2918
+ bySheetId: c(n.bySheetId, (l) => r.has(l)),
2919
+ byCardId: c(n.byCardId, (l) => i.has(l))
2920
+ // Document sections are not viewer state.
2921
+ });
2922
+ }
2923
+ function B(e, t, n, o = {}) {
2924
+ const r = new Map(
2925
+ H(e).map(({ card: s }) => [s.id, s])
2926
+ ), i = {};
2927
+ for (const [s, a] of Object.entries(t ?? {})) {
2928
+ const c = r.get(s);
2929
+ if (c && en(c)) {
2930
+ Ir(a) || (i[s] = a);
2931
+ continue;
2932
+ }
2933
+ if (c && o.sessionSorts && vr(c)) {
2934
+ a.sort && (i[s] = { sort: a.sort });
2935
+ continue;
2936
+ }
2937
+ n == null || n.push({
2938
+ kind: "setting-no-longer-applies",
2939
+ target: "card",
2940
+ id: s,
2941
+ reason: ie(e, s) ? "not-eligible" : "removed"
2942
+ });
2943
+ }
2944
+ return i;
2945
+ }
2946
+ function _s(e, t, n) {
2947
+ if (t) {
2948
+ if (le(e, t)) return t;
2949
+ n.push({
2950
+ kind: "setting-no-longer-applies",
2951
+ target: "sheet",
2952
+ id: t,
2953
+ reason: "removed"
2954
+ });
2955
+ }
2956
+ }
2957
+ const at = (e, t) => Te(e ?? null, t ?? null);
2958
+ function qn(e) {
2959
+ return {
2960
+ adHocFilterValues: e.adHocFilterValues,
2961
+ controlOverrides: e.controlOverrides,
2962
+ dashboardInputValues: e.dashboardInputValues,
2963
+ ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
2964
+ selectedSheetId: e.selectedSheetId,
2965
+ tableSettings: e.tableSettings
2966
+ };
2967
+ }
2968
+ function de(e, t) {
2969
+ return {
2970
+ adHocFilterValues: [],
2971
+ controlOverrides: e.controlOverrides,
2972
+ dashboardInputValues: e.hostInputValues,
2973
+ selectedSheetId: e.selectedSheetId,
2974
+ tableSettings: t
2975
+ };
2976
+ }
2977
+ function Nn(e, t) {
2978
+ const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
2979
+ return {
2980
+ selectedSheetId: t.selectedSheetId,
2981
+ // Overlay: the bookmark's values on the baseline's runtime values.
2982
+ inputs: n ? e.baseline.materializedInputs : st(e.dashboard, t, e.calendar),
2983
+ tableSettings: t.tableSettings
2984
+ };
2985
+ }
2986
+ function G(e, t) {
2987
+ const n = qn(t), o = t.restore ?? n;
2988
+ return {
2989
+ ...n,
2990
+ appliedBookmarkId: t.appliedBookmarkId,
2991
+ rememberedWrites: t.rememberedWrites ?? [],
2992
+ notices: t.notices ?? [],
2993
+ opened: Nn(e, o),
2994
+ restore: o
2995
+ };
2996
+ }
2997
+ function kt(e, t, n, o) {
2998
+ const { dashboard: r, baseline: i } = e, s = [], a = on(t.state, Qe), c = a.ok ? a.value : {};
2999
+ for (const g of a.ok ? a.issues : [])
3000
+ s.push(Rs(g));
3001
+ const l = _n(r), u = En(
3002
+ l.compatibility,
3003
+ Kn(r, l, c.inputs, s)
3004
+ ), d = _s(r, c.selectedSheetId, s) ?? i.selectedSheetId, f = B(
3005
+ r,
3006
+ c.tableSettings,
3007
+ s
3008
+ ), m = B(
3009
+ r,
3010
+ n,
3011
+ void 0
3012
+ );
3013
+ return G(e, {
3014
+ appliedBookmarkId: t.id,
3015
+ // A bookmark opens without ad-hoc values, as today (P4a-02 f).
3016
+ adHocFilterValues: [],
3017
+ controlOverrides: Bn(
3018
+ r,
3019
+ i.controlOverrides,
3020
+ u.controlValues
3021
+ ),
3022
+ // Overlay, never replacement: the bookmark's slots over the host's.
3023
+ dashboardInputValues: ze(
3024
+ i.hostInputValues,
3025
+ u.runtime
3026
+ ),
3027
+ ...Ln(
3028
+ ws(
3029
+ it(r, e.calendar),
3030
+ u.inlineFilterValues
3031
+ )
3032
+ ),
3033
+ selectedSheetId: d,
3034
+ tableSettings: o.writeRemembered ? { ...m, ...f } : (
3035
+ // A default bookmark on load: remembered settings per card win.
3036
+ { ...f, ...m }
3037
+ ),
3038
+ rememberedWrites: o.writeRemembered ? Object.entries(f).filter(
3039
+ ([g, p]) => !at(m[g], p)
3040
+ ).map(([g, p]) => ({
3041
+ kind: "set",
3042
+ cardId: g,
3043
+ settings: p
3044
+ })) : [],
3045
+ notices: s
3046
+ });
3047
+ }
3048
+ function Rs(e) {
3049
+ return {
3050
+ kind: "setting-no-longer-applies",
3051
+ target: e.target,
3052
+ id: e.id,
3053
+ reason: "invalid"
3054
+ };
3055
+ }
3056
+ function Ln(e) {
3057
+ return e ? { inlineFilterValuesMap: e } : {};
3058
+ }
3059
+ function Pt(e, t, n) {
3060
+ const { dashboard: o, baseline: r } = e;
3061
+ return {
3062
+ // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
3063
+ // template now defines a filter with that id.
3064
+ adHocFilterValues: t.adHocFilterValues.filter(
3065
+ (i) => !K(o).findFilterInput({ filterId: i.filterId })
3066
+ ),
3067
+ // A host's new control defaults are the baseline's, not the viewer's.
3068
+ controlOverrides: n.controlsChanged ? r.controlOverrides : t.controlOverrides,
3069
+ // Live slots stay, except a filter value this template no longer accepts:
3070
+ // that filter loads its new default, as the old list did. The resolver
3071
+ // ignores slots this template no longer has.
3072
+ dashboardInputValues: Es(
3073
+ o,
3074
+ t.dashboardInputValues
3075
+ ),
3076
+ ...Ln(
3077
+ Os(
3078
+ o,
3079
+ it(o, e.calendar),
3080
+ t.inlineFilterValuesMap ?? {}
3081
+ )
3082
+ ),
3083
+ selectedSheetId: !n.sheetChanged && le(o, t.selectedSheetId) ? t.selectedSheetId : r.selectedSheetId,
3084
+ tableSettings: B(
3085
+ o,
3086
+ t.tableSettings,
3087
+ void 0,
3088
+ { sessionSorts: !0 }
3089
+ )
3090
+ };
3091
+ }
3092
+ function El(e) {
3093
+ const { dashboard: t, baseline: n, event: o } = e, r = e.rememberedTableSettings;
3094
+ switch (o.kind) {
3095
+ case "initial-load":
3096
+ return o.defaultBookmark ? kt(e, o.defaultBookmark, r, {
3097
+ writeRemembered: !1
3098
+ }) : G(e, {
3099
+ appliedBookmarkId: null,
3100
+ ...de(
3101
+ n,
3102
+ B(t, r, void 0, {
3103
+ sessionSorts: o.captured
3104
+ })
3105
+ )
3106
+ });
3107
+ case "refetch": {
3108
+ const { live: i } = o, s = i.applied, a = {
3109
+ sheetChanged: !!i.previousBaseline && i.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
3110
+ controlsChanged: !!i.previousBaseline && !Te(
3111
+ i.previousBaseline.controlOverrides ?? null,
3112
+ n.controlOverrides ?? null
3113
+ )
3114
+ }, c = Pt(
3115
+ e,
3116
+ {
3117
+ adHocFilterValues: i.adHocFilterValues,
3118
+ controlOverrides: i.controlValues ?? n.controlOverrides,
3119
+ dashboardInputValues: i.dashboardInputValues,
3120
+ inlineFilterValuesMap: i.inlineFilterValuesMap,
3121
+ selectedSheetId: i.selectedSheetId,
3122
+ tableSettings: i.tableSettings
3123
+ },
3124
+ a
3125
+ ), l = s ? Pt(e, s.restore, a) : de(
3126
+ n,
3127
+ B(t, r, void 0)
3128
+ );
3129
+ return G(e, {
3130
+ appliedBookmarkId: (s == null ? void 0 : s.appliedBookmarkId) ?? null,
3131
+ ...c,
3132
+ notices: (s == null ? void 0 : s.notices) ?? [],
3133
+ restore: l
3134
+ });
3135
+ }
3136
+ case "open-bookmark":
3137
+ return kt(e, o.bookmark, r, {
3138
+ writeRemembered: !0
3139
+ });
3140
+ case "open-default-view":
3141
+ return G(e, {
3142
+ appliedBookmarkId: null,
3143
+ ...de(
3144
+ n,
3145
+ B(t, r, void 0)
3146
+ )
3147
+ });
3148
+ case "reset-to-default-view":
3149
+ return G(e, {
3150
+ appliedBookmarkId: null,
3151
+ ...de(n, {}),
3152
+ rememberedWrites: [{ kind: "clear-all" }]
3153
+ });
3154
+ case "discard-changes": {
3155
+ const { restore: i } = o.applied, s = B(
3156
+ t,
3157
+ i.tableSettings,
3158
+ void 0,
3159
+ { sessionSorts: !0 }
3160
+ ), a = B(t, s, void 0), c = B(t, r, void 0), l = [];
3161
+ for (const u of /* @__PURE__ */ new Set([
3162
+ ...Object.keys(c),
3163
+ ...Object.keys(a)
3164
+ ])) {
3165
+ if (at(c[u], a[u])) continue;
3166
+ const d = a[u];
3167
+ l.push(
3168
+ d ? { kind: "set", cardId: u, settings: d } : { kind: "clear", cardId: u }
3169
+ );
3170
+ }
3171
+ return G(e, {
3172
+ appliedBookmarkId: o.applied.appliedBookmarkId,
3173
+ ...i,
3174
+ selectedSheetId: le(t, i.selectedSheetId) ? i.selectedSheetId : n.selectedSheetId,
3175
+ tableSettings: s,
3176
+ rememberedWrites: l,
3177
+ notices: o.applied.notices,
3178
+ restore: i
3179
+ });
3180
+ }
3181
+ }
3182
+ }
3183
+ function Bl(e) {
3184
+ const { dashboard: t, calendar: n } = e, o = e.hostControlValues, r = {
3185
+ ...e.baseline,
3186
+ controlOverrides: o,
3187
+ materializedInputs: st(
3188
+ t,
3189
+ {
3190
+ adHocFilterValues: [],
3191
+ controlOverrides: o,
3192
+ dashboardInputValues: e.baseline.hostInputValues
3193
+ },
3194
+ n
3195
+ )
3196
+ };
3197
+ let i = o;
3198
+ if (e.appliedBookmark) {
3199
+ const c = on(
3200
+ e.appliedBookmark.state,
3201
+ Qe
3202
+ ), l = _n(t), u = En(
3203
+ l.compatibility,
3204
+ Kn(
3205
+ t,
3206
+ l,
3207
+ c.ok ? c.value.inputs : void 0,
3208
+ []
3209
+ )
3210
+ ).controlValues;
3211
+ i = Bn(t, o, u);
3212
+ }
3213
+ const s = e.applied;
3214
+ if (!s) return { baseline: r, controlOverrides: i, applied: null };
3215
+ const a = { ...s.restore, controlOverrides: i };
3216
+ return {
3217
+ baseline: r,
3218
+ controlOverrides: i,
3219
+ applied: {
3220
+ ...s,
3221
+ controlOverrides: i,
3222
+ restore: a,
3223
+ opened: Nn({ dashboard: t, baseline: r, calendar: n }, a)
3224
+ }
3225
+ };
3226
+ }
3227
+ function _l(e, t, n) {
3228
+ const o = qn(n.values);
3229
+ return {
3230
+ ...o,
3231
+ appliedBookmarkId: t,
3232
+ rememberedWrites: [],
3233
+ notices: e.notices,
3234
+ opened: n.snapshot,
3235
+ restore: o
3236
+ };
3237
+ }
3238
+ const xt = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
3239
+ function fe(e) {
3240
+ return !e || e.status === "cleared" && !e.comparisonSelection;
3241
+ }
3242
+ function jn(e, t) {
3243
+ const n = new Map(
3244
+ ne(e).map((i) => [xt(i), i])
3245
+ ), o = new Map(
3246
+ ne(t).map((i) => [xt(i), i])
3247
+ ), r = {};
3248
+ for (const [i, s] of o) {
3249
+ const a = n.get(i);
3250
+ a && Te(a.slot, s.slot) || fe(s.slot) && fe(a == null ? void 0 : a.slot) || Ie(
3251
+ r,
3252
+ s,
3253
+ fe(s.slot) ? { status: "cleared" } : s.slot
3254
+ );
3255
+ }
3256
+ for (const [i, s] of n)
3257
+ o.has(i) || fe(s.slot) || Ie(r, s, { status: "cleared" });
3258
+ return Se(r);
3259
+ }
3260
+ function Rl(e) {
3261
+ const { dashboard: t, baseline: n, current: o } = e, r = jn(n.materializedInputs, o.inputs), i = B(
3262
+ t,
3263
+ o.tableSettings,
3264
+ void 0
3265
+ ), s = o.selectedSheetId && o.selectedSheetId !== n.selectedSheetId && le(t, o.selectedSheetId) ? o.selectedSheetId : void 0;
3266
+ return {
3267
+ version: Qe,
3268
+ ...s ? { selectedSheetId: s } : {},
3269
+ ...ne(r).length ? { inputs: r } : {},
3270
+ ...Object.keys(i).length ? { tableSettings: i } : {}
3271
+ };
3272
+ }
3273
+ function Ks(e) {
3274
+ const t = /* @__PURE__ */ new Map();
3275
+ for (const n of Ge(e))
3276
+ n.label && t.set(n.id, n.label);
3277
+ return t;
3278
+ }
3279
+ function qs(e, t, n) {
3280
+ var r, i;
3281
+ const o = Ut(n);
3282
+ if (o) {
3283
+ const s = (i = (r = ie(e, o)) == null ? void 0 : r.title) == null ? void 0 : i.trim();
3284
+ return s ? `Selection in ${s}` : "Selection";
3285
+ }
3286
+ return t.get(n) ?? n;
3287
+ }
3288
+ function Kl(e) {
3289
+ var l, u;
3290
+ const { dashboard: t, opened: n, current: o } = e, r = [], i = Ks(t), s = /* @__PURE__ */ new Set();
3291
+ for (const d of ne(
3292
+ jn(n.inputs, o.inputs)
3293
+ ))
3294
+ s.has(d.inputId) || (s.add(d.inputId), r.push({
3295
+ target: "input",
3296
+ inputId: d.inputId,
3297
+ label: qs(t, i, d.inputId)
3298
+ }));
3299
+ (n.selectedSheetId ?? null) !== (o.selectedSheetId ?? null) && r.push({ target: "sheet" });
3300
+ const a = B(
3301
+ t,
3302
+ n.tableSettings,
3303
+ void 0
3304
+ ), c = B(
3305
+ t,
3306
+ o.tableSettings,
3307
+ void 0
3308
+ );
3309
+ for (const d of /* @__PURE__ */ new Set([
3310
+ ...Object.keys(a),
3311
+ ...Object.keys(c)
3312
+ ]))
3313
+ at(a[d], c[d]) || r.push({
3314
+ target: "table",
3315
+ cardId: d,
3316
+ cardTitle: ((u = (l = ie(t, d)) == null ? void 0 : l.title) == null ? void 0 : u.trim()) || "Table"
3317
+ });
3318
+ return r;
3319
+ }
3320
+ function wt(e) {
3321
+ const t = ee(e.filter);
3322
+ return {
3323
+ inputId: e.inputId,
3324
+ filterId: e.filterId,
3325
+ label: e.label,
3326
+ selection: e.selection,
3327
+ owner: t ? { kind: "global_date" } : {
3328
+ kind: "field_date",
3329
+ filterId: e.filterId,
3330
+ label: e.label
3331
+ }
3332
+ };
3333
+ }
3334
+ function Ns(e) {
3335
+ var r, i;
3336
+ if ((r = e.card.sql) != null && r.trim())
3337
+ return {
3338
+ inputs: e.inputs,
3339
+ fieldCandidates: [],
3340
+ resolution: { status: "none" }
3341
+ };
3342
+ const t = e.inputs.filter((s) => !ee(s.filter)).map((s) => ({
3343
+ input: s,
3344
+ resolution: Ko({
3345
+ filter: s.filter,
3346
+ filterValue: s.filterValue,
3347
+ effectiveFilterValue: s.effectiveFilterValue,
3348
+ mappedFilterValue: s.mappedFilterValue,
3349
+ temporalBinding: e.temporalBinding,
3350
+ card: e.card
3351
+ })
3352
+ }));
3353
+ if (!e.temporalBinding)
3354
+ return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
3355
+ const n = e.inputs.find(
3356
+ (s) => ee(s.filter)
3357
+ );
3358
+ if (n && ((i = n.filterValue) == null ? void 0 : i.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && qo(n.effectiveFilterValue))
3359
+ return {
3360
+ inputs: e.inputs,
3361
+ fieldCandidates: t,
3362
+ resolution: {
3363
+ status: "resolved",
3364
+ resolvedOwner: wt(n)
3365
+ }
3366
+ };
3367
+ const o = t.filter(
3368
+ (s) => s.resolution.status === "eligible"
3369
+ );
3370
+ return o.length === 1 ? {
3371
+ inputs: e.inputs,
3372
+ fieldCandidates: t,
3373
+ resolution: {
3374
+ status: "resolved",
3375
+ resolvedOwner: wt(o[0].input)
3376
+ }
3377
+ } : o.length > 1 ? {
3378
+ inputs: e.inputs,
3379
+ fieldCandidates: t,
3380
+ resolution: {
3381
+ status: "ambiguous",
3382
+ candidateInputIds: o.map(
3383
+ (s) => s.input.inputId
3384
+ )
3385
+ }
3386
+ } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
3387
+ }
3388
+ function ql(e) {
3389
+ var n, o;
3390
+ const t = {
3391
+ ownerCardCount: 0,
3392
+ matchingCardCount: 0,
3393
+ globalPrecedenceCardCount: 0,
3394
+ ambiguousCardCount: 0,
3395
+ authorControlledCardCount: 0
3396
+ };
3397
+ for (const r of e.targets) {
3398
+ const i = r.plan.fieldCandidates.find(
3399
+ (a) => a.input.inputId === e.inputId
3400
+ );
3401
+ if (!i || i.resolution.status !== "eligible") continue;
3402
+ t.matchingCardCount += 1;
3403
+ const { resolution: s } = r.plan;
3404
+ s.status === "resolved" && s.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : s.status === "resolved" && s.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : s.status === "ambiguous" && s.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1), (((n = r.card.preferences) == null ? void 0 : n.inheritGlobalComparison) === !1 || (((o = r.card.config) == null ? void 0 : o.metricColumns) || []).some(
3405
+ (a) => a.comparison !== void 0
3406
+ )) && (t.authorControlledCardCount += 1);
3407
+ }
3408
+ return t;
3409
+ }
3410
+ const Ls = /* @__PURE__ */ new Set([
3411
+ "between",
3412
+ "not between",
3413
+ "=",
3414
+ "!=",
3415
+ ">",
3416
+ ">=",
3417
+ "<",
3418
+ "<=",
3419
+ "is null",
3420
+ "is not null"
3421
+ ]), js = /^(\d{4}-\d{2}-\d{2})T/, zs = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
3422
+ function lt(e) {
3423
+ return Ls.has(e);
3424
+ }
3425
+ function Gs(e, t) {
3426
+ if (e instanceof Date)
3427
+ return Number.isNaN(e.getTime()) ? e : t ? bt(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
3428
+ if (typeof e != "string")
3429
+ return e;
3430
+ const n = e.trim();
3431
+ if (t && zs.test(n)) {
3432
+ const r = new Date(n);
3433
+ if (!Number.isNaN(r.getTime()))
3434
+ return bt(r, t, "yyyy-MM-dd");
3435
+ }
3436
+ const o = js.exec(n);
3437
+ return o ? o[1] : e;
3438
+ }
3439
+ function zn(e, t) {
3440
+ return Array.isArray(e) ? e.map(
3441
+ (n) => Gs(n, t)
3442
+ ) : e;
3443
+ }
3444
+ function Gn(e) {
3445
+ return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : He(
3446
+ e.dashboard,
3447
+ e.semanticExecutionPayload
3448
+ ).allEligibleTargetsAreDateTime;
3449
+ }
3450
+ function Hn(e) {
3451
+ const {
3452
+ globalDateFilter: t,
3453
+ globalDateFilterValue: n,
3454
+ timezone: o,
3455
+ allowMinutePrecision: r = !1
3456
+ } = e;
3457
+ if (!t || !n)
3458
+ return;
3459
+ if (!lt(n.operation))
3460
+ return {
3461
+ ...n,
3462
+ filterId: t.id
3463
+ };
3464
+ const i = n, s = i.temporalPrecision === "minute" || me(i.relativeMeta), a = !r && s, c = i.operation === "is null" || i.operation === "is not null" ? [] : a ? zn(i.values, o) : i.values, l = r || !me(i.relativeMeta) ? i.relativeMeta : void 0, u = r && i.temporalPrecision === "minute" ? i.temporalPrecision : void 0, {
3465
+ relativeMeta: d,
3466
+ temporalPrecision: f,
3467
+ values: m,
3468
+ ...g
3469
+ } = n;
3470
+ return {
3471
+ ...g,
3472
+ filterId: t.id,
3473
+ values: c,
3474
+ ...l ? { relativeMeta: l } : {},
3475
+ ...u ? { temporalPrecision: u } : {}
3476
+ };
3477
+ }
3478
+ function Hs(e) {
3479
+ const t = $(e.filters);
3480
+ if (!t)
3481
+ return e.filterValues;
3482
+ const n = Gn(e);
3483
+ return e.filterValues.map((o) => o.filterId !== t.id ? o : Hn({
3484
+ globalDateFilter: t,
3485
+ globalDateFilterValue: o,
3486
+ timezone: e.timezone,
3487
+ allowMinutePrecision: n
3488
+ }) || o);
3489
+ }
3490
+ function Un(e) {
3491
+ const {
3492
+ globalDateFilter: t,
3493
+ globalDateFilterValue: n,
3494
+ resolvedPrimaryDateField: o,
3495
+ semanticContext: r,
3496
+ timezone: i,
3497
+ allowMinutePrecision: s = !1
3498
+ } = e;
3499
+ if (!t || !n || !o || !lt(n.operation))
3500
+ return null;
3501
+ const a = n, c = No(
3502
+ o.dataType
3503
+ ), l = s && c, u = a.temporalPrecision === "minute" || me(a.relativeMeta), d = l && a.temporalPrecision === "minute" ? a.temporalPrecision : void 0, f = l || !me(a.relativeMeta) ? a.relativeMeta : void 0, m = !l && u;
3504
+ return {
3505
+ filterId: t.id,
3506
+ dateOwner: "global_date",
3507
+ name: o.qualifiedFieldName || o.name,
3508
+ operation: a.operation,
3509
+ valueType: "date",
3510
+ values: a.operation === "is null" || a.operation === "is not null" ? [] : m ? zn(
3511
+ a.values,
3512
+ i
3513
+ ) : a.values,
3514
+ dataType: o.dataType || "date",
3515
+ // The exact type travels with the filter, so the server formats the predicate for
3516
+ // the column's storage type (it read it from `dataType` before 2.1 split the two).
3517
+ ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
3518
+ fieldMeta: {
3519
+ name: o.name,
3520
+ qualifiedFieldName: o.qualifiedFieldName,
3521
+ qualifiedEntityName: o.qualifiedEntityName,
3522
+ entityId: o.entityId,
3523
+ entityName: o.entityName,
3524
+ entityType: o.entityType,
3525
+ dataType: o.dataType,
3526
+ ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
3527
+ role: "groupby",
3528
+ ...t != null && t.title ? { label: t.title } : {}
3529
+ },
3530
+ ...r ? { semanticContext: r } : {},
3531
+ ...f ? { relativeMeta: f } : {},
3532
+ ...d ? { temporalPrecision: d } : {}
3533
+ };
3534
+ }
3535
+ function q(e) {
3536
+ return typeof e == "string" ? e.trim() : "";
3537
+ }
3538
+ function Us(e) {
3539
+ var t;
3540
+ return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
3541
+ var o;
3542
+ return {
3543
+ domainId: q(n.domainId) || q((o = e.semanticContext) == null ? void 0 : o.semanticDomainId),
3544
+ datasetName: q(n.name),
3545
+ selectedEntityId: q(n.id)
3546
+ };
3547
+ }).filter((n) => n.domainId && n.datasetName);
3548
+ }
3549
+ function $s(e) {
3550
+ var c, l, u, d, f;
3551
+ if (ee(e) || (c = e.sql) != null && c.trim())
3552
+ return null;
3553
+ const t = Us(e), n = q((l = e.semanticContext) == null ? void 0 : l.semanticDomainId), o = q((u = e.fieldMeta) == null ? void 0 : u.entityId), r = q((d = e.fieldMeta) == null ? void 0 : d.entityName), i = q((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", s = t.find(
3554
+ (m) => o && m.selectedEntityId === o
3555
+ );
3556
+ if (s)
3557
+ return s;
3558
+ const a = t.find(
3559
+ (m) => r && m.datasetName === r && (!n || m.domainId === n)
3560
+ );
3561
+ return a || (t.length === 1 ? t[0] : i && r && n ? {
3562
+ domainId: n,
3563
+ datasetName: r
3564
+ } : null);
3565
+ }
3566
+ function Qs(e) {
3567
+ var r, i;
3568
+ const { filter: t, semanticExecutionPayload: n } = e;
3569
+ if (!n)
3570
+ return null;
3571
+ const o = $s(t);
3572
+ return o && ((i = (r = n.domainsById[o.domainId]) == null ? void 0 : r.datasetsByName[o.datasetName]) == null ? void 0 : i.primaryDateField) || null;
3573
+ }
3574
+ function $n(e) {
3575
+ const t = $(e.filters);
3576
+ return t ? e.filterValues.filter(
3577
+ (n) => n.filterId !== t.id
3578
+ ) : e.filterValues;
3579
+ }
3580
+ function Nl(e) {
3581
+ const t = $(e.filters), n = $n({
3582
+ filters: e.filters,
3583
+ filterValues: e.filterValues
3584
+ });
3585
+ if (!t || ee(e.filter))
3586
+ return n;
3587
+ const o = e.filterValues.find(
3588
+ (s) => s.filterId === t.id
3589
+ ), r = Qs({
3590
+ filter: e.filter,
3591
+ semanticExecutionPayload: e.semanticExecutionPayload
3592
+ }), i = Un({
3593
+ globalDateFilter: t,
3594
+ globalDateFilterValue: o,
3595
+ resolvedPrimaryDateField: r || void 0,
3596
+ semanticContext: e.filter.semanticContext,
3597
+ timezone: e.timezone,
3598
+ allowMinutePrecision: e.allowMinutePrecision
3599
+ });
3600
+ return i ? [i, ...n] : n;
3601
+ }
3602
+ function Ws(e) {
3603
+ var u;
3604
+ const t = $(e.filters), n = t ? e.cardFilterValues.find(
3605
+ (d) => d.filterId === t.id
3606
+ ) : void 0, o = t ? e.cardFilterValues.filter(
3607
+ (d) => d.filterId !== t.id
3608
+ ) : e.cardFilterValues, r = e.resolvedPrimaryDateField ?? Nt({
3609
+ card: e.card,
3610
+ cardConfig: e.cardConfig,
3611
+ resolvedFields: e.resolvedFields,
3612
+ semanticExecutionPayload: e.semanticExecutionPayload
3613
+ }), i = Un({
3614
+ globalDateFilter: t,
3615
+ globalDateFilterValue: n,
3616
+ resolvedPrimaryDateField: r || void 0,
3617
+ timezone: e.timezone,
3618
+ allowMinutePrecision: e.allowMinutePrecision
3619
+ }), s = i ? [i, ...o] : o, a = new Map(
3620
+ s.map((d) => [
3621
+ d.filterId,
3622
+ d
3623
+ ])
3624
+ ), c = ((u = e.dateComparisonInputs) == null ? void 0 : u.flatMap((d) => {
3625
+ var m;
3626
+ const f = a.get(
3627
+ d.filterId
3628
+ );
3629
+ return f ? [{
3630
+ ...d,
3631
+ effectiveFilterValue: f,
3632
+ mappedFilterValue: (m = e.mappedFilterValuesByInputId) == null ? void 0 : m.get(d.inputId)
3633
+ }] : [];
3634
+ })) || [], l = Ns({
3635
+ inputs: c,
3636
+ temporalBinding: r,
3637
+ card: e.card
3638
+ });
3639
+ return {
3640
+ cardFilterValues: s,
3641
+ resolvedPrimaryDateField: r,
3642
+ dateComparisonPlan: l
3643
+ };
3644
+ }
3645
+ function Ll(e) {
3646
+ const t = $(e.filters), n = Gn(e), o = t ? e.filterValues.find(
3647
+ (s) => s.filterId === t.id
3648
+ ) : void 0, r = $n(e);
3649
+ return !t || !o || !lt(o.operation) ? r : [
3650
+ {
3651
+ ...Hn({
3652
+ globalDateFilter: t,
3653
+ globalDateFilterValue: o,
3654
+ timezone: e.timezone,
3655
+ allowMinutePrecision: n
3656
+ }) || o,
3657
+ filterId: t.id,
3658
+ name: t.title || t.column
3659
+ },
3660
+ ...r
3661
+ ];
3662
+ }
3663
+ class Ys extends Error {
3664
+ }
3665
+ function jl(e, t) {
3666
+ const n = new Map((e ? H(e) : []).map(({ card: o }) => [o.id, o]));
3667
+ return t && n.set(t.id, t), [...n.values()].flatMap((o) => {
3668
+ const r = We(o);
3669
+ return r.status === "ready" ? hs(r.config.spec, o.controlBindings) : [];
3670
+ });
3671
+ }
3672
+ function Js(e, t, n) {
3673
+ const o = Dr(e);
3674
+ if (!o) throw new Error("Matrix card definition is required.");
3675
+ const r = n && Cs({
3676
+ ...n,
3677
+ spec: o.spec,
3678
+ catalog: t.map((u) => ({ ...u, id: u.resolvedField.id }))
3679
+ }), i = r ? { ...o, spec: r.spec } : o, s = Lo(t), a = jo(t), c = (u) => {
3680
+ const d = a(u, i.spec.source);
3681
+ if (!(!d && u.derivedField)) {
3682
+ if (!d) throw new Ys(`Matrix field metadata is unavailable: ${u.name}`);
3683
+ return { ...d, ...u.derivedField ? { derivedField: u.derivedField } : {} };
3684
+ }
3685
+ }, l = {
3686
+ rows: i.spec.rows.flatMap((u) => {
3687
+ const d = c(u.field);
3688
+ return d ? [{ ...d, id: u.id, granularity: u.grain, role: "groupby" }] : [];
3689
+ }),
3690
+ columns: i.spec.columns.flatMap((u) => {
3691
+ const d = c(u.field);
3692
+ return d ? [{ ...d, id: u.id, granularity: u.grain, role: "pivotby" }] : [];
3693
+ }),
3694
+ // Aggregate-stage expressions have no source-column filter target. They stay
3695
+ // authoritative in matrix.spec, including all dependencies and controls.
3696
+ metrics: i.spec.measures.flatMap((u) => {
3697
+ if (u.kind !== "aggregate" || u.field.name === "*") return [];
3698
+ const d = c(u.field);
3699
+ return d ? [{ ...d, id: u.id, aggregate: u.aggregate, role: "metric" }] : [];
3700
+ })
3701
+ };
3702
+ return { config: i, fields: l, resolveField: s };
3703
+ }
3704
+ function Zs(e) {
3705
+ const t = e.filter(Boolean);
3706
+ if (t.length !== 0)
3707
+ return t.length === 1 ? t[0] : {
3708
+ id: zo(),
3709
+ logicalOperator: "AND",
3710
+ negate: !1,
3711
+ conditions: [],
3712
+ groups: t
3713
+ };
3714
+ }
3715
+ function Xs(e) {
3716
+ if (!e) return;
3717
+ const t = (n) => ({
3718
+ logicalOperator: n.logicalOperator,
3719
+ negate: n.negate,
3720
+ conditions: n.conditions.map((o) => ({
3721
+ field: o.field.id,
3722
+ operator: o.operator,
3723
+ value: o.value,
3724
+ temporalBucket: o.temporalBucket,
3725
+ rawTemporal: o.rawTemporal,
3726
+ // The run-time markers decide what runs, so they belong in the key.
3727
+ relativeMeta: o.relativeMeta,
3728
+ latestValue: o.latestValue
3729
+ })),
3730
+ groups: n.groups.map(t)
3731
+ });
3732
+ return JSON.stringify(t(e));
3733
+ }
3734
+ function ea(e, t, n = {}) {
3735
+ const o = e.metricColumns || [];
3736
+ if (o.length === 0) return e;
3737
+ const r = Go.includes(
3738
+ t
3739
+ ), i = Ho.includes(
3740
+ t
3741
+ ), s = (l) => {
3742
+ var u;
3743
+ return (u = l.parameters) != null && u.windowTransform ? {
3744
+ ...l,
3745
+ parameters: {
3746
+ ...l.parameters,
3747
+ windowTransform: void 0
3748
+ }
3749
+ } : l;
3750
+ };
3751
+ let a = !1;
3752
+ const c = o.map(
3753
+ (l) => {
3754
+ var f;
3755
+ const u = Fr(l);
3756
+ if (u === "none")
3757
+ return l;
3758
+ let d = l;
3759
+ return (f = d.parameters) != null && f.windowTransform && (a = !0, d = s(d)), n.keepsPeriodComparison && u !== "target" ? d : r ? u === "target" && !i ? (a = !0, {
3760
+ ...d,
3761
+ comparison: void 0
3762
+ }) : d : (a = !0, { ...d, comparison: void 0 });
3763
+ }
3764
+ );
3765
+ return a ? {
3766
+ ...e,
3767
+ metricColumns: c
3768
+ } : e;
3769
+ }
3770
+ function zl(e, t = {}) {
3771
+ return Qn(Wn(e, t));
3772
+ }
3773
+ function Qn(e) {
3774
+ return Zs([e.authored, e.drill, e.selections]);
3775
+ }
3776
+ function Wn(e, t = {}) {
3777
+ return {
3778
+ authored: t.includeAuthoredFilters === !1 ? void 0 : Uo(e),
3779
+ drill: Ts(t.drill, e.id),
3780
+ selections: Or(t.selections ?? [])
3781
+ };
3782
+ }
3783
+ function ta(e, t, n) {
3784
+ const o = Fs(e, t);
3785
+ return Ne(e) ? ea(
3786
+ { ...o, filters: n },
3787
+ e.type,
3788
+ // A data variable's card keeps its own period comparison (P3b-03).
3789
+ { keepsPeriodComparison: Sr(e) }
3790
+ ) : o;
3791
+ }
3792
+ function na(e) {
3793
+ const t = $o(e);
3794
+ return {
3795
+ contextMode: t,
3796
+ shouldApplyDashboardFilters: !t || t === "full"
3797
+ };
3798
+ }
3799
+ function oa(e) {
3800
+ const t = e.dashboardControls || [], n = e.card.controls || [], o = /* @__PURE__ */ new Set([
3801
+ ...t.map((r) => r.id),
3802
+ ...n.map((r) => r.id)
3803
+ ]);
3804
+ return Yn(
3805
+ e.card,
3806
+ {
3807
+ controlValues: Lt({
3808
+ relevantControlIds: o,
3809
+ dashboardValues: e.dashboardControlValues,
3810
+ cardValues: e.cardControlValues
3811
+ }),
3812
+ controlDefinitions: t,
3813
+ cardControlDefinitions: n,
3814
+ controlBindings: e.card.controlBindings || []
3815
+ },
3816
+ e.presentationControlIds
3817
+ );
3818
+ }
3819
+ function Yn(e, t, n) {
3820
+ const r = t.controlBindings.filter(
3821
+ (f) => !ve(f)
3822
+ ), i = new Set(
3823
+ Ye({
3824
+ sql: e.sql,
3825
+ controlBindings: r
3826
+ })
3827
+ ), s = new Set(
3828
+ [...n].filter(
3829
+ (f) => !i.has(f)
3830
+ )
3831
+ ), a = t.controlDefinitions.filter(
3832
+ (f) => !s.has(f.id)
3833
+ ), c = t.cardControlDefinitions.filter(
3834
+ (f) => !s.has(f.id)
3835
+ ), l = /* @__PURE__ */ new Set([
3836
+ ...a.map((f) => f.id),
3837
+ ...c.map((f) => f.id)
3838
+ ]), u = r.filter(
3839
+ (f) => l.has(f.controlId)
3840
+ );
3841
+ return {
3842
+ controlValues: Lt({
3843
+ relevantControlIds: l,
3844
+ dashboardValues: t.controlValues
3845
+ }),
3846
+ controlDefinitions: a,
3847
+ cardControlDefinitions: c,
3848
+ controlBindings: u
3849
+ };
3850
+ }
3851
+ function ra({
3852
+ card: e,
3853
+ dashboard: t,
3854
+ transientContexts: n,
3855
+ cardViewState: o,
3856
+ viewerTableSettings: r,
3857
+ adHocFilterValues: i,
3858
+ selectedSheetId: s,
3859
+ inlineFilterValuesMap: a,
3860
+ dashboardControls: c,
3861
+ dashboardControlValues: l,
3862
+ cardControlValuesMap: u,
3863
+ dashboardInputContext: d,
3864
+ includeAuthoredFilters: f
3865
+ }) {
3866
+ var T;
3867
+ const m = vn(t);
3868
+ for (const F of e.controlBindings || [])
3869
+ ve(F) && m.add(F.controlId);
3870
+ const { shouldApplyDashboardFilters: g } = na(n), p = d != null && d.inputs.length ? d : void 0, y = Wn(e, {
3871
+ includeAuthoredFilters: f,
3872
+ // Blocked and skipped conditions are already projected away, so a
3873
+ // selection can only ever narrow this card on its own fields. Carried
3874
+ // selections are among them.
3875
+ selections: ((d == null ? void 0 : d.selections) ?? []).filter(
3876
+ (F) => F.status === "apply"
3877
+ ),
3878
+ drill: o == null ? void 0 : o.drill
3879
+ }), b = Qn(y), I = f === !1 ? De(b, !0) : b, v = ta(
3880
+ e,
3881
+ o == null ? void 0 : o.drill,
3882
+ I
3883
+ ), M = rs({ ...e, config: v }, r) ?? v, h = bn(M, {
3884
+ cardType: e.type,
3885
+ dataSource: e.dataSource,
3886
+ temporalResultOwner: jt({
3887
+ hasExecutableConfig: Fe(M, e.type),
3888
+ sql: e.sql,
3889
+ normalizedPython: Le(e.python || "")
3890
+ })
3891
+ }) || M, w = Xs(I) || "", A = p ? Yn(
3892
+ e,
3893
+ {
3894
+ controlValues: p.controlValues,
3895
+ controlDefinitions: p.controlDefinitions,
3896
+ cardControlDefinitions: p.cardControlDefinitions,
3897
+ controlBindings: p.controlBindings
3898
+ },
3899
+ m
3900
+ ) : oa({
3901
+ card: e,
3902
+ presentationControlIds: m,
3903
+ dashboardControls: c,
3904
+ dashboardControlValues: l,
3905
+ cardControlValues: u == null ? void 0 : u[e.id]
3906
+ });
3907
+ return {
3908
+ filterCompilationInput: {
3909
+ adHocFilterValues: i || [],
3910
+ selectedSheetId: s,
3911
+ inlineFilterValues: (a == null ? void 0 : a[e.id]) || [],
3912
+ shouldApplyDashboardFilters: g,
3913
+ ...p ? {
3914
+ dashboardInputContext: {
3915
+ inputs: p.inputs,
3916
+ resolvedInputs: p.resolvedInputs,
3917
+ activeFilters: p.activeFilters
3918
+ }
3919
+ } : {},
3920
+ ...p != null && p.globalDateComparisonSelection ? {
3921
+ globalDateComparisonSelection: p.globalDateComparisonSelection
3922
+ } : {},
3923
+ ...p != null && p.dateComparisonInputs ? {
3924
+ dateComparisonInputs: p.dateComparisonInputs
3925
+ } : {}
3926
+ },
3927
+ ...A,
3928
+ resolvedFilters: I,
3929
+ resolvedFilterParts: y,
3930
+ drillSteps: ((T = o == null ? void 0 : o.drill) == null ? void 0 : T.steps) ?? Qo,
3931
+ finalConfig: M,
3932
+ queryRelevantConfig: h,
3933
+ finalFiltersKey: w
3934
+ };
3935
+ }
3936
+ function ia(e, t) {
3937
+ return !!t && e.endsWith(t);
3938
+ }
3939
+ function Jn(e, t) {
3940
+ return (e ?? []).filter(
3941
+ (n) => ia(n.filterId, t)
3942
+ );
3943
+ }
3944
+ function Zn(e, t, n) {
3945
+ var o;
3946
+ if (t)
3947
+ return {
3948
+ selection: t,
3949
+ ...((o = e.preferences) == null ? void 0 : o.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
3950
+ ...n ? { owner: n } : {}
3951
+ };
3952
+ }
3953
+ function sa(e) {
3954
+ if (e.resolution.status === "resolved")
3955
+ return Zn(
3956
+ e.card,
3957
+ e.resolution.resolvedOwner.selection,
3958
+ e.resolution.resolvedOwner.owner
3959
+ );
3960
+ }
3961
+ function aa(e) {
3962
+ return `Set ${e.join(", ")} to run this card.`;
3963
+ }
3964
+ function la({
3965
+ dashboardInputContext: e,
3966
+ shouldApplyDashboardFilters: t
3967
+ }) {
3968
+ if (t)
3969
+ return e.activeFilters;
3970
+ const n = new Set(
3971
+ e.inputs.flatMap(
3972
+ (o) => o.kind === "filter" && rn(o) ? [o.filter.id] : []
3973
+ )
3974
+ );
3975
+ return e.activeFilters.filter(
3976
+ (o) => n.has(o.filterId)
3977
+ );
3978
+ }
3979
+ function ca({
3980
+ dashboardInputFilterValues: e,
3981
+ adHocFilterValues: t
3982
+ }) {
3983
+ const n = [...e], o = new Set(
3984
+ n.map((r) => r.filterId)
3985
+ );
3986
+ for (const r of t)
3987
+ o.has(r.filterId) || (n.push(r), o.add(r.filterId));
3988
+ return n;
3989
+ }
3990
+ function Ke(e, t) {
3991
+ const n = t.shouldApplyDashboardFilters ? Jn(t.adHocFilterValues, t.selectedSheetId) : [];
3992
+ if (!t.dashboardInputContext)
3993
+ return {
3994
+ status: "ready",
3995
+ filterValues: [...n, ...t.inlineFilterValues],
3996
+ mappingDispositions: []
3997
+ };
3998
+ const o = t.dashboardInputContext.inputs.filter(
3999
+ (u) => u.kind === "filter" && !!u.application
4000
+ ), r = new Set(
4001
+ o.map((u) => u.filter.id)
4002
+ ), i = new Set(
4003
+ t.dashboardInputContext.inputs.flatMap(
4004
+ (u) => {
4005
+ var d;
4006
+ return u.kind === "filter" && ((d = u.compatibility) == null ? void 0 : d.source) === "cardInlineFilter" ? [u.filter.id] : [];
4007
+ }
4008
+ )
4009
+ ), s = la({
4010
+ dashboardInputContext: t.dashboardInputContext,
4011
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
4012
+ }).filter((u) => !r.has(u.filterId)), a = s.filter(
4013
+ (u) => !i.has(u.filterId)
4014
+ ), c = s.filter(
4015
+ (u) => i.has(u.filterId)
4016
+ ), l = Wo({
4017
+ card: e,
4018
+ inputs: o,
4019
+ resolvedInputs: t.dashboardInputContext.resolvedInputs,
4020
+ activeFilterValues: t.dashboardInputContext.activeFilters,
4021
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
4022
+ });
4023
+ return l.status === "blocked" ? {
4024
+ status: "blocked",
4025
+ mappingDispositions: l.dispositions
4026
+ } : {
4027
+ status: "ready",
4028
+ filterValues: [
4029
+ ...ca({
4030
+ dashboardInputFilterValues: [
4031
+ ...a,
4032
+ ...l.filterValues
4033
+ ],
4034
+ adHocFilterValues: n
4035
+ }),
4036
+ ...c
4037
+ ],
4038
+ mappingDispositions: l.dispositions
4039
+ };
4040
+ }
4041
+ function ua(e, t) {
4042
+ const n = e.dashboardInputContext;
4043
+ if (!n) return [];
4044
+ const o = new Set(
4045
+ t.flatMap(
4046
+ (i) => i.status === "skip" && (i.reason === "explicitlyExcluded" || i.reason === "outsideScope") ? [i.inputId] : []
4047
+ )
4048
+ ), r = new Map(n.inputs.map((i) => [i.id, i]));
4049
+ return n.resolvedInputs.flatMap((i) => {
4050
+ if (!i.missingRequiredValue) return [];
4051
+ const s = r.get(i.id);
4052
+ return s ? s.kind === "filter" && (!e.shouldApplyDashboardFilters && !rn(s) || o.has(s.id)) ? [] : [i.label] : [];
4053
+ });
4054
+ }
4055
+ function da({
4056
+ card: e,
4057
+ cardConfig: t,
4058
+ input: n,
4059
+ resolvedPrimaryDateField: o,
4060
+ resolvedFields: r,
4061
+ semanticExecutionPayload: i,
4062
+ timezone: s,
4063
+ allowMinutePrecision: a
4064
+ }) {
4065
+ var p;
4066
+ const c = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
4067
+ (y) => y.kind === "filter" ? [y.filter] : []
4068
+ ) : [], l = Ke(e, n), u = ua(
4069
+ n,
4070
+ l.mappingDispositions
4071
+ );
4072
+ if (u.length)
4073
+ return {
4074
+ status: "blocked",
4075
+ cardId: e.id,
4076
+ reason: "requiredInput",
4077
+ mappingDispositions: l.mappingDispositions,
4078
+ missingRequiredLabels: u
4079
+ };
4080
+ if (l.status === "blocked")
4081
+ return {
4082
+ status: "blocked",
4083
+ cardId: e.id,
4084
+ reason: "mapping",
4085
+ mappingDispositions: l.mappingDispositions,
4086
+ missingRequiredLabels: []
4087
+ };
4088
+ const d = Ws({
4089
+ card: e,
4090
+ cardConfig: t,
4091
+ filters: c,
4092
+ cardFilterValues: l.filterValues,
4093
+ resolvedPrimaryDateField: o,
4094
+ resolvedFields: r,
4095
+ semanticExecutionPayload: i,
4096
+ timezone: s,
4097
+ allowMinutePrecision: a,
4098
+ dateComparisonInputs: n.dateComparisonInputs,
4099
+ mappedFilterValuesByInputId: new Map(
4100
+ l.mappingDispositions.flatMap(
4101
+ (y) => y.status === "apply" ? [[y.inputId, y.filterValue]] : []
4102
+ )
4103
+ )
4104
+ }), f = $(c), m = !!(f && d.cardFilterValues.some(
4105
+ (y) => y.filterId === f.id
4106
+ )), g = d.resolvedPrimaryDateField && !((p = e.sql) != null && p.trim()) ? d.dateComparisonPlan.inputs.length ? sa({
4107
+ card: e,
4108
+ resolution: d.dateComparisonPlan.resolution
4109
+ }) : m ? Zn(
4110
+ e,
4111
+ n.globalDateComparisonSelection
4112
+ ) : void 0 : void 0;
4113
+ return {
4114
+ status: "ready",
4115
+ ...d,
4116
+ queryFilterDefinitions: c,
4117
+ globalDateComparison: g,
4118
+ mappingDispositions: l.mappingDispositions
4119
+ };
4120
+ }
4121
+ function Xn(e, t, n) {
4122
+ const o = da({
4123
+ resolvedFields: t.resolvedDateFields,
4124
+ ...n,
4125
+ card: e,
4126
+ cardConfig: t.queryRelevantConfig,
4127
+ input: t.filterCompilationInput
4128
+ });
4129
+ if (o.status === "blocked") return o;
4130
+ const { filterCompilationInput: r, ...i } = t;
4131
+ return { status: "ready", queryContext: {
4132
+ ...i,
4133
+ cardFilterValues: o.cardFilterValues,
4134
+ queryFilterDefinitions: o.queryFilterDefinitions,
4135
+ resolvedPrimaryDateField: o.resolvedPrimaryDateField,
4136
+ globalDateComparison: o.globalDateComparison,
4137
+ globalDateComparisonSelection: r.globalDateComparisonSelection,
4138
+ dateComparisonInputs: r.dateComparisonInputs
4139
+ }, compiledFilters: o };
4140
+ }
4141
+ function fa(e, t, n) {
4142
+ const o = Yo(e), r = Xn(e, t, {
4143
+ resolvedPrimaryDateField: n.resolvedPrimaryDateField,
4144
+ timezone: n.calendarContext.tz,
4145
+ allowMinutePrecision: n.allowGlobalDateMinutePrecision
4146
+ });
4147
+ if (r.status === "blocked")
4148
+ return { ...r, tableConfig: o };
4149
+ const { compiledFilters: i } = r, {
4150
+ cardFilterValues: s,
4151
+ resolvedPrimaryDateField: a,
4152
+ globalDateComparison: c
4153
+ } = i, { queryKey: l, queryInputIdentity: u, paginationConfig: d } = Ui(
4154
+ e,
4155
+ r.queryContext,
4156
+ n.calendarContext,
4157
+ { resolvePaginationConfig: n.resolvePaginationConfig }
4158
+ ), f = t.queryRelevantConfig, m = Le(e.python || ""), g = jt({
4159
+ hasExecutableConfig: Fe(f, e.type),
4160
+ sql: e.sql,
4161
+ normalizedPython: m
4162
+ });
4163
+ return {
4164
+ status: "ready",
4165
+ queryKey: l,
4166
+ queryInputIdentity: u,
4167
+ paginationConfig: d,
4168
+ tableConfig: o,
4169
+ compiledFilters: i,
4170
+ requestPayloadBase: {
4171
+ cardId: e.id,
4172
+ sql: (e == null ? void 0 : e.sql) || "",
4173
+ python: m,
4174
+ resultOwner: g,
4175
+ active_filters: s,
4176
+ controlValues: t.controlValues,
4177
+ controlDefinitions: t.controlDefinitions,
4178
+ cardControlDefinitions: t.cardControlDefinitions,
4179
+ controlBindings: t.controlBindings,
4180
+ cache_config: n.globalCacheConfig,
4181
+ queryConfig: e.queryConfig,
4182
+ tableConfig: o,
4183
+ cardType: e.type,
4184
+ cardTitle: e.title || "",
4185
+ cardConfig: f,
4186
+ cardDataSource: e.dataSource,
4187
+ resolvedPrimaryDateField: a || void 0,
4188
+ calendarContext: n.calendarContext,
4189
+ ...c ? { globalDateComparison: c } : {},
4190
+ ...t.sqlRowLimit ? { sqlRowLimit: t.sqlRowLimit } : {}
4191
+ }
4192
+ };
4193
+ }
4194
+ const Ot = [], pa = [], ma = {};
4195
+ function Gl(e, t) {
4196
+ return {
4197
+ sheetId: e.sheetId,
4198
+ sectionId: e.sectionId,
4199
+ documentFilterValues: e.documentFilterValues ?? Ot,
4200
+ documentControlDefinitions: e.documentControlDefinitions ?? pa,
4201
+ documentControlValues: e.documentControlValues ?? ma,
4202
+ editorFilterValues: t ?? Ot
4203
+ };
4204
+ }
4205
+ function ga({
4206
+ card: e,
4207
+ dashboard: t,
4208
+ runtime: n,
4209
+ dashboardRuntimeValues: o,
4210
+ calendar: r
4211
+ }) {
4212
+ const i = zt({
4213
+ dashboard: t,
4214
+ dashboardInputValues: o.dashboardInputValues,
4215
+ transientContexts: void 0
4216
+ }) ? Ue({
4217
+ transientContexts: void 0,
4218
+ dashboard: t,
4219
+ sheetId: n.sheetId,
4220
+ sheetKind: "document",
4221
+ sectionId: n.sectionId,
4222
+ card: e,
4223
+ runtimeValues: {
4224
+ ...o,
4225
+ dashboardInputValues: n.documentDashboardInputValues || o.dashboardInputValues
4226
+ },
4227
+ calendar: r
4228
+ }) : void 0, s = i && (i.inputs.length > 0 || i.selections.length > 0) ? i : void 0, a = !!(i != null && i.inputs.length), c = [
4229
+ ...n.editorFilterValues || [],
4230
+ ...n.documentFilterValues
4231
+ ];
4232
+ return {
4233
+ card: a ? e : ya(
4234
+ e,
4235
+ n.documentControlDefinitions
4236
+ ),
4237
+ dashboard: t,
4238
+ transientContexts: void 0,
4239
+ // Document section cards do not drill.
4240
+ cardViewState: void 0,
4241
+ // Document section cards are not viewer-customizable tables.
4242
+ viewerTableSettings: void 0,
4243
+ adHocFilterValues: [],
4244
+ inlineFilterValuesMap: !a && c.length ? { [e.id]: c } : {},
4245
+ dashboardControls: [],
4246
+ dashboardControlValues: {},
4247
+ cardControlValuesMap: !a && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
4248
+ dashboardInputContext: s
4249
+ };
4250
+ }
4251
+ function ya(e, t) {
4252
+ if (t.length === 0)
4253
+ return e;
4254
+ const n = /* @__PURE__ */ new Map();
4255
+ for (const o of e.controls || [])
4256
+ n.set(o.id, o);
4257
+ for (const o of t)
4258
+ n.set(o.id, o);
4259
+ return {
4260
+ ...e,
4261
+ controls: Array.from(n.values())
4262
+ };
4263
+ }
4264
+ function Hl({
4265
+ card: e,
4266
+ place: t,
4267
+ source: n
4268
+ }) {
4269
+ const o = qe(e, t, n);
4270
+ return {
4271
+ card: o.card,
4272
+ context: o.context,
4273
+ inputContext: o.inputContext
4274
+ };
4275
+ }
4276
+ function ba(e, t, n) {
4277
+ return {
4278
+ calendarContext: n ?? Mr,
4279
+ allowGlobalDateMinutePrecision: He(
4280
+ e,
4281
+ t
4282
+ ).allEligibleTargetsAreDateTime,
4283
+ semanticExecutionPayload: t,
4284
+ globalCacheConfig: e.globalCacheConfig
4285
+ };
4286
+ }
4287
+ function Ul(e, t) {
4288
+ return no(
4289
+ e,
4290
+ t,
4291
+ t.allowGlobalDateMinutePrecision
4292
+ );
4293
+ }
4294
+ function Ca(e, t, n = {}) {
4295
+ const o = to(e, t);
4296
+ return {
4297
+ ...fa(e.card, e.context, {
4298
+ resolvedPrimaryDateField: o,
4299
+ calendarContext: t.calendarContext,
4300
+ allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
4301
+ globalCacheConfig: t.globalCacheConfig,
4302
+ resolvePaginationConfig: n.resolvePaginationConfig
4303
+ }),
4304
+ resolvedPrimaryDateField: o
4305
+ };
4306
+ }
4307
+ function ha({
4308
+ card: e,
4309
+ place: t,
4310
+ source: n,
4311
+ semanticExecutionPayload: o,
4312
+ matrixCatalog: r,
4313
+ withRequest: i = !1
4314
+ }) {
4315
+ var p, y;
4316
+ const { dashboard: s } = n, a = e.id, c = (b, I) => {
4317
+ var M;
4318
+ let v;
4319
+ try {
4320
+ const h = We(b);
4321
+ if (h.status === "invalid") throw h.error;
4322
+ const w = qe(
4323
+ b,
4324
+ I,
4325
+ n,
4326
+ h.status === "absent"
4327
+ );
4328
+ if (v = w.context, h.status === "absent")
4329
+ return { status: "ready", value: { assembled: w } };
4330
+ if (!r)
4331
+ return {
4332
+ status: "blocked",
4333
+ reason: "metadata",
4334
+ message: "Matrix field metadata is required.",
4335
+ context: v
4336
+ };
4337
+ const A = Is(h.config.spec, v), T = r.filter(
4338
+ (P) => P.field.source && A.some(
4339
+ (E) => Oe(E, P.field.source)
4340
+ )
4341
+ ), F = Js(b, T, v), { params: k } = w, O = k.dashboardInputContext;
4342
+ F.config = {
4343
+ ...F.config,
4344
+ presentation: wi(
4345
+ b,
4346
+ F.config,
4347
+ {
4348
+ controls: O ? [
4349
+ ...O.controlDefinitions,
4350
+ ...O.cardControlDefinitions
4351
+ ] : [
4352
+ ...k.dashboardControls ?? s.controls ?? [],
4353
+ ...k.card.controls ?? []
4354
+ ],
4355
+ values: (O == null ? void 0 : O.controlValues) ?? {
4356
+ ...k.dashboardControlValues,
4357
+ ...(M = k.cardControlValuesMap) == null ? void 0 : M[b.id]
4358
+ }
4359
+ },
4360
+ T
4361
+ )
4362
+ };
4363
+ const x = {
4364
+ ...b,
4365
+ config: { matrix: F.config }
4366
+ }, D = qe(x, I, n, !1);
4367
+ return {
4368
+ status: "ready",
4369
+ value: {
4370
+ assembled: {
4371
+ card: x,
4372
+ context: { ...D.context, resolvedDateFields: F.fields },
4373
+ inputContext: D.inputContext
4374
+ },
4375
+ matrix: F
4376
+ }
4377
+ };
4378
+ } catch (h) {
4379
+ return {
4380
+ status: "blocked",
4381
+ reason: "configuration",
4382
+ message: h instanceof Error ? h.message : "Card configuration is invalid.",
4383
+ context: v
4384
+ };
4385
+ }
4386
+ }, l = c(e, t);
4387
+ if (l.status === "blocked")
4388
+ return {
4389
+ status: "blocked",
4390
+ cardId: a,
4391
+ mappingDispositions: [],
4392
+ reason: l.reason,
4393
+ missingRequiredLabels: [],
4394
+ message: l.message
4395
+ };
4396
+ const { assembled: u, matrix: d } = l.value, f = ba(
4397
+ s,
4398
+ o,
4399
+ n.calendar
4400
+ ), m = u.context.filterCompilationInput, g = Jo(s);
4401
+ try {
4402
+ const b = Ke(u.card, m), I = d && g && b.status === "ready" && b.filterValues.some((w) => w.filterId === g.id);
4403
+ let v = f.allowGlobalDateMinutePrecision;
4404
+ if (I) {
4405
+ const w = (p = m.dashboardInputContext) == null ? void 0 : p.inputs.find(
4406
+ (D) => D.kind === "filter" && D.filter.id === g.id
4407
+ ), T = Zo(s, g).filter(
4408
+ ({ card: D, sheet: P }) => !w || Tr(w, {
4409
+ cardId: D.id,
4410
+ sheetId: P.id,
4411
+ sheetKind: Gt(P) ? "document" : "dashboard"
4412
+ })
4413
+ ).map(({ card: D, sheet: P }) => ({
4414
+ card: D,
4415
+ value: D.id === a ? l : c(D, { kind: "sheet", sheetId: P.id })
4416
+ })), F = new Map(
4417
+ T.map(({ card: D, value: P }) => [
4418
+ D.id,
4419
+ P.status === "ready" ? P.value.assembled.card : null
4420
+ ])
4421
+ ), k = new Map(
4422
+ T.map(({ card: D, value: P }) => {
4423
+ var E;
4424
+ return [
4425
+ D.id,
4426
+ P.status === "ready" ? (E = P.value.matrix) == null ? void 0 : E.fields : void 0
4427
+ ];
4428
+ })
4429
+ ), O = T.flatMap(
4430
+ ({ card: D, value: P }) => {
4431
+ const E = D.id, R = P.status === "ready" ? P.value.assembled.context : P.context;
4432
+ if (!R) return [E];
4433
+ const z = P.status === "ready" ? P.value.assembled.card : D;
4434
+ try {
4435
+ const Y = Ke(
4436
+ z,
4437
+ R.filterCompilationInput
4438
+ );
4439
+ return Y.status === "blocked" || Y.filterValues.some((Ve) => Ve.filterId === g.id) ? [E] : [];
4440
+ } catch {
4441
+ return F.set(E, null), [E];
4442
+ }
4443
+ }
4444
+ ), x = He(
4445
+ s,
4446
+ o,
4447
+ g,
4448
+ F,
4449
+ k,
4450
+ O
4451
+ );
4452
+ if ((y = x.unresolvedCardIds) != null && y.length)
4453
+ return {
4454
+ status: "blocked",
4455
+ cardId: a,
4456
+ mappingDispositions: [],
4457
+ reason: "coverage",
4458
+ missingRequiredLabels: [],
4459
+ message: `Date precision requires field metadata and valid inputs for: ${x.unresolvedCardIds.join(", ")}.`
4460
+ };
4461
+ v = x.allEligibleTargetsAreDateTime;
4462
+ }
4463
+ const M = no(u, f, v);
4464
+ if (M.status === "blocked")
4465
+ return {
4466
+ status: "blocked",
4467
+ cardId: M.cardId,
4468
+ mappingDispositions: M.mappingDispositions,
4469
+ reason: M.reason,
4470
+ missingRequiredLabels: M.missingRequiredLabels,
4471
+ ...M.reason === "requiredInput" ? { message: aa(M.missingRequiredLabels) } : {},
4472
+ ...M.resolvedPrimaryDateField ? { resolvedPrimaryDateField: M.resolvedPrimaryDateField } : {}
4473
+ };
4474
+ const h = i && !d ? Ca(u, f) : void 0;
4475
+ return {
4476
+ ...M,
4477
+ ...d ? { matrix: d } : {},
4478
+ // The whole request a card runs with: the contract's payload and its
4479
+ // extras (server pagination, table totals) from the one extras owner,
4480
+ // on the first page a new viewer opens (ledger P3-78).
4481
+ ...(h == null ? void 0 : h.status) === "ready" ? {
4482
+ request: {
4483
+ ...h.requestPayloadBase,
4484
+ ...ms({
4485
+ card: u.card,
4486
+ finalConfig: u.context.finalConfig,
4487
+ documentSection: t.kind === "documentSection" ? {} : void 0,
4488
+ page: ps(u.card)
4489
+ })
4490
+ }
4491
+ } : {}
4492
+ };
4493
+ } catch (b) {
4494
+ return {
4495
+ status: "blocked",
4496
+ cardId: a,
4497
+ mappingDispositions: [],
4498
+ reason: "configuration",
4499
+ missingRequiredLabels: [],
4500
+ message: b instanceof Error ? b.message : "Card filter configuration is invalid."
4501
+ };
4502
+ }
4503
+ }
4504
+ function Ia(e) {
4505
+ const t = e.editor ? {
4506
+ ...e.inlineFilterValuesMap,
4507
+ ...Object.fromEntries(
4508
+ Object.entries(e.editor.inlineFilterValuesMap).filter(
4509
+ (n) => n[1] !== void 0
4510
+ )
4511
+ )
4512
+ } : e.inlineFilterValuesMap;
4513
+ return {
4514
+ dashboardInputValues: e.dashboardInputValues,
4515
+ adHocFilterValues: e.adHocFilterValues,
4516
+ controlValues: e.controlValues,
4517
+ inlineFilterValuesMap: t,
4518
+ cardControlValuesMap: e.cardControlValuesMap
4519
+ };
4520
+ }
4521
+ function qe(e, t, n, o) {
4522
+ var l, u;
4523
+ const { dashboard: r } = n, i = Ia(n), s = t.kind === "documentSection" ? {
4524
+ ...ga({
4525
+ card: e,
4526
+ dashboard: r,
4527
+ runtime: t.section,
4528
+ dashboardRuntimeValues: i,
4529
+ calendar: n.calendar
4530
+ }),
4531
+ selectedSheetId: t.section.sheetId,
4532
+ includeAuthoredFilters: o
4533
+ } : va(e, t.sheetId, n, i, o), a = ra(s), c = (l = e.config) == null ? void 0 : l.rowLimit;
4534
+ return (u = e.sql) != null && u.trim() && c && eo(r, e.id) && (a.sqlRowLimit = c), {
4535
+ card: s.card,
4536
+ params: s,
4537
+ context: a,
4538
+ inputContext: s.dashboardInputContext
4539
+ };
4540
+ }
4541
+ function eo(e, t) {
4542
+ return (e.variables ?? []).some((n) => n.id === t);
4543
+ }
4544
+ function va(e, t, n, o, r) {
4545
+ var l, u;
4546
+ const { dashboard: i } = n, s = eo(i, e.id), a = s ? void 0 : n.transientContexts, c = zt({
4547
+ dashboard: i,
4548
+ dashboardInputValues: o.dashboardInputValues,
4549
+ transientContexts: a
4550
+ }) ? Ue({
4551
+ transientContexts: a,
4552
+ dashboard: i,
4553
+ sheetId: t,
4554
+ card: e,
4555
+ runtimeValues: o,
4556
+ calendar: n.calendar
4557
+ }) : void 0;
4558
+ return {
4559
+ card: e,
4560
+ dashboard: i,
4561
+ transientContexts: a,
4562
+ cardViewState: s || (l = n.cardViewStates) == null ? void 0 : l[e.id],
4563
+ viewerTableSettings: n.editor || s || (u = n.viewerTableSettings) == null ? void 0 : u[e.id],
4564
+ adHocFilterValues: s ? [] : o.adHocFilterValues,
4565
+ selectedSheetId: t,
4566
+ inlineFilterValuesMap: o.inlineFilterValuesMap,
4567
+ dashboardControls: i.controls,
4568
+ dashboardControlValues: o.controlValues,
4569
+ cardControlValuesMap: o.cardControlValuesMap,
4570
+ // Keep a selection-only context so the query has one resolved-input contract.
4571
+ dashboardInputContext: c && (c.inputs.length > 0 || c.selections.length > 0) ? c : void 0,
4572
+ includeAuthoredFilters: r
4573
+ };
4574
+ }
4575
+ function to({ card: e, context: t }, n) {
4576
+ return Nt({
4577
+ card: e,
4578
+ cardConfig: t.queryRelevantConfig,
4579
+ resolvedFields: t.resolvedDateFields,
4580
+ semanticExecutionPayload: n.semanticExecutionPayload
4581
+ });
4582
+ }
4583
+ function no(e, t, n) {
4584
+ const { card: o } = e, r = to(e, t), i = Xn(o, e.context, {
4585
+ resolvedPrimaryDateField: r,
4586
+ timezone: t.calendarContext.tz,
4587
+ allowMinutePrecision: n
4588
+ });
4589
+ return i.status === "blocked" ? { ...i, card: o, resolvedPrimaryDateField: r } : {
4590
+ status: "ready",
4591
+ card: o,
4592
+ queryContext: i.queryContext,
4593
+ compiledFilters: i.compiledFilters,
4594
+ resolvedPrimaryDateField: r
4595
+ };
4596
+ }
4597
+ function $l({
4598
+ dashboard: e,
4599
+ dashboardInputValues: t,
4600
+ adHocFilterValues: n,
4601
+ calendar: o,
4602
+ selectedSheetId: r,
4603
+ sheetSelection: i = "current",
4604
+ dashboardControlValues: s,
4605
+ cardControlValuesMap: a,
4606
+ semanticExecutionPayload: c,
4607
+ timezone: l
4608
+ }) {
4609
+ const u = e ? [...Xo(e)] : void 0, d = r ?? null, f = (I) => {
4610
+ var v;
4611
+ return e ? Ta({
4612
+ dashboard: e,
4613
+ runtimeValues: { dashboardInputValues: t },
4614
+ adHocFilterValues: n,
4615
+ sheetId: I,
4616
+ sheetKind: Gt(
4617
+ (v = e.sheets) == null ? void 0 : v.find((M) => M.id === I)
4618
+ ) ? "document" : "dashboard",
4619
+ calendar: o
4620
+ }) : [];
4621
+ }, m = i === "all" ? Array.from(
4622
+ new Map(
4623
+ ((e == null ? void 0 : e.sheets) || []).flatMap(
4624
+ (I) => f(I.id).map(
4625
+ (v) => [v.filterId, v]
4626
+ )
4627
+ )
4628
+ ).values()
4629
+ ) : f(d), g = {
4630
+ ...s || {}
4631
+ }, p = i === "all" ? H({ sheets: (e == null ? void 0 : e.sheets) || [] }) : d ? H({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
4632
+ (I) => I.sheet.id === d
4633
+ ) : [];
4634
+ for (const I of p)
4635
+ Object.assign(g, (a == null ? void 0 : a[I.card.id]) || {});
4636
+ const y = er({
4637
+ filterDefinitions: u,
4638
+ filterValues: m
4639
+ }), b = Hs({
4640
+ filters: u,
4641
+ filterValues: y,
4642
+ dashboard: e,
4643
+ semanticExecutionPayload: c,
4644
+ timezone: l
4645
+ });
4646
+ return {
4647
+ selectedSheetId: d,
4648
+ filterValues: b,
4649
+ controlValues: g
4650
+ };
4651
+ }
4652
+ function Ql({
4653
+ dashboard: e,
4654
+ cardId: t,
4655
+ transientContexts: n,
4656
+ cardViewStates: o,
4657
+ viewerTableSettings: r,
4658
+ semanticExecutionPayload: i,
4659
+ adHocFilterValues: s,
4660
+ inlineFilterValuesMap: a,
4661
+ dashboardControlValues: c,
4662
+ cardControlValuesMap: l,
4663
+ dashboardInputValues: u,
4664
+ calendar: d,
4665
+ matrixCatalog: f,
4666
+ cardOverride: m,
4667
+ sheetId: g,
4668
+ documentSection: p,
4669
+ editor: y,
4670
+ withRequest: b
4671
+ }) {
4672
+ var M;
4673
+ if (!e)
4674
+ return null;
4675
+ m && !Ct(e, t) && g && (e = { ...e, sheets: (M = e.sheets) == null ? void 0 : M.map((h) => h.id === g ? { ...h, cards: [...h.cards ?? [], m] } : h) });
4676
+ const I = Ct(e, t);
4677
+ if (!I)
4678
+ return null;
4679
+ const v = ha({
4680
+ card: m ?? I.card,
4681
+ place: p ? { kind: "documentSection", section: p } : { kind: "sheet", sheetId: I.sheet.id },
4682
+ source: {
4683
+ dashboard: e,
4684
+ adHocFilterValues: s,
4685
+ controlValues: c,
4686
+ inlineFilterValuesMap: a,
4687
+ cardControlValuesMap: l ? Object.fromEntries(
4688
+ Object.entries(l).filter(
4689
+ (h) => h[1] !== void 0
4690
+ )
4691
+ ) : void 0,
4692
+ dashboardInputValues: u,
4693
+ transientContexts: n,
4694
+ cardViewStates: o,
4695
+ viewerTableSettings: r,
4696
+ calendar: d,
4697
+ ...y ? { editor: y } : {}
4698
+ },
4699
+ semanticExecutionPayload: i,
4700
+ matrixCatalog: f,
4701
+ withRequest: b
4702
+ });
4703
+ return v.status === "blocked" ? v : {
4704
+ status: "ready",
4705
+ card: m ?? I.card,
4706
+ sheetId: I.sheet.id,
4707
+ queryContext: v.queryContext,
4708
+ compiledFilters: v.compiledFilters,
4709
+ resolvedPrimaryDateField: v.resolvedPrimaryDateField,
4710
+ ...v.matrix ? { matrix: v.matrix } : {},
4711
+ ...v.request ? { request: v.request } : {}
4712
+ };
4713
+ }
4714
+ function Fa(e, t, n) {
4715
+ const o = t === "date" && "relativeMeta" in e ? fr(e.relativeMeta) : void 0;
4716
+ if (!o) return { values: e.values };
4717
+ const r = rr(o, n ?? void 0), i = e.operation === "between" || e.operation === "not between";
4718
+ return {
4719
+ values: r && i ? r : e.values,
4720
+ relativeMeta: o,
4721
+ ..."temporalPrecision" in e && e.temporalPrecision === "minute" ? { temporalPrecision: "minute" } : {}
4722
+ };
4723
+ }
4724
+ function Sa(e, t, n) {
4725
+ const o = t, r = nr(e);
4726
+ return or({
4727
+ definition: e,
4728
+ sourceValue: o,
4729
+ value: {
4730
+ filterId: o.filterId,
4731
+ name: e.column,
4732
+ operation: o.operation ?? e.operation,
4733
+ valueType: r,
4734
+ dataType: e.dataType,
4735
+ fieldMeta: e.fieldMeta,
4736
+ semanticContext: e.semanticContext,
4737
+ ...Fa(o, r, n)
4738
+ }
4739
+ });
4740
+ }
4741
+ function oo(e, t, n) {
4742
+ const o = K(e);
4743
+ let r = {};
4744
+ const i = [], s = [];
4745
+ for (const a of t ?? []) {
4746
+ const c = o.findFilterInput({ filterId: a.filterId }), l = c == null ? void 0 : c.input;
4747
+ if (l || i.push(a), !l || l.runtimeScope === "perCard" || l.runtimeScope === "perDocumentSection") {
4748
+ s.push(a.filterId);
4749
+ continue;
4750
+ }
4751
+ const u = tr(
4752
+ Sa(l.filter, a, n.calendar)
4753
+ );
4754
+ if (u) {
4755
+ if (l.runtimeScope === "shared") {
4756
+ r = gt(r, l, {}, u);
4757
+ continue;
4758
+ }
4759
+ for (const d of sn(e).values())
4760
+ an(l, d) && (r = gt(
4761
+ r,
4762
+ l,
4763
+ { sheetId: d.sheetId },
4764
+ u
4765
+ ));
4766
+ }
4767
+ }
4768
+ return { slots: r, adHocFilterValues: i, droppedFilterIds: s };
4769
+ }
4770
+ function Ta(e) {
4771
+ const { dashboard: t, sheetId: n } = e, o = [];
4772
+ if (n)
4773
+ for (const { input: r } of ir(t, n, e.sheetKind)) {
4774
+ const i = sr({
4775
+ dashboard: t,
4776
+ input: r,
4777
+ runtimeValues: { dashboardInputValues: e.runtimeValues.dashboardInputValues },
4778
+ target: { sheetId: n },
4779
+ calendar: e.calendar
4780
+ });
4781
+ i.kind === "filter" && i.filterValue && o.push(i.filterValue);
4782
+ }
4783
+ return [...o, ...Jn(e.adHocFilterValues, n)];
4784
+ }
4785
+ function Wl(e, t) {
4786
+ switch (t.runtimeScope) {
4787
+ case "shared":
4788
+ return [{}];
4789
+ case "perSheet":
4790
+ return [...sn(e).values()].filter((n) => an(t, n)).map((n) => ({ sheetId: n.sheetId }));
4791
+ case "perCard": {
4792
+ const n = K(e);
4793
+ return [
4794
+ ...n.reachedCards({ inputId: t.id }).map((o) => ({ sheetId: o.sheetId, cardId: o.cardId })),
4795
+ // A variable holds a value at each place it is used (DV-D35).
4796
+ ...n.reachedVariables({ inputId: t.id }).flatMap(
4797
+ (o) => o.places.map((r) => ({ sheetId: r.sheetId, cardId: o.variableId }))
4798
+ )
4799
+ ];
4800
+ }
4801
+ case "perDocumentSection": {
4802
+ const n = /* @__PURE__ */ new Map();
4803
+ for (const o of K(e).reachedCards({ inputId: t.id }))
4804
+ o.kind === "documentSectionCard" && n.set(o.sectionId, { sheetId: o.sheetId, sectionId: o.sectionId });
4805
+ return [...n.values()];
4806
+ }
4807
+ default:
4808
+ return [];
4809
+ }
4810
+ }
4811
+ function At(e) {
4812
+ var t;
4813
+ return [
4814
+ ...e.cards ?? [],
4815
+ ...(e.frames ?? []).flatMap((n) => n.cards),
4816
+ ...(((t = e.document) == null ? void 0 : t.sections) ?? []).flatMap(
4817
+ (n) => ln(n)
4818
+ )
4819
+ ];
4820
+ }
4821
+ function Da(e, t) {
4822
+ var n, o;
4823
+ return {
4824
+ sheetId: e.id,
4825
+ cardId: t.id,
4826
+ sheetKind: e.kind ?? "dashboard",
4827
+ sectionId: (o = (n = e.document) == null ? void 0 : n.sections.find(
4828
+ (r) => ln(r).some(({ id: i }) => i === t.id)
4829
+ )) == null ? void 0 : o.id
4830
+ };
4831
+ }
4832
+ function Ma(e, t, n, o) {
4833
+ var l, u, d;
4834
+ const r = {}, i = (l = e.preferences) == null ? void 0 : l.textVisualOptions;
4835
+ if (!i) return r;
4836
+ const s = Ue({
4837
+ // Authoring: carried drill context never applies to a dashboard being edited.
4838
+ transientContexts: void 0,
4839
+ dashboard: n,
4840
+ ...Da(o, t),
4841
+ card: t,
4842
+ runtimeValues: {},
4843
+ // Aliases only: no input value is read.
4844
+ calendar: null
4845
+ }), a = (f) => {
4846
+ if (f.source !== "dashboardInputAlias") return f;
4847
+ const m = s.variablesByName[f.variableName], g = m ? {
4848
+ source: "input",
4849
+ inputId: m.id,
4850
+ export: f.export ?? "label"
4851
+ } : f;
4852
+ return m && (r[f.variableName] = g), g;
4853
+ }, c = (f) => {
4854
+ Object.assign(f, Wt(f, (m) => a(m))), f.type === "link" && [...f.children, ...Array.isArray(f.url) ? f.url : []].forEach((m) => c(m)), f.type === "when" && [...f.then ?? [], ...f.else ?? []].forEach(c);
4855
+ };
4856
+ return (u = i.content) == null || u.forEach((f) => {
4857
+ f.type === "variable" && (f.ref = a(f.ref));
4858
+ }), (d = i.richContent) == null || d.blocks.forEach((f) => {
4859
+ f.type === "list" ? f.items.forEach((m) => m.forEach(c)) : f.children.forEach(c);
4860
+ }), r;
4861
+ }
4862
+ function Va(e, t) {
4863
+ var i;
4864
+ const n = At(e);
4865
+ if (!n.some((s) => {
4866
+ var a;
4867
+ return (a = s.preferences) == null ? void 0 : a.textVisualOptions;
4868
+ }))
4869
+ return e;
4870
+ const o = ye(e), r = At(o);
4871
+ for (let s = 0; s < r.length; s++) {
4872
+ const a = Ma(
4873
+ r[s],
4874
+ n[s],
4875
+ t,
4876
+ e
4877
+ );
4878
+ (i = e.frames) != null && i.some(
4879
+ (c) => c.visualId && c.cards.some((l) => l.id === r[s].id)
4880
+ ) && (r[s].linkedReferenceOverrides = Jr(
4881
+ r[s].linkedReferenceOverrides,
4882
+ { inputAliases: a }
4883
+ ));
4884
+ }
4885
+ return o;
4886
+ }
4887
+ function ka(e) {
4888
+ var n;
4889
+ const t = (n = e.sheets) == null ? void 0 : n.map(
4890
+ (o) => Va(o, e)
4891
+ );
4892
+ return t && t.some((o, r) => o !== e.sheets[r]) ? { ...e, sheets: t } : e;
4893
+ }
4894
+ function Pa(e) {
4895
+ const t = K(e);
4896
+ return t.issues.length === 0 && !t.needsUpgrade ? e : t.issues.length ? t.toStoredDashboard() : K(
4897
+ ka(e)
4898
+ ).toStoredDashboard();
4899
+ }
4900
+ export {
4901
+ rt as $,
4902
+ oo as A,
4903
+ Ta as B,
4904
+ Wl as C,
4905
+ ia as D,
4906
+ Jn as E,
4907
+ Jr as F,
4908
+ Ya as G,
4909
+ si as H,
4910
+ Cs as I,
4911
+ Mt as J,
4912
+ gl as K,
4913
+ Zr as L,
4914
+ fl as M,
4915
+ Di as N,
4916
+ Ti as O,
4917
+ Fi as P,
4918
+ il as Q,
4919
+ In as R,
4920
+ Be as S,
4921
+ el as T,
4922
+ ss as U,
4923
+ as as V,
4924
+ ki as W,
4925
+ U as X,
4926
+ ul as Y,
4927
+ xi as Z,
4928
+ dl as _,
4929
+ qs as a,
4930
+ bl as a$,
4931
+ ot as a0,
4932
+ Rr as a1,
4933
+ sl as a2,
4934
+ cl as a3,
4935
+ Mi as a4,
4936
+ ol as a5,
4937
+ nt as a6,
4938
+ xn as a7,
4939
+ Ul as a8,
4940
+ ba as a9,
4941
+ Gl as aA,
4942
+ Ll as aB,
4943
+ se as aC,
4944
+ pn as aD,
4945
+ Xa as aE,
4946
+ Za as aF,
4947
+ nl as aG,
4948
+ ha as aH,
4949
+ di as aI,
4950
+ tl as aJ,
4951
+ jl as aK,
4952
+ un as aL,
4953
+ al as aM,
4954
+ Nl as aN,
4955
+ Vl as aO,
4956
+ Ds as aP,
4957
+ ql as aQ,
4958
+ Hn as aR,
4959
+ Ke as aS,
4960
+ rl as aT,
4961
+ Ys as aU,
4962
+ Un as aV,
4963
+ Ye as aW,
4964
+ ll as aX,
4965
+ Il as aY,
4966
+ vl as aZ,
4967
+ tt as a_,
4968
+ At as aa,
4969
+ Da as ab,
4970
+ Ma as ac,
4971
+ Va as ad,
4972
+ _l as ae,
4973
+ El as af,
4974
+ On as ag,
4975
+ Bl as ah,
4976
+ _i as ai,
4977
+ aa as aj,
4978
+ $l as ak,
4979
+ ta as al,
4980
+ zl as am,
4981
+ hl as an,
4982
+ Hl as ao,
4983
+ ds as ap,
4984
+ fs as aq,
4985
+ Ca as ar,
4986
+ Sl as as,
4987
+ Tl as at,
4988
+ ms as au,
4989
+ Re as av,
4990
+ us as aw,
4991
+ gs as ax,
4992
+ Dl as ay,
4993
+ Pn as az,
4994
+ pl as b,
4995
+ Cl as b0,
4996
+ Fl as b1,
4997
+ cs as b2,
4998
+ ne as b3,
4999
+ Pl as b4,
5000
+ Kl as b5,
5001
+ Rl as b6,
5002
+ Ui as c,
5003
+ na as d,
5004
+ Wr as e,
5005
+ yl as f,
5006
+ Ml as g,
5007
+ Al as h,
5008
+ ml as i,
5009
+ wl as j,
5010
+ ye as k,
5011
+ Ks as l,
5012
+ Ql as m,
5013
+ Ol as n,
5014
+ st as o,
5015
+ kl as p,
5016
+ Sa as q,
5017
+ xl as r,
5018
+ hs as s,
5019
+ Is as t,
5020
+ Xr as u,
5021
+ ni as v,
5022
+ fn as w,
5023
+ Ja as x,
5024
+ ri as y,
5025
+ Pa as z
5026
+ };