react-semaphor 0.1.311 → 0.1.314

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 (51) hide show
  1. package/dist/brand-studio/index.cjs +1 -1
  2. package/dist/brand-studio/index.js +4 -4
  3. package/dist/chunks/{braces-CSECDaJQ.js → braces-CWi8x9ww.js} +1 -1
  4. package/dist/chunks/{braces-DwaAt32i.js → braces-NfG5hX2c.js} +1 -1
  5. package/dist/chunks/calendar-preferences-dialog-BzpQ5u4h.js +1 -0
  6. package/dist/chunks/calendar-preferences-dialog-D70CuT-1.js +456 -0
  7. package/dist/chunks/{chevrons-up-down-DJhB8JNW.js → chevrons-up-down-B2viXO2I.js} +1 -1
  8. package/dist/chunks/{chevrons-up-down-3vBEM7eI.js → chevrons-up-down-DiWloubI.js} +1 -1
  9. package/dist/chunks/dashboard-controls-BS_aZcxs.js +57 -0
  10. package/dist/chunks/dashboard-controls-DbKtbw1V.js +2021 -0
  11. package/dist/chunks/dashboard-filter-controls-launcher-C8Wm2Smj.js +1540 -0
  12. package/dist/chunks/dashboard-filter-controls-launcher-CMXpudFJ.js +11 -0
  13. package/dist/chunks/{dashboard-json-GL_IXTCk.js → dashboard-json-CJCAen1R.js} +2 -2
  14. package/dist/chunks/{dashboard-json-B_rQbUUz.js → dashboard-json-v2C6Tmqf.js} +1 -1
  15. package/dist/chunks/{edit-dashboard-visual-nGSsSTYx.js → edit-dashboard-visual-DljWvnMy.js} +4758 -4694
  16. package/dist/chunks/edit-dashboard-visual-lRn3FeaP.js +183 -0
  17. package/dist/chunks/{index-9v7DehZd.js → index-P5hPTTzm.js} +33681 -33108
  18. package/dist/chunks/{index-CGCrm-dj.js → index-XYIIY48z.js} +228 -228
  19. package/dist/chunks/{palette-CI2J34i6.js → palette-CIuwlEiG.js} +1 -1
  20. package/dist/chunks/{palette-C5o9bLo6.js → palette-CJTdBzJB.js} +1 -1
  21. package/dist/chunks/{resource-management-panel-CNmVHnCz.js → resource-management-panel-CAxXzMdi.js} +1 -1
  22. package/dist/chunks/{resource-management-panel-DTg9_DI9.js → resource-management-panel-Dk0DzgVm.js} +18 -18
  23. package/dist/chunks/{save-CMv91_Hz.js → save-B8x5Vi0W.js} +1 -1
  24. package/dist/chunks/{save-Cpz6BWx9.js → save-_ALpoMy6.js} +1 -1
  25. package/dist/chunks/{switch-Dhoqe3OE.js → switch-B6fh8nb-.js} +139 -138
  26. package/dist/chunks/{switch-otrSiyjH.js → switch-DPaKnsb8.js} +14 -14
  27. package/dist/chunks/{use-create-flow-overlay-state-C8WGfC8T.js → use-create-flow-overlay-state-Cqf7GaFm.js} +511 -483
  28. package/dist/chunks/use-create-flow-overlay-state-DMZTflFt.js +16 -0
  29. package/dist/chunks/{use-visual-utils-RkPa2gqQ.js → use-visual-utils-CPMQLBYR.js} +12 -12
  30. package/dist/chunks/{use-visual-utils-BeJ73yvV.js → use-visual-utils-CQQ3jvDn.js} +1 -1
  31. package/dist/dashboard/index.cjs +1 -1
  32. package/dist/dashboard/index.js +1 -1
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.js +118 -117
  35. package/dist/style.css +1 -1
  36. package/dist/surfboard/index.cjs +1 -1
  37. package/dist/surfboard/index.js +7 -8
  38. package/dist/types/dashboard.d.ts +1 -1
  39. package/dist/types/main.d.ts +76 -34
  40. package/dist/types/shared.d.ts +1 -1
  41. package/dist/types/surfboard.d.ts +1 -11
  42. package/dist/types/types.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/dist/chunks/dashboard-controls-CeKjYa7s.js +0 -2274
  45. package/dist/chunks/dashboard-controls-Ds8Hmo3Q.js +0 -57
  46. package/dist/chunks/dashboard-filter-controls-button-CWL2jJcu.js +0 -11
  47. package/dist/chunks/dashboard-filter-controls-button-Tk5lhwVV.js +0 -1116
  48. package/dist/chunks/dashboard-summary-settings-dialog-CcszMc1A.js +0 -545
  49. package/dist/chunks/dashboard-summary-settings-dialog-DgqFlYl9.js +0 -1
  50. package/dist/chunks/edit-dashboard-visual-Bu2rxJjm.js +0 -183
  51. package/dist/chunks/use-create-flow-overlay-state-DiH6M1Cd.js +0 -16
