react-semaphor 0.1.445 → 0.1.447

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 (91) hide show
  1. package/dist/analytics-protocol/index.js +8 -8
  2. package/dist/appearance/index.cjs +1 -1
  3. package/dist/appearance/index.js +1 -1
  4. package/dist/brand-studio/index.cjs +2 -2
  5. package/dist/brand-studio/index.js +9 -9
  6. package/dist/briefings/index.js +4 -4
  7. package/dist/chunks/{analyze-result-contract-DUv3QnMl.js → analyze-result-contract-T-0Ntzys.js} +1 -1
  8. package/dist/chunks/{braces-BdbUk_r9.js → braces-8TRlDwDw.js} +1 -1
  9. package/dist/chunks/{braces-BKimshER.cjs → braces-v55uLCAK.cjs} +1 -1
  10. package/dist/chunks/{catalog-field-grounding-AOGwWu0K.js → catalog-field-grounding-S2jKwKGD.js} +9 -9
  11. package/dist/chunks/{common-types-DFsDdpH7.js → common-types-B7Jk3Rtj.js} +5 -5
  12. package/dist/chunks/{dashboard-briefing-launcher-2SLNOaTg.js → dashboard-briefing-launcher-CDjcivK2.js} +192 -191
  13. package/dist/chunks/dashboard-briefing-launcher-D44Au-Qp.cjs +26 -0
  14. package/dist/chunks/dashboard-controls-DH3J4L1D.cjs +52 -0
  15. package/dist/chunks/dashboard-controls-tHwb3g3W.js +2409 -0
  16. package/dist/chunks/{dashboard-date-comparison-definition-BaYxjLi5.js → dashboard-date-comparison-definition-Ba-clViK.js} +1 -1
  17. package/dist/chunks/{dashboard-input-contract-BFpERluO.js → dashboard-input-contract-DSt8dGzP.js} +4 -4
  18. package/dist/chunks/{dashboard-json-BZwq3EcS.js → dashboard-json-Bihrrl5_.js} +11 -11
  19. package/dist/chunks/dashboard-json-VOXcUBqx.cjs +1 -0
  20. package/dist/chunks/edit-dashboard-visual-8XtuSSKG.cjs +177 -0
  21. package/dist/chunks/{edit-dashboard-visual-njLPYip3.js → edit-dashboard-visual-Dsc9mZnc.js} +7113 -7097
  22. package/dist/chunks/{editor-action-buttons-CBVMFipA.cjs → editor-action-buttons-BFqvBlLw.cjs} +1 -1
  23. package/dist/chunks/{editor-action-buttons-BhLX5Q6m.js → editor-action-buttons-BbVgPOda.js} +41 -41
  24. package/dist/chunks/{format-types-CZH5w1lo.js → format-types-DZGgYj39.js} +5 -5
  25. package/dist/chunks/index-BSTyv45D.cjs +1395 -0
  26. package/dist/chunks/{index-If0wlXGi.js → index-CJdxSyQq.js} +308 -308
  27. package/dist/chunks/{index-Dpm_VET4.cjs → index-DRlMUglg.cjs} +2 -2
  28. package/dist/chunks/{dashboard-u61yfU6u.js → index-srGACKDr.js} +148223 -151540
  29. package/dist/chunks/{layout-grid-D5tYJg1-.js → layout-grid-CiubineE.js} +1 -1
  30. package/dist/chunks/{layout-grid-3-HWzEwU.cjs → layout-grid-xm8pqtx0.cjs} +1 -1
  31. package/dist/chunks/{metric-comparison-BJ_Qu1ZF.js → metric-comparison-97zHGEx5.js} +7 -7
  32. package/dist/chunks/mouse-pointer-2-BZvGk45-.js +19 -0
  33. package/dist/chunks/mouse-pointer-2-DX4A_XZw.cjs +6 -0
  34. package/dist/chunks/{palette-DW_l7Jr0.cjs → palette-BN-jYtaK.cjs} +1 -1
  35. package/dist/chunks/{palette-jqaAcwiQ.js → palette-Cp1hqZtm.js} +1 -1
  36. package/dist/chunks/{pivot-result-identity-B6QCWOSi.js → pivot-result-identity-CwJWpKI7.js} +3 -3
  37. package/dist/chunks/{pivot-result-lifecycle-BM3Pl-D1.js → pivot-result-lifecycle-BBabQ_da.js} +27 -27
  38. package/dist/chunks/{presentation-execution-CGlb7YZ6.js → presentation-execution-BLfPTGX_.js} +10 -10
  39. package/dist/chunks/{report-preferences-dialog-D_NJu2wU.js → report-preferences-dialog-DZez53xw.js} +6 -6
  40. package/dist/chunks/report-preferences-dialog-TYTIHpHi.cjs +1 -0
  41. package/dist/chunks/{report-runtime-context-Qzn11HQe.js → report-runtime-context-bCy3CVzK.js} +1 -1
  42. package/dist/chunks/{save-4_uMnE6s.cjs → save-3dYRmehL.cjs} +1 -1
  43. package/dist/chunks/{save-HCJjjzdX.js → save-DgMfP0j8.js} +1 -1
  44. package/dist/chunks/{search-DHZCro8B.js → search-BHsQIWBV.js} +1 -1
  45. package/dist/chunks/{search-6ZmeMq55.cjs → search-BqqhaMx9.cjs} +1 -1
  46. package/dist/chunks/{code-editor-B4gTfvc5.js → switch-Bz2uj3q0.js} +9405 -9330
  47. package/dist/chunks/switch-rbwGjmad.cjs +138 -0
  48. package/dist/chunks/{temporal-bucket-authoring-BUZMuVca.js → temporal-bucket-authoring-CgOuakGW.js} +2 -2
  49. package/dist/chunks/{temporal-bucket-contract-B2bJ1oe4.js → temporal-bucket-contract-_F6vNhhH.js} +3 -3
  50. package/dist/chunks/{temporal-result-owner-Cb27SSG9.js → temporal-result-owner-6peubmhU.js} +3 -3
  51. package/dist/chunks/{token-types-DLo91nOf.js → token-types-BHR58aTy.js} +1 -1
  52. package/dist/chunks/{update-policy-eg59mQqv.js → update-policy-g0rCQ9BM.js} +9 -9
  53. package/dist/chunks/{validators-wZ2WlNHc.js → validators-Cs74WVie.js} +46 -46
  54. package/dist/chunks/x-B6ghREd2.cjs +31 -0
  55. package/dist/chunks/{index-xHCrHprY.js → x-CXDkqdur.js} +59 -59
  56. package/dist/dashboard/index.cjs +1 -1
  57. package/dist/dashboard/index.js +2 -2
  58. package/dist/dashboard-authoring/index.js +6 -6
  59. package/dist/data-app-builder/index.cjs +13 -18
  60. package/dist/data-app-builder/index.js +92 -106
  61. package/dist/data-app-codegen/index.js +2 -2
  62. package/dist/data-app-codegen-node/index.js +3 -3
  63. package/dist/data-app-sdk/index.cjs +1 -1
  64. package/dist/data-app-sdk/index.js +6 -6
  65. package/dist/data-app-sdk-adapters/index.js +2 -2
  66. package/dist/data-app-sdk-validation/index.js +4 -4
  67. package/dist/format-utils/index.js +8 -8
  68. package/dist/index.cjs +1 -1
  69. package/dist/index.js +16 -16
  70. package/dist/report-runtime-context/index.js +2 -2
  71. package/dist/style.css +1 -1
  72. package/dist/surfboard/index.cjs +1 -1
  73. package/dist/surfboard/index.js +3 -3
  74. package/dist/types/brand-studio.d.ts +2 -2
  75. package/dist/types/dashboard.d.ts +3 -2
  76. package/dist/types/data-app-builder.d.ts +2 -2
  77. package/dist/types/data-app-sdk.d.ts +1 -1
  78. package/dist/types/index.cjs +1 -1
  79. package/dist/types/index.js +7 -7
  80. package/dist/types/main.d.ts +27 -25
  81. package/dist/types/surfboard.d.ts +3 -2
  82. package/package.json +1 -2
  83. package/dist/chunks/code-editor-BYVorgOf.cjs +0 -138
  84. package/dist/chunks/dashboard-CAiwJW3L.cjs +0 -1397
  85. package/dist/chunks/dashboard-briefing-launcher-CHwjpUYz.cjs +0 -26
  86. package/dist/chunks/dashboard-controls-BfL14aqO.js +0 -2238
  87. package/dist/chunks/dashboard-controls-BgGTg4yw.cjs +0 -36
  88. package/dist/chunks/dashboard-json-BOv8tCa9.cjs +0 -1
  89. package/dist/chunks/edit-dashboard-visual-BdVCH0DJ.cjs +0 -182
  90. package/dist/chunks/index-jSrCwPQz.cjs +0 -31
  91. package/dist/chunks/report-preferences-dialog-r8QzOSFb.cjs +0 -1
