react-semaphor 0.1.175 → 0.1.177

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 (28) hide show
  1. package/dist/chunks/dashboard-controls-00cjSeD7.js +42 -0
  2. package/dist/chunks/dashboard-controls-C9IWIFfW.js +1624 -0
  3. package/dist/chunks/{dashboard-json-DddaSWpl.js → dashboard-json--ke9XK9p.js} +1 -1
  4. package/dist/chunks/{dashboard-json-CMYMYz8t.js → dashboard-json-BDjl-3ej.js} +1 -1
  5. package/dist/chunks/{edit-dashboard-visual-CYfGc778.js → edit-dashboard-visual-BBsC9feJ.js} +762 -726
  6. package/dist/chunks/{edit-dashboard-visual-DPKlhiyI.js → edit-dashboard-visual-BroCdmtP.js} +34 -34
  7. package/dist/chunks/{editor-action-buttons-DPK6j7ie.js → editor-action-buttons-CHoiNw7F.js} +2 -2
  8. package/dist/chunks/{editor-action-buttons-D2f078Q2.js → editor-action-buttons-JE9t84-4.js} +1 -1
  9. package/dist/chunks/{index-Ddo6owXU.js → index-CdfFCbJb.js} +199 -230
  10. package/dist/chunks/{index-nz5YKmTp.js → index-DZjcALSv.js} +16033 -16342
  11. package/dist/chunks/{resource-management-panel-CnlQHXZ9.js → resource-management-panel-C96ElLa5.js} +1 -1
  12. package/dist/chunks/{resource-management-panel-DpWhJzMn.js → resource-management-panel-DE8DnPSl.js} +3 -3
  13. package/dist/chunks/{schedule-dashboard-CA-u7Ov1.js → schedule-dashboard-BFa0Uljc.js} +3 -3
  14. package/dist/chunks/{schedule-dashboard-BL5CTGzo.js → schedule-dashboard-CzU0ziLB.js} +1 -1
  15. package/dist/chunks/{use-role-aware-display-preferences-BAbYQx23.js → use-role-aware-display-preferences-Dovp_VmV.js} +1 -1
  16. package/dist/chunks/{use-role-aware-display-preferences-CSacCN5X.js → use-role-aware-display-preferences-Rd1BhDG4.js} +1 -1
  17. package/dist/chunks/{use-visual-utils-DV14Lork.js → use-visual-utils-BkRr5LoD.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-Dt5WKeeY.js → use-visual-utils-Cnju2tnE.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 +4 -4
  23. package/dist/surfboard/index.cjs +1 -1
  24. package/dist/surfboard/index.js +1 -1
  25. package/dist/types/main.d.ts +6 -3
  26. package/package.json +2 -2
  27. package/dist/chunks/dashboard-controls-BF1ISsg_.js +0 -26
  28. package/dist/chunks/dashboard-controls-CQNvLMGb.js +0 -1509
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Ddo6owXU.js"),c=require("react"),de=require("./use-visual-utils-Dt5WKeeY.js"),pe=require("./use-role-aware-display-preferences-CSacCN5X.js");/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-CdfFCbJb.js"),c=require("react"),de=require("./use-visual-utils-Cnju2tnE.js"),pe=require("./use-role-aware-display-preferences-Rd1BhDG4.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,8 +1,8 @@
1
1
  import { jsx as e, jsxs as a, Fragment as ge } from "react/jsx-runtime";
2
- import { l as $e, u as me, n as Qe, aB as re, b9 as Xe, ba as Ze, c as X, bb as ke, aS as et, aT as tt, B as _, aU as st, aV as at, aW as W, bc as pe, L as oe, bd as nt, be as it, bf as rt, bg as ve, bh as De, bi as ot, bj as lt, K as dt, bk as ye, e as le, bl as Se, bm as Ve, bn as ct, _ as Ee, V as Le, bo as Ae, a_ as Te, a$ as Oe, b0 as Re, b2 as Pe, b3 as Ue, b4 as Ie, b5 as je, b6 as Me, bp as ut, bq as ht, br as Fe, bs as Be, bt as ze, bu as mt, bv as He, bw as pt, R as ne, aA as ft, bx as _e, by as gt, bz as Dt, aF as xt, aG as Nt, aH as bt, aI as wt, aJ as vt, aK as Ce, aL as fe, aO as Ct, bA as yt, bB as St, bC as Vt, bD as Et } from "./index-nz5YKmTp.js";
2
+ import { l as $e, u as me, n as Qe, aB as re, b9 as Xe, ba as Ze, c as X, bb as ke, aS as et, aT as tt, B as _, aU as st, aV as at, aW as W, bc as pe, L as oe, bd as nt, be as it, bf as rt, bg as ve, bh as De, bi as ot, bj as lt, K as dt, bk as ye, e as le, bl as Se, bm as Ve, bn as ct, _ as Ee, V as Le, bo as Ae, a_ as Te, a$ as Oe, b0 as Re, b2 as Pe, b3 as Ue, b4 as Ie, b5 as je, b6 as Me, bp as ut, bq as ht, br as Fe, bs as Be, bt as ze, bu as mt, bv as He, bw as pt, R as ne, aA as ft, bx as _e, by as gt, bz as Dt, aF as xt, aG as Nt, aH as bt, aI as wt, aJ as vt, aK as Ce, aL as fe, aO as Ct, bA as yt, bB as St, bC as Vt, bD as Et } from "./index-DZjcALSv.js";
3
3
  import Lt, { useRef as At, useEffect as ie, useState as x } from "react";
4
- import { a as Ke } from "./use-visual-utils-DV14Lork.js";
5
- import { u as Tt } from "./use-role-aware-display-preferences-BAbYQx23.js";
4
+ import { a as Ke } from "./use-visual-utils-BkRr5LoD.js";
5
+ import { u as Tt } from "./use-role-aware-display-preferences-Dovp_VmV.js";
6
6
  /**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
@@ -1,8 +1,8 @@
1
1
  import { jsx as e, jsxs as a, Fragment as F } from "react/jsx-runtime";
2
- import { l as _, aF as $, aG as q, aH as K, aI as X, aJ as Y, aK as T, aL as G, aM as J, aN as E, aO as Q, B as I, L as H, n as k, q as Z, u as g, aB as ee, o as R, aP as ae, aQ as O, t as y, R as se, aR as te, c as w, aS as B, aT as P, aU as L, aV as U, aW as z, m as de, aX as le, aY as ne, aZ as re, a_ as oe, a$ as ie, b0 as ce, b1 as he, b2 as ue, b3 as me, b4 as ve, b5 as pe, b6 as be, a5 as fe, K as ge, b7 as Ce, b8 as De } from "./index-nz5YKmTp.js";
3
- import { E as xe, V as Ae, a as Se, b as Ne, S as j, c as ye } from "./editor-action-buttons-DPK6j7ie.js";
2
+ import { l as _, aF as $, aG as q, aH as K, aI as X, aJ as Y, aK as T, aL as G, aM as J, aN as E, aO as Q, B as I, L as H, n as k, q as Z, u as g, aB as ee, o as R, aP as ae, aQ as O, t as y, R as se, aR as te, c as w, aS as B, aT as P, aU as L, aV as U, aW as z, m as de, aX as le, aY as ne, aZ as re, a_ as oe, a$ as ie, b0 as ce, b1 as he, b2 as ue, b3 as me, b4 as ve, b5 as pe, b6 as be, a5 as fe, K as ge, b7 as Ce, b8 as De } from "./index-DZjcALSv.js";
3
+ import { E as xe, V as Ae, a as Se, b as Ne, S as j, c as ye } from "./editor-action-buttons-CHoiNw7F.js";
4
4
  import we, { useState as D, useContext as Ie, useEffect as ke } from "react";
5
- import { a as W } from "./use-visual-utils-DV14Lork.js";
5
+ import { a as W } from "./use-visual-utils-BkRr5LoD.js";
6
6
  /**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
@@ -1,4 +1,4 @@
1
- "use strict";const s=require("react/jsx-runtime"),e=require("./index-Ddo6owXU.js"),C=require("./editor-action-buttons-D2f078Q2.js"),x=require("react"),y=require("./use-visual-utils-Dt5WKeeY.js");/**
1
+ "use strict";const s=require("react/jsx-runtime"),e=require("./index-CdfFCbJb.js"),C=require("./editor-action-buttons-JE9t84-4.js"),x=require("react"),y=require("./use-visual-utils-Cnju2tnE.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import { b as m, e as t, g as D, f as U, h as b, i as u, j as E, k as g } from "./index-nz5YKmTp.js";
1
+ import { b as m, e as t, g as D, f as U, h as b, i as u, j as E, k as g } from "./index-DZjcALSv.js";
2
2
  import { useMemo as i } from "react";
3
3
  function S() {
4
4
  const { displayPreferences: n, shouldShowElement: c } = m(), { currentUser: a, userContext: s } = t(), r = i(
@@ -1 +1 @@
1
- "use strict";const a=require("./index-Ddo6owXU.js"),n=require("react");function f(){const{displayPreferences:c,shouldShowElement:o}=a.useDisplayPreferences(),{currentUser:e,userContext:s}=a.useCurrentUserInfo(),i=n.useMemo(()=>a.getRoleBasedDisplayOverrides(e),[e]),t=n.useMemo(()=>r=>i&&i[r]!==void 0&&i[r]===!1?!1:o(r),[i,o,c]),p=n.useMemo(()=>{var r,d,l,u,h;return{canEdit:((r=s==null?void 0:s.permissions)==null?void 0:r.canEdit)??a.canUserEdit(e),canUseFilters:((d=s==null?void 0:s.permissions)==null?void 0:d.canEdit)??a.canUserUseFilters(e),canManageDashboards:((l=s==null?void 0:s.permissions)==null?void 0:l.canCreateDashboard)??a.canUserManageDashboards(e),canCreateDashboards:((u=s==null?void 0:s.permissions)==null?void 0:u.canCreateDashboard)??a.canUserCreateDashboards(e),canAccessVisuals:((h=s==null?void 0:s.permissions)==null?void 0:h.canEdit)??a.canUserAccessVisuals(e)}},[e,s]);return{displayPreferences:c,shouldShowElement:t,permissions:p,currentUser:e}}exports.useRoleAwareDisplayPreferences=f;
1
+ "use strict";const a=require("./index-CdfFCbJb.js"),n=require("react");function f(){const{displayPreferences:c,shouldShowElement:o}=a.useDisplayPreferences(),{currentUser:e,userContext:s}=a.useCurrentUserInfo(),i=n.useMemo(()=>a.getRoleBasedDisplayOverrides(e),[e]),t=n.useMemo(()=>r=>i&&i[r]!==void 0&&i[r]===!1?!1:o(r),[i,o,c]),p=n.useMemo(()=>{var r,d,l,u,h;return{canEdit:((r=s==null?void 0:s.permissions)==null?void 0:r.canEdit)??a.canUserEdit(e),canUseFilters:((d=s==null?void 0:s.permissions)==null?void 0:d.canEdit)??a.canUserUseFilters(e),canManageDashboards:((l=s==null?void 0:s.permissions)==null?void 0:l.canCreateDashboard)??a.canUserManageDashboards(e),canCreateDashboards:((u=s==null?void 0:s.permissions)==null?void 0:u.canCreateDashboard)??a.canUserCreateDashboards(e),canAccessVisuals:((h=s==null?void 0:s.permissions)==null?void 0:h.canEdit)??a.canUserAccessVisuals(e)}},[e,s]);return{displayPreferences:c,shouldShowElement:t,permissions:p,currentUser:e}}exports.useRoleAwareDisplayPreferences=f;
@@ -1,4 +1,4 @@
1
- import { az as G, aA as Y, p as J, q as K, aB as X, m as z, o as Z, u as v, aC as q, aD as ee, t as V, aE as te, n as f } from "./index-nz5YKmTp.js";
1
+ import { az as G, aA as Y, p as J, q as K, aB as X, m as z, o as Z, u as v, aC as q, aD as ee, t as V, aE as te, n as f } from "./index-DZjcALSv.js";
2
2
  import { useState as T, useEffect as re, useCallback as A } from "react";
3
3
  function se(e) {
4
4
  const o = e.toUpperCase().indexOf("WHERE"), t = e.toUpperCase().indexOf("GROUP BY"), r = e.toUpperCase().indexOf("LIMIT"), n = e.toUpperCase().indexOf("ORDER BY");
@@ -1 +1 @@
1
- "use strict";const s=require("./index-Ddo6owXU.js"),g=require("react");function H(e){const a=e.toUpperCase().indexOf("WHERE"),t=e.toUpperCase().indexOf("GROUP BY"),r=e.toUpperCase().indexOf("LIMIT"),c=e.toUpperCase().indexOf("ORDER BY");let d=e.length;if(c!==-1&&(d=c),r!==-1&&r<d&&(d=r),a!==-1){const i=e.substring(0,a),o=e.substring(a);return`${i} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const i=e.substring(0,t),o=e.substring(t);return`${i} {{ filters | where }} ${o}`}else{const i=e.substring(0,d),o=e.substring(d);return console.log("beforeClause",i),console.log("afterClause",o),o?`${i} {{ filters | where }} ${o}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,t]=g.useState(null),[r,c]=g.useState(null),d=s.useEnsureReactGlobals();return g.useEffect(()=>{if(!e||e.trim()===""){t(null),c(null);return}if(!d)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const h=await import(l);if(typeof h.useChartStore!="function")throw new Error("useChartStore is not a function");t(()=>h.useChartStore),c(null)}catch(o){const l=o instanceof Error?o.message:"Unknown error";console.error("Failed to load remote chart store:",l),c(l),t(null)}})()},[e,d]),a}function Q(e,a){if(e.length===0)return"";if(a){const t=e.find(r=>r.id===a);if(t){const r=t.tabTitle;if(r=="All__Header")return e[0].id;if(r&&r.endsWith("__Header")){const d=r.split("__")[0],i=e.find(o=>o.tabTitle===d);return i?i.id:e[0].id}return a}}return e[0].id}async function j(e,a,t,r){if(!a||!t)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",t],d=r.getQueryData(c);if(d)return console.log("Using cached visual data for:",t),{data:d,fromCache:!0};console.log("Fetching visual data from network for:",t);const i=s.ue.loading("Loading visual...",{position:"top-center"});try{const o=await fetch(`${e}/management/v1/visuals/${t}`,{headers:{Authorization:`Bearer ${a}`}});if(!o.ok)throw new Error("Failed to load visual");const l=await o.json();return r.setQueryData(c,l),s.ue.dismiss(i),{data:l,fromCache:!1}}catch(o){throw s.ue.dismiss(i),o}}function T(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function z(e,a){var d,i;const t=(e==null?void 0:e.frameObject)??((d=e==null?void 0:e.visual)==null?void 0:d.frameObject);if(!t)return!1;const r=T(t);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const c=(i=r.cards)==null?void 0:i.find(o=>o.id===r.activeCardId);return c?(s.setupEditorWithCard({...a,frame:r,card:c,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function G(){var C;const{setCardSql:e}=s.useEditorActions(),a=s.useEditorStore(n=>n.frame),t=s.useEditorStore(n=>n.card),r=s.useEditorStore(n=>n.isDevMode),c=B(((C=t.customCardPreferences)==null?void 0:C.url)||""),d=s.useEditorStore(n=>n.selectedSchemaName),i=s.useEditorStore(n=>n.selectedDatamodelId),o=s.useEditorStore(n=>n.selectedDatabaseName),l=s.useEditorStore(n=>n.selectedTableName),h=s.useEditorStore(n=>n.selectedConnectionId),m=s.useEditorStore(n=>n.isShowingVisual),S=t.sql;return{getUpdatedFrame:g.useCallback(()=>{var I;let n=S;S&&!S.includes("{{")&&(n=H(S),e(n));const w=(I=c==null?void 0:c.getState())==null?void 0:I.settings,v={...t,dataSource:t.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:i,lastSelectedDatabase:o,lastSelectedTable:l,connectionId:h,sql:r?n:void 0,python:r?t.python:void 0,config:r?void 0:t.config,customCfg:m?t.customCfg:null,preferences:t.preferences,...w&&{customCardPreferences:{...t.customCardPreferences,settings:w}}},E=a.cards.map(p=>p.id===t.id?v:p);return{...a,cards:E,activeCardId:Q(E,a.activeCardId)}},[t,a,r,m,d,i,o,l,h,e,c,S])}}function Y(){const{authToken:e,tokenProps:a}=s.useSemaphorContext(),t=s.useQueryClient(),r=s.useSelectedVisual(),{selectVisual:c}=s.useManagementActions(),{setFrame:d,setCard:i,setIsDevMode:o,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:S,setSelectedConnectionId:V,setSelectedDatabaseName:C,setSelectedSchemaName:n,setSelectedTableName:w,setSelectedDatamodelId:v,setFilterValues:E,setApplyFilters:I}=s.useEditorActions(),{setIsDashboardEditing:p,setIsVisualEditing:$,setSelectedFrameId:D,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=s.useDashboardActions(),y=s.useDashboardStore(u=>u.selectedSheetId),O=s.useDashboardStore(u=>u.selectedFrameId),x=s.useDashboardStore(u=>u.dashboard),W=s.useDashboardStore(u=>u.filterValues),F=s.useVisualById((r==null?void 0:r.id)||"",{enabled:!!(r!=null&&r.id)&&!!(e!=null&&e.accessToken)}),k=g.useCallback(async u=>{try{c(u),A();const{data:b,fromCache:f}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t);if(!z(b,{setFrame:d,setCard:i,setIsDevMode:o,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:S,setSelectedConnectionId:V,setSelectedDatabaseName:C,setSelectedSchemaName:n,setSelectedTableName:w,setSelectedDatamodelId:v,setFilterValues:E,setApplyFilters:I,setIsDashboardEditing:p,setIsVisualEditing:$,dashboard:x,selectedSheetId:y,selectedFrameId:O,filterValues:W}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:f}}catch(b){return console.error("Error editing visual:",b),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,t,c,d,i,p,$,o,l,h,m,S,V,C,n,w,v,E,I,A,x,y,O,W]),_=g.useCallback(async u=>{var b;try{if(c(u),!y)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:f,fromCache:M}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t),L=(f==null?void 0:f.frameObject)??((b=f==null?void 0:f.visual)==null?void 0:b.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const U=T(L);if(!(U!=null&&U.cards)||U.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...s.cloneFrameWithNewIds(U),visualId:u.id};return N(y,P,"end"),p(!0),D(P.id),R(!1),{success:!0,fromCache:M}}catch(f){return console.error("Error adding visual:",f),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,t,c,y,N,p,D,R]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:k,handleAddLibraryVisual:_,getUpdatedFrame:G().getUpdatedFrame,refetch:F.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=Y;
1
+ "use strict";const s=require("./index-CdfFCbJb.js"),g=require("react");function H(e){const a=e.toUpperCase().indexOf("WHERE"),t=e.toUpperCase().indexOf("GROUP BY"),r=e.toUpperCase().indexOf("LIMIT"),c=e.toUpperCase().indexOf("ORDER BY");let d=e.length;if(c!==-1&&(d=c),r!==-1&&r<d&&(d=r),a!==-1){const i=e.substring(0,a),o=e.substring(a);return`${i} {{ filters | where }} AND ${o.substring(6)}`}else if(t!==-1){const i=e.substring(0,t),o=e.substring(t);return`${i} {{ filters | where }} ${o}`}else{const i=e.substring(0,d),o=e.substring(d);return console.log("beforeClause",i),console.log("afterClause",o),o?`${i} {{ filters | where }} ${o}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,t]=g.useState(null),[r,c]=g.useState(null),d=s.useEnsureReactGlobals();return g.useEffect(()=>{if(!e||e.trim()===""){t(null),c(null);return}if(!d)return;(async()=>{try{if(!e.startsWith("http://")&&!e.startsWith("https://"))throw new Error(`Invalid URL format: ${e}`);try{new URL(e)}catch{throw new Error(`Invalid URL: ${e}`)}const l=`${e.endsWith("/")?e:`${e}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const h=await import(l);if(typeof h.useChartStore!="function")throw new Error("useChartStore is not a function");t(()=>h.useChartStore),c(null)}catch(o){const l=o instanceof Error?o.message:"Unknown error";console.error("Failed to load remote chart store:",l),c(l),t(null)}})()},[e,d]),a}function Q(e,a){if(e.length===0)return"";if(a){const t=e.find(r=>r.id===a);if(t){const r=t.tabTitle;if(r=="All__Header")return e[0].id;if(r&&r.endsWith("__Header")){const d=r.split("__")[0],i=e.find(o=>o.tabTitle===d);return i?i.id:e[0].id}return a}}return e[0].id}async function j(e,a,t,r){if(!a||!t)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",t],d=r.getQueryData(c);if(d)return console.log("Using cached visual data for:",t),{data:d,fromCache:!0};console.log("Fetching visual data from network for:",t);const i=s.ue.loading("Loading visual...",{position:"top-center"});try{const o=await fetch(`${e}/management/v1/visuals/${t}`,{headers:{Authorization:`Bearer ${a}`}});if(!o.ok)throw new Error("Failed to load visual");const l=await o.json();return r.setQueryData(c,l),s.ue.dismiss(i),{data:l,fromCache:!1}}catch(o){throw s.ue.dismiss(i),o}}function T(e){if(typeof e=="string")return JSON.parse(e);if(typeof e=="object")return e;throw new Error("Invalid frame object format")}function z(e,a){var d,i;const t=(e==null?void 0:e.frameObject)??((d=e==null?void 0:e.visual)==null?void 0:d.frameObject);if(!t)return!1;const r=T(t);if(!(r!=null&&r.cards)||r.cards.length===0)return!1;const c=(i=r.cards)==null?void 0:i.find(o=>o.id===r.activeCardId);return c?(s.setupEditorWithCard({...a,frame:r,card:c,visualId:(e==null?void 0:e.id)||r.visualId}),!0):!1}function G(){var C;const{setCardSql:e}=s.useEditorActions(),a=s.useEditorStore(n=>n.frame),t=s.useEditorStore(n=>n.card),r=s.useEditorStore(n=>n.isDevMode),c=B(((C=t.customCardPreferences)==null?void 0:C.url)||""),d=s.useEditorStore(n=>n.selectedSchemaName),i=s.useEditorStore(n=>n.selectedDatamodelId),o=s.useEditorStore(n=>n.selectedDatabaseName),l=s.useEditorStore(n=>n.selectedTableName),h=s.useEditorStore(n=>n.selectedConnectionId),m=s.useEditorStore(n=>n.isShowingVisual),S=t.sql;return{getUpdatedFrame:g.useCallback(()=>{var I;let n=S;S&&!S.includes("{{")&&(n=H(S),e(n));const w=(I=c==null?void 0:c.getState())==null?void 0:I.settings,v={...t,dataSource:t.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:i,lastSelectedDatabase:o,lastSelectedTable:l,connectionId:h,sql:r?n:void 0,python:r?t.python:void 0,config:r?void 0:t.config,customCfg:m?t.customCfg:null,preferences:t.preferences,...w&&{customCardPreferences:{...t.customCardPreferences,settings:w}}},E=a.cards.map(p=>p.id===t.id?v:p);return{...a,cards:E,activeCardId:Q(E,a.activeCardId)}},[t,a,r,m,d,i,o,l,h,e,c,S])}}function Y(){const{authToken:e,tokenProps:a}=s.useSemaphorContext(),t=s.useQueryClient(),r=s.useSelectedVisual(),{selectVisual:c}=s.useManagementActions(),{setFrame:d,setCard:i,setIsDevMode:o,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:S,setSelectedConnectionId:V,setSelectedDatabaseName:C,setSelectedSchemaName:n,setSelectedTableName:w,setSelectedDatamodelId:v,setFilterValues:E,setApplyFilters:I}=s.useEditorActions(),{setIsDashboardEditing:p,setIsVisualEditing:$,setSelectedFrameId:D,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=s.useDashboardActions(),y=s.useDashboardStore(u=>u.selectedSheetId),O=s.useDashboardStore(u=>u.selectedFrameId),x=s.useDashboardStore(u=>u.dashboard),W=s.useDashboardStore(u=>u.filterValues),F=s.useVisualById((r==null?void 0:r.id)||"",{enabled:!!(r!=null&&r.id)&&!!(e!=null&&e.accessToken)}),k=g.useCallback(async u=>{try{c(u),A();const{data:b,fromCache:f}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t);if(!z(b,{setFrame:d,setCard:i,setIsDevMode:o,initializeModeDrafts:l,setActiveTabCardId:h,updateDataSource:m,setQueryResultColumns:S,setSelectedConnectionId:V,setSelectedDatabaseName:C,setSelectedSchemaName:n,setSelectedTableName:w,setSelectedDatamodelId:v,setFilterValues:E,setApplyFilters:I,setIsDashboardEditing:p,setIsVisualEditing:$,dashboard:x,selectedSheetId:y,selectedFrameId:O,filterValues:W}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:f}}catch(b){return console.error("Error editing visual:",b),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,t,c,d,i,p,$,o,l,h,m,S,V,C,n,w,v,E,I,A,x,y,O,W]),_=g.useCallback(async u=>{var b;try{if(c(u),!y)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:f,fromCache:M}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,t),L=(f==null?void 0:f.frameObject)??((b=f==null?void 0:f.visual)==null?void 0:b.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const U=T(L);if(!(U!=null&&U.cards)||U.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...s.cloneFrameWithNewIds(U),visualId:u.id};return N(y,P,"end"),p(!0),D(P.id),R(!1),{success:!0,fromCache:M}}catch(f){return console.error("Error adding visual:",f),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,t,c,y,N,p,D,R]);return{visual:F.data,isLoading:F.isLoading,isError:F.isError,error:F.error,handleEditLibraryVisual:k,handleAddLibraryVisual:_,getUpdatedFrame:G().getUpdatedFrame,refetch:F.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=Y;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-Ddo6owXU.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-CdfFCbJb.js"),r=require("../types/index.cjs");exports.Dashboard=e.Dashboard;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { D as a } from "../chunks/index-nz5YKmTp.js";
1
+ import { D as a } from "../chunks/index-DZjcALSv.js";
2
2
  import { EMPTY_SELECTION as e } from "../types/index.js";
3
3
  export {
4
4
  a as Dashboard,
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-Ddo6owXU.js"),v=require("./types/index.cjs"),a=require("react/jsx-runtime"),b=require("react"),j=require("./chunks/resource-management-panel-CnlQHXZ9.js"),h=require("./chunks/schedule-dashboard-BL5CTGzo.js");require("react-dom");function P(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(o,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return o.default=r,Object.freeze(o)}const m=P(b);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-CdfFCbJb.js"),v=require("./types/index.cjs"),a=require("react/jsx-runtime"),b=require("react"),j=require("./chunks/resource-management-panel-C96ElLa5.js"),h=require("./chunks/schedule-dashboard-CzU0ziLB.js");require("react-dom");function P(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const s in r)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(o,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return o.default=r,Object.freeze(o)}const m=P(b);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { l as w, E as T, F as N, S as _, v as P, U as M, w as A, x as I, u as R, y as D, z as k, P as F, A as L, B as V, c as v, G as O, H as B, I as H, J as U, K as W, M as j, N as q, O as z, Q, C as G } from "./chunks/index-nz5YKmTp.js";
2
- import { aa as ia, ab as da, D as la, a8 as ca, a2 as ua, af as ha, V as pa, Z as ma, Z as fa, _ as Ca, a as va, a5 as ya, ay as ba, am as Da, a7 as Ta, a3 as ga, a4 as Ea, ag as Sa, ao as xa, an as wa, ar as Na, as as _a, al as Pa, a6 as Ma, ak as Aa, ad as Ia, ae as Ra, ac as ka, ap as Fa, aj as La, ai as Va, ah as Oa, at as Ba, aq as Ha, a1 as Ua, av as Wa, ax as ja, aw as qa, o as za, a0 as Qa, T as Ga, a9 as Ka, W as Ya, m as $a, au as Za, n as Ja, R as Xa, $ as ae, Y as ee } from "./chunks/index-nz5YKmTp.js";
1
+ import { l as w, E as T, F as N, S as _, v as P, U as M, w as A, x as I, u as R, y as D, z as k, P as F, A as L, B as V, c as v, G as O, H as B, I as H, J as U, K as W, M as j, N as q, O as z, Q, C as G } from "./chunks/index-DZjcALSv.js";
2
+ import { aa as ia, ab as da, D as la, a8 as ca, a2 as ua, af as ha, V as pa, Z as ma, Z as fa, _ as Ca, a as va, a5 as ya, ay as ba, am as Da, a7 as Ta, a3 as ga, a4 as Ea, ag as Sa, ao as xa, an as wa, ar as Na, as as _a, al as Pa, a6 as Ma, ak as Aa, ad as Ia, ae as Ra, ac as ka, ap as Fa, aj as La, ai as Va, ah as Oa, at as Ba, aq as Ha, a1 as Ua, av as Wa, ax as ja, aw as qa, o as za, a0 as Qa, T as Ga, a9 as Ka, W as Ya, m as $a, au as Za, n as Ja, R as Xa, $ as ae, Y as ee } from "./chunks/index-DZjcALSv.js";
3
3
  import { EMPTY_SELECTION as oe } from "./types/index.js";
4
4
  import { jsx as a, jsxs as i } from "react/jsx-runtime";
5
5
  import * as p from "react";
6
6
  import { useMemo as K, useEffect as Y } from "react";
7
- import { ResourceManagementPanel as ne } from "./chunks/resource-management-panel-DpWhJzMn.js";
8
- import { A as ie, S as de, U as le, V as ce, u as ue } from "./chunks/schedule-dashboard-CA-u7Ov1.js";
7
+ import { ResourceManagementPanel as ne } from "./chunks/resource-management-panel-DE8DnPSl.js";
8
+ import { A as ie, S as de, U as le, V as ce, u as ue } from "./chunks/schedule-dashboard-BFa0Uljc.js";
9
9
  import "react-dom";
10
10
  /**
11
11
  * @license lucide-react v0.453.0 - ISC
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-Ddo6owXU.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-CdfFCbJb.js"),r=require("../types/index.cjs");exports.Surfboard=e.DashboardPlus;exports.EMPTY_SELECTION=r.EMPTY_SELECTION;
@@ -1,4 +1,4 @@
1
- import { a } from "../chunks/index-nz5YKmTp.js";
1
+ import { a } from "../chunks/index-DZjcALSv.js";
2
2
  import { EMPTY_SELECTION as E } from "../types/index.js";
3
3
  export {
4
4
  E as EMPTY_SELECTION,
@@ -3150,7 +3150,8 @@ export declare function useDashboardQuery(): {
3150
3150
  };
3151
3151
 
3152
3152
  export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardStore>, "setState"> & {
3153
- setState(nextStateOrUpdater: DashboardStore | Partial<DashboardStore> | ((state: WritableDraft<DashboardStore>) => void), shouldReplace?: boolean | undefined): void;
3153
+ setState(nextStateOrUpdater: DashboardStore | Partial<DashboardStore> | ((state: WritableDraft<DashboardStore>) => void), shouldReplace?: false): void;
3154
+ setState(nextStateOrUpdater: DashboardStore | ((state: WritableDraft<DashboardStore>) => void), shouldReplace: true): void;
3154
3155
  }>;
3155
3156
 
3156
3157
  export declare function useDataColumns(token?: AuthToken): {
@@ -3228,7 +3229,8 @@ export declare function useEditorAside(token?: AuthToken, _connectionQueryKey?:
3228
3229
  };
3229
3230
 
3230
3231
  export declare const useEditorStore: UseBoundStore<Omit<StoreApi<EditorStore>, "setState"> & {
3231
- setState(nextStateOrUpdater: EditorStore | Partial<EditorStore> | ((state: WritableDraft<EditorStore>) => void), shouldReplace?: boolean | undefined): void;
3232
+ setState(nextStateOrUpdater: EditorStore | Partial<EditorStore> | ((state: WritableDraft<EditorStore>) => void), shouldReplace?: false): void;
3233
+ setState(nextStateOrUpdater: EditorStore | ((state: WritableDraft<EditorStore>) => void), shouldReplace: true): void;
3232
3234
  }>;
3233
3235
 
3234
3236
  /**
@@ -3252,7 +3254,8 @@ setState(nextStateOrUpdater: EditorStore | Partial<EditorStore> | ((state: Writa
3252
3254
  export declare function useExposePrintState(isPdfRender: boolean, printState: PrintState | null): void;
3253
3255
 
3254
3256
  export declare const useManagementStore: UseBoundStore<Omit<StoreApi<ManagementStore>, "setState"> & {
3255
- setState(nextStateOrUpdater: ManagementStore | Partial<ManagementStore> | ((state: WritableDraft<ManagementStore>) => void), shouldReplace?: boolean | undefined): void;
3257
+ setState(nextStateOrUpdater: ManagementStore | Partial<ManagementStore> | ((state: WritableDraft<ManagementStore>) => void), shouldReplace?: false): void;
3258
+ setState(nextStateOrUpdater: ManagementStore | ((state: WritableDraft<ManagementStore>) => void), shouldReplace: true): void;
3256
3259
  }>;
3257
3260
 
3258
3261
  /**
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.175",
8
+ "version": "0.1.177",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -129,7 +129,7 @@
129
129
  "tailwind-merge": "^2.1.0",
130
130
  "tailwindcss-animate": "^1.0.7",
131
131
  "uuid": "^9.0.1",
132
- "zustand": "^4.4.7"
132
+ "zustand": "^5.0.9"
133
133
  },
134
134
  "peerDependencies": {
135
135
  "react": "^18.0.0 || ^19.0.0",
@@ -1,26 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Ddo6owXU.js"),f=require("react");require("react-dom");const B=require("./schedule-dashboard-BL5CTGzo.js"),_e=require("./use-role-aware-display-preferences-CSacCN5X.js"),pe=require("./editor-action-buttons-D2f078Q2.js");function ze(t){const n=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(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const w=ze(f);/**
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 Qe=s.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 He=s.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 Ve=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
17
- * @license lucide-react v0.453.0 - ISC
18
- *
19
- * This source code is licensed under the ISC license.
20
- * See the LICENSE file in the root directory of this source tree.
21
- */const Ke=s.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
22
- * @license lucide-react v0.453.0 - ISC
23
- *
24
- * This source code is licensed under the ISC license.
25
- * See the LICENSE file in the root directory of this source tree.
26
- */const Je=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 We=s.requireShim();function Xe(){const{setTheme:t}=s.useTheme(),n=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(Je,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ve,{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"),n("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),n("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),n("system")},children:"System"})]})]})}async function Ye(t,n,a,r,l){if(!l)return null;const i=JSON.stringify(a),c=`${t}/v1/lens`;return await s.postRequest(c,l,{name:n,template:i,filterValues:r,operation:"create"})}async function se(t,n,a){if(!a)return null;const{id:r,template:l,filterValues:i,isDefault:c,shared:u}=n,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:l,filterValues:i,isDefault:c,shared:u,operation:"update"})}async function Ze(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function es(){const[t,n]=f.useState(""),[a,r]=f.useState(!1),l=s.useDashboardStore(N=>N.lenses),{setLenses:i,setSelectedLensId:c}=s.useDashboardActions(),[u,p]=f.useState(!1),[g,d]=f.useState(!1),m=s.useDashboardStore(N=>N.dashboard),x=s.useDashboardStore(N=>N.filterValues),{authToken:j,tokenProps:v}=s.useSemaphorContext();async function b(){p(!0);const N=await Ye(v.apiServiceUrl,t,m,x,j==null?void 0:j.accessToken);N&&(i([...l||[],N]),c(N.id),d(!1)),p(!1)}return e.jsxs(s.Dialog,{open:g,onOpenChange:d,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$1,{value:t,onChange:N=>{n(N.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:b,disabled:u,children:u?"Creating...":"Add"})})]})]})}function ss(){const[t,n]=f.useState(!1),a=s.useDashboardStore(m=>m.lenses),r=s.useDashboardStore(m=>m.selectedLensId),{setLenses:l,setSelectedLensId:i}=s.useDashboardActions(),{authToken:c,tokenProps:u}=s.useSemaphorContext();async function p(m){i(m)}async function g(m){if(await Ze(u.apiServiceUrl,m,c==null?void 0:c.accessToken)){const j=a==null?void 0:a.filter(v=>v.id!==m);l(j||[]),i("original")}}async function d(m){const x=a==null?void 0:a.map(b=>b.id===m.id?{...b,isDefault:!m.isDefault}:{...b,isDefault:!1});l(x||[]);const j={...m,isDefault:!m.isDefault};await se(u.apiServiceUrl,j,c==null?void 0:c.accessToken);const v=a==null?void 0:a.find(b=>b.isDefault);if(v&&v.id!==m.id){const b={...v,isDefault:!1};await se(u.apiServiceUrl,b,c==null?void 0:c.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Qe,{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(m=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[e.jsx("p",{children:m.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:x=>{x.preventDefault(),d(m)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:x=>{x.preventDefault(),g(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})]})}const ts=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,n,a)},as=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`,l=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${n}`}});if(!l.ok){const i=await l.text();throw new Error(i||"Failed to delete group")}},rs=async(t,n,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,n,r)},ns=async(t,n,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`,i=await fetch(l,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!i.ok){const c=await i.text();throw new Error(c||"Failed to remove group members")}};function os(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>ts(n.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:r.message})}})}function is(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>as(n.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:r.message})}})}function ls(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>rs(n.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:r.message})}})}function cs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>ns(n.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:r.message})}})}function ds({onSuccess:t,tenantId:n,isTenantUser:a}){const[r,l]=f.useState(""),[i,c]=f.useState(""),[u,p]=f.useState({}),g=os(),d=()=>{const x={};return r.trim()?r.length<3?x.name="Group name must be at least 3 characters":r.length>50&&(x.name="Group name must be less than 50 characters"):x.name="Group name is required",i&&i.length>200&&(x.description="Description must be less than 200 characters"),p(x),Object.keys(x).length===0},m=async x=>{if(x.preventDefault(),!d())return;const j={name:r.trim(),description:i.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&n?{tenantId:n}:{}};try{await g.mutateAsync(j),l(""),c(""),p({}),t()}catch(v){console.error("Failed to create group:",v)}};return e.jsxs("form",{onSubmit:m,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$1,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:x=>{l(x.target.value),u.name&&p(j=>({...j,name:""}))},className:u.name?"border-destructive":"",disabled:g.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:i,onChange:x=>{c(x.target.value),u.description&&p(j=>({...j,description:""}))},className:u.description?"border-destructive":"",disabled:g.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:[i.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(""),c(""),p({})},disabled:g.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:g.isPending||!r.trim(),children:g.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 us(t,n=[]){let a=[];function r(i,c){const u=w.createContext(c);u.displayName=i+"Context";const p=a.length;a=[...a,c];const g=m=>{var T;const{scope:x,children:j,...v}=m,b=((T=x==null?void 0:x[t])==null?void 0:T[p])||u,N=w.useMemo(()=>v,Object.values(v));return e.jsx(b.Provider,{value:N,children:j})};g.displayName=i+"Provider";function d(m,x){var b;const j=((b=x==null?void 0:x[t])==null?void 0:b[p])||u,v=w.useContext(j);if(v)return v;if(c!==void 0)return c;throw new Error(`\`${m}\` must be used within \`${i}\``)}return[g,d]}const l=()=>{const i=a.map(c=>w.createContext(c));return function(u){const p=(u==null?void 0:u[t])||i;return w.useMemo(()=>({[`__scope${t}`]:{...u,[t]:p}}),[u,p])}};return l.scopeName=t,[r,ms(l,...n)]}function ms(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(i){const c=r.reduce((u,{useScope:p,scopeName:g})=>{const m=p(i)[`__scope${g}`];return{...u,...m}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:c}),[c])}};return a.scopeName=n.scopeName,a}var hs=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],te=hs.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=w.forwardRef((l,i)=>{const{asChild:c,...u}=l,p=c?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...u,ref:i})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function ps(){return We.useSyncExternalStore(xs,()=>!0,()=>!1)}function xs(){return()=>{}}var ae="Avatar",[gs]=us(ae),[fs,ge]=gs(ae),fe=w.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[l,i]=w.useState("idle");return e.jsx(fs,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:i,children:e.jsx(te.span,{...r,ref:n})})});fe.displayName=ae;var je="AvatarImage",ve=w.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...i}=t,c=ge(je,a),u=js(r,i),p=s.useCallbackRef(g=>{l(g),c.onImageLoadingStatusChange(g)});return s.useLayoutEffect2(()=>{u!=="idle"&&p(u)},[u,p]),u==="loaded"?e.jsx(te.img,{...i,ref:n,src:r}):null});ve.displayName=je;var be="AvatarFallback",ye=w.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,i=ge(be,a),[c,u]=w.useState(r===void 0);return w.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(p)}},[r]),c&&i.imageLoadingStatus!=="loaded"?e.jsx(te.span,{...l,ref:n}):null});ye.displayName=be;function xe(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function js(t,{referrerPolicy:n,crossOrigin:a}){const r=ps(),l=w.useRef(null),i=r?(l.current||(l.current=new window.Image),l.current):null,[c,u]=w.useState(()=>xe(i,t));return s.useLayoutEffect2(()=>{u(xe(i,t))},[i,t]),s.useLayoutEffect2(()=>{const p=m=>()=>{u(m)};if(!i)return;const g=p("loaded"),d=p("error");return i.addEventListener("load",g),i.addEventListener("error",d),n&&(i.referrerPolicy=n),typeof a=="string"&&(i.crossOrigin=a),()=>{i.removeEventListener("load",g),i.removeEventListener("error",d)}},[i,a,n]),c}var Ne=fe,Se=ve,De=ye;const re=w.forwardRef(({className:t,...n},a)=>e.jsx(Ne,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));re.displayName=Ne.displayName;const vs=w.forwardRef(({className:t,...n},a)=>e.jsx(Se,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));vs.displayName=Se.displayName;const ne=w.forwardRef(({className:t,...n},a)=>e.jsx(De,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));ne.displayName=De.displayName;function bs({open:t,onOpenChange:n,group:a,onUpdate:r}){const[l,i]=f.useState("members"),[c,u]=f.useState(""),[p,g]=f.useState([]),[d,m]=f.useState([]),{data:x,isLoading:j,refetch:v}=s.useGroupMembers(a.id),b=a.type==="TENANT_GROUP"?"tenant":"organization",{users:N,isLoading:T}=s.useUnifiedUsers({type:b,tenantId:a.tenantId||void 0,active:!0,limit:100}),P=ls(),k=cs(),C=(x==null?void 0:x.members)||[],I=f.useMemo(()=>new Set(C.map(h=>h.userId)),[C]),L=f.useMemo(()=>N.filter(h=>!I.has(h.id)),[N,I]),F=f.useMemo(()=>{if(!c)return L;const h=c.toLowerCase();return L.filter(D=>{var M,E;return((M=D.name)==null?void 0:M.toLowerCase().includes(h))||((E=D.email)==null?void 0:E.toLowerCase().includes(h))})},[L,c]),y=f.useMemo(()=>{if(!c)return C;const h=c.toLowerCase();return C.filter(D=>{var M,E,$,_;return((E=(M=D.user)==null?void 0:M.name)==null?void 0:E.toLowerCase().includes(h))||((_=($=D.user)==null?void 0:$.email)==null?void 0:_.toLowerCase().includes(h))})},[C,c]),R=async()=>{if(p.length!==0)try{await P.mutateAsync({groupId:a.id,data:{userIds:p,userType:b==="tenant"?"tenant":"org"}}),g([]),i("members"),v(),r==null||r()}catch(h){console.error("Failed to add members:",h)}},K=async()=>{if(d.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:d}}),m([]),v(),r==null||r()}catch(h){console.error("Failed to remove members:",h)}},J=h=>{g(D=>D.includes(h)?D.filter(M=>M!==h):[...D,h])},S=h=>{m(D=>D.includes(h)?D.filter(M=>M!==h):[...D,h])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:a.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[C.length," ",C.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:h=>{i(h),u(""),m([])},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$1,{placeholder:"Search members...",value:c,onChange:h=>u(h.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:j?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(h=>e.jsx(s.Skeleton,{className:"h-16 w-full"},h))}):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:c?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:c?"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(h=>e.jsx(ys,{member:h,selected:d.includes(h.userId),onToggle:()=>S(h.userId)},h.id))})}),d.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:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:K,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$1,{placeholder:"Search users to add...",value:c,onChange:h=>u(h.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:T?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(h=>e.jsx(s.Skeleton,{className:"h-16 w-full"},h))}):F.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:c?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:F.map(h=>e.jsx(Ns,{user:h,selected:p.includes(h.id),onToggle:()=>J(h.id)},h.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:R,disabled:P.isPending,children:P.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 ys({member:t,selected:n,onToggle:a}){var l,i,c,u;const r=((i=(l=t.user)==null?void 0:l.name)==null?void 0:i.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:n}),e.jsx(re,{className:"h-8 w-8",children:e.jsx(ne,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((c=t.user)==null?void 0:c.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(u=t.user)==null?void 0:u.email})]})]})}function Ns({user:t,selected:n,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(i=>i[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:n}),e.jsx(re,{className:"h-8 w-8",children:e.jsx(ne,{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 Ss({open:t,onOpenChange:n}){const[a,r]=f.useState("groups"),[l,i]=f.useState(""),[c,u]=f.useState(null),[p,g]=f.useState(!1),[d,m]=f.useState(null),{tokenProps:x}=s.useSemaphorContext(),{currentUser:j}=s.useCurrentUserInfo(),v=is(),b=(j==null?void 0:j.type)==="tenant",N=x==null?void 0:x.tenantId,{groups:T,isLoading:P,refetch:k}=s.useGroups({type:b?"TENANT_GROUP":"all",tenantId:b?N:void 0,includeMembers:!1}),C=T.filter(y=>{var R;return y.name.toLowerCase().includes(l.toLowerCase())||((R=y.description)==null?void 0:R.toLowerCase().includes(l.toLowerCase()))}),I=async()=>{if(d)try{await v.mutateAsync(d.id),m(null),k()}catch(y){console.error("Failed to delete group:",y)}},L=y=>{u(y),g(!0)},F=()=>{r("groups"),k()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,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$1,{placeholder:"Search groups...",value:l,onChange:y=>i(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:P?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):C.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:C.map(y=>e.jsx(Ds,{group:y,onManageMembers:()=>L(y),onDelete:()=>m(y),currentUserId:j==null?void 0:j.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(ds,{onSuccess:F,tenantId:N,isTenantUser:b})})]})]})}),c&&e.jsx(bs,{open:p,onOpenChange:g,group:c,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>m(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 "',d==null?void 0:d.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:I,disabled:v.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function Ds({group:t,onManageMembers:n,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:n,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 ws(){var ue,me,he;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=_e.useRoleAwareDisplayPreferences(),i=s.useHasDashboardId(),{isLoading:c}=s.useDashboardQuery();s.useDashboardStore(o=>o.theme);const u=s.useDashboardStore(o=>o.lenses),p=s.useDashboardStore(o=>o.selectedLensId),g=u==null?void 0:u.find(o=>o.id===p),d=s.useDashboardStore(o=>o.dashboard);s.useDashboardStore(o=>o.selectedSheetId);const m=s.useDashboardStore(o=>o.isDashboardEditing),{setDashboardTitle:x}=s.useDashboardStore(o=>o.actions),[j,v]=f.useState(!1),[b,N]=f.useState(!1),[T,P]=f.useState(!1),[k,C]=f.useState(!1),[I,L]=f.useState(null),[F,y]=f.useState(!1),R=s.useDashboardStore(o=>o.isDashboardPanelOpen),K=s.useDashboardStore(o=>o.actions.setIsDashboardPanelOpen),J=s.useDashboardStore(o=>o.filterValues),S=s.useDashboardStore(o=>o.isVisualEditing);s.useEditorStore(o=>o.card);const h=s.useManagementStore(o=>o.selectedDashboard),D=s.useManagementStore(o=>o.initialDashboard);s.useManagementStore(o=>o.selectedVisual),s.useDashboardStore(o=>o.selectedFrameId),s.useEditorStore(o=>o.frame);const M=h?(me=h==null?void 0:h.permissions)==null?void 0:me.canEdit:(ue=D==null?void 0:D.permissions)==null?void 0:ue.canEdit,E=s.useDashboardStore(o=>o.showFilters),$=s.useAssistantLayoutStore(o=>o.setPanelOpen),_=s.useDashboardStore(o=>o.showDashboardJSON),W=s.useDashboardStore(o=>o.onSaveFunction),we=s.useDashboardStore(o=>o.actions.setShowFilters),{setIsDashboardEditing:oe,setShowDashboardJSON:ie}=s.useDashboardStore(o=>o.actions),{setInitialDashboard:le,clearSelectedDashboard:Ce}=s.useManagementStore(o=>o.actions),{resources:z}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:Me}=s.useCurrentUserInfo(),Ae=s.canUserManageGroups(Me),O=h||D,ce=O?{id:O.id,title:(d==null?void 0:d.title)||O.title||"Dashboard"}:null,{handleAddNewFrame:Le}=s.useAddNewFrame(),[U,X]=f.useState(!1),[ke,Q]=f.useState(!1),H=s.useUpdateResource(s.ResourceType.DASHBOARD),[G,Y]=f.useState(null),Ie=async(o,A)=>{if(!(d!=null&&d.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:d.id,newTitle:o,previousTitle:A}),H.mutate({resourceId:d.id,data:{title:o}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:q=>{console.error("Failed to update dashboard title:",q),s.ue.error("Failed to update dashboard title"),x(A)}})};f.useEffect(()=>{if(z&&z.length>0){const o=d==null?void 0:d.id;if(o){const A=z.find(q=>q.id===o);A&&le(A)}}},[z,d==null?void 0:d.id,le]);const V=n.orgUserId||n.tenantId,Te=m&&!S&&V&&M,{setDashboard:Pe}=s.useDashboardStore(o=>o.actions),Ee=()=>{oe(!0)},Z=()=>{oe(!1),ie(!1),Y(null)};B.usePristineSnapshotInitializer(m,d,G,o=>Y(o));const Fe=()=>G?JSON.stringify(d)!==JSON.stringify(G):!1,Re=()=>{Fe()?Q(!0):Z()},Oe=async()=>{await ee({closeAfterSave:!0})},Ue=()=>{G&&Pe(G),Z(),Q(!1)};async function ee(o){const A=(o==null?void 0:o.closeAfterSave)??F;y(A),A&&Q(!1);const q=s.cloneDeep(d);C(!0),L(null),X(!0);const $e={template:d};H.mutate({resourceId:d.id,data:$e},{onSuccess:()=>{X(!1),s.ue.success("Dashboard saved!"),Y(q),C(!1),y(!1),A&&Z()},onError:()=>{X(!1),L("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function Ge(){if(v(!0),!p||!g)return;const o=JSON.stringify(d),A={...g,template:o,filterValues:J};await se(n.apiServiceUrl,A,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),W==null||W(d),v(!1)}const de=(g==null?void 0:g.name)||d.title;H.isPending&&console.log("Title during update:",{title:de,dashboardStateTitle:d.title,dashboardId:d==null?void 0:d.id,currentLensName:g==null?void 0:g.name});const qe=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,Be=i;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:[qe&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{K(!R)},className:"h-7 p-2",children:e.jsx(He,{className:"h-4 w-4"})}),Be&&!S&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:()=>Ce(),className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!S&&i&&(c?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.LoaderCircle,{className:"h-3 w-3 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):e.jsx(s.EditableText,{value:de||"Untitled Dashboard",onSave:o=>{console.log("EditableText onSave called:",{newTitle:o,canEditDashboard:M,dashboardId:d==null?void 0:d.id});const A=(d==null?void 0:d.title)||"";x(o),Ie(o,A)},isEditable:M&&!g,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:H.isPending}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[S&&e.jsxs(e.Fragment,{children:[e.jsx(B.AdvancedModeToggle,{className:"mr-2"}),e.jsx(B.VisualEditingControls,{className:"h-7"})]}),r&&!S&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var o;t!=null&&t.accessToken&&((o=navigator==null?void 0:navigator.clipboard)!=null&&o.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(n.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Ke,{className:"h-4 w-4"})})]}),!S&&i&&e.jsx(s.DownloadPdf,{}),!S&&i&&e.jsx(B.ScheduleDashboard,{}),!S&&i&&Ae&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>P(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!S&&i&&((he=O==null?void 0:O.permissions)==null?void 0:he.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"})}),!E&&!S&&m&&l.canUseFilters&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>{$("dashboard",!1),we(!0)},size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),m&&!S&&V&&r&&i&&e.jsx(es,{}),!S&&V&&r&&i&&e.jsx(ss,{}),m&&!S&&V&&g&&r&&i&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:j,onClick:Ge,size:"sm",children:[e.jsx(pe.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),m&&!S&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!m,onClick:()=>Le(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!S&&!m&&M&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ee,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Te&&i&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:U,onClick:()=>ee(),size:"sm",children:[U?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(pe.Save,{className:"mr-2 h-4 w-4"}),U?"Saving...":"Save"]}),!S&&m&&r&&i&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>ie(!_),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!S&&r&&e.jsx(Xe,{}),m&&!S&&i&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Re,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),b&&ce&&e.jsx(s.ShareDialog,{resource:ce,resourceType:s.ResourceType.DASHBOARD,onClose:()=>N(!1)}),e.jsx(Ss,{open:T,onOpenChange:P}),e.jsx(s.AlertDialog,{open:k,onOpenChange:o=>{!o&&U&&!I||(C(o),o||(L(null),y(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:I?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:I?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:I?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{C(!1),L(null),y(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ee(),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(B.UnsavedChangesAlert,{open:ke,onOpenChange:Q,onSave:Oe,onDiscard:Ue,isSaving:U})]})]})}exports.default=ws;