react-semaphor 0.0.562 → 0.0.564
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{dashboard-plus-BYsfLtBi.js → dashboard-plus-BXuu8joa.js} +4577 -4343
- package/dist/chunks/dashboard-plus-jmg1QJuX.js +435 -0
- package/dist/chunks/{index-vGMyBsty.js → index-BCSRVTst.js} +55 -55
- package/dist/chunks/{index-Dj7J6ekb.js → index-DSwq8_oh.js} +25 -24
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/dashboard-plus-DowivGLd.js +0 -425
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
"use strict";var rt=t=>{throw TypeError(t)};var ps=(t,a,n)=>a.has(t)||rt("Cannot "+n);var re=(t,a,n)=>(ps(t,a,"read from private field"),n?n.call(t):a.get(t)),Fe=(t,a,n)=>a.has(t)?rt("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),Be=(t,a,n,r)=>(ps(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),Pe=(t,a,n)=>(ps(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-vGMyBsty.js"),M=require("react");require("react-dom");function Rn(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const ue=Rn(M);var Ne,Ce,de,je,ye,es,Ss,St,On=(St=class extends s.Subscribable{constructor(a,n){super();Fe(this,ye);Fe(this,Ne);Fe(this,Ce);Fe(this,de);Fe(this,je);Be(this,Ne,a),this.setOptions(n),this.bindMethods(),Pe(this,ye,es).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(a){var r;const n=this.options;this.options=re(this,Ne).defaultMutationOptions(a),s.shallowEqualObjects(this.options,n)||re(this,Ne).getMutationCache().notify({type:"observerOptionsUpdated",mutation:re(this,de),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&s.hashKey(n.mutationKey)!==s.hashKey(this.options.mutationKey)?this.reset():((r=re(this,de))==null?void 0:r.state.status)==="pending"&&re(this,de).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=re(this,de))==null||a.removeObserver(this)}onMutationUpdate(a){Pe(this,ye,es).call(this),Pe(this,ye,Ss).call(this,a)}getCurrentResult(){return re(this,Ce)}reset(){var a;(a=re(this,de))==null||a.removeObserver(this),Be(this,de,void 0),Pe(this,ye,es).call(this),Pe(this,ye,Ss).call(this)}mutate(a,n){var r;return Be(this,je,n),(r=re(this,de))==null||r.removeObserver(this),Be(this,de,re(this,Ne).getMutationCache().build(re(this,Ne),this.options)),re(this,de).addObserver(this),re(this,de).execute(a)}},Ne=new WeakMap,Ce=new WeakMap,de=new WeakMap,je=new WeakMap,ye=new WeakSet,es=function(){var n;const a=((n=re(this,de))==null?void 0:n.state)??s.getDefaultState();Be(this,Ce,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ss=function(a){s.notifyManager.batch(()=>{var n,r,o,i,c,l,u,m;if(re(this,je)&&this.hasListeners()){const d=re(this,Ce).variables,h=re(this,Ce).context;(a==null?void 0:a.type)==="success"?((r=(n=re(this,je)).onSuccess)==null||r.call(n,a.data,d,h),(i=(o=re(this,je)).onSettled)==null||i.call(o,a.data,null,d,h)):(a==null?void 0:a.type)==="error"&&((l=(c=re(this,je)).onError)==null||l.call(c,a.error,d,h),(m=(u=re(this,je)).onSettled)==null||m.call(u,void 0,a.error,d,h))}this.listeners.forEach(d=>{d(re(this,Ce))})})},St);function Ae(t,a){const n=s.useQueryClient(),[r]=ue.useState(()=>new On(n,t));ue.useEffect(()=>{r.setOptions(t)},[r,t]);const o=ue.useSyncExternalStore(ue.useCallback(c=>r.subscribe(s.notifyManager.batchCalls(c)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=ue.useCallback((c,l)=>{r.mutate(c,l).catch(s.noop)},[r]);if(o.error&&s.shouldThrowError(r.options.throwOnError,[o.error]))throw o.error;return{...o,mutate:i,mutateAsync:o.mutate}}/**
|
|
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 Fn=s.createLucideIcon("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 Bn=s.createLucideIcon("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 Pn=s.createLucideIcon("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 zn=s.createLucideIcon("ArrowDown10",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M17 10V4h-2",key:"zcsr5x"}],["path",{d:"M15 10h4",key:"id2lce"}],["rect",{x:"15",y:"14",width:"4",height:"6",ry:"2",key:"33xykx"}]]);/**
|
|
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 Vn=s.createLucideIcon("ArrowDownZA",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M15 4h5l-5 6h5",key:"8asdl1"}],["path",{d:"M15 20v-3.5a2.5 2.5 0 0 1 5 0V20",key:"r6l5cz"}],["path",{d:"M20 18h-5",key:"18j1r2"}]]);/**
|
|
27
|
-
* @license lucide-react v0.453.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const _n=s.createLucideIcon("ArrowLeftRight",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);/**
|
|
32
|
-
* @license lucide-react v0.453.0 - ISC
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the ISC license.
|
|
35
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const Un=s.createLucideIcon("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
37
|
-
* @license lucide-react v0.453.0 - ISC
|
|
38
|
-
*
|
|
39
|
-
* This source code is licensed under the ISC license.
|
|
40
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const qn=s.createLucideIcon("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
|
|
42
|
-
* @license lucide-react v0.453.0 - ISC
|
|
43
|
-
*
|
|
44
|
-
* This source code is licensed under the ISC license.
|
|
45
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const $n=s.createLucideIcon("ArrowUp01",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["rect",{x:"15",y:"4",width:"4",height:"6",ry:"2",key:"1bwicg"}],["path",{d:"M17 20v-6h-2",key:"1qp1so"}],["path",{d:"M15 20h4",key:"1j968p"}]]);/**
|
|
47
|
-
* @license lucide-react v0.453.0 - ISC
|
|
48
|
-
*
|
|
49
|
-
* This source code is licensed under the ISC license.
|
|
50
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const Yn=s.createLucideIcon("ArrowUpAZ",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
|
|
52
|
-
* @license lucide-react v0.453.0 - ISC
|
|
53
|
-
*
|
|
54
|
-
* This source code is licensed under the ISC license.
|
|
55
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const Gn=s.createLucideIcon("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);/**
|
|
57
|
-
* @license lucide-react v0.453.0 - ISC
|
|
58
|
-
*
|
|
59
|
-
* This source code is licensed under the ISC license.
|
|
60
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const Hn=s.createLucideIcon("BookOpenText",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M16 12h2",key:"7q9ll5"}],["path",{d:"M16 8h2",key:"msurwy"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}],["path",{d:"M6 12h2",key:"32wvfc"}],["path",{d:"M6 8h2",key:"30oboj"}]]);/**
|
|
62
|
-
* @license lucide-react v0.453.0 - ISC
|
|
63
|
-
*
|
|
64
|
-
* This source code is licensed under the ISC license.
|
|
65
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const wt=s.createLucideIcon("BookType",[["path",{d:"M10 13h4",key:"ytezjc"}],["path",{d:"M12 6v7",key:"1f6ttz"}],["path",{d:"M16 8V6H8v2",key:"x8j6u4"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
|
|
67
|
-
* @license lucide-react v0.453.0 - ISC
|
|
68
|
-
*
|
|
69
|
-
* This source code is licensed under the ISC license.
|
|
70
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const Qn=s.createLucideIcon("Box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/**
|
|
72
|
-
* @license lucide-react v0.453.0 - ISC
|
|
73
|
-
*
|
|
74
|
-
* This source code is licensed under the ISC license.
|
|
75
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
-
*/const Kn=s.createLucideIcon("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
|
|
77
|
-
* @license lucide-react v0.453.0 - ISC
|
|
78
|
-
*
|
|
79
|
-
* This source code is licensed under the ISC license.
|
|
80
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
-
*/const ot=s.createLucideIcon("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]);/**
|
|
82
|
-
* @license lucide-react v0.453.0 - ISC
|
|
83
|
-
*
|
|
84
|
-
* This source code is licensed under the ISC license.
|
|
85
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
-
*/const Dt=s.createLucideIcon("Calculator",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["line",{x1:"8",x2:"16",y1:"6",y2:"6",key:"x4nwl0"}],["line",{x1:"16",x2:"16",y1:"14",y2:"18",key:"wjye3r"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M8 18h.01",key:"lrp35t"}]]);/**
|
|
87
|
-
* @license lucide-react v0.453.0 - ISC
|
|
88
|
-
*
|
|
89
|
-
* This source code is licensed under the ISC license.
|
|
90
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
-
*/const kt=s.createLucideIcon("ChartArea",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M7 11.207a.5.5 0 0 1 .146-.353l2-2a.5.5 0 0 1 .708 0l3.292 3.292a.5.5 0 0 0 .708 0l4.292-4.292a.5.5 0 0 1 .854.353V16a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z",key:"q0gr47"}]]);/**
|
|
92
|
-
* @license lucide-react v0.453.0 - ISC
|
|
93
|
-
*
|
|
94
|
-
* This source code is licensed under the ISC license.
|
|
95
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
-
*/const cs=s.createLucideIcon("ChartColumnIncreasing",[["path",{d:"M13 17V9",key:"1fwyjl"}],["path",{d:"M18 17V5",key:"sfb6ij"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
|
|
97
|
-
* @license lucide-react v0.453.0 - ISC
|
|
98
|
-
*
|
|
99
|
-
* This source code is licensed under the ISC license.
|
|
100
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
-
*/const As=s.createLucideIcon("ChartColumnStacked",[["path",{d:"M11 13H7",key:"t0o9gq"}],["path",{d:"M19 9h-4",key:"rera1j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["rect",{x:"15",y:"5",width:"4",height:"12",rx:"1",key:"q8uenq"}],["rect",{x:"7",y:"8",width:"4",height:"9",rx:"1",key:"sr5ea"}]]);/**
|
|
102
|
-
* @license lucide-react v0.453.0 - ISC
|
|
103
|
-
*
|
|
104
|
-
* This source code is licensed under the ISC license.
|
|
105
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
-
*/const ds=s.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
|
|
107
|
-
* @license lucide-react v0.453.0 - ISC
|
|
108
|
-
*
|
|
109
|
-
* This source code is licensed under the ISC license.
|
|
110
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
-
*/const Wn=s.createLucideIcon("ChartNoAxesCombined",[["path",{d:"M12 16v5",key:"zza2cw"}],["path",{d:"M16 14v7",key:"1g90b9"}],["path",{d:"M20 10v11",key:"1iqoj0"}],["path",{d:"m22 3-8.646 8.646a.5.5 0 0 1-.708 0L9.354 8.354a.5.5 0 0 0-.707 0L2 15",key:"1fw8x9"}],["path",{d:"M4 18v3",key:"1yp0dc"}],["path",{d:"M8 14v7",key:"n3cwzv"}]]);/**
|
|
112
|
-
* @license lucide-react v0.453.0 - ISC
|
|
113
|
-
*
|
|
114
|
-
* This source code is licensed under the ISC license.
|
|
115
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
-
*/const Ls=s.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
117
|
-
* @license lucide-react v0.453.0 - ISC
|
|
118
|
-
*
|
|
119
|
-
* This source code is licensed under the ISC license.
|
|
120
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const us=s.createLucideIcon("ChartPie",[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]]);/**
|
|
122
|
-
* @license lucide-react v0.453.0 - ISC
|
|
123
|
-
*
|
|
124
|
-
* This source code is licensed under the ISC license.
|
|
125
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const Rs=s.createLucideIcon("ChartScatter",[["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}],["circle",{cx:"18.5",cy:"5.5",r:".5",fill:"currentColor",key:"lysivs"}],["circle",{cx:"11.5",cy:"11.5",r:".5",fill:"currentColor",key:"byv1b8"}],["circle",{cx:"7.5",cy:"16.5",r:".5",fill:"currentColor",key:"nkw3mc"}],["circle",{cx:"17.5",cy:"14.5",r:".5",fill:"currentColor",key:"1gjh6j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}]]);/**
|
|
127
|
-
* @license lucide-react v0.453.0 - ISC
|
|
128
|
-
*
|
|
129
|
-
* This source code is licensed under the ISC license.
|
|
130
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const Jn=s.createLucideIcon("CircleArrowRight",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m12 16 4-4-4-4",key:"1i9zcv"}]]);/**
|
|
132
|
-
* @license lucide-react v0.453.0 - ISC
|
|
133
|
-
*
|
|
134
|
-
* This source code is licensed under the ISC license.
|
|
135
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const Tt=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
|
|
137
|
-
* @license lucide-react v0.453.0 - ISC
|
|
138
|
-
*
|
|
139
|
-
* This source code is licensed under the ISC license.
|
|
140
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const it=s.createLucideIcon("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
|
|
142
|
-
* @license lucide-react v0.453.0 - ISC
|
|
143
|
-
*
|
|
144
|
-
* This source code is licensed under the ISC license.
|
|
145
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
-
*/const Xn=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
147
|
-
* @license lucide-react v0.453.0 - ISC
|
|
148
|
-
*
|
|
149
|
-
* This source code is licensed under the ISC license.
|
|
150
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
-
*/const Zn=s.createLucideIcon("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
|
|
152
|
-
* @license lucide-react v0.453.0 - ISC
|
|
153
|
-
*
|
|
154
|
-
* This source code is licensed under the ISC license.
|
|
155
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
-
*/const ea=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
|
|
157
|
-
* @license lucide-react v0.453.0 - ISC
|
|
158
|
-
*
|
|
159
|
-
* This source code is licensed under the ISC license.
|
|
160
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
161
|
-
*/const sa=s.createLucideIcon("DollarSign",[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]]);/**
|
|
162
|
-
* @license lucide-react v0.453.0 - ISC
|
|
163
|
-
*
|
|
164
|
-
* This source code is licensed under the ISC license.
|
|
165
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
166
|
-
*/const Os=s.createLucideIcon("Donut",[["path",{d:"M20.5 10a2.5 2.5 0 0 1-2.4-3H18a2.95 2.95 0 0 1-2.6-4.4 10 10 0 1 0 6.3 7.1c-.3.2-.8.3-1.2.3",key:"19sr3x"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
167
|
-
* @license lucide-react v0.453.0 - ISC
|
|
168
|
-
*
|
|
169
|
-
* This source code is licensed under the ISC license.
|
|
170
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
171
|
-
*/const Et=s.createLucideIcon("Expand",[["path",{d:"m21 21-6-6m6 6v-4.8m0 4.8h-4.8",key:"1c15vz"}],["path",{d:"M3 16.2V21m0 0h4.8M3 21l6-6",key:"1fsnz2"}],["path",{d:"M21 7.8V3m0 0h-4.8M21 3l-6 6",key:"hawz9i"}],["path",{d:"M3 7.8V3m0 0h4.8M3 3l6 6",key:"u9ee12"}]]);/**
|
|
172
|
-
* @license lucide-react v0.453.0 - ISC
|
|
173
|
-
*
|
|
174
|
-
* This source code is licensed under the ISC license.
|
|
175
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
176
|
-
*/const ta=s.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
|
|
177
|
-
* @license lucide-react v0.453.0 - ISC
|
|
178
|
-
*
|
|
179
|
-
* This source code is licensed under the ISC license.
|
|
180
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
181
|
-
*/const na=s.createLucideIcon("FileCode2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
|
|
182
|
-
* @license lucide-react v0.453.0 - ISC
|
|
183
|
-
*
|
|
184
|
-
* This source code is licensed under the ISC license.
|
|
185
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
186
|
-
*/const aa=s.createLucideIcon("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
|
|
187
|
-
* @license lucide-react v0.453.0 - ISC
|
|
188
|
-
*
|
|
189
|
-
* This source code is licensed under the ISC license.
|
|
190
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
-
*/const ra=s.createLucideIcon("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
|
|
192
|
-
* @license lucide-react v0.453.0 - ISC
|
|
193
|
-
*
|
|
194
|
-
* This source code is licensed under the ISC license.
|
|
195
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
196
|
-
*/const oa=s.createLucideIcon("Fingerprint",[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]]);/**
|
|
197
|
-
* @license lucide-react v0.453.0 - ISC
|
|
198
|
-
*
|
|
199
|
-
* This source code is licensed under the ISC license.
|
|
200
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
201
|
-
*/const ia=s.createLucideIcon("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);/**
|
|
202
|
-
* @license lucide-react v0.453.0 - ISC
|
|
203
|
-
*
|
|
204
|
-
* This source code is licensed under the ISC license.
|
|
205
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
206
|
-
*/const la=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"}]]);/**
|
|
207
|
-
* @license lucide-react v0.453.0 - ISC
|
|
208
|
-
*
|
|
209
|
-
* This source code is licensed under the ISC license.
|
|
210
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
211
|
-
*/const ca=s.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
212
|
-
* @license lucide-react v0.453.0 - ISC
|
|
213
|
-
*
|
|
214
|
-
* This source code is licensed under the ISC license.
|
|
215
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
216
|
-
*/const da=s.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
|
|
217
|
-
* @license lucide-react v0.453.0 - ISC
|
|
218
|
-
*
|
|
219
|
-
* This source code is licensed under the ISC license.
|
|
220
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
221
|
-
*/const $e=s.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
|
|
222
|
-
* @license lucide-react v0.453.0 - ISC
|
|
223
|
-
*
|
|
224
|
-
* This source code is licensed under the ISC license.
|
|
225
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
226
|
-
*/const ua=s.createLucideIcon("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);/**
|
|
227
|
-
* @license lucide-react v0.453.0 - ISC
|
|
228
|
-
*
|
|
229
|
-
* This source code is licensed under the ISC license.
|
|
230
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
-
*/const ma=s.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
|
|
232
|
-
* @license lucide-react v0.453.0 - ISC
|
|
233
|
-
*
|
|
234
|
-
* This source code is licensed under the ISC license.
|
|
235
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
236
|
-
*/const ha=s.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
|
|
237
|
-
* @license lucide-react v0.453.0 - ISC
|
|
238
|
-
*
|
|
239
|
-
* This source code is licensed under the ISC license.
|
|
240
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
-
*/const xa=s.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
|
|
242
|
-
* @license lucide-react v0.453.0 - ISC
|
|
243
|
-
*
|
|
244
|
-
* This source code is licensed under the ISC license.
|
|
245
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
-
*/const pa=s.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
|
|
247
|
-
* @license lucide-react v0.453.0 - ISC
|
|
248
|
-
*
|
|
249
|
-
* This source code is licensed under the ISC license.
|
|
250
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
251
|
-
*/const It=s.createLucideIcon("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);/**
|
|
252
|
-
* @license lucide-react v0.453.0 - ISC
|
|
253
|
-
*
|
|
254
|
-
* This source code is licensed under the ISC license.
|
|
255
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
256
|
-
*/const fa=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
|
|
257
|
-
* @license lucide-react v0.453.0 - ISC
|
|
258
|
-
*
|
|
259
|
-
* This source code is licensed under the ISC license.
|
|
260
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
-
*/const ga=s.createLucideIcon("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
|
|
262
|
-
* @license lucide-react v0.453.0 - ISC
|
|
263
|
-
*
|
|
264
|
-
* This source code is licensed under the ISC license.
|
|
265
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
-
*/const lt=s.createLucideIcon("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/**
|
|
267
|
-
* @license lucide-react v0.453.0 - ISC
|
|
268
|
-
*
|
|
269
|
-
* This source code is licensed under the ISC license.
|
|
270
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
271
|
-
*/const Fs=s.createLucideIcon("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
|
|
272
|
-
* @license lucide-react v0.453.0 - ISC
|
|
273
|
-
*
|
|
274
|
-
* This source code is licensed under the ISC license.
|
|
275
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
276
|
-
*/const ja=s.createLucideIcon("MessageCircleMore",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]]);/**
|
|
277
|
-
* @license lucide-react v0.453.0 - ISC
|
|
278
|
-
*
|
|
279
|
-
* This source code is licensed under the ISC license.
|
|
280
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
281
|
-
*/const ya=s.createLucideIcon("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
|
|
282
|
-
* @license lucide-react v0.453.0 - ISC
|
|
283
|
-
*
|
|
284
|
-
* This source code is licensed under the ISC license.
|
|
285
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
286
|
-
*/const ct=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
|
|
287
|
-
* @license lucide-react v0.453.0 - ISC
|
|
288
|
-
*
|
|
289
|
-
* This source code is licensed under the ISC license.
|
|
290
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
-
*/const dt=s.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
|
|
292
|
-
* @license lucide-react v0.453.0 - ISC
|
|
293
|
-
*
|
|
294
|
-
* This source code is licensed under the ISC license.
|
|
295
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
296
|
-
*/const va=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
|
|
297
|
-
* @license lucide-react v0.453.0 - ISC
|
|
298
|
-
*
|
|
299
|
-
* This source code is licensed under the ISC license.
|
|
300
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
301
|
-
*/const ba=s.createLucideIcon("PenLine",[["path",{d:"M12 20h9",key:"t2du7b"}],["path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z",key:"1ykcvy"}]]);/**
|
|
302
|
-
* @license lucide-react v0.453.0 - ISC
|
|
303
|
-
*
|
|
304
|
-
* This source code is licensed under the ISC license.
|
|
305
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
306
|
-
*/const Na=s.createLucideIcon("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
|
|
307
|
-
* @license lucide-react v0.453.0 - ISC
|
|
308
|
-
*
|
|
309
|
-
* This source code is licensed under the ISC license.
|
|
310
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
-
*/const Bs=s.createLucideIcon("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]);/**
|
|
312
|
-
* @license lucide-react v0.453.0 - ISC
|
|
313
|
-
*
|
|
314
|
-
* This source code is licensed under the ISC license.
|
|
315
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
316
|
-
*/const Mt=s.createLucideIcon("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
317
|
-
* @license lucide-react v0.453.0 - ISC
|
|
318
|
-
*
|
|
319
|
-
* This source code is licensed under the ISC license.
|
|
320
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
321
|
-
*/const Ca=s.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
|
|
322
|
-
* @license lucide-react v0.453.0 - ISC
|
|
323
|
-
*
|
|
324
|
-
* This source code is licensed under the ISC license.
|
|
325
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
326
|
-
*/const ws=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
327
|
-
* @license lucide-react v0.453.0 - ISC
|
|
328
|
-
*
|
|
329
|
-
* This source code is licensed under the ISC license.
|
|
330
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
331
|
-
*/const Sa=s.createLucideIcon("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);/**
|
|
332
|
-
* @license lucide-react v0.453.0 - ISC
|
|
333
|
-
*
|
|
334
|
-
* This source code is licensed under the ISC license.
|
|
335
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
336
|
-
*/const Ye=s.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
|
|
337
|
-
* @license lucide-react v0.453.0 - ISC
|
|
338
|
-
*
|
|
339
|
-
* This source code is licensed under the ISC license.
|
|
340
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
341
|
-
*/const Ge=s.createLucideIcon("Share2",[["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}],["circle",{cx:"6",cy:"12",r:"3",key:"w7nqdw"}],["circle",{cx:"18",cy:"19",r:"3",key:"1xt0gg"}],["line",{x1:"8.59",x2:"15.42",y1:"13.51",y2:"17.49",key:"47mynk"}],["line",{x1:"15.41",x2:"8.59",y1:"6.51",y2:"10.49",key:"1n3mei"}]]);/**
|
|
342
|
-
* @license lucide-react v0.453.0 - ISC
|
|
343
|
-
*
|
|
344
|
-
* This source code is licensed under the ISC license.
|
|
345
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
346
|
-
*/const wa=s.createLucideIcon("Share",[["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}],["polyline",{points:"16 6 12 2 8 6",key:"m901s6"}],["line",{x1:"12",x2:"12",y1:"2",y2:"15",key:"1p0rca"}]]);/**
|
|
347
|
-
* @license lucide-react v0.453.0 - ISC
|
|
348
|
-
*
|
|
349
|
-
* This source code is licensed under the ISC license.
|
|
350
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
351
|
-
*/const Da=s.createLucideIcon("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);/**
|
|
352
|
-
* @license lucide-react v0.453.0 - ISC
|
|
353
|
-
*
|
|
354
|
-
* This source code is licensed under the ISC license.
|
|
355
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
356
|
-
*/const At=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
|
|
357
|
-
* @license lucide-react v0.453.0 - ISC
|
|
358
|
-
*
|
|
359
|
-
* This source code is licensed under the ISC license.
|
|
360
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
361
|
-
*/const ka=s.createLucideIcon("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);/**
|
|
362
|
-
* @license lucide-react v0.453.0 - ISC
|
|
363
|
-
*
|
|
364
|
-
* This source code is licensed under the ISC license.
|
|
365
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
366
|
-
*/const Ta=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
367
|
-
* @license lucide-react v0.453.0 - ISC
|
|
368
|
-
*
|
|
369
|
-
* This source code is licensed under the ISC license.
|
|
370
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
371
|
-
*/const He=s.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
|
|
372
|
-
* @license lucide-react v0.453.0 - ISC
|
|
373
|
-
*
|
|
374
|
-
* This source code is licensed under the ISC license.
|
|
375
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
376
|
-
*/const Lt=s.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
|
|
377
|
-
* @license lucide-react v0.453.0 - ISC
|
|
378
|
-
*
|
|
379
|
-
* This source code is licensed under the ISC license.
|
|
380
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
381
|
-
*/const Ea=s.createLucideIcon("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);/**
|
|
382
|
-
* @license lucide-react v0.453.0 - ISC
|
|
383
|
-
*
|
|
384
|
-
* This source code is licensed under the ISC license.
|
|
385
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
386
|
-
*/const ts=s.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
|
|
387
|
-
* @license lucide-react v0.453.0 - ISC
|
|
388
|
-
*
|
|
389
|
-
* This source code is licensed under the ISC license.
|
|
390
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
391
|
-
*/const Ps=s.createLucideIcon("Tornado",[["path",{d:"M21 4H3",key:"1hwok0"}],["path",{d:"M18 8H6",key:"41n648"}],["path",{d:"M19 12H9",key:"1g4lpz"}],["path",{d:"M16 16h-6",key:"1j5d54"}],["path",{d:"M11 20H9",key:"39obr8"}]]);/**
|
|
392
|
-
* @license lucide-react v0.453.0 - ISC
|
|
393
|
-
*
|
|
394
|
-
* This source code is licensed under the ISC license.
|
|
395
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
396
|
-
*/const Qe=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
|
|
397
|
-
* @license lucide-react v0.453.0 - ISC
|
|
398
|
-
*
|
|
399
|
-
* This source code is licensed under the ISC license.
|
|
400
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
401
|
-
*/const we=s.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/**
|
|
402
|
-
* @license lucide-react v0.453.0 - ISC
|
|
403
|
-
*
|
|
404
|
-
* This source code is licensed under the ISC license.
|
|
405
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
406
|
-
*/const ve=s.createLucideIcon("Users",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["path",{d:"M16 3.13a4 4 0 0 1 0 7.75",key:"1da9ce"}]]);function ns(t){var a;return{...t,sheets:(a=t==null?void 0:t.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(c=>Rt(c))}})}})}}function Rt(t){return{...t,customCfg:Ia(t.customCfg),data:[]}}function Ia(t){var a,n;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(n=(a=t==null?void 0:t.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Ma(t,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:n,operation:"create"})}async function Ds(t,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:i,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:i,shared:c,operation:"update"})}async function Aa(t,a){return a?await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:t}):null}function La(){const[t,a]=M.useState(""),[n,r]=M.useState(!1),o=s.useDashboardStore(p=>p.lenses),{setLenses:i,setSelectedLensId:c}=s.useDashboardActions(),[l,u]=M.useState(!1),[m,d]=M.useState(!1),h=s.useDashboardStore(p=>p.dashboard),x=s.useDashboardStore(p=>p.filterValues),{authToken:f}=s.useSemaphorContext();async function g(){u(!0);const p=ns(h),v=await Ma(t,p,x,f==null?void 0:f.accessToken);v&&(i([...o||[],v]),c(v.id),d(!1)),u(!1)}return e.jsxs(s.Dialog,{open:m,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,{value:t,onChange:p=>{a(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&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:g,disabled:l,children:l?"Creating...":"Add"})})]})]})}function Ra(){const[t,a]=M.useState(!1),n=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function l(d){i(d)}async function u(d){if(await Aa(d,c==null?void 0:c.accessToken)){const x=n==null?void 0:n.filter(f=>f.id!==d);o(x||[]),i("original")}}async function m(d){const h=n==null?void 0:n.map(g=>g.id===d.id?{...g,isDefault:!d.isDefault}:{...g,isDefault:!1});o(h||[]);const x={...d,isDefault:!d.isDefault};await Ds(x,c==null?void 0:c.accessToken);const f=n==null?void 0:n.find(g=>g.isDefault);if(f&&f.id!==d.id){const g={...f,isDefault:!1};await Ds(g,c==null?void 0:c.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:a,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(la,{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:l,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),m(d)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),u(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}function Ot(){var i;const t=s.useDashboardStore.getState().authToken,a=s.useDashboardStore.getState().theme,n=s.useDashboardStore.getState().filterValues,r=(i=s.useDashboardStore.getState().dashboard)==null?void 0:i.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function Ft(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:i}=Ot();if(t)return;const c=new URLSearchParams;c.set("token",(a==null?void 0:a.accessToken)||""),c.set("theme",n),c.set("filterValues",JSON.stringify(r)),c.set("selectedSheetId",i||"");const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const d=(await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,h=document.createElement("a");h.href=d;const x=`${o}-${new Date().toISOString()}.pdf`;h.download=x,h.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Oa({iconClassName:t}){const{authToken:a}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const n=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ft()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(s.LoaderCircle,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function he({defaultValue:t,label:a,options:n,value:r,onValueChange:o,className:i,icon:c,showPlaceholderLabel:l=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:o,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",i),children:e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("span",{children:c}),l&&e.jsx(s.SelectValue,{placeholder:a})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:a}),n.map(u=>e.jsx(s.SelectItem,{value:u.value,children:u.label},u.value))]})})]})}const ut=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Bt({triggerButtonClassName:t}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:i,isDeleting:c}=Fa(),[l,u]=M.useState(""),[m,d]=M.useState(ut[0].value),[h,x]=M.useState("06:00"),[f,g]=M.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(s.Clock,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:l,onChange:p=>u(p.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(s.Input,{id:"subject",placeholder:"Monthly Sales Report",value:f,onChange:p=>{g(p.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(he,{className:"col-span-2 h-8",label:"Select Frequency",options:ut,value:m,onValueChange:p=>d(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"time",children:"Time"}),e.jsx(s.Input,{id:"time",type:"time",value:h,onChange:p=>x(p.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await n({email:l,frequency:m,time:h,subject:f}),x("00:00"),u(""),g("")},className:"h-8 p-2",disabled:o==="loading"||!l,children:[o==="loading"&&e.jsx(s.LoaderCircle,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(Tt,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:i})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),s.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(p=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[s.titleCase(p.frequency)," "]}),e.jsx(s.Label,{children:p.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(mt,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(Jn,{className:"size-3.5"})}),e.jsx(mt,{tooltip:`${p.endUserEmail}`,children:e.jsx(ga,{className:"size-3.5"})}),c===p.id?e.jsx(s.LoaderCircle,{className:"size-3.5 animate-spin"}):e.jsx(s.Trash2,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const mt=({children:t,tooltip:a})=>e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:t}),e.jsx(s.TooltipContent,{children:a})]})});function Fa(){const[t,a]=M.useState("idle"),[n,r]=M.useState(""),[o,i]=M.useState(null),c=s.useDashboardStore(k=>k.authToken),l=s.useDashboardStore(k=>k.dashboard.id),u=s.useDashboardStore(k=>k.dashboard.title),{endUserId:m}=s.getTenantAndEndUserId((c==null?void 0:c.accessToken)||""),d="https://semaphor.cloud/api/v1/subscriptions/get",h={dashboardId:l,endUserId:m},{data:x,isLoading:f,isError:g,isFetching:p,refetch:v}=s.useQuery({queryKey:["subscriptions",l,m],queryFn:()=>s.getRequest(d,(c==null?void 0:c.accessToken)||"",h),enabled:!!(c!=null&&c.accessToken)&&!!l&&!!m});async function j({email:k,subject:O,frequency:T,time:S}){const{authToken:y,...D}=Ot(),b=Intl.DateTimeFormat().resolvedOptions().timeZone,A={email:k,frequency:T,time:S,timezone:b,endUserId:m,endUserEmail:k,subject:O||u||"Scheduled Dashboard",dashboardId:l,dashboardParams:D};a("loading");const C="https://semaphor.cloud/api/v1/subscriptions/create";try{const R=await s.postRequestRegular(C,(y==null?void 0:y.accessToken)||"",{...A});a("success"),r(""),v(),setTimeout(()=>{a("idle")},2e3)}catch(R){console.error(R),a("error"),r(R.message)}}async function w(k){const O="https://semaphor.cloud/api/v1/subscriptions/delete";i(k);try{await s.postRequestRegular(O,(c==null?void 0:c.accessToken)||"",{id:k}),v(),setTimeout(()=>{i(null)},2e3)}catch(T){console.error(T),i(null),a("error"),r(T.message)}}return{data:x,isLoading:f,isFetching:p,isError:g,isDeleting:o,refetch:v,handleScheduleSubscription:j,handleDeleteSubscription:w,status:t,error:n}}function Le(){const{authToken:t,tokenProps:a}=s.useSemaphorContext();let n=null;a&&(a.endUserId&&a.endUserEmail&&a.tenantId?n={id:a.endUserId,name:a.endUserEmail?String(a.displayName):"",email:a.endUserEmail?String(a.endUserEmail):"",type:"tenant",tenantId:a.tenantId}:a.orgUserId&&a.orgUserEmail&&(n={id:a.orgUserId,name:a.orgUserEmail?String(a.displayName):"",email:a.orgUserEmail?String(a.orgUserEmail):"",type:"organization"}));const{data:r,isLoading:o,isError:i}=s.useQuery({queryKey:["userInfo",n==null?void 0:n.id],queryFn:async()=>{if(!(n!=null&&n.id))return;const l=await fetch(`https://semaphor.cloud/api/management/v1/unified-users/${n.id}`,{headers:{Authorization:`Bearer ${(t==null?void 0:t.accessToken)||""}`,"Content-Type":"application/json"}});if(!l.ok)throw new Error("Failed to fetch user info");return(await l.json()).user},enabled:!!(t!=null&&t.accessToken)&&!!(n!=null&&n.id)});return{currentUser:n?{...n,...r||{}}:null,isLoading:o,isError:i}}function Pt(){return e.jsx(s.ScrollArea,{className:"w-full flex-1",children:e.jsxs("div",{className:"space-y-4 px-4",children:[e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"space-y-2",children:[...Array(4)].map((t,a)=>e.jsx("div",{className:"animate-pulse",children:e.jsxs("div",{className:"group relative flex items-start gap-3 px-4 py-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-muted"})}),e.jsxs("div",{className:"flex w-full items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})}),e.jsx("div",{className:"shrink-0",children:e.jsx("div",{className:"h-3.5 w-3.5 rounded bg-muted"})})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx("div",{className:"h-3 w-48 rounded bg-muted"})})]}),e.jsx("div",{className:"absolute right-3 top-2",children:e.jsx("div",{className:"flex items-center opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:e.jsx("div",{className:"h-6 w-6 rounded bg-muted"})})})]})]})},a))})]})})}var ee=(t=>(t.DASHBOARD="dashboard",t.VISUAL="visual",t))(ee||{});const Ba=async(t,a,n,r,o,i)=>{const c={},l={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${l[a]}`,t,c)},Pa=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}`,t,n)},za=async(t,a,n,r)=>{const o={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};console.log("data",r);const i=await fetch(`https://semaphor.cloud/api/management/v1/${o[a]}/${n}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(r)});if(!i.ok){const c=await i.json();throw new Error((c==null?void 0:c.error)||`HTTP error! status: ${i.status}`)}return i.json()},Va=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"},o=await fetch(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}});if(!o.ok){const i=await o.json();throw new Error((i==null?void 0:i.error)||`HTTP error! status: ${o.status}`)}return o.json()},_a=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/duplicate`,t,{})},Ua=async(t,a,n,r)=>{const o={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${o[a]}/${n}/share`,t,r)},qa=async(t,a,n,r)=>{const o={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"},i=await fetch(`https://semaphor.cloud/api/management/v1/${o[a]}/${n}/share`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(r)});if(!i.ok){const c=await i.json();throw new Error((c==null?void 0:c.error)||`HTTP error! status: ${i.status}`)}return i.json()},$a=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/shares`,t)},Ya=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}`,t)};function Ga(t){const{authToken:a}=s.useSemaphorContext();return s.useQuery({queryKey:["tenants"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/management/v1/tenants",(a==null?void 0:a.accessToken)||""),enabled:(t==null?void 0:t.enabled)!==void 0?t.enabled&&!!(a!=null&&a.accessToken):!!(a!=null&&a.accessToken)})}function Ha(t,a,n,r,o){const{authToken:i}=s.useSemaphorContext(),{currentUser:c}=Le();return s.useQuery({queryKey:[t,a,n,r,o],queryFn:()=>Ba((i==null?void 0:i.accessToken)||"",t),enabled:!!(i!=null&&i.accessToken)&&!!c})}function Qa(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Ae({mutationFn:o=>Pa((n==null?void 0:n.accessToken)||"",t,o),onMutate:async()=>{await r.cancelQueries({queryKey:[t]})},onSuccess:async()=>{await r.invalidateQueries({queryKey:[t]}),s.ue.success(`${s.toTitleCase(t)} created successfully`),a==null||a()},onError:o=>{s.ue.error(`Failed to create ${s.toTitleCase(t)}: ${o.message}`)}})}function zt(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Ae({mutationFn:({resourceId:r,data:o})=>za((a==null?void 0:a.accessToken)||"",t,r,o),onMutate:async()=>{await n.cancelQueries({queryKey:[t]})},onSuccess:async()=>{await n.invalidateQueries({queryKey:[t]})},onError:r=>{s.ue.error(`Failed to update ${s.toTitleCase(t)}: ${r.message}`)}})}function Ka(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Ae({mutationFn:o=>Va((n==null?void 0:n.accessToken)||"",t,o),onMutate:async()=>{await r.cancelQueries({queryKey:[t]})},onSuccess:async()=>{await r.invalidateQueries({queryKey:[t]}),s.ue.success(`${s.toTitleCase(t)} deleted successfully`),a==null||a()},onError:o=>{s.ue.error(`Failed to delete ${s.toTitleCase(t)}: ${o.message}`)}})}function Wa(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Ae({mutationFn:r=>_a((a==null?void 0:a.accessToken)||"",t,r),onMutate:async()=>{await n.cancelQueries({queryKey:[t]})},onSuccess:async()=>{await n.invalidateQueries({queryKey:[t]}),s.ue.success(`${s.toTitleCase(t)} duplicated successfully`)},onError:r=>{s.ue.error(`Failed to duplicate ${s.toTitleCase(t)}: ${r.message}`)}})}function Ja(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ae({mutationFn:({resourceType:n,resourceId:r,data:o})=>Ua((t==null?void 0:t.accessToken)||"",n,r,o),onMutate:async n=>{await a.cancelQueries({queryKey:["resource-shares",n.resourceType,n.resourceId]})},onSuccess:async(n,r)=>{await a.invalidateQueries({queryKey:["resource-shares",r.resourceType,r.resourceId]}),a.invalidateQueries({queryKey:[r.resourceType]})},onError:n=>{s.ue.error(`Failed to share resource: ${n.message}`)}})}function Xa(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ae({mutationFn:({resourceType:n,resourceId:r,data:o})=>qa((t==null?void 0:t.accessToken)||"",n,r,o),onMutate:async n=>{await a.cancelQueries({queryKey:["resource-shares",n.resourceType,n.resourceId]})},onSuccess:async(n,r)=>{await a.invalidateQueries({queryKey:["resource-shares",r.resourceType,r.resourceId]}),a.invalidateQueries({queryKey:[r.resourceType]})},onError:n=>{s.ue.error(`Failed to remove resource shares: ${n.message}`)}})}function Za(t,a){const{authToken:n}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-shares",t,a],queryFn:()=>$a((n==null?void 0:n.accessToken)||"",t,a),enabled:!!(n!=null&&n.accessToken)&&!!a})}function er(t,a,n){const{authToken:r}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-by-id",t,a],queryFn:()=>Ya((r==null?void 0:r.accessToken)||"",t,a),enabled:(n==null?void 0:n.enabled)!==void 0?n.enabled&&!!(r!=null&&r.accessToken)&&!!a:!!(r!=null&&r.accessToken)&&!!a})}function sr(t,a){return er(ee.VISUAL,t,a)}function Vt(){const[t,a]=M.useState(new Map),n=M.useCallback((i,c)=>{a(l=>{const u=new Map(l),m=new Set(u.get(i)||[]);return c?m.add(c):(m.add("title"),m.add("description")),u.set(i,m),u})},[]),r=M.useCallback((i,c)=>{a(l=>{const u=new Map(l),m=new Set(u.get(i)||[]);return c?m.delete(c):m.clear(),m.size===0?u.delete(i):u.set(i,m),u})},[]),o=M.useCallback((i,c)=>{const l=t.get(i);return l?c?l.has(c):l.size>0:!1},[t]);return{startUpdating:n,stopUpdating:r,isUpdating:o}}function _t(t,a,n){var h;const r=Ha(t),o=Qa(t,n),i=zt(t),c=Ka(t,a),l=Wa(t),u=Ja(),m=Xa(),d={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return{resources:((h=r.data)==null?void 0:h[d[t]])||[],isLoading:r.isLoading,isError:r.isError,isFetching:r.isFetching,error:r.error,createResource:o.mutate,updateResource:i.mutate,deleteResource:c.mutate,duplicateResource:l.mutate,shareResource:u.mutate,removeResourceShares:m.mutate,isCreating:o.isPending,isUpdating:i.isPending,isDeleting:c.isPending,isDuplicating:l.isPending,isSharing:u.isPending,isRemovingShares:m.isPending,isUpdatingShares:u.isPending,refetch:r.refetch}}function tr(t,a){return _t(ee.DASHBOARD,t,a)}function nr(t,a){return _t(ee.VISUAL,t,a)}function ar(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ae({mutationFn:async({visualId:n,data:r})=>{const o=await fetch(`https://semaphor.cloud/api/management/v1/visuals/${n}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t==null?void 0:t.accessToken}`},body:JSON.stringify(r)});if(!o.ok)throw new Error("Failed to update visual");return o.json()},onSuccess:()=>{s.ue.success("Visual updated successfully"),a.invalidateQueries({queryKey:["visuals"]})},onError:()=>{s.ue.error("Failed to update visual")}})}function rr({visual:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:o=!1,onAddVisual:i,onEditVisual:c,onUpdateVisual:l,onDeleteClick:u,onDuplicateVisual:m,onShareVisual:d,formatDate:h}){var S;const{selectVisual:x}=s.useManagementActions(),f=s.useIsVisualSelected(t.id),g=s.useDashboardStore(y=>y.actions.setIsDashboardPanelOpen),[p,v]=M.useState(!1),[j,w]=M.useState(!1);M.useEffect(()=>{n?(v(!0),w(!0)):j&&(v(!1),w(!1))},[n,j]);const k=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx(It,{className:"h-3 w-3 text-purple-500"}):e.jsx(ve,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(we,{className:"h-3.5 w-3.5 text-slate-500"}),O=()=>e.jsx(s.ChartColumn,{className:"h-4 w-4 text-slate-400"}),T=()=>{x(t),c==null||c(t)};return e.jsxs("div",{className:s.cn("group relative flex cursor-pointer items-start gap-3 px-4 py-3 dark:border-slate-800","cursor-pointer transition-colors duration-150 hover:bg-slate-50 dark:hover:bg-slate-900/50",t.ownership.isOwner&&"border-blue-200 dark:border-blue-800",f&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:T,children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-slate-100 dark:bg-slate-800",children:O()})}),e.jsxs("div",{className:"flex w-full items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.EditableText,{inputClassName:"text-sm font-medium text-slate-900 dark:text-slate-100",value:t.title,onSave:y=>l==null?void 0:l(t.id,{title:y}),isEditable:t.ownership.isOwner&&f,isPending:r,placeholder:"Untitled Visual",displayClassName:"line-clamp-1 max-w-[150px] text-sm font-medium text-slate-900 dark:text-slate-100"})}),e.jsx("div",{className:"shrink-0",children:k()})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx(s.EditableText,{inputClassName:"line-clamp-1 text-xs text-slate-500 dark:text-slate-400",value:t.description||"",onSave:y=>l==null?void 0:l(t.id,{description:y}),isEditable:t.ownership.isOwner&&f,isPending:o,placeholder:"No description",displayClassName:"mt-0.5 max-w-[220px] line-clamp-1 text-xs text-slate-500 dark:text-slate-400"})})]}),e.jsx("div",{className:"absolute right-3 top-2 flex items-center justify-between text-xs text-muted-foreground",children:e.jsxs("div",{className:s.cn("flex items-center opacity-0 transition-opacity duration-150 group-hover:opacity-100"),children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 hover:bg-slate-200 dark:hover:bg-slate-700",onClick:y=>{y.stopPropagation(),i(t)},children:e.jsx(s.Plus,{className:"h-3.5 w-3.5"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:p,onOpenChange:v,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 hover:bg-slate-200 dark:hover:bg-slate-700",onClick:y=>y.stopPropagation(),children:e.jsx(s.Ellipsis,{className:"h-3 w-3"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),i(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.preventDefault(),y.stopPropagation(),m(t.id)},disabled:n,children:[n?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),n?"Duplicating...":"Duplicate"]}),t.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),c==null||c(t)},children:[e.jsx(ba,{className:"mr-2 h-3 w-3"}),"Edit"]}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),d(t)},children:[e.jsx(ve,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),u(t),g(!1)},className:"text-destructive",disabled:a,children:[e.jsx(s.Trash2,{className:"mr-2 h-3 w-3"}),a?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:((S=t.ownership.createdBy)==null?void 0:S.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:h(t.lastModified)})]})]})]})]})]})})]})]},t.id)}function Ut({value:t,onChange:a,placeholder:n="Search users by name, email, or department..."}){return 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:n,value:t,onChange:r=>a(r.target.value),className:"pl-9"})]})}function as({currentRole:t,onRoleChange:a,roleOptions:n,disabled:r=!1,className:o="",allowDropdown:i=!0}){var u;const c=((u=n.find(m=>m.value===t))==null?void 0:u.label)||t,l=n.filter(m=>m.value!==t);return i?e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"outline",className:`cursor-pointer hover:bg-muted ${r?"cursor-not-allowed opacity-50":""} ${o}`,onClick:()=>console.log("Badge clicked:",{currentRole:t,disabled:r,allowDropdown:i}),children:c})}),e.jsx(s.DropdownMenuContent,{className:"z-[51]",children:l.map(m=>e.jsx(s.DropdownMenuItem,{onClick:()=>{console.log("Dropdown item clicked:",{currentRole:t,newRole:m.value,disabled:r}),a(m.value)},disabled:r,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]})},m.value))})]}):e.jsx(s.Badge,{variant:"outline",className:`text-xs ${o}`,children:c})}function qt({selectedUsers:t,selectedUserObjects:a,onRemove:n,onRoleChange:r,getRoleOptions:o}){return t.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{className:"text-sm font-medium",children:["Selected Users (",t.length,")"]}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>t.forEach(i=>n(i.id)),className:"h-auto p-1 text-xs",children:"Clear all"})]}),e.jsx("div",{className:"flex max-h-20 flex-wrap gap-2 overflow-y-auto",children:a.map(i=>{const c=t.find(u=>u.id===i.id),l=o(i.type);return e.jsxs(s.Badge,{variant:"secondary",className:"gap-1",children:[i.name,e.jsx(as,{currentRole:(c==null?void 0:c.role)||"VIEWER",onRoleChange:u=>r(i.id,u),roleOptions:l}),e.jsx("button",{onClick:()=>n(i.id),className:"ml-1 rounded-full p-0.5 hover:bg-muted-foreground/20",children:e.jsx(s.X,{className:"h-3 w-3"})})]},i.id)})}),e.jsx(s.Separator,{})]})}function $t({usersToRemove:t,allUsers:a,onRemove:n}){return t.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{className:"text-sm font-medium text-destructive",children:["Users to Remove Access (",t.length,")"]}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>t.forEach(r=>n(r)),className:"h-auto p-1 text-xs text-destructive hover:text-destructive",children:"Clear all"})]}),e.jsx("div",{className:"flex max-h-20 flex-wrap gap-2 overflow-y-auto",children:a.filter(r=>t.includes(r.id)).map(r=>e.jsxs(s.Badge,{variant:"destructive",className:"gap-1",children:[r.name,e.jsx("button",{onClick:()=>n(r.id),className:"ml-1 rounded-full p-0.5 hover:bg-destructive-foreground/20",children:e.jsx(s.X,{className:"h-3 w-3"})})]},r.id))}),e.jsx(s.Separator,{})]})}function Yt({usersToUpdate:t,allUsers:a,onRemove:n,getRoleOptions:r}){if(t.length===0)return null;const o=r("tenant"),i=l=>{const u=a.find(m=>m.id===l);return(u==null?void 0:u.name)||"Unknown User"},c=l=>{const u=o.find(m=>m.value===l);return(u==null?void 0:u.label)||l};return e.jsxs("div",{className:"rounded-lg border border-orange-200 bg-orange-50 p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4 text-orange-600"}),e.jsxs("span",{className:"text-sm font-medium text-orange-800",children:["Updating Access (",t.length,")"]})]}),e.jsx("div",{className:"space-y-2",children:t.map(l=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:i(l.id)}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:c(l.currentRole)}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx(s.Badge,{variant:"default",className:"text-xs",children:c(l.newRole)})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>n(l.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},l.id))})]})}function Gt(t,a={}){const{enabled:n=!0,eventType:r="mousedown"}=a,o=M.useRef(null);return M.useEffect(()=>{const i=c=>{const l=c.target;o.current&&o.current.contains(l)||l instanceof Element&&(l.closest("[data-radix-popper-content-wrapper]")||l.closest("[data-radix-select-content]")||l.closest("[data-radix-popover-content]")||l.closest("[data-radix-dropdown-menu-content]")||l.closest("[data-radix-tooltip-content]")||l.closest('[role="listbox"]')||l.closest('[role="option"]')||l.closest('[role="combobox"]'))||l instanceof Element&&l.hasAttribute("data-radix-")||t()};return n&&document.addEventListener(r,i),()=>{document.removeEventListener(r,i)}},[t,n,r]),o}function pe(t,a){var n;return((n=a.find(r=>r.value===t))==null?void 0:n.label)||t}function or(t){return["POWER_USER","ADMIN","EDITOR"].includes(t)}function Ht(t){return"tenantId"in t&&t.tenantId?"tenant":"organization"}function ir(t,a,n){const r=Ht(t),o=(n==null?void 0:n.type)||"organization";if(!(!a||!a.shares))if(o==="organization")if(r==="organization"){if("specificOrgUsers"in a.shares)return(a.shares.specificOrgUsers||[]).find(l=>l.orgUserId===t.id)}else return(a.shares.specificTenantUsers||[]).find(l=>l.tenantUserId===t.id);else return(a.shares.specificTenantUsers||[]).find(l=>l.tenantUserId===t.id)}function lr({user:t}){return Ht(t)==="tenant"?e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:t.role==="POWER_USER"?"Power User":"Viewer"}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:t.role==="ADMIN"?"Admin":t.role==="POWER_USER"?"Power User":"Viewer"})}function cr({user:t,userShare:a,usersToUpdate:n,currentUser:r,getRoleOptions:o,handleUpdateAccess:i}){if(!(a!=null&&a.role))return null;const c=or((r==null?void 0:r.type)||""),l=n.some(h=>h.id===t.id),u=n.find(h=>h.id===t.id),m=u?u.newRole:a==null?void 0:a.role,d=o(t.type);return a?e.jsx("div",{className:"flex items-center gap-2",children:c?e.jsx(as,{currentRole:m,onRoleChange:h=>{i(t.id,a.role,h)},roleOptions:d,disabled:!c,allowDropdown:c,className:l?"border-orange-300 bg-orange-100":""}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:pe(m,d)})}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:"Unknown"})}function dr({hasAccess:t,isUserRemoving:a,isSelected:n,hasAccessFromAPI:r}){return e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[t&&!a&&e.jsxs(s.Badge,{variant:"outline",className:"border-green-200 bg-green-50 text-xs text-green-700",children:[e.jsx(s.Eye,{className:"mr-1 h-3 w-3"}),"Has Access"]}),a&&e.jsxs(s.Badge,{variant:"outline",className:"border-red-200 bg-red-50 text-xs text-red-700",children:[e.jsx(s.X,{className:"mr-1 h-3 w-3"}),"Remove Access"]}),n&&!r&&e.jsxs(s.Badge,{variant:"outline",className:"border-blue-200 bg-blue-50 text-xs text-blue-700",children:[e.jsx(Ge,{className:"mr-1 h-3 w-3"}),"Will Share"]})]})}function ur({isUserRemoving:t,isSelected:a,hasAccess:n,isRemoving:r,isSharing:o}){return e.jsxs(e.Fragment,{children:[t&&e.jsx("span",{className:"text-xs font-medium text-red-600",children:r?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Removing..."]}):"⚠ Will remove access"}),a&&!n&&e.jsx("span",{className:"text-xs font-medium text-blue-600",children:o?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Sharing..."]}):"Will share"})]})}function mr({existingShares:t,allUsers:a,getRoleOptions:n,currentUser:r}){if(((r==null?void 0:r.type)||"organization")==="organization")if("specificOrgUsers"in t.shares){const c=t.shares,l=c.specificOrgUsers||[],u=c.specificTenantUsers||[],m=c.orgWide||[],d=c.orgUsersOnly||[],h=c.allTenantsOnly||[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"font-medium",children:"Current Access"}),e.jsxs("div",{className:"space-y-2",children:[l.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-600",children:["Specific Org Users (",l.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[l.slice(0,3).map((x,f)=>{var j,w;const g=((j=a.find(k=>k.id===x.orgUserId))==null?void 0:j.name)||"Unknown User",p=((w=a.find(k=>k.id===x.orgUserId))==null?void 0:w.type)||"",v=pe(x.role,n(p));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:g}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:v})]},f)}),l.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",l.length-3," more users"]})]})]}),u.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs font-medium text-green-600",children:["Specific Tenant Users (",u.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[u.slice(0,3).map((x,f)=>{var j,w;const g=((j=a.find(k=>k.id===x.tenantUserId))==null?void 0:j.name)||"Unknown User",p=((w=a.find(k=>k.id===x.tenantUserId))==null?void 0:w.type)||"",v=pe(x.role,n(p));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:g}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:v})]},f)}),u.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",u.length-3," more users"]})]})]}),m.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-purple-600",children:"All Org Users"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:m.map((x,f)=>{const g=pe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Organization Users"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:g})]},f)})})]}),d.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-orange-600",children:"Org Users Only"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:d.map((x,f)=>{const g=pe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Org Users Only"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:g})]},f)})})]}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-indigo-600",children:"All Tenants"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:h.map((x,f)=>{const g=pe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Tenants"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:g})]},f)})})]}),!l.length&&!u.length&&!m.length&&!d.length&&!h.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}else{const c=t.shares.specificTenantUsers||[],l=t.shares.tenantWide||[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"font-medium",children:"Current Access"}),e.jsxs("div",{className:"space-y-2",children:[c.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-600",children:["Specific Users (",c.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[c.slice(0,3).map((u,m)=>{var f,g;const d=((f=a.find(p=>p.id===u.tenantUserId))==null?void 0:f.name)||"Unknown User",h=((g=a.find(p=>p.id===u.tenantUserId))==null?void 0:g.type)||"",x=pe(u.role,n(h));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:d}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:x})]},m)}),c.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",c.length-3," more users"]})]})]}),l.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-green-600",children:"All Users"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:l.map((u,m)=>{const d=pe(u.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Tenant Users"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:d})]},m)})})]}),!c.length&&!l.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}else{const i=t.shares.specificTenantUsers||[],c=t.shares.tenantWide||[];return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"font-medium",children:"Current Access"}),e.jsxs("div",{className:"space-y-2",children:[i.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-600",children:["Specific Users (",i.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[i.slice(0,3).map((l,u)=>{var x,f;const m=((x=a.find(g=>g.id===l.tenantUserId))==null?void 0:x.name)||"Unknown User",d=((f=a.find(g=>g.id===l.tenantUserId))==null?void 0:f.type)||"",h=pe(l.role,n(d));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:m}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:h})]},u)}),i.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",i.length-3," more users"]})]})]}),c.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-green-600",children:"All Users"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:c.map((l,u)=>{const m=pe(l.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Tenant Users"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:m})]},u)})})]}),!i.length&&!c.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}}function hr({isInitialLoading:t,searchQuery:a,availableUsers:n}){return t?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(s.LoaderCircle,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading users..."})]})}):n.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:a?"No users found matching your search.":"No users available to share with."}):null}function xr({user:t,userShare:a,isUserRemoving:n,hasAccess:r,hasAccessFromAPI:o,isSelected:i,selectedUser:c,roleOptions:l,currentUser:u,usersToUpdate:m,handleUserToggle:d,handleRemoveAccess:h,handleUpdateAccess:x,handleUserRoleChange:f}){return e.jsxs("div",{className:s.cn("flex items-center space-x-3 rounded-lg p-2 transition-colors",r&&!n?"border border-green-200 bg-green-50":n?"border border-red-200 bg-red-50":i?"border border-blue-200 bg-blue-50":"hover:bg-muted/50"),children:[e.jsx(s.Checkbox,{checked:o?!n:i,disabled:t.id===(u==null?void 0:u.id),onCheckedChange:()=>{o?n?d(t.id):h(t.id):d(t.id)}}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:t.name}),e.jsx(lr,{user:t})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&!n?e.jsx(as,{currentRole:a==null?void 0:a.role,onRoleChange:g=>x(t.id,a.role,g),roleOptions:l,disabled:!1,allowDropdown:!0}):e.jsx(cr,{user:t,userShare:a,usersToUpdate:m,currentUser:u,getRoleOptions:()=>l,handleUpdateAccess:x}),i&&!o&&e.jsx("div",{onClick:g=>g.stopPropagation(),children:e.jsx(as,{currentRole:(c==null?void 0:c.role)||"VIEWER",onRoleChange:g=>f(t.id,g),roleOptions:l,disabled:!1})})]})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.email}),e.jsx(dr,{hasAccess:r,isUserRemoving:n,isSelected:i,hasAccessFromAPI:o}),e.jsx(ur,{isUserRemoving:n,isSelected:i,hasAccess:r,isRemoving:!1,isSharing:!1})]})]})}function Qt({existingShares:t,isInitialLoading:a,isSearching:n,getRoleOptions:r,allUsers:o=[],currentUser:i,handleUserToggle:c,handleUserRoleChange:l,handleRemoveAccess:u,handleUpdateAccess:m}){const d=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate(),f=s.useShareSearchQuery(),g=s.useShareManagementActions(),p=c||(T=>{const S=d.some(D=>D.id===T),y=h.includes(T);S?g.removeSelectedUser(T):y?g.removeUserFromRemove(T):g.addSelectedUser({id:T,role:"VIEWER"})}),v=l||g.updateSelectedUserRole,j=u||g.addUserToRemove,w=m||((T,S,y)=>{g.addUserToUpdate({id:T,currentRole:S,newRole:y})}),k=o,O=h;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{className:"text-sm font-medium",children:["All Users (",(k??[]).length,")"]}),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:e.jsx(s.Info,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{className:"w-48 max-w-sm",children:e.jsx(mr,{existingShares:t,allUsers:o,getRoleOptions:r,currentUser:i})})]})})]}),(k==null?void 0:k.length)>0&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>{d.length===k.length?g.setSelectedUsers([]):g.setSelectedUsers(k.map(T=>({id:T.id,role:"VIEWER"})))},className:"h-auto p-1 text-xs",children:d.length===k.length?"Deselect all":"Select all"})]}),e.jsxs("div",{className:"max-h-60 space-y-1 overflow-y-auto rounded-md border p-2",children:[e.jsx(hr,{isInitialLoading:a,isSearching:n,searchQuery:f,availableUsers:k||[]}),!a&&!n&&(k==null?void 0:k.length)>0&&k.map(T=>{const S=t?ir(T,t,i):void 0,y=O.includes(T.id),D=!!S,b=D&&!y,A=d.some(I=>I.id===T.id),C=d.find(I=>I.id===T.id),R=r(T.type);return e.jsx(xr,{user:T,userShare:S,isUserRemoving:y,hasAccess:b,hasAccessFromAPI:D,isSelected:A,selectedUser:C,roleOptions:R,currentUser:i,usersToUpdate:x,handleUserToggle:p,handleRemoveAccess:j,handleUpdateAccess:w,handleUserRoleChange:v},T.id)})]})]})}function Kt({shareType:t,onShareTypeChange:a,currentUser:n,options:r}){const o=(n==null?void 0:n.role)&&["POWER_USER","ADMIN","AUTHOR","SUPER_ADMIN"].includes(n.role);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.RadioGroup,{value:t,onValueChange:a,className:`grid grid-cols-${r.length} gap-4`,children:r.map(i=>e.jsxs("div",{children:[e.jsx(s.RadioGroupItem,{value:i.value,id:i.value,className:"peer sr-only",disabled:i.disabled}),e.jsxs(s.Label,{htmlFor:i.value,className:`flex flex-col items-center justify-between rounded-md border-2 border-muted bg-popover p-4 hover:bg-accent hover:text-accent-foreground peer-data-[state=checked]:border-primary peer-data-[state=checked]:bg-primary/5 [&:has([data-state=checked])]:border-primary [&:has([data-state=checked])]:bg-primary/5 ${i.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,children:[i.icon||e.jsx(we,{className:"mb-3 h-6 w-6"}),e.jsxs("div",{className:"space-y-1 text-center",children:[e.jsx("p",{className:"text-sm font-medium leading-none",children:i.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i.description})]})]})]},i.value))}),!o&&r.some(i=>i.value==="all_users")&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only admins, authors, power users, and super admins can share with all users."})]})}const Te=()=>[{value:"VIEWER",label:"Viewer",description:"Can view only"},{value:"EDITOR",label:"Editor",description:"Can view and edit"},{value:"CONTRIBUTOR",label:"Contributor",description:"Can view, edit, and share"},{value:"OWNER",label:"Owner",description:"Full access (view, edit, share, delete)"}];function pr({currentUser:t,currentShare:a,isSharing:n,onUpdateAccess:r,allUsersToUpdate:o=null,allUsersToRemove:i=!1,isUpdating:c=!1,isRemoving:l=!1}){const u=s.useShareCurrentMode(),m=Te().filter(w=>w.value==="VIEWER"||w.value==="EDITOR"||w.value==="CONTRIBUTOR"),d=a.role!=="NONE"?a.role:"NONE",h=o?o.newRole:d,x=a.role!=="NONE"&&!i&&(!o||o.newRole===d),f=o!==null&&o.newRole!==d,g=i,p=d==="NONE"||!d,v=w=>{switch(w){case"VIEWER":return e.jsx(s.Eye,{className:"h-4 w-4"});case"EDITOR":return e.jsx(s.SquarePen,{className:"h-4 w-4"});case"CONTRIBUTOR":return e.jsx(wa,{className:"h-4 w-4"});default:return e.jsx(s.Eye,{className:"h-4 w-4"})}},j=w=>{r(d,w)};return e.jsx("div",{className:"space-y-4",children:e.jsxs(s.Card,{className:s.cn("pb-6",f&&!g&&!p?"border-orange-300 bg-orange-50":x?"border-green-300 bg-green-50":g||p?"border-destructive bg-destructive/10":""),children:[e.jsxs(s.CardHeader,{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-base",children:[e.jsx(ve,{className:"h-5 w-5"}),"Share with All"," ",u==="allOrgUsers"?"Organization":u==="allTenantUsers"?"Tenant":u==="specificOrgUsers"?"Org":"Tenant"," ","Users",x&&e.jsx(s.Badge,{variant:"default",className:"ml-2 border-green-400 bg-green-100 text-green-800",children:"Active"}),f&&e.jsx(s.Badge,{variant:"secondary",className:"ml-2 border-orange-400 bg-orange-100 text-orange-800",children:"Pending Update"}),(g||p)&&e.jsx(s.Badge,{variant:"destructive",className:"ml-2",children:"No Access"})]}),e.jsx(s.CardDescription,{children:g||p?"No access for all users.":"This will share the dashboard with all users in your "+((t==null?void 0:t.type)==="organization"?"organization":"tenant")+". Select an access level below."})]}),e.jsx(s.CardContent,{className:"space-y-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Select Access Level:"}),e.jsxs(s.HoverCard,{children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-4 w-4 p-0 text-muted-foreground hover:text-foreground",children:e.jsx(s.Info,{className:"h-3 w-3"})})}),e.jsx(s.HoverCardContent,{className:"w-80",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Share with All Users"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This action will share the dashboard with all users in your"," ",(t==null?void 0:t.type)==="organization"?"organization":"tenant",". Users will receive the selected access level."]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Viewer:"})," Can view the dashboard"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Editor:"})," Can view and edit the dashboard"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Contributor:"})," Can view, edit, and share the dashboard"]}),e.jsxs("p",{children:[e.jsx("strong",{children:"None:"})," No access for all users"]})]})]})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:m.map(w=>e.jsxs(s.Button,{variant:h===w.value?"default":"outline",className:"h-auto flex-col items-start gap-2 p-3",onClick:()=>j(w.value),disabled:n||c||l,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[v(w.value),e.jsx("span",{className:"font-medium",children:w.label})]}),e.jsx("p",{className:"text-left text-xs text-muted-foreground",children:w.description})]},w.value))})]})})]})})}function Wt({currentUser:t,currentShare:a,isSharing:n,isUpdating:r,isRemoving:o,onUpdateAccess:i,onRemoveAccess:c,allUsersToUpdate:l,allUsersToRemove:u}){const m=p=>p==="OWNER"?"CONTRIBUTOR":p,h=a?{role:m(a.role)}:{role:"NONE"},x=l?{currentRole:m(l.currentRole),newRole:m(l.newRole)}:null,f=(p,v)=>{i(p,v)},g=()=>{c()};return e.jsx(pr,{currentUser:t,currentShare:h,isSharing:n,isUpdating:r,isRemoving:o,onUpdateAccess:f,onRemoveAccess:g,allUsersToUpdate:x,allUsersToRemove:u})}const fr=async(t,a={})=>{const n={};return a.search&&(n.search=a.search),a.type&&(n.type=a.type),a.active!==void 0&&(n.active=a.active.toString()),a.tenantId&&(n.tenantId=a.tenantId),a.limit&&(n.limit=a.limit.toString()),a.offset&&(n.offset=a.offset.toString()),a.page&&(n.page=a.page.toString()),a.pageSize&&(n.pageSize=a.pageSize.toString()),await s.getRequest("https://semaphor.cloud/api/management/v1/unified-users",t,n)};function gr(t={}){var i,c,l;const{authToken:a,tokenProps:n}=s.useSemaphorContext(),r=(n==null?void 0:n.endUserId)||(n==null?void 0:n.orgUserId),o=s.useQuery({queryKey:["unified-users",t],queryFn:()=>fr((a==null?void 0:a.accessToken)||"",t),enabled:!!(a!=null&&a.accessToken)&&!!r,retry:(u,m)=>m instanceof Error&&m.message.includes("401")||m instanceof Error&&m.message.includes("403")?!1:u<2,retryDelay:u=>Math.min(1e3*2**u,3e4)});return{users:((i=o.data)==null?void 0:i.users)||[],userContext:(c=o.data)==null?void 0:c.userContext,total:((l=o.data)==null?void 0:l.total)||0,isLoading:o.isLoading,isError:o.isError,isFetching:o.isFetching,error:o.error,refetch:o.refetch}}function De(t){const{debouncedSearchQuery:a,resourceId:n,resourceType:r=ee.DASHBOARD,userType:o,tenantId:i}=t,c=M.useMemo(()=>({search:a,active:!0,...o?{type:o}:{},...o==="tenant"&&i?{tenantId:i}:{}}),[a,o,i]),{users:l,isLoading:u,isError:m}=gr(c),d=Za(r,n);return{allUsers:l,isLoadingUsers:u,isErrorLoadingUsers:m,existingShares:d.data,isLoadingShares:d.isLoading,isErrorLoadingShares:d.isError,isFetchingShares:d.isFetching}}function jr({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:o=!1,isUpdating:i=!1,isRemoving:c=!1}){var K,F;const l=s.useShareSelectedTab(),u=s.useShareSelectedTenant(),{searchQuery:m,setSearchQuery:d,debouncedSearchQuery:h}=s.useShareSearchWithDebounce(),x=s.useShareSelectedUsers(),f=s.useShareUsersToRemove(),g=s.useShareUsersToUpdate(),p=s.useShareCurrentMode(),v=s.useShareOrgWideRole(),j=s.useShareManagementActions(),[w,k]=M.useState("specific_users"),O=()=>{if(l==="org")return"organization";if(l==="tenant")return"tenant"},T=()=>{if(l==="tenant"&&u)return u},{allUsers:S,existingShares:y,isLoadingUsers:D}=De({debouncedSearchQuery:h,resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:O(),tenantId:T()});M.useEffect(()=>{j.setCurrentContext("org-tab"),j.setCurrentMode(w==="all_users"?"allOrgUsers":"specificOrgUsers")},[j,w]);const b=_=>{var q,Y;const $=_;if(k($),r==null||r($),j.setCurrentContext("org-tab"),$==="specific_users")j.setCurrentMode("specificOrgUsers");else if($==="all_users"){j.setCurrentMode("allOrgUsers");const Q=(Y=(q=y==null?void 0:y.shares)==null?void 0:q.orgUsersOnly)==null?void 0:Y[0];Q&&Q.role!==void 0&&j.setOrgWideRole(Q.role)}},A=S.filter(_=>_.name.toLowerCase().includes(m.toLowerCase())||_.email.toLowerCase().includes(m.toLowerCase())),C=S.filter(_=>x.some($=>$.id===_.id)),R=_=>{var Q,G;const $=x.some(Z=>Z.id===_),q=f.includes(_),Y=(G=(Q=y==null?void 0:y.shares)==null?void 0:Q.specificOrgUsers)==null?void 0:G.some(Z=>Z.orgUserId===_);$?j.removeSelectedUser(_):q?j.removeUserFromRemove(_):Y||j.addSelectedUser({id:_,role:"VIEWER"})},I=(_,$)=>{j.updateSelectedUserRole(_,$)},E=_=>{j.addUserToRemove(_),j.removeSelectedUser(_)},N=_=>{j.removeUserFromRemove(_)},L=_=>{j.removeUserFromUpdate(_)},B=(_,$)=>{j.setOrgWideRole($)},z=()=>{j.setOrgWideRole((V==null?void 0:V.role)||"NONE")},V=(F=(K=y==null?void 0:y.shares)==null?void 0:K.orgUsersOnly)==null?void 0:F[0];M.useEffect(()=>{w==="all_users"&&V&&V.role!==void 0&&j.setOrgWideRole(V.role)},[w,V,j]);const U=D,X=!1;return n?e.jsxs(e.Fragment,{children:[e.jsx(Kt,{shareType:w,onShareTypeChange:b,currentUser:n,options:[{value:"specific_users",label:"Specific Org User",description:"Choose individual users to share with",icon:e.jsx(we,{className:"mb-3 h-6 w-6 text-orange-500"})},{value:"all_users",label:"All Org Users",description:`Share with all ${(n==null?void 0:n.type)==="organization"?"organization":"tenant"} users`,icon:e.jsx(ve,{className:"mb-3 h-6 w-6 text-indigo-500"}),disabled:!["POWER_USER","ADMIN","AUTHOR","SUPER_ADMIN"].includes(n.role??"")}]}),w==="specific_users"?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(Ut,{value:m,onChange:d}),e.jsx(qt,{selectedUsers:x,selectedUserObjects:C,onRemove:R,onRoleChange:I,getRoleOptions:Te}),e.jsx($t,{usersToRemove:f,allUsers:A,onRemove:N}),e.jsx(Yt,{usersToUpdate:g,allUsers:A,onRemove:L,getRoleOptions:Te}),e.jsx(Qt,{existingShares:y,isInitialLoading:U,isSearching:X,resource:t,onShare:()=>{},getRoleOptions:Te,allUsers:A,currentUser:n,handleUserToggle:R,handleUserRoleChange:I,handleRemoveAccess:E,handleUpdateAccess:(_,$,q)=>{j.addUserToUpdate({id:_,currentRole:$,newRole:q})}})]}):e.jsx("div",{className:"mt-3",children:e.jsx(Wt,{currentUser:n,currentShare:V,isSharing:o,isUpdating:i,isRemoving:c,onUpdateAccess:B,onRemoveAccess:z,allUsersToUpdate:p==="allOrgUsers"&&v!==((V==null?void 0:V.role)||"NONE")?{currentRole:(V==null?void 0:V.role)||"NONE",newRole:v}:null,allUsersToRemove:p==="allOrgUsers"&&(V==null?void 0:V.role)===void 0})})]}):null}function ht({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:o=!1,isUpdating:i=!1,isRemoving:c=!1}){var Q;const{searchQuery:l,debouncedSearchQuery:u,setSearchQuery:m}=s.useShareSearchWithDebounce(),d=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate(),f=s.useShareCurrentMode(),g=s.useShareTenantWideRole(),p=s.useShareAllTenantsRole(),v=s.useShareSelectedTenant(),j=s.useShareManagementActions(),{data:w,isLoading:k}=Ga({enabled:(n==null?void 0:n.type)==="organization"}),[O,T]=M.useState((n==null?void 0:n.type)==="organization"?"all_tenants":"specific_tenant_users");M.useEffect(()=>{(n==null?void 0:n.type)==="tenant"?(j.setCurrentContext("tenant-dialog"),j.setCurrentMode("specificTenantUsers")):(j.setCurrentContext("tenant-tab"),j.setCurrentMode("allTenants"))},[j,n==null?void 0:n.type]);const S=G=>{var te,ae,se,oe;T(G);let Z;if(G==="specific_tenant_users"?Z="specific_users":G==="all_tenant_users"||G==="all_tenants"?Z="all_users":Z="specific_users",r==null||r(Z),(n==null?void 0:n.type)==="tenant"?(j.setCurrentContext("tenant-dialog"),G==="specific_tenant_users"?j.setCurrentMode("specificTenantUsers"):G==="all_tenant_users"&&(j.setCurrentMode("allTenantUsers"),n!=null&&n.tenantId&&j.setSelectedTenant(n.tenantId))):(j.setCurrentContext("tenant-tab"),G==="specific_tenant_users"?j.setCurrentMode("specificTenantUsers"):G==="all_tenant_users"?j.setCurrentMode("allTenantUsers"):G==="all_tenants"&&j.setCurrentMode("allTenants")),G==="all_tenant_users"){const H=(ae=(te=b==null?void 0:b.shares)==null?void 0:te.tenantWide)==null?void 0:ae[0];H&&H.role!==void 0&&j.setTenantWideRole(H.role)}else if(G==="all_tenants"){const H=(oe=(se=b==null?void 0:b.shares)==null?void 0:se.allTenantsOnly)==null?void 0:oe[0];H&&H.role!==void 0&&j.setAllTenantsRole(H.role)}},y=G=>{j.setSelectedTenant(G)},{allUsers:D,existingShares:b,isLoadingUsers:A,isErrorLoadingUsers:C,isLoadingShares:R,isErrorLoadingShares:I}=De({debouncedSearchQuery:u,resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"tenant",tenantId:(n==null?void 0:n.type)==="tenant"?n.tenantId:v}),E=G=>{var se,oe;const Z=d.some(H=>H.id===G),te=h.includes(G),ae=(oe=(se=b==null?void 0:b.shares)==null?void 0:se.specificTenantUsers)==null?void 0:oe.some(H=>H.tenantUserId===G);Z?j.removeSelectedUser(G):te?j.removeUserFromRemove(G):ae||j.addSelectedUser({id:G,role:"VIEWER"})},N=(G,Z)=>{j.updateSelectedUserRole(G,Z)},L=G=>{j.addUserToRemove(G),j.removeSelectedUser(G)},B=G=>{j.removeUserFromRemove(G)},z=G=>{j.removeUserFromUpdate(G)},V=(G,Z,te)=>{j.addUserToUpdate({id:G,currentRole:Z,newRole:te})},U=(G,Z)=>{O==="all_tenant_users"?j.setTenantWideRole(Z):O==="all_tenants"&&j.setAllTenantsRole(Z)},X=()=>{O==="all_tenant_users"?j.setTenantWideRole("VIEWER"):O==="all_tenants"&&j.setAllTenantsRole("VIEWER")},F=(()=>{var G,Z,te,ae;return f==="allTenants"?(Z=(G=b==null?void 0:b.shares)==null?void 0:G.allTenantsOnly)==null?void 0:Z[0]:f==="allTenantUsers"?(ae=(te=b==null?void 0:b.shares)==null?void 0:te.tenantWide)==null?void 0:ae[0]:null})();M.useEffect(()=>{var G,Z,te,ae;if(O==="all_tenant_users"){const se=(Z=(G=b==null?void 0:b.shares)==null?void 0:G.tenantWide)==null?void 0:Z[0];se&&se.role!==void 0&&j.setTenantWideRole(se.role)}else if(O==="all_tenants"){const se=(ae=(te=b==null?void 0:b.shares)==null?void 0:te.allTenantsOnly)==null?void 0:ae[0];se&&se.role!==void 0&&j.setAllTenantsRole(se.role)}},[O,b,j]);const _=D.filter(G=>d.some(Z=>Z.id===G.id)),$=A||R,q=C||I,Y=()=>(n==null?void 0:n.type)==="tenant"||O==="all_tenants"?!0:v&&(O==="specific_tenant_users"||O==="all_tenant_users");return e.jsxs(e.Fragment,{children:[q&&e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(s.CircleAlert,{className:"mx-auto mb-2 h-8 w-8 text-destructive"}),e.jsx("p",{className:"mb-4 text-sm text-destructive",children:"Failed to load users or shares"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:()=>window.location.reload(),children:"Retry"})]})}),!q&&n&&e.jsxs("div",{className:"max-h-[500px] space-y-4 overflow-y-auto",children:[e.jsx(Kt,{shareType:O,onShareTypeChange:S,currentUser:n,options:(n==null?void 0:n.type)==="tenant"?[{value:"all_tenant_users",label:"All Users",description:"Share with all users of this tenant",icon:e.jsx(ve,{className:"mb-3 h-6 w-6 text-purple-500"})},{value:"specific_tenant_users",label:"Specific Users",description:"Share with specific tenant users",icon:e.jsx(we,{className:"mb-3 h-6 w-6 text-orange-500"})}]:[{value:"all_tenants",label:"All Tenants",description:"Share with all tenants and their users",icon:e.jsx(ot,{className:"mb-3 h-6 w-6 text-purple-500"})},{value:"all_tenant_users",label:"Specific Tenant",description:"Share with all users of a specific tenant",icon:e.jsx(s.House,{className:"mb-3 h-6 w-6 text-blue-500"})},{value:"specific_tenant_users",label:"Specific Tenant User",description:"Share with users of a specific tenant",icon:e.jsx(we,{className:"mb-3 h-6 w-6 text-orange-500"})}]}),(n==null?void 0:n.type)==="organization"&&(O==="specific_tenant_users"||O==="all_tenant_users")&&e.jsxs("div",{className:"mt-4",children:[e.jsx(s.Label,{className:"mb-1 block text-sm font-medium",children:"Select Tenant"}),e.jsxs(s.Select,{value:v||"",onValueChange:y,disabled:k,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:k?"Loading tenants...":"Select a tenant..."})}),e.jsx(s.SelectContent,{className:"z-[51]",children:(Q=w==null?void 0:w.tenants)==null?void 0:Q.map(G=>e.jsx(s.SelectItem,{value:G.id,children:G.name},G.id))})]})]}),Y()?e.jsx(e.Fragment,{children:O==="specific_tenant_users"?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ut,{value:l,onChange:m}),e.jsx(qt,{selectedUsers:d,selectedUserObjects:_,onRemove:G=>E(G),onRoleChange:N,getRoleOptions:Te}),e.jsx($t,{usersToRemove:h,allUsers:D,onRemove:B}),e.jsx(Yt,{usersToUpdate:x,allUsers:D,onRemove:z,getRoleOptions:Te}),e.jsx(Qt,{existingShares:b,isInitialLoading:!!$,isSearching:!1,resource:t,onShare:()=>{},getRoleOptions:Te,allUsers:D,currentUser:n,handleUserToggle:E,handleUserRoleChange:N,handleRemoveAccess:L,handleUpdateAccess:V})]}):O==="all_tenant_users"||O==="all_tenants"?e.jsx("div",{className:"mt-6",children:e.jsx(Wt,{currentUser:n,currentShare:F,isSharing:o,isUpdating:i,isRemoving:c,onUpdateAccess:U,onRemoveAccess:X,allUsersToUpdate:f==="allTenantUsers"&&((F==null?void 0:F.role)===void 0||g!==F.role)||f==="allTenants"&&((F==null?void 0:F.role)===void 0||p!==F.role)?{currentRole:(F==null?void 0:F.role)||"VIEWER",newRole:f==="allTenantUsers"?g:p}:null,allUsersToRemove:f==="allTenantUsers"&&(F==null?void 0:F.role)===void 0||f==="allTenants"&&(F==null?void 0:F.role)===void 0})}):null}):(n==null?void 0:n.type)==="organization"&&(O==="specific_tenant_users"||O==="all_tenant_users")&&e.jsx("div",{className:"mt-6 flex items-center justify-center py-8",children:e.jsxs("div",{className:"text-center",children:[e.jsx(ot,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please select a tenant to continue"})]})})]})]})}const Jt=()=>{const t=s.useShareCurrentContext(),a=s.useShareCurrentMode(),n=s.useShareSelectedUsers(),r=s.useShareUsersToRemove(),o=s.useShareUsersToUpdate(),i=s.useShareSelectedTenant(),c=s.useShareOrgWideRole(),l=s.useShareAllTenantsRole(),u=s.useShareTenantWideRole(),m=M.useMemo(()=>()=>s.buildShareData({currentContext:t,currentMode:a,selectedUsers:n,usersToRemove:r,usersToUpdate:o,selectedTenant:i,orgWideRole:c,allTenantsRole:l,tenantWideRole:u}),[t,a,n,r,o,i,c,l,u]),d=M.useMemo(()=>x=>s.validateShareData(x),[]),h=M.useMemo(()=>{if(!t||!a)return!1;switch(t){case"org-tab":return a==="specificOrgUsers"?n.length>0||r.length>0||o.length>0:!0;case"tenant-tab":if(a==="allTenantUsers"){if(!i)return!1}else if(a==="specificTenantUsers")return i?n.length>0||r.length>0||o.length>0:!1;return!0;case"tenant-dialog":return a==="specificTenantUsers"?n.length>0||r.length>0||o.length>0:!0}return!1},[t,a,n,r,o,i]);return{buildShareData:m,validateShareData:d,isCurrentStateValid:h,currentContext:t,currentMode:a,selectedUsers:n,usersToRemove:r,usersToUpdate:o,selectedTenant:i,orgWideRole:c,allTenantsRole:l,tenantWideRole:u}};function xt({resource:t,existingShares:a,isSharing:n,isRemoving:r,isUpdating:o,onShare:i,onClose:c,shareTabType:l,currentAllUsersShare:u,onRemoveAccess:m}){const d=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const f=s.useShareSelectedTenant();s.useShareSelectedTab();const g=s.useShareOrgWideRole(),p=s.useShareAllTenantsRole(),v=s.useShareTenantWideRole(),{buildShareData:j,validateShareData:w,isCurrentStateValid:k}=Jt(),O=n||r||o,T=()=>{var A,C,R,I;if(O)return"Updating...";if(l==="specific_users"){if(d.length===0&&h.length===0&&x.length===0)return"Select users to share with";const E=d.length+h.length+x.length;return E===0?"Select users to share with":d.length>0&&h.length>0?`Update access for ${E} user${E!==1?"s":""}`:h.length>0&&d.length===0&&x.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:d.length>0&&h.length===0&&x.length===0?`Share with ${d.length} user${d.length!==1?"s":""}`:x.length>0&&d.length===0&&h.length===0?`Update access for ${x.length} user${x.length!==1?"s":""}`:`Update access for ${E} user${E!==1?"s":""}`}else if(l==="all_users"){if(!u||u.role===void 0)return"Share with All Users";const E=u.role;return g===E?"Remove Access":"Update Access"}else if(l==="all_tenants"){const E=(C=(A=a==null?void 0:a.shares)==null?void 0:A.allTenantsOnly)==null?void 0:C[0];if(!E||E.role===void 0)return"Share with All Tenants";const N=E.role;return p===N?"Remove Access":"Update Access"}else if(l==="all_tenant_users"){const E=(I=(R=a==null?void 0:a.shares)==null?void 0:R.tenantWide)==null?void 0:I[0];if(!E||E.role===void 0)return"Share with All Tenant Users";const N=E.role;return v===N?"Remove Access":"Update Access"}else if(l==="specific_tenant_users"){if(d.length===0&&h.length===0&&x.length===0)return"Select users to share with";const E=d.length+h.length+x.length;return E===0?"Select users to share with":d.length>0&&h.length>0?`Update access for ${E} user${E!==1?"s":""}`:h.length>0&&d.length===0&&x.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:d.length>0&&h.length===0&&x.length===0?`Share with ${d.length} user${d.length!==1?"s":""}`:x.length>0&&d.length===0&&h.length===0?`Update access for ${x.length} user${x.length!==1?"s":""}`:`Update access for ${E} user${E!==1?"s":""}`}return"Share"},S=()=>O||!t||l==="all_tenant_users"&&!f||l==="specific_tenant_users"&&!f?!0:!k,y=()=>{const A=j();A&&w(A)&&i(A)},D=()=>{var A,C,R,I;if(l==="all_users")if(!u||u.role===void 0){const E=j();E&&w(E)&&i(E)}else{const E=u.role;if(g===E)m==null||m();else{const L=j();if(L&&w(L)){const B={...L,updateAccess:!0};i(B)}}}else if(l==="all_tenants"){const E=(C=(A=a==null?void 0:a.shares)==null?void 0:A.allTenantsOnly)==null?void 0:C[0];if(!E||E.role===void 0){const N=j();N&&w(N)&&i(N)}else{const N=E.role;if(p===N)m==null||m();else{const B=j();if(B&&w(B)){const z={...B,updateAccess:!0};i(z)}}}}else if(l==="all_tenant_users"){const E=(I=(R=a==null?void 0:a.shares)==null?void 0:R.tenantWide)==null?void 0:I[0];if(!E||E.role===void 0){const N=j();N&&w(N)&&i(N)}else{const N=E.role;if(v===N)m==null||m();else{const B=j();if(B&&w(B)){const z={...B,updateAccess:!0};i(z)}}}}},b=()=>{var A,C,R,I;if(l==="all_users"){if(!u||u.role===void 0)return"default";const E=u.role;return g===E?"destructive":"default"}else if(l==="all_tenants"){const E=(C=(A=a==null?void 0:a.shares)==null?void 0:A.allTenantsOnly)==null?void 0:C[0];if(!E||E.role===void 0)return"default";const N=E.role;return p===N?"destructive":"default"}else if(l==="all_tenant_users"){const E=(I=(R=a==null?void 0:a.shares)==null?void 0:R.tenantWide)==null?void 0:I[0];if(!E||E.role===void 0)return"default";const N=E.role;return v===N?"destructive":"default"}return"default"};return e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:c,disabled:O,children:"Close"}),(l==="specific_users"||l==="specific_tenant_users")&&e.jsx(e.Fragment,{children:(d.length>0||h.length>0||x.length>0)&&e.jsxs(s.Button,{onClick:y,disabled:!t||O,variant:"default",children:[O?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Ge,{className:"mr-2 h-4 w-4"}),!O&&T()]})}),(l==="all_users"||l==="all_tenants"||l==="all_tenant_users")&&e.jsxs(s.Button,{onClick:D,disabled:S(),variant:b(),children:[O?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(ve,{className:"mr-2 h-4 w-4"}),!O&&T()]})]})}function yr({resource:t,isSharing:a,isRemoving:n,isUpdating:r,onShare:o,onClose:i,shareTabType:c,currentAllUsersShare:l}){const u=s.useShareSelectedUsers(),m=s.useShareUsersToRemove(),d=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const h=s.useShareTenantWideRole();s.useShareSelectedTenant();const{buildShareData:x,validateShareData:f,isCurrentStateValid:g}=Jt(),p=a||n||r,v=()=>{if(p)return"Updating...";if(c==="specific_users"){if(u.length===0&&m.length===0&&d.length===0)return"Select users to share with";const T=u.length+m.length+d.length;return T===0?"Select users to share with":u.length>0&&m.length>0?`Update access for ${T} user${T!==1?"s":""}`:m.length>0&&u.length===0&&d.length===0?`Remove access for ${m.length} user${m.length!==1?"s":""}`:u.length>0&&m.length===0&&d.length===0?`Share with ${u.length} user${u.length!==1?"s":""}`:d.length>0&&u.length===0&&m.length===0?`Update access for ${d.length} user${d.length!==1?"s":""}`:`Update access for ${T} user${T!==1?"s":""}`}else if(c==="all_users"){if(!l||l.role==="NONE")return"Share with All Users";const T=l.role;return h===T?"Remove Access":"Update Access"}return"Share"},j=()=>p||!t?!0:!g,w=()=>{const T=x();T&&f(T)&&o(T)},k=()=>{if(!l||l.role==="NONE"){const T=x();T&&f(T)&&o(T)}else{const T=l.role;if(h===T){const y=x();if(y&&f(y)){const D={...y,removeAccess:!0};o(D)}}else{const y=x();if(y&&f(y)){const D={...y,updateAccess:!0};o(D)}}}},O=()=>!l||l.role==="NONE"?"default":"destructive";return e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:i,disabled:p,children:"Close"}),c==="specific_users"&&e.jsx(e.Fragment,{children:(u.length>0||m.length>0||d.length>0)&&e.jsxs(s.Button,{onClick:w,disabled:!t||p,variant:"default",children:[p?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Ge,{className:"mr-2 h-4 w-4"}),!p&&v()]})}),c==="all_users"&&e.jsxs(s.Button,{onClick:k,disabled:j(),variant:O(),children:[p?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Ge,{className:"mr-2 h-4 w-4"}),!p&&v()]})]})}function Xt({resource:t,resourceType:a,isSharing:n,isRemoving:r,isUpdating:o,onClose:i,onShare:c,onRemoveAccess:l}){var y,D,b,A;const{currentUser:u}=Le(),[m,d]=M.useState("specific_users"),[h,x]=M.useState("specific_users"),f=s.useShareManagementActions(),g=s.useShareSelectedTab(),p=s.useShareCurrentMode(),{existingShares:v}=De({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"tenant"}),{existingShares:j}=De({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"organization"}),w=(D=(y=v==null?void 0:v.shares)==null?void 0:y.tenantWide)==null?void 0:D[0],k=(A=(b=j==null?void 0:j.shares)==null?void 0:b.orgUsersOnly)==null?void 0:A[0],O=()=>{if(g==="org")return h;switch(p){case"specificTenantUsers":return"specific_tenant_users";case"allTenantUsers":return"all_tenant_users";case"allTenants":return"all_tenants";default:return"specific_tenant_users"}},T=M.useCallback(()=>{f.resetShareState(),i()},[f,i]),S=(u==null?void 0:u.type)==="organization";return e.jsx(s.Dialog,{open:!0,onOpenChange:T,children:e.jsxs(s.DialogContent,{className:"z-[51] flex max-h-[80vh] max-w-3xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ge,{className:"h-5 w-5"}),' Share "',t==null?void 0:t.title,'"']})}),e.jsx(s.DialogDescription,{children:S?"Share this resource with org users or tenant users. As a super admin, you can share with all users.":"Share this resource with other users in your tenant."})]}),S?e.jsxs(s.Tabs,{value:g,onValueChange:C=>{const R=C;f.setSelectedTab(R),f.resetUserSelections()},className:"mb-4 min-h-0 flex-1",children:[e.jsxs(s.TabsList,{className:"mb-2 grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"org",children:"Org Users"}),e.jsx(s.TabsTrigger,{value:"tenant",children:"Tenant Users"})]}),e.jsx(s.TabsContent,{value:"org",className:"min-h-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsx(jr,{resource:t,resourceType:a,currentUser:u,onShareTabTypeChange:x,isSharing:n,isUpdating:o,isRemoving:r})})}),e.jsx(s.TabsContent,{value:"tenant",className:"min-h-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsx(ht,{resource:t,resourceType:a,currentUser:u,onShareTabTypeChange:C=>d(C),isSharing:n,isUpdating:o,isRemoving:r})})})]}):e.jsx("div",{className:"mb-4 min-h-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsx(ht,{resource:t,resourceType:a,currentUser:u,onShareTabTypeChange:C=>d(C),isSharing:n,isUpdating:o,isRemoving:r})})}),e.jsx("div",{className:"mt-auto flex-shrink-0",children:S?g==="org"?e.jsx(xt,{resource:t,existingShares:j,isSharing:n,isRemoving:r,isUpdating:o,onShare:c,onClose:i,shareTabType:h,currentAllUsersShare:k,onRemoveAccess:l}):e.jsx(xt,{resource:t,existingShares:v,isSharing:n,isRemoving:r,isUpdating:o,onShare:c,onClose:i,shareTabType:O(),currentAllUsersShare:w,onRemoveAccess:l}):e.jsx(yr,{resource:t,isSharing:n,isRemoving:r,isUpdating:o,onShare:c,onClose:i,shareTabType:m,currentAllUsersShare:w,onRemoveAccess:l})})]})})}function me(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function Se(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function Zt(t,a,n){const{resourceType:r,resourceId:o,shareMutation:i,removeMutation:c,existingShares:l,resetUserSelections:u}=a;if(o)switch(t.context){case"org-tab":if(t.mode==="allOrgUsers"){const m=me(r,o,[{scope:"org_users_only",role:t.orgWideRole}]);i(m,{onSuccess:()=>{u()}})}else if(t.mode==="specificOrgUsers"){const{selectedUsers:m,usersToRemove:d,usersToUpdate:h}=t;if(m&&m.length>0){const x=me(r,o,m.map(f=>({scope:"specific_org_user",orgUserId:f.id,role:f.role})));i(x,{onSuccess:()=>{u()}})}if(d&&d.length>0){const x=Se(r,o,d.map(f=>{var p,v;const g=(v=(p=l==null?void 0:l.shares)==null?void 0:p.specificOrgUsers)==null?void 0:v.find(j=>j.orgUserId===f);return{scope:"specific_org_user",orgUserId:f,role:(g==null?void 0:g.role)||"VIEWER"}}));c(x,{onSuccess:()=>{u()}})}h&&h.length>0&&h.forEach(x=>{const f=me(r,o,[{scope:"specific_org_user",orgUserId:x.id,role:x.newRole}]);i(f,{onSuccess:()=>{u()}})})}break;case"tenant-tab":if(t.mode==="allTenants"){const m=me(r,o,[{scope:"all_tenants_only",role:t.allTenantsRole}]);i(m,{onSuccess:()=>{u()}})}else if(t.mode==="allTenantUsers"){const m=me(r,o,[{scope:"all_tenant_users",tenantId:t.tenantId,role:t.tenantWideRole}]);i(m,{onSuccess:()=>{u()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:m,usersToRemove:d,usersToUpdate:h,tenantId:x}=t;if(d&&d.length>0){const f=Se(r,o,d.map(g=>{var v,j;const p=(j=(v=l==null?void 0:l.shares)==null?void 0:v.specificTenantUsers)==null?void 0:j.find(w=>w.tenantUserId===g);return{scope:"specific_tenant_user",tenantUserId:g,tenantId:x,role:(p==null?void 0:p.role)||"VIEWER"}}));c(f,{onSuccess:()=>{u()}})}if(h&&h.length>0&&h.forEach(f=>{const g=me(r,o,[{scope:"specific_tenant_user",tenantUserId:f.id,tenantId:x,role:f.newRole}]);i(g,{onSuccess:()=>{u()}})}),m&&m.length>0){const f=me(r,o,m.map(g=>({scope:"specific_tenant_user",tenantUserId:g.id,tenantId:x,role:g.role})));i(f,{onSuccess:()=>{u()}})}}break;case"tenant-dialog":if(t.mode==="allTenantUsers")if(t.removeAccess){const m=Se(r,o,[{scope:"all_tenant_users",role:"VIEWER"}]);c(m,{onSuccess:()=>{u()}})}else if(t.updateAccess){const m=me(r,o,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);i(m,{onSuccess:()=>{u()}})}else{const m=me(r,o,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);i(m,{onSuccess:()=>{u()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:m,usersToRemove:d,usersToUpdate:h}=t;if(m&&m.length>0){const x=me(r,o,m.map(f=>({scope:"specific_tenant_user",tenantUserId:f.id,role:f.role})));i(x,{onSuccess:()=>{u()}})}if(d&&d.length>0){const x=Se(r,o,d.map(f=>{var p,v;const g=(v=(p=l==null?void 0:l.shares)==null?void 0:p.specificTenantUsers)==null?void 0:v.find(j=>j.tenantUserId===f);return{scope:"specific_tenant_user",tenantUserId:f,role:(g==null?void 0:g.role)||"VIEWER"}}));c(x,{onSuccess:()=>{u()}})}h&&h.length>0&&h.forEach(x=>{const f=me(r,o,[{scope:"specific_tenant_user",tenantUserId:x.id,role:x.newRole}]);i(f,{onSuccess:()=>{u()}})})}break}}function en(t,a,n,r){var m,d,h,x,f,g;const{resourceType:o,resourceId:i,removeMutation:c,existingShares:l,resetUserSelections:u}=r;if(i)if(t.length>0){const p=Se(o,i,t.map(v=>{var w,k;const j=(k=(w=l==null?void 0:l.shares)==null?void 0:w.specificTenantUsers)==null?void 0:k.find(O=>O.tenantUserId===v);return{scope:"specific_tenant_user",tenantUserId:v,role:(j==null?void 0:j.role)||"VIEWER"}}));c(p,{onSuccess:()=>{u()},onError:v=>{console.error("Remove access failed:",v)}})}else{const p=a==="tenant"&&n==="allTenants",v=a==="tenant"&&n==="allTenantUsers";if(p){const j=(d=(m=l==null?void 0:l.shares)==null?void 0:m.allTenantsOnly)==null?void 0:d[0];if(j){const w=Se(o,i,[{scope:"all_tenants_only",role:j.role}]);c(w,{onSuccess:()=>{u()},onError:k=>{console.error("Remove all-tenants access failed:",k)}})}}else if(v){const j=(x=(h=l==null?void 0:l.shares)==null?void 0:h.tenantWide)==null?void 0:x[0];if(j){const w=Se(o,i,[{scope:"all_tenant_users",role:j.role}]);c(w,{onSuccess:()=>{u()},onError:k=>{console.error("Remove all-tenant-users access failed:",k)}})}}else{const j=(g=(f=l==null?void 0:l.shares)==null?void 0:f.orgUsersOnly)==null?void 0:g[0];if(j){const w=Se(o,i,[{scope:"org_users_only",role:j.role}]);c(w,{onSuccess:()=>{u()},onError:k=>{console.error("Remove org-wide access failed:",k)}})}}}}function vr(t,a,n){const r=s.useShareManagementActions(),o=s.useShareUsersToRemove(),i=s.useShareSelectedTab(),c=s.useShareCurrentMode(),{currentUser:l}=Le(),{existingShares:u}=De({debouncedSearchQuery:"",resourceId:t||"",resourceType:ee.DASHBOARD,userType:"tenant"}),m=M.useCallback(()=>{r.resetUserSelections()},[r]),d=M.useCallback(x=>{if(!t)return;const f={resourceType:ee.DASHBOARD,resourceId:t,shareMutation:a,removeMutation:n,existingShares:u,resetUserSelections:m};Zt(x,f,l)},[t,a,n,u,m,l]),h=M.useCallback(()=>{if(!t)return;const x={resourceType:ee.DASHBOARD,resourceId:t,removeMutation:n,existingShares:u,resetUserSelections:m};en(o,i||"",c||"",x)},[t,a,n,u,m,o,i,c]);return{handleShareSubmit:d,handleRemoveAccess:h}}function br(t,a,n){const{currentUser:r}=Le(),o=s.useShareManagementActions(),i=s.useShareUsersToRemove(),c=s.useShareSelectedTab(),l=s.useShareCurrentMode(),{existingShares:u}=De({debouncedSearchQuery:"",resourceId:t||"",resourceType:ee.VISUAL,userType:"tenant"}),m=M.useCallback(()=>{o.resetUserSelections()},[o]),d=M.useCallback(x=>{if(!t)return;const f={resourceType:ee.VISUAL,resourceId:t,shareMutation:a,removeMutation:n,existingShares:u,resetUserSelections:m};Zt(x,f,r)},[t,a,n,u,m,r]),h=M.useCallback(()=>{if(!t)return;const x={resourceType:ee.VISUAL,resourceId:t,removeMutation:n,existingShares:u,resetUserSelections:m};en(i,c||"",l||"",x)},[t,a,n,u,m,i,c,l]);return{handleShareSubmit:d,handleRemoveAccess:h}}function Nr(t){const a=t.toUpperCase().indexOf("WHERE"),n=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),a!==-1){const c=t.substring(0,a),l=t.substring(a);return`${c} {{ filters | where }} AND ${l.substring(6)}`}else if(n!==-1){const c=t.substring(0,n),l=t.substring(n);return`${c} {{ filters | where }} ${l}`}else{const c=t.substring(0,i),l=t.substring(i);return console.log("beforeClause",c),console.log("afterClause",l),l?`${c} {{ filters | where }} ${l}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function zs(t){const[a,n]=M.useState(null),[r,o]=M.useState(null);return M.useEffect(()=>{if(!t||t.trim()===""){n(null),o(null);return}(async()=>{try{if(!t.startsWith("http://")&&!t.startsWith("https://"))throw new Error(`Invalid URL format: ${t}`);try{new URL(t)}catch{throw new Error(`Invalid URL: ${t}`)}const l=`${t.endsWith("/")?t:`${t}/`}index.js`;try{if(!(await fetch(l,{method:"HEAD"})).ok)throw new Error(`Module not found at ${l}`)}catch{}const u=await import(l);if(typeof u.useChartStore!="function")throw new Error("useChartStore is not a function");n(()=>u.useChartStore),o(null)}catch(c){const l=c instanceof Error?c.message:"Unknown error";console.error("Failed to load remote chart store:",l),o(l),n(null)}})()},[t]),a}function Cr(t,a){if(t.length===0)return"";if(a){const n=t.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return t[0].id;if(r&&r.endsWith("__Header")){const i=r.split("__")[0],c=t.find(l=>l.tabTitle===i);return c?c.id:t[0].id}return a}}return t[0].id}async function pt(t,a,n){if(!t||!a)throw new Error("Missing auth token or visual ID");const r=["resource-by-id","visual",a],o=n.getQueryData(r);if(o)return console.log("Using cached visual data for:",a),{data:o,fromCache:!0};console.log("Fetching visual data from network for:",a);const i=s.ue.loading("Loading visual...",{position:"top-center"});try{const c=await fetch(`https://semaphor.cloud/api/management/v1/visuals/${a}`,{headers:{Authorization:`Bearer ${t}`}});if(!c.ok)throw new Error("Failed to load visual");const l=await c.json();return n.setQueryData(r,l),s.ue.dismiss(i),{data:l,fromCache:!1}}catch(c){throw s.ue.dismiss(i),c}}function Sr(t,a,n,r,o){const i=t.frameObject;a(i);const c=i.cards.find(l=>l.id===i.activeCardId);c&&n(c),r(!0),o(!0)}function wr(){var x;const{setCardSql:t}=s.useEditorActions(),a=s.useEditorStore(f=>f.frame),n=s.useEditorStore(f=>f.card),r=zs(((x=n.customCardPreferences)==null?void 0:x.url)||""),o=s.useEditorStore(f=>f.selectedSchemaName),i=s.useEditorStore(f=>f.selectedDatamodelId),c=s.useEditorStore(f=>f.selectedDatabaseName),l=s.useEditorStore(f=>f.selectedTableName),u=s.useEditorStore(f=>f.selectedConnectionId),m=s.useEditorStore(f=>f.isShowingVisual),d=n.sql;return{getUpdatedFrame:M.useCallback(()=>{var j;let f=d;d&&!d.includes("{{")&&(f=Nr(d),t(f));const g=(j=r==null?void 0:r.getState())==null?void 0:j.settings,p={...n,dataSource:n.dataSource||{mode:"directSource"},lastSelectedSchema:o,lastSelectedDatamodelId:i,lastSelectedDatabase:c,lastSelectedTable:l,connectionId:u,sql:f,customCfg:m?n.customCfg:null,...g&&{customCardPreferences:{...n.customCardPreferences,settings:g}}},v=a.cards.map(w=>w.id===n.id?p:w);return{...a,cards:v,activeCardId:Cr(v,a.activeCardId)}},[n,a,m,o,i,c,l,u,t,r,d])}}function Vs(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient(),n=s.useSelectedVisual(),{selectVisual:r}=s.useManagementActions(),{setFrame:o,setCard:i}=s.useEditorActions(),{setIsDashboardEditing:c,setIsVisualEditing:l,setSelectedFrameId:u,addFrame:m,setIsDashboardPanelOpen:d}=s.useDashboardActions(),h=s.useDashboardStore(p=>p.selectedSheetId),x=sr((n==null?void 0:n.id)||"",{enabled:!!(n!=null&&n.id)&&!!(t!=null&&t.accessToken)}),f=M.useCallback(async p=>{try{r(p);const{data:v,fromCache:j}=await pt((t==null?void 0:t.accessToken)||"",p.id,a);return Sr(v,o,i,c,l),{success:!0,fromCache:j}}catch(v){return console.error("Error editing visual:",v),{success:!1,error:"Failed to load visual for editing"}}},[t==null?void 0:t.accessToken,a,r,o,i,c,l]),g=M.useCallback(async p=>{try{if(r(p),!h)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:v,fromCache:j}=await pt((t==null?void 0:t.accessToken)||"",p.id,a),w=v.frameObject;if(!w)return{success:!1,error:"Visual has no frame data"};const k={...w,id:s.v4()};return m(h,k,"end"),c(!0),u(k.id),d(!1),{success:!0,fromCache:j}}catch(v){return console.error("Error adding visual:",v),{success:!1,error:"Failed to add visual to dashboard"}}},[t==null?void 0:t.accessToken,a,r,h,m,c,u,d]);return{visual:x.data,isLoading:x.isLoading,isError:x.isError,error:x.error,handleEditLibraryVisual:f,handleAddLibraryVisual:g,getUpdatedFrame:wr().getUpdatedFrame,refetch:x.refetch}}function Dr(){const[t,a]=M.useState(""),[n,r]=M.useState(!1),[o,i]=M.useState(""),[c,l]=M.useState(""),[u,m]=M.useState(!1),[d,h]=M.useState(null),[x,f]=M.useState(!1),[g,p]=M.useState(null),[v,j]=M.useState(null),{setIsDashboardEditing:w,setIsVisualEditing:k}=s.useDashboardActions(),{handleEditLibraryVisual:O,handleAddLibraryVisual:T}=Vs(),{resources:S,isLoading:y,isError:D,createResource:b,updateResource:A,deleteResource:C,duplicateResource:R,shareResource:I,isCreating:E,isDeleting:N,removeResourceShares:L,isSharing:B,isRemovingShares:z,isUpdatingShares:V}=nr(()=>{f(!1),p(null)},()=>{r(!1),i(""),l("")}),{handleShareSubmit:U,handleRemoveAccess:X}=br((d==null?void 0:d.id)||null,I,L);Le();const K=S.filter(P=>{var J,ie;return((J=P==null?void 0:P.title)==null?void 0:J.toLowerCase().includes(t.toLowerCase()))||((ie=P==null?void 0:P.description)==null?void 0:ie.toLowerCase().includes(t.toLowerCase()))}),F=P=>new Date(P).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),_=()=>{o.trim()&&b({title:o,description:c,isPrivate:!1})},$=P=>{p(P),f(!0)},q=()=>{g&&C(g.id)},{startUpdating:Y,stopUpdating:Q,isUpdating:G}=Vt(),Z=(P,J)=>{const ie=J.title!==void 0?"title":"description";Y(P,ie),A({resourceId:P,data:J},{onSuccess:()=>{Q(P,ie)},onError:()=>{Q(P,ie)}})},te=P=>{j(P),R(P,{onSettled:()=>j(null)})},ae=P=>{O(P)},se=P=>{T(P)},oe=P=>{const J=S.find(ie=>ie.id===P);J&&A({resourceId:P,data:{isPrivate:!J.isPrivate}})},H=P=>{h(P),m(!0)};return s.useShareUsersToRemove(),s.useShareManagementActions(),De({debouncedSearchQuery:"",resourceId:(d==null?void 0:d.id)||"",resourceType:ee.VISUAL,userType:"tenant"}),y?e.jsx(Pt,{}):D?e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load visuals"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"mt-1 flex h-full flex-1 flex-col gap-3 px-4",children:[e.jsx("div",{className:"px-1",children:n?e.jsxs(s.Card,{className:"border-dashed p-4 pb-2",children:[e.jsx(s.CardHeader,{className:"px-0 pb-3 pt-0",children:e.jsx(s.CardTitle,{className:"text-sm",children:"New Visual"})}),e.jsxs(s.CardContent,{className:"space-y-3 px-0 pb-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"title",className:"text-xs",children:"Title"}),e.jsx(s.Input$1,{id:"title",placeholder:"Enter visual title...",value:o,onChange:P=>i(P.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs",children:"Description (optional)"}),e.jsx(s.Input$1,{id:"description",placeholder:"Enter visual description...",value:c,onChange:P=>l(P.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(s.Button,{onClick:_,size:"sm",className:"h-7 text-xs",disabled:!o.trim()||E,children:E?"Creating...":"Create"}),e.jsx(s.Button,{onClick:()=>{r(!1),i(""),l("")},variant:"outline",size:"sm",className:"h-7 text-xs",disabled:E,children:"Cancel"})]})]})]}):e.jsxs(s.Button,{onClick:()=>r(!0),className:"h-8 w-full",size:"sm",disabled:E,children:[e.jsx(s.Plus,{className:"mr-2 h-3.5 w-3.5"}),E?"Creating...":"Create New Visual"]})}),e.jsx("div",{className:"space-y-2 px-1",children:e.jsx(s.Input$1,{id:"search",placeholder:"Search by title or description...",value:t,onChange:P=>a(P.target.value),className:"h-8"})}),e.jsx("div",{className:"mb-4 flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-2 overflow-y-auto p-1",children:K.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(us,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No visuals found"})]}):K.map(P=>e.jsx(rr,{visual:P,onAddVisual:se,onEditVisual:ae,onUpdateVisual:Z,onDeleteClick:$,onDuplicateVisual:te,onTogglePrivacy:oe,onShareVisual:H,isDeleting:N,isDuplicating:v===P.id,isTitleUpdating:G(P.id,"title"),isDescriptionUpdating:G(P.id,"description"),formatDate:F},P.id))})}),u&&d&&e.jsx(Xt,{resource:d,resourceType:ee.VISUAL,onShare:U,isSharing:B,isRemoving:z,isUpdating:V,onClose:()=>{m(!1),h(null)},onRemoveAccess:X}),e.jsx(s.AlertDialog,{open:x,onOpenChange:P=>{!P&&N||(f(P),P||p(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',g==null?void 0:g.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:N,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:P=>{P.preventDefault(),P.stopPropagation(),q()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:N,children:N?"Deleting...":"Delete"})]})]})})]})}function kr({dashboard:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:o=!1,onLoadDashboard:i,onUpdateDashboard:c,onDeleteClick:l,onDuplicateDashboard:u,onShareDashboard:m,formatDate:d,onDashboardItemClick:h}){var S;const{selectDashboard:x}=s.useManagementActions(),f=s.useIsDashboardSelected(t.id),[g,p]=M.useState(!1),[v,j]=M.useState(!1),w=s.useDashboardStore(y=>y.actions.setIsDashboardPanelOpen);M.useEffect(()=>{n?(p(!0),j(!0)):v&&(p(!1),j(!1))},[n,v]);const k=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx(It,{className:"h-3 w-3 text-purple-500"}):e.jsx(ve,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(we,{className:"h-3.5 w-3.5 text-slate-500"}),O=()=>e.jsx(s.LayoutDashboard,{className:"h-4 w-4 text-slate-400"}),T=()=>{x(t),i(t.id),h==null||h(t.id)};return e.jsxs("div",{className:s.cn("group relative flex cursor-pointer items-start gap-3 px-4 py-3 dark:border-slate-800","cursor-pointer transition-colors duration-150 hover:bg-slate-50 dark:hover:bg-slate-900/50",t.ownership.isOwner&&"border-blue-200 dark:border-blue-800",f&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:T,children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-slate-100 dark:bg-slate-800",children:O()})}),e.jsxs("div",{className:"flex w-full items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.EditableText,{inputClassName:"text-sm font-medium text-slate-900 dark:text-slate-100",value:t.title,onSave:y=>c==null?void 0:c(t.id,{title:y}),isEditable:t.permissions.canEdit&&f,isPending:r,placeholder:"Untitled Dashboard",displayClassName:"line-clamp-1 max-w-[220px] text-sm font-medium text-slate-900 dark:text-slate-100"})}),e.jsx("div",{className:"shrink-0",children:k()})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx(s.EditableText,{inputClassName:"line-clamp-1 text-xs text-slate-500 dark:text-slate-400",value:t.description||"",onSave:y=>c==null?void 0:c(t.id,{description:y}),isEditable:t.permissions.canEdit&&f,isPending:o,placeholder:"No description",displayClassName:"mt-0.5 max-w-[250px] line-clamp-1 text-xs text-slate-500 dark:text-slate-400"})})]}),e.jsx("div",{className:"absolute right-3 top-2 flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("div",{className:s.cn("flex items-center opacity-0 transition-opacity duration-150 group-hover:opacity-100"),children:e.jsxs(s.DropdownMenu,{modal:!1,open:g,onOpenChange:p,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 hover:bg-slate-200 dark:hover:bg-slate-700",onClick:y=>y.stopPropagation(),children:e.jsx(s.Ellipsis,{className:"h-3 w-3"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.preventDefault(),y.stopPropagation(),u(t.id)},disabled:n,children:[n?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),n?"Duplicating...":"Duplicate"]}),t.permissions.canEdit&&e.jsx(e.Fragment,{children:e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),m(t)},children:[e.jsx(ve,{className:"mr-2 h-3 w-3"}),"Share"]})}),t.permissions.canDelete&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:y=>{y.stopPropagation(),l(t),w(!1)},className:"text-destructive",disabled:a,children:[e.jsx(s.Trash2,{className:"mr-2 h-3 w-3"}),a?"Deleting...":"Delete"]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"h-3 w-3"}),e.jsx("span",{children:((S=t.ownership.createdBy)==null?void 0:S.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:d(t.lastModified)})]})]})]})]})})})]})]},t.id)}function Tr({onRetry:t}){return e.jsx(s.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})})}function Er(t){const[a,n]=M.useState(""),[r,o]=M.useState(!1),[i,c]=M.useState(""),[l,u]=M.useState(""),[m,d]=M.useState(!1),[h,x]=M.useState(null),[f,g]=M.useState(!1),[p,v]=M.useState(null),[j,w]=M.useState(null),k=s.useManagementStore(H=>H.lastSelectedDashboard),O=s.useManagementStore(H=>H.actions.selectDashboard);s.useShareManagementActions(),s.useShareUsersToRemove(),s.useShareSelectedTab(),s.useShareCurrentMode();const{resources:T,isLoading:S,isError:y,createResource:D,updateResource:b,deleteResource:A,duplicateResource:C,isCreating:R,isDeleting:I,isSharing:E,isRemovingShares:N,isUpdatingShares:L,shareResource:B,removeResourceShares:z}=tr(()=>{g(!1),v(null),k&&O(k)},()=>{o(!1),c(""),u("")}),{handleShareSubmit:V,handleRemoveAccess:U}=vr((h==null?void 0:h.id)||null,B,z),{currentUser:X}=Le(),K=T.filter(H=>{var P,J;return((P=H==null?void 0:H.title)==null?void 0:P.toLowerCase().includes(a.toLowerCase()))||((J=H==null?void 0:H.description)==null?void 0:J.toLowerCase().includes(a.toLowerCase()))}),F=H=>new Date(H).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),_=()=>{i.trim()&&D({title:i,description:l,isPrivate:!1})},$=H=>{var P;(P=t.onLoadDashboard)==null||P.call(t,H)},q=H=>{v(H),g(!0)},Y=()=>{p&&A(p.id)},Q=H=>{w(H),C(H,{onSettled:()=>w(null)})},{startUpdating:G,stopUpdating:Z,isUpdating:te}=Vt(),ae=(H,P)=>{const J=P.title!==void 0?"title":"description";G(H,J),b({resourceId:H,data:P},{onSuccess:()=>{Z(H,J)},onError:()=>{Z(H,J)}})},se=H=>{const P=T.find(J=>J.id===H);P&&b({resourceId:H,data:{isPrivate:!P.isPrivate}})},oe=H=>{x(H),X==null||X.type,d(!0)};return De({debouncedSearchQuery:"",resourceId:(h==null?void 0:h.id)||"",resourceType:ee.DASHBOARD,userType:"tenant"}),S?e.jsx(Pt,{}):y?e.jsx(Tr,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"mt-1 flex h-full flex-1 flex-col gap-3 px-4",children:[e.jsx("div",{className:"px-1",children:r?e.jsxs(s.Card,{className:"border-dashed p-4 pb-2",children:[e.jsx(s.CardHeader,{className:"px-0 pb-3 pt-0",children:e.jsx(s.CardTitle,{className:"text-sm",children:"New Dashboard"})}),e.jsxs(s.CardContent,{className:"space-y-3 px-0 pb-0",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"title",className:"text-xs",children:"Title"}),e.jsx(s.Input$1,{id:"title",placeholder:"Enter dashboard title...",value:i,onChange:H=>c(H.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"description",className:"text-xs",children:"Description (optional)"}),e.jsx(s.Input$1,{id:"description",placeholder:"Enter dashboard description...",value:l,onChange:H=>u(H.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(s.Button,{onClick:_,size:"sm",className:"h-7 text-xs",disabled:!i.trim()||R,children:R?"Creating...":"Create"}),e.jsx(s.Button,{onClick:()=>{o(!1),c(""),u("")},variant:"outline",size:"sm",className:"h-7 text-xs",disabled:R,children:"Cancel"})]})]})]}):e.jsxs(s.Button,{onClick:()=>o(!0),className:"h-8 w-full",size:"sm",disabled:R,children:[e.jsx(s.Plus,{className:"mr-2 h-3.5 w-3.5"}),R?"Creating...":"Create New Dashboard"]})}),e.jsx("div",{className:"space-y-2 px-1",children:e.jsx(s.Input$1,{id:"search",placeholder:"Search by title or description...",value:a,onChange:H=>n(H.target.value),className:"h-8"})}),e.jsx("div",{className:"mb-4 flex flex-1 flex-col",children:e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-2 overflow-y-auto p-1",children:K.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(ia,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No dashboards found"})]}):K.map(H=>e.jsx(kr,{dashboard:H,isDeleting:I,isDuplicating:j===H.id,isTitleUpdating:te(H.id,"title"),isDescriptionUpdating:te(H.id,"description"),onLoadDashboard:$,onEditDashboard:t.onEditDashboard,onUpdateDashboard:ae,onDeleteClick:q,onDuplicateDashboard:Q,onTogglePrivacy:se,onShareDashboard:oe,formatDate:F,onDashboardItemClick:t.onDashboardItemClick},H.id))})}),m&&h&&e.jsx(Xt,{resource:h,resourceType:ee.DASHBOARD,onShare:V,isSharing:E,isRemoving:N,isUpdating:L,onClose:()=>{d(!1),x(null)},onRemoveAccess:U}),e.jsx(s.AlertDialog,{open:f,onOpenChange:H=>{!H&&I||(g(H),H||v(null))},children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',p==null?void 0:p.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:I,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:H=>{H.preventDefault(),H.stopPropagation(),Y()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:I,children:I?"Deleting...":"Delete"})]})]})})]})}function sn({isOpen:t,onClose:a,className:n,onDashboardItemClick:r}){s.useDashboardStore(f=>f.dashboard);const{setDashboard:o,addSheet:i}=s.useDashboardStore(f=>f.actions),{currentUser:c}=Le(),l=c,[u,m]=s.useLocalStorageState("resource-management-active-tab","dashboards"),d=Gt(a,{enabled:t}),h=f=>{},x=f=>{console.log("Editing dashboard:",f)};return e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{ref:d,className:s.cn("absolute inset-y-0 left-0 z-[51] flex w-96 flex-col border-r bg-background shadow-lg transition-transform duration-300 ease-in-out",t?"translate-x-0":"hidden -translate-x-full",n),children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsx("div",{className:"flex items-center gap-3",children:l&&e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-muted bg-muted/30 px-2 py-1",children:[e.jsxs(s.Avatar,{className:"h-5 w-5",children:[e.jsx(s.AvatarImage,{alt:l.name}),e.jsx(s.AvatarFallback,{className:"text-xs",children:l.name.charAt(0).toUpperCase()})]}),e.jsx("span",{className:"text-xs font-medium",children:l.name})]})}),e.jsx(s.TooltipContent,{side:"bottom",className:"ml-2 max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:l.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:l.email}),l.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(l.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",l.id]})]})})]})})}),e.jsx(s.IconButton,{className:"h-6 p-1 text-muted-foreground hover:text-foreground",onClick:a,tooltip:"Hide Dashboard Management",children:e.jsx(s.X,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-hidden",children:e.jsxs(s.Tabs,{value:u,onValueChange:m,className:"flex h-9 grow flex-col",children:[e.jsx("div",{className:"px-5",children:e.jsxs(s.TabsList,{className:"grid h-8 w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"dashboards",className:"h-6",children:"Dashboards"}),e.jsx(s.TabsTrigger,{value:"visuals",className:"h-6",children:"Visuals"})]})}),e.jsx(s.TabsContent,{value:"dashboards",className:"flex-1",children:e.jsx(Er,{onLoadDashboard:h,onEditDashboard:x,onDashboardItemClick:r})}),e.jsx(s.TabsContent,{value:"visuals",className:"flex-1",children:e.jsx(Dr,{})})]})})]})})}function Ir(){var K;const{authToken:t,tokenProps:a}=s.useSemaphorContext();s.useDashboardStore(F=>F.theme);const n=s.useDashboardStore(F=>F.lenses),r=s.useDashboardStore(F=>F.selectedLensId),o=n==null?void 0:n.find(F=>F.id===r),i=s.useDashboardStore(F=>F.dashboard);s.useDashboardStore(F=>F.selectedSheetId);const c=s.useDashboardStore(F=>F.isDashboardEditing),l=s.useEditorStore(F=>F.card),u=s.useEditorStore(F=>F.selectedConnectionId),[m,d]=M.useState(!1),h=s.useDashboardStore(F=>F.isDashboardPanelOpen),x=s.useDashboardStore(F=>F.actions.setIsDashboardPanelOpen),f=s.useDashboardStore(F=>F.filterValues),g=s.useDashboardStore(F=>F.isVisualEditing),p=s.useManagementStore(F=>F.selectedDashboard),v=(K=p==null?void 0:p.permissions)==null?void 0:K.canEdit,j=s.useDashboardStore(F=>F.showFilters);s.useDashboardStore(F=>F.showDashboardJSON);const w=s.useDashboardStore(F=>F.onSaveFunction),k=s.useDashboardStore(F=>F.actions.setShowFilters),{addFrame:O,setSelectedFrameId:T}=s.useDashboardStore(F=>F.actions),{getSelectedSheet:S,setIsDashboardEditing:y,setShowDashboardJSON:D}=s.useDashboardStore(F=>F.actions),b=S(),{tenantId:A,endUserId:C}=M.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),R=M.useMemo(()=>A||C,[A,C]),I=()=>{if(!c||!b)return;const F={dataSource:l.dataSource,mode:"explorer",connectionId:u,id:s.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},_={id:s.v4(),cards:[F],activeCardId:F.id};O(b.id,_),T(_.id)},E=()=>{y(!0)},[N,L]=M.useState(!1),B=zt(ee.DASHBOARD);async function z(){const F=ns(i);L(!0);const _={template:F};B.mutate({resourceId:F.id,data:_},{onSuccess:()=>{L(!1),s.ue.success("Dashboard saved!")},onError:()=>{L(!1),s.ue.error("Failed to save dashboard")}})}async function V(){if(d(!0),!r||!o)return;const F=ns(i),_=JSON.stringify(F),$={...o,template:_,filterValues:f};await Ds($,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),w==null||w(F),d(!1)}if(g)return null;const U=(o==null?void 0:o.name)||i.title,X=a.orgUserId||a.tenantId&&a.endUserId&&a.endUserEmail;return e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-2 pl-3 pr-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[X&&e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>x(!0),className:"h-7 p-2",children:e.jsx(ua,{className:"h-4 w-4"})}),!g&&e.jsx(s.Label,{children:U})]}),e.jsxs("div",{className:"flex gap-2",children:[!1,!g&&e.jsx(Oa,{}),!g&&e.jsx(Bt,{}),c&&!g&&R&&e.jsx(La,{}),!g&&R&&e.jsx(Ra,{}),c&&!g&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:I,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!g&&!c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:E,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),c&&!g&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",onClick:()=>{y(!1),D(!1)},children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),c&&!g&&R&&o&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:m,onClick:V,size:"sm",children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),c&&!g&&R&&v&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:N,onClick:z,size:"sm",children:[N?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ws,{className:"mr-2 h-4 w-4"}),N?"Saving...":"Save"]}),!j&&!g&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>k(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),!g&&c&&!1,!g&&!1,!g&&e.jsx(sn,{isOpen:h,onClose:()=>x(!1)})]})]})}function Mr({name:t,items:a,value:n,onChange:r,isLoading:o,isError:i,refetch:c,className:l,icon:u,showNone:m=!1}){const d=ue.useRef(null),[h,x]=ue.useState(!1),[f,g]=ue.useState("100%"),p=m?[...a||[],{id:"none",name:"None"}]:a;ue.useLayoutEffect(()=>{d.current&&g(d.current.offsetWidth)},[]);function v(){var w;return o?"Loading...":i?"Error":n?(w=a==null?void 0:a.find(k=>k.id===n))==null?void 0:w.name:`Select ${t}`}function j(w,k){r(k),x(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:x,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:d,variant:"outline",role:"combobox","aria-expanded":h,className:s.cn("flex h-9 w-full justify-between",l),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"mr-2",children:u}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:v()})]}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:f},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx(Mt,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:p==null?void 0:p.map(w=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:w.name,onSelect:k=>j(k,w.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",n===w.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:w.name,children:w.name})]})},w.id))})]})]})})]})}function ze({title:t,items:a,value:n,isLoading:r,isError:o,refetch:i,onChange:c,showNone:l=!1,className:u,disabled:m=!1,type:d="combobox"}){const h=r?"Loading...":o?"Error":n;function x(){if(t==="Connection")return e.jsx(Na,{className:"size-4"});if(t==="Database")return e.jsx(s.Database,{className:"size-4"});if(t==="Schema")return e.jsx(va,{className:"size-4"});if(t==="Table")return e.jsx(He,{className:"size-4"});if(t==="Model")return e.jsx(Qn,{className:"size-4"})}function f(){return e.jsxs(s.Select,{disabled:m,value:h,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",u),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(Mt,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:i})]}),e.jsxs(e.Fragment,{children:[l&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((p,v)=>e.jsx(s.SelectItem,{value:p.id,children:p.name},v))]}),(r||o)&&e.jsx(s.SelectItem,{value:h,children:h})]})})]})}function g(){return e.jsx(Mr,{icon:x(),items:a,value:h,onChange:c||(()=>{}),isLoading:r,isError:o,refetch:i,name:t,showNone:l})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:d==="select"?f():g()})})}function Ar({column:t}){const[a,n]=M.useState(!1),r=s.useEditorStore(p=>p.selectedTableName),o=s.useEditorStore(p=>p.selectedSchemaName),i=s.useEditorStore(p=>p.selectedDatabaseName),c=s.useEditorStore(p=>p.selectedDatamodelId),l=s.useEditorStore(p=>p.sqlGen),{modelItems:u,connectionType:m}=s.useEditorAside(),d=s.useEditorStore(p=>p.actions.setSqlGen),h=s.useEditorStore(p=>p.actions.setCardSql),x=s.useEditorStore(p=>p.actions.setRunSql);function f(p,v){var O;const j=s.createSqlGenConfig(p,l,v),w=(O=u==null?void 0:u.find(T=>T.id===c))==null?void 0:O.name;d(j);const k=s.getSql(j,s.fmt(o||""),s.fmt(r),w||"",m,i||"");k&&(h(k),x(!0)),n(!1)}function g(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>f(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>f(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>f(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>f(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>f(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:g()})]})}function _s({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{className:"shrink-0",asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(s.TextIcon,{className:"size-3 text-muted-foreground"}):s.isNumberDataType(t.data_type)?e.jsx($e,{className:"size-3 text-muted-foreground"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3 text-muted-foreground"}):s.isBooleanDataType(t.data_type)?e.jsx(ts,{className:"size-3 text-muted-foreground"}):t.data_type.startsWith("json")?e.jsx(Kn,{className:"size-3 text-muted-foreground"}):e.jsx(s.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:t.data_type})})]})}function fs({column:t,className:a}){return e.jsxs("div",{className:s.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(_s,{column:t}),e.jsx("span",{children:t.column_name})]})}function Lr({id:t,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:i,transform:c}=s.useDraggable({id:t,data:{type:n}}),l=c?{translate:s.CSS.Translate.toString(c),transform:s.CSS.Transform.toString(c)}:void 0;return e.jsx("div",{ref:i,style:l,...o,...r,children:a})}function Rr({onClick:t,column:a}){const n=s.useDndStore(d=>d.activeId),r=s.useEditorStore(d=>{var h;return(h=d.card.queryConfig)==null?void 0:h.groupByColumns}),o=s.useEditorStore(d=>{var h;return(h=d.card.queryConfig)==null?void 0:h.metricColumns}),i=s.useEditorStore(d=>{var h;return(h=d.card.queryConfig)==null?void 0:h.filterColumns});function c(d){return l(d)||u(d)||m(d)}function l(d){return r==null?void 0:r.some(h=>h.name===d.column_name)}function u(d){return o==null?void 0:o.some(h=>h.name===d.column_name)}function m(d){return i==null?void 0:i.some(h=>h.name===d.column_name)}return e.jsxs("div",{onClick:()=>t(a),className:s.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":c(a)}),children:[n===a.column_name&&e.jsx(s.DragOverlay,{children:e.jsx(fs,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(fs,{column:a})}),e.jsx(Lr,{id:a.column_name,type:"column",children:e.jsx(fs,{column:a})})]})}const gs={id:"__placeholder__",role:"groupby",type:"string"},js={id:"__placeholder__",role:"groupby",type:"string"},ys={id:"__placeholder__",role:"metric",type:"number"},vs={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},tn={id:"__placeholder__"},Ee="droppable-group-by",Ie="droppable-metrics",Me="droppable-pivot-by",rs="sortable-group-by",ks="sortable-metrics",os="sortable-pivot-by",Ts="droppable-filters",Es="sortable-filters",Us="sortable-order-by";function Or(){const t=s.useDndStore(E=>E.insertIndex),a=s.useEditorStore(E=>{var N;return((N=E.card.queryConfig)==null?void 0:N.groupByColumns)||[]}),n=s.useEditorStore(E=>{var N;return((N=E.card.queryConfig)==null?void 0:N.metricColumns)||[]}),r=s.useEditorStore(E=>{var N;return((N=E.card.queryConfig)==null?void 0:N.filterColumns)||[]}),o=s.useEditorStore(E=>{var N;return((N=E.card.queryConfig)==null?void 0:N.orderBy)||[]}),i=s.useEditorStore(E=>{var N;return((N=E.card.queryConfig)==null?void 0:N.pivotColumns)||[]}),{setInsertIndex:c,setActiveId:l,setPreviewGroupByColumns:u,setPreviewMetricColumns:m,setPreviewFilterColumns:d,setPreviewPivotColumns:h}=s.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setFilterColumns:g,setOrderByColumns:p,setPivotByColumns:v}=s.useEditorActions(),{columns:j}=s.useDataColumns(),{formattedTableName:w}=s.useEditorAside(),k=s.useSensors(s.useSensor(s.MouseSensor,{activationConstraint:{distance:1}})),O=E=>{var B;const{active:N,over:L}=E;if(((B=N.data.current)==null?void 0:B.type)==="column"&&L){const z=L.id,V=j.find(F=>F.column_name===N.id);if(!V)return;const U=s.isNumberDataType(V.data_type),X=s.isTextDataType(V.data_type),K=s.isDateDataType(V.data_type);if(X||K){if(a.some(_=>_.id===z)){const _=a.findIndex(q=>q.id===z);c(_);const $=a.filter(q=>q.id!==gs.id);$.splice(_,0,gs),u($)}else if(L.id===Ee){c(a.length);const _=[...a,gs];u(_),m(n),d(r)}}if(X||K){if(i.some(_=>_.id===z)){const _=i.findIndex(q=>q.id===z);c(_);const $=i.filter(q=>q.id!==js.id);$.splice(_,0,js),h($)}else if(L.id===Me){c(i.length);const _=[...i,js];h(_),u(a),m(n),d(r)}}if(U||X){if(n.some(_=>_.id===z)){console.log("isOverMetricSortable",z);const _=n.findIndex(q=>q.id===z);c(_);const $=n.filter(q=>q.id!==ys.id);$.splice(_,0,ys),m($)}else if(L.id===Ie){c(n.length);const _=[...n,ys];m(_),d(r),u(a),h(i)}}if(S(V)){if(r.some(_=>_.id===z)){const _=r.findIndex(q=>q.id===z);c(_);const $=r.filter(q=>q.id!==vs.id);$.splice(_,0,vs),d($)}else if(L.id===Ts){c(r.length);const _=[...r,vs];d(_),m(n),u(a),h(i)}}}else u(a),m(n),d(r),h(i)};function T(E){l(E.active.id),c(null),u(a),m(n),d(r),h(i)}function S(E){return!r.some(N=>N.name===E.column_name)}function y(E,N="SUM"){const{column_name:L,data_type:B}=E,z=[...n],V=t!==null?t:n.length,U={...E,id:fe(L),name:L,label:Ke(L,N),type:B,role:"metric",aggregate:N};z.splice(V,0,U),f(z)}function D(E){const N=s.isTextDataType(E.data_type);s.isDateDataType(E.data_type);const L=[...i],B=t!==null?t:i.length;let z;N?z={...E,id:fe(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:z={...E,id:fe(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:Ve(E.column_name,"month"),granularity:"month"},L.splice(B,0,z),v(L)}function b(E){const N=s.isTextDataType(E.data_type);s.isDateDataType(E.data_type);const L=[...a],B=t!==null?t:a.length;let z;N?z={...E,id:fe(E.column_name),name:E.column_name,type:E.data_type,role:"groupby"}:z={...E,id:fe(E.column_name),name:E.column_name,type:E.data_type,role:"groupby",label:Ve(E.column_name,"month"),granularity:"month"},L.splice(B,0,z),x(L)}function A(E){const N=[...r],L=t!==null?t:r.length,B={...E,id:fe(E.column_name),name:E.column_name,type:E.data_type,sql:s.getDefaultFilterSql(E.data_type,w,s.fmt(E.column_name)),role:"filter"};N.splice(L,0,B),g(N)}function C(E){var z,V,U,X,K,F,_,$;const{active:N,over:L}=E,B=N.data.current;if((B==null?void 0:B.type)==="column"&&L){const q=j.find(Z=>Z.column_name===N.id);if(!q)return;const Y=s.isNumberDataType(q.data_type),Q=s.isTextDataType(q.data_type),G=s.isDateDataType(q.data_type);(Q||G)&&(L.id===Ee||((z=L.data.current)==null?void 0:z.type)===rs)&&b(q),(Q||G)&&(L.id===Me||((V=L.data.current)==null?void 0:V.type)===os)?D(q):(Y||Q)&&(L.id===Ie||((U=L.data.current)==null?void 0:U.type)===ks)?(Y&&y(q),Q&&y(q,"COUNT")):S(q)&&(L.id===Ts||((X=L.data.current)==null?void 0:X.type)===Es)&&A(q)}if(L&&((K=L.data.current)==null?void 0:K.type)===rs&&a.some(q=>q.id===N.id)){const q=a.findIndex(Q=>Q.id===N.id),Y=a.findIndex(Q=>Q.id===L.id);if(q!==-1&&Y!==-1&&q!==Y){const Q=[...a],[G]=Q.splice(q,1);Q.splice(Y,0,G),x(Q)}}if(L&&((F=L.data.current)==null?void 0:F.type)===os&&i.some(q=>q.id===N.id)){const q=i.findIndex(Q=>Q.id===N.id),Y=i.findIndex(Q=>Q.id===L.id);if(q!==-1&&Y!==-1&&q!==Y){const Q=[...i],[G]=Q.splice(q,1);Q.splice(Y,0,G),v(Q)}}if(L&&((_=L.data.current)==null?void 0:_.type)===ks&&n.some(q=>q.id===N.id)){const q=n.findIndex(Q=>Q.id===N.id),Y=n.findIndex(Q=>Q.id===L.id);if(q!==-1&&Y!==-1&&q!==Y){const Q=[...n],[G]=Q.splice(q,1);Q.splice(Y,0,G),f(Q)}}if(L&&(($=L.data.current)==null?void 0:$.type)===Es&&r.some(q=>q.id===N.id)){const q=r.findIndex(Q=>Q.id===N.id),Y=r.findIndex(Q=>Q.id===L.id);if(q!==-1&&Y!==-1&&q!==Y){const Q=[...r],[G]=Q.splice(q,1);Q.splice(Y,0,G),g(Q)}}R(E),l(null),c(null),u(a),m(n),d(r),h(i)}function R(E){const{active:N,over:L}=E,B=N.data.current;if((B==null?void 0:B.type)===Us&&L){const z=o.findIndex(U=>qe(U.columnId)===N.id),V=o.findIndex(U=>qe(U.columnId)===L.id);if(z!==-1&&V!==-1&&z!==V){const U=[...o],[X]=U.splice(z,1);U.splice(V,0,X),p(U)}}}function I(){l(null),c(null),u(a),m(n),d(r)}return{handleDragOver:O,handleDragEnd:C,handleDragStart:T,handleDragCancel:I,sensors:k}}function fe(t){return`${t}-${s.v4()}`}function Ke(t,a){const n=s.toTitleCase(t.replace(/_/g," "));switch(a){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function qe(t){return`${Us}-${t}`}function Ve(t,a){const n=s.toTitleCase(t.replace(/_/g," "));switch(a){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function Fr({schemaName:t,tableName:a,columns:n,status:r}){const o=s.useEditorStore(N=>N.sqlGen),i=s.useEditorStore(N=>N.isDevMode),c=s.useEditorStore(N=>N.selectedConnectionId),l=s.useEditorStore(N=>{var L,B;return(B=(L=N.card)==null?void 0:L.queryConfig)==null?void 0:B.metricColumns});s.useEditorStore(N=>{var L,B;return(B=(L=N.card)==null?void 0:L.queryConfig)==null?void 0:B.groupByColumns});const u=s.useEditorStore(N=>N.selectedDatabaseName),m=s.useEditorStore(N=>N.selectedSchemaName),d=s.useEditorStore(N=>N.selectedTableName),h=s.useEditorStore(N=>N.selectedDatamodelId),x=s.useDashboardStore(N=>N.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:g}=s.useDashboardActions(),{addColumnToMetricColumns:p,addColumnToGroupBy:v,setCardSql:j,setRunSql:w,setSqlGen:k,setIsShowingVisual:O}=s.useEditorActions(),{connectionType:T,modelItems:S,selectedDatamodelName:y}=s.useEditorAside();function D(N){var L;if(i){const B=s.createSqlGenConfig(N,o);k(B);const z=(L=S==null?void 0:S.find(U=>U.id===h))==null?void 0:L.name,V=s.getSql(B,s.fmt(t),s.fmt(a),z||"",T,u||"");V&&(j(V),w(!0))}if(!i){if(s.isTextDataType(N.data_type))if(l&&l.length>0){const B={...N,role:"groupby",id:fe(N.column_name),name:N.column_name,type:N.data_type};v(B)}else{const B={...N,role:"metric",id:fe(N.column_name),name:N.column_name,label:Ke(N.column_name,"COUNT"),type:N.data_type,aggregate:"COUNT"};p(B)}if(s.isDateDataType(N.data_type)){const B={...N,role:"groupby",id:fe(N.column_name),name:N.column_name,type:N.data_type,label:Ve(N.column_name,"month"),granularity:"month"};v(B)}if(s.isNumberDataType(N.data_type)){const B={...N,role:"metric",id:fe(N.column_name),name:N.column_name,label:Ke(N.column_name,"SUM"),type:N.data_type,aggregate:"SUM"};p(B)}}}function b(N){N===!0&&(d||y)&&c?(f({connectionId:c,connectionType:T==="S3"||T==="API"?"DuckDb":T||"",databaseName:u||"",schemaName:m||"",tableName:d||"",datamodelName:s.resolveDatamodelName(y),datamodelId:h||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(g({connectionId:c||"",connectionType:T||"",tableName:d||"",datamodelName:s.resolveDatamodelName(y),datamodelId:h||"",databaseName:u||"",schemaName:m||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function A(){const N=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:y,connectionType:T,databaseName:u||""});O(!1);const L=T==="MSSQL"?`SELECT top 10 * FROM ${N}`:`SELECT * FROM ${N} LIMIT 10`;j(L),w(!0)}function C(){const N=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:y,connectionType:T,databaseName:u||""});j(`SELECT COUNT(*) as count FROM ${N}`),w(!0)}function R(){return(x==null?void 0:x.find(N=>N.connectionId===c&&(N.tableName===d||N.datamodelName===y)))!==void 0}function I(N){return i?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>D(N),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(_s,{column:N}),e.jsx("span",{children:N.column_name})]}),e.jsx("div",{onClick:L=>L.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(N.data_type)&&e.jsx(Ar,{column:N})})]}):e.jsx(Rr,{onClick:D,column:N})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs(s.Toggle,{title:`${R()?"Remove from":"Add to"} Assistant Scope`,pressed:R(),onPressedChange:b,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":R(),"text-muted-foreground":!R()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(fa,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:C,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(At,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-6",children:Array.from({length:3}).map((N,L)=>e.jsx(s.Skeleton,{className:"h-7 w-full"},L))}):e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[i&&e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:E()}),e.jsxs(s.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-2 py-0",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(N=>e.jsx("div",{className:s.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:I(N)},N.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function nn({ColumnsComponent:t,type:a}){var ke;const n=s.useEditorStore(ne=>ne.card),r=s.useEditorStore(ne=>ne.selectedConnectionId),o=s.useDashboardStore(ne=>ne.showFilters),i=s.useEditorStore(ne=>ne.selectedDatamodelId),c=s.useEditorStore(ne=>ne.selectedDatabaseName),l=s.useEditorStore(ne=>ne.selectedSchemaName),u=s.useEditorStore(ne=>ne.selectedTableName),m=s.useEditorStore(ne=>ne.isDevMode),{setSelectedTableName:d,setIsDevMode:h,setCardSql:x}=s.useEditorActions(),{connectionItems:f,modelItems:g,schemaItems:p,databaseItems:v,tableItems:j,columns:w,isConnectionsLoading:k,isModelsLoading:O,isConnectionsError:T,isModelsError:S,isDatabasesLoadingOrFetching:y,isDatabaseError:D,isSchemaLoadingOrFetching:b,isSchemaError:A,isColumnsError:C,isColumnsLoadingOrFetching:R,isTableLoadingOrFetching:I,isTableError:E,connectionType:N,isNonDbConnection:L,refetchDatabases:B,refetchModels:z,refetchSchemas:V,refetchTables:U,refetchColumns:X,refetchConnections:K,handleConnectionChange:F,handleDatabaseChange:_,handleSchemaChange:$,handleDatamodelChange:q,handleTableChange:Y,tableName:Q,schemaName:G}=s.useEditorAside(),{data:Z,refetch:te}=s.useDashboardCardQuery(n);function ae(){return t?t(G,Q,w):e.jsx(Fr,{schemaName:G,tableName:Q,columns:w,status:R?"Loading...":C?"Error":"Success"})}function se(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function oe(ne){ne===!0?Z&&(x(Z.userSql),setTimeout(()=>{te()},100)):x(""),h(ne)}function H(){if(!r||N==="S3"||N==="API")return null;if(!i||i==="none")return e.jsx(ze,{refetch:B,showNone:!0,onChange:_,isError:D,isLoading:y,items:v,value:c||"",title:"Database",type:"combobox"})}function P(){if(r&&!L&&(!c||c==="none")&&(!i||i==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function J(){if(!r||N==="S3"||N==="API")return null;if(!c||c==="none")return e.jsx(ze,{refetch:z,showNone:!0,onChange:q,isError:S,isLoading:O,items:g,value:i||"",title:"Model",type:"combobox"})}function ie(){return!r||N==="S3"||N==="API"||!c||c==="none"?null:e.jsx(ze,{refetch:V,onChange:$,isError:A,isLoading:b,items:p,value:l||"",title:"Schema",type:"combobox"})}function be(){function ne(){let le=!1;return N==="API"?(le=!1,le):((N==="S3"||r&&c&&c!=="none"&&l)&&(le=!0),le)}return ne()?e.jsx(ze,{refetch:U,onChange:Y,isError:E,items:j,isLoading:I,value:u||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:s.cn("flex h-full min-w-[310px] max-w-[310px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ze,{refetch:K,items:f,title:"Connection",value:r||"",onChange:F,isLoading:k,isError:T,type:"combobox",connectionTooltip:((ke=f==null?void 0:f.find(ne=>ne.id===r))==null?void 0:ke.type)||""}),H(),P(),J(),ie(),be()]}),ae(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:m,onCheckedChange:oe,id:"dev-mode"}),e.jsx(s.Label,{htmlFor:"dev-mode",children:"Advanced Mode"})]}),e.jsxs(s.Button,{onClick:se,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(ja,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function an({error:t,className:a="",textClassName:n="",copyButtonClassName:r=""}){const[o,i]=M.useState(!1),c=M.useRef(null),l=M.useRef(!1);function u(){t&&!l.current&&navigator.clipboard.writeText(t)}function m(x){(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),u())}function d(){const x=window.getSelection();if(x&&x.toString().trim()!==""){const f=x.toString();navigator.clipboard.writeText(f),i(!0),l.current=!0,setTimeout(()=>{i(!1),l.current=!1},1e3)}else l.current=!1}function h(){i(!1),l.current=!1}return e.jsxs("div",{className:`relative rounded-md border border-red-200 bg-red-50 p-3 dark:border-red-800 dark:bg-red-950/20 ${a}`,children:[e.jsx("div",{className:"float-right mb-2 ml-2",children:e.jsx(s.CopyButton,{text:t,className:`h-6 w-6 p-0 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 ${r}`})}),e.jsx("div",{ref:c,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${n}`,onClick:u,onKeyDown:m,onMouseUp:d,onMouseDown:h,tabIndex:0,role:"button","aria-label":"Click to copy error message or select text to copy",children:t}),o&&e.jsx("div",{className:"absolute bottom-1 right-1 rounded bg-green-100 px-2 py-1 text-xs text-green-600 dark:bg-green-900/30 dark:text-green-400",children:"Copied!"}),e.jsx("div",{className:"clear-both"})]})}function rn({sql:t,error:a,onDebugWithAssistant:n}){const r=s.useEditorStore(u=>u.isDevMode),{setIsDevMode:o,setCardSql:i,setRunSql:c}=s.useEditorActions();function l(){o(!r),i(t),setTimeout(()=>{c(!0)},100)}return e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&e.jsx(an,{error:a}),t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsx("div",{className:"rounded-md",children:e.jsx(s.CodeHighlighter,{code:t,language:"sql"})})})]}),!r&&t&&e.jsxs(s.Button,{onClick:l,variant:"secondary",size:"sm",children:[e.jsx(na,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),a&&n&&e.jsxs(s.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(da,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function on({sql:t,error:a,onDebugWithAssistant:n}){return e.jsxs(s.HoverCard,{openDelay:a?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(Tt,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"flex w-[600px]",children:e.jsx(rn,{sql:t,error:a,onDebugWithAssistant:n})})]})}var ln={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ft=M.createContext&&M.createContext(ln),Br=["attr","size","title"];function Pr(t,a){if(t==null)return{};var n=zr(t,a),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function zr(t,a){if(t==null)return{};var n={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(a.indexOf(r)>=0)continue;n[r]=t[r]}return n}function is(){return is=Object.assign?Object.assign.bind():function(t){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},is.apply(this,arguments)}function gt(t,a){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function ls(t){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?gt(Object(n),!0).forEach(function(r){Vr(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gt(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function Vr(t,a,n){return a=_r(a),a in t?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,t}function _r(t){var a=Ur(t,"string");return typeof a=="symbol"?a:a+""}function Ur(t,a){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(t)}function cn(t){return t&&t.map((a,n)=>M.createElement(a.tag,ls({key:n},a.attr),cn(a.child)))}function Re(t){return a=>M.createElement(qr,is({attr:ls({},t.attr)},a),cn(t.child))}function qr(t){var a=n=>{var{attr:r,size:o,title:i}=t,c=Pr(t,Br),l=o||n.size||"1em",u;return n.className&&(u=n.className),t.className&&(u=(u?u+" ":"")+t.className),M.createElement("svg",is({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,c,{className:u,style:ls(ls({color:t.color||n.color},n.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),i&&M.createElement("title",null,i),t.children)};return ft!==void 0?M.createElement(ft.Consumer,null,n=>a(n)):a(ln)}function $r(t){return Re({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function dn(t){const{theme:a}=s.useTheme(),n=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),o=s.useEditorStore(p=>p.card),i=s.useEditorStore(p=>p.activeTabCardId),c=s.Le(),{refetch:l}=s.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:m}=s.useEditorActions(),d=M.useRef(),h=M.useRef({}),x=r.cards.find(p=>p.id===i),f=M.useCallback(()=>{let p="";return t==="python"&&(p=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(x==null?void 0:x.sql)||""),p},[t,x]);M.useEffect(()=>{if(i&&o.id&&o.id!==i){if(d.current&&c){const p=d.current.getModel();p&&(h.current[o.id]=p);let v=h.current[i];if(!v){const j=f();v=c.editor.createModel(j,t),h.current[i]=v}d.current.setModel(v)}u(i,o),m(!0)}},[i,o,u,c,m,t,f]),M.useEffect(()=>{if(!c)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",v=n==="system"?p:n;c.editor.defineTheme("default",{base:v==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":v==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[a,n,c]),M.useEffect(()=>{const p=d.current;p&&c&&o&&p.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return l(),!1})},[c,l,o]);function g(p,v){if(d.current=p,!h.current[o.id]){const j=p.getModel(),w=f();h.current[o.id]=j||(v==null?void 0:v.editor.createModel(w,t))||p.getModel()}p.setModel(h.current[o.id])}return{handleEditorDidMount:g}}function Yr(){const t=s.useEditorStore(c=>c.card.sql),a=s.useEditorStore(c=>c.sqlGen),{setCardSql:n,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=dn("sql");function i(c){n(c),s.isObjectEmpty(a)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!t&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})]})}function Gr(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:a}=s.useEditorActions(),{handleEditorDidMount:n}=dn("python");function r(o){a(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function Hr({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function qs({variant:t="outline"}){var c;const{setCardSql:a}=s.useEditorActions();s.useEditorStore(l=>l.frame);const n=s.useEditorStore(l=>l.card);zs(((c=n.customCardPreferences)==null?void 0:c.url)||""),s.useEditorStore(l=>l.selectedSchemaName),s.useEditorStore(l=>l.selectedDatamodelId),s.useEditorStore(l=>l.selectedDatabaseName),s.useEditorStore(l=>l.selectedTableName),s.useEditorStore(l=>l.selectedConnectionId),s.useEditorStore(l=>l.isShowingVisual),n.sql;const r=s.useEditorStore(l=>l.onSave),{getUpdatedFrame:o}=Vs();function i(){const l=o();r==null||r(l)}return e.jsxs(s.Button,{onClick:i,className:"h-8",size:"sm",variant:t,children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Qr(){const t=s.useQueryClient(),[a,n]=M.useState(!1),r=s.useDashboardStore(m=>m.actions.setIsDashboardPanelOpen),{setIsVisualEditing:o}=s.useDashboardActions(),{getUpdatedFrame:i}=Vs(),c=s.useSelectedVisual(),l=ar(),u=()=>{const m=i();if(!(c!=null&&c.id)){s.ue.error("No visual selected");return}n(!0),l.mutate({visualId:c.id,data:{frameObject:m}},{onSuccess:()=>{n(!1),o(!1),r(!0),s.ue.success("Visual updated successfully"),t.invalidateQueries({queryKey:["resource-by-id","visual",c.id],exact:!0})},onError:()=>{n(!1),s.ue.error("Failed to update visual")}})};return e.jsxs(s.Button,{onClick:u,className:"h-8",size:"sm",children:[a&&e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-4 animate-spin font-bold"})," Saving"]}),!a&&e.jsxs(e.Fragment,{children:[e.jsx(ws,{className:"mr-2 size-4 font-bold"}),"Save"]})]})}function $s(){const{setTempQueryData:t,setSqlGen:a}=s.useEditorActions(),n=s.useQueryClient(),r=s.useEditorStore(u=>u.tempQueryData),o=s.useEditorStore(u=>u.onClose),i=s.useEditorStore(u=>u.card),{queryKey:c}=s.useDashboardCardQuery(i);function l(){if(r){const{queryKey:u,queryData:m}=r;u&&m&&n.setQueryData(u,m)}a({}),o==null||o()}return e.jsxs(s.Button,{onClick:l,className:"h-8",size:"sm",variant:"outline",children:[e.jsx(s.X,{className:"mr-2 size-4"}),"Close"]})}function ms(){const{setTempQueryData:t}=s.useEditorActions(),a=s.useQueryClient(),n=s.useEditorStore(v=>v.isDevMode),r=s.useEditorStore(v=>v.tempQueryData),o=s.useEditorStore(v=>v.card),{queryKey:i}=s.useDashboardCardQuery(o),{setCardSql:c,setSqlGen:l,setCardPython:u,setCardCustomCfg:m,setCardPreferences:d,updateDataSource:h,clearQueryConfig:x,setCardConfig:f,setCardType:g}=s.useEditorActions();function p(){const v=a.getQueryData(i);r!=null&&r.queryData||t({queryKey:i,queryData:v}),a.setQueryData(i,null),a.removeQueries({queryKey:i,exact:!0}),n&&h(s.EMPTY_DATA_SOURCE),c(""),l({}),x(),f(void 0),u(""),m(""),d({}),g("bar")}return e.jsxs(s.Button,{onClick:p,className:"h-8",size:"sm",variant:"secondary",children:[e.jsx(s.SquarePen,{className:"mr-2 size-4"}),"Clear"]})}function Kr(){const t=s.useQueryClient(),[a,n]=M.useState(!1),[r,o]=M.useState(!1);s.useEditorStore(U=>U.frame);const i=s.useEditorStore(U=>U.card);s.useEditorStore(U=>U.isShowingVisual),s.useEditorStore(U=>U.selectedConnectionId),s.useEditorStore(U=>U.tempQueryData),s.useEditorStore(U=>U.selectedDatabaseName),s.useEditorStore(U=>U.selectedDatamodelId),s.useEditorStore(U=>U.selectedSchemaName);const c=s.useEditorStore(U=>U.showAIDialog);s.useEditorStore(U=>U.selectedTableName);const l=s.useEditorStore(U=>{var X;return(X=U==null?void 0:U.card)==null?void 0:X.sql}),u=s.useEditorStore(U=>{var X;return(X=U==null?void 0:U.card)==null?void 0:X.python}),{sheetFilterValues:m}=s.useSheetFilterValues(),{setCardCustomCfg:d,setQueryResultColumns:h,setCardSql:x,setTempQueryData:f,setPythonStdOut:g,setCardPreferences:p,setCardType:v,setCardPython:j,runAssistant:w,setShowAIDialog:k}=s.useEditorActions();s.useEditorStore(U=>U.onSave),s.useEditorStore(U=>U.onClose),s.useEditorStore(U=>U.actions.setSqlGen);const O=s.useEditorStore(U=>U.runSql),T=s.useEditorStore(U=>U.actions.setRunSql),S=s.useEditorStore(U=>U.actions.setIsSqlRunning),{data:y,isLoading:D,isFetching:b,isSuccess:A,isError:C,error:R,queryKey:I,refetch:E,errorMessage:N}=s.useDashboardCardQuery(i);M.useEffect(()=>{if(y&&(y.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),g((y==null?void 0:y.output)||""),y.records.length>0)){const{dimensionKeys:U}=s.getKeys(y.records);h(U)}},[y,h,g]),M.useEffect(()=>{(D||b)&&S(!0),(C||A)&&S(!1),C&&(h([]),g(""))},[D,b,y,g,C,A,S,h,R]),M.useEffect(()=>{O&&(t.getQueryData(I)||E(),T(!1))},[O,E,T,I,t]);async function L(){const U=`Can you help me debug this query in the current table scope?
|
|
407
|
-
|
|
408
|
-
Error:
|
|
409
|
-
|
|
410
|
-
${N}
|
|
411
|
-
|
|
412
|
-
Query:
|
|
413
|
-
|
|
414
|
-
${l}
|
|
415
|
-
|
|
416
|
-
${u?`Python:
|
|
417
|
-
${u}`:""}
|
|
418
|
-
`;w(U)}function B(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(Hr,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function z(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(Yr,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(Gr,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function V(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:D||b,onClick:()=>{E()},className:"h-8 shrink-0",size:"sm",children:[D||b?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(on,{sql:y==null?void 0:y.sql,error:N,onDebugWithAssistant:L}),e.jsx(ms,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:U=>n(U),className:"",size:"sm",children:e.jsx($r,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:c,onClick:()=>{k(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:c?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($s,{}),e.jsx(qs,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[z(),B()]}),V()]})}function Wr({data:t}){var c;const[a,n]=M.useState([]),o=Object.keys(t[0]).map(l=>({accessorKey:l,header:({column:u})=>{const m=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[l,m==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsxs(s.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:[e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:i.getHeaderGroups().map(l=>e.jsx(s.TableRow,{className:"",children:l.headers.map(u=>e.jsx(s.TableHead,{className:"h-11 font-semibold text-foreground",children:u.isPlaceholder?null:s.flexRender(u.column.columnDef.header,u.getContext())},u.id))},l.id))}),e.jsx(s.TableBody,{children:(c=i.getRowModel().rows)!=null&&c.length?i.getRowModel().rows.map(l=>e.jsx(s.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(u=>e.jsx(s.TableCell,{className:"py-2",children:s.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},l.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Jr({card:t}){var w,k,O,T,S,y,D,b,A,C,R;const[a,n]=M.useState(!1),[r,o]=M.useState([]),{authToken:i}=s.useSemaphorContext(),c=s.getTokenParams(i==null?void 0:i.accessToken),l=s.useDashboardStore(I=>I.themeStyle),u={colors:((k=(w=l==null?void 0:l.chart)==null?void 0:w.dataset)==null?void 0:k.backgroundColor)||[]};(O=t.customCardPreferences)!=null&&O.inputData;const{getCard:m}=s.useCustomVisual(((T=t.customCardPreferences)==null?void 0:T.url)||""),d=((S=t.customCardPreferences)==null?void 0:S.visualType)||"single",h=s.useEditorStore(I=>I.frame),{setCustomCardPreferences:x}=s.useEditorActions(),{data:f}=s.useDashboardCardQuery(t),g=M.useCallback((I,E)=>{o(N=>({...N,[I]:E}))},[]);if(!((y=t.customCardPreferences)!=null&&y.componentName))return null;const p=m((D=t.customCardPreferences)==null?void 0:D.componentName);function v(I){n(I)}const j=Object.keys(((b=t.customCardPreferences)==null?void 0:b.dataInputCardIds)||{}).map(I=>{var L,B,z;const E=(B=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:B[I].cardId,N=(z=h==null?void 0:h.cards)==null?void 0:z.find(V=>V.id===E);return N||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(M.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&d==="single"&&e.jsx(p,{editing:!0,params:c,theme:u,settings:(A=t.customCardPreferences)==null?void 0:A.settings,onDataChange:g,data:(f==null?void 0:f.records)||[]}),p&&d==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((C=t.customCardPreferences)==null?void 0:C.dataInputCardIds)||{}).map(I=>{var L,B,z;const E=(B=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:B[I].cardId,N=(z=h==null?void 0:h.cards)==null?void 0:z.find(V=>V.id===E);if(N)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:v,onDataChange:g,dataInputIndex:I,card:N},N.id+I)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:g,settings:j.map(I=>{var E;return(E=I==null?void 0:I.customCardPreferences)==null?void 0:E.settings}),data:j.map(I=>I!=null&&I.id?r==null?void 0:r[I.id]:[])})})]})]},(R=t.customCardPreferences)==null?void 0:R.componentName)})}function un({className:t,...a}){var D;const n=s.useEditorStore(b=>b.card),r=s.isExplorerCard(n),o=((D=n.customCardPreferences)==null?void 0:D.showCardHeader)??!0,i=s.useEditorStore(b=>b.frame),c=s.useDashboardStore(b=>b.dashboard.filters),l=s.useEditorStore(b=>b.actions.setRunSql),{updateFilter:u}=s.useDashboardActions(),m=c==null?void 0:c.find(b=>b.id===i.filterId),{data:d,isLoading:h,isFetching:x,errorMessage:f,pagination:g,refetch:p}=s.useDashboardCardQuery(n),{setCard:v,updateCardInFrame:j}=s.useEditorActions(),{data:w}=s.useTopoJson(n),k=M.useMemo(()=>n.type==="pivotTable"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0?s.getPivotTableConfig({card:n,data:{records:(d==null?void 0:d.records)||[],columnSubtotalMeta:d==null?void 0:d.columnSubtotalMeta,subtotalColumns:d==null?void 0:d.subtotalColumns,pivotSchema:(d==null?void 0:d.pivotSchema)||[],groupByColumns:d==null?void 0:d.groupByColumns}}):null,[n,d==null?void 0:d.records,d==null?void 0:d.columnSubtotalMeta,d==null?void 0:d.subtotalColumns,d==null?void 0:d.pivotSchema,d==null?void 0:d.groupByColumns]),O=(b,A)=>{var R,I;const C={...n,paginationConfig:{page:b+1,pageSize:A}};v(C),j(C),n.sql&&((I=(R=n.preferences)==null?void 0:R.tablePrefs)!=null&&I.enableDevModePagination)&&l(!0)},T=M.useMemo(()=>!n.id||!(d!=null&&d.records)?null:s.createChartConfig({card:n,data:d==null?void 0:d.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:w}),[n.id,d==null?void 0:d.records,n.type,n.queryConfig,n.customCfg,n.preferences,w]);function S(b){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Jr,{card:b})})}function y(){if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!h&&!x)return f?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.SearchX,{className:"size-8 text-destructive"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Error fetching data. Please check your chart configuration":"Error fetching data. Please check your SQL or Python code."})]}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No results to display"})]});if((h||x)&&n.type!=="table")return e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!n.id)return null;if(n.type==="custom")return S(n);if(!["table","pivotTable","custom"].includes(n.type)&&T)return e.jsx(e.Fragment,{children:h||x?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:T})});if(n.type==="table")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:n,data:(d==null?void 0:d.records)||[],paginationMetadata:g,onPaginationChange:O,isLoading:h||x})});if(n.type==="pivotTable"&&k)return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.PivotTableVisual,{card:n,data:k.data,options:k.options,onAggregationChange:b=>{const A=s.handleAggregationChange(b,n.config),C={...n,config:A};v(C),j(C)},onAggregationLabelChange:b=>{const A=s.handleAggregationLabelChange(b,n.config),C={...n,config:A};v(C),j(C)}})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[o&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{enabled:!0,text:n.title,onSave:b=>v({...n,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:n.title||"Add title"})})},n.title),e.jsx(s.Editable,{enabled:!0,text:n.description||"",onSave:b=>v({...n,description:b}),children:e.jsx(s.CardDescription,{children:n.description||"Add description"})},n.description)]}),m&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{enabled:!0,className:"my-1",text:m.title||m.column,onSave:b=>u({...m,title:b}),children:e.jsx(s.Label,{children:m.title})}),e.jsx(s.FilterComponent,{filter:m})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:y()})]})}const bs=({language:t,value:a,onChange:n,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:a,onChange:n}),Xr=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),Zr=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(bs,{language:"json",value:n,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(bs,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(bs,{language:"javascript",value:t,onChange:o})})]}),eo=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function so(){const[t,a]=M.useState(!1),[n,r]=M.useState(""),[o,i]=M.useState(""),[c,l]=M.useState(""),[u,m]=M.useState(""),d=s.useEditorStore(T=>T.card),h=s.useEditorStore(T=>T.card.customCfg),x=h?JSON.stringify(h,null,2):"",{data:f}=s.useDashboardCardQuery(d),{data:g}=s.useTopoJson(d),{setCardCustomCfg:p,setCustomVisualCode:v}=s.useEditorActions(),j=T=>{var S,y;return JSON.stringify({...T,data:{...T.data,datasets:(y=(S=T.data)==null?void 0:S.datasets)==null?void 0:y.map(D=>({...D,data:[]}))}},null,2)},w=()=>{var S,y;if(!((S=f==null?void 0:f.records)!=null&&S.length))return;const T=s.createChartConfig({card:d,data:f.records,cardType:d.type,queryConfig:d.queryConfig,preferences:d.preferences,topoJson:g});if(T){r(j(T)),l(((y=d.preferences)==null?void 0:y.customVisualCode)||"");const D=s.merge(T,h);i(j(D))}},k=()=>{try{if(c&&v(c),o){const T=JSON.parse(o),S=s.getObjectDiff(JSON.parse(n),T);p(S),m("")}}catch{m("Invalid JSON configuration")}},O=Object.keys(h||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:a,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:w,className:O?"":"text-green-600 hover:text-green-700",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Xr,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(un,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Zr,{customCode:c,cardCustomCfgString:x,mergedConfig:o,onConfigChange:T=>i(T??""),onCodeChange:T=>l(T??"")})]}),e.jsx(eo,{error:u,hasCardCustomConfig:!!h,onReset:()=>{i(n),p(null)},onApply:k,onClose:()=>a(!1)})]})]})}function hs(t){const[a,n]=M.useState(null);return a}function Ys(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function to({onChartTypeChange:t}){const[a,n]=M.useState([]),{setCardCustomCfg:r,setCardPreferences:o,setCardType:i,setCustomCardPreferences:c}=s.useEditorActions(),{data:l}=Ys();function u(m,d){r(null),o({}),i(m),d&&c({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),t==null||t()}return M.useEffect(()=>{(async()=>{var d;if(l){const x=(await Promise.all((d=l==null?void 0:l.plugins)==null?void 0:d.map(async f=>(await s.loadManifest(f.value)).visuals.map(v=>({name:v.name,icon:v.icon,url:f.value}))))).flat();n(x)}})()},[l]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((m,d)=>e.jsx(no,{text:m.name,onClick:()=>u("custom",m),icon:m.icon},m.url+m.name+d))})]})}const no=({text:t,icon:a,onClick:n})=>{const r=hs(),o=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function Gs(t){return Re({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function ao(t){return Re({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function Hs(t){return Re({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function Qs(t){return Re({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4.387 3h15.226a1 1 0 0 1 .948 1.316l-5.105 15.316a2 2 0 0 1 -1.898 1.368h-3.116a2 2 0 0 1 -1.898 -1.368l-5.104 -15.316a1 1 0 0 1 .947 -1.316"},child:[]},{tag:"path",attr:{d:"M5 9h14"},child:[]},{tag:"path",attr:{d:"M7 15h10"},child:[]}]})(t)}function Ks(t){return Re({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function Ws(t){return Re({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function mn({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:o}=s.useEditorStore(d=>d.actions),{setCardCustomCfg:i,setCustomCardPreferences:c,setQueryConfig:l}=s.useEditorActions();function u(d,h){i(null),r({}),n(d),["custom","text","map"].includes(d)&&(o(!0),l(void 0)),t==null||t()}const m=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(s.IconButton,{openDelay:m,tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(He,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bar Chart",onClick:()=>u("bar"),className:"h-10 p-4",children:e.jsx(cs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(ds,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(As,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(Ks,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx(Rs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(Hs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(us,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(Os,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Funnel Chart",onClick:()=>u("funnel"),className:"h-10 p-4",children:e.jsx(Qs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(Bs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(Gs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Tornado Chart",onClick:()=>u("tornado"),className:"h-10 p-4",children:e.jsx(Ps,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(Ls,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(Ws,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(wt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(Fs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(Ye,{className:s.cn("size-5",a)})})]})}function ro({chartType:t,className:a,customIcon:n,componentName:r}){const o=hs();switch(t){case"bar":return e.jsx(cs,{className:a});case"line":return e.jsx(ds,{className:a});case"pie":return e.jsx(us,{className:a});case"radar":return e.jsx(Bs,{className:a});case"scatter":return e.jsx(Rs,{className:a});case"bubble":return e.jsx(Hs,{className:a});case"doughnut":return e.jsx(Os,{className:a});case"stackedBar":return e.jsx(As,{className:a});case"stackedLine":return e.jsx(Ks,{className:a});case"polarArea":return e.jsx(Gs,{className:a});case"funnel":return e.jsx(Qs,{className:a});case"tornado":case"pyramid":return e.jsx(Ps,{className:a});case"range":return e.jsx(Ls,{className:a});case"kpi":return e.jsx(Ws,{className:a});case"text":return e.jsx(Qe,{className:a});case"map":return e.jsx(Fs,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ye,{className:a});default:return e.jsx(He,{className:a})}}function hn({variant:t="ghost"}){var i,c;const[a,n]=M.useState(!1),r=s.useEditorStore(l=>l.card),o=r.type;return s.useDashboardStore(l=>l.isVisualEditing),e.jsxs(s.Popover,{open:a,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(ro,{className:"size-4",chartType:o,customIcon:(i=r.customCardPreferences)==null?void 0:i.icon,componentName:(c=r.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:l=>l.preventDefault(),className:"w-72 p-1",children:[e.jsx(mn,{onChartTypeChange:()=>n(!1)}),e.jsx(to,{onChartTypeChange:()=>n(!1)})]})]})}const We="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function jt(t,a){var r,o,i;const n=s.getNumberAxis(t,{});return["pie","doughnut","polarArea","funnel"].includes(a)?"category":((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:i.type)||"linear"}function oo(){var L,B,z,V,U,X;const[t,a]=M.useState(!1),n=s.useEditorStore(K=>{var F;return(F=K.card)==null?void 0:F.preferences}),r=s.useEditorStore(K=>{var F;return(F=K.card)==null?void 0:F.type}),o=s.getNumberAxis(n,{}),[i,c]=M.useState(jt(n,r)),[l,u]=M.useState(((z=(B=(L=n==null?void 0:n.chartOptions)==null?void 0:L.scales)==null?void 0:B[o])==null?void 0:z.min)||""),[m,d]=M.useState(((X=(U=(V=n==null?void 0:n.chartOptions)==null?void 0:V.scales)==null?void 0:U[o])==null?void 0:X.max)||""),[h,x]=M.useState(l||m?"custom":"auto"),[f,g]=M.useState(""),[p,v]=M.useState(0),[j,w]=M.useState(""),[k,O]=M.useState(""),[T,S]=M.useState(""),y=s.useEditorStore(K=>K.actions.setCardPreferences),{updateCardInFrame:D}=s.useEditorActions(),b=s.useEditorStore(K=>K.card),A=["pie","doughnut","polarArea","funnel"].includes(r);M.useEffect(()=>{var K,F,_,$,q,Y,Q,G,Z,te,ae,se,oe,H;c(jt(n,r)),u(((_=(F=(K=n==null?void 0:n.chartOptions)==null?void 0:K.scales)==null?void 0:F[o])==null?void 0:_.min)===0?0:""),d(((Y=(q=($=n==null?void 0:n.chartOptions)==null?void 0:$.scales)==null?void 0:q[o])==null?void 0:Y.max)||""),g(((te=(Z=(G=(Q=n==null?void 0:n.chartOptions)==null?void 0:Q.scales)==null?void 0:G[o])==null?void 0:Z.ticks)==null?void 0:te.stepSize)||""),v(((ae=n==null?void 0:n.numberAxisFormat)==null?void 0:ae.decimalPlaces)||0),w(((se=n==null?void 0:n.numberAxisFormat)==null?void 0:se.suffix)||""),O(((oe=n==null?void 0:n.numberAxisFormat)==null?void 0:oe.currency)||""),S(((H=n==null?void 0:n.numberAxisFormat)==null?void 0:H.locale)||"")},[t,n,o,r]);function C(K,F){return F===""||/^[0-9\b]+$/.test(F)?Number(F):Number(K)}function R(){const K=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(F=>F.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:k||"none",onValueChange:F=>O(F==="none"?"":F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),K.map(F=>e.jsx(s.SelectItem,{value:F,children:F},F))]})})]}),e.jsxs(s.Select,{value:T,onValueChange:F=>S(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(F=>e.jsx(s.SelectItem,{value:F.locale,children:F.locale},F.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:p,onChange:F=>v(Number(F.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${We}`})]})]})}function I(){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for number axis"})}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:A,value:i,onValueChange:K=>c(K),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"}),e.jsx(s.SelectItem,{value:"category",children:"Category"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:A,id:"scale-option",value:h,onValueChange:K=>x(K),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&i=="linear"&&E()]})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:l,onChange:K=>u(F=>C(F,K.target.value)),className:`col-span-1 h-8 w-full ${We}`}),e.jsx(s.Input,{value:m,onChange:K=>d(F=>C(F,K.target.value)),id:"max",className:`col-span-1 h-8 w-full ${We}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:f,onChange:K=>g(F=>C(F,K.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${We}`})]})]})}function N(){var $;let K={};h==="custom"&&(K={min:l,max:m,ticks:{stepSize:f}});const F={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...($=n==null?void 0:n.chartOptions)==null?void 0:$.scales,[o]:{type:i,...i==="linear"?K:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:j,currency:k,locale:T}};console.log(F),y(F);const _={...b,preferences:F};D(_)}return e.jsxs(s.Popover,{onOpenChange:K=>a(K),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Format Number",children:e.jsx(sa,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"max-w-65 z-[51]",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Format Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the format for number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[R(),I(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:N,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function io(){const t=s.useEditorStore(l=>{var u,m,d,h;return(h=(d=(m=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:m.plugins)==null?void 0:d.legend)==null?void 0:h.position}),a=s.useEditorStore(l=>{var u,m,d,h;return(h=(d=(m=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:m.plugins)==null?void 0:d.legend)==null?void 0:h.align}),n=s.useEditorStore(l=>{var u,m,d,h;return(h=(d=(m=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:m.plugins)==null?void 0:d.legend)==null?void 0:h.display}),{setLegendOptions:r}=s.useEditorActions(),o=l=>{r({display:l,position:t,align:a})},i=l=>{r({display:n,position:l,align:a})},c=l=>{r({display:n,position:t,align:l})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(ma,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"z-[51] w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:n,onCheckedChange:o,id:"displayLegend"})})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>i("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>i("left"),children:e.jsx(Un,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>i("bottom"),children:e.jsx(s.ArrowDown,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>i("right"),children:e.jsx(qn,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>c("start"),children:e.jsx(Bn,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>c("center"),children:e.jsx(Fn,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>c("end"),children:e.jsx(Pn,{className:"size-4"})})]})]})]})]})]})})]})}function lo(){const t=s.useEditorStore(i=>{var c,l;return(l=(c=i.card.preferences)==null?void 0:c.chartOptions)==null?void 0:l.indexAxis}),a=s.useEditorStore(i=>i.card.type),{setChartOrientation:n}=s.useEditorStore(i=>i.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(dt,{className:"size-4"}):e.jsx(ct,{className:"size-4"})})}function o(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(dt,{className:"size-4"}):e.jsx(ct,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?o():r()})}function xn(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.isShowingVisual),n=s.useEditorStore(c=>{var l,u;return(u=(l=c.card)==null?void 0:l.preferences)==null?void 0:u.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:o}=s.useEditorActions();function i(){const c=["xy","none","x","y"],u=(c.indexOf(r)+1)%c.length;o(c[u])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(lo,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(oo,{}),e.jsx(io,{})]}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:i,children:[(r==="xy"||!r)&&e.jsx(ca,{className:"size-4"}),r==="x"&&e.jsx(Xn,{className:"size-4"}),r==="y"&&e.jsx(Ca,{className:"size-4"}),r==="none"&&e.jsx(Ta,{className:"size-4"})]})]}):null}function co(){const t=s.useEditorStore(g=>g.frame),a=s.useEditorStore(g=>g.card),{setFrame:n,setActiveTabCardId:r,setCard:o,updateCardInFrame:i}=s.useEditorActions(),c=(g,p)=>{g.dataTransfer.setData("tabIndex",p.toString())},l=g=>{g.preventDefault()},u=(g,p)=>{const v=g.dataTransfer.getData("tabIndex");if(v===p.toString())return;const j=Array.from(t.cards),[w]=j.splice(parseInt(v),1);j.splice(p,0,w),n({...t,cards:j})};function m(g){const p=t.cards.filter(w=>w.id!==g),v=p[0],j={...t,cards:p,activeCardId:v.id};n(j),r(v.id),o(v)}function d(g,p){const v={...t,cards:[...t.cards,p],activeCardId:g.id};n(v),r(p.id)}function h(){const g={...a,id:s.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};d(a,g)}function x(g){const p={dataSource:g.dataSource,connectionId:g.connectionId,lastSelectedDatabase:g.lastSelectedDatabase,lastSelectedSchema:g.lastSelectedSchema,lastSelectedTable:g.lastSelectedTable,lastSelectedDatamodelId:g.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};d(g,p)}function f(g,p){return g.cards.length===1&&(p.displayTab===!0||p.displayTab===void 0)||g.activeCardId!==p.id&&(p.displayTab===!0||p.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=p.displayTab===void 0?!1:!p.displayTab;o({...p,displayTab:v}),i({...p,displayTab:v})},children:p.displayTab===!0||p.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(ta,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(s.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((g,p)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:v=>c(v,p),onDragOver:l,onDrop:v=>u(v,p),className:"",value:g.id,children:[f(t,g),e.jsx(s.Editable,{enabled:t.activeCardId===g.id,text:g.tabTitle||g.title,onSave:v=>{o({...a,tabTitle:v}),i({...a,tabTitle:v})},children:g.tabTitle||g.title},g.id),t.activeCardId===g.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>m(g.id)})]},g.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>x(a),children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:h,children:e.jsx(ea,{className:"h-4 w-4"})})]})})}function pn(){const t=s.useEditorStore(p=>p.frame),a=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>p.isSqlRunning),r=s.useEditorStore(p=>p.isDevMode),{setFrame:o,setActiveTabCardId:i,setCard:c,setIsDevMode:l,setRunSql:u}=s.useEditorActions(),{data:m,isLoading:d,isFetching:h}=s.useDashboardCardQuery(a);function x(p){const v=t.cards.find(j=>j.id===p);if(v!=null&&v.sql){r||l(!0),i(p);return}if(v!=null&&v.queryConfig){r&&l(!1),f(p),i(p);return}r||f(p),i(p)}function f(p){const v={...t,cards:t.cards.map(w=>w.id===a.id?a:w),activeCardId:p};o(v);const j=v.cards.find(w=>w.id===p);j.sql&&u(!0),c(j)}function g(){return a.type==="kpi"?d||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border border-border",children:e.jsx(s.KPICard,{card:a,data:m==null?void 0:m.records,isPending:d||h})})}):a.type==="text"?d||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:n,card:a,data:m==null?void 0:m.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(un,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:x,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(p=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:p.id,children:g()},p.id)),e.jsx(co,{})]})}function Je({children:t}){var O,T;s.useEditorStore(S=>S.frame);const a=s.useEditorStore(S=>S.card),n=s.useEditorStore(S=>S.isDevMode),r=s.useEditorStore(S=>S.isShowingVisual),o=s.useDashboardStore(S=>S.isVisualEditing),i=s.useEditorStore(S=>S.pythonStdOut);s.useEditorStore(S=>S.actions.setRunSql);const{setFrame:c,setCard:l,setActiveTabCardId:u,runAssistant:m,setIsDevMode:d,setCardPreferences:h}=s.useEditorActions(),{data:x,isLoading:f,isFetching:g,errorMessage:p,refetch:v}=s.useDashboardCardQuery(a);function j(){const S=JSON.stringify(x==null?void 0:x.records,null,2),y=new Blob([S],{type:"application/json"}),D=URL.createObjectURL(y),b=document.createElement("a");b.href=D,b.download=`${a.title}.json`,b.click()}function w(){const y=[Object.keys(x==null?void 0:x.records.reduce((C,R)=>({...C,...R}),{})).join(","),...((x==null?void 0:x.records)||[]).map(C=>Object.values(C).join(","))].join(`
|
|
419
|
-
`),D=new Blob([y],{type:"text/csv"}),b=URL.createObjectURL(D),A=document.createElement("a");A.href=b,A.download=`${a.title}.csv`,A.click()}function k(){const S=`Can you get the documentation for ${a.type} chart?`;m(S)}return a?e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(hn,{}),o&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:k,children:e.jsx(Hn,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(so,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:w,children:e.jsx(ao,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:j,children:e.jsx(aa,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(x==null?void 0:x.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(xn,{})]}),a.type==="table"&&a.sql&&!s.hasValidCardConfig(a.config)&&e.jsxs("div",{className:"mr-2 flex items-center gap-3",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((T=(O=a.preferences)==null?void 0:O.tablePrefs)==null?void 0:T.enableDevModePagination)??!1,onCheckedChange:S=>{var y;h({...a.preferences,tablePrefs:{...(y=a.preferences)==null?void 0:y.tablePrefs,enableDevModePagination:S}}),v()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),n&&e.jsx(mo,{})]}),r?e.jsx(pn,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(uo,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsx(Wr,{data:(x==null?void 0:x.records)||[]}),p&&e.jsx(an,{error:p})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function uo(){const t=s.useEditorStore(n=>n.pythonStdOut);if(!t)return null;const a=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function mo(){const t=s.useEditorStore(n=>n.isShowingVisual),a=s.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>a(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function ho(){var p,v;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:a}=Ys(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:l,manifest:u}=s.useCustomVisual((t==null?void 0:t.url)||""),m=(p=u==null?void 0:u.visuals)==null?void 0:p.find(j=>j.name===(t==null?void 0:t.componentName));function d(j,w){if(!t)return;const O={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:w,hookRef:null}};c({...t,dataInputCardIds:O})}function h(j){var k,O;const w=(k=o==null?void 0:o.cards)==null?void 0:k.filter(T=>{var S;return((S=T==null?void 0:T.customCardPreferences)==null?void 0:S.visualType)!=="multiple"}).map(T=>({value:T.id,label:T.tabTitle||T.title}));return e.jsx("div",{className:"space-y-2",children:(O=j==null?void 0:j.dataInputs)==null?void 0:O.map((T,S)=>{var y,D;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:T}),e.jsx(he,{className:"col-span-6 h-8 w-full justify-between",label:"",options:w||[],value:((D=(y=t==null?void 0:t.dataInputCardIds)==null?void 0:y[S])==null?void 0:D.cardId)||"",onValueChange:b=>d(S,b)})]},S+Math.random())})})}function x(j,w,k=[],O=""){var T,S;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((T=t==null?void 0:t.settings)==null?void 0:T[w])||O,onChange:y=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:y.target.value}})}},w):j==="select"?e.jsx(he,{className:"h-8 w-full",label:"",options:k,value:((S=t==null?void 0:t.settings)==null?void 0:S[w])||O,onValueChange:y=>{c({...t,settings:{...t==null?void 0:t.settings,[w]:y}})}}):null:null}function f(j){const w=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:w.map(([k,O])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:O.title}),x(O.ui,k,O.options,O.defaultValue)]},k))})}function g(j){t&&c({...t,visualType:j,componentName:""})}return e.jsxs(s.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(s.AccordionItem,{value:"plugin-settings",children:[e.jsx(s.AccordionTrigger,{children:"Plugin"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(he,{icon:e.jsx(Gn,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(t==null?void 0:t.url)||"",onValueChange:j=>c({...t||{url:"",componentName:""},url:j})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:i,onValueChange:g,children:e.jsxs(s.TabsList,{className:"h-9 w-full",children:[e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:l&&e.jsx(he,{icon:e.jsx(Zn,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(l==null?void 0:l.filter(j=>j.type===i).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),c({...t,componentName:j})}})})]})})]}),((v=r==null?void 0:r.customCardPreferences)==null?void 0:v.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[m&&m.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:h(m)})]}),m&&m.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:f(m)})})]})]})]})}function Oe(){const[t,a]=M.useState([]),n=s.useEditorStore(m=>m.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=s.useEditorStore(m=>m.actions),i=s.useEditorStore(m=>m.queryResultColumns);s.useEditorStore(m=>{var d;return(d=m.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),M.useEffect(()=>{i&&a(new Array(i.length).fill(!1))},[i]);function c(m,d){var h,x;d?n!=null&&n.onClickFilter&&((h=n==null?void 0:n.onClickFilter)==null?void 0:h.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:m,expression:""}]}):o({...n,onClickFilter:[{columnIndex:m,expression:""}]}):(o({...n,onClickFilter:(x=n==null?void 0:n.onClickFilter)==null?void 0:x.filter(f=>f.columnIndex!==m)}),a(f=>{const g=[...f];return g[m]=!1,g}))}function l(m,d){var x;const h=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.map(f=>f.columnIndex===m?{...f,expression:d.target.value}:f);o({...n,onClickFilter:h})}function u(m){var d,h,x,f;if(t!=null&&t[m]||(h=(d=n==null?void 0:n.onClickFilter)==null?void 0:d.find(g=>g.columnIndex===m))!=null&&h.expression)return e.jsx(s.Input,{value:(f=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(g=>g.columnIndex===m))==null?void 0:f.expression,onChange:g=>l(m,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:[e.jsx(s.Label,{children:"On Click"}),i==null?void 0:i.map((m,d)=>{var h,x;return e.jsx("div",{className:"group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((h=n==null?void 0:n.onClickFilter)!=null&&h.find(f=>f.columnIndex===d)),onCheckedChange:f=>c(d,f)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:m}),e.jsx("div",{className:"flex items-center gap-2",children:((x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(f=>f.columnIndex===d))&&e.jsx(s.Pencil,{onClick:()=>{a(f=>{const g=[...f];return g[d]=!f[d],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(d)]})},m)})]})}function xo({idx:t}){var l;const a=s.useEditorStore(u=>{var m;return(m=u.card)==null?void 0:m.preferences}),n=s.useEditorStore(u=>{var m;return(m=u.card.preferences)==null?void 0:m.datasetOptions}),r=s.useEditorStore(u=>u.actions.setCardPreferences),o=(l=a==null?void 0:a.chartOptions)==null?void 0:l.indexAxis,i=n==null?void 0:n.find(u=>u.idx===t);function c(u,m){(u==="end"||u==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const d={display:u!=="none",align:u,anchor:u,clamp:!0};if(!i)r({...a,datasetOptions:[...n||[],{idx:m,datalabels:d}]});else{const h={...i};h.datalabels=d;const x=n==null?void 0:n.map(f=>f.idx===m?h:f);r({...a,datasetOptions:x})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Lt,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>c("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>c("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(ha,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>c("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(pa,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx("button",{onClick:()=>c("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(xa,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function po(){const t=s.useEditorStore(i=>i.card),{data:a}=s.useDashboardCardQuery(t),{keys:n}=s.getKeys((a==null?void 0:a.records)||[]),r=n.slice(1).filter(i=>!s.METADATA_KEYS.includes(i));let o=r;if(["stackedBar","stackedLine"].includes(t.type)){const i=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:n[0],pivotKey:n[1],valueKey:n[2]}),{keys:c}=s.getKeys(i);o=c.slice(1)}return{transformedMetricKeys:o,dimensionKeys:n.slice(0,1),keys:n,defaultMetricKeys:r}}function Js({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function fn(){const t=s.useEditorStore(u=>u.card),a=s.useEditorStore(u=>{var m,d,h;return(h=(d=(m=u==null?void 0:u.card)==null?void 0:m.preferences)==null?void 0:d.chartOptions)==null?void 0:h.indexAxis}),{data:n}=s.useDashboardCardQuery(t),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{dimensionKeys:i,transformedMetricKeys:c,keys:l}=po();return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:i.map(u=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:u,children:gn(u)},u))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:c.map((u,m)=>e.jsx(jn,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:u,idx:m},u))})]})]})}function gn(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function jn({col:t,idx:a,className:n,iconClassName:r,children:o}){const i=s.useEditorStore(d=>{var h;return(h=d.card)==null?void 0:h.preferences}),c=s.useEditorStore(d=>{var h,x;return(x=(h=d.card)==null?void 0:h.preferences)==null?void 0:x.datasetOptions}),l=c==null?void 0:c.find(d=>d.idx===a),{setCardPreferences:u}=s.useEditorStore(d=>d.actions);function m(d){if(!l)u({...i,datasetOptions:[...c||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const h={...l};h.type=d==="area"?"line":d,h.fill=d==="area"?"origin":"";const x=c==null?void 0:c.map(f=>f.idx===a?h:f);u({...i,datasetOptions:x})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[o||e.jsx(Js,{className:"max-w-[100px]",title:t,children:gn(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(cs,{onClick:()=>m("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(ds,{onClick:()=>m("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(kt,{onClick:()=>m("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(xo,{idx:a})]})]})}function yn(){const t=s.useEditorStore(f=>f.selectedConnectionId),a=s.useEditorStore(f=>f.selectedDatamodelId),n=s.useEditorStore(f=>f.selectedDatabaseName),r=s.useEditorStore(f=>f.selectedSchemaName),o=s.useEditorStore(f=>f.selectedTableName),i=s.useDashboardStore(f=>f.dashboard.filters)||[],c=s.useDashboardStore(f=>f.actions.addFilter),l=s.useDashboardStore(f=>f.actions.removeFilter),{removeFilterValues:u}=s.useDashboardActions(),{modelItems:m,tableName:d,connectionType:h}=s.useEditorAside();function x(f,g="dashboard"){var y;const p=s.fmt(f.column_name),v=s.fmt(n||""),j=s.fmt(r||""),w=s.fmt(d);let k=s.getQualifiedTableName({schemaName:j,tableName:w,connectionType:h,databaseName:v}),O=`${k}.${p}`;const T=(y=m==null?void 0:m.find(D=>D.id===a))==null?void 0:y.name;a&&a!=="none"&&(O=`${s.DATAMODEL_NAMESPCACE}.${T}.${p}`,k=`${s.DATAMODEL_NAMESPCACE}.${T}`);const S=i==null?void 0:i.find(D=>D.column===O&&D.table===w&&(D.database===v||D.database===n));if(S)u(S.id),l(S.id);else{const D=s.v4();return d==="api"&&t?(c({location:g,id:D,column:O,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(f.data_type,k,p)}),D):(c({id:D,location:g,column:O,title:f.column_name,dataType:f.data_type,table:o||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(f.data_type,k,p)}),D)}}return{assignFilter:x}}function _e(){const t=s.useDashboardStore(l=>l.dashboard.filters),a=s.useEditorStore(l=>l.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:o}=yn();function i(l){const u=o(l,"frame");n({...a,filterId:u})}const c=t==null?void 0:t.find(l=>l.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(fo,{onSelect:i,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function fo({columns:t,onSelect:a}){var c;const[n,r]=ue.useState(!1),[o,i]=ue.useState("");return e.jsxs(s.Popover,{open:n,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(c=t.find(l=>l.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t==null?void 0:t.map(l=>e.jsxs(s.CommandItem,{value:l.column_name,onSelect:u=>{const m=u===o?"":u;i(m),r(!1),m&&a(l)},children:[l.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function go({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(fn,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Oe,{}),e.jsx(_e,{})]})]})]})})}function xs(){const t=s.useEditorStore(l=>l.card.type),a=s.useEditorStore(l=>l.isDevMode),n=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:r}=s.useEditorStore(l=>l.actions);function o(l){var d;const u={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},m={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(d=n==null?void 0:n.chartOptions)==null?void 0:d.plugins,...u}}};r(m)}function i(){var l,u,m;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((m=(u=(l=n==null?void 0:n.chartOptions)==null?void 0:l.plugins)==null?void 0:u.datalabels)==null?void 0:m.anchor)||"none",onValueChange:o,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function c(){var l,u,m;return e.jsx("div",{children:e.jsxs(s.Select,{value:((m=(u=(l=n==null?void 0:n.chartOptions)==null?void 0:l.plugins)==null?void 0:u.datalabels)==null?void 0:m.anchor)||"none",onValueChange:o,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"start",children:"Start"}),e.jsx(s.SelectItem,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"end",children:"End"})]})})]})})}return e.jsx(e.Fragment,{children:a?i():c()})}function jo({cardType:t}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(xs,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Oe,{}),e.jsx(_e,{})]})]})]})})}const yo={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},vo={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function bo(){const t=s.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:No(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(xs,{}),e.jsx(Oe,{}),e.jsx(_e,{})]})]})}function No(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(yo,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(vo,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea","funnel"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Co(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(s.FormatNumberSetting,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ns({children:t,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:a}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const So=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],wo=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Do=wo.map(t=>({label:t,value:t}));function ko(){var u,m,d,h,x,f,g,p,v,j,w,k,O,T,S,y,D,b;const t=s.useEditorStore(A=>A.card),a=(m=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:m.topoJsonUrl,[n,r]=M.useState(((h=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),c=Object.keys((i==null?void 0:i.objects)||{}).map(A=>({label:A,value:A}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(Ns,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ns,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(he,{className:"h-9",options:l,onValueChange:A=>{console.log("value",A),o({...t.preferences,mapVisualOptions:{topoJsonUrl:A}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:A=>{r(A.target.value)},onBlur:()=>{var A;console.log("onBlur",n),o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(he,{className:"h-9",options:c,value:((f=(x=t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:f.objectKey)||"",label:"Map Object",onValueChange:A=>{var C;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,objectKey:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(he,{className:"h-9",options:So,value:((p=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:A=>{var C;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projection:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(he,{className:"h-9",options:Do,value:((j=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:A=>{var C;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,colorScale:A}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ns,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((k=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:A=>{var C;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionScale:Number(A.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((S=(T=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:S[0])||0,onChange:A=>{var C,R,I,E;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[Number(A.target.value),((E=(I=(R=t.preferences)==null?void 0:R.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:E[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((b=(D=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:b[1])||0,onChange:A=>{var C,R,I,E;o({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[((E=(I=(R=t.preferences)==null?void 0:R.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:E[0])||0,Number(A.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Oe,{})]})}function To(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=s.useEditorStore(o=>o.actions);function n(o){a({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Xe({cardType:t,docContent:a,suffix:n="Chart"}){let r="pie-donut-polar";return t==="funnel"&&(r="funnel"),e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${n}`}),e.jsx(s.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:o=>o.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/docs/charts/${r}`,children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(xs,{}),t==="text"&&e.jsx(To,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Oe,{}),e.jsx(_e,{})]})]})]})})}function Eo(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:a}=s.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(he,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(fn,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Oe,{}),e.jsx(_e,{})]})]})]})})}function Io({cardType:t="table"}){console.log("cardType",t);const a=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),n=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Oe,{}),e.jsx(_e,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Mo=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),Ao=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),Lo=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function Ro(){const t=s.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Eo,{});case"tornado":case"pyramid":return e.jsx(Xe,{docContent:Mo,cardType:n});case"kpi":return e.jsx(Co,{});case"line":case"bar":return e.jsx(go,{cardType:n});case"range":return e.jsx(Xe,{docContent:Ao,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return e.jsx(Xe,{cardType:n});case"bubble":case"scatter":return e.jsx(jo,{cardType:n});case"table":return e.jsx(Io,{cardType:n});case"text":return e.jsx(Xe,{docContent:Lo,cardType:n,suffix:"Visual"});case"map":return e.jsx(ko,{});case"custom":return e.jsx(ho,{});default:return e.jsx(bo,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function vn({label:t,column:a,functions:n,onFunctionChange:r}){let o=n[0];"aggregate"in a?o=n.find(c=>c.value===a.aggregate)||n[0]:"granularity"in a&&(o=n.find(c=>c.value===a.granularity)||n[0]);function i(c){r(c)}return e.jsx(he,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:o.logo,options:n,value:o.value,onValueChange:c=>i(c),label:t,showPlaceholderLabel:!1})}const Oo=[{label:"Sum",value:"SUM",logo:e.jsx(At,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx($e,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(oa,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(_n,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(s.ArrowDown,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(s.ArrowUp,{className:"size-3.5"})}];function Fo({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions();let n=Oo;s.isTextDataType(t.type)&&(n=n.filter(o=>["COUNT","DISTINCT"].includes(o.value))),s.isNumberDataType(t.type)&&(n=n.filter(o=>!["DISTINCT"].includes(o.value)));function r(o){const i={...t,aggregate:o,label:Ke(t.name,o)};a(t.id,i)}return e.jsx(vn,{column:t,functions:n,onFunctionChange:o=>r(o),label:"Aggregation"})}const Bo=[{label:"Day (D)",value:"day",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function Po({column:t}){const{updateGroupByColumnOld:a}=s.useEditorActions();function n(r){const o={...t,granularity:r,label:Ve(t.name,r)};a(t.id,o)}return e.jsx(vn,{column:t,functions:Bo,onFunctionChange:r=>n(r),label:"Granularity"})}function zo({col:t,onChange:a,droppableId:n}){const{columns:r}=s.useDataColumns(),o=M.useMemo(()=>{let l=[];(n===Ee||n===Ie||n===Me)&&(l=r);const u=l==null?void 0:l.filter(m=>m.column_name!==t.name);return u==null?void 0:u.map(m=>({id:m.column_name,value:m.column_name}))},[r,n,t.name]),i=[{id:t.name,value:t.name}];function c(l){const u=r==null?void 0:r.find(m=>{var d;return m.column_name===((d=l[0])==null?void 0:d.id)});u&&a(u)}return o!=null&&o.length?e.jsx(s.ComboBox2,{multiple:!1,options:o,selectedOptions:i,onChange:c,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted pl-0 pr-8"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:t.name})}function bn({column:t}){const a=s.useEditorStore(u=>u.card.type),n=s.useEditorStore(u=>{var m,d;return(d=(m=u.card)==null?void 0:m.config)==null?void 0:d.metricColumns}),r=(n==null?void 0:n.map(u=>u.label))||[],o=r==null?void 0:r.find(u=>u===t.label||u===t.name),i=o?r.indexOf(o):-1;function c(){return e.jsx("div",{className:"pr-1",children:o&&e.jsx(jn,{idx:i,col:o,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function l(){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Data Labels"}),e.jsx(xs,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(a)&&c(),["pie","doughnut"].includes(a)&&l()]})}function Vo({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[o,i]=M.useState(!1),{updateGroupByColumnOld:c,updateMetricColumnOld:l,updatePivotByColumnOld:u}=s.useEditorActions(),{attributes:m,listeners:d,setNodeRef:h,transform:x,transition:f,isDragging:g}=s.useSortable({id:t.id,data:{type:a}}),p=x?{opacity:g?.5:void 0,transform:s.CSS.Translate.toString(x),transition:f}:void 0,v=s.isTextDataType(t.type);function j(S){const y=s.isNumberDataType(S.data_type),D=s.isTextDataType(S.data_type),b=s.isDateDataType(S.data_type),A=y?"number":D?"string":b?"date":"string";if(r===Ee){if(D){const C={id:t.id,name:S.column_name,type:A,role:"groupby"};c(t.id,C)}if(b){const C={id:t.id,name:S.column_name,type:A,role:"groupby",label:Ve(S.column_name,"month"),granularity:"month"};c(t.id,C)}}if(r===Me){if(D){const C={id:t.id,name:S.column_name,type:A,role:"groupby"};u(t.id,C)}if(b){const C={id:t.id,name:S.column_name,type:A,label:Ve(S.column_name,"month"),granularity:"month",role:"groupby"};u(t.id,C)}}if(r===Ie){const C={id:t.id,name:S.column_name,type:A,role:"metric",label:Ke(S.column_name,"SUM"),aggregate:y?"SUM":"COUNT"};l(t.id,C)}}function w(){if(r===Ie)return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 max-h-32 overflow-y-auto rounded-md border border-border p-3 text-sm",children:e.jsx(bn,{column:t})})}function k(){const S=s.isDateDataType(t.type);if(r===Ie)return e.jsx(Fo,{column:t});if((r===Ee||r===Me)&&S)return e.jsx(Po,{column:t})}function O(){return e.jsx("div",{className:s.cn("grow",{"pl-3":(r===Ee||r===Me)&&v}),children:e.jsx(zo,{col:t,onChange:j,droppableId:r})})}function T(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{className:"h-full pl-2",onClick:()=>i(!o),children:o?e.jsx(Da,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(Et,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...d,...m,ref:h,style:p,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted",children:[T(),k(),O()]}),o&&w()]}),e.jsx("div",{className:s.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:o}),children:e.jsx("button",{onClick:()=>n(t.id),children:e.jsx(s.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function Cs({id:t,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:i}){var p,v;const{setNodeRef:c,isOver:l,over:u}=s.useDroppable({id:t}),m=s.useDndStore(j=>j.activeId),d=s.useEditorStore(j=>{var w;return(w=j.card)==null?void 0:w.type}),h=l||((v=(p=u==null?void 0:u.data)==null?void 0:p.current)==null?void 0:v.type)===o,x=m?r:n,f=o===rs?"Rows":o===os?"Pivot Columns":"Columns";function g(){if(!x||x.length===0)return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(j=>j.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md p-4",h&&"border border-muted-foreground/20"),ref:c,children:[e.jsxs("div",{className:"flex items-center justify-between pr-5",children:[e.jsx(s.Label,{className:"text-sm",children:a}),d!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:f})]}),g(),e.jsx("div",{className:"space-y-2",children:x==null?void 0:x.map(j=>j.id===tn.id?e.jsx(_o,{},j.id):e.jsx(Vo,{droppableId:t,type:o,column:j,onRemoveColumn:i},j.id))})]})})}function _o(){return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm",children:e.jsx("span",{className:"text-muted-foreground/70",children:"Drop here"})})}function Nn({children:t,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:i,transform:c,transition:l,isDragging:u}=s.useSortable({id:a,data:{type:n}}),m=c?{opacity:u?.5:void 0,transform:s.CSS.Translate.toString(c),transition:l}:void 0;return e.jsx("div",{...o,...r,ref:i,style:m,children:t})}function Uo(){const t=s.useEditorStore(j=>{var w;return(w=j.card.queryConfig)==null?void 0:w.orderBy})||[],a=s.useEditorStore(j=>{var w;return(w=j.card.queryConfig)==null?void 0:w.groupByColumns})||[],n=s.useEditorStore(j=>{var w;return(w=j.card.queryConfig)==null?void 0:w.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:o,updateOrderByColumn:i}=s.useEditorActions(),c=[...a,...n];if(c.length===0)return e.jsx(e.Fragment,{});const l=e.jsx(Yn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(Vn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=e.jsx($n,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(zn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=c==null?void 0:c.filter(j=>!t.some(w=>w.columnId===j.id)).map(j=>({id:j.id,value:j.label||j.name}));function x(j,w){const k=f(j);return k?k.role==="metric"?w==="asc"?m:d:w==="asc"?l:u:null}function f(j){return c.find(w=>w.id===j)}function g(j){const w=t.find(k=>k.columnId===j);if(w){const k={...w,direction:w.direction==="asc"?"desc":"asc"};i(k)}}const p=j=>{r({columnId:j.id,direction:"asc"})};function v(j){const w=t.find(k=>k.columnId===j);w&&o(w)}return e.jsx(s.SortableContext,{items:t.map(j=>qe(j.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md p-4 text-sm",children:[e.jsx(s.Label,{className:"text-sm",children:"Sort By"}),h.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(s.ComboBox2,{multiple:!1,options:h,selectedOptions:[],onChange:j=>p(j[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),t.map(j=>{var w,k;return e.jsx(Nn,{id:qe(j.columnId),type:Us,children:e.jsx("div",{className:"group flex h-8 items-center gap-2 rounded-sm p-0",children:e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2 rounded-sm bg-muted px-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Et,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Js,{className:"w-[175px] text-sm",children:((w=f(j.columnId))==null?void 0:w.label)||((k=f(j.columnId))==null?void 0:k.name)})]}),e.jsx("button",{title:j.direction==="asc"?"Ascending":"Descending",onClick:()=>g(j.columnId),className:"rounded-sm p-0",children:x(j.columnId,j.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>v(j.columnId),className:"rounded-sm p-0",children:e.jsx(s.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},j.columnId)},qe(j.columnId))})]})})}function qo(){const t=s.useEditorStore(v=>{var j;return((j=v.card.queryConfig)==null?void 0:j.groupByColumns)||[]}),a=s.useEditorStore(v=>v.card.type),n=s.useDndStore(v=>v.previewGroupByColumns),r=s.useEditorStore(v=>{var j;return((j=v.card.queryConfig)==null?void 0:j.metricColumns)||[]}),o=s.useDndStore(v=>v.previewMetricColumns),i=s.useEditorStore(v=>{var j;return((j=v.card.queryConfig)==null?void 0:j.pivotColumns)||[]}),c=s.useDndStore(v=>v.previewPivotColumns),{removeColumnFromGroupBy:l,removeColumnFromMetricColumns:u,removeColumnFromPivotBy:m}=s.useEditorActions();function d(v){l(v)}function h(v){u(v)}function x(v){m(v)}let f="Group By",g="Metrics",p="Stack By";return a==="table"&&(f="Rows",g="Metrics",p="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(mn,{iconClassName:"size-[19px]"}),e.jsxs(s.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(Cs,{onRemoveColumn:d,sortableType:rs,id:Ee,label:f,columns:t,previewColumns:n}),e.jsx(Cs,{onRemoveColumn:x,sortableType:os,id:Me,label:p,columns:i,previewColumns:c}),e.jsx(Cs,{onRemoveColumn:h,sortableType:ks,id:Ie,label:g,columns:r,previewColumns:o}),e.jsx(Uo,{})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Xs({children:t,column:a,id:n,sortableType:r,className:o}){const[i,c]=M.useState(!1),{removeEditorFilter:l,clearEditorFilter:u}=s.useEditorActions(),m=s.useEditorStore(h=>{var x,f;return(f=(x=h.card.queryConfig)==null?void 0:x.filters)==null?void 0:f.some(g=>g.filterColumnName===a.name)});function d(h){l(h)}return e.jsx(Nn,{id:n,type:r,children:e.jsxs("div",{className:s.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":i}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-sm",children:a.name}),m&&e.jsx("button",{onClick:()=>u(a),children:e.jsx(s.FilterX,{className:"size-3 cursor-pointer items-center justify-center text-muted-foreground hover:text-foreground"})})]}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>d(a),children:e.jsx(s.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:s.cn("group flex items-center rounded-t-md text-sm",!i&&"rounded-b-md",i&&"border border-border"),children:[e.jsx("div",{children:e.jsx(s.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:s.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",o),children:t})]})]})})}function $o({column:t,sortableType:a}){const n=s.useDashboardStore(k=>k.themeStyle),r=s.useEditorStore(k=>{var O,T;return(T=(O=k.card)==null?void 0:O.queryConfig)==null?void 0:T.filters}),o=s.useEditorStore(k=>{var O,T;return(T=(O=k.card.queryConfig)==null?void 0:O.filterColumns)==null?void 0:T.find(S=>S.name===t.name)}),{selectedConnectionId:i,selectedDatabaseName:c,selectedTableName:l}=s.useEditorAside(),u=M.useMemo(()=>{var k;return(k=r==null?void 0:r.find(O=>O.filterColumnName===t.name))==null?void 0:k.filterValue},[r,t.name]),m=M.useMemo(()=>Array.isArray(u)?u.map(k=>({id:k,value:k})):[],[u]),{updateEditorFilterValue:d}=s.useEditorActions(),h={column:t.name,sql:t.sql,id:t.name,connectionId:i,dataType:t.type},{data:x,isLoading:f,isFetching:g,isError:p}=s.useFilterQuery(h),v=M.useMemo(()=>{var O;return h.column?(O=x==null?void 0:x.records)==null?void 0:O.map(T=>{let S=h.column.split(".").slice(-1)[0].replace(/"/g,"");return T[S]===void 0&&(S=S.toLowerCase()),{id:T[S],value:T[S]}}):[]},[x,h.column]);function j(k){const O=k.map(T=>T.id);d(t.name,O)}function w(){return f||g?e.jsx(s.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):p?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(s.ComboBox2,{renderFilterModeButton:()=>e.jsx(Yo,{columnName:t.name}),showNegativeIndicator:(o==null?void 0:o.mode)==="exclude",options:v,onChange:j,selectedOptions:m,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Xs,{className:"w-60",id:t.id,sortableType:a,column:t,children:w()})}function Yo({columnName:t}){const{setEditorFilterMode:a}=s.useEditorActions(),n=s.useEditorStore(o=>{var i,c;return(c=(i=o.card.queryConfig)==null?void 0:i.filterColumns)==null?void 0:c.find(l=>l.name===t)});function r(){(n==null?void 0:n.mode)==="exclude"?a(t,"include"):a(t,"exclude")}return e.jsx(s.Button,{onClick:r,variant:"secondary",size:"sm",className:s.cn("h-5 text-xs hover:underline",{}),children:s.titleCase((n==null?void 0:n.mode)==="exclude"?"exclude":"include")})}function Go({column:t,sortableType:a}){const[n,r]=M.useState(!1),{selectedConnectionId:o,selectedDatabaseName:i,selectedTableName:c}=s.useEditorAside(),l={column:t.name,sql:t.sql,id:t.name,connectionId:o,title:"",dataType:t.type},{isLoading:u,isFetching:m,isError:d,data:h}=s.useFilterQuery(l),x=h==null?void 0:h.records,{dateRange:f,setDateRange:g,initialDateRange:p}=s.useDateRangeFromRecords(x),{updateEditorFilterValue:v}=s.useEditorActions();function j(O){var S,y;const T={gte:(S=O==null?void 0:O.from)==null?void 0:S.toISOString(),lte:(y=O==null?void 0:O.to)==null?void 0:y.toISOString()};v(t.name,T)}function w(){v(t.name,null,!0),g(p)}function k(){return u||m?e.jsx("div",{children:e.jsx(s.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):d?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):x?e.jsx(s.DateRangePopover,{title:l.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:f,setDateRange:g,onApply:j,onClear:w}):e.jsx(s.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Xs,{className:"w-72",id:t.id,sortableType:a,column:t,children:k()})}function Ho({id:t,label:a,columns:n,previewColumns:r,sortableType:o}){var g,p;const{setNodeRef:i,isOver:c,over:l}=s.useDroppable({id:t}),u=s.useDndStore(v=>v.activeId),m={},d=c||((p=(g=l==null?void 0:l.data)==null?void 0:g.current)==null?void 0:p.type)===o;function h(){if(!f||f.length===0)return e.jsx("div",{className:"flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}function x(v){const j=s.isDateDataType(v.type);return v.id===tn.id?e.jsx(Xs,{id:v.id,sortableType:o,column:v,children:e.jsx(Qo,{})},v.id):j?e.jsx(Go,{droppableId:t,sortableType:o,column:v},v.id):e.jsx($o,{droppableId:t,sortableType:o,column:v},v.id)}const f=u?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(v=>v.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md border-muted-foreground/50 p-4",d&&"border border-muted-foreground/20"),ref:i,style:m,children:[e.jsx(s.Label,{className:"text-sm",children:a}),h(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:f==null?void 0:f.map(v=>x(v))})]})})}function Qo(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm text-muted-foreground",children:"Drop here"})}function Ko(){const t=s.useEditorStore(o=>{var i;return((i=o.card.queryConfig)==null?void 0:i.filterColumns)||[]}),a=s.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=s.useEditorActions();function r(o){n(o)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(Ho,{onRemoveColumn:r,sortableType:Es,id:Ts,label:"Filters",columns:t,previewColumns:a})})}function Wo(){const t=s.useEditorStore(i=>i.card),a=s.useEditorStore(i=>i.showAIDialog),{setShowAIDialog:n}=s.useEditorActions(),{data:r,errorMessage:o}=s.useDashboardCardQuery(t);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ms,{}),!a&&e.jsxs(s.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(ya,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(on,{sql:r==null?void 0:r.sql,error:o})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium text-black",children:"Preview"}),e.jsx($s,{}),e.jsx(qs,{variant:"default"})]})]})}function Jo(){const t=M.useRef(null),a=M.useRef(null),n=s.useEditorStore(l=>l.isShowingVisual),r=s.useEditorStore(l=>l.showAIDialog),o=s.useEditorStore(l=>l.isDevMode);M.useEffect(()=>{var l,u,m,d;r?((l=t.current)==null||l.resize(0),(u=a.current)==null||u.resize(0)):((m=t.current)==null||m.resize(25),(d=a.current)==null||d.resize(25))},[r]);function i(){return e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Kr,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!r?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(Ro,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Je,{})})]}):e.jsx(Je,{})})]})}function c(){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"grow","data-biz-mode-container":"",children:n?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:a,defaultSize:25,maxSize:30,children:e.jsx(qo,{})})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{defaultSize:75,maxSize:100,children:e.jsxs(s.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(s.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(Wo,{}),e.jsx(Ko,{})]}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(Je,{})})]})})]}):e.jsx(Je,{})})})}return e.jsx(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:o?i():c()})}function Xo(t){const a=s.useAIInteractionStore(P=>P.currentAIContext),[n,r]=M.useState(""),[o,i]=M.useState(null),{authToken:c}=s.useSemaphorContext(),l=s.useEditorStore(P=>{var J;return(J=P==null?void 0:P.card)==null?void 0:J.sql}),u=s.useEditorStore(P=>P.isDevMode),m=s.useEditorStore(P=>{var J;return(J=P==null?void 0:P.card)==null?void 0:J.python}),{setCardPython:d,setCardSql:h,setRunSql:x,switchCardType:f,setQueryConfig:g}=s.useEditorActions(),p=s.useEditorStore(P=>P.currentAssitantScope)||[],v=s.useEditorStore(P=>P.userInputForAI),j=s.useEditorStore(P=>P.triggerAIRun),w=s.useEditorStore(P=>P.card),k=s.useEditorStore(P=>P.selectedDatabaseName),O=s.useEditorStore(P=>P.selectedTableName),T=s.useEditorStore(P=>P.selectedConnectionId),S=s.useEditorStore(P=>P.selectedSchemaName),y=s.useDashboardStore(P=>P.dashboard.aiScopeTables),{errorMessage:D,refetch:b,data:A}=s.useDashboardCardQuery(w),{setTriggerAIRun:C,setCurrentAssitantScope:R,setCardConfig:I}=s.useEditorActions(),{selectedDatamodelName:E,connectionType:N,selectedDatamodelId:L}=s.useEditorAside(),{messages:B,setMessages:z,reload:V,error:U,append:X,input:K,setInput:F,status:_,handleInputChange:$,handleSubmit:q,stop:Y}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant",isDevMode:u,aiContext:a},maxSteps:10,onError:P=>{console.log("on error",P)},onToolCall:Q,onFinish(P,J){G(J.usage),r(""),J.finishReason==="stop"&&r("")}});M.useEffect(()=>{j&&v&&(X({role:"user",content:v}),C(!1))},[j,v,X,C]);async function Q({toolCall:P}){var J,ie,be,ke;if(["createChartFromSql","createForecast"].includes(P.toolName)){const ne=P.args.sql,le=P.args.python,ce=P.args.chartType;return f(ce),h(ne),d(le),x(!0),{status:"success",message:"Let the user know that chart is created"}}else if(P.toolName==="getTableColumns")r("Getting table columns...");else{if(P.toolName==="getUserSql")return l?{status:"success",sql:l,python:m||""}:{status:"error",message:"No SQL found"};if(P.toolName==="getCurrentTableScope")return r("Getting table scope..."),se(),{status:"success",tables:p};if(P.toolName==="generateQueryConfig"){r("Generating query config...");const ne=P.args.chartType,le=P.args.queryConfig;P.args.cardConfig,f(ne),I(le),h(void 0),d(void 0);const ce=await b();return(J=ce==null?void 0:ce.data)!=null&&J.error?{status:"error",queryConfig:le,message:(ie=ce==null?void 0:ce.data)==null?void 0:ie.error.message}:(be=ce==null?void 0:ce.data)!=null&&be.records?{status:"success",queryConfig:le,message:"The data has been visualized"}:{status:"success",queryConfig:le,message:"The data has been visualized",records:(ke=ce==null?void 0:ce.data)==null?void 0:ke.records}}else r("Analyzing...")}}function G(P){i(J=>J?{promptTokens:J.promptTokens+P.promptTokens,completionTokens:J.completionTokens+P.completionTokens,totalTokens:J.totalTokens+P.totalTokens}:P)}function Z(P){const J=s.removeFromScopeArray(p,P);te(J)}function te(P){const J=s.sanitizeAIScope(P);R(J),z(ie=>[...ie,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(J)}`}])}function ae(){const P={databaseName:k||"",schemaName:S||"",tableName:O||"",datamodelId:L||"",datamodelName:s.resolveDatamodelName(E),connectionId:T||"",connectionType:N||""},J=s.dedup([...p,P]);te(J)}function se(){const P={databaseName:k||"",schemaName:S||"",tableName:O||"",datamodelName:s.resolveDatamodelName(E),connectionId:T||"",connectionType:N||"",datamodelId:L||""};if(!s.isInAiScopeArray([...y||[],...p],P)||p.length===0){const ie=s.dedup([...y||[],...p,P]).filter(be=>be.connectionId===P.connectionId);te(ie)}}const oe=!["ready","error"].includes(_),H=s.getErrorMessage(U);return{messages:B,setMessages:z,reload:V,append:X,input:K,setInput:F,isLoading:oe,handleSetAIScope:se,handleAddCurrentTableToScope:ae,removeFromCurrentSelections:Z,currentAssitantScope:p,setCurrentAssitantScope:R,handleInputChange:$,handleSubmit:q,stop:Y,chatStatus:_,toolStatus:n,llmUsage:o,onFinish:t,errorMessage:H}}const Zo=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function yt(){const t=M.useRef(null),a=M.useRef(null),[n,r]=M.useState(!1),[o,i]=M.useState(s.isDevEnv),[c,l]=M.useState(!1),[u,m]=M.useState(!1),d=s.useCurrentAIContext(),{setCurrentAIContext:h}=s.useAIActions(),x=s.useDashboardStore(Y=>Y.dashboard.aiContext),f=s.useEditorStore(Y=>Y.card.dataSource),g=s.useEditorStore(Y=>Y.actions.setCardSql),p=s.useEditorStore(Y=>Y.actions.setRunSql),v=s.useEditorStore(Y=>Y.showAIDialog),j=s.useDashboardStore(Y=>Y.handleOpenAssistantProfile),{setShowAIDialog:w,setCardPython:k}=s.useEditorActions(),{setDataSource:O}=s.useEditorActions(),{assistantProfile:T}=s.useAssistantProfile(),{messages:S,setMessages:y,reload:D,append:b,input:A,setInput:C,isLoading:R,handleInputChange:I,handleSubmit:E,stop:N,chatStatus:L,llmUsage:B,errorMessage:z}=Xo();s.useAssistantScroll({scrollContainerRef:t,inputRef:a,messages:S}),M.useEffect(()=>{var Y;v&&((Y=a.current)==null||Y.focus(),h({selectedEntities:(f==null?void 0:f.selectedEntities)||[]}))},[v,f,h]);function V(Y,Q){Q==="sql"?(g(Y),p(!0)):Q==="python"&&(k(Y),p(!0))}function U(){var Y;(Y=x==null?void 0:x.selectedEntities)==null||Y[0],m(!0)}function X(){d.selectedEntities.length===0&&h({selectedEntities:(x==null?void 0:x.selectedEntities)||[]})}function K(Y){X();const Q={role:"user",content:Y.title+" "+Y.subtitle};b(Q)}function F(Y){X(),b({role:"user",content:Y})}function _(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",variant:"ghost",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:l,children:"System Message"})]})]})}function $(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const q=(A==null?void 0:A.length)===0&&(S==null?void 0:S.filter(Y=>Y.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[$(),j&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:j,children:(T==null?void 0:T.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center gap-2",children:[_(),e.jsx(s.IconButton,{tooltip:"Add Context",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:U,children:e.jsx(s.Settings,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{y([]),D()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-8 text-muted-foreground hover:text-foreground",size:"sm",onClick:()=>{w(!1)},children:e.jsx(s.EyeOff,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"mt-2 flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:S,showTools:o,handleRun:V,showSystemMessage:c}),e.jsx(s.ChatStatus,{messages:S,chatStatus:L,errorMessage:z})]})}),e.jsxs("div",{className:"mb-3",children:[q&&!T&&e.jsx(s.Placeholders,{onClick:K,placeholders:Zo}),e.jsx("div",{children:q&&T&&e.jsx(s.SeedQuestions,{seedQuestions:T.seedQuestions||[],handleSeedQuestionClick:F})})]}),e.jsx(s.ChatInputWithContext,{ref:a,setInput:C,stop:N,input:A,handleInputChange:I,handleSubmit:Y=>{X(),E(Y)},isLoading:R,onFocus:()=>{}}),B&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",B.promptTokens," prompt tokens,"," ",B.completionTokens," completion tokens,"," ",B.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(f==null?void 0:f.selectedEntities)||[],open:u,onOpenChange:m,dataSource:f||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function Cn(t,a,n){var r;return!n||!((r=n.baseEntity)!=null&&r.name)||!n.joins?!1:t===a||t===n.baseEntity.name||a===n.baseEntity.name?!0:n.joins.some(o=>{const i=s.getQualifiedEntityName(o.source),c=s.getQualifiedEntityName(o.target);return i===t&&c===a||i===a&&c===t})}function ei(t,a,n){if(a.length===0)return{isValid:!0};const r=a[0].qualifiedEntityName;if(!r)return{isValid:!0};if(r!==t.qualifiedEntityName&&t.qualifiedEntityName)if(n){if(!Cn(r,t.qualifiedEntityName,n))return{isValid:!1,showError:!0}}else return{isValid:!1,showError:!0};return{isValid:!0}}function Is(){s.ue.error("Join Configuration Required",{richColors:!0,description:"To combine fields from two different tables, you need to define a join between them first.",position:"top-center",duration:4e3})}function Ms(t,a){return a.some(n=>n.name===t.name&&n.qualifiedEntityName===t.qualifiedEntityName)}const Zs=t=>{var C;const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:o,updateSortByColumn:i,removeGroupByColumn:c,removeMetricColumn:l,removePivotByColumn:u,removeSortByColumn:m}=s.useEditorActions(),d=s.useEditorStore(R=>R.card.type),h=t==null?void 0:t.id,x=M.useCallback(R=>{if(!(t!=null&&t.config))return[];switch(R){case"groupBy":return(t.config.groupByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,dateFormat:I.dateFormat,customFormat:I.customFormat,granularity:I.granularity}));case"metrics":return t.config.metricColumns||[];case"pivotBy":return(t.config.pivotByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType}));case"sortBy":return(t.config.sortByColumns||[]).map(I=>({id:I.id,name:I.name,dataType:I.dataType,label:I.label!==void 0?I.label:I.name,qualifiedEntityName:I.qualifiedEntityName,entityId:I.entityId,entityName:I.entityName,entityType:I.entityType,direction:I.direction}));case"source":return[];default:return[]}},[t]),f=M.useCallback((R,I)=>{if(h)switch(R){case"groupBy":{a(h,{groupByColumns:I});break}case"metrics":{a(h,{metricColumns:I});break}case"pivotBy":{a(h,{pivotByColumns:I});break}case"sortBy":{a(h,{sortByColumns:I});break}}},[h,a]),g=M.useCallback((R,I,E)=>{if(!h)return;const L=x(R)[I];if(L)switch(R){case"groupBy":n(h,L.id,{label:E});break;case"metrics":r(h,L.id,{label:E});break;case"pivotBy":o(h,L.id,{label:E});break;case"sortBy":i(h,L.id,{label:E});break}},[h,x,n,r,o,i]),p=M.useCallback((R,I)=>{if(!h)return;const N=x("metrics")[R];N&&r(h,N.id,{aggregate:I,label:s.getAggregationLabel(N.name,I)})},[h,x,r]),v=M.useCallback((R,I,E)=>{if(!h)return;const L=x("groupBy")[R];if(!L)return;const B={dateFormat:I};I==="custom"&&E?B.customFormat=E:B.customFormat=void 0,n(h,L.id,B)},[h,x,n]),j=M.useCallback((R,I)=>{if(!h)return;const N=x("groupBy")[R];N&&n(h,N.id,{granularity:I})},[h,x,n]),w=M.useCallback((R,I)=>{if(!h)return;const N=x("metrics")[R];N&&r(h,N.id,{aliasTemplate:I})},[h,x,r]),k=M.useCallback((R,I)=>{if(console.log("handleValueAliasesChange",R,I),!h)return;console.log("handleValueAliasesChange",R,I);const N=x("metrics")[R];N&&(console.log("handleValueAliasesChange",I),r(h,N.id,{valueAliases:I}))},[h,x,r]),O=M.useCallback(R=>{h&&a(h,{comparisonType:R})},[h,a]),T=M.useCallback(R=>{h&&a(h,{showTrendline:R})},[h,a]),S=M.useCallback(R=>{h&&a(h,{trendlineWindow:R})},[h,a]),y=M.useCallback(R=>{h&&a(h,{trendlineGranularity:R})},[h,a]),D=M.useCallback(R=>{h&&a(h,{targetValue:R})},[h,a]),b=M.useCallback(R=>{var V;if(!h)return;const I=[...x("groupBy"),...x("pivotBy"),...x("metrics"),...x("sortBy")],E=(V=t==null?void 0:t.config)==null?void 0:V.joinPlan,N=ei(R,I,E);if(!N.isValid){N.showError&&Is();return}const L=s.getSmartContainerForField(R),B=x(L);if(Ms(R,B))return;const z=s.getNewField(R,L);z&&f(L,[...B,z])},[h,(C=t==null?void 0:t.config)==null?void 0:C.joinPlan,x,f]),A=M.useCallback((R,I)=>{if(!h)return;const N=x(R)[I];if(N){if(R!=="sortBy"){const L=x("sortBy"),B=L.filter(z=>!(z.name===N.name&&z.qualifiedEntityName===N.qualifiedEntityName));B.length!==L.length&&a(h,{sortByColumns:B})}switch(R){case"groupBy":c(h,N.id);break;case"metrics":l(h,N.id);break;case"pivotBy":u(h,N.id);break;case"sortBy":m(h,N.id);break}}},[h,x,c,l,u,m,a]);return{getFieldsForContainer:x,setFieldsForContainer:f,updateLabel:g,handleAggregationChange:p,handleDateFormatChange:v,handleGranularityChange:j,handleAliasTemplateChange:w,handleValueAliasesChange:k,removeField:A,handleFieldClick:b,handleKpiComparisonTypeChange:O,handleKpiShowTrendlineChange:T,handleKpiTrendlineWindowChange:S,handleKpiTrendlineGranularityChange:y,handleKpiTargetValueChange:D,cardType:d}};function si({field:t}){return e.jsxs("div",{className:"w-64 bg-background p-0",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium text-foreground",children:t.label||t.name}),e.jsx("span",{className:"rounded bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:t.dataType})]}),t.description&&e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:t.description}),e.jsx("div",{className:"overflow-x-auto border-t border-border pb-2 pt-2",children:e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:t.name})})]})}function ti({field:t}){const{attributes:a,listeners:n,setNodeRef:r,transform:o,transition:i,isDragging:c}=s.useSortable({id:t.id}),[l,u]=M.useState(!1),m=s.useEditorStore(g=>g.card),{handleFieldClick:d}=Zs(m),h={transform:s.CSS.Transform.toString(o),transition:i};s.getDataType(t.dataType);const x=g=>{const p=(g||"").toLowerCase();switch(s.getDataType(p)){case"number":return $e;case"date":return s.Calendar;case"boolean":return ts;case"json":return it;case"geo":return lt;default:return Qe}},f=g=>{const p=(g||"").toLowerCase(),v=s.getDataType(p);return v==="string"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(Qe,{className:"h-3 w-3"})}):v==="number"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx($e,{className:"h-3 w-3"})}):v==="date"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-purple-100 text-xs text-purple-700 dark:bg-purple-950 dark:text-purple-300",children:e.jsx(s.Calendar,{className:"h-3 w-3"})}):v==="boolean"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-orange-100 text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(ts,{className:"h-3 w-3"})}):v==="json"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(it,{className:"h-3 w-3"})}):v==="geo"?e.jsx("div",{className:"bg-orange -100 flex size-6 shrink-0 items-center justify-center rounded-sm text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(lt,{className:"h-3 w-3"})}):v==="calculated"?e.jsx("div",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Dt,{className:"h-3 w-3"})}):null};return x(t.dataType),e.jsxs("div",{ref:r,style:h,...a,...n,className:`group/container overflow-hidden rounded-lg transition-all ${c?"scale-95 opacity-50":"border border-transparent hover:bg-muted"}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 p-2",onClick:()=>d(t),children:[f(t.dataType),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:e.jsx("span",{className:`block text-sm text-foreground/80 hover:text-foreground dark:text-muted-foreground ${l?"whitespace-normal break-words":"truncate"}`,children:t.label||t.name})})}),e.jsx(s.TooltipContent,{side:"bottom",align:"start",className:"ml-5 max-w-xs px-4 pb-2 pt-4",children:e.jsx(si,{field:t})})]})})]}),l&&e.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:e.jsx(s.Card,{className:"",children:e.jsxs(s.CardContent,{className:"space-y-2 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.label||t.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ea,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.name})]}),e.jsx(s.Badge,{variant:"outline",className:"mt-2 text-xs",children:t.dataType})]})})})]})}function ni(){const[t,a]=M.useState(""),[n,r]=M.useState("all"),o=s.useEditorStore(k=>k.card.dataSource),{columns:i=[],columnGroups:c=[],isLoading:l,error:u}=s.useColumns(),m=i.filter(k=>k.name.toLowerCase().includes(t.toLowerCase())||k.dataType.toLowerCase().includes(t.toLowerCase())||k.qualifiedEntityName&&k.qualifiedEntityName.toLowerCase().includes(t.toLowerCase())),d=k=>{if(k.dataType==="number"||k.dataType==="integer"||k.dataType==="float"||k.dataType==="decimal"||k.dataType==="currency")return"metrics";const O=s.getDataType(k.dataType);return["date","string","boolean"].includes(O)?"dimensions":O==="number"?"metrics":"dimensions"},x=(n==="all"?m:m.filter(k=>d(k)===n)).reduce((k,O)=>{const T=O.qualifiedEntityName||"Other Fields";return k[T]||(k[T]={label:s.toLabel(O.entityName),fields:[]}),k[T].fields.push(O),k},{}),g=Object.keys(x),p=m.filter(k=>d(k)==="dimensions").length,v=m.filter(k=>d(k)==="metrics").length,j=m.filter(k=>d(k)==="calculated").length,w=m.length>0;return l?e.jsx("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):u?e.jsxs("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:[e.jsx(s.Database,{className:"mb-4 h-12 w-12 text-red-300"}),e.jsx("p",{className:"mb-2 text-sm text-red-500",children:"Error loading fields"}),e.jsx("p",{className:"px-4 text-center text-xs text-red-400",children:u.message||"Failed to load column data"})]}):!o||!o.selectedEntities||o.selectedEntities.length===0?e.jsx(s.ScrollArea,{className:"h-[calc(100vh-200px)] w-[290px]",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(s.Database,{className:"mb-4 h-12 w-12 text-gray-300"}),e.jsx("p",{className:"mb-2 text-sm text-gray-500",children:"No data source selected"}),e.jsx("p",{className:"px-4 text-xs text-gray-400",children:"Select a table, view, or dataset from the data source panel to see available fields"})]})}):e.jsxs("div",{className:"mt-2 flex h-[calc(100vh-200px)] w-full grow flex-col gap-2 px-6 pb-6",children:[e.jsxs("div",{className:"mt-1 flex-shrink-0 space-y-2",children:[i.length>0&&e.jsxs("div",{className:"relative mb-4",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"}),e.jsx(s.Input$1,{className:"pl-10",type:"text",placeholder:"Search fields...",value:t,onChange:k=>a(k.target.value)})]}),w&&e.jsx(s.Tabs,{defaultValue:"all",value:n,onValueChange:k=>r(k),className:"mb-4",children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-4",children:[e.jsxs(s.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:m.length})]}),e.jsxs(s.TabsTrigger,{value:"dimensions",className:"text-xs",children:[e.jsx(s.Layers,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:p})]}),e.jsxs(s.TabsTrigger,{value:"metrics",className:"text-xs",children:[e.jsx(s.ChartColumn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:v})]}),e.jsxs(s.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(Dt,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:j})]})]})})]}),e.jsxs(s.CustomScrollArea,{className:"py-2",children:[e.jsx(s.Accordion,{type:"multiple",defaultValue:g,className:"space-y-2",children:Object.entries(x).map(([k,O])=>{const T=c.find(S=>S.entityName===k)||{entityName:k,label:O.label};return e.jsxs(s.AccordionItem,{value:k,className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"group rounded-md px-2.5 py-2 text-muted-foreground hover:bg-muted hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-primary",children:T.label||T.entityName}),e.jsx(s.Badge,{variant:"secondary",className:"rounded-full text-xs text-muted-foreground group-hover:bg-background",children:O.fields.length})]})}),e.jsx(s.AccordionContent,{className:"pb-2",children:e.jsx("div",{className:"space-y-1",children:O.fields.map(S=>e.jsx(ti,{field:S},S.id))})})]},k)})}),Object.keys(x).length===0&&i.length===0&&e.jsxs("div",{className:"py-8 text-center text-sm text-gray-500",children:[e.jsx("p",{children:"No fields found for selected data source"}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"Try selecting different data sources"})]}),Object.keys(x).length===0&&i.length>0&&e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"}),e.jsx(s.ScrollBar,{orientation:"horizontal"}),e.jsx(s.ScrollBar,{orientation:"vertical"})]})]})}function ai(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(ni,{})," "]})}function ri({initialJoinPlan:t,availableDataSources:a}){const[n,r]=M.useState(t),[o,i]=M.useState(new Set),c=()=>{const S=n.joins.length>0?Math.max(...n.joins.map(D=>D.sequence))+1:1,y={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:S,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...n,joins:[...n.joins,y]}),i(new Set([...o,y.id]))},l=S=>{r({...n,joins:n.joins.filter(y=>y.id!==S)}),i(new Set([...o].filter(y=>y!==S)))},u=(S,y)=>{var C,R;const D=n.joins.find(I=>I.id===S);if(!D)return;const b={...D,...y},A=n.joins.map(I=>I.id===S?b:I);if((C=b.source)!=null&&C.name&&((R=b.target)!=null&&R.name)&&b.joinKeyGroups[0].keys.length===0){const I=a.find(B=>{var z;return B.name===((z=b.source)==null?void 0:z.name)}),E=a.find(B=>{var z;return B.name===((z=b.target)==null?void 0:z.name)}),N={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",entityId:(I==null?void 0:I.name)||"",entityName:(I==null?void 0:I.name)||"",entityType:(I==null?void 0:I.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(E==null?void 0:E.name)||"",entityName:(E==null?void 0:E.name)||"",entityType:(E==null?void 0:E.type)||"table"},operator:"="},L=[...b.joinKeyGroups];L[0]={...L[0],keys:[N]},b.joinKeyGroups=L,A[A.findIndex(B=>B.id===S)]=b}r({...n,joins:A})};return{joinPlan:n,expandedJoins:o,setJoinPlan:r,addJoin:c,removeJoin:l,updateJoin:u,moveJoinUp:S=>{const y=n.joins.findIndex(D=>D.id===S);if(y>0){const D=[...n.joins],b={...D[y]},A={...D[y-1]};D[y]=A,D[y-1]=b,D.forEach((R,I)=>{R.sequence=I+1});const C={...n,joins:D};r(C)}},moveJoinDown:S=>{const y=n.joins.findIndex(D=>D.id===S);if(y<n.joins.length-1){const D=[...n.joins],b={...D[y]},A={...D[y+1]};D[y]=A,D[y+1]=b,D.forEach((R,I)=>{R.sequence=I+1});const C={...n,joins:D};r(C)}},toggleJoinExpansion:S=>{const y=new Set(o);y.has(S)?y.delete(S):y.add(S),i(y)},getAvailableSourceEntities:S=>{if(n.joins.length===0)return a;const y=n.joins.findIndex(b=>b.id===S);if(y===0)return a;const D=new Set;return n.baseEntity.name&&D.add(n.baseEntity.name),n.joins.slice(0,y).forEach(b=>{D.add(b.source.name),D.add(b.target.name)}),a.filter(b=>D.has(b.name))},getAvailableTargetEntities:S=>a.filter(y=>y.name!==S),addJoinKeyGroup:S=>{const y=n.joins.find(b=>b.id===S);if(!y)return;const D=[...y.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];u(S,{joinKeyGroups:D})},updateGroupOperator:(S,y,D)=>{const b=n.joins.find(C=>C.id===S);if(!b)return;const A=[...b.joinKeyGroups];A[y]={...A[y],operator:D},u(S,{joinKeyGroups:A})},removeJoinKeyGroup:(S,y)=>{const D=n.joins.find(A=>A.id===S);if(!D)return;const b=[...D.joinKeyGroups];b.splice(y,1),u(S,{joinKeyGroups:b})},addJoinKey:(S,y)=>{const D=n.joins.find(I=>I.id===S);if(!D)return;const b=a.find(I=>I.name===D.source.name),A=a.find(I=>I.name===D.target.name),C=[...D.joinKeyGroups],R={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",entityId:(b==null?void 0:b.name)||"",entityName:(b==null?void 0:b.name)||"",entityType:(b==null?void 0:b.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(A==null?void 0:A.name)||"",entityName:(A==null?void 0:A.name)||"",entityType:(A==null?void 0:A.type)||"table"},operator:"="};C[y]={...C[y],keys:[...C[y].keys,R]},u(S,{joinKeyGroups:C})},updateJoinKey:(S,y,D,b,A)=>{const C=n.joins.find(L=>L.id===S);if(!C)return;const R=a.find(L=>L.name===C.source.name),I=a.find(L=>L.name===C.target.name),E=[...C.joinKeyGroups],N=E[y].keys[D];b==="sourceColumnName"&&R?E[y].keys[D]={...N,source:{...N.source,name:A}}:b==="targetColumnName"&&I?E[y].keys[D]={...N,target:{...N.target,name:A}}:b==="operator"&&(E[y].keys[D]={...N,operator:A}),u(S,{joinKeyGroups:E})},removeJoinKey:(S,y,D)=>{const b=n.joins.find(C=>C.id===S);if(!b)return;const A=[...b.joinKeyGroups];A[y].keys.splice(D,1),u(S,{joinKeyGroups:A})},generateSQLPreview:()=>{const S=[...n.joins].sort((b,A)=>b.sequence-A.sequence),y=n.baseEntity;if(!y.name)return"SELECT * FROM table -- Please select a base entity";let D=`SELECT *
|
|
420
|
-
FROM ${y.name}`;return S.forEach(b=>{const A=a.find(I=>I.name===b.target.name);if(!A)return;const C=b.joinKeyGroups.filter(I=>I.keys&&I.keys.length>0).map(I=>{const E=I.keys.filter(N=>{var L,B,z,V;return((L=N.source)==null?void 0:L.name)&&((B=N.target)==null?void 0:B.name)&&((z=N.source)==null?void 0:z.entityName)&&((V=N.target)==null?void 0:V.entityName)}).map(N=>`${N.source.entityName}.${N.source.name} ${N.operator} ${N.target.entityName}.${N.target.name}`);return E.length>1?`(${E.join(` ${I.operator} `)})`:E[0]}).filter(Boolean),R=C.length>1?C.join(" OR "):C[0]||"condition_here";D+=`
|
|
421
|
-
${b.joinType} JOIN ${A.name}
|
|
422
|
-
ON ${R}`}),D},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(b=>!b.source.name||!b.target.name)||n.joins.some(b=>b.joinKeyGroups.some(A=>A.keys.length===0))||n.joins.some(b=>b.joinKeyGroups.some(A=>A.keys.some(C=>!C.source.name||!C.target.name||!C.operator))))}}function oi({joinPlan:t,availableDataSources:a,onSave:n,onRemove:r,onCancel:o}){const{setCardConfig:i}=s.useEditorActions();s.useEditorStore(C=>C.card.config);const{columnGroups:c}=s.useColumns(),{joinPlan:l,expandedJoins:u,setJoinPlan:m,addJoin:d,removeJoin:h,updateJoin:x,moveJoinUp:f,moveJoinDown:g,toggleJoinExpansion:p,getAvailableSourceEntities:v,getAvailableTargetEntities:j,addJoinKeyGroup:w,updateGroupOperator:k,removeJoinKeyGroup:O,addJoinKey:T,updateJoinKey:S,removeJoinKey:y,generateSQLPreview:D,isValidConfiguration:b}=ri({initialJoinPlan:t,availableDataSources:a}),A=C=>{const R=c.find(I=>I.entityName===C);return(R==null?void 0:R.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:l.baseEntity.name,onValueChange:C=>{const R=a.find(I=>I.name===C);m({...l,baseEntity:{connectionId:(R==null?void 0:R.connectionId)||"",connectionType:(R==null?void 0:R.connectionType)||"none",type:(R==null?void 0:R.type)||"table",name:C,database:R==null?void 0:R.database,schema:R==null?void 0:R.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:a.map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:C.type}),C.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},C.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:D()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",l.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),l.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:l.joins.map(C=>{const R=a.find(N=>N.name===C.source.name),I=a.find(N=>N.name===C.target.name),E=u.has(C.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:C.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",C.sequence,R&&I&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",R.name," → ",I.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>f(C.id),disabled:C.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>g(C.id),disabled:C.sequence===l.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(C.id),children:E?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>h(C.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),E&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:C.source.name,onValueChange:N=>{const L=a.find(B=>B.name===N);x(C.id,{source:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:N,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:v(C.id).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:N.type}),N.name]})},N.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:C.joinType,onValueChange:N=>x(C.id,{joinType:N}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:C.target.name,onValueChange:N=>{const L=a.find(B=>B.name===N);x(C.id,{target:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:N,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},disabled:!C.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:C.source.name?j(C.source.name).map(N=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:N.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:N.type}),N.name,N.name===C.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},N.name)):[]})]})]})]}),C.source.name&&C.target.name&&R&&I&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>w(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),C.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:C.joinKeyGroups.map((N,L)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",L+1]}),L>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:N.operator,onValueChange:B=>k(C.id,L,B),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>O(C.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[N.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:N.keys.map((B,z)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[z>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:N.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:B.source.name,onValueChange:V=>S(C.id,L,z,"sourceColumnName",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:A(C.source.name).map(V=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:V.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:V.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:V.dataType})]})},V.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:B.operator,onValueChange:V=>S(C.id,L,z,"operator",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:B.target.name,onValueChange:V=>S(C.id,L,z,"targetColumnName",V),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:A(C.target.name).map(V=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:V.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:V.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:V.dataType})]})},V.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>y(C.id,L,z),children:e.jsx(s.X,{className:"size-3.5"})})]},B.id||z))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>T(C.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},N.id))})]})]})]},C.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),o()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:o,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>n(l),disabled:!b(),children:"Save"})]})]})}function vt({children:t,open:a,onOpenChange:n,joinPlan:r,availableDataSources:o,onRemove:i,onSave:c,onCancel:l}){return e.jsxs(s.Dialog,{open:a,onOpenChange:n,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(oi,{joinPlan:r,availableDataSources:o,onSave:c,onCancel:l,onRemove:i})]}),t]})}function ii({joins:t,baseEntityId:a,availableDataSources:n,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",children:[t.length>0&&e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const o=[...t].sort((c,l)=>c.sequence-l.sequence),i=n.find(c=>c.name===a);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),o.map(c=>{const l=n.find(u=>u.name===c.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:c.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:l==null?void 0:l.type}),e.jsx("span",{className:"text-xs font-medium",children:l==null?void 0:l.name})]})]},c.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((o,i)=>o.sequence-i.sequence).map((o,i)=>{const c=n.find(u=>u.name===o.source.name),l=n.find(u=>u.name===o.target.name);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted p-2 text-left",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:i+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:o.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[c==null?void 0:c.name," → ",l==null?void 0:l.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[o.joinKeyGroups.reduce((u,m)=>u+m.keys.length,0)," ","condition",o.joinKeyGroups.reduce((u,m)=>u+m.keys.length,0)>1?"s":""]})]},o.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function li(){var d,h;const t=s.useEditorStore(x=>x.card),a=s.useEditorStore(x=>x.actions.updateCardConfig),n=((d=t==null?void 0:t.config)==null?void 0:d.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,o]=M.useState(!1),i=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],c=x=>{a(t.id,{...t==null?void 0:t.config,joinPlan:x}),o(!1)},l=()=>{a(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},u=()=>{o(!1)},m=()=>{const x=[...n.joins].sort((p,v)=>p.sequence-v.sequence),f=n.baseEntity;if(!f.name)return"SELECT * FROM table -- Please select a base entity";let g=`SELECT *
|
|
423
|
-
FROM ${f.name}`;return x.forEach(p=>{const v=i.find(k=>k.name===p.target.name);if(!v)return;const j=p.joinKeyGroups.filter(k=>k.keys&&k.keys.length>0).map(k=>{const O=k.keys.filter(T=>{var S,y,D,b;return((S=T.source)==null?void 0:S.name)&&((y=T.target)==null?void 0:y.name)&&((D=T.source)==null?void 0:D.entityName)&&((b=T.target)==null?void 0:b.entityName)}).map(T=>`${T.source.entityName}.${T.source.name} ${T.operator} ${T.target.entityName}.${T.target.name}`);return O.length>1?`(${O.join(` ${k.operator} `)})`:O[0]}).filter(Boolean),w=j.length>1?j.join(" OR "):j[0]||"condition_here";g+=`
|
|
424
|
-
${p.joinType} JOIN ${v.name}
|
|
425
|
-
ON ${w}`}),g};return i.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[n.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>o(!0),children:[e.jsx(s.Link,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":n.joins.length>0,"text-gray-500":n.joins.length===0})}),"Join",n.joins.length>1?"s":""," (",n.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(ii,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:i,generateSQLPreview:m})})]})}),e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:u,onRemove:l,children:e.jsx("div",{})})]}),n.joins.length===0&&e.jsx(vt,{open:r,onOpenChange:o,joinPlan:n,availableDataSources:i,onSave:c,onCancel:u,onRemove:l,children:e.jsxs(s.Button,{onClick:()=>o(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function ci({entity:t,title:a,maxDetails:n=10}){const o=s.getEntityDetails(t).slice(0,n),i=o.find(l=>l.label==="Description"),c=o.filter(l=>l.label==="Description"?!1:!["Connection","Database","Schema"].includes(l.label));return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:a||s.getDisplayName(t)}),i&&e.jsxs("div",{className:"border-t border-border pt-2",children:[e.jsx("div",{className:"mb-1 text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:i.value})]}),c.length>0&&e.jsx("div",{className:"space-y-0.5",children:c.map((l,u)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[l.label,":"]}),e.jsx("span",{className:"font-mono",children:l.value})]},u))})]})})}function di({entities:t}){return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"text-sm font-medium",children:[t.length," more entities"]}),e.jsx("div",{className:"space-y-1",children:t.map((a,n)=>{const r=s.getEntityDetails(a),o=r.find(c=>c.label==="Description"),i=r.filter(c=>c.label==="Description"?!1:!["Connection","Database","Schema"].includes(c.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(a)}),o&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),i.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:i.map((c,l)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[c.label,":"]}),e.jsx("span",{className:"font-mono",children:c.value})]},l))})]},`remaining-${a.type}-${a.name}-${n}`)})})]})})}function ui({isVisible:t,onToggleVisibility:a}){s.useEditorStore(d=>d.isDevMode),s.useEditorStore(d=>d.card.connectionId),s.useDashboardStore(d=>d.isVisualEditing);const[n,r]=M.useState(!1),[o,i]=M.useState(!0),c=s.useEditorStore(d=>d.card.dataSource),{updateDataSource:l}=s.useEditorActions(),u={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},m={...u,...c,selectedEntities:(c==null?void 0:c.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[e.jsxs("div",{children:[e.jsx("div",{className:s.cn("p-4 px-6",{"pb-0":!o}),children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex cursor-pointer items-center gap-2",children:[e.jsx("h2",{className:"text-brand-100 font-semibold",children:"Data Source"}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>i(!o),className:"h-6 w-6 p-0",children:o?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronRight,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,title:"Hide Data Source Panel",children:e.jsx(s.EyeOff,{className:"h-3.5 w-3.5"})}),e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7",onClick:()=>r(!0),children:[e.jsx(s.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Add"]})]})]})}),e.jsxs("div",{className:`overflow-hidden px-6 ${o?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[m.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[m.selectedEntities.slice(0,3).map((d,h)=>e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[s.getDisplayName(d),e.jsx("button",{onClick:x=>{x.stopPropagation();const f=m.selectedEntities.filter(g=>!(g.name===d.name&&g.type===d.type));l({...u,...c,selectedEntities:f})},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 hover:bg-red-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 group-hover:text-red-500"})})]})}),e.jsx(ci,{entity:d})]},`${d.type}-${d.name}-${h}`)),m.selectedEntities.length>3&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",m.selectedEntities.length-3," more"]})}),e.jsx(di,{entities:m.selectedEntities.slice(3)})]})]})}),e.jsx(li,{})]})]}),e.jsx(ai,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(c==null?void 0:c.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:m,fallbackDataSource:u})]})}const ss=[{id:"table",icon:He,label:"Table"},{id:"pivotTable",icon:He,label:"Pivot Table"},{id:"bar",icon:cs,label:"Bar Chart"},{id:"line",icon:ds,label:"Line Chart"},{id:"area",icon:kt,label:"Area Chart"},{id:"stackedBar",icon:As,label:"Stacked Bar Chart"},{id:"combo",icon:Wn,label:"Combo Chart"},{id:"stackedLine",icon:Ks,label:"Stacked Line Chart"},{id:"scatter",icon:Rs,label:"Scatter Chart"},{id:"bubble",icon:Hs,label:"Bubble Chart"},{id:"pie",icon:us,label:"Pie Chart"},{id:"doughnut",icon:Os,label:"Doughnut Chart"},{id:"funnel",icon:Qs,label:"Funnel Chart"},{id:"radar",icon:Bs,label:"Radar Chart"},{id:"polarArea",icon:Gs,label:"Polar Area Chart"},{id:"tornado",icon:Ps,label:"Tornado Chart"},{id:"range",icon:Ls,label:"Range Chart"},{id:"kpi",icon:Ws,label:"KPI"},{id:"text",icon:wt,label:"Text"},{id:"map",icon:Fs,label:"Map"}],et=t=>{const a=t.toLowerCase();for(const n of ss)if(n.id==="doughnut"){if(a.includes("doughnut")||a.includes("donut")){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}return null},mi="chart-selector-standard-first";function hi(){const[t,a]=s.useLocalStorageState(mi,!0);return{standardFirst:t,updatePreference:a}}const bt=({pluginVisual:t,index:a,onSelect:n})=>{const r=hs(t.icon||""),o=t.name.charAt(0).toUpperCase(),i=et(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:n,className:"group flex items-center gap-2",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(r,{className:"h-4 w-4"}):i||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:o}),e.jsx("span",{children:t.name})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{tabIndex:0,className:"opacity-0 outline-none transition-opacity group-hover:opacity-100",children:e.jsx(s.Info,{className:"ml-1 h-3.5 w-3.5 text-muted-foreground"})})}),e.jsx(s.TooltipContent,{side:"right",children:t.pluginName})]})]})},`${t.url}-${t.name}-${a}`)},Nt=["default","standardPlugin","customPlugin"];function xi({selectedChart:t,onChartChange:a}){var S;const[n,r]=M.useState([]),[o,i]=M.useState(!1),{data:c}=Ys();hi();const u=((S=s.useEditorStore(y=>y.card).customCardPreferences)==null?void 0:S.url)||"";zs(u);const{setCardType:m,setCardPreferences:d,setIsDevMode:h}=s.useEditorStore(y=>y.actions),{setCardCustomCfg:x,setCustomCardPreferences:f,setQueryConfig:g}=s.useEditorActions(),[p,v]=s.useLocalStorageState("chart-section-active",null),j=M.useMemo(()=>p?[p,...Nt.filter(y=>y!==p)]:Nt,[p]);M.useEffect(()=>{(async()=>{if(c){const b=(await Promise.allSettled(c.plugins.map(async A=>{try{return(await s.loadManifest(A.value)).visuals.map(R=>({name:R.name,icon:R.icon,url:A.value,pluginName:A.label,pluginType:A.type,chartType:R.chartType,componentType:R.componentType}))}catch(C){return console.error(`Failed to load manifest for plugin ${A.label}`,C),[]}}))).filter(A=>A.status==="fulfilled").flatMap(A=>A.value);r(b)}})()},[c]);function w(y){x(null),d({}),m(y),["custom","text","map"].includes(y)&&(h(!0),g(void 0)),a(y),i(!1)}function k(y){x(null),d({}),m("custom"),f({type:"component",visualType:"single",url:y.url,componentName:y.name,icon:y.icon,pluginChartType:y.chartType}),g(void 0),a("custom"),i(!1)}const O=()=>{var D;if(t==="custom"){const b=s.useEditorStore.getState().card;return((D=b==null?void 0:b.customCardPreferences)==null?void 0:D.componentName)||"Custom Visual"}const y=ss.find(b=>b.id===t);return(y==null?void 0:y.label)||"Select chart type"},T=()=>{var D,b;if(t==="custom"){const A=s.useEditorStore.getState().card,C=(D=A==null?void 0:A.customCardPreferences)==null?void 0:D.icon,R=(b=A==null?void 0:A.customCardPreferences)==null?void 0:b.componentName;if(C&&R)return e.jsx(pi,{icon:C,componentName:R});if(R){const I=et(R);if(I)return I}return e.jsx(Ye,{className:"h-4 w-4"})}const y=ss.find(A=>A.id===t);if(y){const A=y.icon;return e.jsx(A,{className:"h-4 w-4"})}return e.jsx(Ye,{className:"h-4 w-4"})};return e.jsx("div",{className:"mb-6",children:e.jsxs(s.Popover,{open:o,onOpenChange:i,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[T(),e.jsx("span",{children:O()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[300px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search chart types..."}),e.jsxs(s.CommandList,{className:"mb-2 max-h-[300px]",children:[e.jsx(s.CommandEmpty,{children:"No chart type found."}),j.map(y=>{if(y==="default")return e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"flex items-center gap-2",children:"Default Visuals"})}),e.jsx(s.TooltipContent,{side:"right",children:"These are the standard visuals available in Semaphor"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="default",onCheckedChange:D=>v(D?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ss.map(D=>{const b=D.icon;return e.jsx(s.CommandItem,{value:`${D.label} ${D.id} chart graph visualization`,onSelect:()=>w(D.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx("span",{children:D.label})]})},D.id)})},"default");if(y==="standardPlugin"){const D=n.filter(b=>b.pluginType==="standard");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsx("p",{children:"Standard Visuals"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="standardPlugin",onCheckedChange:b=>v(b?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.filter(b=>b.componentType==="chart").map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"standardPlugin"):null}if(y==="customPlugin"){const D=n.filter(b=>b.pluginType==="custom");return D.length?e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"group flex w-full items-center justify-between",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("span",{className:"flex items-center gap-2",children:["Custom Visuals",e.jsx(s.Info,{className:"h-3.5 w-3.5 text-muted-foreground"})]})}),e.jsx(s.TooltipContent,{side:"right",children:"External visuals that are specific to your project"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:"Show on top"}),e.jsx(s.Switch,{checked:p==="customPlugin",onCheckedChange:b=>v(b?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:D.map((b,A)=>e.jsx(bt,{pluginVisual:b,index:A,onSelect:()=>k(b)},`${b.url}-${b.name}-${A}`))},"customPlugin"):null}return null})]})]})})]})})}const pi=({icon:t,componentName:a})=>{const n=hs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(Ye,{className:"h-4 w-4"})},Sn=({dataType:t})=>{const a=s.getDataType(t);return a==="string"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(Qe,{className:"h-3 w-3"})}):a==="number"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx($e,{className:"h-3 w-3"})}):a==="date"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-purple-100 text-xs text-purple-700 dark:bg-purple-950 dark:text-purple-300",children:e.jsx(s.Calendar,{className:"h-3 w-3"})}):a==="boolean"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-orange-100 text-xs text-orange-700 dark:bg-orange-950 dark:text-orange-300",children:e.jsx(ts,{className:"h-3 w-3"})}):e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Qe,{className:"h-3 w-3"})})};function fi({aliasTemplate:t,onAliasTemplateChange:a}){var u;const[n,r]=M.useState(t),[o,i]=M.useState(!1),c=(u=s.useEditorStore(m=>{var d;return(d=m.card.config)==null?void 0:d.pivotByColumns}))==null?void 0:u[0],l=c?`e.g. Min Sales in {{${c.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:l,value:o?n:t,onChange:m=>{r(m.target.value),i(!0)},onFocus:()=>i(!0),onPointerDown:m=>m.stopPropagation(),className:"h-8 text-xs",onKeyDown:m=>{m.key==="Enter"&&o&&n!==t?(a(n),i(!1)):m.key==="Escape"&&(r(t),i(!1))},"aria-label":"Edit alias template"}),o&&n!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{a(n),i(!1)},children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{r(t),i(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function gi({valueAliases:t,onValueAliasesChange:a}){const[n,r]=M.useState(null),[o,i]=M.useState(""),[c,l]=M.useState(""),u=()=>{a({...t,"":""})},m=h=>{const x={...t};delete x[h],a(x)},d=h=>{const x={...t};delete x[h],x[o]=c,a(x),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([h,x],f)=>e.jsx("div",{className:"flex items-center gap-2",children:n===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:o,onChange:g=>i(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?d(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>l(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?d(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>d(h),children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>r(null),children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(x)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:x,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),i(h),l(x)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>m(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+f)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:u,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Ct({value:t,onSave:a,placeholder:n="",type:r="text",className:o=""}){const[i,c]=M.useState(t??""),[l,u]=M.useState(!1);M.useEffect(()=>{c(t??"")},[t]);const m=()=>{a(i),u(!1)},d=()=>{c(t??""),u(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${o}`,children:[e.jsx(s.Input$1,{placeholder:n,type:r,value:l?i:t??"",onChange:h=>{c(h.target.value),u(!0)},onFocus:()=>u(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&l&&i!==t?m():h.key==="Escape"&&d()},"aria-label":n||"Edit field"}),l&&i!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm edit",onClick:m,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:d,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function ji({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:o,hasPivotColumns:i=!1,cardType:c}){var nt;const{attributes:l,listeners:u,setNodeRef:m,transform:d,transition:h,isDragging:x}=s.useSortable({id:t.id}),f=s.useEditorStore(W=>W.card),{updateLabel:g,handleAggregationChange:p,handleDateFormatChange:v,handleGranularityChange:j,handleAliasTemplateChange:w,handleValueAliasesChange:k,removeField:O,handleKpiComparisonTypeChange:T,handleKpiShowTrendlineChange:S,handleKpiTrendlineWindowChange:y,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:b}=Zs(f),[A,C]=M.useState(!1),[R,I]=M.useState(t.dateFormat||"YYYY-MM-DD"),[E,N]=M.useState(t.customFormat||""),[L,B]=M.useState(!!t.customFormat),[z,V]=M.useState(t.granularity||"day"),[U,X]=M.useState(t.aliasTemplate||""),[K,F]=M.useState(t.valueAliases||{}),_=W=>{W==="custom"?B(!0):(B(!1),I(W),a==="groupBy"&&v(n,W,""))},$=W=>{N(W),a==="groupBy"&&v(n,"custom",W)},q=W=>{var Ue;V(W);const xe=(Ue=H(W)[0])==null?void 0:Ue.value;xe&&!L&&(I(xe),a==="groupBy"&&v(n,xe,"")),a==="groupBy"&&j(n,W)},Y=W=>{X(W),a==="metrics"&&w(n,W)},Q=W=>{F(W),a==="metrics"&&k(n,W)},G=W=>{g(a,n,W)},Z=()=>{O(a,n)},te={transform:s.CSS.Transform.toString(d),transition:h},ae=s.getDataType(t.dataType),se=ae==="date",oe=c==="kpi",H=W=>{switch(W){case"day":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"custom",label:"Custom Format..."}];case"week":return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"Week of MMM DD, YYYY",label:"Week of Jan 15, 2024"},{value:"Week of MMMM DD, YYYY",label:"Week of January 15, 2024"},{value:"YYYY-WW",label:"2024-W03 (YYYY-WW)"},{value:"custom",label:"Custom Format..."}];case"month":return[{value:"MMM YYYY",label:"Jan 2024 (MMM YYYY)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MM/YYYY",label:"01/2024 (MM/YYYY)"},{value:"YYYY MMM",label:"2024 Jan (YYYY MMM)"},{value:"custom",label:"Custom Format..."}];case"quarter":return[{value:"Q1 YYYY",label:"Q1 2024 (Q1 YYYY)"},{value:"YYYY Q1",label:"2024 Q1 (YYYY Q1)"},{value:"1st Quarter YYYY",label:"1st Quarter 2024"},{value:"YYYY-Q1",label:"2024-Q1 (YYYY-Q1)"},{value:"Quarter 1, YYYY",label:"Quarter 1, 2024"},{value:"custom",label:"Custom Format..."}];case"year":return[{value:"YYYY",label:"2024 (YYYY)"},{value:"YY",label:"24 (YY)"},{value:"custom",label:"Custom Format..."}];default:return[{value:"MM-DD-YYYY",label:"01-15-2024 (MM-DD-YYYY)"},{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}]}},P=H(z),J=!oe&&a!=="pivotBy",ie=se&&a==="groupBy",be=!oe&&se&&a==="groupBy",ke=oe&&se&&a==="groupBy",ne=oe&&a==="metrics"&&((nt=f.config)==null?void 0:nt.comparisonType)==="target",le=a==="metrics",ce=()=>e.jsx("div",{onPointerDown:W=>{W.stopPropagation()},className:"cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),kn=()=>J?e.jsx(Ct,{value:t.label??"",onSave:G,placeholder:"Display label...",type:"text"}):null,tt=()=>ie?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),e.jsxs(s.Select,{value:z,onValueChange:q,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsx(s.SelectContent,{children:["day","week","month","quarter","year"].map(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W,children:s.toTitleCase(W)},W))})]})]}):null,Tn=()=>be?e.jsxs(e.Fragment,{children:[tt(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:L?"custom":R,onValueChange:_,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select date format..."})}),e.jsx(s.SelectContent,{children:P.map(W=>e.jsx(s.SelectItem,{className:"text-xs",value:W.value,children:W.label},W.value))})]}),L&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:E,onChange:W=>{W.stopPropagation(),$(W.target.value)},onClick:W=>W.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}):null,En=()=>{var W,ge,xe,Ue,at;return ke?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:((W=f.config)==null?void 0:W.comparisonType)||"none",onValueChange:T,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select comparison type..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"none",children:"No Comparison"}),e.jsx(s.SelectItem,{value:"previous_period",children:"Previous Period"}),e.jsx(s.SelectItem,{value:"same_period_last_year",children:"Same Period Last Year"}),e.jsx(s.SelectItem,{value:"target",children:"Target Value"})]})]})]}),e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((ge=f.config)==null?void 0:ge.showTrendline)||!1,onCheckedChange:S})]})}),((xe=f.config)==null?void 0:xe.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((Ue=f.config)==null?void 0:Ue.trendlineWindow)||30,onChange:An=>{const Ln=parseInt(An.target.value)||30;y(Ln)},className:"h-8 text-xs",placeholder:"30"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Granularity"}),e.jsxs(s.Select,{value:((at=f.config)==null?void 0:at.trendlineGranularity)||"day",onValueChange:D,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]}):null},In=()=>{var W,ge;return ne?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(Ct,{value:((W=f.config)==null?void 0:W.targetValue)!==void 0&&((ge=f.config)==null?void 0:ge.targetValue)!==null?String(f.config.targetValue):"",onSave:xe=>{!isNaN(Number(xe))&&xe!==null?b(Number(xe)):b(0)},placeholder:"Enter target value...",type:"text"})]}):null},Mn=()=>le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:W=>{p(n,W)},children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select function..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"COUNT",children:"Count"}),e.jsx(s.SelectItem,{className:"text-xs",value:"DISTINCT",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{className:"text-xs",value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MEDIAN",children:"Median"})]})]})]})]}),e.jsx(bn,{column:t}),i&&e.jsxs(e.Fragment,{children:[e.jsx(fi,{aliasTemplate:U,onAliasTemplateChange:Y}),e.jsx(gi,{valueAliases:K,onValueAliasesChange:Q})]})]}):null;return e.jsxs("div",{ref:m,style:te,...l,...u,className:`group mx-auto flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${x?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Sn,{dataType:ae}),e.jsx(Js,{className:"w-[140px] flex-1 text-sm",children:t.label||t.name}),a!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),C(!A)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${A?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const ge=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",ge),o(ge)},children:r==="asc"?e.jsx(s.ArrowUp,{className:"h-3 w-3"}):e.jsx(s.ArrowDown,{className:"h-3 w-3"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:W=>{W.stopPropagation(),Z()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),A&&e.jsxs("div",{className:"space-y-3",children:[ce(),kn(),c==="kpi"&&tt(),Tn(),En(),In(),Mn()]})]})}function yi({concept:t}){const a=()=>{switch(t){case"groupBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Rows = Group By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that define how your data is grouped into rows."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-100 text-xs font-medium dark:bg-blue-200/20",children:"Product"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Sales"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Profit"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/50 text-xs font-medium dark:bg-blue-200/20",children:"Electronics"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$5,200"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$1,300"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/30 text-xs font-medium dark:bg-blue-300/20",children:"Clothing"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$3,100"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$620"})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/20 text-xs font-medium dark:bg-blue-200/20",children:"Food"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$2,400"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$480"})]})]})]});case"pivotBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Columns = Pivot By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that split your data into multiple columns or series."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Region"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"North"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"South"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"East"})]}),e.jsxs("div",{className:"flex border-b py-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$2,300"}),e.jsx("div",{className:"w-1/4 bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$1,800"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$3,400"})]}),e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$460"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$360"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$680"})]})]})]});case"metrics":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Metrics = Values (Cells)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that represent the values shown in your visualization."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q2"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q3"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"rounded bg-blue-100 p-1 text-center text-xs dark:bg-blue-300/20",children:"$2,300"}),e.jsx("div",{className:"rounded bg-blue-200 p-1 text-center text-xs dark:bg-blue-400/20",children:"$3,100"}),e.jsx("div",{className:"rounded bg-blue-300 p-1 text-center text-xs dark:bg-blue-500/20",children:"$4,200"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"rounded bg-green-100 p-1 text-center text-xs dark:bg-green-300/20",children:"$460"}),e.jsx("div",{className:"rounded bg-green-200 p-1 text-center text-xs dark:bg-green-400/20",children:"$620"}),e.jsx("div",{className:"rounded bg-green-300 p-1 text-center text-xs dark:bg-green-500/20",children:"$840"})]})]})]});default:return null}};return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.CircleHelp,{className:"size-4 text-muted-foreground hover:text-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"start",className:"p-3",children:a()})]})})}function Ze({zone:t,fields:a,label:n,placeholder:r,shouldShow:o,hasPivotColumns:i=!1}){const{isOver:c,setNodeRef:l}=s.useDroppable({id:t}),{updateSortByColumn:u}=s.useEditorActions(),m=s.useEditorStore(g=>g.card),d=s.useEditorStore(g=>g.card.type),h=a.length>0,x=(g,p)=>{var j;!((j=m.config)!=null&&j.sortByColumns)||m.config.sortByColumns.findIndex(w=>w.id===g)===-1||u(m.id,g,{direction:p})};if(t==="sortBy"&&o===!1)return null;const f=t!=="sortBy"&&d!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:n}),f&&e.jsx(yi,{concept:t})]}),e.jsx("div",{ref:l,className:`min-h-[60px] rounded-lg border-2 border-dashed p-2 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":h?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"border-muted-foreground/20 bg-background"}`,children:a.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:a.map(g=>g.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((g,p)=>{const j=g.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(ji,{field:g,zone:t,index:p,sortDirection:j,onSortDirectionChange:w=>x(g.id,w),hasPivotColumns:i,cardType:d})})},g.id)})})})})]})}function vi({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r}){const o=s.useEditorStore(h=>h.card),i=o==null?void 0:o.type,c=t.length>0||n.length>0,l=i!=="kpi",u=i!=="kpi"&&c,m=()=>i==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},d=()=>i==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx(Ze,{zone:"groupBy",fields:t,label:m().label,placeholder:m().placeholder}),l&&e.jsx(Ze,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(Ze,{zone:"metrics",fields:n,label:d().label,placeholder:d().placeholder,hasPivotColumns:a.length>0}),u&&e.jsx(Ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})}function bi({selectedChart:t,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}){const c=s.useEditorStore(h=>h.showAIDialog),l=n.length>0||r.length>0||o.length>0,{setShowAIDialog:u}=s.useEditorActions(),m=s.useEditorStore(h=>h.card),{data:d}=s.useDashboardCardQuery(m);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col",children:[e.jsxs("div",{className:"space-y-4 px-6 pt-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})}),e.jsx(xi,{selectedChart:t,onChartChange:a})]}),e.jsxs("div",{className:s.cn("flex justify-end gap-2 px-6 pt-6"),children:[e.jsx("div",{className:s.cn("invisible",{visible:l||d}),children:e.jsx(ms,{})}),!c&&e.jsxs(s.Button,{onClick:()=>u(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(ka,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6",children:[e.jsx(vi,{groupByFields:n,pivotByFields:r,metricsFields:o,sortByFields:i}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Ni({initialFilters:t,availableFields:a}={}){const[n,r]=M.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(T=>T.card.dataSource);const{columns:o,isLoading:i}=s.useColumns(),l=a||o||[],u={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},m=T=>{const S=y=>{if(y.id===T){const D=l[0]||u;return{...y,conditions:[...y.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...y,groups:y.groups.map(S)}};r(S(n))},d=T=>{const S=y=>{if(y.id===T){const D=l[0]||u;return{...y,groups:[...y.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...y,groups:y.groups.map(S)}};r(S(n))},h=(T,S)=>{const y=D=>D.id===T?{...D,conditions:D.conditions.filter(b=>b.id!==S)}:{...D,groups:D.groups.map(y)};r(y(n))},x=(T,S)=>{const y=D=>D.id===T?{...D,groups:D.groups.filter(b=>b.id!==S)}:{...D,groups:D.groups.map(y)};r(y(n))},f=(T,S,y,D)=>{if(y==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const b=A=>A.id===T?{...A,conditions:A.conditions.map(C=>C.id===S?{...C,[y]:D}:C)}:{...A,groups:A.groups.map(b)};r(b(n))},g=(T,S,y)=>{const D=b=>b.id===T?{...b,conditions:b.conditions.map(A=>A.id===S?{...A,...y}:A)}:{...b,groups:b.groups.map(D)};r(D(n))},p=(T,S)=>{const y=D=>D.id===T?{...D,logicalOperator:S}:{...D,groups:D.groups.map(y)};r(y(n))},v=(T,S)=>{const y=D=>D.id===T?{...D,negate:S}:{...D,groups:D.groups.map(y)};r(y(n))},j=(T,S,y)=>{const D=b=>b.id===T?{...b,conditions:s.arrayMove(b.conditions,S,y)}:{...b,groups:b.groups.map(D)};r(D(n))},w=(T,S,y)=>{const D=b=>b.id===T?{...b,groups:s.arrayMove(b.groups,S,y)}:{...b,groups:b.groups.map(D)};r(D(n))},k=T=>{if(!T||T.conditions.length===0&&T.groups.length===0)return"-- No filters defined";const S=D=>{let b="";typeof D.field=="object"?b=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:b=String(D.field);const A=D.operator;let C=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof C=="string"?C=`'${C}'`:Array.isArray(C)&&(C=`'${C.join(", ")}'`);else if(D.field.dataType==="date")(typeof C=="string"||C instanceof Date)&&(C=`DATE('${C}')`);else if(["in","not in"].includes(D.operator)){let R=[];Array.isArray(C)?R=C.map(I=>typeof I=="string"?`'${I}'`:String(I)):typeof C=="string"?R=C.split(",").map(I=>{const E=I.trim();return D.field.dataType==="string"?`'${E}'`:E}):typeof C=="number"&&(R=[String(C)]),C=`(${R.join(", ")})`}switch(A){case"contains":return typeof C=="string"?`${b} LIKE '%${C.replace(/'/g,"")}'`:`${b} LIKE '%${String(C)}'`;case"startsWith":return typeof C=="string"?`${b} LIKE '${C.replace(/'/g,"")}%'`:`${b} LIKE '${String(C)}%'`;case"endsWith":return typeof C=="string"?`${b} LIKE '%${C.replace(/'/g,"")}'`:`${b} LIKE '%${String(C)}'`;default:return`${b} ${A} ${C}`}},y=D=>{const b=D.conditions.map(S),A=D.groups.map(E=>y(E)),C=[...b,...A].filter(Boolean);if(C.length===0)return"";const R=C.join(` ${D.logicalOperator} `),I=C.length>1?`(${R})`:R;return D.negate?`NOT ${I}`:I};return y(T)},O=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:l,isLoading:i,addCondition:m,addGroup:d,removeCondition:h,removeGroup:x,updateCondition:f,updateConditionFields:g,updateGroupOperator:p,updateGroupNegate:v,reorderConditions:j,reorderGroups:w,generateSQLPreview:k,hasAnyFilters:O}}function Ci({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:s.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",a),children:t})}),e.jsx(s.PortalTooltipContent,{children:t})]})})}const Si=t=>{switch(t){case"table":return e.jsx(s.Table,{className:"h-3 w-3"});case"view":return e.jsx(s.Eye,{className:"h-3 w-3"});case"dataset":return e.jsx(s.ChartColumn,{className:"h-3 w-3"});case"file":return e.jsx(ra,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},wi=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Di({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:o="w-64"}){const[i,c]=M.useState(!1),l=M.useMemo(()=>{const u={};return n.forEach(m=>{const d=wi(m);u[d]||(u[d]={}),u[d][m.entityId]||(u[d][m.entityId]=[]),u[d][m.entityId].push(m)}),u},[n]);return e.jsxs(s.Popover,{modal:!0,open:i,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,className:s.cn("justify-between",!t&&"text-muted-foreground",o),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(Ci,{children:[t.entityName,".",t.name]})}):r,e.jsx(s.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(s.CommandEmpty,{children:"No fields found."}),e.jsx(s.CommandList,{className:"max-h-80",children:Object.entries(l).map(([u,m])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),u]}),children:Object.entries(m).map(([d,h])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 bg-gray-50/50 px-2 py-1 text-xs font-medium text-gray-600",children:[Si(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((x,f)=>e.jsxs(s.CommandItem,{value:x.id,onSelect:()=>{a(x),c(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===x.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"",children:x.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:x.description&&e.jsx("span",{children:x.description})})]})]},x.id+f))]},`${u}-${d}`))},u))})]})})]})}function st(t){var g;const a=s.useEditorStore(p=>p.card),{authToken:n}=s.useSemaphorContext(),r=s.useEditorStore(p=>p.card.config),o=r==null?void 0:r.joinPlan,i={...t,alias:t.name,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},l={...i,role:"sortby",direction:"asc"},u={joinPlan:o,groupByColumns:[i],metricColumns:[c],sortByColumns:[l]},m=((g=a.dataSource)==null?void 0:g.connectionId)||a.connectionId,{data:d,isPending:h,error:x}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:m,cardConfig:u,cardDataSource:a.dataSource})}catch(p){console.log(t),console.error("error",p)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((d==null?void 0:d.records)||[]).map(p=>({label:p[t.name]||"BLANK",value:p[t.name]||"BLANK",count:(p==null?void 0:p.count)||0})),isPending:h,error:x}}function ki({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:o}){const[i,c]=ue.useState(!1),{filterValues:l}=st(t),u=d=>{n(a.filter(h=>h!==d))},m=d=>{a.includes(d)?n(a.filter(h=>h!==d)):n([...a,d])};return e.jsx("div",{className:s.cn("w-full",o),children:e.jsxs(s.Popover,{open:i,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":i,className:"h-auto min-h-10 w-full justify-between p-2",children:[e.jsx("div",{className:"flex flex-1 flex-wrap gap-1",children:a.length>0?a.map(d=>{const h=l.find(x=>x.value===d);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:x=>{x.key==="Enter"&&u(d)},onMouseDown:x=>{x.preventDefault(),x.stopPropagation()},onClick:x=>{x.stopPropagation(),u(d)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},d)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:l.map((d,h)=>e.jsxs(s.CommandItem,{onSelect:()=>m(d.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(d.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:d.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:d.count})]})]},d.value+h))})]})]})})]})})}const wn=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=wn(n)}),a};function Ti({field:t,value:a,onChange:n,placeholder:r="Select value...",className:o}){const{filterValues:i,isPending:c,error:l}=st(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):l?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:a,onValueChange:n,children:[e.jsx(s.SelectTrigger,{className:o||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:a})}),e.jsx(s.SelectContent,{children:i.map((u,m)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:u.value,children:u.label},u.value+m))})]})}const Ei=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Ii=["=","!=","contains","startsWith","endsWith","in","not in"],Mi=["=","!=",">",">=","<","<=","in","not in"],Ai=["=","!="],Li=["=","!=",">",">=","<","<=","in","not in"];function Ri(t){switch(t){case"string":return Ii;case"number":return Mi;case"boolean":return Ai;case"date":return Li;default:return Ei}}function Dn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:o,onRemoveCondition:i,onUpdateGroupOperator:c,availableFields:l,updateConditionFields:u}){const{attributes:m,listeners:d,setNodeRef:h,transform:x,transition:f,isDragging:g}=s.useSortable({id:t.id}),{isPending:p,error:v}=st(t.field),j={transform:s.CSS.Transform.toString(x),transition:f};return e.jsxs("div",{ref:h,style:j,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...m,...d,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:w=>c(n,w),children:[e.jsx(s.SelectTrigger,{className:"w-24",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),a===0&&e.jsx("div",{className:"w-24"}),e.jsx(Di,{value:t.field,onValueChange:w=>{u(n,t.id,{field:w,value:""})},availableFields:l,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:w=>{w==="in"||w==="not in"?u(n,t.id,{operator:w,value:[]}):u(n,t.id,{operator:w,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ri(s.getDataType(t.field.dataType)).map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w,children:w},w))})]}),s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?p?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):v?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(ki,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(w=>typeof w=="string")?t.value:[],onChange:w=>u(n,t.id,{value:w}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:w=>u(n,t.id,{value:w.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Ti,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:w=>u(n,t.id,{value:w}),placeholder:"Select value...",className:"flex-1"}):s.getDataType(t.field.dataType)==="boolean"?e.jsxs(s.Select,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:w=>u(n,t.id,{value:w==="true"}),children:[e.jsx(s.SelectTrigger,{className:"flex-1",children:e.jsx(s.SelectValue,{placeholder:"Select value..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"true",children:"True"}),e.jsx(s.SelectItem,{value:"false",children:"False"})]})]}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:w=>o(n,t.id,"value",w.target.value),className:"flex-1",placeholder:t.operator==="in"||t.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>i(n,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function Oi({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:o,onRemoveGroup:i,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:u,onReorderConditions:m,onReorderGroups:d,onAddCondition:h,onAddGroup:x,availableFields:f,renderFilterGroup:g,updateConditionFields:p}){const{attributes:v,listeners:j,setNodeRef:w,transform:k,transition:O,isDragging:T}=s.useSortable({id:t.id}),S={transform:s.CSS.Transform.toString(k),transition:O},y=b=>{const{active:A,over:C}=b;if(C&&A.id!==C.id){const R=t.conditions.findIndex(E=>E.id===A.id),I=t.conditions.findIndex(E=>E.id===C.id);R!==-1&&I!==-1&&m(t.id,R,I)}},D=b=>{const{active:A,over:C}=b;if(C&&A.id!==C.id&&n){const R=t.groups.findIndex(E=>E.id===A.id),I=t.groups.findIndex(E=>E.id===C.id);R!==-1&&I!==-1&&d(n,R,I)}};return e.jsxs("div",{ref:w,style:S,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${T?"z-50 opacity-50":""}`,children:[a>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...v,...j,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(s.Button,{variant:t.negate?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>o(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:b=>r(t.id,b),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>n&&i(n,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${a>0?"":"px-0"}`,children:[e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:y,children:e.jsx(s.SortableContext,{items:t.conditions.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((b,A)=>e.jsx(Dn,{condition:b,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:l,onRemoveCondition:u,onUpdateGroupOperator:r,availableFields:f,updateConditionFields:p},b.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:D,children:e.jsx(s.SortableContext,{items:t.groups.map(b=>b.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(b=>g(b,a+1,t.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>x(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Fi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:o}){const{currentFilters:i,availableFields:c,isLoading:l,addCondition:u,addGroup:m,removeCondition:d,removeGroup:h,updateCondition:x,updateConditionFields:f,updateGroupOperator:g,updateGroupNegate:p,reorderConditions:v,reorderGroups:j,generateSQLPreview:w,hasAnyFilters:k,setCurrentFilters:O}=Ni({initialFilters:t,availableFields:a}),T=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[S,y]=M.useState(!1),D=(C,R,I)=>{const E=N=>N.id===C?{...N,conditions:N.conditions.map(L=>L.id===R?{...L,field:I,dataType:I.dataType}:L)}:{...N,groups:N.groups.map(E)};O(E(i))},b=(C,R=0,I)=>R===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=C.conditions.findIndex(V=>V.id===N.id),z=C.conditions.findIndex(V=>V.id===L.id);B!==-1&&z!==-1&&v(C.id,B,z)}},children:e.jsx(s.SortableContext,{items:C.conditions.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:C.conditions.map((E,N)=>e.jsx(Dn,{condition:E,index:N,groupId:C.id,groupLogicalOperator:C.logicalOperator,onUpdateCondition:x,onUpdateField:D,onRemoveCondition:d,onUpdateGroupOperator:g,availableFields:c,updateConditionFields:f},E.id))})}),e.jsx(s.DndContext,{sensors:T,collisionDetection:s.closestCenter,onDragEnd:E=>{const{active:N,over:L}=E;if(L&&N.id!==L.id){const B=C.groups.findIndex(V=>V.id===N.id),z=C.groups.findIndex(V=>V.id===L.id);B!==-1&&z!==-1&&j(C.id,B,z)}},children:e.jsx(s.SortableContext,{items:C.groups.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:C.groups.map(E=>b(E,R+1,C.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>u(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),S&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},C.id):e.jsx(Oi,{group:C,depth:R,parentGroupId:I,onUpdateGroupOperator:g,onUpdateGroupNegate:p,onRemoveGroup:h,onUpdateCondition:x,onUpdateField:D,onRemoveCondition:d,onReorderConditions:v,onReorderGroups:j,onAddCondition:u,onAddGroup:m,availableFields:c,renderFilterGroup:b,updateConditionFields:f},C.id),A=wn(t);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Card,{children:e.jsx(s.CardContent,{className:"p-4",children:e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"flex items-center justify-center p-4",children:[e.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading columns..."})]}):b(i),e.jsx("div",{className:"mt-4 border-t border-border pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{id:"advanced-mode",checked:S,onCheckedChange:C=>y(!!C)}),e.jsx("label",{htmlFor:"advanced-mode",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Advanced mode (enable grouping)"})]})}),k&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:w(i)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:o,children:"Cancel"}),A>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(k?i:null),children:"Apply Filters"})]})]})}function Bi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:o,isOpen:i,onOpenChange:c}){const l=m=>{n(t,m),c(!1)},u=()=>{r(t),c(!1)};return e.jsxs(s.Dialog,{modal:!1,open:i,onOpenChange:c,children:[i&&e.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-background/80 backdrop-blur-sm"}),e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-4xl overflow-y-auto",onInteractOutside:m=>{m.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(Fi,{filters:a,availableFields:o,onSave:l,onCancel:()=>c(!1),onClearAll:u})]})]})}function Pi({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var f;const[o,i]=M.useState(null),c=s.useEditorStore(g=>g.card),l=(f=c==null?void 0:c.config)==null?void 0:f.joinPlan,u=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],m=M.useCallback(g=>g.startsWith("card-")?null:g.startsWith("source-")||a.find(p=>p.id===g)?"source":n("groupBy").find(p=>p.id===g)?"groupBy":n("metrics").find(p=>p.id===g)?"metrics":n("pivotBy").find(p=>p.id===g)?"pivotBy":n("sortBy").find(p=>p.id===g)?"sortBy":null,[a,n]),d=M.useCallback(g=>{i(g.active.id)},[]),h=M.useCallback(g=>{const{active:p,over:v}=g;if(!v||!t){i(null);return}const j=p.id,w=v.id,k=m(j),O=m(w)||w;if(k==="source"&&O==="sortBy"){i(null);return}if(k==="source"&&O!=="source"&&O!=="sortBy"){const T=[...a].find(b=>b.id===j);if(!T){i(null);return}const S=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(S.length>0){const b=S[0].qualifiedEntityName;if(!b){i(null);return}if(b!==T.qualifiedEntityName&&T.qualifiedEntityName)if(l){if(!Cn(b,T.qualifiedEntityName,l)){Is(),i(null);return}}else{Is(),i(null);return}}const y=n(O);if(Ms(T,y)){i(null);return}const D=s.getNewField(T,O);i(null),r(O,[...y,D]);return}if(k&&O&&k!=="source"&&O!=="source"&&k!==O){const T=n(k),S=n(O),y=T.find(A=>A.id===j);if(!y){i(null);return}const D=s.getNewField(y,O);if(i(null),O==="sortBy"){if(k==="pivotBy"){i(null);return}Ms(y,S)||r(O,[...S,D]);return}const b=T.filter(A=>A.id!==j);r(k,b),r(O,[...S,D]);return}if(k&&O&&k===O&&k!=="source"){const T=n(k),S=T.findIndex(D=>D.id===j),y=T.findIndex(D=>D.id===w);if(S!==y){const D=s.arrayMove(T,S,y);r(k,D)}}i(null)},[t,a,n,r,m,l]),x=o?u.find(g=>g.id===o):null;return{activeId:o,activeField:x,handleDragStart:d,handleDragEnd:h}}function zi({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const r=s.useEditorStore(f=>f.isDevMode),o=s.useEditorStore(f=>f.card);s.isExplorerCard(o);const{config:i}=M.useContext(s.SemaphorContext).tokenProps,c=(i==null?void 0:i.showAdvancedMode)!==!1,{setIsDevMode:l}=s.useEditorActions(),u=s.useEditorStore(f=>f.showAIDialog),m=s.useEditorStore(f=>f.frame),d=s.useManagementStore(f=>f.selectedVisual),h=(d==null?void 0:d.id)===(m==null?void 0:m.id),{setShowAIDialog:x}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",u&&"justify-end",!c&&"justify-end"),children:[c&&t&&!u&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:r,onCheckedChange:()=>l(!r),id:"advanced-mode"}),e.jsx("label",{htmlFor:"advanced-mode",className:"text-sm font-medium",children:"Advanced Mode"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx($s,{}),n&&!h&&e.jsx(qs,{variant:"default"}),h&&e.jsx(Qr,{}),a&&s.isDevEnv]})]})}function Vi({activeView:t,onViewChange:a}){const n=s.useEditorStore(o=>o.card),{errorMessage:r}=s.useDashboardCardQuery(n);return e.jsx(s.Tabs,{value:t,onValueChange:o=>a(o),children:e.jsxs(s.TabsList,{className:"h-9 w-fit gap-2 bg-background p-0",children:[e.jsx(s.TabsTrigger,{value:"chart",className:"rounded-md transition data-[state=active]:bg-muted",children:"Chart"}),e.jsx(s.TabsTrigger,{value:"table",className:"rounded-md transition data-[state=active]:bg-muted",children:"Results"}),n.type!=="kpi"&&e.jsx(s.TabsTrigger,{value:"sql",className:s.cn("rounded-md transition data-[state=active]:bg-muted",r&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:r?"Error":"Query"})]})})}const _i=[{value:"10",label:"Top 10"},{value:"20",label:"Top 20"},{value:"50",label:"Top 50"},{value:"100",label:"Top 100"},{value:"200",label:"Top 200"},{value:"500",label:"Top 500"},{value:"1000",label:"Top 1000"}];function Ui(){var u,m;const t=s.useEditorStore(d=>d.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=M.useState(!1),[o,i]=M.useState(""),c=d=>{if(d==="custom"){r(!0);return}r(!1),a(t.id,parseInt(d))},l=d=>{const h=d.target.value;i(h),h&&!isNaN(parseInt(h))&&a(t.id,parseInt(h))};return e.jsx("div",{className:"flex items-center gap-2",children:n?e.jsx(s.Input,{type:"number",value:o,onChange:l,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((m=(u=t.config)==null?void 0:u.rowLimit)==null?void 0:m.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:_i.map(d=>e.jsx(s.SelectItem,{value:d.value,children:d.label},d.value))})]})})}function qi({isOpen:t,onClose:a}){const n=Gt(a,{enabled:t}),r=s.useEditorStore(d=>{var h;return((h=d.card.customCardPreferences)==null?void 0:h.url)||""}),o=s.useEditorStore(d=>d.card),i=s.useEditorStore(d=>{var h;return((h=d.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(d=>{var h;return((h=d.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:l}=s.useDashboardCardQuery(o),{getCard:u}=s.useCustomVisual(r),m=M.useMemo(()=>!r||r.trim()===""?null:u("Chart Settings"),[u,r]);return e.jsx("div",{ref:n,className:s.cn("absolute right-0 top-0 z-40 h-full w-[350px] border-l bg-background shadow-lg transition-transform duration-300",t?"translate-x-0":"translate-x-full"),style:{willChange:"transform"},tabIndex:t?0:-1,"aria-hidden":!t,children:e.jsxs("div",{className:"flex h-full flex-col p-4 px-5 pr-4",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Chart Settings"}),e.jsx(s.IconButton,{"aria-label":"Hide Chart Settings",tooltip:"Hide",onClick:a,className:"h-7 p-2 text-muted-foreground hover:text-foreground",children:e.jsx(s.X,{className:"size-3.5"})})]}),e.jsx("div",{className:"h-full min-h-0 flex-1",children:m&&e.jsx(M.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(m,{chartData:(l==null?void 0:l.records)||[],chartType:i,settings:c})})})]})})}function $i({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:u,activeCard:m,columns:d,columnsLoading:h,columnsError:x}){var L;const f=s.useEditorStore(B=>B.card);s.useEditorStore(B=>B.frame);const g=s.useDashboardStore(B=>B.filterValues),{updateCardConfig:p,setCard:v,updateCardInFrame:j}=s.useEditorActions(),w=s.useEditorStore(B=>B.showAIDialog),[k,O]=M.useState(!1),T=s.useEditorStore(B=>{var z;return((z=B.card.customCardPreferences)==null?void 0:z.url)&&B.card.type==="custom"}),{data:S,errorMessage:y,isPending:D,isLoading:b,isFetching:A,pagination:C}=s.useDashboardCardQuery(m),R=(B,z)=>{const V={...m,paginationConfig:{page:B+1,pageSize:z}};v(V),j(V)};function I(){return e.jsx("div",{className:"border-b border-border bg-background p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Active Card Config"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(f.config||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Dashboard Filters"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(g||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Card Data Source State"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(m.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",d.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":x?"Error loading columns":JSON.stringify(d.slice(0,5),null,2)})]})]})})}const E=B=>{if(!f.config)return;if(!B.length){p(f.id,{...f.config,sortByColumns:[]});return}const z=f.config,V=B.map(({id:U,desc:X})=>{var $,q;const K=($=z.metricColumns)==null?void 0:$.find(Y=>Y.label===U),F=(q=z.groupByColumns)==null?void 0:q.find(Y=>Y.label===U),_=K||F;return _?{id:s.getFieldId("sortBy",_),name:_.name,dataType:_.dataType,label:_.label,qualifiedEntityName:_.qualifiedEntityName,entityId:_.entityId,entityName:_.entityName,entityType:_.entityType,role:"sortby",direction:X?"desc":"asc"}:null}).filter(U=>U!==null);p(f.id,{...z,sortByColumns:V})},N=M.useMemo(()=>{var B,z;return(z=(B=f.config)==null?void 0:B.sortByColumns)==null?void 0:z.map(V=>({id:V.label,desc:V.direction==="desc"}))},[(L=f.config)==null?void 0:L.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(zi,{showDebug:n,onDebugToggle:r,onAccept:o,onClear:i,onAdvancedToggle:c,onFiltersClick:l,filterCount:u}),n&&I(),e.jsxs("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t==="chart"&&w&&e.jsx(hn,{variant:"outline"}),e.jsx(Vi,{activeView:t,onViewChange:a}),l&&e.jsxs(s.IconButton,{tooltip:"Card Filters",className:"h-8 gap-1",onClick:l,children:[e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),u>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:u})]}),e.jsx("div",{className:"ml-2",children:e.jsx(Ui,{})}),w&&e.jsx(ms,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(xn,{})})]}),!k&&T&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>O(!0),className:"absolute right-5 top-1/2 z-40 size-10 -translate-y-1/2 rounded-full border border-border bg-background shadow-lg hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:e.jsx(Sa,{className:"size-4"})}),e.jsxs("div",{className:"mt-3 flex grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:e.jsx(pn,{})}),t==="table"&&(S==null?void 0:S.records)&&e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:m,data:(S==null?void 0:S.records)||[],paginationMetadata:C,onPaginationChange:R,isLoading:b||A,onSortChange:E,sortState:N})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(S==null?void 0:S.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(rn,{sql:S==null?void 0:S.sql,error:y})]})})]}),e.jsx(qi,{isOpen:k,onClose:()=>O(!1)})]})]})}function Yi({activeField:t}){const[a,n]=M.useState(!0);return M.useEffect(()=>{t&&n(!0)},[t]),t?e.jsxs("div",{className:`flex max-w-[300px] items-center gap-2 rounded-lg border border-blue-500 bg-background p-2 shadow-lg transition-all duration-200 ${a?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(s.GripVertical,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Sn,{dataType:t.dataType}),e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap text-sm dark:text-muted-foreground",children:t.label||t.name})]}):null}const Gi=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r)};const a=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1},n=r=>{var o;if((o=r.reason)!=null&&o.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1};return window.addEventListener("error",a,!0),window.addEventListener("unhandledrejection",n,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",n,!0)}};function Hi(){var F,_;const[t,a]=M.useState("chart"),[n,r]=M.useState(!1),[o,i]=M.useState(!1),[c,l]=M.useState(!0),u=s.useEditorStore($=>$.showAIDialog),m=s.useDashboardStore($=>$.isVisualEditing),{setCardType:d}=s.useEditorActions(),h=s.useEditorStore($=>$.card.type);M.useEffect(()=>Gi(),[]);const x=()=>{console.log("Accept clicked - would save/apply current configuration")},f=()=>{console.log("Clear clicked - would reset all configurations")},g=()=>{console.log("Advanced mode toggled")},p=()=>{i(!0)},v=$=>{d($)},j=s.useEditorStore($=>$.frame),w=s.useEditorStore($=>$.card);s.useEditorStore($=>$.activeTabCardId),s.useEditorStore($=>$.actions.getAvailableFields);const{addCard:k,removeCard:O,updateCard:T,setActiveCard:S,updateFilters:y}=s.useEditorActions(),{columns:D=[],isLoading:b,error:A}=s.useColumns(),C=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),R=w,{getFieldsForContainer:I,setFieldsForContainer:E}=Zs(R),{activeField:N,handleDragStart:L,handleDragEnd:B}=Pi({activeCardId:j.activeCardId,sourceFields:D,getFieldsForContainer:I,setFieldsForContainer:E}),z=($,q)=>{q&&y($,q)},V=$=>{var q;T($,{config:{...(q=j.cards.find(Y=>Y.id===$))==null?void 0:q.config,filters:void 0}})},U=D,X=$=>{if(!$)return 0;let q=$.conditions.length;return $.groups.forEach(Y=>{q+=X(Y)}),q},K=X(((F=R==null?void 0:R.config)==null?void 0:F.filters)||null);return e.jsxs(s.DndContext,{sensors:C,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:B,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ui,{isVisible:c,onToggleVisibility:()=>l(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!u&&e.jsx(bi,{selectedChart:h,onChartChange:v,groupByFields:I("groupBy"),pivotByFields:I("pivotBy"),metricsFields:I("metrics"),sortByFields:I("sortBy")}),e.jsx($i,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:x,onClear:f,onAdvancedToggle:g,onFiltersClick:p,filterCount:K,activeCard:R,dataSourceState:w.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:b,columnsError:A,getFieldsForContainer:I,cards:j.cards,activeCardId:j.activeCardId,addCard:k,setActiveCard:S})]}),!c&&m&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>l(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),R&&e.jsx(Bi,{cardId:R.id,filters:((_=R.config)==null?void 0:_.filters)||null,onFiltersChange:z,onClearFilters:V,availableFields:U,isOpen:o,onOpenChange:i}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Yi,{activeField:N||null})})]})}function Qi({authToken:t,onSave:a,onClose:n}){const r=M.useRef(null),o=s.useEditorStore(w=>w.showAIDialog),i=s.useEditorStore(w=>w.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:u,setOnClose:m}=s.useEditorActions(),{handleDragOver:d,handleDragEnd:h,handleDragStart:x,handleDragCancel:f,sensors:g}=Or();M.useEffect(()=>{a&&u(a),n&&m(n)},[a,u,n,m]),M.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),M.useEffect(()=>{var w,k;o?((w=r.current)==null||w.resize(40),l(!0)):(l(!1),(k=r.current)==null||k.resize(0))},[o,l]);function p(w){w<1?l(!1):o||l(!0)}function v(){return e.jsxs(e.Fragment,{children:[e.jsx(nn,{type:"main"}),e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(Jo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(yt,{})})]})]})}function j(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(Hi,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(yt,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:i?e.jsx(s.DndContext,{sensors:g,onDragStart:x,onDragEnd:h,onDragOver:d,onDragCancel:f,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:v()})}):j()})}function Ki(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:a}=s.useDashboardStore(c=>c.actions),n=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),a(!1))}function i(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!n}),children:e.jsx(Qi,{onSave:o,onClose:i})})}function Wi(){const t=s.useEditorStore(i=>i.selectedDatabaseName),a=s.useEditorStore(i=>i.selectedTableName),n=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=s.useEditorAside(),{assignFilter:o}=yn();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=n==null?void 0:n.find(l=>l.column===s.fmt(i.column_name)&&l.table===a&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_s,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Ji(){s.useDashboardStore(a=>a.showFilters);const t=s.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(nn,{type:"filter",ColumnsComponent:()=>e.jsx(Wi,{})})})]})}function Xi(){const t=s.useDashboardStore(r=>r.dashboard.filters),a=s.useDashboardStore(r=>r.theme),n=t==null?void 0:t.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function Zi(){const t=s.useDashboardStore(r=>r.showFilters),a=s.useDashboardStore(r=>r.isVisualEditing),n=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(Xi,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ji,{})})]})}function el(){const t=s.useDashboardStore(o=>o.dashboard),a=s.useDashboardStore(o=>o.actions.setDashboard),n=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!n}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function sl({showControls:t=!1,showFooter:a=!0,...n}){return typeof window>"u"?null:e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(el,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(Ir,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(Ki,{}),e.jsx(Zi,{})]})]})]})]})})}exports.DashboardPlus=sl;exports.ResourceManagementPanel=sn;exports.ScheduleDashboard=Bt;exports.SelectComponent=ze;exports.cleanCard=Rt;exports.downloadPdf=Ft;exports.getDashbaordStateWithoutData=ns;
|