react-semaphor 0.1.470 → 0.1.472

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 (41) hide show
  1. package/README.md +10 -0
  2. package/dist/brand-studio/index.cjs +1 -1
  3. package/dist/brand-studio/index.js +1 -1
  4. package/dist/chunks/dashboard-briefing-launcher-8vxGyexK.cjs +26 -0
  5. package/dist/chunks/{dashboard-briefing-launcher-DEVbQCQE.js → dashboard-briefing-launcher-Lw4gjW_M.js} +5 -5
  6. package/dist/chunks/{dashboard-controls-8D1m_ECN.cjs → dashboard-controls-BKR8g3M9.cjs} +1 -1
  7. package/dist/chunks/{dashboard-controls-DPK-CRWL.js → dashboard-controls-CRgDlxdt.js} +4 -4
  8. package/dist/chunks/dashboard-filter-value-compatibility-Dmh-NaPK.cjs +1 -0
  9. package/dist/chunks/dashboard-filter-value-compatibility-ilbH2A31.js +836 -0
  10. package/dist/chunks/{dashboard-json-DVWLTmIJ.js → dashboard-json-BhhVg9mI.js} +2 -2
  11. package/dist/chunks/{dashboard-json-DhKOoHwK.cjs → dashboard-json-CUgAzrYq.cjs} +1 -1
  12. package/dist/chunks/{edit-dashboard-visual-B6zidwTu.cjs → edit-dashboard-visual-BxmanBVo.cjs} +33 -33
  13. package/dist/chunks/{edit-dashboard-visual-CxEC3bPx.js → edit-dashboard-visual-DlQtYQOO.js} +3609 -3711
  14. package/dist/chunks/{editor-action-buttons-HfJ-Bohl.js → editor-action-buttons-CRWacpxi.js} +2 -2
  15. package/dist/chunks/{editor-action-buttons-B3S00DsB.cjs → editor-action-buttons-DKcD0UQy.cjs} +1 -1
  16. package/dist/chunks/{index-tsB3LfTQ.js → index-0fmECZL2.js} +28713 -28753
  17. package/dist/chunks/{index-DVBYvkj0.cjs → index-xdqe-Zvd.cjs} +224 -224
  18. package/dist/chunks/{pivot-header-presentation-BW0Ay7WV.js → pivot-header-presentation-7XrwJYDm.js} +101 -94
  19. package/dist/chunks/pivot-header-presentation-Cr6pU5JL.cjs +4 -0
  20. package/dist/chunks/{report-preferences-dialog-DvNWNrlj.cjs → report-preferences-dialog-8KYKazoG.cjs} +1 -1
  21. package/dist/chunks/{report-preferences-dialog-D-VpoQJz.js → report-preferences-dialog-Dxt9XMpd.js} +2 -2
  22. package/dist/chunks/{switch-NAbuOQNg.cjs → switch-CQN9Hzho.cjs} +19 -19
  23. package/dist/chunks/{switch-DnbD-yCM.js → switch-n2yUNY8i.js} +383 -370
  24. package/dist/dashboard/index.cjs +1 -1
  25. package/dist/dashboard/index.js +1 -1
  26. package/dist/dashboard-authoring/index.cjs +1 -1
  27. package/dist/dashboard-authoring/index.js +1 -1
  28. package/dist/data-app-builder/index.cjs +1 -1
  29. package/dist/data-app-builder/index.js +2 -2
  30. package/dist/format-utils/index.cjs +3 -3
  31. package/dist/format-utils/index.js +71 -68
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.js +6 -6
  34. package/dist/surfboard/index.cjs +1 -1
  35. package/dist/surfboard/index.js +2 -2
  36. package/dist/types/format-utils.d.ts +9 -0
  37. package/package.json +1 -1
  38. package/dist/chunks/dashboard-briefing-launcher-exfJnSop.cjs +0 -26
  39. package/dist/chunks/dashboard-filter-value-compatibility-BAaqJGjt.js +0 -692
  40. package/dist/chunks/dashboard-filter-value-compatibility-CYrWe1U6.cjs +0 -1
  41. package/dist/chunks/pivot-header-presentation-DVBTHug2.cjs +0 -4
