react-semaphor 0.1.260 → 0.1.262

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 (48) hide show
  1. package/dist/chunks/dashboard-controls-AFlpiHtC.js +42 -0
  2. package/dist/chunks/dashboard-controls-Cq2fQ7bv.js +1979 -0
  3. package/dist/chunks/dashboard-filter-controls-button-Cedz-YZx.js +11 -0
  4. package/dist/chunks/dashboard-filter-controls-button-udrHABi3.js +1066 -0
  5. package/dist/chunks/{dashboard-json-BUrApiYl.js → dashboard-json-BU6cvmRP.js} +1 -1
  6. package/dist/chunks/{dashboard-json-U7VmojaR.js → dashboard-json-RKwWONKm.js} +1 -1
  7. package/dist/chunks/dashboard-summary-settings-dialog-Bl-XplTR.js +1 -0
  8. package/dist/chunks/dashboard-summary-settings-dialog-DDxHxKjp.js +535 -0
  9. package/dist/chunks/{edit-dashboard-visual-N2r5ObJ_.js → edit-dashboard-visual-B1r0Ho9B.js} +5970 -5492
  10. package/dist/chunks/edit-dashboard-visual-BwDFI3hI.js +188 -0
  11. package/dist/chunks/{index-BNdZjo5d.js → index-BtbNfaQD.js} +50751 -47206
  12. package/dist/chunks/index-DZ93VE76.js +1114 -0
  13. package/dist/chunks/{normalize-dashboard-for-dirty-check-Bn27S0PN.js → normalize-dashboard-for-dirty-check-5KpZN8xr.js} +20 -19
  14. package/dist/chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js +1 -0
  15. package/dist/chunks/{resource-management-panel-C_ZqsVMH.js → resource-management-panel-Cz7MYBC7.js} +1 -1
  16. package/dist/chunks/{resource-management-panel-zF23gLOJ.js → resource-management-panel-DxG6-naG.js} +70 -70
  17. package/dist/chunks/use-create-flow-overlay-state-BcMrPzMc.js +1445 -0
  18. package/dist/chunks/use-create-flow-overlay-state-D13D1vB_.js +21 -0
  19. package/dist/chunks/{use-visual-utils-BBTQGDdB.js → use-visual-utils-DScc5-p_.js} +1 -1
  20. package/dist/chunks/{use-visual-utils-K1k39w2U.js → use-visual-utils-DmxEKpor.js} +1 -1
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +5 -4
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +102 -99
  25. package/dist/shared/index.cjs +1 -1
  26. package/dist/shared/index.js +1 -1
  27. package/dist/style.css +1 -1
  28. package/dist/surfboard/index.cjs +1 -1
  29. package/dist/surfboard/index.js +5 -4
  30. package/dist/types/dashboard.d.ts +105 -0
  31. package/dist/types/index.cjs +1 -1
  32. package/dist/types/index.js +4 -3
  33. package/dist/types/main.d.ts +175 -1
  34. package/dist/types/shared.d.ts +89 -0
  35. package/dist/types/surfboard.d.ts +105 -0
  36. package/dist/types/types.d.ts +113 -0
  37. package/package.json +1 -1
  38. package/dist/chunks/dashboard-controls-CIdYp98a.js +0 -47
  39. package/dist/chunks/dashboard-controls-DOqBYrkB.js +0 -1847
  40. package/dist/chunks/dashboard-summary-settings-dialog-CaxmCNyy.js +0 -1
  41. package/dist/chunks/dashboard-summary-settings-dialog-DlVBUQmC.js +0 -544
  42. package/dist/chunks/edit-dashboard-visual-uA-0wLnR.js +0 -193
  43. package/dist/chunks/editor-action-buttons-B6lABkRB.js +0 -412
  44. package/dist/chunks/editor-action-buttons-Dh7Xndgk.js +0 -21
  45. package/dist/chunks/index-DOeggx0V.js +0 -1109
  46. package/dist/chunks/normalize-dashboard-for-dirty-check-B7NQDI1H.js +0 -1
  47. package/dist/chunks/notification-bell-BxyeaeRc.js +0 -839
  48. package/dist/chunks/notification-bell-tJRds5JJ.js +0 -6
@@ -1,5 +1,5 @@
1
1
  import { jsxs as o, jsx as r } from "react/jsx-runtime";
