react-semaphor 0.1.313 → 0.1.315

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 (37) hide show
  1. package/dist/brand-studio/index.js +4 -4
  2. package/dist/chunks/{braces-raPCNcS4.js → braces-CWi8x9ww.js} +1 -1
  3. package/dist/chunks/calendar-preferences-dialog-B3JYKgek.js +456 -0
  4. package/dist/chunks/calendar-preferences-dialog-aODuCeYE.js +1 -0
  5. package/dist/chunks/{chevrons-up-down-BYzO4q5w.js → chevrons-up-down-B2viXO2I.js} +1 -1
  6. package/dist/chunks/dashboard-controls-CSunAZVx.js +57 -0
  7. package/dist/chunks/{dashboard-controls-DMsmUQkB.js → dashboard-controls-jvJF-AJC.js} +501 -523
  8. package/dist/chunks/{dashboard-filter-controls-launcher-DBmNn4EY.js → dashboard-filter-controls-launcher-B0i9xSZZ.js} +1 -1
  9. package/dist/chunks/{dashboard-filter-controls-launcher-CqXgWEa1.js → dashboard-filter-controls-launcher-DG6yRPmx.js} +39 -39
  10. package/dist/chunks/{dashboard-json-DMFZLkws.js → dashboard-json-Duea3KSa.js} +1 -1
  11. package/dist/chunks/{dashboard-json-CHoCrAp0.js → dashboard-json-zKDTezgS.js} +2 -2
  12. package/dist/chunks/{edit-dashboard-visual-B0Ae_O25.js → edit-dashboard-visual-MZCJaPiq.js} +419 -419
  13. package/dist/chunks/{edit-dashboard-visual-CIP9G-Bu.js → edit-dashboard-visual-QjRIAadP.js} +1 -1
  14. package/dist/chunks/{index-DjZqoaV5.js → index-B7C8qBWC.js} +193 -193
  15. package/dist/chunks/{index-D7e2Eyp_.js → index-CjRLHvSp.js} +17676 -17583
  16. package/dist/chunks/{palette-7yJYVEvk.js → palette-CIuwlEiG.js} +1 -1
  17. package/dist/chunks/{resource-management-panel-B1mhnY97.js → resource-management-panel-CM3Zsk9H.js} +1 -1
  18. package/dist/chunks/{resource-management-panel-CSkNW3es.js → resource-management-panel-S0LXyguo.js} +18 -18
  19. package/dist/chunks/{save-DDX_vrED.js → save-_ALpoMy6.js} +1 -1
  20. package/dist/chunks/{switch-DEPWsRhf.js → switch-B6fh8nb-.js} +25 -25
  21. package/dist/chunks/{use-create-flow-overlay-state-BHQjJwik.js → use-create-flow-overlay-state-Cp7PYD-t.js} +4 -4
  22. package/dist/chunks/{use-create-flow-overlay-state-7LiC_vaL.js → use-create-flow-overlay-state-CqTBDwBF.js} +1 -1
  23. package/dist/chunks/{use-visual-utils-Dw-uLgop.js → use-visual-utils-D9DsvP1v.js} +12 -12
  24. package/dist/chunks/{use-visual-utils-Bz7kjSrk.js → use-visual-utils-DDd0pAJ_.js} +1 -1
  25. package/dist/dashboard/index.cjs +1 -1
  26. package/dist/dashboard/index.js +1 -1
  27. package/dist/index.cjs +1 -1
  28. package/dist/index.js +69 -70
  29. package/dist/style.css +1 -1
  30. package/dist/surfboard/index.cjs +1 -1
  31. package/dist/surfboard/index.js +7 -8
  32. package/dist/types/main.d.ts +0 -11
  33. package/dist/types/surfboard.d.ts +0 -10
  34. package/package.json +1 -1
  35. package/dist/chunks/dashboard-controls-wPVXTTiH.js +0 -57
  36. package/dist/chunks/dashboard-summary-settings-dialog-CZkn4rtm.js +0 -545
  37. package/dist/chunks/dashboard-summary-settings-dialog-DoxcpXjk.js +0 -1