@@ -1,16 +1,16 @@
1
- var U = Object.defineProperty;
2
- var E = (e, t, n) => t in e ? U(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var A = (e, t, n) => E(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { t as f, c as P, g as R, e as O, a as T, m as S, b as M, i as Z, f as k, d as B } from "./format-types-CFHQoIuk.js";
1
+ var F = Object.defineProperty;
2
+ var R = (e, t, n) => t in e ? F(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var A = (e, t, n) => R(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { t as f, c as U, g as O, e as P, a as T, m as S, b as M, i as Z, f as k, d as X } from "./format-types-CFHQoIuk.js";
5
5
  import { b as y } from "./pivot-result-lifecycle-O_roVguV.js";
6
- import { f as j } from "./index-CACdoqu3.js";
7
- import { h as X } from "./temporal-bucket-CUKJktCl.js";
6
+ import { f as B } from "./index-CACdoqu3.js";
7
+ import { h as j } from "./temporal-bucket-CUKJktCl.js";
8
8
  function b(e, t) {
9
9
  const n = f(e), o = f(t), r = n.getTime() - o.getTime();
10
10
  return r < 0 ? -1 : r > 0 ? 1 : r;
11
11
  }
12
12
  function G(e) {
13
- return P(e, Date.now());
13
+ return U(e, Date.now());
14
14
  }
15
15
  function H(e, t) {
16
16
  const n = f(e), o = f(t), r = n.getFullYear() - o.getFullYear(), s = n.getMonth() - o.getMonth();
@@ -56,16 +56,16 @@ function z(e, t, n) {
56
56
  return Y(n == null ? void 0 : n.roundingMethod)(o);
57
57
  }
58
58
  function ee(e, t, n) {
59
- const o = R(), r = (n == null ? void 0 : n.locale) ?? o.locale ?? O, s = 2520, i = b(e, t);
59
+ const o = O(), r = (n == null ? void 0 : n.locale) ?? o.locale ?? P, s = 2520, i = b(e, t);
60
60
  if (isNaN(i))
61
61
  throw new RangeError("Invalid time value");
62
62
  const a = Object.assign({}, n, {
63
63
  addSuffix: n == null ? void 0 : n.addSuffix,
64
64
  comparison: i
65
65
  });
66
- let l, c;
67
- i > 0 ? (l = f(t), c = f(e)) : (l = f(e), c = f(t));
68
- const d = z(c, l), m = (T(c) - T(l)) / 1e3, u = Math.round((d - m) / 60);
66
+ let c, l;
67
+ i > 0 ? (c = f(t), l = f(e)) : (c = f(e), l = f(t));
68
+ const d = z(l, c), m = (T(l) - T(c)) / 1e3, u = Math.round((d - m) / 60);
69
69
  let h;
70
70
  if (u < 2)
71
71
  return n != null && n.includeSeconds ? d < 5 ? r.formatDistance("lessThanXSeconds", 5, a) : d < 10 ? r.formatDistance("lessThanXSeconds", 10, a) : d < 20 ? r.formatDistance("lessThanXSeconds", 20, a) : d < 40 ? r.formatDistance("halfAMinute", 0, a) : d < 60 ? r.formatDistance("lessThanXMinutes", 1, a) : r.formatDistance("xMinutes", 1, a) : u === 0 ? r.formatDistance("lessThanXMinutes", 1, a) : r.formatDistance("xMinutes", u, a);
@@ -85,7 +85,7 @@ function ee(e, t, n) {
85
85
  } else if (u < M * 2)
86
86
  return h = Math.round(u / M), r.formatDistance("aboutXMonths", h, a);
87
87
  }
88
- if (h = Q(c, l), h < 12) {
88
+ if (h = Q(l, c), h < 12) {
89
89
  const g = Math.round(u / M);
90
90
  return r.formatDistance("xMonths", g, a);
91
91
  } else {
@@ -96,13 +96,13 @@ function ee(e, t, n) {
96
96
  function te(e, t) {
97
97
  return ee(e, G(e), t);
98
98
  }
99
- const V = [
99
+ const N = [
100
100
  "day",
101
101
  "hour",
102
102
  "minute",
103
103
  "second",
104
104
  "millisecond"
105
- ], L = {
105
+ ], p = {
106
106
  day: 864e5,
107
107
  hour: 36e5,
108
108
  minute: 6e4,
@@ -124,32 +124,32 @@ const V = [
124
124
  function oe(e) {
125
125
  return e === "day" || e === "hour" || e === "minute" || e === "second" || e === "millisecond";
126
126
  }
127
- function $(e, t) {
127
+ function V(e, t) {
128
128
  return oe(e) ? e : t;
129
129
  }
130
- function N(e, t) {
131
- return V.indexOf($(e, t));
130
+ function _(e, t) {
131
+ return N.indexOf(V(e, t));
132
132
  }
133
133
  function se(e, t) {
134
- const n = N(e, "day"), o = N(t, "second"), r = Math.min(n, o), s = Math.max(n, o);
135
- return V.slice(r, s + 1);
134
+ const n = _(e, "day"), o = _(t, "second"), r = Math.min(n, o), s = Math.max(n, o);
135
+ return N.slice(r, s + 1);
136
136
  }
137
137
  function ae(e, t) {
138
- return e * L[$(t, "second")];
138
+ return e * p[V(t, "second")];
139
139
  }
140
140
  function ie(e, t) {
141
- const n = se(t.largestUnit, t.smallestUnit), o = n[n.length - 1], r = L[o];
141
+ const n = se(t.largestUnit, t.smallestUnit), o = n[n.length - 1], r = p[o];
142
142
  let s = Math.round(e / r) * r;
143
143
  return n.map((i) => {
144
- const a = L[i], l = Math.floor(s / a);
145
- return s -= l * a, { unit: i, value: l };
144
+ const a = p[i], c = Math.floor(s / a);
145
+ return s -= c * a, { unit: i, value: c };
146
146
  });
147
147
  }
148
- function le(e, t) {
148
+ function ce(e, t) {
149
149
  const n = e.filter((s) => s.value !== 0), o = n.length > 0 ? n : [e[e.length - 1]], r = typeof t == "number" && Number.isFinite(t) ? Math.max(1, Math.trunc(t)) : o.length;
150
150
  return o.slice(0, r).map((s) => `${s.value}${ne[s.unit]}`).join(" ");
151
151
  }
152
- function ce(e, t) {
152
+ function le(e, t) {
153
153
  const n = e.filter((s) => s.value !== 0), o = n.length > 0 ? n : [e[e.length - 1]], r = typeof t == "number" && Number.isFinite(t) ? Math.max(1, Math.trunc(t)) : o.length;
154
154
  return o.slice(0, r).map((s) => {
155
155
  const [i, a] = re[s.unit];
@@ -158,11 +158,11 @@ function ce(e, t) {
158
158
  }
159
159
  function ue(e) {
160
160
  const t = e.some(
161
- (l) => l.unit === "day" && l.value !== 0
162
- ), n = e.some((l) => l.unit === "millisecond"), o = e.findIndex((l) => l.value !== 0), r = Math.max(0, e.length - 2), s = t ? 0 : o === -1 ? r : Math.min(o, r), i = o === -1 ? e.slice(r) : e.slice(s);
161
+ (c) => c.unit === "day" && c.value !== 0
162
+ ), n = e.some((c) => c.unit === "millisecond"), o = e.findIndex((c) => c.value !== 0), r = Math.max(0, e.length - 2), s = t ? 0 : o === -1 ? r : Math.min(o, r), i = o === -1 ? e.slice(r) : e.slice(s);
163
163
  if (i.length === 0)
164
164
  return "0";
165
- const a = i.map((l, c) => l.unit === "millisecond" ? String(l.value).padStart(3, "0") : c === 0 ? String(l.value) : String(l.value).padStart(2, "0")).join(":");
165
+ const a = i.map((c, l) => c.unit === "millisecond" ? String(c.value).padStart(3, "0") : l === 0 ? String(c.value) : String(c.value).padStart(2, "0")).join(":");
166
166
  return n ? a.replace(/:(\d{3})$/, ".$1") : a;
167
167
  }
168
168
  function fe(e, t, n) {
@@ -175,8 +175,8 @@ function me(e, t = {}) {
175
175
  const n = typeof e == "number" ? e : typeof e == "string" && e.trim() ? Number(e) : NaN;
176
176
  if (!Number.isFinite(n))
177
177
  return "";
178
- const o = t.inputUnit || "second", r = t.outputStyle === "digital" || t.outputStyle === "long" ? t.outputStyle : "compact", s = n < 0, i = Math.abs(ae(n, o)), a = ie(i, t), l = r === "digital" ? ue(a) : r === "long" ? ce(a, t.maxUnits) : le(a, t.maxUnits);
179
- return fe(l, s, t);
178
+ const o = t.inputUnit || "second", r = t.outputStyle === "digital" || t.outputStyle === "long" ? t.outputStyle : "compact", s = n < 0, i = Math.abs(ae(n, o)), a = ie(i, t), c = r === "digital" ? ue(a) : r === "long" ? le(a, t.maxUnits) : ce(a, t.maxUnits);
179
+ return fe(c, s, t);
180
180
  }
181
181
  function de(e, t, n) {
182
182
  const o = {
@@ -191,7 +191,7 @@ function de(e, t, n) {
191
191
  negativeStyle: o.type === "currency" ? o.negativeStyle : "minus"
192
192
  })}${s ?? ""}`;
193
193
  }
194
- function p(e, t, n) {
194
+ function L(e, t, n) {
195
195
  return e === null ? { value: e, text: null } : !t || !Z(t) && t.type !== "duration" ? {
196
196
  value: e,
197
197
  text: y(e, { type: "number", locale: n })
@@ -236,21 +236,21 @@ function I(e, t) {
236
236
  throw new RangeError("Comparison precision must be an integer from 0 to 6.");
237
237
  return e;
238
238
  }
239
- function Ne(e, t) {
239
+ function ve(e, t) {
240
240
  const n = {
241
241
  mode: t.displayMode,
242
- current: p(
242
+ current: L(
243
243
  e.currentValue,
244
244
  t.metricFormat,
245
245
  t.locale
246
246
  ),
247
- comparison: p(
247
+ comparison: L(
248
248
  e.comparisonValue,
249
249
  t.metricFormat,
250
250
  t.locale
251
251
  )
252
252
  };
253
- return (t.displayMode === "difference" || t.displayMode === "both") && (n.difference = p(
253
+ return (t.displayMode === "difference" || t.displayMode === "both") && (n.difference = L(
254
254
  e.delta,
255
255
  t.metricFormat,
256
256
  t.locale
@@ -266,10 +266,10 @@ function Ne(e, t) {
266
266
  "ratio"
267
267
  )), n;
268
268
  }
269
- function ve(e, t) {
269
+ function Ie(e, t) {
270
270
  return e && e !== "auto" ? e : t;
271
271
  }
272
- function Ie(e, t = /* @__PURE__ */ new Date()) {
272
+ function Ne(e, t = /* @__PURE__ */ new Date()) {
273
273
  try {
274
274
  const n = {
275
275
  timeZone: e,
@@ -305,9 +305,9 @@ function C(e, t = "auto") {
305
305
  return new Date(s);
306
306
  }
307
307
  return new Date(e);
308
- } else return t === "UTC" ? n ? new Date(e) : o ? new Date(e) : /* @__PURE__ */ new Date(e + "Z") : n || o || r ? new Date(e) : j(e, t);
308
+ } else return t === "UTC" ? n ? new Date(e) : o ? new Date(e) : /* @__PURE__ */ new Date(e + "Z") : n || o || r ? new Date(e) : B(e, t);
309
309
  }
310
- const ge = "MM/dd/yyyy", $e = (e, t, n, o = "auto") => {
310
+ const ge = "MM/dd/yyyy", Ce = (e, t, n, o = "auto") => {
311
311
  if (!e)
312
312
  return "";
313
313
  try {
@@ -315,11 +315,11 @@ const ge = "MM/dd/yyyy", $e = (e, t, n, o = "auto") => {
315
315
  if (isNaN(r.getTime()))
316
316
  return e;
317
317
  const i = (t && t.trim() ? t : ge).replace(/LLLL/g, "MMMM").replace(/LLL/g, "MMM");
318
- return n && n !== "auto" ? k(r, n, i) : B(r, i);
318
+ return n && n !== "auto" ? k(r, n, i) : X(r, i);
319
319
  } catch (r) {
320
320
  return console.error("Date formatting error:", r), e;
321
321
  }
322
- }, Ce = (e, t = "auto") => {
322
+ }, $e = (e, t = "auto") => {
323
323
  if (!e)
324
324
  return "";
325
325
  try {
@@ -344,7 +344,7 @@ function Me(e, t = {}) {
344
344
  ` } = t;
345
345
  return e.map((r) => ye(r, n)).join(o);
346
346
  }
347
- function _e(e, t = {}) {
347
+ function Ee(e, t = {}) {
348
348
  if (e.length === 0)
349
349
  return "";
350
350
  const {
@@ -355,33 +355,37 @@ function _e(e, t = {}) {
355
355
  columns: s
356
356
  } = t, i = s || Object.keys(e[0]), a = [];
357
357
  r && a.push(i);
358
- for (const l of e) {
359
- const c = i.map((d) => {
360
- const m = l[d];
358
+ for (const c of e) {
359
+ const l = i.map((d) => {
360
+ const m = c[d];
361
361
  return m == null ? "" : String(m);
362
362
  });
363
- a.push(c);
363
+ a.push(l);
364
364
  }
365
365
  return Me(a, { delimiter: n, lineEnding: o });
366
366
  }
367
- const be = "__TOTAL__";
367
+ const be = 1e4, Fe = 1e6;
368
+ function Re(e) {
369
+ return e > be;
370
+ }
371
+ const De = "__TOTAL__";
368
372
  function D(e) {
369
373
  return typeof e == "object" && e !== null && !Array.isArray(e);
370
374
  }
371
375
  function x(e) {
372
- return e === be;
376
+ return e === De;
373
377
  }
374
- function Fe(e) {
378
+ function Ue(e) {
375
379
  const t = /* @__PURE__ */ new Map(), n = (e.groupByColumns ?? []).map((r, s) => {
376
- var c, d, m;
380
+ var l, d, m;
377
381
  if (!D(r))
378
382
  throw new Error(`Aggregate groupByColumns[${s}] is invalid`);
379
- const i = typeof r.id == "string" && r.id.length > 0 ? r.id : void 0, a = i ? (m = (d = (c = e.columnKeyMap) == null ? void 0 : c.byRole) == null ? void 0 : d.groupby) == null ? void 0 : m[i] : void 0, l = (a == null ? void 0 : a.outputKey) || (a == null ? void 0 : a.rawKey) || (typeof r.alias == "string" && r.alias.length > 0 ? r.alias : typeof r.name == "string" && r.name.length > 0 ? r.name : void 0);
380
- if (!l)
383
+ const i = typeof r.id == "string" && r.id.length > 0 ? r.id : void 0, a = i ? (m = (d = (l = e.columnKeyMap) == null ? void 0 : l.byRole) == null ? void 0 : d.groupby) == null ? void 0 : m[i] : void 0, c = (a == null ? void 0 : a.outputKey) || (a == null ? void 0 : a.rawKey) || (typeof r.alias == "string" && r.alias.length > 0 ? r.alias : typeof r.name == "string" && r.name.length > 0 ? r.name : void 0);
384
+ if (!c)
381
385
  throw new Error(`Aggregate groupByColumns[${s}] has no output key`);
382
- return [i, r.alias, r.name, l].forEach((u) => {
383
- typeof u == "string" && u.length > 0 && t.set(u, l);
384
- }), l;
386
+ return [i, r.alias, r.name, c].forEach((u) => {
387
+ typeof u == "string" && u.length > 0 && t.set(u, c);
388
+ }), c;
385
389
  }), o = (e.rowAggregates ?? []).flatMap((r) => !D(r) || typeof r.function != "string" || typeof r.groupLevel != "string" ? [] : [
386
390
  {
387
391
  function: r.function,
@@ -391,13 +395,13 @@ function Fe(e) {
391
395
  ]);
392
396
  return { groupColumnKeys: n, rowAggregates: o };
393
397
  }
394
- function _(e) {
398
+ function $(e) {
395
399
  return e === "SUM" ? "Total" : e.charAt(0).toUpperCase() + e.slice(1).toLowerCase();
396
400
  }
397
- function De(e) {
401
+ function we(e) {
398
402
  var n;
399
403
  if (e.customLabel) return e.customLabel;
400
- const t = _(e.aggregateFunction);
404
+ const t = $(e.aggregateFunction);
401
405
  if (e.levelValue !== void 0 && !x(e.levelValue)) {
402
406
  if (e.levelValue === null) {
403
407
  const r = (n = e.formatValue) == null ? void 0 : n.call(e, null);
@@ -408,10 +412,10 @@ function De(e) {
408
412
  }
409
413
  return `Subtotal ${t}`;
410
414
  }
411
- function we(e, t) {
412
- return t || `Grand ${_(e)}`;
415
+ function Le(e, t) {
416
+ return t || `Grand ${$(e)}`;
413
417
  }
414
- function F(e) {
418
+ function E(e) {
415
419
  var o, r;
416
420
  const t = e.context.groupColumnKeys, n = typeof e.row.aggregate == "string" ? e.row.aggregate : "SUM";
417
421
  if (e.row.isGrandTotal === !0) {
@@ -422,7 +426,7 @@ function F(e) {
422
426
  kind: "grand-total",
423
427
  cells: t.map((i, a) => ({
424
428
  columnKey: i,
425
- text: a === 0 ? we(n, s) : "",
429
+ text: a === 0 ? Le(n, s) : "",
426
430
  placement: a === 0 ? "label" : "empty",
427
431
  colSpan: a === 0 ? t.length : 1
428
432
  }))
@@ -436,35 +440,35 @@ function F(e) {
436
440
  throw new Error(
437
441
  `Aggregate subtotal level "${e.row.subtotalLevel}" has no group column`
438
442
  );
439
- const i = D(e.row.subtotalContext) ? e.row.subtotalContext : void 0, a = D(i == null ? void 0 : i.groupByValues) ? i.groupByValues : {}, l = (r = e.context.rowAggregates.find(
440
- (c) => c.groupLevel === e.row.subtotalLevel && c.function === n
443
+ const i = D(e.row.subtotalContext) ? e.row.subtotalContext : void 0, a = D(i == null ? void 0 : i.groupByValues) ? i.groupByValues : {}, c = (r = e.context.rowAggregates.find(
444
+ (l) => l.groupLevel === e.row.subtotalLevel && l.function === n
441
445
  )) == null ? void 0 : r.label;
442
446
  return {
443
447
  kind: "subtotal",
444
- cells: t.map((c, d) => {
448
+ cells: t.map((l, d) => {
445
449
  if (d > s)
446
450
  return {
447
- columnKey: c,
451
+ columnKey: l,
448
452
  text: "",
449
453
  placement: "empty",
450
454
  colSpan: 1
451
455
  };
452
456
  if (d < s) {
453
- const m = e.row[c];
457
+ const m = e.row[l];
454
458
  return {
455
- columnKey: c,
456
- text: m === void 0 || x(m) ? "" : e.formatValue(m, c),
459
+ columnKey: l,
460
+ text: m === void 0 || x(m) ? "" : e.formatValue(m, l),
457
461
  placement: "value",
458
462
  colSpan: 1
459
463
  };
460
464
  }
461
465
  return {
462
- columnKey: c,
463
- text: De({
466
+ columnKey: l,
467
+ text: we({
464
468
  aggregateFunction: n,
465
- customLabel: l,
466
- levelValue: a[c],
467
- formatValue: (m) => e.formatLabelValue ? e.formatLabelValue(m, c) : String(e.formatValue(m, c) ?? "")
469
+ customLabel: c,
470
+ levelValue: a[l],
471
+ formatValue: (m) => e.formatLabelValue ? e.formatLabelValue(m, l) : String(e.formatValue(m, l) ?? "")
468
472
  }),
469
473
  placement: "label",
470
474
  colSpan: t.length - s
@@ -485,16 +489,16 @@ function F(e) {
485
489
  })
486
490
  };
487
491
  }
488
- function Ue(e) {
489
- const t = F(e).cells.find(
492
+ function Oe(e) {
493
+ const t = E(e).cells.find(
490
494
  (n) => n.columnKey === e.columnKey
491
495
  );
492
496
  if (!t)
493
497
  throw new Error(`Aggregate group column "${e.columnKey}" is unknown`);
494
498
  return t.text;
495
499
  }
496
- function Ee(e) {
497
- return F(e).cells.map((t) => t.text);
500
+ function Pe(e) {
501
+ return E(e).cells.map((t) => t.text);
498
502
  }
499
503
  class pe extends Error {
500
504
  constructor(n, o) {
@@ -503,7 +507,7 @@ class pe extends Error {
503
507
  this.code = n, this.name = "PivotHeaderPresentationError";
504
508
  }
505
509
  }
506
- function Pe(e) {
510
+ function Ze(e) {
507
511
  var r;
508
512
  const t = e.mode ?? "formatted", n = e.members.map((s) => {
509
513
  var a;
@@ -515,7 +519,7 @@ function Pe(e) {
515
519
  "missing_resolved_temporal_format",
516
520
  `Missing resolved temporal presentation for pivot field "${s.fieldId}"`
517
521
  );
518
- return X({
522
+ return j({
519
523
  value: s.value,
520
524
  metadata: s.temporalBucket,
521
525
  format: i
@@ -531,27 +535,30 @@ function Pe(e) {
531
535
  };
532
536
  }
533
537
  export {
534
- be as A,
538
+ De as A,
539
+ be as D,
540
+ Fe as F,
535
541
  pe as P,
536
- $e as a,
542
+ Ce as a,
537
543
  ye as b,
538
544
  me as c,
539
- Ne as d,
545
+ ve as d,
540
546
  he as e,
541
- Ce as f,
542
- Ie as g,
547
+ $e as f,
548
+ Ne as g,
543
549
  Ve as h,
544
550
  Me as i,
545
- x as j,
546
- Fe as k,
547
- De as l,
551
+ Re as j,
552
+ x as k,
553
+ Ue as l,
548
554
  we as m,
549
- F as n,
550
- _e as o,
555
+ Le as n,
556
+ Ee as o,
551
557
  C as p,
552
- Ue as q,
553
- ve as r,
554
- Ee as s,
558
+ E as q,
559
+ Ie as r,
560
+ Oe as s,
555
561
  Pe as t,
556
- te as u
562
+ Ze as u,
563
+ te as v
557
564
  };
@@ -0,0 +1,4 @@
1
+ "use strict";var Z=Object.defineProperty;var G=(e,t,n)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var x=(e,t,n)=>G(e,typeof t!="symbol"?t+"":t,n);const l=require("./format-types-PSZZ7hG8.cjs"),M=require("./pivot-result-lifecycle-DJgO2P0H.cjs"),B=require("./index-F25jnH0p.cjs"),j=require("./temporal-bucket-9Wz9Ds6H.cjs");function y(e,t){const n=l.toDate(e),o=l.toDate(t),r=n.getTime()-o.getTime();return r<0?-1:r>0?1:r}function H(e){return l.constructFrom(e,Date.now())}function Y(e,t){const n=l.toDate(e),o=l.toDate(t),r=n.getFullYear()-o.getFullYear(),a=n.getMonth()-o.getMonth();return r*12+a}function W(e){return t=>{const o=(e?Math[e]:Math.trunc)(t);return o===0?0:o}}function q(e,t){return+l.toDate(e)-+l.toDate(t)}function K(e){const t=l.toDate(e);return t.setHours(23,59,59,999),t}function J(e){const t=l.toDate(e),n=t.getMonth();return t.setFullYear(t.getFullYear(),n+1,0),t.setHours(23,59,59,999),t}function Q(e){const t=l.toDate(e);return+K(t)==+J(t)}function z(e,t){const n=l.toDate(e),o=l.toDate(t),r=y(n,o),a=Math.abs(Y(n,o));let i;if(a<1)i=0;else{n.getMonth()===1&&n.getDate()>27&&n.setDate(30),n.setMonth(n.getMonth()-r*a);let s=y(n,o)===-r;Q(l.toDate(e))&&a===1&&y(e,o)===1&&(s=!1),i=r*(a-Number(s))}return i===0?0:i}function ee(e,t,n){const o=q(e,t)/1e3;return W(n==null?void 0:n.roundingMethod)(o)}function te(e,t,n){const o=l.getDefaultOptions(),r=(n==null?void 0:n.locale)??o.locale??l.enUS,a=2520,i=y(e,t);if(isNaN(i))throw new RangeError("Invalid time value");const s=Object.assign({},n,{addSuffix:n==null?void 0:n.addSuffix,comparison:i});let c,u;i>0?(c=l.toDate(t),u=l.toDate(e)):(c=l.toDate(e),u=l.toDate(t));const g=ee(u,c),m=(l.getTimezoneOffsetInMilliseconds(u)-l.getTimezoneOffsetInMilliseconds(c))/1e3,f=Math.round((g-m)/60);let h;if(f<2)return n!=null&&n.includeSeconds?g<5?r.formatDistance("lessThanXSeconds",5,s):g<10?r.formatDistance("lessThanXSeconds",10,s):g<20?r.formatDistance("lessThanXSeconds",20,s):g<40?r.formatDistance("halfAMinute",0,s):g<60?r.formatDistance("lessThanXMinutes",1,s):r.formatDistance("xMinutes",1,s):f===0?r.formatDistance("lessThanXMinutes",1,s):r.formatDistance("xMinutes",f,s);if(f<45)return r.formatDistance("xMinutes",f,s);if(f<90)return r.formatDistance("aboutXHours",1,s);if(f<l.minutesInDay){const d=Math.round(f/60);return r.formatDistance("aboutXHours",d,s)}else{if(f<a)return r.formatDistance("xDays",1,s);if(f<l.minutesInMonth){const d=Math.round(f/l.minutesInDay);return r.formatDistance("xDays",d,s)}else if(f<l.minutesInMonth*2)return h=Math.round(f/l.minutesInMonth),r.formatDistance("aboutXMonths",h,s)}if(h=z(u,c),h<12){const d=Math.round(f/l.minutesInMonth);return r.formatDistance("xMonths",d,s)}else{const d=h%12,T=Math.trunc(h/12);return d<3?r.formatDistance("aboutXYears",T,s):d<9?r.formatDistance("overXYears",T,s):r.formatDistance("almostXYears",T+1,s)}}function v(e,t){return te(e,H(e),t)}const E=["day","hour","minute","second","millisecond"],L={day:864e5,hour:36e5,minute:6e4,second:1e3,millisecond:1},ne={day:"d",hour:"hr",minute:"min",second:"s",millisecond:"ms"},re={day:["day","days"],hour:["hour","hours"],minute:["minute","minutes"],second:["second","seconds"],millisecond:["millisecond","milliseconds"]};function oe(e){return e==="day"||e==="hour"||e==="minute"||e==="second"||e==="millisecond"}function R(e,t){return oe(e)?e:t}function S(e,t){return E.indexOf(R(e,t))}function ae(e,t){const n=S(e,"day"),o=S(t,"second"),r=Math.min(n,o),a=Math.max(n,o);return E.slice(r,a+1)}function se(e,t){return e*L[R(t,"second")]}function ie(e,t){const n=ae(t.largestUnit,t.smallestUnit),o=n[n.length-1],r=L[o];let a=Math.round(e/r)*r;return n.map(i=>{const s=L[i],c=Math.floor(a/s);return a-=c*s,{unit:i,value:c}})}function ce(e,t){const n=e.filter(a=>a.value!==0),o=n.length>0?n:[e[e.length-1]],r=typeof t=="number"&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):o.length;return o.slice(0,r).map(a=>`${a.value}${ne[a.unit]}`).join(" ")}function le(e,t){const n=e.filter(a=>a.value!==0),o=n.length>0?n:[e[e.length-1]],r=typeof t=="number"&&Number.isFinite(t)?Math.max(1,Math.trunc(t)):o.length;return o.slice(0,r).map(a=>{const[i,s]=re[a.unit];return`${a.value} ${a.value===1?i:s}`}).join(" ")}function ue(e){const t=e.some(c=>c.unit==="day"&&c.value!==0),n=e.some(c=>c.unit==="millisecond"),o=e.findIndex(c=>c.value!==0),r=Math.max(0,e.length-2),a=t?0:o===-1?r:Math.min(o,r),i=o===-1?e.slice(r):e.slice(a);if(i.length===0)return"0";const s=i.map((c,u)=>c.unit==="millisecond"?String(c.value).padStart(3,"0"):u===0?String(c.value):String(c.value).padStart(2,"0")).join(":");return n?s.replace(/:(\d{3})$/,".$1"):s}function fe(e,t,n){const o=`${n.prefix||""}${e}${n.suffix||""}`;return t?n.negativeInParentheses?`(${o})`:`-${o}`:o}function V(e,t={}){if(e==null)return"";const n=typeof e=="number"?e:typeof e=="string"&&e.trim()?Number(e):NaN;if(!Number.isFinite(n))return"";const o=t.inputUnit||"second",r=t.outputStyle==="digital"||t.outputStyle==="long"?t.outputStyle:"compact",a=n<0,i=Math.abs(se(n,o)),s=ie(i,t),c=r==="digital"?ue(s):r==="long"?le(s,t.maxUnits):ce(s,t.maxUnits);return fe(c,a,t)}function me(e,t,n){const o={...t,locale:t.locale??n};if(o.type==="number")return M.formatNumericCanonical(e,o);const{prefix:r,suffix:a,...i}=o;return`${r??""}${M.formatNumericCanonical(e,{...i,negativeStyle:o.type==="currency"?o.negativeStyle:"minus"})}${a??""}`}function w(e,t,n){return e===null?{value:e,text:null}:!t||!l.isNumericCanonicalFormat(t)&&t.type!=="duration"?{value:e,text:M.formatNumericCanonical(e,{type:"number",locale:n})}:t.type==="duration"?{value:e,text:V(e,{inputUnit:t.inputUnit,outputStyle:t.outputStyle,largestUnit:t.largestUnit,smallestUnit:t.smallestUnit,maxUnits:t.maxUnits,prefix:t.prefix,suffix:t.suffix,negativeInParentheses:t.negativeStyle==="parentheses"})}:{value:e,text:me(e,t,n)}}function C(e,t,n,o){return e===null?{value:e,text:null}:o==="percent"?{value:e,text:M.formatNumericCanonical(e,{type:"percent",locale:n,minimumFractionDigits:t,maximumFractionDigits:t,percentValueMode:"fraction"})}:{value:e,text:M.formatNumericCanonical(e,{type:"number",locale:n,minimumFractionDigits:t,maximumFractionDigits:t,suffix:"×"})}}function _(e,t){if(e===void 0)return t;if(!Number.isInteger(e)||e<0||e>6)throw new RangeError("Comparison precision must be an integer from 0 to 6.");return e}function ge(e,t){const n={mode:t.displayMode,current:w(e.currentValue,t.metricFormat,t.locale),comparison:w(e.comparisonValue,t.metricFormat,t.locale)};return(t.displayMode==="difference"||t.displayMode==="both")&&(n.difference=w(e.delta,t.metricFormat,t.locale)),(t.displayMode==="percent_change"||t.displayMode==="both")&&(n.percentChange=C(e.percentChange,_(t.precision,1),t.locale,"percent")),t.displayMode==="ratio"&&(n.ratio=C(e.ratio,_(t.precision,2),t.locale,"ratio")),n}function de(e,t){return e&&e!=="auto"?e:t}function he(e,t=new Date){try{const n={timeZone:e,timeZoneName:"short"},r=new Intl.DateTimeFormat("en-US",n).formatToParts(t).find(a=>a.type==="timeZoneName");return(r==null?void 0:r.value)||e}catch{return e}}function Me(e){try{const t={timeZone:e,timeZoneName:"long"},o=new Intl.DateTimeFormat("en-US",t).formatToParts(new Date).find(r=>r.type==="timeZoneName");return(o==null?void 0:o.value)||e}catch{return e}}function p(e,t="auto"){if(!e)return new Date(NaN);const n=e.endsWith("Z"),o=/[+-]\d{2}:?\d{2}$/.test(e),r=/\([A-Z]{3,4}\)$/.test(e);if(t==="auto")return n||o||r?new Date(e):new Date(e+"Z");if(t==="local"){if(n||o){const a=e.replace(/Z$/,"").replace(/[+-]\d{2}:?\d{2}$/,"");return new Date(a)}return new Date(e)}else return t==="UTC"?n?new Date(e):o?new Date(e):new Date(e+"Z"):n||o||r?new Date(e):B.fromZonedTime(e,t)}const ye="MM/dd/yyyy",De=(e,t,n,o="auto")=>{if(!e)return"";try{const r=p(e,o);if(isNaN(r.getTime()))return e;const i=(t&&t.trim()?t:ye).replace(/LLLL/g,"MMMM").replace(/LLL/g,"MMM");return n&&n!=="auto"?l.formatInTimeZone(r,n,i):l.format(r,i)}catch(r){return console.error("Date formatting error:",r),e}},be=(e,t="auto")=>{if(!e)return"";try{const n=p(e,t);return isNaN(n.getTime())?e:v(n,{addSuffix:!0})}catch(n){return console.error("Relative time formatting error:",n),e}};function I(e,t=","){if(e==null)return"";const n=String(e);return n.includes(t)||n.includes('"')||n.includes(`
2
+ `)||n.includes("\r")?`"${n.replace(/"/g,'""')}"`:n}function N(e,t=","){return e.map(n=>I(n,t)).join(t)}function O(e,t={}){const{delimiter:n=",",lineEnding:o=`
3
+ `}=t;return e.map(r=>N(r,n)).join(o)}function Te(e,t={}){if(e.length===0)return"";const{delimiter:n=",",lineEnding:o=`
4
+ `,includeHeaders:r=!0,columns:a}=t,i=a||Object.keys(e[0]),s=[];r&&s.push(i);for(const c of e){const u=i.map(g=>{const m=c[g];return m==null?"":String(m)});s.push(u)}return O(s,{delimiter:n,lineEnding:o})}const $=1e4,we=1e6;function Le(e){return e>$}const P="__TOTAL__";function D(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function b(e){return e===P}function pe(e){const t=new Map,n=(e.groupByColumns??[]).map((r,a)=>{var u,g,m;if(!D(r))throw new Error(`Aggregate groupByColumns[${a}] is invalid`);const i=typeof r.id=="string"&&r.id.length>0?r.id:void 0,s=i?(m=(g=(u=e.columnKeyMap)==null?void 0:u.byRole)==null?void 0:g.groupby)==null?void 0:m[i]:void 0,c=(s==null?void 0:s.outputKey)||(s==null?void 0:s.rawKey)||(typeof r.alias=="string"&&r.alias.length>0?r.alias:typeof r.name=="string"&&r.name.length>0?r.name:void 0);if(!c)throw new Error(`Aggregate groupByColumns[${a}] has no output key`);return[i,r.alias,r.name,c].forEach(f=>{typeof f=="string"&&f.length>0&&t.set(f,c)}),c}),o=(e.rowAggregates??[]).flatMap(r=>!D(r)||typeof r.function!="string"||typeof r.groupLevel!="string"?[]:[{function:r.function,groupLevel:r.groupLevel==="ALL"?"ALL":t.get(r.groupLevel)||r.groupLevel,...typeof r.label=="string"?{label:r.label}:{}}]);return{groupColumnKeys:n,rowAggregates:o}}function F(e){return e==="SUM"?"Total":e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function U(e){var n;if(e.customLabel)return e.customLabel;const t=F(e.aggregateFunction);if(e.levelValue!==void 0&&!b(e.levelValue)){if(e.levelValue===null){const r=(n=e.formatValue)==null?void 0:n.call(e,null);return r?`Subtotal ${r}`:`Subtotal ${t}`}const o=e.formatValue?e.formatValue(e.levelValue):String(e.levelValue);if(o)return`Subtotal (${o})`}return`Subtotal ${t}`}function k(e,t){return t||`Grand ${F(e)}`}function A(e){var o,r;const t=e.context.groupColumnKeys,n=typeof e.row.aggregate=="string"?e.row.aggregate:"SUM";if(e.row.isGrandTotal===!0){const a=(o=e.context.rowAggregates.find(i=>i.groupLevel==="ALL"))==null?void 0:o.label;return{kind:"grand-total",cells:t.map((i,s)=>({columnKey:i,text:s===0?k(n,a):"",placement:s===0?"label":"empty",colSpan:s===0?t.length:1}))}}if(e.row.isSubtotal===!0){if(typeof e.row.subtotalLevel!="string")throw new Error("Aggregate subtotal row is missing subtotalLevel");const a=t.indexOf(e.row.subtotalLevel);if(a<0)throw new Error(`Aggregate subtotal level "${e.row.subtotalLevel}" has no group column`);const i=D(e.row.subtotalContext)?e.row.subtotalContext:void 0,s=D(i==null?void 0:i.groupByValues)?i.groupByValues:{},c=(r=e.context.rowAggregates.find(u=>u.groupLevel===e.row.subtotalLevel&&u.function===n))==null?void 0:r.label;return{kind:"subtotal",cells:t.map((u,g)=>{if(g>a)return{columnKey:u,text:"",placement:"empty",colSpan:1};if(g<a){const m=e.row[u];return{columnKey:u,text:m===void 0||b(m)?"":e.formatValue(m,u),placement:"value",colSpan:1}}return{columnKey:u,text:U({aggregateFunction:n,customLabel:c,levelValue:s[u],formatValue:m=>e.formatLabelValue?e.formatLabelValue(m,u):String(e.formatValue(m,u)??"")}),placement:"label",colSpan:t.length-a}})}}return{kind:"data",cells:t.map(a=>{const i=e.row[a];return{columnKey:a,text:i===void 0||b(i)?"":e.formatValue(i,a),placement:"value",colSpan:1}})}}function Ae(e){const t=A(e).cells.find(n=>n.columnKey===e.columnKey);if(!t)throw new Error(`Aggregate group column "${e.columnKey}" is unknown`);return t.text}function xe(e){return A(e).cells.map(t=>t.text)}class X extends Error{constructor(n,o){super(`${n}: ${o}`);x(this,"deliveryBlocking",!0);this.code=n,this.name="PivotHeaderPresentationError"}}function Se(e){var r;const t=e.mode??"formatted",n=e.members.map(a=>{var s;if(t==="canonical"||!a.temporalBucket)return a.value===null?"":String(a.value);const i=(s=e.resolveTemporalFormat)==null?void 0:s.call(e,a.fieldId);if(!i)throw new X("missing_resolved_temporal_format",`Missing resolved temporal presentation for pivot field "${a.fieldId}"`);return j.formatTemporalBucket({value:a.value,metadata:a.temporalBucket,format:i})}),o=((r=e.metricLabel)==null?void 0:r.trim())||void 0;return{memberLabels:n,...o?{metricLabel:o}:{},flattenedLabel:[...n,...o?[o]:[]].join(" / ")}}exports.AGGREGATE_TOTAL_MEMBER_MARKER=P;exports.DIRECT_CSV_EXPORT_MAX_ROWS=$;exports.FULL_DATASET_CSV_EXPORT_MAX_ROWS=we;exports.PivotHeaderPresentationError=X;exports.arrayToCSV=O;exports.arrayToCSVRow=N;exports.escapeCSVValue=I;exports.formatAggregateGrandTotalLabel=k;exports.formatAggregateGroupCell=Ae;exports.formatAggregateGroupRow=xe;exports.formatAggregateSubtotalLabel=U;exports.formatDate=De;exports.formatDistanceToNow=v;exports.formatDuration=V;exports.formatMetricComparison=ge;exports.formatRelativeTime=be;exports.getTimezoneAbbreviation=he;exports.getTimezoneName=Me;exports.isAggregateTotalMemberMarker=b;exports.objectsToCSV=Te;exports.parseWithSourceTimezone=p;exports.presentAggregateGroupRow=A;exports.presentPivotHeader=Se;exports.requiresChunkedCsvExport=Le;exports.resolveAggregateTablePresentationContext=pe;exports.resolveTimezone=de;
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),o=require("react"),l=require("./index-DVBYvkj0.cjs"),u=require("./switch-NAbuOQNg.cjs"),V=require("./report-runtime-context-RFiWq4wK.cjs");require("./x-B6ghREd2.cjs");require("./saved-temporal-bucket-format-DNMtD77o.cjs");require("./validators-DcshgK7w.cjs");require("./analyze-result-contract-OgPk-zGu.cjs");const L=require("../value-format-preferences/index.cjs");function G(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(p=>p.actions.applyResolvedCalendarPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,[g,S]=o.useState(!1),[b,C]=o.useState(!1),[f,j]=o.useState(!1),[T,x]=o.useState(null),[w,P]=o.useState(null),v=o.useRef(i);v.current=i,o.useEffect(()=>{P(null),x(null),S(!1),C(!1),j(!1)},[i]);const N=o.useCallback(async p=>{const r=V.parseCalendarPreferencesResponse(await p.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),k=o.useCallback(async()=>{if(!s||!i||!h)return;const p=i;S(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to fetch preferences")}const n=await N(r);v.current===p&&P(n)}catch(r){v.current===p&&x(r instanceof Error?r.message:"Unknown error")}finally{v.current===p&&S(!1)}},[i,h,s,N]);o.useEffect(()=>{s&&k()},[s,k]);const E=o.useCallback(async p=>{if(!i||!h)return x("Not authenticated"),!1;const r=i;C(!0),x(null);try{const n=await fetch(`${h}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(p)});if(!n.ok){const D=await n.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}const y=await N(n);return v.current!==r?!1:(P(y),m(y.resolved,y.sources),!0)}catch(n){return v.current===r&&x(n instanceof Error?n.message:"Unknown error"),!1}finally{v.current===r&&C(!1)}},[i,h,m,N]),A=o.useCallback(async()=>{if(!i||!h)return x("Not authenticated"),!1;const p=i;j(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to clear preferences")}const n=await N(r);return v.current!==p?!1:(P(n),m(n.resolved,n.sources),!0)}catch(r){return v.current===p&&x(r instanceof Error?r.message:"Unknown error"),!1}finally{v.current===p&&j(!1)}},[i,h,m,N]);return{preferences:w,isLoading:g,isSaving:b,isClearing:f,error:T,updatePreferences:E,clearPreferences:A,refetch:k}}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"}],B=[{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 W(){try{const a=Intl;if(a.supportedValuesOf)return a.supportedValuesOf("timeZone")}catch{}return F.map(a=>a.value)}function H(a){if(!a)return"default";if(a.tz!==a.weekStart)return"inherited";switch(a.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(a){const c=F.find(t=>t.value===a);return c?c.label:a}function K(a){const c=B.find(t=>t.value===a);return c?c.label:String(a)}function J({active:a,onClose:c}){const{preferences:t,isLoading:m,isSaving:s,isClearing:i,updatePreferences:h,clearPreferences:g}=G({enabled:a}),S=l.useCalendarContext(),b=(t==null?void 0:t.resolved.tz)||(S==null?void 0:S.tz)||"UTC",C=(t==null?void 0:t.resolved.weekStart)??(S==null?void 0:S.weekStart)??1,[f,j]=o.useState((t==null?void 0:t.stored)===null),[T,x]=o.useState(!1),[w,P]=o.useState(b),[v,N]=o.useState(C),[k,E]=o.useState(!1),A=o.useMemo(()=>W(),[]),p=o.useMemo(()=>A.filter(d=>!F.some(M=>M.value===d)),[A]),r=o.useMemo(()=>U(w),[w]),n=t!=null&&t.inherited?U(t.inherited.tz):"UTC",y=t!=null&&t.inherited?K(t.inherited.weekStart):"Monday",D=H(t==null?void 0:t.inheritedSources);o.useEffect(()=>{if(!a){x(!1);return}T||(t&&j(t.stored===null),P(b),N(C))},[a,T,t,b,C]);const O=async()=>{if(m){l.ue.error("Preferences are still loading. Please try again.");return}f?await g()?(l.ue.success("Now using default settings."),c()):l.ue.error("Failed to save preferences. Please try again."):await h({tz:w,weekStart:v})?(l.ue.success("Preferences saved."),c()):l.ue.error("Failed to save preferences. Please try again.")},_=()=>{c()},z=s||i,$=z||m;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(l.RadioGroup,{value:f?"defaults":"custom",onValueChange:d=>{x(!0),j(d==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",f&&"bg-muted/50"),onClick:()=>{x(!0),j(!0)},children:[e.jsx(l.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 ",D," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[n,", week starts ",y]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!f&&"bg-muted/50"),onClick:()=>{x(!0),j(!1)},children:[e.jsx(l.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:u.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",f&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Timezone"}),e.jsxs(u.Popover,{open:k,onOpenChange:E,modal:!0,children:[e.jsx(u.PopoverTrigger,{asChild:!0,children:e.jsxs(u.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"w-full justify-between text-[12px] font-normal",disabled:f,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(l.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(u.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(l.Command,{className:"overflow-visible",children:[e.jsx(l.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(l.CommandList,{children:[e.jsx(l.CommandEmpty,{children:"No timezone found."}),e.jsx(l.CommandGroup,{heading:"Common",children:F.map(d=>e.jsxs(l.CommandItem,{value:`${d.value} ${d.label}`,onSelect:()=>{x(!0),P(d.value),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:d.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:d.value})]},d.value))}),e.jsx(l.CommandSeparator,{}),e.jsx(l.CommandGroup,{heading:"All timezones",children:p.map(d=>e.jsxs(l.CommandItem,{value:d,onSelect:()=>{x(!0),P(d),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d?"opacity-100":"opacity-0")}),d]},d))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Week starts on"}),e.jsx(l.RadioGroup,{value:String(v),onValueChange:d=>{x(!0),N(Number(d))},className:"flex gap-4",disabled:f,children:B.map(d=>e.jsxs("label",{htmlFor:`week-start-${d.value}`,className:u.cn("flex cursor-pointer items-center gap-2 text-[13px]",f&&"cursor-not-allowed"),children:[e.jsx(l.RadioGroupItem,{value:String(d.value),id:`week-start-${d.value}`,disabled:f}),d.label]},d.value))})]})]})]}),e.jsxs(l.DialogFooter,{children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:_,disabled:z,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:O,disabled:$,children:z?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function Y(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,g=o.useRef(i);g.current=i;const[S,b]=o.useState(null),[C,f]=o.useState(!1),[j,T]=o.useState(!1),[x,w]=o.useState(!1),[P,v]=o.useState(null);o.useEffect(()=>{b(null),v(null),f(!1),T(!1),w(!1)},[i]);const N=o.useCallback(async r=>{const n=L.parseValueFormatPreferencesResponse(await r.json());if(!n.ok)throw new Error("Value format preferences response is invalid");return n.value},[]),k=o.useCallback(async(r,n)=>{if(!i||!h)throw new Error("Not authenticated");const y=await fetch(`${h}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${i}`,...n?{"Content-Type":"application/json"}:{}},body:n?JSON.stringify(n):void 0});if(!y.ok){const D=await y.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}return N(y)},[i,h,N]),E=o.useCallback(async()=>{if(!s||!i||!h)return;const r=i;f(!0),v(null);try{const n=await k("GET");g.current===r&&b(n)}catch(n){g.current===r&&v(n instanceof Error?n.message:"Unknown error")}finally{g.current===r&&f(!1)}},[i,h,s,k]);o.useEffect(()=>{s&&E()},[s,E]);const A=o.useCallback(async r=>{const n=i;T(!0),v(null);try{const y=await k("PATCH",r);return g.current!==n?!1:(b(y),m(y.resolved,y.sources),!0)}catch(y){return g.current===n&&v(y instanceof Error?y.message:"Unknown error"),!1}finally{g.current===n&&T(!1)}},[i,m,k]),p=o.useCallback(async()=>{const r=i;w(!0),v(null);try{const n=await k("DELETE");return g.current!==r?!1:(b(n),m(n.resolved,n.sources),!0)}catch(n){return g.current===r&&v(n instanceof Error?n.message:"Unknown error"),!1}finally{g.current===r&&w(!1)}},[i,m,k]);return{preferences:S,isLoading:C,isSaving:j,isClearing:x,error:P,updatePreferences:A,clearPreferences:p,refetch:E}}const I=["locale","dateStyle","dateTime.dateStyle","dateTime.timeStyle","defaultCurrency"];function q(a,c){var t,m;switch(c){case"locale":return a==null?void 0:a.locale;case"dateStyle":return a==null?void 0:a.dateStyle;case"dateTime.dateStyle":return(t=a==null?void 0:a.dateTime)==null?void 0:t.dateStyle;case"dateTime.timeStyle":return(m=a==null?void 0:a.dateTime)==null?void 0:m.timeStyle;case"defaultCurrency":return a==null?void 0:a.defaultCurrency}}function Z(a){var m,s;const c=(m=a==null?void 0:a.dateTime)==null?void 0:m.dateStyle,t=(s=a==null?void 0:a.dateTime)==null?void 0:s.timeStyle;return{locale:a==null?void 0:a.locale,dateStyle:a==null?void 0:a.dateStyle,dateTime:c===void 0&&t===void 0?void 0:{dateStyle:c,timeStyle:t},defaultCurrency:a==null?void 0:a.defaultCurrency}}function Q({active:a,onClose:c}){var g,S,b,C,f,j,T;const{preferences:t,isLoading:m,isSaving:s,updatePreferences:i}=Y({enabled:a});if(!a)return null;if(!t)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:m?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const h=[((g=t.stored)==null?void 0:g.locale)??"",((S=t.stored)==null?void 0:S.dateStyle)??"",((C=(b=t.stored)==null?void 0:b.dateTime)==null?void 0:C.dateStyle)??"",((j=(f=t.stored)==null?void 0:f.dateTime)==null?void 0:j.timeStyle)??"",((T=t.stored)==null?void 0:T.defaultCurrency)??""].join(":");return e.jsx(X,{preferences:t,isSaving:s,updatePreferences:i,onClose:c},h)}function X({preferences:a,isSaving:c,updatePreferences:t,onClose:m}){var b,C;const[s,i]=o.useState(()=>Z(a.stored)),h=(s.locale===void 0||L.canonicalizeSupportedLocale(s.locale)!==void 0)&&(s.defaultCurrency===void 0||L.canonicalizeSupportedCurrencyCode(s.defaultCurrency)!==void 0)&&(s.dateStyle===void 0||["short","medium","long"].includes(s.dateStyle))&&(((b=s.dateTime)==null?void 0:b.dateStyle)===void 0||["short","medium","long"].includes(s.dateTime.dateStyle))&&(((C=s.dateTime)==null?void 0:C.timeStyle)===void 0||["short","medium","long"].includes(s.dateTime.timeStyle)),g=async()=>{const f={...s.locale!==void 0?{locale:s.locale}:{},...s.dateStyle!==void 0?{dateStyle:s.dateStyle}:{},...s.dateTime?{dateTime:{...s.dateTime}}:{},...s.defaultCurrency!==void 0?{defaultCurrency:s.defaultCurrency}:{}},j=I.filter(w=>q(s,w)===void 0&&q(a.stored,w)!==void 0),T={...Object.keys(f).length>0?{set:f}:{},...j.length>0?{clear:j}:{}};(Object.keys(T).length===0?!0:await t(T))?(l.ue.success("Display format preferences saved."),m()):l.ue.error("Failed to save preferences. Please try again.")},S=async()=>{await t({clear:[...I]})?(l.ue.success("Display format preferences reset."),m()):l.ue.error("Failed to reset display format preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(l.DisplayFormatPreferencesFields,{value:s,inherited:a.inherited,inheritedSources:a.inheritedSources,onChange:i,disabled:c})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",onClick:S,disabled:c||a.stored===null,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:m,disabled:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:g,disabled:c||!h,children:c?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function ee({open:a,onOpenChange:c}){const[t,m]=o.useState("display"),s=()=>c(!1);return e.jsx(l.Dialog,{open:a,onOpenChange:c,children:e.jsxs(l.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(l.DialogHeader,{children:[e.jsx(l.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(l.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(u.Tabs,{value:t,onValueChange:m,children:[e.jsxs(u.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(u.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(u.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(u.TabsContent,{value:"display",children:e.jsx(Q,{active:a&&t==="display",onClose:s})}),e.jsx(u.TabsContent,{value:"calendar",children:e.jsx(J,{active:a&&t==="calendar",onClose:s})})]})]})})}exports.ReportPreferencesDialog=ee;
1
+ "use strict";const e=require("react/jsx-runtime"),o=require("react"),l=require("./index-xdqe-Zvd.cjs"),u=require("./switch-CQN9Hzho.cjs"),V=require("./report-runtime-context-RFiWq4wK.cjs");require("./x-B6ghREd2.cjs");require("./saved-temporal-bucket-format-DNMtD77o.cjs");require("./validators-DcshgK7w.cjs");require("./analyze-result-contract-OgPk-zGu.cjs");const L=require("../value-format-preferences/index.cjs");function G(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(p=>p.actions.applyResolvedCalendarPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,[g,S]=o.useState(!1),[b,C]=o.useState(!1),[f,j]=o.useState(!1),[T,x]=o.useState(null),[w,P]=o.useState(null),v=o.useRef(i);v.current=i,o.useEffect(()=>{P(null),x(null),S(!1),C(!1),j(!1)},[i]);const N=o.useCallback(async p=>{const r=V.parseCalendarPreferencesResponse(await p.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),k=o.useCallback(async()=>{if(!s||!i||!h)return;const p=i;S(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to fetch preferences")}const n=await N(r);v.current===p&&P(n)}catch(r){v.current===p&&x(r instanceof Error?r.message:"Unknown error")}finally{v.current===p&&S(!1)}},[i,h,s,N]);o.useEffect(()=>{s&&k()},[s,k]);const E=o.useCallback(async p=>{if(!i||!h)return x("Not authenticated"),!1;const r=i;C(!0),x(null);try{const n=await fetch(`${h}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(p)});if(!n.ok){const D=await n.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}const y=await N(n);return v.current!==r?!1:(P(y),m(y.resolved,y.sources),!0)}catch(n){return v.current===r&&x(n instanceof Error?n.message:"Unknown error"),!1}finally{v.current===r&&C(!1)}},[i,h,m,N]),A=o.useCallback(async()=>{if(!i||!h)return x("Not authenticated"),!1;const p=i;j(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to clear preferences")}const n=await N(r);return v.current!==p?!1:(P(n),m(n.resolved,n.sources),!0)}catch(r){return v.current===p&&x(r instanceof Error?r.message:"Unknown error"),!1}finally{v.current===p&&j(!1)}},[i,h,m,N]);return{preferences:w,isLoading:g,isSaving:b,isClearing:f,error:T,updatePreferences:E,clearPreferences:A,refetch:k}}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"}],B=[{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 W(){try{const a=Intl;if(a.supportedValuesOf)return a.supportedValuesOf("timeZone")}catch{}return F.map(a=>a.value)}function H(a){if(!a)return"default";if(a.tz!==a.weekStart)return"inherited";switch(a.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(a){const c=F.find(t=>t.value===a);return c?c.label:a}function K(a){const c=B.find(t=>t.value===a);return c?c.label:String(a)}function J({active:a,onClose:c}){const{preferences:t,isLoading:m,isSaving:s,isClearing:i,updatePreferences:h,clearPreferences:g}=G({enabled:a}),S=l.useCalendarContext(),b=(t==null?void 0:t.resolved.tz)||(S==null?void 0:S.tz)||"UTC",C=(t==null?void 0:t.resolved.weekStart)??(S==null?void 0:S.weekStart)??1,[f,j]=o.useState((t==null?void 0:t.stored)===null),[T,x]=o.useState(!1),[w,P]=o.useState(b),[v,N]=o.useState(C),[k,E]=o.useState(!1),A=o.useMemo(()=>W(),[]),p=o.useMemo(()=>A.filter(d=>!F.some(M=>M.value===d)),[A]),r=o.useMemo(()=>U(w),[w]),n=t!=null&&t.inherited?U(t.inherited.tz):"UTC",y=t!=null&&t.inherited?K(t.inherited.weekStart):"Monday",D=H(t==null?void 0:t.inheritedSources);o.useEffect(()=>{if(!a){x(!1);return}T||(t&&j(t.stored===null),P(b),N(C))},[a,T,t,b,C]);const O=async()=>{if(m){l.ue.error("Preferences are still loading. Please try again.");return}f?await g()?(l.ue.success("Now using default settings."),c()):l.ue.error("Failed to save preferences. Please try again."):await h({tz:w,weekStart:v})?(l.ue.success("Preferences saved."),c()):l.ue.error("Failed to save preferences. Please try again.")},_=()=>{c()},z=s||i,$=z||m;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(l.RadioGroup,{value:f?"defaults":"custom",onValueChange:d=>{x(!0),j(d==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",f&&"bg-muted/50"),onClick:()=>{x(!0),j(!0)},children:[e.jsx(l.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 ",D," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[n,", week starts ",y]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!f&&"bg-muted/50"),onClick:()=>{x(!0),j(!1)},children:[e.jsx(l.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:u.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",f&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Timezone"}),e.jsxs(u.Popover,{open:k,onOpenChange:E,modal:!0,children:[e.jsx(u.PopoverTrigger,{asChild:!0,children:e.jsxs(u.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"w-full justify-between text-[12px] font-normal",disabled:f,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(l.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(u.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(l.Command,{className:"overflow-visible",children:[e.jsx(l.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(l.CommandList,{children:[e.jsx(l.CommandEmpty,{children:"No timezone found."}),e.jsx(l.CommandGroup,{heading:"Common",children:F.map(d=>e.jsxs(l.CommandItem,{value:`${d.value} ${d.label}`,onSelect:()=>{x(!0),P(d.value),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:d.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:d.value})]},d.value))}),e.jsx(l.CommandSeparator,{}),e.jsx(l.CommandGroup,{heading:"All timezones",children:p.map(d=>e.jsxs(l.CommandItem,{value:d,onSelect:()=>{x(!0),P(d),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d?"opacity-100":"opacity-0")}),d]},d))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Week starts on"}),e.jsx(l.RadioGroup,{value:String(v),onValueChange:d=>{x(!0),N(Number(d))},className:"flex gap-4",disabled:f,children:B.map(d=>e.jsxs("label",{htmlFor:`week-start-${d.value}`,className:u.cn("flex cursor-pointer items-center gap-2 text-[13px]",f&&"cursor-not-allowed"),children:[e.jsx(l.RadioGroupItem,{value:String(d.value),id:`week-start-${d.value}`,disabled:f}),d.label]},d.value))})]})]})]}),e.jsxs(l.DialogFooter,{children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:_,disabled:z,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:O,disabled:$,children:z?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function Y(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,g=o.useRef(i);g.current=i;const[S,b]=o.useState(null),[C,f]=o.useState(!1),[j,T]=o.useState(!1),[x,w]=o.useState(!1),[P,v]=o.useState(null);o.useEffect(()=>{b(null),v(null),f(!1),T(!1),w(!1)},[i]);const N=o.useCallback(async r=>{const n=L.parseValueFormatPreferencesResponse(await r.json());if(!n.ok)throw new Error("Value format preferences response is invalid");return n.value},[]),k=o.useCallback(async(r,n)=>{if(!i||!h)throw new Error("Not authenticated");const y=await fetch(`${h}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${i}`,...n?{"Content-Type":"application/json"}:{}},body:n?JSON.stringify(n):void 0});if(!y.ok){const D=await y.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}return N(y)},[i,h,N]),E=o.useCallback(async()=>{if(!s||!i||!h)return;const r=i;f(!0),v(null);try{const n=await k("GET");g.current===r&&b(n)}catch(n){g.current===r&&v(n instanceof Error?n.message:"Unknown error")}finally{g.current===r&&f(!1)}},[i,h,s,k]);o.useEffect(()=>{s&&E()},[s,E]);const A=o.useCallback(async r=>{const n=i;T(!0),v(null);try{const y=await k("PATCH",r);return g.current!==n?!1:(b(y),m(y.resolved,y.sources),!0)}catch(y){return g.current===n&&v(y instanceof Error?y.message:"Unknown error"),!1}finally{g.current===n&&T(!1)}},[i,m,k]),p=o.useCallback(async()=>{const r=i;w(!0),v(null);try{const n=await k("DELETE");return g.current!==r?!1:(b(n),m(n.resolved,n.sources),!0)}catch(n){return g.current===r&&v(n instanceof Error?n.message:"Unknown error"),!1}finally{g.current===r&&w(!1)}},[i,m,k]);return{preferences:S,isLoading:C,isSaving:j,isClearing:x,error:P,updatePreferences:A,clearPreferences:p,refetch:E}}const I=["locale","dateStyle","dateTime.dateStyle","dateTime.timeStyle","defaultCurrency"];function q(a,c){var t,m;switch(c){case"locale":return a==null?void 0:a.locale;case"dateStyle":return a==null?void 0:a.dateStyle;case"dateTime.dateStyle":return(t=a==null?void 0:a.dateTime)==null?void 0:t.dateStyle;case"dateTime.timeStyle":return(m=a==null?void 0:a.dateTime)==null?void 0:m.timeStyle;case"defaultCurrency":return a==null?void 0:a.defaultCurrency}}function Z(a){var m,s;const c=(m=a==null?void 0:a.dateTime)==null?void 0:m.dateStyle,t=(s=a==null?void 0:a.dateTime)==null?void 0:s.timeStyle;return{locale:a==null?void 0:a.locale,dateStyle:a==null?void 0:a.dateStyle,dateTime:c===void 0&&t===void 0?void 0:{dateStyle:c,timeStyle:t},defaultCurrency:a==null?void 0:a.defaultCurrency}}function Q({active:a,onClose:c}){var g,S,b,C,f,j,T;const{preferences:t,isLoading:m,isSaving:s,updatePreferences:i}=Y({enabled:a});if(!a)return null;if(!t)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:m?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const h=[((g=t.stored)==null?void 0:g.locale)??"",((S=t.stored)==null?void 0:S.dateStyle)??"",((C=(b=t.stored)==null?void 0:b.dateTime)==null?void 0:C.dateStyle)??"",((j=(f=t.stored)==null?void 0:f.dateTime)==null?void 0:j.timeStyle)??"",((T=t.stored)==null?void 0:T.defaultCurrency)??""].join(":");return e.jsx(X,{preferences:t,isSaving:s,updatePreferences:i,onClose:c},h)}function X({preferences:a,isSaving:c,updatePreferences:t,onClose:m}){var b,C;const[s,i]=o.useState(()=>Z(a.stored)),h=(s.locale===void 0||L.canonicalizeSupportedLocale(s.locale)!==void 0)&&(s.defaultCurrency===void 0||L.canonicalizeSupportedCurrencyCode(s.defaultCurrency)!==void 0)&&(s.dateStyle===void 0||["short","medium","long"].includes(s.dateStyle))&&(((b=s.dateTime)==null?void 0:b.dateStyle)===void 0||["short","medium","long"].includes(s.dateTime.dateStyle))&&(((C=s.dateTime)==null?void 0:C.timeStyle)===void 0||["short","medium","long"].includes(s.dateTime.timeStyle)),g=async()=>{const f={...s.locale!==void 0?{locale:s.locale}:{},...s.dateStyle!==void 0?{dateStyle:s.dateStyle}:{},...s.dateTime?{dateTime:{...s.dateTime}}:{},...s.defaultCurrency!==void 0?{defaultCurrency:s.defaultCurrency}:{}},j=I.filter(w=>q(s,w)===void 0&&q(a.stored,w)!==void 0),T={...Object.keys(f).length>0?{set:f}:{},...j.length>0?{clear:j}:{}};(Object.keys(T).length===0?!0:await t(T))?(l.ue.success("Display format preferences saved."),m()):l.ue.error("Failed to save preferences. Please try again.")},S=async()=>{await t({clear:[...I]})?(l.ue.success("Display format preferences reset."),m()):l.ue.error("Failed to reset display format preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(l.DisplayFormatPreferencesFields,{value:s,inherited:a.inherited,inheritedSources:a.inheritedSources,onChange:i,disabled:c})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",onClick:S,disabled:c||a.stored===null,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:m,disabled:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:g,disabled:c||!h,children:c?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function ee({open:a,onOpenChange:c}){const[t,m]=o.useState("display"),s=()=>c(!1);return e.jsx(l.Dialog,{open:a,onOpenChange:c,children:e.jsxs(l.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(l.DialogHeader,{children:[e.jsx(l.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(l.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(u.Tabs,{value:t,onValueChange:m,children:[e.jsxs(u.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(u.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(u.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(u.TabsContent,{value:"display",children:e.jsx(Q,{active:a&&t==="display",onClose:s})}),e.jsx(u.TabsContent,{value:"calendar",children:e.jsx(J,{active:a&&t==="calendar",onClose:s})})]})]})})}exports.ReportPreferencesDialog=ee;
@@ -1,7 +1,7 @@
1
1
  import { jsxs as o, Fragment as j, jsx as t } from "react/jsx-runtime";
2
2
  import oe, { useState as S, useRef as X, useEffect as U, useCallback as E, useMemo as _ } from "react";
3
- import { az as ee, aA as ce, aB as B, aC as $, aD as de, h as ue, i as me, j as fe, k as he, l as M, m as H, aE as ve, aF as V, aG as z, b as ye, aH as pe, aI as ge, aJ as Se, aK as be, aL as Te } from "./index-tsB3LfTQ.js";
4
- import { u as ae, c as F, O as W, P as we, a as Ce, B as L, b as ke, d as q, L as te, T as xe, F as Ne, G, I as K } from "./switch-DnbD-yCM.js";
3
+ import { az as ee, aA as ce, aB as B, aC as $, aD as de, h as ue, i as me, j as fe, k as he, l as M, m as H, aE as ve, aF as V, aG as z, b as ye, aH as pe, aI as ge, aJ as Se, aK as be, aL as Te } from "./index-0fmECZL2.js";
4
+ import { u as ae, c as F, O as W, P as we, a as Ce, B as L, b as ke, d as q, L as te, T as xe, F as Ne, G, I as K } from "./switch-n2yUNY8i.js";
5
5
  import { a as Pe } from "./report-runtime-context-DnNbpkGo.js";
6
6
  import "./x-CXDkqdur.js";
7
7
  import "./saved-temporal-bucket-format-CygnBDO2.js";