react-semaphor 0.1.444 → 0.1.446

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 (136) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/analytics-protocol/index.cjs +1 -1
  3. package/dist/analytics-protocol/index.js +123 -107
  4. package/dist/appearance/index.cjs +1 -1
  5. package/dist/brand-studio/index.cjs +2 -2
  6. package/dist/brand-studio/index.js +5 -4
  7. package/dist/briefings/index.cjs +1 -1
  8. package/dist/briefings/index.js +526 -457
  9. package/dist/chunks/analyze-result-contract-BHb7sUUW.cjs +1 -0
  10. package/dist/chunks/analyze-result-contract-DUv3QnMl.js +29 -0
  11. package/dist/chunks/{braces-CbO-aIwH.js → braces-BKimshER.cjs} +1 -1
  12. package/dist/chunks/{code-editor-BpADiIlq.js → code-editor-B4gTfvc5.js} +6800 -6560
  13. package/dist/chunks/code-editor-BYVorgOf.cjs +138 -0
  14. package/dist/chunks/common-types-CQ6SHfLk.cjs +1 -0
  15. package/dist/chunks/{common-types-ClkOI-3O.js → common-types-DFsDdpH7.js} +22 -21
  16. package/dist/chunks/dashboard-DGX9b3T-.cjs +1402 -0
  17. package/dist/chunks/{dashboard-CJNVq8XI.js → dashboard-ECv6p6DC.js} +50511 -47720
  18. package/dist/chunks/{dashboard-briefing-launcher-Bg_SeBV8.js → dashboard-briefing-launcher-BpWq3shh.js} +190 -187
  19. package/dist/chunks/dashboard-briefing-launcher-C2kEWFgy.cjs +26 -0
  20. package/dist/chunks/{dashboard-controls-CYBi_mes.js → dashboard-controls-DNoMwxMy.cjs} +2 -2
  21. package/dist/chunks/{dashboard-controls-Da9MkPaf.js → dashboard-controls-DPLepxZy.js} +14 -13
  22. package/dist/chunks/dashboard-date-comparison-definition-DZq0htjG.cjs +1 -0
  23. package/dist/chunks/{dashboard-json-BtrdGo1U.js → dashboard-json-0Etvlp57.js} +14 -12
  24. package/dist/chunks/dashboard-json-4LbKuMSm.cjs +1 -0
  25. package/dist/chunks/{edit-dashboard-visual-kE6_3R3j.js → edit-dashboard-visual-0uKSZPPa.js} +8302 -8123
  26. package/dist/chunks/edit-dashboard-visual-C1uVqhI5.cjs +182 -0
  27. package/dist/chunks/{editor-action-buttons-8_CQa8Hb.js → editor-action-buttons-DKXO5aK7.cjs} +1 -1
  28. package/dist/chunks/{editor-action-buttons-DROkx4PS.js → editor-action-buttons-DpA5PdEo.js} +24 -23
  29. package/dist/chunks/{index-D7KJindZ.js → format-types-CSv0V7mm.cjs} +1 -1
  30. package/dist/chunks/{index-CnujJ3fa.js → format-types-CZH5w1lo.js} +23 -17
  31. package/dist/chunks/{layout-grid-B08pP7v6.js → layout-grid-3-HWzEwU.cjs} +1 -1
  32. package/dist/chunks/{metric-comparison-CPoDx56y.js → metric-comparison-BJ_Qu1ZF.js} +1 -1
  33. package/dist/chunks/metric-comparison-CUAJ8n4y.cjs +1 -0
  34. package/dist/chunks/mouse-pointer-2-BOL92ext.cjs +6 -0
  35. package/dist/chunks/mouse-pointer-2-DXNw3_3o.js +19 -0
  36. package/dist/chunks/{palette-C0yjT5Tv.js → palette-DW_l7Jr0.cjs} +1 -1
  37. package/dist/chunks/pivot-result-identity-B6QCWOSi.js +94 -0
  38. package/dist/chunks/pivot-result-identity-CDLRT-YG.cjs +1 -0
  39. package/dist/chunks/pivot-result-lifecycle-BM3Pl-D1.js +914 -0
  40. package/dist/chunks/pivot-result-lifecycle-DPc0ANwk.cjs +4 -0
  41. package/dist/chunks/presentation-execution-BTV-Q43g.cjs +1 -0
  42. package/dist/chunks/presentation-execution-CGlb7YZ6.js +637 -0
  43. package/dist/chunks/report-preferences-dialog-CBMox_qt.cjs +1 -0
  44. package/dist/chunks/{report-preferences-dialog-Dq7rmN93.js → report-preferences-dialog-CkZ2KHWX.js} +7 -6
  45. package/dist/chunks/report-runtime-context-C8LZFsqV.cjs +1 -0
  46. package/dist/chunks/report-runtime-context-Qzn11HQe.js +387 -0
  47. package/dist/chunks/{save-Xdc4pnys.js → save-4_uMnE6s.cjs} +1 -1
  48. package/dist/chunks/{search-Dcud9ajy.js → search-6ZmeMq55.cjs} +1 -1
  49. package/dist/chunks/temporal-bucket-BnPxGrAi.js +446 -0
  50. package/dist/chunks/temporal-bucket-authoring-BUZMuVca.js +205 -0
  51. package/dist/chunks/temporal-bucket-authoring-CPTwHzvs.cjs +1 -0
  52. package/dist/chunks/temporal-bucket-contract-B2bJ1oe4.js +108 -0
  53. package/dist/chunks/temporal-bucket-contract-ChDBWX8I.cjs +1 -0
  54. package/dist/chunks/temporal-bucket-pMnV-4Nj.cjs +1 -0
  55. package/dist/chunks/{comparison-document-migration-Dj6xZMCb.js → temporal-result-owner-Cb27SSG9.js} +152 -123
  56. package/dist/chunks/temporal-result-owner-f6-i65Fb.cjs +1 -0
  57. package/dist/chunks/token-types-BdQ8kHBm.cjs +1 -0
  58. package/dist/chunks/token-types-DLo91nOf.js +8 -0
  59. package/dist/chunks/{update-policy-DnF_74zC.js → update-policy-BxvYMYz0.cjs} +1 -1
  60. package/dist/chunks/{update-policy-De2NswtM.js → update-policy-eg59mQqv.js} +1 -1
  61. package/dist/chunks/validators-9D4KBqKD.cjs +1 -0
  62. package/dist/chunks/validators-wZ2WlNHc.js +4640 -0
  63. package/dist/dashboard/index.cjs +1 -1
  64. package/dist/dashboard/index.js +2 -2
  65. package/dist/dashboard-authoring/index.cjs +3 -3
  66. package/dist/dashboard-authoring/index.js +136 -126
  67. package/dist/data-app-builder/index.cjs +13 -18
  68. package/dist/data-app-builder/index.js +91 -105
  69. package/dist/data-app-codegen/index.cjs +1 -1
  70. package/dist/data-app-codegen/index.js +2 -2
  71. package/dist/data-app-codegen-node/index.cjs +1 -1
  72. package/dist/data-app-codegen-node/index.js +3 -3
  73. package/dist/data-app-sdk/index.cjs +2 -2
  74. package/dist/data-app-sdk/index.js +34 -35
  75. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  76. package/dist/data-app-sdk-adapters/index.js +5 -5
  77. package/dist/data-app-sdk-validation/index.cjs +1 -1
  78. package/dist/data-app-sdk-validation/index.js +9 -10
  79. package/dist/format-utils/index.cjs +3 -3
  80. package/dist/format-utils/index.js +155 -176
  81. package/dist/index.cjs +1 -1
  82. package/dist/index.js +180 -174
  83. package/dist/report-runtime-context/index.cjs +1 -1
  84. package/dist/report-runtime-context/index.js +7 -392
  85. package/dist/shared/index.cjs +1 -1
  86. package/dist/style.css +1 -1
  87. package/dist/surfboard/index.cjs +1 -1
  88. package/dist/surfboard/index.js +3 -3
  89. package/dist/types/analytics-protocol.d.ts +257 -48
  90. package/dist/types/briefings.d.ts +138 -50
  91. package/dist/types/dashboard-assistant.d.ts +207 -52
  92. package/dist/types/dashboard-authoring.d.ts +182 -50
  93. package/dist/types/dashboard.d.ts +290 -48
  94. package/dist/types/data-app-builder.d.ts +48 -42
  95. package/dist/types/data-app-codegen-node.d.ts +50 -44
  96. package/dist/types/data-app-codegen.d.ts +50 -44
  97. package/dist/types/data-app-sdk-adapters.d.ts +48 -42
  98. package/dist/types/data-app-sdk-validation.d.ts +81 -43
  99. package/dist/types/data-app-sdk.d.ts +83 -45
  100. package/dist/types/format-utils.d.ts +645 -67
  101. package/dist/types/index.cjs +1 -1
  102. package/dist/types/index.js +19 -19
  103. package/dist/types/main.d.ts +305 -100
  104. package/dist/types/report-runtime-context.d.ts +3 -0
  105. package/dist/types/shared.d.ts +116 -41
  106. package/dist/types/surfboard.d.ts +290 -48
  107. package/dist/types/types.d.ts +455 -65
  108. package/package.json +3 -1
  109. package/dist/chunks/analyze-result-contract-BswhsmWT.js +0 -1
  110. package/dist/chunks/analyze-result-contract-CfOBEwaC.js +0 -1998
  111. package/dist/chunks/code-editor-M7HTUhdF.js +0 -138
  112. package/dist/chunks/common-types-C73-Ud1-.js +0 -1
  113. package/dist/chunks/comparison-document-migration-DbU_BTxR.js +0 -1
  114. package/dist/chunks/csv-utils-BZDvO2Fw.js +0 -376
  115. package/dist/chunks/csv-utils-Co0WxHke.js +0 -4
  116. package/dist/chunks/dashboard-DxZuqe8t.js +0 -1402
  117. package/dist/chunks/dashboard-briefing-launcher-Do6ZcOj4.js +0 -26
  118. package/dist/chunks/dashboard-date-comparison-definition-DGZr3m-b.js +0 -1
  119. package/dist/chunks/dashboard-json-ezLyW7AK.js +0 -1
  120. package/dist/chunks/edit-dashboard-visual-DEb9MeSM.js +0 -182
  121. package/dist/chunks/metric-comparison-DVy3fll_.js +0 -1
  122. package/dist/chunks/numeric-presentation-BJs5lSar.js +0 -517
  123. package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +0 -1
  124. package/dist/chunks/report-preferences-dialog-D5sIaFnb.js +0 -1
  125. package/dist/chunks/source-identity-5OPV4gvg.js +0 -92
  126. package/dist/chunks/source-identity-Cbo2LOHQ.js +0 -1
  127. package/dist/chunks/validators-B2vUAqTf.js +0 -1
  128. package/dist/chunks/validators-Bce_J7Vd.js +0 -2448
  129. /package/dist/chunks/{card-config-utils-15sRtebL.js → card-config-utils-15sRtebL.cjs} +0 -0
  130. /package/dist/chunks/{catalog-field-grounding-Bnx-3tE0.js → catalog-field-grounding-Bnx-3tE0.cjs} +0 -0
  131. /package/dist/chunks/{dashboard-input-contract-DV3cshjz.js → dashboard-input-contract-DV3cshjz.cjs} +0 -0
  132. /package/dist/chunks/{index-Dpm_VET4.js → index-Dpm_VET4.cjs} +0 -0
  133. /package/dist/chunks/{index-jSrCwPQz.js → index-jSrCwPQz.cjs} +0 -0
  134. /package/dist/chunks/{normalize-dashboard-for-dirty-check-BXRUMVb2.js → normalize-dashboard-for-dirty-check-BXRUMVb2.cjs} +0 -0
  135. /package/dist/chunks/{operators-DrTQsJXv.js → operators-DrTQsJXv.cjs} +0 -0
  136. /package/dist/chunks/{use-debounced-dirty-check-XHSwAefL.js → use-debounced-dirty-check-XHSwAefL.cjs} +0 -0
