react-semaphor 0.1.292 → 0.1.294

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 (44) hide show
  1. package/dist/chunks/{braces-hczcJsV8.js → braces-DR-GdaLC.js} +1 -1
  2. package/dist/chunks/{braces-0bzwctGp.js → braces-DfDQiR3J.js} +1 -1
  3. package/dist/chunks/dashboard-controls-C3Z9bpYE.js +2014 -0
  4. package/dist/chunks/dashboard-controls-DGEVXgP5.js +47 -0
  5. package/dist/chunks/dashboard-filter-controls-button-BIYT1ucX.js +11 -0
  6. package/dist/chunks/dashboard-filter-controls-button-DxgGUl00.js +1152 -0
  7. package/dist/chunks/{dashboard-json-COXiPm3N.js → dashboard-json-BvTeHePu.js} +1 -1
  8. package/dist/chunks/{dashboard-json-BDyKcoGT.js → dashboard-json-DQW8TN0I.js} +1 -1
  9. package/dist/chunks/dashboard-summary-settings-dialog-BsmKiGud.js +1 -0
  10. package/dist/chunks/dashboard-summary-settings-dialog-q7fx3YAK.js +543 -0
  11. package/dist/chunks/edit-dashboard-visual-ChKj-Lzr.js +183 -0
  12. package/dist/chunks/{edit-dashboard-visual-DLyimx6x.js → edit-dashboard-visual-RVl9nbDZ.js} +3018 -2989
  13. package/dist/chunks/index-BlspGR07.js +1435 -0
  14. package/dist/chunks/{index-72yod5pb.js → index-DerPpfv0.js} +40703 -39330
  15. package/dist/chunks/{resource-management-panel-DwPION_M.js → resource-management-panel-DnZ1rw1A.js} +64 -64
  16. package/dist/chunks/{resource-management-panel-CSLGSJjC.js → resource-management-panel-epydPwyM.js} +1 -1
  17. package/dist/chunks/use-create-flow-overlay-state-Bcg4EgoD.js +21 -0
  18. package/dist/chunks/{use-create-flow-overlay-state-UruHbtfS.js → use-create-flow-overlay-state-C5vdfXhM.js} +430 -425
  19. package/dist/chunks/use-visual-utils-D9Kknvjl.js +337 -0
  20. package/dist/chunks/use-visual-utils-Dw_yw9zU.js +1 -0
  21. package/dist/dashboard/index.cjs +1 -1
  22. package/dist/dashboard/index.js +1 -1
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +258 -253
  25. package/dist/style.css +1 -1
  26. package/dist/surfboard/index.cjs +1 -1
  27. package/dist/surfboard/index.js +2 -2
  28. package/dist/types/dashboard.d.ts +28 -0
  29. package/dist/types/main.d.ts +45 -5
  30. package/dist/types/shared.d.ts +3 -0
  31. package/dist/types/surfboard.d.ts +28 -0
  32. package/dist/types/types.d.ts +28 -0
  33. package/package.json +1 -1
  34. package/dist/chunks/dashboard-controls-Db0F38eK.js +0 -47
  35. package/dist/chunks/dashboard-controls-DeUHM4uL.js +0 -1970
  36. package/dist/chunks/dashboard-filter-controls-button-DDqEus_E.js +0 -1109
  37. package/dist/chunks/dashboard-filter-controls-button-DSQHVjjX.js +0 -11
  38. package/dist/chunks/dashboard-summary-settings-dialog-CryMC_4x.js +0 -1
  39. package/dist/chunks/dashboard-summary-settings-dialog-DbcWMZsr.js +0 -536
  40. package/dist/chunks/edit-dashboard-visual-BqfzqW4i.js +0 -183
  41. package/dist/chunks/index-BQ6qu8FI.js +0 -1435
  42. package/dist/chunks/use-create-flow-overlay-state-zz9TYhdC.js +0 -21
  43. package/dist/chunks/use-visual-utils-Bm-ZnkON.js +0 -1
  44. package/dist/chunks/use-visual-utils-DPBqTRUC.js +0 -334
