react-semaphor 0.1.285 → 0.1.286
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.
- package/dist/chunks/{dashboard-controls-B8f_BKTb.js → dashboard-controls-ItYogy_p.js} +4 -4
- package/dist/chunks/{dashboard-controls-DSwmmI8w.js → dashboard-controls-L0PZjJCt.js} +318 -341
- package/dist/chunks/{dashboard-filter-controls-button-BqmNXVoa.js → dashboard-filter-controls-button-BBM66Kjx.js} +476 -442
- package/dist/chunks/dashboard-filter-controls-button-C0aCuD2T.js +11 -0
- package/dist/chunks/{dashboard-json-qT21EDMm.js → dashboard-json-BQ-vAiN1.js} +1 -1
- package/dist/chunks/{dashboard-json-D0H5w5WI.js → dashboard-json-DVGKEKGc.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-BRI5dAfz.js → dashboard-summary-settings-dialog-DlXqW4ur.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-Mq8T35Qv.js → dashboard-summary-settings-dialog-jRhWndnZ.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-DLpQykTX.js → edit-dashboard-visual-BFIX635s.js} +2 -2
- package/dist/chunks/{edit-dashboard-visual-gSIS7RGI.js → edit-dashboard-visual-DOyPqIRy.js} +4 -4
- package/dist/chunks/{index-Celt_oJr.js → index-5fuOmhsI.js} +170 -170
- package/dist/chunks/{index-r_DA-pny.js → index-BJLFSwZr.js} +10190 -10214
- package/dist/chunks/resource-management-panel-DMIhpLZ1.js +933 -0
- package/dist/chunks/resource-management-panel-DPJ6MzLA.js +6 -0
- package/dist/chunks/{use-create-flow-overlay-state-C1xhazfY.js → use-create-flow-overlay-state-BU00QaON.js} +142 -145
- package/dist/chunks/use-create-flow-overlay-state-CvuLpw1f.js +21 -0
- package/dist/chunks/{use-visual-utils-CWcTBBvd.js → use-visual-utils-DUV4E_sx.js} +1 -1
- package/dist/chunks/{use-visual-utils-CqL5PNOR.js → use-visual-utils-DlwYqcbg.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/main.d.ts +18 -2
- package/package.json +1 -1
- package/dist/chunks/dashboard-filter-controls-button-DXKJ-0iV.js +0 -11
- package/dist/chunks/resource-management-panel-Brj3iNyX.js +0 -6
- package/dist/chunks/resource-management-panel-DXLca9OX.js +0 -920
- package/dist/chunks/use-create-flow-overlay-state-DVyd9L7O.js +0 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-5fuOmhsI.js"),x=require("react");require("react-dom");const P=require("./dashboard-filter-controls-button-C0aCuD2T.js"),_s=require("./date-formatter-CqXdM6JO.js"),Xe=require("./dashboard-summary-settings-dialog-jRhWndnZ.js"),Us=require("./use-debounced-dirty-check-XHSwAefL.js"),Ne=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),Ye=require("./use-create-flow-overlay-state-CvuLpw1f.js");function Rs(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(o,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return o.default=t,Object.freeze(o)}const C=Rs(x);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const
|
|
26
|
+
*/const zs=s.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"}]]);var Me={exports:{}},we={};/**
|
|
27
27
|
* @license React
|
|
28
28
|
* use-sync-external-store-shim.production.js
|
|
29
29
|
*
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*
|
|
32
32
|
* This source code is licensed under the MIT license found in the
|
|
33
33
|
* LICENSE file in the root directory of this source tree.
|
|
34
|
-
*/var Ze;function
|
|
34
|
+
*/var Ze;function Hs(){if(Ze)return we;Ze=1;var t=x;function o(n,d){return n===d&&(n!==0||1/n===1/d)||n!==n&&d!==d}var a=typeof Object.is=="function"?Object.is:o,r=t.useState,l=t.useEffect,c=t.useLayoutEffect,m=t.useDebugValue;function u(n,d){var g=d(),b=r({inst:{value:g,getSnapshot:d}}),v=b[0].inst,S=b[1];return c(function(){v.value=g,v.getSnapshot=d,p(v)&&S({inst:v})},[n,g,d]),l(function(){return p(v)&&S({inst:v}),n(function(){p(v)&&S({inst:v})})},[n]),m(g),g}function p(n){var d=n.getSnapshot;n=n.value;try{var g=d();return!a(n,g)}catch{return!0}}function j(n,d){return d()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?j:u;return we.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,we}var Ce={};/**
|
|
35
35
|
* @license React
|
|
36
36
|
* use-sync-external-store-shim.development.js
|
|
37
37
|
*
|
|
@@ -39,4 +39,4 @@
|
|
|
39
39
|
*
|
|
40
40
|
* This source code is licensed under the MIT license found in the
|
|
41
41
|
* LICENSE file in the root directory of this source tree.
|
|
42
|
-
*/var es;function zs(){return es||(es=1,process.env.NODE_ENV!=="production"&&function(){function t(g,b){return g===b&&(g!==0||1/g===1/b)||g!==g&&b!==b}function o(g,b){h||l.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 v=b();if(!n){var S=b();c(v,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),n=!0)}S=m({inst:{value:v,getSnapshot:b}});var N=S[0].inst,I=S[1];return p(function(){N.value=v,N.getSnapshot=b,a(N)&&I({inst:N})},[g,v,b]),u(function(){return a(N)&&I({inst:N}),g(function(){a(N)&&I({inst:N})})},[g]),j(v),v}function a(g){var b=g.getSnapshot;g=g.value;try{var v=b();return!c(g,v)}catch{return!0}}function r(g,b){return b()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=x,c=typeof Object.is=="function"?Object.is:t,m=l.useState,u=l.useEffect,p=l.useLayoutEffect,j=l.useDebugValue,h=!1,n=!1,d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:o;Me.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:d,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Me}process.env.NODE_ENV==="production"?Le.exports=Vs():Le.exports=zs();var Ks=Le.exports;function Qs(){const{setTheme:t}=s.useTheme(),o=s.useDashboardStore(a=>a.actions.setDashboardTheme);return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"h-7 p-2",variant:"ghost",size:"sm",children:[e.jsx(Hs,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(qs,{strokeWidth:1.5,className:"absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),e.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>{t("light"),o("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),o("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),o("system")},children:"System"})]})]})}async function Ws(t,o,a,r,l){if(!l)return null;const c=JSON.stringify(a),m=`${t}/v1/lens`;return await s.postRequest(m,l,{name:o,template:c,filterValues:r,operation:"create"})}async function Ae(t,o,a){if(!a)return null;const{id:r,template:l,filterValues:c,isDefault:m,shared:u}=o,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:l,filterValues:c,isDefault:m,shared:u,operation:"update"})}async function Js(t,o,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:o})}function Xs(){const[t,o]=x.useState(""),[a,r]=x.useState(!1),l=s.useDashboardStore(S=>S.lenses),{setLenses:c,setSelectedLensId:m}=s.useDashboardActions(),[u,p]=x.useState(!1),[j,h]=x.useState(!1),n=s.useDashboardStore(S=>S.dashboard),d=s.useDashboardStore(S=>S.filterValues),{authToken:g,tokenProps:b}=s.useSemaphorContext();async function v(){p(!0);const S=await Ws(b.apiServiceUrl,t,n,d,g==null?void 0:g.accessToken);S&&(c([...l||[],S]),m(S.id),h(!1)),p(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:h,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:S=>{o(S.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:v,disabled:u,children:u?"Creating...":"Add"})})]})]})}function Ys(){const[t,o]=x.useState(!1),a=s.useDashboardStore(n=>n.lenses),r=s.useDashboardStore(n=>n.selectedLensId),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),{authToken:m,tokenProps:u}=s.useSemaphorContext();async function p(n){c(n)}async function j(n){if(await Js(u.apiServiceUrl,n,m==null?void 0:m.accessToken)){const g=a==null?void 0:a.filter(b=>b.id!==n);l(g||[]),c("original")}}async function h(n){const d=a==null?void 0:a.map(v=>v.id===n.id?{...v,isDefault:!n.isDefault}:{...v,isDefault:!1});l(d||[]);const g={...n,isDefault:!n.isDefault};await Ae(u.apiServiceUrl,g,m==null?void 0:m.accessToken);const b=a==null?void 0:a.find(v=>v.isDefault);if(b&&b.id!==n.id){const v={...b,isDefault:!1};await Ae(u.apiServiceUrl,v,m==null?void 0:m.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:o,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Gs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:p,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(n=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:n.id,children:[e.jsx("p",{children:n.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:d=>{d.preventDefault(),h(n)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!n.isDefault,"text-green-500":n.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:d=>{d.preventDefault(),j(n.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},n.id))]})]})]})}function Zs(){const{displayPreferences:t,shouldShowElement:o}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),l=x.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),c=x.useMemo(()=>u=>l&&l[u]!==void 0&&l[u]===!1?!1:o(u),[l,o,t]),m=x.useMemo(()=>{var u,p,j,h,n;return{canEdit:((u=r==null?void 0:r.permissions)==null?void 0:u.canEdit)??s.canUserEdit(a),canUseFilters:((p=r==null?void 0:r.permissions)==null?void 0:p.canEdit)??s.canUserUseFilters(a),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((h=r==null?void 0:r.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((n=r==null?void 0:r.permissions)==null?void 0:n.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:c,permissions:m,currentUser:a}}const et=async(t,o,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,o,a)},st=async(t,o,a)=>{const r=`${t}/management/v1/groups/${a}`;await s.requestJsonRegular(r,o,"DELETE")},tt=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,o,r)},at=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;await s.requestJsonRegular(l,o,"DELETE",r)};function rt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>et(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:s.getRequestErrorMessage(r,"Failed to create group")})}})}function nt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>st(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:s.getRequestErrorMessage(r,"Failed to delete group")})}})}function ot(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>tt(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:s.getRequestErrorMessage(r,"Failed to add members")})}})}function it(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>at(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:s.getRequestErrorMessage(r,"Failed to remove members")})}})}function lt({onSuccess:t,tenantId:o,isTenantUser:a}){const[r,l]=x.useState(""),[c,m]=x.useState(""),[u,p]=x.useState({}),j=rt(),h=()=>{const d={};return r.trim()?r.length<3?d.name="Group name must be at least 3 characters":r.length>50&&(d.name="Group name must be less than 50 characters"):d.name="Group name is required",c&&c.length>200&&(d.description="Description must be less than 200 characters"),p(d),Object.keys(d).length===0},n=async d=>{if(d.preventDefault(),!h())return;const g={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&o?{tenantId:o}:{}};try{await j.mutateAsync(g),l(""),m(""),p({}),t()}catch(b){console.error("Failed to create group:",b)}};return e.jsxs("form",{onSubmit:n,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-name",children:["Group Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:d=>{l(d.target.value),u.name&&p(g=>({...g,name:""}))},className:u.name?"border-destructive":"",disabled:j.isPending}),u.name&&e.jsx("p",{className:"text-sm text-destructive",children:u.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-description",children:["Description",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(optional)"})]}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group...",value:c,onChange:d=>{m(d.target.value),u.description&&p(g=>({...g,description:""}))},className:u.description?"border-destructive":"",disabled:j.isPending,rows:3}),u.description&&e.jsx("p",{className:"text-sm text-destructive",children:u.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.length,"/200 characters"]})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(s.CircleAlert,{className:"h-4 w-4 mt-0.5 text-muted-foreground"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"This group will be accessible to users in your workspace. You can add members after creating the group."})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(s.Button,{type:"button",variant:"outline",onClick:()=>{l(""),m(""),p({})},disabled:j.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:j.isPending||!r.trim(),children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Create Group"]})})]})]})}function ct(t,o=[]){let a=[];function r(c,m){const u=C.createContext(m);u.displayName=c+"Context";const p=a.length;a=[...a,m];const j=n=>{var N;const{scope:d,children:g,...b}=n,v=((N=d==null?void 0:d[t])==null?void 0:N[p])||u,S=C.useMemo(()=>b,Object.values(b));return e.jsx(v.Provider,{value:S,children:g})};j.displayName=c+"Provider";function h(n,d){var v;const g=((v=d==null?void 0:d[t])==null?void 0:v[p])||u,b=C.useContext(g);if(b)return b;if(m!==void 0)return m;throw new Error(`\`${n}\` must be used within \`${c}\``)}return[j,h]}const l=()=>{const c=a.map(m=>C.createContext(m));return function(u){const p=(u==null?void 0:u[t])||c;return C.useMemo(()=>({[`__scope${t}`]:{...u,[t]:p}}),[u,p])}};return l.scopeName=t,[r,dt(l,...o)]}function dt(...t){const o=t[0];if(t.length===1)return o;const a=()=>{const r=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const m=r.reduce((u,{useScope:p,scopeName:j})=>{const n=p(c)[`__scope${j}`];return{...u,...n}},{});return C.useMemo(()=>({[`__scope${o.scopeName}`]:m}),[m])}};return a.scopeName=o.scopeName,a}var ut=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=ut.reduce((t,o)=>{const a=s.createSlot(`Primitive.${o}`),r=C.forwardRef((l,c)=>{const{asChild:m,...u}=l,p=m?a:o;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...u,ref:c})});return r.displayName=`Primitive.${o}`,{...t,[o]:r}},{});function mt(){return Ks.useSyncExternalStore(ht,()=>!0,()=>!1)}function ht(){return()=>{}}var Ie="Avatar",[pt]=ct(Ie),[gt,ts]=pt(Ie),as=C.forwardRef((t,o)=>{const{__scopeAvatar:a,...r}=t,[l,c]=C.useState("idle");return e.jsx(gt,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Ee.span,{...r,ref:o})})});as.displayName=Ie;var rs="AvatarImage",ns=C.forwardRef((t,o)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...c}=t,m=ts(rs,a),u=ft(r,c),p=s.useCallbackRef(j=>{l(j),m.onImageLoadingStatusChange(j)});return s.useLayoutEffect2(()=>{u!=="idle"&&p(u)},[u,p]),u==="loaded"?e.jsx(Ee.img,{...c,ref:o,src:r}):null});ns.displayName=rs;var os="AvatarFallback",is=C.forwardRef((t,o)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,c=ts(os,a),[m,u]=C.useState(r===void 0);return C.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(p)}},[r]),m&&c.imageLoadingStatus!=="loaded"?e.jsx(Ee.span,{...l,ref:o}):null});is.displayName=os;function ss(t,o){return t?o?(t.src!==o&&(t.src=o),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function ft(t,{referrerPolicy:o,crossOrigin:a}){const r=mt(),l=C.useRef(null),c=r?(l.current||(l.current=new window.Image),l.current):null,[m,u]=C.useState(()=>ss(c,t));return s.useLayoutEffect2(()=>{u(ss(c,t))},[c,t]),s.useLayoutEffect2(()=>{const p=n=>()=>{u(n)};if(!c)return;const j=p("loaded"),h=p("error");return c.addEventListener("load",j),c.addEventListener("error",h),o&&(c.referrerPolicy=o),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",j),c.removeEventListener("error",h)}},[c,a,o]),m}var ls=as,cs=ns,ds=is;const ke=C.forwardRef(({className:t,...o},a)=>e.jsx(ls,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...o}));ke.displayName=ls.displayName;const xt=C.forwardRef(({className:t,...o},a)=>e.jsx(cs,{ref:a,className:s.cn("aspect-square h-full w-full",t),...o}));xt.displayName=cs.displayName;const Te=C.forwardRef(({className:t,...o},a)=>e.jsx(ds,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...o}));Te.displayName=ds.displayName;function bt({open:t,onOpenChange:o,group:a,onUpdate:r}){const[l,c]=x.useState("members"),[m,u]=x.useState(""),[p,j]=x.useState([]),[h,n]=x.useState([]),{data:d,isLoading:g,refetch:b}=s.useGroupMembers(a.id),v=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:N}=s.useUnifiedUsers({type:v,tenantId:a.tenantId||void 0,active:!0,limit:100}),I=ot(),k=it(),E=(d==null?void 0:d.members)||[],_=x.useMemo(()=>new Set(E.map(f=>f.userId)),[E]),U=x.useMemo(()=>S.filter(f=>!_.has(f.id)),[S,_]),R=x.useMemo(()=>{if(!m)return U;const f=m.toLowerCase();return U.filter(w=>{var L,F;return((L=w.name)==null?void 0:L.toLowerCase().includes(f))||((F=w.email)==null?void 0:F.toLowerCase().includes(f))})},[U,m]),y=x.useMemo(()=>{if(!m)return E;const f=m.toLowerCase();return E.filter(w=>{var L,F,$,V;return((F=(L=w.user)==null?void 0:L.name)==null?void 0:F.toLowerCase().includes(f))||((V=($=w.user)==null?void 0:$.email)==null?void 0:V.toLowerCase().includes(f))})},[E,m]),G=async()=>{if(p.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:p,userType:v==="tenant"?"tenant":"org"}}),j([]),c("members"),b(),r==null||r()}catch(f){console.error("Failed to add members:",f)}},Z=async()=>{if(h.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:h}}),n([]),b(),r==null||r()}catch(f){console.error("Failed to remove members:",f)}},H=f=>{j(w=>w.includes(f)?w.filter(L=>L!==f):[...w,f])},ue=f=>{n(w=>w.includes(f)?w.filter(L=>L!==f):[...w,f])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:o,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:a.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[E.length," ",E.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",a.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:f=>{c(f),u(""),n([])},className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(s.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(s.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(s.Input,{placeholder:"Search members...",value:m,onChange:f=>u(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:g?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):y.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:m?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:m?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:y.map(f=>e.jsx(vt,{member:f,selected:h.includes(f.userId),onToggle:()=>ue(f.userId)},f.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(s.Button,{variant:"destructive",size:"sm",onClick:Z,disabled:k.isPending,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.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(s.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(s.Input,{placeholder:"Search users to add...",value:m,onChange:f=>u(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:N?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):R.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.UserPlus,{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:m?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:R.map(f=>e.jsx(jt,{user:f,selected:p.includes(f.id),onToggle:()=>H(f.id)},f.id))})}),p.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:[p.length," user",p.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:G,disabled:I.isPending,children:I.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function vt({member:t,selected:o,onToggle:a}){var l,c,m,u;const r=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(p=>p[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:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(ke,{className:"h-8 w-8",children:e.jsx(Te,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((m=t.user)==null?void 0:m.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(u=t.user)==null?void 0:u.email})]})]})}function jt({user:t,selected:o,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(c=>c[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:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(ke,{className:"h-8 w-8",children:e.jsx(Te,{className:"text-xs",children:r})}),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 St({open:t,onOpenChange:o}){const[a,r]=x.useState("groups"),[l,c]=x.useState(""),[m,u]=x.useState(null),[p,j]=x.useState(!1),[h,n]=x.useState(null),{tokenProps:d}=s.useSemaphorContext(),{currentUser:g}=s.useCurrentUserInfo(),b=nt(),v=(g==null?void 0:g.type)==="tenant",S=d==null?void 0:d.tenantId,{groups:N,isLoading:I,refetch:k}=s.useGroups({type:v?"TENANT_GROUP":"all",tenantId:v?S:void 0,includeMembers:!1}),E=N.filter(y=>{var G;return y.name.toLowerCase().includes(l.toLowerCase())||((G=y.description)==null?void 0:G.toLowerCase().includes(l.toLowerCase()))}),_=async()=>{if(h)try{await b.mutateAsync(h.id),n(null),k()}catch(y){console.error("Failed to delete group:",y)}},U=y=>{u(y),j(!0)},R=()=>{r("groups"),k()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:o,children:e.jsxs(s.DialogContent,{className:"max-w-4xl max-h-[80vh]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-5 w-5"}),"Group Management"]}),e.jsx(s.DialogDescription,{children:"Manage your groups, create new groups, and control group membership"})]}),e.jsxs(s.Tabs,{value:a,onValueChange:r,className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsxs(s.TabsTrigger,{value:"groups",className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-4 w-4"}),"Groups"]}),e.jsxs(s.TabsTrigger,{value:"create",className:"flex items-center gap-2",children:[e.jsx(s.Plus,{className:"h-4 w-4"}),"Create Group"]})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"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(s.Input,{placeholder:"Search groups...",value:l,onChange:y=>c(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:I?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):E.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:"No groups found"}),e.jsx("p",{className:"text-xs mt-1",children:l?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:E.map(y=>e.jsx(yt,{group:y,onManageMembers:()=>U(y),onDelete:()=>n(y),currentUserId:g==null?void 0:g.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(lt,{onSuccess:R,tenantId:S,isTenantUser:v})})]})]})}),m&&e.jsx(bt,{open:p,onOpenChange:j,group:m,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!h,onOpenChange:()=>n(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Group"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',h==null?void 0:h.name,'"? This action cannot be undone and will remove all members from the group.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:_,disabled:b.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function yt({group:t,onManageMembers:o,onDelete:a,currentUserId:r}){const l=t.createdBy===r;return e.jsx("div",{className:"rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"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 ",_s.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:o,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:a,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function X(t,o,a){var c,m;const r=(t.controls||[]).find(u=>u.id===a);if(r)return r.label;const l=(m=(c=s.findCardById(t,o))==null?void 0:c.controls)==null?void 0:m.find(u=>u.id===a);return(l==null?void 0:l.label)||a}function Y(t,o){var a;return((a=s.findCardById(t,o))==null?void 0:a.title)||o}function Dt(t){const{errors:o,dashboard:a}=t;if(!a)return o;const r=new Map;for(const l of o){const c=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,h,n]=c,d=`${h}:${n}:missing-metric`;r.has(d)||r.set(d,`"${Y(a,h)}" has an outdated "${X(a,h,n)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const m=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(m){const[,h,n]=m,d=`${h}:${n}:missing-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" has an outdated "${X(a,h,n)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(u){const[,h,n]=u,d=`${h}:${n}:invalid-metric`;r.has(d)||r.set(d,`"${Y(a,h)}" has an invalid "${X(a,h,n)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const p=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(p){const[,h,n]=p,d=`${h}:${n}:invalid-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" has an invalid "${X(a,h,n)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const j=l.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(j){const[,h,n]=j,d=`${h}:${n}:missing-temporal-group-by`;r.has(d)||r.set(d,`"${Y(a,h)}" can no longer use "${X(a,h,n)}" for time grain because the card does not currently group by a date field.`);continue}r.set(l,l)}return Array.from(r.values())}function Nt(){var ze,Ke,Qe,We;P.useExportRecovery(),P.useExportPolling();const{authToken:t,tokenProps:o,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=Zs(),c=s.useHasDashboardId(),{isLoading:m}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const u=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),p=s.useDashboardStore(i=>i.lenses),j=s.useDashboardStore(i=>i.selectedLensId),h=p==null?void 0:p.find(i=>i.id===j),n=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const d=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:g}=s.useDashboardStore(i=>i.actions),[b,v]=x.useState(!1),[S,N]=x.useState(!1),[I,k]=x.useState(!1),[E,_]=x.useState(!1),[U,R]=x.useState(!1),[y,G]=x.useState(!1),[Z,H]=x.useState(null),[ue,f]=x.useState(!1),[w,L]=x.useState(null),[F,$]=x.useState([]),[V,ee]=x.useState(!1),us=s.useDashboardStore(i=>i.isDashboardPanelOpen),ms=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),hs=s.useDashboardStore(i=>i.filterValues),D=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const z=s.useManagementStore(i=>i.selectedDashboard),se=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const te=z?(Ke=z==null?void 0:z.permissions)==null?void 0:Ke.canEdit:(ze=se==null?void 0:se.permissions)==null?void 0:ze.canEdit,ae=s.useDashboardStore(i=>i.showFilters),Oe=s.useAssistantLayoutStore(i=>i.setPanelOpen),ps=s.useDashboardStore(i=>i.showDashboardJSON),me=s.useDashboardStore(i=>i.onSaveFunction),Pe=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Fe,setShowDashboardJSON:_e}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:Ue,clearSelectedDashboard:he}=s.useManagementStore(i=>i.actions),{resources:re}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:pe}=s.useUserPreferences(),gs=((Qe=pe==null?void 0:pe.preference)==null?void 0:Qe.defaultDashboardId)||null,{mutate:fs,isPending:xs}=s.useDefaultDashboardMutation(),{currentUser:bs}=s.useCurrentUserInfo(),vs=s.canUserManageGroups(bs),B=z||se,Re=B?{id:B.id,title:(n==null?void 0:n.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:js}=s.useAddNewFrame(),[ge,fe]=x.useState(!1),[Ss,K]=x.useState(!1),[xe,ne]=x.useState("close"),Q=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,be]=x.useState(null),Ge=x.useCallback(i=>{window.setTimeout(()=>{H(i)},0)},[]),ys=async(i,M)=>{if(!(n!=null&&n.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:n.id,newTitle:i,previousTitle:M}),Q.mutate({resourceId:n.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:O=>{console.error("Failed to update dashboard title:",O),s.ue.error("Failed to update dashboard title"),g(M)}})};x.useEffect(()=>{if(re&&re.length>0){const i=n==null?void 0:n.id;if(i){const M=re.find(O=>O.id===i);M&&Ue(M)}}},[re,n==null?void 0:n.id,Ue]);const oe=o.orgUserId||o.tenantId,$e=d&&!D&&oe&&te,{setDashboard:ve}=s.useDashboardStore(i=>i.actions),Ds=()=>{Fe(!0)},je=()=>{Fe(!1),_e(!1),be(null),H(null)};P.usePristineSnapshotInitializer(d,n,T,i=>be(i));const{isDirty:qe,isDirtyPending:Ns,resetDirty:ie}=Us.useDebouncedDirtyCheck(n,T,300,1e3,we.serializeDashboardForDirtyCheck),Be=x.useCallback(()=>T?we.serializeDashboardForDirtyCheck(n)!==we.serializeDashboardForDirtyCheck(T):!1,[n,T]),Se=qe||Ns,W=ge||Q.isPending,ws=()=>{Be()?(ne("close"),K(!0)):(je(),ie())},Cs=async()=>{await ye({closeAfterSave:!0,navigateHomeAfterSave:xe==="home"})},Ms=()=>{T&&ve(T),je(),xe==="home"&&he(),ne("close"),K(!1),ie()},Ls=()=>{T&&(ve(T),ie())},As=()=>{if(d&&Be()){ne("home"),K(!0);return}he()};async function ye(i){const M=s.useDashboardStore.getState().dashboard;if(!M)return;const O=(i==null?void 0:i.closeAfterSave)??V,Os=(i==null?void 0:i.navigateHomeAfterSave)??!1;ee(O),O&&K(!1);const Ps=s.cloneDeep(M);f(!0),L(null),$([]),fe(!0);const Fs={template:M};Q.mutate({resourceId:M.id,data:Fs},{onSuccess:A=>{var le,ce,Je;const q=(A==null?void 0:A.id)||((le=A==null?void 0:A.dashboard)==null?void 0:le.id)||((ce=A==null?void 0:A.resource)==null?void 0:ce.id)||((Je=A==null?void 0:A.template)==null?void 0:Je.id)||null;if(!M.id&&q){const Ne=s.useAIInteractionStore.getState(),de=Ne.pendingDashboardDraftMigration;(de==null?void 0:de.scopeKey)===u?Ne.actions.setPendingDashboardDraftMigrationExpectedDashboardId(q):de&&Ne.actions.clearPendingDashboardDraftMigration()}fe(!1),s.ue.success("Dashboard saved!"),be(Ps),f(!1),ee(!1),O&&(je(),ie(),Os&&he()),ne("close")},onError:A=>{fe(!1),L("Failed to save dashboard. Please try again.");const q=A.details,le=Array.isArray(q==null?void 0:q.errors)?(q.errors||[]).filter(ce=>typeof ce=="string"):[];$(Dt({errors:le,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Es(){if(v(!0),!j||!h)return;const i=s.useDashboardStore.getState().dashboard;if(!i){v(!1);return}const M=JSON.stringify(i),O={...h,template:M,filterValues:hs};await Ae(o.apiServiceUrl,O,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),me==null||me(i),v(!1)}const He=(h==null?void 0:h.name)||n.title;Q.isPending&&console.log("Title during update:",{title:He,dashboardStateTitle:n.title,dashboardId:n==null?void 0:n.id,currentLensName:h==null?void 0:h.name});const Ve=o.orgUserId||o.tenantId&&o.endUserId&&o.endUserEmail,Is=!!Ve&&!!(t!=null&&t.accessToken)&&!!(o!=null&&o.apiServiceUrl),ks=c,J=(n==null?void 0:n.id)||null,De=!!J&&gs===J,Ts=()=>{J&&fs({dashboardId:De?null:J})};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:[Ve&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{ms(!us)},className:"h-7 p-2",children:e.jsx($s,{className:"h-4 w-4"})}),ks&&!D&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:As,className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!D&&c&&(m?e.jsx("div",{className:"h-4 w-28 rounded-md bg-muted/70 animate-pulse","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:He||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:te,dashboardId:n==null?void 0:n.id});const M=(n==null?void 0:n.title)||"";g(i),ys(i,M)},isEditable:te&&!h,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:Q.isPending}),Is&&J&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"icon",onClick:Ts,disabled:xs||!(t!=null&&t.accessToken)||!(o!=null&&o.apiServiceUrl),className:"h-7 w-7",children:e.jsx(s.Star,{className:s.cn("h-4 w-4 transition-colors",De?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-400")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:De?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[D&&e.jsxs(e.Fragment,{children:[e.jsx(P.AdvancedModeToggle,{className:"mr-2"}),e.jsx(P.VisualEditingControls,{className:"h-7"})]}),r&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.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"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(o.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Bs,{className:"h-4 w-4"})})]}),!D&&c&&e.jsx(s.DownloadPdf,{}),!D&&c&&e.jsx(P.NotificationBell,{}),!D&&c&&((We=B==null?void 0:B.permissions)==null?void 0:We.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>N(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!D&&d&&l.canUseFilters&&c&&e.jsx(P.DashboardFilterControlsButton,{showFilters:ae,onToggleFilters:()=>{ae||Oe("dashboard",!1),Pe(!ae)},onAddFilter:()=>{ae||(Oe("dashboard",!1),Pe(!0))},onAddControl:()=>{Ge("create")},onManageControls:()=>Ge("manage")}),d&&!D&&c&&Z?e.jsx(P.DashboardControlsSettings,{open:!0,onOpenChange:i=>{i||H(null)},showTrigger:!1,initialMode:Z}):null,d&&!D&&oe&&r&&c&&e.jsx(Xs,{}),!D&&oe&&r&&c&&e.jsx(Ys,{}),d&&!D&&oe&&h&&r&&c&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:b,onClick:Es,size:"sm",children:[e.jsx(Ye.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!d,onClick:()=>js(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!D&&!d&&te&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ds,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),$e&&c&&qe&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ls,size:"sm",disabled:W,children:[e.jsx(s.Undo2,{className:"mr-2 h-4 w-4"}),"Undo"]}),$e&&c&&e.jsxs("div",{className:"relative inline-flex",children:[e.jsxs(s.Button,{className:s.cn("h-7 p-2",!Se&&"opacity-60"),disabled:W||!Se,onClick:()=>ye(),size:"sm",children:[W?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ye.Save,{className:"mr-2 h-4 w-4"}),W?"Saving...":"Save"]}),Se&&!W&&e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full bg-orange-500 ring-2 ring-background"})]}),!D&&d&&r&&c&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>_e(!ps),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!D&&r&&e.jsx(Qs,{}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:ws,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),!D&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",buttonProps:{"aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-xl border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Automation"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>_(!0),className:"flex items-center gap-2",children:[e.jsx(s.Clock,{className:"mr-2 h-4 w-4"}),"Schedule Dashboard"]}),e.jsx(s.DropdownMenuSeparator,{}),vs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>k(!0),className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>R(!0),className:"flex items-center gap-2",children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>G(!0),className:"flex items-center gap-2",children:[e.jsx(s.FileText,{className:"mr-2 h-4 w-4"}),"Summary Settings"]})]})]}),S&&Re&&e.jsx(s.ShareDialog,{resource:Re,resourceType:s.ResourceType.DASHBOARD,onClose:()=>N(!1)}),e.jsx(St,{open:I,onOpenChange:k}),(n==null?void 0:n.id)&&e.jsx(s.EmailScheduleDialog,{open:E,onOpenChange:_,dashboardId:n.id,dashboardName:n==null?void 0:n.title}),e.jsx(Xe.CalendarPreferencesDialog,{open:U,onOpenChange:R}),e.jsx(Xe.DashboardSummarySettingsDialog,{open:y,onOpenChange:G,dashboard:n,disabled:!d,onApply:i=>ve({...n,summary:i})}),e.jsx(s.AlertDialog,{open:ue,onOpenChange:i=>{!i&&ge&&!w||(f(i),i||(L(null),$([]),ee(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:w?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:w?"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(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:w?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{f(!1),L(null),$([]),ee(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ye({closeAfterSave:V,navigateHomeAfterSave:xe==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(P.UnsavedChangesAlert,{open:Ss,onOpenChange:i=>{K(i)},onSave:Cs,onDiscard:Ms,isSaving:ge,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Nt;
|
|
42
|
+
*/var es;function Vs(){return es||(es=1,process.env.NODE_ENV!=="production"&&function(){function t(g,b){return g===b&&(g!==0||1/g===1/b)||g!==g&&b!==b}function o(g,b){h||l.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 v=b();if(!n){var S=b();c(v,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),n=!0)}S=m({inst:{value:v,getSnapshot:b}});var N=S[0].inst,I=S[1];return p(function(){N.value=v,N.getSnapshot=b,a(N)&&I({inst:N})},[g,v,b]),u(function(){return a(N)&&I({inst:N}),g(function(){a(N)&&I({inst:N})})},[g]),j(v),v}function a(g){var b=g.getSnapshot;g=g.value;try{var v=b();return!c(g,v)}catch{return!0}}function r(g,b){return b()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=x,c=typeof Object.is=="function"?Object.is:t,m=l.useState,u=l.useEffect,p=l.useLayoutEffect,j=l.useDebugValue,h=!1,n=!1,d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:o;Ce.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:d,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ce}process.env.NODE_ENV==="production"?Me.exports=Hs():Me.exports=Vs();var Ks=Me.exports;function Qs(){const{setTheme:t}=s.useTheme(),o=s.useDashboardStore(a=>a.actions.setDashboardTheme);return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"h-7 p-2",variant:"ghost",size:"sm",children:[e.jsx(zs,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(qs,{strokeWidth:1.5,className:"absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),e.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>{t("light"),o("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),o("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),o("system")},children:"System"})]})]})}async function Ws(t,o,a,r,l){if(!l)return null;const c=JSON.stringify(a),m=`${t}/v1/lens`;return await s.postRequest(m,l,{name:o,template:c,filterValues:r,operation:"create"})}async function Le(t,o,a){if(!a)return null;const{id:r,template:l,filterValues:c,isDefault:m,shared:u}=o,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:l,filterValues:c,isDefault:m,shared:u,operation:"update"})}async function Js(t,o,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:o})}function Xs(){const[t,o]=x.useState(""),[a,r]=x.useState(!1),l=s.useDashboardStore(S=>S.lenses),{setLenses:c,setSelectedLensId:m}=s.useDashboardActions(),[u,p]=x.useState(!1),[j,h]=x.useState(!1),n=s.useDashboardStore(S=>S.dashboard),d=s.useDashboardStore(S=>S.filterValues),{authToken:g,tokenProps:b}=s.useSemaphorContext();async function v(){p(!0);const S=await Ws(b.apiServiceUrl,t,n,d,g==null?void 0:g.accessToken);S&&(c([...l||[],S]),m(S.id),h(!1)),p(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:h,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:S=>{o(S.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:v,disabled:u,children:u?"Creating...":"Add"})})]})]})}function Ys(){const[t,o]=x.useState(!1),a=s.useDashboardStore(n=>n.lenses),r=s.useDashboardStore(n=>n.selectedLensId),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),{authToken:m,tokenProps:u}=s.useSemaphorContext();async function p(n){c(n)}async function j(n){if(await Js(u.apiServiceUrl,n,m==null?void 0:m.accessToken)){const g=a==null?void 0:a.filter(b=>b.id!==n);l(g||[]),c("original")}}async function h(n){const d=a==null?void 0:a.map(v=>v.id===n.id?{...v,isDefault:!n.isDefault}:{...v,isDefault:!1});l(d||[]);const g={...n,isDefault:!n.isDefault};await Le(u.apiServiceUrl,g,m==null?void 0:m.accessToken);const b=a==null?void 0:a.find(v=>v.isDefault);if(b&&b.id!==n.id){const v={...b,isDefault:!1};await Le(u.apiServiceUrl,v,m==null?void 0:m.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:o,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Gs,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:p,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(n=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:n.id,children:[e.jsx("p",{children:n.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:d=>{d.preventDefault(),h(n)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!n.isDefault,"text-green-500":n.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:d=>{d.preventDefault(),j(n.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},n.id))]})]})]})}function Zs(){const{displayPreferences:t,shouldShowElement:o}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),l=x.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),c=x.useMemo(()=>u=>l&&l[u]!==void 0&&l[u]===!1?!1:o(u),[l,o,t]),m=x.useMemo(()=>{var u,p,j,h,n;return{canEdit:((u=r==null?void 0:r.permissions)==null?void 0:u.canEdit)??s.canUserEdit(a),canUseFilters:((p=r==null?void 0:r.permissions)==null?void 0:p.canEdit)??s.canUserUseFilters(a),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((h=r==null?void 0:r.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((n=r==null?void 0:r.permissions)==null?void 0:n.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:c,permissions:m,currentUser:a}}const et=async(t,o,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,o,a)},st=async(t,o,a)=>{const r=`${t}/management/v1/groups/${a}`;await s.requestJsonRegular(r,o,"DELETE")},tt=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,o,r)},at=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;await s.requestJsonRegular(l,o,"DELETE",r)};function rt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>et(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:s.getRequestErrorMessage(r,"Failed to create group")})}})}function nt(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>st(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:s.getRequestErrorMessage(r,"Failed to delete group")})}})}function ot(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>tt(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:s.getRequestErrorMessage(r,"Failed to add members")})}})}function it(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>at(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:s.getRequestErrorMessage(r,"Failed to remove members")})}})}function lt({onSuccess:t,tenantId:o,isTenantUser:a}){const[r,l]=x.useState(""),[c,m]=x.useState(""),[u,p]=x.useState({}),j=rt(),h=()=>{const d={};return r.trim()?r.length<3?d.name="Group name must be at least 3 characters":r.length>50&&(d.name="Group name must be less than 50 characters"):d.name="Group name is required",c&&c.length>200&&(d.description="Description must be less than 200 characters"),p(d),Object.keys(d).length===0},n=async d=>{if(d.preventDefault(),!h())return;const g={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&o?{tenantId:o}:{}};try{await j.mutateAsync(g),l(""),m(""),p({}),t()}catch(b){console.error("Failed to create group:",b)}};return e.jsxs("form",{onSubmit:n,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-name",children:["Group Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:d=>{l(d.target.value),u.name&&p(g=>({...g,name:""}))},className:u.name?"border-destructive":"",disabled:j.isPending}),u.name&&e.jsx("p",{className:"text-sm text-destructive",children:u.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-description",children:["Description",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(optional)"})]}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group...",value:c,onChange:d=>{m(d.target.value),u.description&&p(g=>({...g,description:""}))},className:u.description?"border-destructive":"",disabled:j.isPending,rows:3}),u.description&&e.jsx("p",{className:"text-sm text-destructive",children:u.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.length,"/200 characters"]})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(s.CircleAlert,{className:"h-4 w-4 mt-0.5 text-muted-foreground"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"This group will be accessible to users in your workspace. You can add members after creating the group."})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(s.Button,{type:"button",variant:"outline",onClick:()=>{l(""),m(""),p({})},disabled:j.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:j.isPending||!r.trim(),children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Create Group"]})})]})]})}function ct(t,o=[]){let a=[];function r(c,m){const u=C.createContext(m);u.displayName=c+"Context";const p=a.length;a=[...a,m];const j=n=>{var N;const{scope:d,children:g,...b}=n,v=((N=d==null?void 0:d[t])==null?void 0:N[p])||u,S=C.useMemo(()=>b,Object.values(b));return e.jsx(v.Provider,{value:S,children:g})};j.displayName=c+"Provider";function h(n,d){var v;const g=((v=d==null?void 0:d[t])==null?void 0:v[p])||u,b=C.useContext(g);if(b)return b;if(m!==void 0)return m;throw new Error(`\`${n}\` must be used within \`${c}\``)}return[j,h]}const l=()=>{const c=a.map(m=>C.createContext(m));return function(u){const p=(u==null?void 0:u[t])||c;return C.useMemo(()=>({[`__scope${t}`]:{...u,[t]:p}}),[u,p])}};return l.scopeName=t,[r,dt(l,...o)]}function dt(...t){const o=t[0];if(t.length===1)return o;const a=()=>{const r=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const m=r.reduce((u,{useScope:p,scopeName:j})=>{const n=p(c)[`__scope${j}`];return{...u,...n}},{});return C.useMemo(()=>({[`__scope${o.scopeName}`]:m}),[m])}};return a.scopeName=o.scopeName,a}var ut=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ae=ut.reduce((t,o)=>{const a=s.createSlot(`Primitive.${o}`),r=C.forwardRef((l,c)=>{const{asChild:m,...u}=l,p=m?a:o;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...u,ref:c})});return r.displayName=`Primitive.${o}`,{...t,[o]:r}},{});function mt(){return Ks.useSyncExternalStore(ht,()=>!0,()=>!1)}function ht(){return()=>{}}var Ee="Avatar",[pt]=ct(Ee),[gt,ts]=pt(Ee),as=C.forwardRef((t,o)=>{const{__scopeAvatar:a,...r}=t,[l,c]=C.useState("idle");return e.jsx(gt,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Ae.span,{...r,ref:o})})});as.displayName=Ee;var rs="AvatarImage",ns=C.forwardRef((t,o)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...c}=t,m=ts(rs,a),u=ft(r,c),p=s.useCallbackRef(j=>{l(j),m.onImageLoadingStatusChange(j)});return s.useLayoutEffect2(()=>{u!=="idle"&&p(u)},[u,p]),u==="loaded"?e.jsx(Ae.img,{...c,ref:o,src:r}):null});ns.displayName=rs;var os="AvatarFallback",is=C.forwardRef((t,o)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,c=ts(os,a),[m,u]=C.useState(r===void 0);return C.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(p)}},[r]),m&&c.imageLoadingStatus!=="loaded"?e.jsx(Ae.span,{...l,ref:o}):null});is.displayName=os;function ss(t,o){return t?o?(t.src!==o&&(t.src=o),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function ft(t,{referrerPolicy:o,crossOrigin:a}){const r=mt(),l=C.useRef(null),c=r?(l.current||(l.current=new window.Image),l.current):null,[m,u]=C.useState(()=>ss(c,t));return s.useLayoutEffect2(()=>{u(ss(c,t))},[c,t]),s.useLayoutEffect2(()=>{const p=n=>()=>{u(n)};if(!c)return;const j=p("loaded"),h=p("error");return c.addEventListener("load",j),c.addEventListener("error",h),o&&(c.referrerPolicy=o),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",j),c.removeEventListener("error",h)}},[c,a,o]),m}var ls=as,cs=ns,ds=is;const Ie=C.forwardRef(({className:t,...o},a)=>e.jsx(ls,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...o}));Ie.displayName=ls.displayName;const xt=C.forwardRef(({className:t,...o},a)=>e.jsx(cs,{ref:a,className:s.cn("aspect-square h-full w-full",t),...o}));xt.displayName=cs.displayName;const ke=C.forwardRef(({className:t,...o},a)=>e.jsx(ds,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...o}));ke.displayName=ds.displayName;function bt({open:t,onOpenChange:o,group:a,onUpdate:r}){const[l,c]=x.useState("members"),[m,u]=x.useState(""),[p,j]=x.useState([]),[h,n]=x.useState([]),{data:d,isLoading:g,refetch:b}=s.useGroupMembers(a.id),v=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:N}=s.useUnifiedUsers({type:v,tenantId:a.tenantId||void 0,active:!0,limit:100}),I=ot(),k=it(),E=(d==null?void 0:d.members)||[],_=x.useMemo(()=>new Set(E.map(f=>f.userId)),[E]),U=x.useMemo(()=>S.filter(f=>!_.has(f.id)),[S,_]),R=x.useMemo(()=>{if(!m)return U;const f=m.toLowerCase();return U.filter(w=>{var L,F;return((L=w.name)==null?void 0:L.toLowerCase().includes(f))||((F=w.email)==null?void 0:F.toLowerCase().includes(f))})},[U,m]),y=x.useMemo(()=>{if(!m)return E;const f=m.toLowerCase();return E.filter(w=>{var L,F,$,H;return((F=(L=w.user)==null?void 0:L.name)==null?void 0:F.toLowerCase().includes(f))||((H=($=w.user)==null?void 0:$.email)==null?void 0:H.toLowerCase().includes(f))})},[E,m]),G=async()=>{if(p.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:p,userType:v==="tenant"?"tenant":"org"}}),j([]),c("members"),b(),r==null||r()}catch(f){console.error("Failed to add members:",f)}},Y=async()=>{if(h.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:h}}),n([]),b(),r==null||r()}catch(f){console.error("Failed to remove members:",f)}},z=f=>{j(w=>w.includes(f)?w.filter(L=>L!==f):[...w,f])},me=f=>{n(w=>w.includes(f)?w.filter(L=>L!==f):[...w,f])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:o,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:a.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[E.length," ",E.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",a.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:f=>{c(f),u(""),n([])},className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(s.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(s.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(s.Input,{placeholder:"Search members...",value:m,onChange:f=>u(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:g?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):y.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:m?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:m?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:y.map(f=>e.jsx(vt,{member:f,selected:h.includes(f.userId),onToggle:()=>me(f.userId)},f.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(s.Button,{variant:"destructive",size:"sm",onClick:Y,disabled:k.isPending,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.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(s.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(s.Input,{placeholder:"Search users to add...",value:m,onChange:f=>u(f.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:N?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(f=>e.jsx(s.Skeleton,{className:"h-16 w-full"},f))}):R.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.UserPlus,{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:m?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:R.map(f=>e.jsx(jt,{user:f,selected:p.includes(f.id),onToggle:()=>z(f.id)},f.id))})}),p.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:[p.length," user",p.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:G,disabled:I.isPending,children:I.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function vt({member:t,selected:o,onToggle:a}){var l,c,m,u;const r=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(p=>p[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:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(Ie,{className:"h-8 w-8",children:e.jsx(ke,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((m=t.user)==null?void 0:m.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(u=t.user)==null?void 0:u.email})]})]})}function jt({user:t,selected:o,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(c=>c[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:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(Ie,{className:"h-8 w-8",children:e.jsx(ke,{className:"text-xs",children:r})}),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 St({open:t,onOpenChange:o}){const[a,r]=x.useState("groups"),[l,c]=x.useState(""),[m,u]=x.useState(null),[p,j]=x.useState(!1),[h,n]=x.useState(null),{tokenProps:d}=s.useSemaphorContext(),{currentUser:g}=s.useCurrentUserInfo(),b=nt(),v=(g==null?void 0:g.type)==="tenant",S=d==null?void 0:d.tenantId,{groups:N,isLoading:I,refetch:k}=s.useGroups({type:v?"TENANT_GROUP":"all",tenantId:v?S:void 0,includeMembers:!1}),E=N.filter(y=>{var G;return y.name.toLowerCase().includes(l.toLowerCase())||((G=y.description)==null?void 0:G.toLowerCase().includes(l.toLowerCase()))}),_=async()=>{if(h)try{await b.mutateAsync(h.id),n(null),k()}catch(y){console.error("Failed to delete group:",y)}},U=y=>{u(y),j(!0)},R=()=>{r("groups"),k()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:o,children:e.jsxs(s.DialogContent,{className:"max-w-4xl max-h-[80vh]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-5 w-5"}),"Group Management"]}),e.jsx(s.DialogDescription,{children:"Manage your groups, create new groups, and control group membership"})]}),e.jsxs(s.Tabs,{value:a,onValueChange:r,className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsxs(s.TabsTrigger,{value:"groups",className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-4 w-4"}),"Groups"]}),e.jsxs(s.TabsTrigger,{value:"create",className:"flex items-center gap-2",children:[e.jsx(s.Plus,{className:"h-4 w-4"}),"Create Group"]})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"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(s.Input,{placeholder:"Search groups...",value:l,onChange:y=>c(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:I?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):E.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:"No groups found"}),e.jsx("p",{className:"text-xs mt-1",children:l?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:E.map(y=>e.jsx(yt,{group:y,onManageMembers:()=>U(y),onDelete:()=>n(y),currentUserId:g==null?void 0:g.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(lt,{onSuccess:R,tenantId:S,isTenantUser:v})})]})]})}),m&&e.jsx(bt,{open:p,onOpenChange:j,group:m,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!h,onOpenChange:()=>n(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Group"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',h==null?void 0:h.name,'"? This action cannot be undone and will remove all members from the group.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:_,disabled:b.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function yt({group:t,onManageMembers:o,onDelete:a,currentUserId:r}){const l=t.createdBy===r;return e.jsx("div",{className:"rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"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 ",_s.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:o,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:a,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function J(t,o,a){var c,m;const r=(t.controls||[]).find(u=>u.id===a);if(r)return r.label;const l=(m=(c=s.findCardById(t,o))==null?void 0:c.controls)==null?void 0:m.find(u=>u.id===a);return(l==null?void 0:l.label)||a}function X(t,o){var a;return((a=s.findCardById(t,o))==null?void 0:a.title)||o}function Dt(t){const{errors:o,dashboard:a}=t;if(!a)return o;const r=new Map;for(const l of o){const c=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,h,n]=c,d=`${h}:${n}:missing-metric`;r.has(d)||r.set(d,`"${X(a,h)}" has an outdated "${J(a,h,n)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const m=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(m){const[,h,n]=m,d=`${h}:${n}:missing-group-by`;r.has(d)||r.set(d,`"${X(a,h)}" has an outdated "${J(a,h,n)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const u=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(u){const[,h,n]=u,d=`${h}:${n}:invalid-metric`;r.has(d)||r.set(d,`"${X(a,h)}" has an invalid "${J(a,h,n)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const p=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(p){const[,h,n]=p,d=`${h}:${n}:invalid-group-by`;r.has(d)||r.set(d,`"${X(a,h)}" has an invalid "${J(a,h,n)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const j=l.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(j){const[,h,n]=j,d=`${h}:${n}:missing-temporal-group-by`;r.has(d)||r.set(d,`"${X(a,h)}" can no longer use "${J(a,h,n)}" for time grain because the card does not currently group by a date field.`);continue}r.set(l,l)}return Array.from(r.values())}function Nt(){var Ve,Ke,Qe,We;P.useExportRecovery(),P.useExportPolling();const{authToken:t,tokenProps:o,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=Zs(),c=s.useHasDashboardId(),{isLoading:m}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const u=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),p=s.useDashboardStore(i=>i.lenses),j=s.useDashboardStore(i=>i.selectedLensId),h=p==null?void 0:p.find(i=>i.id===j),n=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const d=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:g}=s.useDashboardStore(i=>i.actions),[b,v]=x.useState(!1),[S,N]=x.useState(!1),[I,k]=x.useState(!1),[E,_]=x.useState(!1),[U,R]=x.useState(!1),[y,G]=x.useState(!1),[Y,z]=x.useState(null),[me,f]=x.useState(!1),[w,L]=x.useState(null),[F,$]=x.useState([]),[H,Z]=x.useState(!1),us=s.useDashboardStore(i=>i.isDashboardPanelOpen),ms=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),hs=s.useDashboardStore(i=>i.filterValues),D=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const V=s.useManagementStore(i=>i.selectedDashboard),ee=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const se=V?(Ke=V==null?void 0:V.permissions)==null?void 0:Ke.canEdit:(Ve=ee==null?void 0:ee.permissions)==null?void 0:Ve.canEdit,te=s.useDashboardStore(i=>i.showFilters),Te=s.useAssistantLayoutStore(i=>i.setPanelOpen),ps=s.useDashboardStore(i=>i.showDashboardJSON),he=s.useDashboardStore(i=>i.onSaveFunction),Oe=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Pe,setShowDashboardJSON:Fe}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:_e,clearSelectedDashboard:pe}=s.useManagementStore(i=>i.actions),{resources:ae}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:ge}=s.useUserPreferences(),gs=((Qe=ge==null?void 0:ge.preference)==null?void 0:Qe.defaultDashboardId)||null,{mutate:fs,isPending:xs}=s.useDefaultDashboardMutation(),{currentUser:bs}=s.useCurrentUserInfo(),vs=s.canUserManageGroups(bs),B=V||ee,Ue=B?{id:B.id,title:(n==null?void 0:n.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:js}=s.useAddNewFrame(),[fe,xe]=x.useState(!1),[Ss,K]=x.useState(!1),[be,re]=x.useState("close"),Q=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,ve]=x.useState(null),Re=x.useCallback(i=>{window.setTimeout(()=>{z(i)},0)},[]),ys=async(i,M)=>{if(!(n!=null&&n.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:n.id,newTitle:i,previousTitle:M}),Q.mutate({resourceId:n.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:O=>{console.error("Failed to update dashboard title:",O),s.ue.error("Failed to update dashboard title"),g(M)}})};x.useEffect(()=>{if(ae&&ae.length>0){const i=n==null?void 0:n.id;if(i){const M=ae.find(O=>O.id===i);M&&_e(M)}}},[ae,n==null?void 0:n.id,_e]);const ne=o.orgUserId||o.tenantId,Ge=d&&!D&&ne&&se,{setDashboard:je}=s.useDashboardStore(i=>i.actions),Ds=()=>{Pe(!0)},Se=()=>{Pe(!1),Fe(!1),ve(null),z(null)};P.usePristineSnapshotInitializer(d,n,T,i=>ve(i));const{isDirty:$e,isDirtyPending:Ns,resetDirty:oe}=Us.useDebouncedDirtyCheck(n,T,300,1e3,Ne.serializeDashboardForDirtyCheck),qe=x.useCallback(()=>T?Ne.serializeDashboardForDirtyCheck(n)!==Ne.serializeDashboardForDirtyCheck(T):!1,[n,T]),Be=$e||Ns,ie=fe||Q.isPending,ws=()=>{qe()?(re("close"),K(!0)):(Se(),oe())},Cs=async()=>{await ye({closeAfterSave:!0,navigateHomeAfterSave:be==="home"})},Ms=()=>{T&&je(T),Se(),be==="home"&&pe(),re("close"),K(!1),oe()},Ls=()=>{T&&(je(T),oe())},As=()=>{if(d&&qe()){re("home"),K(!0);return}pe()};async function ye(i){const M=s.useDashboardStore.getState().dashboard;if(!M)return;const O=(i==null?void 0:i.closeAfterSave)??H,Os=(i==null?void 0:i.navigateHomeAfterSave)??!1;Z(O),O&&K(!1);const Ps=s.cloneDeep(M);f(!0),L(null),$([]),xe(!0);const Fs={template:M};Q.mutate({resourceId:M.id,data:Fs},{onSuccess:A=>{var ce,de,Je;const q=(A==null?void 0:A.id)||((ce=A==null?void 0:A.dashboard)==null?void 0:ce.id)||((de=A==null?void 0:A.resource)==null?void 0:de.id)||((Je=A==null?void 0:A.template)==null?void 0:Je.id)||null;if(!M.id&&q){const De=s.useAIInteractionStore.getState(),ue=De.pendingDashboardDraftMigration;(ue==null?void 0:ue.scopeKey)===u?De.actions.setPendingDashboardDraftMigrationExpectedDashboardId(q):ue&&De.actions.clearPendingDashboardDraftMigration()}xe(!1),s.ue.success("Dashboard saved!"),ve(Ps),f(!1),Z(!1),O&&(Se(),oe(),Os&&pe()),re("close")},onError:A=>{xe(!1),L("Failed to save dashboard. Please try again.");const q=A.details,ce=Array.isArray(q==null?void 0:q.errors)?(q.errors||[]).filter(de=>typeof de=="string"):[];$(Dt({errors:ce,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Es(){if(v(!0),!j||!h)return;const i=s.useDashboardStore.getState().dashboard;if(!i){v(!1);return}const M=JSON.stringify(i),O={...h,template:M,filterValues:hs};await Le(o.apiServiceUrl,O,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),he==null||he(i),v(!1)}const ze=(h==null?void 0:h.name)||n.title;Q.isPending&&console.log("Title during update:",{title:ze,dashboardStateTitle:n.title,dashboardId:n==null?void 0:n.id,currentLensName:h==null?void 0:h.name});const He=o.orgUserId||o.tenantId&&o.endUserId&&o.endUserEmail,Is=!!He&&!!(t!=null&&t.accessToken)&&!!(o!=null&&o.apiServiceUrl),ks=c,W=(n==null?void 0:n.id)||null,le=!!W&&gs===W,Ts=()=>{W&&fs({dashboardId:le?null:W})};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:[He&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{ms(!us)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx($s,{className:"h-3.5 w-3.5"})}),ks&&!D&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:As,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!D&&c&&(m?e.jsx("div",{className:"h-4 w-28 rounded-md bg-muted/70 animate-pulse","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:ze||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:se,dashboardId:n==null?void 0:n.id});const M=(n==null?void 0:n.title)||"";g(i),ys(i,M)},isEditable:se&&!h,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:Q.isPending}),Is&&W&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"xs",onClick:Ts,disabled:xs||!(t!=null&&t.accessToken)||!(o!=null&&o.apiServiceUrl),className:"w-7 px-0","aria-label":le?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:s.cn("h-3.5 w-3.5 transition-colors",le?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:le?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[D&&e.jsxs(e.Fragment,{children:[e.jsx(P.AdvancedModeToggle,{}),e.jsx(P.VisualEditingControls,{})]}),r&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.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"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(o.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Bs,{className:"h-4 w-4"})})]}),!D&&c&&e.jsx(s.DownloadPdf,{}),!D&&c&&e.jsx(P.NotificationBell,{}),!D&&c&&((We=B==null?void 0:B.permissions)==null?void 0:We.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>N(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!D&&d&&l.canUseFilters&&c&&e.jsx(P.DashboardFilterControlsButton,{showFilters:te,onToggleFilters:()=>{te||Te("dashboard",!1),Oe(!te)},onAddFilter:()=>{te||(Te("dashboard",!1),Oe(!0))},onAddControl:()=>{Re("create")},onManageControls:()=>Re("manage")}),d&&!D&&c&&Y?e.jsx(P.DashboardControlsSettings,{open:!0,onOpenChange:i=>{i||z(null)},showTrigger:!1,initialMode:Y}):null,d&&!D&&ne&&r&&c&&e.jsx(Xs,{}),!D&&ne&&r&&c&&e.jsx(Ys,{}),d&&!D&&ne&&h&&r&&c&&e.jsxs(s.Button,{variant:"secondary",size:"xs",disabled:b,onClick:Es,children:[e.jsx(Ye.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",disabled:!d,onClick:()=>js(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!D&&!d&&se&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Ds,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Ge&&c&&$e&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Ls,disabled:ie,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Ge&&c&&e.jsxs(s.Button,{size:"xs",className:s.cn(!Be&&"opacity-60"),disabled:ie||!Be,onClick:()=>ye(),children:[ie?e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ye.Save,{className:"h-3.5 w-3.5"}),ie?"Saving...":"Save"]}),!D&&d&&r&&c&&e.jsx(s.Button,{size:"xs",variant:"ghost",onClick:()=>Fe(!ps),children:e.jsx(s.Code,{className:"h-3.5 w-3.5"})}),!D&&r&&e.jsx(Qs,{}),d&&!D&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:ws,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!D&&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-[6px] border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Automation"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>_(!0),children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule Dashboard"]}),e.jsx(s.DropdownMenuSeparator,{}),vs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>k(!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:()=>R(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>G(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]})]})]}),S&&Ue&&e.jsx(s.ShareDialog,{resource:Ue,resourceType:s.ResourceType.DASHBOARD,onClose:()=>N(!1)}),e.jsx(St,{open:I,onOpenChange:k}),(n==null?void 0:n.id)&&e.jsx(s.EmailScheduleDialog,{open:E,onOpenChange:_,dashboardId:n.id,dashboardName:n==null?void 0:n.title}),e.jsx(Xe.CalendarPreferencesDialog,{open:U,onOpenChange:R}),e.jsx(Xe.DashboardSummarySettingsDialog,{open:y,onOpenChange:G,dashboard:n,disabled:!d,onApply:i=>je({...n,summary:i})}),e.jsx(s.AlertDialog,{open:me,onOpenChange:i=>{!i&&fe&&!w||(f(i),i||(L(null),$([]),Z(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:w?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:w?"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(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:w?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{f(!1),L(null),$([]),Z(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ye({closeAfterSave:H,navigateHomeAfterSave:be==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(P.UnsavedChangesAlert,{open:Ss,onOpenChange:i=>{K(i)},onSave:Cs,onDiscard:Ms,isSaving:fe,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Nt;
|