react-semaphor 0.1.305 → 0.1.307
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brand-studio/index.cjs +2 -2
- package/dist/brand-studio/index.js +14 -14
- package/dist/chunks/braces-CkL8POe0.js +6 -0
- package/dist/chunks/braces-e5qkN-I_.js +23 -0
- package/dist/chunks/{dashboard-controls-DjOO0fkG.js → dashboard-controls-5bibC_5a.js} +141 -128
- package/dist/chunks/dashboard-controls-Dwet_9h0.js +52 -0
- package/dist/chunks/{dashboard-filter-controls-button-YvRfoUuN.js → dashboard-filter-controls-button-D0k9NDci.js} +4 -4
- package/dist/chunks/{dashboard-filter-controls-button-CR0_duPw.js → dashboard-filter-controls-button-ZeYO5jux.js} +1 -1
- package/dist/chunks/{dashboard-json-tOsNVccY.js → dashboard-json-Bi5XdgG5.js} +1 -1
- package/dist/chunks/{dashboard-json-BYLaWi0-.js → dashboard-json-CfRKLL7C.js} +2 -2
- package/dist/chunks/{dashboard-summary-settings-dialog-CMxi2arh.js → dashboard-summary-settings-dialog-Bj4_wBW9.js} +2 -2
- package/dist/chunks/{dashboard-summary-settings-dialog-DioOegLQ.js → dashboard-summary-settings-dialog-DD9Aj2XH.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-ClLcFLD_.js → edit-dashboard-visual-DIuzuJfj.js} +8796 -8713
- package/dist/chunks/edit-dashboard-visual-Wfs53Kbn.js +183 -0
- package/dist/chunks/{index-DJFckbGE.js → index-DMFCfjgD.js} +52348 -49752
- package/dist/chunks/index-DQCMUspd.js +1350 -0
- package/dist/chunks/{palette-BqJlrRto.js → palette-D5Lorzf2.js} +2 -7
- package/dist/chunks/{palette-DD-i7bNS.js → palette-Oa4O9jWG.js} +3 -23
- package/dist/chunks/{resource-management-panel-CoHy6cOi.js → resource-management-panel-CNr6uMMf.js} +1 -1
- package/dist/chunks/{resource-management-panel-BS9nfJbb.js → resource-management-panel-Dqc3gfYn.js} +3 -3
- package/dist/chunks/{save-j-clxFtx.js → save-CDX2p4v1.js} +1 -1
- package/dist/chunks/{save-CFBIhbHD.js → save-zEdICevW.js} +1 -1
- package/dist/chunks/{switch-BH17qlxH.js → switch-BPFzGTzF.js} +34 -29
- package/dist/chunks/{switch-BFhVVwh9.js → switch-CKiXRRoh.js} +432 -390
- package/dist/chunks/{use-create-flow-overlay-state-Lmk-mIkA.js → use-create-flow-overlay-state-CLyv5c2m.js} +4 -4
- package/dist/chunks/{use-create-flow-overlay-state-BSUi4chy.js → use-create-flow-overlay-state-CSMe5Ls6.js} +1 -1
- package/dist/chunks/{use-visual-utils-CR9nLyEz.js → use-visual-utils-DDAs4dCz.js} +1 -1
- package/dist/chunks/{use-visual-utils-CikIkKb2.js → use-visual-utils-Det6M3Wd.js} +2 -2
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +142 -44
- package/dist/types/main.d.ts +144 -46
- package/dist/types/shared.d.ts +142 -44
- package/dist/types/surfboard.d.ts +142 -44
- package/dist/types/types.d.ts +142 -44
- package/package.json +4 -4
- package/dist/chunks/dashboard-controls-BcwXajYv.js +0 -47
- package/dist/chunks/edit-dashboard-visual-331vOmKT.js +0 -183
- package/dist/chunks/index-BOGpMmRo.js +0 -1360
- package/dist/chunks/rotate-ccw-CdGW8Rxm.js +0 -6
- package/dist/chunks/rotate-ccw-X8MbX_hF.js +0 -14
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./switch-BPFzGTzF.js"),s=require("./index-DQCMUspd.js"),b=require("react");require("./index-DRlMUglg.js");require("react-dom");const G=require("./dashboard-filter-controls-button-ZeYO5jux.js"),it=require("./index-D7KJindZ.js"),gs=require("./dashboard-summary-settings-dialog-DD9Aj2XH.js"),lt=require("./use-debounced-dirty-check-XHSwAefL.js"),Fe=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),bs=require("./use-create-flow-overlay-state-CSMe5Ls6.js"),vs=require("./save-zEdICevW.js"),ct=require("./palette-D5Lorzf2.js"),dt=require("./braces-CkL8POe0.js");function ut(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const I=ut(b);/**
|
|
2
|
+
* @license lucide-react v0.453.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const mt=o.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
7
|
+
* @license lucide-react v0.453.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const ht=o.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
|
|
12
|
+
* @license lucide-react v0.453.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const pt=o.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
|
|
17
|
+
* @license lucide-react v0.453.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const ft=o.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const xt=o.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
27
|
+
* @license lucide-react v0.453.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const gt=o.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/**
|
|
32
|
+
* @license lucide-react v0.453.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const Re=o.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var qe={exports:{}},_e={};/**
|
|
37
|
+
* @license React
|
|
38
|
+
* use-sync-external-store-shim.production.js
|
|
39
|
+
*
|
|
40
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
41
|
+
*
|
|
42
|
+
* This source code is licensed under the MIT license found in the
|
|
43
|
+
* LICENSE file in the root directory of this source tree.
|
|
44
|
+
*/var ys;function bt(){if(ys)return _e;ys=1;var t=b;function a(x,p){return x===p&&(x!==0||1/x===1/p)||x!==x&&p!==p}var n=typeof Object.is=="function"?Object.is:a,r=t.useState,c=t.useEffect,m=t.useLayoutEffect,d=t.useDebugValue;function f(x,p){var u=p(),i=r({inst:{value:u,getSnapshot:p}}),y=i[0].inst,w=i[1];return m(function(){y.value=u,y.getSnapshot=p,g(y)&&w({inst:y})},[x,u,p]),c(function(){return g(y)&&w({inst:y}),x(function(){g(y)&&w({inst:y})})},[x]),d(u),u}function g(x){var p=x.getSnapshot;x=x.value;try{var u=p();return!n(x,u)}catch{return!0}}function v(x,p){return p()}var h=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?v:f;return _e.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:h,_e}var Ue={};/**
|
|
45
|
+
* @license React
|
|
46
|
+
* use-sync-external-store-shim.development.js
|
|
47
|
+
*
|
|
48
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
49
|
+
*
|
|
50
|
+
* This source code is licensed under the MIT license found in the
|
|
51
|
+
* LICENSE file in the root directory of this source tree.
|
|
52
|
+
*/var Ss;function vt(){return Ss||(Ss=1,process.env.NODE_ENV!=="production"&&function(){function t(u,i){return u===i&&(u!==0||1/u===1/i)||u!==u&&i!==i}function a(u,i){h||c.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 y=i();if(!x){var w=i();m(y,w)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),x=!0)}w=d({inst:{value:y,getSnapshot:i}});var D=w[0].inst,C=w[1];return g(function(){D.value=y,D.getSnapshot=i,n(D)&&C({inst:D})},[u,y,i]),f(function(){return n(D)&&C({inst:D}),u(function(){n(D)&&C({inst:D})})},[u]),v(y),y}function n(u){var i=u.getSnapshot;u=u.value;try{var y=i();return!m(u,y)}catch{return!0}}function r(u,i){return i()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var c=b,m=typeof Object.is=="function"?Object.is:t,d=c.useState,f=c.useEffect,g=c.useLayoutEffect,v=c.useDebugValue,h=!1,x=!1,p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:a;Ue.useSyncExternalStore=c.useSyncExternalStore!==void 0?c.useSyncExternalStore:p,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ue}process.env.NODE_ENV==="production"?qe.exports=bt():qe.exports=vt();var yt=qe.exports;const je=["light","dark","system"];function St(){const{theme:t,setTheme:a}=s.useTheme(),n=o.useDashboardStore(d=>d.actions.setDashboardTheme);function r(){const d=je.includes(t)?t:"system",f=je[(je.indexOf(d)+1)%je.length];a(f),n(f)}const c=t==="light"?gt:t==="dark"?ft:pt,m=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(o.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:r,"aria-label":m,title:m,children:e.jsx(c,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function jt(t,a,n,r,c){if(!c)return null;const m=JSON.stringify(n),d=`${t}/v1/lens`;return await o.postRequest(d,c,{name:a,template:m,filterValues:r,operation:"create"})}async function Ge(t,a,n){if(!n)return null;const{id:r,template:c,filterValues:m,isDefault:d,shared:f}=a,g=`${t}/v1/lens`;return await o.postRequest(g,n,{lensId:r,template:c,filterValues:m,isDefault:d,shared:f,operation:"update"})}async function Dt(t,a,n){if(!n)return null;const r=`${t}/v1/lens`;return await o.postRequest(r,n,{operation:"delete",lensId:a})}const wt="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Ct({open:t,onOpenChange:a}={}){const[n,r]=b.useState(""),[c,m]=b.useState(!1),d=o.useDashboardStore(M=>M.lenses),{setLenses:f,setSelectedLensId:g}=o.useDashboardActions(),[v,h]=b.useState(!1),[x,p]=b.useState(!1),u=t!==void 0,i=u?t:x,y=M=>{u||p(M),a==null||a(M)},w=o.useDashboardStore(M=>M.dashboard),D=o.useDashboardStore(M=>M.filterValues),{authToken:C,tokenProps:N}=s.useSemaphorContext();async function E(){h(!0);const M=await jt(N.apiServiceUrl,n,w,D,C==null?void 0:C.accessToken);M&&(f([...d||[],M]),g(M.id),y(!1)),h(!1)}return e.jsxs(s.Dialog,{open:i,onOpenChange:y,children:[u?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(o.Label,{htmlFor:"lens-name",className:wt,children:"Name"}),e.jsx(o.Input,{id:"lens-name",size:"xs",value:n,placeholder:"Monthly review, West region, …",onChange:M=>r(M.target.value)}),c&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:()=>y(!1),children:"Cancel"}),e.jsx(o.Button,{size:"xs",type:"submit",onClick:E,disabled:v||!n.trim(),children:v?"Creating…":"Create"})]})]})]})}function Nt({includeLabel:t=!1}={}){const a=o.useDashboardStore(h=>h.lenses),n=o.useDashboardStore(h=>h.selectedLensId),{setLenses:r,setSelectedLensId:c}=o.useDashboardActions(),{authToken:m,tokenProps:d}=s.useSemaphorContext();async function f(h){c(h)}async function g(h){if(await Dt(d.apiServiceUrl,h,m==null?void 0:m.accessToken)){const p=a==null?void 0:a.filter(u=>u.id!==h);r(p||[]),c("original")}}async function v(h){const x=a==null?void 0:a.map(i=>i.id===h.id?{...i,isDefault:!h.isDefault}:{...i,isDefault:!1});r(x||[]);const p={...h,isDefault:!h.isDefault};await Ge(d.apiServiceUrl,p,m==null?void 0:m.accessToken);const u=a==null?void 0:a.find(i=>i.isDefault);if(u&&u.id!==h.id){const i={...u,isDefault:!1};await Ge(d.apiServiceUrl,i,m==null?void 0:m.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:n,onValueChange:f,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(h=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:h.id,children:[e.jsx("p",{children:h.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:x=>{x.preventDefault(),v(h)},className:o.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!h.isDefault,"text-green-500":h.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:x=>{x.preventDefault(),g(h.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},h.id))]})]})}function Mt(){const{displayPreferences:t,shouldShowElement:a}=s.useDisplayPreferences(),{currentUser:n,userContext:r}=s.useCurrentUserInfo(),c=b.useMemo(()=>s.getRoleBasedDisplayOverrides(n),[n]),m=b.useMemo(()=>f=>c&&c[f]!==void 0&&c[f]===!1?!1:a(f),[c,a,t]),d=b.useMemo(()=>{var f,g,v,h,x;return{canEdit:((f=r==null?void 0:r.permissions)==null?void 0:f.canEdit)??s.canUserEdit(n),canUseFilters:((g=r==null?void 0:r.permissions)==null?void 0:g.canEdit)??s.canUserUseFilters(n),canManageDashboards:((v=r==null?void 0:r.permissions)==null?void 0:v.canCreateDashboard)??s.canUserManageDashboards(n),canCreateDashboards:((h=r==null?void 0:r.permissions)==null?void 0:h.canCreateDashboard)??s.canUserCreateDashboards(n),canAccessVisuals:((x=r==null?void 0:r.permissions)==null?void 0:x.canEdit)??s.canUserAccessVisuals(n)}},[n,r]);return{displayPreferences:t,shouldShowElement:m,permissions:d,currentUser:n}}const It=async(t,a,n)=>{const r=`${t}/management/v1/groups`;return await o.postRequestRegular(r,a,n)},Et=async(t,a,n)=>{const r=`${t}/management/v1/groups/${n}`;await o.requestJsonRegular(r,a,"DELETE")},Lt=async(t,a,n,r)=>{const c=`${t}/management/v1/groups/${n}/members`;return await o.postRequestRegular(c,a,r)},At=async(t,a,n,r)=>{const c=`${t}/management/v1/groups/${n}/members`;await o.requestJsonRegular(c,a,"DELETE",r)};function kt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>It(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{n.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:o.getRequestErrorMessage(r,"Failed to create group")})}})}function Ot(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:r=>Et(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["groups"]}),n.removeQueries({queryKey:["group",c]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:o.getRequestErrorMessage(r,"Failed to delete group")})}})}function Tt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:c})=>Lt(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,c),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["group",c.groupId]}),n.invalidateQueries({queryKey:["group-members",c.groupId]}),n.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:o.getRequestErrorMessage(r,"Failed to add members")})}})}function Pt(){const{authToken:t,tokenProps:a}=s.useSemaphorContext(),n=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:c})=>At(a.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,c),onSuccess:(r,c)=>{n.invalidateQueries({queryKey:["group",c.groupId]}),n.invalidateQueries({queryKey:["group-members",c.groupId]}),n.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:o.getRequestErrorMessage(r,"Failed to remove members")})}})}const js="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Ft({onSuccess:t,tenantId:a,isTenantUser:n}){const[r,c]=b.useState(""),[m,d]=b.useState(""),[f,g]=b.useState({}),v=kt(),h=()=>{const p={};return r.trim()?r.length<3?p.name="Group name must be at least 3 characters":r.length>50&&(p.name="Group name must be less than 50 characters"):p.name="Group name is required",m&&m.length>200&&(p.description="Description must be less than 200 characters"),g(p),Object.keys(p).length===0},x=async p=>{if(p.preventDefault(),!h())return;const u={name:r.trim(),description:m.trim()||void 0,type:n?"TENANT_GROUP":"ORG_GROUP",...n&&a?{tenantId:a}:{}};try{await v.mutateAsync(u),c(""),d(""),g({}),t()}catch(i){console.error("Failed to create group:",i)}};return e.jsxs("form",{onSubmit:x,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(o.Label,{htmlFor:"group-name",className:js,children:["Group name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(o.Input,{id:"group-name",size:"xs",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:p=>{c(p.target.value),f.name&&g(u=>({...u,name:""}))},className:f.name?"border-destructive":"",disabled:v.isPending}),f.name&&e.jsx("p",{className:"text-[12px] text-destructive",children:f.name})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{htmlFor:"group-description",className:js,children:"Description (optional)"}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group…",value:m,onChange:p=>{d(p.target.value),f.description&&g(u=>({...u,description:""}))},className:`text-[13px] ${f.description?"border-destructive":""}`,disabled:v.isPending,rows:3}),f.description?e.jsx("p",{className:"text-[12px] text-destructive",children:f.description}):e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[m.length,"/200"]})]}),e.jsxs("div",{className:"flex gap-2 text-[12px] text-muted-foreground",children:[e.jsx(o.Info,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),e.jsx("p",{children:"This group will be accessible to users in your workspace. You can add members after creating it."})]}),e.jsxs("div",{className:"flex justify-end gap-1.5 pt-1",children:[e.jsx(o.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>{c(""),d(""),g({})},disabled:v.isPending,children:"Clear"}),e.jsx(o.Button,{type:"submit",size:"xs",disabled:v.isPending||!r.trim(),children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Creating…"]}):"Create group"})]})]})}function _t(t,a=[]){let n=[];function r(m,d){const f=I.createContext(d);f.displayName=m+"Context";const g=n.length;n=[...n,d];const v=x=>{var D;const{scope:p,children:u,...i}=x,y=((D=p==null?void 0:p[t])==null?void 0:D[g])||f,w=I.useMemo(()=>i,Object.values(i));return e.jsx(y.Provider,{value:w,children:u})};v.displayName=m+"Provider";function h(x,p){var y;const u=((y=p==null?void 0:p[t])==null?void 0:y[g])||f,i=I.useContext(u);if(i)return i;if(d!==void 0)return d;throw new Error(`\`${x}\` must be used within \`${m}\``)}return[v,h]}const c=()=>{const m=n.map(d=>I.createContext(d));return function(f){const g=(f==null?void 0:f[t])||m;return I.useMemo(()=>({[`__scope${t}`]:{...f,[t]:g}}),[f,g])}};return c.scopeName=t,[r,Ut(c,...a)]}function Ut(...t){const a=t[0];if(t.length===1)return a;const n=()=>{const r=t.map(c=>({useScope:c(),scopeName:c.scopeName}));return function(m){const d=r.reduce((f,{useScope:g,scopeName:v})=>{const x=g(m)[`__scope${v}`];return{...f,...x}},{});return I.useMemo(()=>({[`__scope${a.scopeName}`]:d}),[d])}};return n.scopeName=a.scopeName,n}var Rt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],$e=Rt.reduce((t,a)=>{const n=o.createSlot(`Primitive.${a}`),r=I.forwardRef((c,m)=>{const{asChild:d,...f}=c,g=d?n:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(g,{...f,ref:m})});return r.displayName=`Primitive.${a}`,{...t,[a]:r}},{});function qt(){return yt.useSyncExternalStore(Gt,()=>!0,()=>!1)}function Gt(){return()=>{}}var Be="Avatar",[$t]=_t(Be),[Bt,Cs]=$t(Be),Ns=I.forwardRef((t,a)=>{const{__scopeAvatar:n,...r}=t,[c,m]=I.useState("idle");return e.jsx(Bt,{scope:n,imageLoadingStatus:c,onImageLoadingStatusChange:m,children:e.jsx($e.span,{...r,ref:a})})});Ns.displayName=Be;var Ms="AvatarImage",Is=I.forwardRef((t,a)=>{const{__scopeAvatar:n,src:r,onLoadingStatusChange:c=()=>{},...m}=t,d=Cs(Ms,n),f=zt(r,m),g=o.useCallbackRef(v=>{c(v),d.onImageLoadingStatusChange(v)});return o.useLayoutEffect2(()=>{f!=="idle"&&g(f)},[f,g]),f==="loaded"?e.jsx($e.img,{...m,ref:a,src:r}):null});Is.displayName=Ms;var Es="AvatarFallback",Ls=I.forwardRef((t,a)=>{const{__scopeAvatar:n,delayMs:r,...c}=t,m=Cs(Es,n),[d,f]=I.useState(r===void 0);return I.useEffect(()=>{if(r!==void 0){const g=window.setTimeout(()=>f(!0),r);return()=>window.clearTimeout(g)}},[r]),d&&m.imageLoadingStatus!=="loaded"?e.jsx($e.span,{...c,ref:a}):null});Ls.displayName=Es;function Ds(t,a){return t?a?(t.src!==a&&(t.src=a),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function zt(t,{referrerPolicy:a,crossOrigin:n}){const r=qt(),c=I.useRef(null),m=r?(c.current||(c.current=new window.Image),c.current):null,[d,f]=I.useState(()=>Ds(m,t));return o.useLayoutEffect2(()=>{f(Ds(m,t))},[m,t]),o.useLayoutEffect2(()=>{const g=x=>()=>{f(x)};if(!m)return;const v=g("loaded"),h=g("error");return m.addEventListener("load",v),m.addEventListener("error",h),a&&(m.referrerPolicy=a),typeof n=="string"&&(m.crossOrigin=n),()=>{m.removeEventListener("load",v),m.removeEventListener("error",h)}},[m,n,a]),d}var As=Ns,ks=Is,Os=Ls;const ze=I.forwardRef(({className:t,...a},n)=>e.jsx(As,{ref:n,className:o.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...a}));ze.displayName=As.displayName;const Vt=I.forwardRef(({className:t,...a},n)=>e.jsx(ks,{ref:n,className:o.cn("aspect-square h-full w-full",t),...a}));Vt.displayName=ks.displayName;const Ve=I.forwardRef(({className:t,...a},n)=>e.jsx(Os,{ref:n,className:o.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...a}));Ve.displayName=Os.displayName;function Ht({open:t,onOpenChange:a,group:n,onUpdate:r}){const[c,m]=b.useState("members"),[d,f]=b.useState(""),[g,v]=b.useState([]),[h,x]=b.useState([]),{data:p,isLoading:u,refetch:i}=s.useGroupMembers(n.id),y=n.type==="TENANT_GROUP"?"tenant":"organization",{users:w,isLoading:D}=s.useUnifiedUsers({type:y,tenantId:n.tenantId||void 0,active:!0,limit:100}),C=Tt(),N=Pt(),E=(p==null?void 0:p.members)||[],M=b.useMemo(()=>new Set(E.map(S=>S.userId)),[E]),P=b.useMemo(()=>w.filter(S=>!M.has(S.id)),[w,M]),_=b.useMemo(()=>{if(!d)return P;const S=d.toLowerCase();return P.filter(L=>{var F,q;return((F=L.name)==null?void 0:F.toLowerCase().includes(S))||((q=L.email)==null?void 0:q.toLowerCase().includes(S))})},[P,d]),j=b.useMemo(()=>{if(!d)return E;const S=d.toLowerCase();return E.filter(L=>{var F,q,te,K;return((q=(F=L.user)==null?void 0:F.name)==null?void 0:q.toLowerCase().includes(S))||((K=(te=L.user)==null?void 0:te.email)==null?void 0:K.toLowerCase().includes(S))})},[E,d]),R=async()=>{if(g.length!==0)try{await C.mutateAsync({groupId:n.id,data:{userIds:g,userType:y==="tenant"?"tenant":"org"}}),v([]),m("members"),i(),r==null||r()}catch(S){console.error("Failed to add members:",S)}},B=async()=>{if(h.length!==0)try{await N.mutateAsync({groupId:n.id,data:{userIds:h}}),x([]),i(),r==null||r()}catch(S){console.error("Failed to remove members:",S)}},V=S=>{v(L=>L.includes(S)?L.filter(F=>F!==S):[...L,S])},H=S=>{x(L=>L.includes(S)?L.filter(F=>F!==S):[...L,S])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:a,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:n.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 ",n.name," group"]})]}),e.jsxs(o.Tabs,{value:c,onValueChange:S=>{m(S),f(""),x([])},className:"mt-4",children:[e.jsxs(o.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(o.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(o.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(o.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{placeholder:"Search members...",value:d,onChange:S=>f(S.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:h.length>0?"h-[300px]":"h-[350px]",children:u?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(S=>e.jsx(s.Skeleton,{className:"h-16 w-full"},S))}):j.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:d?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:j.map(S=>e.jsx(Kt,{member:S,selected:h.includes(S.userId),onToggle:()=>H(S.userId)},S.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," member",h.length!==1?"s":""," selected"]}),e.jsx(o.Button,{variant:"destructive",size:"sm",onClick:B,disabled:N.isPending,children:N.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),e.jsxs(o.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{placeholder:"Search users to add...",value:d,onChange:S=>f(S.target.value),className:"pl-10"})]}),e.jsx(o.ScrollArea,{className:"h-[300px]",children:D?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(S=>e.jsx(s.Skeleton,{className:"h-16 w-full"},S))}):_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(Re,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No available users"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:_.map(S=>e.jsx(Qt,{user:S,selected:g.includes(S.id),onToggle:()=>V(S.id)},S.id))})}),g.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[g.length," user",g.length!==1?"s":""," selected"]}),e.jsx(o.Button,{onClick:R,disabled:C.isPending,children:C.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function Kt({member:t,selected:a,onToggle:n}){var c,m,d,f;const r=((m=(c=t.user)==null?void 0:c.name)==null?void 0:m.split(" ").map(g=>g[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:n,children:[e.jsx(s.Checkbox,{checked:a}),e.jsx(ze,{className:"h-8 w-8",children:e.jsx(Ve,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((d=t.user)==null?void 0:d.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(f=t.user)==null?void 0:f.email})]})]})}function Qt({user:t,selected:a,onToggle:n}){var c;const r=((c=t.name)==null?void 0:c.split(" ").map(m=>m[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:n,children:[e.jsx(s.Checkbox,{checked:a}),e.jsx(ze,{className:"h-8 w-8",children:e.jsx(Ve,{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 Wt({open:t,onOpenChange:a}){const[n,r]=b.useState("groups"),[c,m]=b.useState(""),[d,f]=b.useState(null),[g,v]=b.useState(!1),[h,x]=b.useState(null),{tokenProps:p}=s.useSemaphorContext(),{currentUser:u}=s.useCurrentUserInfo(),i=Ot(),y=(u==null?void 0:u.type)==="tenant",w=p==null?void 0:p.tenantId,{groups:D,isLoading:C,refetch:N}=s.useGroups({type:y?"TENANT_GROUP":"all",tenantId:y?w:void 0,includeMembers:!1}),E=D.filter(j=>{var R;return j.name.toLowerCase().includes(c.toLowerCase())||((R=j.description)==null?void 0:R.toLowerCase().includes(c.toLowerCase()))}),M=async()=>{if(h)try{await i.mutateAsync(h.id),x(null),N()}catch(j){console.error("Failed to delete group:",j)}},P=j=>{f(j),v(!0)},_=()=>{r("groups"),N()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-3xl rounded-[6px] border-border/60 sm:rounded-[6px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Group management"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Manage groups, create new ones, and control membership."})]}),e.jsxs(o.Tabs,{value:n,onValueChange:r,className:"mt-2",children:[e.jsxs(o.TabsList,{className:"h-8 w-full justify-start gap-1 bg-transparent p-0 border-b border-border/60 rounded-none",children:[e.jsx(o.TabsTrigger,{value:"groups",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Groups"}),e.jsx(o.TabsTrigger,{value:"create",className:"h-8 rounded-none border-b-2 border-transparent bg-transparent px-3 text-[13px] data-[state=active]:border-foreground data-[state=active]:bg-transparent data-[state=active]:shadow-none",children:"Create group"})]}),e.jsx(o.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(o.Input,{size:"xs",placeholder:"Search groups…",value:c,onChange:j=>m(j.target.value),className:"pl-7"})]}),e.jsx(o.ScrollArea,{className:"h-[400px]",children:C?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(j=>e.jsx(s.Skeleton,{className:"h-16 w-full rounded-[6px]"},j))}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx("p",{className:"text-[13px]",children:"No groups found."}),e.jsx("p",{className:"mt-1 text-[12px]",children:c?"Try a different search.":"Create your first group to get started."})]}):e.jsx("div",{className:"space-y-2 pr-2",children:E.map(j=>e.jsx(Jt,{group:j,onManageMembers:()=>P(j),onDelete:()=>x(j),currentUserId:u==null?void 0:u.id},j.id))})})]})}),e.jsx(o.TabsContent,{value:"create",className:"mt-4",children:e.jsx(Ft,{onSuccess:_,tenantId:w,isTenantUser:y})})]})]})}),d&&e.jsx(Ht,{open:g,onOpenChange:v,group:d,onUpdate:()=>N()}),e.jsx(s.AlertDialog,{open:!!h,onOpenChange:()=>x(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete group"}),e.jsxs(s.AlertDialogDescription,{children:['Delete "',h==null?void 0:h.name,`"? This removes all members and can't be undone.`]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:M,disabled:i.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:i.isPending?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Deleting…"]}):"Delete group"})]})]})})]})}function Jt({group:t,onManageMembers:a,onDelete:n,currentUserId:r}){const c=t.createdBy===r;return e.jsx("div",{className:"rounded-[6px] border border-border/60 bg-card px-3 py-2.5 transition-colors hover:bg-muted/30",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx("h4",{className:"text-[13px] font-medium text-foreground",children:t.name}),t.description&&e.jsx("p",{className:"text-[12px] text-muted-foreground",children:t.description}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),e.jsxs("span",{children:["Created ",it.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,title:"Manage members","aria-label":"Manage members",children:e.jsx(Re,{className:"h-3.5 w-3.5"})}),c&&e.jsx(o.Button,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:n,title:"Delete group","aria-label":"Delete group",children:e.jsx(s.Trash2,{className:"h-3.5 w-3.5"})})]})]})})}function ee(t,a,n){var m,d;const r=(t.controls||[]).find(f=>f.id===n);if(r)return r.label;const c=(d=(m=o.findCardById(t,a))==null?void 0:m.controls)==null?void 0:d.find(f=>f.id===n);return(c==null?void 0:c.label)||n}function se(t,a){var n;return((n=o.findCardById(t,a))==null?void 0:n.title)||a}function Yt(t){const{errors:a,dashboard:n}=t;if(!n)return a;const r=new Map;for(const c of a){const m=c.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(m){const[,h,x]=m,p=`${h}:${x}:missing-metric`;r.has(p)||r.set(p,`"${se(n,h)}" has an outdated "${ee(n,h,x)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const d=c.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(d){const[,h,x]=d,p=`${h}:${x}:missing-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" has an outdated "${ee(n,h,x)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const f=c.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(f){const[,h,x]=f,p=`${h}:${x}:invalid-metric`;r.has(p)||r.set(p,`"${se(n,h)}" has an invalid "${ee(n,h,x)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const g=c.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(g){const[,h,x]=g,p=`${h}:${x}:invalid-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" has an invalid "${ee(n,h,x)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const v=c.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(v){const[,h,x]=v,p=`${h}:${x}:missing-temporal-group-by`;r.has(p)||r.set(p,`"${se(n,h)}" can no longer use "${ee(n,h,x)}" for time grain because the card does not currently group by a date field.`);continue}r.set(c,c)}return Array.from(r.values())}const Xt=["enum","multi_enum","text","number","boolean","date"];function Zt({open:t,onOpenChange:a,initialMode:n="manage"}){var _;const r=n==="create",{forceClose:c,handleOpenChange:m,isCreateFlowActive:d,preventPassiveDismissDuringCreate:f,resolvedOpen:g,setIsCreateFlowActive:v}=bs.useCreateFlowOverlayState({open:t,onOpenChange:a,initialCreateFlowActive:n==="create",dismissMode:"explicit-only"}),h=o.useDashboardStore(j=>j.dashboard),x=o.useDashboardStore(j=>j.selectedSheetId),{setDashboardInputs:p}=o.useDashboardActions(),u=(_=h.sheets)==null?void 0:_.find(j=>j.id===x),i=(u==null?void 0:u.kind)==="document"&&!!u.document,y=b.useMemo(()=>i&&(u!=null&&u.document)?s.getDocumentSheetDashboardInputs(h,u.id):[],[h,i,u==null?void 0:u.document,u==null?void 0:u.id]),w=b.useMemo(()=>y.filter(j=>j.kind==="control"),[y]),D=b.useMemo(()=>w.map(j=>j.control),[w]),C=b.useMemo(()=>sa(D),[D]),N=b.useMemo(()=>ea(h),[h]),E=b.useCallback(()=>{if(r){c();return}v(!1)},[r,c,v]),M=b.useCallback((j,R,B)=>{!i||!(u!=null&&u.document)||p(aa({allInputs:h.inputs||[],documentSheetId:u.id,currentDocumentInputs:y,nextControls:j,nextDefaultValues:R,change:B}))},[h.inputs,y,i,u,p]);if(!i||!(u!=null&&u.document))return null;const P=d?"Add document control":"Document Controls";return e.jsx(s.Dialog,{open:g,onOpenChange:m,children:e.jsxs(s.DialogContent,{className:"flex max-h-[88vh] flex-col overflow-hidden sm:max-w-[600px]",onEscapeKeyDown:f,onPointerDownOutside:f,children:[e.jsxs(s.DialogHeader,{className:d?"space-y-0":void 0,children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:P}),e.jsx(s.DialogDescription,{className:d?"sr-only":"text-[13px]",children:d?"Configure and add a document-local control input.":"Add document-local control inputs. They are stored on this document sheet and are not dashboard controls."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:e.jsx(bs.ControlDefinitionListEditor,{scope:"dashboard",controls:D,reservedControlIds:N,defaultValues:C,usageByControlId:{},availableFieldChoices:[],availableMetricChoices:[],structuralParticipants:[],structuralParticipantIdsByControlId:{},allowedControlTypes:Xt,initialCreateFlow:n==="create",onCreateFlowActiveChange:v,onCreateFlowComplete:E,onChange:M,emptyMessage:"No document controls yet."})})]})})}function ea(t){return(t.controls||[]).map(a=>a.id)}function sa(t){const a={};for(const n of t)n.defaultValue!==void 0&&(a[n.id]=n.defaultValue);return a}function ta(t,a){return a?Object.prototype.hasOwnProperty.call(a,t.id)?{...t,defaultValue:a[t.id]}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}:t.defaultValue===void 0?t:{...t,defaultValue:void 0}}function aa({allInputs:t,documentSheetId:a,currentDocumentInputs:n,nextControls:r,nextDefaultValues:c,change:m}){const d=new Map(r.map(p=>[p.id,ta(p,c)])),f=(m==null?void 0:m.type)==="rename"?{oldId:m.oldId,newId:m.newId}:null,g=new Set,v=[];for(const p of n){if(p.kind!=="control"){v.push(p);continue}const u=d.get(p.control.id)||((f==null?void 0:f.oldId)===p.control.id?d.get(f.newId):void 0);if(!u)continue;g.add(u.id);const i=s.createUniqueDashboardInputVariableNameFromName(u.id,[...t,...v].filter(w=>w.id!==p.id)),y=u.id===i?u:{...u,id:i};v.push({...p,label:y.label,variableName:i,requiredAtExecution:y.requiredAtExecution,control:y})}for(const p of d.values())g.has(p.id)||v.push(s.createDashboardControlInputFromControl({control:p,existingInputs:[...t,...v],sheetId:a}));const h=new Set(n.map(p=>p.id));return[...t.filter(p=>!h.has(p.id)),...v]}function ws(t,a){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(a)}}function na(){var ds,us,ms,hs,ps,fs;G.useExportRecovery(),G.useExportPolling();const{authToken:t,tokenProps:a,id:n}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{openBrandStudioPreview:c}=s.useBrandStudioPreview(),{permissions:m}=Mt(),d=s.useHasDashboardId(),{isLoading:f}=s.useDashboardQuery(),g=o.useDashboardStore(l=>l.theme),v=o.useDashboardStore(l=>l.isDownloadingPdf),h=o.useDashboardStore(l=>l.dashboardAssistantDraftScopeKey),x=o.useDashboardStore(l=>l.lenses),p=o.useDashboardStore(l=>l.selectedLensId),u=x==null?void 0:x.find(l=>l.id===p),i=o.useDashboardStore(l=>l.dashboard),y=o.useDashboardStore(l=>l.selectedSheetId),w=(ds=i==null?void 0:i.sheets)==null?void 0:ds.find(l=>l.id===y),D=o.isDocumentSheet(w),C=D?(us=w==null?void 0:w.document)==null?void 0:us.page:void 0,N=o.useDashboardStore(l=>l.isDashboardEditing),{setDashboardTitle:E}=o.useDashboardStore(l=>l.actions),[M,P]=b.useState(!1),[_,j]=b.useState(!1),[R,B]=b.useState(!1),[V,H]=b.useState(!1),[S,L]=b.useState(!1),[F,q]=b.useState(!1),[te,K]=b.useState(!1),[Ts,He]=b.useState(!1),[De,ae]=b.useState(null),[Ps,ne]=b.useState(!1),[re,oe]=b.useState(null),[Ke,ie]=b.useState([]),[Qe,le]=b.useState(!1),Fs=o.useDashboardStore(l=>l.isDashboardPanelOpen),_s=o.useDashboardStore(l=>l.actions.setIsDashboardPanelOpen),Us=o.useDashboardStore(l=>l.filterValues),k=o.useDashboardStore(l=>l.isVisualEditing);o.useEditorStore(l=>l.card);const Q=s.useManagementStore(l=>l.selectedDashboard),ce=s.useManagementStore(l=>l.initialDashboard);s.useManagementStore(l=>l.selectedVisual),o.useDashboardStore(l=>l.selectedFrameId),o.useEditorStore(l=>l.frame);const de=Q?(hs=Q==null?void 0:Q.permissions)==null?void 0:hs.canEdit:(ms=ce==null?void 0:ce.permissions)==null?void 0:ms.canEdit,ue=o.useDashboardStore(l=>l.showFilters),We=s.useAssistantLayoutStore(l=>l.setPanelOpen),Je=o.useDashboardStore(l=>l.showDashboardJSON),we=o.useDashboardStore(l=>l.onSaveFunction),Ye=o.useDashboardStore(l=>l.actions.setShowFilters),{setDocumentInspectorTab:Xe,setIsDashboardEditing:Ze,setShowDashboardJSON:es}=o.useDashboardStore(l=>l.actions),{setInitialDashboard:ss,clearSelectedDashboard:Ce}=s.useManagementStore(l=>l.actions),{resources:me}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Ne}=s.useUserPreferences(),Rs=((ps=Ne==null?void 0:Ne.preference)==null?void 0:ps.defaultDashboardId)||null,{mutate:qs,isPending:Gs}=s.useDefaultDashboardMutation(),{currentUser:$s}=s.useCurrentUserInfo(),Bs=s.canUserManageGroups($s),z=Q||ce,ts=z?{id:z.id,title:(i==null?void 0:i.title)||z.title||"Dashboard"}:null,{handleAddNewFrame:zs}=s.useAddNewFrame(),[Me,Ie]=b.useState(!1),[Vs,W]=b.useState(!1),[Ee,he]=b.useState("close"),J=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,pe]=b.useState(null),as=b.useCallback(l=>{window.setTimeout(()=>{ae(l)},0)},[]),Hs=async(l,A)=>{if(!(i!=null&&i.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:i.id,newTitle:l,previousTitle:A}),J.mutate({resourceId:i.id,data:{title:l}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),s.ue.error("Failed to update dashboard title"),E(A)}})};b.useEffect(()=>{if(me&&me.length>0){const l=i==null?void 0:i.id;if(l){const A=me.find(U=>U.id===l);A&&ss(A)}}},[me,i==null?void 0:i.id,ss]);const Y=a.orgUserId||a.tenantId,Le=b.useMemo(()=>ra({accessToken:t==null?void 0:t.accessToken,dashboardId:(i==null?void 0:i.id)||n||a.dashboard_id,selectedSheetId:D?y:void 0,pageSize:C==null?void 0:C.size,orientation:C==null?void 0:C.orientation,theme:g}),[t==null?void 0:t.accessToken,n,i==null?void 0:i.id,D,C==null?void 0:C.orientation,C==null?void 0:C.size,y,g,a.dashboard_id]),ns=N&&!k&&Y&&de,{setDashboard:Ae}=o.useDashboardStore(l=>l.actions),ke=o.useDashboardStore(l=>l.semanticExecutionPayload),Ks=()=>{Ze(!0)},Oe=()=>{Ze(!1),es(!1),pe(null),ae(null)};b.useEffect(()=>{if(!N){T&&pe(null);return}T||!i||f||pe(ws(i,ke))},[i,T,N,f,ke]);const fe=(T==null?void 0:T.dashboard)??null,{isDirty:rs,isDirtyPending:Qs,resetDirty:xe}=lt.useDebouncedDirtyCheck(i,fe,300,1e3,Fe.serializeDashboardForDirtyCheck),os=b.useCallback(()=>fe?Fe.serializeDashboardForDirtyCheck(i)!==Fe.serializeDashboardForDirtyCheck(fe):!1,[i,fe]),is=rs||Qs,ge=Me||J.isPending,Ws=()=>{os()?(he("close"),W(!0)):(Oe(),xe())},Js=async()=>{await Te({closeAfterSave:!0,navigateHomeAfterSave:Ee==="home"})},Ys=()=>{T&&Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),Oe(),Ee==="home"&&Ce(),he("close"),W(!1),xe()},Xs=()=>{T&&(Ae(T.dashboard,{semanticExecutionPayload:T.semanticExecutionPayload}),xe())},Zs=()=>{if(N&&os()){he("home"),W(!0);return}Ce()};async function Te(l){const A=o.useDashboardStore.getState().dashboard;if(!A)return;const U=(l==null?void 0:l.closeAfterSave)??Qe,nt=(l==null?void 0:l.navigateHomeAfterSave)??!1;le(U),U&&W(!1);const rt=s.cloneDeep(A);ne(!0),oe(null),ie([]),Ie(!0);const ot={template:A};J.mutate({resourceId:A.id,data:ot},{onSuccess:O=>{var ve,ye,xs;const $=(O==null?void 0:O.id)||((ve=O==null?void 0:O.dashboard)==null?void 0:ve.id)||((ye=O==null?void 0:O.resource)==null?void 0:ye.id)||((xs=O==null?void 0:O.template)==null?void 0:xs.id)||null;if(!A.id&&$){const Pe=o.useAIInteractionStore.getState(),Se=Pe.pendingDashboardDraftMigration;(Se==null?void 0:Se.scopeKey)===h?Pe.actions.setPendingDashboardDraftMigrationExpectedDashboardId($):Se&&Pe.actions.clearPendingDashboardDraftMigration()}Ie(!1),s.ue.success("Dashboard saved!"),pe(ws(rt,o.useDashboardStore.getState().semanticExecutionPayload)),ne(!1),le(!1),U&&(Oe(),xe(),nt&&Ce()),he("close")},onError:O=>{Ie(!1),oe("Failed to save dashboard. Please try again.");const $=O.details,ve=Array.isArray($==null?void 0:$.errors)?($.errors||[]).filter(ye=>typeof ye=="string"):[];ie(Yt({errors:ve,dashboard:A||void 0})),s.ue.error("Failed to save dashboard")}})}async function et(){if(P(!0),!p||!u)return;const l=o.useDashboardStore.getState().dashboard;if(!l){P(!1);return}const A=JSON.stringify(l),U={...u,template:A,filterValues:Us};await Ge(a.apiServiceUrl,U,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),we==null||we(l),P(!1)}const ls=(u==null?void 0:u.name)||i.title,X=!!(i!=null&&i.id);J.isPending&&console.log("Title during update:",{title:ls,dashboardStateTitle:i.title,dashboardId:i==null?void 0:i.id,currentLensName:u==null?void 0:u.name});const cs=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail,st=!!cs&&!!(t!=null&&t.accessToken)&&!!(a!=null&&a.apiServiceUrl);b.useEffect(()=>{!X&&V&&H(!1)},[X,V]);const tt=d,Z=(i==null?void 0:i.id)||null,be=!!Z&&Rs===Z,at=()=>{Z&&qs({dashboardId:be?null:Z})};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:[cs&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{_s(!Fs)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),tt&&!k&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Zs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!k&&d&&(f?e.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:ls||"Untitled Dashboard",onSave:l=>{console.log("EditableText onSave called:",{newTitle:l,canEditDashboard:de,dashboardId:i==null?void 0:i.id});const A=(i==null?void 0:i.title)||"";E(l),Hs(l,A)},isEditable:de&&!u,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:J.isPending}),st&&Z&&e.jsx(o.TooltipProvider,{children:e.jsxs(o.Tooltip,{children:[e.jsx(o.TooltipTrigger,{asChild:!0,children:e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:at,disabled:Gs||!(t!=null&&t.accessToken)||!(a!=null&&a.apiServiceUrl),className:"w-7 px-0","aria-label":be?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:o.cn("h-3.5 w-3.5 transition-colors",be?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(o.TooltipContent,{children:e.jsx("p",{children:be?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k&&e.jsxs(e.Fragment,{children:[e.jsx(G.AdvancedModeToggle,{}),e.jsx(G.VisualEditingControls,{})]}),!k&&d&&((fs=z==null?void 0:z.permissions)==null?void 0:fs.canShare)&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:()=>j(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!k&&N&&m.canUseFilters&&d&&e.jsx(G.DashboardFilterControlsButton,{showFilters:D?!1:ue,onToggleFilters:()=>{if(D&&y){Xe(y,"inputs");return}ue||We("dashboard",!1),Ye(!ue)},onAddFilter:()=>{if(D&&y){Xe(y,"inputs");return}ue||(We("dashboard",!1),Ye(!0))},onAddControl:()=>{as("create")},onManageControls:()=>as("manage")}),N&&!k&&d&&De?D?e.jsx(Zt,{open:!0,onOpenChange:l=>{l||ae(null)},initialMode:De}):e.jsx(G.DashboardControlsSettings,{open:!0,onOpenChange:l=>{l||ae(null)},showTrigger:!1,initialMode:De}):null,N&&!k&&Y&&u&&r&&d&&e.jsxs(o.Button,{variant:"secondary",size:"xs",disabled:M,onClick:et,children:[e.jsx(vs.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),N&&!k&&d&&!D&&e.jsxs(o.Button,{variant:"outline",size:"xs",disabled:!N,onClick:()=>zs(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!k&&!N&&de&&d&&e.jsxs(o.Button,{size:"xs",onClick:Ks,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),ns&&d&&rs&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Xs,disabled:ge,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),ns&&d&&e.jsxs(o.Button,{size:"xs",className:o.cn(!is&&"opacity-60"),disabled:ge||!is,onClick:()=>Te(),children:[ge?e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(vs.Save,{className:"h-3.5 w-3.5"}),ge?"Saving...":"Save"]}),N&&!k&&d&&e.jsxs(o.Button,{variant:"outline",size:"xs",onClick:Ws,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!k&&d&&e.jsx("div",{className:"ml-2",children:e.jsx(G.NotificationBell,{})}),!k&&r&&e.jsx(St,{}),!k&&d&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:v,onSelect:()=>He(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!X,onSelect:()=>{X&&H(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),Bs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>B(!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:()=>L(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>q(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),r&&d&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var l;t!=null&&t.accessToken&&((l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),D&&e.jsxs(s.DropdownMenuItem,{disabled:!Le,onSelect:()=>{var l;if(!Le){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(l=navigator==null?void 0:navigator.clipboard)!=null&&l.writeText?navigator.clipboard.writeText(Le).then(()=>s.ue.success("Local document PDF URL copied to clipboard")).catch(()=>s.ue.error("Unable to copy local document PDF URL")):s.ue.error("Clipboard not available")},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>o.invalidateToken(a.apiServiceUrl),children:[e.jsx(xt,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:c,children:[e.jsx(ct.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>es(!Je),children:[e.jsx(dt.Braces,{className:"h-3.5 w-3.5"}),Je?"Hide dashboard JSON":"Show dashboard JSON"]}),Y&&N&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>K(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),Y&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(mt,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(Nt,{})})]})]})]})]}),_&&ts&&e.jsx(s.ShareDialog,{resource:ts,resourceType:s.ResourceType.DASHBOARD,onClose:()=>j(!1)}),e.jsx(Wt,{open:R,onOpenChange:B}),X&&(i==null?void 0:i.id)&&e.jsx(s.EmailScheduleDialog,{open:V,onOpenChange:H,dashboardId:i.id,dashboardName:i==null?void 0:i.title}),e.jsx(gs.CalendarPreferencesDialog,{open:S,onOpenChange:L}),e.jsx(gs.DashboardSummarySettingsDialog,{open:F,onOpenChange:q,dashboard:i,disabled:!N,onApply:l=>Ae({...i,summary:l},{semanticExecutionPayload:ke})}),r&&Y&&d&&e.jsx(Ct,{open:te,onOpenChange:K}),d&&e.jsx(s.DownloadPdf,{open:Ts,onOpenChange:He}),e.jsx(s.AlertDialog,{open:Ps,onOpenChange:l=>{!l&&Me&&!re||(ne(l),l||(oe(null),ie([]),le(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:re?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:re?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),Ke.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:Ke.slice(0,5).map(l=>e.jsx("li",{children:l},l))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:re?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{ne(!1),oe(null),ie([]),le(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Te({closeAfterSave:Qe,navigateHomeAfterSave:Ee==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(o.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(G.UnsavedChangesAlert,{open:Vs,onOpenChange:l=>{W(l)},onSave:Js,onDiscard:Ys,isSaving:Me,saveLabel:"Save",discardLabel:"Discard"})]})]})}function ra({accessToken:t,dashboardId:a,selectedSheetId:n,pageSize:r,orientation:c,theme:m}){if(!t||!n)return null;const d=new URL("http://localhost:5173/print-document");d.searchParams.set("token",t),a&&d.searchParams.set("dashboardId",a),d.searchParams.set("selectedSheetId",n),m&&d.searchParams.set("theme",m);const f=new URL("http://127.0.0.1:3002/");return f.searchParams.set("pdfMode","document"),f.searchParams.set("pageSize",r||"letter"),f.searchParams.set("orientation",c||"portrait"),f.searchParams.set("url",d.toString()),f.toString()}exports.default=na;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Se, { useState as T, useRef as X, useCallback as $, useEffect as O, useContext as Ae } from "react";
|
|
2
|
-
import { u as W, ae as z, aZ as q, aV as le, aW as K, af as de, aU as Ie, b as ce, c as ue, d as me, e as he, f as pe, bV as Fe, o as Le, t as Te, v as Pe, b8 as fe, bW as ke, p as k, b9 as G, W as Ue, bq as ve, br as ge, bt as be, bu as R, by as Ve, bl as Me, bX as Be, bY as Oe, bF as ze, bG as Re, bH as $e, bI as _e, bJ as He, bK as je, bL as Xe, a$ as Ge, bZ as We, b_ as qe, bn as Ke, aX as J, M as Qe, ah as Ze, b$ as Ye, c0 as Je, c1 as et, c2 as tt, c3 as ee, c4 as at } from "./index-
|
|
2
|
+
import { u as W, ae as z, aZ as q, aV as le, aW as K, af as de, aU as Ie, b as ce, c as ue, d as me, e as he, f as pe, bV as Fe, o as Le, t as Te, v as Pe, b8 as fe, bW as ke, p as k, b9 as G, W as Ue, bq as ve, br as ge, bt as be, bu as R, by as Ve, bl as Me, bX as Be, bY as Oe, bF as ze, bG as Re, bH as $e, bI as _e, bJ as He, bK as je, bL as Xe, a$ as Ge, bZ as We, b_ as qe, bn as Ke, aX as J, M as Qe, ah as Ze, b$ as Ye, c0 as Je, c1 as et, c2 as tt, c3 as ee, c4 as at } from "./index-DMFCfjgD.js";
|
|
3
3
|
import { jsx as t, jsxs as s, Fragment as _ } from "react/jsx-runtime";
|
|
4
|
-
import { c as xe, L as te, I as st, B as I, f as Q, n as j, u as B, m as Z,
|
|
5
|
-
import { V as dt, E as se, a as re, b as ct, c as ut, L as mt, d as ht, C as pt, u as ft, e as vt } from "./use-create-flow-overlay-state-
|
|
6
|
-
import { u as Ee } from "./use-visual-utils-
|
|
4
|
+
import { c as xe, L as te, I as st, B as I, f as Q, n as j, u as B, m as Z, aF as ae, af as ye, G as we, e as rt, l as ot, a as H, p as Y, X as nt, P as Ce, b as De, d as Ne, aG as it, aH as lt } from "./switch-CKiXRRoh.js";
|
|
5
|
+
import { V as dt, E as se, a as re, b as ct, c as ut, L as mt, d as ht, C as pt, u as ft, e as vt } from "./use-create-flow-overlay-state-CLyv5c2m.js";
|
|
6
|
+
import { u as Ee } from "./use-visual-utils-Det6M3Wd.js";
|
|
7
7
|
import { k as oe } from "./date-formatter-DyIOb6uC.js";
|
|
8
8
|
/**
|
|
9
9
|
* @license lucide-react v0.453.0 - ISC
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const g=require("react"),t=require("./index-
|
|
1
|
+
"use strict";const g=require("react"),t=require("./index-DQCMUspd.js"),e=require("react/jsx-runtime"),r=require("./switch-BPFzGTzF.js"),F=require("./use-create-flow-overlay-state-CSMe5Ls6.js"),R=require("./use-visual-utils-DDAs4dCz.js"),U=require("./date-formatter-D9Bvw5Qk.js");/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),o=require("react"),s=require("./switch-BPFzGTzF.js");require("./index-DQCMUspd.js");require("./index-DRlMUglg.js");require("react-dom");function b(){const t=s.useDashboardStore(e=>e.dashboard),c=s.useDashboardStore(e=>e.actions.setDashboard),u=s.useDashboardStore(e=>e.showDashboardJSON),h=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),a=o.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,d]=o.useState(a),n=o.useRef(a);return o.useEffect(()=>{a!==n.current&&(d(a),n.current=a)},[a]),r.jsxs("div",{className:s.cn("relative p-2",{hidden:!u}),children:[r.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>h(!1),children:[r.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),r.jsx("div",{className:"h-[550px] overflow-hidden",children:r.jsx(s.CodeEditor,{value:l,onValueChange:e=>{d(e);try{const i=JSON.parse(e);n.current=JSON.stringify(i,null,2),c(i)}catch{}},language:"json"})})]})}exports.default=b;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as i, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo as m, useState as b, useRef as f, useEffect as S } from "react";
|
|
3
|
-
import { u as o, a as N, B as p, X as D, C as J } from "./switch-
|
|
4
|
-
import "./index-
|
|
3
|
+
import { u as o, a as N, B as p, X as D, C as J } from "./switch-CKiXRRoh.js";
|
|
4
|
+
import "./index-DMFCfjgD.js";
|
|
5
5
|
import "./index-CJdxSyQq.js";
|
|
6
6
|
import "react-dom";
|
|
7
7
|
function C() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as a, Fragment as ue } from "react/jsx-runtime";
|
|
2
2
|
import me, { useState as f, useCallback as H, useEffect as q, useMemo as U } from "react";
|
|
3
|
-
import { u as he, b as Q, c as ee, d as ae, e as te, f as se, R, g as $, C as fe, h as pe, i as be, j as ve, k as ge, l as V, m as G, n as xe, o as re, p as I } from "./index-
|
|
4
|
-
import { a as k, L as P, P as Se, b as ye, B as A, d as Ne, e as X, f as we, S as ke, g as Ce, h as Te, i as Ie, j as Pe, k as Z, I as Ae } from "./switch-
|
|
3
|
+
import { u as he, b as Q, c as ee, d as ae, e as te, f as se, R, g as $, C as fe, h as pe, i as be, j as ve, k as ge, l as V, m as G, n as xe, o as re, p as I } from "./index-DMFCfjgD.js";
|
|
4
|
+
import { a as k, L as P, P as Se, b as ye, B as A, d as Ne, e as X, f as we, S as ke, g as Ce, h as Te, i as Ie, j as Pe, k as Z, I as Ae } from "./switch-CKiXRRoh.js";
|
|
5
5
|
function ze(r = {}) {
|
|
6
6
|
var T, L, D, M;
|
|
7
7
|
const { authToken: i, tokenProps: t } = he(), g = r.enabled ?? !0, o = (i == null ? void 0 : i.accessToken) ?? null, h = (t == null ? void 0 : t.apiServiceUrl) ?? null, [N, S] = f(!1), [x, b] = f(!1), [u, n] = f(!1), [y, c] = f(null), [p, w] = f(null), z = p || {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),o=require("react"),a=require("./index-BOGpMmRo.js"),s=require("./switch-BH17qlxH.js");function q(n={}){var k,P,A,E;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),S=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[v,b]=o.useState(!1),[h,l]=o.useState(!1),[y,d]=o.useState(null),[p,w]=o.useState(null),T=p||{tz:((P=(k=t==null?void 0:t.params)==null?void 0:k.calendarContext)==null?void 0:P.tz)||null,weekStart:((E=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:E.weekStart)??null},g=o.useCallback(async()=>{if(!(!S||!u||!f)){j(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const i=await m.json();w({tz:i.tz,weekStart:i.weekStart,source:i.source,isInherited:i.isInherited,userHasPrefs:i.userHasPrefs,inherited:i.inherited})}catch(m){const i=m instanceof Error?m.message:"Unknown error";d(i)}finally{j(!1)}}},[u,f,S]);o.useEffect(()=>{S&&g()},[S,g]);const I=o.useCallback(async m=>{if(!u||!f)return d("Not authenticated"),!1;b(!0),d(null);try{const i=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify(m)});if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.error||"Failed to update preferences")}return await g(),!0}catch(i){const x=i instanceof Error?i.message:"Unknown error";return d(x),!1}finally{b(!1)}},[u,f,g]),C=o.useCallback(async()=>{if(!u||!f)return d("Not authenticated"),!1;l(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const i=await m.text();if(i)try{const x=JSON.parse(i);return w({tz:x.tz,weekStart:x.weekStart,source:x.source,isInherited:x.isInherited??!0,userHasPrefs:!1,inherited:x.inherited}),!0}catch{}return await g(),!0}catch(m){const i=m instanceof Error?m.message:"Unknown error";return d(i),!1}finally{l(!1)}},[u,f,g]);return{preferences:T,isLoading:N,isSaving:v,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const D=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],$=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],B="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function X(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return D.map(n=>n.value)}function Z(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=D.find(t=>t.value===n);return c?c.label:n}function J(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function K({open:n,onOpenChange:c}){var M,F,U;const{preferences:t,isLoading:S,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=q({enabled:n}),v=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((F=t.inherited)==null?void 0:F.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(v),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>X(),[]),P=o.useMemo(()=>k.filter(r=>!D.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),E=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?J(t.inherited.weekStart):"Monday",i=Z((U=t.inherited)==null?void 0:U.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(v),g(b))},[n,y,t.userHasPrefs,v,b]);const x=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}h?await j()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again."):await N({tz:p,weekStart:T})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again.")},G=()=>{c(!1)},L=u||f,W=L||S;return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Set your timezone and week-start for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(a.RadioGroup,{value:h?"defaults":"custom",onValueChange:r=>{d(!0),l(r==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",h&&"bg-muted/50"),onClick:()=>{d(!0),l(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",i," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[E,", week starts ",m]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!h&&"bg-muted/50"),onClick:()=>{d(!0),l(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:s.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",h&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Timezone"}),e.jsxs(s.Popover,{open:I,onOpenChange:C,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":I,className:"w-full justify-between text-[12px] font-normal",disabled:h,children:[e.jsx("span",{className:"truncate",children:A}),e.jsx(a.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:D.map(r=>e.jsxs(a.CommandItem,{value:`${r.value} ${r.label}`,onSelect:()=>{d(!0),w(r.value),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:r.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:r.value})]},r.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All timezones",children:P.map(r=>e.jsxs(a.CommandItem,{value:r,onSelect:()=>{d(!0),w(r),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r?"opacity-100":"opacity-0")}),r]},r))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Week starts on"}),e.jsx(a.RadioGroup,{value:String(T),onValueChange:r=>{d(!0),g(Number(r))},className:"flex gap-4",disabled:h,children:$.map(r=>e.jsxs("label",{htmlFor:`week-start-${r.value}`,className:s.cn("flex cursor-pointer items-center gap-2 text-[13px]",h&&"cursor-not-allowed"),children:[e.jsx(a.RadioGroupItem,{value:String(r.value),id:`week-start-${r.value}`,disabled:h}),r.label]},r.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:G,disabled:L,children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:x,disabled:W,children:L?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}const z=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Y(n){return Number.isNaN(n)?z:Math.min(R,Math.max(O,n))}function Q({open:n,onOpenChange:c,dashboard:t,onApply:S,disabled:u=!1}){const[f,N]=o.useState(!1),[j,v]=o.useState("top"),[b,h]=o.useState(String(z)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),v((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??z)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Y(Number.parseInt(b||`${z}`,10)),[b]),d=()=>{S({enabled:f,position:j,maxItems:y}),c(!1)};return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Summary Settings"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-enabled",className:"text-[13px]",children:"Enable dashboard summary"}),e.jsx(s.Switch,{size:"xs",id:"dashboard-summary-enabled",checked:f,disabled:u,onCheckedChange:N})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-position",className:H,children:"Position"}),e.jsxs(s.Select,{value:j,disabled:u,onValueChange:p=>v(p),children:[e.jsx(s.SelectTrigger,{id:"dashboard-summary-position",size:"xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-max-items",className:H,children:"Max items"}),e.jsx(s.Input,{size:"xs",id:"dashboard-summary-max-items",type:"number",min:O,max:R,disabled:u,value:b,onChange:p=>h(p.target.value),onBlur:()=>h(String(y))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),u&&e.jsx("p",{className:"text-[12px] text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>c(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:d,disabled:u,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=K;exports.DashboardSummarySettingsDialog=Q;
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),o=require("react"),a=require("./index-DQCMUspd.js"),s=require("./switch-BPFzGTzF.js");function q(n={}){var k,P,A,E;const{authToken:c,tokenProps:t}=a.useSemaphorContext(),S=n.enabled??!0,u=(c==null?void 0:c.accessToken)??null,f=(t==null?void 0:t.apiServiceUrl)??null,[N,j]=o.useState(!1),[v,b]=o.useState(!1),[h,l]=o.useState(!1),[y,d]=o.useState(null),[p,w]=o.useState(null),T=p||{tz:((P=(k=t==null?void 0:t.params)==null?void 0:k.calendarContext)==null?void 0:P.tz)||null,weekStart:((E=(A=t==null?void 0:t.params)==null?void 0:A.calendarContext)==null?void 0:E.weekStart)??null},g=o.useCallback(async()=>{if(!(!S||!u||!f)){j(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const i=await m.json();w({tz:i.tz,weekStart:i.weekStart,source:i.source,isInherited:i.isInherited,userHasPrefs:i.userHasPrefs,inherited:i.inherited})}catch(m){const i=m instanceof Error?m.message:"Unknown error";d(i)}finally{j(!1)}}},[u,f,S]);o.useEffect(()=>{S&&g()},[S,g]);const I=o.useCallback(async m=>{if(!u||!f)return d("Not authenticated"),!1;b(!0),d(null);try{const i=await fetch(`${f}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify(m)});if(!i.ok){const x=await i.json().catch(()=>({}));throw new Error(x.error||"Failed to update preferences")}return await g(),!0}catch(i){const x=i instanceof Error?i.message:"Unknown error";return d(x),!1}finally{b(!1)}},[u,f,g]),C=o.useCallback(async()=>{if(!u||!f)return d("Not authenticated"),!1;l(!0),d(null);try{const m=await fetch(`${f}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${u}`}});if(!m.ok){const x=await m.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const i=await m.text();if(i)try{const x=JSON.parse(i);return w({tz:x.tz,weekStart:x.weekStart,source:x.source,isInherited:x.isInherited??!0,userHasPrefs:!1,inherited:x.inherited}),!0}catch{}return await g(),!0}catch(m){const i=m instanceof Error?m.message:"Unknown error";return d(i),!1}finally{l(!1)}},[u,f,g]);return{preferences:T,isLoading:N,isSaving:v,isClearing:h,error:y,updatePreferences:I,clearPreferences:C,refetch:g}}const D=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],$=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],B="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function X(){try{const n=Intl;if(n.supportedValuesOf)return n.supportedValuesOf("timeZone")}catch{}return D.map(n=>n.value)}function Z(n){switch(n){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function _(n){const c=D.find(t=>t.value===n);return c?c.label:n}function J(n){const c=$.find(t=>t.value===n);return c?c.label:String(n)}function K({open:n,onOpenChange:c}){var M,F,U;const{preferences:t,isLoading:S,isSaving:u,isClearing:f,updatePreferences:N,clearPreferences:j}=q({enabled:n}),v=t.tz||((M=t.inherited)==null?void 0:M.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,b=t.weekStart??((F=t.inherited)==null?void 0:F.weekStart)??1,[h,l]=o.useState(!t.userHasPrefs),[y,d]=o.useState(!1),[p,w]=o.useState(v),[T,g]=o.useState(b),[I,C]=o.useState(!1),k=o.useMemo(()=>X(),[]),P=o.useMemo(()=>k.filter(r=>!D.some(V=>V.value===r)),[k]),A=o.useMemo(()=>_(p),[p]),E=t.inherited?_(t.inherited.tz):"UTC",m=t.inherited?J(t.inherited.weekStart):"Monday",i=Z((U=t.inherited)==null?void 0:U.source);o.useEffect(()=>{if(!n){d(!1);return}y||(t.userHasPrefs!==void 0&&l(!t.userHasPrefs),w(v),g(b))},[n,y,t.userHasPrefs,v,b]);const x=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}h?await j()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again."):await N({tz:p,weekStart:T})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),c(!1)):a.ue.error("Failed to save preferences. Please try again.")},G=()=>{c(!1)},L=u||f,W=L||S;return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Calendar preferences"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Set your timezone and week-start for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(a.RadioGroup,{value:h?"defaults":"custom",onValueChange:r=>{d(!0),l(r==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",h&&"bg-muted/50"),onClick:()=>{d(!0),l(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",i," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[E,", week starts ",m]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:s.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!h&&"bg-muted/50"),onClick:()=>{d(!0),l(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:s.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",h&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Timezone"}),e.jsxs(s.Popover,{open:I,onOpenChange:C,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":I,className:"w-full justify-between text-[12px] font-normal",disabled:h,children:[e.jsx("span",{className:"truncate",children:A}),e.jsx(a.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:D.map(r=>e.jsxs(a.CommandItem,{value:`${r.value} ${r.label}`,onSelect:()=>{d(!0),w(r.value),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:r.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:r.value})]},r.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All timezones",children:P.map(r=>e.jsxs(a.CommandItem,{value:r,onSelect:()=>{d(!0),w(r),C(!1)},children:[e.jsx(s.Check,{className:s.cn("h-3.5 w-3.5",p===r?"opacity-100":"opacity-0")}),r]},r))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:B,children:"Week starts on"}),e.jsx(a.RadioGroup,{value:String(T),onValueChange:r=>{d(!0),g(Number(r))},className:"flex gap-4",disabled:h,children:$.map(r=>e.jsxs("label",{htmlFor:`week-start-${r.value}`,className:s.cn("flex cursor-pointer items-center gap-2 text-[13px]",h&&"cursor-not-allowed"),children:[e.jsx(a.RadioGroupItem,{value:String(r.value),id:`week-start-${r.value}`,disabled:h}),r.label]},r.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:G,disabled:L,children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:x,disabled:W,children:L?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})})}const z=6,O=1,R=20,H="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function Y(n){return Number.isNaN(n)?z:Math.min(R,Math.max(O,n))}function Q({open:n,onOpenChange:c,dashboard:t,onApply:S,disabled:u=!1}){const[f,N]=o.useState(!1),[j,v]=o.useState("top"),[b,h]=o.useState(String(z)),l=t.summary;o.useEffect(()=>{n&&(N((l==null?void 0:l.enabled)===!0),v((l==null?void 0:l.position)==="bottom"?"bottom":"top"),h(String((l==null?void 0:l.maxItems)??z)))},[n,l==null?void 0:l.enabled,l==null?void 0:l.position,l==null?void 0:l.maxItems]);const y=o.useMemo(()=>Y(Number.parseInt(b||`${z}`,10)),[b]),d=()=>{S({enabled:f,position:j,maxItems:y}),c(!1)};return e.jsx(a.Dialog,{open:n,onOpenChange:c,children:e.jsxs(a.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{className:"text-[15px]",children:"Summary Settings"}),e.jsx(a.DialogDescription,{className:"text-[13px] leading-5",children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-enabled",className:"text-[13px]",children:"Enable dashboard summary"}),e.jsx(s.Switch,{size:"xs",id:"dashboard-summary-enabled",checked:f,disabled:u,onCheckedChange:N})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-position",className:H,children:"Position"}),e.jsxs(s.Select,{value:j,disabled:u,onValueChange:p=>v(p),children:[e.jsx(s.SelectTrigger,{id:"dashboard-summary-position",size:"xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{htmlFor:"dashboard-summary-max-items",className:H,children:"Max items"}),e.jsx(s.Input,{size:"xs",id:"dashboard-summary-max-items",type:"number",min:O,max:R,disabled:u,value:b,onChange:p=>h(p.target.value),onBlur:()=>h(String(y))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),u&&e.jsx("p",{className:"text-[12px] text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",size:"xs",onClick:()=>c(!1),children:"Cancel"}),e.jsx(s.Button,{size:"xs",onClick:d,disabled:u,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=K;exports.DashboardSummarySettingsDialog=Q;
|