react-semaphor 0.1.428 → 0.1.429

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 (96) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +72 -71
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +5 -4
  5. package/dist/briefings/index.cjs +1 -1
  6. package/dist/briefings/index.js +1031 -622
  7. package/dist/chunks/analyze-result-contract-BswhsmWT.js +1 -0
  8. package/dist/chunks/{analyze-result-contract-DnfF8kBb.js → analyze-result-contract-CfOBEwaC.js} +681 -759
  9. package/dist/chunks/{code-editor-CojfM3qp.js → code-editor-C65eEYyU.js} +2980 -2960
  10. package/dist/chunks/code-editor-DOh3aYEh.js +138 -0
  11. package/dist/chunks/{comparison-document-migration-b6c3xiWh.js → comparison-document-migration-DbU_BTxR.js} +1 -1
  12. package/dist/chunks/{comparison-document-migration-BJH1idOd.js → comparison-document-migration-Dj6xZMCb.js} +2 -2
  13. package/dist/chunks/csv-utils-Co0WxHke.js +4 -0
  14. package/dist/chunks/csv-utils-suxSkJGj.js +376 -0
  15. package/dist/chunks/dashboard-CQfAvRYI.js +1401 -0
  16. package/dist/chunks/{dashboard-509sbC4_.js → dashboard-agBXhvKo.js} +47563 -44929
  17. package/dist/chunks/{dashboard-briefing-launcher-B-ZTWJwo.js → dashboard-briefing-launcher-CkH_pthg.js} +1 -1
  18. package/dist/chunks/{dashboard-briefing-launcher-DIdYHNTq.js → dashboard-briefing-launcher-gBNNKqoH.js} +100 -99
  19. package/dist/chunks/{dashboard-controls-CWprw-Pb.js → dashboard-controls-CAZnIGfT.js} +2 -2
  20. package/dist/chunks/{dashboard-controls-CbRzWo1N.js → dashboard-controls-CoIxUTvH.js} +114 -113
  21. package/dist/chunks/{dashboard-json-jO4GQfZk.js → dashboard-json-BMcPjL8-.js} +18 -17
  22. package/dist/chunks/dashboard-json-D4hFrMkX.js +1 -0
  23. package/dist/chunks/{edit-dashboard-visual-KgQTjqWp.js → edit-dashboard-visual-Bc8qNfSr.js} +8721 -8481
  24. package/dist/chunks/edit-dashboard-visual-onhUUXlw.js +182 -0
  25. package/dist/chunks/{metric-comparison-CWweq9RG.js → metric-comparison-CPoDx56y.js} +1 -1
  26. package/dist/chunks/{metric-comparison-BKgkMy9r.js → metric-comparison-DVy3fll_.js} +1 -1
  27. package/dist/chunks/numeric-presentation-CGTcqocU.js +517 -0
  28. package/dist/chunks/numeric-presentation-Dlb-Dk4c.js +1 -0
  29. package/dist/chunks/report-preferences-dialog-CPptr_V9.js +690 -0
  30. package/dist/chunks/report-preferences-dialog-DV_5aHrS.js +1 -0
  31. package/dist/chunks/source-identity-5OPV4gvg.js +92 -0
  32. package/dist/chunks/source-identity-Cbo2LOHQ.js +1 -0
  33. package/dist/chunks/{update-policy-CY2k-pJP.js → update-policy-De2NswtM.js} +1 -1
  34. package/dist/chunks/{update-policy-BgONreNd.js → update-policy-DnF_74zC.js} +1 -1
  35. package/dist/chunks/{use-create-flow-overlay-state-BiMYdjZP.js → use-create-flow-overlay-state-Bs6gqgjo.js} +1 -1
  36. package/dist/chunks/{use-create-flow-overlay-state-CGsLzp9A.js → use-create-flow-overlay-state-CgQbCrni.js} +97 -96
  37. package/dist/chunks/validators-B2vUAqTf.js +1 -0
  38. package/dist/chunks/{validators-Cz-XuORM.js → validators-Bce_J7Vd.js} +19 -13
  39. package/dist/dashboard/index.cjs +1 -1
  40. package/dist/dashboard/index.js +1 -1
  41. package/dist/dashboard-authoring/index.cjs +3 -3
  42. package/dist/dashboard-authoring/index.js +20 -19
  43. package/dist/data-app-builder/index.cjs +1 -1
  44. package/dist/data-app-builder/index.js +50 -50
  45. package/dist/data-app-codegen/index.cjs +1 -1
  46. package/dist/data-app-codegen/index.js +2 -2
  47. package/dist/data-app-codegen-node/index.cjs +1 -1
  48. package/dist/data-app-codegen-node/index.js +3 -3
  49. package/dist/data-app-sdk/index.cjs +2 -2
  50. package/dist/data-app-sdk/index.js +27 -26
  51. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  52. package/dist/data-app-sdk-adapters/index.js +25 -24
  53. package/dist/data-app-sdk-validation/index.cjs +1 -1
  54. package/dist/data-app-sdk-validation/index.js +57 -55
  55. package/dist/format-utils/index.cjs +2 -5
  56. package/dist/format-utils/index.js +136 -161
  57. package/dist/index.cjs +1 -1
  58. package/dist/index.js +158 -155
  59. package/dist/report-runtime-context/index.cjs +1 -0
  60. package/dist/report-runtime-context/index.js +394 -0
  61. package/dist/style.css +1 -1
  62. package/dist/surfboard/index.cjs +1 -1
  63. package/dist/surfboard/index.js +7 -6
  64. package/dist/types/analytics-protocol.d.ts +0 -4
  65. package/dist/types/briefings.d.ts +216 -19
  66. package/dist/types/dashboard-assistant.d.ts +0 -2
  67. package/dist/types/dashboard-authoring.d.ts +34 -9
  68. package/dist/types/dashboard.d.ts +93 -9
  69. package/dist/types/data-app-builder.d.ts +0 -1
  70. package/dist/types/data-app-codegen-node.d.ts +6 -28
  71. package/dist/types/data-app-codegen.d.ts +6 -28
  72. package/dist/types/data-app-sdk-adapters.d.ts +6 -28
  73. package/dist/types/data-app-sdk-validation.d.ts +6 -29
  74. package/dist/types/data-app-sdk.d.ts +6 -31
  75. package/dist/types/format-utils.d.ts +128 -4
  76. package/dist/types/index.cjs +1 -1
  77. package/dist/types/index.js +10 -13
  78. package/dist/types/main.d.ts +249 -89
  79. package/dist/types/report-runtime-context.d.ts +99 -0
  80. package/dist/types/shared.d.ts +34 -9
  81. package/dist/types/surfboard.d.ts +119 -16
  82. package/dist/types/types.d.ts +156 -73
  83. package/dist/types/value-format-preferences.d.ts +126 -0
  84. package/dist/value-format-preferences/index.cjs +1 -0
  85. package/dist/value-format-preferences/index.js +635 -0
  86. package/package.json +11 -1
  87. package/dist/chunks/analyze-result-contract-ege_u6Nl.js +0 -1
  88. package/dist/chunks/calendar-preferences-dialog-BF9bNAF_.js +0 -457
  89. package/dist/chunks/calendar-preferences-dialog-_L9eBQfj.js +0 -1
  90. package/dist/chunks/code-editor-BoowcKU0.js +0 -138
  91. package/dist/chunks/dashboard-CMDXBLnG.js +0 -1402
  92. package/dist/chunks/dashboard-json-BEZrxx_k.js +0 -1
  93. package/dist/chunks/date-formatter-BTTYdAik.js +0 -1
  94. package/dist/chunks/date-formatter-D-89jTjG.js +0 -514
  95. package/dist/chunks/edit-dashboard-visual-D3uhqgm3.js +0 -182
  96. package/dist/chunks/validators-B4VMLX3_.js +0 -1
