react-semaphor 0.1.390 → 0.1.392

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 (68) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +120 -252
  3. package/dist/brand-studio/index.cjs +1 -1
  4. package/dist/brand-studio/index.js +7 -7
  5. package/dist/chunks/analyze-result-contract-C9Gv2_qW.js +1585 -0
  6. package/dist/chunks/analyze-result-contract-Zgg-Bbpj.js +1 -0
  7. package/dist/chunks/{braces--20GzUQh.js → braces-8TRlDwDw.js} +1 -1
  8. package/dist/chunks/{braces-C0Vh_Mft.js → braces-D2tStQjF.js} +1 -1
  9. package/dist/chunks/{calendar-preferences-dialog-B-VsxhsA.js → calendar-preferences-dialog-49fcEPXS.js} +4 -4
  10. package/dist/chunks/{calendar-preferences-dialog-DE67Z3oQ.js → calendar-preferences-dialog-DwLeBLy2.js} +1 -1
  11. package/dist/chunks/dashboard-briefing-launcher-CgkSKkZR.js +80 -0
  12. package/dist/chunks/{dashboard-briefing-launcher-BIj3X7b3.js → dashboard-briefing-launcher-cgPKz1yX.js} +252 -252
  13. package/dist/chunks/dashboard-controls-D12ZSUP_.js +52 -0
  14. package/dist/chunks/{dashboard-controls-BXxucM4f.js → dashboard-controls-VMFm3OP4.js} +87 -87
  15. package/dist/chunks/{dashboard-json-C6oZuipD.js → dashboard-json-C-GG5yC7.js} +4 -4
  16. package/dist/chunks/{dashboard-json-BNwshkK2.js → dashboard-json-CvK0oI24.js} +1 -1
  17. package/dist/chunks/{edit-dashboard-visual-CmfrI_L3.js → edit-dashboard-visual-B5KB7dx4.js} +977 -977
  18. package/dist/chunks/edit-dashboard-visual-ql99faTz.js +178 -0
  19. package/dist/chunks/{index-icb12JV1.js → index-CQmKDEbe.js} +735 -741
  20. package/dist/chunks/{index-4W_ElSBJ.js → index-DXCBPLDu.js} +218 -223
  21. package/dist/chunks/{layout-grid-B7-klXiK.js → layout-grid-C0OI-MRn.js} +1 -1
  22. package/dist/chunks/{layout-grid-DV89AC9_.js → layout-grid-CiubineE.js} +1 -1
  23. package/dist/chunks/{palette-Dj-dgPYh.js → palette-C4KTXOug.js} +1 -1
  24. package/dist/chunks/{palette-5IwhMbSF.js → palette-Cp1hqZtm.js} +1 -1
  25. package/dist/chunks/{save-C5fwVdTF.js → save-C__QggEE.js} +1 -1
  26. package/dist/chunks/{save-16C6YSW2.js → save-DgMfP0j8.js} +1 -1
  27. package/dist/chunks/{search-0LmWwZzW.js → search-BHsQIWBV.js} +17 -7
  28. package/dist/chunks/{search-Dq1Mbb03.js → search-DNCejM7Z.js} +9 -4
  29. package/dist/chunks/source-identity-uMaUe036.js +1 -0
  30. package/dist/chunks/{source-identity-CN4xiyKJ.js → source-identity-y0VSSreA.js} +33 -15
  31. package/dist/chunks/{switch-bdJp0Bkw.js → switch-B79Hn4Qh.js} +27 -32
  32. package/dist/chunks/{switch-DUdaHFZQ.js → switch-BXQAlSuW.js} +637 -647
  33. package/dist/chunks/use-create-flow-overlay-state-7MFN3PWX.js +21 -0
  34. package/dist/chunks/{use-create-flow-overlay-state-YvqCp6Zo.js → use-create-flow-overlay-state-Bw5LRkf9.js} +93 -92
  35. package/dist/chunks/{validators-CHPH6ORs.js → validators-4EGCWWga.js} +1 -1
  36. package/dist/chunks/{validators-lWo8m0Q7.js → validators-CPtkrola.js} +1 -1
  37. package/dist/chunks/{x-B_cx7LwM.js → x-B6ghREd2.js} +10 -5
  38. package/dist/chunks/{x-IdR_js6f.js → x-CXDkqdur.js} +28 -18
  39. package/dist/dashboard/index.cjs +1 -1
  40. package/dist/dashboard/index.js +1 -1
  41. package/dist/dashboard-authoring/index.cjs +1 -1
  42. package/dist/dashboard-authoring/index.js +3 -3
  43. package/dist/data-app-builder/index.cjs +13 -13
  44. package/dist/data-app-builder/index.js +11 -11
  45. package/dist/data-app-sdk/index.cjs +5 -5
  46. package/dist/data-app-sdk/index.js +1698 -1121
  47. package/dist/data-app-sdk-adapters/index.cjs +1 -1
  48. package/dist/data-app-sdk-adapters/index.js +6 -7
  49. package/dist/data-app-sdk-validation/index.cjs +1 -1
  50. package/dist/data-app-sdk-validation/index.js +3 -3
  51. package/dist/index.cjs +1 -1
  52. package/dist/index.js +13 -13
  53. package/dist/surfboard/index.cjs +1 -1
  54. package/dist/surfboard/index.js +2 -2
  55. package/dist/types/analytics-protocol.d.ts +2107 -43
  56. package/dist/types/dashboard-assistant.d.ts +3 -1
  57. package/dist/types/data-app-sdk-adapters.d.ts +1 -1
  58. package/dist/types/data-app-sdk-validation.d.ts +4 -2
  59. package/dist/types/data-app-sdk.d.ts +73 -5
  60. package/package.json +2 -1
  61. package/src/data-app-sdk/README.md +55 -0
  62. package/dist/chunks/analyze-result-contract-CtXfp3nv.js +0 -1
  63. package/dist/chunks/analyze-result-contract-DuhlklhI.js +0 -102
  64. package/dist/chunks/dashboard-briefing-launcher-Czx6BcXW.js +0 -80
  65. package/dist/chunks/dashboard-controls-BP-DcPFs.js +0 -52
  66. package/dist/chunks/edit-dashboard-visual-BAprin3J.js +0 -178
  67. package/dist/chunks/source-identity-C-xaeE_I.js +0 -1
  68. package/dist/chunks/use-create-flow-overlay-state-BIHKf_XK.js +0 -21