@@ -1,31 +0,0 @@
1
- "use strict";const s=require("react");/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const f=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),d=(...t)=>t.filter((e,r,o)=>!!e&&o.indexOf(e)===r).join(" ");/**
7
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */var g={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const m=s.forwardRef(({color:t="currentColor",size:e=24,strokeWidth:r=2,absoluteStrokeWidth:o,className:a="",children:n,iconNode:l,...u},p)=>s.createElement("svg",{ref:p,...g,width:e,height:e,stroke:t,strokeWidth:o?Number(r)*24/Number(e):r,className:d("lucide",a),...u},[...l.map(([h,w])=>s.createElement(h,w)),...Array.isArray(n)?n:[n]]));/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const i=(t,e)=>{const r=s.forwardRef(({className:o,...a},n)=>s.createElement(m,{ref:n,iconNode:e,className:d(`lucide-${f(t)}`,o),...a}));return r.displayName=`${t}`,r};/**
22
- * @license lucide-react v0.453.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const b=i("ChevronDown",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);/**
27
- * @license lucide-react v0.453.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const k=i("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);class c extends Error{}c.prototype.name="InvalidTokenError";function v(t){return decodeURIComponent(atob(t).replace(/(.)/g,(e,r)=>{let o=r.charCodeAt(0).toString(16).toUpperCase();return o.length<2&&(o="0"+o),"%"+o}))}function y(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");switch(e.length%4){case 0:break;case 2:e+="==";break;case 3:e+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return v(e)}catch{return atob(e)}}function C(t,e){if(typeof t!="string")throw new c("Invalid token specified: must be a string");e||(e={});const r=e.header===!0?0:1,o=t.split(".")[r];if(typeof o!="string")throw new c(`Invalid token specified: missing part #${r+1}`);let a;try{a=y(o)}catch(n){throw new c(`Invalid token specified: invalid base64 for part #${r+1} (${n.message})`)}try{return JSON.parse(a)}catch(n){throw new c(`Invalid token specified: invalid json for part #${r+1} (${n.message})`)}}exports.ChevronDown=b;exports.X=k;exports.createLucideIcon=i;exports.jwtDecode=C;
@@ -1 +0,0 @@
1
- "use strict";const e=require("react/jsx-runtime"),l=require("react"),n=require("./dashboard-CAiwJW3L.cjs"),o=require("./code-editor-BYVorgOf.cjs"),V=require("./report-runtime-context-C8LZFsqV.cjs");require("./index-jSrCwPQz.cjs");require("./validators-9D4KBqKD.cjs");require("./analyze-result-contract-BHb7sUUW.cjs");const D=require("../value-format-preferences/index.cjs");function M(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(C=>C.actions.applyResolvedCalendarPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,[v,b]=l.useState(!1),[g,j]=l.useState(!1),[y,k]=l.useState(!1),[T,f]=l.useState(null),[N,P]=l.useState(null),h=l.useRef(c);h.current=c,l.useEffect(()=>{P(null),f(null),b(!1),j(!1),k(!1)},[c]);const w=l.useCallback(async C=>{const r=V.parseCalendarPreferencesResponse(await C.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),S=l.useCallback(async()=>{if(!d||!c||!m)return;const C=c;b(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const t=await w(r);h.current===C&&P(t)}catch(r){h.current===C&&f(r instanceof Error?r.message:"Unknown error")}finally{h.current===C&&b(!1)}},[c,m,d,w]);l.useEffect(()=>{d&&S()},[d,S]);const E=l.useCallback(async C=>{if(!c||!m)return f("Not authenticated"),!1;const r=c;j(!0),f(null);try{const t=await fetch(`${m}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(C)});if(!t.ok){const z=await t.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}const x=await w(t);return h.current!==r?!1:(P(x),p(x.resolved,x.sources),!0)}catch(t){return h.current===r&&f(t instanceof Error?t.message:"Unknown error"),!1}finally{h.current===r&&j(!1)}},[c,m,p,w]),A=l.useCallback(async()=>{if(!c||!m)return f("Not authenticated"),!1;const C=c;k(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const t=await w(r);return h.current!==C?!1:(P(t),p(t.resolved,t.sources),!0)}catch(r){return h.current===C&&f(r instanceof Error?r.message:"Unknown error"),!1}finally{h.current===C&&k(!1)}},[c,m,p,w]);return{preferences:N,isLoading:v,isSaving:g,isClearing:y,error:T,updatePreferences:E,clearPreferences:A,refetch:S}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],I=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return F.map(s=>s.value)}function G(s){if(!s)return"default";if(s.tz!==s.weekStart)return"inherited";switch(s.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(s){const i=F.find(a=>a.value===s);return i?i.label:s}function W(s){const i=I.find(a=>a.value===s);return i?i.label:String(s)}function H({active:s,onClose:i}){const{preferences:a,isLoading:p,isSaving:d,isClearing:c,updatePreferences:m,clearPreferences:v}=M({enabled:s}),b=n.useCalendarContext(),g=(a==null?void 0:a.resolved.tz)||(b==null?void 0:b.tz)||"UTC",j=(a==null?void 0:a.resolved.weekStart)??(b==null?void 0:b.weekStart)??1,[y,k]=l.useState((a==null?void 0:a.stored)===null),[T,f]=l.useState(!1),[N,P]=l.useState(g),[h,w]=l.useState(j),[S,E]=l.useState(!1),A=l.useMemo(()=>_(),[]),C=l.useMemo(()=>A.filter(u=>!F.some($=>$.value===u)),[A]),r=l.useMemo(()=>U(N),[N]),t=a!=null&&a.inherited?U(a.inherited.tz):"UTC",x=a!=null&&a.inherited?W(a.inherited.weekStart):"Monday",z=G(a==null?void 0:a.inheritedSources);l.useEffect(()=>{if(!s){f(!1);return}T||(a&&k(a.stored===null),P(g),w(j))},[s,T,a,g,j]);const q=async()=>{if(p){n.ue.error("Preferences are still loading. Please try again.");return}y?await v()?(n.ue.success("Now using default settings."),i()):n.ue.error("Failed to save preferences. Please try again."):await m({tz:N,weekStart:h})?(n.ue.success("Preferences saved."),i()):n.ue.error("Failed to save preferences. Please try again.")},B=()=>{i()},L=d||c,O=L||p;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(n.RadioGroup,{value:y?"defaults":"custom",onValueChange:u=>{f(!0),k(u==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",y&&"bg-muted/50"),onClick:()=>{f(!0),k(!0)},children:[e.jsx(n.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 ",z," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[t,", week starts ",x]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!y&&"bg-muted/50"),onClick:()=>{f(!0),k(!1)},children:[e.jsx(n.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:o.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",y&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Timezone"}),e.jsxs(o.Popover,{open:S,onOpenChange:E,modal:!0,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":S,className:"w-full justify-between text-[12px] font-normal",disabled:y,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(n.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(o.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(n.Command,{className:"overflow-visible",children:[e.jsx(n.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(n.CommandList,{children:[e.jsx(n.CommandEmpty,{children:"No timezone found."}),e.jsx(n.CommandGroup,{heading:"Common",children:F.map(u=>e.jsxs(n.CommandItem,{value:`${u.value} ${u.label}`,onSelect:()=>{f(!0),P(u.value),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:u.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:u.value})]},u.value))}),e.jsx(n.CommandSeparator,{}),e.jsx(n.CommandGroup,{heading:"All timezones",children:C.map(u=>e.jsxs(n.CommandItem,{value:u,onSelect:()=>{f(!0),P(u),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u?"opacity-100":"opacity-0")}),u]},u))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Week starts on"}),e.jsx(n.RadioGroup,{value:String(h),onValueChange:u=>{f(!0),w(Number(u))},className:"flex gap-4",disabled:y,children:I.map(u=>e.jsxs("label",{htmlFor:`week-start-${u.value}`,className:o.cn("flex cursor-pointer items-center gap-2 text-[13px]",y&&"cursor-not-allowed"),children:[e.jsx(n.RadioGroupItem,{value:String(u.value),id:`week-start-${u.value}`,disabled:y}),u.label]},u.value))})]})]})]}),e.jsxs(n.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:B,disabled:L,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:q,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function K(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,v=l.useRef(c);v.current=c;const[b,g]=l.useState(null),[j,y]=l.useState(!1),[k,T]=l.useState(!1),[f,N]=l.useState(!1),[P,h]=l.useState(null);l.useEffect(()=>{g(null),h(null),y(!1),T(!1),N(!1)},[c]);const w=l.useCallback(async r=>{const t=D.parseValueFormatPreferencesResponse(await r.json());if(!t.ok)throw new Error("Value format preferences response is invalid");return t.value},[]),S=l.useCallback(async(r,t)=>{if(!c||!m)throw new Error("Not authenticated");const x=await fetch(`${m}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${c}`,...t?{"Content-Type":"application/json"}:{}},body:t?JSON.stringify(t):void 0});if(!x.ok){const z=await x.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}return w(x)},[c,m,w]),E=l.useCallback(async()=>{if(!d||!c||!m)return;const r=c;y(!0),h(null);try{const t=await S("GET");v.current===r&&g(t)}catch(t){v.current===r&&h(t instanceof Error?t.message:"Unknown error")}finally{v.current===r&&y(!1)}},[c,m,d,S]);l.useEffect(()=>{d&&E()},[d,E]);const A=l.useCallback(async r=>{const t=c;T(!0),h(null);try{const x=await S("PATCH",r);return v.current!==t?!1:(g(x),p(x.resolved,x.sources),!0)}catch(x){return v.current===t&&h(x instanceof Error?x.message:"Unknown error"),!1}finally{v.current===t&&T(!1)}},[c,p,S]),C=l.useCallback(async()=>{const r=c;N(!0),h(null);try{const t=await S("DELETE");return v.current!==r?!1:(g(t),p(t.resolved,t.sources),!0)}catch(t){return v.current===r&&h(t instanceof Error?t.message:"Unknown error"),!1}finally{v.current===r&&N(!1)}},[c,p,S]);return{preferences:b,isLoading:j,isSaving:k,isClearing:f,error:P,updatePreferences:A,clearPreferences:C,refetch:E}}function J({active:s,onClose:i}){var v,b;const{preferences:a,isLoading:p,isSaving:d,updatePreferences:c}=K({enabled:s});if(!s)return null;if(!a)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:p?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const m=[((v=a.stored)==null?void 0:v.locale)??"",((b=a.stored)==null?void 0:b.defaultCurrency)??""].join(":");return e.jsx(Z,{preferences:a,isSaving:d,updatePreferences:c,onClose:i},m)}function Z({preferences:s,isSaving:i,updatePreferences:a,onClose:p}){const[d,c]=l.useState(()=>{var g,j;return{locale:(g=s.stored)==null?void 0:g.locale,defaultCurrency:(j=s.stored)==null?void 0:j.defaultCurrency}}),m=(d.locale===void 0||D.canonicalizeSupportedLocale(d.locale)!==void 0)&&(d.defaultCurrency===void 0||D.canonicalizeSupportedCurrencyCode(d.defaultCurrency)!==void 0),v=async()=>{var T,f;const g={},j=[];d.locale!==void 0?g.locale=d.locale:((T=s.stored)==null?void 0:T.locale)!==void 0&&j.push("locale"),d.defaultCurrency!==void 0?g.defaultCurrency=d.defaultCurrency:((f=s.stored)==null?void 0:f.defaultCurrency)!==void 0&&j.push("defaultCurrency");const y={...Object.keys(g).length>0?{set:g}:{},...j.length>0?{clear:j}:{}};(Object.keys(y).length===0?!0:await a(y))?(n.ue.success("Display format preferences saved."),p()):n.ue.error("Failed to save preferences. Please try again.")},b=async()=>{await a({clear:["locale","defaultCurrency"]})?(n.ue.success("Locale and currency preferences reset."),p()):n.ue.error("Failed to reset locale and currency preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(n.DisplayFormatPreferencesFields,{value:d,inherited:s.inherited,inheritedSources:s.inheritedSources,onChange:c,disabled:i})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:b,disabled:i||s.stored===null,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:p,disabled:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:v,disabled:i||!m,children:i?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function Y({open:s,onOpenChange:i}){const[a,p]=l.useState("display"),d=()=>i(!1);return e.jsx(n.Dialog,{open:s,onOpenChange:i,children:e.jsxs(n.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(n.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(o.Tabs,{value:a,onValueChange:p,children:[e.jsxs(o.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(o.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(o.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(o.TabsContent,{value:"display",children:e.jsx(J,{active:s&&a==="display",onClose:d})}),e.jsx(o.TabsContent,{value:"calendar",children:e.jsx(H,{active:s&&a==="calendar",onClose:d})})]})]})})}exports.ReportPreferencesDialog=Y;