react-semaphor 0.1.326 → 0.1.328

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 (82) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +1 -1
  3. package/dist/brand-studio/index.cjs +5 -5
  4. package/dist/brand-studio/index.js +23 -24
  5. package/dist/chunks/_commonjsHelpers-BVfed4GL.js +28 -0
  6. package/dist/chunks/_commonjsHelpers-DwTZ_eVU.js +1 -0
  7. package/dist/chunks/{braces-DVaMJoCd.js → braces-CG8viaD2.js} +1 -1
  8. package/dist/chunks/{braces-dHeaioTd.js → braces-DSaa_4Oc.js} +1 -1
  9. package/dist/chunks/{calendar-preferences-dialog-mqU_uOmY.js → calendar-preferences-dialog-DD_qAthL.js} +1 -1
  10. package/dist/chunks/{calendar-preferences-dialog--2jD-eKu.js → calendar-preferences-dialog-JRmNJptJ.js} +3 -3
  11. package/dist/chunks/{chevrons-up-down-DNQE-uEp.js → chevrons-up-down-CBa0uh0X.js} +1 -1
  12. package/dist/chunks/{chevrons-up-down-CLbzBHoI.js → chevrons-up-down-ChDNqVP7.js} +1 -1
  13. package/dist/chunks/dashboard-briefing-launcher-BKdJFwH5.js +106 -0
  14. package/dist/chunks/{dashboard-briefing-launcher-DsjXUPFq.js → dashboard-briefing-launcher-BfyNkd8i.js} +1106 -1108
  15. package/dist/chunks/{dashboard-controls-DgNkM1yT.js → dashboard-controls-0pZDLvFL.js} +218 -218
  16. package/dist/chunks/{dashboard-controls-XCa9PZuU.js → dashboard-controls-C0xm1QMR.js} +10 -10
  17. package/dist/chunks/dashboard-json-BW5OVZ6m.js +1 -0
  18. package/dist/chunks/{dashboard-json-DkA6Bf0Y.js → dashboard-json-DsruhRPD.js} +14 -13
  19. package/dist/chunks/date-formatter-B4EBSe9C.js +1 -0
  20. package/dist/chunks/date-formatter-CzcPZx39.js +416 -0
  21. package/dist/chunks/edit-dashboard-visual-DQyJ7SSv.js +178 -0
  22. package/dist/chunks/{edit-dashboard-visual-Q5hW5MXk.js → edit-dashboard-visual-g5SZZahJ.js} +8242 -7784
  23. package/dist/chunks/index-1JWDPCun.js +1935 -0
  24. package/dist/chunks/index-BdjXTQt4.js +1444 -0
  25. package/dist/chunks/{index-DwfDwtv2.js → index-BmKr-K7J.js} +117670 -113627
  26. package/dist/chunks/index-C1l78BIx.js +3247 -0
  27. package/dist/chunks/lib-Ce3zosXY.js +38 -0
  28. package/dist/chunks/lib-DFvr9fM4.js +5500 -0
  29. package/dist/chunks/{palette-DtmNws9a.js → palette-D0YmAqBS.js} +1 -1
  30. package/dist/chunks/{palette-DpcvHAiY.js → palette-DQgq3edH.js} +1 -1
  31. package/dist/chunks/{resource-management-panel-CGwWKZOP.js → resource-management-panel-CIfBh46E.js} +1 -1
  32. package/dist/chunks/{resource-management-panel-D2oAQkKi.js → resource-management-panel-Cj19pw9M.js} +145 -145
  33. package/dist/chunks/switch-BvTzw2AW.js +173 -0
  34. package/dist/chunks/{switch-j3AThLFk.js → switch-De31SR3q.js} +2752 -2717
  35. package/dist/chunks/typescript-Cmizj1hi.js +446 -0
  36. package/dist/chunks/typescript-H1EwZsOb.js +159820 -0
  37. package/dist/chunks/use-create-flow-overlay-state-BTQiKRD1.js +26 -0
  38. package/dist/chunks/{use-create-flow-overlay-state-CP6GDQAX.js → use-create-flow-overlay-state-IcHP0l39.js} +150 -151
  39. package/dist/chunks/{use-visual-utils-CSXU-96k.js → use-visual-utils-DQ5zGYD2.js} +13 -13
  40. package/dist/chunks/{use-visual-utils-NpOW5uZ1.js → use-visual-utils-XF-AqV8o.js} +1 -1
  41. package/dist/chunks/{validators-DvTxl9i0.js → validators-DDAweCzB.js} +67 -48
  42. package/dist/chunks/validators-odlRJblR.js +2 -0
  43. package/dist/dashboard/index.cjs +1 -1
  44. package/dist/dashboard/index.js +1 -1
  45. package/dist/dashboard-authoring/index.cjs +3 -3
  46. package/dist/dashboard-authoring/index.js +907 -527
  47. package/dist/data-app-builder/index.cjs +1 -0
  48. package/dist/data-app-builder/index.js +4 -0
  49. package/dist/data-app-builder-browser-runtime/index.cjs +1 -0
  50. package/dist/data-app-builder-browser-runtime/index.js +10 -0
  51. package/dist/data-app-sdk/index.cjs +1 -1
  52. package/dist/data-app-sdk/index.js +208 -196
  53. package/dist/format-utils/index.cjs +4 -4
  54. package/dist/format-utils/index.js +22 -21
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.js +14 -14
  57. package/dist/style.css +1 -1
  58. package/dist/surfboard/index.cjs +1 -1
  59. package/dist/surfboard/index.js +2 -2
  60. package/dist/types/analytics-protocol.d.ts +1 -0
  61. package/dist/types/dashboard-authoring.d.ts +79 -2
  62. package/dist/types/dashboard.d.ts +17 -2
  63. package/dist/types/data-app-builder-browser-runtime.d.ts +185 -0
  64. package/dist/types/data-app-builder.d.ts +630 -0
  65. package/dist/types/data-app-sdk.d.ts +15 -1
  66. package/dist/types/format-utils.d.ts +25 -0
  67. package/dist/types/main.d.ts +67 -10
  68. package/dist/types/shared.d.ts +17 -2
  69. package/dist/types/surfboard.d.ts +17 -2
  70. package/dist/types/types.d.ts +32 -3
  71. package/package.json +11 -1
  72. package/dist/chunks/dashboard-briefing-launcher-DguNfFr8.js +0 -106
  73. package/dist/chunks/dashboard-json-DiBd65Xf.js +0 -1
  74. package/dist/chunks/date-formatter-D9Bvw5Qk.js +0 -1
  75. package/dist/chunks/date-formatter-DyIOb6uC.js +0 -333
  76. package/dist/chunks/edit-dashboard-visual-BC9eOc4U.js +0 -178
  77. package/dist/chunks/index-B1-46PoR.js +0 -1303
  78. package/dist/chunks/save-BY7WF62U.js +0 -21
  79. package/dist/chunks/save-Cv_XRb94.js +0 -6
  80. package/dist/chunks/switch-5aQ_jcLH.js +0 -168
  81. package/dist/chunks/use-create-flow-overlay-state-BQPXP0AM.js +0 -26
  82. package/dist/chunks/validators-DJUMR5An.js +0 -2