@@ -0,0 +1,637 @@
1
+ import { b as C } from "./report-runtime-context-Qzn11HQe.js";
2
+ import { canonicalizeSupportedLocale as F, canonicalizeSupportedCurrencyCode as y } from "../value-format-preferences/index.js";
3
+ import { p as M } from "./temporal-bucket-BnPxGrAi.js";
4
+ function I(r) {
5
+ if (!r) return !1;
6
+ const e = r.toLowerCase().replace("_", "-");
7
+ return e === "en-in" || e.startsWith("en-in-");
8
+ }
9
+ function $(r, e) {
10
+ const i = Math.abs(r);
11
+ return i >= 1e12 ? { divisor: 1e12, suffix: "T" } : i >= 1e9 ? { divisor: 1e9, suffix: "B" } : I(e) && i >= 1e7 ? { divisor: 1e7, suffix: "Cr" } : i >= 1e6 ? { divisor: 1e6, suffix: "M" } : I(e) && i >= 1e5 ? { divisor: 1e5, suffix: "L" } : i >= 1e3 ? { divisor: 1e3, suffix: "K" } : { divisor: 1, suffix: "" };
12
+ }
13
+ function h(r, e) {
14
+ try {
15
+ const i = d(e);
16
+ return $(r, i);
17
+ } catch {
18
+ return $(r, "en-US");
19
+ }
20
+ }
21
+ function P(r) {
22
+ try {
23
+ return new Intl.NumberFormat(r), !0;
24
+ } catch {
25
+ return !1;
26
+ }
27
+ }
28
+ function d(r) {
29
+ return r && P(r) ? r : "en-US";
30
+ }
31
+ function v(r, e) {
32
+ if (r == null || isNaN(r))
33
+ return "";
34
+ const i = d(e == null ? void 0 : e.locale);
35
+ let a = r;
36
+ if (e != null && e.multiplyBy && (a *= e.multiplyBy), e != null && e.useSuffix) {
37
+ const { divisor: t, suffix: s } = h(a, i);
38
+ a = a / t;
39
+ const n = new Intl.NumberFormat(i, {
40
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
41
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
42
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
43
+ }).format(a);
44
+ return `${(e == null ? void 0 : e.prefix) ?? ""}${n}${s}${(e == null ? void 0 : e.suffix) ?? ""}`;
45
+ }
46
+ const c = new Intl.NumberFormat(i, {
47
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
48
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
49
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
50
+ }).format(a);
51
+ if (e != null && e.negativeInParentheses && a < 0) {
52
+ const t = c.replace("-", "");
53
+ return `(${(e == null ? void 0 : e.prefix) ?? ""}${t}${(e == null ? void 0 : e.suffix) ?? ""})`;
54
+ }
55
+ return `${(e == null ? void 0 : e.prefix) ?? ""}${c}${(e == null ? void 0 : e.suffix) ?? ""}`;
56
+ }
57
+ function k(r, e) {
58
+ if (r == null || isNaN(r))
59
+ return "";
60
+ const i = d(e == null ? void 0 : e.locale), a = (e == null ? void 0 : e.currency) || "USD", c = r < 0, t = !!(e != null && e.negativeInParentheses && c), s = t ? Math.abs(r) : r;
61
+ try {
62
+ if (e != null && e.useSuffix) {
63
+ const { divisor: u, suffix: l } = h(s, i), m = s / u, D = `${new Intl.NumberFormat(i, {
64
+ style: "currency",
65
+ currency: a,
66
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
67
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
68
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
69
+ }).format(m)}${l}`;
70
+ return t ? `(${D})` : D;
71
+ }
72
+ const n = new Intl.NumberFormat(i, {
73
+ style: "currency",
74
+ currency: a,
75
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
76
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
77
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
78
+ }).format(s);
79
+ return t ? `(${n})` : n;
80
+ } catch {
81
+ const n = Math.abs(r), u = e != null && e.useSuffix ? h(n, i) : { divisor: 1, suffix: "" }, l = v(
82
+ n / u.divisor,
83
+ {
84
+ locale: i,
85
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
86
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
87
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
88
+ }
89
+ ), m = `${a} ${l}${u.suffix}`;
90
+ return c ? e != null && e.negativeInParentheses ? `(${m})` : `-${m}` : m;
91
+ }
92
+ }
93
+ function S(r, e) {
94
+ if (r == null || isNaN(r))
95
+ return "";
96
+ const i = d(e == null ? void 0 : e.locale), c = (e == null ? void 0 : e.alreadyPercent) ?? (e == null ? void 0 : e.percentValueMode) === "whole" ? r / 100 : r;
97
+ return new Intl.NumberFormat(i, {
98
+ style: "percent",
99
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
100
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
101
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0
102
+ }).format(c);
103
+ }
104
+ function E(r, e) {
105
+ if (r == null || isNaN(r))
106
+ return "";
107
+ const i = d(e == null ? void 0 : e.locale);
108
+ return new Intl.NumberFormat(i, {
109
+ notation: "scientific",
110
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
111
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2
112
+ }).format(r);
113
+ }
114
+ function G(r, e) {
115
+ if (r == null || Number.isNaN(r))
116
+ return "";
117
+ const i = e.scale === void 0 ? r : r * e.scale, a = e.negativeStyle === "parentheses" && i < 0, c = a ? Math.abs(i) : i, t = {
118
+ style: e.type === "number" ? "decimal" : e.type,
119
+ locale: e.locale,
120
+ currency: e.currency,
121
+ minimumFractionDigits: e.minimumFractionDigits,
122
+ maximumFractionDigits: e.maximumFractionDigits,
123
+ useGrouping: e.useGrouping,
124
+ percentValueMode: e.percentValueMode,
125
+ useSuffix: e.compact
126
+ };
127
+ let s;
128
+ switch (e.type) {
129
+ case "currency":
130
+ s = k(c, t);
131
+ break;
132
+ case "percent":
133
+ s = S(c, t);
134
+ break;
135
+ case "scientific":
136
+ s = E(c, t);
137
+ break;
138
+ default:
139
+ s = v(c, t);
140
+ break;
141
+ }
142
+ const n = `${e.prefix ?? ""}${s}${e.suffix ?? ""}`;
143
+ return a ? `(${n})` : n;
144
+ }
145
+ function J(r, e, i = "en-US") {
146
+ if (r == null || isNaN(r))
147
+ return "";
148
+ const a = d((e == null ? void 0 : e.locale) || i), c = (e == null ? void 0 : e.style) || "decimal", t = c === "decimal" ? "number" : c;
149
+ return t === "currency" && new Intl.NumberFormat(a, {
150
+ style: "currency",
151
+ currency: (e == null ? void 0 : e.currency) || "USD"
152
+ }), G(r, {
153
+ type: t,
154
+ locale: a,
155
+ currency: t === "currency" ? (e == null ? void 0 : e.currency) || "USD" : void 0,
156
+ minimumFractionDigits: (e == null ? void 0 : e.minimumFractionDigits) ?? 0,
157
+ maximumFractionDigits: (e == null ? void 0 : e.maximumFractionDigits) ?? 2,
158
+ useGrouping: (e == null ? void 0 : e.useGrouping) ?? !0,
159
+ percentValueMode: t === "percent" ? (e == null ? void 0 : e.percentValueMode) ?? "whole" : void 0,
160
+ scale: e == null ? void 0 : e.scale,
161
+ compact: e == null ? void 0 : e.compact,
162
+ negativeStyle: e == null ? void 0 : e.negativeStyle,
163
+ prefix: e == null ? void 0 : e.prefix,
164
+ suffix: e == null ? void 0 : e.suffix
165
+ });
166
+ }
167
+ function Y(r, e, i) {
168
+ const a = {
169
+ style: e === "currency" ? "currency" : e === "percent" ? "percent" : "decimal",
170
+ locale: i == null ? void 0 : i.locale,
171
+ currency: i == null ? void 0 : i.currency,
172
+ minimumFractionDigits: i == null ? void 0 : i.decimalPlaces,
173
+ maximumFractionDigits: i == null ? void 0 : i.decimalPlaces,
174
+ useSuffix: i == null ? void 0 : i.useSuffix,
175
+ prefix: i == null ? void 0 : i.prefix,
176
+ suffix: i == null ? void 0 : i.suffix,
177
+ negativeInParentheses: i == null ? void 0 : i.negativeInParentheses,
178
+ multiplyBy: i == null ? void 0 : i.multiplyBy
179
+ };
180
+ switch (e) {
181
+ case "currency":
182
+ return k(r, a);
183
+ case "percent":
184
+ return S(r, a);
185
+ case "scientific":
186
+ return E(r, a);
187
+ default:
188
+ return v(r, a);
189
+ }
190
+ }
191
+ const V = [
192
+ "type",
193
+ "locale",
194
+ "minimumFractionDigits",
195
+ "maximumFractionDigits",
196
+ "useGrouping",
197
+ "prefix",
198
+ "suffix",
199
+ "negativeStyle",
200
+ "compact",
201
+ "scale",
202
+ "currency",
203
+ "percentValueMode"
204
+ ];
205
+ function j(r) {
206
+ if (r === null || typeof r != "object" || Array.isArray(r))
207
+ return !1;
208
+ const e = Object.getPrototypeOf(r);
209
+ return e === null || e === Object.prototype;
210
+ }
211
+ function K(r) {
212
+ if (!j(r))
213
+ return {
214
+ ok: !1,
215
+ issues: [{ path: "$", message: "Numeric format must be an object." }]
216
+ };
217
+ const e = [], i = new Set(V);
218
+ Object.keys(r).filter((t) => !i.has(t)).forEach(
219
+ (t) => e.push({ path: t, message: `Unknown property "${t}".` })
220
+ ), r.type !== "number" && r.type !== "currency" && r.type !== "percent" && r.type !== "scientific" && e.push({
221
+ path: "type",
222
+ message: "Expected number, currency, percent, or scientific."
223
+ });
224
+ const a = r.locale === void 0 ? void 0 : F(r.locale);
225
+ r.locale !== void 0 && !a && e.push({ path: "locale", message: "Expected a supported BCP 47 locale." });
226
+ const c = r.currency === void 0 ? void 0 : y(r.currency);
227
+ r.currency !== void 0 && !c && e.push({
228
+ path: "currency",
229
+ message: "Expected a supported ISO 4217 currency code."
230
+ });
231
+ for (const t of ["minimumFractionDigits", "maximumFractionDigits"]) {
232
+ const s = r[t];
233
+ s !== void 0 && (!Number.isInteger(s) || typeof s != "number" || s < 0 || s > 20) && e.push({
234
+ path: t,
235
+ message: "Expected an integer from 0 to 20."
236
+ });
237
+ }
238
+ typeof r.minimumFractionDigits == "number" && typeof r.maximumFractionDigits == "number" && r.minimumFractionDigits > r.maximumFractionDigits && e.push({
239
+ path: "maximumFractionDigits",
240
+ message: "Must be greater than or equal to minimumFractionDigits."
241
+ });
242
+ for (const t of ["useGrouping", "compact"])
243
+ r[t] !== void 0 && typeof r[t] != "boolean" && e.push({ path: t, message: "Expected a boolean." });
244
+ for (const t of ["prefix", "suffix"])
245
+ r[t] !== void 0 && typeof r[t] != "string" && e.push({ path: t, message: "Expected a string." });
246
+ return r.negativeStyle !== void 0 && r.negativeStyle !== "minus" && r.negativeStyle !== "parentheses" && e.push({
247
+ path: "negativeStyle",
248
+ message: "Expected minus or parentheses."
249
+ }), r.percentValueMode !== void 0 && r.percentValueMode !== "fraction" && r.percentValueMode !== "whole" && e.push({
250
+ path: "percentValueMode",
251
+ message: "Expected fraction or whole."
252
+ }), r.scale !== void 0 && (typeof r.scale != "number" || !Number.isFinite(r.scale)) && e.push({ path: "scale", message: "Expected a finite number." }), e.length > 0 ? { ok: !1, issues: e } : {
253
+ ok: !0,
254
+ value: {
255
+ type: r.type,
256
+ ...a ? { locale: a } : {},
257
+ ...r.minimumFractionDigits !== void 0 ? { minimumFractionDigits: r.minimumFractionDigits } : {},
258
+ ...r.maximumFractionDigits !== void 0 ? { maximumFractionDigits: r.maximumFractionDigits } : {},
259
+ ...r.useGrouping !== void 0 ? { useGrouping: r.useGrouping } : {},
260
+ ...r.prefix !== void 0 ? { prefix: r.prefix } : {},
261
+ ...r.suffix !== void 0 ? { suffix: r.suffix } : {},
262
+ ...r.negativeStyle !== void 0 ? {
263
+ negativeStyle: r.negativeStyle
264
+ } : {},
265
+ ...r.compact !== void 0 ? { compact: r.compact } : {},
266
+ ...r.scale !== void 0 ? { scale: r.scale } : {},
267
+ ...c ? { currency: c } : {},
268
+ ...r.percentValueMode !== void 0 ? {
269
+ percentValueMode: r.percentValueMode
270
+ } : {}
271
+ }
272
+ };
273
+ }
274
+ function R(r) {
275
+ const e = K(r);
276
+ if (!e.ok)
277
+ return e;
278
+ const i = [];
279
+ return e.value.locale || i.push({
280
+ path: "locale",
281
+ message: "Resolved numeric formats require an explicit locale."
282
+ }), e.value.minimumFractionDigits === void 0 && i.push({
283
+ path: "minimumFractionDigits",
284
+ message: "Resolved numeric formats require minimumFractionDigits."
285
+ }), e.value.maximumFractionDigits === void 0 && i.push({
286
+ path: "maximumFractionDigits",
287
+ message: "Resolved numeric formats require maximumFractionDigits."
288
+ }), e.value.type === "currency" && !e.value.currency && i.push({
289
+ path: "currency",
290
+ message: "Resolved currency formats require an explicit currency."
291
+ }), i.length > 0 ? { ok: !1, issues: i } : e;
292
+ }
293
+ function H(r) {
294
+ var a;
295
+ const e = /* @__PURE__ */ new Set();
296
+ if (r.snapshot.resolvedFormats.forEach((c, t) => {
297
+ if (c.format.type !== "temporal_bucket") {
298
+ if (c.scope.attachmentIndex !== void 0)
299
+ throw new Error(
300
+ `resolvedFormats.${t}.scope.attachmentIndex is not valid for a card export`
301
+ );
302
+ if (c.scope.dashboardId !== r.expectedScope.dashboardId || c.scope.cardId !== r.expectedScope.cardId)
303
+ throw new Error(
304
+ `resolvedFormats.${t}.scope must match the executing dashboard/card`
305
+ );
306
+ if (c.target.kind !== "column")
307
+ throw new Error(
308
+ `resolvedFormats.${t}.target must identify an export column`
309
+ );
310
+ if (e.has(c.target.columnKey))
311
+ throw new Error(
312
+ `resolvedFormats.${t} duplicates export column "${c.target.columnKey}"`
313
+ );
314
+ e.add(c.target.columnKey);
315
+ }
316
+ }), !r.useFormattedValues)
317
+ return;
318
+ if (!((a = r.visibleColumns) != null && a.length))
319
+ throw new Error(
320
+ "visibleColumns must identify every formatted export column"
321
+ );
322
+ const i = r.visibleColumns.find(
323
+ (c) => !e.has(c)
324
+ );
325
+ if (i)
326
+ throw new Error(
327
+ `resolvedFormats is missing visible export column "${i}"`
328
+ );
329
+ }
330
+ function O(r, e) {
331
+ const i = new Intl.NumberFormat(r, {
332
+ style: "currency",
333
+ currency: e
334
+ }).resolvedOptions();
335
+ return {
336
+ minimumFractionDigits: i.minimumFractionDigits,
337
+ maximumFractionDigits: i.maximumFractionDigits
338
+ };
339
+ }
340
+ function _(r) {
341
+ if (r.minimumFractionDigits !== void 0 || r.maximumFractionDigits !== void 0) {
342
+ const i = r.minimumFractionDigits ?? 0;
343
+ return {
344
+ minimumFractionDigits: i,
345
+ maximumFractionDigits: r.maximumFractionDigits ?? Math.max(i, 2)
346
+ };
347
+ }
348
+ const e = r.type === "percent" ? 1 : r.type === "scientific" ? 2 : 0;
349
+ return {
350
+ minimumFractionDigits: e,
351
+ maximumFractionDigits: e
352
+ };
353
+ }
354
+ function Q(r, e, i) {
355
+ const a = F(r.locale) ?? e.locale, c = r.type === "number" || r.type === "currency" ? y(i) : void 0;
356
+ if (!(r.type === "currency" || c !== void 0))
357
+ return {
358
+ ...r,
359
+ locale: a,
360
+ ..._(r)
361
+ };
362
+ const s = c ?? y(r.currency) ?? e.defaultCurrency, n = O(
363
+ a,
364
+ s
365
+ ), u = n.minimumFractionDigits ?? 0, l = n.maximumFractionDigits ?? u, m = r.minimumFractionDigits ?? Math.min(
366
+ u,
367
+ r.maximumFractionDigits ?? u
368
+ ), w = r.maximumFractionDigits ?? Math.max(
369
+ m,
370
+ l
371
+ );
372
+ return {
373
+ ...r,
374
+ type: "currency",
375
+ locale: a,
376
+ currency: s,
377
+ minimumFractionDigits: m,
378
+ maximumFractionDigits: w
379
+ };
380
+ }
381
+ function f(r) {
382
+ if (r === null || typeof r != "object" || Array.isArray(r))
383
+ return !1;
384
+ const e = Object.getPrototypeOf(r);
385
+ return e === null || e === Object.prototype;
386
+ }
387
+ function g(r, e, i) {
388
+ const a = new Set(e), c = Object.keys(r).find((t) => !a.has(t));
389
+ if (c)
390
+ throw new Error(`${i} contains unknown property "${c}"`);
391
+ }
392
+ function T(r, e = "scope") {
393
+ if (!f(r))
394
+ throw new Error(`${e} must be an object`);
395
+ g(
396
+ r,
397
+ ["dashboardId", "cardId", "attachmentIndex"],
398
+ e
399
+ );
400
+ const i = typeof r.dashboardId == "string" ? r.dashboardId.trim() : "";
401
+ if (!i)
402
+ throw new Error(`${e}.dashboardId is required`);
403
+ const a = typeof r.cardId == "string" ? r.cardId.trim() : void 0;
404
+ if (r.cardId !== void 0 && !a)
405
+ throw new Error(`${e}.cardId must be a non-empty string`);
406
+ const c = r.attachmentIndex;
407
+ if (c !== void 0 && (typeof c != "number" || !Number.isInteger(c) || c < 0))
408
+ throw new Error(
409
+ `${e}.attachmentIndex must be a non-negative integer`
410
+ );
411
+ return {
412
+ dashboardId: i,
413
+ ...a ? { cardId: a } : {},
414
+ ...typeof c == "number" ? { attachmentIndex: c } : {}
415
+ };
416
+ }
417
+ function o(r, e, i, a) {
418
+ if (r.kind !== e) return;
419
+ g(r, ["kind", i], a);
420
+ const c = typeof r[i] == "string" ? r[i].trim() : "";
421
+ if (!c)
422
+ throw new Error(`${a}.${i} is required`);
423
+ return c;
424
+ }
425
+ function B(r, e) {
426
+ if (!f(r))
427
+ throw new Error(`${e} must be an object`);
428
+ const i = o(r, "metric", "metricId", e);
429
+ if (i) return { kind: "metric", metricId: i };
430
+ const a = o(r, "column", "columnKey", e);
431
+ if (a) return { kind: "column", columnKey: a };
432
+ const c = o(
433
+ r,
434
+ "matrix_measure",
435
+ "measureId",
436
+ e
437
+ );
438
+ if (c) return { kind: "matrix_measure", measureId: c };
439
+ throw new Error(`${e} is not a valid numeric presentation target`);
440
+ }
441
+ function U(r, e) {
442
+ if (!f(r))
443
+ throw new Error(`${e} must be an object`);
444
+ if (r.kind === "field") {
445
+ g(r, ["kind", "fieldId", "role"], e);
446
+ const c = typeof r.fieldId == "string" ? r.fieldId.trim() : "";
447
+ if (!c)
448
+ throw new Error(`${e}.fieldId is required`);
449
+ const t = r.role;
450
+ if (t !== void 0 && t !== "groupby" && t !== "pivotby")
451
+ throw new Error(`${e}.role must be groupby or pivotby`);
452
+ return {
453
+ kind: "field",
454
+ fieldId: c,
455
+ ...t ? { role: t } : {}
456
+ };
457
+ }
458
+ const i = o(r, "column", "columnKey", e);
459
+ if (i) return { kind: "column", columnKey: i };
460
+ const a = o(
461
+ r,
462
+ "matrix_axis",
463
+ "axisInstanceId",
464
+ e
465
+ );
466
+ if (a) return { kind: "matrix_axis", axisInstanceId: a };
467
+ throw new Error(`${e} is not a valid temporal bucket presentation target`);
468
+ }
469
+ function q(r) {
470
+ return [
471
+ r.dashboardId,
472
+ r.cardId ?? null,
473
+ r.attachmentIndex ?? null
474
+ ];
475
+ }
476
+ function x(r) {
477
+ switch (r.kind) {
478
+ case "metric":
479
+ return [r.kind, r.metricId];
480
+ case "column":
481
+ return [r.kind, r.columnKey];
482
+ case "matrix_measure":
483
+ return [r.kind, r.measureId];
484
+ case "field":
485
+ return [r.kind, r.fieldId, r.role ?? ""];
486
+ case "matrix_axis":
487
+ return [r.kind, r.axisInstanceId];
488
+ }
489
+ }
490
+ function N(r, e) {
491
+ return r.dashboardId === e.dashboardId && r.cardId === e.cardId && r.attachmentIndex === e.attachmentIndex;
492
+ }
493
+ function b(r, e) {
494
+ const i = x(r), a = x(e);
495
+ return i.length === a.length && i.every((c, t) => c === a[t]);
496
+ }
497
+ function A(r) {
498
+ if (!Array.isArray(r))
499
+ throw new Error("resolvedFormats must be an array");
500
+ const e = /* @__PURE__ */ new Set();
501
+ return r.map((i, a) => {
502
+ var u, l;
503
+ const c = `resolvedFormats.${a}`;
504
+ if (!f(i))
505
+ throw new Error(`${c} must be an object`);
506
+ g(i, ["scope", "target", "format"], c);
507
+ const t = T(i.scope, `${c}.scope`);
508
+ if (!f(i.format))
509
+ throw new Error(`${c}.format must be an object`);
510
+ let s;
511
+ if (i.format.type === "temporal_bucket") {
512
+ const m = M(i.format);
513
+ if (!m.ok)
514
+ throw new Error(
515
+ `${c}.format is invalid: ${((u = m.issues[0]) == null ? void 0 : u.message) ?? "invalid value"}`
516
+ );
517
+ s = {
518
+ scope: t,
519
+ target: U(i.target, `${c}.target`),
520
+ format: m.value
521
+ };
522
+ } else {
523
+ const m = R(i.format);
524
+ if (!m.ok)
525
+ throw new Error(
526
+ `${c}.format is invalid: ${((l = m.issues[0]) == null ? void 0 : l.message) ?? "invalid value"}`
527
+ );
528
+ s = {
529
+ scope: t,
530
+ target: B(i.target, `${c}.target`),
531
+ format: m.value
532
+ };
533
+ }
534
+ const n = JSON.stringify([
535
+ ...q(s.scope),
536
+ ...x(s.target)
537
+ ]);
538
+ if (e.has(n))
539
+ throw new Error(
540
+ `${c} duplicates a scoped presentation target`
541
+ );
542
+ return e.add(n), s;
543
+ });
544
+ }
545
+ function X(r) {
546
+ if (!f(r))
547
+ throw new Error("presentation execution snapshot must be an object");
548
+ g(
549
+ r,
550
+ ["reportContext", "resolvedFormats"],
551
+ "presentation execution snapshot"
552
+ );
553
+ const e = C(r.reportContext);
554
+ if (!e.ok) {
555
+ const i = e.issues[0];
556
+ throw new Error(
557
+ `presentation execution snapshot reportContext is invalid: ${i != null && i.path && i.path !== "$" ? `${i.path}: ` : ""}${(i == null ? void 0 : i.message) ?? "invalid value"}`
558
+ );
559
+ }
560
+ return {
561
+ reportContext: e.value,
562
+ resolvedFormats: A(r.resolvedFormats)
563
+ };
564
+ }
565
+ function Z(r) {
566
+ const e = r.snapshot.resolvedFormats.find(
567
+ (i) => i.format.type !== "temporal_bucket" && N(i.scope, r.scope) && b(i.target, r.target)
568
+ );
569
+ return e == null ? void 0 : e.format;
570
+ }
571
+ function p(r) {
572
+ const e = r.snapshot.resolvedFormats.find(
573
+ (i) => i.format.type === "temporal_bucket" && N(i.scope, r.scope) && b(i.target, r.target)
574
+ );
575
+ return e == null ? void 0 : e.format;
576
+ }
577
+ function ee(r) {
578
+ var c;
579
+ const e = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
580
+ if (r.snapshot.resolvedFormats.forEach((t, s) => {
581
+ if (t.scope.attachmentIndex !== void 0)
582
+ throw new Error(
583
+ `resolvedFormats.${s}.scope.attachmentIndex is not valid for a card export`
584
+ );
585
+ if (t.scope.dashboardId !== r.expectedScope.dashboardId || t.scope.cardId !== r.expectedScope.cardId)
586
+ throw new Error(
587
+ `resolvedFormats.${s}.scope must match the executing dashboard/card`
588
+ );
589
+ if (t.target.kind === "field" && t.format.type === "temporal_bucket") {
590
+ const n = JSON.stringify(x(t.target));
591
+ if (i.has(n))
592
+ throw new Error(
593
+ `resolvedFormats.${s} duplicates export field "${t.target.fieldId}"`
594
+ );
595
+ i.add(n);
596
+ return;
597
+ }
598
+ if (t.target.kind !== "column")
599
+ throw new Error(
600
+ `resolvedFormats.${s}.target must identify an export column or temporal pivot field`
601
+ );
602
+ if (e.has(t.target.columnKey))
603
+ throw new Error(
604
+ `resolvedFormats.${s} duplicates export column "${t.target.columnKey}"`
605
+ );
606
+ e.add(t.target.columnKey);
607
+ }), !r.useFormattedValues) return;
608
+ if (!((c = r.visibleColumns) != null && c.length))
609
+ throw new Error("visibleColumns must identify every formatted export column");
610
+ const a = r.visibleColumns.find(
611
+ (t) => !e.has(t)
612
+ );
613
+ if (a)
614
+ throw new Error(
615
+ `resolvedFormats is missing visible export column "${a}"`
616
+ );
617
+ }
618
+ export {
619
+ Z as a,
620
+ G as b,
621
+ p as c,
622
+ k as d,
623
+ v as e,
624
+ J as f,
625
+ Y as g,
626
+ S as h,
627
+ E as i,
628
+ X as j,
629
+ T as k,
630
+ R as l,
631
+ A as m,
632
+ Q as n,
633
+ ee as o,
634
+ K as p,
635
+ O as r,
636
+ H as v
637
+ };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),n=require("./dashboard-DGX9b3T-.cjs"),o=require("./code-editor-BYVorgOf.cjs"),V=require("./report-runtime-context-C8LZFsqV.cjs");require("./index-jSrCwPQz.cjs");require("./validators-9D4KBqKD.cjs");require("./analyze-result-contract-BHb7sUUW.cjs");const D=require("../value-format-preferences/index.cjs");function M(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(C=>C.actions.applyResolvedCalendarPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,[v,b]=l.useState(!1),[g,j]=l.useState(!1),[y,k]=l.useState(!1),[T,f]=l.useState(null),[N,P]=l.useState(null),h=l.useRef(c);h.current=c,l.useEffect(()=>{P(null),f(null),b(!1),j(!1),k(!1)},[c]);const w=l.useCallback(async C=>{const r=V.parseCalendarPreferencesResponse(await C.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),S=l.useCallback(async()=>{if(!d||!c||!m)return;const C=c;b(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const t=await w(r);h.current===C&&P(t)}catch(r){h.current===C&&f(r instanceof Error?r.message:"Unknown error")}finally{h.current===C&&b(!1)}},[c,m,d,w]);l.useEffect(()=>{d&&S()},[d,S]);const E=l.useCallback(async C=>{if(!c||!m)return f("Not authenticated"),!1;const r=c;j(!0),f(null);try{const t=await fetch(`${m}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(C)});if(!t.ok){const z=await t.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}const x=await w(t);return h.current!==r?!1:(P(x),p(x.resolved,x.sources),!0)}catch(t){return h.current===r&&f(t instanceof Error?t.message:"Unknown error"),!1}finally{h.current===r&&j(!1)}},[c,m,p,w]),A=l.useCallback(async()=>{if(!c||!m)return f("Not authenticated"),!1;const C=c;k(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const t=await w(r);return h.current!==C?!1:(P(t),p(t.resolved,t.sources),!0)}catch(r){return h.current===C&&f(r instanceof Error?r.message:"Unknown error"),!1}finally{h.current===C&&k(!1)}},[c,m,p,w]);return{preferences:N,isLoading:v,isSaving:g,isClearing:y,error:T,updatePreferences:E,clearPreferences:A,refetch:S}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],I=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return F.map(s=>s.value)}function G(s){if(!s)return"default";if(s.tz!==s.weekStart)return"inherited";switch(s.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(s){const i=F.find(a=>a.value===s);return i?i.label:s}function W(s){const i=I.find(a=>a.value===s);return i?i.label:String(s)}function H({active:s,onClose:i}){const{preferences:a,isLoading:p,isSaving:d,isClearing:c,updatePreferences:m,clearPreferences:v}=M({enabled:s}),b=n.useCalendarContext(),g=(a==null?void 0:a.resolved.tz)||(b==null?void 0:b.tz)||"UTC",j=(a==null?void 0:a.resolved.weekStart)??(b==null?void 0:b.weekStart)??1,[y,k]=l.useState((a==null?void 0:a.stored)===null),[T,f]=l.useState(!1),[N,P]=l.useState(g),[h,w]=l.useState(j),[S,E]=l.useState(!1),A=l.useMemo(()=>_(),[]),C=l.useMemo(()=>A.filter(u=>!F.some($=>$.value===u)),[A]),r=l.useMemo(()=>U(N),[N]),t=a!=null&&a.inherited?U(a.inherited.tz):"UTC",x=a!=null&&a.inherited?W(a.inherited.weekStart):"Monday",z=G(a==null?void 0:a.inheritedSources);l.useEffect(()=>{if(!s){f(!1);return}T||(a&&k(a.stored===null),P(g),w(j))},[s,T,a,g,j]);const q=async()=>{if(p){n.ue.error("Preferences are still loading. Please try again.");return}y?await v()?(n.ue.success("Now using default settings."),i()):n.ue.error("Failed to save preferences. Please try again."):await m({tz:N,weekStart:h})?(n.ue.success("Preferences saved."),i()):n.ue.error("Failed to save preferences. Please try again.")},B=()=>{i()},L=d||c,O=L||p;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(n.RadioGroup,{value:y?"defaults":"custom",onValueChange:u=>{f(!0),k(u==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",y&&"bg-muted/50"),onClick:()=>{f(!0),k(!0)},children:[e.jsx(n.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",z," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[t,", week starts ",x]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!y&&"bg-muted/50"),onClick:()=>{f(!0),k(!1)},children:[e.jsx(n.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:o.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",y&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Timezone"}),e.jsxs(o.Popover,{open:S,onOpenChange:E,modal:!0,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":S,className:"w-full justify-between text-[12px] font-normal",disabled:y,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(n.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(o.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(n.Command,{className:"overflow-visible",children:[e.jsx(n.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(n.CommandList,{children:[e.jsx(n.CommandEmpty,{children:"No timezone found."}),e.jsx(n.CommandGroup,{heading:"Common",children:F.map(u=>e.jsxs(n.CommandItem,{value:`${u.value} ${u.label}`,onSelect:()=>{f(!0),P(u.value),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:u.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:u.value})]},u.value))}),e.jsx(n.CommandSeparator,{}),e.jsx(n.CommandGroup,{heading:"All timezones",children:C.map(u=>e.jsxs(n.CommandItem,{value:u,onSelect:()=>{f(!0),P(u),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u?"opacity-100":"opacity-0")}),u]},u))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Week starts on"}),e.jsx(n.RadioGroup,{value:String(h),onValueChange:u=>{f(!0),w(Number(u))},className:"flex gap-4",disabled:y,children:I.map(u=>e.jsxs("label",{htmlFor:`week-start-${u.value}`,className:o.cn("flex cursor-pointer items-center gap-2 text-[13px]",y&&"cursor-not-allowed"),children:[e.jsx(n.RadioGroupItem,{value:String(u.value),id:`week-start-${u.value}`,disabled:y}),u.label]},u.value))})]})]})]}),e.jsxs(n.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:B,disabled:L,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:q,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function K(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,v=l.useRef(c);v.current=c;const[b,g]=l.useState(null),[j,y]=l.useState(!1),[k,T]=l.useState(!1),[f,N]=l.useState(!1),[P,h]=l.useState(null);l.useEffect(()=>{g(null),h(null),y(!1),T(!1),N(!1)},[c]);const w=l.useCallback(async r=>{const t=D.parseValueFormatPreferencesResponse(await r.json());if(!t.ok)throw new Error("Value format preferences response is invalid");return t.value},[]),S=l.useCallback(async(r,t)=>{if(!c||!m)throw new Error("Not authenticated");const x=await fetch(`${m}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${c}`,...t?{"Content-Type":"application/json"}:{}},body:t?JSON.stringify(t):void 0});if(!x.ok){const z=await x.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}return w(x)},[c,m,w]),E=l.useCallback(async()=>{if(!d||!c||!m)return;const r=c;y(!0),h(null);try{const t=await S("GET");v.current===r&&g(t)}catch(t){v.current===r&&h(t instanceof Error?t.message:"Unknown error")}finally{v.current===r&&y(!1)}},[c,m,d,S]);l.useEffect(()=>{d&&E()},[d,E]);const A=l.useCallback(async r=>{const t=c;T(!0),h(null);try{const x=await S("PATCH",r);return v.current!==t?!1:(g(x),p(x.resolved,x.sources),!0)}catch(x){return v.current===t&&h(x instanceof Error?x.message:"Unknown error"),!1}finally{v.current===t&&T(!1)}},[c,p,S]),C=l.useCallback(async()=>{const r=c;N(!0),h(null);try{const t=await S("DELETE");return v.current!==r?!1:(g(t),p(t.resolved,t.sources),!0)}catch(t){return v.current===r&&h(t instanceof Error?t.message:"Unknown error"),!1}finally{v.current===r&&N(!1)}},[c,p,S]);return{preferences:b,isLoading:j,isSaving:k,isClearing:f,error:P,updatePreferences:A,clearPreferences:C,refetch:E}}function J({active:s,onClose:i}){var v,b;const{preferences:a,isLoading:p,isSaving:d,updatePreferences:c}=K({enabled:s});if(!s)return null;if(!a)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:p?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const m=[((v=a.stored)==null?void 0:v.locale)??"",((b=a.stored)==null?void 0:b.defaultCurrency)??""].join(":");return e.jsx(Z,{preferences:a,isSaving:d,updatePreferences:c,onClose:i},m)}function Z({preferences:s,isSaving:i,updatePreferences:a,onClose:p}){const[d,c]=l.useState(()=>{var g,j;return{locale:(g=s.stored)==null?void 0:g.locale,defaultCurrency:(j=s.stored)==null?void 0:j.defaultCurrency}}),m=(d.locale===void 0||D.canonicalizeSupportedLocale(d.locale)!==void 0)&&(d.defaultCurrency===void 0||D.canonicalizeSupportedCurrencyCode(d.defaultCurrency)!==void 0),v=async()=>{var T,f;const g={},j=[];d.locale!==void 0?g.locale=d.locale:((T=s.stored)==null?void 0:T.locale)!==void 0&&j.push("locale"),d.defaultCurrency!==void 0?g.defaultCurrency=d.defaultCurrency:((f=s.stored)==null?void 0:f.defaultCurrency)!==void 0&&j.push("defaultCurrency");const y={...Object.keys(g).length>0?{set:g}:{},...j.length>0?{clear:j}:{}};(Object.keys(y).length===0?!0:await a(y))?(n.ue.success("Display format preferences saved."),p()):n.ue.error("Failed to save preferences. Please try again.")},b=async()=>{await a({clear:["locale","defaultCurrency"]})?(n.ue.success("Locale and currency preferences reset."),p()):n.ue.error("Failed to reset locale and currency preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(n.DisplayFormatPreferencesFields,{value:d,inherited:s.inherited,inheritedSources:s.inheritedSources,onChange:c,disabled:i})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:b,disabled:i||s.stored===null,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:p,disabled:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:v,disabled:i||!m,children:i?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function Y({open:s,onOpenChange:i}){const[a,p]=l.useState("display"),d=()=>i(!1);return e.jsx(n.Dialog,{open:s,onOpenChange:i,children:e.jsxs(n.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(n.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(o.Tabs,{value:a,onValueChange:p,children:[e.jsxs(o.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(o.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(o.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(o.TabsContent,{value:"display",children:e.jsx(J,{active:s&&a==="display",onClose:d})}),e.jsx(o.TabsContent,{value:"calendar",children:e.jsx(H,{active:s&&a==="calendar",onClose:d})})]})]})})}exports.ReportPreferencesDialog=Y;