react-semaphor 0.1.590 → 0.1.592

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 (87) hide show
  1. package/dist/analytics-protocol/index.js +254 -236
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +7 -7
  4. package/dist/briefings/index.js +4 -4
  5. package/dist/chunks/{aggregate-measure-field-BrkXsSJp.js → aggregate-measure-field-DHlDj0Pc.js} +2 -2
  6. package/dist/chunks/{assistant-chat-C_6dBLUk.js → assistant-chat-BusR-5uT.js} +13 -13
  7. package/dist/chunks/bookmark-impact-DozXJZDS.js +76 -0
  8. package/dist/chunks/{bookmark-state-Bn7k3ttp.js → bookmark-state-Be2W3s6t.js} +632 -592
  9. package/dist/chunks/{card-filter-builder-6vflbF9O.js → card-filter-builder-DBTJ74yy.js} +916 -897
  10. package/dist/chunks/{comparison-window-caption-fqijZdVd.js → comparison-window-caption-h8w3ySL6.js} +90 -91
  11. package/dist/chunks/{dashboard-DpgRl65K.js → dashboard-CmzJzmph.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-BLbhONJz.js → dashboard-briefing-launcher-BOQGpYr2.js} +160 -160
  13. package/dist/chunks/{dashboard-controls-kCTYEEsq.js → dashboard-controls-BxI3e2_o.js} +64 -64
  14. package/dist/chunks/{dashboard-json-CNIFresY.js → dashboard-json-BMqXV2Rx.js} +4 -4
  15. package/dist/chunks/{dates-BoeweqEo.js → dates-DBsscxL_.js} +8 -8
  16. package/dist/chunks/{edit-dashboard-visual-D0eWTlPL.js → edit-dashboard-visual-Dvc_Pkfg.js} +5443 -5417
  17. package/dist/chunks/filter-line-CYT7KIXb.js +133 -0
  18. package/dist/chunks/{filter-reach-copy-eMhDPTYH.js → filter-reach-copy-hEzlpBu7.js} +224 -224
  19. package/dist/chunks/filter-value-text-CHBm4IU7.js +153 -0
  20. package/dist/chunks/{index-D8LFjI8j.js → index-BoYJqc3F.js} +24 -24
  21. package/dist/chunks/{layout-grid-BG__sPkb.js → layout-grid-DoFIfQGd.js} +1 -1
  22. package/dist/chunks/{list-filter-Cb8i7N8f.js → list-filter-BeTQxjNy.js} +1 -1
  23. package/dist/chunks/{matrix-analytical-definition-D9Ll_9R-.js → matrix-analytical-definition-CyWOwLmE.js} +17 -17
  24. package/dist/chunks/{matrix-member-presentation-DVBJR0MA.js → matrix-member-presentation-Bj2YcHAP.js} +1 -1
  25. package/dist/chunks/{matrix-operation-contract-JSmproo9.js → matrix-operation-contract-CAanJeCj.js} +60 -60
  26. package/dist/chunks/{metric-comparison-xE_J6hkg.js → metric-comparison-BeKnUD08.js} +27 -31
  27. package/dist/chunks/{paintbrush-C310xSuR.js → paintbrush-KeaU1L1a.js} +1 -1
  28. package/dist/chunks/{palette-Ci5P91Zb.js → palette-BcFJLeXB.js} +1 -1
  29. package/dist/chunks/{pivot-result-contract-expectations-DbBahmgc.js → pivot-result-contract-expectations-CaS0y823.js} +522 -486
  30. package/dist/chunks/{pivot-result-identity-CUsMt_4r.js → pivot-result-identity-BKUjYO1u.js} +1 -1
  31. package/dist/chunks/raw-temporal-value-BzdgeDa7.js +454 -0
  32. package/dist/chunks/{report-preferences-dialog-dUlVLgEk.js → report-preferences-dialog-Cu_f-8Kw.js} +13 -13
  33. package/dist/chunks/{report-runtime-context-CrOgmuxO.js → report-runtime-context-g4Zp_TU9.js} +1 -1
  34. package/dist/chunks/{resolve-dashboard-input-context-NurwNg4I.js → resolve-dashboard-input-context-CkMk1RW6.js} +7600 -6398
  35. package/dist/chunks/{save-BhhXfp4s.js → save-C9CZAk6V.js} +1 -1
  36. package/dist/chunks/{saved-dashboard-context-CPp--vXU.js → saved-dashboard-context-RgBS_PIj.js} +19 -19
  37. package/dist/chunks/{selection-filter-compiler-CHG-8xnW.js → selection-filter-compiler-BclSpK3P.js} +1 -1
  38. package/dist/chunks/{semaphor-ready-indicator-CXojR95M.js → semaphor-ready-indicator-DXpTZJ7R.js} +31502 -31453
  39. package/dist/chunks/{shelf-drop-preview-context-BDScAUdq.js → shelf-drop-preview-context-qdlJKaH7.js} +5 -5
  40. package/dist/chunks/stored-dashboard-Baw6Bp2A.js +4029 -0
  41. package/dist/chunks/{style-sheet-parts-CmXmKqGw.js → style-sheet-parts-DM_Mw_sm.js} +45 -42
  42. package/dist/chunks/{table-export-sheet-ClSgERQC.js → table-export-sheet-Cd6z7SsG.js} +1 -1
  43. package/dist/chunks/{token-types-DTocOcwt.js → token-types-BB2ImFx6.js} +1 -1
  44. package/dist/chunks/{upload-DDYc1Qjj.js → upload-CMTCg47S.js} +1 -1
  45. package/dist/chunks/{validators-CrYXNnNE.js → validators-BlEWWX9O.js} +576 -562
  46. package/dist/chunks/{variable-draft-Bi3RlULA.js → variable-draft-BxtN6YcG.js} +4 -4
  47. package/dist/dashboard/index.js +2 -2
  48. package/dist/dashboard-authoring/index.js +1672 -1633
  49. package/dist/format-utils/index.js +217 -218
  50. package/dist/index.js +62 -62
  51. package/dist/report-runtime-context/index.js +1 -1
  52. package/dist/style.css +1 -1
  53. package/dist/surfboard/index.js +2 -2
  54. package/dist/types/components/surfboard/filter/types.d.ts +7 -5
  55. package/dist/types/components/visual/data-table/hooks/use-data-table-logic.d.ts +3 -3
  56. package/dist/types/components/visual/data-table/types/data-table.d.ts +24 -2
  57. package/dist/types/index.js +30 -29
  58. package/dist/types/lib/dashboard-inputs/dashboard-date-comparison-plan.d.ts +0 -1
  59. package/dist/types/lib/dashboard-viewer/table-view-edit.d.ts +27 -0
  60. package/dist/types/lib/dashboard-viewer/table-view.d.ts +37 -1
  61. package/dist/types/lib/formatters/raw-temporal-presentation.d.ts +0 -2
  62. package/dist/types/shared/analytics-protocol/agent-time-window.d.ts +1 -1
  63. package/dist/types/shared/analytics-protocol/relative-date/index.d.ts +2 -1
  64. package/dist/types/shared/analytics-protocol/relative-date/sentence.d.ts +81 -0
  65. package/dist/types/shared/analytics-protocol/relative-date/traits.d.ts +0 -9
  66. package/dist/types/shared/analytics-protocol/relative-date/window.d.ts +23 -2
  67. package/dist/types/shared/dashboard-authoring/canonical-result-keys.d.ts +20 -0
  68. package/dist/types/shared/dashboard-authoring/card-formats/detail-date-display.d.ts +84 -0
  69. package/dist/types/shared/dashboard-authoring/card-settings/card-kinds.d.ts +1 -1
  70. package/dist/types/shared/dashboard-authoring/card-settings/column-names.d.ts +2 -0
  71. package/dist/types/shared/dashboard-authoring/card-settings/inputs.d.ts +6 -0
  72. package/dist/types/shared/dashboard-authoring/card-settings/resolved.d.ts +11 -0
  73. package/dist/types/shared/dashboard-authoring/changes/dashboard-change.d.ts +36 -36
  74. package/dist/types/shared/dashboard-authoring/filter-model/date-filter-default.d.ts +37 -0
  75. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +1 -0
  76. package/dist/types/shared/dashboard-authoring/index.d.ts +1 -0
  77. package/dist/types/shared/dashboard-viewer/table-column-move.d.ts +56 -0
  78. package/dist/types/shared/dashboard-viewer/table-settings.d.ts +7 -0
  79. package/dist/types/shared/format-utils/filter-line.d.ts +2 -0
  80. package/package.json +1 -1
  81. package/dist/chunks/bookmark-impact-DkZABEd3.js +0 -75
  82. package/dist/chunks/filter-line-Dza3ee4w.js +0 -131
  83. package/dist/chunks/filter-value-text-DQw4v3nC.js +0 -146
  84. package/dist/chunks/pivot-header-presentation-D-DfPAjb.js +0 -42
  85. package/dist/chunks/raw-temporal-value-BnGCWJAL.js +0 -322
  86. package/dist/chunks/stored-dashboard-KkH4zOhq.js +0 -4998
  87. package/dist/types/components/visual/shared/utils/table-column-order.d.ts +0 -53