@@ -1,39 +1,39 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./switch-5aQ_jcLH.js"),s=require("./index-B1-46PoR.js");require("./index-BxM99sFL.js");const v=require("react");require("./index-DRlMUglg.js");const Zt=require("react-dom"),O=require("./dashboard-briefing-launcher-DguNfFr8.js"),xt=require("./index-D7KJindZ.js"),es=require("./calendar-preferences-dialog-mqU_uOmY.js"),ts=require("./use-debounced-dirty-check-XHSwAefL.js"),Re=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),ct=require("./save-Cv_XRb94.js"),ss=require("./palette-DpcvHAiY.js"),rs=require("./braces-DVaMJoCd.js");function ns(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(a,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return a.default=t,Object.freeze(a)}const E=ns(v);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./switch-BvTzw2AW.js"),s=require("./index-BdjXTQt4.js");require("./index-BxM99sFL.js");const v=require("react");require("./index-DRlMUglg.js");require("react-dom/client");const Yt=require("react-dom"),O=require("./dashboard-briefing-launcher-BKdJFwH5.js"),ht=require("./index-D7KJindZ.js"),Zt=require("./calendar-preferences-dialog-DD_qAthL.js"),es=require("./use-debounced-dirty-check-XHSwAefL.js"),Re=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),ts=require("./palette-DQgq3edH.js"),ss=require("./braces-CG8viaD2.js");function rs(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(a,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return a.default=t,Object.freeze(a)}const E=rs(v);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const as=d.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
6
+ */const ns=d.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const os=d.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
11
+ */const as=d.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
12
12
  * @license lucide-react v0.453.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const is=d.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
16
+ */const os=d.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
17
17
  * @license lucide-react v0.453.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const ds=d.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
21
+ */const is=d.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
22
22
  * @license lucide-react v0.453.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const cs=d.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
26
+ */const ds=d.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
27
27
  * @license lucide-react v0.453.0 - ISC
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const ls=d.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/**
31
+ */const cs=d.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/**
32
32
  * @license lucide-react v0.453.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const us=d.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var Te={exports:{}},_e={};/**
36
+ */const ls=d.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var Te={exports:{}},_e={};/**
37
37
  * @license React
38
38
  * use-sync-external-store-shim.production.js
39
39
  *
@@ -41,7 +41,7 @@
41
41
  *
42
42
  * This source code is licensed under the MIT license found in the
43
43
  * LICENSE file in the root directory of this source tree.
44
- */var lt;function ms(){if(lt)return _e;lt=1;var t=v;function a(l,x){return l===x&&(l!==0||1/l===1/x)||l!==l&&x!==x}var r=typeof Object.is=="function"?Object.is:a,n=t.useState,o=t.useEffect,m=t.useLayoutEffect,f=t.useDebugValue;function u(l,x){var p=x(),g=n({inst:{value:p,getSnapshot:x}}),i=g[0].inst,S=g[1];return m(function(){i.value=p,i.getSnapshot=x,b(i)&&S({inst:i})},[l,p,x]),o(function(){return b(i)&&S({inst:i}),l(function(){b(i)&&S({inst:i})})},[l]),f(p),p}function b(l){var x=l.getSnapshot;l=l.value;try{var p=x();return!r(l,p)}catch{return!0}}function y(l,x){return x()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?y:u;return _e.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,_e}var Ue={};/**
44
+ */var ct;function us(){if(ct)return _e;ct=1;var t=v;function a(l,x){return l===x&&(l!==0||1/l===1/x)||l!==l&&x!==x}var r=typeof Object.is=="function"?Object.is:a,n=t.useState,o=t.useEffect,m=t.useLayoutEffect,f=t.useDebugValue;function u(l,x){var p=x(),g=n({inst:{value:p,getSnapshot:x}}),i=g[0].inst,S=g[1];return m(function(){i.value=p,i.getSnapshot=x,b(i)&&S({inst:i})},[l,p,x]),o(function(){return b(i)&&S({inst:i}),l(function(){b(i)&&S({inst:i})})},[l]),f(p),p}function b(l){var x=l.getSnapshot;l=l.value;try{var p=x();return!r(l,p)}catch{return!0}}function y(l,x){return x()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?y:u;return _e.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,_e}var Ue={};/**
45
45
  * @license React
46
46
  * use-sync-external-store-shim.development.js
47
47
  *
@@ -49,4 +49,4 @@
49
49
  *
50
50
  * This source code is licensed under the MIT license found in the
51
51
  * LICENSE file in the root directory of this source tree.
52
- */var ut;function ps(){return ut||(ut=1,process.env.NODE_ENV!=="production"&&function(){function t(p,g){return p===g&&(p!==0||1/p===1/g)||p!==p&&g!==g}function a(p,g){h||o.startTransition===void 0||(h=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var i=g();if(!l){var S=g();m(i,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}S=f({inst:{value:i,getSnapshot:g}});var w=S[0].inst,N=S[1];return b(function(){w.value=i,w.getSnapshot=g,r(w)&&N({inst:w})},[p,i,g]),u(function(){return r(w)&&N({inst:w}),p(function(){r(w)&&N({inst:w})})},[p]),y(i),i}function r(p){var g=p.getSnapshot;p=p.value;try{var i=g();return!m(p,i)}catch{return!0}}function n(p,g){return g()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=v,m=typeof Object.is=="function"?Object.is:t,f=o.useState,u=o.useEffect,b=o.useLayoutEffect,y=o.useDebugValue,h=!1,l=!1,x=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?n:a;Ue.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:x,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ue}process.env.NODE_ENV==="production"?Te.exports=ms():Te.exports=ps();var hs=Te.exports;const De=["light","dark","system"];function xs(){const{theme:t,setTheme:a}=s.useTheme(),r=d.useDashboardStore(f=>f.actions.setDashboardTheme);function n(){const f=De.includes(t)?t:"system",u=De[(De.indexOf(f)+1)%De.length];a(u),r(u)}const o=t==="light"?ls:t==="dark"?ds:is,m=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(d.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,"aria-label":m,title:m,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function fs(t,a,r,n,o){if(!o)return null;const m=JSON.stringify(r),f=`${t}/v1/lens`;return await d.postRequest(f,o,{name:a,template:m,filterValues:n,operation:"create"})}async function Fe(t,a,r){if(!r)return null;const{id:n,template:o,filterValues:m,isDefault:f,shared:u}=a,b=`${t}/v1/lens`;return await d.postRequest(b,r,{lensId:n,template:o,filterValues:m,isDefault:f,shared:u,operation:"update"})}async function gs(t,a,r){if(!r)return null;const n=`${t}/v1/lens`;return await d.postRequest(n,r,{operation:"delete",lensId:a})}const bs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function vs({open:t,onOpenChange:a}={}){const[r,n]=v.useState(""),[o,m]=v.useState(!1),f=d.useDashboardStore(D=>D.lenses),{setLenses:u,setSelectedLensId:b}=d.useDashboardActions(),[y,h]=v.useState(!1),[l,x]=v.useState(!1),p=t!==void 0,g=p?t:l,i=D=>{p||x(D),a==null||a(D)},S=d.useDashboardStore(D=>D.dashboard),w=d.useDashboardStore(D=>D.filterValues),{authToken:N,tokenProps:k}=s.useSemaphorContext();async function C(){h(!0);const D=await fs(k.apiServiceUrl,r,S,w,N==null?void 0:N.accessToken);D&&(u([...f||[],D]),b(D.id),i(!1)),h(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:i,children:[p?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(d.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(d.Label,{htmlFor:"lens-name",className:bs,children:"Name"}),e.jsx(d.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:D=>n(D.target.value)}),o&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(d.Button,{variant:"outline",size:"xs",onClick:()=>i(!1),children:"Cancel"}),e.jsx(d.Button,{size:"xs",type:"submit",onClick:C,disabled:y||!r.trim(),children:y?"Creating…":"Create"})]})]})]})}function ys({includeLabel:t=!1}={}){const a=d.useDashboardStore(h=>h.lenses),r=d.useDashboardStore(h=>h.selectedLensId),{setLenses:n,setSelectedLensId:o}=d.useDashboardActions(),{authToken:m,tokenProps:f}=s.useSemaphorContext();async function u(h){o(h)}async function b(h){if(await gs(f.apiServiceUrl,h,m==null?void 0:m.accessToken)){const x=a==null?void 0:a.filter(p=>p.id!==h);n(x||[]),o("original")}}async function y(h){const l=a==null?void 0:a.map(g=>g.id===h.id?{...g,isDefault:!h.isDefault}:{...g,isDefault:!1});n(l||[]);const x={...h,isDefault:!h.isDefault};await Fe(f.apiServiceUrl,x,m==null?void 0:m.accessToken);const p=a==null?void 0:a.find(g=>g.isDefault);if(p&&p.id!==h.id){const g={...p,isDefault:!1};await Fe(f.apiServiceUrl,g,m==null?void 0:m.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:u,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:l=>{l.preventDefault(),y(h)},className:d.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:l=>{l.preventDefault(),b(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})}function js(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:r,userContext:n}=s.useCurrentUserInfo(),o=v.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),m=v.useMemo(()=>u=>o&&o[u]!==void 0&&o[u]===!1?!1:a(u),[o,a,t]),f=v.useMemo(()=>{var u,b,y,h,l;return{canEdit:((u=n==null?void 0:n.permissions)==null?void 0:u.canEdit)??s.canUserEdit(r),canUseFilters:((b=n==null?void 0:n.permissions)==null?void 0:b.canEdit)??s.canUserUseFilters(r),canManageDashboards:((y=n==null?void 0:n.permissions)==null?void 0:y.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((h=n==null?void 0:n.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((l=n==null?void 0:n.permissions)==null?void 0:l.canEdit)??s.canUserAccessVisuals(r)}},[r,n]);return{displayPreferences:t,shouldShowElement:m,permissions:f,currentUser:r}}function Ss(t,a=[]){let r=[];function n(m,f){const u=E.createContext(f);u.displayName=m+"Context";const b=r.length;r=[...r,f];const y=l=>{var w;const{scope:x,children:p,...g}=l,i=((w=x==null?void 0:x[t])==null?void 0:w[b])||u,S=E.useMemo(()=>g,Object.values(g));return e.jsx(i.Provider,{value:S,children:p})};y.displayName=m+"Provider";function h(l,x){var i;const p=((i=x==null?void 0:x[t])==null?void 0:i[b])||u,g=E.useContext(p);if(g)return g;if(f!==void 0)return f;throw new Error(`\`${l}\` must be used within \`${m}\``)}return[y,h]}const o=()=>{const m=r.map(f=>E.createContext(f));return function(u){const b=(u==null?void 0:u[t])||m;return E.useMemo(()=>({[`__scope${t}`]:{...u,[t]:b}}),[u,b])}};return o.scopeName=t,[n,ws(o,...a)]}function ws(...t){const a=t[0];if(t.length===1)return a;const r=()=>{const n=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(m){const f=n.reduce((u,{useScope:b,scopeName:y})=>{const l=b(m)[`__scope${y}`];return{...u,...l}},{});return E.useMemo(()=>({[`__scope${a.scopeName}`]:f}),[f])}};return r.scopeName=a.scopeName,r}var Ds=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],qe=Ds.reduce((t,a)=>{const r=d.createSlot(`Primitive.${a}`),n=E.forwardRef((o,m)=>{const{asChild:f,...u}=o,b=f?r:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(b,{...u,ref:m})});return n.displayName=`Primitive.${a}`,{...t,[a]:n}},{});function Ns(){return hs.useSyncExternalStore(Cs,()=>!0,()=>!1)}function Cs(){return()=>{}}var $e="Avatar",[ks]=Ss($e),[Es,ft]=ks($e),gt=E.forwardRef((t,a)=>{const{__scopeAvatar:r,...n}=t,[o,m]=E.useState("idle");return e.jsx(Es,{scope:r,imageLoadingStatus:o,onImageLoadingStatusChange:m,children:e.jsx(qe.span,{...n,ref:a})})});gt.displayName=$e;var bt="AvatarImage",vt=E.forwardRef((t,a)=>{const{__scopeAvatar:r,src:n,onLoadingStatusChange:o=()=>{},...m}=t,f=ft(bt,r),u=Ls(n,m),b=d.useCallbackRef(y=>{o(y),f.onImageLoadingStatusChange(y)});return d.useLayoutEffect2(()=>{u!=="idle"&&b(u)},[u,b]),u==="loaded"?e.jsx(qe.img,{...m,ref:a,src:n}):null});vt.displayName=bt;var yt="AvatarFallback",jt=E.forwardRef((t,a)=>{const{__scopeAvatar:r,delayMs:n,...o}=t,m=ft(yt,r),[f,u]=E.useState(n===void 0);return E.useEffect(()=>{if(n!==void 0){const b=window.setTimeout(()=>u(!0),n);return()=>window.clearTimeout(b)}},[n]),f&&m.imageLoadingStatus!=="loaded"?e.jsx(qe.span,{...o,ref:a}):null});jt.displayName=yt;function mt(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Ls(t,{referrerPolicy:a,crossOrigin:r}){const n=Ns(),o=E.useRef(null),m=n?(o.current||(o.current=new window.Image),o.current):null,[f,u]=E.useState(()=>mt(m,t));return d.useLayoutEffect2(()=>{u(mt(m,t))},[m,t]),d.useLayoutEffect2(()=>{const b=l=>()=>{u(l)};if(!m)return;const y=b("loaded"),h=b("error");return m.addEventListener("load",y),m.addEventListener("error",h),a&&(m.referrerPolicy=a),typeof r=="string"&&(m.crossOrigin=r),()=>{m.removeEventListener("load",y),m.removeEventListener("error",h)}},[m,r,a]),f}var St=gt,wt=vt,Dt=jt;const Nt=E.forwardRef(({className:t,...a},r)=>e.jsx(St,{ref:r,className:d.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));Nt.displayName=St.displayName;const Ms=E.forwardRef(({className:t,...a},r)=>e.jsx(wt,{ref:r,className:d.cn("aspect-square h-full w-full",t),...a}));Ms.displayName=wt.displayName;const Ct=E.forwardRef(({className:t,...a},r)=>e.jsx(Dt,{ref:r,className:d.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));Ct.displayName=Dt.displayName;const Is=async(t,a,r)=>{const n=`${t}/management/v1/groups`;return await d.postRequestRegular(n,a,r)},As=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}`;return d.requestJsonRegular(o,a,"PATCH",n)},Ps=async(t,a,r)=>{const n=`${t}/management/v1/groups/${r}`;await d.requestJsonRegular(n,a,"DELETE")},Os=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;return await d.postRequestRegular(o,a,n)},Rs=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;await d.requestJsonRegular(o,a,"DELETE",n)};function _s(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:n=>Is(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:n=>{console.error("Failed to create group:",n),s.ue.error("Failed to create group",{description:d.getRequestErrorMessage(n,"Failed to create group")})}})}function Us(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>As(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group updated successfully")},onError:n=>{console.error("Failed to update group:",n),s.ue.error("Failed to update group",{description:d.getRequestErrorMessage(n,"Failed to update group")})}})}function Ts(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:n=>Ps(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",o]}),s.ue.success("Group deleted successfully")},onError:n=>{console.error("Failed to delete group:",n),s.ue.error("Failed to delete group",{description:d.getRequestErrorMessage(n,"Failed to delete group")})}})}function Fs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Os(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["group-members",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:n=>{console.error("Failed to add group members:",n),s.ue.error("Failed to add members",{description:d.getRequestErrorMessage(n,"Failed to add members")})}})}function qs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Rs(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["group-members",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:n=>{console.error("Failed to remove group members:",n),s.ue.error("Failed to remove members",{description:d.getRequestErrorMessage(n,"Failed to remove members")})}})}const $s=[];function Bs({open:t,onOpenChange:a}){var N,k,C;const{tokenProps:r}=s.useSemaphorContext(),{currentUser:n}=s.useCurrentUserInfo(),o=(n==null?void 0:n.type)==="tenant",m=r==null?void 0:r.tenantId,{groups:f,isLoading:u,error:b,refetch:y}=s.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?m:void 0,includeMembers:!1}),h=b?kt(b,"Unable to load groups."):null,[l,x]=v.useState({kind:"list"}),[p,g]=v.useState(null),i=Ts();v.useEffect(()=>{t||(x({kind:"list"}),g(null))},[t]);const S=l.kind==="members"&&f.find(D=>D.id===l.groupId)||null,w=async()=>{if(p)try{await i.mutateAsync(p.id),g(null),x({kind:"list"}),y()}catch{}};return e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0",children:[l.kind==="list"?e.jsxs("div",{className:"shrink-0 border-b border-border px-5 pt-4 pb-3.5",children:[e.jsx(s.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"Group management"}),e.jsx(s.DialogDescription,{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:"Organize people into groups for shared access."})]}):l.kind==="create"?e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:()=>x({kind:"list"}),"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium",children:"New group"}),e.jsx(s.DialogDescription,{className:"sr-only",children:"Create a new group to organize members."})]}):null,l.kind==="list"&&e.jsx(Gs,{groups:f,isLoading:u,errorMessage:h,onRetry:()=>y(),currentUserId:n==null?void 0:n.id,onOpenGroup:D=>x({kind:"members",groupId:D}),onCreate:()=>x({kind:"create"}),onDeleteRequest:D=>g(D)}),l.kind==="members"&&S&&e.jsx(Vs,{group:S,isTenantViewer:o,canEdit:((N=S.permissions)==null?void 0:N.canEdit)??S.createdBy===(n==null?void 0:n.id),canDelete:((k=S.permissions)==null?void 0:k.canDelete)??S.createdBy===(n==null?void 0:n.id),canManageMembers:((C=S.permissions)==null?void 0:C.canManageMembers)??S.createdBy===(n==null?void 0:n.id),onBack:()=>x({kind:"list"}),onMembersChanged:y,onUpdated:y,onRequestDelete:()=>g(S)},S.id),l.kind==="create"&&e.jsx(Ks,{isTenantUser:o,tenantId:m,onCancel:()=>x({kind:"list"}),onCreated:D=>{y(),x({kind:"members",groupId:D})}}),p&&e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] text-foreground",children:["Delete ",e.jsx("span",{className:"font-medium",children:p.name}),"?",e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Members lose any access granted via this group."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>g(null),disabled:i.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:w,disabled:i.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",children:[i.isPending?e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function Gs({groups:t,isLoading:a,errorMessage:r,onRetry:n,currentUserId:o,onOpenGroup:m,onCreate:f,onDeleteRequest:u}){const[b,y]=v.useState(""),h=v.useMemo(()=>t.filter(l=>!b.trim()||l.name.toLowerCase().includes(b.toLowerCase())||(l.description||"").toLowerCase().includes(b.toLowerCase())),[t,b]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(s.Search,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:b,onChange:l=>y(l.target.value),placeholder:"Search groups…",className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"}),b&&e.jsx("button",{type:"button",onClick:()=>y(""),className:"flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(d.X,{className:"h-2.5 w-2.5"})})]}),e.jsxs("button",{type:"button",onClick:f,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:a?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(l=>e.jsx("div",{className:"h-12 animate-pulse rounded-[4px] bg-muted/60"},l))}):r?e.jsx(Et,{title:"Can't load groups",message:r,onRetry:n}):h.length===0&&t.length===0?e.jsx(Hs,{onCreate:f}):h.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsxs("div",{className:"text-[12px] text-foreground",children:['No groups match "',b,'"']}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Try a different search."})]}):h.map(l=>{var x;return e.jsx(zs,{group:l,canDelete:((x=l.permissions)==null?void 0:x.canDelete)??l.createdBy===o,onClick:()=>m(l.id),onDelete:()=>u(l)},l.id)})})]})}function zs({group:t,canDelete:a,onClick:r,onDelete:n}){let o="";try{o=xt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{o=""}return e.jsxs("button",{type:"button",onClick:r,className:"group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground",children:e.jsx(O.UsersRound,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.UserRound,{className:"h-2.5 w-2.5"}),t.memberCount," member",t.memberCount===1?"":"s"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-2.5 w-2.5"}),o]})]}),t.description&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:t.description})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[a&&e.jsx("span",{role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),n()},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),m.stopPropagation(),n())},"aria-label":`Delete ${t.name}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.Trash2,{className:"h-3 w-3"})}),e.jsx(s.ChevronRight,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]})}function Hs({onCreate:t}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground",children:e.jsx(s.Users,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:"No groups yet"}),e.jsx("div",{className:"max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground",children:"Groups let you grant shared access to dashboards. Create one and add members."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]})}function Vs({group:t,isTenantViewer:a,canEdit:r,canDelete:n,canManageMembers:o,onBack:m,onMembersChanged:f,onUpdated:u,onRequestDelete:b}){const{data:y,isLoading:h,error:l,refetch:x}=s.useGroupMembers(t.id),p=(y==null?void 0:y.members)??$s,g=l?kt(l,"Unable to load members for this group."):null,i=t.type==="TENANT_GROUP"?"tenant":"organization",{users:S}=s.useUnifiedUsers({type:i,tenantId:t.tenantId||void 0,active:!0,limit:200}),w=v.useMemo(()=>new Set(p.map(j=>j.userId)),[p]),N=Fs(),k=qs(),C=Us(),[D,W]=v.useState(!1),[B,J]=v.useState(t.name),[re,G]=v.useState(!1),[z,H]=v.useState(t.description||""),[V,ne]=v.useState(""),[ae,oe]=v.useState(!1),ie=v.useMemo(()=>{const j=V.trim().toLowerCase();return S.filter(P=>!w.has(P.id)).filter(P=>!j||(P.name||"").toLowerCase().includes(j)||(P.email||"").toLowerCase().includes(j)).slice(0,50)},[S,w,V]),de=async()=>{const j=B.trim();if(W(!1),j.length>=3&&j!==t.name)try{await C.mutateAsync({groupId:t.id,data:{name:j}}),u()}catch{}},U=async()=>{const j=z.trim();if(G(!1),j!==(t.description||""))try{await C.mutateAsync({groupId:t.id,data:{description:j}}),u()}catch{}},K=async j=>{if(o){ne(""),oe(!1);try{await N.mutateAsync({groupId:t.id,data:{userIds:[j.id],userType:i==="tenant"?"tenant":"org"}}),x(),f()}catch{}}},Q=async j=>{if(o)try{await k.mutateAsync({groupId:t.id,data:{userIds:[j]}}),x(),f()}catch{}};let T="";try{T=xt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{T=""}return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:m,"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),D?e.jsx("input",{autoFocus:!0,value:B,onChange:j=>J(j.target.value),onBlur:de,onKeyDown:j=>{j.key==="Enter"&&de(),j.key==="Escape"&&(J(t.name),W(!1))},className:"h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"}):e.jsx("button",{type:"button",onClick:()=>{r&&(J(t.name),W(!0))},title:r?"Click to rename":t.name,disabled:!r,className:"truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",children:t.name}),e.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground",children:[e.jsx(s.UserRound,{className:"h-2.5 w-2.5"}),p.length," member",p.length===1?"":"s"]})]}),e.jsx("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:re?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:z,onChange:j=>H(j.target.value),maxLength:200,onKeyDown:j=>{j.key==="Escape"&&(H(t.description||""),G(!1)),j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&U()},placeholder:"What is this group for?",className:"block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10.5px] text-muted-foreground",children:[z.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{H(t.description||""),G(!1)},className:"h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",children:"Save"})]})]})]}):e.jsxs("button",{type:"button",onClick:()=>{r&&(H(t.description||""),G(!0))},disabled:!r,title:r?"Click to edit description":void 0,className:"block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",children:[t.description?e.jsx("p",{className:"text-[12px] leading-[1.55] text-foreground/90",children:t.description}):e.jsx("p",{className:"text-[12px] leading-[1.55] text-muted-foreground",children:r?"Add a description…":"No description"}),e.jsxs("p",{className:"mt-1 text-[10.5px] text-muted-foreground",children:[T?`Created ${T}`:"Recently created",r?" · You can edit this group":""]})]})}),o&&e.jsx(Qs,{query:V,setQuery:ne,open:ae,setOpen:oe,candidates:ie,showKindChip:!a,onAdd:K,busy:N.isPending}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:h?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(j=>e.jsx("div",{className:"h-10 animate-pulse rounded-[4px] bg-muted/60"},j))}):g?e.jsx(Et,{title:"Can't load members",message:g,onRetry:()=>x()}):p.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsx("div",{className:"text-[12px] text-foreground",children:"No members yet"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:o?"Search above to add people to this group.":"This group does not have any members."})]}):p.map(j=>{var P,F,ce,le,ue,L;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(Lt,{name:((P=j.user)==null?void 0:P.name)||((F=j.user)==null?void 0:F.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((ce=j.user)==null?void 0:ce.name)||((le=j.user)==null?void 0:le.email)||"Unknown"}),((ue=j.user)==null?void 0:ue.email)&&j.user.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:j.user.email})]}),!a&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:j.userType}),e.jsx("button",{type:"button",onClick:()=>Q(j.userId),disabled:!o||k.isPending,"aria-label":`Remove ${((L=j.user)==null?void 0:L.name)||"member"}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",children:e.jsx(d.X,{className:"h-3 w-3"})})]},j.id)})}),n&&e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:e.jsxs("button",{type:"button",onClick:b,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",children:[e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})})]})}function Ks({isTenantUser:t,tenantId:a,onCancel:r,onCreated:n}){const[o,m]=v.useState(""),[f,u]=v.useState(""),[b,y]=v.useState(null),h=_s(),l=o.trim().length>=3&&o.trim().length<=50,x=async()=>{if(!l)return;y(null);const p={name:o.trim(),description:f.trim()||void 0,type:t?"TENANT_GROUP":"ORG_GROUP",...t&&a?{tenantId:a}:{}};try{const g=await h.mutateAsync(p),i=g==null?void 0:g.id;i?n(i):r()}catch(g){y(g instanceof Error?g.message:"Failed to create group")}};return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsx(pt,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:p=>m(p.target.value),placeholder:"Marketing leads, North America sales, …",maxLength:50,className:"mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsx("div",{className:"mt-1 text-[10.5px] text-muted-foreground",children:"3–50 characters."}),e.jsxs("div",{className:"mt-4",children:[e.jsx(pt,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:f,onChange:p=>u(p.target.value),maxLength:200,placeholder:"What is this group for?",className:"mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1 flex justify-end text-[10.5px] text-muted-foreground",children:[f.length,"/200"]})]}),b&&e.jsx("div",{className:"mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300",children:b})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:[e.jsx("button",{type:"button",onClick:r,disabled:h.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:x,disabled:!l||h.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",children:h.isPending?e.jsxs(e.Fragment,{children:[e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"Create group"]})})]})]})}function Qs({query:t,setQuery:a,open:r,setOpen:n,candidates:o,showKindChip:m,onAdd:f,busy:u}){const b=v.useRef(null),y=v.useRef(null),[h,l]=v.useState(null);v.useLayoutEffect(()=>{if(!r){l(null);return}const p=()=>{const g=b.current;if(!g)return;const i=g.getBoundingClientRect(),S=240,N=window.innerHeight-i.bottom<S+16&&i.top>S;l({left:i.left,top:N?i.top-6:i.bottom+6,width:i.width,above:N})};return p(),window.addEventListener("resize",p),window.addEventListener("scroll",p,!0),()=>{window.removeEventListener("resize",p),window.removeEventListener("scroll",p,!0)}},[r,o.length]),v.useEffect(()=>{if(!r)return;const p=g=>{var S,w;const i=g.target;(S=b.current)!=null&&S.contains(i)||(w=y.current)!=null&&w.contains(i)||n(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[r,n]);const x=r&&o.length>0&&h;return e.jsxs("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{ref:b,className:"flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(us,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:t,onChange:p=>{a(p.target.value),n(!0)},onFocus:()=>n(!0),placeholder:"Add a member by name or email…",disabled:u,className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"})]}),x&&typeof document<"u"&&Zt.createPortal(e.jsx("div",{ref:y,style:{position:"fixed",left:h.left,top:h.top,width:h.width,transform:h.above?"translateY(-100%)":void 0},className:"z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",children:o.map(p=>e.jsxs("button",{type:"button",onClick:()=>f(p),className:"flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",children:[e.jsx(Lt,{name:p.name||p.email||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:p.name||p.email||"Unknown"}),p.email&&p.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:p.email})]}),m&&p.type&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:p.type==="tenant"?"tenant":"org"})]},p.id))}),document.body)]})}function kt(t,a){if(!t)return a;if(t instanceof Error){const r=t.message||"",n=r.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);return n?n[1]:r||a}return typeof t=="string"?t:a}function Et({title:t,message:a,onRetry:r}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-foreground",children:t}),e.jsx("div",{className:"max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground",children:a}),r&&e.jsx("button",{type:"button",onClick:r,className:"mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",children:"Try again"})]})}function pt({children:t}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})}function Lt({name:t}){const a=t.split(" ").map(r=>r[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(Nt,{className:"h-6 w-6 shrink-0",children:e.jsx(Ct,{className:"text-[9px] font-semibold",children:a||"?"})})}function te(t,a,r){var m,f;const n=(t.controls||[]).find(u=>u.id===r);if(n)return n.label;const o=(f=(m=d.findCardById(t,a))==null?void 0:m.controls)==null?void 0:f.find(u=>u.id===r);return(o==null?void 0:o.label)||r}function se(t,a){var r;return((r=d.findCardById(t,a))==null?void 0:r.title)||a}function Ws(t){const{errors:a,dashboard:r}=t;if(!r)return a;const n=new Map;for(const o of a){const m=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(m){const[,h,l]=m,x=`${h}:${l}:missing-metric`;n.has(x)||n.set(x,`"${se(r,h)}" has an outdated "${te(r,h,l)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const f=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(f){const[,h,l]=f,x=`${h}:${l}:missing-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" has an outdated "${te(r,h,l)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(u){const[,h,l]=u,x=`${h}:${l}:invalid-metric`;n.has(x)||n.set(x,`"${se(r,h)}" has an invalid "${te(r,h,l)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const b=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(b){const[,h,l]=b,x=`${h}:${l}:invalid-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" has an invalid "${te(r,h,l)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const y=o.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(y){const[,h,l]=y,x=`${h}:${l}:missing-temporal-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" can no longer use "${te(r,h,l)}" for time grain because the card does not currently group by a date field.`);continue}n.set(o,o)}return Array.from(n.values())}function Js(t,a){return typeof t=="boolean"?t:typeof a=="boolean"?a:!0}function ht(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function Xs(){var tt,st,rt,nt,at,ot,it;O.useExportRecovery(),O.useExportPolling();const{authToken:t,tokenProps:a,id:r,showBriefings:n}=s.useSemaphorContext(),{isLocalDev:o}=s.useDashboardPreferences(),{openBrandStudioPreview:m}=s.useBrandStudioPreview(),{permissions:f}=js(),u=s.useHasDashboardId(),{isLoading:b}=s.useDashboardQuery(),y=d.useDashboardStore(c=>c.theme),h=d.useDashboardStore(c=>c.isDownloadingPdf),l=d.useDashboardStore(c=>c.dashboardAssistantDraftScopeKey),x=d.useDashboardStore(c=>c.lenses),p=d.useDashboardStore(c=>c.selectedLensId),g=x==null?void 0:x.find(c=>c.id===p),i=d.useDashboardStore(c=>c.dashboard),S=d.useDashboardStore(c=>c.selectedSheetId),w=(tt=i==null?void 0:i.sheets)==null?void 0:tt.find(c=>c.id===S),N=d.isDocumentSheet(w),k=N?(st=w==null?void 0:w.document)==null?void 0:st.page:void 0,C=d.useDashboardStore(c=>c.isDashboardEditing),{setDashboardTitle:D}=d.useDashboardStore(c=>c.actions),[W,B]=v.useState(!1),[J,re]=v.useState(!1),[G,z]=v.useState(!1),[H,V]=v.useState(!1),[ne,ae]=v.useState(!1),[oe,ie]=v.useState(!1),[de,U]=v.useState(!1),[K,Q]=v.useState(null),[T,j]=v.useState([]),[P,F]=v.useState(!1),ce=d.useDashboardStore(c=>c.isDashboardPanelOpen),le=d.useDashboardStore(c=>c.actions.setIsDashboardPanelOpen),ue=d.useDashboardStore(c=>c.filterValues),L=d.useDashboardStore(c=>c.isVisualEditing);d.useEditorStore(c=>c.card);const X=s.useManagementStore(c=>c.selectedDashboard),me=s.useManagementStore(c=>c.initialDashboard);s.useManagementStore(c=>c.selectedVisual),d.useDashboardStore(c=>c.selectedFrameId),d.useEditorStore(c=>c.frame);const pe=X?(nt=X==null?void 0:X.permissions)==null?void 0:nt.canEdit:(rt=me==null?void 0:me.permissions)==null?void 0:rt.canEdit,Be=d.useDashboardStore(c=>c.showDashboardJSON),Ne=d.useDashboardStore(c=>c.onSaveFunction),{setIsDashboardEditing:Ge,setShowDashboardJSON:ze}=d.useDashboardStore(c=>c.actions),{setInitialDashboard:He,clearSelectedDashboard:Ce}=s.useManagementStore(c=>c.actions),{resources:he}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:ke}=s.useUserPreferences(),Mt=((at=ke==null?void 0:ke.preference)==null?void 0:at.defaultDashboardId)||null,{mutate:It,isPending:At}=s.useDefaultDashboardMutation(),{currentUser:Pt}=s.useCurrentUserInfo(),Ot=s.canUserManageGroups(Pt),R=X||me,Ve=R?{id:R.id,title:(i==null?void 0:i.title)||R.title||"Dashboard"}:null,{handleAddNewFrame:Rt}=s.useAddNewFrame(),[Ee,Le]=v.useState(!1),[_t,Y]=v.useState(!1),[Me,xe]=v.useState("close"),Z=s.useUpdateResource(s.ResourceType.DASHBOARD),[A,fe]=v.useState(null),Ut=async(c,M)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:c,previousTitle:M}),Z.mutate({resourceId:i.id,data:{title:c}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:_=>{console.error("Failed to update dashboard title:",_),s.ue.error("Failed to update dashboard title"),D(M)}})};v.useEffect(()=>{if(he&&he.length>0){const c=i==null?void 0:i.id;if(c){const M=he.find(_=>_.id===c);M&&He(M)}}},[he,i==null?void 0:i.id,He]);const ee=a.orgUserId||a.tenantId,Ie=v.useMemo(()=>Ys({accessToken:t==null?void 0:t.accessToken,dashboardId:(i==null?void 0:i.id)||r||a.dashboard_id,selectedSheetId:N?S:void 0,pageSize:k==null?void 0:k.size,orientation:k==null?void 0:k.orientation,theme:y}),[t==null?void 0:t.accessToken,r,i==null?void 0:i.id,N,k==null?void 0:k.orientation,k==null?void 0:k.size,S,y,a.dashboard_id]),Ke=C&&!L&&ee&&pe,{setDashboard:Qe}=d.useDashboardStore(c=>c.actions),We=d.useDashboardStore(c=>c.semanticExecutionPayload),Tt=()=>{Ge(!0)},Ae=()=>{Ge(!1),ze(!1),fe(null)};v.useEffect(()=>{if(!C){A&&fe(null);return}A||!i||b||fe(ht(i,We))},[i,A,C,b,We]);const ge=(A==null?void 0:A.dashboard)??null,{isDirty:Je,isDirtyPending:Ft,resetDirty:be}=ts.useDebouncedDirtyCheck(i,ge,300,1e3,Re.serializeDashboardForDirtyCheck),Xe=v.useCallback(()=>ge?Re.serializeDashboardForDirtyCheck(i)!==Re.serializeDashboardForDirtyCheck(ge):!1,[i,ge]),Ye=Je||Ft,ve=Ee||Z.isPending,qt=()=>{Xe()?(xe("close"),Y(!0)):(Ae(),be())},$t=async()=>{await Pe({closeAfterSave:!0,navigateHomeAfterSave:Me==="home"})},Bt=()=>{A&&Qe(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),Ae(),Me==="home"&&Ce(),xe("close"),Y(!1),be()},Gt=()=>{A&&(Qe(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),be())},zt=()=>{if(C&&Xe()){xe("home"),Y(!0);return}Ce()};async function Pe(c){const M=d.useDashboardStore.getState().dashboard;if(!M)return;const _=(c==null?void 0:c.closeAfterSave)??P,Jt=(c==null?void 0:c.navigateHomeAfterSave)??!1;F(_),_&&Y(!1);const Xt=s.cloneDeep(M);U(!0),Q(null),j([]),Le(!0);const Yt={template:M};Z.mutate({resourceId:M.id,data:Yt},{onSuccess:I=>{var je,Se,dt;const $=(I==null?void 0:I.id)||((je=I==null?void 0:I.dashboard)==null?void 0:je.id)||((Se=I==null?void 0:I.resource)==null?void 0:Se.id)||((dt=I==null?void 0:I.template)==null?void 0:dt.id)||null;if(!M.id&&$){const Oe=d.useAIInteractionStore.getState(),we=Oe.pendingDashboardDraftMigration;(we==null?void 0:we.scopeKey)===l?Oe.actions.setPendingDashboardDraftMigrationExpectedDashboardId($):we&&Oe.actions.clearPendingDashboardDraftMigration()}Le(!1),s.ue.success("Dashboard saved!"),fe(ht(Xt,d.useDashboardStore.getState().semanticExecutionPayload)),U(!1),F(!1),_&&(Ae(),be(),Jt&&Ce()),xe("close")},onError:I=>{Le(!1),Q("Failed to save dashboard. Please try again.");const $=I.details,je=Array.isArray($==null?void 0:$.errors)?($.errors||[]).filter(Se=>typeof Se=="string"):[];j(Ws({errors:je,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Ht(){if(B(!0),!p||!g)return;const c=d.useDashboardStore.getState().dashboard;if(!c){B(!1);return}const M=JSON.stringify(c),_={...g,template:M,filterValues:ue};await Fe(a.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),Ne==null||Ne(c),B(!1)}const Ze=(g==null?void 0:g.name)||i.title;Z.isPending&&console.log("Title during update:",{title:Ze,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:g==null?void 0:g.name});const et=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail,Vt=!!et&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl),Kt=u,q=(i==null?void 0:i.id)||null,Qt=Js((ot=a.config)==null?void 0:ot.showBriefings,n),ye=!!q&&Mt===q,Wt=()=>{q&&It({dashboardId:ye?null:q})};return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[et&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{le(!ce)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(os,{className:"h-3.5 w-3.5"})}),Kt&&!L&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:zt,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!L&&u&&(b?e.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:Ze||"Untitled Dashboard",onSave:c=>{console.log("EditableText onSave called:",{newTitle:c,canEditDashboard:pe,dashboardId:i==null?void 0:i.id});const M=(i==null?void 0:i.title)||"";D(c),Ut(c,M)},isEditable:pe&&!g,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:Z.isPending}),Vt&&q&&e.jsx(d.TooltipProvider,{children:e.jsxs(d.Tooltip,{children:[e.jsx(d.TooltipTrigger,{asChild:!0,children:e.jsx(d.Button,{variant:"ghost",size:"xs",onClick:Wt,disabled:At||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0","aria-label":ye?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:d.cn("h-3.5 w-3.5 transition-colors",ye?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(d.TooltipContent,{children:e.jsx("p",{children:ye?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[L&&e.jsxs(e.Fragment,{children:[e.jsx(O.AdvancedModeToggle,{}),e.jsx(O.VisualEditingControls,{})]}),!L&&u&&((it=R==null?void 0:R.permissions)==null?void 0:it.canShare)&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:()=>re(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!L&&!C&&u&&q&&Qt&&e.jsx(O.DashboardBriefingLauncher,{dashboardId:q,dashboardTitle:(i==null?void 0:i.title)||(R==null?void 0:R.title)}),!L&&C&&f.canUseFilters&&u&&e.jsx(O.DashboardFilterControlsLauncher,{}),C&&!L&&ee&&g&&o&&u&&e.jsxs(d.Button,{variant:"secondary",size:"xs",disabled:W,onClick:Ht,children:[e.jsx(ct.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),C&&!L&&u&&!N&&e.jsxs(d.Button,{variant:"outline",size:"xs",disabled:!C,onClick:()=>Rt(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!L&&!C&&pe&&u&&e.jsxs(d.Button,{size:"xs",onClick:Tt,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Ke&&u&&Je&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:Gt,disabled:ve,children:[e.jsx(O.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Ke&&u&&e.jsxs(d.Button,{size:"xs",className:d.cn(!Ye&&"opacity-60"),disabled:ve||!Ye,onClick:()=>Pe(),children:[ve?e.jsx(d.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ct.Save,{className:"h-3.5 w-3.5"}),ve?"Saving...":"Save"]}),C&&!L&&u&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:qt,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!L&&u&&e.jsx("div",{className:"ml-2",children:e.jsx(O.NotificationBell,{})}),!L&&o&&e.jsx(xs,{}),!L&&u&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:h,onSelect:()=>ie(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(s.DropdownMenuSeparator,{}),Ot&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>z(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>V(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),o&&u&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var c;t!=null&&t.accessToken&&((c=navigator==null?void 0:navigator.clipboard)!=null&&c.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),N&&e.jsxs(s.DropdownMenuItem,{disabled:!Ie,onSelect:()=>{var c;if(!Ie){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(c=navigator==null?void 0:navigator.clipboard)!=null&&c.writeText?navigator.clipboard.writeText(Ie).then(()=>s.ue.success("Local document PDF URL copied to clipboard")).catch(()=>s.ue.error("Unable to copy local document PDF URL")):s.ue.error("Clipboard not available")},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>d.invalidateToken(a.apiServiceUrl),children:[e.jsx(cs,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:m,children:[e.jsx(ss.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ze(!Be),children:[e.jsx(rs.Braces,{className:"h-3.5 w-3.5"}),Be?"Hide dashboard JSON":"Show dashboard JSON"]}),ee&&C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ae(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),ee&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(as,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(ys,{})})]})]})]})]}),J&&Ve&&e.jsx(s.ShareDialog,{resource:Ve,resourceType:s.ResourceType.DASHBOARD,onClose:()=>re(!1)}),e.jsx(Bs,{open:G,onOpenChange:z}),e.jsx(es.CalendarPreferencesDialog,{open:H,onOpenChange:V}),o&&ee&&u&&e.jsx(vs,{open:ne,onOpenChange:ae}),u&&e.jsx(s.DownloadPdf,{open:oe,onOpenChange:ie}),e.jsx(s.AlertDialog,{open:de,onOpenChange:c=>{!c&&Ee&&!K||(U(c),c||(Q(null),j([]),F(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:K?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:K?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),T.length>0&&e.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:T.slice(0,5).map(c=>e.jsx("li",{children:c},c))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:K?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{U(!1),Q(null),j([]),F(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Pe({closeAfterSave:P,navigateHomeAfterSave:Me==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(d.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(O.UnsavedChangesAlert,{open:_t,onOpenChange:c=>{Y(c)},onSave:$t,onDiscard:Bt,isSaving:Ee,saveLabel:"Save",discardLabel:"Discard"})]})]})}function Ys({accessToken:t,dashboardId:a,selectedSheetId:r,pageSize:n,orientation:o,theme:m}){if(!t||!r)return null;const f=new URL("http://localhost:5173/print-document");f.searchParams.set("token",t),a&&f.searchParams.set("dashboardId",a),f.searchParams.set("selectedSheetId",r),m&&f.searchParams.set("theme",m);const u=new URL("http://127.0.0.1:3002/");return u.searchParams.set("pdfMode","document"),u.searchParams.set("pageSize",n||"letter"),u.searchParams.set("orientation",o||"portrait"),u.searchParams.set("url",f.toString()),u.toString()}exports.default=Xs;
52
+ */var lt;function ms(){return lt||(lt=1,process.env.NODE_ENV!=="production"&&function(){function t(p,g){return p===g&&(p!==0||1/p===1/g)||p!==p&&g!==g}function a(p,g){h||o.startTransition===void 0||(h=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var i=g();if(!l){var S=g();m(i,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}S=f({inst:{value:i,getSnapshot:g}});var w=S[0].inst,N=S[1];return b(function(){w.value=i,w.getSnapshot=g,r(w)&&N({inst:w})},[p,i,g]),u(function(){return r(w)&&N({inst:w}),p(function(){r(w)&&N({inst:w})})},[p]),y(i),i}function r(p){var g=p.getSnapshot;p=p.value;try{var i=g();return!m(p,i)}catch{return!0}}function n(p,g){return g()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var o=v,m=typeof Object.is=="function"?Object.is:t,f=o.useState,u=o.useEffect,b=o.useLayoutEffect,y=o.useDebugValue,h=!1,l=!1,x=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?n:a;Ue.useSyncExternalStore=o.useSyncExternalStore!==void 0?o.useSyncExternalStore:x,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ue}process.env.NODE_ENV==="production"?Te.exports=us():Te.exports=ms();var ps=Te.exports;const De=["light","dark","system"];function hs(){const{theme:t,setTheme:a}=s.useTheme(),r=d.useDashboardStore(f=>f.actions.setDashboardTheme);function n(){const f=De.includes(t)?t:"system",u=De[(De.indexOf(f)+1)%De.length];a(u),r(u)}const o=t==="light"?cs:t==="dark"?is:os,m=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(d.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,"aria-label":m,title:m,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function xs(t,a,r,n,o){if(!o)return null;const m=JSON.stringify(r),f=`${t}/v1/lens`;return await d.postRequest(f,o,{name:a,template:m,filterValues:n,operation:"create"})}async function Fe(t,a,r){if(!r)return null;const{id:n,template:o,filterValues:m,isDefault:f,shared:u}=a,b=`${t}/v1/lens`;return await d.postRequest(b,r,{lensId:n,template:o,filterValues:m,isDefault:f,shared:u,operation:"update"})}async function fs(t,a,r){if(!r)return null;const n=`${t}/v1/lens`;return await d.postRequest(n,r,{operation:"delete",lensId:a})}const gs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function bs({open:t,onOpenChange:a}={}){const[r,n]=v.useState(""),[o,m]=v.useState(!1),f=d.useDashboardStore(D=>D.lenses),{setLenses:u,setSelectedLensId:b}=d.useDashboardActions(),[y,h]=v.useState(!1),[l,x]=v.useState(!1),p=t!==void 0,g=p?t:l,i=D=>{p||x(D),a==null||a(D)},S=d.useDashboardStore(D=>D.dashboard),w=d.useDashboardStore(D=>D.filterValues),{authToken:N,tokenProps:k}=s.useSemaphorContext();async function C(){h(!0);const D=await xs(k.apiServiceUrl,r,S,w,N==null?void 0:N.accessToken);D&&(u([...f||[],D]),b(D.id),i(!1)),h(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:i,children:[p?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(d.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(d.Label,{htmlFor:"lens-name",className:gs,children:"Name"}),e.jsx(d.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:D=>n(D.target.value)}),o&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(d.Button,{variant:"outline",size:"xs",onClick:()=>i(!1),children:"Cancel"}),e.jsx(d.Button,{size:"xs",type:"submit",onClick:C,disabled:y||!r.trim(),children:y?"Creating…":"Create"})]})]})]})}function vs({includeLabel:t=!1}={}){const a=d.useDashboardStore(h=>h.lenses),r=d.useDashboardStore(h=>h.selectedLensId),{setLenses:n,setSelectedLensId:o}=d.useDashboardActions(),{authToken:m,tokenProps:f}=s.useSemaphorContext();async function u(h){o(h)}async function b(h){if(await fs(f.apiServiceUrl,h,m==null?void 0:m.accessToken)){const x=a==null?void 0:a.filter(p=>p.id!==h);n(x||[]),o("original")}}async function y(h){const l=a==null?void 0:a.map(g=>g.id===h.id?{...g,isDefault:!h.isDefault}:{...g,isDefault:!1});n(l||[]);const x={...h,isDefault:!h.isDefault};await Fe(f.apiServiceUrl,x,m==null?void 0:m.accessToken);const p=a==null?void 0:a.find(g=>g.isDefault);if(p&&p.id!==h.id){const g={...p,isDefault:!1};await Fe(f.apiServiceUrl,g,m==null?void 0:m.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:u,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:l=>{l.preventDefault(),y(h)},className:d.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:l=>{l.preventDefault(),b(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})}function ys(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:r,userContext:n}=s.useCurrentUserInfo(),o=v.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),m=v.useMemo(()=>u=>o&&o[u]!==void 0&&o[u]===!1?!1:a(u),[o,a,t]),f=v.useMemo(()=>{var u,b,y,h,l;return{canEdit:((u=n==null?void 0:n.permissions)==null?void 0:u.canEdit)??s.canUserEdit(r),canUseFilters:((b=n==null?void 0:n.permissions)==null?void 0:b.canEdit)??s.canUserUseFilters(r),canManageDashboards:((y=n==null?void 0:n.permissions)==null?void 0:y.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((h=n==null?void 0:n.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((l=n==null?void 0:n.permissions)==null?void 0:l.canEdit)??s.canUserAccessVisuals(r)}},[r,n]);return{displayPreferences:t,shouldShowElement:m,permissions:f,currentUser:r}}function js(t,a=[]){let r=[];function n(m,f){const u=E.createContext(f);u.displayName=m+"Context";const b=r.length;r=[...r,f];const y=l=>{var w;const{scope:x,children:p,...g}=l,i=((w=x==null?void 0:x[t])==null?void 0:w[b])||u,S=E.useMemo(()=>g,Object.values(g));return e.jsx(i.Provider,{value:S,children:p})};y.displayName=m+"Provider";function h(l,x){var i;const p=((i=x==null?void 0:x[t])==null?void 0:i[b])||u,g=E.useContext(p);if(g)return g;if(f!==void 0)return f;throw new Error(`\`${l}\` must be used within \`${m}\``)}return[y,h]}const o=()=>{const m=r.map(f=>E.createContext(f));return function(u){const b=(u==null?void 0:u[t])||m;return E.useMemo(()=>({[`__scope${t}`]:{...u,[t]:b}}),[u,b])}};return o.scopeName=t,[n,Ss(o,...a)]}function Ss(...t){const a=t[0];if(t.length===1)return a;const r=()=>{const n=t.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(m){const f=n.reduce((u,{useScope:b,scopeName:y})=>{const l=b(m)[`__scope${y}`];return{...u,...l}},{});return E.useMemo(()=>({[`__scope${a.scopeName}`]:f}),[f])}};return r.scopeName=a.scopeName,r}var ws=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],qe=ws.reduce((t,a)=>{const r=d.createSlot(`Primitive.${a}`),n=E.forwardRef((o,m)=>{const{asChild:f,...u}=o,b=f?r:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(b,{...u,ref:m})});return n.displayName=`Primitive.${a}`,{...t,[a]:n}},{});function Ds(){return ps.useSyncExternalStore(Ns,()=>!0,()=>!1)}function Ns(){return()=>{}}var $e="Avatar",[Cs]=js($e),[ks,xt]=Cs($e),ft=E.forwardRef((t,a)=>{const{__scopeAvatar:r,...n}=t,[o,m]=E.useState("idle");return e.jsx(ks,{scope:r,imageLoadingStatus:o,onImageLoadingStatusChange:m,children:e.jsx(qe.span,{...n,ref:a})})});ft.displayName=$e;var gt="AvatarImage",bt=E.forwardRef((t,a)=>{const{__scopeAvatar:r,src:n,onLoadingStatusChange:o=()=>{},...m}=t,f=xt(gt,r),u=Es(n,m),b=d.useCallbackRef(y=>{o(y),f.onImageLoadingStatusChange(y)});return d.useLayoutEffect2(()=>{u!=="idle"&&b(u)},[u,b]),u==="loaded"?e.jsx(qe.img,{...m,ref:a,src:n}):null});bt.displayName=gt;var vt="AvatarFallback",yt=E.forwardRef((t,a)=>{const{__scopeAvatar:r,delayMs:n,...o}=t,m=xt(vt,r),[f,u]=E.useState(n===void 0);return E.useEffect(()=>{if(n!==void 0){const b=window.setTimeout(()=>u(!0),n);return()=>window.clearTimeout(b)}},[n]),f&&m.imageLoadingStatus!=="loaded"?e.jsx(qe.span,{...o,ref:a}):null});yt.displayName=vt;function ut(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Es(t,{referrerPolicy:a,crossOrigin:r}){const n=Ds(),o=E.useRef(null),m=n?(o.current||(o.current=new window.Image),o.current):null,[f,u]=E.useState(()=>ut(m,t));return d.useLayoutEffect2(()=>{u(ut(m,t))},[m,t]),d.useLayoutEffect2(()=>{const b=l=>()=>{u(l)};if(!m)return;const y=b("loaded"),h=b("error");return m.addEventListener("load",y),m.addEventListener("error",h),a&&(m.referrerPolicy=a),typeof r=="string"&&(m.crossOrigin=r),()=>{m.removeEventListener("load",y),m.removeEventListener("error",h)}},[m,r,a]),f}var jt=ft,St=bt,wt=yt;const Dt=E.forwardRef(({className:t,...a},r)=>e.jsx(jt,{ref:r,className:d.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));Dt.displayName=jt.displayName;const Ls=E.forwardRef(({className:t,...a},r)=>e.jsx(St,{ref:r,className:d.cn("aspect-square h-full w-full",t),...a}));Ls.displayName=St.displayName;const Nt=E.forwardRef(({className:t,...a},r)=>e.jsx(wt,{ref:r,className:d.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));Nt.displayName=wt.displayName;const Ms=async(t,a,r)=>{const n=`${t}/management/v1/groups`;return await d.postRequestRegular(n,a,r)},Is=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}`;return d.requestJsonRegular(o,a,"PATCH",n)},As=async(t,a,r)=>{const n=`${t}/management/v1/groups/${r}`;await d.requestJsonRegular(n,a,"DELETE")},Ps=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;return await d.postRequestRegular(o,a,n)},Os=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;await d.requestJsonRegular(o,a,"DELETE",n)};function Rs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:n=>Ms(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:n=>{console.error("Failed to create group:",n),s.ue.error("Failed to create group",{description:d.getRequestErrorMessage(n,"Failed to create group")})}})}function _s(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Is(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group updated successfully")},onError:n=>{console.error("Failed to update group:",n),s.ue.error("Failed to update group",{description:d.getRequestErrorMessage(n,"Failed to update group")})}})}function Us(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:n=>As(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",o]}),s.ue.success("Group deleted successfully")},onError:n=>{console.error("Failed to delete group:",n),s.ue.error("Failed to delete group",{description:d.getRequestErrorMessage(n,"Failed to delete group")})}})}function Ts(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Ps(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["group-members",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:n=>{console.error("Failed to add group members:",n),s.ue.error("Failed to add members",{description:d.getRequestErrorMessage(n,"Failed to add members")})}})}function Fs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Os(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",n,o),onSuccess:(n,o)=>{r.invalidateQueries({queryKey:["group",o.groupId]}),r.invalidateQueries({queryKey:["group-members",o.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:n=>{console.error("Failed to remove group members:",n),s.ue.error("Failed to remove members",{description:d.getRequestErrorMessage(n,"Failed to remove members")})}})}const qs=[];function $s({open:t,onOpenChange:a}){var N,k,C;const{tokenProps:r}=s.useSemaphorContext(),{currentUser:n}=s.useCurrentUserInfo(),o=(n==null?void 0:n.type)==="tenant",m=r==null?void 0:r.tenantId,{groups:f,isLoading:u,error:b,refetch:y}=s.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?m:void 0,includeMembers:!1}),h=b?Ct(b,"Unable to load groups."):null,[l,x]=v.useState({kind:"list"}),[p,g]=v.useState(null),i=Us();v.useEffect(()=>{t||(x({kind:"list"}),g(null))},[t]);const S=l.kind==="members"&&f.find(D=>D.id===l.groupId)||null,w=async()=>{if(p)try{await i.mutateAsync(p.id),g(null),x({kind:"list"}),y()}catch{}};return e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0",children:[l.kind==="list"?e.jsxs("div",{className:"shrink-0 border-b border-border px-5 pt-4 pb-3.5",children:[e.jsx(s.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"Group management"}),e.jsx(s.DialogDescription,{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:"Organize people into groups for shared access."})]}):l.kind==="create"?e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:()=>x({kind:"list"}),"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium",children:"New group"}),e.jsx(s.DialogDescription,{className:"sr-only",children:"Create a new group to organize members."})]}):null,l.kind==="list"&&e.jsx(Bs,{groups:f,isLoading:u,errorMessage:h,onRetry:()=>y(),currentUserId:n==null?void 0:n.id,onOpenGroup:D=>x({kind:"members",groupId:D}),onCreate:()=>x({kind:"create"}),onDeleteRequest:D=>g(D)}),l.kind==="members"&&S&&e.jsx(Hs,{group:S,isTenantViewer:o,canEdit:((N=S.permissions)==null?void 0:N.canEdit)??S.createdBy===(n==null?void 0:n.id),canDelete:((k=S.permissions)==null?void 0:k.canDelete)??S.createdBy===(n==null?void 0:n.id),canManageMembers:((C=S.permissions)==null?void 0:C.canManageMembers)??S.createdBy===(n==null?void 0:n.id),onBack:()=>x({kind:"list"}),onMembersChanged:y,onUpdated:y,onRequestDelete:()=>g(S)},S.id),l.kind==="create"&&e.jsx(Vs,{isTenantUser:o,tenantId:m,onCancel:()=>x({kind:"list"}),onCreated:D=>{y(),x({kind:"members",groupId:D})}}),p&&e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] text-foreground",children:["Delete ",e.jsx("span",{className:"font-medium",children:p.name}),"?",e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Members lose any access granted via this group."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>g(null),disabled:i.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:w,disabled:i.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",children:[i.isPending?e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function Bs({groups:t,isLoading:a,errorMessage:r,onRetry:n,currentUserId:o,onOpenGroup:m,onCreate:f,onDeleteRequest:u}){const[b,y]=v.useState(""),h=v.useMemo(()=>t.filter(l=>!b.trim()||l.name.toLowerCase().includes(b.toLowerCase())||(l.description||"").toLowerCase().includes(b.toLowerCase())),[t,b]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(s.Search,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:b,onChange:l=>y(l.target.value),placeholder:"Search groups…",className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"}),b&&e.jsx("button",{type:"button",onClick:()=>y(""),className:"flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(d.X,{className:"h-2.5 w-2.5"})})]}),e.jsxs("button",{type:"button",onClick:f,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:a?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(l=>e.jsx("div",{className:"h-12 animate-pulse rounded-[4px] bg-muted/60"},l))}):r?e.jsx(kt,{title:"Can't load groups",message:r,onRetry:n}):h.length===0&&t.length===0?e.jsx(zs,{onCreate:f}):h.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsxs("div",{className:"text-[12px] text-foreground",children:['No groups match "',b,'"']}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Try a different search."})]}):h.map(l=>{var x;return e.jsx(Gs,{group:l,canDelete:((x=l.permissions)==null?void 0:x.canDelete)??l.createdBy===o,onClick:()=>m(l.id),onDelete:()=>u(l)},l.id)})})]})}function Gs({group:t,canDelete:a,onClick:r,onDelete:n}){let o="";try{o=ht.format(new Date(t.createdAt),"MMM d, yyyy")}catch{o=""}return e.jsxs("button",{type:"button",onClick:r,className:"group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground",children:e.jsx(O.UsersRound,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.UserRound,{className:"h-2.5 w-2.5"}),t.memberCount," member",t.memberCount===1?"":"s"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-2.5 w-2.5"}),o]})]}),t.description&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:t.description})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[a&&e.jsx("span",{role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),n()},onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),m.stopPropagation(),n())},"aria-label":`Delete ${t.name}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.Trash2,{className:"h-3 w-3"})}),e.jsx(s.ChevronRight,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]})}function zs({onCreate:t}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground",children:e.jsx(s.Users,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:"No groups yet"}),e.jsx("div",{className:"max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground",children:"Groups let you grant shared access to dashboards. Create one and add members."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]})}function Hs({group:t,isTenantViewer:a,canEdit:r,canDelete:n,canManageMembers:o,onBack:m,onMembersChanged:f,onUpdated:u,onRequestDelete:b}){const{data:y,isLoading:h,error:l,refetch:x}=s.useGroupMembers(t.id),p=(y==null?void 0:y.members)??qs,g=l?Ct(l,"Unable to load members for this group."):null,i=t.type==="TENANT_GROUP"?"tenant":"organization",{users:S}=s.useUnifiedUsers({type:i,tenantId:t.tenantId||void 0,active:!0,limit:200}),w=v.useMemo(()=>new Set(p.map(j=>j.userId)),[p]),N=Ts(),k=Fs(),C=_s(),[D,W]=v.useState(!1),[B,J]=v.useState(t.name),[re,G]=v.useState(!1),[z,H]=v.useState(t.description||""),[V,ne]=v.useState(""),[ae,oe]=v.useState(!1),ie=v.useMemo(()=>{const j=V.trim().toLowerCase();return S.filter(P=>!w.has(P.id)).filter(P=>!j||(P.name||"").toLowerCase().includes(j)||(P.email||"").toLowerCase().includes(j)).slice(0,50)},[S,w,V]),de=async()=>{const j=B.trim();if(W(!1),j.length>=3&&j!==t.name)try{await C.mutateAsync({groupId:t.id,data:{name:j}}),u()}catch{}},U=async()=>{const j=z.trim();if(G(!1),j!==(t.description||""))try{await C.mutateAsync({groupId:t.id,data:{description:j}}),u()}catch{}},K=async j=>{if(o){ne(""),oe(!1);try{await N.mutateAsync({groupId:t.id,data:{userIds:[j.id],userType:i==="tenant"?"tenant":"org"}}),x(),f()}catch{}}},Q=async j=>{if(o)try{await k.mutateAsync({groupId:t.id,data:{userIds:[j]}}),x(),f()}catch{}};let T="";try{T=ht.format(new Date(t.createdAt),"MMM d, yyyy")}catch{T=""}return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:m,"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),D?e.jsx("input",{autoFocus:!0,value:B,onChange:j=>J(j.target.value),onBlur:de,onKeyDown:j=>{j.key==="Enter"&&de(),j.key==="Escape"&&(J(t.name),W(!1))},className:"h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"}):e.jsx("button",{type:"button",onClick:()=>{r&&(J(t.name),W(!0))},title:r?"Click to rename":t.name,disabled:!r,className:"truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",children:t.name}),e.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground",children:[e.jsx(s.UserRound,{className:"h-2.5 w-2.5"}),p.length," member",p.length===1?"":"s"]})]}),e.jsx("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:re?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:z,onChange:j=>H(j.target.value),maxLength:200,onKeyDown:j=>{j.key==="Escape"&&(H(t.description||""),G(!1)),j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&U()},placeholder:"What is this group for?",className:"block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10.5px] text-muted-foreground",children:[z.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{H(t.description||""),G(!1)},className:"h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:U,className:"inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",children:"Save"})]})]})]}):e.jsxs("button",{type:"button",onClick:()=>{r&&(H(t.description||""),G(!0))},disabled:!r,title:r?"Click to edit description":void 0,className:"block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",children:[t.description?e.jsx("p",{className:"text-[12px] leading-[1.55] text-foreground/90",children:t.description}):e.jsx("p",{className:"text-[12px] leading-[1.55] text-muted-foreground",children:r?"Add a description…":"No description"}),e.jsxs("p",{className:"mt-1 text-[10.5px] text-muted-foreground",children:[T?`Created ${T}`:"Recently created",r?" · You can edit this group":""]})]})}),o&&e.jsx(Ks,{query:V,setQuery:ne,open:ae,setOpen:oe,candidates:ie,showKindChip:!a,onAdd:K,busy:N.isPending}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:h?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(j=>e.jsx("div",{className:"h-10 animate-pulse rounded-[4px] bg-muted/60"},j))}):g?e.jsx(kt,{title:"Can't load members",message:g,onRetry:()=>x()}):p.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsx("div",{className:"text-[12px] text-foreground",children:"No members yet"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:o?"Search above to add people to this group.":"This group does not have any members."})]}):p.map(j=>{var P,F,ce,le,ue,L;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(Et,{name:((P=j.user)==null?void 0:P.name)||((F=j.user)==null?void 0:F.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((ce=j.user)==null?void 0:ce.name)||((le=j.user)==null?void 0:le.email)||"Unknown"}),((ue=j.user)==null?void 0:ue.email)&&j.user.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:j.user.email})]}),!a&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:j.userType}),e.jsx("button",{type:"button",onClick:()=>Q(j.userId),disabled:!o||k.isPending,"aria-label":`Remove ${((L=j.user)==null?void 0:L.name)||"member"}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",children:e.jsx(d.X,{className:"h-3 w-3"})})]},j.id)})}),n&&e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:e.jsxs("button",{type:"button",onClick:b,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",children:[e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})})]})}function Vs({isTenantUser:t,tenantId:a,onCancel:r,onCreated:n}){const[o,m]=v.useState(""),[f,u]=v.useState(""),[b,y]=v.useState(null),h=Rs(),l=o.trim().length>=3&&o.trim().length<=50,x=async()=>{if(!l)return;y(null);const p={name:o.trim(),description:f.trim()||void 0,type:t?"TENANT_GROUP":"ORG_GROUP",...t&&a?{tenantId:a}:{}};try{const g=await h.mutateAsync(p),i=g==null?void 0:g.id;i?n(i):r()}catch(g){y(g instanceof Error?g.message:"Failed to create group")}};return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsx(mt,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:p=>m(p.target.value),placeholder:"Marketing leads, North America sales, …",maxLength:50,className:"mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsx("div",{className:"mt-1 text-[10.5px] text-muted-foreground",children:"3–50 characters."}),e.jsxs("div",{className:"mt-4",children:[e.jsx(mt,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:f,onChange:p=>u(p.target.value),maxLength:200,placeholder:"What is this group for?",className:"mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1 flex justify-end text-[10.5px] text-muted-foreground",children:[f.length,"/200"]})]}),b&&e.jsx("div",{className:"mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300",children:b})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:[e.jsx("button",{type:"button",onClick:r,disabled:h.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:x,disabled:!l||h.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",children:h.isPending?e.jsxs(e.Fragment,{children:[e.jsx(d.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"Create group"]})})]})]})}function Ks({query:t,setQuery:a,open:r,setOpen:n,candidates:o,showKindChip:m,onAdd:f,busy:u}){const b=v.useRef(null),y=v.useRef(null),[h,l]=v.useState(null);v.useLayoutEffect(()=>{if(!r){l(null);return}const p=()=>{const g=b.current;if(!g)return;const i=g.getBoundingClientRect(),S=240,N=window.innerHeight-i.bottom<S+16&&i.top>S;l({left:i.left,top:N?i.top-6:i.bottom+6,width:i.width,above:N})};return p(),window.addEventListener("resize",p),window.addEventListener("scroll",p,!0),()=>{window.removeEventListener("resize",p),window.removeEventListener("scroll",p,!0)}},[r,o.length]),v.useEffect(()=>{if(!r)return;const p=g=>{var S,w;const i=g.target;(S=b.current)!=null&&S.contains(i)||(w=y.current)!=null&&w.contains(i)||n(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[r,n]);const x=r&&o.length>0&&h;return e.jsxs("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{ref:b,className:"flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(ls,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:t,onChange:p=>{a(p.target.value),n(!0)},onFocus:()=>n(!0),placeholder:"Add a member by name or email…",disabled:u,className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"})]}),x&&typeof document<"u"&&Yt.createPortal(e.jsx("div",{ref:y,style:{position:"fixed",left:h.left,top:h.top,width:h.width,transform:h.above?"translateY(-100%)":void 0},className:"z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",children:o.map(p=>e.jsxs("button",{type:"button",onClick:()=>f(p),className:"flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",children:[e.jsx(Et,{name:p.name||p.email||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:p.name||p.email||"Unknown"}),p.email&&p.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:p.email})]}),m&&p.type&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:p.type==="tenant"?"tenant":"org"})]},p.id))}),document.body)]})}function Ct(t,a){if(!t)return a;if(t instanceof Error){const r=t.message||"",n=r.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);return n?n[1]:r||a}return typeof t=="string"?t:a}function kt({title:t,message:a,onRetry:r}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-foreground",children:t}),e.jsx("div",{className:"max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground",children:a}),r&&e.jsx("button",{type:"button",onClick:r,className:"mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",children:"Try again"})]})}function mt({children:t}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})}function Et({name:t}){const a=t.split(" ").map(r=>r[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(Dt,{className:"h-6 w-6 shrink-0",children:e.jsx(Nt,{className:"text-[9px] font-semibold",children:a||"?"})})}function te(t,a,r){var m,f;const n=(t.controls||[]).find(u=>u.id===r);if(n)return n.label;const o=(f=(m=d.findCardById(t,a))==null?void 0:m.controls)==null?void 0:f.find(u=>u.id===r);return(o==null?void 0:o.label)||r}function se(t,a){var r;return((r=d.findCardById(t,a))==null?void 0:r.title)||a}function Qs(t){const{errors:a,dashboard:r}=t;if(!r)return a;const n=new Map;for(const o of a){const m=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(m){const[,h,l]=m,x=`${h}:${l}:missing-metric`;n.has(x)||n.set(x,`"${se(r,h)}" has an outdated "${te(r,h,l)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const f=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(f){const[,h,l]=f,x=`${h}:${l}:missing-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" has an outdated "${te(r,h,l)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(u){const[,h,l]=u,x=`${h}:${l}:invalid-metric`;n.has(x)||n.set(x,`"${se(r,h)}" has an invalid "${te(r,h,l)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const b=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(b){const[,h,l]=b,x=`${h}:${l}:invalid-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" has an invalid "${te(r,h,l)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const y=o.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(y){const[,h,l]=y,x=`${h}:${l}:missing-temporal-group-by`;n.has(x)||n.set(x,`"${se(r,h)}" can no longer use "${te(r,h,l)}" for time grain because the card does not currently group by a date field.`);continue}n.set(o,o)}return Array.from(n.values())}function Ws(t,a){return typeof t=="boolean"?t:typeof a=="boolean"?a:!0}function pt(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function Js(){var tt,st,rt,nt,at,ot,it;O.useExportRecovery(),O.useExportPolling();const{authToken:t,tokenProps:a,id:r,showBriefings:n}=s.useSemaphorContext(),{isLocalDev:o}=s.useDashboardPreferences(),{openBrandStudioPreview:m}=s.useBrandStudioPreview(),{permissions:f}=ys(),u=s.useHasDashboardId(),{isLoading:b}=s.useDashboardQuery(),y=d.useDashboardStore(c=>c.theme),h=d.useDashboardStore(c=>c.isDownloadingPdf),l=d.useDashboardStore(c=>c.dashboardAssistantDraftScopeKey),x=d.useDashboardStore(c=>c.lenses),p=d.useDashboardStore(c=>c.selectedLensId),g=x==null?void 0:x.find(c=>c.id===p),i=d.useDashboardStore(c=>c.dashboard),S=d.useDashboardStore(c=>c.selectedSheetId),w=(tt=i==null?void 0:i.sheets)==null?void 0:tt.find(c=>c.id===S),N=d.isDocumentSheet(w),k=N?(st=w==null?void 0:w.document)==null?void 0:st.page:void 0,C=d.useDashboardStore(c=>c.isDashboardEditing),{setDashboardTitle:D}=d.useDashboardStore(c=>c.actions),[W,B]=v.useState(!1),[J,re]=v.useState(!1),[G,z]=v.useState(!1),[H,V]=v.useState(!1),[ne,ae]=v.useState(!1),[oe,ie]=v.useState(!1),[de,U]=v.useState(!1),[K,Q]=v.useState(null),[T,j]=v.useState([]),[P,F]=v.useState(!1),ce=d.useDashboardStore(c=>c.isDashboardPanelOpen),le=d.useDashboardStore(c=>c.actions.setIsDashboardPanelOpen),ue=d.useDashboardStore(c=>c.filterValues),L=d.useDashboardStore(c=>c.isVisualEditing);d.useEditorStore(c=>c.card);const X=s.useManagementStore(c=>c.selectedDashboard),me=s.useManagementStore(c=>c.initialDashboard);s.useManagementStore(c=>c.selectedVisual),d.useDashboardStore(c=>c.selectedFrameId),d.useEditorStore(c=>c.frame);const pe=X?(nt=X==null?void 0:X.permissions)==null?void 0:nt.canEdit:(rt=me==null?void 0:me.permissions)==null?void 0:rt.canEdit,Be=d.useDashboardStore(c=>c.showDashboardJSON),Ne=d.useDashboardStore(c=>c.onSaveFunction),{setIsDashboardEditing:Ge,setShowDashboardJSON:ze}=d.useDashboardStore(c=>c.actions),{setInitialDashboard:He,clearSelectedDashboard:Ce}=s.useManagementStore(c=>c.actions),{resources:he}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:ke}=s.useUserPreferences(),Lt=((at=ke==null?void 0:ke.preference)==null?void 0:at.defaultDashboardId)||null,{mutate:Mt,isPending:It}=s.useDefaultDashboardMutation(),{currentUser:At}=s.useCurrentUserInfo(),Pt=s.canUserManageGroups(At),R=X||me,Ve=R?{id:R.id,title:(i==null?void 0:i.title)||R.title||"Dashboard"}:null,{handleAddNewFrame:Ot}=s.useAddNewFrame(),[Ee,Le]=v.useState(!1),[Rt,Y]=v.useState(!1),[Me,xe]=v.useState("close"),Z=s.useUpdateResource(s.ResourceType.DASHBOARD),[A,fe]=v.useState(null),_t=async(c,M)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:c,previousTitle:M}),Z.mutate({resourceId:i.id,data:{title:c}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:_=>{console.error("Failed to update dashboard title:",_),s.ue.error("Failed to update dashboard title"),D(M)}})};v.useEffect(()=>{if(he&&he.length>0){const c=i==null?void 0:i.id;if(c){const M=he.find(_=>_.id===c);M&&He(M)}}},[he,i==null?void 0:i.id,He]);const ee=a.orgUserId||a.tenantId,Ie=v.useMemo(()=>Xs({accessToken:t==null?void 0:t.accessToken,dashboardId:(i==null?void 0:i.id)||r||a.dashboard_id,selectedSheetId:N?S:void 0,pageSize:k==null?void 0:k.size,orientation:k==null?void 0:k.orientation,theme:y}),[t==null?void 0:t.accessToken,r,i==null?void 0:i.id,N,k==null?void 0:k.orientation,k==null?void 0:k.size,S,y,a.dashboard_id]),Ke=C&&!L&&ee&&pe,{setDashboard:Qe}=d.useDashboardStore(c=>c.actions),We=d.useDashboardStore(c=>c.semanticExecutionPayload),Ut=()=>{Ge(!0)},Ae=()=>{Ge(!1),ze(!1),fe(null)};v.useEffect(()=>{if(!C){A&&fe(null);return}A||!i||b||fe(pt(i,We))},[i,A,C,b,We]);const ge=(A==null?void 0:A.dashboard)??null,{isDirty:Je,isDirtyPending:Tt,resetDirty:be}=es.useDebouncedDirtyCheck(i,ge,300,1e3,Re.serializeDashboardForDirtyCheck),Xe=v.useCallback(()=>ge?Re.serializeDashboardForDirtyCheck(i)!==Re.serializeDashboardForDirtyCheck(ge):!1,[i,ge]),Ye=Je||Tt,ve=Ee||Z.isPending,Ft=()=>{Xe()?(xe("close"),Y(!0)):(Ae(),be())},qt=async()=>{await Pe({closeAfterSave:!0,navigateHomeAfterSave:Me==="home"})},$t=()=>{A&&Qe(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),Ae(),Me==="home"&&Ce(),xe("close"),Y(!1),be()},Bt=()=>{A&&(Qe(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),be())},Gt=()=>{if(C&&Xe()){xe("home"),Y(!0);return}Ce()};async function Pe(c){const M=d.useDashboardStore.getState().dashboard;if(!M)return;const _=(c==null?void 0:c.closeAfterSave)??P,Wt=(c==null?void 0:c.navigateHomeAfterSave)??!1;F(_),_&&Y(!1);const Jt=s.cloneDeep(M);U(!0),Q(null),j([]),Le(!0);const Xt={template:M};Z.mutate({resourceId:M.id,data:Xt},{onSuccess:I=>{var je,Se,dt;const $=(I==null?void 0:I.id)||((je=I==null?void 0:I.dashboard)==null?void 0:je.id)||((Se=I==null?void 0:I.resource)==null?void 0:Se.id)||((dt=I==null?void 0:I.template)==null?void 0:dt.id)||null;if(!M.id&&$){const Oe=d.useAIInteractionStore.getState(),we=Oe.pendingDashboardDraftMigration;(we==null?void 0:we.scopeKey)===l?Oe.actions.setPendingDashboardDraftMigrationExpectedDashboardId($):we&&Oe.actions.clearPendingDashboardDraftMigration()}Le(!1),s.ue.success("Dashboard saved!"),fe(pt(Jt,d.useDashboardStore.getState().semanticExecutionPayload)),U(!1),F(!1),_&&(Ae(),be(),Wt&&Ce()),xe("close")},onError:I=>{Le(!1),Q("Failed to save dashboard. Please try again.");const $=I.details,je=Array.isArray($==null?void 0:$.errors)?($.errors||[]).filter(Se=>typeof Se=="string"):[];j(Qs({errors:je,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function zt(){if(B(!0),!p||!g)return;const c=d.useDashboardStore.getState().dashboard;if(!c){B(!1);return}const M=JSON.stringify(c),_={...g,template:M,filterValues:ue};await Fe(a.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),Ne==null||Ne(c),B(!1)}const Ze=(g==null?void 0:g.name)||i.title;Z.isPending&&console.log("Title during update:",{title:Ze,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:g==null?void 0:g.name});const et=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail,Ht=!!et&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl),Vt=u,q=(i==null?void 0:i.id)||null,Kt=Ws((ot=a.config)==null?void 0:ot.showBriefings,n),ye=!!q&&Lt===q,Qt=()=>{q&&Mt({dashboardId:ye?null:q})};return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[et&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{le(!ce)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(as,{className:"h-3.5 w-3.5"})}),Vt&&!L&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Gt,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!L&&u&&(b?e.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:Ze||"Untitled Dashboard",onSave:c=>{console.log("EditableText onSave called:",{newTitle:c,canEditDashboard:pe,dashboardId:i==null?void 0:i.id});const M=(i==null?void 0:i.title)||"";D(c),_t(c,M)},isEditable:pe&&!g,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:Z.isPending}),Ht&&q&&e.jsx(d.TooltipProvider,{children:e.jsxs(d.Tooltip,{children:[e.jsx(d.TooltipTrigger,{asChild:!0,children:e.jsx(d.Button,{variant:"ghost",size:"xs",onClick:Qt,disabled:It||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0","aria-label":ye?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:d.cn("h-3.5 w-3.5 transition-colors",ye?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(d.TooltipContent,{children:e.jsx("p",{children:ye?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[L&&e.jsxs(e.Fragment,{children:[e.jsx(O.AdvancedModeToggle,{}),e.jsx(O.VisualEditingControls,{})]}),!L&&u&&((it=R==null?void 0:R.permissions)==null?void 0:it.canShare)&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:()=>re(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!L&&!C&&u&&q&&Kt&&e.jsx(O.DashboardBriefingLauncher,{dashboardId:q,dashboardTitle:(i==null?void 0:i.title)||(R==null?void 0:R.title)}),!L&&C&&f.canUseFilters&&u&&e.jsx(O.DashboardFilterControlsLauncher,{}),C&&!L&&ee&&g&&o&&u&&e.jsxs(d.Button,{variant:"secondary",size:"xs",disabled:W,onClick:zt,children:[e.jsx(d.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),C&&!L&&u&&!N&&e.jsxs(d.Button,{variant:"outline",size:"xs",disabled:!C,onClick:()=>Ot(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!L&&!C&&pe&&u&&e.jsxs(d.Button,{size:"xs",onClick:Ut,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Ke&&u&&Je&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:Bt,disabled:ve,children:[e.jsx(O.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Ke&&u&&e.jsxs(d.Button,{size:"xs",className:d.cn(!Ye&&"opacity-60"),disabled:ve||!Ye,onClick:()=>Pe(),children:[ve?e.jsx(d.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(d.Save,{className:"h-3.5 w-3.5"}),ve?"Saving...":"Save"]}),C&&!L&&u&&e.jsxs(d.Button,{variant:"outline",size:"xs",onClick:Ft,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!L&&u&&e.jsx("div",{className:"ml-2",children:e.jsx(O.NotificationBell,{})}),!L&&o&&e.jsx(hs,{}),!L&&u&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:h,onSelect:()=>ie(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(s.DropdownMenuSeparator,{}),Pt&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>z(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>V(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),o&&u&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var c;t!=null&&t.accessToken&&((c=navigator==null?void 0:navigator.clipboard)!=null&&c.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),N&&e.jsxs(s.DropdownMenuItem,{disabled:!Ie,onSelect:()=>{var c;if(!Ie){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(c=navigator==null?void 0:navigator.clipboard)!=null&&c.writeText?navigator.clipboard.writeText(Ie).then(()=>s.ue.success("Local document PDF URL copied to clipboard")).catch(()=>s.ue.error("Unable to copy local document PDF URL")):s.ue.error("Clipboard not available")},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>d.invalidateToken(a.apiServiceUrl),children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:m,children:[e.jsx(ts.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ze(!Be),children:[e.jsx(ss.Braces,{className:"h-3.5 w-3.5"}),Be?"Hide dashboard JSON":"Show dashboard JSON"]}),ee&&C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ae(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),ee&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(ns,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(vs,{})})]})]})]})]}),J&&Ve&&e.jsx(s.ShareDialog,{resource:Ve,resourceType:s.ResourceType.DASHBOARD,onClose:()=>re(!1)}),e.jsx($s,{open:G,onOpenChange:z}),e.jsx(Zt.CalendarPreferencesDialog,{open:H,onOpenChange:V}),o&&ee&&u&&e.jsx(bs,{open:ne,onOpenChange:ae}),u&&e.jsx(s.DownloadPdf,{open:oe,onOpenChange:ie}),e.jsx(s.AlertDialog,{open:de,onOpenChange:c=>{!c&&Ee&&!K||(U(c),c||(Q(null),j([]),F(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:K?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:K?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),T.length>0&&e.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:T.slice(0,5).map(c=>e.jsx("li",{children:c},c))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:K?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{U(!1),Q(null),j([]),F(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Pe({closeAfterSave:P,navigateHomeAfterSave:Me==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(d.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(O.UnsavedChangesAlert,{open:Rt,onOpenChange:c=>{Y(c)},onSave:qt,onDiscard:$t,isSaving:Ee,saveLabel:"Save",discardLabel:"Discard"})]})]})}function Xs({accessToken:t,dashboardId:a,selectedSheetId:r,pageSize:n,orientation:o,theme:m}){if(!t||!r)return null;const f=new URL("http://localhost:5173/print-document");f.searchParams.set("token",t),a&&f.searchParams.set("dashboardId",a),f.searchParams.set("selectedSheetId",r),m&&f.searchParams.set("theme",m);const u=new URL("http://127.0.0.1:3002/");return u.searchParams.set("pdfMode","document"),u.searchParams.set("pageSize",n||"letter"),u.searchParams.set("orientation",o||"portrait"),u.searchParams.set("url",f.toString()),u.toString()}exports.default=Js;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),o=require("react");require("./index-BxM99sFL.js");const s=require("./switch-BvTzw2AW.js");require("./index-BdjXTQt4.js");require("./index-DRlMUglg.js");require("react-dom/client");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),c=s.useDashboardStore(e=>e.actions.setDashboard),u=s.useDashboardStore(e=>e.showDashboardJSON),h=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),r=o.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,i]=o.useState(r),n=o.useRef(r);return o.useEffect(()=>{r!==n.current&&(i(r),n.current=r)},[r]),a.jsxs("div",{className:s.cn("relative p-2",{hidden:!u}),children:[a.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>h(!1),children:[a.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),a.jsx("div",{className:"h-[550px] overflow-hidden",children:a.jsx(s.CodeEditor,{value:l,onValueChange:e=>{i(e);try{const d=JSON.parse(e);n.current=JSON.stringify(d,null,2),c(d)}catch{}},language:"json"})})]})}exports.default=b;
@@ -1,11 +1,12 @@
1
- import { jsxs as i, jsx as t } from "react/jsx-runtime";
2
- import { useMemo as m, useState as b, useRef as f, useEffect as S } from "react";
1
+ import { jsxs as d, jsx as t } from "react/jsx-runtime";
2
+ import { useMemo as m, useState as b, useRef as f, useEffect as p } from "react";
3
3
  import "./index-CuHybtft.js";
4
- import { u as o, a as p, B as N, X as D, C as J } from "./switch-j3AThLFk.js";
5
- import "./index-DwfDwtv2.js";
4
+ import { u as o, a as S, B as N, X as D, C as J } from "./switch-De31SR3q.js";
5
+ import "./index-BmKr-K7J.js";
6
6
  import "./index-CJdxSyQq.js";
7
+ import "react-dom/client";
7
8
  import "react-dom";
8
- function V() {
9
+ function j() {
9
10
  const e = o((s) => s.dashboard), c = o((s) => s.actions.setDashboard), h = o(
10
11
  (s) => s.showDashboardJSON
11
12
  ), l = o(
@@ -14,16 +15,16 @@ function V() {
14
15
  () => e ? JSON.stringify(e, null, 2) : "",
15
16
  [e]
16
17
  ), [u, n] = b(a), r = f(a);
17
- return S(() => {
18
+ return p(() => {
18
19
  a !== r.current && (n(a), r.current = a);
19
- }, [a]), /* @__PURE__ */ i(
20
+ }, [a]), /* @__PURE__ */ d(
20
21
  "div",
21
22
  {
22
- className: p("relative p-2", {
23
+ className: S("relative p-2", {
23
24
  hidden: !h
24
25
  }),
25
26
  children: [
26
- /* @__PURE__ */ i(
27
+ /* @__PURE__ */ d(
27
28
  N,
28
29
  {
29
30
  variant: "secondary",
@@ -43,12 +44,12 @@ function V() {
43
44
  onValueChange: (s) => {
44
45
  n(s);
45
46
  try {
46
- const d = JSON.parse(s);
47
+ const i = JSON.parse(s);
47
48
  r.current = JSON.stringify(
48
- d,
49
+ i,
49
50
  null,
50
51
  2
51
- ), c(d);
52
+ ), c(i);
52
53
  } catch {
53
54
  }
54
55
  },
@@ -60,5 +61,5 @@ function V() {
60
61
  );
61
62
  }
62
63
  export {
63
- V as default
64
+ j as default
64
65
  };
@@ -0,0 +1 @@
1
+ "use strict";const a=require("./index-D7KJindZ.js");function M(t,e){const r=a.toDate(t),n=a.toDate(e),c=r.getTime()-n.getTime();return c<0?-1:c>0?1:c}function _(t){return a.constructFrom(t,Date.now())}function C(t,e){const r=a.toDate(t),n=a.toDate(e),c=r.getFullYear()-n.getFullYear(),i=r.getMonth()-n.getMonth();return c*12+i}function A(t){return e=>{const n=(t?Math[t]:Math.trunc)(e);return n===0?0:n}}function R(t,e){return+a.toDate(t)-+a.toDate(e)}function X(t){const e=a.toDate(t);return e.setHours(23,59,59,999),e}function B(t){const e=a.toDate(t),r=e.getMonth();return e.setFullYear(e.getFullYear(),r+1,0),e.setHours(23,59,59,999),e}function V(t){const e=a.toDate(t);return+X(e)==+B(e)}function W(t,e){const r=a.toDate(t),n=a.toDate(e),c=M(r,n),i=Math.abs(C(r,n));let f;if(i<1)f=0;else{r.getMonth()===1&&r.getDate()>27&&r.setDate(30),r.setMonth(r.getMonth()-c*i);let u=M(r,n)===-c;V(a.toDate(t))&&i===1&&M(t,n)===1&&(u=!1),f=c*(i-Number(u))}return f===0?0:f}function Y(t,e,r){const n=R(t,e)/1e3;return A(r==null?void 0:r.roundingMethod)(n)}function E(t,e,r){const n=a.getDefaultOptions(),c=(r==null?void 0:r.locale)??n.locale??a.enUS,i=2520,f=M(t,e);if(isNaN(f))throw new RangeError("Invalid time value");const u=Object.assign({},r,{addSuffix:r==null?void 0:r.addSuffix,comparison:f});let l,d;f>0?(l=a.toDate(e),d=a.toDate(t)):(l=a.toDate(t),d=a.toDate(e));const m=Y(d,l),T=(a.getTimezoneOffsetInMilliseconds(d)-a.getTimezoneOffsetInMilliseconds(l))/1e3,s=Math.round((m-T)/60);let D;if(s<2)return r!=null&&r.includeSeconds?m<5?c.formatDistance("lessThanXSeconds",5,u):m<10?c.formatDistance("lessThanXSeconds",10,u):m<20?c.formatDistance("lessThanXSeconds",20,u):m<40?c.formatDistance("halfAMinute",0,u):m<60?c.formatDistance("lessThanXMinutes",1,u):c.formatDistance("xMinutes",1,u):s===0?c.formatDistance("lessThanXMinutes",1,u):c.formatDistance("xMinutes",s,u);if(s<45)return c.formatDistance("xMinutes",s,u);if(s<90)return c.formatDistance("aboutXHours",1,u);if(s<a.minutesInDay){const g=Math.round(s/60);return c.formatDistance("aboutXHours",g,u)}else{if(s<i)return c.formatDistance("xDays",1,u);if(s<a.minutesInMonth){const g=Math.round(s/a.minutesInDay);return c.formatDistance("xDays",g,u)}else if(s<a.minutesInMonth*2)return D=Math.round(s/a.minutesInMonth),c.formatDistance("aboutXMonths",D,u)}if(D=W(d,l),D<12){const g=Math.round(s/a.minutesInMonth);return c.formatDistance("xMonths",g,u)}else{const g=D%12,x=Math.trunc(D/12);return g<3?c.formatDistance("aboutXYears",x,u):g<9?c.formatDistance("overXYears",x,u):c.formatDistance("almostXYears",x+1,u)}}function U(t,e){return E(t,_(t),e)}function S(t){if(!t)return!1;const e=t.toLowerCase().replace("_","-");return e==="en-in"||e.startsWith("en-in-")}function P(t,e){const r=Math.abs(t);return r>=1e12?{divisor:1e12,suffix:"T"}:r>=1e9?{divisor:1e9,suffix:"B"}:S(e)&&r>=1e7?{divisor:1e7,suffix:"Cr"}:r>=1e6?{divisor:1e6,suffix:"M"}:S(e)&&r>=1e5?{divisor:1e5,suffix:"L"}:r>=1e3?{divisor:1e3,suffix:"K"}:{divisor:1,suffix:""}}function y(t,e){try{const r=h(e);return P(t,r)}catch{return P(t,"en-US")}}function k(t){try{return new Intl.NumberFormat(t),!0}catch{return!1}}function h(t){return t&&k(t)?t:"en-US"}function I(t,e){if(t==null||isNaN(t))return"";const r=h(e==null?void 0:e.locale);let n=t;if(e!=null&&e.multiplyBy&&(n*=e.multiplyBy),e!=null&&e.useSuffix){const{divisor:i,suffix:f}=y(n,r);n=n/i;const u=new Intl.NumberFormat(r,{minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(n);return`${(e==null?void 0:e.prefix)??""}${u}${f}${(e==null?void 0:e.suffix)??""}`}const c=new Intl.NumberFormat(r,{minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(n);if(e!=null&&e.negativeInParentheses&&n<0){const i=c.replace("-","");return`(${(e==null?void 0:e.prefix)??""}${i}${(e==null?void 0:e.suffix)??""})`}return`${(e==null?void 0:e.prefix)??""}${c}${(e==null?void 0:e.suffix)??""}`}function G(t,e){if(t==null||isNaN(t))return"";const r=h(e==null?void 0:e.locale),n=(e==null?void 0:e.currency)||"USD",c=t<0,i=!!(e!=null&&e.negativeInParentheses&&c),f=i?Math.abs(t):t;try{if(e!=null&&e.useSuffix){const{divisor:l,suffix:d}=y(f,r),m=f/l,s=`${new Intl.NumberFormat(r,{style:"currency",currency:n,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(m)}${d}`;return i?`(${s})`:s}const u=new Intl.NumberFormat(r,{style:"currency",currency:n,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(f);return i?`(${u})`:u}catch{const u=Math.abs(t),l=e!=null&&e.useSuffix?y(u,r):{divisor:1,suffix:""},d=I(u/l.divisor,{locale:r,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}),m=`${n} ${d}${l.suffix}`;return c?e!=null&&e.negativeInParentheses?`(${m})`:`-${m}`:m}}function v(t,e){if(t==null||isNaN(t))return"";const r=h(e==null?void 0:e.locale),c=(e==null?void 0:e.alreadyPercent)??(e==null?void 0:e.percentValueMode)==="whole"?t/100:t;return new Intl.NumberFormat(r,{style:"percent",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(c)}function w(t,e){if(t==null||isNaN(t))return"";const r=h(e==null?void 0:e.locale);return new Intl.NumberFormat(r,{notation:"scientific",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2}).format(t)}function j(t,e,r="en-US"){if(t==null||isNaN(t))return"";const n=h((e==null?void 0:e.locale)||r),c=(e==null?void 0:e.style)||"decimal";if(c==="percent"){const f=((e==null?void 0:e.percentValueMode)??"whole")==="whole"?t/100:t;return new Intl.NumberFormat(n,{style:"percent",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(f)}return c==="currency"?new Intl.NumberFormat(n,{style:"currency",currency:(e==null?void 0:e.currency)||"USD",minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(t):c==="scientific"?w(t,{locale:n,minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2}):new Intl.NumberFormat(n,{minimumFractionDigits:(e==null?void 0:e.minimumFractionDigits)??0,maximumFractionDigits:(e==null?void 0:e.maximumFractionDigits)??2,useGrouping:(e==null?void 0:e.useGrouping)??!0}).format(t)}function H(t,e,r){const n={style:e==="currency"?"currency":e==="percent"?"percent":"decimal",locale:r==null?void 0:r.locale,currency:r==null?void 0:r.currency,minimumFractionDigits:r==null?void 0:r.decimalPlaces,maximumFractionDigits:r==null?void 0:r.decimalPlaces,useSuffix:r==null?void 0:r.useSuffix,prefix:r==null?void 0:r.prefix,suffix:r==null?void 0:r.suffix,negativeInParentheses:r==null?void 0:r.negativeInParentheses,multiplyBy:r==null?void 0:r.multiplyBy};switch(e){case"currency":return G(t,n);case"percent":return v(t,n);case"scientific":return w(t,n);default:return I(t,n)}}const O=["day","hour","minute","second","millisecond"],N={day:864e5,hour:36e5,minute:6e4,second:1e3,millisecond:1},q={day:"d",hour:"hr",minute:"min",second:"s",millisecond:"ms"},K={day:["day","days"],hour:["hour","hours"],minute:["minute","minutes"],second:["second","seconds"],millisecond:["millisecond","milliseconds"]};function z(t){return t==="day"||t==="hour"||t==="minute"||t==="second"||t==="millisecond"}function Z(t,e){return z(t)?t:e}function L(t,e){return O.indexOf(Z(t,e))}function J(t,e){const r=L(t,"day"),n=L(e,"second"),c=Math.min(r,n),i=Math.max(r,n);return O.slice(c,i+1)}function Q(t,e){return t*N[Z(e,"second")]}function F(t,e){const r=J(e.largestUnit,e.smallestUnit),n=r[r.length-1],c=N[n];let i=Math.round(t/c)*c;return r.map(f=>{const u=N[f],l=Math.floor(i/u);return i-=l*u,{unit:f,value:l}})}function b(t,e){const r=t.filter(i=>i.value!==0),n=r.length>0?r:[t[t.length-1]],c=typeof e=="number"&&Number.isFinite(e)?Math.max(1,Math.trunc(e)):n.length;return n.slice(0,c).map(i=>`${i.value}${q[i.unit]}`).join(" ")}function o(t,e){const r=t.filter(i=>i.value!==0),n=r.length>0?r:[t[t.length-1]],c=typeof e=="number"&&Number.isFinite(e)?Math.max(1,Math.trunc(e)):n.length;return n.slice(0,c).map(i=>{const[f,u]=K[i.unit];return`${i.value} ${i.value===1?f:u}`}).join(" ")}function p(t){const e=t.some(l=>l.unit==="day"&&l.value!==0),r=t.some(l=>l.unit==="millisecond"),n=t.findIndex(l=>l.value!==0),c=Math.max(0,t.length-2),i=e?0:n===-1?c:Math.min(n,c),f=n===-1?t.slice(c):t.slice(i);if(f.length===0)return"0";const u=f.map((l,d)=>l.unit==="millisecond"?String(l.value).padStart(3,"0"):d===0?String(l.value):String(l.value).padStart(2,"0")).join(":");return r?u.replace(/:(\d{3})$/,".$1"):u}function ee(t,e,r){const n=`${r.prefix||""}${t}${r.suffix||""}`;return e?r.negativeInParentheses?`(${n})`:`-${n}`:n}function te(t,e={}){if(t==null)return"";const r=typeof t=="number"?t:typeof t=="string"&&t.trim()?Number(t):NaN;if(!Number.isFinite(r))return"";const n=e.inputUnit||"second",c=e.outputStyle==="digital"||e.outputStyle==="long"?e.outputStyle:"compact",i=r<0,f=Math.abs(Q(r,n)),u=F(f,e),l=c==="digital"?p(u):c==="long"?o(u,e.maxUnits):b(u,e.maxUnits);return ee(l,i,e)}function re(t,e){return t&&t!=="auto"?t:e}function ne(t,e=new Date){try{const r={timeZone:t,timeZoneName:"short"},c=new Intl.DateTimeFormat("en-US",r).formatToParts(e).find(i=>i.type==="timeZoneName");return(c==null?void 0:c.value)||t}catch{return t}}function ce(t){try{const e={timeZone:t,timeZoneName:"long"},n=new Intl.DateTimeFormat("en-US",e).formatToParts(new Date).find(c=>c.type==="timeZoneName");return(n==null?void 0:n.value)||t}catch{return t}}function $(t,e="auto"){if(!t)return new Date(NaN);const r=t.endsWith("Z"),n=/[+-]\d{2}:?\d{2}$/.test(t),c=/\([A-Z]{3,4}\)$/.test(t);if(e==="auto")return r||n||c?new Date(t):new Date(t+"Z");if(e==="local"){if(r||n){const i=t.replace(/Z$/,"").replace(/[+-]\d{2}:?\d{2}$/,"");return new Date(i)}return new Date(t)}else return e==="UTC"?r?new Date(t):n?new Date(t):new Date(t+"Z"):r||n||c?new Date(t):a.fromZonedTime(t,e)}const ie="MM/dd/yyyy",ue=(t,e,r,n="auto")=>{if(!t)return"";try{const c=$(t,n);if(isNaN(c.getTime()))return t;const f=(e&&e.trim()?e:ie).replace(/LLLL/g,"MMMM").replace(/LLL/g,"MMM");return r&&r!=="auto"?a.formatInTimeZone(c,r,f):a.format(c,f)}catch(c){return console.error("Date formatting error:",c),t}},ae=(t,e="auto")=>{if(!t)return"";try{const r=$(t,e);return isNaN(r.getTime())?t:U(r,{addSuffix:!0})}catch(r){return console.error("Relative time formatting error:",r),t}};exports.formatCurrency=G;exports.formatDate=ue;exports.formatDistanceToNow=U;exports.formatDuration=te;exports.formatNumber=I;exports.formatNumberCustom=H;exports.formatNumberWithColumnSettings=j;exports.formatPercent=v;exports.formatRelativeTime=ae;exports.formatScientific=w;exports.getTimezoneAbbreviation=ne;exports.getTimezoneName=ce;exports.parseWithSourceTimezone=$;exports.resolveTimezone=re;