@@ -0,0 +1,690 @@
1
+ import { jsxs as l, Fragment as R, jsx as a } from "react/jsx-runtime";
2
+ import le, { useState as C, useRef as Y, useEffect as U, useCallback as A, useMemo as _ } from "react";
3
+ import { az as Q, aA as ce, aB as B, aC as $, aD as oe, h as ie, i as ue, j as de, k as fe, l as M, m as W, aE as me, aF as V, aG as z, a as he, aH as pe, aI as ve, aJ as ye, aK as ge, aL as be } from "./dashboard-agBXhvKo.js";
4
+ import { u as X, c as F, O as q, P as we, a as Ce, B as L, b as Se, d as G, L as ee, T as ke, F as Te, G as H, I as K } from "./code-editor-C65eEYyU.js";
5
+ import { parseCalendarPreferencesResponse as xe } from "../report-runtime-context/index.js";
6
+ import "./index-xHCrHprY.js";
7
+ import "./analyze-result-contract-CfOBEwaC.js";
8
+ import { parseValueFormatPreferencesResponse as Ne, canonicalizeSupportedLocale as Pe, canonicalizeSupportedCurrencyCode as Ee } from "../value-format-preferences/index.js";
9
+ function Ae(r = {}) {
10
+ const { authToken: c, tokenProps: e } = Q(), m = X(
11
+ (w) => w.actions.applyResolvedCalendarPreferences
12
+ ), i = r.enabled ?? !0, t = (c == null ? void 0 : c.accessToken) ?? null, d = (e == null ? void 0 : e.apiServiceUrl) ?? null, [p, g] = C(!1), [v, b] = C(!1), [y, T] = C(!1), [x, u] = C(null), [N, P] = C(null), f = Y(t);
13
+ f.current = t, U(() => {
14
+ P(null), u(null), g(!1), b(!1), T(!1);
15
+ }, [t]);
16
+ const k = A(async (w) => {
17
+ const s = xe(await w.json());
18
+ if (!s.ok)
19
+ throw new Error("Calendar preferences response is invalid");
20
+ return s.value;
21
+ }, []), S = A(async () => {
22
+ if (!i || !t || !d) return;
23
+ const w = t;
24
+ g(!0), u(null);
25
+ try {
26
+ const s = await fetch(
27
+ `${d}/v1/user-preferences/calendar`,
28
+ {
29
+ method: "GET",
30
+ headers: { Authorization: `Bearer ${t}` }
31
+ }
32
+ );
33
+ if (!s.ok) {
34
+ const h = await s.json().catch(() => ({}));
35
+ throw new Error(h.error || "Failed to fetch preferences");
36
+ }
37
+ const n = await k(s);
38
+ f.current === w && P(n);
39
+ } catch (s) {
40
+ f.current === w && u(s instanceof Error ? s.message : "Unknown error");
41
+ } finally {
42
+ f.current === w && g(!1);
43
+ }
44
+ }, [t, d, i, k]);
45
+ U(() => {
46
+ i && S();
47
+ }, [i, S]);
48
+ const E = A(
49
+ async (w) => {
50
+ if (!t || !d)
51
+ return u("Not authenticated"), !1;
52
+ const s = t;
53
+ b(!0), u(null);
54
+ try {
55
+ const n = await fetch(
56
+ `${d}/v1/user-preferences/calendar`,
57
+ {
58
+ method: "PATCH",
59
+ headers: {
60
+ "Content-Type": "application/json",
61
+ Authorization: `Bearer ${t}`
62
+ },
63
+ body: JSON.stringify(w)
64
+ }
65
+ );
66
+ if (!n.ok) {
67
+ const j = await n.json().catch(() => ({}));
68
+ throw new Error(j.error || "Failed to update preferences");
69
+ }
70
+ const h = await k(n);
71
+ return f.current !== s ? !1 : (P(h), m(h.resolved, h.sources), !0);
72
+ } catch (n) {
73
+ return f.current === s && u(n instanceof Error ? n.message : "Unknown error"), !1;
74
+ } finally {
75
+ f.current === s && b(!1);
76
+ }
77
+ },
78
+ [
79
+ t,
80
+ d,
81
+ m,
82
+ k
83
+ ]
84
+ ), D = A(async () => {
85
+ if (!t || !d)
86
+ return u("Not authenticated"), !1;
87
+ const w = t;
88
+ T(!0), u(null);
89
+ try {
90
+ const s = await fetch(
91
+ `${d}/v1/user-preferences/calendar`,
92
+ {
93
+ method: "DELETE",
94
+ headers: { Authorization: `Bearer ${t}` }
95
+ }
96
+ );
97
+ if (!s.ok) {
98
+ const h = await s.json().catch(() => ({}));
99
+ throw new Error(h.error || "Failed to clear preferences");
100
+ }
101
+ const n = await k(s);
102
+ return f.current !== w ? !1 : (P(n), m(n.resolved, n.sources), !0);
103
+ } catch (s) {
104
+ return f.current === w && u(s instanceof Error ? s.message : "Unknown error"), !1;
105
+ } finally {
106
+ f.current === w && T(!1);
107
+ }
108
+ }, [
109
+ t,
110
+ d,
111
+ m,
112
+ k
113
+ ]);
114
+ return {
115
+ preferences: N,
116
+ isLoading: p,
117
+ isSaving: v,
118
+ isClearing: y,
119
+ error: x,
120
+ updatePreferences: E,
121
+ clearPreferences: D,
122
+ refetch: S
123
+ };
124
+ }
125
+ const I = [
126
+ { value: "America/New_York", label: "Eastern Time (US & Canada)" },
127
+ { value: "America/Chicago", label: "Central Time (US & Canada)" },
128
+ { value: "America/Denver", label: "Mountain Time (US & Canada)" },
129
+ { value: "America/Los_Angeles", label: "Pacific Time (US & Canada)" },
130
+ { value: "America/Phoenix", label: "Arizona" },
131
+ { value: "America/Anchorage", label: "Alaska" },
132
+ { value: "Pacific/Honolulu", label: "Hawaii" },
133
+ { value: "Europe/London", label: "London" },
134
+ { value: "Europe/Paris", label: "Paris, Berlin, Rome" },
135
+ { value: "Asia/Tokyo", label: "Tokyo" },
136
+ { value: "Asia/Shanghai", label: "Beijing, Shanghai" },
137
+ { value: "Asia/Kolkata", label: "Mumbai, New Delhi" },
138
+ { value: "Australia/Sydney", label: "Sydney" },
139
+ { value: "UTC", label: "UTC" }
140
+ ], ae = [
141
+ { value: 0, label: "Sunday" },
142
+ { value: 1, label: "Monday" },
143
+ { value: 6, label: "Saturday" }
144
+ ], J = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
145
+ function ze() {
146
+ try {
147
+ const r = Intl;
148
+ if (r.supportedValuesOf)
149
+ return r.supportedValuesOf("timeZone");
150
+ } catch {
151
+ }
152
+ return I.map((r) => r.value);
153
+ }
154
+ function Le(r) {
155
+ if (!r) return "default";
156
+ if (r.tz !== r.weekStart) return "inherited";
157
+ switch (r.tz) {
158
+ case "viewer_tenant":
159
+ return "tenant";
160
+ case "viewer_organization":
161
+ return "organization";
162
+ case "system_default":
163
+ return "system";
164
+ case "session_initial":
165
+ return "embedded";
166
+ default:
167
+ return "default";
168
+ }
169
+ }
170
+ function Z(r) {
171
+ const c = I.find((e) => e.value === r);
172
+ return c ? c.label : r;
173
+ }
174
+ function De(r) {
175
+ const c = ae.find((e) => e.value === r);
176
+ return c ? c.label : String(r);
177
+ }
178
+ function Fe({
179
+ active: r,
180
+ onClose: c
181
+ }) {
182
+ const {
183
+ preferences: e,
184
+ isLoading: m,
185
+ isSaving: i,
186
+ isClearing: t,
187
+ updatePreferences: d,
188
+ clearPreferences: p
189
+ } = Ae({ enabled: r }), g = ce(), v = (e == null ? void 0 : e.resolved.tz) || (g == null ? void 0 : g.tz) || "UTC", b = (e == null ? void 0 : e.resolved.weekStart) ?? (g == null ? void 0 : g.weekStart) ?? 1, [y, T] = C((e == null ? void 0 : e.stored) === null), [x, u] = C(!1), [N, P] = C(
190
+ v
191
+ ), [f, k] = C(
192
+ b
193
+ ), [S, E] = C(!1), D = _(() => ze(), []), w = _(
194
+ () => D.filter(
195
+ (o) => !I.some((te) => te.value === o)
196
+ ),
197
+ [D]
198
+ ), s = _(() => Z(N), [N]), n = e != null && e.inherited ? Z(e.inherited.tz) : "UTC", h = e != null && e.inherited ? De(e.inherited.weekStart) : "Monday", j = Le(
199
+ e == null ? void 0 : e.inheritedSources
200
+ );
201
+ le.useEffect(() => {
202
+ if (!r) {
203
+ u(!1);
204
+ return;
205
+ }
206
+ x || (e && T(e.stored === null), P(v), k(b));
207
+ }, [
208
+ r,
209
+ x,
210
+ e,
211
+ v,
212
+ b
213
+ ]);
214
+ const re = async () => {
215
+ if (m) {
216
+ z.error("Preferences are still loading. Please try again.");
217
+ return;
218
+ }
219
+ y ? await p() ? (z.success("Now using default settings."), c()) : z.error("Failed to save preferences. Please try again.") : await d({
220
+ tz: N,
221
+ weekStart: f
222
+ }) ? (z.success("Preferences saved."), c()) : z.error("Failed to save preferences. Please try again.");
223
+ }, se = () => {
224
+ c();
225
+ }, O = i || t, ne = O || m;
226
+ return /* @__PURE__ */ l(R, { children: [
227
+ /* @__PURE__ */ l("div", { className: "space-y-4 py-1", children: [
228
+ /* @__PURE__ */ l(
229
+ B,
230
+ {
231
+ value: y ? "defaults" : "custom",
232
+ onValueChange: (o) => {
233
+ u(!0), T(o === "defaults");
234
+ },
235
+ className: "space-y-0.5",
236
+ children: [
237
+ /* @__PURE__ */ l(
238
+ "label",
239
+ {
240
+ htmlFor: "mode-defaults",
241
+ className: F(
242
+ "flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",
243
+ y && "bg-muted/50"
244
+ ),
245
+ onClick: () => {
246
+ u(!0), T(!0);
247
+ },
248
+ children: [
249
+ /* @__PURE__ */ a(
250
+ $,
251
+ {
252
+ value: "defaults",
253
+ id: "mode-defaults",
254
+ className: "mt-0.5"
255
+ }
256
+ ),
257
+ /* @__PURE__ */ l("div", { className: "flex-1 min-w-0", children: [
258
+ /* @__PURE__ */ l("p", { className: "text-[13px] font-medium text-foreground", children: [
259
+ "Use ",
260
+ j,
261
+ " defaults"
262
+ ] }),
263
+ /* @__PURE__ */ l("p", { className: "text-[12px] text-muted-foreground", children: [
264
+ n,
265
+ ", week starts ",
266
+ h
267
+ ] })
268
+ ] })
269
+ ]
270
+ }
271
+ ),
272
+ /* @__PURE__ */ l(
273
+ "label",
274
+ {
275
+ htmlFor: "mode-custom",
276
+ className: F(
277
+ "flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",
278
+ !y && "bg-muted/50"
279
+ ),
280
+ onClick: () => {
281
+ u(!0), T(!1);
282
+ },
283
+ children: [
284
+ /* @__PURE__ */ a(
285
+ $,
286
+ {
287
+ value: "custom",
288
+ id: "mode-custom",
289
+ className: "mt-0.5"
290
+ }
291
+ ),
292
+ /* @__PURE__ */ a("p", { className: "flex-1 text-[13px] font-medium text-foreground", children: "Use custom settings" })
293
+ ]
294
+ }
295
+ )
296
+ ]
297
+ }
298
+ ),
299
+ /* @__PURE__ */ l(
300
+ "div",
301
+ {
302
+ className: F(
303
+ "space-y-4 border-t border-border/60 pt-4 transition-opacity",
304
+ y && "pointer-events-none opacity-50"
305
+ ),
306
+ children: [
307
+ /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
308
+ /* @__PURE__ */ a(q, { className: J, children: "Timezone" }),
309
+ /* @__PURE__ */ l(
310
+ we,
311
+ {
312
+ open: S,
313
+ onOpenChange: E,
314
+ modal: !0,
315
+ children: [
316
+ /* @__PURE__ */ a(Ce, { asChild: !0, children: /* @__PURE__ */ l(
317
+ L,
318
+ {
319
+ variant: "outline",
320
+ size: "xs",
321
+ role: "combobox",
322
+ "aria-expanded": S,
323
+ className: "w-full justify-between text-[12px] font-normal",
324
+ disabled: y,
325
+ children: [
326
+ /* @__PURE__ */ a("span", { className: "truncate", children: s }),
327
+ /* @__PURE__ */ a(oe, { className: "ml-2 h-3.5 w-3.5 shrink-0 opacity-50" })
328
+ ]
329
+ }
330
+ ) }),
331
+ /* @__PURE__ */ a(
332
+ Se,
333
+ {
334
+ className: "z-50 w-[--radix-popover-trigger-width] p-0",
335
+ align: "start",
336
+ children: /* @__PURE__ */ l(ie, { className: "overflow-visible", children: [
337
+ /* @__PURE__ */ a(ue, { placeholder: "Search timezones…" }),
338
+ /* @__PURE__ */ l(de, { children: [
339
+ /* @__PURE__ */ a(fe, { children: "No timezone found." }),
340
+ /* @__PURE__ */ a(M, { heading: "Common", children: I.map((o) => /* @__PURE__ */ l(
341
+ W,
342
+ {
343
+ value: `${o.value} ${o.label}`,
344
+ onSelect: () => {
345
+ u(!0), P(o.value), E(!1);
346
+ },
347
+ children: [
348
+ /* @__PURE__ */ a(
349
+ G,
350
+ {
351
+ className: F(
352
+ "h-3.5 w-3.5",
353
+ N === o.value ? "opacity-100" : "opacity-0"
354
+ )
355
+ }
356
+ ),
357
+ /* @__PURE__ */ a("span", { className: "flex-1", children: o.label }),
358
+ /* @__PURE__ */ a("span", { className: "text-[11px] text-muted-foreground", children: o.value })
359
+ ]
360
+ },
361
+ o.value
362
+ )) }),
363
+ /* @__PURE__ */ a(me, {}),
364
+ /* @__PURE__ */ a(M, { heading: "All timezones", children: w.map((o) => /* @__PURE__ */ l(
365
+ W,
366
+ {
367
+ value: o,
368
+ onSelect: () => {
369
+ u(!0), P(o), E(!1);
370
+ },
371
+ children: [
372
+ /* @__PURE__ */ a(
373
+ G,
374
+ {
375
+ className: F(
376
+ "h-3.5 w-3.5",
377
+ N === o ? "opacity-100" : "opacity-0"
378
+ )
379
+ }
380
+ ),
381
+ o
382
+ ]
383
+ },
384
+ o
385
+ )) })
386
+ ] })
387
+ ] })
388
+ }
389
+ )
390
+ ]
391
+ }
392
+ )
393
+ ] }),
394
+ /* @__PURE__ */ l("div", { className: "space-y-1.5", children: [
395
+ /* @__PURE__ */ a(q, { className: J, children: "Week starts on" }),
396
+ /* @__PURE__ */ a(
397
+ B,
398
+ {
399
+ value: String(f),
400
+ onValueChange: (o) => {
401
+ u(!0), k(Number(o));
402
+ },
403
+ className: "flex gap-4",
404
+ disabled: y,
405
+ children: ae.map((o) => /* @__PURE__ */ l(
406
+ "label",
407
+ {
408
+ htmlFor: `week-start-${o.value}`,
409
+ className: F(
410
+ "flex cursor-pointer items-center gap-2 text-[13px]",
411
+ y && "cursor-not-allowed"
412
+ ),
413
+ children: [
414
+ /* @__PURE__ */ a(
415
+ $,
416
+ {
417
+ value: String(o.value),
418
+ id: `week-start-${o.value}`,
419
+ disabled: y
420
+ }
421
+ ),
422
+ o.label
423
+ ]
424
+ },
425
+ o.value
426
+ ))
427
+ }
428
+ )
429
+ ] })
430
+ ]
431
+ }
432
+ )
433
+ ] }),
434
+ /* @__PURE__ */ l(V, { children: [
435
+ /* @__PURE__ */ a(
436
+ L,
437
+ {
438
+ variant: "outline",
439
+ size: "xs",
440
+ onClick: se,
441
+ disabled: O,
442
+ children: "Cancel"
443
+ }
444
+ ),
445
+ /* @__PURE__ */ a(L, { size: "xs", onClick: re, disabled: ne, children: O ? /* @__PURE__ */ l(R, { children: [
446
+ /* @__PURE__ */ a(ee, { className: "h-3.5 w-3.5 animate-spin" }),
447
+ "Saving…"
448
+ ] }) : "Save" })
449
+ ] })
450
+ ] });
451
+ }
452
+ function je(r = {}) {
453
+ const { authToken: c, tokenProps: e } = Q(), m = X(
454
+ (s) => s.actions.applyResolvedValueFormatPreferences
455
+ ), i = r.enabled ?? !0, t = (c == null ? void 0 : c.accessToken) ?? null, d = (e == null ? void 0 : e.apiServiceUrl) ?? null, p = Y(t);
456
+ p.current = t;
457
+ const [g, v] = C(null), [b, y] = C(!1), [T, x] = C(!1), [u, N] = C(!1), [P, f] = C(null);
458
+ U(() => {
459
+ v(null), f(null), y(!1), x(!1), N(!1);
460
+ }, [t]);
461
+ const k = A(async (s) => {
462
+ const n = Ne(await s.json());
463
+ if (!n.ok)
464
+ throw new Error("Value format preferences response is invalid");
465
+ return n.value;
466
+ }, []), S = A(
467
+ async (s, n) => {
468
+ if (!t || !d)
469
+ throw new Error("Not authenticated");
470
+ const h = await fetch(
471
+ `${d}/v1/user-preferences/value-format`,
472
+ {
473
+ method: s,
474
+ headers: {
475
+ Authorization: `Bearer ${t}`,
476
+ ...n ? { "Content-Type": "application/json" } : {}
477
+ },
478
+ body: n ? JSON.stringify(n) : void 0
479
+ }
480
+ );
481
+ if (!h.ok) {
482
+ const j = await h.json().catch(() => ({}));
483
+ throw new Error(j.error || "Failed to update preferences");
484
+ }
485
+ return k(h);
486
+ },
487
+ [t, d, k]
488
+ ), E = A(async () => {
489
+ if (!i || !t || !d) return;
490
+ const s = t;
491
+ y(!0), f(null);
492
+ try {
493
+ const n = await S("GET");
494
+ p.current === s && v(n);
495
+ } catch (n) {
496
+ p.current === s && f(n instanceof Error ? n.message : "Unknown error");
497
+ } finally {
498
+ p.current === s && y(!1);
499
+ }
500
+ }, [t, d, i, S]);
501
+ U(() => {
502
+ i && E();
503
+ }, [i, E]);
504
+ const D = A(
505
+ async (s) => {
506
+ const n = t;
507
+ x(!0), f(null);
508
+ try {
509
+ const h = await S("PATCH", s);
510
+ return p.current !== n ? !1 : (v(h), m(h.resolved, h.sources), !0);
511
+ } catch (h) {
512
+ return p.current === n && f(h instanceof Error ? h.message : "Unknown error"), !1;
513
+ } finally {
514
+ p.current === n && x(!1);
515
+ }
516
+ },
517
+ [t, m, S]
518
+ ), w = A(async () => {
519
+ const s = t;
520
+ N(!0), f(null);
521
+ try {
522
+ const n = await S("DELETE");
523
+ return p.current !== s ? !1 : (v(n), m(n.resolved, n.sources), !0);
524
+ } catch (n) {
525
+ return p.current === s && f(n instanceof Error ? n.message : "Unknown error"), !1;
526
+ } finally {
527
+ p.current === s && N(!1);
528
+ }
529
+ }, [t, m, S]);
530
+ return {
531
+ preferences: g,
532
+ isLoading: b,
533
+ isSaving: T,
534
+ isClearing: u,
535
+ error: P,
536
+ updatePreferences: D,
537
+ clearPreferences: w,
538
+ refetch: E
539
+ };
540
+ }
541
+ function Re({
542
+ active: r,
543
+ onClose: c
544
+ }) {
545
+ var p, g;
546
+ const {
547
+ preferences: e,
548
+ isLoading: m,
549
+ isSaving: i,
550
+ updatePreferences: t
551
+ } = je({ enabled: r });
552
+ if (!r) return null;
553
+ if (!e)
554
+ return /* @__PURE__ */ l(R, { children: [
555
+ /* @__PURE__ */ a("div", { className: "py-2", children: /* @__PURE__ */ a("div", { className: "flex min-h-36 items-center justify-center text-[12px] text-muted-foreground", children: m ? "Loading preferences…" : "Preferences unavailable." }) }),
556
+ /* @__PURE__ */ l(V, { className: "justify-between sm:justify-between", children: [
557
+ /* @__PURE__ */ a(L, { variant: "ghost", size: "xs", disabled: !0, children: "Reset locale and currency" }),
558
+ /* @__PURE__ */ l("div", { className: "flex gap-2", children: [
559
+ /* @__PURE__ */ a(L, { variant: "outline", size: "xs", onClick: c, children: "Cancel" }),
560
+ /* @__PURE__ */ a(L, { size: "xs", disabled: !0, children: "Save" })
561
+ ] })
562
+ ] })
563
+ ] });
564
+ const d = [
565
+ ((p = e.stored) == null ? void 0 : p.locale) ?? "",
566
+ ((g = e.stored) == null ? void 0 : g.defaultCurrency) ?? ""
567
+ ].join(":");
568
+ return /* @__PURE__ */ a(
569
+ Ue,
570
+ {
571
+ preferences: e,
572
+ isSaving: i,
573
+ updatePreferences: t,
574
+ onClose: c
575
+ },
576
+ d
577
+ );
578
+ }
579
+ function Ue({
580
+ preferences: r,
581
+ isSaving: c,
582
+ updatePreferences: e,
583
+ onClose: m
584
+ }) {
585
+ const [i, t] = C(() => {
586
+ var v, b;
587
+ return {
588
+ locale: (v = r.stored) == null ? void 0 : v.locale,
589
+ defaultCurrency: (b = r.stored) == null ? void 0 : b.defaultCurrency
590
+ };
591
+ }), d = (i.locale === void 0 || Pe(i.locale) !== void 0) && (i.defaultCurrency === void 0 || Ee(i.defaultCurrency) !== void 0), p = async () => {
592
+ var x, u;
593
+ const v = {}, b = [];
594
+ i.locale !== void 0 ? v.locale = i.locale : ((x = r.stored) == null ? void 0 : x.locale) !== void 0 && b.push("locale"), i.defaultCurrency !== void 0 ? v.defaultCurrency = i.defaultCurrency : ((u = r.stored) == null ? void 0 : u.defaultCurrency) !== void 0 && b.push("defaultCurrency");
595
+ const y = {
596
+ ...Object.keys(v).length > 0 ? { set: v } : {},
597
+ ...b.length > 0 ? { clear: b } : {}
598
+ };
599
+ (Object.keys(y).length === 0 ? !0 : await e(y)) ? (z.success("Display format preferences saved."), m()) : z.error("Failed to save preferences. Please try again.");
600
+ }, g = async () => {
601
+ await e({
602
+ clear: ["locale", "defaultCurrency"]
603
+ }) ? (z.success("Locale and currency preferences reset."), m()) : z.error(
604
+ "Failed to reset locale and currency preferences. Please try again."
605
+ );
606
+ };
607
+ return /* @__PURE__ */ l(R, { children: [
608
+ /* @__PURE__ */ a("div", { className: "py-2", children: /* @__PURE__ */ a(
609
+ he,
610
+ {
611
+ value: i,
612
+ inherited: r.inherited,
613
+ inheritedSources: r.inheritedSources,
614
+ onChange: t,
615
+ disabled: c
616
+ }
617
+ ) }),
618
+ /* @__PURE__ */ l(V, { className: "justify-between sm:justify-between", children: [
619
+ /* @__PURE__ */ a(
620
+ L,
621
+ {
622
+ variant: "ghost",
623
+ size: "xs",
624
+ onClick: g,
625
+ disabled: c || r.stored === null,
626
+ children: "Reset locale and currency"
627
+ }
628
+ ),
629
+ /* @__PURE__ */ l("div", { className: "flex gap-2", children: [
630
+ /* @__PURE__ */ a(
631
+ L,
632
+ {
633
+ variant: "outline",
634
+ size: "xs",
635
+ onClick: m,
636
+ disabled: c,
637
+ children: "Cancel"
638
+ }
639
+ ),
640
+ /* @__PURE__ */ a(
641
+ L,
642
+ {
643
+ size: "xs",
644
+ onClick: p,
645
+ disabled: c || !d,
646
+ children: c ? /* @__PURE__ */ l(R, { children: [
647
+ /* @__PURE__ */ a(ee, { className: "h-3.5 w-3.5 animate-spin" }),
648
+ "Saving…"
649
+ ] }) : "Save"
650
+ }
651
+ )
652
+ ] })
653
+ ] })
654
+ ] });
655
+ }
656
+ function qe({
657
+ open: r,
658
+ onOpenChange: c
659
+ }) {
660
+ const [e, m] = C("display"), i = () => c(!1);
661
+ return /* @__PURE__ */ a(pe, { open: r, onOpenChange: c, children: /* @__PURE__ */ l(ve, { className: "rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control", children: [
662
+ /* @__PURE__ */ l(ye, { children: [
663
+ /* @__PURE__ */ a(ge, { className: "text-[15px]", children: "Report preferences" }),
664
+ /* @__PURE__ */ a(be, { className: "text-[13px] leading-5", children: "Set how values and Calendar periods appear for you." })
665
+ ] }),
666
+ /* @__PURE__ */ l(ke, { value: e, onValueChange: m, children: [
667
+ /* @__PURE__ */ l(Te, { variant: "underline", className: "w-full justify-start", children: [
668
+ /* @__PURE__ */ a(H, { value: "display", children: "Display formats" }),
669
+ /* @__PURE__ */ a(H, { value: "calendar", children: "Calendar" })
670
+ ] }),
671
+ /* @__PURE__ */ a(K, { value: "display", children: /* @__PURE__ */ a(
672
+ Re,
673
+ {
674
+ active: r && e === "display",
675
+ onClose: i
676
+ }
677
+ ) }),
678
+ /* @__PURE__ */ a(K, { value: "calendar", children: /* @__PURE__ */ a(
679
+ Fe,
680
+ {
681
+ active: r && e === "calendar",
682
+ onClose: i
683
+ }
684
+ ) })
685
+ ] })
686
+ ] }) });
687
+ }
688
+ export {
689
+ qe as R
690
+ };