react-semaphor 0.1.150 → 0.1.151

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 (26) hide show
  1. package/dist/chunks/{dashboard-controls-CrWp_eW0.js → dashboard-controls-C9vPPAA5.js} +295 -303
  2. package/dist/chunks/dashboard-controls-R0Ll84Gl.js +26 -0
  3. package/dist/chunks/{dashboard-export-dialog-CTDWnL2v.js → dashboard-export-dialog-CzMFzBse.js} +3 -3
  4. package/dist/chunks/{dashboard-export-dialog-Bdt-TnlL.js → dashboard-export-dialog-DYniVga5.js} +1 -1
  5. package/dist/chunks/{dashboard-json-CKQPyk-T.js → dashboard-json-3GJosjZ1.js} +1 -1
  6. package/dist/chunks/{dashboard-json-BvV_dByo.js → dashboard-json-D_Ew5v58.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-JmSJtVAb.js → edit-dashboard-visual-DVgTTLJA.js} +304 -304
  8. package/dist/chunks/{edit-dashboard-visual-DKx_Fd1g.js → edit-dashboard-visual-DxpnXWrq.js} +1 -1
  9. package/dist/chunks/{editor-action-buttons-D98KnvrV.js → editor-action-buttons-BGRGrvil.js} +1 -1
  10. package/dist/chunks/{editor-action-buttons-BrlrQ2Xg.js → editor-action-buttons-nOqTm8Zx.js} +2 -2
  11. package/dist/chunks/index-C39yXWHP.js +1354 -0
  12. package/dist/chunks/{index-DHIYxVk4.js → index-CClisLGZ.js} +65080 -64485
  13. package/dist/chunks/{resource-management-panel-QHQGFqsL.js → resource-management-panel-CpxLsJ42.js} +2 -2
  14. package/dist/chunks/{resource-management-panel-B5efhyg2.js → resource-management-panel-XGVGu9yZ.js} +1 -1
  15. package/dist/chunks/{use-visual-utils-CuQz3wl2.js → use-visual-utils-BgJnVTRi.js} +1 -1
  16. package/dist/chunks/{use-visual-utils-B8vSKgmQ.js → use-visual-utils-D4_F3SrQ.js} +1 -1
  17. package/dist/dashboard/index.cjs +1 -1
  18. package/dist/dashboard/index.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +4 -4
  21. package/dist/surfboard/index.cjs +1 -1
  22. package/dist/surfboard/index.js +1 -1
  23. package/dist/types/main.d.ts +16 -26
  24. package/package.json +8 -4
  25. package/dist/chunks/dashboard-controls-Hw3sWZQd.js +0 -26
  26. package/dist/chunks/index-zUMoYWue.js +0 -1339
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as a, Fragment as me } from "react/jsx-runtime";
2
- import { b as We, u as ce, f as qe, ap as ie, b5 as Je, b6 as Qe, c as ee, b7 as Ye, aG as Xe, aH as Ze, B as G, aI as $e, aJ as ke, aK as Q, b8 as ue, L as re, b9 as et, ba as tt, bb as st, bc as Ne, bd as pe, be as at, bf as nt, I as it, bg as we, bh as oe, bi as ve, bj as Ce, bk as rt, M as ye, R as Se, bl as Ee, aO as Ve, aP as Le, aQ as Ae, aS as Te, aT as Oe, aU as Re, aV as Pe, aW as Ie, bm as ot, bn as lt, bo as Ue, bp as Me, bq as je, br as dt, bs as Fe, bt as ct, A as ae, ao as ut, bu as ht, bv as ze, bw as mt, bx as pt, at as ft, au as gt, av as Dt, aw as xt, ax as Nt, ay as be, az as he, aC as bt, by as wt, bz as vt, bA as Ct, bB as yt } from "./index-DHIYxVk4.js";
2
+ import { b as We, u as ce, f as qe, ap as ie, b5 as Je, b6 as Qe, c as ee, b7 as Ye, aG as Xe, aH as Ze, B as G, aI as $e, aJ as ke, aK as Q, b8 as ue, L as re, b9 as et, ba as tt, bb as st, bc as Ne, bd as pe, be as at, bf as nt, I as it, bg as we, bh as oe, bi as ve, bj as Ce, bk as rt, M as ye, R as Se, bl as Ee, aO as Ve, aP as Le, aQ as Ae, aS as Te, aT as Oe, aU as Re, aV as Pe, aW as Ie, bm as ot, bn as lt, bo as Ue, bp as Me, bq as je, br as dt, bs as Fe, bt as ct, A as ae, ao as ut, bu as ht, bv as ze, bw as mt, bx as pt, at as ft, au as gt, av as Dt, aw as xt, ax as Nt, ay as be, az as he, aC as bt, by as wt, bz as vt, bA as Ct, bB as yt } from "./index-CClisLGZ.js";
3
3
  import St, { useRef as Et, useEffect as ne, useState as x } from "react";
