react-semaphor 0.1.544 → 0.1.545

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 (88) hide show
  1. package/dist/analytics-protocol/index.js +35 -34
  2. package/dist/assistant-context/index.js +1 -1
  3. package/dist/brand-studio/index.js +2 -2
  4. package/dist/briefings/index.js +50 -47
  5. package/dist/chunks/{class-utils-Df1OVOT1.js → _commonjsHelpers-DimLPMtv.js} +124 -98
  6. package/dist/chunks/{apply-dashboard-operations-Bz4n1Lq6.js → apply-dashboard-operations-CZEMsx8E.js} +778 -958
  7. package/dist/chunks/{assistant-chat-BNLkCDml.js → assistant-chat-D7sWTypJ.js} +308 -309
  8. package/dist/chunks/calendar-day-equality-dvoQp1xW.js +410 -0
  9. package/dist/chunks/{comparison-window-caption-BTkrN3W4.js → comparison-window-caption-D4E6IHPD.js} +56 -55
  10. package/dist/chunks/{custom-visual-inputs-DUtpYZOk.js → custom-visual-inputs-DLCD9Y5V.js} +8 -2
  11. package/dist/chunks/{dashboard-g5a4DKWq.js → dashboard-B1tMju0u.js} +1 -1
  12. package/dist/chunks/{dashboard-briefing-launcher-DQ_8O_e2.js → dashboard-briefing-launcher-CePgIu0Z.js} +771 -776
  13. package/dist/chunks/{dashboard-controls-8RyBTQUO.js → dashboard-controls-Cq05n3e0.js} +28 -28
  14. package/dist/chunks/{dashboard-json-7qT9jmfL.js → dashboard-json-CoYRPqxx.js} +3 -3
  15. package/dist/chunks/document-dashboard-inputs-BesAHZvB.js +3112 -0
  16. package/dist/chunks/{edit-dashboard-visual-BfJwnRIZ.js → edit-dashboard-visual-JPtNfJRb.js} +5624 -5615
  17. package/dist/chunks/{filter-value-text-CYsVYPuD.js → filter-value-text-ff7osJr7.js} +1 -1
  18. package/dist/chunks/{index-DkAyQvC6.js → index-DRWiuqyd.js} +378 -333
  19. package/dist/chunks/{matrix-formatter-CxJLkztA.js → matrix-formatter-DnCyRXJE.js} +13 -13
  20. package/dist/chunks/{numeric-presentation-DESvLiu9.js → numeric-presentation-7X_IrD58.js} +2571 -2572
  21. package/dist/chunks/{raw-temporal-presentation-CLiVi90c.js → raw-temporal-presentation-C3mUgnEx.js} +1 -1
  22. package/dist/chunks/{zoned-wall-clock-MulfA26h.js → relative-date-label-Bk2j94pA.js} +21 -64
  23. package/dist/chunks/rendered-file-D8xEuVVx.js +108 -0
  24. package/dist/chunks/{report-preferences-dialog-Df7VpRVW.js → report-preferences-dialog-DUtuUL_5.js} +631 -603
  25. package/dist/chunks/resolve-dashboard-input-context-DJ2tICwz.js +9415 -0
  26. package/dist/chunks/{saved-dashboard-context-B-mQ--nV.js → saved-dashboard-context-LrF_kW0l.js} +183 -211
  27. package/dist/chunks/selection-filter-compiler-BKXmyLrS.js +79 -0
  28. package/dist/chunks/{semaphor-ready-indicator-DDAxk8us.js → semaphor-ready-indicator-BxF96Yhv.js} +45764 -46519
  29. package/dist/chunks/{shelf-drop-preview-context-BSRPwaED.js → shelf-drop-preview-context-CNaM_Gmh.js} +885 -866
  30. package/dist/chunks/{switch-C3jLxlG0.js → switch-uDtPgQlQ.js} +44 -45
  31. package/dist/chunks/{table-export-sheet-CPfGAQ9X.js → table-export-sheet-YzMioA7Y.js} +1 -1
  32. package/dist/chunks/{use-create-flow-overlay-state-BxzFviM-.js → use-create-flow-overlay-state-CjB7ig1o.js} +105 -105
  33. package/dist/chunks/zoned-wall-clock-BkxV9jS2.js +46 -0
  34. package/dist/dashboard/index.js +1 -1
  35. package/dist/dashboard-authoring/index.js +556 -544
  36. package/dist/data-app-sdk/index.js +1 -1
  37. package/dist/format-utils/index.js +163 -152
  38. package/dist/index.js +351 -323
  39. package/dist/style.css +1 -1
  40. package/dist/surfboard/index.js +1 -1
  41. package/dist/types/briefings/attachment-outcomes.d.ts +1 -1
  42. package/dist/types/briefings/attachments.d.ts +33 -6
  43. package/dist/types/briefings/index.d.ts +6 -5
  44. package/dist/types/components/surfboard/filter/types.d.ts +0 -14
  45. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-authoring.d.ts +68 -82
  46. package/dist/types/lib/dashboard-inputs/dashboard-input-target-context.d.ts +0 -8
  47. package/dist/types/lib/dashboard-inputs/dashboard-input-values.d.ts +35 -1
  48. package/dist/types/lib/dashboard-inputs/filter-settings.d.ts +199 -0
  49. package/dist/types/lib/dashboard-inputs/resolve-dashboard-input-context.d.ts +7 -2
  50. package/dist/types/lib/dashboard-inputs/resolve-selection-input.d.ts +1 -1
  51. package/dist/types/lib/dashboard-viewer/captured-runtime-values.d.ts +40 -0
  52. package/dist/types/lib/dashboard-viewer/compatibility-input-storage.d.ts +16 -16
  53. package/dist/types/lib/dashboard-viewer/viewer-state.d.ts +11 -9
  54. package/dist/types/lib/download-pdf.d.ts +75 -1
  55. package/dist/types/lib/hooks/use-date-filter.d.ts +5 -0
  56. package/dist/types/lib/hooks/use-text-filter.d.ts +5 -0
  57. package/dist/types/lib/matrix-table/matrix-delivery-policy.d.ts +5 -4
  58. package/dist/types/lib/query-context/assemble-card-query.d.ts +158 -0
  59. package/dist/types/lib/query-context/build-card-query-context.d.ts +3 -3
  60. package/dist/types/lib/query-context/build-dashboard-card-query-contract.d.ts +15 -6
  61. package/dist/types/lib/query-context/build-dashboard-execution-snapshot.d.ts +11 -13
  62. package/dist/types/lib/query-context/compile-dashboard-card-filters.d.ts +22 -12
  63. package/dist/types/lib/stores/dashboard-store.d.ts +39 -55
  64. package/dist/types/lib/stores/editor-store.d.ts +0 -3
  65. package/dist/types/lib/types/common-types.d.ts +21 -6
  66. package/dist/types/shared/assistant-context/saved-dashboard-context.d.ts +4 -11
  67. package/dist/types/shared/dashboard-authoring/control-execution-contract.d.ts +12 -12
  68. package/dist/types/shared/dashboard-authoring/dashboard-filter-mapping-contract.d.ts +7 -0
  69. package/dist/types/shared/dashboard-authoring/dashboard-input-scope.d.ts +92 -0
  70. package/dist/types/shared/dashboard-authoring/filter-model/ad-hoc-filter-values.d.ts +10 -0
  71. package/dist/types/shared/dashboard-authoring/filter-model/filter-definitions.d.ts +29 -0
  72. package/dist/types/shared/dashboard-authoring/filter-model/filter-values.d.ts +58 -0
  73. package/dist/types/shared/dashboard-authoring/filter-model/index.d.ts +7 -0
  74. package/dist/types/shared/dashboard-authoring/filter-model/prototype-document-inputs.d.ts +15 -0
  75. package/dist/types/shared/dashboard-authoring/filter-model/read-dashboard-filter-model.d.ts +78 -0
  76. package/dist/types/shared/dashboard-authoring/filter-model/stored-dashboard.d.ts +18 -0
  77. package/dist/types/shared/dashboard-authoring/filter-model/toolbar-filter-reach.d.ts +23 -0
  78. package/dist/types/shared/dashboard-authoring/index.d.ts +2 -0
  79. package/dist/types/shared/format-utils/exporters/index.d.ts +2 -0
  80. package/dist/types/shared/format-utils/exporters/rendered-file.d.ts +106 -0
  81. package/package.json +2 -2
  82. package/dist/chunks/_commonjsHelpers-BkfeUUK-.js +0 -28
  83. package/dist/chunks/calendar-day-equality-BmJAWduY.js +0 -460
  84. package/dist/chunks/document-dashboard-inputs-BC6p-ESg.js +0 -8087
  85. package/dist/chunks/document-sheet-utils-Duo9uLoH.js +0 -3619
  86. package/dist/chunks/sort-target-MT1WK1vX.js +0 -29
  87. package/dist/types/lib/dashboard-inputs/dashboard-filter-mapping-storage-transition.d.ts +0 -88
  88. package/dist/types/lib/dashboard-inputs/dashboard-input-scope.d.ts +0 -10
