react-semaphor 0.1.285 → 0.1.287

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/chunks/{dashboard-controls-DSwmmI8w.js → dashboard-controls-B8xnCPTZ.js} +318 -341
  2. package/dist/chunks/{dashboard-controls-B8f_BKTb.js → dashboard-controls-C25JMBLV.js} +4 -4
  3. package/dist/chunks/dashboard-filter-controls-button-BOJUiKGk.js +11 -0
  4. package/dist/chunks/{dashboard-filter-controls-button-BqmNXVoa.js → dashboard-filter-controls-button-D-o6ofi2.js} +476 -442
  5. package/dist/chunks/{dashboard-json-D0H5w5WI.js → dashboard-json-BYCWtm_z.js} +1 -1
  6. package/dist/chunks/{dashboard-json-qT21EDMm.js → dashboard-json-DFuRB4cG.js} +1 -1
  7. package/dist/chunks/{dashboard-summary-settings-dialog-BRI5dAfz.js → dashboard-summary-settings-dialog-CFTJNcmp.js} +1 -1
  8. package/dist/chunks/{dashboard-summary-settings-dialog-Mq8T35Qv.js → dashboard-summary-settings-dialog-CsnHeIhi.js} +1 -1
  9. package/dist/chunks/{edit-dashboard-visual-DLpQykTX.js → edit-dashboard-visual-DU3NzdD5.js} +2 -2
  10. package/dist/chunks/{edit-dashboard-visual-gSIS7RGI.js → edit-dashboard-visual-YmESbDUP.js} +4 -4
  11. package/dist/chunks/{index-Celt_oJr.js → index-BDE8cMG8.js} +170 -170
  12. package/dist/chunks/{index-r_DA-pny.js → index-Bz0-3JKw.js} +10194 -10218
  13. package/dist/chunks/resource-management-panel-C6qnO0ID.js +6 -0
  14. package/dist/chunks/resource-management-panel-Lxjcn4i0.js +933 -0
  15. package/dist/chunks/use-create-flow-overlay-state-AXNDXDqV.js +21 -0
  16. package/dist/chunks/{use-create-flow-overlay-state-C1xhazfY.js → use-create-flow-overlay-state-CJiyn4FY.js} +142 -145
  17. package/dist/chunks/{use-visual-utils-CWcTBBvd.js → use-visual-utils-BygqTxyR.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-CqL5PNOR.js → use-visual-utils-CWVz-eYg.js} +1 -1
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +5 -5
  23. package/dist/style.css +1 -1
  24. package/dist/surfboard/index.cjs +1 -1
  25. package/dist/surfboard/index.js +2 -2
  26. package/dist/types/main.d.ts +18 -2
  27. package/package.json +1 -1
  28. package/dist/chunks/dashboard-filter-controls-button-DXKJ-0iV.js +0 -11
  29. package/dist/chunks/resource-management-panel-Brj3iNyX.js +0 -6
  30. package/dist/chunks/resource-management-panel-DXLca9OX.js +0 -920
  31. 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-Celt_oJr.js"),x=require("react");require("react-dom");const P=require("./dashboard-filter-controls-button-DXKJ-0iV.js"),_s=require("./date-formatter-CqXdM6JO.js"),Xe=require("./dashboard-summary-settings-dialog-Mq8T35Qv.js"),Us=require("./use-debounced-dirty-check-XHSwAefL.js"),we=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),Ye=require("./use-create-flow-overlay-state-DVyd9L7O.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);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BDE8cMG8.js"),x=require("react");require("react-dom");const P=require("./dashboard-filter-controls-button-BOJUiKGk.js"),_s=require("./date-formatter-CqXdM6JO.js"),Xe=require("./dashboard-summary-settings-dialog-CsnHeIhi.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-AXNDXDqV.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 Hs=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 Le={exports:{}},Ce={};/**
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 Vs(){if(Ze)return Ce;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 Ce.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,Ce}var Me={};/**
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;
@@ -0,0 +1,11 @@
1
+ "use strict";const g=require("react"),e=require("./index-BDE8cMG8.js"),t=require("react/jsx-runtime"),I=require("./use-create-flow-overlay-state-AXNDXDqV.js"),M=require("./use-visual-utils-BygqTxyR.js"),L=require("./date-formatter-CqXdM6JO.js");/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const T=e.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
7
+ * @license lucide-react v0.453.0 - ISC
8
+ *
9
+ * This source code is licensed under the ISC license.
10
+ * See the LICENSE file in the root directory of this source tree.
11
+ */const P=e.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),V=1e4,z=15e3,O=3e4,R=3e4,H=12e4,k=2*60*60*1e3;function $(s){const r=Date.now()-s.getTime();return r<R?V:r<H?z:O}function _(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(p=>p.activeExports),[d,l]=g.useState(typeof document<"u"?!document.hidden:!0),h=g.useRef(null),o=g.useRef(!1),c=g.useRef(void 0),u=r==null?void 0:r.apiServiceUrl,n=s==null?void 0:s.accessToken,f=g.useCallback(()=>{const p=e.useExportStore.getState().activeExports;return Array.from(p.values()).filter(C=>e.isExportInProgress(C.status))},[]);g.useEffect(()=>{if(typeof document>"u")return;const p=()=>{l(!document.hidden)};return document.addEventListener("visibilitychange",p),()=>{document.removeEventListener("visibilitychange",p)}},[]);const b=g.useCallback(async()=>{if(!u||!n){o.current=!1;return}const p=f();if(p.length===0){o.current=!1;return}const C=Date.now(),D=p.filter(a=>C-a.startedAt.getTime()>k);if(D.length>0){const{updateExport:a}=e.useExportStore.getState().actions;for(const i of D)a(i.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const x=p.filter(a=>C-a.startedAt.getTime()<=k);if(x.length===0){o.current=!1;return}const j=await Promise.allSettled(x.map(async a=>{try{const i=await e.getExportStatus(u,n,a.id);let v;if(i.status==="completed")try{v=await e.getDownloadUrl(u,n,a.id)}catch(A){console.error(`[useExportPolling] Failed to get download URL for ${a.id}:`,A)}return{id:a.id,status:i.status,progress:i.progress,completedChunks:i.completedChunks,completedAt:i.completedAt?new Date(i.completedAt):void 0,lastUpdatedAt:new Date,fileSize:i.fileSize,error:i.error,downloadUrl:v}}catch(i){return console.error(`[useExportPolling] Failed to poll export ${a.id}:`,i),null}})),{updateExport:E}=e.useExportStore.getState().actions;for(const a of j)a.status==="fulfilled"&&a.value&&E(a.value.id,a.value);const w=f();if(w.length>0&&!document.hidden){const a=w.reduce((v,A)=>A.startedAt<v?A.startedAt:v,w[0].startedAt),i=$(a);h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{var v;(v=c.current)==null||v.call(c)},i)}else o.current=!1},[u,n,f]);return g.useEffect(()=>{c.current=b},[b]),g.useEffect(()=>{var C;f().length>0&&d&&!o.current&&(o.current=!0,(C=c.current)==null||C.call(c))},[m,d,f]),g.useEffect(()=>{var C;const p=f();d&&p.length>0&&!o.current&&(o.current=!0,(C=c.current)==null||C.call(c))},[d,f]),g.useEffect(()=>{!d&&h.current&&(clearTimeout(h.current),h.current=null,o.current=!1)},[d]),g.useEffect(()=>()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),{isPolling:o.current,isTabVisible:d,inProgressCount:f().length}}function q(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(c=>c.activeExports),{addExport:d}=e.useExportActions(),l=g.useRef(!1),h=r==null?void 0:r.apiServiceUrl,o=s==null?void 0:s.accessToken;g.useEffect(()=>{if(l.current||!h||!o)return;(async()=>{try{const{exports:u}=await e.getExports(h,o,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const n of u){if(m.has(n.id))continue;const f=n.totalChunks?Math.round(n.completedChunks/n.totalChunks*100):0;let b;if(n.status==="completed")try{b=await e.getDownloadUrl(h,o,n.id)}catch(C){console.error(`[useExportRecovery] Failed to get download URL for ${n.id}:`,C)}const p={id:n.id,status:n.status,progress:f,title:X(n),totalRows:n.totalRows,totalChunks:n.totalChunks,completedChunks:n.completedChunks,startedAt:new Date(n.createdAt),lastUpdatedAt:new Date,completedAt:n.completedAt?new Date(n.completedAt):void 0,fileSize:n.fileSize,error:n.error,expiresAt:new Date(n.expiresAt),downloadUrl:b};d(p)}l.current=!0}catch(u){console.error("[useExportRecovery] Failed to recover exports:",u),l.current=!0}})()},[h,o,d,m])}function X(s){return s.title?s.title:e.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function G({open:s,onOpenChange:r,isLibraryVisual:m,currentVisualName:d,isSaving:l=!1,destinationMode:h="both",onConfirm:o}){const[c,u]=g.useState(m&&d?`Copy of ${d}`:d||""),[n,f]=g.useState("");g.useEffect(()=>{s&&(u(m&&d?`Copy of ${d}`:d||""),f(""))},[s,m,d]);const b=!!c.trim(),p=h==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:h==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},C=()=>{!b||l||o({name:c.trim(),description:n.trim()||void 0,saveToLibrary:p.saveToLibrary,saveToCurrentDashboard:p.saveToCurrentDashboard})};return t.jsx(e.Dialog,{open:s,onOpenChange:r,children:t.jsxs(e.DialogContent,{className:"sm:max-w-[500px]",children:[t.jsxs(e.DialogHeader,{children:[t.jsxs(e.DialogTitle,{className:"flex items-center gap-2",children:[t.jsx("span",{children:"Save Visual As"}),p.badgeType!=="local"&&t.jsx(I.VisualBadge,{type:p.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),t.jsx(e.DialogDescription,{children:p.description})]}),t.jsxs("div",{className:"grid gap-4 py-4",children:[t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"name",children:"Name"}),t.jsx(e.Input,{id:"name",value:c,onChange:D=>u(D.target.value),placeholder:"Enter visual name",disabled:l})]}),t.jsxs("div",{className:"grid gap-2",children:[t.jsx(e.Label,{htmlFor:"description",children:"Description (optional)"}),t.jsx(e.Textarea,{id:"description",value:n,onChange:D=>f(D.target.value),placeholder:"Enter visual description",rows:3,disabled:l})]})]}),t.jsxs(e.DialogFooter,{children:[t.jsx(e.Button,{variant:"outline",onClick:()=>r(!1),disabled:l,children:"Cancel"}),t.jsxs(e.Button,{onClick:C,disabled:!b||l,children:[l&&t.jsx(e.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),p.actionLabel]})]})]})})}function K(){const[s,r]=g.useState(!1),[m,d]=g.useState(!1),[l,h]=g.useState(null),o=e.useEditorStore(i=>i.frame),c=e.useEditorStore(i=>i.card),u=e.useSelectedVisual(),n=e.useDashboardStore(i=>i.selectedSheetId),f=e.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),{getUpdatedFrame:b}=M.useVisualUtils(),{selectVisual:p}=e.useManagementActions(),{addFrame:C,setSelectedFrameId:D,setIsVisualEditing:x}=e.useDashboardActions(),j=!!(o!=null&&o.visualId),E=(()=>{var i,v;return((i=o==null?void 0:o.cards)==null?void 0:i.length)===1&&((v=o.cards[0])!=null&&v.title)?o.cards[0].title:u!=null&&u.title?u.title:(c==null?void 0:c.title)||"Untitled Visual"})(),w=e.useCreateVisualWithFrame(i=>{if(i!=null&&i.id){if(p(i),m&&l&&n){const v={...l,id:e.v4(),visualId:i.id};C(n,v,"end"),D(v.id),d(!1),h(null),x(!1)}f(!0),r(!1)}});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async i=>{if(!n){e.ue.error("No sheet selected");return}const v=b(),A=e.getDynamicFrameSaveIssue(v);if(A){e.ue.error(A);return}const N=v.cards.length===1?{...v,cards:v.cards.map(y=>({...y,title:i.name}))}:v;if(i.saveToLibrary){d(i.saveToCurrentDashboard),h(N);const y={title:i.name,description:i.description,frameObject:N,isPrivate:!1};w.mutate(y)}else if(i.saveToCurrentDashboard){const y={...N,id:e.v4(),visualId:void 0};C(n,y,"end"),D(y.id),e.ue.success("Visual saved to dashboard"),r(!1),x(!1)}},isLibraryVisual:j,currentVisualName:E,isSaving:w.isPending}}function Q(s={}){const r=e.useEditorStore(S=>S.frame),m=e.useManagementStore(S=>S.selectedVisual),d=e.useDashboardStore(S=>S.selectedFrameId),l=e.useDashboardStore(S=>S.selectedSheetId),{setIsVisualEditing:h,updateFrame:o}=e.useDashboardActions(),[c,u]=g.useState(!1),[n,f]=g.useState("both"),b=!!(r!=null&&r.visualId||m!=null&&m.id),p=!!(r!=null&&r.visualId&&d),C=b&&!p,{saveAsDialogOpen:D,setSaveAsDialogOpen:x,handleSaveAs:j,isLibraryVisual:E,currentVisualName:w,isSaving:a}=K(),{getUpdatedFrame:i}=M.useVisualUtils(),v=()=>{if(!l){e.ue.error("No sheet selected");return}if(c)return;u(!0);const S=i(),N=e.getDynamicFrameSaveIssue(S);if(N){u(!1),e.ue.error(N);return}const y={...S,visualId:void 0};o(l,y),setTimeout(()=>{u(!1),e.ue.success("Changes applied. Visual is now local to this dashboard"),h(!1)},300)},A=S=>{f(S),x(!0)};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-[5px]",children:[!b&&t.jsx(I.EditorAcceptButton,{className:"rounded-none",variant:"default"}),b&&C&&t.jsx(I.VisualSaveButton,{className:"rounded-none",variant:"default"}),b&&p&&t.jsx(I.VisualSaveAndApplyButton,{className:"rounded-none"}),t.jsxs(e.DropdownMenu,{modal:!1,children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"default",size:"xs",className:"w-7 rounded-none border-l border-primary-foreground/20 px-0","aria-label":"Open visual save options",disabled:a||c,children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"end",className:"min-w-[220px] rounded-[6px] border border-border/60 p-1 shadow-sm",children:[p&&t.jsxs(t.Fragment,{children:[t.jsxs(e.DropdownMenuItem,{onClick:v,disabled:c,children:[t.jsx(e.Check,{className:"h-3.5 w-3.5"}),c?"Applying...":"Apply Locally"]}),t.jsx(e.DropdownMenuSeparator,{})]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("local"),disabled:a,children:[t.jsx(e.Plus,{className:"h-3.5 w-3.5"}),"Add to Dashboard (Local)"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("library"),disabled:a,children:[t.jsx(I.Library,{className:"h-3.5 w-3.5"}),"Save as Library Visual"]}),t.jsxs(e.DropdownMenuItem,{onClick:()=>A("both"),disabled:a,children:[t.jsx(I.Link2,{className:"h-3.5 w-3.5"}),"Save Copy as Linked Visual"]})]})]})]}),t.jsx(I.EditorCancelButton,{}),t.jsx(G,{open:D,onOpenChange:S=>{a||x(S)},isLibraryVisual:E,currentVisualName:w,isSaving:a,destinationMode:n,onConfirm:j})]})}function W({className:s}){const r=e.useEditorStore(u=>u.isDevMode),m=e.useDashboardStore(u=>u.isVisualEditing),{setIsDevMode:d}=e.useEditorActions(),{config:l}=g.useContext(e.SemaphorContext).tokenProps,h=(l==null?void 0:l.showAdvancedMode)!==!1;if(!m||!h)return null;const o="h-7 rounded-none border-0 bg-transparent px-2.5 shadow-none text-muted-foreground hover:bg-accent/50 hover:text-foreground",c="bg-muted text-foreground hover:bg-muted";return t.jsxs("div",{role:"radiogroup","aria-label":"Editor mode",className:e.cn("inline-flex items-stretch overflow-hidden rounded-[5px] border border-input bg-background",s),children:[t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":!r,className:e.cn(o,!r&&c),onClick:()=>d(!1),children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Drag & drop"]}),t.jsxs(e.Button,{type:"button",variant:"ghost",size:"xs",role:"radio","aria-checked":r,className:e.cn(o,"border-l border-border/60",r&&c),onClick:()=>d(!0),children:[t.jsx(e.CodeXml,{className:"h-3.5 w-3.5"}),"SQL"]})]})}function Y({open:s,onOpenChange:r,onSave:m,onDiscard:d,isSaving:l,title:h="Unsaved changes",description:o="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:c="Cancel",discardLabel:u="Discard",saveLabel:n="Save"}){const f=b=>{!b&&l||r(b)};return t.jsx(e.AlertDialog,{open:s,onOpenChange:f,children:t.jsxs(e.AlertDialogContent,{children:[t.jsxs(e.AlertDialogHeader,{children:[t.jsx(e.AlertDialogTitle,{children:h}),t.jsx(e.AlertDialogDescription,{children:o})]}),t.jsxs(e.AlertDialogFooter,{children:[t.jsx(e.Button,{type:"button",size:"xs",onClick:d,disabled:l,variant:"ghost",className:"mr-auto text-muted-foreground hover:bg-destructive/10 hover:text-destructive focus-visible:bg-destructive/10 focus-visible:text-destructive",children:u}),t.jsx(e.AlertDialogCancel,{disabled:l,children:c}),t.jsx(e.Button,{type:"button",size:"xs",onClick:m,disabled:l,children:l?t.jsxs(t.Fragment,{children:[t.jsx(e.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving..."]}):n})]})]})})}function Z(s,r,m,d){g.useEffect(()=>{s&&!m&&r&&d(e.cloneDeep(r))},[s,m,r,d])}function B({export:s,onRemove:r}){const m=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},d=c=>{c.stopPropagation(),r==null||r(s.id)},l=()=>{switch(s.status){case"completed":return t.jsx(e.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return t.jsx(I.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return t.jsx(e.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},h=e.isExportInProgress(s.status),o=(()=>{switch(s.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return t.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[t.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[t.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[l(),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"•"}),t.jsx("span",{children:e.formatFileSize(s.fileSize)})]})]}),h&&t.jsx("div",{className:"text-xs text-muted-foreground",children:o}),s.status==="failed"&&t.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),t.jsx(e.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:d,"aria-label":"Remove notification",children:t.jsx(e.X,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&t.jsxs(e.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:m,children:[t.jsx(e.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),h&&t.jsxs("div",{children:[t.jsx(e.Progress,{value:s.progress,className:"h-1.5"}),t.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&t.jsx("span",{className:"text-xs text-muted-foreground",children:L.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function U(){const{authToken:s,tokenProps:r}=e.useSemaphorContext(),m=e.useExportStore(x=>x.activeExports),{clearCompleted:d,removeExport:l,updateExport:h}=e.useExportActions(),[o,c]=g.useState(!1),[u,n]=g.useState(!1),f=Array.from(m.values()).sort((x,j)=>j.startedAt.getTime()-x.startedAt.getTime()),b=f.some(x=>x.status==="completed"||x.status==="failed"),p=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!x||!j)){c(!0);try{const E=Array.from(m.values());await Promise.all(E.map(async w=>{try{const a=await e.getExportStatus(x,j,w.id);let i;if(a.status==="completed")try{i=await e.getDownloadUrl(x,j,w.id)}catch(v){console.error(`Failed to get download URL for ${w.id}:`,v)}h(w.id,{status:a.status,progress:a.progress,completedChunks:a.completedChunks,completedAt:a.completedAt?new Date(a.completedAt):void 0,lastUpdatedAt:new Date,fileSize:a.fileSize,error:a.error,downloadUrl:i})}catch(a){console.error(`Failed to refresh export ${w.id}:`,a)}}))}finally{c(!1)}}},[m,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,h]),C=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!x||!j){d();return}n(!0);try{const E=f.filter(a=>a.status==="completed"||a.status==="failed"),w=await Promise.allSettled(E.map(async a=>(await e.cancelExport(x,j,a.id),a.id)));for(const a of w)a.status==="fulfilled"?l(a.value):console.error("Failed to delete export:",a.reason)}finally{n(!1)}},[f,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,d,l]),D=g.useCallback(async x=>{const j=r==null?void 0:r.apiServiceUrl,E=s==null?void 0:s.accessToken;if(j&&E)try{await e.cancelExport(j,E,x),l(x);return}catch(w){console.error(`Failed to cancel export ${x}:`,w)}l(x)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,l]);return f.length===0?t.jsxs("div",{className:"p-6 text-center",children:[t.jsx(T,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),t.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(T,{className:"h-5 w-5 text-muted-foreground"}),t.jsx("h4",{className:"font-semibold",children:"Exports"})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:p,disabled:o,title:"Refresh status",children:t.jsx(e.RefreshCw,{className:`h-4 w-4 ${o?"animate-spin":""}`})}),b&&t.jsx(e.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:C,disabled:u,children:u?"Clearing...":"Clear all"})]})]}),t.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:t.jsx("div",{className:"divide-y",children:f.map(x=>t.jsx(B,{export:x,onRemove:D},x.id))})})]})}function J({variant:s}){const r=e.useExportStore(u=>u.activeExports),m=e.useInProgressExportsCount(),d=r.size>0,l=Array.from(r.values()).some(u=>u.status==="completed"||u.status==="failed"),o=m>0?m>9?"9+":String(m):null,c=d;return t.jsxs(e.Popover,{children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:t.jsxs(e.Button,{variant:s??"ghost",size:"xs",className:"relative w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":"Export notifications",children:[t.jsx(e.Bell,{className:"h-3.5 w-3.5"}),c&&t.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${o?"-right-0.5 -top-0.5 h-3.5 min-w-3.5 px-0.5 text-[9px] font-semibold":"right-1 top-1 h-1.5 w-1.5"}`,children:o})]})}),t.jsx(e.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:t.jsx(U,{})})]})}function ee(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function te({open:s,onOpenChange:r,trigger:m,showTrigger:d=!0,initialMode:l="manage"}){const h=l==="create",{forceClose:o,handleOpenChange:c,isCreateFlowActive:u,preventPassiveDismissDuringCreate:n,resolvedOpen:f,setIsCreateFlowActive:b}=I.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:l==="create",dismissMode:d?"passive":"explicit-only"}),p=e.useDashboardStore(N=>N.dashboard),{setDashboardControlsModel:C}=e.useDashboardActions(),{participants:D}=e.useDashboardStructuralParticipants(e.getDashboardCards(p)),x=Array.from(new Map(D.flatMap(N=>N.fieldChoices.map(y=>{var F;return[y.value,{option:y,target:(F=N.fieldTargetMap)==null?void 0:F[y.value]}]}))).values()),j=Array.from(new Map(D.flatMap(N=>N.metricChoices.map(y=>{var F;return[y.value,{option:y,target:(F=N.metricTargetMap)==null?void 0:F[y.value]}]}))).values()),E=e.collectDashboardControlIds({...p||{},controls:[]}),w=e.buildDashboardStructuralParticipantIdsByControlId(p),a=(N,y,F)=>{C(N,y,ee(F))},i=g.useCallback(()=>{if(h){o();return}b(!1)},[h,o,b]),v=t.jsx(I.ControlDefinitionListEditor,{scope:"dashboard",controls:p.controls||[],reservedControlIds:E,defaultValues:p.defaultControlValues||{},usageByControlId:e.buildDashboardControlUsageById(p),availableFieldChoices:x,availableMetricChoices:j,structuralParticipants:D,structuralParticipantIdsByControlId:w,initialCreateFlow:l==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:i,onChange:a,emptyMessage:"No dashboard controls yet."}),A=u?"Add dashboard control":"Dashboard Controls",S=t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),v]});return d?t.jsxs(e.Popover,{open:f,onOpenChange:c,children:[t.jsx(e.PopoverTrigger,{asChild:!0,children:m||t.jsxs(e.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[t.jsx(e.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),t.jsx(e.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:n,onPointerDownOutside:n,children:S})]}):t.jsx(e.Dialog,{open:f,onOpenChange:c,children:t.jsxs(e.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:n,onPointerDownOutside:n,children:[t.jsxs(e.DialogHeader,{className:u?"space-y-0":void 0,children:[t.jsx(e.DialogTitle,{className:"text-[15px]",children:A}),t.jsx(e.DialogDescription,{className:u?"sr-only":"text-[13px]",children:u?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),t.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:v})]})})}function se({showFilters:s,onToggleFilters:r,onAddFilter:m,onAddControl:d,onManageControls:l,size:h="default",className:o,primaryButtonClassName:c,secondaryButtonClassName:u,dropdownContentClassName:n}){const f=h==="toolbar";return t.jsxs("div",{className:e.cn("relative inline-flex items-stretch overflow-hidden rounded-[5px] border border-input bg-background",o),children:[t.jsxs(e.Button,{variant:"ghost",size:"xs",className:e.cn(f?"h-8":"h-7","rounded-none border-0 bg-transparent pl-2.5 pr-2 shadow-none hover:bg-accent/50",c),onClick:r,children:[s?t.jsx(P,{className:"h-3.5 w-3.5"}):t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Filter"]}),t.jsxs(e.DropdownMenu,{children:[t.jsx(e.DropdownMenuTrigger,{asChild:!0,children:t.jsx(e.Button,{variant:"ghost",size:"xs",className:e.cn(f?"h-8 w-7":"h-7 w-7","rounded-none border-0 border-l border-border/60 bg-transparent px-0 shadow-none hover:bg-accent/50",u),"aria-label":"Filter and control actions",children:t.jsx(e.ChevronDown,{className:"h-3.5 w-3.5"})})}),t.jsxs(e.DropdownMenuContent,{align:"start",className:e.cn("min-w-[180px] rounded-[6px] border border-border/60 p-1 shadow-sm",n),children:[t.jsxs(e.DropdownMenuItem,{onSelect:m,children:[t.jsx(e.Filter,{className:"h-3.5 w-3.5"}),"Add filter"]}),t.jsxs(e.DropdownMenuItem,{onSelect:d,children:[t.jsx(e.SlidersHorizontal,{className:"h-3.5 w-3.5"}),"Add control"]}),t.jsxs(e.DropdownMenuItem,{onSelect:l,children:[t.jsx(e.Pencil,{className:"h-3.5 w-3.5"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=W;exports.DashboardControlsSettings=te;exports.DashboardFilterControlsButton=se;exports.ExportNotificationItem=B;exports.ExportNotificationList=U;exports.NotificationBell=J;exports.UnsavedChangesAlert=Y;exports.VisualEditingControls=Q;exports.useExportPolling=_;exports.useExportRecovery=q;exports.usePristineSnapshotInitializer=Z;