2
- import { u as s, c as l, B as h, X as d, d as c } from "./index-BNdZjo5d.js";
2
+ import { u as s, c as l, B as h, X as d, d as c } from "./index-BtbNfaQD.js";
3
3
  import "react";
4
4
  import "react-dom";
5
5
  function N() {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-DOeggx0V.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-DZ93VE76.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-DZ93VE76.js");function W(r={}){var C,I,P,D;const{authToken:o,tokenProps:s}=a.useSemaphorContext(),S=r.enabled??!0,d=(o==null?void 0:o.accessToken)??null,f=(s==null?void 0:s.apiServiceUrl)??null,[y,g]=l.useState(!1),[v,p]=l.useState(!1),[m,n]=l.useState(!1),[j,c]=l.useState(null),[x,w]=l.useState(null),k=x||{tz:((I=(C=s==null?void 0:s.params)==null?void 0:C.calendarContext)==null?void 0:I.tz)||null,weekStart:((D=(P=s==null?void 0:s.params)==null?void 0:P.calendarContext)==null?void 0:D.weekStart)??null},b=l.useCallback(async()=>{if(!(!S||!d||!f)){g(!0),c(null);try{const u=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${d}`}});if(!u.ok){const h=await u.json().catch(()=>({}));throw new Error(h.error||"Failed to fetch preferences")}const i=await u.json();w({tz:i.tz,weekStart:i.weekStart,source:i.source,isInherited:i.isInherited,userHasPrefs:i.userHasPrefs,inherited:i.inherited})}catch(u){const i=u instanceof Error?u.message:"Unknown error";c(i)}finally{g(!1)}}},[d,f,S]);l.useEffect(()=>{S&&b()},[S,b]);const T=l.useCallback(async u=>{if(!d||!f)return c("Not authenticated"),!1;p(!0),c(null);try{const i=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify(u)});if(!i.ok){const h=await i.json().catch(()=>({}));throw new Error(h.error||"Failed to update preferences")}return await b(),!0}catch(i){const h=i instanceof Error?i.message:"Unknown error";return c(h),!1}finally{p(!1)}},[d,f,b]),N=l.useCallback(async()=>{if(!d||!f)return c("Not authenticated"),!1;n(!0),c(null);try{const u=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${d}`}});if(!u.ok){const h=await u.json().catch(()=>({}));throw new Error(h.error||"Failed to clear preferences")}const i=await u.text();if(i)try{const h=JSON.parse(i);return w({tz:h.tz,weekStart:h.weekStart,source:h.source,isInherited:h.isInherited??!0,userHasPrefs:!1,inherited:h.inherited}),!0}catch{}return await b(),!0}catch(u){const i=u instanceof Error?u.message:"Unknown error";return c(i),!1}finally{n(!1)}},[d,f,b]);return{preferences:k,isLoading:y,isSaving:v,isClearing:m,error:j,updatePreferences:T,clearPreferences:N,refetch:b}}const A=[{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"}],H=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}];function G(){try{const r=Intl;if(r.supportedValuesOf)return r.supportedValuesOf("timeZone")}catch{}return A.map(r=>r.value)}function V(r){switch(r){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function U(r){const o=A.find(s=>s.value===r);return o?o.label:r}function X(r){const o=H.find(s=>s.value===r);return o?o.label:String(r)}function q({open:r,onOpenChange:o}){var M,z,F;const{preferences:s,isLoading:S,isSaving:d,isClearing:f,updatePreferences:y,clearPreferences:g}=W({enabled:r}),v=s.tz||((M=s.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,p=s.weekStart??((z=s.inherited)==null?void 0:z.weekStart)??1,[m,n]=l.useState(!s.userHasPrefs),[j,c]=l.useState(!1),[x,w]=l.useState(v),[k,b]=l.useState(p),[T,N]=l.useState(!1),C=l.useMemo(()=>G(),[]),I=l.useMemo(()=>C.filter(t=>!A.some(R=>R.value===t)),[C]),P=l.useMemo(()=>U(x),[x]),D=s.inherited?U(s.inherited.tz):"UTC",u=s.inherited?X(s.inherited.weekStart):"Monday",i=V((F=s.inherited)==null?void 0:F.source);l.useEffect(()=>{if(!r){c(!1);return}j||(s.userHasPrefs!==void 0&&n(!s.userHasPrefs),w(v),b(p))},[r,j,s.userHasPrefs,v,p]);const h=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}m?await g()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),o(!1)):a.ue.error("Failed to save preferences. Please try again."):await y({tz:x,weekStart:k})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),o(!1)):a.ue.error("Failed to save preferences. Please try again.")},$=()=>{o(!1)},L=d||f,O=L||S;return e.jsx(a.Dialog,{open:r,onOpenChange:o,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Calendar Preferences"}),e.jsx(a.DialogDescription,{children:"Set your timezone and week start preferences for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{c(!0),n(t==="defaults")},className:"space-y-3",children:[e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"),onClick:()=>{c(!0),n(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs(a.Label,{htmlFor:"mode-defaults",className:"cursor-pointer font-medium",children:["Use ",i," defaults"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[D,", Week starts ",u]})]})]}),e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"),onClick:()=>{c(!0),n(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom"}),e.jsx(a.Label,{htmlFor:"mode-custom",className:"cursor-pointer font-medium",children:"Use custom settings"})]})]}),e.jsxs("div",{className:a.cn("space-y-6 transition-opacity",m&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:N,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",role:"combobox","aria-expanded":T,className:"w-full justify-between",disabled:m,children:[P,e.jsx(a.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:A.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{c(!0),w(t.value),N(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",x===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.value})]},t.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All Timezones",children:I.map(t=>e.jsxs(a.CommandItem,{value:t,onSelect:()=>{c(!0),w(t),N(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",x===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{children:"Week Starts On"}),e.jsx(a.RadioGroup,{value:String(k),onValueChange:t=>{c(!0),b(Number(t))},className:"flex gap-4",disabled:m,children:H.map(t=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),e.jsx(a.Label,{htmlFor:`week-start-${t.value}`,className:a.cn("cursor-pointer font-normal",m&&"cursor-not-allowed"),children:t.label})]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:$,disabled:L,children:"Cancel"}),e.jsx(a.Button,{onClick:h,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})})}const E=6,B=1,_=20;function Z(r){return Number.isNaN(r)?E:Math.min(_,Math.max(B,r))}function J({open:r,onOpenChange:o,dashboard:s,onApply:S,disabled:d=!1}){const[f,y]=l.useState(!1),[g,v]=l.useState("top"),[p,m]=l.useState(String(E)),n=s.summary;l.useEffect(()=>{r&&(y((n==null?void 0:n.enabled)===!0),v((n==null?void 0:n.position)==="bottom"?"bottom":"top"),m(String((n==null?void 0:n.maxItems)??E)))},[r,n==null?void 0:n.enabled,n==null?void 0:n.position,n==null?void 0:n.maxItems]);const j=l.useMemo(()=>Z(Number.parseInt(p||`${E}`,10)),[p]),c=()=>{S({enabled:f,position:g,maxItems:j}),o(!1)};return e.jsx(a.Dialog,{open:r,onOpenChange:o,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[420px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Summary Settings"}),e.jsx(a.DialogDescription,{children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",children:"Enable Dashboard Summary"}),e.jsx(a.SmallSwitch,{id:"dashboard-summary-enabled",checked:f,disabled:d,onCheckedChange:y})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",children:"Position"}),e.jsxs(a.Select,{value:g,disabled:d,onValueChange:x=>v(x),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",children:e.jsx(a.SelectValue,{placeholder:"Select position"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"top",children:"Top"}),e.jsx(a.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",children:"Max Items"}),e.jsx(a.Input,{id:"dashboard-summary-max-items",type:"number",min:B,max:_,disabled:d,value:p,onChange:x=>m(x.target.value),onBlur:()=>m(String(j))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),d&&e.jsx("p",{className:"text-xs text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>o(!1),children:"Cancel"}),e.jsx(a.Button,{onClick:c,disabled:d,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=q;exports.DashboardSummarySettingsDialog=J;
@@ -0,0 +1,535 @@
1
+ import { jsx as e, jsxs as a, Fragment as ce } from "react/jsx-runtime";
2
+ import de, { useState as f, useCallback as j, useEffect as K, useMemo as F } from "react";
3
+ import { b as ue, e as q, f as Y, g as Q, h as ee, i as ae, R, c as k, j as $, L as y, P as me, k as he, B as E, C as fe, l as pe, m as ve, n as be, o as Se, p as ge, q as V, r as G, s as X, t as ye, v as re, w as we, x as P, S as xe, y as Ne, z as Ce, A as ke, E as Te, F as Z, I as Ie } from "./index-BtbNfaQD.js";
4
+ function Pe(s = {}) {
5
+ var I, D, M, L;
6
+ const { authToken: i, tokenProps: r } = ue(), S = s.enabled ?? !0, o = (i == null ? void 0 : i.accessToken) ?? null, h = (r == null ? void 0 : r.apiServiceUrl) ?? null, [N, w] = f(!1), [g, v] = f(!1), [u, n] = f(!1), [x, c] = f(null), [p, C] = f(null), A = p || {
7
+ tz: ((D = (I = r == null ? void 0 : r.params) == null ? void 0 : I.calendarContext) == null ? void 0 : D.tz) || null,
8
+ weekStart: ((L = (M = r == null ? void 0 : r.params) == null ? void 0 : M.calendarContext) == null ? void 0 : L.weekStart) ?? null
9
+ }, b = j(async () => {
10
+ if (!(!S || !o || !h)) {
11
+ w(!0), c(null);
12
+ try {
13
+ const d = await fetch(`${h}/v1/user-preferences/calendar`, {
14
+ method: "GET",
15
+ headers: {
16
+ Authorization: `Bearer ${o}`
17
+ }
18
+ });
19
+ if (!d.ok) {
20
+ const m = await d.json().catch(() => ({}));
21
+ throw new Error(m.error || "Failed to fetch preferences");
22
+ }
23
+ const l = await d.json();
24
+ C({
25
+ tz: l.tz,
26
+ weekStart: l.weekStart,
27
+ source: l.source,
28
+ isInherited: l.isInherited,
29
+ userHasPrefs: l.userHasPrefs,
30
+ inherited: l.inherited
31
+ });
32
+ } catch (d) {
33
+ const l = d instanceof Error ? d.message : "Unknown error";
34
+ c(l);
35
+ } finally {
36
+ w(!1);
37
+ }
38
+ }
39
+ }, [o, h, S]);
40
+ K(() => {
41
+ S && b();
42
+ }, [S, b]);
43
+ const z = j(
44
+ async (d) => {
45
+ if (!o || !h)
46
+ return c("Not authenticated"), !1;
47
+ v(!0), c(null);
48
+ try {
49
+ const l = await fetch(`${h}/v1/user-preferences/calendar`, {
50
+ method: "PATCH",
51
+ headers: {
52
+ "Content-Type": "application/json",
53
+ Authorization: `Bearer ${o}`
54
+ },
55
+ body: JSON.stringify(d)
56
+ });
57
+ if (!l.ok) {
58
+ const m = await l.json().catch(() => ({}));
59
+ throw new Error(m.error || "Failed to update preferences");
60
+ }
61
+ return await b(), !0;
62
+ } catch (l) {
63
+ const m = l instanceof Error ? l.message : "Unknown error";
64
+ return c(m), !1;
65
+ } finally {
66
+ v(!1);
67
+ }
68
+ },
69
+ [o, h, b]
70
+ ), T = j(async () => {
71
+ if (!o || !h)
72
+ return c("Not authenticated"), !1;
73
+ n(!0), c(null);
74
+ try {
75
+ const d = await fetch(`${h}/v1/user-preferences/calendar`, {
76
+ method: "DELETE",
77
+ headers: {
78
+ Authorization: `Bearer ${o}`
79
+ }
80
+ });
81
+ if (!d.ok) {
82
+ const m = await d.json().catch(() => ({}));
83
+ throw new Error(m.error || "Failed to clear preferences");
84
+ }
85
+ const l = await d.text();
86
+ if (l)
87
+ try {
88
+ const m = JSON.parse(l);
89
+ return C({
90
+ tz: m.tz,
91
+ weekStart: m.weekStart,
92
+ source: m.source,
93
+ isInherited: m.isInherited ?? !0,
94
+ userHasPrefs: !1,
95
+ inherited: m.inherited
96
+ }), !0;
97
+ } catch {
98
+ }
99
+ return await b(), !0;
100
+ } catch (d) {
101
+ const l = d instanceof Error ? d.message : "Unknown error";
102
+ return c(l), !1;
103
+ } finally {
104
+ n(!1);
105
+ }
106
+ }, [o, h, b]);
107
+ return {
108
+ preferences: A,
109
+ isLoading: N,
110
+ isSaving: g,
111
+ isClearing: u,
112
+ error: x,
113
+ updatePreferences: z,
114
+ clearPreferences: T,
115
+ refetch: b
116
+ };
117
+ }
118
+ const _ = [
119
+ { value: "America/New_York", label: "Eastern Time (US & Canada)" },
120
+ { value: "America/Chicago", label: "Central Time (US & Canada)" },
121
+ { value: "America/Denver", label: "Mountain Time (US & Canada)" },
122
+ { value: "America/Los_Angeles", label: "Pacific Time (US & Canada)" },
123
+ { value: "America/Phoenix", label: "Arizona" },
124
+ { value: "America/Anchorage", label: "Alaska" },
125
+ { value: "Pacific/Honolulu", label: "Hawaii" },
126
+ { value: "Europe/London", label: "London" },
127
+ { value: "Europe/Paris", label: "Paris, Berlin, Rome" },
128
+ { value: "Asia/Tokyo", label: "Tokyo" },
129
+ { value: "Asia/Shanghai", label: "Beijing, Shanghai" },
130
+ { value: "Asia/Kolkata", label: "Mumbai, New Delhi" },
131
+ { value: "Australia/Sydney", label: "Sydney" },
132
+ { value: "UTC", label: "UTC" }
133
+ ], te = [
134
+ { value: 0, label: "Sunday" },
135
+ { value: 1, label: "Monday" },
136
+ { value: 6, label: "Saturday" }
137
+ ];
138
+ function Ee() {
139
+ try {
140
+ const s = Intl;
141
+ if (s.supportedValuesOf)
142
+ return s.supportedValuesOf("timeZone");
143
+ } catch {
144
+ }
145
+ return _.map((s) => s.value);
146
+ }
147
+ function Ae(s) {
148
+ switch (s) {
149
+ case "tenant":
150
+ return "tenant";
151
+ case "organization":
152
+ return "organization";
153
+ case "system":
154
+ return "system";
155
+ default:
156
+ return "default";
157
+ }
158
+ }
159
+ function J(s) {
160
+ const i = _.find((r) => r.value === s);
161
+ return i ? i.label : s;
162
+ }
163
+ function ze(s) {
164
+ const i = te.find((r) => r.value === s);
165
+ return i ? i.label : String(s);
166
+ }
167
+ function Ue({
168
+ open: s,
169
+ onOpenChange: i
170
+ }) {
171
+ var B, O, W;
172
+ const {
173
+ preferences: r,
174
+ isLoading: S,
175
+ isSaving: o,
176
+ isClearing: h,
177
+ updatePreferences: N,
178
+ clearPreferences: w
179
+ } = Pe({ enabled: s }), g = r.tz || ((B = r.inherited) == null ? void 0 : B.tz) || Intl.DateTimeFormat().resolvedOptions().timeZone, v = r.weekStart ?? ((O = r.inherited) == null ? void 0 : O.weekStart) ?? 1, [u, n] = f(!r.userHasPrefs), [x, c] = f(!1), [p, C] = f(
180
+ g
181
+ ), [A, b] = f(
182
+ v
183
+ ), [z, T] = f(!1), I = F(() => Ee(), []), D = F(
184
+ () => I.filter(
185
+ (t) => !_.some((oe) => oe.value === t)
186
+ ),
187
+ [I]
188
+ ), M = F(() => J(p), [p]), L = r.inherited ? J(r.inherited.tz) : "UTC", d = r.inherited ? ze(r.inherited.weekStart) : "Monday", l = Ae(
189
+ (W = r.inherited) == null ? void 0 : W.source
190
+ );
191
+ de.useEffect(() => {
192
+ if (!s) {
193
+ c(!1);
194
+ return;
195
+ }
196
+ x || (r.userHasPrefs !== void 0 && n(!r.userHasPrefs), C(g), b(v));
197
+ }, [
198
+ s,
199
+ x,
200
+ r.userHasPrefs,
201
+ g,
202
+ v
203
+ ]);
204
+ const m = async () => {
205
+ if (S) {
206
+ P.error("Preferences are still loading. Please try again.");
207
+ return;
208
+ }
209
+ u ? await w() ? (P.success(
210
+ "Now using default settings. Please refresh the page to apply changes.",
211
+ { duration: 5e3 }
212
+ ), i(!1)) : P.error("Failed to save preferences. Please try again.") : await N({
213
+ tz: p,
214
+ weekStart: A
215
+ }) ? (P.success(
216
+ "Preferences saved. Please refresh the page to apply changes.",
217
+ { duration: 5e3 }
218
+ ), i(!1)) : P.error("Failed to save preferences. Please try again.");
219
+ }, le = () => {
220
+ i(!1);
221
+ }, H = o || h, ie = H || S;
222
+ return /* @__PURE__ */ e(q, { open: s, onOpenChange: i, children: /* @__PURE__ */ a(Y, { className: "sm:max-w-[425px]", children: [
223
+ /* @__PURE__ */ a(Q, { children: [
224
+ /* @__PURE__ */ e(ee, { children: "Calendar Preferences" }),
225
+ /* @__PURE__ */ e(ae, { children: "Set your timezone and week start preferences for date calculations and displays." })
226
+ ] }),
227
+ /* @__PURE__ */ a("div", { className: "space-y-6 py-4", children: [
228
+ /* @__PURE__ */ a(
229
+ R,
230
+ {
231
+ value: u ? "defaults" : "custom",
232
+ onValueChange: (t) => {
233
+ c(!0), n(t === "defaults");
234
+ },
235
+ className: "space-y-3",
236
+ children: [
237
+ /* @__PURE__ */ a(
238
+ "div",
239
+ {
240
+ className: k(
241
+ "flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",
242
+ u ? "border-primary bg-primary/5" : "border-border hover:border-muted-foreground/50"
243
+ ),
244
+ onClick: () => {
245
+ c(!0), n(!0);
246
+ },
247
+ children: [
248
+ /* @__PURE__ */ e($, { value: "defaults", id: "mode-defaults" }),
249
+ /* @__PURE__ */ a("div", { className: "flex-1 space-y-1", children: [
250
+ /* @__PURE__ */ a(
251
+ y,
252
+ {
253
+ htmlFor: "mode-defaults",
254
+ className: "cursor-pointer font-medium",
255
+ children: [
256
+ "Use ",
257
+ l,
258
+ " defaults"
259
+ ]
260
+ }
261
+ ),
262
+ /* @__PURE__ */ a("p", { className: "text-sm text-muted-foreground", children: [
263
+ L,
264
+ ", Week starts ",
265
+ d
266
+ ] })
267
+ ] })
268
+ ]
269
+ }
270
+ ),
271
+ /* @__PURE__ */ a(
272
+ "div",
273
+ {
274
+ className: k(
275
+ "flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",
276
+ u ? "border-border hover:border-muted-foreground/50" : "border-primary bg-primary/5"
277
+ ),
278
+ onClick: () => {
279
+ c(!0), n(!1);
280
+ },
281
+ children: [
282
+ /* @__PURE__ */ e($, { value: "custom", id: "mode-custom" }),
283
+ /* @__PURE__ */ e(
284
+ y,
285
+ {
286
+ htmlFor: "mode-custom",
287
+ className: "cursor-pointer font-medium",
288
+ children: "Use custom settings"
289
+ }
290
+ )
291
+ ]
292
+ }
293
+ )
294
+ ]
295
+ }
296
+ ),
297
+ /* @__PURE__ */ a(
298
+ "div",
299
+ {
300
+ className: k(
301
+ "space-y-6 transition-opacity",
302
+ u && "opacity-50 pointer-events-none"
303
+ ),
304
+ children: [
305
+ /* @__PURE__ */ a("div", { className: "space-y-2", children: [
306
+ /* @__PURE__ */ e(y, { children: "Timezone" }),
307
+ /* @__PURE__ */ a(
308
+ me,
309
+ {
310
+ open: z,
311
+ onOpenChange: T,
312
+ modal: !0,
313
+ children: [
314
+ /* @__PURE__ */ e(he, { asChild: !0, children: /* @__PURE__ */ a(
315
+ E,
316
+ {
317
+ variant: "outline",
318
+ role: "combobox",
319
+ "aria-expanded": z,
320
+ className: "w-full justify-between",
321
+ disabled: u,
322
+ children: [
323
+ M,
324
+ /* @__PURE__ */ e(fe, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" })
325
+ ]
326
+ }
327
+ ) }),
328
+ /* @__PURE__ */ e(
329
+ pe,
330
+ {
331
+ className: "z-50 w-[--radix-popover-trigger-width] p-0",
332
+ align: "start",
333
+ children: /* @__PURE__ */ a(ve, { className: "overflow-visible", children: [
334
+ /* @__PURE__ */ e(be, { placeholder: "Search timezones..." }),
335
+ /* @__PURE__ */ a(Se, { children: [
336
+ /* @__PURE__ */ e(ge, { children: "No timezone found." }),
337
+ /* @__PURE__ */ e(V, { heading: "Common", children: _.map((t) => /* @__PURE__ */ a(
338
+ G,
339
+ {
340
+ value: `${t.value} ${t.label}`,
341
+ onSelect: () => {
342
+ c(!0), C(t.value), T(!1);
343
+ },
344
+ children: [
345
+ /* @__PURE__ */ e(
346
+ X,
347
+ {
348
+ className: k(
349
+ "mr-2 h-4 w-4",
350
+ p === t.value ? "opacity-100" : "opacity-0"
351
+ )
352
+ }
353
+ ),
354
+ /* @__PURE__ */ e("span", { className: "flex-1", children: t.label }),
355
+ /* @__PURE__ */ e("span", { className: "text-xs text-muted-foreground", children: t.value })
356
+ ]
357
+ },
358
+ t.value
359
+ )) }),
360
+ /* @__PURE__ */ e(ye, {}),
361
+ /* @__PURE__ */ e(V, { heading: "All Timezones", children: D.map((t) => /* @__PURE__ */ a(
362
+ G,
363
+ {
364
+ value: t,
365
+ onSelect: () => {
366
+ c(!0), C(t), T(!1);
367
+ },
368
+ children: [
369
+ /* @__PURE__ */ e(
370
+ X,
371
+ {
372
+ className: k(
373
+ "mr-2 h-4 w-4",
374
+ p === t ? "opacity-100" : "opacity-0"
375
+ )
376
+ }
377
+ ),
378
+ t
379
+ ]
380
+ },
381
+ t
382
+ )) })
383
+ ] })
384
+ ] })
385
+ }
386
+ )
387
+ ]
388
+ }
389
+ )
390
+ ] }),
391
+ /* @__PURE__ */ a("div", { className: "space-y-3", children: [
392
+ /* @__PURE__ */ e(y, { children: "Week Starts On" }),
393
+ /* @__PURE__ */ e(
394
+ R,
395
+ {
396
+ value: String(A),
397
+ onValueChange: (t) => {
398
+ c(!0), b(Number(t));
399
+ },
400
+ className: "flex gap-4",
401
+ disabled: u,
402
+ children: te.map((t) => /* @__PURE__ */ a(
403
+ "div",
404
+ {
405
+ className: "flex items-center space-x-2",
406
+ children: [
407
+ /* @__PURE__ */ e(
408
+ $,
409
+ {
410
+ value: String(t.value),
411
+ id: `week-start-${t.value}`,
412
+ disabled: u
413
+ }
414
+ ),
415
+ /* @__PURE__ */ e(
416
+ y,
417
+ {
418
+ htmlFor: `week-start-${t.value}`,
419
+ className: k(
420
+ "cursor-pointer font-normal",
421
+ u && "cursor-not-allowed"
422
+ ),
423
+ children: t.label
424
+ }
425
+ )
426
+ ]
427
+ },
428
+ t.value
429
+ ))
430
+ }
431
+ )
432
+ ] })
433
+ ]
434
+ }
435
+ )
436
+ ] }),
437
+ /* @__PURE__ */ a(re, { children: [
438
+ /* @__PURE__ */ e(E, { variant: "outline", onClick: le, disabled: H, children: "Cancel" }),
439
+ /* @__PURE__ */ e(E, { onClick: m, disabled: ie, children: H ? /* @__PURE__ */ a(ce, { children: [
440
+ /* @__PURE__ */ e(we, { className: "mr-2 h-4 w-4 animate-spin" }),
441
+ "Saving..."
442
+ ] }) : "Save" })
443
+ ] })
444
+ ] }) });
445
+ }
446
+ const U = 6, se = 1, ne = 20;
447
+ function De(s) {
448
+ return Number.isNaN(s) ? U : Math.min(ne, Math.max(se, s));
449
+ }
450
+ function _e({
451
+ open: s,
452
+ onOpenChange: i,
453
+ dashboard: r,
454
+ onApply: S,
455
+ disabled: o = !1
456
+ }) {
457
+ const [h, N] = f(!1), [w, g] = f("top"), [v, u] = f(String(U)), n = r.summary;
458
+ K(() => {
459
+ s && (N((n == null ? void 0 : n.enabled) === !0), g((n == null ? void 0 : n.position) === "bottom" ? "bottom" : "top"), u(String((n == null ? void 0 : n.maxItems) ?? U)));
460
+ }, [s, n == null ? void 0 : n.enabled, n == null ? void 0 : n.position, n == null ? void 0 : n.maxItems]);
461
+ const x = F(
462
+ () => De(Number.parseInt(v || `${U}`, 10)),
463
+ [v]
464
+ );
465
+ return /* @__PURE__ */ e(q, { open: s, onOpenChange: i, children: /* @__PURE__ */ a(Y, { className: "sm:max-w-[420px]", children: [
466
+ /* @__PURE__ */ a(Q, { children: [
467
+ /* @__PURE__ */ e(ee, { children: "Summary Settings" }),
468
+ /* @__PURE__ */ e(ae, { children: "Configure dashboard-level summary display. Card-level summary settings still control which cards contribute." })
469
+ ] }),
470
+ /* @__PURE__ */ a("div", { className: "space-y-4 py-2", children: [
471
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
472
+ /* @__PURE__ */ e(y, { htmlFor: "dashboard-summary-enabled", children: "Enable Dashboard Summary" }),
473
+ /* @__PURE__ */ e(
474
+ xe,
475
+ {
476
+ id: "dashboard-summary-enabled",
477
+ checked: h,
478
+ disabled: o,
479
+ onCheckedChange: N
480
+ }
481
+ )
482
+ ] }),
483
+ /* @__PURE__ */ a("div", { className: "space-y-2", children: [
484
+ /* @__PURE__ */ e(y, { htmlFor: "dashboard-summary-position", children: "Position" }),
485
+ /* @__PURE__ */ a(
486
+ Ne,
487
+ {
488
+ value: w,
489
+ disabled: o,
490
+ onValueChange: (p) => g(p),
491
+ children: [
492
+ /* @__PURE__ */ e(Ce, { id: "dashboard-summary-position", children: /* @__PURE__ */ e(ke, { placeholder: "Select position" }) }),
493
+ /* @__PURE__ */ a(Te, { children: [
494
+ /* @__PURE__ */ e(Z, { value: "top", children: "Top" }),
495
+ /* @__PURE__ */ e(Z, { value: "bottom", children: "Bottom" })
496
+ ] })
497
+ ]
498
+ }
499
+ )
500
+ ] }),
501
+ /* @__PURE__ */ a("div", { className: "space-y-2", children: [
502
+ /* @__PURE__ */ e(y, { htmlFor: "dashboard-summary-max-items", children: "Max Items" }),
503
+ /* @__PURE__ */ e(
504
+ Ie,
505
+ {
506
+ id: "dashboard-summary-max-items",
507
+ type: "number",
508
+ min: se,
509
+ max: ne,
510
+ disabled: o,
511
+ value: v,
512
+ onChange: (p) => u(p.target.value),
513
+ onBlur: () => u(String(x))
514
+ }
515
+ ),
516
+ /* @__PURE__ */ e("p", { className: "text-xs text-muted-foreground", children: "Display limit only. Computation is unchanged." })
517
+ ] }),
518
+ o && /* @__PURE__ */ e("p", { className: "text-xs text-amber-700", children: "Enter dashboard edit mode to modify summary settings." })
519
+ ] }),
520
+ /* @__PURE__ */ a(re, { children: [
521
+ /* @__PURE__ */ e(E, { variant: "outline", onClick: () => i(!1), children: "Cancel" }),
522
+ /* @__PURE__ */ e(E, { onClick: () => {
523
+ S({
524
+ enabled: h,
525
+ position: w,
526
+ maxItems: x
527
+ }), i(!1);
528
+ }, disabled: o, children: "Apply" })
529
+ ] })
530
+ ] }) });
531
+ }
532
+ export {
533
+ Ue as C,
534
+ _e as D
535
+ };