react-semaphor 0.1.563 → 0.1.565

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