react-semaphor 0.1.293 → 0.1.295

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 (40) hide show
  1. package/dist/chunks/{braces-BwW2HFlB.js → braces-BdoTYzuj.js} +1 -1
  2. package/dist/chunks/{braces-C7GP95Fp.js → braces-DWldEFn5.js} +1 -1
  3. package/dist/chunks/{dashboard-controls-DgUc38Tn.js → dashboard-controls-B3lrnI_r.js} +9 -9
  4. package/dist/chunks/{dashboard-controls-jrkoCSY_.js → dashboard-controls-D7U6E1sB.js} +504 -472
  5. package/dist/chunks/dashboard-filter-controls-button-D0AsV28-.js +11 -0
  6. package/dist/chunks/dashboard-filter-controls-button-XwenlcXw.js +1152 -0
  7. package/dist/chunks/{dashboard-json-COjT-zjQ.js → dashboard-json-CU55qPXj.js} +1 -1
  8. package/dist/chunks/{dashboard-json-C0NiRL-A.js → dashboard-json-V6m6lJ_c.js} +1 -1
  9. package/dist/chunks/{dashboard-summary-settings-dialog-CGuFl7Xe.js → dashboard-summary-settings-dialog-0CIiWsKc.js} +1 -1
  10. package/dist/chunks/{dashboard-summary-settings-dialog-CXqaN_zj.js → dashboard-summary-settings-dialog-DRLPzp1P.js} +1 -1
  11. package/dist/chunks/{edit-dashboard-visual-ppdXk86H.js → edit-dashboard-visual-8ha6EM_g.js} +2205 -2147
  12. package/dist/chunks/edit-dashboard-visual-sSLAkmgf.js +183 -0
  13. package/dist/chunks/{index-9z-jMqN8.js → index-14M0TnH6.js} +35272 -33064
  14. package/dist/chunks/index-Ze8VskG1.js +1435 -0
  15. package/dist/chunks/{resource-management-panel-CP8cegZP.js → resource-management-panel-BL5-5ouC.js} +64 -64
  16. package/dist/chunks/{resource-management-panel-os6AuEKT.js → resource-management-panel-CcDAn86l.js} +1 -1
  17. package/dist/chunks/use-create-flow-overlay-state-BbQVNDCj.js +21 -0
  18. package/dist/chunks/{use-create-flow-overlay-state-wpuqRZX5.js → use-create-flow-overlay-state-D3PxfjYv.js} +430 -425
  19. package/dist/chunks/use-visual-utils-CdIOq4nt.js +337 -0
  20. package/dist/chunks/use-visual-utils-kh8p2QFm.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 +65 -0
  29. package/dist/types/main.d.ts +79 -4
  30. package/dist/types/shared.d.ts +40 -0
  31. package/dist/types/surfboard.d.ts +65 -0
  32. package/dist/types/types.d.ts +65 -0
  33. package/package.json +1 -1
  34. package/dist/chunks/dashboard-filter-controls-button-B19UWmsK.js +0 -11
  35. package/dist/chunks/dashboard-filter-controls-button-DGH4DxJ8.js +0 -1109
  36. package/dist/chunks/edit-dashboard-visual-CDOz4LWO.js +0 -183
  37. package/dist/chunks/index-K25f5Rqr.js +0 -1435
  38. package/dist/chunks/use-create-flow-overlay-state-CecnMS_v.js +0 -21
  39. package/dist/chunks/use-visual-utils-BTfG-ppd.js +0 -1
  40. package/dist/chunks/use-visual-utils-BhRKGJql.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-9z-jMqN8.js";
3
+ import { u as e, b as N, B as D, X as p, C as J } from "./index-14M0TnH6.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-K25f5Rqr.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-Ze8VskG1.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,6 +1,6 @@
1
1
  import { jsx as e, jsxs as a, Fragment as ue } from "react/jsx-runtime";
2
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-9z-jMqN8.js";
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-14M0TnH6.js";
4
4
  function ze(r = {}) {
5
5
  var T, L, D, M;
6
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 || {
@@ -1 +1 @@
1
- "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-K25f5Rqr.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;
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-Ze8VskG1.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;