@@ -1,10 +1,10 @@
1
1
  import { jsxs as d, jsx as r, Fragment as ce } from "react/jsx-runtime";
2
2
  import m from "react";
3
- import { c as $, a as K, P as ge, b as be, B as C, d as fe, U as De, C as Ie, R as me, f as le, X as je, p as se, e as Je, T as Le, q as $e, r as G, s as _e, t as M, v as Ue, w as Ve, x as Ge, y as Me, L as E, z as Q, A as ee, D as re, E as he, F as oe, I as ae, g as xe, h as ye, i as ke, j as ve, k as Ce, S as We } from "../chunks/switch-DEPWsRhf.js";
3
+ import { c as $, a as K, P as ge, b as be, B as C, d as fe, U as De, C as Ie, R as me, f as le, X as je, S as se, e as Je, T as Le, k as $e, l as G, m as _e, n as M, o as Ue, p as Ve, q as Ge, r as Me, L as E, s as Q, t as ee, v as re, I as he, w as oe, x as ae, y as xe, z as ye, A as ke, D as ve, E as Ce, F as We } from "../chunks/switch-B6fh8nb-.js";
4
4
  import { r as He, v as Xe, A as Ye, a as qe, p as Ze } from "../chunks/index-CJdxSyQq.js";
5
- import { P as W } from "../chunks/palette-7yJYVEvk.js";
6
- import { B as Ke } from "../chunks/braces-raPCNcS4.js";
7
- import { S as Qe } from "../chunks/save-DDX_vrED.js";
5
+ import { P as W } from "../chunks/palette-CIuwlEiG.js";
6
+ import { B as Ke } from "../chunks/braces-CWi8x9ww.js";
7
+ import { S as Qe } from "../chunks/save-_ALpoMy6.js";
8
8
  /**
9
9
  * @license lucide-react v0.453.0 - ISC
10
10
  *
@@ -1,4 +1,4 @@
1
- import { c as a } from "./switch-DEPWsRhf.js";
1
+ import { c as a } from "./switch-B6fh8nb-.js";
2
2
  /**
3
3
  * @license lucide-react v0.453.0 - ISC
4
4
  *
@@ -0,0 +1,456 @@
1
+ import { jsx as r, jsxs as s, Fragment as X } from "react/jsx-runtime";
2
+ import ee, { useState as h, useCallback as F, useEffect as ae, useMemo as H } from "react";
3
+ import { u as re, b as te, c as se, d as ne, e as le, f as oe, R as W, g as O, C as ie, h as ce, i as de, j as ue, k as _, l as R, m as me, n as fe, o as N } from "./index-CjRLHvSp.js";
4
+ import { a as S, L as G, P as he, b as pe, B as j, d as ge, e as V, f as ve } from "./switch-B6fh8nb-.js";
5
+ import { C as be } from "./chevrons-up-down-B2viXO2I.js";
6
+ function we(n = {}) {
7
+ var C, A, E, L;
8
+ const { authToken: c, tokenProps: e } = re(), p = n.enabled ?? !0, d = (c == null ? void 0 : c.accessToken) ?? null, u = (e == null ? void 0 : e.apiServiceUrl) ?? null, [I, k] = h(!1), [y, b] = h(!1), [m, g] = h(!1), [T, o] = h(null), [v, w] = h(null), P = v || {
9
+ tz: ((A = (C = e == null ? void 0 : e.params) == null ? void 0 : C.calendarContext) == null ? void 0 : A.tz) || null,
10
+ weekStart: ((L = (E = e == null ? void 0 : e.params) == null ? void 0 : E.calendarContext) == null ? void 0 : L.weekStart) ?? null
11
+ }, f = F(async () => {
12
+ if (!(!p || !d || !u)) {
13
+ k(!0), o(null);
14
+ try {
15
+ const l = await fetch(`${u}/v1/user-preferences/calendar`, {
16
+ method: "GET",
17
+ headers: {
18
+ Authorization: `Bearer ${d}`
19
+ }
20
+ });
21
+ if (!l.ok) {
22
+ const i = await l.json().catch(() => ({}));
23
+ throw new Error(i.error || "Failed to fetch preferences");
24
+ }
25
+ const t = await l.json();
26
+ w({
27
+ tz: t.tz,
28
+ weekStart: t.weekStart,
29
+ source: t.source,
30
+ isInherited: t.isInherited,
31
+ userHasPrefs: t.userHasPrefs,
32
+ inherited: t.inherited
33
+ });
34
+ } catch (l) {
35
+ const t = l instanceof Error ? l.message : "Unknown error";
36
+ o(t);
37
+ } finally {
38
+ k(!1);
39
+ }
40
+ }
41
+ }, [d, u, p]);
42
+ ae(() => {
43
+ p && f();
44
+ }, [p, f]);
45
+ const z = F(
46
+ async (l) => {
47
+ if (!d || !u)
48
+ return o("Not authenticated"), !1;
49
+ b(!0), o(null);
50
+ try {
51
+ const t = await fetch(`${u}/v1/user-preferences/calendar`, {
52
+ method: "PATCH",
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ Authorization: `Bearer ${d}`
56
+ },
57
+ body: JSON.stringify(l)
58
+ });
59
+ if (!t.ok) {
60
+ const i = await t.json().catch(() => ({}));
61
+ throw new Error(i.error || "Failed to update preferences");
62
+ }
63
+ return await f(), !0;
64
+ } catch (t) {
65
+ const i = t instanceof Error ? t.message : "Unknown error";
66
+ return o(i), !1;
67
+ } finally {
68
+ b(!1);
69
+ }
70
+ },
71
+ [d, u, f]
72
+ ), x = F(async () => {
73
+ if (!d || !u)
74
+ return o("Not authenticated"), !1;
75
+ g(!0), o(null);
76
+ try {
77
+ const l = await fetch(`${u}/v1/user-preferences/calendar`, {
78
+ method: "DELETE",
79
+ headers: {
80
+ Authorization: `Bearer ${d}`
81
+ }
82
+ });
83
+ if (!l.ok) {
84
+ const i = await l.json().catch(() => ({}));
85
+ throw new Error(i.error || "Failed to clear preferences");
86
+ }
87
+ const t = await l.text();
88
+ if (t)
89
+ try {
90
+ const i = JSON.parse(t);
91
+ return w({
92
+ tz: i.tz,
93
+ weekStart: i.weekStart,
94
+ source: i.source,
95
+ isInherited: i.isInherited ?? !0,
96
+ userHasPrefs: !1,
97
+ inherited: i.inherited
98
+ }), !0;
99
+ } catch {
100
+ }
101
+ return await f(), !0;
102
+ } catch (l) {
103
+ const t = l instanceof Error ? l.message : "Unknown error";
104
+ return o(t), !1;
105
+ } finally {
106
+ g(!1);
107
+ }
108
+ }, [d, u, f]);
109
+ return {
110
+ preferences: P,
111
+ isLoading: I,
112
+ isSaving: y,
113
+ isClearing: m,
114
+ error: T,
115
+ updatePreferences: z,
116
+ clearPreferences: x,
117
+ refetch: f
118
+ };
119
+ }
120
+ const D = [
121
+ { value: "America/New_York", label: "Eastern Time (US & Canada)" },
122
+ { value: "America/Chicago", label: "Central Time (US & Canada)" },
123
+ { value: "America/Denver", label: "Mountain Time (US & Canada)" },
124
+ { value: "America/Los_Angeles", label: "Pacific Time (US & Canada)" },
125
+ { value: "America/Phoenix", label: "Arizona" },
126
+ { value: "America/Anchorage", label: "Alaska" },
127
+ { value: "Pacific/Honolulu", label: "Hawaii" },
128
+ { value: "Europe/London", label: "London" },
129
+ { value: "Europe/Paris", label: "Paris, Berlin, Rome" },
130
+ { value: "Asia/Tokyo", label: "Tokyo" },
131
+ { value: "Asia/Shanghai", label: "Beijing, Shanghai" },
132
+ { value: "Asia/Kolkata", label: "Mumbai, New Delhi" },
133
+ { value: "Australia/Sydney", label: "Sydney" },
134
+ { value: "UTC", label: "UTC" }
135
+ ], K = [
136
+ { value: 0, label: "Sunday" },
137
+ { value: 1, label: "Monday" },
138
+ { value: 6, label: "Saturday" }
139
+ ], Z = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
140
+ function Se() {
141
+ try {
142
+ const n = Intl;
143
+ if (n.supportedValuesOf)
144
+ return n.supportedValuesOf("timeZone");
145
+ } catch {
146
+ }
147
+ return D.map((n) => n.value);
148
+ }
149
+ function ye(n) {
150
+ switch (n) {
151
+ case "tenant":
152
+ return "tenant";
153
+ case "organization":
154
+ return "organization";
155
+ case "system":
156
+ return "system";
157
+ default:
158
+ return "default";
159
+ }
160
+ }
161
+ function J(n) {
162
+ const c = D.find((e) => e.value === n);
163
+ return c ? c.label : n;
164
+ }
165
+ function xe(n) {
166
+ const c = K.find((e) => e.value === n);
167
+ return c ? c.label : String(n);
168
+ }
169
+ function ze({
170
+ open: n,
171
+ onOpenChange: c
172
+ }) {
173
+ var $, B, M;
174
+ const {
175
+ preferences: e,
176
+ isLoading: p,
177
+ isSaving: d,
178
+ isClearing: u,
179
+ updatePreferences: I,
180
+ clearPreferences: k
181
+ } = we({ enabled: n }), y = e.tz || (($ = e.inherited) == null ? void 0 : $.tz) || Intl.DateTimeFormat().resolvedOptions().timeZone, b = e.weekStart ?? ((B = e.inherited) == null ? void 0 : B.weekStart) ?? 1, [m, g] = h(!e.userHasPrefs), [T, o] = h(!1), [v, w] = h(
182
+ y
183
+ ), [P, f] = h(
184
+ b
185
+ ), [z, x] = h(!1), C = H(() => Se(), []), A = H(
186
+ () => C.filter(
187
+ (a) => !D.some((Q) => Q.value === a)
188
+ ),
189
+ [C]
190
+ ), E = H(() => J(v), [v]), L = e.inherited ? J(e.inherited.tz) : "UTC", l = e.inherited ? xe(e.inherited.weekStart) : "Monday", t = ye(
191
+ (M = e.inherited) == null ? void 0 : M.source
192
+ );
193
+ ee.useEffect(() => {
194
+ if (!n) {
195
+ o(!1);
196
+ return;
197
+ }
198
+ T || (e.userHasPrefs !== void 0 && g(!e.userHasPrefs), w(y), f(b));
199
+ }, [
200
+ n,
201
+ T,
202
+ e.userHasPrefs,
203
+ y,
204
+ b
205
+ ]);
206
+ const i = async () => {
207
+ if (p) {
208
+ N.error("Preferences are still loading. Please try again.");
209
+ return;
210
+ }
211
+ m ? await k() ? (N.success(
212
+ "Now using default settings. Please refresh the page to apply changes.",
213
+ { duration: 5e3 }
214
+ ), c(!1)) : N.error("Failed to save preferences. Please try again.") : await I({
215
+ tz: v,
216
+ weekStart: P
217
+ }) ? (N.success(
218
+ "Preferences saved. Please refresh the page to apply changes.",
219
+ { duration: 5e3 }
220
+ ), c(!1)) : N.error("Failed to save preferences. Please try again.");
221
+ }, Y = () => {
222
+ c(!1);
223
+ }, U = d || u, q = U || p;
224
+ return /* @__PURE__ */ r(te, { open: n, onOpenChange: c, children: /* @__PURE__ */ s(se, { className: "rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control", children: [
225
+ /* @__PURE__ */ s(ne, { children: [
226
+ /* @__PURE__ */ r(le, { className: "text-[15px]", children: "Calendar preferences" }),
227
+ /* @__PURE__ */ r(oe, { className: "text-[13px] leading-5", children: "Set your timezone and week-start for date calculations and displays." })
228
+ ] }),
229
+ /* @__PURE__ */ s("div", { className: "space-y-4 py-1", children: [
230
+ /* @__PURE__ */ s(
231
+ W,
232
+ {
233
+ value: m ? "defaults" : "custom",
234
+ onValueChange: (a) => {
235
+ o(!0), g(a === "defaults");
236
+ },
237
+ className: "space-y-0.5",
238
+ children: [
239
+ /* @__PURE__ */ s(
240
+ "label",
241
+ {
242
+ htmlFor: "mode-defaults",
243
+ className: S(
244
+ "flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",
245
+ m && "bg-muted/50"
246
+ ),
247
+ onClick: () => {
248
+ o(!0), g(!0);
249
+ },
250
+ children: [
251
+ /* @__PURE__ */ r(
252
+ O,
253
+ {
254
+ value: "defaults",
255
+ id: "mode-defaults",
256
+ className: "mt-0.5"
257
+ }
258
+ ),
259
+ /* @__PURE__ */ s("div", { className: "flex-1 min-w-0", children: [
260
+ /* @__PURE__ */ s("p", { className: "text-[13px] font-medium text-foreground", children: [
261
+ "Use ",
262
+ t,
263
+ " defaults"
264
+ ] }),
265
+ /* @__PURE__ */ s("p", { className: "text-[12px] text-muted-foreground", children: [
266
+ L,
267
+ ", week starts ",
268
+ l
269
+ ] })
270
+ ] })
271
+ ]
272
+ }
273
+ ),
274
+ /* @__PURE__ */ s(
275
+ "label",
276
+ {
277
+ htmlFor: "mode-custom",
278
+ className: S(
279
+ "flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",
280
+ !m && "bg-muted/50"
281
+ ),
282
+ onClick: () => {
283
+ o(!0), g(!1);
284
+ },
285
+ children: [
286
+ /* @__PURE__ */ r(
287
+ O,
288
+ {
289
+ value: "custom",
290
+ id: "mode-custom",
291
+ className: "mt-0.5"
292
+ }
293
+ ),
294
+ /* @__PURE__ */ r("p", { className: "flex-1 text-[13px] font-medium text-foreground", children: "Use custom settings" })
295
+ ]
296
+ }
297
+ )
298
+ ]
299
+ }
300
+ ),
301
+ /* @__PURE__ */ s(
302
+ "div",
303
+ {
304
+ className: S(
305
+ "space-y-4 border-t border-border/60 pt-4 transition-opacity",
306
+ m && "pointer-events-none opacity-50"
307
+ ),
308
+ children: [
309
+ /* @__PURE__ */ s("div", { className: "space-y-1.5", children: [
310
+ /* @__PURE__ */ r(G, { className: Z, children: "Timezone" }),
311
+ /* @__PURE__ */ s(
312
+ he,
313
+ {
314
+ open: z,
315
+ onOpenChange: x,
316
+ modal: !0,
317
+ children: [
318
+ /* @__PURE__ */ r(pe, { asChild: !0, children: /* @__PURE__ */ s(
319
+ j,
320
+ {
321
+ variant: "outline",
322
+ size: "xs",
323
+ role: "combobox",
324
+ "aria-expanded": z,
325
+ className: "w-full justify-between text-[12px] font-normal",
326
+ disabled: m,
327
+ children: [
328
+ /* @__PURE__ */ r("span", { className: "truncate", children: E }),
329
+ /* @__PURE__ */ r(be, { className: "ml-2 h-3.5 w-3.5 shrink-0 opacity-50" })
330
+ ]
331
+ }
332
+ ) }),
333
+ /* @__PURE__ */ r(
334
+ ge,
335
+ {
336
+ className: "z-50 w-[--radix-popover-trigger-width] p-0",
337
+ align: "start",
338
+ children: /* @__PURE__ */ s(ie, { className: "overflow-visible", children: [
339
+ /* @__PURE__ */ r(ce, { placeholder: "Search timezones…" }),
340
+ /* @__PURE__ */ s(de, { children: [
341
+ /* @__PURE__ */ r(ue, { children: "No timezone found." }),
342
+ /* @__PURE__ */ r(_, { heading: "Common", children: D.map((a) => /* @__PURE__ */ s(
343
+ R,
344
+ {
345
+ value: `${a.value} ${a.label}`,
346
+ onSelect: () => {
347
+ o(!0), w(a.value), x(!1);
348
+ },
349
+ children: [
350
+ /* @__PURE__ */ r(
351
+ V,
352
+ {
353
+ className: S(
354
+ "h-3.5 w-3.5",
355
+ v === a.value ? "opacity-100" : "opacity-0"
356
+ )
357
+ }
358
+ ),
359
+ /* @__PURE__ */ r("span", { className: "flex-1", children: a.label }),
360
+ /* @__PURE__ */ r("span", { className: "text-[11px] text-muted-foreground", children: a.value })
361
+ ]
362
+ },
363
+ a.value
364
+ )) }),
365
+ /* @__PURE__ */ r(me, {}),
366
+ /* @__PURE__ */ r(_, { heading: "All timezones", children: A.map((a) => /* @__PURE__ */ s(
367
+ R,
368
+ {
369
+ value: a,
370
+ onSelect: () => {
371
+ o(!0), w(a), x(!1);
372
+ },
373
+ children: [
374
+ /* @__PURE__ */ r(
375
+ V,
376
+ {
377
+ className: S(
378
+ "h-3.5 w-3.5",
379
+ v === a ? "opacity-100" : "opacity-0"
380
+ )
381
+ }
382
+ ),
383
+ a
384
+ ]
385
+ },
386
+ a
387
+ )) })
388
+ ] })
389
+ ] })
390
+ }
391
+ )
392
+ ]
393
+ }
394
+ )
395
+ ] }),
396
+ /* @__PURE__ */ s("div", { className: "space-y-1.5", children: [
397
+ /* @__PURE__ */ r(G, { className: Z, children: "Week starts on" }),
398
+ /* @__PURE__ */ r(
399
+ W,
400
+ {
401
+ value: String(P),
402
+ onValueChange: (a) => {
403
+ o(!0), f(Number(a));
404
+ },
405
+ className: "flex gap-4",
406
+ disabled: m,
407
+ children: K.map((a) => /* @__PURE__ */ s(
408
+ "label",
409
+ {
410
+ htmlFor: `week-start-${a.value}`,
411
+ className: S(
412
+ "flex cursor-pointer items-center gap-2 text-[13px]",
413
+ m && "cursor-not-allowed"
414
+ ),
415
+ children: [
416
+ /* @__PURE__ */ r(
417
+ O,
418
+ {
419
+ value: String(a.value),
420
+ id: `week-start-${a.value}`,
421
+ disabled: m
422
+ }
423
+ ),
424
+ a.label
425
+ ]
426
+ },
427
+ a.value
428
+ ))
429
+ }
430
+ )
431
+ ] })
432
+ ]
433
+ }
434
+ )
435
+ ] }),
436
+ /* @__PURE__ */ s(fe, { children: [
437
+ /* @__PURE__ */ r(
438
+ j,
439
+ {
440
+ variant: "outline",
441
+ size: "xs",
442
+ onClick: Y,
443
+ disabled: U,
444
+ children: "Cancel"
445
+ }
446
+ ),
447
+ /* @__PURE__ */ r(j, { size: "xs", onClick: i, disabled: q, children: U ? /* @__PURE__ */ s(X, { children: [
448
+ /* @__PURE__ */ r(ve, { className: "h-3.5 w-3.5 animate-spin" }),
449
+ "Saving…"
450
+ ] }) : "Save" })
451
+ ] })
452
+ ] }) });
453
+ }
454
+ export {
455
+ ze as C
456
+ };
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),t=require("./index-B7C8qBWC.js"),i=require("./switch-DPaKnsb8.js"),G=require("./chevrons-up-down-DiWloubI.js");function W(n={}){var y,P,z,A;const{authToken:d,tokenProps:a}=t.useSemaphorContext(),x=n.enabled??!0,m=(d==null?void 0:d.accessToken)??null,f=(a==null?void 0:a.apiServiceUrl)??null,[L,C]=l.useState(!1),[j,b]=l.useState(!1),[h,g]=l.useState(!1),[N,c]=l.useState(null),[v,S]=l.useState(null),k=v||{tz:((P=(y=a==null?void 0:a.params)==null?void 0:y.calendarContext)==null?void 0:P.tz)||null,weekStart:((A=(z=a==null?void 0:a.params)==null?void 0:z.calendarContext)==null?void 0:A.weekStart)??null},p=l.useCallback(async()=>{if(!(!x||!m||!f)){C(!0),c(null);try{const o=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${m}`}});if(!o.ok){const u=await o.json().catch(()=>({}));throw new Error(u.error||"Failed to fetch preferences")}const r=await o.json();S({tz:r.tz,weekStart:r.weekStart,source:r.source,isInherited:r.isInherited,userHasPrefs:r.userHasPrefs,inherited:r.inherited})}catch(o){const r=o instanceof Error?o.message:"Unknown error";c(r)}finally{C(!1)}}},[m,f,x]);l.useEffect(()=>{x&&p()},[x,p]);const T=l.useCallback(async o=>{if(!m||!f)return c("Not authenticated"),!1;b(!0),c(null);try{const r=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${m}`},body:JSON.stringify(o)});if(!r.ok){const u=await r.json().catch(()=>({}));throw new Error(u.error||"Failed to update preferences")}return await p(),!0}catch(r){const u=r instanceof Error?r.message:"Unknown error";return c(u),!1}finally{b(!1)}},[m,f,p]),w=l.useCallback(async()=>{if(!m||!f)return c("Not authenticated"),!1;g(!0),c(null);try{const o=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${m}`}});if(!o.ok){const u=await o.json().catch(()=>({}));throw new Error(u.error||"Failed to clear preferences")}const r=await o.text();if(r)try{const u=JSON.parse(r);return S({tz:u.tz,weekStart:u.weekStart,source:u.source,isInherited:u.isInherited??!0,userHasPrefs:!1,inherited:u.inherited}),!0}catch{}return await p(),!0}catch(o){const r=o instanceof Error?o.message:"Unknown error";return c(r),!1}finally{g(!1)}},[m,f,p]);return{preferences:k,isLoading:L,isSaving:j,isClearing:h,error:N,updatePreferences:T,clearPreferences:w,refetch:p}}const E=[{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"}],M=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return E.map(n=>n.value)}function q(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function O(n){const d=E.find(a=>a.value===n);return d?d.label:n}function V(n){const d=M.find(a=>a.value===n);return d?d.label:String(n)}function Z({open:n,onOpenChange:d}){var D,U,F;const{preferences:a,isLoading:x,isSaving:m,isClearing:f,updatePreferences:L,clearPreferences:C}=W({enabled:n}),j=a.tz||((D=a.inherited)==null?void 0:D.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=a.weekStart??((U=a.inherited)==null?void 0:U.weekStart)??1,[h,g]=l.useState(!a.userHasPrefs),[N,c]=l.useState(!1),[v,S]=l.useState(j),[k,p]=l.useState(b),[T,w]=l.useState(!1),y=l.useMemo(()=>_(),[]),P=l.useMemo(()=>y.filter(s=>!E.some(R=>R.value===s)),[y]),z=l.useMemo(()=>O(v),[v]),A=a.inherited?O(a.inherited.tz):"UTC",o=a.inherited?V(a.inherited.weekStart):"Monday",r=q((F=a.inherited)==null?void 0:F.source);l.useEffect(()=>{if(!n){c(!1);return}N||(a.userHasPrefs!==void 0&&g(!a.userHasPrefs),S(j),p(b))},[n,N,a.userHasPrefs,j,b]);const u=async()=>{if(x){t.ue.error("Preferences are still loading. Please try again.");return}h?await C()?(t.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),d(!1)):t.ue.error("Failed to save preferences. Please try again."):await L({tz:v,weekStart:k})?(t.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),d(!1)):t.ue.error("Failed to save preferences. Please try again.")},$=()=>{d(!1)},I=m||f,B=I||x;return e.jsx(t.Dialog,{open:n,onOpenChange:d,children:e.jsxs(t.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(t.DialogDescription,{className:"text-[13px] leading-5",children:"Set your timezone and week-start for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(t.RadioGroup,{value:h?"defaults":"custom",onValueChange:s=>{c(!0),g(s==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:i.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",h&&"bg-muted/50"),onClick:()=>{c(!0),g(!0)},children:[e.jsx(t.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 ",r," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[A,", week starts ",o]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:i.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!h&&"bg-muted/50"),onClick:()=>{c(!0),g(!1)},children:[e.jsx(t.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:i.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",h&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i.Label,{className:H,children:"Timezone"}),e.jsxs(i.Popover,{open:T,onOpenChange:w,modal:!0,children:[e.jsx(i.PopoverTrigger,{asChild:!0,children:e.jsxs(i.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":T,className:"w-full justify-between text-[12px] font-normal",disabled:h,children:[e.jsx("span",{className:"truncate",children:z}),e.jsx(G.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(i.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(t.Command,{className:"overflow-visible",children:[e.jsx(t.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No timezone found."}),e.jsx(t.CommandGroup,{heading:"Common",children:E.map(s=>e.jsxs(t.CommandItem,{value:`${s.value} ${s.label}`,onSelect:()=>{c(!0),S(s.value),w(!1)},children:[e.jsx(i.Check,{className:i.cn("h-3.5 w-3.5",v===s.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:s.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:s.value})]},s.value))}),e.jsx(t.CommandSeparator,{}),e.jsx(t.CommandGroup,{heading:"All timezones",children:P.map(s=>e.jsxs(t.CommandItem,{value:s,onSelect:()=>{c(!0),S(s),w(!1)},children:[e.jsx(i.Check,{className:i.cn("h-3.5 w-3.5",v===s?"opacity-100":"opacity-0")}),s]},s))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i.Label,{className:H,children:"Week starts on"}),e.jsx(t.RadioGroup,{value:String(k),onValueChange:s=>{c(!0),p(Number(s))},className:"flex gap-4",disabled:h,children:M.map(s=>e.jsxs("label",{htmlFor:`week-start-${s.value}`,className:i.cn("flex cursor-pointer items-center gap-2 text-[13px]",h&&"cursor-not-allowed"),children:[e.jsx(t.RadioGroupItem,{value:String(s.value),id:`week-start-${s.value}`,disabled:h}),s.label]},s.value))})]})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(i.Button,{variant:"outline",size:"xs",onClick:$,disabled:I,children:"Cancel"}),e.jsx(i.Button,{size:"xs",onClick:u,disabled:B,children:I?e.jsxs(e.Fragment,{children:[e.jsx(i.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}exports.CalendarPreferencesDialog=Z;
@@ -1,4 +1,4 @@
1
- import { c as o } from "./switch-DEPWsRhf.js";
1
+ import { c as o } from "./switch-B6fh8nb-.js";
2
2
  /**
3
3
  * @license lucide-react v0.453.0 - ISC
4
4
  *