@@ -0,0 +1,3112 @@
1
+ import { bs as St, ad as Vt, bt as M, r as oe, bu as kt, bv as R, bw as Mt, bx as Tt, by as Me, d as W, bz as Ot, bA as xt, bB as wt, bC as Pt, bD as Et, bE as Rt, bF as qt, bG as Te, bH as Bt, bI as ie, bJ as Y, bK as se, bL as At, W as Z, l as re, bM as Nt, a1 as Oe, g as ve, bN as xe, bO as jt, bP as zt, bQ as _t, bR as Gt, T as Lt, bS as Ht, i as z, bT as Kt, bU as Qt, bV as j, bW as ae, bX as $, bY as we, bZ as $t, aj as Ut, C as Wt, b_ as Yt, b$ as Zt, c0 as Jt, c1 as Pe, c2 as Xt, c3 as en, c4 as tn, c5 as nn, aa as on, c6 as sn, a as Ee, c as rn, c7 as Re, a5 as an, c8 as ln, aX as qe, c9 as dn, ca as cn, D as un, cb as fn, a4 as Be, a2 as pn, cc as mn, M as bn, O as Ae, P as In, cd as Ne } from "./resolve-dashboard-input-context-DJ2tICwz.js";
2
+ import { A as hn } from "./validators-DMHTpf7a.js";
3
+ import { b as le } from "./matrix-operation-contract-8OIO4gob.js";
4
+ import "./analytics-base-schemas-BFAoRlkU.js";
5
+ import "zod";
6
+ import "./index-CuHybtft.js";
7
+ import "../value-format-preferences/index.js";
8
+ import "./_commonjsHelpers-DimLPMtv.js";
9
+ import "./pivot-result-lifecycle-DM4CyGKs.js";
10
+ import { F as gn, x as de, G as q, A as ee, q as Cn, j as vn, o as yn, B as G, y as Dn } from "./table-settings-CLZocegs.js";
11
+ import { ak as je, al as Fn, am as Sn, an as Vn, ao as kn, ap as Mn, $ as ze, d as _e, af as Ge, n as Le, aq as Tn } from "./numeric-presentation-7X_IrD58.js";
12
+ import { r as He, B as ce } from "./bookmark-state-CXw7lZ50.js";
13
+ import { n as ye } from "./matrix-formatter-DnCyRXJE.js";
14
+ import { r as On, i as Ke } from "./matrix-card-DjwWcCo8.js";
15
+ import { D as xn } from "./report-runtime-context-Dq8XyODK.js";
16
+ import { v as ue } from "./custom-visual-inputs-DLCD9Y5V.js";
17
+ import { c as wn } from "./selection-filter-compiler-BKXmyLrS.js";
18
+ function fe(e, t) {
19
+ const n = {};
20
+ for (const o of gn(e)) {
21
+ if (!o.inlineFilters || o.inlineFilters.length === 0)
22
+ continue;
23
+ const i = [];
24
+ for (const s of o.inlineFilters) {
25
+ const r = St(s, t);
26
+ r && i.push(r);
27
+ }
28
+ i.length > 0 && (n[o.id] = i);
29
+ }
30
+ return n;
31
+ }
32
+ const Pn = [];
33
+ function En(e) {
34
+ return e.label || e.name;
35
+ }
36
+ function gi(e, t, n) {
37
+ const o = e == null ? void 0 : e.drill;
38
+ return {
39
+ ...e,
40
+ drill: {
41
+ // A dynamic drill carries no hierarchy and keeps the one already walked.
42
+ hierarchyId: n ?? (o == null ? void 0 : o.hierarchyId),
43
+ steps: [...(o == null ? void 0 : o.steps) ?? [], t]
44
+ }
45
+ };
46
+ }
47
+ function Ci(e) {
48
+ const t = e == null ? void 0 : e.drill;
49
+ if (!e || !(t != null && t.steps.length)) return e;
50
+ const { drill: n, ...o } = e, i = t.steps.slice(0, -1);
51
+ return i.length > 0 ? { ...o, drill: { ...t, steps: i } } : Object.keys(o).length > 0 ? o : void 0;
52
+ }
53
+ function E(e) {
54
+ return typeof e == "object" && e !== null && !Array.isArray(e);
55
+ }
56
+ function Rn(e) {
57
+ if (!E(e)) return !1;
58
+ const { toField: t, conditions: n } = e;
59
+ return E(t) && typeof t.name == "string" && Array.isArray(n) && n.every(
60
+ (o) => E(o) && E(o.field) && typeof o.field.name == "string"
61
+ );
62
+ }
63
+ function qn(e) {
64
+ if (!E(e)) return {};
65
+ const t = {};
66
+ for (const [n, o] of Object.entries(e)) {
67
+ if (!E(o) || !E(o.drill)) continue;
68
+ const { steps: i, hierarchyId: s } = o.drill;
69
+ !Array.isArray(i) || i.length === 0 || i.every(Rn) && (t[n] = {
70
+ drill: {
71
+ ...typeof s == "string" ? { hierarchyId: s } : {},
72
+ steps: i.map((r) => ({
73
+ ...r,
74
+ label: typeof r.label == "string" && r.label ? r.label : En(r.toField)
75
+ }))
76
+ }
77
+ });
78
+ }
79
+ return t;
80
+ }
81
+ function Bn(e, t) {
82
+ const n = Object.entries(e ?? {}).filter(
83
+ ([o, i]) => {
84
+ var s;
85
+ return (((s = i.drill) == null ? void 0 : s.steps.length) ?? 0) > 0 && (!t || t.has(o));
86
+ }
87
+ );
88
+ return n.length > 0 ? Object.fromEntries(n) : void 0;
89
+ }
90
+ function An(e, t) {
91
+ return {
92
+ id: t,
93
+ field: e.field,
94
+ operator: e.operator,
95
+ value: e.value,
96
+ label: e.label,
97
+ temporalBucket: e.temporalBucket
98
+ };
99
+ }
100
+ function Nn(e, t) {
101
+ return je(e) ? jn(e, t) : e.config ?? {};
102
+ }
103
+ function jn(e, t) {
104
+ var o;
105
+ const n = (o = t == null ? void 0 : t.steps[t.steps.length - 1]) == null ? void 0 : o.toField;
106
+ return n ? Vt(e.config ?? {}, n, {
107
+ sortPolicy: "retargetDimensionSort"
108
+ }) : e.config ?? {};
109
+ }
110
+ function zn(e, t) {
111
+ const n = (e == null ? void 0 : e.steps) ?? [];
112
+ if (n.length !== 0)
113
+ return {
114
+ id: `${t}-drill-root`,
115
+ logicalOperator: "AND",
116
+ negate: !1,
117
+ conditions: [],
118
+ groups: n.map((o, i) => ({
119
+ id: `breadcrumb-${i}`,
120
+ logicalOperator: "OR",
121
+ negate: !1,
122
+ conditions: [],
123
+ groups: [
124
+ {
125
+ id: `breadcrumb-${i}-group-0`,
126
+ logicalOperator: "AND",
127
+ negate: !1,
128
+ conditions: o.conditions.map(
129
+ (s) => An(
130
+ s,
131
+ `${s.field.id}-${s.value}`
132
+ )
133
+ ),
134
+ groups: []
135
+ }
136
+ ]
137
+ }))
138
+ };
139
+ }
140
+ function Qe(e) {
141
+ const t = $e(e);
142
+ return t.status === "unresolved" ? {} : t.values;
143
+ }
144
+ function vi(e) {
145
+ const t = $e(e);
146
+ return t.status === "unresolved" ? t : { status: "resolved", uncaptured: t.cleared };
147
+ }
148
+ function $e({
149
+ dashboard: e,
150
+ dashboardInputValues: t,
151
+ sheetId: n,
152
+ cardId: o
153
+ }) {
154
+ let i = M(
155
+ t || {}
156
+ );
157
+ const s = [], r = Gn({
158
+ dashboard: e,
159
+ sheetId: n,
160
+ cardId: o
161
+ });
162
+ if (r.status === "unresolved")
163
+ return { status: "unresolved" };
164
+ i = _n({
165
+ dashboardInputValues: i,
166
+ savedSheetId: n,
167
+ cardId: o,
168
+ targets: r.targets
169
+ });
170
+ for (const a of r.targets) {
171
+ const c = wt(
172
+ Pt({
173
+ dashboard: e,
174
+ card: a.card
175
+ }).allInputs
176
+ ).filter(
177
+ (d) => Et(d, a) && W(d, a)
178
+ );
179
+ for (const d of c) {
180
+ const l = Rt(
181
+ i,
182
+ d,
183
+ a
184
+ ), u = Me(
185
+ d,
186
+ l
187
+ );
188
+ if (u && u !== l && (i = R(
189
+ i,
190
+ d,
191
+ a,
192
+ u
193
+ )), !u || u.status === void 0) {
194
+ i = R(
195
+ i,
196
+ d,
197
+ a,
198
+ {
199
+ status: "cleared",
200
+ comparisonSelection: u == null ? void 0 : u.comparisonSelection
201
+ }
202
+ ), s.push({
203
+ input: d,
204
+ target: {
205
+ sheetId: a.sheetId,
206
+ cardId: a.cardId,
207
+ sectionId: a.sectionId
208
+ }
209
+ });
210
+ continue;
211
+ }
212
+ u.status === "set" && qt(d) && !u.comparisonSelection && (i = R(
213
+ i,
214
+ d,
215
+ a,
216
+ {
217
+ ...u,
218
+ comparisonSelection: { mode: "off" }
219
+ }
220
+ ));
221
+ }
222
+ }
223
+ return {
224
+ status: "resolved",
225
+ values: M(i),
226
+ cleared: s
227
+ };
228
+ }
229
+ function _n({
230
+ dashboardInputValues: e,
231
+ savedSheetId: t,
232
+ cardId: n,
233
+ targets: o
234
+ }) {
235
+ var c, d, l, u;
236
+ const i = {}, s = new Set(
237
+ o.flatMap((f) => f.sheetId ? [f.sheetId] : [])
238
+ ), r = new Set(
239
+ o.flatMap((f) => f.cardId ? [f.cardId] : [])
240
+ ), a = new Set(
241
+ o.flatMap((f) => f.sectionId ? [f.sectionId] : [])
242
+ );
243
+ if (e.shared && (i.shared = { ...e.shared }), n) {
244
+ const f = o[0], p = (t ? (c = e.bySheetId) == null ? void 0 : c[t] : void 0) ?? (f.sheetId ? (d = e.bySheetId) == null ? void 0 : d[f.sheetId] : void 0);
245
+ f.sheetId && p && (i.bySheetId = {
246
+ [f.sheetId]: { ...p }
247
+ });
248
+ const m = f.cardId ? (l = e.byCardId) == null ? void 0 : l[f.cardId] : void 0;
249
+ f.cardId && m && (i.byCardId = {
250
+ [f.cardId]: { ...m }
251
+ });
252
+ const b = Object.entries(
253
+ e.byDocumentSectionId || {}
254
+ ), I = (f.sectionId ? (u = e.byDocumentSectionId) == null ? void 0 : u[f.sectionId] : void 0) ?? (b.length === 1 ? b[0][1] : void 0);
255
+ return f.sectionId && I && (i.byDocumentSectionId = {
256
+ [f.sectionId]: { ...I }
257
+ }), M(i);
258
+ }
259
+ return i.bySheetId = J(
260
+ e.bySheetId,
261
+ s
262
+ ), i.byCardId = J(
263
+ e.byCardId,
264
+ r
265
+ ), i.byDocumentSectionId = J(
266
+ e.byDocumentSectionId,
267
+ a
268
+ ), M(i);
269
+ }
270
+ function J(e, t) {
271
+ if (!e) return;
272
+ const n = Object.entries(e).filter(
273
+ ([o]) => t.has(o)
274
+ );
275
+ return n.length > 0 ? Object.fromEntries(
276
+ n.map(([o, i]) => [
277
+ o,
278
+ { ...i }
279
+ ])
280
+ ) : void 0;
281
+ }
282
+ function Gn({
283
+ dashboard: e,
284
+ sheetId: t,
285
+ cardId: n
286
+ }) {
287
+ var r;
288
+ if (n) {
289
+ const a = Ln(e, n);
290
+ return a ? {
291
+ status: "resolved",
292
+ targets: [a]
293
+ } : { status: "unresolved", targetKind: "card" };
294
+ }
295
+ const o = (e.sheets || []).filter(
296
+ (a) => !t || a.id === t
297
+ );
298
+ if (t && o.length === 0)
299
+ return { status: "unresolved", targetKind: "sheet" };
300
+ const i = o.map(
301
+ (a) => ({
302
+ sheetId: a.id,
303
+ sheetKind: a.kind || "dashboard"
304
+ })
305
+ ), s = new Set(o.map((a) => a.id));
306
+ for (const a of q(e))
307
+ s.has(a.sheet.id) && i.push({
308
+ sheetId: a.sheet.id,
309
+ cardId: a.card.id,
310
+ card: a.card,
311
+ sheetKind: a.sheet.kind || "dashboard"
312
+ });
313
+ for (const a of o)
314
+ if (a.kind === "document")
315
+ for (const c of ((r = a.document) == null ? void 0 : r.sections) || []) {
316
+ const d = de(c);
317
+ d.length === 0 && i.push({
318
+ sheetId: a.id,
319
+ sectionId: c.id,
320
+ sheetKind: "document"
321
+ });
322
+ for (const l of d)
323
+ i.push({
324
+ sheetId: a.id,
325
+ sectionId: c.id,
326
+ cardId: l.id,
327
+ card: l,
328
+ sheetKind: "document"
329
+ });
330
+ }
331
+ return {
332
+ status: "resolved",
333
+ targets: i.length > 0 ? i : [{}]
334
+ };
335
+ }
336
+ function Ln(e, t) {
337
+ var o;
338
+ const n = ee(e, t);
339
+ if (n)
340
+ return {
341
+ sheetId: n.sheet.id,
342
+ cardId: n.card.id,
343
+ card: n.card,
344
+ sheetKind: n.sheet.kind || "dashboard"
345
+ };
346
+ for (const i of e.sheets || [])
347
+ if (i.kind === "document")
348
+ for (const s of ((o = i.document) == null ? void 0 : o.sections) || []) {
349
+ const r = de(s).find(
350
+ (a) => a.id === t
351
+ );
352
+ if (r)
353
+ return {
354
+ sheetId: i.id,
355
+ sectionId: s.id,
356
+ cardId: r.id,
357
+ card: r,
358
+ sheetKind: "document"
359
+ };
360
+ }
361
+ }
362
+ function yi({
363
+ dashboardInputValues: e,
364
+ dashboard: t,
365
+ filterValues: n,
366
+ sheetId: o,
367
+ cardId: i,
368
+ sectionId: s,
369
+ sheetKind: r
370
+ }) {
371
+ var d, l, u;
372
+ if (!((d = t.inputs) != null && d.length))
373
+ return e;
374
+ const a = new Map(
375
+ n.map((f) => [f.filterId, f])
376
+ );
377
+ let c = e || {};
378
+ for (const f of t.inputs) {
379
+ if (f.kind !== "filter" || !W(f, {
380
+ sheetId: o,
381
+ cardId: i,
382
+ sectionId: s,
383
+ sheetKind: r
384
+ }))
385
+ continue;
386
+ const p = ((l = f.filter) == null ? void 0 : l.id) || ((u = f.filterReference) == null ? void 0 : u.filterId);
387
+ if (!p) continue;
388
+ const m = a.get(p), b = m ? Ot(m) : void 0, I = (b == null ? void 0 : b.status) === "set" ? b : { status: "cleared" };
389
+ c = xt(
390
+ c,
391
+ f,
392
+ { sheetId: o, cardId: i, sectionId: s },
393
+ I
394
+ );
395
+ }
396
+ return c;
397
+ }
398
+ function N({
399
+ dashboard: e,
400
+ sheetId: t,
401
+ card: n,
402
+ sectionId: o,
403
+ sheetKind: i,
404
+ mode: s,
405
+ runtimeValues: r,
406
+ transientContexts: a,
407
+ generatedAt: c,
408
+ calendar: d
409
+ }) {
410
+ const l = Yn({
411
+ dashboard: e,
412
+ sheetId: t,
413
+ card: n,
414
+ sectionId: o,
415
+ sheetKind: i,
416
+ runtimeValues: r,
417
+ calendar: d
418
+ });
419
+ return {
420
+ context: l,
421
+ snapshot: {
422
+ ...t ? { sheetId: t } : {},
423
+ ...n != null && n.id ? { cardId: n.id } : {},
424
+ mode: s,
425
+ dashboardInputValues: Un(
426
+ Wn({
427
+ inputs: l.inputs,
428
+ context: l,
429
+ sheetId: t,
430
+ cardId: n == null ? void 0 : n.id,
431
+ sectionId: o
432
+ }),
433
+ r.dashboardInputValues
434
+ ),
435
+ ...Ue(r.cardViewState, {
436
+ cardId: n == null ? void 0 : n.id,
437
+ sheetKind: i
438
+ }),
439
+ ...We(a, { sheetKind: i }),
440
+ generatedAt: c,
441
+ timezone: d == null ? void 0 : d.tz
442
+ }
443
+ };
444
+ }
445
+ function Hn({
446
+ sheetIds: e,
447
+ sheetKind: t = "dashboard",
448
+ ...n
449
+ }) {
450
+ var a;
451
+ const o = e.map(
452
+ (c) => N({
453
+ ...n,
454
+ sheetId: c,
455
+ sheetKind: t
456
+ })
457
+ ), i = e.flatMap(
458
+ (c) => Kn(n.dashboard, c).map(
459
+ (d) => N({
460
+ ...n,
461
+ sheetId: c,
462
+ card: d,
463
+ sheetKind: t
464
+ })
465
+ )
466
+ ), s = o[0] || i[0] || N({
467
+ ...n,
468
+ sheetKind: t
469
+ }), r = Ye(
470
+ ...o.map(
471
+ (c) => c.snapshot.dashboardInputValues
472
+ ),
473
+ ...i.map(
474
+ (c) => c.snapshot.dashboardInputValues
475
+ )
476
+ );
477
+ return {
478
+ context: s.context,
479
+ snapshot: {
480
+ ...e.length === 1 ? { sheetId: e[0] } : {},
481
+ mode: n.mode,
482
+ dashboardInputValues: r,
483
+ ...Ue(n.runtimeValues.cardViewState, { sheetKind: t }),
484
+ ...We(n.transientContexts, { sheetKind: t }),
485
+ generatedAt: n.generatedAt,
486
+ timezone: (a = n.calendar) == null ? void 0 : a.tz
487
+ }
488
+ };
489
+ }
490
+ function Kn(e, t) {
491
+ var r;
492
+ const n = (r = e.sheets) == null ? void 0 : r.find((a) => a.id === t), o = [], i = /* @__PURE__ */ new Set(), s = (a) => {
493
+ !(a != null && a.id) || i.has(a.id) || (i.add(a.id), o.push(a));
494
+ };
495
+ for (const a of (n == null ? void 0 : n.cards) || [])
496
+ s(a);
497
+ for (const a of (n == null ? void 0 : n.frames) || [])
498
+ for (const c of (a == null ? void 0 : a.cards) || [])
499
+ s(c);
500
+ return o;
501
+ }
502
+ function Qn({
503
+ sectionIds: e,
504
+ ...t
505
+ }) {
506
+ const n = N(t), o = e.map(
507
+ (s) => N({
508
+ ...t,
509
+ sectionId: s
510
+ })
511
+ ), i = $n(
512
+ t.dashboard,
513
+ t.sheetId,
514
+ e
515
+ ).map(
516
+ ({ sectionId: s, card: r }) => N({
517
+ ...t,
518
+ sectionId: s,
519
+ card: r
520
+ })
521
+ );
522
+ return {
523
+ ...n,
524
+ snapshot: {
525
+ ...n.snapshot,
526
+ dashboardInputValues: Ye(
527
+ n.snapshot.dashboardInputValues,
528
+ ...o.map(
529
+ (s) => s.snapshot.dashboardInputValues
530
+ ),
531
+ ...i.map(
532
+ (s) => s.snapshot.dashboardInputValues
533
+ )
534
+ )
535
+ }
536
+ };
537
+ }
538
+ function $n(e, t, n) {
539
+ var s, r;
540
+ const o = new Set(n), i = (s = e.sheets) == null ? void 0 : s.find((a) => a.id === t);
541
+ return (((r = i == null ? void 0 : i.document) == null ? void 0 : r.sections) || []).flatMap(
542
+ (a) => a.id && o.has(a.id) ? de(a).map((c) => ({
543
+ sectionId: a.id,
544
+ card: c
545
+ })) : []
546
+ );
547
+ }
548
+ function Un(e, t) {
549
+ let n = e;
550
+ for (const o of Object.keys((t == null ? void 0 : t.shared) ?? {})) {
551
+ const i = le(o), s = i ? kt(t, i) : void 0;
552
+ !i || !s || (n = R(
553
+ n,
554
+ Tt(i),
555
+ Mt,
556
+ { status: "set", value: { kind: "selection", selection: s } }
557
+ ));
558
+ }
559
+ return n;
560
+ }
561
+ function Ue(e, t) {
562
+ if (t.sheetKind === "document") return {};
563
+ const n = Bn(
564
+ e,
565
+ t.cardId ? /* @__PURE__ */ new Set([t.cardId]) : void 0
566
+ );
567
+ return n ? { cardViewState: n } : {};
568
+ }
569
+ function We(e, t) {
570
+ return t.sheetKind === "document" || !(e != null && e.length) ? {} : { transientContexts: [...e] };
571
+ }
572
+ function Wn({
573
+ inputs: e,
574
+ context: t,
575
+ sheetId: n,
576
+ cardId: o,
577
+ sectionId: i
578
+ }) {
579
+ const s = new Map(
580
+ t.resolvedInputs.map((a) => [
581
+ a.id,
582
+ a
583
+ ])
584
+ );
585
+ let r = {};
586
+ for (const a of e) {
587
+ const c = s.get(a.id), d = Me(a, c == null ? void 0 : c.slot) || { status: "cleared" };
588
+ r = R(
589
+ r,
590
+ a,
591
+ { sheetId: n, cardId: o, sectionId: i },
592
+ d
593
+ );
594
+ }
595
+ return M(r);
596
+ }
597
+ function Yn({
598
+ dashboard: e,
599
+ sheetId: t,
600
+ card: n,
601
+ sectionId: o,
602
+ sheetKind: i,
603
+ runtimeValues: s,
604
+ calendar: r
605
+ }) {
606
+ return oe({
607
+ // See `carryTransientContexts`: the snapshot's values are the dashboard's
608
+ // own, and carried contexts travel beside them.
609
+ transientContexts: void 0,
610
+ dashboard: e,
611
+ sheetId: t,
612
+ card: n,
613
+ sectionId: o,
614
+ sheetKind: i,
615
+ runtimeValues: s,
616
+ calendar: r
617
+ });
618
+ }
619
+ function Ye(...e) {
620
+ const t = {};
621
+ for (const n of e)
622
+ n.shared && (t.shared = {
623
+ ...t.shared,
624
+ ...n.shared
625
+ }), X(t, "bySheetId", n.bySheetId), X(t, "byCardId", n.byCardId), X(
626
+ t,
627
+ "byDocumentSectionId",
628
+ n.byDocumentSectionId
629
+ );
630
+ return M(t);
631
+ }
632
+ function X(e, t, n) {
633
+ if (n) {
634
+ e[t] || (e[t] = {});
635
+ for (const [o, i] of Object.entries(n))
636
+ e[t][o] = {
637
+ ...e[t][o],
638
+ ...i
639
+ };
640
+ }
641
+ }
642
+ function _(e) {
643
+ const t = M(e ?? {}), n = [];
644
+ for (const [o, i] of Object.entries(t.shared ?? {}))
645
+ n.push({ scope: "shared", target: null, inputId: o, slot: i });
646
+ for (const o of ["bySheetId", "byCardId"])
647
+ for (const [i, s] of Object.entries(t[o] ?? {}))
648
+ for (const [r, a] of Object.entries(s))
649
+ n.push({ scope: o, target: i, inputId: r, slot: a });
650
+ return n;
651
+ }
652
+ function U(e, t, n) {
653
+ const o = e;
654
+ if (t.scope === "shared") {
655
+ o.shared = { ...o.shared, [t.inputId]: n };
656
+ return;
657
+ }
658
+ const i = { ...o[t.scope] ?? {} };
659
+ i[t.target] = { ...i[t.target], [t.inputId]: n }, o[t.scope] = i;
660
+ }
661
+ function Ze(e, t, n) {
662
+ const o = Te(
663
+ e,
664
+ t.controlOverrides,
665
+ { hasExplicitRuntimeOverrides: t.controlOverrides !== void 0 }
666
+ );
667
+ return {
668
+ adHocFilterValues: [...t.adHocFilterValues],
669
+ controlValues: o.dashboardControlValues,
670
+ cardControlValuesMap: o.cardControlValuesMap,
671
+ dashboardInputValues: t.dashboardInputValues,
672
+ inlineFilterValuesMap: t.inlineFilterValuesMap ?? fe(e, n)
673
+ };
674
+ }
675
+ function pe(e, t, n) {
676
+ return Je(
677
+ e,
678
+ Ze(e, t, n),
679
+ n
680
+ );
681
+ }
682
+ function Di(e, t, n) {
683
+ return Je(e, t, n);
684
+ }
685
+ function Je(e, t, n) {
686
+ const o = e.sheets ?? [], i = o.filter((a) => (a.kind ?? "dashboard") === "dashboard").map((a) => a.id), s = o.filter((a) => a.kind === "document"), r = i.length ? Hn({
687
+ dashboard: e,
688
+ sheetIds: i,
689
+ mode: "dashboard",
690
+ runtimeValues: t,
691
+ transientContexts: void 0,
692
+ calendar: n ?? null
693
+ }).snapshot.dashboardInputValues : {};
694
+ return s.reduce(
695
+ (a, c) => {
696
+ var d;
697
+ return se(
698
+ a,
699
+ Qn({
700
+ dashboard: e,
701
+ sheetId: c.id,
702
+ sheetKind: "document",
703
+ mode: "document",
704
+ sectionIds: (((d = c.document) == null ? void 0 : d.sections) ?? []).map(
705
+ (l) => l.id
706
+ ),
707
+ runtimeValues: t,
708
+ transientContexts: void 0,
709
+ calendar: n ?? null
710
+ }).snapshot.dashboardInputValues
711
+ );
712
+ },
713
+ r
714
+ );
715
+ }
716
+ function Xe(e, t) {
717
+ const n = {}, o = {}, i = /* @__PURE__ */ new Map();
718
+ for (const s of _(t)) {
719
+ const r = e.get(s.inputId), { slot: a } = s, c = () => a.status === "set" && a.value.kind === "filter" ? a.value.filterValue : a.status === "cleared" ? null : void 0;
720
+ if ((r == null ? void 0 : r.source) === "cardInlineFilter") {
721
+ const d = c();
722
+ if (d !== void 0) {
723
+ const l = i.get(r.cardId) ?? /* @__PURE__ */ new Map();
724
+ l.set(r.filterId, d), i.set(r.cardId, l);
725
+ }
726
+ } else if ((r == null ? void 0 : r.source) === "dashboardControl" || (r == null ? void 0 : r.source) === "cardControl")
727
+ a.status === "set" && a.value.kind === "control" ? o[r.controlId] = a.value.value : a.status === "cleared" && (o[r.controlId] = void 0);
728
+ else {
729
+ U(n, s, a);
730
+ continue;
731
+ }
732
+ a.comparisonSelection && U(n, s, {
733
+ comparisonSelection: a.comparisonSelection
734
+ });
735
+ }
736
+ return {
737
+ runtime: M(n),
738
+ controlValues: o,
739
+ inlineFilterValues: i
740
+ };
741
+ }
742
+ function Zn(e, t) {
743
+ if (!t.size) return [...e];
744
+ const n = e.filter((i) => !t.has(i.filterId)), o = [...t.values()].filter(
745
+ (i) => i !== null
746
+ );
747
+ return At(n, o);
748
+ }
749
+ function et(e, t, n) {
750
+ if (!Object.keys(n).length) return t;
751
+ const o = Te(
752
+ e,
753
+ t,
754
+ { hasExplicitRuntimeOverrides: t !== void 0 }
755
+ );
756
+ return {
757
+ ...Bt({
758
+ dashboardValues: o.dashboardControlValues,
759
+ cardValuesMap: o.cardControlValuesMap
760
+ }),
761
+ ...n
762
+ };
763
+ }
764
+ function Jn(e, t) {
765
+ if (!t.size) return;
766
+ const n = Object.fromEntries(
767
+ Object.entries(e).map(([o, i]) => [o, [...i]])
768
+ );
769
+ for (const [o, i] of t)
770
+ n[o] = Zn(n[o] ?? [], i);
771
+ return n;
772
+ }
773
+ function Xn(e, t, n) {
774
+ const o = new Map(
775
+ q(e).map(({ card: r }) => [
776
+ r.id,
777
+ new Map((r.inlineFilters ?? []).map((a) => [a.id, a]))
778
+ ])
779
+ );
780
+ let i = !1;
781
+ const s = Object.fromEntries(
782
+ Object.entries(t).map(([r, a]) => [r, [...a]])
783
+ );
784
+ for (const [r, a] of Object.entries(n)) {
785
+ const c = o.get(r), d = (a ?? []).filter((l) => {
786
+ const u = c == null ? void 0 : c.get(l.filterId);
787
+ return u ? ie(u, l) : !1;
788
+ });
789
+ Y(d, s[r] ?? []) || (i = !0), s[r] = d;
790
+ }
791
+ return i ? s : void 0;
792
+ }
793
+ const eo = ["bySheetId", "byCardId", "byDocumentSectionId"];
794
+ function to(e, t) {
795
+ const n = Z(e);
796
+ let o = !1;
797
+ const i = (r) => {
798
+ if (!r) return r;
799
+ const a = Object.entries(r).filter(([c, d]) => {
800
+ var u;
801
+ if (d.status !== "set" || d.value.kind !== "filter") return !0;
802
+ const l = (u = n.findFilterInput({ inputId: c })) == null ? void 0 : u.input.filter;
803
+ return !l || ie(l, d.value.filterValue) ? !0 : (o = !0, !1);
804
+ });
805
+ return Object.fromEntries(a);
806
+ }, s = {
807
+ ...t,
808
+ ...t.shared ? { shared: i(t.shared) } : {}
809
+ };
810
+ for (const r of eo) {
811
+ const a = t[r];
812
+ a && (s[r] = Object.fromEntries(
813
+ Object.entries(a).map(([c, d]) => [c, i(d) ?? {}])
814
+ ));
815
+ }
816
+ return o ? s : t;
817
+ }
818
+ function no(e) {
819
+ var t, n;
820
+ return ((n = (t = e.sheets) == null ? void 0 : t[0]) == null ? void 0 : n.id) ?? null;
821
+ }
822
+ function L(e, t) {
823
+ var n;
824
+ return !!t && !!((n = e.sheets) != null && n.some((o) => o.id === t));
825
+ }
826
+ function Fi(e) {
827
+ const { dashboard: t, host: n, calendar: o } = e, i = Oe(t, n.filterValues, {
828
+ calendar: o
829
+ }).slots, s = n.controlValues, r = L(t, n.selectedSheetId) ? n.selectedSheetId : no(t);
830
+ return {
831
+ hostInputValues: i,
832
+ controlOverrides: s,
833
+ selectedSheetId: r,
834
+ hostSelectedSheetId: n.selectedSheetId ?? null,
835
+ materializedInputs: e.materializeInputs === !1 ? {} : pe(
836
+ t,
837
+ {
838
+ adHocFilterValues: [],
839
+ controlOverrides: s,
840
+ dashboardInputValues: i
841
+ },
842
+ o
843
+ )
844
+ };
845
+ }
846
+ function tt(e) {
847
+ const t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map();
848
+ for (const i of re(e))
849
+ i.kind === "filter" && i.filter ? t.set(i.id, i.filter) : i.kind === "control" && n.add(i.id), i.compatibility && o.set(i.id, i.compatibility);
850
+ return { filterInputs: t, controlInputIds: n, compatibility: o };
851
+ }
852
+ function nt(e, t) {
853
+ const n = le(t);
854
+ if (!n) return;
855
+ const o = G(e, n);
856
+ return o ? Nt(o, e) ? "applies" : "not-eligible" : "removed";
857
+ }
858
+ function Si(e, t) {
859
+ const n = nt(e, t);
860
+ return n ? n === "applies" : re(e).some(
861
+ (o) => o.id === t
862
+ );
863
+ }
864
+ function ot(e, t, n, o) {
865
+ if (!n) return {};
866
+ const i = new Set((e.sheets ?? []).map((d) => d.id)), s = new Set(
867
+ q(e).map(({ card: d }) => d.id)
868
+ ), r = Z(e), a = (d) => {
869
+ var u;
870
+ if (!d) return;
871
+ const l = {};
872
+ for (const [f, p] of Object.entries(d)) {
873
+ const m = t.filterInputs.has(f) || t.controlInputIds.has(f) ? f : ((u = r.findFilterInput({ inputId: f })) == null ? void 0 : u.input.id) ?? f;
874
+ if (m !== f && d[m]) continue;
875
+ const b = nt(e, m);
876
+ if (b) {
877
+ if (b !== "applies") {
878
+ o.push({
879
+ kind: "setting-no-longer-applies",
880
+ target: "selection",
881
+ id: m,
882
+ reason: b
883
+ });
884
+ continue;
885
+ }
886
+ l[m] = p;
887
+ continue;
888
+ }
889
+ const I = t.filterInputs.get(m);
890
+ if (!I && !t.controlInputIds.has(m)) {
891
+ o.push({
892
+ kind: "setting-no-longer-applies",
893
+ target: "input",
894
+ id: m,
895
+ reason: "removed"
896
+ });
897
+ continue;
898
+ }
899
+ if (I && p.status === "set" && p.value.kind === "filter" && !ie(I, p.value.filterValue)) {
900
+ o.push({
901
+ kind: "setting-no-longer-applies",
902
+ target: "input",
903
+ id: m,
904
+ reason: "incompatible"
905
+ });
906
+ continue;
907
+ }
908
+ l[m] = p;
909
+ }
910
+ return Object.keys(l).length ? l : void 0;
911
+ }, c = (d, l) => {
912
+ if (!d) return;
913
+ const u = {};
914
+ for (const [f, p] of Object.entries(d)) {
915
+ if (!l(f)) {
916
+ for (const b of Object.keys(p))
917
+ o.push({
918
+ kind: "setting-no-longer-applies",
919
+ target: "input",
920
+ id: b,
921
+ reason: "removed"
922
+ });
923
+ continue;
924
+ }
925
+ const m = a(p);
926
+ m && (u[f] = m);
927
+ }
928
+ return u;
929
+ };
930
+ return M({
931
+ shared: a(n.shared),
932
+ bySheetId: c(n.bySheetId, (d) => i.has(d)),
933
+ byCardId: c(n.byCardId, (d) => s.has(d))
934
+ // Document sections are not viewer state.
935
+ });
936
+ }
937
+ function V(e, t, n, o = {}) {
938
+ const i = new Map(
939
+ q(e).map(({ card: r }) => [r.id, r])
940
+ ), s = {};
941
+ for (const [r, a] of Object.entries(t ?? {})) {
942
+ const c = i.get(r);
943
+ if (c && Cn(c)) {
944
+ vn(a) || (s[r] = a);
945
+ continue;
946
+ }
947
+ if (c && o.sessionSorts && yn(c)) {
948
+ a.sort && (s[r] = { sort: a.sort });
949
+ continue;
950
+ }
951
+ n == null || n.push({
952
+ kind: "setting-no-longer-applies",
953
+ target: "card",
954
+ id: r,
955
+ reason: G(e, r) ? "not-eligible" : "removed"
956
+ });
957
+ }
958
+ return s;
959
+ }
960
+ function oo(e, t, n) {
961
+ if (t) {
962
+ if (L(e, t)) return t;
963
+ n.push({
964
+ kind: "setting-no-longer-applies",
965
+ target: "sheet",
966
+ id: t,
967
+ reason: "removed"
968
+ });
969
+ }
970
+ }
971
+ const me = (e, t) => Y(e ?? null, t ?? null);
972
+ function it(e) {
973
+ return {
974
+ adHocFilterValues: e.adHocFilterValues,
975
+ controlOverrides: e.controlOverrides,
976
+ dashboardInputValues: e.dashboardInputValues,
977
+ ...e.inlineFilterValuesMap ? { inlineFilterValuesMap: e.inlineFilterValuesMap } : {},
978
+ selectedSheetId: e.selectedSheetId,
979
+ tableSettings: e.tableSettings
980
+ };
981
+ }
982
+ function K(e, t) {
983
+ return {
984
+ adHocFilterValues: [],
985
+ controlOverrides: e.controlOverrides,
986
+ dashboardInputValues: e.hostInputValues,
987
+ selectedSheetId: e.selectedSheetId,
988
+ tableSettings: t
989
+ };
990
+ }
991
+ function st(e, t) {
992
+ const n = t.dashboardInputValues === e.baseline.hostInputValues && !t.inlineFilterValuesMap && !t.adHocFilterValues.length && t.controlOverrides === e.baseline.controlOverrides;
993
+ return {
994
+ selectedSheetId: t.selectedSheetId,
995
+ // Overlay: the bookmark's values on the baseline's runtime values.
996
+ inputs: n ? e.baseline.materializedInputs : pe(e.dashboard, t, e.calendar),
997
+ tableSettings: t.tableSettings
998
+ };
999
+ }
1000
+ function A(e, t) {
1001
+ const n = it(t), o = t.restore ?? n;
1002
+ return {
1003
+ ...n,
1004
+ appliedBookmarkId: t.appliedBookmarkId,
1005
+ rememberedWrites: t.rememberedWrites ?? [],
1006
+ notices: t.notices ?? [],
1007
+ opened: st(e, o),
1008
+ restore: o
1009
+ };
1010
+ }
1011
+ function De(e, t, n, o) {
1012
+ const { dashboard: i, baseline: s } = e, r = [], a = He(t.state, ce), c = a.ok ? a.value : {};
1013
+ for (const m of a.ok ? a.issues : [])
1014
+ r.push(io(m));
1015
+ const d = tt(i), l = Xe(
1016
+ d.compatibility,
1017
+ ot(i, d, c.inputs, r)
1018
+ ), u = oo(i, c.selectedSheetId, r) ?? s.selectedSheetId, f = V(
1019
+ i,
1020
+ c.tableSettings,
1021
+ r
1022
+ ), p = V(
1023
+ i,
1024
+ n,
1025
+ void 0
1026
+ );
1027
+ return A(e, {
1028
+ appliedBookmarkId: t.id,
1029
+ // A bookmark opens without ad-hoc values, as today (P4a-02 f).
1030
+ adHocFilterValues: [],
1031
+ controlOverrides: et(
1032
+ i,
1033
+ s.controlOverrides,
1034
+ l.controlValues
1035
+ ),
1036
+ // Overlay, never replacement: the bookmark's slots over the host's.
1037
+ dashboardInputValues: se(
1038
+ s.hostInputValues,
1039
+ l.runtime
1040
+ ),
1041
+ ...rt(
1042
+ Jn(
1043
+ fe(i, e.calendar),
1044
+ l.inlineFilterValues
1045
+ )
1046
+ ),
1047
+ selectedSheetId: u,
1048
+ tableSettings: o.writeRemembered ? { ...p, ...f } : (
1049
+ // A default bookmark on load: remembered settings per card win.
1050
+ { ...f, ...p }
1051
+ ),
1052
+ rememberedWrites: o.writeRemembered ? Object.entries(f).filter(
1053
+ ([m, b]) => !me(p[m], b)
1054
+ ).map(([m, b]) => ({
1055
+ kind: "set",
1056
+ cardId: m,
1057
+ settings: b
1058
+ })) : [],
1059
+ notices: r
1060
+ });
1061
+ }
1062
+ function io(e) {
1063
+ return {
1064
+ kind: "setting-no-longer-applies",
1065
+ target: e.target,
1066
+ id: e.id,
1067
+ reason: "invalid"
1068
+ };
1069
+ }
1070
+ function rt(e) {
1071
+ return e ? { inlineFilterValuesMap: e } : {};
1072
+ }
1073
+ function Fe(e, t, n) {
1074
+ const { dashboard: o, baseline: i } = e;
1075
+ return {
1076
+ // A reload in place keeps ad-hoc values, as today (P4a-02 f), unless the
1077
+ // template now defines a filter with that id.
1078
+ adHocFilterValues: t.adHocFilterValues.filter(
1079
+ (s) => !Z(o).findFilterInput({ filterId: s.filterId })
1080
+ ),
1081
+ // A host's new control defaults are the baseline's, not the viewer's.
1082
+ controlOverrides: n.controlsChanged ? i.controlOverrides : t.controlOverrides,
1083
+ // Live slots stay, except a filter value this template no longer accepts:
1084
+ // that filter loads its new default, as the old list did. The resolver
1085
+ // ignores slots this template no longer has.
1086
+ dashboardInputValues: to(
1087
+ o,
1088
+ t.dashboardInputValues
1089
+ ),
1090
+ ...rt(
1091
+ Xn(
1092
+ o,
1093
+ fe(o, e.calendar),
1094
+ t.inlineFilterValuesMap ?? {}
1095
+ )
1096
+ ),
1097
+ selectedSheetId: !n.sheetChanged && L(o, t.selectedSheetId) ? t.selectedSheetId : i.selectedSheetId,
1098
+ tableSettings: V(
1099
+ o,
1100
+ t.tableSettings,
1101
+ void 0,
1102
+ { sessionSorts: !0 }
1103
+ )
1104
+ };
1105
+ }
1106
+ function Vi(e) {
1107
+ const { dashboard: t, baseline: n, event: o } = e, i = e.rememberedTableSettings;
1108
+ switch (o.kind) {
1109
+ case "initial-load":
1110
+ return o.defaultBookmark ? De(e, o.defaultBookmark, i, {
1111
+ writeRemembered: !1
1112
+ }) : A(e, {
1113
+ appliedBookmarkId: null,
1114
+ ...K(
1115
+ n,
1116
+ V(t, i, void 0, {
1117
+ sessionSorts: o.captured
1118
+ })
1119
+ )
1120
+ });
1121
+ case "refetch": {
1122
+ const { live: s } = o, r = s.applied, a = {
1123
+ sheetChanged: !!s.previousBaseline && s.previousBaseline.hostSelectedSheetId !== n.hostSelectedSheetId,
1124
+ controlsChanged: !!s.previousBaseline && !Y(
1125
+ s.previousBaseline.controlOverrides ?? null,
1126
+ n.controlOverrides ?? null
1127
+ )
1128
+ }, c = Fe(
1129
+ e,
1130
+ {
1131
+ adHocFilterValues: s.adHocFilterValues,
1132
+ controlOverrides: s.controlValues ?? n.controlOverrides,
1133
+ dashboardInputValues: s.dashboardInputValues,
1134
+ inlineFilterValuesMap: s.inlineFilterValuesMap,
1135
+ selectedSheetId: s.selectedSheetId,
1136
+ tableSettings: s.tableSettings
1137
+ },
1138
+ a
1139
+ ), d = r ? Fe(e, r.restore, a) : K(
1140
+ n,
1141
+ V(t, i, void 0)
1142
+ );
1143
+ return A(e, {
1144
+ appliedBookmarkId: (r == null ? void 0 : r.appliedBookmarkId) ?? null,
1145
+ ...c,
1146
+ notices: (r == null ? void 0 : r.notices) ?? [],
1147
+ restore: d
1148
+ });
1149
+ }
1150
+ case "open-bookmark":
1151
+ return De(e, o.bookmark, i, {
1152
+ writeRemembered: !0
1153
+ });
1154
+ case "open-default-view":
1155
+ return A(e, {
1156
+ appliedBookmarkId: null,
1157
+ ...K(
1158
+ n,
1159
+ V(t, i, void 0)
1160
+ )
1161
+ });
1162
+ case "reset-to-default-view":
1163
+ return A(e, {
1164
+ appliedBookmarkId: null,
1165
+ ...K(n, {}),
1166
+ rememberedWrites: [{ kind: "clear-all" }]
1167
+ });
1168
+ case "discard-changes": {
1169
+ const { restore: s } = o.applied, r = V(
1170
+ t,
1171
+ s.tableSettings,
1172
+ void 0,
1173
+ { sessionSorts: !0 }
1174
+ ), a = V(t, r, void 0), c = V(t, i, void 0), d = [];
1175
+ for (const l of /* @__PURE__ */ new Set([
1176
+ ...Object.keys(c),
1177
+ ...Object.keys(a)
1178
+ ])) {
1179
+ if (me(c[l], a[l])) continue;
1180
+ const u = a[l];
1181
+ d.push(
1182
+ u ? { kind: "set", cardId: l, settings: u } : { kind: "clear", cardId: l }
1183
+ );
1184
+ }
1185
+ return A(e, {
1186
+ appliedBookmarkId: o.applied.appliedBookmarkId,
1187
+ ...s,
1188
+ selectedSheetId: L(t, s.selectedSheetId) ? s.selectedSheetId : n.selectedSheetId,
1189
+ tableSettings: r,
1190
+ rememberedWrites: d,
1191
+ notices: o.applied.notices,
1192
+ restore: s
1193
+ });
1194
+ }
1195
+ }
1196
+ }
1197
+ function ki(e) {
1198
+ const { dashboard: t, calendar: n } = e, o = e.hostControlValues, i = {
1199
+ ...e.baseline,
1200
+ controlOverrides: o,
1201
+ materializedInputs: pe(
1202
+ t,
1203
+ {
1204
+ adHocFilterValues: [],
1205
+ controlOverrides: o,
1206
+ dashboardInputValues: e.baseline.hostInputValues
1207
+ },
1208
+ n
1209
+ )
1210
+ };
1211
+ let s = o;
1212
+ if (e.appliedBookmark) {
1213
+ const c = He(
1214
+ e.appliedBookmark.state,
1215
+ ce
1216
+ ), d = tt(t), l = Xe(
1217
+ d.compatibility,
1218
+ ot(
1219
+ t,
1220
+ d,
1221
+ c.ok ? c.value.inputs : void 0,
1222
+ []
1223
+ )
1224
+ ).controlValues;
1225
+ s = et(t, o, l);
1226
+ }
1227
+ const r = e.applied;
1228
+ if (!r) return { baseline: i, controlOverrides: s, applied: null };
1229
+ const a = { ...r.restore, controlOverrides: s };
1230
+ return {
1231
+ baseline: i,
1232
+ controlOverrides: s,
1233
+ applied: {
1234
+ ...r,
1235
+ controlOverrides: s,
1236
+ restore: a,
1237
+ opened: st({ dashboard: t, baseline: i, calendar: n }, a)
1238
+ }
1239
+ };
1240
+ }
1241
+ function Mi(e, t, n) {
1242
+ const o = it(n.values);
1243
+ return {
1244
+ ...o,
1245
+ appliedBookmarkId: t,
1246
+ rememberedWrites: [],
1247
+ notices: e.notices,
1248
+ opened: n.snapshot,
1249
+ restore: o
1250
+ };
1251
+ }
1252
+ const Se = (e) => JSON.stringify([e.scope, e.target, e.inputId]);
1253
+ function Q(e) {
1254
+ return !e || e.status === "cleared" && !e.comparisonSelection;
1255
+ }
1256
+ function at(e, t) {
1257
+ const n = new Map(
1258
+ _(e).map((s) => [Se(s), s])
1259
+ ), o = new Map(
1260
+ _(t).map((s) => [Se(s), s])
1261
+ ), i = {};
1262
+ for (const [s, r] of o) {
1263
+ const a = n.get(s);
1264
+ a && Y(a.slot, r.slot) || Q(r.slot) && Q(a == null ? void 0 : a.slot) || U(
1265
+ i,
1266
+ r,
1267
+ Q(r.slot) ? { status: "cleared" } : r.slot
1268
+ );
1269
+ }
1270
+ for (const [s, r] of n)
1271
+ o.has(s) || Q(r.slot) || U(i, r, { status: "cleared" });
1272
+ return M(i);
1273
+ }
1274
+ function Ti(e) {
1275
+ const { dashboard: t, baseline: n, current: o } = e, i = at(n.materializedInputs, o.inputs), s = V(
1276
+ t,
1277
+ o.tableSettings,
1278
+ void 0
1279
+ ), r = o.selectedSheetId && o.selectedSheetId !== n.selectedSheetId && L(t, o.selectedSheetId) ? o.selectedSheetId : void 0;
1280
+ return {
1281
+ version: ce,
1282
+ ...r ? { selectedSheetId: r } : {},
1283
+ ..._(i).length ? { inputs: i } : {},
1284
+ ...Object.keys(s).length ? { tableSettings: s } : {}
1285
+ };
1286
+ }
1287
+ function so(e) {
1288
+ const t = /* @__PURE__ */ new Map();
1289
+ for (const n of re(e))
1290
+ n.label && t.set(n.id, n.label);
1291
+ return t;
1292
+ }
1293
+ function ro(e, t, n) {
1294
+ var i, s;
1295
+ const o = le(n);
1296
+ if (o) {
1297
+ const r = (s = (i = G(e, o)) == null ? void 0 : i.title) == null ? void 0 : s.trim();
1298
+ return r ? `Selection in ${r}` : "Selection";
1299
+ }
1300
+ return t.get(n) ?? n;
1301
+ }
1302
+ function Oi(e) {
1303
+ var d, l;
1304
+ const { dashboard: t, opened: n, current: o } = e, i = [], s = so(t), r = /* @__PURE__ */ new Set();
1305
+ for (const u of _(
1306
+ at(n.inputs, o.inputs)
1307
+ ))
1308
+ r.has(u.inputId) || (r.add(u.inputId), i.push({
1309
+ target: "input",
1310
+ inputId: u.inputId,
1311
+ label: ro(t, s, u.inputId)
1312
+ }));
1313
+ (n.selectedSheetId ?? null) !== (o.selectedSheetId ?? null) && i.push({ target: "sheet" });
1314
+ const a = V(
1315
+ t,
1316
+ n.tableSettings,
1317
+ void 0
1318
+ ), c = V(
1319
+ t,
1320
+ o.tableSettings,
1321
+ void 0
1322
+ );
1323
+ for (const u of /* @__PURE__ */ new Set([
1324
+ ...Object.keys(a),
1325
+ ...Object.keys(c)
1326
+ ]))
1327
+ me(a[u], c[u]) || i.push({
1328
+ target: "table",
1329
+ cardId: u,
1330
+ cardTitle: ((l = (d = G(t, u)) == null ? void 0 : d.title) == null ? void 0 : l.trim()) || "Table"
1331
+ });
1332
+ return i;
1333
+ }
1334
+ function ao(e) {
1335
+ const t = e.qualifiedFieldName, o = (e.qualifiedEntityName || e.qualifiedFieldName.split(".").slice(0, -1).join(".")).split(".").map((s) => ve(s)).join("."), i = ve(e.name);
1336
+ return {
1337
+ qualifiedColumnName: t,
1338
+ qualifiedTableName: o,
1339
+ formattedColumnName: i
1340
+ };
1341
+ }
1342
+ function xi({
1343
+ field: e,
1344
+ dataSource: t,
1345
+ connectionId: n,
1346
+ connectionType: o,
1347
+ filterId: i
1348
+ }) {
1349
+ const { qualifiedColumnName: s, qualifiedTableName: r } = ao(e), a = xe(e.dataType), c = a === "date" ? "between" : "in", d = zt(e), l = _t(t, {
1350
+ connectionId: n,
1351
+ connectionType: o
1352
+ }, e);
1353
+ return {
1354
+ id: i || ue(),
1355
+ title: e.label || e.name,
1356
+ connectionId: n || (t == null ? void 0 : t.connectionId) || "",
1357
+ column: s,
1358
+ dataType: e.dataType,
1359
+ table: e.entityName || "",
1360
+ database: Gt(t, l, e) || "",
1361
+ qualifiedTableName: r,
1362
+ operation: c,
1363
+ sql: "",
1364
+ fieldMeta: d,
1365
+ semanticContext: l,
1366
+ ...a === "date" ? { dateSelectionMode: "range" } : { type: "single" }
1367
+ };
1368
+ }
1369
+ function lo(e, t) {
1370
+ return e.kind === "filter" && jt(e.filter, t);
1371
+ }
1372
+ function co(e) {
1373
+ return xe(e.dataType) === "date" ? ["label", "start", "end", "range"] : ["label", "value"];
1374
+ }
1375
+ function lt(e) {
1376
+ return uo(e) ? ["label", "value"] : ["value"];
1377
+ }
1378
+ function uo(e) {
1379
+ return e.type === "enum" || e.type === "multi_enum" || e.type === "field_selector" || e.type === "metric_selector" || e.type === "aggregation_selector" || e.type === "grain_selector";
1380
+ }
1381
+ function be(e) {
1382
+ return e === "in" || e === "not in";
1383
+ }
1384
+ function Ie(e) {
1385
+ return e === "not in" ? "exclude" : "include";
1386
+ }
1387
+ function fo(e) {
1388
+ return e === "exclude" ? "not in" : "in";
1389
+ }
1390
+ function wi(e) {
1391
+ var n;
1392
+ const t = (n = e.liveValue) == null ? void 0 : n.operation;
1393
+ return be(t) ? Ie(t) : e.pendingMode ?? e.authoredMode;
1394
+ }
1395
+ function po(e) {
1396
+ var o;
1397
+ let t = !1;
1398
+ const n = (o = e.inputs) == null ? void 0 : o.map((i) => {
1399
+ if (i.kind !== "filter" || !i.filter) return i;
1400
+ const s = mo(
1401
+ i.filter,
1402
+ new Set(bo(e.defaultInputValues, i))
1403
+ );
1404
+ return s === i.filter ? i : (t = !0, { ...i, filter: s });
1405
+ });
1406
+ return t ? { ...e, inputs: n } : e;
1407
+ }
1408
+ function mo(e, t) {
1409
+ if (t.size !== 1 || !be(e.operation))
1410
+ return e;
1411
+ const [n] = t;
1412
+ return Ie(e.operation) === n ? e : { ...e, operation: fo(n) };
1413
+ }
1414
+ function bo(e, t) {
1415
+ var i;
1416
+ const n = (s) => Object.values(s ?? {}).map((r) => r[t.id]);
1417
+ return (t.runtimeScope === "shared" ? [(i = e == null ? void 0 : e.shared) == null ? void 0 : i[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(
1418
+ (s) => (s == null ? void 0 : s.status) === "set" && s.value.kind === "filter" ? Io(s.value.filterValue) : []
1419
+ );
1420
+ }
1421
+ function Io(e) {
1422
+ return be(e.operation) ? [Ie(e.operation)] : [];
1423
+ }
1424
+ function Pi(e) {
1425
+ const n = Z(e).issues.length ? e : Lt(e);
1426
+ return po(n);
1427
+ }
1428
+ function Ei(e, t) {
1429
+ const { controlContractOverrides: n, cardId: o } = t;
1430
+ if (!n || (n.controlDefinitions !== void 0 && (e.controls = n.controlDefinitions), typeof o != "string" || o.trim().length === 0))
1431
+ return e;
1432
+ const i = G(e, o);
1433
+ return i && (n.cardControlDefinitions !== void 0 && (i.controls = n.cardControlDefinitions), n.controlBindings !== void 0 && (i.controlBindings = n.controlBindings)), e;
1434
+ }
1435
+ function Ri(e) {
1436
+ const { dashboard: t, capture: n, calendar: o } = e, i = Oe(t, n.filterValues, {
1437
+ calendar: o
1438
+ }), s = n.dashboardInputExecutionSnapshot, r = n.controlValues, a = {
1439
+ ...Ze(
1440
+ t,
1441
+ {
1442
+ adHocFilterValues: i.adHocFilterValues,
1443
+ controlOverrides: r,
1444
+ // The snapshot replays exactly over the listed values.
1445
+ dashboardInputValues: s ? se(
1446
+ i.slots,
1447
+ Qe({
1448
+ dashboard: t,
1449
+ dashboardInputValues: s.dashboardInputValues,
1450
+ sheetId: s.sheetId,
1451
+ cardId: s.cardId
1452
+ })
1453
+ ) : i.slots
1454
+ },
1455
+ o
1456
+ ),
1457
+ cardViewState: s ? qn(s.cardViewState) : {}
1458
+ }, c = s ? Ht(s.transientContexts) : void 0;
1459
+ return {
1460
+ runtimeValues: a,
1461
+ controlOverrides: r,
1462
+ ...c != null && c.length ? { transientContexts: c } : {}
1463
+ };
1464
+ }
1465
+ function Ve(e) {
1466
+ const t = z(e.filter);
1467
+ return {
1468
+ inputId: e.inputId,
1469
+ filterId: e.filterId,
1470
+ label: e.label,
1471
+ selection: e.selection,
1472
+ owner: t ? { kind: "global_date" } : {
1473
+ kind: "field_date",
1474
+ filterId: e.filterId,
1475
+ label: e.label
1476
+ }
1477
+ };
1478
+ }
1479
+ function ho(e) {
1480
+ var i, s;
1481
+ if ((i = e.card.sql) != null && i.trim())
1482
+ return {
1483
+ inputs: e.inputs,
1484
+ fieldCandidates: [],
1485
+ resolution: { status: "none" }
1486
+ };
1487
+ const t = e.inputs.filter((r) => !z(r.filter)).map((r) => ({
1488
+ input: r,
1489
+ resolution: Kt({
1490
+ filter: r.filter,
1491
+ filterValue: r.filterValue,
1492
+ effectiveFilterValue: r.effectiveFilterValue,
1493
+ mappedFilterValue: r.mappedFilterValue,
1494
+ temporalBinding: e.temporalBinding,
1495
+ card: e.card
1496
+ })
1497
+ }));
1498
+ if (!e.temporalBinding)
1499
+ return { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
1500
+ const n = e.inputs.find(
1501
+ (r) => z(r.filter)
1502
+ );
1503
+ if (n && ((s = n.filterValue) == null ? void 0 : s.filterId) === n.filterId && n.effectiveFilterValue.filterId === n.filterId && Qt(n.effectiveFilterValue))
1504
+ return {
1505
+ inputs: e.inputs,
1506
+ fieldCandidates: t,
1507
+ resolution: {
1508
+ status: "resolved",
1509
+ resolvedOwner: Ve(n)
1510
+ }
1511
+ };
1512
+ const o = t.filter(
1513
+ (r) => r.resolution.status === "eligible"
1514
+ );
1515
+ return o.length === 1 ? {
1516
+ inputs: e.inputs,
1517
+ fieldCandidates: t,
1518
+ resolution: {
1519
+ status: "resolved",
1520
+ resolvedOwner: Ve(o[0].input)
1521
+ }
1522
+ } : o.length > 1 ? {
1523
+ inputs: e.inputs,
1524
+ fieldCandidates: t,
1525
+ resolution: {
1526
+ status: "ambiguous",
1527
+ candidateInputIds: o.map(
1528
+ (r) => r.input.inputId
1529
+ )
1530
+ }
1531
+ } : { inputs: e.inputs, fieldCandidates: t, resolution: { status: "none" } };
1532
+ }
1533
+ function qi(e) {
1534
+ var n, o;
1535
+ const t = {
1536
+ ownerCardCount: 0,
1537
+ matchingCardCount: 0,
1538
+ globalPrecedenceCardCount: 0,
1539
+ ambiguousCardCount: 0,
1540
+ authorControlledCardCount: 0
1541
+ };
1542
+ for (const i of e.targets) {
1543
+ const s = i.plan.fieldCandidates.find(
1544
+ (a) => a.input.inputId === e.inputId
1545
+ );
1546
+ if (!s || s.resolution.status !== "eligible") continue;
1547
+ t.matchingCardCount += 1;
1548
+ const { resolution: r } = i.plan;
1549
+ r.status === "resolved" && r.resolvedOwner.inputId === e.inputId ? t.ownerCardCount += 1 : r.status === "resolved" && r.resolvedOwner.owner.kind === "global_date" ? t.globalPrecedenceCardCount += 1 : r.status === "ambiguous" && r.candidateInputIds.includes(e.inputId) && (t.ambiguousCardCount += 1), (((n = i.card.preferences) == null ? void 0 : n.inheritGlobalComparison) === !1 || (((o = i.card.config) == null ? void 0 : o.metricColumns) || []).some(
1550
+ (a) => a.comparison !== void 0
1551
+ )) && (t.authorControlledCardCount += 1);
1552
+ }
1553
+ return t;
1554
+ }
1555
+ const go = /* @__PURE__ */ new Set([
1556
+ "between",
1557
+ "not between",
1558
+ "=",
1559
+ "!=",
1560
+ ">",
1561
+ ">=",
1562
+ "<",
1563
+ "<=",
1564
+ "is null",
1565
+ "is not null"
1566
+ ]), Co = /^(\d{4}-\d{2}-\d{2})T/, vo = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:\d{2})$/;
1567
+ function he(e) {
1568
+ return go.has(e);
1569
+ }
1570
+ function yo(e, t) {
1571
+ if (e instanceof Date)
1572
+ return Number.isNaN(e.getTime()) ? e : t ? ye(e, t, "yyyy-MM-dd") : e.toISOString().slice(0, 10);
1573
+ if (typeof e != "string")
1574
+ return e;
1575
+ const n = e.trim();
1576
+ if (t && vo.test(n)) {
1577
+ const i = new Date(n);
1578
+ if (!Number.isNaN(i.getTime()))
1579
+ return ye(i, t, "yyyy-MM-dd");
1580
+ }
1581
+ const o = Co.exec(n);
1582
+ return o ? o[1] : e;
1583
+ }
1584
+ function dt(e, t) {
1585
+ return Array.isArray(e) ? e.map(
1586
+ (n) => yo(n, t)
1587
+ ) : e;
1588
+ }
1589
+ function ct(e) {
1590
+ return typeof e.allowMinutePrecision == "boolean" ? e.allowMinutePrecision : ae(
1591
+ e.dashboard,
1592
+ e.semanticExecutionPayload
1593
+ ).allEligibleTargetsAreDateTime;
1594
+ }
1595
+ function ut(e) {
1596
+ const {
1597
+ globalDateFilter: t,
1598
+ globalDateFilterValue: n,
1599
+ timezone: o,
1600
+ allowMinutePrecision: i = !1
1601
+ } = e;
1602
+ if (!t || !n)
1603
+ return;
1604
+ if (!he(n.operation))
1605
+ return {
1606
+ ...n,
1607
+ filterId: t.id
1608
+ };
1609
+ const s = n, r = s.temporalPrecision === "minute" || $(s.relativeMeta), a = !i && r, c = s.operation === "is null" || s.operation === "is not null" ? [] : a ? dt(s.values, o) : s.values, d = i || !$(s.relativeMeta) ? s.relativeMeta : void 0, l = i && s.temporalPrecision === "minute" ? s.temporalPrecision : void 0, {
1610
+ relativeMeta: u,
1611
+ temporalPrecision: f,
1612
+ values: p,
1613
+ ...m
1614
+ } = n;
1615
+ return {
1616
+ ...m,
1617
+ filterId: t.id,
1618
+ values: c,
1619
+ ...d ? { relativeMeta: d } : {},
1620
+ ...l ? { temporalPrecision: l } : {}
1621
+ };
1622
+ }
1623
+ function Do(e) {
1624
+ const t = j(e.filters);
1625
+ if (!t)
1626
+ return e.filterValues;
1627
+ const n = ct(e);
1628
+ return e.filterValues.map((o) => o.filterId !== t.id ? o : ut({
1629
+ globalDateFilter: t,
1630
+ globalDateFilterValue: o,
1631
+ timezone: e.timezone,
1632
+ allowMinutePrecision: n
1633
+ }) || o);
1634
+ }
1635
+ function ft(e) {
1636
+ const {
1637
+ globalDateFilter: t,
1638
+ globalDateFilterValue: n,
1639
+ resolvedPrimaryDateField: o,
1640
+ semanticContext: i,
1641
+ timezone: s,
1642
+ allowMinutePrecision: r = !1
1643
+ } = e;
1644
+ if (!t || !n || !o || !he(n.operation))
1645
+ return null;
1646
+ const a = n, c = $t(
1647
+ o.dataType
1648
+ ), d = r && c, l = a.temporalPrecision === "minute" || $(a.relativeMeta), u = d && a.temporalPrecision === "minute" ? a.temporalPrecision : void 0, f = d || !$(a.relativeMeta) ? a.relativeMeta : void 0, p = !d && l;
1649
+ return {
1650
+ filterId: t.id,
1651
+ dateOwner: "global_date",
1652
+ name: o.qualifiedFieldName || o.name,
1653
+ operation: a.operation,
1654
+ valueType: "date",
1655
+ values: a.operation === "is null" || a.operation === "is not null" ? [] : p ? dt(
1656
+ a.values,
1657
+ s
1658
+ ) : a.values,
1659
+ dataType: o.dataType || "date",
1660
+ // The exact type travels with the filter, so the server formats the predicate for
1661
+ // the column's storage type (it read it from `dataType` before 2.1 split the two).
1662
+ ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
1663
+ fieldMeta: {
1664
+ name: o.name,
1665
+ qualifiedFieldName: o.qualifiedFieldName,
1666
+ qualifiedEntityName: o.qualifiedEntityName,
1667
+ entityId: o.entityId,
1668
+ entityName: o.entityName,
1669
+ entityType: o.entityType,
1670
+ dataType: o.dataType,
1671
+ ...o.nativeDataType ? { nativeDataType: o.nativeDataType } : {},
1672
+ role: "groupby",
1673
+ ...t != null && t.title ? { label: t.title } : {}
1674
+ },
1675
+ ...i ? { semanticContext: i } : {},
1676
+ ...f ? { relativeMeta: f } : {},
1677
+ ...u ? { temporalPrecision: u } : {}
1678
+ };
1679
+ }
1680
+ function w(e) {
1681
+ return typeof e == "string" ? e.trim() : "";
1682
+ }
1683
+ function Fo(e) {
1684
+ var t;
1685
+ return (((t = e.semanticContext) == null ? void 0 : t.selectedEntities) || []).filter((n) => typeof n == "object" && n !== null).filter((n) => n.type === "dataset").map((n) => {
1686
+ var o;
1687
+ return {
1688
+ domainId: w(n.domainId) || w((o = e.semanticContext) == null ? void 0 : o.semanticDomainId),
1689
+ datasetName: w(n.name),
1690
+ selectedEntityId: w(n.id)
1691
+ };
1692
+ }).filter((n) => n.domainId && n.datasetName);
1693
+ }
1694
+ function So(e) {
1695
+ var c, d, l, u, f;
1696
+ if (z(e) || (c = e.sql) != null && c.trim())
1697
+ return null;
1698
+ const t = Fo(e), n = w((d = e.semanticContext) == null ? void 0 : d.semanticDomainId), o = w((l = e.fieldMeta) == null ? void 0 : l.entityId), i = w((u = e.fieldMeta) == null ? void 0 : u.entityName), s = w((f = e.fieldMeta) == null ? void 0 : f.entityType) === "dataset", r = t.find(
1699
+ (p) => o && p.selectedEntityId === o
1700
+ );
1701
+ if (r)
1702
+ return r;
1703
+ const a = t.find(
1704
+ (p) => i && p.datasetName === i && (!n || p.domainId === n)
1705
+ );
1706
+ return a || (t.length === 1 ? t[0] : s && i && n ? {
1707
+ domainId: n,
1708
+ datasetName: i
1709
+ } : null);
1710
+ }
1711
+ function Vo(e) {
1712
+ var i, s;
1713
+ const { filter: t, semanticExecutionPayload: n } = e;
1714
+ if (!n)
1715
+ return null;
1716
+ const o = So(t);
1717
+ return o && ((s = (i = n.domainsById[o.domainId]) == null ? void 0 : i.datasetsByName[o.datasetName]) == null ? void 0 : s.primaryDateField) || null;
1718
+ }
1719
+ function pt(e) {
1720
+ const t = j(e.filters);
1721
+ return t ? e.filterValues.filter(
1722
+ (n) => n.filterId !== t.id
1723
+ ) : e.filterValues;
1724
+ }
1725
+ function Bi(e) {
1726
+ const t = j(e.filters), n = pt({
1727
+ filters: e.filters,
1728
+ filterValues: e.filterValues
1729
+ });
1730
+ if (!t || z(e.filter))
1731
+ return n;
1732
+ const o = e.filterValues.find(
1733
+ (r) => r.filterId === t.id
1734
+ ), i = Vo({
1735
+ filter: e.filter,
1736
+ semanticExecutionPayload: e.semanticExecutionPayload
1737
+ }), s = ft({
1738
+ globalDateFilter: t,
1739
+ globalDateFilterValue: o,
1740
+ resolvedPrimaryDateField: i || void 0,
1741
+ semanticContext: e.filter.semanticContext,
1742
+ timezone: e.timezone,
1743
+ allowMinutePrecision: e.allowMinutePrecision
1744
+ });
1745
+ return s ? [s, ...n] : n;
1746
+ }
1747
+ function ko(e) {
1748
+ var l;
1749
+ const t = j(e.filters), n = t ? e.cardFilterValues.find(
1750
+ (u) => u.filterId === t.id
1751
+ ) : void 0, o = t ? e.cardFilterValues.filter(
1752
+ (u) => u.filterId !== t.id
1753
+ ) : e.cardFilterValues, i = e.resolvedPrimaryDateField ?? we({
1754
+ card: e.card,
1755
+ cardConfig: e.cardConfig,
1756
+ resolvedFields: e.resolvedFields,
1757
+ semanticExecutionPayload: e.semanticExecutionPayload
1758
+ }), s = ft({
1759
+ globalDateFilter: t,
1760
+ globalDateFilterValue: n,
1761
+ resolvedPrimaryDateField: i || void 0,
1762
+ timezone: e.timezone,
1763
+ allowMinutePrecision: e.allowMinutePrecision
1764
+ }), r = s ? [s, ...o] : o, a = new Map(
1765
+ r.map((u) => [
1766
+ u.filterId,
1767
+ u
1768
+ ])
1769
+ ), c = ((l = e.dateComparisonInputs) == null ? void 0 : l.flatMap((u) => {
1770
+ var p;
1771
+ const f = a.get(
1772
+ u.filterId
1773
+ );
1774
+ return f ? [{
1775
+ ...u,
1776
+ effectiveFilterValue: f,
1777
+ mappedFilterValue: (p = e.mappedFilterValuesByInputId) == null ? void 0 : p.get(u.inputId)
1778
+ }] : [];
1779
+ })) || [], d = ho({
1780
+ inputs: c,
1781
+ temporalBinding: i,
1782
+ card: e.card
1783
+ });
1784
+ return {
1785
+ cardFilterValues: r,
1786
+ resolvedPrimaryDateField: i,
1787
+ dateComparisonPlan: d
1788
+ };
1789
+ }
1790
+ function Ai(e) {
1791
+ const t = j(e.filters), n = ct(e), o = t ? e.filterValues.find(
1792
+ (r) => r.filterId === t.id
1793
+ ) : void 0, i = pt(e);
1794
+ return !t || !o || !he(o.operation) ? i : [
1795
+ {
1796
+ ...ut({
1797
+ globalDateFilter: t,
1798
+ globalDateFilterValue: o,
1799
+ timezone: e.timezone,
1800
+ allowMinutePrecision: n
1801
+ }) || o,
1802
+ filterId: t.id,
1803
+ name: t.title || t.column
1804
+ },
1805
+ ...i
1806
+ ];
1807
+ }
1808
+ class Mo extends Error {
1809
+ }
1810
+ function Ni(e, t) {
1811
+ const n = new Map((e ? q(e) : []).map(({ card: o }) => [o.id, o]));
1812
+ return t && n.set(t.id, t), [...n.values()].flatMap((o) => {
1813
+ const i = Ke(o);
1814
+ return i.status === "ready" ? Wt(i.config.spec, o.controlBindings) : [];
1815
+ });
1816
+ }
1817
+ function To(e, t, n) {
1818
+ const o = On(e);
1819
+ if (!o) throw new Error("Matrix card definition is required.");
1820
+ const i = n && Ut({
1821
+ ...n,
1822
+ spec: o.spec,
1823
+ catalog: t.map((l) => ({ ...l, id: l.resolvedField.id }))
1824
+ }), s = i ? { ...o, spec: i.spec } : o, r = Fn(t), a = Sn(t), c = (l) => {
1825
+ const u = a(l, s.spec.source);
1826
+ if (!(!u && l.derivedField)) {
1827
+ if (!u) throw new Mo(`Matrix field metadata is unavailable: ${l.name}`);
1828
+ return { ...u, ...l.derivedField ? { derivedField: l.derivedField } : {} };
1829
+ }
1830
+ }, d = {
1831
+ rows: s.spec.rows.flatMap((l) => {
1832
+ const u = c(l.field);
1833
+ return u ? [{ ...u, id: l.id, granularity: l.grain, role: "groupby" }] : [];
1834
+ }),
1835
+ columns: s.spec.columns.flatMap((l) => {
1836
+ const u = c(l.field);
1837
+ return u ? [{ ...u, id: l.id, granularity: l.grain, role: "pivotby" }] : [];
1838
+ }),
1839
+ // Aggregate-stage expressions have no source-column filter target. They stay
1840
+ // authoritative in matrix.spec, including all dependencies and controls.
1841
+ metrics: s.spec.measures.flatMap((l) => {
1842
+ if (l.kind !== "aggregate" || l.field.name === "*") return [];
1843
+ const u = c(l.field);
1844
+ return u ? [{ ...u, id: l.id, aggregate: l.aggregate, role: "metric" }] : [];
1845
+ })
1846
+ };
1847
+ return { config: s, fields: d, resolveField: r };
1848
+ }
1849
+ function Oo(e) {
1850
+ const t = e.filter(Boolean);
1851
+ if (t.length !== 0)
1852
+ return t.length === 1 ? t[0] : {
1853
+ id: ue(),
1854
+ logicalOperator: "AND",
1855
+ negate: !1,
1856
+ conditions: [],
1857
+ groups: t
1858
+ };
1859
+ }
1860
+ function xo(e) {
1861
+ if (!e) return;
1862
+ const t = (n) => ({
1863
+ logicalOperator: n.logicalOperator,
1864
+ negate: n.negate,
1865
+ conditions: n.conditions.map((o) => ({
1866
+ field: o.field.id,
1867
+ operator: o.operator,
1868
+ value: o.value,
1869
+ temporalBucket: o.temporalBucket,
1870
+ // The run-time markers decide what runs, so they belong in the key.
1871
+ relativeMeta: o.relativeMeta,
1872
+ latestValue: o.latestValue
1873
+ })),
1874
+ groups: n.groups.map(t)
1875
+ });
1876
+ return JSON.stringify(t(e));
1877
+ }
1878
+ function wo(e, t) {
1879
+ const n = e.metricColumns || [];
1880
+ if (n.length === 0) return e;
1881
+ const o = Vn.includes(
1882
+ t
1883
+ ), i = kn.includes(
1884
+ t
1885
+ ), s = (c) => {
1886
+ var d;
1887
+ return (d = c.parameters) != null && d.windowTransform ? {
1888
+ ...c,
1889
+ parameters: {
1890
+ ...c.parameters,
1891
+ windowTransform: void 0
1892
+ }
1893
+ } : c;
1894
+ };
1895
+ let r = !1;
1896
+ const a = n.map(
1897
+ (c) => {
1898
+ var u;
1899
+ const d = Yt(c);
1900
+ if (d === "none")
1901
+ return c;
1902
+ let l = c;
1903
+ return (u = l.parameters) != null && u.windowTransform && (r = !0, l = s(l)), o ? d === "target" && !i ? (r = !0, {
1904
+ ...l,
1905
+ comparison: void 0
1906
+ }) : l : (r = !0, { ...l, comparison: void 0 });
1907
+ }
1908
+ );
1909
+ return r ? {
1910
+ ...e,
1911
+ metricColumns: a
1912
+ } : e;
1913
+ }
1914
+ function ji(e, t = {}) {
1915
+ return mt(bt(e, t));
1916
+ }
1917
+ function mt(e) {
1918
+ return Oo([e.authored, e.drill, e.selections]);
1919
+ }
1920
+ function bt(e, t = {}) {
1921
+ return {
1922
+ authored: t.includeAuthoredFilters === !1 ? void 0 : Mn(e),
1923
+ drill: zn(t.drill, e.id),
1924
+ selections: wn(t.selections ?? [])
1925
+ };
1926
+ }
1927
+ function Po(e, t, n) {
1928
+ const o = Nn(e, t);
1929
+ return je(e) ? wo(
1930
+ { ...o, filters: n },
1931
+ e.type
1932
+ ) : o;
1933
+ }
1934
+ function Eo(e) {
1935
+ const t = Zt(e);
1936
+ return {
1937
+ contextMode: t,
1938
+ shouldApplyDashboardFilters: !t || t === "full"
1939
+ };
1940
+ }
1941
+ function Ro(e) {
1942
+ const t = e.dashboardControls || [], n = e.card.controls || [], o = /* @__PURE__ */ new Set([
1943
+ ...t.map((i) => i.id),
1944
+ ...n.map((i) => i.id)
1945
+ ]);
1946
+ return It(
1947
+ e.card,
1948
+ {
1949
+ controlValues: Pe({
1950
+ relevantControlIds: o,
1951
+ dashboardValues: e.dashboardControlValues,
1952
+ cardValues: e.cardControlValues
1953
+ }),
1954
+ controlDefinitions: t,
1955
+ cardControlDefinitions: n,
1956
+ controlBindings: e.card.controlBindings || []
1957
+ },
1958
+ e.presentationControlIds
1959
+ );
1960
+ }
1961
+ function It(e, t, n) {
1962
+ const i = t.controlBindings.filter(
1963
+ (f) => !ze(f)
1964
+ ), s = new Set(
1965
+ Jt({
1966
+ sql: e.sql,
1967
+ controlBindings: i
1968
+ })
1969
+ ), r = new Set(
1970
+ [...n].filter(
1971
+ (f) => !s.has(f)
1972
+ )
1973
+ ), a = t.controlDefinitions.filter(
1974
+ (f) => !r.has(f.id)
1975
+ ), c = t.cardControlDefinitions.filter(
1976
+ (f) => !r.has(f.id)
1977
+ ), d = /* @__PURE__ */ new Set([
1978
+ ...a.map((f) => f.id),
1979
+ ...c.map((f) => f.id)
1980
+ ]), l = i.filter(
1981
+ (f) => d.has(f.controlId)
1982
+ );
1983
+ return {
1984
+ controlValues: Pe({
1985
+ relevantControlIds: d,
1986
+ dashboardValues: t.controlValues
1987
+ }),
1988
+ controlDefinitions: a,
1989
+ cardControlDefinitions: c,
1990
+ controlBindings: l
1991
+ };
1992
+ }
1993
+ function qo({
1994
+ card: e,
1995
+ dashboard: t,
1996
+ transientContexts: n,
1997
+ cardViewState: o,
1998
+ viewerTableSettings: i,
1999
+ adHocFilterValues: s,
2000
+ selectedSheetId: r,
2001
+ inlineFilterValuesMap: a,
2002
+ dashboardControls: c,
2003
+ dashboardControlValues: d,
2004
+ cardControlValuesMap: l,
2005
+ dashboardInputContext: u,
2006
+ includeAuthoredFilters: f
2007
+ }) {
2008
+ var T;
2009
+ const p = Xt(t);
2010
+ for (const S of e.controlBindings || [])
2011
+ ze(S) && p.add(S.controlId);
2012
+ const { shouldApplyDashboardFilters: m } = Eo(n), b = u != null && u.inputs.length ? u : void 0, I = bt(e, {
2013
+ includeAuthoredFilters: f,
2014
+ // Blocked and skipped conditions are already projected away, so a
2015
+ // selection can only ever narrow this card on its own fields. Carried
2016
+ // selections are among them.
2017
+ selections: ((u == null ? void 0 : u.selections) ?? []).filter(
2018
+ (S) => S.status === "apply"
2019
+ ),
2020
+ drill: o == null ? void 0 : o.drill
2021
+ }), y = mt(I), g = f === !1 ? en(y, !0) : y, h = Po(
2022
+ e,
2023
+ o == null ? void 0 : o.drill,
2024
+ g
2025
+ ), v = tn({ ...e, config: h }, i) ?? h, C = nn(v, {
2026
+ cardType: e.type,
2027
+ dataSource: e.dataSource,
2028
+ temporalResultOwner: _e({
2029
+ hasExecutableConfig: Ge(v, e.type),
2030
+ sql: e.sql,
2031
+ normalizedPython: Le(e.python || "")
2032
+ })
2033
+ }) || v, k = xo(g) || "", H = b ? It(
2034
+ e,
2035
+ {
2036
+ controlValues: b.controlValues,
2037
+ controlDefinitions: b.controlDefinitions,
2038
+ cardControlDefinitions: b.cardControlDefinitions,
2039
+ controlBindings: b.controlBindings
2040
+ },
2041
+ p
2042
+ ) : Ro({
2043
+ card: e,
2044
+ presentationControlIds: p,
2045
+ dashboardControls: c,
2046
+ dashboardControlValues: d,
2047
+ cardControlValues: l == null ? void 0 : l[e.id]
2048
+ });
2049
+ return {
2050
+ filterCompilationInput: {
2051
+ adHocFilterValues: s || [],
2052
+ selectedSheetId: r,
2053
+ inlineFilterValues: (a == null ? void 0 : a[e.id]) || [],
2054
+ shouldApplyDashboardFilters: m,
2055
+ ...b ? {
2056
+ dashboardInputContext: {
2057
+ inputs: b.inputs,
2058
+ resolvedInputs: b.resolvedInputs,
2059
+ activeFilters: b.activeFilters
2060
+ }
2061
+ } : {},
2062
+ ...b != null && b.globalDateComparisonSelection ? {
2063
+ globalDateComparisonSelection: b.globalDateComparisonSelection
2064
+ } : {},
2065
+ ...b != null && b.dateComparisonInputs ? {
2066
+ dateComparisonInputs: b.dateComparisonInputs
2067
+ } : {}
2068
+ },
2069
+ ...H,
2070
+ resolvedFilters: g,
2071
+ resolvedFilterParts: I,
2072
+ drillSteps: ((T = o == null ? void 0 : o.drill) == null ? void 0 : T.steps) ?? Pn,
2073
+ finalConfig: v,
2074
+ queryRelevantConfig: C,
2075
+ finalFiltersKey: k
2076
+ };
2077
+ }
2078
+ function ht(e, t, n) {
2079
+ var o;
2080
+ if (t)
2081
+ return {
2082
+ selection: t,
2083
+ ...((o = e.preferences) == null ? void 0 : o.inheritGlobalComparison) === !1 ? { inheritGlobalComparison: !1 } : {},
2084
+ ...n ? { owner: n } : {}
2085
+ };
2086
+ }
2087
+ function Bo(e) {
2088
+ if (e.resolution.status === "resolved")
2089
+ return ht(
2090
+ e.card,
2091
+ e.resolution.resolvedOwner.selection,
2092
+ e.resolution.resolvedOwner.owner
2093
+ );
2094
+ }
2095
+ function Ao(e) {
2096
+ return `Set ${e.join(", ")} to run this card.`;
2097
+ }
2098
+ function No({
2099
+ dashboardInputContext: e,
2100
+ shouldApplyDashboardFilters: t
2101
+ }) {
2102
+ if (t)
2103
+ return e.activeFilters;
2104
+ const n = new Set(
2105
+ e.inputs.flatMap(
2106
+ (o) => o.kind === "filter" && Ee(o) ? [o.filter.id] : []
2107
+ )
2108
+ );
2109
+ return e.activeFilters.filter(
2110
+ (o) => n.has(o.filterId)
2111
+ );
2112
+ }
2113
+ function jo({
2114
+ dashboardInputFilterValues: e,
2115
+ adHocFilterValues: t
2116
+ }) {
2117
+ const n = [...e], o = new Set(
2118
+ n.map((i) => i.filterId)
2119
+ );
2120
+ for (const i of t)
2121
+ o.has(i.filterId) || (n.push(i), o.add(i.filterId));
2122
+ return n;
2123
+ }
2124
+ function te(e, t) {
2125
+ const n = t.shouldApplyDashboardFilters ? on(t.adHocFilterValues, t.selectedSheetId) : [];
2126
+ if (!t.dashboardInputContext)
2127
+ return {
2128
+ status: "ready",
2129
+ filterValues: [...n, ...t.inlineFilterValues],
2130
+ mappingDispositions: []
2131
+ };
2132
+ const o = t.dashboardInputContext.inputs.filter(
2133
+ (l) => l.kind === "filter" && !!l.application
2134
+ ), i = new Set(
2135
+ o.map((l) => l.filter.id)
2136
+ ), s = new Set(
2137
+ t.dashboardInputContext.inputs.flatMap(
2138
+ (l) => {
2139
+ var u;
2140
+ return l.kind === "filter" && ((u = l.compatibility) == null ? void 0 : u.source) === "cardInlineFilter" ? [l.filter.id] : [];
2141
+ }
2142
+ )
2143
+ ), r = No({
2144
+ dashboardInputContext: t.dashboardInputContext,
2145
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2146
+ }).filter((l) => !i.has(l.filterId)), a = r.filter(
2147
+ (l) => !s.has(l.filterId)
2148
+ ), c = r.filter(
2149
+ (l) => s.has(l.filterId)
2150
+ ), d = sn({
2151
+ card: e,
2152
+ inputs: o,
2153
+ resolvedInputs: t.dashboardInputContext.resolvedInputs,
2154
+ activeFilterValues: t.dashboardInputContext.activeFilters,
2155
+ shouldApplyDashboardFilters: t.shouldApplyDashboardFilters
2156
+ });
2157
+ return d.status === "blocked" ? {
2158
+ status: "blocked",
2159
+ mappingDispositions: d.dispositions
2160
+ } : {
2161
+ status: "ready",
2162
+ filterValues: [
2163
+ ...jo({
2164
+ dashboardInputFilterValues: [
2165
+ ...a,
2166
+ ...d.filterValues
2167
+ ],
2168
+ adHocFilterValues: n
2169
+ }),
2170
+ ...c
2171
+ ],
2172
+ mappingDispositions: d.dispositions
2173
+ };
2174
+ }
2175
+ function zo(e, t) {
2176
+ const n = e.dashboardInputContext;
2177
+ if (!n) return [];
2178
+ const o = new Set(
2179
+ t.flatMap(
2180
+ (s) => s.status === "skip" && (s.reason === "explicitlyExcluded" || s.reason === "outsideScope") ? [s.inputId] : []
2181
+ )
2182
+ ), i = new Map(n.inputs.map((s) => [s.id, s]));
2183
+ return n.resolvedInputs.flatMap((s) => {
2184
+ if (!s.missingRequiredValue) return [];
2185
+ const r = i.get(s.id);
2186
+ return r ? r.kind === "filter" && (!e.shouldApplyDashboardFilters && !Ee(r) || o.has(r.id)) ? [] : [s.label] : [];
2187
+ });
2188
+ }
2189
+ function _o({
2190
+ card: e,
2191
+ cardConfig: t,
2192
+ input: n,
2193
+ resolvedPrimaryDateField: o,
2194
+ resolvedFields: i,
2195
+ semanticExecutionPayload: s,
2196
+ timezone: r,
2197
+ allowMinutePrecision: a
2198
+ }) {
2199
+ var b;
2200
+ const c = n.dashboardInputContext ? n.dashboardInputContext.inputs.flatMap(
2201
+ (I) => I.kind === "filter" ? [I.filter] : []
2202
+ ) : [], d = te(e, n), l = zo(
2203
+ n,
2204
+ d.mappingDispositions
2205
+ );
2206
+ if (l.length)
2207
+ return {
2208
+ status: "blocked",
2209
+ cardId: e.id,
2210
+ reason: "requiredInput",
2211
+ mappingDispositions: d.mappingDispositions,
2212
+ missingRequiredLabels: l
2213
+ };
2214
+ if (d.status === "blocked")
2215
+ return {
2216
+ status: "blocked",
2217
+ cardId: e.id,
2218
+ reason: "mapping",
2219
+ mappingDispositions: d.mappingDispositions,
2220
+ missingRequiredLabels: []
2221
+ };
2222
+ const u = ko({
2223
+ card: e,
2224
+ cardConfig: t,
2225
+ filters: c,
2226
+ cardFilterValues: d.filterValues,
2227
+ resolvedPrimaryDateField: o,
2228
+ resolvedFields: i,
2229
+ semanticExecutionPayload: s,
2230
+ timezone: r,
2231
+ allowMinutePrecision: a,
2232
+ dateComparisonInputs: n.dateComparisonInputs,
2233
+ mappedFilterValuesByInputId: new Map(
2234
+ d.mappingDispositions.flatMap(
2235
+ (I) => I.status === "apply" ? [[I.inputId, I.filterValue]] : []
2236
+ )
2237
+ )
2238
+ }), f = j(c), p = !!(f && u.cardFilterValues.some(
2239
+ (I) => I.filterId === f.id
2240
+ )), m = u.resolvedPrimaryDateField && !((b = e.sql) != null && b.trim()) ? u.dateComparisonPlan.inputs.length ? Bo({
2241
+ card: e,
2242
+ resolution: u.dateComparisonPlan.resolution
2243
+ }) : p ? ht(
2244
+ e,
2245
+ n.globalDateComparisonSelection
2246
+ ) : void 0 : void 0;
2247
+ return {
2248
+ status: "ready",
2249
+ ...u,
2250
+ queryFilterDefinitions: c,
2251
+ globalDateComparison: m,
2252
+ mappingDispositions: d.mappingDispositions
2253
+ };
2254
+ }
2255
+ function gt(e, t, n) {
2256
+ const o = _o({
2257
+ resolvedFields: t.resolvedDateFields,
2258
+ ...n,
2259
+ card: e,
2260
+ cardConfig: t.queryRelevantConfig,
2261
+ input: t.filterCompilationInput
2262
+ });
2263
+ if (o.status === "blocked") return o;
2264
+ const { filterCompilationInput: i, ...s } = t;
2265
+ return { status: "ready", queryContext: {
2266
+ ...s,
2267
+ cardFilterValues: o.cardFilterValues,
2268
+ queryFilterDefinitions: o.queryFilterDefinitions,
2269
+ resolvedPrimaryDateField: o.resolvedPrimaryDateField,
2270
+ globalDateComparison: o.globalDateComparison,
2271
+ globalDateComparisonSelection: i.globalDateComparisonSelection,
2272
+ dateComparisonInputs: i.dateComparisonInputs
2273
+ }, compiledFilters: o };
2274
+ }
2275
+ function Go(e, t, n) {
2276
+ const o = Tn(e), i = gt(e, t, {
2277
+ resolvedPrimaryDateField: n.resolvedPrimaryDateField,
2278
+ timezone: n.calendarContext.tz,
2279
+ allowMinutePrecision: n.allowGlobalDateMinutePrecision
2280
+ });
2281
+ if (i.status === "blocked")
2282
+ return { ...i, tableConfig: o };
2283
+ const { compiledFilters: s } = i, {
2284
+ cardFilterValues: r,
2285
+ resolvedPrimaryDateField: a,
2286
+ globalDateComparison: c
2287
+ } = s, { queryKey: d, queryInputIdentity: l, paginationConfig: u } = rn(
2288
+ e,
2289
+ i.queryContext,
2290
+ n.calendarContext,
2291
+ { resolvePaginationConfig: n.resolvePaginationConfig }
2292
+ ), f = t.queryRelevantConfig, p = Le(e.python || ""), m = _e({
2293
+ hasExecutableConfig: Ge(f, e.type),
2294
+ sql: e.sql,
2295
+ normalizedPython: p
2296
+ });
2297
+ return {
2298
+ status: "ready",
2299
+ queryKey: d,
2300
+ queryInputIdentity: l,
2301
+ paginationConfig: u,
2302
+ tableConfig: o,
2303
+ compiledFilters: s,
2304
+ requestPayloadBase: {
2305
+ cardId: e.id,
2306
+ sql: (e == null ? void 0 : e.sql) || "",
2307
+ python: p,
2308
+ resultOwner: m,
2309
+ active_filters: r,
2310
+ controlValues: t.controlValues,
2311
+ controlDefinitions: t.controlDefinitions,
2312
+ cardControlDefinitions: t.cardControlDefinitions,
2313
+ controlBindings: t.controlBindings,
2314
+ cache_config: n.globalCacheConfig,
2315
+ queryConfig: e.queryConfig,
2316
+ tableConfig: o,
2317
+ cardType: e.type,
2318
+ cardTitle: e.title || "",
2319
+ cardConfig: f,
2320
+ cardDataSource: e.dataSource,
2321
+ resolvedPrimaryDateField: a || void 0,
2322
+ calendarContext: n.calendarContext,
2323
+ ...c ? { globalDateComparison: c } : {}
2324
+ }
2325
+ };
2326
+ }
2327
+ const ke = [], Lo = [], Ho = {};
2328
+ function zi(e, t) {
2329
+ return {
2330
+ sheetId: e.sheetId,
2331
+ sectionId: e.sectionId,
2332
+ documentFilterValues: e.documentFilterValues ?? ke,
2333
+ documentControlDefinitions: e.documentControlDefinitions ?? Lo,
2334
+ documentControlValues: e.documentControlValues ?? Ho,
2335
+ editorFilterValues: t ?? ke
2336
+ };
2337
+ }
2338
+ function Ko({
2339
+ card: e,
2340
+ dashboard: t,
2341
+ runtime: n,
2342
+ dashboardRuntimeValues: o,
2343
+ calendar: i
2344
+ }) {
2345
+ const s = Re({
2346
+ dashboard: t,
2347
+ dashboardInputValues: o.dashboardInputValues,
2348
+ transientContexts: void 0
2349
+ }) ? oe({
2350
+ transientContexts: void 0,
2351
+ dashboard: t,
2352
+ sheetId: n.sheetId,
2353
+ sheetKind: "document",
2354
+ sectionId: n.sectionId,
2355
+ card: e,
2356
+ runtimeValues: {
2357
+ ...o,
2358
+ dashboardInputValues: n.documentDashboardInputValues || o.dashboardInputValues
2359
+ },
2360
+ calendar: i
2361
+ }) : void 0, r = s && (s.inputs.length > 0 || s.selections.length > 0) ? s : void 0, a = !!(s != null && s.inputs.length), c = [
2362
+ ...n.editorFilterValues || [],
2363
+ ...n.documentFilterValues
2364
+ ];
2365
+ return {
2366
+ card: a ? e : Qo(
2367
+ e,
2368
+ n.documentControlDefinitions
2369
+ ),
2370
+ dashboard: t,
2371
+ transientContexts: void 0,
2372
+ // Document section cards do not drill.
2373
+ cardViewState: void 0,
2374
+ // Document section cards are not viewer-customizable tables.
2375
+ viewerTableSettings: void 0,
2376
+ adHocFilterValues: [],
2377
+ inlineFilterValuesMap: !a && c.length ? { [e.id]: c } : {},
2378
+ dashboardControls: [],
2379
+ dashboardControlValues: {},
2380
+ cardControlValuesMap: !a && Object.keys(n.documentControlValues).length > 0 ? { [e.id]: n.documentControlValues } : {},
2381
+ dashboardInputContext: r
2382
+ };
2383
+ }
2384
+ function Qo(e, t) {
2385
+ if (t.length === 0)
2386
+ return e;
2387
+ const n = /* @__PURE__ */ new Map();
2388
+ for (const o of e.controls || [])
2389
+ n.set(o.id, o);
2390
+ for (const o of t)
2391
+ n.set(o.id, o);
2392
+ return {
2393
+ ...e,
2394
+ controls: Array.from(n.values())
2395
+ };
2396
+ }
2397
+ function _i({
2398
+ card: e,
2399
+ place: t,
2400
+ source: n
2401
+ }) {
2402
+ const o = ne(e, t, n);
2403
+ return {
2404
+ card: o.card,
2405
+ context: o.context,
2406
+ inputContext: o.inputContext
2407
+ };
2408
+ }
2409
+ function $o(e, t, n) {
2410
+ return {
2411
+ calendarContext: n ?? xn,
2412
+ allowGlobalDateMinutePrecision: ae(
2413
+ e,
2414
+ t
2415
+ ).allEligibleTargetsAreDateTime,
2416
+ semanticExecutionPayload: t,
2417
+ globalCacheConfig: e.globalCacheConfig
2418
+ };
2419
+ }
2420
+ function Gi(e, t) {
2421
+ return vt(
2422
+ e,
2423
+ t,
2424
+ t.allowGlobalDateMinutePrecision
2425
+ );
2426
+ }
2427
+ function Uo(e, t, n = {}) {
2428
+ const o = Ct(e, t);
2429
+ return {
2430
+ ...Go(e.card, e.context, {
2431
+ resolvedPrimaryDateField: o,
2432
+ calendarContext: t.calendarContext,
2433
+ allowGlobalDateMinutePrecision: t.allowGlobalDateMinutePrecision,
2434
+ globalCacheConfig: t.globalCacheConfig,
2435
+ resolvePaginationConfig: n.resolvePaginationConfig
2436
+ }),
2437
+ resolvedPrimaryDateField: o
2438
+ };
2439
+ }
2440
+ function Wo({
2441
+ card: e,
2442
+ place: t,
2443
+ source: n,
2444
+ semanticExecutionPayload: o,
2445
+ matrixCatalog: i,
2446
+ withRequest: s = !1
2447
+ }) {
2448
+ var b, I;
2449
+ const { dashboard: r } = n, a = e.id, c = (y, g) => {
2450
+ var v;
2451
+ let h;
2452
+ try {
2453
+ const C = Ke(y);
2454
+ if (C.status === "invalid") throw C.error;
2455
+ const k = ne(
2456
+ y,
2457
+ g,
2458
+ n,
2459
+ C.status === "absent"
2460
+ );
2461
+ if (h = k.context, C.status === "absent")
2462
+ return { status: "ready", value: { assembled: k } };
2463
+ if (!i)
2464
+ return {
2465
+ status: "blocked",
2466
+ reason: "metadata",
2467
+ message: "Matrix field metadata is required.",
2468
+ context: h
2469
+ };
2470
+ const H = un(C.config.spec, h), T = i.filter(
2471
+ (D) => D.field.source && H.some(
2472
+ (O) => hn(O, D.field.source)
2473
+ )
2474
+ ), S = To(y, T, h), { params: P } = k, x = P.dashboardInputContext;
2475
+ S.config = {
2476
+ ...S.config,
2477
+ presentation: fn(
2478
+ y,
2479
+ S.config,
2480
+ {
2481
+ controls: x ? [
2482
+ ...x.controlDefinitions,
2483
+ ...x.cardControlDefinitions
2484
+ ] : [
2485
+ ...P.dashboardControls ?? r.controls ?? [],
2486
+ ...P.card.controls ?? []
2487
+ ],
2488
+ values: (x == null ? void 0 : x.controlValues) ?? {
2489
+ ...P.dashboardControlValues,
2490
+ ...(v = P.cardControlValuesMap) == null ? void 0 : v[y.id]
2491
+ }
2492
+ },
2493
+ T
2494
+ )
2495
+ };
2496
+ const B = {
2497
+ ...y,
2498
+ config: { matrix: S.config }
2499
+ }, F = ne(B, g, n, !1);
2500
+ return {
2501
+ status: "ready",
2502
+ value: {
2503
+ assembled: {
2504
+ card: B,
2505
+ context: { ...F.context, resolvedDateFields: S.fields },
2506
+ inputContext: F.inputContext
2507
+ },
2508
+ matrix: S
2509
+ }
2510
+ };
2511
+ } catch (C) {
2512
+ return {
2513
+ status: "blocked",
2514
+ reason: "configuration",
2515
+ message: C instanceof Error ? C.message : "Card configuration is invalid.",
2516
+ context: h
2517
+ };
2518
+ }
2519
+ }, d = c(e, t);
2520
+ if (d.status === "blocked")
2521
+ return {
2522
+ status: "blocked",
2523
+ cardId: a,
2524
+ mappingDispositions: [],
2525
+ reason: d.reason,
2526
+ missingRequiredLabels: [],
2527
+ message: d.message
2528
+ };
2529
+ const { assembled: l, matrix: u } = d.value, f = $o(
2530
+ r,
2531
+ o,
2532
+ n.calendar
2533
+ ), p = l.context.filterCompilationInput, m = an(r);
2534
+ try {
2535
+ const y = te(l.card, p), g = u && m && y.status === "ready" && y.filterValues.some((k) => k.filterId === m.id);
2536
+ let h = f.allowGlobalDateMinutePrecision;
2537
+ if (g) {
2538
+ const k = (b = p.dashboardInputContext) == null ? void 0 : b.inputs.find(
2539
+ (F) => F.kind === "filter" && F.filter.id === m.id
2540
+ ), T = ln(r, m).filter(
2541
+ ({ card: F, sheet: D }) => !k || W(k, {
2542
+ cardId: F.id,
2543
+ sheetId: D.id,
2544
+ sheetKind: qe(D) ? "document" : "dashboard"
2545
+ })
2546
+ ).map(({ card: F, sheet: D }) => ({
2547
+ card: F,
2548
+ value: F.id === a ? d : c(F, { kind: "sheet", sheetId: D.id })
2549
+ })), S = new Map(
2550
+ T.map(({ card: F, value: D }) => [
2551
+ F.id,
2552
+ D.status === "ready" ? D.value.assembled.card : null
2553
+ ])
2554
+ ), P = new Map(
2555
+ T.map(({ card: F, value: D }) => {
2556
+ var O;
2557
+ return [
2558
+ F.id,
2559
+ D.status === "ready" ? (O = D.value.matrix) == null ? void 0 : O.fields : void 0
2560
+ ];
2561
+ })
2562
+ ), x = T.flatMap(
2563
+ ({ card: F, value: D }) => {
2564
+ const O = F.id, ge = D.status === "ready" ? D.value.assembled.context : D.context;
2565
+ if (!ge) return [O];
2566
+ const Dt = D.status === "ready" ? D.value.assembled.card : F;
2567
+ try {
2568
+ const Ce = te(
2569
+ Dt,
2570
+ ge.filterCompilationInput
2571
+ );
2572
+ return Ce.status === "blocked" || Ce.filterValues.some((Ft) => Ft.filterId === m.id) ? [O] : [];
2573
+ } catch {
2574
+ return S.set(O, null), [O];
2575
+ }
2576
+ }
2577
+ ), B = ae(
2578
+ r,
2579
+ o,
2580
+ m,
2581
+ S,
2582
+ P,
2583
+ x
2584
+ );
2585
+ if ((I = B.unresolvedCardIds) != null && I.length)
2586
+ return {
2587
+ status: "blocked",
2588
+ cardId: a,
2589
+ mappingDispositions: [],
2590
+ reason: "coverage",
2591
+ missingRequiredLabels: [],
2592
+ message: `Date precision requires field metadata and valid inputs for: ${B.unresolvedCardIds.join(", ")}.`
2593
+ };
2594
+ h = B.allEligibleTargetsAreDateTime;
2595
+ }
2596
+ const v = vt(l, f, h);
2597
+ if (v.status === "blocked")
2598
+ return {
2599
+ status: "blocked",
2600
+ cardId: v.cardId,
2601
+ mappingDispositions: v.mappingDispositions,
2602
+ reason: v.reason,
2603
+ missingRequiredLabels: v.missingRequiredLabels,
2604
+ ...v.reason === "requiredInput" ? { message: Ao(v.missingRequiredLabels) } : {}
2605
+ };
2606
+ const C = s && !u ? Uo(l, f) : void 0;
2607
+ return {
2608
+ ...v,
2609
+ ...u ? { matrix: u } : {},
2610
+ // The whole request a card runs with: the contract's payload and its
2611
+ // extras (server pagination, table totals) from the one extras owner,
2612
+ // on the first page a new viewer opens (ledger P3-78).
2613
+ ...(C == null ? void 0 : C.status) === "ready" ? {
2614
+ request: {
2615
+ ...C.requestPayloadBase,
2616
+ ...dn({
2617
+ card: l.card,
2618
+ finalConfig: l.context.finalConfig,
2619
+ documentSection: t.kind === "documentSection" ? {} : void 0,
2620
+ page: cn(l.card)
2621
+ })
2622
+ }
2623
+ } : {}
2624
+ };
2625
+ } catch (y) {
2626
+ return {
2627
+ status: "blocked",
2628
+ cardId: a,
2629
+ mappingDispositions: [],
2630
+ reason: "configuration",
2631
+ missingRequiredLabels: [],
2632
+ message: y instanceof Error ? y.message : "Card filter configuration is invalid."
2633
+ };
2634
+ }
2635
+ }
2636
+ function Yo(e) {
2637
+ const t = e.editor ? {
2638
+ ...e.inlineFilterValuesMap,
2639
+ ...Object.fromEntries(
2640
+ Object.entries(e.editor.inlineFilterValuesMap).filter(
2641
+ (n) => n[1] !== void 0
2642
+ )
2643
+ )
2644
+ } : e.inlineFilterValuesMap;
2645
+ return {
2646
+ dashboardInputValues: e.dashboardInputValues,
2647
+ adHocFilterValues: e.adHocFilterValues,
2648
+ controlValues: e.controlValues,
2649
+ inlineFilterValuesMap: t,
2650
+ cardControlValuesMap: e.cardControlValuesMap
2651
+ };
2652
+ }
2653
+ function ne(e, t, n, o) {
2654
+ const { dashboard: i } = n, s = Yo(n), r = t.kind === "documentSection" ? {
2655
+ ...Ko({
2656
+ card: e,
2657
+ dashboard: i,
2658
+ runtime: t.section,
2659
+ dashboardRuntimeValues: s,
2660
+ calendar: n.calendar
2661
+ }),
2662
+ selectedSheetId: t.section.sheetId,
2663
+ includeAuthoredFilters: o
2664
+ } : Zo(e, t.sheetId, n, s, o);
2665
+ return {
2666
+ card: r.card,
2667
+ params: r,
2668
+ context: qo(r),
2669
+ inputContext: r.dashboardInputContext
2670
+ };
2671
+ }
2672
+ function Zo(e, t, n, o, i) {
2673
+ var c, d;
2674
+ const { dashboard: s, transientContexts: r } = n, a = Re({
2675
+ dashboard: s,
2676
+ dashboardInputValues: o.dashboardInputValues,
2677
+ transientContexts: r
2678
+ }) ? oe({
2679
+ transientContexts: r,
2680
+ dashboard: s,
2681
+ sheetId: t,
2682
+ card: e,
2683
+ runtimeValues: o,
2684
+ calendar: n.calendar
2685
+ }) : void 0;
2686
+ return {
2687
+ card: e,
2688
+ dashboard: s,
2689
+ transientContexts: r,
2690
+ cardViewState: (c = n.cardViewStates) == null ? void 0 : c[e.id],
2691
+ viewerTableSettings: n.editor || (d = n.viewerTableSettings) == null ? void 0 : d[e.id],
2692
+ adHocFilterValues: o.adHocFilterValues,
2693
+ selectedSheetId: t,
2694
+ inlineFilterValuesMap: o.inlineFilterValuesMap,
2695
+ dashboardControls: s.controls,
2696
+ dashboardControlValues: o.controlValues,
2697
+ cardControlValuesMap: o.cardControlValuesMap,
2698
+ // Keep a selection-only context so the query has one resolved-input contract.
2699
+ dashboardInputContext: a && (a.inputs.length > 0 || a.selections.length > 0) ? a : void 0,
2700
+ includeAuthoredFilters: i
2701
+ };
2702
+ }
2703
+ function Ct({ card: e, context: t }, n) {
2704
+ return we({
2705
+ card: e,
2706
+ cardConfig: t.queryRelevantConfig,
2707
+ resolvedFields: t.resolvedDateFields,
2708
+ semanticExecutionPayload: n.semanticExecutionPayload
2709
+ });
2710
+ }
2711
+ function vt(e, t, n) {
2712
+ const { card: o } = e, i = Ct(e, t), s = gt(o, e.context, {
2713
+ resolvedPrimaryDateField: i,
2714
+ timezone: t.calendarContext.tz,
2715
+ allowMinutePrecision: n
2716
+ });
2717
+ return s.status === "blocked" ? { ...s, card: o, resolvedPrimaryDateField: i } : {
2718
+ status: "ready",
2719
+ card: o,
2720
+ queryContext: s.queryContext,
2721
+ compiledFilters: s.compiledFilters,
2722
+ resolvedPrimaryDateField: i
2723
+ };
2724
+ }
2725
+ function Li({
2726
+ dashboard: e,
2727
+ dashboardInputValues: t,
2728
+ adHocFilterValues: n,
2729
+ calendar: o,
2730
+ selectedSheetId: i,
2731
+ sheetSelection: s = "current",
2732
+ dashboardControlValues: r,
2733
+ cardControlValuesMap: a,
2734
+ semanticExecutionPayload: c,
2735
+ timezone: d
2736
+ }) {
2737
+ const l = e ? [...Be(e)] : void 0, u = i ?? null, f = (g) => {
2738
+ var h;
2739
+ return e ? pn({
2740
+ dashboard: e,
2741
+ runtimeValues: { dashboardInputValues: t },
2742
+ adHocFilterValues: n,
2743
+ sheetId: g,
2744
+ sheetKind: qe(
2745
+ (h = e.sheets) == null ? void 0 : h.find((v) => v.id === g)
2746
+ ) ? "document" : "dashboard",
2747
+ calendar: o
2748
+ }) : [];
2749
+ }, p = s === "all" ? Array.from(
2750
+ new Map(
2751
+ ((e == null ? void 0 : e.sheets) || []).flatMap(
2752
+ (g) => f(g.id).map(
2753
+ (h) => [h.filterId, h]
2754
+ )
2755
+ )
2756
+ ).values()
2757
+ ) : f(u), m = {
2758
+ ...r || {}
2759
+ }, b = s === "all" ? q({ sheets: (e == null ? void 0 : e.sheets) || [] }) : u ? q({ sheets: (e == null ? void 0 : e.sheets) || [] }).filter(
2760
+ (g) => g.sheet.id === u
2761
+ ) : [];
2762
+ for (const g of b)
2763
+ Object.assign(m, (a == null ? void 0 : a[g.card.id]) || {});
2764
+ const I = mn({
2765
+ filterDefinitions: l,
2766
+ filterValues: p
2767
+ }), y = Do({
2768
+ filters: l,
2769
+ filterValues: I,
2770
+ dashboard: e,
2771
+ semanticExecutionPayload: c,
2772
+ timezone: d
2773
+ });
2774
+ return {
2775
+ selectedSheetId: u,
2776
+ filterValues: y,
2777
+ controlValues: m
2778
+ };
2779
+ }
2780
+ function Hi({
2781
+ dashboard: e,
2782
+ cardId: t,
2783
+ transientContexts: n,
2784
+ cardViewStates: o,
2785
+ viewerTableSettings: i,
2786
+ semanticExecutionPayload: s,
2787
+ adHocFilterValues: r,
2788
+ inlineFilterValuesMap: a,
2789
+ dashboardControlValues: c,
2790
+ cardControlValuesMap: d,
2791
+ dashboardInputValues: l,
2792
+ calendar: u,
2793
+ matrixCatalog: f,
2794
+ cardOverride: p,
2795
+ sheetId: m,
2796
+ documentSection: b,
2797
+ editor: I,
2798
+ withRequest: y
2799
+ }) {
2800
+ var v;
2801
+ if (!e)
2802
+ return null;
2803
+ p && !ee(e, t) && m && (e = { ...e, sheets: (v = e.sheets) == null ? void 0 : v.map((C) => C.id === m ? { ...C, cards: [...C.cards ?? [], p] } : C) });
2804
+ const g = ee(e, t);
2805
+ if (!g)
2806
+ return null;
2807
+ const h = Wo({
2808
+ card: p ?? g.card,
2809
+ place: b ? { kind: "documentSection", section: b } : { kind: "sheet", sheetId: g.sheet.id },
2810
+ source: {
2811
+ dashboard: e,
2812
+ adHocFilterValues: r,
2813
+ controlValues: c,
2814
+ inlineFilterValuesMap: a,
2815
+ cardControlValuesMap: d ? Object.fromEntries(
2816
+ Object.entries(d).filter(
2817
+ (C) => C[1] !== void 0
2818
+ )
2819
+ ) : void 0,
2820
+ dashboardInputValues: l,
2821
+ transientContexts: n,
2822
+ cardViewStates: o,
2823
+ viewerTableSettings: i,
2824
+ calendar: u,
2825
+ ...I ? { editor: I } : {}
2826
+ },
2827
+ semanticExecutionPayload: s,
2828
+ matrixCatalog: f,
2829
+ withRequest: y
2830
+ });
2831
+ return h.status === "blocked" ? h : {
2832
+ status: "ready",
2833
+ card: p ?? g.card,
2834
+ sheetId: g.sheet.id,
2835
+ queryContext: h.queryContext,
2836
+ ...h.matrix ? { matrix: h.matrix } : {},
2837
+ ...h.request ? { request: h.request } : {}
2838
+ };
2839
+ }
2840
+ function Jo(e, t) {
2841
+ const n = bn({
2842
+ inputs: e.inputs,
2843
+ dashboardFilters: [...Be(e)]
2844
+ }), o = yt(e, t);
2845
+ return n.filter(
2846
+ (i) => W(i, { sheetId: t, sheetKind: "document" }) || i.kind === "filter" && (i.runtimeScope === "shared" || i.runtimeScope === "perSheet") && Ae(i, o)
2847
+ );
2848
+ }
2849
+ function yt(e, t) {
2850
+ return {
2851
+ ...In(e).get(t) ?? {
2852
+ sheetId: t,
2853
+ cardIds: /* @__PURE__ */ new Set()
2854
+ },
2855
+ sheetKind: "document"
2856
+ };
2857
+ }
2858
+ function Ki(e, t) {
2859
+ const n = yt(e, t);
2860
+ return (e.inputs || []).some(
2861
+ (o) => Ae(o, n)
2862
+ );
2863
+ }
2864
+ function Xo(e) {
2865
+ const t = {
2866
+ id: e.id,
2867
+ label: e.label,
2868
+ variableName: e.variableName,
2869
+ requiredAtExecution: !!e.requiredAtExecution,
2870
+ documentPlacement: "input_bar",
2871
+ description: e.description
2872
+ };
2873
+ return e.kind === "filter" ? {
2874
+ ...t,
2875
+ kind: "filter",
2876
+ filter: e.filter,
2877
+ exports: e.exports
2878
+ } : {
2879
+ ...t,
2880
+ kind: "control",
2881
+ control: e.control,
2882
+ exports: e.exports
2883
+ };
2884
+ }
2885
+ function Qi({
2886
+ control: e,
2887
+ existingInputs: t,
2888
+ sheetId: n,
2889
+ inputId: o
2890
+ }) {
2891
+ const i = Ne(
2892
+ e.id || e.label,
2893
+ t
2894
+ ), s = e.id === i ? e : { ...e, id: i };
2895
+ return {
2896
+ id: o || ue(),
2897
+ kind: "control",
2898
+ label: s.label,
2899
+ variableName: i,
2900
+ requiredAtExecution: s.requiredAtExecution,
2901
+ scope: { kind: "sheets", sheetIds: [n] },
2902
+ runtimeScope: "perSheet",
2903
+ presentation: { placement: "toolbar" },
2904
+ control: s,
2905
+ exports: lt(s)
2906
+ };
2907
+ }
2908
+ function $i({
2909
+ input: e,
2910
+ allInputs: t,
2911
+ label: n,
2912
+ variableName: o
2913
+ }) {
2914
+ const i = (n == null ? void 0 : n.trim()) || e.label, s = o === void 0 ? e.variableName : Ne(
2915
+ o,
2916
+ t.filter((a) => a.id !== e.id)
2917
+ );
2918
+ if (e.kind === "filter") {
2919
+ if (!e.filter)
2920
+ throw new Error(
2921
+ `Referenced dashboard input '${e.id}' cannot be edited as a document input.`
2922
+ );
2923
+ const a = {
2924
+ ...e.filter,
2925
+ title: i,
2926
+ variableName: s
2927
+ };
2928
+ return {
2929
+ ...e,
2930
+ label: i,
2931
+ variableName: s,
2932
+ filter: a,
2933
+ exports: co(a)
2934
+ };
2935
+ }
2936
+ const r = {
2937
+ ...e.control,
2938
+ id: s,
2939
+ label: i
2940
+ };
2941
+ return {
2942
+ ...e,
2943
+ label: i,
2944
+ variableName: s,
2945
+ requiredAtExecution: r.requiredAtExecution,
2946
+ control: r,
2947
+ exports: lt(r)
2948
+ };
2949
+ }
2950
+ function Ui(e, t, n) {
2951
+ return !t || !n || t === n ? e : {
2952
+ ...e,
2953
+ sections: e.sections.map(
2954
+ (o) => Dn(
2955
+ o,
2956
+ (i) => ei(i, t, n)
2957
+ )
2958
+ )
2959
+ };
2960
+ }
2961
+ function ei(e, t, n) {
2962
+ var s;
2963
+ const o = `[[param.${t}]]`, i = `[[param.${n}]]`;
2964
+ return {
2965
+ ...e,
2966
+ ...(s = e.sql) != null && s.includes(o) ? { sql: e.sql.split(o).join(i) } : {},
2967
+ ...e.controls ? {
2968
+ controls: e.controls.map(
2969
+ (r) => r.id === t ? { ...r, id: n } : r
2970
+ )
2971
+ } : {},
2972
+ ...e.controlBindings ? {
2973
+ controlBindings: e.controlBindings.map((r) => ({
2974
+ ...r,
2975
+ controlId: r.controlId === t ? n : r.controlId,
2976
+ ...r.target === "sql_param" && r.paramId === t ? { paramId: n } : {}
2977
+ }))
2978
+ } : {}
2979
+ };
2980
+ }
2981
+ function Wi(e, t) {
2982
+ return e.kind === "filter" && lo(
2983
+ Xo(e),
2984
+ t
2985
+ );
2986
+ }
2987
+ function Yi(e) {
2988
+ var n;
2989
+ const t = {};
2990
+ for (const o of e)
2991
+ o.kind === "filter" && (t[o.id] = ((n = o.slot) == null ? void 0 : n.status) === "cleared" ? void 0 : o.filterValue);
2992
+ return t;
2993
+ }
2994
+ function Zi(e) {
2995
+ var n;
2996
+ const t = {};
2997
+ for (const o of e)
2998
+ o.kind === "control" && ((n = o.slot) == null ? void 0 : n.status) === "set" && (t[o.id] = o.controlValue);
2999
+ return t;
3000
+ }
3001
+ function Ji({
3002
+ dashboard: e,
3003
+ sheetId: t,
3004
+ filterValuesByInputId: n,
3005
+ controlValuesByInputId: o
3006
+ }) {
3007
+ const i = Jo(e, t);
3008
+ let s = {};
3009
+ for (const r of i) {
3010
+ if (r.kind === "filter" && n && Object.prototype.hasOwnProperty.call(n, r.id)) {
3011
+ const a = n[r.id];
3012
+ s = R(
3013
+ s,
3014
+ r,
3015
+ { sheetId: t },
3016
+ a ? {
3017
+ status: "set",
3018
+ value: {
3019
+ kind: "filter",
3020
+ filterValue: a
3021
+ }
3022
+ } : { status: "cleared" }
3023
+ );
3024
+ }
3025
+ if (r.kind === "control" && o && Object.prototype.hasOwnProperty.call(o, r.id)) {
3026
+ const a = o[r.id];
3027
+ s = R(
3028
+ s,
3029
+ r,
3030
+ { sheetId: t },
3031
+ a === void 0 ? { status: "cleared" } : {
3032
+ status: "set",
3033
+ value: {
3034
+ kind: "control",
3035
+ value: a
3036
+ }
3037
+ }
3038
+ );
3039
+ }
3040
+ }
3041
+ return Qe({
3042
+ dashboard: e,
3043
+ dashboardInputValues: s,
3044
+ sheetId: t
3045
+ });
3046
+ }
3047
+ export {
3048
+ $i as $,
3049
+ Ao as A,
3050
+ Li as B,
3051
+ N as C,
3052
+ Bn as D,
3053
+ Po as E,
3054
+ ji as F,
3055
+ _i as G,
3056
+ Uo as H,
3057
+ zi as I,
3058
+ Ai as J,
3059
+ Wo as K,
3060
+ En as L,
3061
+ Ni as M,
3062
+ Bi as N,
3063
+ Ie as O,
3064
+ be as P,
3065
+ wi as Q,
3066
+ fo as R,
3067
+ qi as S,
3068
+ ut as T,
3069
+ te as U,
3070
+ Mo as V,
3071
+ ft as W,
3072
+ Pn as X,
3073
+ ao as Y,
3074
+ Xo as Z,
3075
+ Wi as _,
3076
+ Ei as a,
3077
+ Ui as a0,
3078
+ Ji as a1,
3079
+ Yi as a2,
3080
+ Zi as a3,
3081
+ co as a4,
3082
+ _ as a5,
3083
+ Di as a6,
3084
+ Oi as a7,
3085
+ Ti as a8,
3086
+ Ki as a9,
3087
+ Ri as b,
3088
+ Fi as c,
3089
+ Hi as d,
3090
+ ro as e,
3091
+ Qi as f,
3092
+ Jo as g,
3093
+ Si as h,
3094
+ Gi as i,
3095
+ $o as j,
3096
+ xi as k,
3097
+ so as l,
3098
+ Mi as m,
3099
+ Vi as n,
3100
+ Ze as o,
3101
+ Pi as p,
3102
+ ki as q,
3103
+ Eo as r,
3104
+ Ci as s,
3105
+ gi as t,
3106
+ Qn as u,
3107
+ Hn as v,
3108
+ vi as w,
3109
+ qn as x,
3110
+ Qe as y,
3111
+ yi as z
3112
+ };