@@ -0,0 +1,57 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-DPaKnsb8.js"),s=require("./index-XYIIY48z.js"),b=require("react");require("./index-DRlMUglg.js");require("react-dom");const G=require("./dashboard-filter-controls-launcher-CMXpudFJ.js"),Js=require("./index-D7KJindZ.js"),Ys=require("./calendar-preferences-dialog-BzpQ5u4h.js"),Xs=require("./use-debounced-dirty-check-XHSwAefL.js"),Ae=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),ls=require("./save-B8x5Vi0W.js"),Zs=require("./palette-CJTdBzJB.js"),et=require("./braces-NfG5hX2c.js");function st(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const L=st(b);/**
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 tt=o.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 at=o.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
+ * @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 rt=o.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
+ * @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 nt=o.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
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 ot=o.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
+ * @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 it=o.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
+ * @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 ct=o.createLucideIcon("Undo2",[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]]);/**
37
+ * @license lucide-react v0.453.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const Te=o.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 Pe={exports:{}},ke={};/**
42
+ * @license React
43
+ * use-sync-external-store-shim.production.js
44
+ *
45
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
46
+ *
47
+ * This source code is licensed under the MIT license found in the
48
+ * LICENSE file in the root directory of this source tree.
49
+ */var ds;function lt(){if(ds)return ke;ds=1;var t=b;function n(x,p){return x===p&&(x!==0||1/x===1/p)||x!==x&&p!==p}var r=typeof Object.is=="function"?Object.is:n,a=t.useState,i=t.useEffect,u=t.useLayoutEffect,d=t.useDebugValue;function m(x,p){var f=p(),c=a({inst:{value:f,getSnapshot:p}}),j=c[0].inst,D=c[1];return u(function(){j.value=f,j.getSnapshot=p,g(j)&&D({inst:j})},[x,f,p]),i(function(){return g(j)&&D({inst:j}),x(function(){g(j)&&D({inst:j})})},[x]),d(f),f}function g(x){var p=x.getSnapshot;x=x.value;try{var f=p();return!r(x,f)}catch{return!0}}function y(x,p){return p()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?y:m;return ke.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,ke}var Oe={};/**
50
+ * @license React
51
+ * use-sync-external-store-shim.development.js
52
+ *
53
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
54
+ *
55
+ * This source code is licensed under the MIT license found in the
56
+ * LICENSE file in the root directory of this source tree.
57
+ */var us;function dt(){return us||(us=1,process.env.NODE_ENV!=="production"&&function(){function t(f,c){return f===c&&(f!==0||1/f===1/c)||f!==f&&c!==c}function n(f,c){h||i.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 j=c();if(!x){var D=c();u(j,D)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),x=!0)}D=d({inst:{value:j,getSnapshot:c}});var w=D[0].inst,S=D[1];return g(function(){w.value=j,w.getSnapshot=c,r(w)&&S({inst:w})},[f,j,c]),m(function(){return r(w)&&S({inst:w}),f(function(){r(w)&&S({inst:w})})},[f]),y(j),j}function r(f){var c=f.getSnapshot;f=f.value;try{var j=c();return!u(f,j)}catch{return!0}}function a(f,c){return c()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var i=b,u=typeof Object.is=="function"?Object.is:t,d=i.useState,m=i.useEffect,g=i.useLayoutEffect,y=i.useDebugValue,h=!1,x=!1,p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?a:n;Oe.useSyncExternalStore=i.useSyncExternalStore!==void 0?i.useSyncExternalStore:p,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Oe}process.env.NODE_ENV==="production"?Pe.exports=lt():Pe.exports=dt();var ut=Pe.exports;const ye=["light","dark","system"];function mt(){const{theme:t,setTheme:n}=s.useTheme(),r=o.useDashboardStore(d=>d.actions.setDashboardTheme);function a(){const d=ye.includes(t)?t:"system",m=ye[(ye.indexOf(d)+1)%ye.length];n(m),r(m)}const i=t==="light"?it:t==="dark"?nt:rt,u=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(o.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":u,title:u,children:e.jsx(i,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function ht(t,n,r,a,i){if(!i)return null;const u=JSON.stringify(r),d=`${t}/v1/lens`;return await o.postRequest(d,i,{name:n,template:u,filterValues:a,operation:"create"})}async function Ue(t,n,r){if(!r)return null;const{id:a,template:i,filterValues:u,isDefault:d,shared:m}=n,g=`${t}/v1/lens`;return await o.postRequest(g,r,{lensId:a,template:i,filterValues:u,isDefault:d,shared:m,operation:"update"})}async function pt(t,n,r){if(!r)return null;const a=`${t}/v1/lens`;return await o.postRequest(a,r,{operation:"delete",lensId:n})}const xt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function ft({open:t,onOpenChange:n}={}){const[r,a]=b.useState(""),[i,u]=b.useState(!1),d=o.useDashboardStore(C=>C.lenses),{setLenses:m,setSelectedLensId:g}=o.useDashboardActions(),[y,h]=b.useState(!1),[x,p]=b.useState(!1),f=t!==void 0,c=f?t:x,j=C=>{f||p(C),n==null||n(C)},D=o.useDashboardStore(C=>C.dashboard),w=o.useDashboardStore(C=>C.filterValues),{authToken:S,tokenProps:N}=s.useSemaphorContext();async function A(){h(!0);const C=await ht(N.apiServiceUrl,r,D,w,S==null?void 0:S.accessToken);C&&(m([...d||[],C]),g(C.id),j(!1)),h(!1)}return e.jsxs(s.Dialog,{open:c,onOpenChange:j,children:[f?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(o.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(o.Label,{htmlFor:"lens-name",className:xt,children:"Name"}),e.jsx(o.Input,{id:"lens-name",size:"xs",value:r,placeholder:"Monthly review, West region, …",onChange:C=>a(C.target.value)}),i&&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(o.Button,{variant:"outline",size:"xs",onClick:()=>j(!1),children:"Cancel"}),e.jsx(o.Button,{size:"xs",type:"submit",onClick:A,disabled:y||!r.trim(),children:y?"Creating…":"Create"})]})]})]})}function gt({includeLabel:t=!1}={}){const n=o.useDashboardStore(h=>h.lenses),r=o.useDashboardStore(h=>h.selectedLensId),{setLenses:a,setSelectedLensId:i}=o.useDashboardActions(),{authToken:u,tokenProps:d}=s.useSemaphorContext();async function m(h){i(h)}async function g(h){if(await pt(d.apiServiceUrl,h,u==null?void 0:u.accessToken)){const p=n==null?void 0:n.filter(f=>f.id!==h);a(p||[]),i("original")}}async function y(h){const x=n==null?void 0:n.map(c=>c.id===h.id?{...c,isDefault:!h.isDefault}:{...c,isDefault:!1});a(x||[]);const p={...h,isDefault:!h.isDefault};await Ue(d.apiServiceUrl,p,u==null?void 0:u.accessToken);const f=n==null?void 0:n.find(c=>c.isDefault);if(f&&f.id!==h.id){const c={...f,isDefault:!1};await Ue(d.apiServiceUrl,c,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:m,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.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:x=>{x.preventDefault(),y(h)},className:o.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:x=>{x.preventDefault(),g(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 bt(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:r,userContext:a}=s.useCurrentUserInfo(),i=b.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),u=b.useMemo(()=>m=>i&&i[m]!==void 0&&i[m]===!1?!1:n(m),[i,n,t]),d=b.useMemo(()=>{var m,g,y,h,x;return{canEdit:((m=a==null?void 0:a.permissions)==null?void 0:m.canEdit)??s.canUserEdit(r),canUseFilters:((g=a==null?void 0:a.permissions)==null?void 0:g.canEdit)??s.canUserUseFilters(r),canManageDashboards:((y=a==null?void 0:a.permissions)==null?void 0:y.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((h=a==null?void 0:a.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((x=a==null?void 0:a.permissions)==null?void 0:x.canEdit)??s.canUserAccessVisuals(r)}},[r,a]);return{displayPreferences:t,shouldShowElement:u,permissions:d,currentUser:r}}const vt=async(t,n,r)=>{const a=`${t}/management/v1/groups`;return await o.postRequestRegular(a,n,r)},yt=async(t,n,r)=>{const a=`${t}/management/v1/groups/${r}`;await o.requestJsonRegular(a,n,"DELETE")},jt=async(t,n,r,a)=>{const i=`${t}/management/v1/groups/${r}/members`;return await o.postRequestRegular(i,n,a)},St=async(t,n,r,a)=>{const i=`${t}/management/v1/groups/${r}/members`;await o.requestJsonRegular(i,n,"DELETE",a)};function Dt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>vt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:a=>{console.error("Failed to create group:",a),s.ue.error("Failed to create group",{description:o.getRequestErrorMessage(a,"Failed to create group")})}})}function wt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>yt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",i]}),s.ue.success("Group deleted successfully")},onError:a=>{console.error("Failed to delete group:",a),s.ue.error("Failed to delete group",{description:o.getRequestErrorMessage(a,"Failed to delete group")})}})}function Nt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:i})=>jt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,i),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["group",i.groupId]}),r.invalidateQueries({queryKey:["group-members",i.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:a=>{console.error("Failed to add group members:",a),s.ue.error("Failed to add members",{description:o.getRequestErrorMessage(a,"Failed to add members")})}})}function Ct(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:i})=>St(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,i),onSuccess:(a,i)=>{r.invalidateQueries({queryKey:["group",i.groupId]}),r.invalidateQueries({queryKey:["group-members",i.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:a=>{console.error("Failed to remove group members:",a),s.ue.error("Failed to remove members",{description:o.getRequestErrorMessage(a,"Failed to remove members")})}})}const ms="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Mt({onSuccess:t,tenantId:n,isTenantUser:r}){const[a,i]=b.useState(""),[u,d]=b.useState(""),[m,g]=b.useState({}),y=Dt(),h=()=>{const p={};return a.trim()?a.length<3?p.name="Group name must be at least 3 characters":a.length>50&&(p.name="Group name must be less than 50 characters"):p.name="Group name is required",u&&u.length>200&&(p.description="Description must be less than 200 characters"),g(p),Object.keys(p).length===0},x=async p=>{if(p.preventDefault(),!h())return;const f={name:a.trim(),description:u.trim()||void 0,type:r?"TENANT_GROUP":"ORG_GROUP",...r&&n?{tenantId:n}:{}};try{await y.mutateAsync(f),i(""),d(""),g({}),t()}catch(c){console.error("Failed to create group:",c)}};return e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(o.Label,{htmlFor:"group-name",className:ms,children:["Group name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(o.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:a,onChange:p=>{i(p.target.value),m.name&&g(f=>({...f,name:""}))},className:m.name?"border-destructive":"",disabled:y.isPending}),m.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{htmlFor:"group-description",className:ms,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:u,onChange:p=>{d(p.target.value),m.description&&g(f=>({...f,description:""}))},className:`text-[13px] ${m.description?"border-destructive":""}`,disabled:y.isPending,rows:3}),m.description?e.jsx("p",{className:"text-[12px] text-destructive",children:m.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[u.length,"/200"]})]}),e.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[e.jsx(o.Info,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),e.jsx("p",{children:"This group will be accessible to users in your workspace. You can add members after creating it."})]}),e.jsxs("div",{className:"flex justify-end gap-1.5 pt-1",children:[e.jsx(o.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{i(""),d(""),g({})},disabled:y.isPending,children:"Clear"}),e.jsx(o.Button,{type:"submit",size:"xs",disabled:y.isPending||!a.trim(),children:y.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function Lt(t,n=[]){let r=[];function a(u,d){const m=L.createContext(d);m.displayName=u+"Context";const g=r.length;r=[...r,d];const y=x=>{var w;const{scope:p,children:f,...c}=x,j=((w=p==null?void 0:p[t])==null?void 0:w[g])||m,D=L.useMemo(()=>c,Object.values(c));return e.jsx(j.Provider,{value:D,children:f})};y.displayName=u+"Provider";function h(x,p){var j;const f=((j=p==null?void 0:p[t])==null?void 0:j[g])||m,c=L.useContext(f);if(c)return c;if(d!==void 0)return d;throw new Error(`\`${x}\` must be used within \`${u}\``)}return[y,h]}const i=()=>{const u=r.map(d=>L.createContext(d));return function(m){const g=(m==null?void 0:m[t])||u;return L.useMemo(()=>({[`__scope${t}`]:{...m,[t]:g}}),[m,g])}};return i.scopeName=t,[a,Et(i,...n)]}function Et(...t){const n=t[0];if(t.length===1)return n;const r=()=>{const a=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(u){const d=a.reduce((m,{useScope:g,scopeName:y})=>{const x=g(u)[`__scope${y}`];return{...m,...x}},{});return L.useMemo(()=>({[`__scope${n.scopeName}`]:d}),[d])}};return r.scopeName=n.scopeName,r}var It=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],_e=It.reduce((t,n)=>{const r=o.createSlot(`Primitive.${n}`),a=L.forwardRef((i,u)=>{const{asChild:d,...m}=i,g=d?r:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(g,{...m,ref:u})});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function At(){return ut.useSyncExternalStore(kt,()=>!0,()=>!1)}function kt(){return()=>{}}var Re="Avatar",[Ot]=Lt(Re),[Tt,xs]=Ot(Re),fs=L.forwardRef((t,n)=>{const{__scopeAvatar:r,...a}=t,[i,u]=L.useState("idle");return e.jsx(Tt,{scope:r,imageLoadingStatus:i,onImageLoadingStatusChange:u,children:e.jsx(_e.span,{...a,ref:n})})});fs.displayName=Re;var gs="AvatarImage",bs=L.forwardRef((t,n)=>{const{__scopeAvatar:r,src:a,onLoadingStatusChange:i=()=>{},...u}=t,d=xs(gs,r),m=Pt(a,u),g=o.useCallbackRef(y=>{i(y),d.onImageLoadingStatusChange(y)});return o.useLayoutEffect2(()=>{m!=="idle"&&g(m)},[m,g]),m==="loaded"?e.jsx(_e.img,{...u,ref:n,src:a}):null});bs.displayName=gs;var vs="AvatarFallback",ys=L.forwardRef((t,n)=>{const{__scopeAvatar:r,delayMs:a,...i}=t,u=xs(vs,r),[d,m]=L.useState(a===void 0);return L.useEffect(()=>{if(a!==void 0){const g=window.setTimeout(()=>m(!0),a);return()=>window.clearTimeout(g)}},[a]),d&&u.imageLoadingStatus!=="loaded"?e.jsx(_e.span,{...i,ref:n}):null});ys.displayName=vs;function hs(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function Pt(t,{referrerPolicy:n,crossOrigin:r}){const a=At(),i=L.useRef(null),u=a?(i.current||(i.current=new window.Image),i.current):null,[d,m]=L.useState(()=>hs(u,t));return o.useLayoutEffect2(()=>{m(hs(u,t))},[u,t]),o.useLayoutEffect2(()=>{const g=x=>()=>{m(x)};if(!u)return;const y=g("loaded"),h=g("error");return u.addEventListener("load",y),u.addEventListener("error",h),n&&(u.referrerPolicy=n),typeof r=="string"&&(u.crossOrigin=r),()=>{u.removeEventListener("load",y),u.removeEventListener("error",h)}},[u,r,n]),d}var js=fs,Ss=bs,Ds=ys;const Fe=L.forwardRef(({className:t,...n},r)=>e.jsx(js,{ref:r,className:o.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Fe.displayName=js.displayName;const Ut=L.forwardRef(({className:t,...n},r)=>e.jsx(Ss,{ref:r,className:o.cn("aspect-square h-full w-full",t),...n}));Ut.displayName=Ss.displayName;const Ge=L.forwardRef(({className:t,...n},r)=>e.jsx(Ds,{ref:r,className:o.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Ge.displayName=Ds.displayName;function _t({open:t,onOpenChange:n,group:r,onUpdate:a}){const[i,u]=b.useState("members"),[d,m]=b.useState(""),[g,y]=b.useState([]),[h,x]=b.useState([]),{data:p,isLoading:f,refetch:c}=s.useGroupMembers(r.id),j=r.type==="TENANT_GROUP"?"tenant":"organization",{users:D,isLoading:w}=s.useUnifiedUsers({type:j,tenantId:r.tenantId||void 0,active:!0,limit:100}),S=Nt(),N=Ct(),A=(p==null?void 0:p.members)||[],C=b.useMemo(()=>new Set(A.map(v=>v.userId)),[A]),U=b.useMemo(()=>D.filter(v=>!C.has(v.id)),[D,C]),$=b.useMemo(()=>{if(!d)return U;const v=d.toLowerCase();return U.filter(E=>{var P,R;return((P=E.name)==null?void 0:P.toLowerCase().includes(v))||((R=E.email)==null?void 0:R.toLowerCase().includes(v))})},[U,d]),M=b.useMemo(()=>{if(!d)return A;const v=d.toLowerCase();return A.filter(E=>{var P,R,te,V;return((R=(P=E.user)==null?void 0:P.name)==null?void 0:R.toLowerCase().includes(v))||((V=(te=E.user)==null?void 0:te.email)==null?void 0:V.toLowerCase().includes(v))})},[A,d]),q=async()=>{if(g.length!==0)try{await S.mutateAsync({groupId:r.id,data:{userIds:g,userType:j==="tenant"?"tenant":"org"}}),y([]),u("members"),c(),a==null||a()}catch(v){console.error("Failed to add members:",v)}},se=async()=>{if(h.length!==0)try{await N.mutateAsync({groupId:r.id,data:{userIds:h}}),x([]),c(),a==null||a()}catch(v){console.error("Failed to remove members:",v)}},z=v=>{y(E=>E.includes(v)?E.filter(P=>P!==v):[...E,v])},H=v=>{x(E=>E.includes(v)?E.filter(P=>P!==v):[...E,v])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:r.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[A.length," ",A.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",r.name," group"]})]}),e.jsxs(o.Tabs,{value:i,onValueChange:v=>{u(v),m(""),x([])},className:"mt-4",children:[e.jsxs(o.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(o.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(o.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(o.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{placeholder:"Search members...",value:d,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:f?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):M.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:d?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:M.map(v=>e.jsx(Rt,{member:v,selected:h.includes(v.userId),onToggle:()=>H(v.userId)},v.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," member",h.length!==1?"s":""," selected"]}),e.jsx(o.Button,{variant:"destructive",size:"sm",onClick:se,disabled:N.isPending,children:N.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),e.jsxs(o.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{placeholder:"Search users to add...",value:d,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:"h-[300px]",children:w?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):$.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Te,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No available users"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:$.map(v=>e.jsx(Ft,{user:v,selected:g.includes(v.id),onToggle:()=>z(v.id)},v.id))})}),g.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[g.length," user",g.length!==1?"s":""," selected"]}),e.jsx(o.Button,{onClick:q,disabled:S.isPending,children:S.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function Rt({member:t,selected:n,onToggle:r}){var i,u,d,m;const a=((u=(i=t.user)==null?void 0:i.name)==null?void 0:u.split(" ").map(g=>g[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(Ge,{className:"text-xs",children:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((d=t.user)==null?void 0:d.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function Ft({user:t,selected:n,onToggle:r}){var i;const a=((i=t.name)==null?void 0:i.split(" ").map(u=>u[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(Ge,{className:"text-xs",children:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.email})]})]})}function Gt({open:t,onOpenChange:n}){const[r,a]=b.useState("groups"),[i,u]=b.useState(""),[d,m]=b.useState(null),[g,y]=b.useState(!1),[h,x]=b.useState(null),{tokenProps:p}=s.useSemaphorContext(),{currentUser:f}=s.useCurrentUserInfo(),c=wt(),j=(f==null?void 0:f.type)==="tenant",D=p==null?void 0:p.tenantId,{groups:w,isLoading:S,refetch:N}=s.useGroups({type:j?"TENANT_GROUP":"all",tenantId:j?D:void 0,includeMembers:!1}),A=w.filter(M=>{var q;return M.name.toLowerCase().includes(i.toLowerCase())||((q=M.description)==null?void 0:q.toLowerCase().includes(i.toLowerCase()))}),C=async()=>{if(h)try{await c.mutateAsync(h.id),x(null),N()}catch(M){console.error("Failed to delete group:",M)}},U=M=>{m(M),y(!0)},$=()=>{a("groups"),N()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-3xl rounded-[6px] border-border/60 sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Group management"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Manage groups, create new ones, and control membership."})]}),e.jsxs(o.Tabs,{value:r,onValueChange:a,className:"mt-2",children:[e.jsxs(o.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[e.jsx(o.TabsTrigger,{value:"groups",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Groups"}),e.jsx(o.TabsTrigger,{value:"create",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Create group"})]}),e.jsx(o.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{size:"xs",placeholder:"Search groups…",value:i,onChange:M=>u(M.target.value),className:"pl-7"})]}),e.jsx(o.ScrollArea,{className:"h-[400px]",children:S?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(M=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},M))}):A.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx("p",{className:"text-[13px]",children:"No groups found."}),e.jsx("p",{className:"mt-1 text-[12px]",children:i?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:A.map(M=>e.jsx($t,{group:M,onManageMembers:()=>U(M),onDelete:()=>x(M),currentUserId:f==null?void 0:f.id},M.id))})})]})}),e.jsx(o.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Mt,{onSuccess:$,tenantId:D,isTenantUser:j})})]})]})}),d&&e.jsx(_t,{open:g,onOpenChange:y,group:d,onUpdate:()=>N()}),e.jsx(s.AlertDialog,{open:!!h,onOpenChange:()=>x(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete group"}),e.jsxs(s.AlertDialogDescription,{children:['Delete "',h==null?void 0:h.name,`"? This removes all members and can't be undone.`]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:C,disabled:c.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:c.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function $t({group:t,onManageMembers:n,onDelete:r,currentUserId:a}){const i=t.createdBy===a;return e.jsx("div",{className:"rounded-[6px] border border-border/60 bg-card px-3 py-2.5 transition-colors hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h4",{className:"text-[13px] font-medium text-foreground",children:t.name}),t.description&&e.jsx("p",{className:"text-[12px] text-muted-foreground",children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),e.jsxs("span",{children:["Created ",Js.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:n,title:"Manage members","aria-label":"Manage members",children:e.jsx(Te,{className:"h-3.5 w-3.5"})}),i&&e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:r,title:"Delete group","aria-label":"Delete group",children:e.jsx(s.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function Z(t,n,r){var u,d;const a=(t.controls||[]).find(m=>m.id===r);if(a)return a.label;const i=(d=(u=o.findCardById(t,n))==null?void 0:u.controls)==null?void 0:d.find(m=>m.id===r);return(i==null?void 0:i.label)||r}function ee(t,n){var r;return((r=o.findCardById(t,n))==null?void 0:r.title)||n}function qt(t){const{errors:n,dashboard:r}=t;if(!r)return n;const a=new Map;for(const i of n){const u=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(u){const[,h,x]=u,p=`${h}:${x}:missing-metric`;a.has(p)||a.set(p,`"${ee(r,h)}" has an outdated "${Z(r,h,x)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const d=i.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(d){const[,h,x]=d,p=`${h}:${x}:missing-group-by`;a.has(p)||a.set(p,`"${ee(r,h)}" has an outdated "${Z(r,h,x)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const m=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(m){const[,h,x]=m,p=`${h}:${x}:invalid-metric`;a.has(p)||a.set(p,`"${ee(r,h)}" has an invalid "${Z(r,h,x)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const g=i.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(g){const[,h,x]=g,p=`${h}:${x}:invalid-group-by`;a.has(p)||a.set(p,`"${ee(r,h)}" has an invalid "${Z(r,h,x)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const y=i.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(y){const[,h,x]=y,p=`${h}:${x}:missing-temporal-group-by`;a.has(p)||a.set(p,`"${ee(r,h)}" can no longer use "${Z(r,h,x)}" for time grain because the card does not currently group by a date field.`);continue}a.set(i,i)}return Array.from(a.values())}function ps(t,n){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(n)}}function Bt(){var ts,as,rs,ns,os,is;G.useExportRecovery(),G.useExportPolling();const{authToken:t,tokenProps:n,id:r}=s.useSemaphorContext(),{isLocalDev:a}=s.useDashboardPreferences(),{openBrandStudioPreview:i}=s.useBrandStudioPreview(),{permissions:u}=bt(),d=s.useHasDashboardId(),{isLoading:m}=s.useDashboardQuery(),g=o.useDashboardStore(l=>l.theme),y=o.useDashboardStore(l=>l.isDownloadingPdf),h=o.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),x=o.useDashboardStore(l=>l.lenses),p=o.useDashboardStore(l=>l.selectedLensId),f=x==null?void 0:x.find(l=>l.id===p),c=o.useDashboardStore(l=>l.dashboard),j=o.useDashboardStore(l=>l.selectedSheetId),D=(ts=c==null?void 0:c.sheets)==null?void 0:ts.find(l=>l.id===j),w=o.isDocumentSheet(D),S=w?(as=D==null?void 0:D.document)==null?void 0:as.page:void 0,N=o.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:A}=o.useDashboardStore(l=>l.actions),[C,U]=b.useState(!1),[$,M]=b.useState(!1),[q,se]=b.useState(!1),[z,H]=b.useState(!1),[v,E]=b.useState(!1),[P,R]=b.useState(!1),[te,V]=b.useState(!1),[ws,ae]=b.useState(!1),[re,ne]=b.useState(null),[$e,oe]=b.useState([]),[qe,ie]=b.useState(!1),Ns=o.useDashboardStore(l=>l.isDashboardPanelOpen),Cs=o.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),Ms=o.useDashboardStore(l=>l.filterValues),O=o.useDashboardStore(l=>l.isVisualEditing);o.useEditorStore(l=>l.card);const K=s.useManagementStore(l=>l.selectedDashboard),ce=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),o.useDashboardStore(l=>l.selectedFrameId),o.useEditorStore(l=>l.frame);const le=K?(ns=K==null?void 0:K.permissions)==null?void 0:ns.canEdit:(rs=ce==null?void 0:ce.permissions)==null?void 0:rs.canEdit,Be=o.useDashboardStore(l=>l.showDashboardJSON),je=o.useDashboardStore(l=>l.onSaveFunction),{setIsDashboardEditing:ze,setShowDashboardJSON:He}=o.useDashboardStore(l=>l.actions),{setInitialDashboard:Ve,clearSelectedDashboard:Se}=s.useManagementStore(l=>l.actions),{resources:de}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:De}=s.useUserPreferences(),Ls=((os=De==null?void 0:De.preference)==null?void 0:os.defaultDashboardId)||null,{mutate:Es,isPending:Is}=s.useDefaultDashboardMutation(),{currentUser:As}=s.useCurrentUserInfo(),ks=s.canUserManageGroups(As),B=K||ce,Ke=B?{id:B.id,title:(c==null?void 0:c.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:Os}=s.useAddNewFrame(),[we,Ne]=b.useState(!1),[Ts,Q]=b.useState(!1),[Ce,ue]=b.useState("close"),W=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,me]=b.useState(null),Ps=async(l,I)=>{if(!(c!=null&&c.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:c.id,newTitle:l,previousTitle:I}),W.mutate({resourceId:c.id,data:{title:l}},{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"),A(I)}})};b.useEffect(()=>{if(de&&de.length>0){const l=c==null?void 0:c.id;if(l){const I=de.find(_=>_.id===l);I&&Ve(I)}}},[de,c==null?void 0:c.id,Ve]);const J=n.orgUserId||n.tenantId,Me=b.useMemo(()=>zt({accessToken:t==null?void 0:t.accessToken,dashboardId:(c==null?void 0:c.id)||r||n.dashboard_id,selectedSheetId:w?j:void 0,pageSize:S==null?void 0:S.size,orientation:S==null?void 0:S.orientation,theme:g}),[t==null?void 0:t.accessToken,r,c==null?void 0:c.id,w,S==null?void 0:S.orientation,S==null?void 0:S.size,j,g,n.dashboard_id]),Qe=N&&!O&&J&&le,{setDashboard:We}=o.useDashboardStore(l=>l.actions),Je=o.useDashboardStore(l=>l.semanticExecutionPayload),Us=()=>{ze(!0)},Le=()=>{ze(!1),He(!1),me(null)};b.useEffect(()=>{if(!N){T&&me(null);return}T||!c||m||me(ps(c,Je))},[c,T,N,m,Je]);const he=(T==null?void 0:T.dashboard)??null,{isDirty:Ye,isDirtyPending:_s,resetDirty:pe}=Xs.useDebouncedDirtyCheck(c,he,300,1e3,Ae.serializeDashboardForDirtyCheck),Xe=b.useCallback(()=>he?Ae.serializeDashboardForDirtyCheck(c)!==Ae.serializeDashboardForDirtyCheck(he):!1,[c,he]),Ze=Ye||_s,xe=we||W.isPending,Rs=()=>{Xe()?(ue("close"),Q(!0)):(Le(),pe())},Fs=async()=>{await Ee({closeAfterSave:!0,navigateHomeAfterSave:Ce==="home"})},Gs=()=>{T&&We(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),Le(),Ce==="home"&&Se(),ue("close"),Q(!1),pe()},$s=()=>{T&&(We(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),pe())},qs=()=>{if(N&&Xe()){ue("home"),Q(!0);return}Se()};async function Ee(l){const I=o.useDashboardStore.getState().dashboard;if(!I)return;const _=(l==null?void 0:l.closeAfterSave)??qe,Ks=(l==null?void 0:l.navigateHomeAfterSave)??!1;ie(_),_&&Q(!1);const Qs=s.cloneDeep(I);ae(!0),ne(null),oe([]),Ne(!0);const Ws={template:I};W.mutate({resourceId:I.id,data:Ws},{onSuccess:k=>{var ge,be,cs;const F=(k==null?void 0:k.id)||((ge=k==null?void 0:k.dashboard)==null?void 0:ge.id)||((be=k==null?void 0:k.resource)==null?void 0:be.id)||((cs=k==null?void 0:k.template)==null?void 0:cs.id)||null;if(!I.id&&F){const Ie=o.useAIInteractionStore.getState(),ve=Ie.pendingDashboardDraftMigration;(ve==null?void 0:ve.scopeKey)===h?Ie.actions.setPendingDashboardDraftMigrationExpectedDashboardId(F):ve&&Ie.actions.clearPendingDashboardDraftMigration()}Ne(!1),s.ue.success("Dashboard saved!"),me(ps(Qs,o.useDashboardStore.getState().semanticExecutionPayload)),ae(!1),ie(!1),_&&(Le(),pe(),Ks&&Se()),ue("close")},onError:k=>{Ne(!1),ne("Failed to save dashboard. Please try again.");const F=k.details,ge=Array.isArray(F==null?void 0:F.errors)?(F.errors||[]).filter(be=>typeof be=="string"):[];oe(qt({errors:ge,dashboard:I||void 0})),s.ue.error("Failed to save dashboard")}})}async function Bs(){if(U(!0),!p||!f)return;const l=o.useDashboardStore.getState().dashboard;if(!l){U(!1);return}const I=JSON.stringify(l),_={...f,template:I,filterValues:Ms};await Ue(n.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),je==null||je(l),U(!1)}const es=(f==null?void 0:f.name)||c.title,Y=!!(c!=null&&c.id);W.isPending&&console.log("Title during update:",{title:es,dashboardStateTitle:c.title,dashboardId:c==null?void 0:c.id,currentLensName:f==null?void 0:f.name});const ss=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,zs=!!ss&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl);b.useEffect(()=>{!Y&&z&&H(!1)},[Y,z]);const Hs=d,X=(c==null?void 0:c.id)||null,fe=!!X&&Ls===X,Vs=()=>{X&&Es({dashboardId:fe?null:X})};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:[ss&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{Cs(!Ns)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(at,{className:"h-3.5 w-3.5"})}),Hs&&!O&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:qs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!O&&d&&(m?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:es||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:le,dashboardId:c==null?void 0:c.id});const I=(c==null?void 0:c.title)||"";A(l),Ps(l,I)},isEditable:le&&!f,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:W.isPending}),zs&&X&&e.jsx(o.TooltipProvider,{children:e.jsxs(o.Tooltip,{children:[e.jsx(o.TooltipTrigger,{asChild:!0,children:e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:Vs,disabled:Is||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0","aria-label":fe?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:o.cn("h-3.5 w-3.5 transition-colors",fe?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(o.TooltipContent,{children:e.jsx("p",{children:fe?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[O&&e.jsxs(e.Fragment,{children:[e.jsx(G.AdvancedModeToggle,{}),e.jsx(G.VisualEditingControls,{})]}),!O&&d&&((is=B==null?void 0:B.permissions)==null?void 0:is.canShare)&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:()=>M(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!O&&N&&u.canUseFilters&&d&&e.jsx(G.DashboardFilterControlsLauncher,{}),N&&!O&&J&&f&&a&&d&&e.jsxs(o.Button,{variant:"secondary",size:"xs",disabled:C,onClick:Bs,children:[e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),N&&!O&&d&&!w&&e.jsxs(o.Button,{variant:"outline",size:"xs",disabled:!N,onClick:()=>Os(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!O&&!N&&le&&d&&e.jsxs(o.Button,{size:"xs",onClick:Us,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Qe&&d&&Ye&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:$s,disabled:xe,children:[e.jsx(ct,{className:"h-3.5 w-3.5"}),"Undo"]}),Qe&&d&&e.jsxs(o.Button,{size:"xs",className:o.cn(!Ze&&"opacity-60"),disabled:xe||!Ze,onClick:()=>Ee(),children:[xe?e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(ls.Save,{className:"h-3.5 w-3.5"}),xe?"Saving...":"Save"]}),N&&!O&&d&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Rs,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!O&&d&&e.jsx("div",{className:"ml-2",children:e.jsx(G.NotificationBell,{})}),!O&&a&&e.jsx(mt,{}),!O&&d&&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:y,onSelect:()=>V(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!Y,onSelect:()=>{Y&&H(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),ks&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>se(!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:()=>E(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),a&&d&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.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"]}),w&&e.jsxs(s.DropdownMenuItem,{disabled:!Me,onSelect:()=>{var l;if(!Me){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(Me).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:()=>o.invalidateToken(n.apiServiceUrl),children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:i,children:[e.jsx(Zs.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>He(!Be),children:[e.jsx(et.Braces,{className:"h-3.5 w-3.5"}),Be?"Hide dashboard JSON":"Show dashboard JSON"]}),J&&N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>R(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),J&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(tt,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(gt,{})})]})]})]})]}),$&&Ke&&e.jsx(s.ShareDialog,{resource:Ke,resourceType:s.ResourceType.DASHBOARD,onClose:()=>M(!1)}),e.jsx(Gt,{open:q,onOpenChange:se}),Y&&(c==null?void 0:c.id)&&e.jsx(s.EmailScheduleDialog,{open:z,onOpenChange:H,dashboardId:c.id,dashboardName:c==null?void 0:c.title}),e.jsx(Ys.CalendarPreferencesDialog,{open:v,onOpenChange:E}),a&&J&&d&&e.jsx(ft,{open:P,onOpenChange:R}),d&&e.jsx(s.DownloadPdf,{open:te,onOpenChange:V}),e.jsx(s.AlertDialog,{open:ws,onOpenChange:l=>{!l&&we&&!re||(ae(l),l||(ne(null),oe([]),ie(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:re?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:re?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),$e.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:$e.slice(0,5).map(l=>e.jsx("li",{children:l},l))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:re?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{ae(!1),ne(null),oe([]),ie(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Ee({closeAfterSave:qe,navigateHomeAfterSave:Ce==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(G.UnsavedChangesAlert,{open:Ts,onOpenChange:l=>{Q(l)},onSave:Fs,onDiscard:Gs,isSaving:we,saveLabel:"Save",discardLabel:"Discard"})]})]})}function zt({accessToken:t,dashboardId:n,selectedSheetId:r,pageSize:a,orientation:i,theme:u}){if(!t||!r)return null;const d=new URL("http://localhost:5173/print-document");d.searchParams.set("token",t),n&&d.searchParams.set("dashboardId",n),d.searchParams.set("selectedSheetId",r),u&&d.searchParams.set("theme",u);const m=new URL("http://127.0.0.1:3002/");return m.searchParams.set("pdfMode","document"),m.searchParams.set("pageSize",a||"letter"),m.searchParams.set("orientation",i||"portrait"),m.searchParams.set("url",d.toString()),m.toString()}exports.default=Bt;