4
- import { a as Be } from "./use-visual-utils-CuQz3wl2.js";
4
+ import { a as Be } from "./use-visual-utils-BgJnVTRi.js";
5
5
  /**
6
6
  * @license lucide-react v0.453.0 - ISC
7
7
  *
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-zUMoYWue.js"),c=require("react"),oe=require("./use-visual-utils-B8vSKgmQ.js");/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-C39yXWHP.js"),c=require("react"),oe=require("./use-visual-utils-D4_F3SrQ.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 { an as G, ao as z, h as Y, i as J, ap as K, e as _, g as X, u as U, aq as Z, ar as q, l as v, as as ee, f as h } from "./index-DHIYxVk4.js";
1
+ import { an as G, ao as z, h as Y, i as J, ap as K, e as _, g as X, u as U, aq as Z, ar as q, l as v, as as ee, f as h } from "./index-CClisLGZ.js";
2
2
  import { useState as T, useEffect as te, useCallback as V } from "react";
3
3
  function re(e) {
4
4
  const o = e.toUpperCase().indexOf("WHERE"), r = e.toUpperCase().indexOf("GROUP BY"), t = e.toUpperCase().indexOf("LIMIT"), i = e.toUpperCase().indexOf("ORDER BY");
@@ -1 +1 @@
1
- "use strict";const o=require("./index-zUMoYWue.js"),b=require("react");function _(e){const a=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),t=e.toUpperCase().indexOf("LIMIT"),d=e.toUpperCase().indexOf("ORDER BY");let c=e.length;if(d!==-1&&(c=d),t!==-1&&t<c&&(c=t),a!==-1){const n=e.substring(0,a),s=e.substring(a);return`${n} {{ filters | where }} AND ${s.substring(6)}`}else if(r!==-1){const n=e.substring(0,r),s=e.substring(r);return`${n} {{ filters | where }} ${s}`}else{const n=e.substring(0,c),s=e.substring(c);return console.log("beforeClause",n),console.log("afterClause",s),s?`${n} {{ filters | where }} ${s}`:`${n.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,r]=b.useState(null),[t,d]=b.useState(null),c=o.useEnsureReactGlobals();return b.useEffect(()=>{if(!e||e.trim()===""){r(null),d(null);return}if(!c)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 m=await import(l);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>m.useChartStore),d(null)}catch(s){const l=s instanceof Error?s.message:"Unknown error";console.error("Failed to load remote chart store:",l),d(l),r(null)}})()},[e,c]),a}function H(e,a){if(e.length===0)return"";if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],n=e.find(s=>s.tabTitle===c);return n?n.id:e[0].id}return a}}return e[0].id}async function j(e,a,r,t){if(!a||!r)throw new Error("Missing auth token or visual ID");const d=["resource-by-id","visual",r],c=t.getQueryData(d);if(c)return console.log("Using cached visual data for:",r),{data:c,fromCache:!0};console.log("Fetching visual data from network for:",r);const n=o.ue.loading("Loading visual...",{position:"top-center"});try{const s=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${a}`}});if(!s.ok)throw new Error("Failed to load visual");const l=await s.json();return t.setQueryData(d,l),o.ue.dismiss(n),{data:l,fromCache:!1}}catch(s){throw o.ue.dismiss(n),s}}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 Q(e,a){var c,n;const r=(e==null?void 0:e.frameObject)??((c=e==null?void 0:e.visual)==null?void 0:c.frameObject);if(!r)return!1;const t=T(r);if(!(t!=null&&t.cards)||t.cards.length===0)return!1;const d=(n=t.cards)==null?void 0:n.find(s=>s.id===t.activeCardId);return d?(o.setupEditorWithCard({...a,frame:t,card:d,visualId:(e==null?void 0:e.id)||t.visualId}),!0):!1}function G(){var g;const{setCardSql:e}=o.useEditorActions(),a=o.useEditorStore(i=>i.frame),r=o.useEditorStore(i=>i.card),t=B(((g=r.customCardPreferences)==null?void 0:g.url)||""),d=o.useEditorStore(i=>i.selectedSchemaName),c=o.useEditorStore(i=>i.selectedDatamodelId),n=o.useEditorStore(i=>i.selectedDatabaseName),s=o.useEditorStore(i=>i.selectedTableName),l=o.useEditorStore(i=>i.selectedConnectionId),m=o.useEditorStore(i=>i.isShowingVisual),f=r.sql;return{getUpdatedFrame:b.useCallback(()=>{var E;let i=f;f&&!f.includes("{{")&&(i=_(f),e(i));const C=(E=t==null?void 0:t.getState())==null?void 0:E.settings,U={...r,dataSource:r.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:c,lastSelectedDatabase:n,lastSelectedTable:s,connectionId:l,sql:i,customCfg:m?r.customCfg:null,preferences:r.preferences,...C&&{customCardPreferences:{...r.customCardPreferences,settings:C}}},w=a.cards.map(S=>S.id===r.id?U:S);return{...a,cards:w,activeCardId:H(w,a.activeCardId)}},[r,a,m,d,c,n,s,l,e,t,f])}}function z(){const{authToken:e,tokenProps:a}=o.useSemaphorContext(),r=o.useQueryClient(),t=o.useSelectedVisual(),{selectVisual:d}=o.useManagementActions(),{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E}=o.useEditorActions(),{setIsDashboardEditing:S,setIsVisualEditing:$,setSelectedFrameId:v,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),D=o.useDashboardStore(u=>u.selectedFrameId),O=o.useDashboardStore(u=>u.dashboard),x=o.useDashboardStore(u=>u.filterValues),y=o.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),M=b.useCallback(async u=>{try{d(u),A();const{data:p,fromCache:h}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r);if(!Q(p,{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E,setIsDashboardEditing:S,setIsVisualEditing:$,dashboard:O,selectedSheetId:I,selectedFrameId:D,filterValues:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:h}}catch(p){return console.error("Error editing visual:",p),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,c,n,S,$,s,l,m,f,V,g,i,C,U,w,E,A,O,I,D,x]),k=b.useCallback(async u=>{var p;try{if(d(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:h,fromCache:W}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r),L=(h==null?void 0:h.frameObject)??((p=h==null?void 0:h.visual)==null?void 0:p.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const F=T(L);if(!(F!=null&&F.cards)||F.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...o.cloneFrameWithNewIds(F),visualId:u.id};return N(I,P,"end"),S(!0),v(P.id),R(!1),{success:!0,fromCache:W}}catch(h){return console.error("Error adding visual:",h),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,I,N,S,v,R]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:M,handleAddLibraryVisual:k,getUpdatedFrame:G().getUpdatedFrame,refetch:y.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=z;
1
+ "use strict";const o=require("./index-C39yXWHP.js"),b=require("react");function _(e){const a=e.toUpperCase().indexOf("WHERE"),r=e.toUpperCase().indexOf("GROUP BY"),t=e.toUpperCase().indexOf("LIMIT"),d=e.toUpperCase().indexOf("ORDER BY");let c=e.length;if(d!==-1&&(c=d),t!==-1&&t<c&&(c=t),a!==-1){const n=e.substring(0,a),s=e.substring(a);return`${n} {{ filters | where }} AND ${s.substring(6)}`}else if(r!==-1){const n=e.substring(0,r),s=e.substring(r);return`${n} {{ filters | where }} ${s}`}else{const n=e.substring(0,c),s=e.substring(c);return console.log("beforeClause",n),console.log("afterClause",s),s?`${n} {{ filters | where }} ${s}`:`${n.replace(/;$/,"")} {{ filters | where }}`}}function B(e){const[a,r]=b.useState(null),[t,d]=b.useState(null),c=o.useEnsureReactGlobals();return b.useEffect(()=>{if(!e||e.trim()===""){r(null),d(null);return}if(!c)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 m=await import(l);if(typeof m.useChartStore!="function")throw new Error("useChartStore is not a function");r(()=>m.useChartStore),d(null)}catch(s){const l=s instanceof Error?s.message:"Unknown error";console.error("Failed to load remote chart store:",l),d(l),r(null)}})()},[e,c]),a}function H(e,a){if(e.length===0)return"";if(a){const r=e.find(t=>t.id===a);if(r){const t=r.tabTitle;if(t=="All__Header")return e[0].id;if(t&&t.endsWith("__Header")){const c=t.split("__")[0],n=e.find(s=>s.tabTitle===c);return n?n.id:e[0].id}return a}}return e[0].id}async function j(e,a,r,t){if(!a||!r)throw new Error("Missing auth token or visual ID");const d=["resource-by-id","visual",r],c=t.getQueryData(d);if(c)return console.log("Using cached visual data for:",r),{data:c,fromCache:!0};console.log("Fetching visual data from network for:",r);const n=o.ue.loading("Loading visual...",{position:"top-center"});try{const s=await fetch(`${e}/management/v1/visuals/${r}`,{headers:{Authorization:`Bearer ${a}`}});if(!s.ok)throw new Error("Failed to load visual");const l=await s.json();return t.setQueryData(d,l),o.ue.dismiss(n),{data:l,fromCache:!1}}catch(s){throw o.ue.dismiss(n),s}}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 Q(e,a){var c,n;const r=(e==null?void 0:e.frameObject)??((c=e==null?void 0:e.visual)==null?void 0:c.frameObject);if(!r)return!1;const t=T(r);if(!(t!=null&&t.cards)||t.cards.length===0)return!1;const d=(n=t.cards)==null?void 0:n.find(s=>s.id===t.activeCardId);return d?(o.setupEditorWithCard({...a,frame:t,card:d,visualId:(e==null?void 0:e.id)||t.visualId}),!0):!1}function G(){var g;const{setCardSql:e}=o.useEditorActions(),a=o.useEditorStore(i=>i.frame),r=o.useEditorStore(i=>i.card),t=B(((g=r.customCardPreferences)==null?void 0:g.url)||""),d=o.useEditorStore(i=>i.selectedSchemaName),c=o.useEditorStore(i=>i.selectedDatamodelId),n=o.useEditorStore(i=>i.selectedDatabaseName),s=o.useEditorStore(i=>i.selectedTableName),l=o.useEditorStore(i=>i.selectedConnectionId),m=o.useEditorStore(i=>i.isShowingVisual),f=r.sql;return{getUpdatedFrame:b.useCallback(()=>{var E;let i=f;f&&!f.includes("{{")&&(i=_(f),e(i));const C=(E=t==null?void 0:t.getState())==null?void 0:E.settings,U={...r,dataSource:r.dataSource||{mode:"directSource"},lastSelectedSchema:d,lastSelectedDatamodelId:c,lastSelectedDatabase:n,lastSelectedTable:s,connectionId:l,sql:i,customCfg:m?r.customCfg:null,preferences:r.preferences,...C&&{customCardPreferences:{...r.customCardPreferences,settings:C}}},w=a.cards.map(S=>S.id===r.id?U:S);return{...a,cards:w,activeCardId:H(w,a.activeCardId)}},[r,a,m,d,c,n,s,l,e,t,f])}}function z(){const{authToken:e,tokenProps:a}=o.useSemaphorContext(),r=o.useQueryClient(),t=o.useSelectedVisual(),{selectVisual:d}=o.useManagementActions(),{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E}=o.useEditorActions(),{setIsDashboardEditing:S,setIsVisualEditing:$,setSelectedFrameId:v,clearSelectedFrameId:A,addFrame:N,setIsDashboardPanelOpen:R}=o.useDashboardActions(),I=o.useDashboardStore(u=>u.selectedSheetId),D=o.useDashboardStore(u=>u.selectedFrameId),O=o.useDashboardStore(u=>u.dashboard),x=o.useDashboardStore(u=>u.filterValues),y=o.useVisualById((t==null?void 0:t.id)||"",{enabled:!!(t!=null&&t.id)&&!!(e!=null&&e.accessToken)}),M=b.useCallback(async u=>{try{d(u),A();const{data:p,fromCache:h}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r);if(!Q(p,{setFrame:c,setCard:n,setIsDevMode:s,setActiveTabCardId:l,updateDataSource:m,setQueryResultColumns:f,setSelectedConnectionId:V,setSelectedDatabaseName:g,setSelectedSchemaName:i,setSelectedTableName:C,setSelectedDatamodelId:U,setFilterValues:w,setApplyFilters:E,setIsDashboardEditing:S,setIsVisualEditing:$,dashboard:O,selectedSheetId:I,selectedFrameId:D,filterValues:x}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:h}}catch(p){return console.error("Error editing visual:",p),{success:!1,error:"Failed to load visual for editing"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,c,n,S,$,s,l,m,f,V,g,i,C,U,w,E,A,O,I,D,x]),k=b.useCallback(async u=>{var p;try{if(d(u),!I)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:h,fromCache:W}=await j(a.apiServiceUrl,(e==null?void 0:e.accessToken)||"",u.id,r),L=(h==null?void 0:h.frameObject)??((p=h==null?void 0:h.visual)==null?void 0:p.frameObject);if(!L)return{success:!1,error:"Visual has no frame data"};const F=T(L);if(!(F!=null&&F.cards)||F.cards.length===0)return{success:!1,error:"Visual frame is malformed"};const P={...o.cloneFrameWithNewIds(F),visualId:u.id};return N(I,P,"end"),S(!0),v(P.id),R(!1),{success:!0,fromCache:W}}catch(h){return console.error("Error adding visual:",h),{success:!1,error:"Failed to add visual to dashboard"}}},[e==null?void 0:e.accessToken,a.apiServiceUrl,r,d,I,N,S,v,R]);return{visual:y.data,isLoading:y.isLoading,isError:y.isError,error:y.error,handleEditLibraryVisual:M,handleAddLibraryVisual:k,getUpdatedFrame:G().getUpdatedFrame,refetch:y.refetch}}exports.useRemoteChartStore=B;exports.useVisualUtils=z;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../chunks/index-zUMoYWue.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-C39yXWHP.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-DHIYxVk4.js";
1
+ import { D as a } from "../chunks/index-CClisLGZ.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-zUMoYWue.js"),E=require("./types/index.cjs"),a=require("react/jsx-runtime"),g=require("react"),j=require("./chunks/resource-management-panel-B5efhyg2.js"),c=require("./chunks/dashboard-export-dialog-Bdt-TnlL.js");require("react-dom");function P(r){const t=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(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return t.default=r,Object.freeze(t)}const C=P(g);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/index-C39yXWHP.js"),E=require("./types/index.cjs"),a=require("react/jsx-runtime"),g=require("react"),j=require("./chunks/resource-management-panel-XGVGu9yZ.js"),c=require("./chunks/dashboard-export-dialog-DYniVga5.js");require("react-dom");function P(r){const t=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(t,s,i.get?i:{enumerable:!0,get:()=>r[s]})}}return t.default=r,Object.freeze(t)}const C=P(g);/**
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 { b as T, E as y, F as P, S as w, U as M, m as k, n as A, u as F, o as g, p as L, P as R, q as I, B as V, c as v, r as _, s as U, t as B, v as W, I as j, w as q, x as z, y as O, z as Q, C as G } from "./chunks/index-DHIYxVk4.js";
2
- import { _ as oa, $ as na, D as ta, O as ia, a3 as la, R as da, K as ca, K as ua, M as ha, a as pa, V as fa, am as ma, aa as Ca, Y as va, Q as ba, T as Da, a4 as ga, ac as ya, ab as xa, af as Ea, ag as Na, a9 as Sa, W as Ta, a8 as Pa, a1 as wa, a2 as Ma, a0 as ka, ad as Aa, a7 as Fa, a6 as La, a5 as Ra, ah as Ia, ae as Va, N as _a, aj as Ua, al as Ba, ak as Wa, g as ja, G as qa, Z as za, H as Oa, e as Qa, ai as Ga, f as Ha, A as Ka, J as Ya } from "./chunks/index-DHIYxVk4.js";
1
+ import { b as T, E as y, F as P, S as w, U as M, m as k, n as A, u as F, o as g, p as L, P as R, q as I, B as V, c as v, r as _, s as U, t as B, v as W, I as j, w as q, x as z, y as O, z as Q, C as G } from "./chunks/index-CClisLGZ.js";
2
+ import { _ as oa, $ as na, D as ta, O as ia, a3 as la, R as da, K as ca, K as ua, M as ha, a as pa, V as fa, am as ma, aa as Ca, Y as va, Q as ba, T as Da, a4 as ga, ac as ya, ab as xa, af as Ea, ag as Na, a9 as Sa, W as Ta, a8 as Pa, a1 as wa, a2 as Ma, a0 as ka, ad as Aa, a7 as Fa, a6 as La, a5 as Ra, ah as Ia, ae as Va, N as _a, aj as Ua, al as Ba, ak as Wa, g as ja, G as qa, Z as za, H as Oa, e as Qa, ai as Ga, f as Ha, A as Ka, J as Ya } from "./chunks/index-CClisLGZ.js";
3
3
  import { EMPTY_SELECTION as Ja } from "./types/index.js";
4
4
  import { jsx as a, jsxs as l } from "react/jsx-runtime";
5
5
  import * as p from "react";
6
6
  import { useMemo as H } from "react";
7
- import { ResourceManagementPanel as Za } from "./chunks/resource-management-panel-QHQGFqsL.js";
8
- import { A as ee, D as se, S as re, U as oe, V as ne, u as te } from "./chunks/dashboard-export-dialog-CTDWnL2v.js";
7
+ import { ResourceManagementPanel as Za } from "./chunks/resource-management-panel-CpxLsJ42.js";
8
+ import { A as ee, D as se, S as re, U as oe, V as ne, u as te } from "./chunks/dashboard-export-dialog-CzMFzBse.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-zUMoYWue.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-C39yXWHP.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-DHIYxVk4.js";
1
+ import { a } from "../chunks/index-CClisLGZ.js";
2
2
  import { EMPTY_SELECTION as E } from "../types/index.js";
3
3
  export {
4
4
  E as EMPTY_SELECTION,
@@ -1,25 +1,15 @@
1
1
  import { Chart } from 'chart.js';
2
2
  import { ChartConfiguration } from 'chart.js';
3
3
  import { ColumnSizingState } from '@tanstack/react-table';
4
- import { ComboBoxOption as ComboBoxOption_2 } from '../../components/surfboard/filter/types';
5
- import { ComparisonMetadata as ComparisonMetadata_2 } from '../types/query-types';
6
4
  import { DateRange } from 'react-day-picker';
7
5
  import { default as default_2 } from 'react-grid-layout';
8
- import { Dialect as Dialect_2 } from '../types/explorer-types';
9
- import { DropdownItem as DropdownItem_2 } from '../types/dropdown-types';
10
6
  import { FontSpec } from 'chart.js';
11
- import { GetDashboardResponse as GetDashboardResponse_2 } from '../types';
12
- import { GroupByField as GroupByField_2 } from '../types/explorer-types';
13
7
  import { JSX } from 'react/jsx-runtime';
14
8
  import { JSX as JSX_2 } from 'react';
15
- import { MetricField as MetricField_2 } from '../types/explorer-types';
16
- import { PaginationMetadata as PaginationMetadata_2 } from '../types/explorer-types';
17
- import { PivotByField as PivotByField_2 } from '../types/explorer-types';
18
9
  import { QueryObserverResult } from '@tanstack/query-core';
19
10
  import * as React_2 from 'react';
20
11
  import { RefetchOptions } from '@tanstack/query-core';
21
12
  import { StoreApi } from 'zustand';
22
- import { TDbCapabilities as TDbCapabilities_2 } from '../types';
23
13
  import { UseBoundStore } from 'zustand';
24
14
  import { WritableDraft } from 'immer';
25
15
 
@@ -2935,16 +2925,16 @@ export declare function useCard(cardId: string): {
2935
2925
  handleDatapointClick: (chart: Chart, datasetIndex: number, clickIndex: number, value: number) => void;
2936
2926
  cfg: TChartConfiguration | undefined;
2937
2927
  queryKey: string[];
2938
- pagination: PaginationMetadata_2 | undefined;
2939
- comparisonMetadata: ComparisonMetadata_2 | undefined;
2928
+ pagination: PaginationMetadata | undefined;
2929
+ comparisonMetadata: ComparisonMetadata | undefined;
2940
2930
  };
2941
2931
 
2942
2932
  export declare const useCurrentActiveCard: () => TCard | undefined;
2943
2933
 
2944
2934
  export declare const useCurrentCardConfig: () => {
2945
- metricFields: MetricField_2[];
2946
- groupByFields: GroupByField_2[];
2947
- pivotByFields: PivotByField_2[];
2935
+ metricFields: MetricField[];
2936
+ groupByFields: GroupByField[];
2937
+ pivotByFields: PivotByField[];
2948
2938
  };
2949
2939
 
2950
2940
  export declare const useCurrentSheetActiveCards: () => TCard[];
@@ -2952,11 +2942,11 @@ export declare const useCurrentSheetActiveCards: () => TCard[];
2952
2942
  export declare const useDashboardActions: () => Actions_2;
2953
2943
 
2954
2944
  export declare function useDashboardQuery(): {
2955
- data: GetDashboardResponse_2 | null | undefined;
2945
+ data: GetDashboardResponse | null | undefined;
2956
2946
  isLoading: boolean;
2957
2947
  isFetching: boolean;
2958
2948
  isError: boolean;
2959
- refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<GetDashboardResponse_2 | null, Error>>;
2949
+ refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<GetDashboardResponse | null, Error>>;
2960
2950
  };
2961
2951
 
2962
2952
  export declare const useDashboardStore: UseBoundStore<Omit<StoreApi<DashboardStore>, "setState"> & {
@@ -2993,26 +2983,26 @@ export declare function useEditorAside(token?: AuthToken, _connectionQueryKey?:
2993
2983
  id: string;
2994
2984
  name: string;
2995
2985
  type: string;
2996
- dialect?: Dialect_2;
2986
+ dialect?: Dialect;
2997
2987
  uiType?: "database" | "api" | "s3";
2998
- capabilities: TDbCapabilities_2;
2988
+ capabilities: TDbCapabilities;
2999
2989
  } | undefined;
3000
2990
  isConnectionsLoading: boolean;
3001
2991
  isConnectionsError: boolean;
3002
- modelItems: DropdownItem_2[];
2992
+ modelItems: DropdownItem[];
3003
2993
  selectedDatamodelId: string | undefined;
3004
2994
  selectedDatamodelName: any;
3005
2995
  isModelsLoading: boolean;
3006
2996
  isModelsError: boolean;
3007
2997
  selectedDatabaseName: string | undefined;
3008
- databaseItems: DropdownItem_2[];
2998
+ databaseItems: DropdownItem[];
3009
2999
  isDatabasesLoadingOrFetching: boolean;
3010
3000
  isDatabaseError: boolean;
3011
- schemaItems: DropdownItem_2[];
3001
+ schemaItems: DropdownItem[];
3012
3002
  selectedSchemaName: string | undefined;
3013
3003
  isSchemaLoadingOrFetching: boolean;
3014
3004
  isSchemaError: boolean;
3015
- tableItems: DropdownItem_2[];
3005
+ tableItems: DropdownItem[];
3016
3006
  selectedTableName: string | undefined;
3017
3007
  isTableLoadingOrFetching: boolean;
3018
3008
  isTableError: boolean;
@@ -3070,13 +3060,13 @@ export declare function useTextFilterHook(filterId: string): {
3070
3060
  isLoading: boolean;
3071
3061
  isFetching: boolean;
3072
3062
  isError: boolean;
3073
- records: ComboBoxOption_2[];
3074
- selectedRecords: ComboBoxOption_2[];
3063
+ records: ComboBoxOption[];
3064
+ selectedRecords: ComboBoxOption[];
3075
3065
  handleChange: (selectedRecords: TSelectedRecord[]) => void;
3076
3066
  handleClear: () => void;
3077
3067
  handleSelectAll: (checked: boolean) => void;
3078
3068
  handleApplyOperatorExpression: () => boolean;
3079
- filteredRecords: ComboBoxOption_2[];
3069
+ filteredRecords: ComboBoxOption[];
3080
3070
  isSingleSelect: boolean;
3081
3071
  allSelected: boolean;
3082
3072
  activeFilterValue: TFilterValue | undefined;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.150",
8
+ "version": "0.1.151",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -82,7 +82,7 @@
82
82
  "@radix-ui/react-icons": "^1.3.2",
83
83
  "@radix-ui/react-label": "^2.1.1",
84
84
  "@radix-ui/react-popover": "^1.1.4",
85
- "@radix-ui/react-progress": "^1.0.3",
85
+ "@radix-ui/react-progress": "^1.1.8",
86
86
  "@radix-ui/react-radio-group": "^1.2.2",
87
87
  "@radix-ui/react-scroll-area": "^1.2.2",
88
88
  "@radix-ui/react-select": "^2.1.4",
@@ -135,6 +135,10 @@
135
135
  "react": "^18.0.0 || ^19.0.0",
136
136
  "react-dom": "^18.0.0 || ^19.0.0"
137
137
  },
138
+ "overrides": {
139
+ "react": "$react",
140
+ "react-dom": "$react-dom"
141
+ },
138
142
  "devDependencies": {
139
143
  "@microsoft/api-extractor": "^7.52.1",
140
144
  "@tanstack/react-query-devtools": "^5.62.15",
@@ -170,8 +174,8 @@
170
174
  "postcss-prefix-selector": "^2.1.0",
171
175
  "postcss-preset-env": "^10.0.9",
172
176
  "prettier-plugin-tailwindcss": "^0.6.1",
173
- "react": "^19.2.1",
174
- "react-dom": "^19.2.1",
177
+ "react": "19.3.0-canary-52684925-20251110",
178
+ "react-dom": "19.3.0-canary-52684925-20251110",
175
179
  "rollup-plugin-visualizer": "^5.12.0",
176
180
  "simple-zustand-devtools": "^1.1.0",
177
181
  "tailwindcss": "^3.4.1",
@@ -1,26 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-zUMoYWue.js"),f=require("react");require("react-dom");const G=require("./dashboard-export-dialog-Bdt-TnlL.js"),pe=require("./editor-action-buttons-D98KnvrV.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 S=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 _e=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 Qe=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 He=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 Ve=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 Ke=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 Je=s.requireShim();function We(){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(Ke,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(He,{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 Xe(t,n,a,r,l){if(!l)return null;const o=JSON.stringify(a),c=`${t}/v1/lens`;return await s.postRequest(c,l,{name:n,template:o,filterValues:r,operation:"create"})}async function ee(t,n,a){if(!a)return null;const{id:r,template:l,filterValues:o,isDefault:c,shared:u}=n,p=`${t}/v1/lens`;return await s.postRequest(p,a,{lensId:r,template:l,filterValues:o,isDefault:c,shared:u,operation:"update"})}async function Ye(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:n})}function Ze(){const[t,n]=f.useState(""),[a,r]=f.useState(!1),l=s.useDashboardStore(y=>y.lenses),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),[u,p]=f.useState(!1),[g,d]=f.useState(!1),m=s.useDashboardStore(y=>y.dashboard),x=s.useDashboardStore(y=>y.filterValues),{authToken:j,tokenProps:v}=s.useSemaphorContext();async function b(){p(!0);const y=await Xe(v.apiServiceUrl,t,m,x,j==null?void 0:j.accessToken);y&&(o([...l||[],y]),c(y.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:y=>{n(y.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 es(){const[t,n]=f.useState(!1),a=s.useDashboardStore(m=>m.lenses),r=s.useDashboardStore(m=>m.selectedLensId),{setLenses:l,setSelectedLensId:o}=s.useDashboardActions(),{authToken:c,tokenProps:u}=s.useSemaphorContext();async function p(m){o(m)}async function g(m){if(await Ye(u.apiServiceUrl,m,c==null?void 0:c.accessToken)){const j=a==null?void 0:a.filter(v=>v.id!==m);l(j||[]),o("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 ee(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 ee(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(_e,{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))]})]})]})}function ss({iconClassName:t}){const[n,a]=f.useState(!1),r=s.useDashboardStore(l=>l.isDownloadingPdf);return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",disabled:r,onClick:()=>a(!0),children:e.jsx(s.Download,{className:s.cn("size-4",t)})}),e.jsx(G.DashboardExportDialog,{open:n,onOpenChange:a})]})}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 o=await l.text();throw new Error(o||"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`,o=await fetch(l,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify(r)});if(!o.ok){const c=await o.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(""),[o,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",o&&o.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:o.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:o,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:[o.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(o,c){const u=S.createContext(c),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,y=S.useMemo(()=>v,Object.values(v));return e.jsx(b.Provider,{value:y,children:j})};g.displayName=o+"Provider";function d(m,x){var b;const j=((b=x==null?void 0:x[t])==null?void 0:b[p])||u,v=S.useContext(j);if(v)return v;if(c!==void 0)return c;throw new Error(`\`${m}\` must be used within \`${o}\``)}return[g,d]}const l=()=>{const o=a.map(c=>S.createContext(c));return function(u){const p=(u==null?void 0:u[t])||o;return S.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(o){const c=r.reduce((u,{useScope:p,scopeName:g})=>{const m=p(o)[`__scope${g}`];return{...u,...m}},{});return S.useMemo(()=>({[`__scope${n.scopeName}`]:c}),[c])}};return a.scopeName=n.scopeName,a}function hs(t){const n=S.useRef(t);return S.useEffect(()=>{n.current=t}),S.useMemo(()=>(...a)=>{var r;return(r=n.current)==null?void 0:r.call(n,...a)},[])}var se=globalThis!=null&&globalThis.document?S.useLayoutEffect:()=>{},ps=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],te=ps.reduce((t,n)=>{const a=s.createSlot(`Primitive.${n}`),r=S.forwardRef((l,o)=>{const{asChild:c,...u}=l,p=c?a:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...u,ref:o})});return r.displayName=`Primitive.${n}`,{...t,[n]:r}},{});function xs(){return Je.useSyncExternalStore(gs,()=>!0,()=>!1)}function gs(){return()=>{}}var ae="Avatar",[fs]=us(ae),[js,ge]=fs(ae),fe=S.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[l,o]=S.useState("idle");return e.jsx(js,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:o,children:e.jsx(te.span,{...r,ref:n})})});fe.displayName=ae;var je="AvatarImage",ve=S.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...o}=t,c=ge(je,a),u=vs(r,o),p=hs(g=>{l(g),c.onImageLoadingStatusChange(g)});return se(()=>{u!=="idle"&&p(u)},[u,p]),u==="loaded"?e.jsx(te.img,{...o,ref:n,src:r}):null});ve.displayName=je;var be="AvatarFallback",Ne=S.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,o=ge(be,a),[c,u]=S.useState(r===void 0);return S.useEffect(()=>{if(r!==void 0){const p=window.setTimeout(()=>u(!0),r);return()=>window.clearTimeout(p)}},[r]),c&&o.imageLoadingStatus!=="loaded"?e.jsx(te.span,{...l,ref:n}):null});Ne.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 vs(t,{referrerPolicy:n,crossOrigin:a}){const r=xs(),l=S.useRef(null),o=r?(l.current||(l.current=new window.Image),l.current):null,[c,u]=S.useState(()=>xe(o,t));return se(()=>{u(xe(o,t))},[o,t]),se(()=>{const p=m=>()=>{u(m)};if(!o)return;const g=p("loaded"),d=p("error");return o.addEventListener("load",g),o.addEventListener("error",d),n&&(o.referrerPolicy=n),typeof a=="string"&&(o.crossOrigin=a),()=>{o.removeEventListener("load",g),o.removeEventListener("error",d)}},[o,a,n]),c}var ye=fe,Se=ve,De=Ne;const re=S.forwardRef(({className:t,...n},a)=>e.jsx(ye,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));re.displayName=ye.displayName;const bs=S.forwardRef(({className:t,...n},a)=>e.jsx(Se,{ref:a,className:s.cn("aspect-square h-full w-full",t),...n}));bs.displayName=Se.displayName;const ne=S.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 Ns({open:t,onOpenChange:n,group:a,onUpdate:r}){const[l,o]=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:y,isLoading:T}=s.useUnifiedUsers({type:b,tenantId:a.tenantId||void 0,active:!0,limit:100}),E=ls(),k=cs(),C=(x==null?void 0:x.members)||[],I=f.useMemo(()=>new Set(C.map(h=>h.userId)),[C]),L=f.useMemo(()=>y.filter(h=>!I.has(h.id)),[y,I]),F=f.useMemo(()=>{if(!c)return L;const h=c.toLowerCase();return L.filter(w=>{var M,P;return((M=w.name)==null?void 0:M.toLowerCase().includes(h))||((P=w.email)==null?void 0:P.toLowerCase().includes(h))})},[L,c]),N=f.useMemo(()=>{if(!c)return C;const h=c.toLowerCase();return C.filter(w=>{var M,P,z,O;return((P=(M=w.user)==null?void 0:M.name)==null?void 0:P.toLowerCase().includes(h))||((O=(z=w.user)==null?void 0:z.email)==null?void 0:O.toLowerCase().includes(h))})},[C,c]),R=async()=>{if(p.length!==0)try{await E.mutateAsync({groupId:a.id,data:{userIds:p,userType:b==="tenant"?"tenant":"org"}}),g([]),o("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(w=>w.includes(h)?w.filter(M=>M!==h):[...w,h])},D=h=>{m(w=>w.includes(h)?w.filter(M=>M!==h):[...w,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=>{o(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))}):N.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:N.map(h=>e.jsx(ys,{member:h,selected:d.includes(h.userId),onToggle:()=>D(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(Ss,{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:E.isPending,children:E.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,o,c,u;const r=((o=(l=t.user)==null?void 0:l.name)==null?void 0:o.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 Ss({user:t,selected:n,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(o=>o[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 Ds({open:t,onOpenChange:n}){const[a,r]=f.useState("groups"),[l,o]=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",y=x==null?void 0:x.tenantId,{groups:T,isLoading:E,refetch:k}=s.useGroups({type:b?"TENANT_GROUP":"all",tenantId:b?y:void 0,includeMembers:!1}),C=T.filter(N=>{var R;return N.name.toLowerCase().includes(l.toLowerCase())||((R=N.description)==null?void 0:R.toLowerCase().includes(l.toLowerCase()))}),I=async()=>{if(d)try{await v.mutateAsync(d.id),m(null),k()}catch(N){console.error("Failed to delete group:",N)}},L=N=>{u(N),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:N=>o(N.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:E?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(N=>e.jsx(s.Skeleton,{className:"h-24 w-full"},N))}):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(N=>e.jsx(ws,{group:N,onManageMembers:()=>L(N),onDelete:()=>m(N),currentUserId:j==null?void 0:j.id},N.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(ds,{onSuccess:F,tenantId:y,isTenantUser:b})})]})]})}),c&&e.jsx(Ns,{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 ws({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 Cs(){var ue,me,he;const{authToken:t,tokenProps:n,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=s.useRoleAwareDisplayPreferences(),o=s.useHasDashboardId(),{isLoading:c}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const u=s.useDashboardStore(i=>i.lenses),p=s.useDashboardStore(i=>i.selectedLensId),g=u==null?void 0:u.find(i=>i.id===p),d=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const m=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:x}=s.useDashboardStore(i=>i.actions),[j,v]=f.useState(!1),[b,y]=f.useState(!1),[T,E]=f.useState(!1),[k,C]=f.useState(!1),[I,L]=f.useState(null),[F,N]=f.useState(!1),R=s.useDashboardStore(i=>i.isDashboardPanelOpen),K=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),J=s.useDashboardStore(i=>i.filterValues),D=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const h=s.useManagementStore(i=>i.selectedDashboard),w=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const M=h?(me=h==null?void 0:h.permissions)==null?void 0:me.canEdit:(ue=w==null?void 0:w.permissions)==null?void 0:ue.canEdit,P=s.useDashboardStore(i=>i.showFilters),z=s.useDashboardStore(i=>i.showDashboardJSON),O=s.useDashboardStore(i=>i.onSaveFunction),we=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:oe,setShowDashboardJSON:ie}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:le,clearSelectedDashboard:Ce}=s.useManagementStore(i=>i.actions),{resources:_}=s.useResourceManagement(s.ResourceType.DASHBOARD),{currentUser:Me}=s.useCurrentUserInfo(),Ae=s.canUserManageGroups(Me),U=h||w,ce=U?{id:U.id,title:(d==null?void 0:d.title)||U.title||"Dashboard"}:null,{handleAddNewFrame:Le}=s.useAddNewFrame(),[B,W]=f.useState(!1),[ke,Q]=f.useState(!1),H=s.useUpdateResource(s.ResourceType.DASHBOARD),[q,X]=f.useState(null),Ie=async(i,A)=>{if(!(d!=null&&d.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:d.id,newTitle:i,previousTitle:A}),H.mutate({resourceId:d.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:$=>{console.error("Failed to update dashboard title:",$),s.ue.error("Failed to update dashboard title"),x(A)}})};f.useEffect(()=>{if(_&&_.length>0){const i=d==null?void 0:d.id;if(i){const A=_.find($=>$.id===i);A&&le(A)}}},[_,d==null?void 0:d.id,le]);const V=n.orgUserId||n.tenantId,Te=m&&!D&&V&&M,{setDashboard:Ee}=s.useDashboardStore(i=>i.actions),Pe=()=>{oe(!0)},Y=()=>{oe(!1),ie(!1),X(null)};G.usePristineSnapshotInitializer(m,d,q,i=>X(i));const Fe=()=>q?JSON.stringify(d)!==JSON.stringify(q):!1,Re=()=>{Fe()?Q(!0):Y()},Oe=async()=>{await Z({closeAfterSave:!0})},Ue=()=>{q&&Ee(q),Y(),Q(!1)};async function Z(i){const A=(i==null?void 0:i.closeAfterSave)??F;N(A),A&&Q(!1);const $=s.cloneDeep(d);C(!0),L(null),W(!0);const $e={template:d};H.mutate({resourceId:d.id,data:$e},{onSuccess:()=>{W(!1),s.ue.success("Dashboard saved!"),X($),C(!1),N(!1),A&&Y()},onError:()=>{W(!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 i=JSON.stringify(d),A={...g,template:i,filterValues:J};await ee(n.apiServiceUrl,A,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),O==null||O(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 Be=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,qe=o;return e.jsxs("div",{className:"flex h-11 items-center justify-between gap-2 border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Be&&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(Qe,{className:"h-4 w-4"})}),qe&&!D&&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"})})]}),!D&&o&&(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:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:M,dashboardId:d==null?void 0:d.id});const A=(d==null?void 0:d.title)||"";x(i),Ie(i,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:[D&&e.jsxs(e.Fragment,{children:[e.jsx(G.AdvancedModeToggle,{className:"mr-2"}),e.jsx(G.VisualEditingControls,{className:"h-7"})]}),r&&!D&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(n.apiServiceUrl),className:"h-7 p-2",children:e.jsx(Ve,{className:"h-4 w-4"})})]}),!D&&o&&e.jsx(ss,{}),!D&&o&&e.jsx(G.ScheduleDashboard,{}),!D&&o&&Ae&&e.jsx(s.IconButton,{tooltip:"Manage Groups",onClick:()=>E(!0),className:"h-7 p-2",children:e.jsx(s.Users,{className:"h-4 w-4"})}),!D&&o&&((he=U==null?void 0:U.permissions)==null?void 0:he.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>y(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!P&&!D&&m&&l.canUseFilters&&o&&e.jsx(s.Button,{className:"h-7 p-2",variant:"outline",onClick:()=>we(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),m&&!D&&V&&r&&o&&e.jsx(Ze,{}),!D&&V&&r&&o&&e.jsx(es,{}),m&&!D&&V&&g&&r&&o&&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&&!D&&o&&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"]}),!D&&!m&&l.canEdit&&o&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Pe,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),Te&&o&&e.jsxs(s.Button,{className:"h-7 p-2",disabled:B,onClick:()=>Z(),size:"sm",children:[B?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(pe.Save,{className:"mr-2 h-4 w-4"}),B?"Saving...":"Save"]}),!D&&m&&r&&o&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>ie(!z),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!D&&r&&e.jsx(We,{}),m&&!D&&o&&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:()=>y(!1)}),e.jsx(Ds,{open:T,onOpenChange:E}),e.jsx(s.AlertDialog,{open:k,onOpenChange:i=>{!i&&B&&!I||(C(i),i||(L(null),N(!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),N(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Z(),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(G.UnsavedChangesAlert,{open:ke,onOpenChange:Q,onSave:Oe,onDiscard:Ue,isSaving:B})]})]})}exports.default=Cs;