@@ -1,6 +1,6 @@
1
1
  import { jsxs as i, jsx as t } from "react/jsx-runtime";
2
2
  import { useMemo as b, useState as f, useRef as m, useEffect as S } from "react";
3
- import { u as e, b as N, B as D, X as p, C as J } from "./index-72yod5pb.js";
3
+ import { u as e, b as N, B as D, X as p, C as J } from "./index-DerPpfv0.js";
4
4
  import "react-dom";
5
5
  function x() {
6
6
  const o = e((s) => s.dashboard), c = e((s) => s.actions.setDashboard), h = e(
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),r=require("react"),s=require("./index-BQ6qu8FI.js");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),i=s.useDashboardStore(e=>e.actions.setDashboard),h=s.useDashboardStore(e=>e.showDashboardJSON),u=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),a=r.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,d]=r.useState(a),n=r.useRef(a);return r.useEffect(()=>{a!==n.current&&(d(a),n.current=a)},[a]),o.jsxs("div",{className:s.cn("relative p-2",{hidden:!h}),children:[o.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>u(!1),children:[o.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),o.jsx("div",{className:"h-[550px] overflow-hidden",children:o.jsx(s.CodeEditor,{value:l,onValueChange:e=>{d(e);try{const c=JSON.parse(e);n.current=JSON.stringify(c,null,2),i(c)}catch{}},language:"json"})})]})}exports.default=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),r=require("react"),s=require("./index-BlspGR07.js");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),i=s.useDashboardStore(e=>e.actions.setDashboard),h=s.useDashboardStore(e=>e.showDashboardJSON),u=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),a=r.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,d]=r.useState(a),n=r.useRef(a);return r.useEffect(()=>{a!==n.current&&(d(a),n.current=a)},[a]),o.jsxs("div",{className:s.cn("relative p-2",{hidden:!h}),children:[o.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>u(!1),children:[o.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),o.jsx("div",{className:"h-[550px] overflow-hidden",children:o.jsx(s.CodeEditor,{value:l,onValueChange:e=>{d(e);try{const c=JSON.parse(e);n.current=JSON.stringify(c,null,2),i(c)}catch{}},language:"json"})})]})}exports.default=b;
@@ -0,0 +1 @@
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-BlspGR07.js");function V(r={}){var C,I,P,A;const{authToken:o,tokenProps:s}=a.useSemaphorContext(),g=r.enabled??!0,d=(o==null?void 0:o.accessToken)??null,x=(s==null?void 0:s.apiServiceUrl)??null,[y,v]=l.useState(!1),[S,p]=l.useState(!1),[m,n]=l.useState(!1),[j,c]=l.useState(null),[f,N]=l.useState(null),k=f||{tz:((I=(C=s==null?void 0:s.params)==null?void 0:C.calendarContext)==null?void 0:I.tz)||null,weekStart:((A=(P=s==null?void 0:s.params)==null?void 0:P.calendarContext)==null?void 0:A.weekStart)??null},b=l.useCallback(async()=>{if(!(!g||!d||!x)){v(!0),c(null);try{const u=await fetch(`${x}/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();N({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{v(!1)}}},[d,x,g]);l.useEffect(()=>{g&&b()},[g,b]);const T=l.useCallback(async u=>{if(!d||!x)return c("Not authenticated"),!1;p(!0),c(null);try{const i=await fetch(`${x}/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,x,b]),w=l.useCallback(async()=>{if(!d||!x)return c("Not authenticated"),!1;n(!0),c(null);try{const u=await fetch(`${x}/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 N({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,x,b]);return{preferences:k,isLoading:y,isSaving:S,isClearing:m,error:j,updatePreferences:T,clearPreferences:w,refetch:b}}const z=[{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"}],_=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],U="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function X(){try{const r=Intl;if(r.supportedValuesOf)return r.supportedValuesOf("timeZone")}catch{}return z.map(r=>r.value)}function q(r){switch(r){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function B(r){const o=z.find(s=>s.value===r);return o?o.label:r}function Z(r){const o=_.find(s=>s.value===r);return o?o.label:String(r)}function J({open:r,onOpenChange:o}){var L,M,F;const{preferences:s,isLoading:g,isSaving:d,isClearing:x,updatePreferences:y,clearPreferences:v}=V({enabled:r}),S=s.tz||((L=s.inherited)==null?void 0:L.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,p=s.weekStart??((M=s.inherited)==null?void 0:M.weekStart)??1,[m,n]=l.useState(!s.userHasPrefs),[j,c]=l.useState(!1),[f,N]=l.useState(S),[k,b]=l.useState(p),[T,w]=l.useState(!1),C=l.useMemo(()=>X(),[]),I=l.useMemo(()=>C.filter(t=>!z.some(W=>W.value===t)),[C]),P=l.useMemo(()=>B(f),[f]),A=s.inherited?B(s.inherited.tz):"UTC",u=s.inherited?Z(s.inherited.weekStart):"Monday",i=q((F=s.inherited)==null?void 0:F.source);l.useEffect(()=>{if(!r){c(!1);return}j||(s.userHasPrefs!==void 0&&n(!s.userHasPrefs),N(S),b(p))},[r,j,s.userHasPrefs,S,p]);const h=async()=>{if(g){a.ue.error("Preferences are still loading. Please try again.");return}m?await v()?(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:f,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.")},R=()=>{o(!1)},D=d||x,G=D||g;return e.jsx(a.Dialog,{open:r,onOpenChange:o,children:e.jsxs(a.DialogContent,{className:"rounded-[6px] border-border/60 sm:max-w-[440px] sm:rounded-[6px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(a.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(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{c(!0),n(t==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:a.cn("flex cursor-pointer items-start gap-2 rounded-[5px] px-2 py-1.5 hover:bg-muted/50",m&&"bg-muted/50"),onClick:()=>{c(!0),n(!0)},children:[e.jsx(a.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 ",i," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[A,", week starts ",u]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:a.cn("flex cursor-pointer items-start gap-2 rounded-[5px] px-2 py-1.5 hover:bg-muted/50",!m&&"bg-muted/50"),onClick:()=>{c(!0),n(!1)},children:[e.jsx(a.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:a.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",m&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(a.Label,{className:U,children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:w,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":T,className:"w-full justify-between text-[12px] font-normal",disabled:m,children:[e.jsx("span",{className:"truncate",children:P}),e.jsx(a.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 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:z.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{c(!0),N(t.value),w(!1)},children:[e.jsx(a.Check,{className:a.cn("h-3.5 w-3.5",f===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-[11px] 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),N(t),w(!1)},children:[e.jsx(a.Check,{className:a.cn("h-3.5 w-3.5",f===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(a.Label,{className:U,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:_.map(t=>e.jsxs("label",{htmlFor:`week-start-${t.value}`,className:a.cn("flex cursor-pointer items-center gap-2 text-[13px]",m&&"cursor-not-allowed"),children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),t.label]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",size:"xs",onClick:R,disabled:D,children:"Cancel"}),e.jsx(a.Button,{size:"xs",onClick:h,disabled:G,children:D?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}const E=6,$=1,O=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function K(r){return Number.isNaN(r)?E:Math.min(O,Math.max($,r))}function Y({open:r,onOpenChange:o,dashboard:s,onApply:g,disabled:d=!1}){const[x,y]=l.useState(!1),[v,S]=l.useState("top"),[p,m]=l.useState(String(E)),n=s.summary;l.useEffect(()=>{r&&(y((n==null?void 0:n.enabled)===!0),S((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(()=>K(Number.parseInt(p||`${E}`,10)),[p]),c=()=>{g({enabled:x,position:v,maxItems:j}),o(!1)};return e.jsx(a.Dialog,{open:r,onOpenChange:o,children:e.jsxs(a.DialogContent,{className:"rounded-[6px] border-border/60 sm:max-w-[420px] sm:rounded-[6px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Summary Settings"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",className:"text-[13px]",children:"Enable dashboard summary"}),e.jsx(a.Switch,{size:"xs",id:"dashboard-summary-enabled",checked:x,disabled:d,onCheckedChange:y})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",className:H,children:"Position"}),e.jsxs(a.Select,{value:v,disabled:d,onValueChange:f=>S(f),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",size:"xs",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-1.5",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",className:H,children:"Max items"}),e.jsx(a.Input,{size:"xs",id:"dashboard-summary-max-items",type:"number",min:$,max:O,disabled:d,value:p,onChange:f=>m(f.target.value),onBlur:()=>m(String(j))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),d&&e.jsx("p",{className:"text-[12px] text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",size:"xs",onClick:()=>o(!1),children:"Cancel"}),e.jsx(a.Button,{size:"xs",onClick:c,disabled:d,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=J;exports.DashboardSummarySettingsDialog=Y;
@@ -0,0 +1,543 @@
1
+ import { jsx as e, jsxs as a, Fragment as ue } from "react/jsx-runtime";
2
+ import me, { useState as f, useCallback as $, useEffect as Y, useMemo as F } from "react";
3
+ import { d as he, e as Q, f as ee, g as ae, h as te, i as se, R, b as k, j, L as P, P as fe, k as pe, B as A, l as xe, m as be, n as ve, o as ge, p as Se, q as ye, r as V, s as G, t as X, v as Ne, w as re, x as we, y as I, S as ke, z as Ce, A as Te, E as Ie, F as Pe, G as Z, I as Ae } from "./index-DerPpfv0.js";
4
+ function ze(r = {}) {
5
+ var T, L, D, M;
6
+ const { authToken: i, tokenProps: t } = he(), v = r.enabled ?? !0, o = (i == null ? void 0 : i.accessToken) ?? null, h = (t == null ? void 0 : t.apiServiceUrl) ?? null, [N, S] = f(!1), [g, x] = f(!1), [u, n] = f(!1), [y, c] = f(null), [p, w] = f(null), z = p || {
7
+ tz: ((L = (T = t == null ? void 0 : t.params) == null ? void 0 : T.calendarContext) == null ? void 0 : L.tz) || null,
8
+ weekStart: ((M = (D = t == null ? void 0 : t.params) == null ? void 0 : D.calendarContext) == null ? void 0 : M.weekStart) ?? null
9
+ }, b = $(async () => {
10
+ if (!(!v || !o || !h)) {
11
+ S(!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
+ w({
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
+ S(!1);
37
+ }
38
+ }
39
+ }, [o, h, v]);
40
+ Y(() => {
41
+ v && b();
42
+ }, [v, b]);
43
+ const E = $(
44
+ async (d) => {
45
+ if (!o || !h)
46
+ return c("Not authenticated"), !1;
47
+ x(!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
+ x(!1);
67
+ }
68
+ },
69
+ [o, h, b]
70
+ ), C = $(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 w({
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: z,
109
+ isLoading: N,
110
+ isSaving: g,
111
+ isClearing: u,
112
+ error: y,
113
+ updatePreferences: E,
114
+ clearPreferences: C,
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
+ ], ne = [
134
+ { value: 0, label: "Sunday" },
135
+ { value: 1, label: "Monday" },
136
+ { value: 6, label: "Saturday" }
137
+ ], J = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
138
+ function Ee() {
139
+ try {
140
+ const r = Intl;
141
+ if (r.supportedValuesOf)
142
+ return r.supportedValuesOf("timeZone");
143
+ } catch {
144
+ }
145
+ return _.map((r) => r.value);
146
+ }
147
+ function Le(r) {
148
+ switch (r) {
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 K(r) {
160
+ const i = _.find((t) => t.value === r);
161
+ return i ? i.label : r;
162
+ }
163
+ function De(r) {
164
+ const i = ne.find((t) => t.value === r);
165
+ return i ? i.label : String(r);
166
+ }
167
+ function He({
168
+ open: r,
169
+ onOpenChange: i
170
+ }) {
171
+ var B, O, W;
172
+ const {
173
+ preferences: t,
174
+ isLoading: v,
175
+ isSaving: o,
176
+ isClearing: h,
177
+ updatePreferences: N,
178
+ clearPreferences: S
179
+ } = ze({ enabled: r }), g = t.tz || ((B = t.inherited) == null ? void 0 : B.tz) || Intl.DateTimeFormat().resolvedOptions().timeZone, x = t.weekStart ?? ((O = t.inherited) == null ? void 0 : O.weekStart) ?? 1, [u, n] = f(!t.userHasPrefs), [y, c] = f(!1), [p, w] = f(
180
+ g
181
+ ), [z, b] = f(
182
+ x
183
+ ), [E, C] = f(!1), T = F(() => Ee(), []), L = F(
184
+ () => T.filter(
185
+ (s) => !_.some((de) => de.value === s)
186
+ ),
187
+ [T]
188
+ ), D = F(() => K(p), [p]), M = t.inherited ? K(t.inherited.tz) : "UTC", d = t.inherited ? De(t.inherited.weekStart) : "Monday", l = Le(
189
+ (W = t.inherited) == null ? void 0 : W.source
190
+ );
191
+ me.useEffect(() => {
192
+ if (!r) {
193
+ c(!1);
194
+ return;
195
+ }
196
+ y || (t.userHasPrefs !== void 0 && n(!t.userHasPrefs), w(g), b(x));
197
+ }, [
198
+ r,
199
+ y,
200
+ t.userHasPrefs,
201
+ g,
202
+ x
203
+ ]);
204
+ const m = async () => {
205
+ if (v) {
206
+ I.error("Preferences are still loading. Please try again.");
207
+ return;
208
+ }
209
+ u ? await S() ? (I.success(
210
+ "Now using default settings. Please refresh the page to apply changes.",
211
+ { duration: 5e3 }
212
+ ), i(!1)) : I.error("Failed to save preferences. Please try again.") : await N({
213
+ tz: p,
214
+ weekStart: z
215
+ }) ? (I.success(
216
+ "Preferences saved. Please refresh the page to apply changes.",
217
+ { duration: 5e3 }
218
+ ), i(!1)) : I.error("Failed to save preferences. Please try again.");
219
+ }, oe = () => {
220
+ i(!1);
221
+ }, H = o || h, ce = H || v;
222
+ return /* @__PURE__ */ e(Q, { open: r, onOpenChange: i, children: /* @__PURE__ */ a(ee, { className: "rounded-[6px] border-border/60 sm:max-w-[440px] sm:rounded-[6px]", children: [
223
+ /* @__PURE__ */ a(ae, { children: [
224
+ /* @__PURE__ */ e(te, { className: "text-[15px]", children: "Calendar preferences" }),
225
+ /* @__PURE__ */ e(se, { className: "text-[13px] leading-5", children: "Set your timezone and week-start for date calculations and displays." })
226
+ ] }),
227
+ /* @__PURE__ */ a("div", { className: "space-y-4 py-1", children: [
228
+ /* @__PURE__ */ a(
229
+ R,
230
+ {
231
+ value: u ? "defaults" : "custom",
232
+ onValueChange: (s) => {
233
+ c(!0), n(s === "defaults");
234
+ },
235
+ className: "space-y-0.5",
236
+ children: [
237
+ /* @__PURE__ */ a(
238
+ "label",
239
+ {
240
+ htmlFor: "mode-defaults",
241
+ className: k(
242
+ "flex cursor-pointer items-start gap-2 rounded-[5px] px-2 py-1.5 hover:bg-muted/50",
243
+ u && "bg-muted/50"
244
+ ),
245
+ onClick: () => {
246
+ c(!0), n(!0);
247
+ },
248
+ children: [
249
+ /* @__PURE__ */ e(
250
+ j,
251
+ {
252
+ value: "defaults",
253
+ id: "mode-defaults",
254
+ className: "mt-0.5"
255
+ }
256
+ ),
257
+ /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: [
258
+ /* @__PURE__ */ a("p", { className: "text-[13px] font-medium text-foreground", children: [
259
+ "Use ",
260
+ l,
261
+ " defaults"
262
+ ] }),
263
+ /* @__PURE__ */ a("p", { className: "text-[12px] text-muted-foreground", children: [
264
+ M,
265
+ ", week starts ",
266
+ d
267
+ ] })
268
+ ] })
269
+ ]
270
+ }
271
+ ),
272
+ /* @__PURE__ */ a(
273
+ "label",
274
+ {
275
+ htmlFor: "mode-custom",
276
+ className: k(
277
+ "flex cursor-pointer items-start gap-2 rounded-[5px] px-2 py-1.5 hover:bg-muted/50",
278
+ !u && "bg-muted/50"
279
+ ),
280
+ onClick: () => {
281
+ c(!0), n(!1);
282
+ },
283
+ children: [
284
+ /* @__PURE__ */ e(
285
+ j,
286
+ {
287
+ value: "custom",
288
+ id: "mode-custom",
289
+ className: "mt-0.5"
290
+ }
291
+ ),
292
+ /* @__PURE__ */ e("p", { className: "flex-1 text-[13px] font-medium text-foreground", children: "Use custom settings" })
293
+ ]
294
+ }
295
+ )
296
+ ]
297
+ }
298
+ ),
299
+ /* @__PURE__ */ a(
300
+ "div",
301
+ {
302
+ className: k(
303
+ "space-y-4 border-t border-border/60 pt-4 transition-opacity",
304
+ u && "pointer-events-none opacity-50"
305
+ ),
306
+ children: [
307
+ /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
308
+ /* @__PURE__ */ e(P, { className: J, children: "Timezone" }),
309
+ /* @__PURE__ */ a(
310
+ fe,
311
+ {
312
+ open: E,
313
+ onOpenChange: C,
314
+ modal: !0,
315
+ children: [
316
+ /* @__PURE__ */ e(pe, { asChild: !0, children: /* @__PURE__ */ a(
317
+ A,
318
+ {
319
+ variant: "outline",
320
+ size: "xs",
321
+ role: "combobox",
322
+ "aria-expanded": E,
323
+ className: "w-full justify-between text-[12px] font-normal",
324
+ disabled: u,
325
+ children: [
326
+ /* @__PURE__ */ e("span", { className: "truncate", children: D }),
327
+ /* @__PURE__ */ e(xe, { className: "ml-2 h-3.5 w-3.5 shrink-0 opacity-50" })
328
+ ]
329
+ }
330
+ ) }),
331
+ /* @__PURE__ */ e(
332
+ be,
333
+ {
334
+ className: "z-50 w-[--radix-popover-trigger-width] p-0",
335
+ align: "start",
336
+ children: /* @__PURE__ */ a(ve, { className: "overflow-visible", children: [
337
+ /* @__PURE__ */ e(ge, { placeholder: "Search timezones…" }),
338
+ /* @__PURE__ */ a(Se, { children: [
339
+ /* @__PURE__ */ e(ye, { children: "No timezone found." }),
340
+ /* @__PURE__ */ e(V, { heading: "Common", children: _.map((s) => /* @__PURE__ */ a(
341
+ G,
342
+ {
343
+ value: `${s.value} ${s.label}`,
344
+ onSelect: () => {
345
+ c(!0), w(s.value), C(!1);
346
+ },
347
+ children: [
348
+ /* @__PURE__ */ e(
349
+ X,
350
+ {
351
+ className: k(
352
+ "h-3.5 w-3.5",
353
+ p === s.value ? "opacity-100" : "opacity-0"
354
+ )
355
+ }
356
+ ),
357
+ /* @__PURE__ */ e("span", { className: "flex-1", children: s.label }),
358
+ /* @__PURE__ */ e("span", { className: "text-[11px] text-muted-foreground", children: s.value })
359
+ ]
360
+ },
361
+ s.value
362
+ )) }),
363
+ /* @__PURE__ */ e(Ne, {}),
364
+ /* @__PURE__ */ e(V, { heading: "All timezones", children: L.map((s) => /* @__PURE__ */ a(
365
+ G,
366
+ {
367
+ value: s,
368
+ onSelect: () => {
369
+ c(!0), w(s), C(!1);
370
+ },
371
+ children: [
372
+ /* @__PURE__ */ e(
373
+ X,
374
+ {
375
+ className: k(
376
+ "h-3.5 w-3.5",
377
+ p === s ? "opacity-100" : "opacity-0"
378
+ )
379
+ }
380
+ ),
381
+ s
382
+ ]
383
+ },
384
+ s
385
+ )) })
386
+ ] })
387
+ ] })
388
+ }
389
+ )
390
+ ]
391
+ }
392
+ )
393
+ ] }),
394
+ /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
395
+ /* @__PURE__ */ e(P, { className: J, children: "Week starts on" }),
396
+ /* @__PURE__ */ e(
397
+ R,
398
+ {
399
+ value: String(z),
400
+ onValueChange: (s) => {
401
+ c(!0), b(Number(s));
402
+ },
403
+ className: "flex gap-4",
404
+ disabled: u,
405
+ children: ne.map((s) => /* @__PURE__ */ a(
406
+ "label",
407
+ {
408
+ htmlFor: `week-start-${s.value}`,
409
+ className: k(
410
+ "flex cursor-pointer items-center gap-2 text-[13px]",
411
+ u && "cursor-not-allowed"
412
+ ),
413
+ children: [
414
+ /* @__PURE__ */ e(
415
+ j,
416
+ {
417
+ value: String(s.value),
418
+ id: `week-start-${s.value}`,
419
+ disabled: u
420
+ }
421
+ ),
422
+ s.label
423
+ ]
424
+ },
425
+ s.value
426
+ ))
427
+ }
428
+ )
429
+ ] })
430
+ ]
431
+ }
432
+ )
433
+ ] }),
434
+ /* @__PURE__ */ a(re, { children: [
435
+ /* @__PURE__ */ e(
436
+ A,
437
+ {
438
+ variant: "outline",
439
+ size: "xs",
440
+ onClick: oe,
441
+ disabled: H,
442
+ children: "Cancel"
443
+ }
444
+ ),
445
+ /* @__PURE__ */ e(A, { size: "xs", onClick: m, disabled: ce, children: H ? /* @__PURE__ */ a(ue, { children: [
446
+ /* @__PURE__ */ e(we, { className: "h-3.5 w-3.5 animate-spin" }),
447
+ "Saving…"
448
+ ] }) : "Save" })
449
+ ] })
450
+ ] }) });
451
+ }
452
+ const U = 6, le = 1, ie = 20, q = "text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";
453
+ function Me(r) {
454
+ return Number.isNaN(r) ? U : Math.min(ie, Math.max(le, r));
455
+ }
456
+ function $e({
457
+ open: r,
458
+ onOpenChange: i,
459
+ dashboard: t,
460
+ onApply: v,
461
+ disabled: o = !1
462
+ }) {
463
+ const [h, N] = f(!1), [S, g] = f("top"), [x, u] = f(String(U)), n = t.summary;
464
+ Y(() => {
465
+ r && (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)));
466
+ }, [r, n == null ? void 0 : n.enabled, n == null ? void 0 : n.position, n == null ? void 0 : n.maxItems]);
467
+ const y = F(
468
+ () => Me(Number.parseInt(x || `${U}`, 10)),
469
+ [x]
470
+ );
471
+ return /* @__PURE__ */ e(Q, { open: r, onOpenChange: i, children: /* @__PURE__ */ a(ee, { className: "rounded-[6px] border-border/60 sm:max-w-[420px] sm:rounded-[6px]", children: [
472
+ /* @__PURE__ */ a(ae, { children: [
473
+ /* @__PURE__ */ e(te, { className: "text-[15px]", children: "Summary Settings" }),
474
+ /* @__PURE__ */ e(se, { className: "text-[13px] leading-5", children: "Configure dashboard-level summary display. Card-level summary settings still control which cards contribute." })
475
+ ] }),
476
+ /* @__PURE__ */ a("div", { className: "space-y-4 py-1", children: [
477
+ /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
478
+ /* @__PURE__ */ e(P, { htmlFor: "dashboard-summary-enabled", className: "text-[13px]", children: "Enable dashboard summary" }),
479
+ /* @__PURE__ */ e(
480
+ ke,
481
+ {
482
+ size: "xs",
483
+ id: "dashboard-summary-enabled",
484
+ checked: h,
485
+ disabled: o,
486
+ onCheckedChange: N
487
+ }
488
+ )
489
+ ] }),
490
+ /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
491
+ /* @__PURE__ */ e(P, { htmlFor: "dashboard-summary-position", className: q, children: "Position" }),
492
+ /* @__PURE__ */ a(
493
+ Ce,
494
+ {
495
+ value: S,
496
+ disabled: o,
497
+ onValueChange: (p) => g(p),
498
+ children: [
499
+ /* @__PURE__ */ e(Te, { id: "dashboard-summary-position", size: "xs", children: /* @__PURE__ */ e(Ie, { placeholder: "Select position" }) }),
500
+ /* @__PURE__ */ a(Pe, { children: [
501
+ /* @__PURE__ */ e(Z, { value: "top", children: "Top" }),
502
+ /* @__PURE__ */ e(Z, { value: "bottom", children: "Bottom" })
503
+ ] })
504
+ ]
505
+ }
506
+ )
507
+ ] }),
508
+ /* @__PURE__ */ a("div", { className: "space-y-1.5", children: [
509
+ /* @__PURE__ */ e(P, { htmlFor: "dashboard-summary-max-items", className: q, children: "Max items" }),
510
+ /* @__PURE__ */ e(
511
+ Ae,
512
+ {
513
+ size: "xs",
514
+ id: "dashboard-summary-max-items",
515
+ type: "number",
516
+ min: le,
517
+ max: ie,
518
+ disabled: o,
519
+ value: x,
520
+ onChange: (p) => u(p.target.value),
521
+ onBlur: () => u(String(y))
522
+ }
523
+ ),
524
+ /* @__PURE__ */ e("p", { className: "text-[12px] text-muted-foreground", children: "Display limit only. Computation is unchanged." })
525
+ ] }),
526
+ o && /* @__PURE__ */ e("p", { className: "text-[12px] text-amber-700", children: "Enter dashboard edit mode to modify summary settings." })
527
+ ] }),
528
+ /* @__PURE__ */ a(re, { children: [
529
+ /* @__PURE__ */ e(A, { variant: "outline", size: "xs", onClick: () => i(!1), children: "Cancel" }),
530
+ /* @__PURE__ */ e(A, { size: "xs", onClick: () => {
531
+ v({
532
+ enabled: h,
533
+ position: S,
534
+ maxItems: y
535
+ }), i(!1);
536
+ }, disabled: o, children: "Apply" })
537
+ ] })
538
+ ] }) });
539
+ }
540
+ export {
541
+ He as C,
542
+ $e as D
543
+ };