@@ -1,52 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),m=require("./switch-bdJp0Bkw.js"),s=require("./index-4W_ElSBJ.js"),U=require("./x-B_cx7LwM.js");require("./analyze-result-contract-CtXfp3nv.js");const v=require("react");require("./index-DRlMUglg.js");const ts=require("react-dom"),P=require("./dashboard-briefing-launcher-Czx6BcXW.js"),ss=require("./search-Dq1Mbb03.js"),ft=require("./index-D7KJindZ.js"),rs=require("./calendar-preferences-dialog-DE67Z3oQ.js"),ns=require("./use-debounced-dirty-check-XHSwAefL.js"),Ue=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),lt=require("./save-C5fwVdTF.js"),as=require("./palette-Dj-dgPYh.js"),os=require("./braces-C0Vh_Mft.js");function is(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 L=is(v);/**
2
- * @license lucide-react v0.453.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const ds=U.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
- * @license lucide-react v0.453.0 - ISC
8
- *
9
- * This source code is licensed under the ISC license.
10
- * See the LICENSE file in the root directory of this source tree.
11
- */const cs=U.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"}]]);/**
12
- * @license lucide-react v0.453.0 - ISC
13
- *
14
- * This source code is licensed under the ISC license.
15
- * See the LICENSE file in the root directory of this source tree.
16
- */const ls=U.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const us=U.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"}]]);/**
22
- * @license lucide-react v0.453.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const ms=U.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"}]]);/**
27
- * @license lucide-react v0.453.0 - ISC
28
- *
29
- * This source code is licensed under the ISC license.
30
- * See the LICENSE file in the root directory of this source tree.
31
- */const ps=U.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"}]]);/**
32
- * @license lucide-react v0.453.0 - ISC
33
- *
34
- * This source code is licensed under the ISC license.
35
- * See the LICENSE file in the root directory of this source tree.
36
- */const gt=U.createLucideIcon("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]);var qe={exports:{}},Te={};/**
37
- * @license React
38
- * use-sync-external-store-shim.production.js
39
- *
40
- * Copyright (c) Meta Platforms, Inc. and affiliates.
41
- *
42
- * This source code is licensed under the MIT license found in the
43
- * LICENSE file in the root directory of this source tree.
44
- */var ut;function hs(){if(ut)return Te;ut=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,u=t.useLayoutEffect,f=t.useDebugValue;function c(l,x){var p=x(),g=n({inst:{value:p,getSnapshot:x}}),i=g[0].inst,w=g[1];return u(function(){i.value=p,i.getSnapshot=x,b(i)&&w({inst:i})},[l,p,x]),o(function(){return b(i)&&w({inst:i}),l(function(){b(i)&&w({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:c;return Te.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,Te}var Fe={};/**
45
- * @license React
46
- * use-sync-external-store-shim.development.js
47
- *
48
- * Copyright (c) Meta Platforms, Inc. and affiliates.
49
- *
50
- * This source code is licensed under the MIT license found in the
51
- * LICENSE file in the root directory of this source tree.
52
- */var mt;function xs(){return mt||(mt=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 w=g();u(i,w)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}w=f({inst:{value:i,getSnapshot:g}});var S=w[0].inst,N=w[1];return b(function(){S.value=i,S.getSnapshot=g,r(S)&&N({inst:S})},[p,i,g]),c(function(){return r(S)&&N({inst:S}),p(function(){r(S)&&N({inst:S})})},[p]),y(i),i}function r(p){var g=p.getSnapshot;p=p.value;try{var i=g();return!u(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,u=typeof Object.is=="function"?Object.is:t,f=o.useState,c=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;Fe.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())}()),Fe}process.env.NODE_ENV==="production"?qe.exports=hs():qe.exports=xs();var fs=qe.exports;const Ce=["light","dark","system"];function gs(){const{theme:t,setTheme:a}=s.useTheme(),r=m.useDashboardStore(f=>f.actions.setDashboardTheme);function n(){const f=Ce.includes(t)?t:"system",c=Ce[(Ce.indexOf(f)+1)%Ce.length];a(c),r(c)}const o=t==="light"?ms:t==="dark"?ls:cs,u=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(m.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,"aria-label":u,title:u,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function bs(t,a,r,n,o){if(!o)return null;const u=JSON.stringify(r),f=`${t}/v1/lens`;return await m.postRequest(f,o,{name:a,template:u,filterValues:n,operation:"create"})}async function $e(t,a,r){if(!r)return null;const{id:n,template:o,filterValues:u,isDefault:f,shared:c}=a,b=`${t}/v1/lens`;return await m.postRequest(b,r,{lensId:n,template:o,filterValues:u,isDefault:f,shared:c,operation:"update"})}async function vs(t,a,r){if(!r)return null;const n=`${t}/v1/lens`;return await m.postRequest(n,r,{operation:"delete",lensId:a})}const ys="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function js({open:t,onOpenChange:a}={}){const[r,n]=v.useState(""),[o,u]=v.useState(!1),f=m.useDashboardStore(D=>D.lenses),{setLenses:c,setSelectedLensId:b}=m.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)},w=m.useDashboardStore(D=>D.dashboard),S=m.useDashboardStore(D=>D.filterValues),{authToken:N,tokenProps:k}=s.useSemaphorContext();async function C(){h(!0);const D=await bs(k.apiServiceUrl,r,w,S,N==null?void 0:N.accessToken);D&&(c([...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(m.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(m.Label,{htmlFor:"lens-name",className:ys,children:"Name"}),e.jsx(m.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(m.Button,{variant:"outline",size:"xs",onClick:()=>i(!1),children:"Cancel"}),e.jsx(m.Button,{size:"xs",type:"submit",onClick:C,disabled:y||!r.trim(),children:y?"Creating…":"Create"})]})]})]})}function ws({includeLabel:t=!1}={}){const a=m.useDashboardStore(h=>h.lenses),r=m.useDashboardStore(h=>h.selectedLensId),{setLenses:n,setSelectedLensId:o}=m.useDashboardActions(),{authToken:u,tokenProps:f}=s.useSemaphorContext();async function c(h){o(h)}async function b(h){if(await vs(f.apiServiceUrl,h,u==null?void 0:u.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 $e(f.apiServiceUrl,x,u==null?void 0:u.accessToken);const p=a==null?void 0:a.find(g=>g.isDefault);if(p&&p.id!==h.id){const g={...p,isDefault:!1};await $e(f.apiServiceUrl,g,u==null?void 0:u.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:c,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:m.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 Ss(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:r,userContext:n}=s.useCurrentUserInfo(),o=v.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),u=v.useMemo(()=>c=>o&&o[c]!==void 0&&o[c]===!1?!1:a(c),[o,a,t]),f=v.useMemo(()=>{var c,b,y,h,l;return{canEdit:((c=n==null?void 0:n.permissions)==null?void 0:c.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:u,permissions:f,currentUser:r}}function Ds(t,a=[]){let r=[];function n(u,f){const c=L.createContext(f);c.displayName=u+"Context";const b=r.length;r=[...r,f];const y=l=>{var S;const{scope:x,children:p,...g}=l,i=((S=x==null?void 0:x[t])==null?void 0:S[b])||c,w=L.useMemo(()=>g,Object.values(g));return e.jsx(i.Provider,{value:w,children:p})};y.displayName=u+"Provider";function h(l,x){var i;const p=((i=x==null?void 0:x[t])==null?void 0:i[b])||c,g=L.useContext(p);if(g)return g;if(f!==void 0)return f;throw new Error(`\`${l}\` must be used within \`${u}\``)}return[y,h]}const o=()=>{const u=r.map(f=>L.createContext(f));return function(c){const b=(c==null?void 0:c[t])||u;return L.useMemo(()=>({[`__scope${t}`]:{...c,[t]:b}}),[c,b])}};return o.scopeName=t,[n,Ns(o,...a)]}function Ns(...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(u){const f=n.reduce((c,{useScope:b,scopeName:y})=>{const l=b(u)[`__scope${y}`];return{...c,...l}},{});return L.useMemo(()=>({[`__scope${a.scopeName}`]:f}),[f])}};return r.scopeName=a.scopeName,r}var Cs=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Be=Cs.reduce((t,a)=>{const r=m.createSlot(`Primitive.${a}`),n=L.forwardRef((o,u)=>{const{asChild:f,...c}=o,b=f?r:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(b,{...c,ref:u})});return n.displayName=`Primitive.${a}`,{...t,[a]:n}},{});function ks(){return fs.useSyncExternalStore(Es,()=>!0,()=>!1)}function Es(){return()=>{}}var Ge="Avatar",[Ls]=Ds(Ge),[Ms,bt]=Ls(Ge),vt=L.forwardRef((t,a)=>{const{__scopeAvatar:r,...n}=t,[o,u]=L.useState("idle");return e.jsx(Ms,{scope:r,imageLoadingStatus:o,onImageLoadingStatusChange:u,children:e.jsx(Be.span,{...n,ref:a})})});vt.displayName=Ge;var yt="AvatarImage",jt=L.forwardRef((t,a)=>{const{__scopeAvatar:r,src:n,onLoadingStatusChange:o=()=>{},...u}=t,f=bt(yt,r),c=Is(n,u),b=m.useCallbackRef(y=>{o(y),f.onImageLoadingStatusChange(y)});return m.useLayoutEffect2(()=>{c!=="idle"&&b(c)},[c,b]),c==="loaded"?e.jsx(Be.img,{...u,ref:a,src:n}):null});jt.displayName=yt;var wt="AvatarFallback",St=L.forwardRef((t,a)=>{const{__scopeAvatar:r,delayMs:n,...o}=t,u=bt(wt,r),[f,c]=L.useState(n===void 0);return L.useEffect(()=>{if(n!==void 0){const b=window.setTimeout(()=>c(!0),n);return()=>window.clearTimeout(b)}},[n]),f&&u.imageLoadingStatus!=="loaded"?e.jsx(Be.span,{...o,ref:a}):null});St.displayName=wt;function pt(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Is(t,{referrerPolicy:a,crossOrigin:r}){const n=ks(),o=L.useRef(null),u=n?(o.current||(o.current=new window.Image),o.current):null,[f,c]=L.useState(()=>pt(u,t));return m.useLayoutEffect2(()=>{c(pt(u,t))},[u,t]),m.useLayoutEffect2(()=>{const b=l=>()=>{c(l)};if(!u)return;const y=b("loaded"),h=b("error");return u.addEventListener("load",y),u.addEventListener("error",h),a&&(u.referrerPolicy=a),typeof r=="string"&&(u.crossOrigin=r),()=>{u.removeEventListener("load",y),u.removeEventListener("error",h)}},[u,r,a]),f}var Dt=vt,Nt=jt,Ct=St;const kt=L.forwardRef(({className:t,...a},r)=>e.jsx(Dt,{ref:r,className:m.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));kt.displayName=Dt.displayName;const As=L.forwardRef(({className:t,...a},r)=>e.jsx(Nt,{ref:r,className:m.cn("aspect-square h-full w-full",t),...a}));As.displayName=Nt.displayName;const Et=L.forwardRef(({className:t,...a},r)=>e.jsx(Ct,{ref:r,className:m.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));Et.displayName=Ct.displayName;const Ps=async(t,a,r)=>{const n=`${t}/management/v1/groups`;return await m.postRequestRegular(n,a,r)},Os=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}`;return m.requestJsonRegular(o,a,"PATCH",n)},Rs=async(t,a,r)=>{const n=`${t}/management/v1/groups/${r}`;await m.requestJsonRegular(n,a,"DELETE")},_s=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;return await m.postRequestRegular(o,a,n)},Us=async(t,a,r,n)=>{const o=`${t}/management/v1/groups/${r}/members`;await m.requestJsonRegular(o,a,"DELETE",n)};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:()=>{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:m.getRequestErrorMessage(n,"Failed to create 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:["groups"]}),s.ue.success("Group updated successfully")},onError:n=>{console.error("Failed to update group:",n),s.ue.error("Failed to update group",{description:m.getRequestErrorMessage(n,"Failed to update group")})}})}function qs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:n=>Rs(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:m.getRequestErrorMessage(n,"Failed to delete group")})}})}function $s(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>_s(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:m.getRequestErrorMessage(n,"Failed to add members")})}})}function Bs(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:n,data:o})=>Us(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:m.getRequestErrorMessage(n,"Failed to remove members")})}})}const Gs=[];function zs({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",u=r==null?void 0:r.tenantId,{groups:f,isLoading:c,error:b,refetch:y}=s.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?u:void 0,includeMembers:!1}),h=b?Lt(b,"Unable to load groups."):null,[l,x]=v.useState({kind:"list"}),[p,g]=v.useState(null),i=qs();v.useEffect(()=>{t||(x({kind:"list"}),g(null))},[t]);const w=l.kind==="members"&&f.find(D=>D.id===l.groupId)||null,S=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(Hs,{groups:f,isLoading:c,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"&&w&&e.jsx(Qs,{group:w,isTenantViewer:o,canEdit:((N=w.permissions)==null?void 0:N.canEdit)??w.createdBy===(n==null?void 0:n.id),canDelete:((k=w.permissions)==null?void 0:k.canDelete)??w.createdBy===(n==null?void 0:n.id),canManageMembers:((C=w.permissions)==null?void 0:C.canManageMembers)??w.createdBy===(n==null?void 0:n.id),onBack:()=>x({kind:"list"}),onMembersChanged:y,onUpdated:y,onRequestDelete:()=>g(w)},w.id),l.kind==="create"&&e.jsx(Ws,{isTenantUser:o,tenantId:u,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:S,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(m.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function Hs({groups:t,isLoading:a,errorMessage:r,onRetry:n,currentUserId:o,onOpenGroup:u,onCreate:f,onDeleteRequest:c}){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(ss.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(U.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(Mt,{title:"Can't load groups",message:r,onRetry:n}):h.length===0&&t.length===0?e.jsx(Ks,{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(Vs,{group:l,canDelete:((x=l.permissions)==null?void 0:x.canDelete)??l.createdBy===o,onClick:()=>u(l.id),onDelete:()=>c(l)},l.id)})})]})}function Vs({group:t,canDelete:a,onClick:r,onDelete:n}){let o="";try{o=ft.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(P.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(gt,{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:u=>{u.stopPropagation(),n()},onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),u.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 Ks({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 Qs({group:t,isTenantViewer:a,canEdit:r,canDelete:n,canManageMembers:o,onBack:u,onMembersChanged:f,onUpdated:c,onRequestDelete:b}){const{data:y,isLoading:h,error:l,refetch:x}=s.useGroupMembers(t.id),p=(y==null?void 0:y.members)??Gs,g=l?Lt(l,"Unable to load members for this group."):null,i=t.type==="TENANT_GROUP"?"tenant":"organization",{users:w}=s.useUnifiedUsers({type:i,tenantId:t.tenantId||void 0,active:!0,limit:200}),S=v.useMemo(()=>new Set(p.map(j=>j.userId)),[p]),N=$s(),k=Bs(),C=Fs(),[D,J]=v.useState(!1),[G,X]=v.useState(t.name),[ie,z]=v.useState(!1),[H,V]=v.useState(t.description||""),[K,de]=v.useState(""),[ce,le]=v.useState(!1),ue=v.useMemo(()=>{const j=K.trim().toLowerCase();return w.filter(O=>!S.has(O.id)).filter(O=>!j||(O.name||"").toLowerCase().includes(j)||(O.email||"").toLowerCase().includes(j)).slice(0,50)},[w,S,K]),me=async()=>{const j=G.trim();if(J(!1),j.length>=3&&j!==t.name)try{await C.mutateAsync({groupId:t.id,data:{name:j}}),c()}catch{}},T=async()=>{const j=H.trim();if(z(!1),j!==(t.description||""))try{await C.mutateAsync({groupId:t.id,data:{description:j}}),c()}catch{}},Q=async j=>{if(o){de(""),le(!1);try{await N.mutateAsync({groupId:t.id,data:{userIds:[j.id],userType:i==="tenant"?"tenant":"org"}}),x(),f()}catch{}}},W=async j=>{if(o)try{await k.mutateAsync({groupId:t.id,data:{userIds:[j]}}),x(),f()}catch{}};let F="";try{F=ft.format(new Date(t.createdAt),"MMM d, yyyy")}catch{F=""}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:u,"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:G,onChange:j=>X(j.target.value),onBlur:me,onKeyDown:j=>{j.key==="Enter"&&me(),j.key==="Escape"&&(X(t.name),J(!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&&(X(t.name),J(!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(gt,{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:ie?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:H,onChange:j=>V(j.target.value),maxLength:200,onKeyDown:j=>{j.key==="Escape"&&(V(t.description||""),z(!1)),j.key==="Enter"&&(j.metaKey||j.ctrlKey)&&T()},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:[H.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{V(t.description||""),z(!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:T,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&&(V(t.description||""),z(!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:[F?`Created ${F}`:"Recently created",r?" · You can edit this group":""]})]})}),o&&e.jsx(Js,{query:K,setQuery:de,open:ce,setOpen:le,candidates:ue,showKindChip:!a,onAdd:Q,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(Mt,{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 O,q,pe,Y,he,E;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(It,{name:((O=j.user)==null?void 0:O.name)||((q=j.user)==null?void 0:q.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((pe=j.user)==null?void 0:pe.name)||((Y=j.user)==null?void 0:Y.email)||"Unknown"}),((he=j.user)==null?void 0:he.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:()=>W(j.userId),disabled:!o||k.isPending,"aria-label":`Remove ${((E=j.user)==null?void 0:E.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(U.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 Ws({isTenantUser:t,tenantId:a,onCancel:r,onCreated:n}){const[o,u]=v.useState(""),[f,c]=v.useState(""),[b,y]=v.useState(null),h=Ts(),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(ht,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:p=>u(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(ht,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:f,onChange:p=>c(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(m.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 Js({query:t,setQuery:a,open:r,setOpen:n,candidates:o,showKindChip:u,onAdd:f,busy:c}){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(),w=240,N=window.innerHeight-i.bottom<w+16&&i.top>w;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 w,S;const i=g.target;(w=b.current)!=null&&w.contains(i)||(S=y.current)!=null&&S.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(ps,{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:c,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"&&ts.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(It,{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})]}),u&&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 Lt(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 Mt({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 ht({children:t}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})}function It({name:t}){const a=t.split(" ").map(r=>r[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(kt,{className:"h-6 w-6 shrink-0",children:e.jsx(Et,{className:"text-[9px] font-semibold",children:a||"?"})})}function ae(t,a,r){var u,f;const n=(t.controls||[]).find(c=>c.id===r);if(n)return n.label;const o=(f=(u=m.findCardById(t,a))==null?void 0:u.controls)==null?void 0:f.find(c=>c.id===r);return(o==null?void 0:o.label)||r}function oe(t,a){var r;return((r=m.findCardById(t,a))==null?void 0:r.title)||a}function Xs(t){const{errors:a,dashboard:r}=t;if(!r)return a;const n=new Map;for(const o of a){const u=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(u){const[,h,l]=u,x=`${h}:${l}:missing-metric`;n.has(x)||n.set(x,`"${oe(r,h)}" has an outdated "${ae(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,`"${oe(r,h)}" has an outdated "${ae(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 c=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(c){const[,h,l]=c,x=`${h}:${l}:invalid-metric`;n.has(x)||n.set(x,`"${oe(r,h)}" has an invalid "${ae(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,`"${oe(r,h)}" has an invalid "${ae(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,`"${oe(r,h)}" can no longer use "${ae(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 Ys(t,a){return typeof t=="boolean"?t:typeof a=="boolean"?a:!0}function xt(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function Zs(){var st,rt,nt,at,ot,it,dt;P.useExportRecovery(),P.useExportPolling();const{authToken:t,tokenProps:a,id:r,showBriefings:n}=s.useSemaphorContext(),{isLocalDev:o}=s.useDashboardPreferences(),{openBrandStudioPreview:u}=s.useBrandStudioPreview(),{permissions:f}=Ss(),c=s.useHasDashboardId(),{isLoading:b}=s.useDashboardQuery(),y=m.useDashboardStore(d=>d.theme),h=m.useDashboardStore(d=>d.isDownloadingPdf),l=m.useDashboardStore(d=>d.dashboardAssistantDraftScopeKey),x=m.useDashboardStore(d=>d.lenses),p=m.useDashboardStore(d=>d.selectedLensId),g=x==null?void 0:x.find(d=>d.id===p),i=m.useDashboardStore(d=>d.dashboard),w=m.useDashboardStore(d=>d.selectedSheetId),S=(st=i==null?void 0:i.sheets)==null?void 0:st.find(d=>d.id===w),N=m.isDocumentSheet(S),k=N?(rt=S==null?void 0:S.document)==null?void 0:rt.page:void 0,C=m.useDashboardStore(d=>d.isDashboardEditing),{setDashboardTitle:D}=m.useDashboardStore(d=>d.actions),[J,G]=v.useState(!1),[X,ie]=v.useState(!1),[z,H]=v.useState(!1),[V,K]=v.useState(!1),[de,ce]=v.useState(!1),[le,ue]=v.useState(!1),[me,T]=v.useState(!1),[Q,W]=v.useState(null),[F,j]=v.useState([]),[O,q]=v.useState(!1),[pe,Y]=v.useState(!1),he=m.useDashboardStore(d=>d.filterValues),E=m.useDashboardStore(d=>d.isVisualEditing);m.useEditorStore(d=>d.card);const Z=s.useManagementStore(d=>d.selectedDashboard),xe=s.useManagementStore(d=>d.initialDashboard);s.useManagementStore(d=>d.selectedVisual),m.useDashboardStore(d=>d.selectedFrameId),m.useEditorStore(d=>d.frame);const fe=Z?(at=Z==null?void 0:Z.permissions)==null?void 0:at.canEdit:(nt=xe==null?void 0:xe.permissions)==null?void 0:nt.canEdit,ze=m.useDashboardStore(d=>d.showDashboardJSON),ke=m.useDashboardStore(d=>d.onSaveFunction),{setIsDashboardEditing:He,setShowDashboardJSON:Ve}=m.useDashboardStore(d=>d.actions),{setInitialDashboard:Ke,clearSelectedDashboard:Ee}=s.useManagementStore(d=>d.actions),ee=!!a.orgUserId||!!(a.tenantId&&a.endUserId&&a.endUserEmail),{resources:ge}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Le}=s.useUserPreferences(),At=((ot=Le==null?void 0:Le.preference)==null?void 0:ot.defaultDashboardId)||null,{mutate:Pt,isPending:Ot}=s.useDefaultDashboardMutation(),{currentUser:Rt}=s.useCurrentUserInfo(),_t=s.canUserManageGroups(Rt),R=Z||xe,Qe=R?{id:R.id,title:(i==null?void 0:i.title)||R.title||"Dashboard"}:null,{handleAddNewFrame:Ut}=s.useAddNewFrame(),[Me,Ie]=v.useState(!1),[Tt,te]=v.useState(!1),[Ae,be]=v.useState("close"),se=s.useUpdateResource(s.ResourceType.DASHBOARD),[A,ve]=v.useState(null),Ft=async(d,M)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:d,previousTitle:M}),se.mutate({resourceId:i.id,data:{title:d}},{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(ge&&ge.length>0){const d=i==null?void 0:i.id;if(d){const M=ge.find(_=>_.id===d);M&&Ke(M)}}},[ge,i==null?void 0:i.id,Ke]);const re=a.orgUserId||a.tenantId,Pe=v.useMemo(()=>er({accessToken:t==null?void 0:t.accessToken,dashboardId:(i==null?void 0:i.id)||r||a.dashboard_id,selectedSheetId:N?w: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,w,y,a.dashboard_id]),We=C&&!E&&re&&fe,{setDashboard:Je}=m.useDashboardStore(d=>d.actions),Xe=m.useDashboardStore(d=>d.semanticExecutionPayload),qt=()=>{He(!0)},Oe=()=>{He(!1),Ve(!1),ve(null)};v.useEffect(()=>{if(!C){A&&ve(null);return}A||!i||b||ve(xt(i,Xe))},[i,A,C,b,Xe]);const ye=(A==null?void 0:A.dashboard)??null,{isDirty:Ye,isDirtyPending:$t,resetDirty:je}=ns.useDebouncedDirtyCheck(i,ye,300,1e3,Ue.serializeDashboardForDirtyCheck),Ze=v.useCallback(()=>ye?Ue.serializeDashboardForDirtyCheck(i)!==Ue.serializeDashboardForDirtyCheck(ye):!1,[i,ye]),et=Ye||$t,we=Me||se.isPending,Bt=()=>{Ze()?(be("close"),te(!0)):(Oe(),je())},Gt=async()=>{await Re({closeAfterSave:!0,navigateHomeAfterSave:Ae==="home"})},zt=()=>{const d=Ae==="home"&&!!ee;A&&Je(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),Oe(),d&&Ee(),be("close"),te(!1),je()},Ht=()=>{A&&(Je(A.dashboard,{semanticExecutionPayload:A.semanticExecutionPayload}),je())},Vt=()=>{if(ee){if(C&&Ze()){be("home"),te(!0);return}Ee()}};async function Re(d){const M=m.useDashboardStore.getState().dashboard;if(!M)return;const _=(d==null?void 0:d.closeAfterSave)??O,Yt=(d==null?void 0:d.navigateHomeAfterSave)??!1;q(_),_&&te(!1);const Zt=s.cloneDeep(M);T(!0),W(null),j([]),Ie(!0);const es={template:M};se.mutate({resourceId:M.id,data:es},{onSuccess:I=>{var Se,De,ct;const B=(I==null?void 0:I.id)||((Se=I==null?void 0:I.dashboard)==null?void 0:Se.id)||((De=I==null?void 0:I.resource)==null?void 0:De.id)||((ct=I==null?void 0:I.template)==null?void 0:ct.id)||null;if(!M.id&&B){const _e=m.useAIInteractionStore.getState(),Ne=_e.pendingDashboardDraftMigration;(Ne==null?void 0:Ne.scopeKey)===l?_e.actions.setPendingDashboardDraftMigrationExpectedDashboardId(B):Ne&&_e.actions.clearPendingDashboardDraftMigration()}Ie(!1),s.ue.success("Dashboard saved!"),ve(xt(Zt,m.useDashboardStore.getState().semanticExecutionPayload)),T(!1),q(!1),_&&(Oe(),je(),Yt&&ee&&Ee()),be("close")},onError:I=>{Ie(!1),W("Failed to save dashboard. Please try again.");const B=I.details,Se=Array.isArray(B==null?void 0:B.errors)?(B.errors||[]).filter(De=>typeof De=="string"):[];j(Xs({errors:Se,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Kt(){if(G(!0),!p||!g)return;const d=m.useDashboardStore.getState().dashboard;if(!d){G(!1);return}const M=JSON.stringify(d),_={...g,template:M,filterValues:he};await $e(a.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),ke==null||ke(d),G(!1)}const tt=(g==null?void 0:g.name)||i.title;se.isPending&&console.log("Title during update:",{title:tt,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:g==null?void 0:g.name});const Qt=ee&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl),Wt=c&&ee,$=(i==null?void 0:i.id)||null,Jt=Ys((it=a.config)==null?void 0:it.showBriefings,n),ne=!!$&&At===$,Xt=()=>{$&&Pt({dashboardId:ne?null:$})};return!c&&!E?null: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:[Wt&&!E&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Vt,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})}),!E&&c&&(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:tt||"Untitled Dashboard",onSave:d=>{console.log("EditableText onSave called:",{newTitle:d,canEditDashboard:fe,dashboardId:i==null?void 0:i.id});const M=(i==null?void 0:i.title)||"";D(d),Ft(d,M)},isEditable:fe&&!g,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:se.isPending}),ne&&e.jsx("span",{className:"shrink-0 rounded-[4px] border border-border/60 px-1.5 py-px text-[10px] font-medium uppercase tracking-[0.06em] text-muted-foreground",title:"Default dashboard",children:"Default"}),Qt&&$&&e.jsx(m.TooltipProvider,{children:e.jsxs(m.Tooltip,{children:[e.jsx(m.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{variant:"ghost",size:"xs",onClick:Xt,disabled:Ot||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":ne?"Clear default dashboard":"Set as default dashboard",children:ne?e.jsx(s.PinOff,{className:"h-3.5 w-3.5"}):e.jsx(s.Pin,{className:"h-3.5 w-3.5"})})}),e.jsx(m.TooltipContent,{children:e.jsx("p",{children:ne?"Clear default":"Set as default"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[E&&e.jsxs(e.Fragment,{children:[e.jsx(P.AdvancedModeToggle,{}),e.jsx(P.VisualEditingControls,{})]}),!E&&c&&((dt=R==null?void 0:R.permissions)==null?void 0:dt.canShare)&&e.jsxs(m.Button,{variant:"outline",size:"xs",onClick:()=>ie(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!E&&!C&&c&&$&&Jt&&e.jsx(P.DashboardBriefingLauncher,{dashboardId:$,dashboardTitle:(i==null?void 0:i.title)||(R==null?void 0:R.title)}),!E&&C&&f.canUseFilters&&c&&e.jsx(P.DashboardFilterControlsLauncher,{}),C&&!E&&re&&g&&o&&c&&e.jsxs(m.Button,{variant:"secondary",size:"xs",disabled:J,onClick:Kt,children:[e.jsx(lt.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),C&&!E&&c&&!N&&e.jsxs("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[e.jsxs(m.Button,{variant:"ghost",size:"xs",disabled:!C,onClick:()=>void Ut(),className:"h-full rounded-none border-0 shadow-none hover:bg-accent",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(m.Button,{variant:"ghost",size:"xs",className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open visual options",disabled:!C,children:e.jsx(m.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>Y(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"From library..."]})})]}),e.jsx(P.VisualsLibraryDialog,{open:pe,onOpenChange:Y})]}),!E&&!C&&fe&&c&&e.jsxs(m.Button,{size:"xs",onClick:qt,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),We&&c&&Ye&&e.jsxs(m.Button,{variant:"outline",size:"xs",onClick:Ht,disabled:we,children:[e.jsx(P.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),We&&c&&e.jsxs(m.Button,{size:"xs",className:m.cn(!et&&"opacity-60"),disabled:we||!et,onClick:()=>Re(),children:[we?e.jsx(m.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(lt.Save,{className:"h-3.5 w-3.5"}),we?"Saving...":"Save"]}),C&&!E&&c&&e.jsxs(m.Button,{variant:"outline",size:"xs",onClick:Bt,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!E&&c&&e.jsx("div",{className:"ml-2",children:e.jsx(P.NotificationBell,{})}),!E&&o&&e.jsx(gs,{}),!E&&c&&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:()=>ue(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(s.DropdownMenuSeparator,{}),_t&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>H(!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:()=>K(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),o&&c&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var d;t!=null&&t.accessToken&&((d=navigator==null?void 0:navigator.clipboard)!=null&&d.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:!Pe,onSelect:()=>{var d;if(!Pe){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(d=navigator==null?void 0:navigator.clipboard)!=null&&d.writeText?navigator.clipboard.writeText(Pe).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:()=>m.invalidateToken(a.apiServiceUrl),children:[e.jsx(us,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:u,children:[e.jsx(as.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Ve(!ze),children:[e.jsx(os.Braces,{className:"h-3.5 w-3.5"}),ze?"Hide dashboard JSON":"Show dashboard JSON"]}),re&&C&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>ce(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),re&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(ws,{})})]})]})]})]}),X&&Qe&&e.jsx(s.ShareDialog,{resource:Qe,resourceType:s.ResourceType.DASHBOARD,onClose:()=>ie(!1)}),e.jsx(zs,{open:z,onOpenChange:H}),e.jsx(rs.CalendarPreferencesDialog,{open:V,onOpenChange:K}),o&&re&&c&&e.jsx(js,{open:de,onOpenChange:ce}),c&&e.jsx(s.DownloadPdf,{open:le,onOpenChange:ue}),e.jsx(s.AlertDialog,{open:me,onOpenChange:d=>{!d&&Me&&!Q||(T(d),d||(W(null),j([]),q(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:Q?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:Q?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),F.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:F.slice(0,5).map(d=>e.jsx("li",{children:d},d))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:Q?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{T(!1),W(null),j([]),q(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Re({closeAfterSave:O,navigateHomeAfterSave:Ae==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(m.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(P.UnsavedChangesAlert,{open:Tt,onOpenChange:d=>{te(d)},onSave:Gt,onDiscard:zt,isSaving:Me,saveLabel:"Save",discardLabel:"Discard"})]})]})}function er({accessToken:t,dashboardId:a,selectedSheetId:r,pageSize:n,orientation:o,theme:u}){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),u&&f.searchParams.set("theme",u);const c=new URL("http://127.0.0.1:3002/");return c.searchParams.set("pdfMode","document"),c.searchParams.set("pageSize",n||"letter"),c.searchParams.set("orientation",o||"portrait"),c.searchParams.set("url",f.toString()),c.toString()}exports.default=Zs;