react-semaphor 0.1.545 → 0.1.547

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