@@ -0,0 +1,4029 @@
1
+ import { hW as hn, cY as vn, cl as Fn, a$ as Dn, bn as Sn, k as Tn, cd as Vn, hX as Te, eG as lt, eJ as Mn, bW as kn, hY as xn, aB as Pn, gX as ct, gZ as wn, bH as Ve, hZ as dt, S as On, g$ as _n, dt as de, s as _, gQ as ue, n as Me, h_ as An, h4 as Bn, dk as ut, dm as ft, d5 as En, ds as Rn, dq as Le, dr as qn, b as Nn, d7 as jn, dj as zn, dh as Ln, bK as pt, bi as Kn, a7 as A, hy as Gn, h$ as fe, i0 as mt, i1 as Hn, i2 as ke, hN as pe, i3 as Un, i4 as xe, i5 as Qn, i6 as $n, i7 as Wn, i8 as Zn, i9 as Yn, o as Pe, ia as Jn, p as U, r as Xn, h as er, ib as L, gH as we, ic as te, id as gt, ie as tr, M as nr, ig as rr, ih as or, gA as yt, ii as ir, ij as ar, e as sr, ik as lr, il as bt, im as cr, io as dr, a3 as It, ip as ur, iq as fr, ir as Ct, m as Oe, is as pr, cM as mr, a8 as gr, t as ht, cL as yr, hK as br, v as Ir, w as Ke, F as Cr, it as hr, iu as vr, cN as Fr, iv as Dr } from "./resolve-dashboard-input-context-CkMk1RW6.js";
2
+ import { am as Sr, a7 as W, M as Tr, x as Vr, ay as Ce, y as Mr, a9 as ne, aA as vt, W as kr, b as xr, r as Pr, k as wr, aE as Or } from "./validators-BlEWWX9O.js";
3
+ import { r as Ft } from "./matrix-operation-contract-CAanJeCj.js";
4
+ import "./analytics-base-schemas-8wz9vqn_.js";
5
+ import "./pickers-DkqmtnTL.js";
6
+ import { canonicalizeSupportedCurrencyCode as Dt } from "../value-format-preferences/index.js";
7
+ import { ZodError as _r } from "zod";
8
+ import { b as re, r as Ar, b6 as Br, i as Er, aP as Rr, ai as Ge, aN as He } from "./pivot-result-contract-expectations-CaS0y823.js";
9
+ import { aE as St, aF as Tt, aG as be, a3 as qr, aD as Vt, C as he, aH as j, A as Z, i as Mt, w as Nr, q as jr, v as zr, B as _e, aI as Lr, al as Kr, G as kt, F as Gr, K as Ue, P as xt, Q as Pt, J as wt } from "./bookmark-state-Be2W3s6t.js";
10
+ import "./schema-C9NPiIru.js";
11
+ import "./index-CV_Kzou0.js";
12
+ import "./context-CVXTFljo.js";
13
+ import { a as Hr, i as Ur } from "./matrix-analytical-definition-CyWOwLmE.js";
14
+ import { D as Qr } from "./report-runtime-context-g4Zp_TU9.js";
15
+ import { isPdfTableCardType as $r, PDF_CAPACITY as Wr } from "../pdf-export-policy/index.js";
16
+ import { K as Qe } from "./raw-temporal-value-BzdgeDa7.js";
17
+ import { t as Zr, n as Yr, c as Jr } from "./selection-filter-compiler-BclSpK3P.js";
18
+ const Xr = (e, t) => {
19
+ const n = {};
20
+ if (e === null || t === null)
21
+ return t;
22
+ const r = /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]);
23
+ for (const o of r) {
24
+ if (!(o in e) && o in t) {
25
+ n[o] = t[o];
26
+ continue;
27
+ }
28
+ if (o in e && !(o in t)) {
29
+ n[o] = void 0;
30
+ continue;
31
+ }
32
+ const i = e[o], a = t[o];
33
+ if (!ve(i, a))
34
+ if (Array.isArray(i) && Array.isArray(a))
35
+ n[o] = a;
36
+ else if ($e(i) && $e(a)) {
37
+ const s = Xr(i, a);
38
+ Object.keys(s).length > 0 && (n[o] = s);
39
+ } else
40
+ n[o] = a;
41
+ }
42
+ return n;
43
+ }, ve = (e, t) => {
44
+ if (e === t) return !0;
45
+ if (e && t && typeof e == "object" && typeof t == "object") {
46
+ if (Array.isArray(e) && Array.isArray(t))
47
+ return e.length !== t.length ? !1 : e.every((o, i) => ve(o, t[i]));
48
+ const n = Object.keys(e), r = Object.keys(t);
49
+ return n.length !== r.length ? !1 : n.every((o) => ve(e[o], t[o]));
50
+ }
51
+ return !1;
52
+ }, $e = (e) => e !== null && typeof e == "object" && !Array.isArray(e), oe = (e) => {
53
+ if (e === null || typeof e != "object")
54
+ return e;
55
+ if (e instanceof Date)
56
+ return new Date(e);
57
+ if (e instanceof RegExp)
58
+ return new RegExp(e);
59
+ if (Array.isArray(e))
60
+ return e.map((n) => oe(n));
61
+ const t = {};
62
+ for (const n in e)
63
+ Object.prototype.hasOwnProperty.call(e, n) && (t[n] = oe(e[n]));
64
+ return t;
65
+ }, eo = /^(?:[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;
66
+ function to(e) {
67
+ return typeof e == "string" && eo.test(e);
68
+ }
69
+ function no(e) {
70
+ if (!to(e))
71
+ throw TypeError("Invalid UUID");
72
+ let t;
73
+ const n = new Uint8Array(16);
74
+ 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;
75
+ }
76
+ function ro(e) {
77
+ e = unescape(encodeURIComponent(e));
78
+ const t = [];
79
+ for (let n = 0; n < e.length; ++n)
80
+ t.push(e.charCodeAt(n));
81
+ return t;
82
+ }
83
+ const oo = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", io = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
84
+ function ao(e, t, n) {
85
+ function r(o, i, a, s) {
86
+ var l;
87
+ if (typeof o == "string" && (o = ro(o)), typeof i == "string" && (i = no(i)), ((l = i) === null || l === void 0 ? void 0 : l.length) !== 16)
88
+ throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
89
+ let c = new Uint8Array(16 + o.length);
90
+ if (c.set(i), c.set(o, i.length), c = n(c), c[6] = c[6] & 15 | t, c[8] = c[8] & 63 | 128, a) {
91
+ s = s || 0;
92
+ for (let d = 0; d < 16; ++d)
93
+ a[s + d] = c[d];
94
+ return a;
95
+ }
96
+ return hn(c);
97
+ }
98
+ try {
99
+ r.name = e;
100
+ } catch {
101
+ }
102
+ return r.DNS = oo, r.URL = io, r;
103
+ }
104
+ function so(e, t, n, r) {
105
+ switch (e) {
106
+ case 0:
107
+ return t & n ^ ~t & r;
108
+ case 1:
109
+ return t ^ n ^ r;
110
+ case 2:
111
+ return t & n ^ t & r ^ n & r;
112
+ case 3:
113
+ return t ^ n ^ r;
114
+ }
115
+ }
116
+ function Ie(e, t) {
117
+ return e << t | e >>> 32 - t;
118
+ }
119
+ function lo(e) {
120
+ const t = [1518500249, 1859775393, 2400959708, 3395469782], n = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
121
+ if (typeof e == "string") {
122
+ const a = unescape(encodeURIComponent(e));
123
+ e = [];
124
+ for (let s = 0; s < a.length; ++s)
125
+ e.push(a.charCodeAt(s));
126
+ } else Array.isArray(e) || (e = Array.prototype.slice.call(e));
127
+ e.push(128);
128
+ const r = e.length / 4 + 2, o = Math.ceil(r / 16), i = new Array(o);
129
+ for (let a = 0; a < o; ++a) {
130
+ const s = new Uint32Array(16);
131
+ for (let l = 0; l < 16; ++l)
132
+ s[l] = e[a * 64 + l * 4] << 24 | e[a * 64 + l * 4 + 1] << 16 | e[a * 64 + l * 4 + 2] << 8 | e[a * 64 + l * 4 + 3];
133
+ i[a] = s;
134
+ }
135
+ i[o - 1][14] = (e.length - 1) * 8 / Math.pow(2, 32), i[o - 1][14] = Math.floor(i[o - 1][14]), i[o - 1][15] = (e.length - 1) * 8 & 4294967295;
136
+ for (let a = 0; a < o; ++a) {
137
+ const s = new Uint32Array(80);
138
+ for (let m = 0; m < 16; ++m)
139
+ s[m] = i[a][m];
140
+ for (let m = 16; m < 80; ++m)
141
+ s[m] = Ie(s[m - 3] ^ s[m - 8] ^ s[m - 14] ^ s[m - 16], 1);
142
+ let l = n[0], c = n[1], d = n[2], u = n[3], f = n[4];
143
+ for (let m = 0; m < 80; ++m) {
144
+ const y = Math.floor(m / 20), p = Ie(l, 5) + so(y, c, d, u) + f + t[y] + s[m] >>> 0;
145
+ f = u, u = d, d = Ie(c, 30) >>> 0, c = l, l = p;
146
+ }
147
+ n[0] = n[0] + l >>> 0, n[1] = n[1] + c >>> 0, n[2] = n[2] + d >>> 0, n[3] = n[3] + u >>> 0, n[4] = n[4] + f >>> 0;
148
+ }
149
+ 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];
150
+ }
151
+ const co = ao("v5", 80, lo), We = /\[\[\s*param\.([A-Za-z0-9_.-]+)\s*\]\]/g, Ze = /\bparam\s*\(\s*(['"])([^'"]+)\1/g;
152
+ function uo(e) {
153
+ const t = [];
154
+ let n = 0;
155
+ for (; n < e.length; ) {
156
+ const r = e.indexOf("{{", n), o = e.indexOf("{%", n);
157
+ let i = -1, a = "";
158
+ if (r === -1 ? (i = o, a = "%}") : o === -1 || r < o ? (i = r, a = "}}") : (i = o, a = "%}"), i === -1)
159
+ break;
160
+ const s = e.indexOf(a, i + 2);
161
+ if (s === -1) {
162
+ n = i + 2;
163
+ continue;
164
+ }
165
+ t.push(e.slice(i + 2, s)), n = s + 2;
166
+ }
167
+ return t;
168
+ }
169
+ function Ot(e) {
170
+ var r, o;
171
+ if (!e)
172
+ return [];
173
+ const t = /* @__PURE__ */ new Set();
174
+ let n;
175
+ for (We.lastIndex = 0; (n = We.exec(e)) !== null; ) {
176
+ const i = (r = n[1]) == null ? void 0 : r.trim();
177
+ i && t.add(i);
178
+ }
179
+ for (const i of uo(e))
180
+ for (Ze.lastIndex = 0; (n = Ze.exec(i)) !== null; ) {
181
+ const a = (o = n[2]) == null ? void 0 : o.trim();
182
+ a && t.add(a);
183
+ }
184
+ return Array.from(t);
185
+ }
186
+ function Ae(e) {
187
+ const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Map();
188
+ for (const r of e.controlBindings || [])
189
+ t.add(r.controlId), r.target === "sql_param" && n.set(r.paramId, r.controlId);
190
+ for (const r of Ot(e.sql))
191
+ t.add(n.get(r) ?? r);
192
+ return Array.from(t);
193
+ }
194
+ function fo(e) {
195
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
196
+ for (const r of e.controlBindings || [])
197
+ r.target === "sql_param" && n.set(r.paramId, r.controlId);
198
+ for (const r of Ot(e.sql))
199
+ t.set(r, {
200
+ paramId: r,
201
+ controlId: n.get(r) ?? r
202
+ });
203
+ return Array.from(t.values());
204
+ }
205
+ function po(e, t) {
206
+ var o;
207
+ const n = (o = e.controlBindings) == null ? void 0 : o.map((i) => ({
208
+ ...i,
209
+ controlId: t.get(i.controlId) ?? i.controlId
210
+ })), r = fo(e).flatMap(
211
+ ({ paramId: i, controlId: a }) => {
212
+ var l;
213
+ const s = t.get(a);
214
+ return !s || s === a || (l = e.controlBindings) != null && l.some(
215
+ (c) => c.target === "sql_param" && c.paramId === i
216
+ ) ? [] : [{ target: "sql_param", paramId: i, controlId: s }];
217
+ }
218
+ );
219
+ return r.length ? [...n ?? [], ...r] : n;
220
+ }
221
+ function _t(e, t) {
222
+ var a, s;
223
+ const n = be(e) ?? e, r = n.source === "dashboardInputAlias" ? (a = t.inputAliases) == null ? void 0 : a[n.variableName] : void 0, o = n.source === "dashboardInputAlias" && r ? be(r) ?? be({ ...r, export: n.export ?? "label" }) ?? n : n, i = n.source === "dashboardInputAlias" && o !== n ? { ...o, export: n.export ?? "label" } : o;
224
+ return i.source === "input" ? {
225
+ ...i,
226
+ inputId: ((s = t.inputIds) == null ? void 0 : s[i.inputId]) ?? i.inputId
227
+ } : i;
228
+ }
229
+ function mo(e, t) {
230
+ var o;
231
+ const n = {};
232
+ for (const i of [
233
+ "cardIds",
234
+ "sheetIds",
235
+ "inputIds",
236
+ "controlIds",
237
+ "filterIds"
238
+ ]) {
239
+ const a = { ...t[i] };
240
+ for (const [s, l] of Object.entries((e == null ? void 0 : e[i]) ?? {}))
241
+ a[s] = ((o = t[i]) == null ? void 0 : o[l]) ?? l;
242
+ Object.keys(a).length && (n[i] = a);
243
+ }
244
+ const r = { ...t.inputAliases };
245
+ for (const [i, a] of Object.entries((e == null ? void 0 : e.inputAliases) ?? {}))
246
+ r[i] = _t(a, t);
247
+ return Object.keys(r).length && (n.inputAliases = r), n;
248
+ }
249
+ function La(e, t) {
250
+ var o, i, a, s;
251
+ const n = oe(St(e));
252
+ n.controlBindings = po(
253
+ e,
254
+ new Map(Object.entries(t.controlIds ?? {}))
255
+ );
256
+ for (const l of n.controls ?? [])
257
+ l.id = ((o = t.controlIds) == null ? void 0 : o[l.id]) ?? l.id;
258
+ for (const l of n.inlineFilters ?? [])
259
+ l.id = ((i = t.filterIds) == null ? void 0 : i[l.id]) ?? l.id;
260
+ const r = (l) => {
261
+ var d, u;
262
+ if (!l || typeof l != "object") return;
263
+ if (Array.isArray(l)) {
264
+ l.forEach(r);
265
+ return;
266
+ }
267
+ const c = l;
268
+ if (Object.assign(
269
+ c,
270
+ Tt(
271
+ c,
272
+ (f) => f && typeof f == "object" ? _t(f, t) : f
273
+ )
274
+ ), typeof c.entityId == "string") {
275
+ const f = c.entityId;
276
+ c.fieldScope === "card" && (c.entityId = ((d = t.cardIds) == null ? void 0 : d[f]) ?? f), c.fieldScope === "sheet" && (c.entityId = ((u = t.sheetIds) == null ? void 0 : u[f]) ?? f);
277
+ }
278
+ for (const [f, m] of Object.entries(c))
279
+ f !== "linkedReferenceOverrides" && r(m);
280
+ };
281
+ r(n), n.clickToFilter && (n.clickToFilter = vn(n.clickToFilter, t));
282
+ for (const l of Object.values(
283
+ ((a = n.customCardPreferences) == null ? void 0 : a.dataInputCardIds) ?? {}
284
+ ))
285
+ l.cardId = ((s = t.cardIds) == null ? void 0 : s[l.cardId]) ?? l.cardId;
286
+ return n;
287
+ }
288
+ const go = "9677efdd-86ec-4afb-b9bb-5ead8b5442af";
289
+ function yo(e) {
290
+ let t = 0;
291
+ return () => co(`${e}#${t++}`, go);
292
+ }
293
+ const bo = [
294
+ { code: "matrix_definition_incomplete", label: "Matrix definition" }
295
+ ], Io = [
296
+ { code: "connection_type_unresolved", label: "Connection type" }
297
+ ], G = (e) => !Array.isArray(e) || e.length === 0;
298
+ function Co(e) {
299
+ var i;
300
+ const t = e.config ?? {};
301
+ if ((i = e.sql) != null && i.trim() || !G(t.pivotByColumns)) return "matrixTable";
302
+ const n = !G(t.groupByColumns), r = !G(t.metricColumns), o = e.type === "pivotTable" && (n || r) && G(t.rowAggregates) && G(t.columnAggregates);
303
+ return n && !r || o ? "table" : "matrixTable";
304
+ }
305
+ function ho(e) {
306
+ var o;
307
+ const t = e.dataSource;
308
+ if (!t || (o = t.connectionType) != null && o.trim()) return e;
309
+ const n = Sr(Vn(t.selectedEntities));
310
+ if (!n) return e;
311
+ const r = 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;
312
+ return { ...e, dataSource: { ...t, connectionType: n, selectedEntities: r } };
313
+ }
314
+ function At(e) {
315
+ var a, s;
316
+ const t = e;
317
+ if (!Fn(t)) return { status: "not_legacy", card: e };
318
+ const n = ho(t), r = Co(t) === "table" ? Dn(n, "table") : Sn(n, "matrixTable", { createId: yo(t.id) });
319
+ if (r.status !== "changed") throw new Error(`Card ${t.id} could not leave ${t.type}.`);
320
+ const o = r.card.type === "matrixTable" && Tn(r.card).status !== "ready", i = !!n.dataSource && !((s = (a = n.dataSource) == null ? void 0 : a.connectionType) != null && s.trim());
321
+ return {
322
+ status: "routed",
323
+ card: r.card,
324
+ gaps: [
325
+ ...r.gaps,
326
+ ...o ? bo : [],
327
+ ...i ? Io : []
328
+ ]
329
+ };
330
+ }
331
+ function Ka(e) {
332
+ if (!e.cards) return e;
333
+ const t = e.cards.map((n) => At(n).card);
334
+ return t.every((n, r) => n === e.cards[r]) ? e : { ...e, cards: t };
335
+ }
336
+ function vo(e) {
337
+ const t = [];
338
+ return { dashboard: qr(e, (r, o) => {
339
+ const i = At(r);
340
+ return i.status === "routed" && i.gaps.length && t.push({ location: o, gaps: i.gaps }), i.card;
341
+ }), routedWithGaps: t };
342
+ }
343
+ function Fo(e, t) {
344
+ return e.name === t.name && e.qualifiedEntityName === t.qualifiedEntityName;
345
+ }
346
+ function Do(e, t, n) {
347
+ var o, i;
348
+ if (n.sortPolicy === "dropUnrelatedSorts") {
349
+ const a = new Set(
350
+ (e.metricColumns || []).map((s) => s.id)
351
+ );
352
+ return {
353
+ ...e,
354
+ groupByColumns: [t],
355
+ sortByColumns: (e.sortByColumns || []).filter(
356
+ (s) => s.id === t.id || a.has(s.id)
357
+ )
358
+ };
359
+ }
360
+ const r = (o = e.groupByColumns) == null ? void 0 : o[0];
361
+ return {
362
+ ...e,
363
+ groupByColumns: [t],
364
+ sortByColumns: (i = e.sortByColumns) == null ? void 0 : i.map(
365
+ (a) => r && Fo(a, r) ? {
366
+ ...t,
367
+ role: "sortby",
368
+ direction: a.direction
369
+ } : a
370
+ )
371
+ };
372
+ }
373
+ function ie(e) {
374
+ return e == null ? void 0 : e.map(
375
+ ({
376
+ format: t,
377
+ formatOrigin: n,
378
+ semanticTemporalPresentation: r,
379
+ ...o
380
+ }) => o
381
+ );
382
+ }
383
+ function ae(e) {
384
+ if (!e)
385
+ return;
386
+ const {
387
+ format: t,
388
+ formatOrigin: n,
389
+ semanticTemporalPresentation: r,
390
+ ...o
391
+ } = e;
392
+ return Q(o);
393
+ }
394
+ function Bt(e, t) {
395
+ return e == null ? void 0 : e.map(
396
+ (n) => lt(Q(ie([n])[0]), n.format, t)
397
+ );
398
+ }
399
+ function So(e, t) {
400
+ return e == null ? void 0 : e.map(
401
+ (n) => Mn(Q(ie([n])[0]), n.format, t)
402
+ );
403
+ }
404
+ function To(e, t) {
405
+ const { dateFormat: n, customFormat: r, ...o } = ae(e.field);
406
+ return {
407
+ ...e,
408
+ field: t ? o : lt(ae(e.field), e.field.format, "raw")
409
+ };
410
+ }
411
+ function me(e, t = !1) {
412
+ if (e)
413
+ return {
414
+ ...e,
415
+ conditions: e.conditions.map((n) => To(n, t)),
416
+ groups: e.groups.map((n) => me(n, t))
417
+ };
418
+ }
419
+ function Q(e) {
420
+ var n, r;
421
+ const t = { ...e };
422
+ return (n = t.calculatedFormula) != null && n.inputFields && (t.calculatedFormula = {
423
+ ...t.calculatedFormula,
424
+ inputFields: t.calculatedFormula.inputFields.map(
425
+ (o) => ae(o)
426
+ )
427
+ }), (r = t.parameters) != null && r.filters && (t.parameters = {
428
+ ...t.parameters,
429
+ filters: me(t.parameters.filters)
430
+ }), t;
431
+ }
432
+ function Vo(e, t) {
433
+ return t.cardType === "detailTable" || !kn(t.cardType) || t.temporalResultOwner !== "config" ? Bt(e, "grouped") : e == null ? void 0 : e.map((n) => {
434
+ const r = xn(n), o = ae(r ?? n);
435
+ if (!r)
436
+ return o;
437
+ const { dateFormat: i, customFormat: a, ...s } = o;
438
+ return s;
439
+ });
440
+ }
441
+ function Et(e, t) {
442
+ if (!e)
443
+ return;
444
+ const n = { type: t.cardType, config: e };
445
+ return Te(n) ? Mo(n, t) : e.matrix === void 0 ? {} : { matrix: e.matrix };
446
+ }
447
+ function Mo(e, t = {}) {
448
+ var i, a, s;
449
+ const n = e.config;
450
+ if (!n) return;
451
+ const r = { ...t, cardType: e.type };
452
+ return {
453
+ ...n,
454
+ groupByColumns: Vo(n.groupByColumns, r),
455
+ metricColumns: (i = ie(n.metricColumns)) == null ? void 0 : i.map(
456
+ Q
457
+ ),
458
+ pivotByColumns: Bt(n.pivotByColumns, "grouped"),
459
+ sortByColumns: (a = ie(n.sortByColumns)) == null ? void 0 : a.map(
460
+ Q
461
+ ),
462
+ detailColumns: So(n.detailColumns, (s = r.dataSource) == null ? void 0 : s.connectionType),
463
+ filters: me(n.filters)
464
+ };
465
+ }
466
+ function se(e) {
467
+ return (e == null ? void 0 : e.type) === "number" || (e == null ? void 0 : e.type) === "currency";
468
+ }
469
+ function ko(e) {
470
+ return (e == null ? void 0 : e.type) === "number";
471
+ }
472
+ function xo(e) {
473
+ var n;
474
+ if (!ko(e))
475
+ return !1;
476
+ const t = (n = e == null ? void 0 : e.numberFormat) == null ? void 0 : n.style;
477
+ return t === void 0 || t === "decimal" || t === "currency";
478
+ }
479
+ function Po(e, t) {
480
+ const n = t == null ? void 0 : t.type;
481
+ if (n && n !== "none" && n !== "number")
482
+ return { currencyBindable: !1 };
483
+ const r = n === "number" ? t != null && t.numberFormat ? wn(t.numberFormat, {
484
+ preserveOmittedProperties: !0
485
+ }) : { type: "number" } : void 0, o = re(e.format, {
486
+ preserveOmittedProperties: !0
487
+ }), i = W(e.dataType) === "number" ? { type: "number" } : void 0, s = (t == null ? void 0 : t.inheritMetricFormat) === !1 || !!(t != null && t.numberFormat) && (t == null ? void 0 : t.inheritMetricFormat) !== !0 ? r : o || i || r;
488
+ return {
489
+ authoredFormat: s,
490
+ currencyBindable: se(s)
491
+ };
492
+ }
493
+ function wo(e, t) {
494
+ const n = re(t.format, {
495
+ preserveOmittedProperties: !0
496
+ }), r = W(t.dataType) === "number" ? { type: "number" } : void 0, o = n || r;
497
+ return {
498
+ authoredFormat: o,
499
+ source: n ? "semantic" : r ? "inferred" : void 0,
500
+ currencyBindable: se(o)
501
+ };
502
+ }
503
+ function Fe(e, t = {}) {
504
+ var l, c, d;
505
+ const n = t.column ?? ((l = Pn(e)) == null ? void 0 : l.value);
506
+ if ((n == null ? void 0 : n.kind) === "sqlKpiValue") {
507
+ const u = t.resultColumnKey ? {
508
+ kind: "column",
509
+ columnKey: t.resultColumnKey
510
+ } : void 0, f = re(
511
+ Ar({ card: e, column: { kind: "sqlKpiValue" }, surface: "kpiValue" }).format,
512
+ { preserveOmittedProperties: !0 }
513
+ );
514
+ return {
515
+ target: u,
516
+ authoredFormat: f,
517
+ ...f ? { source: "stored" } : {},
518
+ currencyBindable: !!u && se(f)
519
+ };
520
+ }
521
+ const r = n ? (d = (c = e.config) == null ? void 0 : c.metricColumns) == null ? void 0 : d.find((u) => u.id === n.fieldId) : void 0, o = r != null && r.id ? {
522
+ kind: "metric",
523
+ metricId: r.id
524
+ } : void 0, i = re(r == null ? void 0 : r.format, {
525
+ preserveOmittedProperties: !0
526
+ }), a = W(r == null ? void 0 : r.dataType) === "number" ? { type: "number" } : void 0, s = i || a;
527
+ return {
528
+ target: o,
529
+ authoredFormat: s,
530
+ ...i ? { source: "stored" } : a ? { source: "inferred" } : {},
531
+ currencyBindable: ct(e.type) && !!o && se(s)
532
+ };
533
+ }
534
+ function Rt(e, t, n) {
535
+ var o;
536
+ const r = n(e, t);
537
+ return ((o = e.derivedField) == null ? void 0 : o.format) ?? (r == null ? void 0 : r.format) ?? (r == null ? void 0 : r.resolvedField.format);
538
+ }
539
+ function qt(e, t, n) {
540
+ return e.kind === "calculated" ? e.definition.format : Rt(e.field, t, n);
541
+ }
542
+ function Ga(e, t) {
543
+ const n = dt(t), r = (o, i) => Object.fromEntries(o.flatMap((a) => {
544
+ const s = i(a);
545
+ return s ? [[a.id, s]] : [];
546
+ }));
547
+ return {
548
+ measureFormats: r(e.measures, (o) => qt(o, e.source, n)),
549
+ levelFormats: r([...e.rows, ...e.columns], (o) => Rt(o.field, e.source, n))
550
+ };
551
+ }
552
+ function Nt(e, t = []) {
553
+ const n = Ve(e);
554
+ if (n.status !== "ready") return [];
555
+ const { spec: r, presentation: o } = n.config, i = dt(t);
556
+ return r.measures.map((a) => {
557
+ var m;
558
+ const s = a.kind === "aggregate" ? i(a.field, r.source) : void 0, l = Br(o.measureFormats[a.id], qt(a, r.source, i)), c = a.kind === "calculated" ? a.definition.dataType : ["MIN", "MAX"].includes(a.aggregate) ? ((m = a.field.derivedField) == null ? void 0 : m.dataType) ?? (s == null ? void 0 : s.resolvedField.dataType) ?? a.field.dataType : "number", d = W(c) === "number", u = a.kind === "calculated" || !!(s || a.field.derivedField || a.field.name === "*"), f = l && Er(l) ? l : !l && d && u ? { type: "number" } : void 0;
559
+ return { measureId: a.id, label: Rr(a, o), canonical: f };
560
+ });
561
+ }
562
+ function Oo(e) {
563
+ var t, n;
564
+ return e.type === "detailTable" ? ((t = e.config) == null ? void 0 : t.detailColumns) || [] : ((n = e.config) == null ? void 0 : n.metricColumns) || [];
565
+ }
566
+ function jt(e) {
567
+ return new Set(
568
+ Vt(e).flatMap(
569
+ (t) => (t.controlBindings || []).filter(de).map((n) => n.controlId)
570
+ )
571
+ );
572
+ }
573
+ function _o(e, t) {
574
+ const n = [
575
+ t.id,
576
+ t.alias,
577
+ t.label,
578
+ t.name,
579
+ t.qualifiedFieldName
580
+ ].filter((i) => !!i);
581
+ for (const i of n)
582
+ if (e[i])
583
+ return e[i];
584
+ const r = new Set(
585
+ n.map((i) => i.trim().toLowerCase())
586
+ ), o = Object.entries(e).find(
587
+ ([i]) => r.has(i.trim().toLowerCase())
588
+ );
589
+ return o == null ? void 0 : o[1];
590
+ }
591
+ function Ye(e) {
592
+ return [
593
+ ...new Map(
594
+ e.map((t) => [
595
+ z(t),
596
+ t
597
+ ])
598
+ ).values()
599
+ ];
600
+ }
601
+ function Ao(e, t = [], n) {
602
+ var D;
603
+ const r = !!((D = e.sql) != null && D.trim()), o = ct(e.type), i = r && o && e.type !== "kpi" && e.type !== "matrixTable", a = Oo(e), s = On(e), l = !r && e.type === "kpi" ? a.map(
604
+ (g) => Fe(e, {
605
+ column: { kind: "field", fieldId: g.id }
606
+ })
607
+ ) : [], c = !r && e.type === "matrixTable" ? Nt(e, n) : [], d = (r ? [] : a).map(
608
+ (g) => ({
609
+ kind: "metric",
610
+ metricId: g.id
611
+ })
612
+ ), u = c.map(
613
+ (g) => ({
614
+ kind: "matrix_measure",
615
+ measureId: g.measureId
616
+ })
617
+ ), f = c.filter((g) => {
618
+ var V, P;
619
+ return ((V = g.canonical) == null ? void 0 : V.type) === "number" || ((P = g.canonical) == null ? void 0 : P.type) === "currency";
620
+ }).map(
621
+ (g) => ({
622
+ kind: "matrix_measure",
623
+ measureId: g.measureId
624
+ })
625
+ ), m = e.type === "matrixTable" ? [] : e.type === "kpi" ? l.filter((g) => g.currencyBindable).flatMap(
626
+ (g) => g.target ? [g.target] : []
627
+ ) : (r || !o ? [] : a).filter(
628
+ (g) => (_n(e.type) ? Po(
629
+ g,
630
+ _o(s, g)
631
+ ) : wo(e, g)).currencyBindable
632
+ ).map(
633
+ (g) => ({
634
+ kind: "metric",
635
+ metricId: g.id
636
+ })
637
+ ), y = [...new Set(t)], p = (i ? y : []).map(
638
+ (g) => ({
639
+ kind: "column",
640
+ columnKey: g
641
+ })
642
+ ), b = (i ? y : []).filter(
643
+ (g) => xo(
644
+ s[g]
645
+ )
646
+ ).map(
647
+ (g) => ({
648
+ kind: "column",
649
+ columnKey: g
650
+ })
651
+ ), I = (r && e.type === "kpi" ? y.slice(0, 1) : []).map(
652
+ (g) => ({
653
+ kind: "column",
654
+ columnKey: g
655
+ })
656
+ ), C = r && e.type === "kpi" ? Fe(e, {
657
+ resultColumnKey: y[0]
658
+ }) : void 0, h = o && (C != null && C.currencyBindable) ? I : [];
659
+ return {
660
+ knownTargets: Ye([
661
+ ...e.type === "matrixTable" ? u : d,
662
+ ...p,
663
+ ...I
664
+ ]),
665
+ eligibleTargets: Ye([
666
+ ...m,
667
+ ...f,
668
+ ...b,
669
+ ...h
670
+ ])
671
+ };
672
+ }
673
+ function Ha(e, t) {
674
+ const n = Fe(e, {
675
+ resultColumnKey: t
676
+ });
677
+ return n.currencyBindable ? n.target : void 0;
678
+ }
679
+ function Ua(e) {
680
+ var t;
681
+ return (t = e.card.sql) != null && t.trim() ? { kind: "column", columnKey: e.columnKey } : e.metricId ? { kind: "metric", metricId: e.metricId } : void 0;
682
+ }
683
+ function z(e) {
684
+ return e.kind === "metric" ? `metric:${e.metricId}` : e.kind === "column" ? `column:${e.columnKey}` : `matrix_measure:${e.measureId}`;
685
+ }
686
+ function Bo(e) {
687
+ if (!e || typeof e != "object" || Array.isArray(e))
688
+ return;
689
+ const t = e;
690
+ if (t.kind === "metric" && typeof t.metricId == "string" && t.metricId.trim())
691
+ return { kind: "metric", metricId: t.metricId };
692
+ if (t.kind === "column" && typeof t.columnKey == "string" && t.columnKey.trim())
693
+ return { kind: "column", columnKey: t.columnKey };
694
+ if (t.kind === "matrix_measure" && typeof t.measureId == "string" && t.measureId.trim())
695
+ return { kind: "matrix_measure", measureId: t.measureId };
696
+ }
697
+ function Je(e) {
698
+ const t = Dt(e);
699
+ return typeof e == "string" && e === t ? t : void 0;
700
+ }
701
+ function zt(e) {
702
+ if (e.type !== "enum" || e.source.kind !== "manual")
703
+ return { diagnostic: "invalid_control_type" };
704
+ const t = e.source.options.map(
705
+ (n) => Je(n.value)
706
+ );
707
+ if (t.length === 0 || t.some((n) => !n))
708
+ return { diagnostic: "invalid_currency_option" };
709
+ if (e.requiredAtExecution) {
710
+ const n = e.initialValueStrategy === "saved_default" ? Je(e.defaultValue) : void 0;
711
+ if (!n || !t.includes(n))
712
+ return { diagnostic: "invalid_control_default" };
713
+ }
714
+ return {
715
+ control: e,
716
+ currencies: t
717
+ };
718
+ }
719
+ function Qa(e) {
720
+ return "control" in zt(e);
721
+ }
722
+ function Lt(e) {
723
+ const t = jt(e.dashboard);
724
+ if (t.size === 0)
725
+ return {
726
+ definitions: e.definitions || [],
727
+ values: e.values || {}
728
+ };
729
+ const n = new Set(
730
+ [...t].filter(
731
+ (r) => !e.referencedControlIds.has(r)
732
+ )
733
+ );
734
+ return {
735
+ definitions: (e.definitions || []).filter(
736
+ (r) => !n.has(r.id)
737
+ ),
738
+ values: Object.fromEntries(
739
+ Object.entries(e.values || {}).filter(
740
+ ([r]) => !n.has(r)
741
+ )
742
+ )
743
+ };
744
+ }
745
+ function $a(e) {
746
+ return Lt({
747
+ ...e,
748
+ referencedControlIds: new Set(
749
+ Ae({
750
+ sql: e.filterSql,
751
+ controlBindings: []
752
+ })
753
+ )
754
+ });
755
+ }
756
+ function Wa(e) {
757
+ var t;
758
+ return Lt({
759
+ ...e,
760
+ referencedControlIds: new Set(
761
+ Ae({
762
+ sql: (t = e.source) == null ? void 0 : t.sql,
763
+ controlBindings: []
764
+ })
765
+ )
766
+ });
767
+ }
768
+ function Kt(e) {
769
+ return {
770
+ knownKeys: new Set(
771
+ e.knownTargets.map(z)
772
+ ),
773
+ eligibleKeys: new Set(
774
+ e.eligibleTargets.map(z)
775
+ ),
776
+ controlsById: new Map(
777
+ (e.controls || []).map((t) => [t.id, t])
778
+ )
779
+ };
780
+ }
781
+ function Gt(e, t) {
782
+ if (!e || typeof e != "object" || e.target !== "presentation_currency")
783
+ return {};
784
+ const n = e, r = typeof n.controlId == "string" && n.controlId.trim() ? n.controlId : void 0;
785
+ if (!r)
786
+ return { diagnostic: { code: "invalid_binding_shape" } };
787
+ const o = Bo(
788
+ n.presentationTarget
789
+ );
790
+ if (!o)
791
+ return {
792
+ diagnostic: { code: "missing_target", controlId: r }
793
+ };
794
+ const i = z(o);
795
+ if (!t.knownKeys.has(i))
796
+ return {
797
+ diagnostic: { code: "stale_target", controlId: r }
798
+ };
799
+ if (!t.eligibleKeys.has(i))
800
+ return {
801
+ diagnostic: { code: "inapplicable_target", controlId: r }
802
+ };
803
+ const a = t.controlsById.get(r);
804
+ if (!a)
805
+ return {
806
+ diagnostic: { code: "missing_control", controlId: r }
807
+ };
808
+ const s = zt(a);
809
+ return "diagnostic" in s ? {
810
+ diagnostic: { code: s.diagnostic, controlId: r }
811
+ } : {
812
+ binding: {
813
+ controlId: r,
814
+ presentationTarget: o,
815
+ control: s.control,
816
+ currencies: s.currencies
817
+ }
818
+ };
819
+ }
820
+ function Za(e) {
821
+ const t = Kt(e);
822
+ return (e.bindings || []).flatMap((n) => {
823
+ const r = Gt(n, t);
824
+ return "diagnostic" in r ? [r.diagnostic] : [];
825
+ });
826
+ }
827
+ function Eo(e) {
828
+ var o;
829
+ const t = [], n = z(e.target), r = Kt(e);
830
+ for (const i of e.bindings || []) {
831
+ const a = Gt(i, r);
832
+ if ("diagnostic" in a) {
833
+ t.push(a.diagnostic);
834
+ continue;
835
+ }
836
+ const s = a.binding;
837
+ if (!s || z(
838
+ s.presentationTarget
839
+ ) !== n) continue;
840
+ const c = Dt(
841
+ (o = e.values) == null ? void 0 : o[s.control.id]
842
+ );
843
+ if (!(!c || !s.currencies.includes(c)))
844
+ return { currency: c, diagnostics: t };
845
+ }
846
+ return { diagnostics: t };
847
+ }
848
+ function Ro(e, t, n, r) {
849
+ const o = { ...e, config: { ...e.config, matrix: t } }, i = Ao(o, [], r), a = Nt(o, r), s = { ...t.presentation.measureFormats };
850
+ for (const l of a) {
851
+ const c = { kind: "matrix_measure", measureId: l.measureId }, { currency: d } = Eo({
852
+ ...n,
853
+ ...i,
854
+ bindings: e.controlBindings,
855
+ target: c
856
+ });
857
+ if (!d || !l.canonical) continue;
858
+ const { locale: u, ...f } = l.canonical;
859
+ s[l.measureId] = { ...f, type: "currency", currency: d };
860
+ }
861
+ return { ...t.presentation, measureFormats: s };
862
+ }
863
+ function qo(e, t) {
864
+ if (!e || typeof e != "object" || !("kind" in e))
865
+ return e;
866
+ switch (e.kind) {
867
+ case "manual":
868
+ return {
869
+ kind: "manual",
870
+ ...t != null && t.includePresentation ? {
871
+ options: e.options.map((n) => ({
872
+ value: n.value,
873
+ label: n.label,
874
+ presentation: n.presentation
875
+ }))
876
+ } : {
877
+ optionValues: e.options.map((n) => n.value).sort()
878
+ }
879
+ };
880
+ case "dataset_values":
881
+ return {
882
+ kind: "dataset_values",
883
+ fieldId: e.fieldId,
884
+ connectionId: e.connectionId || ""
885
+ };
886
+ case "field_allowlist":
887
+ return {
888
+ kind: "field_allowlist",
889
+ fieldIds: [...e.fieldIds].sort()
890
+ };
891
+ case "metric_allowlist":
892
+ return {
893
+ kind: "metric_allowlist",
894
+ metricIds: [...e.metricIds].sort()
895
+ };
896
+ case "sql_query":
897
+ return {
898
+ kind: "sql_query",
899
+ connectionId: e.connectionId,
900
+ sql: e.sql,
901
+ valueColumn: e.valueColumn,
902
+ labelColumn: e.labelColumn
903
+ };
904
+ default:
905
+ return e;
906
+ }
907
+ }
908
+ function No(e, t) {
909
+ return {
910
+ id: e.id,
911
+ scope: e.scope,
912
+ type: e.type,
913
+ source: qo(e.source, t),
914
+ initialValueStrategy: e.initialValueStrategy,
915
+ defaultValue: e.defaultValue,
916
+ requiredAtExecution: e.requiredAtExecution,
917
+ ...t != null && t.includePresentation ? {
918
+ label: e.label,
919
+ helpText: e.helpText,
920
+ hidden: e.hidden,
921
+ locked: e.locked,
922
+ placement: e.placement,
923
+ showLabel: e.showLabel,
924
+ toolbarWidth: e.toolbarWidth
925
+ } : {}
926
+ };
927
+ }
928
+ function jo(e, t) {
929
+ return e.target === "sql_param" || e.target === "presentation_currency" ? e : e.target === "config_field_selector" && !(t != null && t.includePresentation) ? {
930
+ ...e,
931
+ mapping: Object.fromEntries(
932
+ Object.entries(e.mapping).sort(([n], [r]) => n.localeCompare(r)).map(([n, r]) => {
933
+ if ("kind" in r) return [n, r];
934
+ const o = { ...r };
935
+ return delete o.format, delete o.dateFormat, delete o.customFormat, delete o.semanticTemporalPresentation, [n, o];
936
+ })
937
+ )
938
+ } : {
939
+ ...e,
940
+ mapping: Object.fromEntries(
941
+ Object.entries(e.mapping).sort(([n], [r]) => n.localeCompare(r)).map(([n, r]) => [
942
+ n,
943
+ r && typeof r == "object" && !Array.isArray(r) ? Object.fromEntries(
944
+ Object.entries(r).sort(
945
+ ([o], [i]) => o.localeCompare(i)
946
+ )
947
+ ) : r
948
+ ])
949
+ )
950
+ };
951
+ }
952
+ function Xe(e = [], t) {
953
+ return [...e].map((n) => No(n, t)).sort(
954
+ (n, r) => n.id.localeCompare(r.id) || n.scope.localeCompare(r.scope) || n.type.localeCompare(r.type)
955
+ );
956
+ }
957
+ function zo(e = [], t) {
958
+ return e.filter(
959
+ (n) => (t == null ? void 0 : t.includePresentation) || !de(n)
960
+ ).map((n) => jo(n, t)).sort(
961
+ (n, r) => _(n).localeCompare(_(r))
962
+ );
963
+ }
964
+ function Lo(e, t) {
965
+ return e ? _({
966
+ controlDefinitions: Xe(e.controlDefinitions, t),
967
+ cardControlDefinitions: Xe(
968
+ e.cardControlDefinitions,
969
+ t
970
+ ),
971
+ controlBindings: zo(e.controlBindings, t)
972
+ }) : "__none__";
973
+ }
974
+ const Ko = ["table", "detailTable"], et = (e) => Ko.includes(e.type), Go = "calendar-context";
975
+ function Ho(e) {
976
+ const { id: t, label: n, field: r, ...o } = e;
977
+ return {
978
+ ...o,
979
+ field: Be(
980
+ r
981
+ )
982
+ };
983
+ }
984
+ function ge(e) {
985
+ if (!e)
986
+ return;
987
+ const { id: t, conditions: n, groups: r, ...o } = e;
988
+ return {
989
+ ...o,
990
+ conditions: n.map(Ho),
991
+ groups: r.map((i) => ge(i))
992
+ };
993
+ }
994
+ function Be(e) {
995
+ var r, o;
996
+ const { label: t, ...n } = e;
997
+ return {
998
+ ...n,
999
+ ...(r = e.calculatedFormula) != null && r.inputFields ? {
1000
+ calculatedFormula: {
1001
+ ...e.calculatedFormula,
1002
+ inputFields: e.calculatedFormula.inputFields.map(
1003
+ Be
1004
+ )
1005
+ }
1006
+ } : {},
1007
+ ...(o = e.parameters) != null && o.filters ? {
1008
+ parameters: {
1009
+ ...e.parameters,
1010
+ filters: ge(
1011
+ e.parameters.filters
1012
+ )
1013
+ }
1014
+ } : {}
1015
+ };
1016
+ }
1017
+ function Uo(e) {
1018
+ const t = (n) => n == null ? void 0 : n.map(Be);
1019
+ return {
1020
+ ...e,
1021
+ groupByColumns: t(e.groupByColumns),
1022
+ metricColumns: t(e.metricColumns),
1023
+ pivotByColumns: t(e.pivotByColumns),
1024
+ sortByColumns: t(e.sortByColumns),
1025
+ detailColumns: t(e.detailColumns),
1026
+ filters: e.filters ? ge(e.filters) : void 0
1027
+ };
1028
+ }
1029
+ function Qo(e, t, n) {
1030
+ if (!e)
1031
+ return JSON.stringify(e);
1032
+ if (n === "matrixTable" && e.matrix) return _(Hr(e.matrix.spec));
1033
+ const { matrix: r, ...o } = e, i = t ? Uo(o) : o;
1034
+ return JSON.stringify({
1035
+ ...i,
1036
+ filters: ge(i.filters)
1037
+ });
1038
+ }
1039
+ function $o(e) {
1040
+ if (!e)
1041
+ return null;
1042
+ const { format: t, ...n } = e;
1043
+ return n;
1044
+ }
1045
+ function Wo(e, t) {
1046
+ const n = /* @__PURE__ */ new Map();
1047
+ for (const o of (t == null ? void 0 : t.controlDefinitions) || [])
1048
+ n.set(o.id, o.type);
1049
+ for (const o of (t == null ? void 0 : t.cardControlDefinitions) || [])
1050
+ n.set(o.id, o.type);
1051
+ const r = Object.fromEntries(
1052
+ Object.entries(e || {}).map(([o, i]) => n.get(o) === "multi_enum" && Array.isArray(i) ? [
1053
+ o,
1054
+ [...i].sort(
1055
+ (a, s) => _(a).localeCompare(_(s))
1056
+ )
1057
+ ] : [o, i])
1058
+ );
1059
+ return _(r);
1060
+ }
1061
+ function Zo(e, {
1062
+ finalFiltersKey: t,
1063
+ cardFilterValues: n,
1064
+ controlValues: r,
1065
+ controlDefinitions: o,
1066
+ cardControlDefinitions: i,
1067
+ controlBindings: a,
1068
+ queryRelevantConfig: s,
1069
+ resolvedPrimaryDateField: l,
1070
+ globalDateComparison: c,
1071
+ calendarContext: d
1072
+ }) {
1073
+ const { filterColumns: u, ...f } = e.queryConfig || {}, m = u == null ? void 0 : u.filter(
1074
+ (h) => {
1075
+ var D, g;
1076
+ return (g = (D = e.queryConfig) == null ? void 0 : D.filters) == null ? void 0 : g.some((V) => V.filterColumnName === h.name);
1077
+ }
1078
+ ), y = (e == null ? void 0 : e.sql) || "", p = Me((e == null ? void 0 : e.python) || ""), b = ["table", "detailTable", "matrixTable"].includes(
1079
+ e.type
1080
+ ) ? "table" : e.type === "kpi" ? "kpi" : "chart", I = s || Et(e.config, { cardType: e.type, dataSource: e.dataSource }), C = An.includes(
1081
+ e.type
1082
+ );
1083
+ return [
1084
+ "query",
1085
+ e == null ? void 0 : e.id,
1086
+ b,
1087
+ y,
1088
+ p,
1089
+ JSON.stringify(n),
1090
+ Wo(r, {
1091
+ controlDefinitions: o,
1092
+ cardControlDefinitions: i
1093
+ }),
1094
+ Lo({
1095
+ controlDefinitions: o,
1096
+ cardControlDefinitions: i,
1097
+ controlBindings: a
1098
+ }),
1099
+ _(
1100
+ $o(l)
1101
+ ),
1102
+ _(c ?? null),
1103
+ Go,
1104
+ _(d),
1105
+ JSON.stringify(f),
1106
+ JSON.stringify(m),
1107
+ Qo(
1108
+ I,
1109
+ C,
1110
+ e.type
1111
+ ),
1112
+ t
1113
+ ];
1114
+ }
1115
+ function Yo(e, t, n) {
1116
+ var s, l, c;
1117
+ const r = Zo(e, t), o = _(r), i = ((s = n == null ? void 0 : n.resolvePaginationConfig) == null ? void 0 : s.call(n, o)) ?? e.paginationConfig, a = et(e) && ue(e.config) || et(e) && e.sql && ((c = (l = e.preferences) == null ? void 0 : l.tablePrefs) == null ? void 0 : c.enableDevModePagination);
1118
+ return {
1119
+ queryKey: [
1120
+ ...r,
1121
+ a ? JSON.stringify(i) : ""
1122
+ ],
1123
+ queryInputIdentity: o,
1124
+ paginationConfig: i
1125
+ };
1126
+ }
1127
+ function Jo(e, t, n, r) {
1128
+ return Yo(
1129
+ e,
1130
+ {
1131
+ finalFiltersKey: t.finalFiltersKey,
1132
+ cardFilterValues: t.cardFilterValues,
1133
+ controlValues: t.controlValues,
1134
+ controlDefinitions: t.controlDefinitions,
1135
+ cardControlDefinitions: t.cardControlDefinitions,
1136
+ controlBindings: t.controlBindings,
1137
+ queryRelevantConfig: t.queryRelevantConfig,
1138
+ resolvedPrimaryDateField: t.resolvedPrimaryDateField || void 0,
1139
+ globalDateComparison: t.globalDateComparison,
1140
+ calendarContext: n
1141
+ },
1142
+ r
1143
+ );
1144
+ }
1145
+ const Xo = 500, ei = 250;
1146
+ function De(e) {
1147
+ return e.type === "table" || e.type === "detailTable";
1148
+ }
1149
+ function ti(e) {
1150
+ var t, n, r;
1151
+ return !!((t = e.sql) != null && t.trim() && De(e) && ((r = (n = e.preferences) == null ? void 0 : n.tablePrefs) != null && r.enableDevModePagination));
1152
+ }
1153
+ function Ya(e) {
1154
+ return e === "export-full-with-cap" ? Xo : ei;
1155
+ }
1156
+ function ni({
1157
+ card: e,
1158
+ isTablePrintMode: t,
1159
+ isDocumentSectionRuntime: n,
1160
+ documentTableDataPolicy: r
1161
+ }) {
1162
+ var l, c;
1163
+ const o = n && r !== void 0 && De(e), i = t && !o, a = ue(e.config) && De(e) && !e.sql, s = o ? ti(e) : !!(e.sql && ((c = (l = e.preferences) == null ? void 0 : l.tablePrefs) != null && c.enableDevModePagination));
1164
+ return !i && (a || s);
1165
+ }
1166
+ function ri(e) {
1167
+ var t, n, r;
1168
+ return ((t = e.paginationConfig) == null ? void 0 : t.pageSize) || ((r = (n = e.preferences) == null ? void 0 : n.tablePrefs) == null ? void 0 : r.pageSize) || 50;
1169
+ }
1170
+ function Ja({
1171
+ current: e,
1172
+ defaultPageSize: t,
1173
+ queryInputIdentity: n
1174
+ }) {
1175
+ return (e == null ? void 0 : e.queryInputIdentity) === n ? {
1176
+ page: e.page,
1177
+ pageSize: e.pageSize
1178
+ } : {
1179
+ page: 1,
1180
+ pageSize: (e == null ? void 0 : e.pageSize) ?? t
1181
+ };
1182
+ }
1183
+ function Xa(e, t, n) {
1184
+ return (e == null ? void 0 : e.queryInputIdentity) === n && e.page === t.page && e.pageSize === t.pageSize;
1185
+ }
1186
+ function es(e, t) {
1187
+ return !e || !t || e.page === t.page && e.pageSize === t.pageSize ? e : {
1188
+ ...e,
1189
+ page: t.page,
1190
+ pageSize: t.pageSize,
1191
+ hasPrevPage: t.page > 1
1192
+ };
1193
+ }
1194
+ function oi(e) {
1195
+ return { page: 1, pageSize: ri(e) };
1196
+ }
1197
+ function ii(e) {
1198
+ var a, s, l, c, d;
1199
+ const { card: t } = e, n = ni({
1200
+ card: t,
1201
+ isTablePrintMode: ((a = e.display) == null ? void 0 : a.isTablePrintMode) ?? !1,
1202
+ isDocumentSectionRuntime: !!e.documentSection,
1203
+ documentTableDataPolicy: (s = e.documentSection) == null ? void 0 : s.documentTableDataPolicy
1204
+ }), { page: r } = e, o = e.documentSection && !e.documentSection.totalsRow ? void 0 : Bn(t, e.finalConfig), i = !!((l = e.display) != null && l.deliveryStrict && e.display.isTablePrintMode && !e.documentSection && $r(t.type));
1205
+ return {
1206
+ ...o ? { tableTotalsRequest: o } : {},
1207
+ ...i ? { sourceRowProbe: { limit: Wr.maxTableRows } } : {},
1208
+ ...n ? {
1209
+ pagination: {
1210
+ page: (r == null ? void 0 : r.page) || 1,
1211
+ pageSize: (r == null ? void 0 : r.pageSize) || ((d = (c = t.preferences) == null ? void 0 : c.tablePrefs) == null ? void 0 : d.pageSize) || 50
1212
+ }
1213
+ } : {}
1214
+ };
1215
+ }
1216
+ function ai(e, t = {}) {
1217
+ var o, i, a;
1218
+ const n = ((o = e.connectionId) == null ? void 0 : o.trim()) || void 0;
1219
+ if (t.editorDevMode) return n;
1220
+ const r = ((a = (i = e.dataSource) == null ? void 0 : i.connectionId) == null ? void 0 : a.trim()) || void 0;
1221
+ return e.sql ? n || r : r || n;
1222
+ }
1223
+ function si(e, t) {
1224
+ var n;
1225
+ return {
1226
+ connectionId: t,
1227
+ connectionType: ((n = e.dataSource) == null ? void 0 : n.connectionType) || "unknown",
1228
+ mode: "database",
1229
+ selectedEntities: []
1230
+ };
1231
+ }
1232
+ function ts(e, t, n = {}) {
1233
+ const r = ai(e, n);
1234
+ if (!r)
1235
+ throw new Error("No connection ID found for card");
1236
+ const o = t.cardDataSource || e.dataSource;
1237
+ return {
1238
+ connectionId: r,
1239
+ requestPayloadBase: {
1240
+ ...t,
1241
+ cardDataSource: n.liveDataSource ? o : o || si(e, r)
1242
+ }
1243
+ };
1244
+ }
1245
+ const li = /* @__PURE__ */ new Set([
1246
+ "day",
1247
+ "week",
1248
+ "month",
1249
+ "quarter",
1250
+ "year",
1251
+ "hour",
1252
+ "minute",
1253
+ "second"
1254
+ ]);
1255
+ function ci(e) {
1256
+ let t = e.spec;
1257
+ const n = ut(
1258
+ e.controlDefinitions || [],
1259
+ e.cardControlDefinitions || []
1260
+ ), r = (e.controlBindings || []).filter(
1261
+ (p) => p.target !== "sql_param"
1262
+ ), o = r.filter(
1263
+ (p) => p.target === "config_metric_selector" || p.target === "config_field_selector"
1264
+ ), i = r.filter(
1265
+ (p) => p.target === "config_grain" || p.target === "config_aggregation"
1266
+ ), a = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Map();
1267
+ let l;
1268
+ const c = () => {
1269
+ if (l) return l;
1270
+ const p = e.catalog, b = /* @__PURE__ */ new Map();
1271
+ for (const I of p) {
1272
+ const C = b.get(I.id) ?? [];
1273
+ b.set(I.id, [...C, I]);
1274
+ }
1275
+ return l = { refs: p, byId: b }, l;
1276
+ }, d = (p, b) => {
1277
+ throw new zn(p, {
1278
+ code: Ln,
1279
+ ...b ? { controlId: b } : {}
1280
+ });
1281
+ }, u = (p, b) => {
1282
+ var C;
1283
+ if (p.derivedField) return p.derivedField.dataType;
1284
+ const I = c().refs.filter((h) => h.field.name === p.name && Ce(h.field.source ?? e.spec.source, p.source ?? e.spec.source));
1285
+ return I.length > 1 ? d("The selected field is ambiguous in the authorized Matrix field catalog.", b) : W(((C = I[0]) == null ? void 0 : C.field.dataType) ?? p.dataType);
1286
+ }, f = (p, b) => En(p, b.target, (I) => u(I, b.controlId)), m = Tr.safeParse(t);
1287
+ if (!m.success) return d(m.error.message);
1288
+ t = m.data;
1289
+ const y = [...o, ...i].map((p) => {
1290
+ const b = ft({ binding: p, definitions: n, controlValues: e.controlValues }), I = !p.matrixTargetId && b !== void 0 && b !== he ? f(m.data, p) : [];
1291
+ return {
1292
+ binding: p,
1293
+ selectedValue: b,
1294
+ targetId: p.matrixTargetId ?? (I.length === 1 ? I[0].id : void 0)
1295
+ };
1296
+ });
1297
+ for (const { binding: p, targetId: b, selectedValue: I } of y) {
1298
+ if (I === void 0 || I === he)
1299
+ continue;
1300
+ const C = (v) => d(v, p.controlId), h = p.target === "config_metric_selector" || p.target === "config_aggregation", D = f(t, p);
1301
+ (!b || !D.some((v) => v.id === b)) && C("Choose a valid Matrix level or measure target for this control.");
1302
+ const g = `${p.target}:${b}`;
1303
+ a.has(g) && C("Multiple controls cannot replace the same Matrix target."), a.add(g);
1304
+ const V = (v) => {
1305
+ const S = (c().byId.get(v.id) ?? []).filter((k) => !v.source || Ce(v.source, k.field.source ?? e.spec.source));
1306
+ if (S.length !== 1) return C(S.length ? "The selected field is ambiguous in the authorized Matrix field catalog." : "The selected field is not in the authorized Matrix field catalog.");
1307
+ const M = Mr.safeParse(S[0].field);
1308
+ return M.success ? M.data : C(M.error.message);
1309
+ }, P = p.target === "config_metric_selector" || p.target === "config_field_selector" ? p.mapping[I] : void 0, x = P && typeof P == "object" && "kind" in P && P.kind === "matrix_instance" ? P.id : void 0;
1310
+ if (h) {
1311
+ s.set(b, p.controlId);
1312
+ const v = x === void 0 ? void 0 : m.data.measures.find(
1313
+ (F) => F.id === x && F.kind === "aggregate"
1314
+ );
1315
+ x !== void 0 && !v && C("The selected Matrix aggregate measure is no longer available.");
1316
+ const S = p.target === "config_metric_selector" && !v ? Rn({ binding: p, selectedValue: I }) : void 0, M = ((v == null ? void 0 : v.kind) === "aggregate" ? v.aggregate : S == null ? void 0 : S.aggregate) ?? (p.target === "config_aggregation" ? Le({ binding: p, selectedValue: I }) : void 0), k = M === void 0 ? void 0 : Vr.safeParse(M);
1317
+ k && !k.success && C("This aggregation is not supported by Matrix."), t = {
1318
+ ...t,
1319
+ measures: t.measures.map(
1320
+ (F) => F.id !== b || F.kind !== "aggregate" ? F : {
1321
+ ...F,
1322
+ ...S ? { field: V(S) } : {},
1323
+ ...(v == null ? void 0 : v.kind) === "aggregate" ? { field: v.field } : {},
1324
+ aggregate: k != null && k.success ? k.data : F.aggregate
1325
+ }
1326
+ )
1327
+ };
1328
+ } else {
1329
+ const v = x === void 0 ? void 0 : [...m.data.rows, ...m.data.columns].find(
1330
+ (F) => F.id === x
1331
+ );
1332
+ x !== void 0 && !v && C("The selected Matrix level is no longer available.");
1333
+ const S = p.target === "config_field_selector" && !v ? qn({ binding: p, selectedValue: I }) : void 0, M = p.target === "config_grain" ? Le({ binding: p, selectedValue: I }) : v ? v.grain : S == null ? void 0 : S.granularity;
1334
+ M !== void 0 && !li.has(M) && C("This time grain is not supported by Matrix.");
1335
+ const k = (F) => F.map((T) => {
1336
+ if (T.id !== b) return T;
1337
+ const w = (v == null ? void 0 : v.field) ?? (S ? V(S) : T.field), E = u(w, p.controlId), R = M ?? (S && ne(E) ? T.grain : void 0);
1338
+ return R && !ne(E) && C("A time grain requires a temporal Matrix level."), { ...T, field: w, grain: R };
1339
+ });
1340
+ t = {
1341
+ ...t,
1342
+ rows: k(t.rows),
1343
+ columns: k(t.columns)
1344
+ };
1345
+ }
1346
+ }
1347
+ for (const [p, b] of Array.from(s)) {
1348
+ const I = t.measures.find((h) => h.id === p);
1349
+ if (!I || I.kind !== "aggregate") continue;
1350
+ const C = u(I.field, b);
1351
+ Nn(C).some((h) => h.value === I.aggregate) || d(`Aggregation '${I.aggregate}' is not eligible for this Matrix field datatype.`, b);
1352
+ }
1353
+ try {
1354
+ return jn(m.data, t);
1355
+ } catch (p) {
1356
+ if (p instanceof _r) return d(p.message);
1357
+ throw p;
1358
+ }
1359
+ }
1360
+ function Ht(e, t) {
1361
+ const n = [], r = (o) => {
1362
+ if (o.source) {
1363
+ const i = kr.safeParse(o.source);
1364
+ if (i.success) n.push(i.data);
1365
+ else if (t) throw i.error;
1366
+ }
1367
+ o.derivedField && Object.values(o.derivedField.inputs).forEach((i) => r(i.field));
1368
+ };
1369
+ for (const o of e) {
1370
+ if (o.target !== "config_field_selector" && o.target !== "config_metric_selector") continue;
1371
+ const i = t == null ? void 0 : t.get(o), a = t ? i && i !== he ? [o.mapping[i]] : [] : Object.values(o.mapping);
1372
+ for (const s of a)
1373
+ s && "role" in s && r(s);
1374
+ }
1375
+ return n;
1376
+ }
1377
+ function di(e, t = [], n = []) {
1378
+ return vt([...pt(e), ...Ht(t), ...n]);
1379
+ }
1380
+ function ui(e, t = {}) {
1381
+ const n = t.controlBindings ?? [], r = ut(t.controlDefinitions ?? [], t.cardControlDefinitions ?? []), o = new Map(n.filter((i) => i.target === "config_field_selector" || i.target === "config_metric_selector").map((i) => [i, ft({ binding: i, definitions: r, controlValues: t.controlValues })]));
1382
+ return vt([...pt(e), ...Ht(n, o)]);
1383
+ }
1384
+ function fi(e, t) {
1385
+ return Te(e) ? pi(e, t) : e.config ?? {};
1386
+ }
1387
+ function pi(e, t) {
1388
+ var r;
1389
+ const n = (r = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : r.toField;
1390
+ return n ? Do(e.config ?? {}, n, {
1391
+ sortPolicy: "retargetDimensionSort"
1392
+ }) : e.config ?? {};
1393
+ }
1394
+ function mi(e, t) {
1395
+ const n = (e == null ? void 0 : e.steps) ?? [];
1396
+ if (n.length !== 0)
1397
+ return {
1398
+ id: `${t}-drill-root`,
1399
+ logicalOperator: "AND",
1400
+ negate: !1,
1401
+ conditions: [],
1402
+ groups: n.map((r, o) => ({
1403
+ id: `breadcrumb-${o}`,
1404
+ logicalOperator: "OR",
1405
+ negate: !1,
1406
+ conditions: [],
1407
+ groups: [
1408
+ {
1409
+ id: `breadcrumb-${o}-group-0`,
1410
+ logicalOperator: "AND",
1411
+ negate: !1,
1412
+ conditions: r.conditions.map(
1413
+ (i) => Zr(
1414
+ i,
1415
+ `${i.field.id}-${i.value}`
1416
+ )
1417
+ ),
1418
+ groups: []
1419
+ }
1420
+ ]
1421
+ }))
1422
+ };
1423
+ }
1424
+ const ye = (e) => typeof e == "object" && e !== null && !Array.isArray(e);
1425
+ function H(e) {
1426
+ return e instanceof Date ? JSON.stringify(Number.isNaN(e.getTime()) ? null : e.toISOString()) : Array.isArray(e) ? `[${e.map(H).join(",")}]` : ye(e) ? `{${Object.keys(e).sort().filter((t) => e[t] !== void 0).map((t) => `${JSON.stringify(t)}:${H(e[t])}`).join(",")}}` : JSON.stringify(e) ?? "null";
1427
+ }
1428
+ function gi(e) {
1429
+ const t = e;
1430
+ return t.valueType === "date" || t.relativeMeta !== void 0 || t.temporalBucket !== void 0 || ne(t.dataType);
1431
+ }
1432
+ function yi(e) {
1433
+ const t = ye(e.field) ? e.field : void 0;
1434
+ return e.temporalBucket !== void 0 || e.rawTemporal !== void 0 || e.relativeMeta !== void 0 || ne(t == null ? void 0 : t.dataType);
1435
+ }
1436
+ function Ut(e) {
1437
+ return e ? [...(e.conditions ?? []).filter(yi).map((n) => {
1438
+ const r = ye(n.field) ? n.field : {};
1439
+ return {
1440
+ field: r.qualifiedFieldName ?? r.name,
1441
+ operator: n.operator,
1442
+ value: n.value,
1443
+ temporalBucket: n.temporalBucket,
1444
+ rawTemporal: n.rawTemporal,
1445
+ relativeMeta: n.relativeMeta
1446
+ };
1447
+ }), ...(e.groups ?? []).flatMap((n) => Ut(n))] : [];
1448
+ }
1449
+ function tt(e) {
1450
+ const t = e.filterValues.filter(gi).map((r) => {
1451
+ const o = r, i = ye(o.fieldMeta) ? o.fieldMeta : void 0;
1452
+ return {
1453
+ field: (i == null ? void 0 : i.qualifiedFieldName) ?? o.name,
1454
+ operation: o.operation,
1455
+ ...o.relativeMeta !== void 0 ? { relativeMeta: o.relativeMeta } : { values: o.values },
1456
+ temporalBucket: o.temporalBucket
1457
+ };
1458
+ }), n = Ut(e.selectionFilters);
1459
+ return H({
1460
+ values: t.map(H).sort(),
1461
+ conditions: n.map(H).sort(),
1462
+ ...e.zoom ? { zoom: [e.zoom.from, e.zoom.to] } : {}
1463
+ });
1464
+ }
1465
+ function bi(e, t, n) {
1466
+ if (!t || n.drillActive || t.madeUnder !== n.currentFingerprint) return e;
1467
+ const r = e.groupByColumns ?? [];
1468
+ return r.some((o) => o.id === t.fieldId && o.grainMode === "automatic") ? {
1469
+ ...e,
1470
+ groupByColumns: r.map((o) => {
1471
+ if (o.id !== t.fieldId || o.grainMode !== "automatic") return o;
1472
+ const { grainMode: i, ...a } = o;
1473
+ return { ...a, granularity: t.granularity };
1474
+ })
1475
+ } : e;
1476
+ }
1477
+ function ns(e) {
1478
+ var t;
1479
+ return (((t = e.config) == null ? void 0 : t.groupByColumns) ?? []).find(
1480
+ (n) => n.grainMode === "automatic" && Kn({ cardType: e.type, configBacked: !0, shelf: "groupBy", dataType: n.dataType }).ok
1481
+ );
1482
+ }
1483
+ function Ii(e, t) {
1484
+ if (!e || !t || t.id !== e.fieldId || xr(t)) return;
1485
+ const {
1486
+ granularity: n,
1487
+ grainMode: r,
1488
+ dateFormat: o,
1489
+ timeDrillPath: i,
1490
+ ...a
1491
+ } = t;
1492
+ return {
1493
+ id: `zoom:${e.fieldId}`,
1494
+ logicalOperator: "AND",
1495
+ negate: !1,
1496
+ conditions: [
1497
+ {
1498
+ id: `zoom:${e.fieldId}:range`,
1499
+ field: a,
1500
+ operator: "between",
1501
+ value: [e.from, e.to],
1502
+ viewerZoom: !0
1503
+ }
1504
+ ],
1505
+ groups: []
1506
+ };
1507
+ }
1508
+ function rs(e, t, n) {
1509
+ const r = Ge(e, n), o = Ge(t, n);
1510
+ if (!r || !o) return;
1511
+ const [i, a] = r.first <= o.first ? [r, o] : [o, r];
1512
+ return { from: i.first, to: a.last };
1513
+ }
1514
+ function Ci(e, t, n) {
1515
+ if (!e || e.madeUnder !== n) return;
1516
+ const r = t == null ? void 0 : t.find((i) => i.id === e.fieldId && i.grainMode === "automatic"), o = Ii(e, r);
1517
+ return o ? { zoom: e, filterGroup: o } : void 0;
1518
+ }
1519
+ function os(e, t, n) {
1520
+ if (!e) return;
1521
+ const [r, o] = t <= n ? [t, n] : [n, t];
1522
+ if (r < 0 || o >= e.length) return;
1523
+ const i = e.slice(r, o + 1);
1524
+ if (!i.every((d) => typeof d == "string" && d !== "")) return;
1525
+ const a = [...i].sort(), s = a[0], l = a[a.length - 1];
1526
+ return e.some(
1527
+ (d, u) => (u < r || u > o) && typeof d == "string" && d > s && d < l
1528
+ ) ? void 0 : { first: s, last: l };
1529
+ }
1530
+ function is(e, t, n) {
1531
+ if (!t || !n) return { from: e.from, to: e.to };
1532
+ const r = Qe(new Date(t.startInclusive), n), o = Qe(new Date(Date.parse(t.endExclusive) - 1), n), i = e.from < r ? r : e.from, a = e.to > o ? o : e.to;
1533
+ return i <= a ? { from: i, to: a } : { from: e.from, to: e.to };
1534
+ }
1535
+ function as(e, t, n) {
1536
+ const r = (i) => /* @__PURE__ */ new Date(`${i}T00:00:00.000Z`), o = new Intl.DateTimeFormat(t, { dateStyle: n, timeZone: "UTC" });
1537
+ return e.from === e.to ? o.format(r(e.from)) : o.formatRange(r(e.from), r(e.to));
1538
+ }
1539
+ function Ee(e) {
1540
+ return e === "in" || e === "not in";
1541
+ }
1542
+ function Re(e) {
1543
+ return e === "not in" ? "exclude" : "include";
1544
+ }
1545
+ function hi(e) {
1546
+ return e === "exclude" ? "not in" : "in";
1547
+ }
1548
+ function ss(e) {
1549
+ var n;
1550
+ const t = (n = e.liveValue) == null ? void 0 : n.operation;
1551
+ return Ee(t) ? Re(t) : e.pendingMode ?? e.authoredMode;
1552
+ }
1553
+ function vi(e) {
1554
+ var r;
1555
+ let t = !1;
1556
+ const n = (r = e.inputs) == null ? void 0 : r.map((o) => {
1557
+ if (o.kind !== "filter" || !o.filter) return o;
1558
+ const i = Fi(
1559
+ o.filter,
1560
+ new Set(Di(e.defaultInputValues, o))
1561
+ );
1562
+ return i === o.filter ? o : (t = !0, { ...o, filter: i });
1563
+ });
1564
+ return t ? { ...e, inputs: n } : e;
1565
+ }
1566
+ function Fi(e, t) {
1567
+ if (t.size !== 1 || !Ee(e.operation))
1568
+ return e;
1569
+ const [n] = t;
1570
+ return Re(e.operation) === n ? e : { ...e, operation: hi(n) };
1571
+ }
1572
+ function Di(e, t) {
1573
+ var o;
1574
+ const n = (i) => Object.values(i ?? {}).map((a) => a[t.id]);
1575
+ return (t.runtimeScope === "shared" ? [(o = e == null ? void 0 : e.shared) == null ? void 0 : o[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(
1576
+ (i) => (i == null ? void 0 : i.status) === "set" && i.value.kind === "filter" ? Si(i.value.filterValue) : []
1577
+ );
1578
+ }
1579
+ function Si(e) {
1580
+ return Ee(e.operation) ? [Re(e.operation)] : [];
1581
+ }
1582
+ function ls(e) {
1583
+ const t = St(e), r = A(t).issues.length ? t : Sa(t);
1584
+ return vo(vi(r)).dashboard;
1585
+ }
1586
+ function qe(e, t) {
1587
+ const n = {};
1588
+ for (const r of Vt(e)) {
1589
+ if (!r.inlineFilters || r.inlineFilters.length === 0)
1590
+ continue;
1591
+ const o = [];
1592
+ for (const i of r.inlineFilters) {
1593
+ const a = Gn(i, t);
1594
+ a && o.push(a);
1595
+ }
1596
+ o.length > 0 && (n[r.id] = o);
1597
+ }
1598
+ return n;
1599
+ }
1600
+ function $(e) {
1601
+ const t = fe(e ?? {}), n = [];
1602
+ for (const [r, o] of Object.entries(t.shared ?? {}))
1603
+ n.push({ scope: "shared", target: null, inputId: r, slot: o });
1604
+ for (const r of ["bySheetId", "byCardId"])
1605
+ for (const [o, i] of Object.entries(t[r] ?? {}))
1606
+ for (const [a, s] of Object.entries(i))
1607
+ n.push({ scope: r, target: o, inputId: a, slot: s });
1608
+ return n;
1609
+ }
1610
+ function le(e, t, n) {
1611
+ const r = e;
1612
+ if (t.scope === "shared") {
1613
+ r.shared = { ...r.shared, [t.inputId]: n };
1614
+ return;
1615
+ }
1616
+ const o = { ...r[t.scope] ?? {} };
1617
+ o[t.target] = { ...o[t.target], [t.inputId]: n }, r[t.scope] = o;
1618
+ }
1619
+ function Qt(e, t, n) {
1620
+ const r = mt(
1621
+ e,
1622
+ t.controlOverrides,
1623
+ { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
1624
+ );
1625
+ return {
1626
+ adHocFilterValues: [...t.adHocFilterValues],
1627
+ controlValues: r.dashboardControlValues,
1628
+ cardControlValuesMap: r.cardControlValuesMap,
1629
+ dashboardInputValues: t.dashboardInputValues,
1630
+ inlineFilterValuesMap: t.inlineFilterValuesMap ?? qe(e, n)
1631
+ };
1632
+ }
1633
+ function Ne(e, t, n) {
1634
+ return $t(
1635
+ e,
1636
+ Qt(e, t, n),
1637
+ n
1638
+ );
1639
+ }
1640
+ function cs(e, t, n) {
1641
+ return $t(e, t, n);
1642
+ }
1643
+ function $t(e, t, n) {
1644
+ const r = e.sheets ?? [], o = r.filter((s) => (s.kind ?? "dashboard") === "dashboard").map((s) => s.id), i = r.filter((s) => s.kind === "document"), a = o.length ? Un({
1645
+ dashboard: e,
1646
+ sheetIds: o,
1647
+ mode: "dashboard",
1648
+ runtimeValues: t,
1649
+ transientContexts: void 0,
1650
+ calendar: n ?? null
1651
+ }).snapshot.dashboardInputValues : {};
1652
+ return i.reduce(
1653
+ (s, l) => {
1654
+ var c;
1655
+ return xe(
1656
+ s,
1657
+ Qn({
1658
+ dashboard: e,
1659
+ sheetId: l.id,
1660
+ sheetKind: "document",
1661
+ mode: "document",
1662
+ sectionIds: (((c = l.document) == null ? void 0 : c.sections) ?? []).map(
1663
+ (d) => d.id
1664
+ ),
1665
+ runtimeValues: t,
1666
+ transientContexts: void 0,
1667
+ calendar: n ?? null
1668
+ }).snapshot.dashboardInputValues
1669
+ );
1670
+ },
1671
+ a
1672
+ );
1673
+ }
1674
+ function Wt(e, t) {
1675
+ const n = {}, r = {}, o = /* @__PURE__ */ new Map();
1676
+ for (const i of $(t)) {
1677
+ const a = e.get(i.inputId), { slot: s } = i, l = () => s.status === "set" && s.value.kind === "filter" ? s.value.filterValue : s.status === "cleared" ? null : void 0;
1678
+ if ((a == null ? void 0 : a.source) === "cardInlineFilter") {
1679
+ const c = l();
1680
+ if (c !== void 0) {
1681
+ const d = o.get(a.cardId) ?? /* @__PURE__ */ new Map();
1682
+ d.set(a.filterId, c), o.set(a.cardId, d);
1683
+ }
1684
+ } else if ((a == null ? void 0 : a.source) === "dashboardControl" || (a == null ? void 0 : a.source) === "cardControl")
1685
+ s.status === "set" && s.value.kind === "control" ? r[a.controlId] = s.value.value : s.status === "cleared" && (r[a.controlId] = void 0);
1686
+ else {
1687
+ le(n, i, s);
1688
+ continue;
1689
+ }
1690
+ s.comparisonSelection && le(n, i, {
1691
+ comparisonSelection: s.comparisonSelection
1692
+ });
1693
+ }
1694
+ return {
1695
+ runtime: fe(n),
1696
+ controlValues: r,
1697
+ inlineFilterValues: o
1698
+ };
1699
+ }
1700
+ function Ti(e, t) {
1701
+ if (!t.size) return [...e];
1702
+ const n = e.filter((o) => !t.has(o.filterId)), r = [...t.values()].filter(
1703
+ (o) => o !== null
1704
+ );
1705
+ return $n(n, r);
1706
+ }
1707
+ function Zt(e, t, n) {
1708
+ if (!Object.keys(n).length) return t;
1709
+ const r = mt(
1710
+ e,
1711
+ t,
1712
+ { hasExplicitRuntimeOverrides: t !== void 0 }
1713
+ );
1714
+ return {
1715
+ ...Hn({
1716
+ dashboardValues: r.dashboardControlValues,
1717
+ cardValuesMap: r.cardControlValuesMap
1718
+ }),
1719
+ ...n
1720
+ };
1721
+ }
1722
+ function Vi(e, t) {
1723
+ if (!t.size) return;
1724
+ const n = Object.fromEntries(
1725
+ Object.entries(e).map(([r, o]) => [r, [...o]])
1726
+ );
1727
+ for (const [r, o] of t)
1728
+ n[r] = Ti(n[r] ?? [], o);
1729
+ return n;
1730
+ }
1731
+ function Mi(e, t, n) {
1732
+ const r = new Map(
1733
+ j(e).map(({ card: a }) => [
1734
+ a.id,
1735
+ new Map((a.inlineFilters ?? []).map((s) => [s.id, s]))
1736
+ ])
1737
+ );
1738
+ let o = !1;
1739
+ const i = Object.fromEntries(
1740
+ Object.entries(t).map(([a, s]) => [a, [...s]])
1741
+ );
1742
+ for (const [a, s] of Object.entries(n)) {
1743
+ const l = r.get(a), c = (s ?? []).filter((d) => {
1744
+ const u = l == null ? void 0 : l.get(d.filterId);
1745
+ return u ? ke(u, d) : !1;
1746
+ });
1747
+ pe(c, i[a] ?? []) || (o = !0), i[a] = c;
1748
+ }
1749
+ return o ? i : void 0;
1750
+ }
1751
+ function ds(e) {
1752
+ const { dashboard: t, capture: n, calendar: r } = e, o = Cn(t, n.filterValues, {
1753
+ calendar: r
1754
+ }), i = n.dashboardInputExecutionSnapshot, a = n.controlValues, s = {
1755
+ ...Qt(
1756
+ t,
1757
+ {
1758
+ adHocFilterValues: o.adHocFilterValues,
1759
+ controlOverrides: a,
1760
+ // The snapshot replays exactly over the listed values.
1761
+ dashboardInputValues: i ? xe(
1762
+ o.slots,
1763
+ Zn({
1764
+ dashboard: t,
1765
+ dashboardInputValues: i.dashboardInputValues,
1766
+ sheetId: i.sheetId,
1767
+ cardId: i.cardId
1768
+ })
1769
+ ) : o.slots
1770
+ },
1771
+ r
1772
+ ),
1773
+ cardViewState: i ? Wn(i.cardViewState) : {}
1774
+ }, l = i ? Yn(i.transientContexts) : void 0;
1775
+ return {
1776
+ runtimeValues: s,
1777
+ controlOverrides: a,
1778
+ ...l != null && l.length ? { transientContexts: l } : {}
1779
+ };
1780
+ }
1781
+ function us(e, t) {
1782
+ const { controlContractOverrides: n, cardId: r } = t;
1783
+ if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof r != "string" || r.trim().length === 0))
1784
+ return e;
1785
+ const o = Z(e, r);
1786
+ return o && (n.cardControlDefinitions !== void 0 && (o.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (o.controlBindings = n.controlBindings)), e;
1787
+ }
1788
+ const ki = ["bySheetId", "byCardId", "byDocumentSectionId"];
1789
+ function xi(e, t) {
1790
+ const n = A(e);
1791
+ let r = !1;
1792
+ const o = (a) => {
1793
+ if (!a) return a;
1794
+ const s = Object.entries(a).filter(([l, c]) => {
1795
+ var u;
1796
+ if (c.status !== "set" || c.value.kind !== "filter") return !0;
1797
+ const d = (u = n.findFilterInput({ inputId: l })) == null ? void 0 : u.input.filter;
1798
+ return !d || ke(d, c.value.filterValue) ? !0 : (r = !0, !1);
1799
+ });
1800
+ return Object.fromEntries(s);
1801
+ }, i = {
1802
+ ...t,
1803
+ ...t.shared ? { shared: o(t.shared) } : {}
1804
+ };
1805
+ for (const a of ki) {
1806
+ const s = t[a];
1807
+ s && (i[a] = Object.fromEntries(
1808
+ Object.entries(s).map(([l, c]) => [l, o(c) ?? {}])
1809
+ ));
1810
+ }
1811
+ return r ? i : t;
1812
+ }
1813
+ function Pi(e) {
1814
+ var t, n;
1815
+ return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
1816
+ }
1817
+ function Y(e, t) {
1818
+ var n;
1819
+ return !!t && !!((n = e.sheets) != null && n.some((r) => r.id === t));
1820
+ }
1821
+ function fs(e) {
1822
+ const { dashboard: t, host: n, calendar: r } = e, o = Cn(t, n.filterValues, {
1823
+ calendar: r
1824
+ }).slots, i = n.controlValues, a = Y(t, n.selectedSheetId) ? n.selectedSheetId : Pi(t);
1825
+ return {
1826
+ hostInputValues: o,
1827
+ controlOverrides: i,
1828
+ selectedSheetId: a,
1829
+ hostSelectedSheetId: n.selectedSheetId ?? null,
1830
+ materializedInputs: e.materializeInputs === !1 ? {} : Ne(
1831
+ t,
1832
+ {
1833
+ adHocFilterValues: [],
1834
+ controlOverrides: i,
1835
+ dashboardInputValues: o
1836
+ },
1837
+ r
1838
+ )
1839
+ };
1840
+ }
1841
+ function Yt(e) {
1842
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Map();
1843
+ for (const o of Pe(e))
1844
+ o.kind === "filter" && o.filter ? t.set(o.id, o.filter) : o.kind === "control" && n.add(o.id), o.compatibility && r.set(o.id, o.compatibility);
1845
+ return { filterInputs: t, controlInputIds: n, compatibility: r };
1846
+ }
1847
+ function Jt(e, t) {
1848
+ const n = Ft(t);
1849
+ if (!n) return;
1850
+ const r = Z(e, n);
1851
+ return r ? Jn(r, e) ? "applies" : "not-eligible" : "removed";
1852
+ }
1853
+ function ps(e, t) {
1854
+ const n = Jt(e, t);
1855
+ return n ? n === "applies" : Pe(e).some(
1856
+ (r) => r.id === t
1857
+ );
1858
+ }
1859
+ function Xt(e, t, n, r) {
1860
+ if (!n) return {};
1861
+ const o = new Set((e.sheets ?? []).map((c) => c.id)), i = new Set(
1862
+ j(e).map(({ card: c }) => c.id)
1863
+ ), a = A(e), s = (c) => {
1864
+ var u;
1865
+ if (!c) return;
1866
+ const d = {};
1867
+ for (const [f, m] of Object.entries(c)) {
1868
+ const y = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((u = a.findFilterInput({ inputId: f })) == null ? void 0 : u.input.id) ?? f;
1869
+ if (y !== f && c[y]) continue;
1870
+ const p = Jt(e, y);
1871
+ if (p) {
1872
+ if (p !== "applies") {
1873
+ r.push({
1874
+ kind: "setting-no-longer-applies",
1875
+ target: "selection",
1876
+ id: y,
1877
+ reason: p
1878
+ });
1879
+ continue;
1880
+ }
1881
+ d[y] = m;
1882
+ continue;
1883
+ }
1884
+ const b = t.filterInputs.get(y);
1885
+ if (!b && !t.controlInputIds.has(y)) {
1886
+ r.push({
1887
+ kind: "setting-no-longer-applies",
1888
+ target: "input",
1889
+ id: y,
1890
+ reason: "removed"
1891
+ });
1892
+ continue;
1893
+ }
1894
+ if (b && m.status === "set" && m.value.kind === "filter" && !ke(b, m.value.filterValue)) {
1895
+ r.push({
1896
+ kind: "setting-no-longer-applies",
1897
+ target: "input",
1898
+ id: y,
1899
+ reason: "incompatible"
1900
+ });
1901
+ continue;
1902
+ }
1903
+ d[y] = m;
1904
+ }
1905
+ return Object.keys(d).length ? d : void 0;
1906
+ }, l = (c, d) => {
1907
+ if (!c) return;
1908
+ const u = {};
1909
+ for (const [f, m] of Object.entries(c)) {
1910
+ if (!d(f)) {
1911
+ for (const p of Object.keys(m))
1912
+ r.push({
1913
+ kind: "setting-no-longer-applies",
1914
+ target: "input",
1915
+ id: p,
1916
+ reason: "removed"
1917
+ });
1918
+ continue;
1919
+ }
1920
+ const y = s(m);
1921
+ y && (u[f] = y);
1922
+ }
1923
+ return u;
1924
+ };
1925
+ return fe({
1926
+ shared: s(n.shared),
1927
+ bySheetId: l(n.bySheetId, (c) => o.has(c)),
1928
+ byCardId: l(n.byCardId, (c) => i.has(c))
1929
+ // Document sections are not viewer state.
1930
+ });
1931
+ }
1932
+ function O(e, t, n, r = {}) {
1933
+ const o = new Map(
1934
+ j(e).map(({ card: a }) => [a.id, a])
1935
+ ), i = {};
1936
+ for (const [a, s] of Object.entries(t ?? {})) {
1937
+ const l = o.get(a);
1938
+ if (l && Nr(l)) {
1939
+ jr(s) || (i[a] = s);
1940
+ continue;
1941
+ }
1942
+ if (l && r.sessionSorts && zr(l)) {
1943
+ s.sort && (i[a] = { sort: s.sort });
1944
+ continue;
1945
+ }
1946
+ n == null || n.push({
1947
+ kind: "setting-no-longer-applies",
1948
+ target: "card",
1949
+ id: a,
1950
+ reason: Z(e, a) ? "not-eligible" : "removed"
1951
+ });
1952
+ }
1953
+ return i;
1954
+ }
1955
+ function wi(e, t, n) {
1956
+ if (t) {
1957
+ if (Y(e, t)) return t;
1958
+ n.push({
1959
+ kind: "setting-no-longer-applies",
1960
+ target: "sheet",
1961
+ id: t,
1962
+ reason: "removed"
1963
+ });
1964
+ }
1965
+ }
1966
+ const je = (e, t) => pe(e ?? null, t ?? null);
1967
+ function en(e) {
1968
+ return {
1969
+ adHocFilterValues: e.adHocFilterValues,
1970
+ controlOverrides: e.controlOverrides,
1971
+ dashboardInputValues: e.dashboardInputValues,
1972
+ ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
1973
+ selectedSheetId: e.selectedSheetId,
1974
+ tableSettings: e.tableSettings
1975
+ };
1976
+ }
1977
+ function X(e, t) {
1978
+ return {
1979
+ adHocFilterValues: [],
1980
+ controlOverrides: e.controlOverrides,
1981
+ dashboardInputValues: e.hostInputValues,
1982
+ selectedSheetId: e.selectedSheetId,
1983
+ tableSettings: t
1984
+ };
1985
+ }
1986
+ function tn(e, t) {
1987
+ const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
1988
+ return {
1989
+ selectedSheetId: t.selectedSheetId,
1990
+ // Overlay: the bookmark's values on the baseline's runtime values.
1991
+ inputs: n ? e.baseline.materializedInputs : Ne(e.dashboard, t, e.calendar),
1992
+ tableSettings: t.tableSettings
1993
+ };
1994
+ }
1995
+ function N(e, t) {
1996
+ const n = en(t), r = t.restore ?? n;
1997
+ return {
1998
+ ...n,
1999
+ appliedBookmarkId: t.appliedBookmarkId,
2000
+ rememberedWrites: t.rememberedWrites ?? [],
2001
+ notices: t.notices ?? [],
2002
+ opened: tn(e, r),
2003
+ restore: r
2004
+ };
2005
+ }
2006
+ function nt(e, t, n, r) {
2007
+ const { dashboard: o, baseline: i } = e, a = [], s = Mt(t.state, _e), l = s.ok ? s.value : {};
2008
+ for (const y of s.ok ? s.issues : [])
2009
+ a.push(Oi(y));
2010
+ const c = Yt(o), d = Wt(
2011
+ c.compatibility,
2012
+ Xt(o, c, l.inputs, a)
2013
+ ), u = wi(o, l.selectedSheetId, a) ?? i.selectedSheetId, f = O(
2014
+ o,
2015
+ l.tableSettings,
2016
+ a
2017
+ ), m = O(
2018
+ o,
2019
+ n,
2020
+ void 0
2021
+ );
2022
+ return N(e, {
2023
+ appliedBookmarkId: t.id,
2024
+ // A bookmark opens without ad-hoc values, as today (P4a-02 f).
2025
+ adHocFilterValues: [],
2026
+ controlOverrides: Zt(
2027
+ o,
2028
+ i.controlOverrides,
2029
+ d.controlValues
2030
+ ),
2031
+ // Overlay, never replacement: the bookmark's slots over the host's.
2032
+ dashboardInputValues: xe(
2033
+ i.hostInputValues,
2034
+ d.runtime
2035
+ ),
2036
+ ...nn(
2037
+ Vi(
2038
+ qe(o, e.calendar),
2039
+ d.inlineFilterValues
2040
+ )
2041
+ ),
2042
+ selectedSheetId: u,
2043
+ tableSettings: r.writeRemembered ? { ...m, ...f } : (
2044
+ // A default bookmark on load: remembered settings per card win.
2045
+ { ...f, ...m }
2046
+ ),
2047
+ rememberedWrites: r.writeRemembered ? Object.entries(f).filter(
2048
+ ([y, p]) => !je(m[y], p)
2049
+ ).map(([y, p]) => ({
2050
+ kind: "set",
2051
+ cardId: y,
2052
+ settings: p
2053
+ })) : [],
2054
+ notices: a
2055
+ });
2056
+ }
2057
+ function Oi(e) {
2058
+ return {
2059
+ kind: "setting-no-longer-applies",
2060
+ target: e.target,
2061
+ id: e.id,
2062
+ reason: "invalid"
2063
+ };
2064
+ }
2065
+ function nn(e) {
2066
+ return e ? { inlineFilterValuesMap: e } : {};
2067
+ }
2068
+ function rt(e, t, n) {
2069
+ const { dashboard: r, baseline: o } = e;
2070
+ return {
2071
+ // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
2072
+ // template now defines a filter with that id.
2073
+ adHocFilterValues: t.adHocFilterValues.filter(
2074
+ (i) => !A(r).findFilterInput({ filterId: i.filterId })
2075
+ ),
2076
+ // A host's new control defaults are the baseline's, not the viewer's.
2077
+ controlOverrides: n.controlsChanged ? o.controlOverrides : t.controlOverrides,
2078
+ // Live slots stay, except a filter value this template no longer accepts:
2079
+ // that filter loads its new default, as the old list did. The resolver
2080
+ // ignores slots this template no longer has.
2081
+ dashboardInputValues: xi(
2082
+ r,
2083
+ t.dashboardInputValues
2084
+ ),
2085
+ ...nn(
2086
+ Mi(
2087
+ r,
2088
+ qe(r, e.calendar),
2089
+ t.inlineFilterValuesMap ?? {}
2090
+ )
2091
+ ),
2092
+ selectedSheetId: !n.sheetChanged && Y(r, t.selectedSheetId) ? t.selectedSheetId : o.selectedSheetId,
2093
+ tableSettings: O(
2094
+ r,
2095
+ t.tableSettings,
2096
+ void 0,
2097
+ { sessionSorts: !0 }
2098
+ )
2099
+ };
2100
+ }
2101
+ function ms(e) {
2102
+ const { dashboard: t, baseline: n, event: r } = e, o = e.rememberedTableSettings;
2103
+ switch (r.kind) {
2104
+ case "initial-load":
2105
+ return r.defaultBookmark ? nt(e, r.defaultBookmark, o, {
2106
+ writeRemembered: !1
2107
+ }) : N(e, {
2108
+ appliedBookmarkId: null,
2109
+ ...X(
2110
+ n,
2111
+ O(t, o, void 0, {
2112
+ sessionSorts: r.captured
2113
+ })
2114
+ )
2115
+ });
2116
+ case "refetch": {
2117
+ const { live: i } = r, a = i.applied, s = {
2118
+ sheetChanged: !!i.previousBaseline && i.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
2119
+ controlsChanged: !!i.previousBaseline && !pe(
2120
+ i.previousBaseline.controlOverrides ?? null,
2121
+ n.controlOverrides ?? null
2122
+ )
2123
+ }, l = rt(
2124
+ e,
2125
+ {
2126
+ adHocFilterValues: i.adHocFilterValues,
2127
+ controlOverrides: i.controlValues ?? n.controlOverrides,
2128
+ dashboardInputValues: i.dashboardInputValues,
2129
+ inlineFilterValuesMap: i.inlineFilterValuesMap,
2130
+ selectedSheetId: i.selectedSheetId,
2131
+ tableSettings: i.tableSettings
2132
+ },
2133
+ s
2134
+ ), c = a ? rt(e, a.restore, s) : X(
2135
+ n,
2136
+ O(t, o, void 0)
2137
+ );
2138
+ return N(e, {
2139
+ appliedBookmarkId: (a == null ? void 0 : a.appliedBookmarkId) ?? null,
2140
+ ...l,
2141
+ notices: (a == null ? void 0 : a.notices) ?? [],
2142
+ restore: c
2143
+ });
2144
+ }
2145
+ case "open-bookmark":
2146
+ return nt(e, r.bookmark, o, {
2147
+ writeRemembered: !0
2148
+ });
2149
+ case "open-default-view":
2150
+ return N(e, {
2151
+ appliedBookmarkId: null,
2152
+ ...X(
2153
+ n,
2154
+ O(t, o, void 0)
2155
+ )
2156
+ });
2157
+ case "reset-to-default-view":
2158
+ return N(e, {
2159
+ appliedBookmarkId: null,
2160
+ ...X(n, {}),
2161
+ rememberedWrites: [{ kind: "clear-all" }]
2162
+ });
2163
+ case "discard-changes": {
2164
+ const { restore: i } = r.applied, a = O(
2165
+ t,
2166
+ i.tableSettings,
2167
+ void 0,
2168
+ { sessionSorts: !0 }
2169
+ ), s = O(t, a, void 0), l = O(t, o, void 0), c = [];
2170
+ for (const d of /* @__PURE__ */ new Set([
2171
+ ...Object.keys(l),
2172
+ ...Object.keys(s)
2173
+ ])) {
2174
+ if (je(l[d], s[d])) continue;
2175
+ const u = s[d];
2176
+ c.push(
2177
+ u ? { kind: "set", cardId: d, settings: u } : { kind: "clear", cardId: d }
2178
+ );
2179
+ }
2180
+ return N(e, {
2181
+ appliedBookmarkId: r.applied.appliedBookmarkId,
2182
+ ...i,
2183
+ selectedSheetId: Y(t, i.selectedSheetId) ? i.selectedSheetId : n.selectedSheetId,
2184
+ tableSettings: a,
2185
+ rememberedWrites: c,
2186
+ notices: r.applied.notices,
2187
+ restore: i
2188
+ });
2189
+ }
2190
+ }
2191
+ }
2192
+ function gs(e) {
2193
+ const { dashboard: t, calendar: n } = e, r = e.hostControlValues, o = {
2194
+ ...e.baseline,
2195
+ controlOverrides: r,
2196
+ materializedInputs: Ne(
2197
+ t,
2198
+ {
2199
+ adHocFilterValues: [],
2200
+ controlOverrides: r,
2201
+ dashboardInputValues: e.baseline.hostInputValues
2202
+ },
2203
+ n
2204
+ )
2205
+ };
2206
+ let i = r;
2207
+ if (e.appliedBookmark) {
2208
+ const l = Mt(
2209
+ e.appliedBookmark.state,
2210
+ _e
2211
+ ), c = Yt(t), d = Wt(
2212
+ c.compatibility,
2213
+ Xt(
2214
+ t,
2215
+ c,
2216
+ l.ok ? l.value.inputs : void 0,
2217
+ []
2218
+ )
2219
+ ).controlValues;
2220
+ i = Zt(t, r, d);
2221
+ }
2222
+ const a = e.applied;
2223
+ if (!a) return { baseline: o, controlOverrides: i, applied: null };
2224
+ const s = { ...a.restore, controlOverrides: i };
2225
+ return {
2226
+ baseline: o,
2227
+ controlOverrides: i,
2228
+ applied: {
2229
+ ...a,
2230
+ controlOverrides: i,
2231
+ restore: s,
2232
+ opened: tn({ dashboard: t, baseline: o, calendar: n }, s)
2233
+ }
2234
+ };
2235
+ }
2236
+ function ys(e, t, n) {
2237
+ const r = en(n.values);
2238
+ return {
2239
+ ...r,
2240
+ appliedBookmarkId: t,
2241
+ rememberedWrites: [],
2242
+ notices: e.notices,
2243
+ opened: n.snapshot,
2244
+ restore: r
2245
+ };
2246
+ }
2247
+ const ot = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
2248
+ function ee(e) {
2249
+ return !e || e.status === "cleared" && !e.comparisonSelection;
2250
+ }
2251
+ function rn(e, t) {
2252
+ const n = new Map(
2253
+ $(e).map((i) => [ot(i), i])
2254
+ ), r = new Map(
2255
+ $(t).map((i) => [ot(i), i])
2256
+ ), o = {};
2257
+ for (const [i, a] of r) {
2258
+ const s = n.get(i);
2259
+ s && pe(s.slot, a.slot) || ee(a.slot) && ee(s == null ? void 0 : s.slot) || le(
2260
+ o,
2261
+ a,
2262
+ ee(a.slot) ? { status: "cleared" } : a.slot
2263
+ );
2264
+ }
2265
+ for (const [i, a] of n)
2266
+ r.has(i) || ee(a.slot) || le(o, a, { status: "cleared" });
2267
+ return fe(o);
2268
+ }
2269
+ function bs(e) {
2270
+ const { dashboard: t, baseline: n, current: r } = e, o = rn(n.materializedInputs, r.inputs), i = O(
2271
+ t,
2272
+ r.tableSettings,
2273
+ void 0
2274
+ ), a = r.selectedSheetId && r.selectedSheetId !== n.selectedSheetId && Y(t, r.selectedSheetId) ? r.selectedSheetId : void 0;
2275
+ return {
2276
+ version: _e,
2277
+ ...a ? { selectedSheetId: a } : {},
2278
+ ...$(o).length ? { inputs: o } : {},
2279
+ ...Object.keys(i).length ? { tableSettings: i } : {}
2280
+ };
2281
+ }
2282
+ function _i(e) {
2283
+ const t = /* @__PURE__ */ new Map();
2284
+ for (const n of Pe(e))
2285
+ n.label && t.set(n.id, n.label);
2286
+ return t;
2287
+ }
2288
+ function Ai(e, t, n) {
2289
+ var o, i;
2290
+ const r = Ft(n);
2291
+ if (r) {
2292
+ const a = (i = (o = Z(e, r)) == null ? void 0 : o.title) == null ? void 0 : i.trim();
2293
+ return a ? `Selection in ${a}` : "Selection";
2294
+ }
2295
+ return t.get(n) ?? n;
2296
+ }
2297
+ function Is(e) {
2298
+ var c, d;
2299
+ const { dashboard: t, opened: n, current: r } = e, o = [], i = _i(t), a = /* @__PURE__ */ new Set();
2300
+ for (const u of $(
2301
+ rn(n.inputs, r.inputs)
2302
+ ))
2303
+ a.has(u.inputId) || (a.add(u.inputId), o.push({
2304
+ target: "input",
2305
+ inputId: u.inputId,
2306
+ label: Ai(t, i, u.inputId)
2307
+ }));
2308
+ (n.selectedSheetId ?? null) !== (r.selectedSheetId ?? null) && o.push({ target: "sheet" });
2309
+ const s = O(
2310
+ t,
2311
+ n.tableSettings,
2312
+ void 0
2313
+ ), l = O(
2314
+ t,
2315
+ r.tableSettings,
2316
+ void 0
2317
+ );
2318
+ for (const u of /* @__PURE__ */ new Set([
2319
+ ...Object.keys(s),
2320
+ ...Object.keys(l)
2321
+ ]))
2322
+ je(s[u], l[u]) || o.push({
2323
+ target: "table",
2324
+ cardId: u,
2325
+ cardTitle: ((d = (c = Z(t, u)) == null ? void 0 : c.title) == null ? void 0 : d.trim()) || "Table"
2326
+ });
2327
+ return o;
2328
+ }
2329
+ function it(e) {
2330
+ const t = U(e.filter);
2331
+ return {
2332
+ inputId: e.inputId,
2333
+ filterId: e.filterId,
2334
+ label: e.label,
2335
+ selection: e.selection,
2336
+ owner: t ? { kind: "global_date" } : {
2337
+ kind: "field_date",
2338
+ filterId: e.filterId,
2339
+ label: e.label
2340
+ }
2341
+ };
2342
+ }
2343
+ function Bi(e) {
2344
+ var o, i;
2345
+ if ((o = e.card.sql) != null && o.trim())
2346
+ return {
2347
+ inputs: e.inputs,
2348
+ fieldCandidates: [],
2349
+ resolution: { status: "none" }
2350
+ };
2351
+ const t = e.inputs.filter((a) => !U(a.filter)).map((a) => ({
2352
+ input: a,
2353
+ resolution: Xn({
2354
+ filter: a.filter,
2355
+ filterValue: a.filterValue,
2356
+ effectiveFilterValue: a.effectiveFilterValue,
2357
+ mappedFilterValue: a.mappedFilterValue,
2358
+ temporalBinding: e.temporalBinding,
2359
+ card: e.card
2360
+ })
2361
+ }));
2362
+ if (!e.temporalBinding)
2363
+ return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
2364
+ const n = e.inputs.find(
2365
+ (a) => U(a.filter)
2366
+ );
2367
+ if (n && ((i = n.filterValue) == null ? void 0 : i.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && er(n.effectiveFilterValue))
2368
+ return {
2369
+ inputs: e.inputs,
2370
+ fieldCandidates: t,
2371
+ resolution: {
2372
+ status: "resolved",
2373
+ resolvedOwner: it(n)
2374
+ }
2375
+ };
2376
+ const r = t.filter(
2377
+ (a) => a.resolution.status === "eligible"
2378
+ );
2379
+ return r.length === 1 ? {
2380
+ inputs: e.inputs,
2381
+ fieldCandidates: t,
2382
+ resolution: {
2383
+ status: "resolved",
2384
+ resolvedOwner: it(r[0].input)
2385
+ }
2386
+ } : r.length > 1 ? {
2387
+ inputs: e.inputs,
2388
+ fieldCandidates: t,
2389
+ resolution: {
2390
+ status: "ambiguous",
2391
+ candidateInputIds: r.map(
2392
+ (a) => a.input.inputId
2393
+ )
2394
+ }
2395
+ } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
2396
+ }
2397
+ function Cs(e) {
2398
+ const t = {
2399
+ ownerCardCount: 0,
2400
+ matchingCardCount: 0,
2401
+ globalPrecedenceCardCount: 0,
2402
+ ambiguousCardCount: 0
2403
+ };
2404
+ for (const n of e.targets) {
2405
+ const r = n.plan.fieldCandidates.find(
2406
+ (i) => i.input.inputId === e.inputId
2407
+ );
2408
+ if (!r || r.resolution.status !== "eligible") continue;
2409
+ t.matchingCardCount += 1;
2410
+ const { resolution: o } = n.plan;
2411
+ o.status === "resolved" && o.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : o.status === "resolved" && o.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : o.status === "ambiguous" && o.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1);
2412
+ }
2413
+ return t;
2414
+ }
2415
+ const Ei = /* @__PURE__ */ new Set([
2416
+ "between",
2417
+ "not between",
2418
+ "=",
2419
+ "!=",
2420
+ ">",
2421
+ ">=",
2422
+ "<",
2423
+ "<=",
2424
+ "is null",
2425
+ "is not null"
2426
+ ]), Ri = /^(\d{4}-\d{2}-\d{2})T/, qi = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
2427
+ function ze(e) {
2428
+ return Ei.has(e);
2429
+ }
2430
+ function Ni(e, t) {
2431
+ if (e instanceof Date)
2432
+ return Number.isNaN(e.getTime()) ? e : t ? He(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
2433
+ if (typeof e != "string")
2434
+ return e;
2435
+ const n = e.trim();
2436
+ if (t && qi.test(n)) {
2437
+ const o = new Date(n);
2438
+ if (!Number.isNaN(o.getTime()))
2439
+ return He(o, t, "yyyy-MM-dd");
2440
+ }
2441
+ const r = Ri.exec(n);
2442
+ return r ? r[1] : e;
2443
+ }
2444
+ function on(e, t) {
2445
+ return Array.isArray(e) ? e.map(
2446
+ (n) => Ni(n, t)
2447
+ ) : e;
2448
+ }
2449
+ function an(e) {
2450
+ return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : we(
2451
+ e.dashboard,
2452
+ e.semanticExecutionPayload
2453
+ ).allEligibleTargetsAreDateTime;
2454
+ }
2455
+ function sn(e) {
2456
+ const {
2457
+ globalDateFilter: t,
2458
+ globalDateFilterValue: n,
2459
+ timezone: r,
2460
+ allowMinutePrecision: o = !1
2461
+ } = e;
2462
+ if (!t || !n)
2463
+ return;
2464
+ if (!ze(n.operation))
2465
+ return {
2466
+ ...n,
2467
+ filterId: t.id
2468
+ };
2469
+ const i = n, a = i.temporalPrecision === "minute" || te(i.relativeMeta) === "minute", s = !o && a, l = i.operation === "is null" || i.operation === "is not null" ? [] : s ? on(i.values, r) : i.values, c = o || te(i.relativeMeta) !== "minute" ? i.relativeMeta : void 0, d = o && i.temporalPrecision === "minute" ? i.temporalPrecision : void 0, {
2470
+ relativeMeta: u,
2471
+ temporalPrecision: f,
2472
+ values: m,
2473
+ ...y
2474
+ } = n;
2475
+ return {
2476
+ ...y,
2477
+ filterId: t.id,
2478
+ values: l,
2479
+ ...c ? { relativeMeta: c } : {},
2480
+ ...d ? { temporalPrecision: d } : {}
2481
+ };
2482
+ }
2483
+ function ji(e) {
2484
+ const t = L(e.filters);
2485
+ if (!t)
2486
+ return e.filterValues;
2487
+ const n = an(e);
2488
+ return e.filterValues.map((r) => r.filterId !== t.id ? r : sn({
2489
+ globalDateFilter: t,
2490
+ globalDateFilterValue: r,
2491
+ timezone: e.timezone,
2492
+ allowMinutePrecision: n
2493
+ }) || r);
2494
+ }
2495
+ function ln(e) {
2496
+ const {
2497
+ globalDateFilter: t,
2498
+ globalDateFilterValue: n,
2499
+ resolvedPrimaryDateField: r,
2500
+ semanticContext: o,
2501
+ timezone: i,
2502
+ allowMinutePrecision: a = !1
2503
+ } = e;
2504
+ if (!t || !n || !r || !ze(n.operation))
2505
+ return null;
2506
+ const s = n, l = tr(
2507
+ r.dataType
2508
+ ), c = a && l, d = s.temporalPrecision === "minute" || te(s.relativeMeta) === "minute", u = c && s.temporalPrecision === "minute" ? s.temporalPrecision : void 0, f = c || te(s.relativeMeta) !== "minute" ? s.relativeMeta : void 0, m = !c && d;
2509
+ return {
2510
+ filterId: t.id,
2511
+ dateOwner: "global_date",
2512
+ name: r.qualifiedFieldName || r.name,
2513
+ operation: s.operation,
2514
+ valueType: "date",
2515
+ values: s.operation === "is null" || s.operation === "is not null" ? [] : m ? on(
2516
+ s.values,
2517
+ i
2518
+ ) : s.values,
2519
+ dataType: r.dataType || "date",
2520
+ // The exact type travels with the filter, so the server formats the predicate for
2521
+ // the column's storage type (it read it from `dataType` before 2.1 split the two).
2522
+ ...r.nativeDataType ? { nativeDataType: r.nativeDataType } : {},
2523
+ fieldMeta: {
2524
+ name: r.name,
2525
+ qualifiedFieldName: r.qualifiedFieldName,
2526
+ qualifiedEntityName: r.qualifiedEntityName,
2527
+ entityId: r.entityId,
2528
+ entityName: r.entityName,
2529
+ entityType: r.entityType,
2530
+ dataType: r.dataType,
2531
+ ...r.nativeDataType ? { nativeDataType: r.nativeDataType } : {},
2532
+ role: "groupby",
2533
+ ...t != null && t.title ? { label: t.title } : {}
2534
+ },
2535
+ ...o ? { semanticContext: o } : {},
2536
+ ...f ? { relativeMeta: f } : {},
2537
+ ...u ? { temporalPrecision: u } : {}
2538
+ };
2539
+ }
2540
+ function B(e) {
2541
+ return typeof e == "string" ? e.trim() : "";
2542
+ }
2543
+ function zi(e) {
2544
+ var t;
2545
+ return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
2546
+ var r;
2547
+ return {
2548
+ domainId: B(n.domainId) || B((r = e.semanticContext) == null ? void 0 : r.semanticDomainId),
2549
+ datasetName: B(n.name),
2550
+ selectedEntityId: B(n.id)
2551
+ };
2552
+ }).filter((n) => n.domainId && n.datasetName);
2553
+ }
2554
+ function Li(e) {
2555
+ var l, c, d, u, f;
2556
+ if (U(e) || (l = e.sql) != null && l.trim())
2557
+ return null;
2558
+ const t = zi(e), n = B((c = e.semanticContext) == null ? void 0 : c.semanticDomainId), r = B((d = e.fieldMeta) == null ? void 0 : d.entityId), o = B((u = e.fieldMeta) == null ? void 0 : u.entityName), i = B((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", a = t.find(
2559
+ (m) => r && m.selectedEntityId === r
2560
+ );
2561
+ if (a)
2562
+ return a;
2563
+ const s = t.find(
2564
+ (m) => o && m.datasetName === o && (!n || m.domainId === n)
2565
+ );
2566
+ return s || (t.length === 1 ? t[0] : i && o && n ? {
2567
+ domainId: n,
2568
+ datasetName: o
2569
+ } : null);
2570
+ }
2571
+ function Ki(e) {
2572
+ var o, i;
2573
+ const { filter: t, semanticExecutionPayload: n } = e;
2574
+ if (!n)
2575
+ return null;
2576
+ const r = Li(t);
2577
+ return r && ((i = (o = n.domainsById[r.domainId]) == null ? void 0 : o.datasetsByName[r.datasetName]) == null ? void 0 : i.primaryDateField) || null;
2578
+ }
2579
+ function cn(e) {
2580
+ const t = L(e.filters);
2581
+ return t ? e.filterValues.filter(
2582
+ (n) => n.filterId !== t.id
2583
+ ) : e.filterValues;
2584
+ }
2585
+ function hs(e) {
2586
+ const t = L(e.filters), n = cn({
2587
+ filters: e.filters,
2588
+ filterValues: e.filterValues
2589
+ });
2590
+ if (!t || U(e.filter))
2591
+ return n;
2592
+ const r = e.filterValues.find(
2593
+ (a) => a.filterId === t.id
2594
+ ), o = Ki({
2595
+ filter: e.filter,
2596
+ semanticExecutionPayload: e.semanticExecutionPayload
2597
+ }), i = ln({
2598
+ globalDateFilter: t,
2599
+ globalDateFilterValue: r,
2600
+ resolvedPrimaryDateField: o || void 0,
2601
+ semanticContext: e.filter.semanticContext,
2602
+ timezone: e.timezone,
2603
+ allowMinutePrecision: e.allowMinutePrecision
2604
+ });
2605
+ return i ? [i, ...n] : n;
2606
+ }
2607
+ function Gi(e) {
2608
+ var d;
2609
+ const t = L(e.filters), n = t ? e.cardFilterValues.find(
2610
+ (u) => u.filterId === t.id
2611
+ ) : void 0, r = t ? e.cardFilterValues.filter(
2612
+ (u) => u.filterId !== t.id
2613
+ ) : e.cardFilterValues, o = e.resolvedPrimaryDateField ?? gt({
2614
+ card: e.card,
2615
+ cardConfig: e.cardConfig,
2616
+ resolvedFields: e.resolvedFields,
2617
+ semanticExecutionPayload: e.semanticExecutionPayload
2618
+ }), i = ln({
2619
+ globalDateFilter: t,
2620
+ globalDateFilterValue: n,
2621
+ resolvedPrimaryDateField: o || void 0,
2622
+ timezone: e.timezone,
2623
+ allowMinutePrecision: e.allowMinutePrecision
2624
+ }), a = i ? [i, ...r] : r, s = new Map(
2625
+ a.map((u) => [
2626
+ u.filterId,
2627
+ u
2628
+ ])
2629
+ ), l = ((d = e.dateComparisonInputs) == null ? void 0 : d.flatMap((u) => {
2630
+ var m;
2631
+ const f = s.get(
2632
+ u.filterId
2633
+ );
2634
+ return f ? [{
2635
+ ...u,
2636
+ effectiveFilterValue: f,
2637
+ mappedFilterValue: (m = e.mappedFilterValuesByInputId) == null ? void 0 : m.get(u.inputId)
2638
+ }] : [];
2639
+ })) || [], c = Bi({
2640
+ inputs: l,
2641
+ temporalBinding: o,
2642
+ card: e.card
2643
+ });
2644
+ return {
2645
+ cardFilterValues: a,
2646
+ resolvedPrimaryDateField: o,
2647
+ dateComparisonPlan: c
2648
+ };
2649
+ }
2650
+ function vs(e) {
2651
+ const t = L(e.filters), n = an(e), r = t ? e.filterValues.find(
2652
+ (a) => a.filterId === t.id
2653
+ ) : void 0, o = cn(e);
2654
+ return !t || !r || !ze(r.operation) ? o : [
2655
+ {
2656
+ ...sn({
2657
+ globalDateFilter: t,
2658
+ globalDateFilterValue: r,
2659
+ timezone: e.timezone,
2660
+ allowMinutePrecision: n
2661
+ }) || r,
2662
+ filterId: t.id,
2663
+ name: t.title || t.column
2664
+ },
2665
+ ...o
2666
+ ];
2667
+ }
2668
+ class Hi extends Error {
2669
+ }
2670
+ function Fs(e, t) {
2671
+ const n = new Map((e ? j(e) : []).map(({ card: r }) => [r.id, r]));
2672
+ return t && n.set(t.id, t), [...n.values()].flatMap((r) => {
2673
+ const o = Ve(r);
2674
+ return o.status === "ready" ? di(o.config.spec, r.controlBindings) : [];
2675
+ });
2676
+ }
2677
+ function Ui(e, t, n) {
2678
+ const r = nr(e);
2679
+ if (!r) throw new Error("Matrix card definition is required.");
2680
+ const o = n && ci({
2681
+ ...n,
2682
+ spec: r.spec,
2683
+ catalog: t.map((d) => ({ ...d, id: d.resolvedField.id }))
2684
+ }), i = o ? { ...r, spec: o.spec } : r, a = rr(t), s = or(t), l = (d) => {
2685
+ const u = s(d, i.spec.source);
2686
+ if (!(!u && d.derivedField)) {
2687
+ if (!u) throw new Hi(`Matrix field metadata is unavailable: ${d.name}`);
2688
+ return { ...u, ...d.derivedField ? { derivedField: d.derivedField } : {} };
2689
+ }
2690
+ }, c = {
2691
+ rows: i.spec.rows.flatMap((d) => {
2692
+ const u = l(d.field);
2693
+ return u ? [{ ...u, id: d.id, granularity: d.grain, role: "groupby" }] : [];
2694
+ }),
2695
+ columns: i.spec.columns.flatMap((d) => {
2696
+ const u = l(d.field);
2697
+ return u ? [{ ...u, id: d.id, granularity: d.grain, role: "pivotby" }] : [];
2698
+ }),
2699
+ // Aggregate-stage expressions have no source-column filter target. They stay
2700
+ // authoritative in matrix.spec, including all dependencies and controls.
2701
+ metrics: i.spec.measures.flatMap((d) => {
2702
+ if (d.kind !== "aggregate" || d.field.name === "*") return [];
2703
+ const u = l(d.field);
2704
+ return u ? [{ ...u, id: d.id, aggregate: d.aggregate, role: "metric" }] : [];
2705
+ })
2706
+ };
2707
+ return { config: i, fields: c, resolveField: a };
2708
+ }
2709
+ function Qi(e) {
2710
+ const t = e.filter(Boolean);
2711
+ if (t.length !== 0)
2712
+ return t.length === 1 ? t[0] : {
2713
+ id: yt(),
2714
+ logicalOperator: "AND",
2715
+ negate: !1,
2716
+ conditions: [],
2717
+ groups: t
2718
+ };
2719
+ }
2720
+ function $i(e) {
2721
+ if (!e) return;
2722
+ const t = (n) => ({
2723
+ logicalOperator: n.logicalOperator,
2724
+ negate: n.negate,
2725
+ conditions: n.conditions.map((r) => ({
2726
+ field: r.field.id,
2727
+ operator: r.operator,
2728
+ value: r.value,
2729
+ temporalBucket: r.temporalBucket,
2730
+ rawTemporal: r.rawTemporal,
2731
+ // The run-time markers decide what runs, so they belong in the key.
2732
+ relativeMeta: r.relativeMeta,
2733
+ latestValue: r.latestValue,
2734
+ viewerZoom: r.viewerZoom
2735
+ })),
2736
+ groups: n.groups.map(t)
2737
+ });
2738
+ return JSON.stringify(t(e));
2739
+ }
2740
+ function Wi(e, t, n = {}) {
2741
+ const r = e.metricColumns || [];
2742
+ if (r.length === 0) return e;
2743
+ const o = ir.includes(
2744
+ t
2745
+ ), i = ar.includes(
2746
+ t
2747
+ ), a = (c) => {
2748
+ var d;
2749
+ return (d = c.parameters) != null && d.windowTransform ? {
2750
+ ...c,
2751
+ parameters: {
2752
+ ...c.parameters,
2753
+ windowTransform: void 0
2754
+ }
2755
+ } : c;
2756
+ };
2757
+ let s = !1;
2758
+ const l = r.map(
2759
+ (c) => {
2760
+ var f;
2761
+ const d = Lr(c);
2762
+ if (d === "none")
2763
+ return c;
2764
+ let u = c;
2765
+ return (f = u.parameters) != null && f.windowTransform && (s = !0, u = a(u)), n.keepsPeriodComparison && d !== "target" ? u : o ? d === "target" && !i ? (s = !0, {
2766
+ ...u,
2767
+ comparison: void 0
2768
+ }) : u : (s = !0, { ...u, comparison: void 0 });
2769
+ }
2770
+ );
2771
+ return s ? {
2772
+ ...e,
2773
+ metricColumns: l
2774
+ } : e;
2775
+ }
2776
+ function Ds(e, t = {}) {
2777
+ return dn(un(e, t));
2778
+ }
2779
+ function dn(e) {
2780
+ const t = [e.drill, e.selections, e.zoom];
2781
+ return e.authored ? Yr(e.authored, t, yt()) : Qi(t);
2782
+ }
2783
+ function un(e, t = {}) {
2784
+ return {
2785
+ authored: t.includeAuthoredFilters === !1 ? void 0 : sr(e),
2786
+ drill: mi(t.drill, e.id),
2787
+ selections: Jr(t.selections ?? []),
2788
+ ...t.zoom ? { zoom: t.zoom } : {}
2789
+ };
2790
+ }
2791
+ function Zi(e, t, n) {
2792
+ const r = fi(e, t);
2793
+ return Te(e) ? Wi(
2794
+ { ...r, filters: n },
2795
+ e.type,
2796
+ // A data variable's card keeps its own period comparison (P3b-03).
2797
+ { keepsPeriodComparison: Kr(e) }
2798
+ ) : r;
2799
+ }
2800
+ function Yi(e) {
2801
+ const t = lr(e);
2802
+ return {
2803
+ contextMode: t,
2804
+ shouldApplyDashboardFilters: !t || t === "full"
2805
+ };
2806
+ }
2807
+ function Ji(e) {
2808
+ const t = e.dashboardControls || [], n = e.card.controls || [], r = /* @__PURE__ */ new Set([
2809
+ ...t.map((o) => o.id),
2810
+ ...n.map((o) => o.id)
2811
+ ]);
2812
+ return fn(
2813
+ e.card,
2814
+ {
2815
+ controlValues: bt({
2816
+ relevantControlIds: r,
2817
+ dashboardValues: e.dashboardControlValues,
2818
+ cardValues: e.cardControlValues
2819
+ }),
2820
+ controlDefinitions: t,
2821
+ cardControlDefinitions: n,
2822
+ controlBindings: e.card.controlBindings || []
2823
+ },
2824
+ e.presentationControlIds
2825
+ );
2826
+ }
2827
+ function fn(e, t, n) {
2828
+ const o = t.controlBindings.filter(
2829
+ (f) => !de(f)
2830
+ ), i = new Set(
2831
+ Ae({
2832
+ sql: e.sql,
2833
+ controlBindings: o
2834
+ })
2835
+ ), a = new Set(
2836
+ [...n].filter(
2837
+ (f) => !i.has(f)
2838
+ )
2839
+ ), s = t.controlDefinitions.filter(
2840
+ (f) => !a.has(f.id)
2841
+ ), l = t.cardControlDefinitions.filter(
2842
+ (f) => !a.has(f.id)
2843
+ ), c = /* @__PURE__ */ new Set([
2844
+ ...s.map((f) => f.id),
2845
+ ...l.map((f) => f.id)
2846
+ ]), d = o.filter(
2847
+ (f) => c.has(f.controlId)
2848
+ );
2849
+ return {
2850
+ controlValues: bt({
2851
+ relevantControlIds: c,
2852
+ dashboardValues: t.controlValues
2853
+ }),
2854
+ controlDefinitions: s,
2855
+ cardControlDefinitions: l,
2856
+ controlBindings: d
2857
+ };
2858
+ }
2859
+ function Xi(e, t) {
2860
+ return !!t && e.endsWith(t);
2861
+ }
2862
+ function pn(e, t) {
2863
+ return (e ?? []).filter(
2864
+ (n) => Xi(n.filterId, t)
2865
+ );
2866
+ }
2867
+ function mn(e, t, n) {
2868
+ var r;
2869
+ if (t)
2870
+ return {
2871
+ selection: t,
2872
+ ...((r = e.preferences) == null ? void 0 : r.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
2873
+ ...n ? { owner: n } : {}
2874
+ };
2875
+ }
2876
+ function ea(e) {
2877
+ if (e.resolution.status === "resolved")
2878
+ return mn(
2879
+ e.card,
2880
+ e.resolution.resolvedOwner.selection,
2881
+ e.resolution.resolvedOwner.owner
2882
+ );
2883
+ }
2884
+ function ta(e) {
2885
+ return `Set ${e.join(", ")} to run this card.`;
2886
+ }
2887
+ function na({
2888
+ dashboardInputContext: e,
2889
+ shouldApplyDashboardFilters: t
2890
+ }) {
2891
+ if (t)
2892
+ return e.activeFilters;
2893
+ const n = new Set(
2894
+ e.inputs.flatMap(
2895
+ (r) => r.kind === "filter" && kt(r) ? [r.filter.id] : []
2896
+ )
2897
+ );
2898
+ return e.activeFilters.filter(
2899
+ (r) => n.has(r.filterId)
2900
+ );
2901
+ }
2902
+ function ra({
2903
+ dashboardInputFilterValues: e,
2904
+ adHocFilterValues: t
2905
+ }) {
2906
+ const n = [...e], r = new Set(
2907
+ n.map((o) => o.filterId)
2908
+ );
2909
+ for (const o of t)
2910
+ r.has(o.filterId) || (n.push(o), r.add(o.filterId));
2911
+ return n;
2912
+ }
2913
+ function ce(e, t) {
2914
+ const n = t.shouldApplyDashboardFilters ? pn(t.adHocFilterValues, t.selectedSheetId) : [], r = t.selectionFilterValues ?? [];
2915
+ if (!t.dashboardInputContext)
2916
+ return {
2917
+ status: "ready",
2918
+ filterValues: [...n, ...t.inlineFilterValues, ...r],
2919
+ mappingDispositions: []
2920
+ };
2921
+ const o = t.dashboardInputContext.inputs.filter(
2922
+ (u) => u.kind === "filter" && !!u.application
2923
+ ), i = new Set(
2924
+ o.map((u) => u.filter.id)
2925
+ ), a = new Set(
2926
+ t.dashboardInputContext.inputs.flatMap(
2927
+ (u) => {
2928
+ var f;
2929
+ return u.kind === "filter" && ((f = u.compatibility) == null ? void 0 : f.source) === "cardInlineFilter" ? [u.filter.id] : [];
2930
+ }
2931
+ )
2932
+ ), s = na({
2933
+ dashboardInputContext: t.dashboardInputContext,
2934
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2935
+ }).filter((u) => !i.has(u.filterId)), l = s.filter(
2936
+ (u) => !a.has(u.filterId)
2937
+ ), c = s.filter(
2938
+ (u) => a.has(u.filterId)
2939
+ ), d = cr({
2940
+ card: e,
2941
+ inputs: o,
2942
+ resolvedInputs: t.dashboardInputContext.resolvedInputs,
2943
+ activeFilterValues: t.dashboardInputContext.activeFilters,
2944
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2945
+ });
2946
+ return d.status === "blocked" ? {
2947
+ status: "blocked",
2948
+ mappingDispositions: d.dispositions
2949
+ } : {
2950
+ status: "ready",
2951
+ filterValues: [
2952
+ ...ra({
2953
+ dashboardInputFilterValues: [
2954
+ ...l,
2955
+ ...d.filterValues
2956
+ ],
2957
+ adHocFilterValues: n
2958
+ }),
2959
+ ...c,
2960
+ ...r
2961
+ ],
2962
+ mappingDispositions: d.dispositions
2963
+ };
2964
+ }
2965
+ function oa(e, t) {
2966
+ const n = e.dashboardInputContext;
2967
+ if (!n) return [];
2968
+ const r = new Set(
2969
+ t.flatMap(
2970
+ (i) => i.status === "skip" && (i.reason === "explicitlyExcluded" || i.reason === "outsideScope") ? [i.inputId] : []
2971
+ )
2972
+ ), o = new Map(n.inputs.map((i) => [i.id, i]));
2973
+ return n.resolvedInputs.flatMap((i) => {
2974
+ if (!i.missingRequiredValue) return [];
2975
+ const a = o.get(i.id);
2976
+ return a ? a.kind === "filter" && (!e.shouldApplyDashboardFilters && !kt(a) || r.has(a.id)) ? [] : [i.label] : [];
2977
+ });
2978
+ }
2979
+ function ia({
2980
+ card: e,
2981
+ cardConfig: t,
2982
+ input: n,
2983
+ resolvedPrimaryDateField: r,
2984
+ resolvedFields: o,
2985
+ semanticExecutionPayload: i,
2986
+ timezone: a,
2987
+ allowMinutePrecision: s
2988
+ }) {
2989
+ var p;
2990
+ const l = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
2991
+ (b) => b.kind === "filter" ? [b.filter] : []
2992
+ ) : [], c = ce(e, n), d = oa(
2993
+ n,
2994
+ c.mappingDispositions
2995
+ );
2996
+ if (d.length)
2997
+ return {
2998
+ status: "blocked",
2999
+ cardId: e.id,
3000
+ reason: "requiredInput",
3001
+ mappingDispositions: c.mappingDispositions,
3002
+ missingRequiredLabels: d
3003
+ };
3004
+ if (c.status === "blocked")
3005
+ return {
3006
+ status: "blocked",
3007
+ cardId: e.id,
3008
+ reason: "mapping",
3009
+ mappingDispositions: c.mappingDispositions,
3010
+ missingRequiredLabels: []
3011
+ };
3012
+ const u = Gi({
3013
+ card: e,
3014
+ cardConfig: t,
3015
+ filters: l,
3016
+ cardFilterValues: c.filterValues,
3017
+ resolvedPrimaryDateField: r,
3018
+ resolvedFields: o,
3019
+ semanticExecutionPayload: i,
3020
+ timezone: a,
3021
+ allowMinutePrecision: s,
3022
+ dateComparisonInputs: n.dateComparisonInputs,
3023
+ mappedFilterValuesByInputId: new Map(
3024
+ c.mappingDispositions.flatMap(
3025
+ (b) => b.status === "apply" ? [[b.inputId, b.filterValue]] : []
3026
+ )
3027
+ )
3028
+ }), f = L(l), m = !!(f && u.cardFilterValues.some(
3029
+ (b) => b.filterId === f.id
3030
+ )), y = u.resolvedPrimaryDateField && !((p = e.sql) != null && p.trim()) ? u.dateComparisonPlan.inputs.length ? ea({
3031
+ card: e,
3032
+ resolution: u.dateComparisonPlan.resolution
3033
+ }) : m ? mn(
3034
+ e,
3035
+ n.globalDateComparisonSelection
3036
+ ) : void 0 : void 0;
3037
+ return {
3038
+ status: "ready",
3039
+ ...u,
3040
+ queryFilterDefinitions: l,
3041
+ globalDateComparison: y,
3042
+ mappingDispositions: c.mappingDispositions
3043
+ };
3044
+ }
3045
+ function aa({
3046
+ card: e,
3047
+ dashboard: t,
3048
+ transientContexts: n,
3049
+ cardViewState: r,
3050
+ viewerTableSettings: o,
3051
+ adHocFilterValues: i,
3052
+ selectedSheetId: a,
3053
+ inlineFilterValuesMap: s,
3054
+ dashboardControls: l,
3055
+ dashboardControlValues: c,
3056
+ cardControlValuesMap: d,
3057
+ dashboardInputContext: u,
3058
+ includeAuthoredFilters: f
3059
+ }) {
3060
+ var R, K, J;
3061
+ const m = jt(t);
3062
+ for (const q of e.controlBindings || [])
3063
+ de(q) && m.add(q.controlId);
3064
+ const { shouldApplyDashboardFilters: y } = Yi(n), p = u != null && u.inputs.length ? u : void 0, b = ((u == null ? void 0 : u.selections) ?? []).filter(
3065
+ (q) => q.status === "apply"
3066
+ ), I = un(e, {
3067
+ includeAuthoredFilters: f,
3068
+ selections: b,
3069
+ drill: r == null ? void 0 : r.drill
3070
+ }), C = {
3071
+ adHocFilterValues: i || [],
3072
+ selectedSheetId: a,
3073
+ inlineFilterValues: (s == null ? void 0 : s[e.id]) || [],
3074
+ // Outside the input-context gate: a dashboard whose only input is a
3075
+ // click still sends them.
3076
+ selectionFilterValues: b.flatMap((q) => q.filterValues),
3077
+ shouldApplyDashboardFilters: y,
3078
+ ...p ? {
3079
+ dashboardInputContext: {
3080
+ inputs: p.inputs,
3081
+ resolvedInputs: p.resolvedInputs,
3082
+ activeFilters: p.activeFilters
3083
+ }
3084
+ } : {},
3085
+ ...p != null && p.globalDateComparisonSelection ? {
3086
+ globalDateComparisonSelection: p.globalDateComparisonSelection
3087
+ } : {},
3088
+ ...p != null && p.dateComparisonInputs ? {
3089
+ dateComparisonInputs: p.dateComparisonInputs
3090
+ } : {}
3091
+ }, h = ce(e, C), D = {
3092
+ filterValues: h.status === "ready" ? h.filterValues : [],
3093
+ selectionFilters: I.selections
3094
+ }, g = tt(D), V = Ci(r == null ? void 0 : r.zoom, (R = e.config) == null ? void 0 : R.groupByColumns, g), P = V ? { ...I, zoom: V.filterGroup } : I, x = V ? tt({ ...D, zoom: V.zoom }) : g, v = dn(P), S = f === !1 ? me(v, !0) : v, M = Zi(
3095
+ e,
3096
+ r == null ? void 0 : r.drill,
3097
+ S
3098
+ ), k = bi(M, r == null ? void 0 : r.grainPick, {
3099
+ currentFingerprint: x,
3100
+ drillActive: (((K = r == null ? void 0 : r.drill) == null ? void 0 : K.steps.length) ?? 0) > 0
3101
+ }), F = dr({ ...e, config: k }, o) ?? k, T = Et(F, {
3102
+ cardType: e.type,
3103
+ dataSource: e.dataSource,
3104
+ temporalResultOwner: It({
3105
+ hasExecutableConfig: ue(F, e.type),
3106
+ sql: e.sql,
3107
+ normalizedPython: Me(e.python || "")
3108
+ })
3109
+ }) || F, w = $i(S) || "", E = p ? fn(
3110
+ e,
3111
+ {
3112
+ controlValues: p.controlValues,
3113
+ controlDefinitions: p.controlDefinitions,
3114
+ cardControlDefinitions: p.cardControlDefinitions,
3115
+ controlBindings: p.controlBindings
3116
+ },
3117
+ m
3118
+ ) : Ji({
3119
+ card: e,
3120
+ presentationControlIds: m,
3121
+ dashboardControls: l,
3122
+ dashboardControlValues: c,
3123
+ cardControlValues: d == null ? void 0 : d[e.id]
3124
+ });
3125
+ return {
3126
+ filterCompilationInput: C,
3127
+ ...E,
3128
+ resolvedFilters: S,
3129
+ resolvedFilterParts: P,
3130
+ drillSteps: ((J = r == null ? void 0 : r.drill) == null ? void 0 : J.steps) ?? ur,
3131
+ dateContextKey: x,
3132
+ zoomContextKey: g,
3133
+ ...V ? { activeZoom: V.zoom } : {},
3134
+ finalConfig: F,
3135
+ queryRelevantConfig: T,
3136
+ finalFiltersKey: w
3137
+ };
3138
+ }
3139
+ function gn(e, t, n) {
3140
+ const r = ia({
3141
+ resolvedFields: t.resolvedDateFields,
3142
+ ...n,
3143
+ card: e,
3144
+ cardConfig: t.queryRelevantConfig,
3145
+ input: t.filterCompilationInput
3146
+ });
3147
+ if (r.status === "blocked") return r;
3148
+ const { filterCompilationInput: o, ...i } = t;
3149
+ return { status: "ready", queryContext: {
3150
+ ...i,
3151
+ cardFilterValues: r.cardFilterValues,
3152
+ queryFilterDefinitions: r.queryFilterDefinitions,
3153
+ resolvedPrimaryDateField: r.resolvedPrimaryDateField,
3154
+ globalDateComparison: r.globalDateComparison,
3155
+ globalDateComparisonSelection: o.globalDateComparisonSelection,
3156
+ dateComparisonInputs: o.dateComparisonInputs
3157
+ }, compiledFilters: r };
3158
+ }
3159
+ function sa(e, t, n) {
3160
+ const r = fr(e), o = gn(e, t, {
3161
+ resolvedPrimaryDateField: n.resolvedPrimaryDateField,
3162
+ timezone: n.calendarContext.tz,
3163
+ allowMinutePrecision: n.allowGlobalDateMinutePrecision
3164
+ });
3165
+ if (o.status === "blocked")
3166
+ return { ...o, tableConfig: r };
3167
+ const { compiledFilters: i } = o, {
3168
+ cardFilterValues: a,
3169
+ resolvedPrimaryDateField: s,
3170
+ globalDateComparison: l
3171
+ } = i, { queryKey: c, queryInputIdentity: d, paginationConfig: u } = Jo(
3172
+ e,
3173
+ o.queryContext,
3174
+ n.calendarContext,
3175
+ { resolvePaginationConfig: n.resolvePaginationConfig }
3176
+ ), f = t.queryRelevantConfig, m = Me(e.python || ""), y = It({
3177
+ hasExecutableConfig: ue(f, e.type),
3178
+ sql: e.sql,
3179
+ normalizedPython: m
3180
+ });
3181
+ return {
3182
+ status: "ready",
3183
+ queryKey: c,
3184
+ queryInputIdentity: d,
3185
+ paginationConfig: u,
3186
+ tableConfig: r,
3187
+ compiledFilters: i,
3188
+ requestPayloadBase: {
3189
+ cardId: e.id,
3190
+ sql: (e == null ? void 0 : e.sql) || "",
3191
+ python: m,
3192
+ resultOwner: y,
3193
+ active_filters: a,
3194
+ controlValues: t.controlValues,
3195
+ controlDefinitions: t.controlDefinitions,
3196
+ cardControlDefinitions: t.cardControlDefinitions,
3197
+ controlBindings: t.controlBindings,
3198
+ cache_config: n.globalCacheConfig,
3199
+ queryConfig: e.queryConfig,
3200
+ tableConfig: r,
3201
+ cardType: e.type,
3202
+ cardTitle: e.title || "",
3203
+ cardConfig: f,
3204
+ cardDataSource: e.dataSource,
3205
+ resolvedPrimaryDateField: s || void 0,
3206
+ calendarContext: n.calendarContext,
3207
+ ...l ? { globalDateComparison: l } : {},
3208
+ ...t.sqlRowLimit ? { sqlRowLimit: t.sqlRowLimit } : {}
3209
+ }
3210
+ };
3211
+ }
3212
+ const at = [], la = [], ca = {};
3213
+ function Ss(e, t) {
3214
+ return {
3215
+ sheetId: e.sheetId,
3216
+ sectionId: e.sectionId,
3217
+ documentFilterValues: e.documentFilterValues ?? at,
3218
+ documentControlDefinitions: e.documentControlDefinitions ?? la,
3219
+ documentControlValues: e.documentControlValues ?? ca,
3220
+ editorFilterValues: t ?? at
3221
+ };
3222
+ }
3223
+ function da({
3224
+ card: e,
3225
+ dashboard: t,
3226
+ runtime: n,
3227
+ dashboardRuntimeValues: r,
3228
+ calendar: o
3229
+ }) {
3230
+ const i = Ct({
3231
+ dashboard: t,
3232
+ dashboardInputValues: r.dashboardInputValues,
3233
+ transientContexts: void 0
3234
+ }) ? Oe({
3235
+ transientContexts: void 0,
3236
+ dashboard: t,
3237
+ sheetId: n.sheetId,
3238
+ sheetKind: "document",
3239
+ sectionId: n.sectionId,
3240
+ card: e,
3241
+ runtimeValues: {
3242
+ ...r,
3243
+ dashboardInputValues: n.documentDashboardInputValues || r.dashboardInputValues
3244
+ },
3245
+ calendar: o
3246
+ }) : void 0, a = i && (i.inputs.length > 0 || i.selections.length > 0) ? i : void 0, s = !!(i != null && i.inputs.length), l = [
3247
+ ...n.editorFilterValues || [],
3248
+ ...n.documentFilterValues
3249
+ ];
3250
+ return {
3251
+ card: s ? e : ua(
3252
+ e,
3253
+ n.documentControlDefinitions
3254
+ ),
3255
+ dashboard: t,
3256
+ transientContexts: void 0,
3257
+ // Document section cards do not drill.
3258
+ cardViewState: void 0,
3259
+ // Document section cards are not viewer-customizable tables.
3260
+ viewerTableSettings: void 0,
3261
+ adHocFilterValues: [],
3262
+ inlineFilterValuesMap: !s && l.length ? { [e.id]: l } : {},
3263
+ dashboardControls: [],
3264
+ dashboardControlValues: {},
3265
+ cardControlValuesMap: !s && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
3266
+ dashboardInputContext: a
3267
+ };
3268
+ }
3269
+ function ua(e, t) {
3270
+ if (t.length === 0)
3271
+ return e;
3272
+ const n = /* @__PURE__ */ new Map();
3273
+ for (const r of e.controls || [])
3274
+ n.set(r.id, r);
3275
+ for (const r of t)
3276
+ n.set(r.id, r);
3277
+ return {
3278
+ ...e,
3279
+ controls: Array.from(n.values())
3280
+ };
3281
+ }
3282
+ function Ts({
3283
+ card: e,
3284
+ place: t,
3285
+ source: n
3286
+ }) {
3287
+ const r = Se(e, t, n);
3288
+ return {
3289
+ card: r.card,
3290
+ context: r.context,
3291
+ inputContext: r.inputContext
3292
+ };
3293
+ }
3294
+ function fa(e, t, n) {
3295
+ return {
3296
+ calendarContext: n ?? Qr,
3297
+ allowGlobalDateMinutePrecision: we(
3298
+ e,
3299
+ t
3300
+ ).allEligibleTargetsAreDateTime,
3301
+ semanticExecutionPayload: t,
3302
+ globalCacheConfig: e.globalCacheConfig
3303
+ };
3304
+ }
3305
+ function Vs(e, t) {
3306
+ return In(
3307
+ e,
3308
+ t,
3309
+ t.allowGlobalDateMinutePrecision
3310
+ );
3311
+ }
3312
+ function pa(e, t, n = {}) {
3313
+ const r = bn(e, t);
3314
+ return {
3315
+ ...sa(e.card, e.context, {
3316
+ resolvedPrimaryDateField: r,
3317
+ calendarContext: t.calendarContext,
3318
+ allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
3319
+ globalCacheConfig: t.globalCacheConfig,
3320
+ resolvePaginationConfig: n.resolvePaginationConfig
3321
+ }),
3322
+ resolvedPrimaryDateField: r
3323
+ };
3324
+ }
3325
+ function ma({
3326
+ card: e,
3327
+ place: t,
3328
+ source: n,
3329
+ semanticExecutionPayload: r,
3330
+ matrixCatalog: o,
3331
+ withRequest: i = !1
3332
+ }) {
3333
+ var p, b;
3334
+ const { dashboard: a } = n, s = e.id, l = (I, C) => {
3335
+ var D;
3336
+ let h;
3337
+ try {
3338
+ const g = Ve(I);
3339
+ if (g.status === "invalid") throw g.error;
3340
+ const V = Se(
3341
+ I,
3342
+ C,
3343
+ n,
3344
+ g.status === "absent"
3345
+ );
3346
+ if (h = V.context, g.status === "absent")
3347
+ return { status: "ready", value: { assembled: V } };
3348
+ if (!o)
3349
+ return {
3350
+ status: "blocked",
3351
+ reason: "metadata",
3352
+ message: "Matrix field metadata is required.",
3353
+ context: h
3354
+ };
3355
+ const P = ui(g.config.spec, h), x = o.filter(
3356
+ (T) => T.field.source && P.some(
3357
+ (w) => Ce(w, T.field.source)
3358
+ )
3359
+ ), v = Ui(I, x, h), { params: S } = V, M = S.dashboardInputContext;
3360
+ v.config = {
3361
+ ...v.config,
3362
+ presentation: Ro(
3363
+ I,
3364
+ v.config,
3365
+ {
3366
+ controls: M ? [
3367
+ ...M.controlDefinitions,
3368
+ ...M.cardControlDefinitions
3369
+ ] : [
3370
+ ...S.dashboardControls ?? a.controls ?? [],
3371
+ ...S.card.controls ?? []
3372
+ ],
3373
+ values: (M == null ? void 0 : M.controlValues) ?? {
3374
+ ...S.dashboardControlValues,
3375
+ ...(D = S.cardControlValuesMap) == null ? void 0 : D[I.id]
3376
+ }
3377
+ },
3378
+ x
3379
+ )
3380
+ };
3381
+ const k = {
3382
+ ...I,
3383
+ config: { matrix: v.config }
3384
+ }, F = Se(k, C, n, !1);
3385
+ return {
3386
+ status: "ready",
3387
+ value: {
3388
+ assembled: {
3389
+ card: k,
3390
+ context: { ...F.context, resolvedDateFields: v.fields },
3391
+ inputContext: F.inputContext
3392
+ },
3393
+ matrix: v
3394
+ }
3395
+ };
3396
+ } catch (g) {
3397
+ return {
3398
+ status: "blocked",
3399
+ reason: "configuration",
3400
+ message: g instanceof Error ? g.message : "Card configuration is invalid.",
3401
+ context: h
3402
+ };
3403
+ }
3404
+ }, c = l(e, t);
3405
+ if (c.status === "blocked")
3406
+ return {
3407
+ status: "blocked",
3408
+ cardId: s,
3409
+ mappingDispositions: [],
3410
+ reason: c.reason,
3411
+ missingRequiredLabels: [],
3412
+ message: c.message
3413
+ };
3414
+ const { assembled: d, matrix: u } = c.value, f = fa(
3415
+ a,
3416
+ r,
3417
+ n.calendar
3418
+ ), m = d.context.filterCompilationInput, y = mr(a);
3419
+ try {
3420
+ const I = ce(d.card, m), C = u && y && I.status === "ready" && I.filterValues.some((V) => V.filterId === y.id);
3421
+ let h = f.allowGlobalDateMinutePrecision;
3422
+ if (C) {
3423
+ const V = (p = m.dashboardInputContext) == null ? void 0 : p.inputs.find(
3424
+ (F) => F.kind === "filter" && F.filter.id === y.id
3425
+ ), x = gr(a, y).filter(
3426
+ ({ card: F, sheet: T }) => !V || Gr(V, {
3427
+ cardId: F.id,
3428
+ sheetId: T.id,
3429
+ sheetKind: ht(T) ? "document" : "dashboard"
3430
+ })
3431
+ ).map(({ card: F, sheet: T }) => ({
3432
+ card: F,
3433
+ value: F.id === s ? c : l(F, { kind: "sheet", sheetId: T.id })
3434
+ })), v = new Map(
3435
+ x.map(({ card: F, value: T }) => [
3436
+ F.id,
3437
+ T.status === "ready" ? T.value.assembled.card : null
3438
+ ])
3439
+ ), S = new Map(
3440
+ x.map(({ card: F, value: T }) => {
3441
+ var w;
3442
+ return [
3443
+ F.id,
3444
+ T.status === "ready" ? (w = T.value.matrix) == null ? void 0 : w.fields : void 0
3445
+ ];
3446
+ })
3447
+ ), M = x.flatMap(
3448
+ ({ card: F, value: T }) => {
3449
+ const w = F.id, E = T.status === "ready" ? T.value.assembled.context : T.context;
3450
+ if (!E) return [w];
3451
+ const R = T.status === "ready" ? T.value.assembled.card : F;
3452
+ try {
3453
+ const K = ce(
3454
+ R,
3455
+ E.filterCompilationInput
3456
+ );
3457
+ return K.status === "blocked" || K.filterValues.some((J) => J.filterId === y.id) ? [w] : [];
3458
+ } catch {
3459
+ return v.set(w, null), [w];
3460
+ }
3461
+ }
3462
+ ), k = we(
3463
+ a,
3464
+ r,
3465
+ y,
3466
+ v,
3467
+ S,
3468
+ M
3469
+ );
3470
+ if ((b = k.unresolvedCardIds) != null && b.length)
3471
+ return {
3472
+ status: "blocked",
3473
+ cardId: s,
3474
+ mappingDispositions: [],
3475
+ reason: "coverage",
3476
+ missingRequiredLabels: [],
3477
+ message: `Date precision requires field metadata and valid inputs for: ${k.unresolvedCardIds.join(", ")}.`
3478
+ };
3479
+ h = k.allEligibleTargetsAreDateTime;
3480
+ }
3481
+ const D = In(d, f, h);
3482
+ if (D.status === "blocked")
3483
+ return {
3484
+ status: "blocked",
3485
+ cardId: D.cardId,
3486
+ mappingDispositions: D.mappingDispositions,
3487
+ reason: D.reason,
3488
+ missingRequiredLabels: D.missingRequiredLabels,
3489
+ ...D.reason === "requiredInput" ? { message: ta(D.missingRequiredLabels) } : {},
3490
+ ...D.resolvedPrimaryDateField ? { resolvedPrimaryDateField: D.resolvedPrimaryDateField } : {}
3491
+ };
3492
+ const g = i && !u ? pa(d, f) : void 0;
3493
+ return {
3494
+ ...D,
3495
+ ...u ? { matrix: u } : {},
3496
+ // The whole request a card runs with: the contract's payload and its
3497
+ // extras (server pagination, table totals) from the one extras owner,
3498
+ // on the first page a new viewer opens (ledger P3-78).
3499
+ ...(g == null ? void 0 : g.status) === "ready" ? {
3500
+ request: {
3501
+ ...g.requestPayloadBase,
3502
+ ...ii({
3503
+ card: d.card,
3504
+ finalConfig: d.context.finalConfig,
3505
+ documentSection: t.kind === "documentSection" ? {} : void 0,
3506
+ page: oi(d.card)
3507
+ })
3508
+ }
3509
+ } : {}
3510
+ };
3511
+ } catch (I) {
3512
+ return {
3513
+ status: "blocked",
3514
+ cardId: s,
3515
+ mappingDispositions: [],
3516
+ reason: "configuration",
3517
+ missingRequiredLabels: [],
3518
+ message: I instanceof Error ? I.message : "Card filter configuration is invalid."
3519
+ };
3520
+ }
3521
+ }
3522
+ function ga(e) {
3523
+ const t = e.editor ? {
3524
+ ...e.inlineFilterValuesMap,
3525
+ ...Object.fromEntries(
3526
+ Object.entries(e.editor.inlineFilterValuesMap).filter(
3527
+ (n) => n[1] !== void 0
3528
+ )
3529
+ )
3530
+ } : e.inlineFilterValuesMap;
3531
+ return {
3532
+ dashboardInputValues: e.dashboardInputValues,
3533
+ adHocFilterValues: e.adHocFilterValues,
3534
+ controlValues: e.controlValues,
3535
+ inlineFilterValuesMap: t,
3536
+ cardControlValuesMap: e.cardControlValuesMap
3537
+ };
3538
+ }
3539
+ function Se(e, t, n, r) {
3540
+ var c, d;
3541
+ const { dashboard: o } = n, i = ga(n), a = t.kind === "documentSection" ? {
3542
+ ...da({
3543
+ card: e,
3544
+ dashboard: o,
3545
+ runtime: t.section,
3546
+ dashboardRuntimeValues: i,
3547
+ calendar: n.calendar
3548
+ }),
3549
+ selectedSheetId: t.section.sheetId,
3550
+ includeAuthoredFilters: r
3551
+ } : ya(e, t.sheetId, n, i, r), s = aa(a), l = (c = e.config) == null ? void 0 : c.rowLimit;
3552
+ return (d = e.sql) != null && d.trim() && l && yn(o, e.id) && (s.sqlRowLimit = l), {
3553
+ card: a.card,
3554
+ params: a,
3555
+ context: s,
3556
+ inputContext: a.dashboardInputContext
3557
+ };
3558
+ }
3559
+ function yn(e, t) {
3560
+ return (e.variables ?? []).some((n) => n.id === t);
3561
+ }
3562
+ function ya(e, t, n, r, o) {
3563
+ var c, d, u;
3564
+ const { dashboard: i } = n, a = yn(i, e.id), s = a ? void 0 : n.transientContexts, l = Ct({
3565
+ dashboard: i,
3566
+ dashboardInputValues: r.dashboardInputValues,
3567
+ transientContexts: s
3568
+ }) ? Oe({
3569
+ transientContexts: s,
3570
+ dashboard: i,
3571
+ sheetId: t,
3572
+ card: e,
3573
+ runtimeValues: r,
3574
+ calendar: n.calendar
3575
+ }) : void 0;
3576
+ return {
3577
+ card: e,
3578
+ dashboard: i,
3579
+ transientContexts: s,
3580
+ // The editor previews the card without a viewer's zoom (chart date zoom
3581
+ // DZ-D1): it shows the dashboard's dates, and its save never sees one.
3582
+ cardViewState: a ? void 0 : n.editor ? pr((c = n.cardViewStates) == null ? void 0 : c[e.id], null) : (d = n.cardViewStates) == null ? void 0 : d[e.id],
3583
+ viewerTableSettings: n.editor || a || (u = n.viewerTableSettings) == null ? void 0 : u[e.id],
3584
+ adHocFilterValues: a ? [] : r.adHocFilterValues,
3585
+ selectedSheetId: t,
3586
+ inlineFilterValuesMap: r.inlineFilterValuesMap,
3587
+ dashboardControls: i.controls,
3588
+ dashboardControlValues: r.controlValues,
3589
+ cardControlValuesMap: r.cardControlValuesMap,
3590
+ // Keep a selection-only context so the query has one resolved-input contract.
3591
+ dashboardInputContext: l && (l.inputs.length > 0 || l.selections.length > 0) ? l : void 0,
3592
+ includeAuthoredFilters: o
3593
+ };
3594
+ }
3595
+ function bn({ card: e, context: t }, n) {
3596
+ return gt({
3597
+ card: e,
3598
+ cardConfig: t.queryRelevantConfig,
3599
+ resolvedFields: t.resolvedDateFields,
3600
+ semanticExecutionPayload: n.semanticExecutionPayload
3601
+ });
3602
+ }
3603
+ function In(e, t, n) {
3604
+ const { card: r } = e, o = bn(e, t), i = gn(r, e.context, {
3605
+ resolvedPrimaryDateField: o,
3606
+ timezone: t.calendarContext.tz,
3607
+ allowMinutePrecision: n
3608
+ });
3609
+ return i.status === "blocked" ? { ...i, card: r, resolvedPrimaryDateField: o } : {
3610
+ status: "ready",
3611
+ card: r,
3612
+ queryContext: i.queryContext,
3613
+ compiledFilters: i.compiledFilters,
3614
+ resolvedPrimaryDateField: o
3615
+ };
3616
+ }
3617
+ function Ms({
3618
+ dashboard: e,
3619
+ dashboardInputValues: t,
3620
+ adHocFilterValues: n,
3621
+ calendar: r,
3622
+ selectedSheetId: o,
3623
+ sheetSelection: i = "current",
3624
+ dashboardControlValues: a,
3625
+ cardControlValuesMap: s,
3626
+ semanticExecutionPayload: l,
3627
+ timezone: c
3628
+ }) {
3629
+ const d = e ? [...yr(e)] : void 0, u = o ?? null, f = (C) => {
3630
+ var h;
3631
+ return e ? Ca({
3632
+ dashboard: e,
3633
+ runtimeValues: { dashboardInputValues: t },
3634
+ adHocFilterValues: n,
3635
+ sheetId: C,
3636
+ sheetKind: ht(
3637
+ (h = e.sheets) == null ? void 0 : h.find((D) => D.id === C)
3638
+ ) ? "document" : "dashboard",
3639
+ calendar: r
3640
+ }) : [];
3641
+ }, m = i === "all" ? Array.from(
3642
+ new Map(
3643
+ ((e == null ? void 0 : e.sheets) || []).flatMap(
3644
+ (C) => f(C.id).map(
3645
+ (h) => [h.filterId, h]
3646
+ )
3647
+ )
3648
+ ).values()
3649
+ ) : f(u), y = {
3650
+ ...a || {}
3651
+ }, p = i === "all" ? j({ sheets: (e == null ? void 0 : e.sheets) || [] }) : u ? j({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
3652
+ (C) => C.sheet.id === u
3653
+ ) : [];
3654
+ for (const C of p)
3655
+ Object.assign(y, (s == null ? void 0 : s[C.card.id]) || {});
3656
+ const b = br({
3657
+ filterDefinitions: d,
3658
+ filterValues: m
3659
+ }), I = ji({
3660
+ filters: d,
3661
+ filterValues: b,
3662
+ dashboard: e,
3663
+ semanticExecutionPayload: l,
3664
+ timezone: c
3665
+ });
3666
+ return {
3667
+ selectedSheetId: u,
3668
+ filterValues: I,
3669
+ controlValues: y
3670
+ };
3671
+ }
3672
+ function ks({
3673
+ dashboard: e,
3674
+ cardId: t,
3675
+ transientContexts: n,
3676
+ cardViewStates: r,
3677
+ viewerTableSettings: o,
3678
+ semanticExecutionPayload: i,
3679
+ adHocFilterValues: a,
3680
+ inlineFilterValuesMap: s,
3681
+ dashboardControlValues: l,
3682
+ cardControlValuesMap: c,
3683
+ dashboardInputValues: d,
3684
+ calendar: u,
3685
+ matrixCatalog: f,
3686
+ cardOverride: m,
3687
+ sheetId: y,
3688
+ documentSection: p,
3689
+ editor: b,
3690
+ withRequest: I
3691
+ }) {
3692
+ var D;
3693
+ if (!e)
3694
+ return null;
3695
+ m && !Ue(e, t) && y && (e = { ...e, sheets: (D = e.sheets) == null ? void 0 : D.map((g) => g.id === y ? { ...g, cards: [...g.cards ?? [], m] } : g) });
3696
+ const C = Ue(e, t);
3697
+ if (!C)
3698
+ return null;
3699
+ const h = ma({
3700
+ card: m ?? C.card,
3701
+ place: p ? { kind: "documentSection", section: p } : { kind: "sheet", sheetId: C.sheet.id },
3702
+ source: {
3703
+ dashboard: e,
3704
+ adHocFilterValues: a,
3705
+ controlValues: l,
3706
+ inlineFilterValuesMap: s,
3707
+ cardControlValuesMap: c ? Object.fromEntries(
3708
+ Object.entries(c).filter(
3709
+ (g) => g[1] !== void 0
3710
+ )
3711
+ ) : void 0,
3712
+ dashboardInputValues: d,
3713
+ transientContexts: n,
3714
+ cardViewStates: r,
3715
+ viewerTableSettings: o,
3716
+ calendar: u,
3717
+ ...b ? { editor: b } : {}
3718
+ },
3719
+ semanticExecutionPayload: i,
3720
+ matrixCatalog: f,
3721
+ withRequest: I
3722
+ });
3723
+ return h.status === "blocked" ? h : {
3724
+ status: "ready",
3725
+ card: m ?? C.card,
3726
+ sheetId: C.sheet.id,
3727
+ queryContext: h.queryContext,
3728
+ compiledFilters: h.compiledFilters,
3729
+ resolvedPrimaryDateField: h.resolvedPrimaryDateField,
3730
+ ...h.matrix ? { matrix: h.matrix } : {},
3731
+ ...h.request ? { request: h.request } : {}
3732
+ };
3733
+ }
3734
+ function ba(e, t, n) {
3735
+ const r = t === "date" && "relativeMeta" in e ? Pr(e.relativeMeta) : void 0;
3736
+ if (!r) return { values: e.values };
3737
+ const o = vr(r, n ?? void 0), i = wr(String(e.operation), r);
3738
+ return {
3739
+ values: o && i ? Or(String(e.operation), o) : e.values,
3740
+ relativeMeta: r,
3741
+ ..."temporalPrecision" in e && e.temporalPrecision === "minute" ? { temporalPrecision: "minute" } : {}
3742
+ };
3743
+ }
3744
+ function Ia(e, t, n) {
3745
+ const r = t, o = Cr(e);
3746
+ return hr({
3747
+ definition: e,
3748
+ sourceValue: r,
3749
+ value: {
3750
+ filterId: r.filterId,
3751
+ name: e.column,
3752
+ operation: r.operation ?? e.operation,
3753
+ valueType: o,
3754
+ dataType: e.dataType,
3755
+ fieldMeta: e.fieldMeta,
3756
+ semanticContext: e.semanticContext,
3757
+ ...ba(r, o, n)
3758
+ }
3759
+ });
3760
+ }
3761
+ function Cn(e, t, n) {
3762
+ const r = A(e);
3763
+ let o = {};
3764
+ const i = [], a = [];
3765
+ for (const s of t ?? []) {
3766
+ if (Ur(s.filterId)) {
3767
+ a.push(s.filterId);
3768
+ continue;
3769
+ }
3770
+ const l = r.findFilterInput({ filterId: s.filterId }), c = l == null ? void 0 : l.input;
3771
+ if (c || i.push(s), !c || c.runtimeScope === "perCard" || c.runtimeScope === "perDocumentSection") {
3772
+ a.push(s.filterId);
3773
+ continue;
3774
+ }
3775
+ const d = Ir(
3776
+ Ia(c.filter, s, n.calendar)
3777
+ );
3778
+ if (d) {
3779
+ if (c.runtimeScope === "shared") {
3780
+ o = Ke(o, c, {}, d);
3781
+ continue;
3782
+ }
3783
+ for (const u of xt(e).values())
3784
+ Pt(c, u) && (o = Ke(
3785
+ o,
3786
+ c,
3787
+ { sheetId: u.sheetId },
3788
+ d
3789
+ ));
3790
+ }
3791
+ }
3792
+ return { slots: o, adHocFilterValues: i, droppedFilterIds: a };
3793
+ }
3794
+ function Ca(e) {
3795
+ const { dashboard: t, sheetId: n } = e, r = [];
3796
+ if (n)
3797
+ for (const { input: o } of Fr(t, n, e.sheetKind)) {
3798
+ const i = Dr({
3799
+ dashboard: t,
3800
+ input: o,
3801
+ runtimeValues: { dashboardInputValues: e.runtimeValues.dashboardInputValues },
3802
+ target: { sheetId: n },
3803
+ calendar: e.calendar
3804
+ });
3805
+ i.kind === "filter" && i.filterValue && r.push(i.filterValue);
3806
+ }
3807
+ return [...r, ...pn(e.adHocFilterValues, n)];
3808
+ }
3809
+ function xs(e, t) {
3810
+ switch (t.runtimeScope) {
3811
+ case "shared":
3812
+ return [{}];
3813
+ case "perSheet":
3814
+ return [...xt(e).values()].filter((n) => Pt(t, n)).map((n) => ({ sheetId: n.sheetId }));
3815
+ case "perCard": {
3816
+ const n = A(e);
3817
+ return [
3818
+ ...n.reachedCards({ inputId: t.id }).map((r) => ({ sheetId: r.sheetId, cardId: r.cardId })),
3819
+ // A variable holds a value at each place it is used (DV-D35).
3820
+ ...n.reachedVariables({ inputId: t.id }).flatMap(
3821
+ (r) => r.places.map((o) => ({ sheetId: o.sheetId, cardId: r.variableId }))
3822
+ )
3823
+ ];
3824
+ }
3825
+ case "perDocumentSection": {
3826
+ const n = /* @__PURE__ */ new Map();
3827
+ for (const r of A(e).reachedCards({ inputId: t.id }))
3828
+ r.kind === "documentSectionCard" && n.set(r.sectionId, { sheetId: r.sheetId, sectionId: r.sectionId });
3829
+ return [...n.values()];
3830
+ }
3831
+ default:
3832
+ return [];
3833
+ }
3834
+ }
3835
+ function st(e) {
3836
+ var t;
3837
+ return [
3838
+ ...e.cards ?? [],
3839
+ ...(e.frames ?? []).flatMap((n) => n.cards),
3840
+ ...(((t = e.document) == null ? void 0 : t.sections) ?? []).flatMap(
3841
+ (n) => wt(n)
3842
+ )
3843
+ ];
3844
+ }
3845
+ function ha(e, t) {
3846
+ var n, r;
3847
+ return {
3848
+ sheetId: e.id,
3849
+ cardId: t.id,
3850
+ sheetKind: e.kind ?? "dashboard",
3851
+ sectionId: (r = (n = e.document) == null ? void 0 : n.sections.find(
3852
+ (o) => wt(o).some(({ id: i }) => i === t.id)
3853
+ )) == null ? void 0 : r.id
3854
+ };
3855
+ }
3856
+ function va(e, t, n, r) {
3857
+ var c, d, u;
3858
+ const o = {}, i = (c = e.preferences) == null ? void 0 : c.textVisualOptions;
3859
+ if (!i) return o;
3860
+ const a = Oe({
3861
+ // Authoring: carried drill context never applies to a dashboard being edited.
3862
+ transientContexts: void 0,
3863
+ dashboard: n,
3864
+ ...ha(r, t),
3865
+ card: t,
3866
+ runtimeValues: {},
3867
+ // Aliases only: no input value is read.
3868
+ calendar: null
3869
+ }), s = (f) => {
3870
+ if (f.source !== "dashboardInputAlias") return f;
3871
+ const m = a.variablesByName[f.variableName], y = m ? {
3872
+ source: "input",
3873
+ inputId: m.id,
3874
+ export: f.export ?? "label"
3875
+ } : f;
3876
+ return m && (o[f.variableName] = y), y;
3877
+ }, l = (f) => {
3878
+ Object.assign(f, Tt(f, (m) => s(m))), f.type === "link" && [...f.children, ...Array.isArray(f.url) ? f.url : []].forEach((m) => l(m)), f.type === "when" && [...f.then ?? [], ...f.else ?? []].forEach(l);
3879
+ };
3880
+ return (d = i.content) == null || d.forEach((f) => {
3881
+ f.type === "variable" && (f.ref = s(f.ref));
3882
+ }), (u = i.richContent) == null || u.blocks.forEach((f) => {
3883
+ f.type === "list" ? f.items.forEach((m) => m.forEach(l)) : f.children.forEach(l);
3884
+ }), o;
3885
+ }
3886
+ function Fa(e, t) {
3887
+ var i;
3888
+ const n = st(e);
3889
+ if (!n.some((a) => {
3890
+ var s;
3891
+ return (s = a.preferences) == null ? void 0 : s.textVisualOptions;
3892
+ }))
3893
+ return e;
3894
+ const r = oe(e), o = st(r);
3895
+ for (let a = 0; a < o.length; a++) {
3896
+ const s = va(
3897
+ o[a],
3898
+ n[a],
3899
+ t,
3900
+ e
3901
+ );
3902
+ (i = e.frames) != null && i.some(
3903
+ (l) => l.visualId && l.cards.some((c) => c.id === o[a].id)
3904
+ ) && (o[a].linkedReferenceOverrides = mo(
3905
+ o[a].linkedReferenceOverrides,
3906
+ { inputAliases: s }
3907
+ ));
3908
+ }
3909
+ return r;
3910
+ }
3911
+ function Da(e) {
3912
+ var n;
3913
+ const t = (n = e.sheets) == null ? void 0 : n.map(
3914
+ (r) => Fa(r, e)
3915
+ );
3916
+ return t && t.some((r, o) => r !== e.sheets[o]) ? { ...e, sheets: t } : e;
3917
+ }
3918
+ function Sa(e) {
3919
+ const t = A(e);
3920
+ return t.issues.length === 0 && !t.needsUpgrade ? e : t.issues.length ? t.toStoredDashboard() : A(
3921
+ Da(e)
3922
+ ).toStoredDashboard();
3923
+ }
3924
+ export {
3925
+ ha as $,
3926
+ Xi as A,
3927
+ pn as B,
3928
+ mo as C,
3929
+ La as D,
3930
+ Do as E,
3931
+ ci as F,
3932
+ et as G,
3933
+ wo as H,
3934
+ Po as I,
3935
+ ko as J,
3936
+ Ua as K,
3937
+ go as L,
3938
+ Nt as M,
3939
+ Fe as N,
3940
+ Ao as O,
3941
+ z as P,
3942
+ Eo as Q,
3943
+ Re as R,
3944
+ Ee as S,
3945
+ Xr as T,
3946
+ Qa as U,
3947
+ Za as V,
3948
+ Oo as W,
3949
+ Ga as X,
3950
+ Vs as Y,
3951
+ fa as Z,
3952
+ st as _,
3953
+ Ai as a,
3954
+ va as a0,
3955
+ Fa as a1,
3956
+ ys as a2,
3957
+ ms as a3,
3958
+ Qt as a4,
3959
+ gs as a5,
3960
+ Lo as a6,
3961
+ ta as a7,
3962
+ Ms as a8,
3963
+ Zi as a9,
3964
+ Cs as aA,
3965
+ sn as aB,
3966
+ ce as aC,
3967
+ Ha as aD,
3968
+ Hi as aE,
3969
+ ln as aF,
3970
+ Ae as aG,
3971
+ Wa as aH,
3972
+ Ya as aI,
3973
+ ei as aJ,
3974
+ $ as aK,
3975
+ cs as aL,
3976
+ Is as aM,
3977
+ bs as aN,
3978
+ Ds as aa,
3979
+ Ts as ab,
3980
+ ni as ac,
3981
+ ri as ad,
3982
+ pa as ae,
3983
+ Ja as af,
3984
+ Xa as ag,
3985
+ ii as ah,
3986
+ De as ai,
3987
+ ti as aj,
3988
+ ai as ak,
3989
+ es as al,
3990
+ Ss as am,
3991
+ vs as an,
3992
+ ns as ao,
3993
+ os as ap,
3994
+ rs as aq,
3995
+ is as ar,
3996
+ as,
3997
+ ma as at,
3998
+ Fs as au,
3999
+ Ot as av,
4000
+ $a as aw,
4001
+ hs as ax,
4002
+ ss as ay,
4003
+ hi as az,
4004
+ Yi as b,
4005
+ Jo as c,
4006
+ ts as d,
4007
+ fo as e,
4008
+ us as f,
4009
+ oe as g,
4010
+ ps as h,
4011
+ ks as i,
4012
+ fs as j,
4013
+ Ia as k,
4014
+ _i as l,
4015
+ Ne as m,
4016
+ di as n,
4017
+ ui as o,
4018
+ ls as p,
4019
+ yo as q,
4020
+ ds as r,
4021
+ Co as s,
4022
+ At as t,
4023
+ Ka as u,
4024
+ vo as v,
4025
+ Sa as w,
4026
+ Cn as x,
4027
+ Ca as y,
4028
+ xs as z
4029
+ };