react-semaphor 0.0.586 → 0.0.588
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-DEcNcvm8.js → dashboard-plus-BrkaFKgF.js} +4990 -4921
- package/dist/chunks/dashboard-plus-DmBycjUh.js +416 -0
- package/dist/chunks/{index-CdBQ25yg.js → index-CXBCMLPS.js} +19837 -19075
- package/dist/chunks/index-DFw6k9mA.js +704 -0
- 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/dist/types/dashboard.d.ts +12 -0
- package/dist/types/main.d.ts +12 -0
- package/dist/types/surfboard.d.ts +12 -0
- package/dist/types/types.d.ts +12 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-plus-nPcGO364.js +0 -421
- package/dist/chunks/index-ChV7eNGL.js +0 -683
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
"use strict";var yt=t=>{throw TypeError(t)};var Ts=(t,a,n)=>a.has(t)||yt("Cannot "+n);var re=(t,a,n)=>(Ts(t,a,"read from private field"),n?n.call(t):a.get(t)),Ye=(t,a,n)=>a.has(t)?yt("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),Ge=(t,a,n,r)=>(Ts(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),He=(t,a,n)=>(Ts(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-ChV7eNGL.js"),I=require("react");require("react-dom");function Ja(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 xe=Ja(I);var Ae,Me,me,ve,Ne,xs,Ps,Pt,Xa=(Pt=class extends s.Subscribable{constructor(a,n){super();Ye(this,Ne);Ye(this,Ae);Ye(this,Me);Ye(this,me);Ye(this,ve);Ge(this,Ae,a),this.setOptions(n),this.bindMethods(),He(this,Ne,xs).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,Ae).defaultMutationOptions(a),s.shallowEqualObjects(this.options,n)||re(this,Ae).getMutationCache().notify({type:"observerOptionsUpdated",mutation:re(this,me),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&s.hashKey(n.mutationKey)!==s.hashKey(this.options.mutationKey)?this.reset():((r=re(this,me))==null?void 0:r.state.status)==="pending"&&re(this,me).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=re(this,me))==null||a.removeObserver(this)}onMutationUpdate(a){He(this,Ne,xs).call(this),He(this,Ne,Ps).call(this,a)}getCurrentResult(){return re(this,Me)}reset(){var a;(a=re(this,me))==null||a.removeObserver(this),Ge(this,me,void 0),He(this,Ne,xs).call(this),He(this,Ne,Ps).call(this)}mutate(a,n){var r;return Ge(this,ve,n),(r=re(this,me))==null||r.removeObserver(this),Ge(this,me,re(this,Ae).getMutationCache().build(re(this,Ae),this.options)),re(this,me).addObserver(this),re(this,me).execute(a)}},Ae=new WeakMap,Me=new WeakMap,me=new WeakMap,ve=new WeakMap,Ne=new WeakSet,xs=function(){var n;const a=((n=re(this,me))==null?void 0:n.state)??s.getDefaultState();Ge(this,Me,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ps=function(a){s.notifyManager.batch(()=>{var n,r,l,o,c,i,d,u;if(re(this,ve)&&this.hasListeners()){const m=re(this,Me).variables,h=re(this,Me).context;(a==null?void 0:a.type)==="success"?((r=(n=re(this,ve)).onSuccess)==null||r.call(n,a.data,m,h),(o=(l=re(this,ve)).onSettled)==null||o.call(l,a.data,null,m,h)):(a==null?void 0:a.type)==="error"&&((i=(c=re(this,ve)).onError)==null||i.call(c,a.error,m,h),(u=(d=re(this,ve)).onSettled)==null||u.call(d,void 0,a.error,m,h))}this.listeners.forEach(m=>{m(re(this,Me))})})},Pt);function Ue(t,a){const n=s.useQueryClient(),[r]=xe.useState(()=>new Xa(n,t));xe.useEffect(()=>{r.setOptions(t)},[r,t]);const l=xe.useSyncExternalStore(xe.useCallback(c=>r.subscribe(s.notifyManager.batchCalls(c)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),o=xe.useCallback((c,i)=>{r.mutate(c,i).catch(s.noop)},[r]);if(l.error&&s.shouldThrowError(r.options.throwOnError,[l.error]))throw l.error;return{...l,mutate:o,mutateAsync:l.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 Za=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"}]]);/**
|
|
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 en=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"}]]);/**
|
|
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 sn=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"}]]);/**
|
|
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 tn=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"}]]);/**
|
|
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 an=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"}]]);/**
|
|
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 nn=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"}]]);/**
|
|
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 rn=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"}]]);/**
|
|
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 zt=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"}]]);/**
|
|
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 ln=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"}]]);/**
|
|
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 on=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"}]]);/**
|
|
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 vt=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"}]]);/**
|
|
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 rs=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"}]]);/**
|
|
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 Vt=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"}]]);/**
|
|
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 Ns=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"}]]);/**
|
|
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 qs=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"}]]);/**
|
|
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 Cs=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"}]]);/**
|
|
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 cn=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"}]]);/**
|
|
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 Ys=s.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
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 Ss=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"}]]);/**
|
|
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 Gs=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"}]]);/**
|
|
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 dn=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"}]]);/**
|
|
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 _t=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"}]]);/**
|
|
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 es=s.createLucideIcon("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
|
|
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 un=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"}]]);/**
|
|
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 mn=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"}]]);/**
|
|
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 hn=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"}]]);/**
|
|
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 xn=s.createLucideIcon("DatabaseZap",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 15 21.84",key:"14ibmq"}],["path",{d:"M21 5V8",key:"1marbg"}],["path",{d:"M21 12L18 17H22L19 22",key:"zafso"}],["path",{d:"M3 12A9 3 0 0 0 14.59 14.87",key:"1y4wr8"}]]);/**
|
|
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 Hs=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"}]]);/**
|
|
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 Ut=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"}]]);/**
|
|
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 pn=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"}]]);/**
|
|
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 fn=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"}]]);/**
|
|
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 gn=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"}]]);/**
|
|
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 jn=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"}]]);/**
|
|
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 yn=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"}]]);/**
|
|
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 vn=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"}]]);/**
|
|
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 bn=s.createLucideIcon("GitCompareArrows",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]);/**
|
|
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 Nn=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"}]]);/**
|
|
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 Cn=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"}]]);/**
|
|
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 Sn=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"}]]);/**
|
|
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 Ce=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"}]]);/**
|
|
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 wn=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"}]]);/**
|
|
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 kn=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"}]]);/**
|
|
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 Dn=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"}]]);/**
|
|
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 Tn=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"}]]);/**
|
|
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 En=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"}]]);/**
|
|
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 In=s.createLucideIcon("List",[["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 18h.01",key:"1tta3j"}],["path",{d:"M3 6h.01",key:"1rqtza"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 18h13",key:"1lx6n3"}],["path",{d:"M8 6h13",key:"ik3vkj"}]]);/**
|
|
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 $t=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"}]]);/**
|
|
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 An=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"}]]);/**
|
|
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 Mn=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"}]]);/**
|
|
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 ss=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"}]]);/**
|
|
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 Ks=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"}]]);/**
|
|
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 Ln=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"}]]);/**
|
|
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 Rn=s.createLucideIcon("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
|
|
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 bt=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"}]]);/**
|
|
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 Nt=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"}]]);/**
|
|
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 On=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"}]]);/**
|
|
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 Fn=s.createLucideIcon("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
|
|
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 Bn=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"}]]);/**
|
|
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 Pn=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"}]]);/**
|
|
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 Qs=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"}]]);/**
|
|
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 qt=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"}]]);/**
|
|
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 zn=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"}]]);/**
|
|
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 zs=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"}]]);/**
|
|
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 ts=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"}]]);/**
|
|
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 as=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"}]]);/**
|
|
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 Vn=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"}]]);/**
|
|
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 _n=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"}]]);/**
|
|
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 Yt=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"}]]);/**
|
|
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 Un=s.createLucideIcon("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]);/**
|
|
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 $n=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
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 Qe=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"}]]);/**
|
|
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 Gt=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"}]]);/**
|
|
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 qn=s.createLucideIcon("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);/**
|
|
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 Yn=s.createLucideIcon("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);/**
|
|
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 _e=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"}]]);/**
|
|
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 Ws=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"}]]);/**
|
|
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 ge=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"}]]);/**
|
|
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 Re=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"}]]);/**
|
|
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 Se=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"}]]);/**
|
|
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 Gn=s.createLucideIcon("View",[["path",{d:"M21 17v2a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-2",key:"mrq65r"}],["path",{d:"M21 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v2",key:"be3xqs"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["path",{d:"M18.944 12.33a1 1 0 0 0 0-.66 7.5 7.5 0 0 0-13.888 0 1 1 0 0 0 0 .66 7.5 7.5 0 0 0 13.888 0",key:"11ak4c"}]]);function fs(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(l=>{var o;return{...l,cards:(o=l.cards)==null?void 0:o.map(c=>Ht(c))}})}})}}function Ht(t){return{...t,customCfg:Hn(t.customCfg),data:[]}}function Hn(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 Kn(t,a,n,r){if(!r)return null;const l=JSON.stringify(a);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:l,filterValues:n,operation:"create"})}async function Vs(t,a){if(!a)return null;const{id:n,template:r,filterValues:l,isDefault:o,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:l,isDefault:o,shared:c,operation:"update"})}async function Qn(t,a){return a?await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:t}):null}function Wn(){const[t,a]=I.useState(""),[n,r]=I.useState(!1),l=s.useDashboardStore(p=>p.lenses),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),[i,d]=I.useState(!1),[u,m]=I.useState(!1),h=s.useDashboardStore(p=>p.dashboard),f=s.useDashboardStore(p=>p.filterValues),{authToken:g}=s.useSemaphorContext();async function j(){d(!0);const p=fs(h),y=await Kn(t,p,f,g==null?void 0:g.accessToken);y&&(o([...l||[],y]),c(y.id),m(!1)),d(!1)}return e.jsxs(s.Dialog,{open:u,onOpenChange:m,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:j,disabled:i,children:i?"Creating...":"Add"})})]})]})}function Jn(){const[t,a]=I.useState(!1),n=s.useDashboardStore(m=>m.lenses),r=s.useDashboardStore(m=>m.selectedLensId),{setLenses:l,setSelectedLensId:o}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function i(m){o(m)}async function d(m){if(await Qn(m,c==null?void 0:c.accessToken)){const f=n==null?void 0:n.filter(g=>g.id!==m);l(f||[]),o("original")}}async function u(m){const h=n==null?void 0:n.map(j=>j.id===m.id?{...j,isDefault:!m.isDefault}:{...j,isDefault:!1});l(h||[]);const f={...m,isDefault:!m.isDefault};await Vs(f,c==null?void 0:c.accessToken);const g=n==null?void 0:n.find(j=>j.isDefault);if(g&&g.id!==m.id){const j={...g,isDefault:!1};await Vs(j,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(Nn,{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:i,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(m=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[e.jsx("p",{children:m.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),u(m)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),d(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})]})}function Kt(){var o;const t=s.useDashboardStore.getState().authToken,a=s.useDashboardStore.getState().theme,n=s.useDashboardStore.getState().filterValues,r=(o=s.useDashboardStore.getState().dashboard)==null?void 0:o.title,l=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:l||""}}async function Qt(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:l,selectedSheetId:o}=Kt();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",o||"");const i=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const m=(await(await fetch(i,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,h=document.createElement("a");h.href=m;const f=`${l}-${new Date().toISOString()}.pdf`;h.download=f,h.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Xn({iconClassName:t}){const{authToken:a}=s.useSemaphorContext();s.useDashboardStore(l=>{var o;return(o=l.dashboard)==null?void 0:o.title}),s.useDashboardStore(l=>l.theme),s.useDashboardStore(l=>l.filterValues);const n=s.useDashboardStore(l=>l.isDownloadingPdf);async function r(){await Qt()}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 fe({defaultValue:t,label:a,options:n,value:r,onValueChange:l,className:o,icon:c,showPlaceholderLabel:i=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("span",{children:c}),i&&e.jsx(s.SelectValue,{placeholder:a})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:a}),n.map(d=>e.jsx(s.SelectItem,{value:d.value,children:d.label},d.value))]})})]})}const Ct=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Wt({triggerButtonClassName:t}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:l,error:o,isDeleting:c}=Zn(),[i,d]=I.useState(""),[u,m]=I.useState(Ct[0].value),[h,f]=I.useState("06:00"),[g,j]=I.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:i,onChange:p=>d(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:g,onChange:p=>{j(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(fe,{className:"col-span-2 h-8",label:"Select Frequency",options:Ct,value:u,onValueChange:p=>m(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=>f(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:i,frequency:u,time:h,subject:g}),f("00:00"),d(""),j("")},className:"h-8 p-2",disabled:l==="loading"||!i,children:[l==="loading"&&e.jsx(s.LoaderCircle,{className:"mr-2 size-4 animate-spin"}),l==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),l==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(_t,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:o})})]}),"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(St,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(dn,{className:"size-3.5"})}),e.jsx(St,{tooltip:`${p.endUserEmail}`,children:e.jsx(Mn,{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 St=({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 Zn(){const[t,a]=I.useState("idle"),[n,r]=I.useState(""),[l,o]=I.useState(null),c=s.useDashboardStore(k=>k.authToken),i=s.useDashboardStore(k=>k.dashboard.id),d=s.useDashboardStore(k=>k.dashboard.title),{endUserId:u}=s.getTenantAndEndUserId((c==null?void 0:c.accessToken)||""),m="https://semaphor.cloud/api/v1/subscriptions/get",h={dashboardId:i,endUserId:u},{data:f,isLoading:g,isError:j,isFetching:p,refetch:y}=s.useQuery({queryKey:["subscriptions",i,u],queryFn:()=>s.getRequest(m,(c==null?void 0:c.accessToken)||"",h),enabled:!!(c!=null&&c.accessToken)&&!!i&&!!u});async function x({email:k,subject:O,frequency:N,time:C}){const{authToken:v,...D}=Kt(),E=Intl.DateTimeFormat().resolvedOptions().timeZone,L={email:k,frequency:N,time:C,timezone:E,endUserId:u,endUserEmail:k,subject:O||d||"Scheduled Dashboard",dashboardId:i,dashboardParams:D};a("loading");const w="https://semaphor.cloud/api/v1/subscriptions/create";try{const F=await s.postRequestRegular(w,(v==null?void 0:v.accessToken)||"",{...L});a("success"),r(""),y(),setTimeout(()=>{a("idle")},2e3)}catch(F){console.error(F),a("error"),r(F.message)}}async function b(k){const O="https://semaphor.cloud/api/v1/subscriptions/delete";o(k);try{await s.postRequestRegular(O,(c==null?void 0:c.accessToken)||"",{id:k}),y(),setTimeout(()=>{o(null)},2e3)}catch(N){console.error(N),o(null),a("error"),r(N.message)}}return{data:f,isLoading:g,isFetching:p,isError:j,isDeleting:l,refetch:y,handleScheduleSubscription:x,handleDeleteSubscription:b,status:t,error:n}}function we(){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:l,isError:o}=s.useQuery({queryKey:["userInfo",n==null?void 0:n.id],queryFn:async()=>{if(!(n!=null&&n.id))return;const i=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(!i.ok)throw new Error("Failed to fetch user info");return(await i.json()).user},enabled:!!(t!=null&&t.accessToken)&&!!(n!=null&&n.id)});return{currentUser:n?{...n,...r||{}}:null,isLoading:l,isError:o}}function Jt(){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 se=(t=>(t.DASHBOARD="dashboard",t.VISUAL="visual",t))(se||{});const er=async(t,a,n,r,l,o)=>{const c={},i={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${i[a]}`,t,c)},sr=async(t,a,n)=>{const r={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}`,t,n)},tr=async(t,a,n,r)=>{const l={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"},o=await fetch(`https://semaphor.cloud/api/management/v1/${l[a]}/${n}`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(r)});if(!o.ok){const c=await o.json();throw new Error((c==null?void 0:c.error)||`HTTP error! status: ${o.status}`)}return o.json()},ar=async(t,a,n)=>{const r={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"},l=await fetch(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}});if(!l.ok){const o=await l.json();throw new Error((o==null?void 0:o.error)||`HTTP error! status: ${l.status}`)}return l.json()},nr=async(t,a,n)=>{const r={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/duplicate`,t,{})},rr=async(t,a,n,r)=>{const l={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${l[a]}/${n}/share`,t,r)},lr=async(t,a,n,r)=>{const l={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"},o=await fetch(`https://semaphor.cloud/api/management/v1/${l[a]}/${n}/share`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(r)});if(!o.ok){const c=await o.json();throw new Error((c==null?void 0:c.error)||`HTTP error! status: ${o.status}`)}return o.json()},or=async(t,a,n)=>{const r={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/shares`,t)},ir=async(t,a,n)=>{const r={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}`,t)};function cr(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 dr(t,a,n,r,l){const{authToken:o}=s.useSemaphorContext(),{currentUser:c}=we();return s.useQuery({queryKey:[t,a,n,r,l],queryFn:()=>er((o==null?void 0:o.accessToken)||"",t),enabled:!!(o!=null&&o.accessToken)&&!!c})}function ur(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Ue({mutationFn:l=>sr((n==null?void 0:n.accessToken)||"",t,l),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:l=>{s.ue.error(`Failed to create ${s.toTitleCase(t)}: ${l.message}`)}})}function Xt(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Ue({mutationFn:({resourceId:r,data:l})=>tr((a==null?void 0:a.accessToken)||"",t,r,l),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 mr(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Ue({mutationFn:l=>ar((n==null?void 0:n.accessToken)||"",t,l),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:l=>{s.ue.error(`Failed to delete ${s.toTitleCase(t)}: ${l.message}`)}})}function hr(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Ue({mutationFn:r=>nr((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 xr(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ue({mutationFn:({resourceType:n,resourceId:r,data:l})=>rr((t==null?void 0:t.accessToken)||"",n,r,l),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 pr(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ue({mutationFn:({resourceType:n,resourceId:r,data:l})=>lr((t==null?void 0:t.accessToken)||"",n,r,l),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 fr(t,a){const{authToken:n}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-shares",t,a],queryFn:()=>or((n==null?void 0:n.accessToken)||"",t,a),enabled:!!(n!=null&&n.accessToken)&&!!a})}function gr(t,a,n){const{authToken:r}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-by-id",t,a],queryFn:()=>ir((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 jr(t,a){return gr(se.VISUAL,t,a)}function Zt(){const[t,a]=I.useState(new Map),n=I.useCallback((o,c)=>{a(i=>{const d=new Map(i),u=new Set(d.get(o)||[]);return c?u.add(c):(u.add("title"),u.add("description")),d.set(o,u),d})},[]),r=I.useCallback((o,c)=>{a(i=>{const d=new Map(i),u=new Set(d.get(o)||[]);return c?u.delete(c):u.clear(),u.size===0?d.delete(o):d.set(o,u),d})},[]),l=I.useCallback((o,c)=>{const i=t.get(o);return i?c?i.has(c):i.size>0:!1},[t]);return{startUpdating:n,stopUpdating:r,isUpdating:l}}function Js(t,a,n){var h;const r=dr(t),l=ur(t,n),o=Xt(t),c=mr(t,a),i=hr(t),d=xr(),u=pr(),m={[se.DASHBOARD]:"dashboards",[se.VISUAL]:"visuals"};return{resources:((h=r.data)==null?void 0:h[m[t]])||[],isLoading:r.isLoading,isError:r.isError,isFetching:r.isFetching,error:r.error,createResource:l.mutate,updateResource:o.mutate,deleteResource:c.mutate,duplicateResource:i.mutate,shareResource:d.mutate,removeResourceShares:u.mutate,isCreating:l.isPending,isUpdating:o.isPending,isDeleting:c.isPending,isDuplicating:i.isPending,isSharing:d.isPending,isRemovingShares:u.isPending,isUpdatingShares:d.isPending,refetch:r.refetch}}function yr(t,a){return Js(se.DASHBOARD,t,a)}function vr(t,a){return Js(se.VISUAL,t,a)}function br(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Ue({mutationFn:async({visualId:n,data:r})=>{const l=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(!l.ok)throw new Error("Failed to update visual");return l.json()},onSuccess:()=>{s.ue.success("Visual updated successfully"),a.invalidateQueries({queryKey:["visuals"]})},onError:()=>{s.ue.error("Failed to update visual")}})}function Nr({visual:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:l=!1,onAddVisual:o,onEditVisual:c,onUpdateVisual:i,onDeleteClick:d,onDuplicateVisual:u,onShareVisual:m,formatDate:h}){var C;const{selectVisual:f}=s.useManagementActions(),g=s.useIsVisualSelected(t.id),j=s.useDashboardStore(v=>v.actions.setIsDashboardPanelOpen),[p,y]=I.useState(!1),[x,b]=I.useState(!1);I.useEffect(()=>{n?(y(!0),b(!0)):x&&(y(!1),b(!1))},[n,x]);const k=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx($t,{className:"h-3 w-3 text-purple-500"}):e.jsx(Se,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(Re,{className:"h-3.5 w-3.5 text-slate-500"}),O=()=>e.jsx(s.ChartColumn,{className:"h-4 w-4 text-slate-400"}),N=()=>{f(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",g&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:N,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:v=>i==null?void 0:i(t.id,{title:v}),isEditable:t.ownership.isOwner&&g,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:v=>i==null?void 0:i(t.id,{description:v}),isEditable:t.ownership.isOwner&&g,isPending:l,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:v=>{v.stopPropagation(),o(t)},children:e.jsx(s.Plus,{className:"h-3.5 w-3.5"})}),e.jsxs(s.DropdownMenu,{modal:!1,open:p,onOpenChange:y,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:v=>v.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:v=>{v.stopPropagation(),o(t)},children:[e.jsx(s.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.preventDefault(),v.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.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),c==null||c(t)},children:[e.jsx(Bn,{className:"mr-2 h-3 w-3"}),"Edit"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),m(t)},children:[e.jsx(Se,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),d(t),j(!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(Re,{className:"h-3 w-3"}),e.jsx("span",{children:((C=t.ownership.createdBy)==null?void 0:C.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 ea({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 gs({currentRole:t,onRoleChange:a,roleOptions:n,disabled:r=!1,className:l="",allowDropdown:o=!0}){var d;const c=((d=n.find(u=>u.value===t))==null?void 0:d.label)||t,i=n.filter(u=>u.value!==t);return o?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":""} ${l}`,onClick:()=>console.log("Badge clicked:",{currentRole:t,disabled:r,allowDropdown:o}),children:c})}),e.jsx(s.DropdownMenuContent,{className:"z-[51]",children:i.map(u=>e.jsx(s.DropdownMenuItem,{onClick:()=>{console.log("Dropdown item clicked:",{currentRole:t,newRole:u.value,disabled:r}),a(u.value)},disabled:r,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:u.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:u.description})]})},u.value))})]}):e.jsx(s.Badge,{variant:"outline",className:`text-xs ${l}`,children:c})}function sa({selectedUsers:t,selectedUserObjects:a,onRemove:n,onRoleChange:r,getRoleOptions:l}){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(o=>n(o.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(o=>{const c=t.find(d=>d.id===o.id),i=l(o.type);return e.jsxs(s.Badge,{variant:"secondary",className:"gap-1",children:[o.name,e.jsx(gs,{currentRole:(c==null?void 0:c.role)||"VIEWER",onRoleChange:d=>r(o.id,d),roleOptions:i}),e.jsx("button",{onClick:()=>n(o.id),className:"ml-1 rounded-full p-0.5 hover:bg-muted-foreground/20",children:e.jsx(s.X,{className:"h-3 w-3"})})]},o.id)})}),e.jsx(s.Separator,{})]})}function ta({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 aa({usersToUpdate:t,allUsers:a,onRemove:n,getRoleOptions:r}){if(t.length===0)return null;const l=r("tenant"),o=i=>{const d=a.find(u=>u.id===i);return(d==null?void 0:d.name)||"Unknown User"},c=i=>{const d=l.find(u=>u.value===i);return(d==null?void 0:d.label)||i};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(Se,{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(i=>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:o(i.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(i.currentRole)}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx(s.Badge,{variant:"default",className:"text-xs",children:c(i.newRole)})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>n(i.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},i.id))})]})}function na(t,a={}){const{enabled:n=!0,eventType:r="mousedown"}=a,l=I.useRef(null);return I.useEffect(()=>{const o=c=>{const i=c.target;l.current&&l.current.contains(i)||i instanceof Element&&(i.closest("[data-radix-popper-content-wrapper]")||i.closest("[data-radix-select-content]")||i.closest("[data-radix-popover-content]")||i.closest("[data-radix-dropdown-menu-content]")||i.closest("[data-radix-tooltip-content]")||i.closest('[role="listbox"]')||i.closest('[role="option"]')||i.closest('[role="combobox"]'))||i instanceof Element&&i.hasAttribute("data-radix-")||t()};return n&&document.addEventListener(r,o),()=>{document.removeEventListener(r,o)}},[t,n,r]),l}function je(t,a){var n;return((n=a.find(r=>r.value===t))==null?void 0:n.label)||t}function Cr(t){return["POWER_USER","ADMIN","EDITOR"].includes(t)}function ra(t){return"tenantId"in t&&t.tenantId?"tenant":"organization"}function Sr(t,a,n){const r=ra(t),l=(n==null?void 0:n.type)||"organization";if(!(!a||!a.shares))if(l==="organization")if(r==="organization"){if("specificOrgUsers"in a.shares)return(a.shares.specificOrgUsers||[]).find(i=>i.orgUserId===t.id)}else return(a.shares.specificTenantUsers||[]).find(i=>i.tenantUserId===t.id);else return(a.shares.specificTenantUsers||[]).find(i=>i.tenantUserId===t.id)}function wr({user:t}){return ra(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 kr({user:t,userShare:a,usersToUpdate:n,currentUser:r,getRoleOptions:l,handleUpdateAccess:o}){if(!(a!=null&&a.role))return null;const c=Cr((r==null?void 0:r.type)||""),i=n.some(h=>h.id===t.id),d=n.find(h=>h.id===t.id),u=d?d.newRole:a==null?void 0:a.role,m=l(t.type);return a?e.jsx("div",{className:"flex items-center gap-2",children:c?e.jsx(gs,{currentRole:u,onRoleChange:h=>{o(t.id,a.role,h)},roleOptions:m,disabled:!c,allowDropdown:c,className:i?"border-orange-300 bg-orange-100":""}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:je(u,m)})}):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(as,{className:"mr-1 h-3 w-3"}),"Will Share"]})]})}function Tr({isUserRemoving:t,isSelected:a,hasAccess:n,isRemoving:r,isSharing:l}){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:l?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 Er({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,i=c.specificOrgUsers||[],d=c.specificTenantUsers||[],u=c.orgWide||[],m=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:[i.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 (",i.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[i.slice(0,3).map((f,g)=>{var x,b;const j=((x=a.find(k=>k.id===f.orgUserId))==null?void 0:x.name)||"Unknown User",p=((b=a.find(k=>k.id===f.orgUserId))==null?void 0:b.type)||"",y=je(f.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:j}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:y})]},g)}),i.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",i.length-3," more users"]})]})]}),d.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 (",d.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[d.slice(0,3).map((f,g)=>{var x,b;const j=((x=a.find(k=>k.id===f.tenantUserId))==null?void 0:x.name)||"Unknown User",p=((b=a.find(k=>k.id===f.tenantUserId))==null?void 0:b.type)||"",y=je(f.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:j}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:y})]},g)}),d.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",d.length-3," more users"]})]})]}),u.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:u.map((f,g)=>{const j=je(f.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:j})]},g)})})]}),m.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:m.map((f,g)=>{const j=je(f.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:j})]},g)})})]}),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((f,g)=>{const j=je(f.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:j})]},g)})})]}),!i.length&&!d.length&&!u.length&&!m.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||[],i=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((d,u)=>{var g,j;const m=((g=a.find(p=>p.id===d.tenantUserId))==null?void 0:g.name)||"Unknown User",h=((j=a.find(p=>p.id===d.tenantUserId))==null?void 0:j.type)||"",f=je(d.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:m}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:f})]},u)}),c.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",c.length-3," more users"]})]})]}),i.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:i.map((d,u)=>{const m=je(d.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)})})]}),!c.length&&!i.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}else{const o=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:[o.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"text-xs font-medium text-blue-600",children:["Specific Users (",o.length,")"]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1",children:[o.slice(0,3).map((i,d)=>{var f,g;const u=((f=a.find(j=>j.id===i.tenantUserId))==null?void 0:f.name)||"Unknown User",m=((g=a.find(j=>j.id===i.tenantUserId))==null?void 0:g.type)||"",h=je(i.role,n(m));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:u}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:h})]},d)}),o.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",o.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((i,d)=>{const u=je(i.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:u})]},d)})})]}),!o.length&&!c.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}}function Ir({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 Ar({user:t,userShare:a,isUserRemoving:n,hasAccess:r,hasAccessFromAPI:l,isSelected:o,selectedUser:c,roleOptions:i,currentUser:d,usersToUpdate:u,handleUserToggle:m,handleRemoveAccess:h,handleUpdateAccess:f,handleUserRoleChange:g}){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":o?"border border-blue-200 bg-blue-50":"hover:bg-muted/50"),children:[e.jsx(s.Checkbox,{checked:l?!n:o,disabled:t.id===(d==null?void 0:d.id),onCheckedChange:()=>{l?n?m(t.id):h(t.id):m(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(wr,{user:t})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&!n?e.jsx(gs,{currentRole:a==null?void 0:a.role,onRoleChange:j=>f(t.id,a.role,j),roleOptions:i,disabled:!1,allowDropdown:!0}):e.jsx(kr,{user:t,userShare:a,usersToUpdate:u,currentUser:d,getRoleOptions:()=>i,handleUpdateAccess:f}),o&&!l&&e.jsx("div",{onClick:j=>j.stopPropagation(),children:e.jsx(gs,{currentRole:(c==null?void 0:c.role)||"VIEWER",onRoleChange:j=>g(t.id,j),roleOptions:i,disabled:!1})})]})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.email}),e.jsx(Dr,{hasAccess:r,isUserRemoving:n,isSelected:o,hasAccessFromAPI:l}),e.jsx(Tr,{isUserRemoving:n,isSelected:o,hasAccess:r,isRemoving:!1,isSharing:!1})]})]})}function la({existingShares:t,isInitialLoading:a,isSearching:n,getRoleOptions:r,allUsers:l=[],currentUser:o,handleUserToggle:c,handleUserRoleChange:i,handleRemoveAccess:d,handleUpdateAccess:u}){const m=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),f=s.useShareUsersToUpdate(),g=s.useShareSearchQuery(),j=s.useShareManagementActions(),p=c||(N=>{const C=m.some(D=>D.id===N),v=h.includes(N);C?j.removeSelectedUser(N):v?j.removeUserFromRemove(N):j.addSelectedUser({id:N,role:"VIEWER"})}),y=i||j.updateSelectedUserRole,x=d||j.addUserToRemove,b=u||((N,C,v)=>{j.addUserToUpdate({id:N,currentRole:C,newRole:v})}),k=l,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(Er,{existingShares:t,allUsers:l,getRoleOptions:r,currentUser:o})})]})})]}),(k==null?void 0:k.length)>0&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>{m.length===k.length?j.setSelectedUsers([]):j.setSelectedUsers(k.map(N=>({id:N.id,role:"VIEWER"})))},className:"h-auto p-1 text-xs",children:m.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(Ir,{isInitialLoading:a,isSearching:n,searchQuery:g,availableUsers:k||[]}),!a&&!n&&(k==null?void 0:k.length)>0&&k.map(N=>{const C=t?Sr(N,t,o):void 0,v=O.includes(N.id),D=!!C,E=D&&!v,L=m.some(S=>S.id===N.id),w=m.find(S=>S.id===N.id),F=r(N.type);return e.jsx(Ar,{user:N,userShare:C,isUserRemoving:v,hasAccess:E,hasAccessFromAPI:D,isSelected:L,selectedUser:w,roleOptions:F,currentUser:o,usersToUpdate:f,handleUserToggle:p,handleRemoveAccess:x,handleUpdateAccess:b,handleUserRoleChange:y},N.id)})]})]})}function oa({shareType:t,onShareTypeChange:a,currentUser:n,options:r}){const l=(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(o=>e.jsxs("div",{children:[e.jsx(s.RadioGroupItem,{value:o.value,id:o.value,className:"peer sr-only",disabled:o.disabled}),e.jsxs(s.Label,{htmlFor:o.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 ${o.disabled?"cursor-not-allowed opacity-50":"cursor-pointer"}`,children:[o.icon||e.jsx(Re,{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:o.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o.description})]})]})]},o.value))}),!l&&r.some(o=>o.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 Be=()=>[{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 Mr({currentUser:t,currentShare:a,isSharing:n,onUpdateAccess:r,allUsersToUpdate:l=null,allUsersToRemove:o=!1,isUpdating:c=!1,isRemoving:i=!1}){const d=s.useShareCurrentMode(),u=Be().filter(b=>b.value==="VIEWER"||b.value==="EDITOR"||b.value==="CONTRIBUTOR"),m=a.role!=="NONE"?a.role:"NONE",h=l?l.newRole:m,f=a.role!=="NONE"&&!o&&(!l||l.newRole===m),g=l!==null&&l.newRole!==m,j=o,p=m==="NONE"||!m,y=b=>{switch(b){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(Vn,{className:"h-4 w-4"});default:return e.jsx(s.Eye,{className:"h-4 w-4"})}},x=b=>{r(m,b)};return e.jsx("div",{className:"space-y-4",children:e.jsxs(s.Card,{className:s.cn("pb-6",g&&!j&&!p?"border-orange-300 bg-orange-50":f?"border-green-300 bg-green-50":j||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(Se,{className:"h-5 w-5"}),"Share with All"," ",d==="allOrgUsers"?"Organization":d==="allTenantUsers"?"Tenant":d==="specificOrgUsers"?"Org":"Tenant"," ","Users",f&&e.jsx(s.Badge,{variant:"default",className:"ml-2 border-green-400 bg-green-100 text-green-800",children:"Active"}),g&&e.jsx(s.Badge,{variant:"secondary",className:"ml-2 border-orange-400 bg-orange-100 text-orange-800",children:"Pending Update"}),(j||p)&&e.jsx(s.Badge,{variant:"destructive",className:"ml-2",children:"No Access"})]}),e.jsx(s.CardDescription,{children:j||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:u.map(b=>e.jsxs(s.Button,{variant:h===b.value?"default":"outline",className:"h-auto flex-col items-start gap-2 p-3",onClick:()=>x(b.value),disabled:n||c||i,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[y(b.value),e.jsx("span",{className:"font-medium",children:b.label})]}),e.jsx("p",{className:"text-left text-xs text-muted-foreground",children:b.description})]},b.value))})]})})]})})}function ia({currentUser:t,currentShare:a,isSharing:n,isUpdating:r,isRemoving:l,onUpdateAccess:o,onRemoveAccess:c,allUsersToUpdate:i,allUsersToRemove:d}){const u=p=>p==="OWNER"?"CONTRIBUTOR":p,h=a?{role:u(a.role)}:{role:"NONE"},f=i?{currentRole:u(i.currentRole),newRole:u(i.newRole)}:null,g=(p,y)=>{o(p,y)},j=()=>{c()};return e.jsx(Mr,{currentUser:t,currentShare:h,isSharing:n,isUpdating:r,isRemoving:l,onUpdateAccess:g,onRemoveAccess:j,allUsersToUpdate:f,allUsersToRemove:d})}const Lr=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 Rr(t={}){var o,c,i;const{authToken:a,tokenProps:n}=s.useSemaphorContext(),r=(n==null?void 0:n.endUserId)||(n==null?void 0:n.orgUserId),l=s.useQuery({queryKey:["unified-users",t],queryFn:()=>Lr((a==null?void 0:a.accessToken)||"",t),enabled:!!(a!=null&&a.accessToken)&&!!r,retry:(d,u)=>u instanceof Error&&u.message.includes("401")||u instanceof Error&&u.message.includes("403")?!1:d<2,retryDelay:d=>Math.min(1e3*2**d,3e4)});return{users:((o=l.data)==null?void 0:o.users)||[],userContext:(c=l.data)==null?void 0:c.userContext,total:((i=l.data)==null?void 0:i.total)||0,isLoading:l.isLoading,isError:l.isError,isFetching:l.isFetching,error:l.error,refetch:l.refetch}}function Oe(t){const{debouncedSearchQuery:a,resourceId:n,resourceType:r=se.DASHBOARD,userType:l,tenantId:o}=t,c=I.useMemo(()=>({search:a,active:!0,...l?{type:l}:{},...l==="tenant"&&o?{tenantId:o}:{}}),[a,l,o]),{users:i,isLoading:d,isError:u}=Rr(c),m=fr(r,n);return{allUsers:i,isLoadingUsers:d,isErrorLoadingUsers:u,existingShares:m.data,isLoadingShares:m.isLoading,isErrorLoadingShares:m.isError,isFetchingShares:m.isFetching}}function Or({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:l=!1,isUpdating:o=!1,isRemoving:c=!1}){var Z,W;const i=s.useShareSelectedTab(),d=s.useShareSelectedTenant(),{searchQuery:u,setSearchQuery:m,debouncedSearchQuery:h}=s.useShareSearchWithDebounce(),f=s.useShareSelectedUsers(),g=s.useShareUsersToRemove(),j=s.useShareUsersToUpdate(),p=s.useShareCurrentMode(),y=s.useShareOrgWideRole(),x=s.useShareManagementActions(),[b,k]=I.useState("specific_users"),O=()=>{if(i==="org")return"organization";if(i==="tenant")return"tenant"},N=()=>{if(i==="tenant"&&d)return d},{allUsers:C,existingShares:v,isLoadingUsers:D}=Oe({debouncedSearchQuery:h,resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:O(),tenantId:N()});I.useEffect(()=>{x.setCurrentContext("org-tab"),x.setCurrentMode(b==="all_users"?"allOrgUsers":"specificOrgUsers")},[x,b]);const E=q=>{var P,_;const G=q;if(k(G),r==null||r(G),x.setCurrentContext("org-tab"),G==="specific_users")x.setCurrentMode("specificOrgUsers");else if(G==="all_users"){x.setCurrentMode("allOrgUsers");const U=(_=(P=v==null?void 0:v.shares)==null?void 0:P.orgUsersOnly)==null?void 0:_[0];U&&U.role!==void 0&&x.setOrgWideRole(U.role)}},L=C.filter(q=>q.name.toLowerCase().includes(u.toLowerCase())||q.email.toLowerCase().includes(u.toLowerCase())),w=C.filter(q=>f.some(G=>G.id===q.id)),F=q=>{var U,Y;const G=f.some(X=>X.id===q),P=g.includes(q),_=(Y=(U=v==null?void 0:v.shares)==null?void 0:U.specificOrgUsers)==null?void 0:Y.some(X=>X.orgUserId===q);G?x.removeSelectedUser(q):P?x.removeUserFromRemove(q):_||x.addSelectedUser({id:q,role:"VIEWER"})},S=(q,G)=>{x.updateSelectedUserRole(q,G)},T=q=>{x.addUserToRemove(q),x.removeSelectedUser(q)},A=q=>{x.removeUserFromRemove(q)},B=q=>{x.removeUserFromUpdate(q)},M=(q,G)=>{x.setOrgWideRole(G)},R=()=>{x.setOrgWideRole((z==null?void 0:z.role)||"NONE")},z=(W=(Z=v==null?void 0:v.shares)==null?void 0:Z.orgUsersOnly)==null?void 0:W[0];I.useEffect(()=>{b==="all_users"&&z&&z.role!==void 0&&x.setOrgWideRole(z.role)},[b,z,x]);const V=D,J=!1;return n?e.jsxs(e.Fragment,{children:[e.jsx(oa,{shareType:b,onShareTypeChange:E,currentUser:n,options:[{value:"specific_users",label:"Specific Org User",description:"Choose individual users to share with",icon:e.jsx(Re,{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(Se,{className:"mb-3 h-6 w-6 text-indigo-500"}),disabled:!["POWER_USER","ADMIN","AUTHOR","SUPER_ADMIN"].includes(n.role??"")}]}),b==="specific_users"?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(ea,{value:u,onChange:m}),e.jsx(sa,{selectedUsers:f,selectedUserObjects:w,onRemove:F,onRoleChange:S,getRoleOptions:Be}),e.jsx(ta,{usersToRemove:g,allUsers:L,onRemove:A}),e.jsx(aa,{usersToUpdate:j,allUsers:L,onRemove:B,getRoleOptions:Be}),e.jsx(la,{existingShares:v,isInitialLoading:V,isSearching:J,resource:t,onShare:()=>{},getRoleOptions:Be,allUsers:L,currentUser:n,handleUserToggle:F,handleUserRoleChange:S,handleRemoveAccess:T,handleUpdateAccess:(q,G,P)=>{x.addUserToUpdate({id:q,currentRole:G,newRole:P})}})]}):e.jsx("div",{className:"mt-3",children:e.jsx(ia,{currentUser:n,currentShare:z,isSharing:l,isUpdating:o,isRemoving:c,onUpdateAccess:M,onRemoveAccess:R,allUsersToUpdate:p==="allOrgUsers"&&y!==((z==null?void 0:z.role)||"NONE")?{currentRole:(z==null?void 0:z.role)||"NONE",newRole:y}:null,allUsersToRemove:p==="allOrgUsers"&&(z==null?void 0:z.role)===void 0})})]}):null}function wt({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:l=!1,isUpdating:o=!1,isRemoving:c=!1}){var U;const{searchQuery:i,debouncedSearchQuery:d,setSearchQuery:u}=s.useShareSearchWithDebounce(),m=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),f=s.useShareUsersToUpdate(),g=s.useShareCurrentMode(),j=s.useShareTenantWideRole(),p=s.useShareAllTenantsRole(),y=s.useShareSelectedTenant(),x=s.useShareManagementActions(),{data:b,isLoading:k}=cr({enabled:(n==null?void 0:n.type)==="organization"}),[O,N]=I.useState((n==null?void 0:n.type)==="organization"?"all_tenants":"specific_tenant_users");I.useEffect(()=>{(n==null?void 0:n.type)==="tenant"?(x.setCurrentContext("tenant-dialog"),x.setCurrentMode("specificTenantUsers")):(x.setCurrentContext("tenant-tab"),x.setCurrentMode("allTenants"))},[x,n==null?void 0:n.type]);const C=Y=>{var $,ee,te,ie;N(Y);let X;if(Y==="specific_tenant_users"?X="specific_users":Y==="all_tenant_users"||Y==="all_tenants"?X="all_users":X="specific_users",r==null||r(X),(n==null?void 0:n.type)==="tenant"?(x.setCurrentContext("tenant-dialog"),Y==="specific_tenant_users"?x.setCurrentMode("specificTenantUsers"):Y==="all_tenant_users"&&(x.setCurrentMode("allTenantUsers"),n!=null&&n.tenantId&&x.setSelectedTenant(n.tenantId))):(x.setCurrentContext("tenant-tab"),Y==="specific_tenant_users"?x.setCurrentMode("specificTenantUsers"):Y==="all_tenant_users"?x.setCurrentMode("allTenantUsers"):Y==="all_tenants"&&x.setCurrentMode("allTenants")),Y==="all_tenant_users"){const K=(ee=($=E==null?void 0:E.shares)==null?void 0:$.tenantWide)==null?void 0:ee[0];K&&K.role!==void 0&&x.setTenantWideRole(K.role)}else if(Y==="all_tenants"){const K=(ie=(te=E==null?void 0:E.shares)==null?void 0:te.allTenantsOnly)==null?void 0:ie[0];K&&K.role!==void 0&&x.setAllTenantsRole(K.role)}},v=Y=>{x.setSelectedTenant(Y)},{allUsers:D,existingShares:E,isLoadingUsers:L,isErrorLoadingUsers:w,isLoadingShares:F,isErrorLoadingShares:S}=Oe({debouncedSearchQuery:d,resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"tenant",tenantId:(n==null?void 0:n.type)==="tenant"?n.tenantId:y}),T=Y=>{var te,ie;const X=m.some(K=>K.id===Y),$=h.includes(Y),ee=(ie=(te=E==null?void 0:E.shares)==null?void 0:te.specificTenantUsers)==null?void 0:ie.some(K=>K.tenantUserId===Y);X?x.removeSelectedUser(Y):$?x.removeUserFromRemove(Y):ee||x.addSelectedUser({id:Y,role:"VIEWER"})},A=(Y,X)=>{x.updateSelectedUserRole(Y,X)},B=Y=>{x.addUserToRemove(Y),x.removeSelectedUser(Y)},M=Y=>{x.removeUserFromRemove(Y)},R=Y=>{x.removeUserFromUpdate(Y)},z=(Y,X,$)=>{x.addUserToUpdate({id:Y,currentRole:X,newRole:$})},V=(Y,X)=>{O==="all_tenant_users"?x.setTenantWideRole(X):O==="all_tenants"&&x.setAllTenantsRole(X)},J=()=>{O==="all_tenant_users"?x.setTenantWideRole("VIEWER"):O==="all_tenants"&&x.setAllTenantsRole("VIEWER")},W=(()=>{var Y,X,$,ee;return g==="allTenants"?(X=(Y=E==null?void 0:E.shares)==null?void 0:Y.allTenantsOnly)==null?void 0:X[0]:g==="allTenantUsers"?(ee=($=E==null?void 0:E.shares)==null?void 0:$.tenantWide)==null?void 0:ee[0]:null})();I.useEffect(()=>{var Y,X,$,ee;if(O==="all_tenant_users"){const te=(X=(Y=E==null?void 0:E.shares)==null?void 0:Y.tenantWide)==null?void 0:X[0];te&&te.role!==void 0&&x.setTenantWideRole(te.role)}else if(O==="all_tenants"){const te=(ee=($=E==null?void 0:E.shares)==null?void 0:$.allTenantsOnly)==null?void 0:ee[0];te&&te.role!==void 0&&x.setAllTenantsRole(te.role)}},[O,E,x]);const q=D.filter(Y=>m.some(X=>X.id===Y.id)),G=L||F,P=w||S,_=()=>(n==null?void 0:n.type)==="tenant"||O==="all_tenants"?!0:y&&(O==="specific_tenant_users"||O==="all_tenant_users");return e.jsxs(e.Fragment,{children:[P&&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"})]})}),!P&&n&&e.jsxs("div",{className:"max-h-[500px] space-y-4 overflow-y-auto",children:[e.jsx(oa,{shareType:O,onShareTypeChange:C,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(Se,{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(Re,{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(vt,{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(Re,{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:y||"",onValueChange:v,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:(U=b==null?void 0:b.tenants)==null?void 0:U.map(Y=>e.jsx(s.SelectItem,{value:Y.id,children:Y.name},Y.id))})]})]}),_()?e.jsx(e.Fragment,{children:O==="specific_tenant_users"?e.jsxs("div",{className:"space-y-4",children:[e.jsx(ea,{value:i,onChange:u}),e.jsx(sa,{selectedUsers:m,selectedUserObjects:q,onRemove:Y=>T(Y),onRoleChange:A,getRoleOptions:Be}),e.jsx(ta,{usersToRemove:h,allUsers:D,onRemove:M}),e.jsx(aa,{usersToUpdate:f,allUsers:D,onRemove:R,getRoleOptions:Be}),e.jsx(la,{existingShares:E,isInitialLoading:!!G,isSearching:!1,resource:t,onShare:()=>{},getRoleOptions:Be,allUsers:D,currentUser:n,handleUserToggle:T,handleUserRoleChange:A,handleRemoveAccess:B,handleUpdateAccess:z})]}):O==="all_tenant_users"||O==="all_tenants"?e.jsx("div",{className:"mt-6",children:e.jsx(ia,{currentUser:n,currentShare:W,isSharing:l,isUpdating:o,isRemoving:c,onUpdateAccess:V,onRemoveAccess:J,allUsersToUpdate:g==="allTenantUsers"&&((W==null?void 0:W.role)===void 0||j!==W.role)||g==="allTenants"&&((W==null?void 0:W.role)===void 0||p!==W.role)?{currentRole:(W==null?void 0:W.role)||"VIEWER",newRole:g==="allTenantUsers"?j:p}:null,allUsersToRemove:g==="allTenantUsers"&&(W==null?void 0:W.role)===void 0||g==="allTenants"&&(W==null?void 0:W.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(vt,{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 ca=()=>{const t=s.useShareCurrentContext(),a=s.useShareCurrentMode(),n=s.useShareSelectedUsers(),r=s.useShareUsersToRemove(),l=s.useShareUsersToUpdate(),o=s.useShareSelectedTenant(),c=s.useShareOrgWideRole(),i=s.useShareAllTenantsRole(),d=s.useShareTenantWideRole(),u=I.useMemo(()=>()=>s.buildShareData({currentContext:t,currentMode:a,selectedUsers:n,usersToRemove:r,usersToUpdate:l,selectedTenant:o,orgWideRole:c,allTenantsRole:i,tenantWideRole:d}),[t,a,n,r,l,o,c,i,d]),m=I.useMemo(()=>f=>s.validateShareData(f),[]),h=I.useMemo(()=>{if(!t||!a)return!1;switch(t){case"org-tab":return a==="specificOrgUsers"?n.length>0||r.length>0||l.length>0:!0;case"tenant-tab":if(a==="allTenantUsers"){if(!o)return!1}else if(a==="specificTenantUsers")return o?n.length>0||r.length>0||l.length>0:!1;return!0;case"tenant-dialog":return a==="specificTenantUsers"?n.length>0||r.length>0||l.length>0:!0}return!1},[t,a,n,r,l,o]);return{buildShareData:u,validateShareData:m,isCurrentStateValid:h,currentContext:t,currentMode:a,selectedUsers:n,usersToRemove:r,usersToUpdate:l,selectedTenant:o,orgWideRole:c,allTenantsRole:i,tenantWideRole:d}};function kt({resource:t,existingShares:a,isSharing:n,isRemoving:r,isUpdating:l,onShare:o,onClose:c,shareTabType:i,currentAllUsersShare:d,onRemoveAccess:u}){const m=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),f=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const g=s.useShareSelectedTenant();s.useShareSelectedTab();const j=s.useShareOrgWideRole(),p=s.useShareAllTenantsRole(),y=s.useShareTenantWideRole(),{buildShareData:x,validateShareData:b,isCurrentStateValid:k}=ca(),O=n||r||l,N=()=>{var L,w,F,S;if(O)return"Updating...";if(i==="specific_users"){if(m.length===0&&h.length===0&&f.length===0)return"Select users to share with";const T=m.length+h.length+f.length;return T===0?"Select users to share with":m.length>0&&h.length>0?`Update access for ${T} user${T!==1?"s":""}`:h.length>0&&m.length===0&&f.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:m.length>0&&h.length===0&&f.length===0?`Share with ${m.length} user${m.length!==1?"s":""}`:f.length>0&&m.length===0&&h.length===0?`Update access for ${f.length} user${f.length!==1?"s":""}`:`Update access for ${T} user${T!==1?"s":""}`}else if(i==="all_users"){if(!d||d.role===void 0)return"Share with All Users";const T=d.role;return j===T?"Remove Access":"Update Access"}else if(i==="all_tenants"){const T=(w=(L=a==null?void 0:a.shares)==null?void 0:L.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0)return"Share with All Tenants";const A=T.role;return p===A?"Remove Access":"Update Access"}else if(i==="all_tenant_users"){const T=(S=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:S[0];if(!T||T.role===void 0)return"Share with All Tenant Users";const A=T.role;return y===A?"Remove Access":"Update Access"}else if(i==="specific_tenant_users"){if(m.length===0&&h.length===0&&f.length===0)return"Select users to share with";const T=m.length+h.length+f.length;return T===0?"Select users to share with":m.length>0&&h.length>0?`Update access for ${T} user${T!==1?"s":""}`:h.length>0&&m.length===0&&f.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:m.length>0&&h.length===0&&f.length===0?`Share with ${m.length} user${m.length!==1?"s":""}`:f.length>0&&m.length===0&&h.length===0?`Update access for ${f.length} user${f.length!==1?"s":""}`:`Update access for ${T} user${T!==1?"s":""}`}return"Share"},C=()=>O||!t||i==="all_tenant_users"&&!g||i==="specific_tenant_users"&&!g?!0:!k,v=()=>{const L=x();L&&b(L)&&o(L)},D=()=>{var L,w,F,S;if(i==="all_users")if(!d||d.role===void 0){const T=x();T&&b(T)&&o(T)}else{const T=d.role;if(j===T)u==null||u();else{const B=x();if(B&&b(B)){const M={...B,updateAccess:!0};o(M)}}}else if(i==="all_tenants"){const T=(w=(L=a==null?void 0:a.shares)==null?void 0:L.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0){const A=x();A&&b(A)&&o(A)}else{const A=T.role;if(p===A)u==null||u();else{const M=x();if(M&&b(M)){const R={...M,updateAccess:!0};o(R)}}}}else if(i==="all_tenant_users"){const T=(S=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:S[0];if(!T||T.role===void 0){const A=x();A&&b(A)&&o(A)}else{const A=T.role;if(y===A)u==null||u();else{const M=x();if(M&&b(M)){const R={...M,updateAccess:!0};o(R)}}}}},E=()=>{var L,w,F,S;if(i==="all_users"){if(!d||d.role===void 0)return"default";const T=d.role;return j===T?"destructive":"default"}else if(i==="all_tenants"){const T=(w=(L=a==null?void 0:a.shares)==null?void 0:L.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0)return"default";const A=T.role;return p===A?"destructive":"default"}else if(i==="all_tenant_users"){const T=(S=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:S[0];if(!T||T.role===void 0)return"default";const A=T.role;return y===A?"destructive":"default"}return"default"};return e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:c,disabled:O,children:"Close"}),(i==="specific_users"||i==="specific_tenant_users")&&e.jsx(e.Fragment,{children:(m.length>0||h.length>0||f.length>0)&&e.jsxs(s.Button,{onClick:v,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(as,{className:"mr-2 h-4 w-4"}),!O&&N()]})}),(i==="all_users"||i==="all_tenants"||i==="all_tenant_users")&&e.jsxs(s.Button,{onClick:D,disabled:C(),variant:E(),children:[O?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Se,{className:"mr-2 h-4 w-4"}),!O&&N()]})]})}function Fr({resource:t,isSharing:a,isRemoving:n,isUpdating:r,onShare:l,onClose:o,shareTabType:c,currentAllUsersShare:i}){const d=s.useShareSelectedUsers(),u=s.useShareUsersToRemove(),m=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const h=s.useShareTenantWideRole();s.useShareSelectedTenant();const{buildShareData:f,validateShareData:g,isCurrentStateValid:j}=ca(),p=a||n||r,y=()=>{if(p)return"Updating...";if(c==="specific_users"){if(d.length===0&&u.length===0&&m.length===0)return"Select users to share with";const N=d.length+u.length+m.length;return N===0?"Select users to share with":d.length>0&&u.length>0?`Update access for ${N} user${N!==1?"s":""}`:u.length>0&&d.length===0&&m.length===0?`Remove access for ${u.length} user${u.length!==1?"s":""}`:d.length>0&&u.length===0&&m.length===0?`Share with ${d.length} user${d.length!==1?"s":""}`:m.length>0&&d.length===0&&u.length===0?`Update access for ${m.length} user${m.length!==1?"s":""}`:`Update access for ${N} user${N!==1?"s":""}`}else if(c==="all_users"){if(!i||i.role==="NONE")return"Share with All Users";const N=i.role;return h===N?"Remove Access":"Update Access"}return"Share"},x=()=>p||!t?!0:!j,b=()=>{const N=f();N&&g(N)&&l(N)},k=()=>{if(!i||i.role==="NONE"){const N=f();N&&g(N)&&l(N)}else{const N=i.role;if(h===N){const v=f();if(v&&g(v)){const D={...v,removeAccess:!0};l(D)}}else{const v=f();if(v&&g(v)){const D={...v,updateAccess:!0};l(D)}}}},O=()=>!i||i.role==="NONE"?"default":"destructive";return e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:o,disabled:p,children:"Close"}),c==="specific_users"&&e.jsx(e.Fragment,{children:(d.length>0||u.length>0||m.length>0)&&e.jsxs(s.Button,{onClick:b,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(as,{className:"mr-2 h-4 w-4"}),!p&&y()]})}),c==="all_users"&&e.jsxs(s.Button,{onClick:k,disabled:x(),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(as,{className:"mr-2 h-4 w-4"}),!p&&y()]})]})}function da({resource:t,resourceType:a,isSharing:n,isRemoving:r,isUpdating:l,onClose:o,onShare:c,onRemoveAccess:i}){var v,D,E,L;const{currentUser:d}=we(),[u,m]=I.useState("specific_users"),[h,f]=I.useState("specific_users"),g=s.useShareManagementActions(),j=s.useShareSelectedTab(),p=s.useShareCurrentMode(),{existingShares:y}=Oe({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"tenant"}),{existingShares:x}=Oe({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"organization"}),b=(D=(v=y==null?void 0:y.shares)==null?void 0:v.tenantWide)==null?void 0:D[0],k=(L=(E=x==null?void 0:x.shares)==null?void 0:E.orgUsersOnly)==null?void 0:L[0],O=()=>{if(j==="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"}},N=I.useCallback(()=>{g.resetShareState(),o()},[g,o]),C=(d==null?void 0:d.type)==="organization";return e.jsx(s.Dialog,{open:!0,onOpenChange:N,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(as,{className:"h-5 w-5"}),' Share "',t==null?void 0:t.title,'"']})}),e.jsx(s.DialogDescription,{children:C?"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."})]}),C?e.jsxs(s.Tabs,{value:j,onValueChange:w=>{const F=w;g.setSelectedTab(F),g.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(Or,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:f,isSharing:n,isUpdating:l,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(wt,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:w=>m(w),isSharing:n,isUpdating:l,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(wt,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:w=>m(w),isSharing:n,isUpdating:l,isRemoving:r})})}),e.jsx("div",{className:"mt-auto flex-shrink-0",children:C?j==="org"?e.jsx(kt,{resource:t,existingShares:x,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:h,currentAllUsersShare:k,onRemoveAccess:i}):e.jsx(kt,{resource:t,existingShares:y,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:O(),currentAllUsersShare:b,onRemoveAccess:i}):e.jsx(Fr,{resource:t,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:u,currentAllUsersShare:b,onRemoveAccess:i})})]})})}function pe(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function Le(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function ua(t,a,n){const{resourceType:r,resourceId:l,shareMutation:o,removeMutation:c,existingShares:i,resetUserSelections:d}=a;if(l)switch(t.context){case"org-tab":if(t.mode==="allOrgUsers"){const u=pe(r,l,[{scope:"org_users_only",role:t.orgWideRole}]);o(u,{onSuccess:()=>{d()}})}else if(t.mode==="specificOrgUsers"){const{selectedUsers:u,usersToRemove:m,usersToUpdate:h}=t;if(u&&u.length>0){const f=pe(r,l,u.map(g=>({scope:"specific_org_user",orgUserId:g.id,role:g.role})));o(f,{onSuccess:()=>{d()}})}if(m&&m.length>0){const f=Le(r,l,m.map(g=>{var p,y;const j=(y=(p=i==null?void 0:i.shares)==null?void 0:p.specificOrgUsers)==null?void 0:y.find(x=>x.orgUserId===g);return{scope:"specific_org_user",orgUserId:g,role:(j==null?void 0:j.role)||"VIEWER"}}));c(f,{onSuccess:()=>{d()}})}h&&h.length>0&&h.forEach(f=>{const g=pe(r,l,[{scope:"specific_org_user",orgUserId:f.id,role:f.newRole}]);o(g,{onSuccess:()=>{d()}})})}break;case"tenant-tab":if(t.mode==="allTenants"){const u=pe(r,l,[{scope:"all_tenants_only",role:t.allTenantsRole}]);o(u,{onSuccess:()=>{d()}})}else if(t.mode==="allTenantUsers"){const u=pe(r,l,[{scope:"all_tenant_users",tenantId:t.tenantId,role:t.tenantWideRole}]);o(u,{onSuccess:()=>{d()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:u,usersToRemove:m,usersToUpdate:h,tenantId:f}=t;if(m&&m.length>0){const g=Le(r,l,m.map(j=>{var y,x;const p=(x=(y=i==null?void 0:i.shares)==null?void 0:y.specificTenantUsers)==null?void 0:x.find(b=>b.tenantUserId===j);return{scope:"specific_tenant_user",tenantUserId:j,tenantId:f,role:(p==null?void 0:p.role)||"VIEWER"}}));c(g,{onSuccess:()=>{d()}})}if(h&&h.length>0&&h.forEach(g=>{const j=pe(r,l,[{scope:"specific_tenant_user",tenantUserId:g.id,tenantId:f,role:g.newRole}]);o(j,{onSuccess:()=>{d()}})}),u&&u.length>0){const g=pe(r,l,u.map(j=>({scope:"specific_tenant_user",tenantUserId:j.id,tenantId:f,role:j.role})));o(g,{onSuccess:()=>{d()}})}}break;case"tenant-dialog":if(t.mode==="allTenantUsers")if(t.removeAccess){const u=Le(r,l,[{scope:"all_tenant_users",role:"VIEWER"}]);c(u,{onSuccess:()=>{d()}})}else if(t.updateAccess){const u=pe(r,l,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);o(u,{onSuccess:()=>{d()}})}else{const u=pe(r,l,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);o(u,{onSuccess:()=>{d()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:u,usersToRemove:m,usersToUpdate:h}=t;if(u&&u.length>0){const f=pe(r,l,u.map(g=>({scope:"specific_tenant_user",tenantUserId:g.id,role:g.role})));o(f,{onSuccess:()=>{d()}})}if(m&&m.length>0){const f=Le(r,l,m.map(g=>{var p,y;const j=(y=(p=i==null?void 0:i.shares)==null?void 0:p.specificTenantUsers)==null?void 0:y.find(x=>x.tenantUserId===g);return{scope:"specific_tenant_user",tenantUserId:g,role:(j==null?void 0:j.role)||"VIEWER"}}));c(f,{onSuccess:()=>{d()}})}h&&h.length>0&&h.forEach(f=>{const g=pe(r,l,[{scope:"specific_tenant_user",tenantUserId:f.id,role:f.newRole}]);o(g,{onSuccess:()=>{d()}})})}break}}function ma(t,a,n,r){var u,m,h,f,g,j;const{resourceType:l,resourceId:o,removeMutation:c,existingShares:i,resetUserSelections:d}=r;if(o)if(t.length>0){const p=Le(l,o,t.map(y=>{var b,k;const x=(k=(b=i==null?void 0:i.shares)==null?void 0:b.specificTenantUsers)==null?void 0:k.find(O=>O.tenantUserId===y);return{scope:"specific_tenant_user",tenantUserId:y,role:(x==null?void 0:x.role)||"VIEWER"}}));c(p,{onSuccess:()=>{d()},onError:y=>{console.error("Remove access failed:",y)}})}else{const p=a==="tenant"&&n==="allTenants",y=a==="tenant"&&n==="allTenantUsers";if(p){const x=(m=(u=i==null?void 0:i.shares)==null?void 0:u.allTenantsOnly)==null?void 0:m[0];if(x){const b=Le(l,o,[{scope:"all_tenants_only",role:x.role}]);c(b,{onSuccess:()=>{d()},onError:k=>{console.error("Remove all-tenants access failed:",k)}})}}else if(y){const x=(f=(h=i==null?void 0:i.shares)==null?void 0:h.tenantWide)==null?void 0:f[0];if(x){const b=Le(l,o,[{scope:"all_tenant_users",role:x.role}]);c(b,{onSuccess:()=>{d()},onError:k=>{console.error("Remove all-tenant-users access failed:",k)}})}}else{const x=(j=(g=i==null?void 0:i.shares)==null?void 0:g.orgUsersOnly)==null?void 0:j[0];if(x){const b=Le(l,o,[{scope:"org_users_only",role:x.role}]);c(b,{onSuccess:()=>{d()},onError:k=>{console.error("Remove org-wide access failed:",k)}})}}}}function Br(t,a,n){const r=s.useShareManagementActions(),l=s.useShareUsersToRemove(),o=s.useShareSelectedTab(),c=s.useShareCurrentMode(),{currentUser:i}=we(),{existingShares:d}=Oe({debouncedSearchQuery:"",resourceId:t||"",resourceType:se.DASHBOARD,userType:"tenant"}),u=I.useCallback(()=>{r.resetUserSelections()},[r]),m=I.useCallback(f=>{if(!t)return;const g={resourceType:se.DASHBOARD,resourceId:t,shareMutation:a,removeMutation:n,existingShares:d,resetUserSelections:u};ua(f,g,i)},[t,a,n,d,u,i]),h=I.useCallback(()=>{if(!t)return;const f={resourceType:se.DASHBOARD,resourceId:t,removeMutation:n,existingShares:d,resetUserSelections:u};ma(l,o||"",c||"",f)},[t,a,n,d,u,l,o,c]);return{handleShareSubmit:m,handleRemoveAccess:h}}function Pr(t,a,n){const{currentUser:r}=we(),l=s.useShareManagementActions(),o=s.useShareUsersToRemove(),c=s.useShareSelectedTab(),i=s.useShareCurrentMode(),{existingShares:d}=Oe({debouncedSearchQuery:"",resourceId:t||"",resourceType:se.VISUAL,userType:"tenant"}),u=I.useCallback(()=>{l.resetUserSelections()},[l]),m=I.useCallback(f=>{if(!t)return;const g={resourceType:se.VISUAL,resourceId:t,shareMutation:a,removeMutation:n,existingShares:d,resetUserSelections:u};ua(f,g,r)},[t,a,n,d,u,r]),h=I.useCallback(()=>{if(!t)return;const f={resourceType:se.VISUAL,resourceId:t,removeMutation:n,existingShares:d,resetUserSelections:u};ma(o,c||"",i||"",f)},[t,a,n,d,u,o,c,i]);return{handleShareSubmit:m,handleRemoveAccess:h}}function zr(t){const a=t.toUpperCase().indexOf("WHERE"),n=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),l=t.toUpperCase().indexOf("ORDER BY");let o=t.length;if(l!==-1&&(o=l),r!==-1&&r<o&&(o=r),a!==-1){const c=t.substring(0,a),i=t.substring(a);return`${c} {{ filters | where }} AND ${i.substring(6)}`}else if(n!==-1){const c=t.substring(0,n),i=t.substring(n);return`${c} {{ filters | where }} ${i}`}else{const c=t.substring(0,o),i=t.substring(o);return console.log("beforeClause",c),console.log("afterClause",i),i?`${c} {{ filters | where }} ${i}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function Xs(t){const[a,n]=I.useState(null),[r,l]=I.useState(null);return I.useEffect(()=>{if(!t||t.trim()===""){n(null),l(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 i=`${t.endsWith("/")?t:`${t}/`}index.js`;try{if(!(await fetch(i,{method:"HEAD"})).ok)throw new Error(`Module not found at ${i}`)}catch{}const d=await import(i);if(typeof d.useChartStore!="function")throw new Error("useChartStore is not a function");n(()=>d.useChartStore),l(null)}catch(c){const i=c instanceof Error?c.message:"Unknown error";console.error("Failed to load remote chart store:",i),l(i),n(null)}})()},[t]),a}function Vr(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 o=r.split("__")[0],c=t.find(i=>i.tabTitle===o);return c?c.id:t[0].id}return a}}return t[0].id}async function Dt(t,a,n){if(!t||!a)throw new Error("Missing auth token or visual ID");const r=["resource-by-id","visual",a],l=n.getQueryData(r);if(l)return console.log("Using cached visual data for:",a),{data:l,fromCache:!0};console.log("Fetching visual data from network for:",a);const o=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 i=await c.json();return n.setQueryData(r,i),s.ue.dismiss(o),{data:i,fromCache:!1}}catch(c){throw s.ue.dismiss(o),c}}function _r(t,a,n,r,l){const o=t.frameObject;a(o);const c=o.cards.find(i=>i.id===o.activeCardId);c&&n(c),r(!0),l(!0)}function Ur(){var f;const{setCardSql:t}=s.useEditorActions(),a=s.useEditorStore(g=>g.frame),n=s.useEditorStore(g=>g.card),r=Xs(((f=n.customCardPreferences)==null?void 0:f.url)||""),l=s.useEditorStore(g=>g.selectedSchemaName),o=s.useEditorStore(g=>g.selectedDatamodelId),c=s.useEditorStore(g=>g.selectedDatabaseName),i=s.useEditorStore(g=>g.selectedTableName),d=s.useEditorStore(g=>g.selectedConnectionId),u=s.useEditorStore(g=>g.isShowingVisual),m=n.sql;return{getUpdatedFrame:I.useCallback(()=>{var x;let g=m;m&&!m.includes("{{")&&(g=zr(m),t(g));const j=(x=r==null?void 0:r.getState())==null?void 0:x.settings,p={...n,dataSource:n.dataSource||{mode:"directSource"},lastSelectedSchema:l,lastSelectedDatamodelId:o,lastSelectedDatabase:c,lastSelectedTable:i,connectionId:d,sql:g,customCfg:u?n.customCfg:null,...j&&{customCardPreferences:{...n.customCardPreferences,settings:j}}},y=a.cards.map(b=>b.id===n.id?p:b);return{...a,cards:y,activeCardId:Vr(y,a.activeCardId)}},[n,a,u,l,o,c,i,d,t,r,m])}}function Zs(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient(),n=s.useSelectedVisual(),{selectVisual:r}=s.useManagementActions(),{setFrame:l,setCard:o}=s.useEditorActions(),{setIsDashboardEditing:c,setIsVisualEditing:i,setSelectedFrameId:d,addFrame:u,setIsDashboardPanelOpen:m}=s.useDashboardActions(),h=s.useDashboardStore(p=>p.selectedSheetId),f=jr((n==null?void 0:n.id)||"",{enabled:!!(n!=null&&n.id)&&!!(t!=null&&t.accessToken)}),g=I.useCallback(async p=>{try{r(p);const{data:y,fromCache:x}=await Dt((t==null?void 0:t.accessToken)||"",p.id,a);return _r(y,l,o,c,i),{success:!0,fromCache:x}}catch(y){return console.error("Error editing visual:",y),{success:!1,error:"Failed to load visual for editing"}}},[t==null?void 0:t.accessToken,a,r,l,o,c,i]),j=I.useCallback(async p=>{try{if(r(p),!h)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:y,fromCache:x}=await Dt((t==null?void 0:t.accessToken)||"",p.id,a),b=y.frameObject;if(!b)return{success:!1,error:"Visual has no frame data"};const k={...b,id:s.v4()};return u(h,k,"end"),c(!0),d(k.id),m(!1),{success:!0,fromCache:x}}catch(y){return console.error("Error adding visual:",y),{success:!1,error:"Failed to add visual to dashboard"}}},[t==null?void 0:t.accessToken,a,r,h,u,c,d,m]);return{visual:f.data,isLoading:f.isLoading,isError:f.isError,error:f.error,handleEditLibraryVisual:g,handleAddLibraryVisual:j,getUpdatedFrame:Ur().getUpdatedFrame,refetch:f.refetch}}function $r(){const[t,a]=I.useState(""),[n,r]=I.useState(!1),[l,o]=I.useState(""),[c,i]=I.useState(""),[d,u]=I.useState(!1),[m,h]=I.useState(null),[f,g]=I.useState(!1),[j,p]=I.useState(null),[y,x]=I.useState(null),{setIsDashboardEditing:b,setIsVisualEditing:k}=s.useDashboardActions(),{handleEditLibraryVisual:O,handleAddLibraryVisual:N}=Zs(),{resources:C,isLoading:v,isError:D,createResource:E,updateResource:L,deleteResource:w,duplicateResource:F,shareResource:S,isCreating:T,isDeleting:A,removeResourceShares:B,isSharing:M,isRemovingShares:R,isUpdatingShares:z}=vr(()=>{g(!1),p(null)},()=>{r(!1),o(""),i("")}),{handleShareSubmit:V,handleRemoveAccess:J}=Pr((m==null?void 0:m.id)||null,S,B);we();const Z=C.filter(Q=>{var ne,de;return((ne=Q==null?void 0:Q.title)==null?void 0:ne.toLowerCase().includes(t.toLowerCase()))||((de=Q==null?void 0:Q.description)==null?void 0:de.toLowerCase().includes(t.toLowerCase()))}),W=Q=>new Date(Q).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),q=()=>{l.trim()&&E({title:l,description:c,isPrivate:!1})},G=Q=>{p(Q),g(!0)},P=()=>{j&&w(j.id)},{startUpdating:_,stopUpdating:U,isUpdating:Y}=Zt(),X=(Q,ne)=>{const de=ne.title!==void 0?"title":"description";_(Q,de),L({resourceId:Q,data:ne},{onSuccess:()=>{U(Q,de)},onError:()=>{U(Q,de)}})},$=Q=>{x(Q),F(Q,{onSettled:()=>x(null)})},ee=Q=>{O(Q)},te=Q=>{N(Q)},ie=Q=>{const ne=C.find(de=>de.id===Q);ne&&L({resourceId:Q,data:{isPrivate:!ne.isPrivate}})},K=Q=>{h(Q),u(!0)};return s.useShareUsersToRemove(),s.useShareManagementActions(),Oe({debouncedSearchQuery:"",resourceId:(m==null?void 0:m.id)||"",resourceType:se.VISUAL,userType:"tenant"}),v?e.jsx(Jt,{}):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:l,onChange:Q=>o(Q.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:Q=>i(Q.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(s.Button,{onClick:q,size:"sm",className:"h-7 text-xs",disabled:!l.trim()||T,children:T?"Creating...":"Create"}),e.jsx(s.Button,{onClick:()=>{r(!1),o(""),i("")},variant:"outline",size:"sm",className:"h-7 text-xs",disabled:T,children:"Cancel"})]})]})]}):e.jsxs(s.Button,{onClick:()=>r(!0),className:"h-8 w-full",size:"sm",disabled:T,children:[e.jsx(s.Plus,{className:"mr-2 h-3.5 w-3.5"}),T?"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:Q=>a(Q.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:Z.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(Ss,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No visuals found"})]}):Z.map(Q=>e.jsx(Nr,{visual:Q,onAddVisual:te,onEditVisual:ee,onUpdateVisual:X,onDeleteClick:G,onDuplicateVisual:$,onTogglePrivacy:ie,onShareVisual:K,isDeleting:A,isDuplicating:y===Q.id,isTitleUpdating:Y(Q.id,"title"),isDescriptionUpdating:Y(Q.id,"description"),formatDate:W},Q.id))})}),d&&m&&e.jsx(da,{resource:m,resourceType:se.VISUAL,onShare:V,isSharing:M,isRemoving:R,isUpdating:z,onClose:()=>{u(!1),h(null)},onRemoveAccess:J}),e.jsx(s.AlertDialog,{open:f,onOpenChange:Q=>{!Q&&A||(g(Q),Q||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 "',j==null?void 0:j.title,'"? This action cannot be undone.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{disabled:A,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:Q=>{Q.preventDefault(),Q.stopPropagation(),P()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:A,children:A?"Deleting...":"Delete"})]})]})})]})}function qr({dashboard:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:l=!1,onLoadDashboard:o,onUpdateDashboard:c,onDeleteClick:i,onDuplicateDashboard:d,onShareDashboard:u,formatDate:m,onDashboardItemClick:h}){var C;const{selectDashboard:f}=s.useManagementActions(),g=s.useIsDashboardSelected(t.id),[j,p]=I.useState(!1),[y,x]=I.useState(!1),b=s.useDashboardStore(v=>v.actions.setIsDashboardPanelOpen);I.useEffect(()=>{n?(p(!0),x(!0)):y&&(p(!1),x(!1))},[n,y]);const k=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx($t,{className:"h-3 w-3 text-purple-500"}):e.jsx(Se,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(Re,{className:"h-3.5 w-3.5 text-slate-500"}),O=()=>e.jsx(s.LayoutDashboard,{className:"h-4 w-4 text-slate-400"}),N=()=>{f(t),o(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",g&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:N,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:v=>c==null?void 0:c(t.id,{title:v}),isEditable:t.permissions.canEdit&&g,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:v=>c==null?void 0:c(t.id,{description:v}),isEditable:t.permissions.canEdit&&g,isPending:l,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:j,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:v=>v.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:v=>{v.preventDefault(),v.stopPropagation(),d(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:v=>{v.stopPropagation(),u(t)},children:[e.jsx(Se,{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:v=>{v.stopPropagation(),i(t),b(!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(Re,{className:"h-3 w-3"}),e.jsx("span",{children:((C=t.ownership.createdBy)==null?void 0:C.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:m(t.lastModified)})]})]})]})]})})})]})]},t.id)}function Yr({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 Gr(t){const[a,n]=I.useState(""),[r,l]=I.useState(!1),[o,c]=I.useState(""),[i,d]=I.useState(""),[u,m]=I.useState(!1),[h,f]=I.useState(null),[g,j]=I.useState(!1),[p,y]=I.useState(null),[x,b]=I.useState(null),k=s.useManagementStore(K=>K.lastSelectedDashboard),O=s.useManagementStore(K=>K.actions.selectDashboard);s.useShareManagementActions(),s.useShareUsersToRemove(),s.useShareSelectedTab(),s.useShareCurrentMode();const{resources:N,isLoading:C,isError:v,createResource:D,updateResource:E,deleteResource:L,duplicateResource:w,isCreating:F,isDeleting:S,isSharing:T,isRemovingShares:A,isUpdatingShares:B,shareResource:M,removeResourceShares:R}=yr(()=>{j(!1),y(null),k&&O(k)},()=>{l(!1),c(""),d("")}),{handleShareSubmit:z,handleRemoveAccess:V}=Br((h==null?void 0:h.id)||null,M,R),{currentUser:J}=we(),Z=N.filter(K=>{var Q,ne;return((Q=K==null?void 0:K.title)==null?void 0:Q.toLowerCase().includes(a.toLowerCase()))||((ne=K==null?void 0:K.description)==null?void 0:ne.toLowerCase().includes(a.toLowerCase()))}),W=K=>new Date(K).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),q=()=>{o.trim()&&D({title:o,description:i,isPrivate:!1})},G=K=>{var Q;(Q=t.onLoadDashboard)==null||Q.call(t,K)},P=K=>{y(K),j(!0)},_=()=>{p&&L(p.id)},U=K=>{b(K),w(K,{onSettled:()=>b(null)})},{startUpdating:Y,stopUpdating:X,isUpdating:$}=Zt(),ee=(K,Q)=>{const ne=Q.title!==void 0?"title":"description";Y(K,ne),E({resourceId:K,data:Q},{onSuccess:()=>{X(K,ne)},onError:()=>{X(K,ne)}})},te=K=>{const Q=N.find(ne=>ne.id===K);Q&&E({resourceId:K,data:{isPrivate:!Q.isPrivate}})},ie=K=>{f(K),J==null||J.type,m(!0)};return Oe({debouncedSearchQuery:"",resourceId:(h==null?void 0:h.id)||"",resourceType:se.DASHBOARD,userType:"tenant"}),C?e.jsx(Jt,{}):v?e.jsx(Yr,{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:o,onChange:K=>c(K.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:i,onChange:K=>d(K.target.value),className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(s.Button,{onClick:q,size:"sm",className:"h-7 text-xs",disabled:!o.trim()||F,children:F?"Creating...":"Create"}),e.jsx(s.Button,{onClick:()=>{l(!1),c(""),d("")},variant:"outline",size:"sm",className:"h-7 text-xs",disabled:F,children:"Cancel"})]})]})]}):e.jsxs(s.Button,{onClick:()=>l(!0),className:"h-8 w-full",size:"sm",disabled:F,children:[e.jsx(s.Plus,{className:"mr-2 h-3.5 w-3.5"}),F?"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:K=>n(K.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:Z.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(vn,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No dashboards found"})]}):Z.map(K=>e.jsx(qr,{dashboard:K,isDeleting:S,isDuplicating:x===K.id,isTitleUpdating:$(K.id,"title"),isDescriptionUpdating:$(K.id,"description"),onLoadDashboard:G,onEditDashboard:t.onEditDashboard,onUpdateDashboard:ee,onDeleteClick:P,onDuplicateDashboard:U,onTogglePrivacy:te,onShareDashboard:ie,formatDate:W,onDashboardItemClick:t.onDashboardItemClick},K.id))})}),u&&h&&e.jsx(da,{resource:h,resourceType:se.DASHBOARD,onShare:z,isSharing:T,isRemoving:A,isUpdating:B,onClose:()=>{m(!1),f(null)},onRemoveAccess:V}),e.jsx(s.AlertDialog,{open:g,onOpenChange:K=>{!K&&S||(j(K),K||y(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:S,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:K=>{K.preventDefault(),K.stopPropagation(),_()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:S,children:S?"Deleting...":"Delete"})]})]})})]})}function ha({isOpen:t,onClose:a,className:n,onDashboardItemClick:r}){s.useDashboardStore(g=>g.dashboard);const{setDashboard:l,addSheet:o}=s.useDashboardStore(g=>g.actions),{currentUser:c}=we(),i=c,[d,u]=s.useLocalStorageState("resource-management-active-tab","dashboards"),m=na(a,{enabled:t}),h=g=>{},f=g=>{console.log("Editing dashboard:",g)};return e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{ref:m,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:i&&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:i.name}),e.jsx(s.AvatarFallback,{className:"text-xs",children:i.name.charAt(0).toUpperCase()})]}),e.jsx("span",{className:"text-xs font-medium",children:i.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:i.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:i.email}),i.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role:"," ",s.toTitleCase(i.role.replace(/_/g," "))]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",i.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:d,onValueChange:u,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(Gr,{onLoadDashboard:h,onEditDashboard:f,onDashboardItemClick:r})}),e.jsx(s.TabsContent,{value:"visuals",className:"flex-1",children:e.jsx($r,{})})]})})]})})}function Hr(){var G,P;const{authToken:t,tokenProps:a}=s.useSemaphorContext();s.useDashboardStore(_=>_.theme);const n=s.useDashboardStore(_=>_.lenses),r=s.useDashboardStore(_=>_.selectedLensId),l=n==null?void 0:n.find(_=>_.id===r),o=s.useDashboardStore(_=>_.dashboard);s.useDashboardStore(_=>_.selectedSheetId);const c=s.useDashboardStore(_=>_.isDashboardEditing),i=s.useEditorStore(_=>_.card),d=s.useEditorStore(_=>_.selectedConnectionId),[u,m]=I.useState(!1),h=s.useDashboardStore(_=>_.isDashboardPanelOpen),f=s.useDashboardStore(_=>_.actions.setIsDashboardPanelOpen),g=s.useDashboardStore(_=>_.filterValues),j=s.useDashboardStore(_=>_.isVisualEditing),p=s.useManagementStore(_=>_.selectedDashboard),y=s.useManagementStore(_=>_.initialDashboard),x=p?(P=p==null?void 0:p.permissions)==null?void 0:P.canEdit:(G=y==null?void 0:y.permissions)==null?void 0:G.canEdit,b=s.useDashboardStore(_=>_.showFilters);s.useDashboardStore(_=>_.showDashboardJSON);const k=s.useDashboardStore(_=>_.onSaveFunction),O=s.useDashboardStore(_=>_.actions.setShowFilters),{addFrame:N,setSelectedFrameId:C}=s.useDashboardStore(_=>_.actions),{getSelectedSheet:v,setIsDashboardEditing:D,setShowDashboardJSON:E}=s.useDashboardStore(_=>_.actions),L=v(),{setInitialDashboard:w}=s.useManagementStore(_=>_.actions),{resources:F}=Js(se.DASHBOARD);I.useEffect(()=>{if(F&&F.length>0){const _=o==null?void 0:o.id;if(_){const U=F.find(Y=>Y.id===_);U&&w(U)}}},[F,o==null?void 0:o.id,w]);const S=a.orgUserId||a.tenantId,T=c&&!j&&S&&x;function A(){var X,$;const _=i.dataSource;if(_)return _;const U=($=(X=o.aiContext)==null?void 0:X.selectedEntities)==null?void 0:$[0],Y=U==null?void 0:U.type;if(U)return{connectionId:U.connectionId,connectionType:U.connectionType,type:Y,selectedEntities:[U]}}const B=()=>{if(!c||!L)return;const U={dataSource:A(),mode:"explorer",connectionId:d,id:s.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},Y={id:s.v4(),cards:[U],activeCardId:U.id};N(L.id,Y),C(Y.id)},M=()=>{D(!0)},[R,z]=I.useState(!1),V=Xt(se.DASHBOARD);async function J(){const _=fs(o);z(!0);const U={template:_};V.mutate({resourceId:_.id,data:U},{onSuccess:()=>{z(!1),s.ue.success("Dashboard saved!")},onError:()=>{z(!1),s.ue.error("Failed to save dashboard")}})}async function Z(){if(m(!0),!r||!l)return;const _=fs(o),U=JSON.stringify(_),Y={...l,template:U,filterValues:g};await Vs(Y,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),k==null||k(_),m(!1)}if(j)return null;const W=(l==null?void 0:l.name)||o.title,q=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:[q&&e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>f(!0),className:"h-7 p-2",children:e.jsx(wn,{className:"h-4 w-4"})}),!j&&e.jsx(s.Label,{children:W})]}),e.jsxs("div",{className:"flex gap-2",children:[!1,!j&&e.jsx(Xn,{}),!j&&e.jsx(Wt,{}),c&&!j&&S&&e.jsx(Wn,{}),!j&&S&&e.jsx(Jn,{}),c&&!j&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:B,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!j&&!c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:M,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),c&&!j&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",onClick:()=>{D(!1),E(!1)},children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),c&&!j&&S&&l&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:u,onClick:Z,size:"sm",children:[e.jsx(zs,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),T&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"outline",disabled:R,onClick:J,size:"sm",children:[R?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(zs,{className:"mr-2 h-4 w-4"}),R?"Saving...":"Save"]}),!b&&!j&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>O(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),!j&&c&&!1,!j&&!1,!j&&e.jsx(ha,{isOpen:h,onClose:()=>f(!1)})]})]})}function Kr({name:t,items:a,value:n,onChange:r,isLoading:l,isError:o,refetch:c,className:i,icon:d,showNone:u=!1}){const m=xe.useRef(null),[h,f]=xe.useState(!1),[g,j]=xe.useState("100%"),p=u?[...a||[],{id:"none",name:"None"}]:a;xe.useLayoutEffect(()=>{m.current&&j(m.current.offsetWidth)},[]);function y(){var b;return l?"Loading...":o?"Error":n?(b=a==null?void 0:a.find(k=>k.id===n))==null?void 0:b.name:`Select ${t}`}function x(b,k){r(k),f(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:f,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:m,variant:"outline",role:"combobox","aria-expanded":h,className:s.cn("flex h-9 w-full justify-between",i),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[d&&e.jsx("div",{className:"mr-2",children:d}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:y()})]}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:g},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(qt,{className:s.cn("size-3.5 opacity-50",l&&"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(b=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:b.name,onSelect:k=>x(k,b.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",n===b.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:b.name,children:b.name})]})},b.id))})]})]})})]})}function Ke({title:t,items:a,value:n,isLoading:r,isError:l,refetch:o,onChange:c,showNone:i=!1,className:d,disabled:u=!1,type:m="combobox"}){const h=r?"Loading...":l?"Error":n;function f(){if(t==="Connection")return e.jsx(Pn,{className:"size-4"});if(t==="Database")return e.jsx(s.Database,{className:"size-4"});if(t==="Schema")return e.jsx(On,{className:"size-4"});if(t==="Table")return e.jsx(Qe,{className:"size-4"});if(t==="Model")return e.jsx(ln,{className:"size-4"})}function g(){return e.jsxs(s.Select,{disabled:u,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",d),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":l?"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(qt,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:o})]}),e.jsxs(e.Fragment,{children:[i&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((p,y)=>e.jsx(s.SelectItem,{value:p.id,children:p.name},y))]}),(r||l)&&e.jsx(s.SelectItem,{value:h,children:h})]})})]})}function j(){return e.jsx(Kr,{icon:f(),items:a,value:h,onChange:c||(()=>{}),isLoading:r,isError:l,refetch:o,name:t,showNone:i})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:m==="select"?g():j()})})}function Qr({column:t}){const[a,n]=I.useState(!1),r=s.useEditorStore(p=>p.selectedTableName),l=s.useEditorStore(p=>p.selectedSchemaName),o=s.useEditorStore(p=>p.selectedDatabaseName),c=s.useEditorStore(p=>p.selectedDatamodelId),i=s.useEditorStore(p=>p.sqlGen),{modelItems:d,connectionType:u}=s.useEditorAside(),m=s.useEditorStore(p=>p.actions.setSqlGen),h=s.useEditorStore(p=>p.actions.setCardSql),f=s.useEditorStore(p=>p.actions.setRunSql);function g(p,y){var O;const x=s.createSqlGenConfig(p,i,y),b=(O=d==null?void 0:d.find(N=>N.id===c))==null?void 0:O.name;m(x);const k=s.getSql(x,s.fmt(l||""),s.fmt(r),b||"",u,o||"");k&&(h(k),f(!0)),n(!1)}function j(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>g(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>g(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>g(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>g(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>g(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:j()})]})}function Wr({dataType:t}){const a=s.getDataType(t);return a==="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(ge,{className:"h-3 w-3"})}):a==="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(Ce,{className:"h-3 w-3"})}):a==="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"})}):a==="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(_e,{className:"h-3 w-3"})}):a==="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(es,{className:"h-3 w-3"})}):a==="geo"?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(ss,{className:"h-3 w-3"})}):a==="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(rs,{className:"h-3 w-3"})}):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(ge,{className:"h-3 w-3"})})}function Es({column:t,className:a}){return e.jsxs("div",{className:s.cn("flex min-h-8 grow items-center gap-2 px-3 py-[6px] text-sm",a),children:[e.jsx(Wr,{dataType:t.data_type}),e.jsx("span",{children:t.column_name})]})}function Jr({id:t,children:a,type:n="column"}){const{attributes:r,listeners:l,setNodeRef:o,transform:c}=s.useDraggable({id:t,data:{type:n}}),i=c?{translate:s.CSS.Translate.toString(c),transform:s.CSS.Transform.toString(c)}:void 0;return e.jsx("div",{ref:o,style:i,...l,...r,children:a})}function Xr({onClick:t,column:a}){const n=s.useDndStore(m=>m.activeId),r=s.useEditorStore(m=>{var h;return(h=m.card.queryConfig)==null?void 0:h.groupByColumns}),l=s.useEditorStore(m=>{var h;return(h=m.card.queryConfig)==null?void 0:h.metricColumns}),o=s.useEditorStore(m=>{var h;return(h=m.card.queryConfig)==null?void 0:h.filterColumns});function c(m){return i(m)||d(m)||u(m)}function i(m){return r==null?void 0:r.some(h=>h.name===m.column_name)}function d(m){return l==null?void 0:l.some(h=>h.name===m.column_name)}function u(m){return o==null?void 0:o.some(h=>h.name===m.column_name)}return e.jsxs("div",{onClick:()=>t(a),className:s.cn("group relative grow cursor-pointer overflow-x-hidden overflow-y-hidden border border-dashed border-background transition-colors hover:bg-muted/50",{"bg-muted":c(a)}),children:[n===a.column_name&&e.jsx(s.DragOverlay,{children:e.jsx(Es,{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(Es,{column:a})}),e.jsx(Jr,{id:a.column_name,type:"column",children:e.jsx(Es,{column:a})})]})}const Is={id:"__placeholder__",role:"groupby",type:"string"},As={id:"__placeholder__",role:"groupby",type:"string"},Ms={id:"__placeholder__",role:"metric",type:"number"},Ls={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},xa={id:"__placeholder__"},Pe="droppable-group-by",ze="droppable-metrics",Ve="droppable-pivot-by",js="sortable-group-by",_s="sortable-metrics",ys="sortable-pivot-by",Us="droppable-filters",$s="sortable-filters",et="sortable-order-by";function Zr(){const t=s.useDndStore(T=>T.insertIndex),a=s.useEditorStore(T=>{var A;return((A=T.card.queryConfig)==null?void 0:A.groupByColumns)||[]}),n=s.useEditorStore(T=>{var A;return((A=T.card.queryConfig)==null?void 0:A.metricColumns)||[]}),r=s.useEditorStore(T=>{var A;return((A=T.card.queryConfig)==null?void 0:A.filterColumns)||[]}),l=s.useEditorStore(T=>{var A;return((A=T.card.queryConfig)==null?void 0:A.orderBy)||[]}),o=s.useEditorStore(T=>{var A;return((A=T.card.queryConfig)==null?void 0:A.pivotColumns)||[]}),{setInsertIndex:c,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:u,setPreviewFilterColumns:m,setPreviewPivotColumns:h}=s.useDndActions(),{setGroupByColumns:f,setMetricColumns:g,setFilterColumns:j,setOrderByColumns:p,setPivotByColumns:y}=s.useEditorActions(),{columns:x}=s.useDataColumns(),{formattedTableName:b}=s.useEditorAside(),k=s.useSensors(s.useSensor(s.MouseSensor,{activationConstraint:{distance:1}})),O=T=>{var M;const{active:A,over:B}=T;if(((M=A.data.current)==null?void 0:M.type)==="column"&&B){const R=B.id,z=x.find(W=>W.column_name===A.id);if(!z)return;const V=s.isNumberDataType(z.data_type),J=s.isTextDataType(z.data_type),Z=s.isDateDataType(z.data_type);if(J||Z){if(a.some(q=>q.id===R)){const q=a.findIndex(P=>P.id===R);c(q);const G=a.filter(P=>P.id!==Is.id);G.splice(q,0,Is),d(G)}else if(B.id===Pe){c(a.length);const q=[...a,Is];d(q),u(n),m(r)}}if(J||Z){if(o.some(q=>q.id===R)){const q=o.findIndex(P=>P.id===R);c(q);const G=o.filter(P=>P.id!==As.id);G.splice(q,0,As),h(G)}else if(B.id===Ve){c(o.length);const q=[...o,As];h(q),d(a),u(n),m(r)}}if(V||J){if(n.some(q=>q.id===R)){console.log("isOverMetricSortable",R);const q=n.findIndex(P=>P.id===R);c(q);const G=n.filter(P=>P.id!==Ms.id);G.splice(q,0,Ms),u(G)}else if(B.id===ze){c(n.length);const q=[...n,Ms];u(q),m(r),d(a),h(o)}}if(C(z)){if(r.some(q=>q.id===R)){const q=r.findIndex(P=>P.id===R);c(q);const G=r.filter(P=>P.id!==Ls.id);G.splice(q,0,Ls),m(G)}else if(B.id===Us){c(r.length);const q=[...r,Ls];m(q),u(n),d(a),h(o)}}}else d(a),u(n),m(r),h(o)};function N(T){i(T.active.id),c(null),d(a),u(n),m(r),h(o)}function C(T){return!r.some(A=>A.name===T.column_name)}function v(T,A="SUM"){const{column_name:B,data_type:M}=T,R=[...n],z=t!==null?t:n.length,V={...T,id:ye(B),name:B,label:ns(B,A),type:M,role:"metric",aggregate:A};R.splice(z,0,V),g(R)}function D(T){const A=s.isTextDataType(T.data_type);s.isDateDataType(T.data_type);const B=[...o],M=t!==null?t:o.length;let R;A?R={...T,id:ye(T.column_name),name:T.column_name,type:T.data_type,role:"groupby"}:R={...T,id:ye(T.column_name),name:T.column_name,type:T.data_type,role:"groupby",label:We(T.column_name,"month"),granularity:"month"},B.splice(M,0,R),y(B)}function E(T){const A=s.isTextDataType(T.data_type);s.isDateDataType(T.data_type);const B=[...a],M=t!==null?t:a.length;let R;A?R={...T,id:ye(T.column_name),name:T.column_name,type:T.data_type,role:"groupby"}:R={...T,id:ye(T.column_name),name:T.column_name,type:T.data_type,role:"groupby",label:We(T.column_name,"month"),granularity:"month"},B.splice(M,0,R),f(B)}function L(T){const A=[...r],B=t!==null?t:r.length,M={...T,id:ye(T.column_name),name:T.column_name,type:T.data_type,sql:s.getDefaultFilterSql(T.data_type,b,s.fmt(T.column_name)),role:"filter"};A.splice(B,0,M),j(A)}function w(T){var R,z,V,J,Z,W,q,G;const{active:A,over:B}=T,M=A.data.current;if((M==null?void 0:M.type)==="column"&&B){const P=x.find(X=>X.column_name===A.id);if(!P)return;const _=s.isNumberDataType(P.data_type),U=s.isTextDataType(P.data_type),Y=s.isDateDataType(P.data_type);(U||Y)&&(B.id===Pe||((R=B.data.current)==null?void 0:R.type)===js)&&E(P),(U||Y)&&(B.id===Ve||((z=B.data.current)==null?void 0:z.type)===ys)?D(P):(_||U)&&(B.id===ze||((V=B.data.current)==null?void 0:V.type)===_s)?(_&&v(P),U&&v(P,"COUNT")):C(P)&&(B.id===Us||((J=B.data.current)==null?void 0:J.type)===$s)&&L(P)}if(B&&((Z=B.data.current)==null?void 0:Z.type)===js&&a.some(P=>P.id===A.id)){const P=a.findIndex(U=>U.id===A.id),_=a.findIndex(U=>U.id===B.id);if(P!==-1&&_!==-1&&P!==_){const U=[...a],[Y]=U.splice(P,1);U.splice(_,0,Y),f(U)}}if(B&&((W=B.data.current)==null?void 0:W.type)===ys&&o.some(P=>P.id===A.id)){const P=o.findIndex(U=>U.id===A.id),_=o.findIndex(U=>U.id===B.id);if(P!==-1&&_!==-1&&P!==_){const U=[...o],[Y]=U.splice(P,1);U.splice(_,0,Y),y(U)}}if(B&&((q=B.data.current)==null?void 0:q.type)===_s&&n.some(P=>P.id===A.id)){const P=n.findIndex(U=>U.id===A.id),_=n.findIndex(U=>U.id===B.id);if(P!==-1&&_!==-1&&P!==_){const U=[...n],[Y]=U.splice(P,1);U.splice(_,0,Y),g(U)}}if(B&&((G=B.data.current)==null?void 0:G.type)===$s&&r.some(P=>P.id===A.id)){const P=r.findIndex(U=>U.id===A.id),_=r.findIndex(U=>U.id===B.id);if(P!==-1&&_!==-1&&P!==_){const U=[...r],[Y]=U.splice(P,1);U.splice(_,0,Y),j(U)}}F(T),i(null),c(null),d(a),u(n),m(r),h(o)}function F(T){const{active:A,over:B}=T,M=A.data.current;if((M==null?void 0:M.type)===et&&B){const R=l.findIndex(V=>Ze(V.columnId)===A.id),z=l.findIndex(V=>Ze(V.columnId)===B.id);if(R!==-1&&z!==-1&&R!==z){const V=[...l],[J]=V.splice(R,1);V.splice(z,0,J),p(V)}}}function S(){i(null),c(null),d(a),u(n),m(r)}return{handleDragOver:O,handleDragEnd:w,handleDragStart:N,handleDragCancel:S,sensors:k}}function ye(t){return`${t}-${s.v4()}`}function ns(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 Ze(t){return`${et}-${t}`}function We(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 el({dataType:t}){const a=s.getDataType(t);return a==="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(ge,{className:"h-3 w-3"})}):a==="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(Ce,{className:"h-3 w-3"})}):a==="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"})}):a==="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(_e,{className:"h-3 w-3"})}):a==="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(es,{className:"h-3 w-3"})}):a==="geo"?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(ss,{className:"h-3 w-3"})}):a==="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(rs,{className:"h-3 w-3"})}):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(ge,{className:"h-3 w-3"})})}function sl({schemaName:t,tableName:a,columns:n,status:r}){const[l,o]=I.useState(""),[c,i]=I.useState("all"),d=s.useEditorStore(R=>R.sqlGen),u=s.useEditorStore(R=>R.isDevMode);s.useEditorStore(R=>R.selectedConnectionId);const m=s.useEditorStore(R=>{var z,V;return(V=(z=R.card)==null?void 0:z.queryConfig)==null?void 0:V.metricColumns});s.useEditorStore(R=>{var z,V;return(V=(z=R.card)==null?void 0:z.queryConfig)==null?void 0:V.groupByColumns});const h=s.useEditorStore(R=>R.selectedDatabaseName);s.useEditorStore(R=>R.selectedSchemaName),s.useEditorStore(R=>R.selectedTableName);const f=s.useEditorStore(R=>R.selectedDatamodelId);s.useDashboardStore(R=>R.dashboard.aiScopeTables);const{addToAIScope:g,removeFromAIScope:j}=s.useDashboardActions(),{addColumnToMetricColumns:p,addColumnToGroupBy:y,setCardSql:x,setRunSql:b,setSqlGen:k,setIsShowingVisual:O}=s.useEditorActions(),{connectionType:N,modelItems:C,selectedDatamodelName:v}=s.useEditorAside();function D(R){var z;if(u){const V=s.createSqlGenConfig(R,d);k(V);const J=(z=C==null?void 0:C.find(W=>W.id===f))==null?void 0:z.name,Z=s.getSql(V,s.fmt(t),s.fmt(a),J||"",N,h||"");Z&&(x(Z),b(!0))}if(!u){if(s.isTextDataType(R.data_type))if(m&&m.length>0){const V={...R,role:"groupby",id:ye(R.column_name),name:R.column_name,type:R.data_type};y(V)}else{const V={...R,role:"metric",id:ye(R.column_name),name:R.column_name,label:ns(R.column_name,"COUNT"),type:R.data_type,aggregate:"COUNT"};p(V)}if(s.isDateDataType(R.data_type)){const V={...R,role:"groupby",id:ye(R.column_name),name:R.column_name,type:R.data_type,label:We(R.column_name,"month"),granularity:"month"};y(V)}if(s.isNumberDataType(R.data_type)){const V={...R,role:"metric",id:ye(R.column_name),name:R.column_name,label:ns(R.column_name,"SUM"),type:R.data_type,aggregate:"SUM"};p(V)}}}function E(){const R=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:v,connectionType:N,databaseName:h||""});O(!1);const z=N==="MSSQL"?`SELECT top 10 * FROM ${R}`:`SELECT * FROM ${R} LIMIT 10`;x(z),b(!0)}function L(){const R=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:v,connectionType:N,databaseName:h||""});x(`SELECT COUNT(*) as count FROM ${R}`),b(!0)}const w=(n==null?void 0:n.filter(R=>R.column_name.toLowerCase().includes(l.toLowerCase())))||[],F=R=>s.isNumberDataType(R.data_type)?"number":"text",S=c==="all"?w:w.filter(R=>F(R)===c),T=w.filter(R=>F(R)==="text").length,A=w.filter(R=>F(R)==="number").length;function B(R){return u?e.jsxs("div",{className:"group flex cursor-pointer items-center justify-between border border-dashed border-background px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",onClick:()=>D(R),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(el,{dataType:R.data_type}),e.jsx("span",{children:R.column_name})]}),e.jsx("div",{onClick:z=>z.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(R.data_type)&&e.jsx(Qr,{column:R})})]}):e.jsx(Xr,{onClick:D,column:R})}function M(){return e.jsxs("div",{className:"flex grow gap-2",children:[e.jsxs(s.Button,{disabled:r!=="Success",onClick:E,size:"sm",variant:"secondary",className:"grow",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(An,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:L,size:"sm",variant:"secondary",className:"grow",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Yt,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-4",children:Array.from({length:3}).map((R,z)=>e.jsx(s.Skeleton,{className:"h-8 w-full"},z))}):e.jsxs("div",{className:"flex grow flex-col",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-3 px-4",children:[u&&e.jsx("div",{className:"flex items-center justify-center gap-2",children:M()}),n&&n.length>0&&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 transform text-muted-foreground"}),e.jsx(s.Input$1,{className:"pl-10",type:"text",placeholder:"Search fields...",value:l,onChange:R=>o(R.target.value)})]}),w.length>0&&e.jsx(s.Tabs,{defaultValue:"all",value:c,onValueChange:R=>i(R),children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-3",children:[e.jsxs(s.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:w.length})]}),e.jsxs(s.TabsTrigger,{value:"text",className:"text-xs",children:[e.jsx(s.Layers,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:T})]}),e.jsxs(s.TabsTrigger,{value:"number",className:"text-xs",children:[e.jsx(s.ChartColumn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:A})]})]})})]}),e.jsxs(s.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-4 pt-3",children:[S.length===0&&l&&e.jsxs("div",{className:"py-4 text-center text-sm text-gray-500",children:['No fields found matching "',l,'"']}),S.length===0&&!l&&c!=="all"&&e.jsxs("div",{className:"py-4 text-center text-sm text-gray-500",children:["No ",c," fields found"]}),e.jsx("div",{className:"flex flex-col gap-1",children:S==null?void 0:S.map(R=>e.jsx("div",{children:B(R)},R.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function pa({ColumnsComponent:t,type:a}){var Te;const[n,r]=I.useState(!1),l=s.useEditorStore(ae=>ae.card),o=s.useEditorStore(ae=>ae.selectedConnectionId),c=s.useDashboardStore(ae=>ae.showFilters),i=s.useEditorStore(ae=>ae.selectedDatamodelId),d=s.useEditorStore(ae=>ae.selectedDatabaseName),u=s.useEditorStore(ae=>ae.selectedSchemaName),m=s.useEditorStore(ae=>ae.selectedTableName),h=s.useEditorStore(ae=>ae.isDevMode),{setSelectedTableName:f,setIsDevMode:g,setCardSql:j}=s.useEditorActions(),{connectionItems:p,modelItems:y,schemaItems:x,databaseItems:b,tableItems:k,columns:O,isConnectionsLoading:N,isModelsLoading:C,isConnectionsError:v,isModelsError:D,isDatabasesLoadingOrFetching:E,isDatabaseError:L,isSchemaLoadingOrFetching:w,isSchemaError:F,isColumnsError:S,isColumnsLoadingOrFetching:T,isTableLoadingOrFetching:A,isTableError:B,connectionType:M,isNonDbConnection:R,refetchDatabases:z,refetchModels:V,refetchSchemas:J,refetchTables:Z,refetchColumns:W,refetchConnections:q,handleConnectionChange:G,handleDatabaseChange:P,handleSchemaChange:_,handleDatamodelChange:U,handleTableChange:Y,tableName:X,schemaName:$}=s.useEditorAside(),{data:ee,refetch:te}=s.useDashboardCardQuery(l);function ie(){return t?t($,X,O):e.jsx(sl,{schemaName:$,tableName:X,columns:O,status:T?"Loading...":S?"Error":"Success"})}function K(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function Q(ae){ae===!0?ee&&(j(ee.userSql),setTimeout(()=>{te()},100)):j(""),g(ae)}function ne(){if(!o||M==="S3"||M==="API")return null;if(!i||i==="none")return e.jsx(Ke,{refetch:z,showNone:!0,onChange:P,isError:L,isLoading:E,items:b,value:d||"",title:"Database",type:"combobox"})}function de(){if(o&&!R&&(!d||d==="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 Fe(){if(!o||M==="S3"||M==="API")return null;if(!d||d==="none")return e.jsx(Ke,{refetch:V,showNone:!0,onChange:U,isError:D,isLoading:C,items:y,value:i||"",title:"Model",type:"combobox"})}function ke(){return!o||M==="S3"||M==="API"||!d||d==="none"?null:e.jsx(Ke,{refetch:J,onChange:_,isError:F,isLoading:w,items:x,value:u||"",title:"Schema",type:"combobox"})}function De(){function ae(){let he=!1;return M==="API"?(he=!1,he):((M==="S3"||o&&d&&d!=="none"&&u)&&(he=!0),he)}return ae()?e.jsx(Ke,{refetch:Z,onChange:Y,isError:B,items:k,isLoading:A,value:m||"",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]":!c}),children:[e.jsxs("section",{className:s.cn("px-4",{"px-4 pb-0 pt-4":n,"px-4 py-4":!n}),children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("h2",{className:"text-brand-100 font-semibold",children:"Direct Source"}),e.jsx(s.Button,{onClick:()=>r(!n),size:"sm",variant:"ghost",className:"h-6 w-6 p-0",children:n?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronUp,{className:"h-4 w-4"})})]}),!n&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ke,{refetch:q,items:p,title:"Connection",value:o||"",onChange:G,isLoading:N,isError:v,type:"combobox",connectionTooltip:((Te=p==null?void 0:p.find(ae=>ae.id===o))==null?void 0:Te.type)||""}),ne(),de(),Fe(),ke(),De()]})]}),ie(),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:h,onCheckedChange:Q,id:"dev-mode"}),e.jsx(s.Label,{htmlFor:"dev-mode",children:"Advanced Mode"})]}),e.jsxs(s.Button,{onClick:K,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(Ln,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function fa({error:t,className:a="",textClassName:n="",copyButtonClassName:r=""}){const[l,o]=I.useState(!1),c=I.useRef(null),i=I.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(f){(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),d())}function m(){const f=window.getSelection();if(f&&f.toString().trim()!==""){const g=f.toString();navigator.clipboard.writeText(g),o(!0),i.current=!0,setTimeout(()=>{o(!1),i.current=!1},1e3)}else i.current=!1}function h(){o(!1),i.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:d,onKeyDown:u,onMouseUp:m,onMouseDown:h,tabIndex:0,role:"button","aria-label":"Click to copy error message or select text to copy",children:t}),l&&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 ga({sql:t,error:a,onDebugWithAssistant:n}){const r=s.useEditorStore(d=>d.isDevMode),{setIsDevMode:l,setCardSql:o,setRunSql:c}=s.useEditorActions();function i(){l(!r),o(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(fa,{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:i,variant:"secondary",size:"sm",children:[e.jsx(fn,{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(Sn,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function ja({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(_t,{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(ga,{sql:t,error:a,onDebugWithAssistant:n})})]})}var ya={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Tt=I.createContext&&I.createContext(ya),tl=["attr","size","title"];function al(t,a){if(t==null)return{};var n=nl(t,a),r,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(l=0;l<o.length;l++)r=o[l],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function nl(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 vs(){return vs=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},vs.apply(this,arguments)}function Et(t,a){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);a&&(r=r.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,r)}return n}function bs(t){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Et(Object(n),!0).forEach(function(r){rl(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Et(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function rl(t,a,n){return a=ll(a),a in t?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,t}function ll(t){var a=ol(t,"string");return typeof a=="symbol"?a:a+""}function ol(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 va(t){return t&&t.map((a,n)=>I.createElement(a.tag,bs({key:n},a.attr),va(a.child)))}function $e(t){return a=>I.createElement(il,vs({attr:bs({},t.attr)},a),va(t.child))}function il(t){var a=n=>{var{attr:r,size:l,title:o}=t,c=al(t,tl),i=l||n.size||"1em",d;return n.className&&(d=n.className),t.className&&(d=(d?d+" ":"")+t.className),I.createElement("svg",vs({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,c,{className:d,style:bs(bs({color:t.color||n.color},n.style),t.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),o&&I.createElement("title",null,o),t.children)};return Tt!==void 0?I.createElement(Tt.Consumer,null,n=>a(n)):a(ya)}function cl(t){return $e({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 ba(t){const{theme:a}=s.useTheme(),n=s.useDashboardStore(p=>p.theme),r=s.useEditorStore(p=>p.frame),l=s.useEditorStore(p=>p.card),o=s.useEditorStore(p=>p.activeTabCardId),c=s.Le(),{refetch:i}=s.useDashboardCardQuery(l),{updateCardTab:d,setRunSql:u}=s.useEditorActions(),m=I.useRef(),h=I.useRef({}),f=r.cards.find(p=>p.id===o),g=I.useCallback(()=>{let p="";return t==="python"&&(p=(f==null?void 0:f.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(f==null?void 0:f.sql)||""),p},[t,f]);I.useEffect(()=>{if(o&&l.id&&l.id!==o){if(m.current&&c){const p=m.current.getModel();p&&(h.current[l.id]=p);let y=h.current[o];if(!y){const x=g();y=c.editor.createModel(x,t),h.current[o]=y}m.current.setModel(y)}d(o,l),u(!0)}},[o,l,d,c,u,t,g]),I.useEffect(()=>{if(!c)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=n==="system"?p:n;c.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[a,n,c]),I.useEffect(()=>{const p=m.current;p&&c&&l&&p.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return i(),!1})},[c,i,l]);function j(p,y){if(m.current=p,!h.current[l.id]){const x=p.getModel(),b=g();h.current[l.id]=x||(y==null?void 0:y.editor.createModel(b,t))||p.getModel()}p.setModel(h.current[l.id])}return{handleEditorDidMount:j}}function dl(){const t=s.useEditorStore(c=>c.card.sql),a=s.useEditorStore(c=>c.sqlGen),{setCardSql:n,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:l}=ba("sql");function o(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:o,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:l})]})}function ul(){const t=s.useEditorStore(l=>l.card.python),{setCardPython:a}=s.useEditorActions(),{handleEditorDidMount:n}=ba("python");function r(l){a(l)}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 ml({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 st({variant:t="outline"}){var c;const{setCardSql:a}=s.useEditorActions();s.useEditorStore(i=>i.frame);const n=s.useEditorStore(i=>i.card);Xs(((c=n.customCardPreferences)==null?void 0:c.url)||""),s.useEditorStore(i=>i.selectedSchemaName),s.useEditorStore(i=>i.selectedDatamodelId),s.useEditorStore(i=>i.selectedDatabaseName),s.useEditorStore(i=>i.selectedTableName),s.useEditorStore(i=>i.selectedConnectionId),s.useEditorStore(i=>i.isShowingVisual),n.sql;const r=s.useEditorStore(i=>i.onSave),{getUpdatedFrame:l}=Zs();function o(){const i=l();r==null||r(i)}return e.jsxs(s.Button,{onClick:o,className:"h-8",size:"sm",variant:t,children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function hl(){const t=s.useQueryClient(),[a,n]=I.useState(!1),r=s.useDashboardStore(u=>u.actions.setIsDashboardPanelOpen),{setIsVisualEditing:l}=s.useDashboardActions(),{getUpdatedFrame:o}=Zs(),c=s.useSelectedVisual(),i=br(),d=()=>{const u=o();if(!(c!=null&&c.id)){s.ue.error("No visual selected");return}n(!0),i.mutate({visualId:c.id,data:{frameObject:u}},{onSuccess:()=>{n(!1),l(!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:d,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(zs,{className:"mr-2 size-4 font-bold"}),"Save"]})]})}function tt(){const{setTempQueryData:t,setSqlGen:a}=s.useEditorActions(),n=s.useQueryClient(),r=s.useEditorStore(d=>d.tempQueryData),l=s.useEditorStore(d=>d.onClose),o=s.useEditorStore(d=>d.card),{queryKey:c}=s.useDashboardCardQuery(o);function i(){if(r){const{queryKey:d,queryData:u}=r;d&&u&&n.setQueryData(d,u)}a({}),l==null||l()}return e.jsxs(s.Button,{onClick:i,className:"h-8",size:"sm",variant:"outline",children:[e.jsx(s.X,{className:"mr-2 size-4"}),"Close"]})}function ws(){const{setTempQueryData:t}=s.useEditorActions(),a=s.useQueryClient(),n=s.useEditorStore(y=>y.isDevMode),r=s.useEditorStore(y=>y.tempQueryData),l=s.useEditorStore(y=>y.card),{queryKey:o}=s.useDashboardCardQuery(l),{setCardSql:c,setSqlGen:i,setCardPython:d,setCardCustomCfg:u,setCardPreferences:m,updateDataSource:h,clearQueryConfig:f,setCardConfig:g,setCardType:j}=s.useEditorActions();function p(){const y=a.getQueryData(o);r!=null&&r.queryData||t({queryKey:o,queryData:y}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),n&&h(s.EMPTY_DATA_SOURCE),c(""),i({}),f(),g(void 0),d(""),u(""),m({}),j("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 xl(){const t=s.useQueryClient(),[a,n]=I.useState(!1),[r,l]=I.useState(!1);s.useEditorStore(V=>V.frame);const o=s.useEditorStore(V=>V.card);s.useEditorStore(V=>V.isShowingVisual),s.useEditorStore(V=>V.selectedConnectionId),s.useEditorStore(V=>V.tempQueryData),s.useEditorStore(V=>V.selectedDatabaseName),s.useEditorStore(V=>V.selectedDatamodelId),s.useEditorStore(V=>V.selectedSchemaName);const c=s.useEditorStore(V=>V.showAIDialog);s.useEditorStore(V=>V.selectedTableName);const i=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.sql}),d=s.useEditorStore(V=>{var J;return(J=V==null?void 0:V.card)==null?void 0:J.python}),{sheetFilterValues:u}=s.useSheetFilterValues(),{setCardCustomCfg:m,setQueryResultColumns:h,setCardSql:f,setTempQueryData:g,setPythonStdOut:j,setCardPreferences:p,setCardType:y,setCardPython:x,runAssistant:b,setShowAIDialog:k}=s.useEditorActions();s.useEditorStore(V=>V.onSave),s.useEditorStore(V=>V.onClose),s.useEditorStore(V=>V.actions.setSqlGen);const O=s.useEditorStore(V=>V.runSql),N=s.useEditorStore(V=>V.actions.setRunSql),C=s.useEditorStore(V=>V.actions.setIsSqlRunning),{data:v,isLoading:D,isFetching:E,isSuccess:L,isError:w,error:F,queryKey:S,refetch:T,errorMessage:A}=s.useDashboardCardQuery(o);I.useEffect(()=>{if(v&&(v.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),j((v==null?void 0:v.output)||""),v.records.length>0)){const{dimensionKeys:V}=s.getKeys(v.records);h(V)}},[v,h,j]),I.useEffect(()=>{(D||E)&&C(!0),(w||L)&&C(!1),w&&(h([]),j(""))},[D,E,v,j,w,L,C,h,F]),I.useEffect(()=>{O&&(t.getQueryData(S)||T(),N(!1))},[O,T,N,S,t]);async function B(){const V=`Can you help me debug this query in the current table scope?
|
|
402
|
-
|
|
403
|
-
Error:
|
|
404
|
-
|
|
405
|
-
${A}
|
|
406
|
-
|
|
407
|
-
Query:
|
|
408
|
-
|
|
409
|
-
${i}
|
|
410
|
-
|
|
411
|
-
${d?`Python:
|
|
412
|
-
${d}`:""}
|
|
413
|
-
`;b(V)}function M(){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(ml,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!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 R(){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(dl,{})}),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(ul,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function z(){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||E,onClick:()=>{T()},className:"h-8 shrink-0",size:"sm",children:[D||E?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(ja,{sql:v==null?void 0:v.sql,error:A,onDebugWithAssistant:B}),e.jsx(ws,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:V=>n(V),className:"h-8",size:"sm",variant:"outline",children:e.jsx(cl,{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(tt,{}),e.jsx(st,{})]})]})}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:[R(),M()]}),z()]})}function pl({card:t}){var b,k,O,N,C,v,D,E,L,w,F;const[a,n]=I.useState(!1),[r,l]=I.useState([]),{authToken:o}=s.useSemaphorContext(),c=s.getTokenParams(o==null?void 0:o.accessToken),i=s.useDashboardStore(S=>S.themeStyle),d={colors:((k=(b=i==null?void 0:i.chart)==null?void 0:b.dataset)==null?void 0:k.backgroundColor)||[]};(O=t.customCardPreferences)!=null&&O.inputData;const{getCard:u}=s.useCustomVisual(((N=t.customCardPreferences)==null?void 0:N.url)||""),m=((C=t.customCardPreferences)==null?void 0:C.visualType)||"single",h=s.useEditorStore(S=>S.frame),{setCustomCardPreferences:f}=s.useEditorActions(),{data:g}=s.useDashboardCardQuery(t),j=I.useCallback((S,T)=>{l(A=>({...A,[S]:T}))},[]);if(!((v=t.customCardPreferences)!=null&&v.componentName))return null;const p=u((D=t.customCardPreferences)==null?void 0:D.componentName);function y(S){n(S)}const x=Object.keys(((E=t.customCardPreferences)==null?void 0:E.dataInputCardIds)||{}).map(S=>{var B,M,R;const T=(M=(B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:M[S].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(z=>z.id===T);return A||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(I.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&m==="single"&&e.jsx(p,{editing:!0,params:c,theme:d,settings:(L=t.customCardPreferences)==null?void 0:L.settings,onDataChange:j,data:(g==null?void 0:g.records)||[]}),p&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((w=t.customCardPreferences)==null?void 0:w.dataInputCardIds)||{}).map(S=>{var B,M,R;const T=(M=(B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:M[S].cardId,A=(R=h==null?void 0:h.cards)==null?void 0:R.find(z=>z.id===T);if(A)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:y,onDataChange:j,dataInputIndex:S,card:A},A.id+S)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:d,onDataChange:j,settings:x.map(S=>{var T;return(T=S==null?void 0:S.customCardPreferences)==null?void 0:T.settings}),data:x.map(S=>S!=null&&S.id?r==null?void 0:r[S.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function Na({className:t,...a}){var E;const n=s.useEditorStore(L=>L.card),r=s.isExplorerCard(n),l=((E=n.customCardPreferences)==null?void 0:E.showCardHeader)??!0,o=s.useEditorStore(L=>L.frame),c=s.useDashboardStore(L=>L.dashboard.filters),i=s.useEditorStore(L=>L.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),u=c==null?void 0:c.find(L=>L.id===o.filterId),{data:m,isLoading:h,isFetching:f,errorMessage:g,pagination:j,refetch:p}=s.useDashboardCardQuery(n),{setCard:y,updateCardInFrame:x}=s.useEditorActions(),{data:b}=s.useTopoJson(n),k=I.useMemo(()=>{var L;return n.type!=="pivotTable"||!((L=m==null?void 0:m.records)!=null&&L.length)?null:{records:m.records,columnSubtotalMeta:m.columnSubtotalMeta,subtotalColumns:m.subtotalColumns||[],pivotSchema:m.pivotSchema||[],groupByColumns:m.groupByColumns}},[n,m==null?void 0:m.records,m==null?void 0:m.columnSubtotalMeta,m==null?void 0:m.subtotalColumns,m==null?void 0:m.pivotSchema,m==null?void 0:m.groupByColumns]),O=s.usePivotTableConfig(n,k),N=(L,w)=>{var S,T;const F={...n,paginationConfig:{page:L+1,pageSize:w}};y(F),x(F),n.sql&&((T=(S=n.preferences)==null?void 0:S.tablePrefs)!=null&&T.enableDevModePagination)&&i(!0)},C=I.useMemo(()=>!n.id||!(m!=null&&m.records)?null:s.createChartConfig({card:n,data:m==null?void 0:m.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:b}),[n.id,m==null?void 0:m.records,n.type,n.queryConfig,n.customCfg,n.preferences,b]);function v(L){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(pl,{card:L})})}function D(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!h&&!f)return g?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||f)&&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 v(n);if(!["table","pivotTable","aggregateTable","custom"].includes(n.type)&&C)return e.jsx(e.Fragment,{children:h||f?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:C})});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:(m==null?void 0:m.records)||[],paginationMetadata:j,onPaginationChange:N,isLoading:h||f})});if(n.type==="pivotTable"&&O)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:O.data,options:O.options,onAggregationChange:L=>{const w=s.handleAggregationChange(L,n.config),F={...n,config:w};y(F),x(F)},onAggregationLabelChange:L=>{const w=s.handleAggregationLabelChange(L,n.config),F={...n,config:w};y(F),x(F)}})});if(n.type==="aggregateTable")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.AggregateTable,{card:n,data:(m==null?void 0:m.records)||[],groupByColumns:m==null?void 0:m.groupByColumns,pivotSchema:m==null?void 0:m.pivotSchema,paginationMetadata:j,onPaginationChange:N,onAggregationChange:L=>{const w=s.handleAggregationChange(L,n.config),F={...n,config:w};y(F),x(F)},isLoading:h||f})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[l&&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:L=>y({...n,title:L}),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:L=>y({...n,description:L}),children:e.jsx(s.CardDescription,{children:n.description||"Add description"})},n.description)]}),u&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{enabled:!0,className:"my-1",text:u.title||u.column,onSave:L=>d({...u,title:L}),children:e.jsx(s.Label,{children:u.title})}),e.jsx(s.FilterComponent,{filter:u})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:D()})]})}const Rs=({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}),fl=()=>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."})]})]}),gl=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:l})=>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(Rs,{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(Rs,{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(Rs,{language:"javascript",value:t,onChange:l})})]}),jl=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:l})=>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:l,variant:"outline",children:"Close"})]});function yl(){const[t,a]=I.useState(!1),[n,r]=I.useState(""),[l,o]=I.useState(""),[c,i]=I.useState(""),[d,u]=I.useState(""),m=s.useEditorStore(N=>N.card),h=s.useEditorStore(N=>N.card.customCfg),f=h?JSON.stringify(h,null,2):"",{data:g}=s.useDashboardCardQuery(m),{data:j}=s.useTopoJson(m),{setCardCustomCfg:p,setCustomVisualCode:y}=s.useEditorActions(),x=N=>{var C,v;return JSON.stringify({...N,data:{...N.data,datasets:(v=(C=N.data)==null?void 0:C.datasets)==null?void 0:v.map(D=>({...D,data:[]}))}},null,2)},b=()=>{var C,v;if(!((C=g==null?void 0:g.records)!=null&&C.length))return;const N=s.createChartConfig({card:m,data:g.records,cardType:m.type,queryConfig:m.queryConfig,preferences:m.preferences,topoJson:j});if(N){r(x(N)),i(((v=m.preferences)==null?void 0:v.customVisualCode)||"");const D=s.merge(N,h);o(x(D))}},k=()=>{try{if(c&&y(c),l){const N=JSON.parse(l),C=s.getObjectDiff(JSON.parse(n),N);p(C),u("")}}catch{u("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:b,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(fl,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Na,{className:"w-1/2 rounded shadow-none"})}),e.jsx(gl,{customCode:c,cardCustomCfgString:f,mergedConfig:l,onConfigChange:N=>o(N??""),onCodeChange:N=>i(N??"")})]}),e.jsx(jl,{error:d,hasCardCustomConfig:!!h,onReset:()=>{o(n),p(null)},onApply:k,onClose:()=>a(!1)})]})]})}function ks(t){const[a,n]=I.useState(null);return a}function Ca(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:l}=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:l}}function Sa(){const{data:t,isLoading:a,isError:n}=Ca(),r=s.useQueries({queries:((t==null?void 0:t.plugins)||[]).map(i=>({queryKey:["manifest",i.value],queryFn:()=>s.loadManifest(i.value),enabled:!!i.value,staleTime:5*60*1e3,gcTime:10*60*1e3,retry:2,retryDelay:d=>Math.min(1e3*2**d,3e4)}))}),l=[];let o=a,c=n;return r.forEach((i,d)=>{var u;if(i.isLoading&&(o=!0),i.isError&&(c=!0),i.data&&((u=t==null?void 0:t.plugins)!=null&&u[d])){const m=t.plugins[d],h=i.data.visuals.map(f=>({name:f.name,pluginName:m.label,componentType:f.componentType,pluginType:m.type,icon:f.icon,chartType:f.chartType,url:m.value}));l.push(...h)}}),{data:l,isLoading:o,isError:c}}function vl({onChartTypeChange:t}){const{setCardCustomCfg:a,setCardPreferences:n,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=Sa(),d=I.useCallback((u,m)=>{a(null),n({}),r(u),m&&l({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),t==null||t()},[a,n,r,l,t]);return c?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading custom visuals..."})})]}):i?e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:e.jsx("div",{className:"text-sm text-destructive",children:"Failed to load custom visuals"})})]}):!o||o.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:o.map((u,m)=>e.jsx(bl,{text:u.name,onClick:()=>d("custom",u),icon:u.icon},`${u.url}-${u.name}-${m}`))})]})}const bl=({text:t,icon:a,onClick:n})=>{const r=ks(),l=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):l})};function at(t){return $e({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 Nl(t){return $e({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 nt(t){return $e({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 rt(t){return $e({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 lt(t){return $e({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 ot(t){return $e({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 wa({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(m,h){o(null),r({}),n(m),["custom","text","map"].includes(m)&&(l(!0),i(void 0)),t==null||t()}const u=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(s.IconButton,{openDelay:u,tooltip:"Table",onClick:()=>d("table"),className:"h-10 p-4",children:e.jsx(Qe,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bar Chart",onClick:()=>d("bar"),className:"h-10 p-4",children:e.jsx(Ns,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Line Chart",onClick:()=>d("line"),className:"h-10 p-4",children:e.jsx(Cs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Bar Chart",onClick:()=>d("stackedBar"),className:"h-10 p-4",children:e.jsx(qs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Stacked Line Chart",onClick:()=>d("stackedLine"),className:"h-10 p-4",children:e.jsx(lt,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Scatter Chart",onClick:()=>d("scatter"),className:"h-10 p-4",children:e.jsx(Gs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Bubble Chart",onClick:()=>d("bubble"),className:"h-10 p-4",children:e.jsx(nt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Pie Chart",onClick:()=>d("pie"),className:"h-10 p-4",children:e.jsx(Ss,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Doughnut Chart",onClick:()=>d("doughnut"),className:"h-10 p-4",children:e.jsx(Hs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Funnel Chart",onClick:()=>d("funnel"),className:"h-10 p-4",children:e.jsx(rt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Radar Chart",onClick:()=>d("radar"),className:"h-10 p-4",children:e.jsx(Qs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Polar Area Chart",onClick:()=>d("polarArea"),className:"h-10 p-4",children:e.jsx(at,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Tornado Chart",onClick:()=>d("tornado"),className:"h-10 p-4",children:e.jsx(Ws,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>d("range"),className:"h-10 p-4",children:e.jsx(Ys,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"KPI",onClick:()=>d("kpi"),className:"h-10 p-4",children:e.jsx(ot,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Text",onClick:()=>d("text"),className:"h-10 p-4",children:e.jsx(zt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(Ks,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:u,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(ts,{className:s.cn("size-5",a)})})]})}function Cl({chartType:t,className:a,customIcon:n,componentName:r}){const l=ks();switch(t){case"bar":return e.jsx(Ns,{className:a});case"line":return e.jsx(Cs,{className:a});case"pie":return e.jsx(Ss,{className:a});case"radar":return e.jsx(Qs,{className:a});case"scatter":return e.jsx(Gs,{className:a});case"bubble":return e.jsx(nt,{className:a});case"doughnut":return e.jsx(Hs,{className:a});case"stackedBar":return e.jsx(qs,{className:a});case"stackedLine":return e.jsx(lt,{className:a});case"polarArea":return e.jsx(at,{className:a});case"funnel":return e.jsx(rt,{className:a});case"tornado":case"pyramid":return e.jsx(Ws,{className:a});case"range":return e.jsx(Ys,{className:a});case"kpi":return e.jsx(ot,{className:a});case"text":return e.jsx(ge,{className:a});case"map":return e.jsx(Ks,{className:a});case"custom":return n&&l?e.jsx(l,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(ts,{className:a});default:return e.jsx(Qe,{className:a})}}function ka({variant:t="ghost"}){var o,c;const[a,n]=I.useState(!1),r=s.useEditorStore(i=>i.card),l=r.type;return s.useDashboardStore(i=>i.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(Cl,{className:"size-4",chartType:l,customIcon:(o=r.customCardPreferences)==null?void 0:o.icon,componentName:(c=r.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:i=>i.preventDefault(),className:"w-72 p-1",children:[e.jsx(wa,{onChartTypeChange:()=>n(!1)}),e.jsx(vl,{onChartTypeChange:()=>n(!1)})]})]})}function Sl(){const t=s.useEditorStore(o=>{var c,i;return(i=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:i.indexAxis}),a=s.useEditorStore(o=>o.card.type),{setChartOrientation:n}=s.useEditorStore(o=>o.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(Nt,{className:"size-4"}):e.jsx(bt,{className:"size-4"})})}function l(){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(Nt,{className:"size-4"}):e.jsx(bt,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?l():r()})}function Da(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.isShowingVisual),n=s.useEditorStore(c=>{var i,d;return(d=(i=c.card)==null?void 0:i.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:l}=s.useEditorActions();function o(){const c=["xy","none","x","y"],d=(c.indexOf(r)+1)%c.length;l(c[d])}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(Sl,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsx(e.Fragment,{}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:o,children:[(r==="xy"||!r)&&e.jsx(Cn,{className:"size-4"}),r==="x"&&e.jsx(un,{className:"size-4"}),r==="y"&&e.jsx(zn,{className:"size-4"}),r==="none"&&e.jsx($n,{className:"size-4"})]})]}):null}function wl(){const t=s.useEditorStore(j=>j.frame),a=s.useEditorStore(j=>j.card),{setFrame:n,setActiveTabCardId:r,setCard:l,updateCardInFrame:o}=s.useEditorActions(),c=(j,p)=>{j.dataTransfer.setData("tabIndex",p.toString())},i=j=>{j.preventDefault()},d=(j,p)=>{const y=j.dataTransfer.getData("tabIndex");if(y===p.toString())return;const x=Array.from(t.cards),[b]=x.splice(parseInt(y),1);x.splice(p,0,b),n({...t,cards:x})};function u(j){const p=t.cards.filter(b=>b.id!==j),y=p[0],x={...t,cards:p,activeCardId:y.id};n(x),r(y.id),l(y)}function m(j,p){const y={...t,cards:[...t.cards,p],activeCardId:j.id};n(y),r(p.id)}function h(){const j={...a,id:s.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};m(a,j)}function f(j){const p={dataSource:j.dataSource,connectionId:j.connectionId,lastSelectedDatabase:j.lastSelectedDatabase,lastSelectedSchema:j.lastSelectedSchema,lastSelectedTable:j.lastSelectedTable,lastSelectedDatamodelId:j.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};m(j,p)}function g(j,p){return j.cards.length===1&&(p.displayTab===!0||p.displayTab===void 0)||j.activeCardId!==p.id&&(p.displayTab===!0||p.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const y=p.displayTab===void 0?!1:!p.displayTab;l({...p,displayTab:y}),o({...p,displayTab:y})},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(pn,{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((j,p)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:y=>c(y,p),onDragOver:i,onDrop:y=>d(y,p),className:"",value:j.id,children:[g(t,j),e.jsx(s.Editable,{enabled:t.activeCardId===j.id,text:j.tabTitle||j.title,onSave:y=>{l({...a,tabTitle:y}),o({...a,tabTitle:y})},children:j.tabTitle||j.title},j.id),t.activeCardId===j.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(j.id)})]},j.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>f(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(hn,{className:"h-4 w-4"})})]})})}function Ta(){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:l,setActiveTabCardId:o,setCard:c,setIsDevMode:i,setRunSql:d}=s.useEditorActions(),{data:u,isLoading:m,isFetching:h}=s.useDashboardCardQuery(a);function f(p){const y=t.cards.find(x=>x.id===p);if(y!=null&&y.sql){r||i(!0),o(p);return}if(y!=null&&y.queryConfig){r&&i(!1),g(p),o(p);return}r||g(p),o(p)}function g(p){const y={...t,cards:t.cards.map(b=>b.id===a.id?a:b),activeCardId:p};l(y);const x=y.cards.find(b=>b.id===p);x.sql&&d(!0),c(x)}function j(){return a.type==="kpi"?m||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:u==null?void 0:u.records,isPending:m||h})})}):a.type==="text"?m||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:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Na,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:f,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:j()},p.id)),e.jsx(wl,{})]})}function ds({children:t}){var O,N;s.useEditorStore(C=>C.frame);const a=s.useEditorStore(C=>C.card),n=s.useEditorStore(C=>C.isDevMode),r=s.useEditorStore(C=>C.isShowingVisual),l=s.useDashboardStore(C=>C.isVisualEditing),o=s.useEditorStore(C=>C.pythonStdOut);s.useEditorStore(C=>C.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:u,setIsDevMode:m,setCardPreferences:h}=s.useEditorActions(),{data:f,isLoading:g,isFetching:j,errorMessage:p,refetch:y}=s.useDashboardCardQuery(a);function x(){const C=JSON.stringify(f==null?void 0:f.records,null,2),v=new Blob([C],{type:"application/json"}),D=URL.createObjectURL(v),E=document.createElement("a");E.href=D,E.download=`${a.title}.json`,E.click()}function b(){const v=[Object.keys(f==null?void 0:f.records.reduce((w,F)=>({...w,...F}),{})).join(","),...((f==null?void 0:f.records)||[]).map(w=>Object.values(w).join(","))].join(`
|
|
414
|
-
`),D=new Blob([v],{type:"text/csv"}),E=URL.createObjectURL(D),L=document.createElement("a");L.href=E,L.download=`${a.title}.csv`,L.click()}function k(){const C=`Can you get the documentation for ${a.type} chart?`;u(C)}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(ka,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:k,children:e.jsx(rn,{className:"size-4"})}),!["table","custom"].includes(a.type)&&l&&e.jsx(yl,{})]}),!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:b,children:e.jsx(Nl,{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:x,children:e.jsx(gn,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(f==null?void 0:f.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(Da,{})]}),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:((N=(O=a.preferences)==null?void 0:O.tablePrefs)==null?void 0:N.enableDevModePagination)??!1,onCheckedChange:C=>{var v;h({...a.preferences,tablePrefs:{...(v=a.preferences)==null?void 0:v.tablePrefs,enableDevModePagination:C}}),y()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),n&&e.jsx(Dl,{})]}),r?e.jsx(Ta,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&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:o&&e.jsx(kl,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:s.cn("relative flex h-full min-h-0 w-full flex-1 basis-0",{"px-6":o}),children:[(f==null?void 0:f.records)&&(f==null?void 0:f.records.length)>0&&e.jsx(s.TableVisual,{card:a,data:(f==null?void 0:f.records)||[]}),p&&e.jsx(fa,{error:p})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function kl(){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",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Dl(){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 Tl(){var p,y;const t=s.useEditorStore(x=>x.card.customCardPreferences),{data:a}=Ca(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(x=>x.card),l=s.useEditorStore(x=>x.frame),o=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:i,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(p=d==null?void 0:d.visuals)==null?void 0:p.find(x=>x.name===(t==null?void 0:t.componentName));function m(x,b){if(!t)return;const O={...(t==null?void 0:t.dataInputCardIds)||{},[x]:{cardId:b,hookRef:null}};c({...t,dataInputCardIds:O})}function h(x){var k,O;const b=(k=l==null?void 0:l.cards)==null?void 0:k.filter(N=>{var C;return((C=N==null?void 0:N.customCardPreferences)==null?void 0:C.visualType)!=="multiple"}).map(N=>({value:N.id,label:N.tabTitle||N.title}));return e.jsx("div",{className:"space-y-2",children:(O=x==null?void 0:x.dataInputs)==null?void 0:O.map((N,C)=>{var v,D;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:N}),e.jsx(fe,{className:"col-span-6 h-8 w-full justify-between",label:"",options:b||[],value:((D=(v=t==null?void 0:t.dataInputCardIds)==null?void 0:v[C])==null?void 0:D.cardId)||"",onValueChange:E=>m(C,E)})]},C+Math.random())})})}function f(x,b,k=[],O=""){var N,C;return t?x==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((N=t==null?void 0:t.settings)==null?void 0:N[b])||O,onChange:v=>{c({...t,settings:{...t==null?void 0:t.settings,[b]:v.target.value}})}},b):x==="select"?e.jsx(fe,{className:"h-8 w-full",label:"",options:k,value:((C=t==null?void 0:t.settings)==null?void 0:C[b])||O,onValueChange:v=>{c({...t,settings:{...t==null?void 0:t.settings,[b]:v}})}}):null:null}function g(x){const b=Object.entries((x==null?void 0:x.settings)||{});return e.jsx("div",{className:"space-y-3",children:b.map(([k,O])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:O.title}),f(O.ui,k,O.options,O.defaultValue)]},k))})}function j(x){t&&c({...t,visualType:x,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(fe,{icon:e.jsx(nn,{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:x=>c({...t||{url:"",componentName:""},url:x})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:o,onValueChange:j,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:i&&e.jsx(fe,{icon:e.jsx(mn,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(x=>x.type===o).map(x=>({value:x.name,label:x.name})))||[],value:t.componentName,onValueChange:x=>{console.log("changing value",x),c({...t,componentName:x})}})})]})})]}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[u&&u.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:h(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:g(u)})})]})]})]})}function qe(){const[t,a]=I.useState([]),n=s.useEditorStore(u=>u.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:l}=s.useEditorStore(u=>u.actions),o=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var m;return(m=u.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),I.useEffect(()=>{o&&a(new Array(o.length).fill(!1))},[o]);function c(u,m){var h,f;m?n!=null&&n.onClickFilter&&((h=n==null?void 0:n.onClickFilter)==null?void 0:h.length)>0?l({...n,onClickFilter:[...n.onClickFilter,{columnIndex:u,expression:""}]}):l({...n,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(g=>g.columnIndex!==u)}),a(g=>{const j=[...g];return j[u]=!1,j}))}function i(u,m){var f;const h=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(g=>g.columnIndex===u?{...g,expression:m.target.value}:g);l({...n,onClickFilter:h})}function d(u){var m,h,f,g;if(t!=null&&t[u]||(h=(m=n==null?void 0:n.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===u))!=null&&h.expression)return e.jsx(s.Input,{value:(g=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(j=>j.columnIndex===u))==null?void 0:g.expression,onChange:j=>i(u,j),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"}),o==null?void 0:o.map((u,m)=>{var h,f;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(g=>g.columnIndex===m)),onCheckedChange:g=>c(m,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(g=>g.columnIndex===m))&&e.jsx(s.Pencil,{onClick:()=>{a(g=>{const j=[...g];return j[m]=!g[m],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(m)]})},u)})]})}function El({idx:t}){var i;const a=s.useEditorStore(d=>{var u;return(u=d.card)==null?void 0:u.preferences}),n=s.useEditorStore(d=>{var u;return(u=d.card.preferences)==null?void 0:u.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),l=(i=a==null?void 0:a.chartOptions)==null?void 0:i.indexAxis,o=n==null?void 0:n.find(d=>d.idx===t);function c(d,u){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const m={display:d!=="none",align:d,anchor:d,clamp:!0};if(!o)r({...a,datasetOptions:[...n||[],{idx:u,datalabels:m}]});else{const h={...o};h.datalabels=m;const f=n==null?void 0:n.map(g=>g.idx===u?h:g);r({...a,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Gt,{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(Dn,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>c("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(En,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})}),e.jsx("button",{onClick:()=>c("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Tn,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function Il(){const t=s.useEditorStore(o=>o.card),{data:a}=s.useDashboardCardQuery(t),{keys:n}=s.getKeys((a==null?void 0:a.records)||[]),r=n.slice(1).filter(o=>!s.METADATA_KEYS.includes(o));let l=r;if(["stackedBar","stackedLine"].includes(t.type)){const o=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:n[0],pivotKey:n[1],valueKey:n[2]}),{keys:c}=s.getKeys(o);l=c.slice(1)}return{transformedMetricKeys:l,dimensionKeys:n.slice(0,1),keys:n,defaultMetricKeys:r}}function Ds({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 Ea(){const t=s.useEditorStore(d=>d.card),a=s.useEditorStore(d=>{var u,m,h;return(h=(m=(u=d==null?void 0:d.card)==null?void 0:u.preferences)==null?void 0:m.chartOptions)==null?void 0:h.indexAxis}),{data:n}=s.useDashboardCardQuery(t),r=a==="y"?"Metric":"Dimension",l=a==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:c,keys:i}=Il();return i.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:o.map(d=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:d,children:Ia(d)},d))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:l}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:c.map((d,u)=>e.jsx(Aa,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:d,idx:u},d))})]})]})}function Ia(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function Aa({col:t,idx:a,className:n,iconClassName:r,children:l}){const o=s.useEditorStore(m=>{var h;return(h=m.card)==null?void 0:h.preferences}),c=s.useEditorStore(m=>{var h,f;return(f=(h=m.card)==null?void 0:h.preferences)==null?void 0:f.datasetOptions}),i=c==null?void 0:c.find(m=>m.idx===a),{setCardPreferences:d}=s.useEditorStore(m=>m.actions);function u(m){if(!i)d({...o,datasetOptions:[...c||[],{idx:a,type:m==="area"?"line":m,fill:m==="area"?"origin":""}]});else{const h={...i};h.type=m==="area"?"line":m,h.fill=m==="area"?"origin":"";const f=c==null?void 0:c.map(g=>g.idx===a?h:g);d({...o,datasetOptions:f})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[l||e.jsx(Ds,{className:"max-w-[100px]",title:t,children:Ia(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ns,{onClick:()=>u("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Cs,{onClick:()=>u("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Vt,{onClick:()=>u("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(El,{idx:a})]})]})}function it(){const t=s.useEditorStore(g=>g.selectedConnectionId),a=s.useEditorStore(g=>g.selectedDatamodelId),n=s.useEditorStore(g=>g.selectedDatabaseName),r=s.useEditorStore(g=>g.selectedSchemaName),l=s.useEditorStore(g=>g.selectedTableName),o=s.useDashboardStore(g=>g.dashboard.filters)||[],c=s.useDashboardStore(g=>g.actions.addFilter),i=s.useDashboardStore(g=>g.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:u,tableName:m,connectionType:h}=s.useEditorAside();function f(g,j="dashboard",p){var D;const y=s.fmt(g.column_name),x=s.fmt(n||""),b=s.fmt(r||""),k=s.fmt(m);let O=s.getQualifiedTableName({schemaName:b,tableName:k,connectionType:h,databaseName:x}),N=`${O}.${y}`;const C=(D=u==null?void 0:u.find(E=>E.id===a))==null?void 0:D.name;a&&a!=="none"&&(N=`${s.DATAMODEL_NAMESPCACE}.${C}.${y}`,O=`${s.DATAMODEL_NAMESPCACE}.${C}`),p!=null&&p.qualifiedFieldName&&(N=p.qualifiedFieldName),p!=null&&p.entityName&&(O=p.entityName);const v=o==null?void 0:o.find(E=>E.column===N&&E.table===k&&(E.database===x||E.database===n));if(v)d(v.id),i(v.id);else{const E=s.v4();return m==="api"&&t?(c({location:j,id:E,column:N,title:g.column_name,dataType:g.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(g.data_type,O,y)}),E):(c({id:E,location:j,column:N,title:g.column_name,dataType:g.data_type,table:l||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(g.data_type,O,y)}),E)}}return{assignFilter:f}}function Je(){const t=s.useDashboardStore(i=>i.dashboard.filters),a=s.useEditorStore(i=>i.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=it();function o(i){const d=l(i,"frame");n({...a,filterId:d})}const c=t==null?void 0:t.find(i=>i.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Al,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function Al({columns:t,onSelect:a}){var c;const[n,r]=xe.useState(!1),[l,o]=xe.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:[l?(c=t.find(i=>i.column_name===l))==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(i=>e.jsxs(s.CommandItem,{value:i.column_name,onSelect:d=>{const u=d===l?"":d;o(u),r(!1),u&&a(i)},children:[i.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",l===i.column_name?"opacity-100":"opacity-0")})]},i.column_name))})]})]})})]})}function Ml({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(Ea,{})})]}),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(qe,{}),e.jsx(Je,{})]})]})]})})}function Ll({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:o=>o.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-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(qe,{}),e.jsx(Je,{})]})]})]})})}function Ma(){const t=s.useEditorStore(i=>i.card.type),a=s.useEditorStore(i=>i.isDevMode),n=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:r}=s.useEditorStore(i=>i.actions);function l(i){var m;const d={datalabels:{display:i!=="none",align:i,anchor:i,clamp:!0}},u={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(m=n==null?void 0:n.chartOptions)==null?void 0:m.plugins,...d}}};r(u)}function o(){var i,d,u;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((u=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,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 i,d,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:u.anchor)||"none",onValueChange:l,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?o():c()})}const Rl={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ol={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Fl(){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:Bl(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ma,{}),e.jsx(qe,{}),e.jsx(Je,{})]})]})}function Bl(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(Rl,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(Ol,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 Pl(){var m,h,f,g,j;const t=s.useEditorStore(p=>p.card.preferences),a=s.useEditorStore(p=>p.actions.setCardPreferences),n=s.useEditorStore(p=>p.card),r=s.isExplorerCard(n),l=s.useEditorStore(p=>p.actions.setNumberFormat);s.useEditorStore(p=>{var y,x;return(x=(y=p.card.preferences)==null?void 0:y.formatNumber)==null?void 0:x.decimalPlaces});const o=s.useEditorStore(p=>{var y,x;return(x=(y=p.card.preferences)==null?void 0:y.formatNumber)==null?void 0:x.locale}),c=s.useEditorStore(p=>{var y,x;return(x=(y=p.card.preferences)==null?void 0:y.formatNumber)==null?void 0:x.currency});s.useEditorStore(p=>p.actions.setFilterOnClickField);const i=s.useEditorStore(p=>{var y,x;return(x=(y=p.card.preferences)==null?void 0:y.formatNumber)==null?void 0:x.colorRanges})||[],d=s.useEditorStore(p=>p.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(p=>p.currency))];return e.jsxs("div",{children:[!r&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((m=t==null?void 0:t.formatNumber)!=null&&m.enabled),onCheckedChange:p=>{a({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:p}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((h=t==null?void 0:t.formatNumber)==null?void 0:h.enabled)===!0||r)&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:o||"none",onValueChange:p=>{var y,x,b;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",p,((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 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:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"Auto"},"none"),s.LOCALE_CURRENCY_PAIRS.map(p=>e.jsx(s.SelectItem,{value:p.locale,children:p.locale},p.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:c||"none",onValueChange:p=>{var y,x,b;console.log("currency",p),l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,p==="none"?"":p,((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 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"},"none"),u.map(p=>e.jsx(s.SelectItem,{value:p,children:p},p))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((g=(f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:p=>{var y,x,b;return l(Number(p),((y=t==null?void 0:t.formatNumber)==null?void 0:y.currency)||"",((x=t==null?void 0:t.formatNumber)==null?void 0:x.locale)||"",((b=t==null?void 0:t.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(p=>e.jsx(s.SelectItem,{value:p,children:p},p))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((j=t==null?void 0:t.formatNumber)==null?void 0:j.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:p=>{var y,x,b;return l(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((x=t==null?void 0:t.formatNumber)==null?void 0:x.currency)||"",((b=t==null?void 0:t.formatNumber)==null?void 0:b.locale)||"",p.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:d})]})]})}function zl(){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(Pl,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Os({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 Vl=[{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"}],_l=["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"],Ul=_l.map(t=>({label:t,value:t}));function $l(){var d,u,m,h,f,g,j,p,y,x,b,k,O,N,C,v,D,E;const t=s.useEditorStore(L=>L.card),a=(u=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:u.topoJsonUrl,[n,r]=I.useState(((h=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:l}=s.useEditorActions(),{data:o}=s.useTopoJson(t),c=Object.keys((o==null?void 0:o.objects)||{}).map(L=>({label:L,value:L}))||[],i=[{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(Os,{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(Os,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(fe,{className:"h-9",options:i,onValueChange:L=>{console.log("value",L),l({...t.preferences,mapVisualOptions:{topoJsonUrl:L}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:L=>{r(L.target.value)},onBlur:()=>{var L;console.log("onBlur",n),l({...t.preferences,mapVisualOptions:{...(L=t.preferences)==null?void 0:L.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(fe,{className:"h-9",options:c,value:((g=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:g.objectKey)||"",label:"Map Object",onValueChange:L=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,objectKey:L}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(fe,{className:"h-9",options:Vl,value:((p=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:L=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projection:L}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(fe,{className:"h-9",options:Ul,value:((x=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:x.colorScale)||"",label:"Select Color Scale",onValueChange:L=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,colorScale:L}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Os,{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=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:k.projectionScale)||1,onChange:L=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(L.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((C=(N=(O=t.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:C[0])||0,onChange:L=>{var w,F,S,T;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(L.target.value),((T=(S=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:T[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((E=(D=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:E[1])||0,onChange:L=>{var w,F,S,T;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((T=(S=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:T[0])||0,Number(L.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(qe,{})]})}function ql(){var r;const t=s.useEditorStore(l=>l.card.preferences),{setCardPreferences:a}=s.useEditorStore(l=>l.actions);function n(l){a({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:l==="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 us({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:l=>l.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/docs/charts/${r}`,children:"example"})," in the docs."]})]})})]}),t==="text"&&e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2 py-4",children:e.jsx(ql,{})})]}),!["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(qe,{}),e.jsx(Je,{})]})]})]})})}function Yl(){const t=s.useEditorStore(r=>{var l,o;return(o=(l=r==null?void 0:r.card)==null?void 0:l.preferences)==null?void 0:o.sortChart}),{setSortChart:a}=s.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(fe,{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(Ea,{})]})]}),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(qe,{}),e.jsx(Je,{})]})]})]})})}function Gl({cardType:t="table"}){console.log("cardType",t);const a=s.useEditorStore(l=>{var o;return(o=l.card)==null?void 0:o.preferences}),n=s.useEditorStore(l=>l.actions.setCardPreferences),r=l=>{n({...a,allowDownload:l})};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(qe,{}),e.jsx(Je,{})]})]})}),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"})]})]})}function La({color:t,onColorChange:a,onClose:n}){const[r,l]=I.useState(0),[o,c]=I.useState(100),[i,d]=I.useState(50),[u,m]=I.useState(t);I.useEffect(()=>{const y=It(t);if(y){const x=At(y.r,y.g,y.b);l(x.h),c(x.s),d(x.l),m(t)}},[t]);const h=y=>{l(y),g(y,o,i)},f=y=>{const x=y.currentTarget.getBoundingClientRect(),b=Math.max(0,Math.min(1,(y.clientX-x.left)/x.width)),k=Math.max(0,Math.min(1,(y.clientY-x.top)/x.height)),O=b*100,N=(1-k)*100;c(O),d(N),g(r,O,N)},g=(y,x,b)=>{const k=Kl(y,x,b),O=Hl(k.r,k.g,k.b);m(O)},j=y=>{if(m(y),/^#[0-9A-Fa-f]{6}$/.test(y)){const x=It(y);if(x){const b=At(x.r,x.g,x.b);l(b.h),c(b.s),d(b.l)}}},p=()=>{/^#[0-9A-Fa-f]{6}$/.test(u)&&(a(u),n())};return e.jsxs("div",{className:"p-4 space-y-4 w-[320px]",children:[e.jsxs("div",{className:"relative h-[200px] rounded cursor-crosshair",style:{background:`hsl(${r}, 100%, 50%)`},onClick:f,onMouseMove:y=>{y.buttons===1&&f(y)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${o}%`,top:`${100-i}%`,backgroundColor:u}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:r,onChange:y=>h(Number(y.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"HEX"}),e.jsx(s.Input,{value:u,onChange:y=>j(y.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:u}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(s.Button,{variant:"outline",onClick:n,children:"Cancel"}),e.jsx(s.Button,{onClick:p,children:"OK"})]})]})}function It(t){const a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return a?{r:parseInt(a[1],16),g:parseInt(a[2],16),b:parseInt(a[3],16)}:null}function Hl(t,a,n){return"#"+((1<<24)+(t<<16)+(a<<8)+n).toString(16).slice(1)}function At(t,a,n){t/=255,a/=255,n/=255;const r=Math.max(t,a,n),l=Math.min(t,a,n);let o=0,c=0;const i=(r+l)/2;if(r!==l){const d=r-l;switch(c=i>.5?d/(2-r-l):d/(r+l),r){case t:o=((a-n)/d+(a<n?6:0))/6;break;case a:o=((n-t)/d+2)/6;break;case n:o=((t-a)/d+4)/6;break}}return{h:Math.round(o*360),s:Math.round(c*100),l:Math.round(i*100)}}function Kl(t,a,n){t/=360,a/=100,n/=100;let r,l,o;if(a===0)r=l=o=n;else{const c=(u,m,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?u+(m-u)*6*h:h<.5?m:h<.6666666666666666?u+(m-u)*(.6666666666666666-h)*6:u),i=n<.5?n*(1+a):n+a-n*a,d=2*n-i;r=c(d,i,t+1/3),l=c(d,i,t),o=c(d,i,t-1/3)}return{r:Math.round(r*255),g:Math.round(l*255),b:Math.round(o*255)}}const Ql=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function Ra(){var k,O,N,C,v,D,E,L,w,F;const t=s.useEditorStore(S=>S.card),a=s.useEditorStore(S=>{var T;return(T=S.card)==null?void 0:T.preferences}),{setCardPreferences:n,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[o,c]=I.useState({}),[i,d]=I.useState(null),[u,m]=I.useState(null),h=I.useMemo(()=>{var B,M,R,z,V,J,Z;if(!(l!=null&&l.records)||l.records.length===0)return[];const S=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",T=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line",A=((B=t==null?void 0:t.config)==null?void 0:B.pivotByColumns)&&t.config.pivotByColumns.length>0;if((S||T)&&A){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const W=new Set;return l.pivotSchema.forEach(q=>{q.alias&&W.add(q.alias)}),Array.from(W)}if(l.records.length>0){const W=l.records[0],q=Object.keys(W),G=new Set;(M=t==null?void 0:t.config)!=null&&M.groupByColumns&&t.config.groupByColumns.forEach(U=>{G.add(U.label||U.name),G.add(U.alias||U.name)});const P=new Set;return(R=t==null?void 0:t.config)!=null&&R.metricColumns&&t.config.metricColumns.forEach(U=>{const Y=U.alias||U.name;P.add(Y),P.add(`${Y}_count`),P.add(`${Y}_sum`),P.add(`${Y}_avg`),P.add(`${Y}_min`),P.add(`${Y}_max`);const X=U.entityName||U.qualifiedEntityName;X&&(P.add(`${X}_${Y}`),P.add(`${X}_${Y}_count`))}),q.filter(U=>!G.has(U)&&!P.has(U))}}if((T||S)&&!A&&((V=(z=t==null?void 0:t.config)==null?void 0:z.metricColumns)!=null&&V.length))return t.config.metricColumns.map(W=>W.alias||W.label||W.name);if((Z=(J=t==null?void 0:t.config)==null?void 0:J.groupByColumns)!=null&&Z.length){const W=t.config.groupByColumns[0],q=W.label||W.name,G=new Set;return l.records.forEach(P=>{const _=P[q];_!=null&&G.add(String(_))}),Array.from(G)}return[]},[l,(k=t==null?void 0:t.config)==null?void 0:k.groupByColumns,(O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns,(N=t==null?void 0:t.config)==null?void 0:N.metricColumns,t==null?void 0:t.type]),f=I.useMemo(()=>s.getDefaultChartColors(),[]);I.useEffect(()=>{const S={};h.forEach((T,A)=>{S[T]=s.getColorForValue(T,A,a==null?void 0:a.colorConfig)}),c(S)},[h,a==null?void 0:a.colorConfig,f]);const g=(S,T)=>{const A={...o,[S]:T};c(A);const B={...a||{},colorConfig:{segments:A}};n(B);const M={...t,preferences:B};r(M)},j=(S,T)=>{var V;const A=f[T%f.length],{[S]:B,...M}=((V=a==null?void 0:a.colorConfig)==null?void 0:V.segments)||{},R={...a||{},colorConfig:{segments:M}};n(R);const z={...t,preferences:R};r(z),c(J=>({...J,[S]:A}))};if(!h.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((v=(C=t==null?void 0:t.config)==null?void 0:C.groupByColumns)==null?void 0:v.length)||((E=(D=t==null?void 0:t.config)==null?void 0:D.pivotByColumns)==null?void 0:E.length):(w=(L=t==null?void 0:t.config)==null?void 0:L.groupByColumns)==null?void 0:w.length)||["table","kpi","text","custom"].includes(t.type))return null;const x=()=>{const S={...a||{},colorConfig:{segments:{}}};n(S);const T={...t,preferences:S};r(T);const A={};h.forEach((B,M)=>{A[B]=s.getColorForValue(B,M,void 0)}),c(A)},b=Object.keys(((F=a==null?void 0:a.colorConfig)==null?void 0:F.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Colors"})]})}),e.jsx(s.AccordionContent,{className:"",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"flex items-center justify-between",children:b&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:x,children:[e.jsx(s.RotateCcw,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:h.map((S,T)=>{const A=s.isDefaultColor(o[S],T),B=!A;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===S,onOpenChange:M=>d(M?S:null),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:o[S]}})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-3",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Theme Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:f.slice(0,10).map((M,R)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",o[S]===M?"border-gray-900":"border-transparent"),style:{backgroundColor:M},onClick:()=>{g(S,M),d(null)},children:[R===T%f.length&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-white/90 px-0.5 text-[8px] font-bold text-gray-900 shadow-sm",children:"D"})}),e.jsx("span",{className:"sr-only",children:M})]},`default-${R}`))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Popular Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Ql.map((M,R)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",o[S]===M?"border-2 border-gray-900":M==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:M},onClick:()=>{g(S,M),d(null)},children:e.jsx("span",{className:"sr-only",children:M})},`preset-${R}`))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[e.jsx("button",{className:"text-sm font-medium text-blue-600 hover:text-blue-700",onClick:()=>{m({value:S,color:o[S]}),d(null)},children:"Custom color"}),!A&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{j(S,T),d(null)},children:[e.jsx(s.RotateCcw,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:S}),B&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},S)})}),u&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>m(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(La,{color:u.color,onColorChange:S=>{g(u.value,S),m(null)},onClose:()=>m(null)})})]})]})})]})}function be({value:t,onSave:a,placeholder:n="",type:r="text",className:l=""}){const[o,c]=I.useState(t??""),[i,d]=I.useState(!1);I.useEffect(()=>{c(t??"")},[t]);const u=()=>{a(o),d(!1)},m=()=>{c(t??""),d(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${l}`,children:[e.jsx(s.Input$1,{placeholder:n,type:r,value:i?o:t??"",onChange:h=>{c(h.target.value),d(!0)},onFocus:()=>d(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&i&&o!==t?u():h.key==="Escape"&&m()},"aria-label":n||"Edit field"}),i&&o!==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:u,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:m,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}const Wl=["auto","number","currency","percent","scientific","date"],Jl=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"},{value:"CHF",label:"CHF - Swiss Franc"},{value:"SEK",label:"SEK - Swedish Krona"},{value:"NZD",label:"NZD - New Zealand Dollar"},{value:"MXN",label:"MXN - Mexican Peso"},{value:"SGD",label:"SGD - Singapore Dollar"},{value:"HKD",label:"HKD - Hong Kong Dollar"},{value:"NOK",label:"NOK - Norwegian Krone"},{value:"KRW",label:"KRW - South Korean Won"}],Xl=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"en-IN",label:"English (India)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"},{value:"ja-JP",label:"Japanese"},{value:"ko-KR",label:"Korean"},{value:"ru-RU",label:"Russian"},{value:"ar-SA",label:"Arabic"},{value:"hi-IN",label:"Hindi"},{value:"nl-NL",label:"Dutch"},{value:"sv-SE",label:"Swedish"}],Zl=t=>t.charAt(0).toUpperCase()+t.slice(1);function ct({formatOptions:t={},onFormatOptionsChange:a,showTitle:n=!0,title:r="NUMBER FORMAT"}){const l=t.type||"auto",o=(i,d)=>{a({...t,[i]:d})},c=()=>l==="currency"?2:l==="percent"?1:0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[n&&e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:r}),e.jsxs(s.Select,{value:l,onValueChange:i=>o("type",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Wl.map(i=>e.jsx(s.SelectItem,{value:i,className:"text-xs",children:i==="auto"?"Auto (Default)":Zl(i)},i))})]})]}),l!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent"].includes(l)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",min:"0",max:"10",placeholder:"0",value:t.decimalPlaces??c(),onChange:i=>o("decimalPlaces",parseInt(i.target.value)||0),className:"h-8 text-xs"})})]}),l==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Currency"}),e.jsxs(s.Select,{value:t.currency||"USD",onValueChange:i=>o("currency",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Jl.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),["number","currency"].includes(l)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:t.useSuffix??!1,onCheckedChange:i=>o("useSuffix",i)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Locale"}),e.jsxs(s.Select,{value:t.locale||"en-US",onValueChange:i=>o("locale",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Xl.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),l==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Prefix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., $",value:t.prefix||"",onChange:i=>o("prefix",i.target.value),className:"h-8 text-xs"})})]}),l==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Suffix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., units",value:t.suffix||"",onChange:i=>o("suffix",i.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(l)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Negative in ()"}),e.jsx(s.SmallSwitch,{checked:t.negativeInParentheses??!1,onCheckedChange:i=>o("negativeInParentheses",i)})]}),l==="percent"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Multiply By"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",placeholder:"100",value:t.multiplyBy??"",onChange:i=>o("multiplyBy",i.target.value?parseFloat(i.target.value):void 0),className:"h-8 text-xs"})})]}),l==="date"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Format"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"text",placeholder:"MM/DD/YYYY",value:t.dateFormat||"",onChange:i=>o("dateFormat",i.target.value),className:"h-8 text-xs"})})]})]})]})}function Mt({axis:t,label:a,type:n,config:r,onChange:l}){var h,f,g,j,p,y,x,b,k,O,N,C;const o=(v,D)=>{l({...r,[v]:D})},c=(v,D)=>{var E,L;l({...r,name:{enabled:v==="enabled"?D:((E=r==null?void 0:r.name)==null?void 0:E.enabled)??!1,text:v==="text"?D:(L=r==null?void 0:r.name)==null?void 0:L.text}})},i=(v,D)=>{var E,L;l({...r,labels:{enabled:v==="enabled"?D:((E=r==null?void 0:r.labels)==null?void 0:E.enabled)??!0,rotation:v==="rotation"?D:(L=r==null?void 0:r.labels)==null?void 0:L.rotation}})},d=(v,D)=>{l({...r,scale:{...r==null?void 0:r.scale,[v]:D===""?"auto":Number(D)}})},u=t==="x"?["auto","top","bottom"]:["auto","left","right"],m=["auto","0","45","90","-45","-90"];return e.jsxs(s.AccordionItem,{value:`${t}-axis`,className:"border-b-0",children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(s.AccordionTrigger,{className:"flex grow items-center justify-between gap-3 py-2 text-sm font-medium hover:no-underline",children:e.jsx("div",{className:"flex grow items-center justify-between gap-2",children:e.jsx("span",{children:a})})}),e.jsx(s.SmallSwitch,{checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:v=>o("enabled",v),onClick:v=>v.stopPropagation()})]}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"TITLE"}),e.jsx(s.SmallSwitch,{checked:((h=r==null?void 0:r.name)==null?void 0:h.enabled)??!1,onCheckedChange:v=>c("enabled",v)})]}),((f=r==null?void 0:r.name)==null?void 0:f.enabled)&&e.jsx(be,{placeholder:`${a} title`,value:((g=r==null?void 0:r.name)==null?void 0:g.text)||"",onSave:v=>c("text",v),className:""})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"POSITION"}),e.jsxs(s.Select,{value:(r==null?void 0:r.position)||"auto",onValueChange:v=>o("position",v),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(v=>e.jsx(s.SelectItem,{value:v,className:"text-xs",children:v==="auto"?"Auto (Default)":s.titleCase(v)},v))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((j=r==null?void 0:r.labels)==null?void 0:j.enabled)!==!1,onCheckedChange:v=>i("enabled",v)})]}),((p=r==null?void 0:r.labels)==null?void 0:p.enabled)!==!1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Rotation"}),e.jsxs(s.Select,{value:String(((y=r==null?void 0:r.labels)==null?void 0:y.rotation)||"auto"),onValueChange:v=>i("rotation",v==="auto"?"auto":Number(v)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(v=>e.jsx(s.SelectItem,{value:v,className:"text-xs",children:v==="auto"?"Auto (Default)":`${v}°`},v))})]})]})]}),n==="value"&&e.jsx(ct,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:v=>l({...r,formatOptions:v}),showTitle:!0,title:"FORMAT"}),n==="value"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"SCALE"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"auto",value:((x=r==null?void 0:r.scale)==null?void 0:x.min)==="auto"||((b=r==null?void 0:r.scale)==null?void 0:b.min)===void 0?"":String(r.scale.min),onSave:v=>d("min",v),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"auto",value:((k=r==null?void 0:r.scale)==null?void 0:k.max)==="auto"||((O=r==null?void 0:r.scale)==null?void 0:O.max)===void 0?"":String(r.scale.max),onSave:v=>d("max",v),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"auto",value:((N=r==null?void 0:r.scale)==null?void 0:N.stepSize)==="auto"||((C=r==null?void 0:r.scale)==null?void 0:C.stepSize)===void 0?"":String(r.scale.stepSize),onSave:v=>d("stepSize",v),className:""})})]})]})]})]})]})}function Oa(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>{var i;return(i=c.card)==null?void 0:i.preferences}),{setCardPreferences:n,updateCardInFrame:r}=s.useEditorActions();if(!t||["tornado","pyramid","kpi"].includes(t.type))return null;const l=s.AxisConfigurator.getAxisInfo(t.type,a);if(!l.hasXAxis&&!l.hasYAxis)return null;const o=(c,i)=>{const u={...a||{},[c==="x"?"xAxisConfig":"yAxisConfig"]:i};n(u);const m={...t,preferences:u};r(m)};return e.jsxs(s.AccordionItem,{value:"axes",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Un,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Axes"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[l.hasXAxis&&e.jsx(Mt,{axis:"x",label:"X-Axis",type:l.xAxisType,config:a==null?void 0:a.xAxisConfig,onChange:c=>o("x",c)}),l.hasYAxis&&e.jsx(Mt,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:a==null?void 0:a.yAxisConfig,onChange:c=>o("y",c)})]})})]})}function Fa(){const t=s.useEditorStore(u=>u.card),a=s.useEditorStore(u=>{var m,h,f,g;return(g=(f=(h=(m=u.card)==null?void 0:m.preferences)==null?void 0:h.chartOptions)==null?void 0:f.plugins)==null?void 0:g.legend}),{setLegendOptions:n}=s.useEditorActions();if(!t||!s.chartSupportsLegend(t.type))return null;const r="bottom",l="center",o=!(t.type==="stackedBar"||t.type==="stackedLine"),c=(u,m)=>{const h={...a,[u]:m};n(h)},i=["top","bottom","left","right"],d=["start","center","end"];return e.jsxs(s.AccordionItem,{value:"legend",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(kn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Legend"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.display)??o,onCheckedChange:u=>c("display",u)})]}),((a==null?void 0:a.display)??o)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:(a==null?void 0:a.position)||r,onValueChange:u=>c("position",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:i.map(u=>e.jsx(s.SelectItem,{value:u,className:"text-xs",children:s.titleCase(u)},u))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Alignment"}),e.jsxs(s.Select,{value:(a==null?void 0:a.align)||l,onValueChange:u=>c("align",u),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:d.map(u=>e.jsx(s.SelectItem,{value:u,className:"text-xs",children:s.titleCase(u)},u))})]})]})]})]})})]})}function Ba(){var D,E,L,w,F,S,T,A,B;const t=s.useEditorStore(M=>M.card),a=s.useEditorStore(M=>{var R,z;return(z=(R=M.card)==null?void 0:R.preferences)==null?void 0:z.dataLabelsConfig}),n=s.useEditorStore(M=>{var R;return(R=M.card)==null?void 0:R.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const o=((D=n==null?void 0:n.chartOptions)==null?void 0:D.indexAxis)==="y",c=t.type==="stackedBar"||t.type==="stackedLine",i=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",d=!i,u=(L=(E=n==null?void 0:n.chartOptions)==null?void 0:E.plugins)==null?void 0:L.datalabels,m=(u==null?void 0:u.display)!==!1&&((u==null?void 0:u.anchor)||(u==null?void 0:u.align)),h=(a==null?void 0:a.enabled)!==void 0?a.enabled:m,f=(M,R)=>{const z={...a,[M]:R},V={...t.preferences||{},dataLabelsConfig:z};r(V);const J={...t,preferences:V};l(J)},g=(M,R)=>{const z={...a,font:{...a==null?void 0:a.font,[M]:R}},V={...t.preferences||{},dataLabelsConfig:z};r(V);const J={...t,preferences:V};l(J)},j=(M,R)=>{const z={...a,formatOptions:{...a==null?void 0:a.formatOptions,[M]:R}},V={...t.preferences||{},dataLabelsConfig:z};r(V);const J={...t,preferences:V};l(J)},y=(()=>{const M=t.type;return M==="stackedBar"||M==="stackedLine"||M==="pie"||M==="doughnut"?"center":o?"right":"top"})();let x=[];c||i?x=["center"]:x=["auto",...(o?["center","left","right"]:["center","top","bottom"]).filter(R=>R!==y),"custom"];const b=()=>s.titleCase(y),k=["center","start","end"],O=["center","start","end","top","bottom"],N=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],C=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],v=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}];return e.jsxs(s.AccordionItem,{value:"data-labels",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Data Labels"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:h,onCheckedChange:M=>f("enabled",M)})]}),h&&e.jsxs(e.Fragment,{children:[!c&&!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:(a==null?void 0:a.position)||"auto",onValueChange:M=>f("position",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:x.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:M==="auto"?b():M==="custom"?"Custom (Advanced)":s.titleCase(M)},M))})]})]}),c&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Show Total"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.showTotal)??!1,onCheckedChange:M=>f("showTotal",M)})]}),(a==null?void 0:a.position)==="custom"&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),e.jsxs(s.Select,{value:(a==null?void 0:a.anchor)||"center",onValueChange:M=>f("anchor",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:k.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:s.titleCase(M)},M))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Align"}),e.jsxs(s.Select,{value:String((a==null?void 0:a.align)||"center"),onValueChange:M=>f("align",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:O.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:s.titleCase(M)},M))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(a==null?void 0:a.format)||(d?"auto":"none"),onValueChange:M=>f("format",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:N.map(M=>e.jsx(s.SelectItem,{value:M,className:"text-xs",children:M==="auto"&&d?"Auto (Use Axis)":M==="none"?"None (Raw Value)":s.titleCase(M)},M))})]})]}),(a==null?void 0:a.format)&&!["auto","none"].includes(a.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(a.format)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"0",value:String(((w=a==null?void 0:a.formatOptions)==null?void 0:w.decimalPlaces)??(a.format==="currency"?2:a.format==="percent"?1:0)),onSave:M=>j("decimalPlaces",Number(M)),className:""})})]}),a.format==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Currency"}),e.jsxs(s.Select,{value:((F=a==null?void 0:a.formatOptions)==null?void 0:F.currency)||"USD",onValueChange:M=>j("currency",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:C.map(M=>e.jsx(s.SelectItem,{value:M.value,className:"text-xs",children:M.label},M.value))})]})]}),["number","currency"].includes(a.format)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:((S=a==null?void 0:a.formatOptions)==null?void 0:S.useSuffix)??!1,onCheckedChange:M=>j("useSuffix",M)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Locale"}),e.jsxs(s.Select,{value:((T=a==null?void 0:a.formatOptions)==null?void 0:T.locale)||"en-US",onValueChange:M=>j("locale",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:v.map(M=>e.jsx(s.SelectItem,{value:M.value,className:"text-xs",children:M.label},M.value))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Appearance"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Size"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"12",value:String(((A=a==null?void 0:a.font)==null?void 0:A.size)||12),onSave:M=>g("size",Number(M)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(s.Select,{value:((B=a==null?void 0:a.font)==null?void 0:B.weight)||"normal",onValueChange:M=>g("weight",M),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(s.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Color"}),e.jsxs(s.Select,{value:(a==null?void 0:a.color)==="auto"||!(a!=null&&a.color)?"auto":"custom",onValueChange:M=>{M==="auto"&&f("color","auto")},children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),e.jsx(s.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),e.jsx("div",{className:"flex-1",children:e.jsx(be,{type:"number",placeholder:"0",value:String((a==null?void 0:a.rotation)||0),onSave:M=>f("rotation",Number(M)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function eo(){return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Chart Configuration"}),e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:[e.jsx(Ra,{}),e.jsx(Oa,{}),e.jsx(Fa,{}),e.jsx(Ba,{})]})]})}const so=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."]})]}),to=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."]})]}),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 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 no(){const t=s.useEditorStore(n=>n.card.type);function a(n){const r=["kpi","table","text","map","custom"],l=o=>r.includes(n)?o:e.jsxs(e.Fragment,{children:[o,e.jsx(eo,{})]});switch(n){case"stackedBar":case"stackedLine":return l(e.jsx(Yl,{}));case"tornado":case"pyramid":return l(e.jsx(us,{docContent:so,cardType:n}));case"kpi":return e.jsx(zl,{});case"line":case"bar":return l(e.jsx(Ml,{cardType:n}));case"range":return l(e.jsx(us,{docContent:to,cardType:n}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(us,{cardType:n}));case"bubble":case"scatter":return l(e.jsx(Ll,{cardType:n}));case"table":return e.jsx(Gl,{cardType:n});case"text":return e.jsx(us,{docContent:ao,cardType:n,suffix:"Visual"});case"map":return e.jsx($l,{});case"custom":return e.jsx(Tl,{});default:return l(e.jsx(Fl,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Pa({label:t,column:a,functions:n,onFunctionChange:r}){let l=n[0];"aggregate"in a?l=n.find(c=>c.value===a.aggregate)||n[0]:"granularity"in a&&(l=n.find(c=>c.value===a.granularity)||n[0]);function o(c){r(c)}return e.jsx(fe,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:l.logo,options:n,value:l.value,onValueChange:c=>o(c),label:t,showPlaceholderLabel:!1})}const ro=[{label:"Sum",value:"SUM",logo:e.jsx(Yt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(Ce,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(yn,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(sn,{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 lo({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions();let n=ro;s.isTextDataType(t.type)&&(n=n.filter(l=>["COUNT","DISTINCT"].includes(l.value))),s.isNumberDataType(t.type)&&(n=n.filter(l=>!["DISTINCT"].includes(l.value)));function r(l){const o={...t,aggregate:l,label:ns(t.name,l)};a(t.id,o)}return e.jsx(Pa,{column:t,functions:n,onFunctionChange:l=>r(l),label:"Aggregation"})}const oo=[{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 io({column:t}){const{updateGroupByColumnOld:a}=s.useEditorActions();function n(r){const l={...t,granularity:r,label:We(t.name,r)};a(t.id,l)}return e.jsx(Pa,{column:t,functions:oo,onFunctionChange:r=>n(r),label:"Granularity"})}function co({col:t,onChange:a,droppableId:n}){const{columns:r}=s.useDataColumns(),l=I.useMemo(()=>{let i=[];(n===Pe||n===ze||n===Ve)&&(i=r);const d=i==null?void 0:i.filter(u=>u.column_name!==t.name);return d==null?void 0:d.map(u=>({id:u.column_name,value:u.column_name}))},[r,n,t.name]),o=[{id:t.name,value:t.name}];function c(i){const d=r==null?void 0:r.find(u=>{var m;return u.column_name===((m=i[0])==null?void 0:m.id)});d&&a(d)}return l!=null&&l.length?e.jsx(s.ComboBox2,{multiple:!1,options:l,selectedOptions:o,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 za({column:t}){const a=s.useEditorStore(d=>d.card.type),n=s.useEditorStore(d=>{var u,m;return(m=(u=d.card)==null?void 0:u.config)==null?void 0:m.metricColumns}),r=(n==null?void 0:n.map(d=>d.label))||[],l=r==null?void 0:r.find(d=>d===t.label||d===t.name),o=l?r.indexOf(l):-1;function c(){return e.jsx("div",{className:"pr-1",children:l&&e.jsx(Aa,{idx:o,col:l,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function i(){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(Ma,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(a)&&c(),["pie","doughnut"].includes(a)&&i()]})}function uo({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[l,o]=I.useState(!1),{updateGroupByColumnOld:c,updateMetricColumnOld:i,updatePivotByColumnOld:d}=s.useEditorActions(),{attributes:u,listeners:m,setNodeRef:h,transform:f,transition:g,isDragging:j}=s.useSortable({id:t.id,data:{type:a}}),p=f?{opacity:j?.5:void 0,transform:s.CSS.Translate.toString(f),transition:g}:void 0,y=s.isTextDataType(t.type);function x(C){const v=s.isNumberDataType(C.data_type),D=s.isTextDataType(C.data_type),E=s.isDateDataType(C.data_type),L=v?"number":D?"string":E?"date":"string";if(r===Pe){if(D){const w={id:t.id,name:C.column_name,type:L,role:"groupby"};c(t.id,w)}if(E){const w={id:t.id,name:C.column_name,type:L,role:"groupby",label:We(C.column_name,"month"),granularity:"month"};c(t.id,w)}}if(r===Ve){if(D){const w={id:t.id,name:C.column_name,type:L,role:"groupby"};d(t.id,w)}if(E){const w={id:t.id,name:C.column_name,type:L,label:We(C.column_name,"month"),granularity:"month",role:"groupby"};d(t.id,w)}}if(r===ze){const w={id:t.id,name:C.column_name,type:L,role:"metric",label:ns(C.column_name,"SUM"),aggregate:v?"SUM":"COUNT"};i(t.id,w)}}function b(){if(r===ze)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(za,{column:t})})}function k(){const C=s.isDateDataType(t.type);if(r===ze)return e.jsx(lo,{column:t});if((r===Pe||r===Ve)&&C)return e.jsx(io,{column:t})}function O(){return e.jsx("div",{className:s.cn("grow",{"pl-3":(r===Pe||r===Ve)&&y}),children:e.jsx(co,{col:t,onChange:x,droppableId:r})})}function N(){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:()=>o(!l),children:l?e.jsx(_n,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(Ut,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...m,...u,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:[N(),k(),O()]}),l&&b()]}),e.jsx("div",{className:s.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:l}),children:e.jsx("button",{onClick:()=>n(t.id),children:e.jsx(s.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function Fs({id:t,label:a,columns:n,previewColumns:r,sortableType:l,onRemoveColumn:o}){var p,y;const{setNodeRef:c,isOver:i,over:d}=s.useDroppable({id:t}),u=s.useDndStore(x=>x.activeId),m=s.useEditorStore(x=>{var b;return(b=x.card)==null?void 0:b.type}),h=i||((y=(p=d==null?void 0:d.data)==null?void 0:p.current)==null?void 0:y.type)===l,f=u?r:n,g=l===js?"Rows":l===ys?"Pivot Columns":"Columns";function j(){if(!f||f.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(x=>x.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}),m!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:g})]}),j(),e.jsx("div",{className:"space-y-2",children:f==null?void 0:f.map(x=>x.id===xa.id?e.jsx(mo,{},x.id):e.jsx(uo,{droppableId:t,type:l,column:x,onRemoveColumn:o},x.id))})]})})}function mo(){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 Va({children:t,id:a,type:n}){const{attributes:r,listeners:l,setNodeRef:o,transform:c,transition:i,isDragging:d}=s.useSortable({id:a,data:{type:n}}),u=c?{opacity:d?.5:void 0,transform:s.CSS.Translate.toString(c),transition:i}:void 0;return e.jsx("div",{...l,...r,ref:o,style:u,children:t})}function ho(){const t=s.useEditorStore(x=>{var b;return(b=x.card.queryConfig)==null?void 0:b.orderBy})||[],a=s.useEditorStore(x=>{var b;return(b=x.card.queryConfig)==null?void 0:b.groupByColumns})||[],n=s.useEditorStore(x=>{var b;return(b=x.card.queryConfig)==null?void 0:b.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:l,updateOrderByColumn:o}=s.useEditorActions(),c=[...a,...n];if(c.length===0)return e.jsx(e.Fragment,{});const i=e.jsx(an,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(en,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(tn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=e.jsx(Za,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=c==null?void 0:c.filter(x=>!t.some(b=>b.columnId===x.id)).map(x=>({id:x.id,value:x.label||x.name}));function f(x,b){const k=g(x);return k?k.role==="metric"?b==="asc"?u:m:b==="asc"?i:d:null}function g(x){return c.find(b=>b.id===x)}function j(x){const b=t.find(k=>k.columnId===x);if(b){const k={...b,direction:b.direction==="asc"?"desc":"asc"};o(k)}}const p=x=>{r({columnId:x.id,direction:"asc"})};function y(x){const b=t.find(k=>k.columnId===x);b&&l(b)}return e.jsx(s.SortableContext,{items:t.map(x=>Ze(x.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:x=>p(x[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),t.map(x=>{var b,k;return e.jsx(Va,{id:Ze(x.columnId),type:et,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(Ut,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Ds,{className:"w-[175px] text-sm",children:((b=g(x.columnId))==null?void 0:b.label)||((k=g(x.columnId))==null?void 0:k.name)})]}),e.jsx("button",{title:x.direction==="asc"?"Ascending":"Descending",onClick:()=>j(x.columnId),className:"rounded-sm p-0",children:f(x.columnId,x.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>y(x.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"})})})]})},x.columnId)},Ze(x.columnId))})]})})}function xo(){const t=s.useEditorStore(y=>{var x;return((x=y.card.queryConfig)==null?void 0:x.groupByColumns)||[]}),a=s.useEditorStore(y=>y.card.type),n=s.useDndStore(y=>y.previewGroupByColumns),r=s.useEditorStore(y=>{var x;return((x=y.card.queryConfig)==null?void 0:x.metricColumns)||[]}),l=s.useDndStore(y=>y.previewMetricColumns),o=s.useEditorStore(y=>{var x;return((x=y.card.queryConfig)==null?void 0:x.pivotColumns)||[]}),c=s.useDndStore(y=>y.previewPivotColumns),{removeColumnFromGroupBy:i,removeColumnFromMetricColumns:d,removeColumnFromPivotBy:u}=s.useEditorActions();function m(y){i(y)}function h(y){d(y)}function f(y){u(y)}let g="Group By",j="Metrics",p="Stack By";return a==="table"&&(g="Rows",j="Metrics",p="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(wa,{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(Fs,{onRemoveColumn:m,sortableType:js,id:Pe,label:g,columns:t,previewColumns:n}),e.jsx(Fs,{onRemoveColumn:f,sortableType:ys,id:Ve,label:p,columns:o,previewColumns:c}),e.jsx(Fs,{onRemoveColumn:h,sortableType:_s,id:ze,label:j,columns:r,previewColumns:l}),e.jsx(ho,{})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function dt({children:t,column:a,id:n,sortableType:r,className:l}){const[o,c]=I.useState(!1),{removeEditorFilter:i,clearEditorFilter:d}=s.useEditorActions(),u=s.useEditorStore(h=>{var f,g;return(g=(f=h.card.queryConfig)==null?void 0:f.filters)==null?void 0:g.some(j=>j.filterColumnName===a.name)});function m(h){i(h)}return e.jsx(Va,{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":o}),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}),u&&e.jsx("button",{onClick:()=>d(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:()=>m(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",!o&&"rounded-b-md",o&&"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",l),children:t})]})]})})}function po({column:t,sortableType:a}){const n=s.useDashboardStore(k=>k.themeStyle),r=s.useEditorStore(k=>{var O,N;return(N=(O=k.card)==null?void 0:O.queryConfig)==null?void 0:N.filters}),l=s.useEditorStore(k=>{var O,N;return(N=(O=k.card.queryConfig)==null?void 0:O.filterColumns)==null?void 0:N.find(C=>C.name===t.name)}),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:i}=s.useEditorAside(),d=I.useMemo(()=>{var k;return(k=r==null?void 0:r.find(O=>O.filterColumnName===t.name))==null?void 0:k.filterValue},[r,t.name]),u=I.useMemo(()=>Array.isArray(d)?d.map(k=>({id:k,value:k})):[],[d]),{updateEditorFilterValue:m}=s.useEditorActions(),h={column:t.name,sql:t.sql,id:t.name,connectionId:o,dataType:t.type},{data:f,isLoading:g,isFetching:j,isError:p}=s.useFilterQuery(h),y=I.useMemo(()=>{var O;return h.column?(O=f==null?void 0:f.records)==null?void 0:O.map(N=>{let C=h.column.split(".").slice(-1)[0].replace(/"/g,"");return N[C]===void 0&&(C=C.toLowerCase()),{id:N[C],value:N[C]}}):[]},[f,h.column]);function x(k){const O=k.map(N=>N.id);m(t.name,O)}function b(){return g||j?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(fo,{columnName:t.name}),showNegativeIndicator:(l==null?void 0:l.mode)==="exclude",options:y,onChange:x,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(dt,{className:"w-60",id:t.id,sortableType:a,column:t,children:b()})}function fo({columnName:t}){const{setEditorFilterMode:a}=s.useEditorActions(),n=s.useEditorStore(l=>{var o,c;return(c=(o=l.card.queryConfig)==null?void 0:o.filterColumns)==null?void 0:c.find(i=>i.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]=I.useState(!1),{selectedConnectionId:l,selectedDatabaseName:o,selectedTableName:c}=s.useEditorAside(),i={column:t.name,sql:t.sql,id:t.name,connectionId:l,title:"",dataType:t.type},{isLoading:d,isFetching:u,isError:m,data:h}=s.useFilterQuery(i),f=h==null?void 0:h.records,{dateRange:g,setDateRange:j,initialDateRange:p}=s.useDateRangeFromRecords(f),{updateEditorFilterValue:y}=s.useEditorActions();function x(O){var C,v;const N={gte:(C=O==null?void 0:O.from)==null?void 0:C.toISOString(),lte:(v=O==null?void 0:O.to)==null?void 0:v.toISOString()};y(t.name,N)}function b(){y(t.name,null,!0),j(p)}function k(){return d||u?e.jsx("div",{children:e.jsx(s.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):m?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):f?e.jsx(s.DateRangePopover,{title:i.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:g,setDateRange:j,onApply:x,onClear:b}):e.jsx(s.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(dt,{className:"w-72",id:t.id,sortableType:a,column:t,children:k()})}function jo({id:t,label:a,columns:n,previewColumns:r,sortableType:l}){var j,p;const{setNodeRef:o,isOver:c,over:i}=s.useDroppable({id:t}),d=s.useDndStore(y=>y.activeId),u={},m=c||((p=(j=i==null?void 0:i.data)==null?void 0:j.current)==null?void 0:p.type)===l;function h(){if(!g||g.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 f(y){const x=s.isDateDataType(y.type);return y.id===xa.id?e.jsx(dt,{id:y.id,sortableType:l,column:y,children:e.jsx(yo,{})},y.id):x?e.jsx(go,{droppableId:t,sortableType:l,column:y},y.id):e.jsx(po,{droppableId:t,sortableType:l,column:y},y.id)}const g=d?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(y=>y.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md border-muted-foreground/50 p-4",m&&"border border-muted-foreground/20"),ref:o,style:u,children:[e.jsx(s.Label,{className:"text-sm",children:a}),h(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:g==null?void 0:g.map(y=>f(y))})]})})}function yo(){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 vo(){const t=s.useEditorStore(l=>{var o;return((o=l.card.queryConfig)==null?void 0:o.filterColumns)||[]}),a=s.useDndStore(l=>l.previewFilterColumns),{removeColumnFromFilterColumns:n}=s.useEditorActions();function r(l){n(l)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(jo,{onRemoveColumn:r,sortableType:$s,id:Us,label:"Filters",columns:t,previewColumns:a})})}function bo(){const t=s.useEditorStore(o=>o.card),a=s.useEditorStore(o=>o.showAIDialog),{setShowAIDialog:n}=s.useEditorActions(),{data:r,errorMessage:l}=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(ws,{}),!a&&e.jsxs(s.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(Rn,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(ja,{sql:r==null?void 0:r.sql,error:l})]}),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(tt,{}),e.jsx(st,{variant:"default"})]})]})}function No(){const t=I.useRef(null),a=I.useRef(null),n=s.useEditorStore(i=>i.isShowingVisual),r=s.useEditorStore(i=>i.showAIDialog),l=s.useEditorStore(i=>i.isDevMode);I.useEffect(()=>{var i,d,u,m;r?((i=t.current)==null||i.resize(0),(d=a.current)==null||d.resize(0)):((u=t.current)==null||u.resize(25),(m=a.current)==null||m.resize(25))},[r]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(xl,{})}),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(no,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ds,{})})]}):e.jsx(ds,{})})]})}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(xo,{})})}),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(bo,{}),e.jsx(vo,{})]}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(ds,{})})]})})]}):e.jsx(ds,{})})})}return e.jsx(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:l?o():c()})}function Co(t){s.useAIInteractionStore($=>$.currentAIContext);const[a,n]=I.useState(""),[r,l]=I.useState(null),{authToken:o}=s.useSemaphorContext(),c=s.useEditorStore($=>{var ee;return(ee=$==null?void 0:$.card)==null?void 0:ee.sql}),i=s.useEditorStore($=>$.isDevMode),d=s.useEditorStore($=>{var ee;return(ee=$==null?void 0:$.card)==null?void 0:ee.python}),{setCardPython:u,setCardSql:m,setRunSql:h,switchCardType:f,setQueryConfig:g}=s.useEditorActions(),j=s.useEditorStore($=>$.currentAssitantScope)||[],p=s.useEditorStore($=>$.userInputForAI),y=s.useEditorStore($=>$.triggerAIRun),x=s.useEditorStore($=>$.card),b=s.useEditorStore($=>$.selectedDatabaseName),k=s.useEditorStore($=>$.selectedTableName),O=s.useEditorStore($=>$.selectedConnectionId),N=s.useEditorStore($=>$.selectedSchemaName),C=s.useDashboardStore($=>$.dashboard.aiScopeTables),{errorMessage:v,refetch:D,data:E}=s.useDashboardCardQuery(x),{setTriggerAIRun:L,setCurrentAssitantScope:w,setCardConfig:F}=s.useEditorActions(),{selectedDatamodelName:S,connectionType:T,selectedDatamodelId:A}=s.useEditorAside(),{messages:B,setMessages:M,regenerate:R,error:z,sendMessage:V,status:J,addToolResult:Z,stop:W}=s.useChat({transport:new s.DefaultChatTransport({api:"https://semaphor.cloud/api/v1/assistant",headers:()=>({Authorization:`Bearer ${o==null?void 0:o.accessToken}`}),body:()=>{const $=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",isDevMode:i,aiContext:$.currentAIContext,reasoningEffort:$.reasoningEffort,showReasoning:$.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:$,body:ee})=>({body:{...ee,messages:s.pruneProblematicParts($)}})}),onError:$=>{console.log("on error",$)},onToolCall:q,onFinish(){n("")}});I.useEffect(()=>{y&&p&&(V({role:"user",parts:[{type:"text",text:p}]}),L(!1))},[y,p,V,L]);async function q({toolCall:$}){var ee,te,ie,K,Q,ne,de,Fe,ke,De,Te,ae,he,ls,os,is;if(["createChartFromSql","createForecast"].includes($.toolName)){const Xe=((ee=$.input)==null?void 0:ee.sql)??((te=$.args)==null?void 0:te.sql),Ee=((ie=$.input)==null?void 0:ie.python)??((K=$.args)==null?void 0:K.python),ce=((Q=$.input)==null?void 0:Q.chartType)??((ne=$.args)==null?void 0:ne.chartType);f(ce),m(Xe),u(Ee),h(!0),Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if($.toolName==="getUserSql"){if(!c){Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"error",message:"No SQL found"}});return}Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"success",sql:c,python:d||""}})}else if($.toolName==="generateQueryConfig"){n("Generating query config...");const Xe=((de=$.input)==null?void 0:de.chartType)??((Fe=$.args)==null?void 0:Fe.chartType),Ee=((ke=$.input)==null?void 0:ke.queryConfig)??((De=$.args)==null?void 0:De.queryConfig);((Te=$.input)==null?void 0:Te.cardConfig)??((ae=$.args)==null||ae.cardConfig),f(Xe),F(Ee),m(void 0),u(void 0);const ce=await D();if((he=ce==null?void 0:ce.data)!=null&&he.error){Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"error",queryConfig:Ee,message:(ls=ce==null?void 0:ce.data)==null?void 0:ls.error.message}});return}if((os=ce==null?void 0:ce.data)!=null&&os.records){Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"success",queryConfig:Ee,message:"The data has been visualized"}});return}Z({tool:$.toolName,toolCallId:$.toolCallId,output:{status:"success",queryConfig:Ee,message:"The data has been visualized",records:(is=ce==null?void 0:ce.data)==null?void 0:is.records}})}else n("Analyzing...")}function G($){const ee=s.removeFromScopeArray(j,$);P(ee)}function P($){const ee=s.sanitizeAIScope($);w(ee),M(te=>[...te,{id:crypto.randomUUID(),role:"system",parts:[{type:"text",text:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(ee)}`}]}])}function _(){const $={databaseName:b||"",schemaName:N||"",tableName:k||"",datamodelId:A||"",datamodelName:s.resolveDatamodelName(S),connectionId:O||"",connectionType:T||""},ee=s.dedup([...j,$]);P(ee)}function U(){const $={databaseName:b||"",schemaName:N||"",tableName:k||"",datamodelName:s.resolveDatamodelName(S),connectionId:O||"",connectionType:T||"",datamodelId:A||""};if(!s.isInAiScopeArray([...C||[],...j],$)||j.length===0){const te=s.dedup([...C||[],...j,$]).filter(ie=>ie.connectionId===$.connectionId);P(te)}}const Y=!["ready","error"].includes(J),X=s.getErrorMessage(z);return{messages:B,setMessages:M,sendMessage:V,regenerate:R,isLoading:Y,handleSetAIScope:U,handleAddCurrentTableToScope:_,removeFromCurrentSelections:G,currentAssitantScope:j,setCurrentAssitantScope:w,stop:W,status:J,toolStatus:a,llmUsage:r,onFinish:t,errorMessage:X}}const So=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Lt(){const t=I.useRef(null),a=I.useRef(null),[n,r]=I.useState(!1),[l,o]=I.useState(s.isDevEnv),[c,i]=I.useState(!1),[d,u]=I.useState(!1),m=s.useCurrentAIContext(),{setCurrentAIContext:h}=s.useAIActions(),f=s.useDashboardStore(P=>P.dashboard.aiContext),g=s.useEditorStore(P=>P.card.dataSource),j=s.useEditorStore(P=>P.actions.setCardSql),p=s.useEditorStore(P=>P.actions.setRunSql),y=s.useEditorStore(P=>P.showAIDialog),x=s.useDashboardStore(P=>P.handleOpenAssistantProfile),{setShowAIDialog:b,setCardPython:k}=s.useEditorActions(),{setDataSource:O}=s.useEditorActions(),{assistantProfile:N}=s.useAssistantProfile(),{messages:C,setMessages:v,sendMessage:D,isLoading:E,stop:L,status:w,llmUsage:F,errorMessage:S}=Co(),[T,A]=I.useState(""),B=P=>{A(P.target.value)},M=P=>{P.preventDefault();const _=T.trim();_&&(D({role:"user",parts:[{type:"text",text:_}]}),A(""))};s.useAssistantScroll({scrollContainerRef:t,inputRef:a,messages:C}),I.useEffect(()=>{var P;y&&((P=a.current)==null||P.focus(),h({selectedEntities:(g==null?void 0:g.selectedEntities)||[]}))},[y,g,h]);function R(P,_){_==="sql"?(j(P),p(!0)):_==="python"&&(k(P),p(!0))}function z(){var P;(P=f==null?void 0:f.selectedEntities)==null||P[0],u(!0)}function V(){m.selectedEntities.length===0&&h({selectedEntities:(f==null?void 0:f.selectedEntities)||[]})}function J(P){V();const _={role:"user",parts:[{type:"text",text:P.title+" "+P.subtitle}]};D(_)}function Z(P){V(),D({role:"user",parts:[{type:"text",text:P}]})}function W(){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/50 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:l,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:i,children:"System Message"})]})]})}function q(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const G=(T==null?void 0:T.length)===0&&(C==null?void 0:C.filter(P=>P.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:[q(),x&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:x,children:(N==null?void 0:N.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[W(),e.jsx(s.IconButton,{tooltip:"Add Context",className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",onClick:z,children:e.jsx(s.Settings,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",tooltip:"New Chat",onClick:()=>{v([])},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2 text-muted-foreground/50 hover:text-foreground",size:"sm",onClick:()=>{b(!1)},children:e.jsx(s.ArrowRightToLine,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"mt-2 flex w-full grow basis-0",children:e.jsx("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:e.jsx(s.PrintMessages,{messages:C,showTools:l,handleRun:R,showSystemMessage:c})})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[G&&!N&&e.jsx(s.Placeholders,{onClick:J,placeholders:So}),e.jsx("div",{children:G&&N&&e.jsx(s.SeedQuestions,{seedQuestions:N.seedQuestions||[],handleSeedQuestionClick:Z})})]}),e.jsx(s.AssistantStatus,{status:w,errorMessage:S}),e.jsx(s.ChatInputWithContext,{ref:a,setInput:A,stop:L,input:T,handleInputChange:B,handleSubmit:P=>{V(),M(P)},isLoading:E,onFocus:()=>{}})]}),F&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",F.inputTokens," prompt tokens, ",F.outputTokens," ","completion tokens, ",F.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(g==null?void 0:g.selectedEntities)||[],open:d,onOpenChange:u,dataSource:g||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}const ut=t=>{var w;const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:l,updateSortByColumn:o,removeGroupByColumn:c,removeMetricColumn:i,removePivotByColumn:d,removeSortByColumn:u}=s.useEditorActions(),m=s.useEditorStore(F=>F.card.type),h=t==null?void 0:t.id,f=I.useCallback(F=>{if(!(t!=null&&t.config))return[];switch(F){case"groupBy":return(t.config.groupByColumns||[]).map(S=>({id:S.id,name:S.name,dataType:S.dataType,label:S.label!==void 0?S.label:S.name,qualifiedEntityName:S.qualifiedEntityName,entityId:S.entityId,entityName:S.entityName,entityType:S.entityType,dateFormat:S.dateFormat,customFormat:S.customFormat,granularity:S.granularity}));case"metrics":return t.config.metricColumns||[];case"pivotBy":return(t.config.pivotByColumns||[]).map(S=>({id:S.id,name:S.name,dataType:S.dataType,label:S.label!==void 0?S.label:S.name,qualifiedEntityName:S.qualifiedEntityName,entityId:S.entityId,entityName:S.entityName,entityType:S.entityType}));case"sortBy":return(t.config.sortByColumns||[]).map(S=>({id:S.id,name:S.name,dataType:S.dataType,label:S.label!==void 0?S.label:S.name,qualifiedEntityName:S.qualifiedEntityName,entityId:S.entityId,entityName:S.entityName,entityType:S.entityType,direction:S.direction}));case"source":return[];default:return[]}},[t]),g=I.useCallback((F,S)=>{if(h)switch(F){case"groupBy":{a(h,{groupByColumns:S});break}case"metrics":{a(h,{metricColumns:S});break}case"pivotBy":{a(h,{pivotByColumns:S});break}case"sortBy":{a(h,{sortByColumns:S});break}}},[h,a]),j=I.useCallback((F,S,T)=>{if(!h)return;const B=f(F)[S];if(B)switch(F){case"groupBy":n(h,B.id,{label:T});break;case"metrics":r(h,B.id,{label:T});break;case"pivotBy":l(h,B.id,{label:T});break;case"sortBy":o(h,B.id,{label:T});break}},[h,f,n,r,l,o]),p=I.useCallback((F,S)=>{if(!h)return;const A=f("metrics")[F];A&&r(h,A.id,{aggregate:S,label:s.getAggregationLabel(A.name,S)})},[h,f,r]),y=I.useCallback((F,S,T)=>{if(!h)return;const B=f("groupBy")[F];if(!B)return;const M={dateFormat:S};S==="custom"&&T?M.customFormat=T:M.customFormat=void 0,n(h,B.id,M)},[h,f,n]),x=I.useCallback((F,S)=>{if(!h)return;const A=f("groupBy")[F];A&&n(h,A.id,{granularity:S})},[h,f,n]),b=I.useCallback((F,S)=>{if(!h)return;const A=f("metrics")[F];A&&r(h,A.id,{aliasTemplate:S})},[h,f,r]),k=I.useCallback((F,S)=>{if(console.log("handleValueAliasesChange",F,S),!h)return;console.log("handleValueAliasesChange",F,S);const A=f("metrics")[F];A&&(console.log("handleValueAliasesChange",S),r(h,A.id,{valueAliases:S}))},[h,f,r]),O=I.useCallback(F=>{h&&a(h,{comparisonType:F})},[h,a]),N=I.useCallback(F=>{h&&a(h,{showTrendline:F})},[h,a]),C=I.useCallback(F=>{h&&a(h,{trendlineWindow:F})},[h,a]),v=I.useCallback(F=>{h&&a(h,{trendlineGranularity:F})},[h,a]),D=I.useCallback(F=>{h&&a(h,{targetValue:F})},[h,a]),E=I.useCallback(F=>{var z;if(!h)return;const S=[...f("groupBy"),...f("pivotBy"),...f("metrics"),...f("sortBy")],T=(z=t==null?void 0:t.config)==null?void 0:z.joinPlan,A=s.validateEntityConsistency(F,S,T);if(!A.isValid){A.showError&&s.showJoinRequiredNotification();return}const B=s.getSmartContainerForField(F,S),M=f(B);if(s.fieldAlreadyExists(F,M))return;const R=s.getNewField(F,B,M);R&&g(B,[...M,R])},[h,(w=t==null?void 0:t.config)==null?void 0:w.joinPlan,f,g]),L=I.useCallback((F,S)=>{if(!h)return;const A=f(F)[S];if(A){if(F!=="sortBy"){const B=f("sortBy"),M=B.filter(R=>!(R.name===A.name&&R.qualifiedEntityName===A.qualifiedEntityName));M.length!==B.length&&a(h,{sortByColumns:M})}switch(F){case"groupBy":c(h,A.id);break;case"metrics":i(h,A.id);break;case"pivotBy":d(h,A.id);break;case"sortBy":u(h,A.id);break}}},[h,f,c,i,d,u,a]);return{getFieldsForContainer:f,setFieldsForContainer:g,updateLabel:j,handleAggregationChange:p,handleDateFormatChange:y,handleGranularityChange:x,handleAliasTemplateChange:b,handleValueAliasesChange:k,removeField:L,handleFieldClick:E,handleKpiComparisonTypeChange:O,handleKpiShowTrendlineChange:N,handleKpiTrendlineWindowChange:C,handleKpiTrendlineGranularityChange:v,handleKpiTargetValueChange:D,cardType:m}};function wo({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 ko({field:t}){const{attributes:a,listeners:n,setNodeRef:r,transform:l,transition:o,isDragging:c}=s.useSortable({id:t.id}),[i,d]=I.useState(!1),u=s.useEditorStore(j=>j.card),{handleFieldClick:m}=ut(u),h={transform:s.CSS.Transform.toString(l),transition:o};s.getDataType(t.dataType);const f=j=>{const p=(j||"").toLowerCase();switch(s.getDataType(p)){case"number":return Ce;case"date":return s.Calendar;case"boolean":return _e;case"json":return es;case"geo":return ss;default:return ge}},g=j=>{const p=(j||"").toLowerCase(),y=s.getDataType(p);return y==="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(ge,{className:"h-3 w-3"})}):y==="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(Ce,{className:"h-3 w-3"})}):y==="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"})}):y==="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(_e,{className:"h-3 w-3"})}):y==="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(es,{className:"h-3 w-3"})}):y==="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(ss,{className:"h-3 w-3"})}):y==="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(rs,{className:"h-3 w-3"})}):null};return f(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:()=>m(t),children:[g(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 ${i?"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(wo,{field:t})})]})})]}),i&&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(Gt,{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(Yn,{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 Do(){const[t,a]=I.useState(""),[n,r]=I.useState("all"),l=s.useEditorStore(k=>k.card.dataSource),{columns:o=[],columnGroups:c=[],isLoading:i,error:d}=s.useColumns(),u=o.filter(k=>k.name.toLowerCase().includes(t.toLowerCase())||k.dataType.toLowerCase().includes(t.toLowerCase())||k.qualifiedEntityName&&k.qualifiedEntityName.toLowerCase().includes(t.toLowerCase())),m=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"},f=(n==="all"?u:u.filter(k=>m(k)===n)).reduce((k,O)=>{const N=O.qualifiedEntityName||"Other Fields";return k[N]||(k[N]={label:s.toLabel(O.entityName),fields:[]}),k[N].fields.push(O),k},{}),j=Object.keys(f),p=u.filter(k=>m(k)==="dimensions").length,y=u.filter(k=>m(k)==="metrics").length,x=u.filter(k=>m(k)==="calculated").length,b=u.length>0;return i?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"})}):d?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:d.message||"Failed to load column data"})]}):!l||!l.selectedEntities||l.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:[o.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)})]}),b&&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:u.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:y})]}),e.jsxs(s.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(rs,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:x})]})]})})]}),e.jsxs(s.CustomScrollArea,{className:"py-2",children:[e.jsx(s.Accordion,{type:"multiple",defaultValue:j,className:"space-y-2",children:Object.entries(f).map(([k,O])=>{const N=c.find(C=>C.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:N.label||N.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(C=>e.jsx(ko,{field:C},C.id))})})]},k)})}),Object.keys(f).length===0&&o.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(f).length===0&&o.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 To(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(Do,{})," "]})}function Eo({initialJoinPlan:t,availableDataSources:a}){const[n,r]=I.useState(t),[l,o]=I.useState(new Set),c=()=>{const C=n.joins.length>0?Math.max(...n.joins.map(D=>D.sequence))+1:1,v={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:C,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...n,joins:[...n.joins,v]}),o(new Set([...l,v.id]))},i=C=>{r({...n,joins:n.joins.filter(v=>v.id!==C)}),o(new Set([...l].filter(v=>v!==C)))},d=(C,v)=>{var w,F;const D=n.joins.find(S=>S.id===C);if(!D)return;const E={...D,...v},L=n.joins.map(S=>S.id===C?E:S);if((w=E.source)!=null&&w.name&&((F=E.target)!=null&&F.name)&&E.joinKeyGroups[0].keys.length===0){const S=a.find(M=>{var R;return M.name===((R=E.source)==null?void 0:R.name)}),T=a.find(M=>{var R;return M.name===((R=E.target)==null?void 0:R.name)}),A={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(S==null?void 0:S.name)||"",entityName:(S==null?void 0:S.name)||"",entityType:(S==null?void 0:S.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(T==null?void 0:T.name)||"",entityName:(T==null?void 0:T.name)||"",entityType:(T==null?void 0:T.type)||"table"},operator:"="},B=[...E.joinKeyGroups];B[0]={...B[0],keys:[A]},E.joinKeyGroups=B,L[L.findIndex(M=>M.id===C)]=E}r({...n,joins:L})};return{joinPlan:n,expandedJoins:l,setJoinPlan:r,addJoin:c,removeJoin:i,updateJoin:d,moveJoinUp:C=>{const v=n.joins.findIndex(D=>D.id===C);if(v>0){const D=[...n.joins],E={...D[v]},L={...D[v-1]};D[v]=L,D[v-1]=E,D.forEach((F,S)=>{F.sequence=S+1});const w={...n,joins:D};r(w)}},moveJoinDown:C=>{const v=n.joins.findIndex(D=>D.id===C);if(v<n.joins.length-1){const D=[...n.joins],E={...D[v]},L={...D[v+1]};D[v]=L,D[v+1]=E,D.forEach((F,S)=>{F.sequence=S+1});const w={...n,joins:D};r(w)}},toggleJoinExpansion:C=>{const v=new Set(l);v.has(C)?v.delete(C):v.add(C),o(v)},getAvailableSourceEntities:C=>{if(n.joins.length===0)return a;const v=n.joins.findIndex(E=>E.id===C);if(v===0)return a;const D=new Set;return n.baseEntity.name&&D.add(n.baseEntity.name),n.joins.slice(0,v).forEach(E=>{D.add(E.source.name),D.add(E.target.name)}),a.filter(E=>D.has(E.name))},getAvailableTargetEntities:C=>a.filter(v=>v.name!==C),addJoinKeyGroup:C=>{const v=n.joins.find(E=>E.id===C);if(!v)return;const D=[...v.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];d(C,{joinKeyGroups:D})},updateGroupOperator:(C,v,D)=>{const E=n.joins.find(w=>w.id===C);if(!E)return;const L=[...E.joinKeyGroups];L[v]={...L[v],operator:D},d(C,{joinKeyGroups:L})},removeJoinKeyGroup:(C,v)=>{const D=n.joins.find(L=>L.id===C);if(!D)return;const E=[...D.joinKeyGroups];E.splice(v,1),d(C,{joinKeyGroups:E})},addJoinKey:(C,v)=>{const D=n.joins.find(S=>S.id===C);if(!D)return;const E=a.find(S=>S.name===D.source.name),L=a.find(S=>S.name===D.target.name),w=[...D.joinKeyGroups],F={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(E==null?void 0:E.name)||"",entityName:(E==null?void 0:E.name)||"",entityType:(E==null?void 0:E.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(L==null?void 0:L.name)||"",entityName:(L==null?void 0:L.name)||"",entityType:(L==null?void 0:L.type)||"table"},operator:"="};w[v]={...w[v],keys:[...w[v].keys,F]},d(C,{joinKeyGroups:w})},updateJoinKey:(C,v,D,E,L)=>{const w=n.joins.find(B=>B.id===C);if(!w)return;const F=a.find(B=>B.name===w.source.name),S=a.find(B=>B.name===w.target.name),T=[...w.joinKeyGroups],A=T[v].keys[D];E==="sourceColumnName"&&F?T[v].keys[D]={...A,source:{...A.source,name:L}}:E==="targetColumnName"&&S?T[v].keys[D]={...A,target:{...A.target,name:L}}:E==="operator"&&(T[v].keys[D]={...A,operator:L}),d(C,{joinKeyGroups:T})},removeJoinKey:(C,v,D)=>{const E=n.joins.find(w=>w.id===C);if(!E)return;const L=[...E.joinKeyGroups];L[v].keys.splice(D,1),d(C,{joinKeyGroups:L})},generateSQLPreview:()=>{const C=[...n.joins].sort((E,L)=>E.sequence-L.sequence),v=n.baseEntity;if(!v.name)return"SELECT * FROM table -- Please select a base entity";let D=`SELECT *
|
|
415
|
-
FROM ${v.name}`;return C.forEach(E=>{const L=a.find(S=>S.name===E.target.name);if(!L)return;const w=E.joinKeyGroups.filter(S=>S.keys&&S.keys.length>0).map(S=>{const T=S.keys.filter(A=>{var B,M,R,z;return((B=A.source)==null?void 0:B.name)&&((M=A.target)==null?void 0:M.name)&&((R=A.source)==null?void 0:R.entityName)&&((z=A.target)==null?void 0:z.entityName)}).map(A=>`${A.source.entityName}.${A.source.name} ${A.operator} ${A.target.entityName}.${A.target.name}`);return T.length>1?`(${T.join(` ${S.operator} `)})`:T[0]}).filter(Boolean),F=w.length>1?w.join(" OR "):w[0]||"condition_here";D+=`
|
|
416
|
-
${E.joinType} JOIN ${L.name}
|
|
417
|
-
ON ${F}`}),D},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(E=>!E.source.name||!E.target.name)||n.joins.some(E=>E.joinKeyGroups.some(L=>L.keys.length===0))||n.joins.some(E=>E.joinKeyGroups.some(L=>L.keys.some(w=>!w.source.name||!w.target.name||!w.operator))))}}function Io({joinPlan:t,availableDataSources:a,onSave:n,onRemove:r,onCancel:l}){const{setCardConfig:o}=s.useEditorActions();s.useEditorStore(w=>w.card.config);const{columnGroups:c}=s.useColumns(),{joinPlan:i,expandedJoins:d,setJoinPlan:u,addJoin:m,removeJoin:h,updateJoin:f,moveJoinUp:g,moveJoinDown:j,toggleJoinExpansion:p,getAvailableSourceEntities:y,getAvailableTargetEntities:x,addJoinKeyGroup:b,updateGroupOperator:k,removeJoinKeyGroup:O,addJoinKey:N,updateJoinKey:C,removeJoinKey:v,generateSQLPreview:D,isValidConfiguration:E}=Eo({initialJoinPlan:t,availableDataSources:a}),L=w=>{const F=c.find(S=>S.entityName===w);return(F==null?void 0:F.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:i.baseEntity.name,onValueChange:w=>{const F=a.find(S=>S.name===w);u({...i,baseEntity:{connectionId:(F==null?void 0:F.connectionId)||"",connectionType:(F==null?void 0:F.connectionType)||"none",type:(F==null?void 0:F.type)||"table",name:w,database:F==null?void 0:F.database,schema:F==null?void 0:F.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:a.map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},w.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 (",i.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:m,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),i.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:i.joins.map(w=>{const F=a.find(A=>A.name===w.source.name),S=a.find(A=>A.name===w.target.name),T=d.has(w.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:w.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",w.sequence,F&&S&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",F.name," → ",S.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>g(w.id),disabled:w.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>j(w.id),disabled:w.sequence===i.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(w.id),children:T?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(w.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),T&&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:w.source.name,onValueChange:A=>{const B=a.find(M=>M.name===A);f(w.id,{source:{connectionId:(B==null?void 0:B.connectionId)||"",connectionType:(B==null?void 0:B.connectionType)||"none",type:(B==null?void 0:B.type)||"table",name:A,database:B==null?void 0:B.database,schema:B==null?void 0:B.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:y(w.id).map(A=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:A.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:A.type}),A.name]})},A.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:w.joinType,onValueChange:A=>f(w.id,{joinType:A}),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:w.target.name,onValueChange:A=>{const B=a.find(M=>M.name===A);f(w.id,{target:{connectionId:(B==null?void 0:B.connectionId)||"",connectionType:(B==null?void 0:B.connectionType)||"none",type:(B==null?void 0:B.type)||"table",name:A,database:B==null?void 0:B.database,schema:B==null?void 0:B.schema}})},disabled:!w.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:w.source.name?x(w.source.name).map(A=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:A.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:A.type}),A.name,A.name===w.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},A.name)):[]})]})]})]}),w.source.name&&w.target.name&&F&&S&&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:()=>b(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),w.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:w.joinKeyGroups.map((A,B)=>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 ",B+1]}),B>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:A.operator,onValueChange:M=>k(w.id,B,M),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(w.id,B),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[A.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:A.keys.map((M,R)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[R>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:A.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:M.source.name,onValueChange:z=>C(w.id,B,R,"sourceColumnName",z),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:L(w.source.name).map(z=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:z.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:z.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:z.dataType})]})},z.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:M.operator,onValueChange:z=>C(w.id,B,R,"operator",z),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:M.target.name,onValueChange:z=>C(w.id,B,R,"targetColumnName",z),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:L(w.target.name).map(z=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:z.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:z.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:z.dataType})]})},z.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>v(w.id,B,R),children:e.jsx(s.X,{className:"size-3.5"})})]},M.id||R))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>N(w.id,B),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},A.id))})]})]})]},w.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),l()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>n(i),disabled:!E(),children:"Save"})]})]})}function Rt({children:t,open:a,onOpenChange:n,joinPlan:r,availableDataSources:l,onRemove:o,onSave:c,onCancel:i}){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(Io,{joinPlan:r,availableDataSources:l,onSave:c,onCancel:i,onRemove:o})]}),t]})}function Ao({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 l=[...t].sort((c,i)=>c.sequence-i.sequence),o=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:o==null?void 0:o.type}),e.jsx("span",{className:"text-xs font-medium",children:o==null?void 0:o.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),l.map(c=>{const i=n.find(d=>d.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:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.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((l,o)=>l.sequence-o.sequence).map((l,o)=>{const c=n.find(d=>d.name===l.source.name),i=n.find(d=>d.name===l.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:o+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:l.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[c==null?void 0:c.name," → ",i==null?void 0:i.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[l.joinKeyGroups.reduce((d,u)=>d+u.keys.length,0)," ","condition",l.joinKeyGroups.reduce((d,u)=>d+u.keys.length,0)>1?"s":""]})]},l.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 Mo(){var m,h;const t=s.useEditorStore(f=>f.card),a=s.useEditorStore(f=>f.actions.updateCardConfig),n=((m=t==null?void 0:t.config)==null?void 0:m.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,l]=I.useState(!1),o=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],c=f=>{a(t.id,{...t==null?void 0:t.config,joinPlan:f}),l(!1)},i=()=>{a(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},d=()=>{l(!1)},u=()=>{const f=[...n.joins].sort((p,y)=>p.sequence-y.sequence),g=n.baseEntity;if(!g.name)return"SELECT * FROM table -- Please select a base entity";let j=`SELECT *
|
|
418
|
-
FROM ${g.name}`;return f.forEach(p=>{const y=o.find(k=>k.name===p.target.name);if(!y)return;const x=p.joinKeyGroups.filter(k=>k.keys&&k.keys.length>0).map(k=>{const O=k.keys.filter(N=>{var C,v,D,E;return((C=N.source)==null?void 0:C.name)&&((v=N.target)==null?void 0:v.name)&&((D=N.source)==null?void 0:D.entityName)&&((E=N.target)==null?void 0:E.entityName)}).map(N=>`${N.source.entityName}.${N.source.name} ${N.operator} ${N.target.entityName}.${N.target.name}`);return O.length>1?`(${O.join(` ${k.operator} `)})`:O[0]}).filter(Boolean),b=x.length>1?x.join(" OR "):x[0]||"condition_here";j+=`
|
|
419
|
-
${p.joinType} JOIN ${y.name}
|
|
420
|
-
ON ${b}`}),j};return o.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:()=>l(!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(Ao,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:o,generateSQLPreview:u})})]})}),e.jsx(Rt,{open:r,onOpenChange:l,joinPlan:n,availableDataSources:o,onSave:c,onCancel:d,onRemove:i,children:e.jsx("div",{})})]}),n.joins.length===0&&e.jsx(Rt,{open:r,onOpenChange:l,joinPlan:n,availableDataSources:o,onSave:c,onCancel:d,onRemove:i,children:e.jsxs(s.Button,{onClick:()=>l(!0),variant:"outline",size:"sm",className:"w-full",children:[e.jsx(s.Link,{className:"mr-3 size-4"}),"Configure Joins"]})})]})})})}function Lo({open:t,onOpenChange:a}){const[n,r]=I.useState([]),{updateDataSource:l}=s.useEditorActions(),o=s.useDashboardStore(p=>p.dashboard.aiContext),c=(o==null?void 0:o.selectedEntities)||[];I.useEffect(()=>{t&&r([])},[t]);const i=p=>{r(y=>y.some(b=>b.name===p.name&&b.type===p.type)?y.filter(b=>!(b.name===p.name&&b.type===p.type)):[...y,p])},d=()=>{r([...c])},u=()=>{r([])},m=()=>{if(n.length===0)return;const p=n[0],y=p.connectionId||"",x=p.connectionType||"",k=n.some(N=>N.type==="dataset")?"semanticDomain":"database";l({connectionId:y,connectionType:x,mode:k,selectedEntities:n}),a(!1)},h=p=>{switch(p.type){case"table":return e.jsx(s.Table,{className:"h-4 w-4"});case"view":return e.jsx(Gn,{className:"h-4 w-4"});case"model":return e.jsx(xn,{className:"h-4 w-4"});case"dataset":return e.jsx(s.Database,{className:"h-4 w-4"});case"file":case"url":case"upload":return e.jsx(s.FileText,{className:"h-4 w-4"});default:return e.jsx(s.Database,{className:"h-4 w-4"})}},f=p=>"label"in p&&p.label?p.label:p.name,g=p=>{if("description"in p&&p.description)return p.description;const y=[];return p.database&&y.push(p.database),p.schema&&y.push(p.schema),p.name&&y.push(p.name),y.join(".")},j=p=>n.some(y=>y.name===p.name&&y.type===p.type);return c.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>a(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:d,disabled:n.length===c.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:u,disabled:n.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[n.length," of ",c.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:c.map((p,y)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",j(p)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:j(p),onCheckedChange:()=>i(p)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:h(p)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:f(p)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:g(p)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:p.type})]},`${p.type}-${p.name}-${y}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:m,disabled:n.length===0,children:["Select"," ",n.length>0?`(${n.length})`:""]})]})})})]})})}function Ro({entity:t,title:a,maxDetails:n=10}){const l=s.getEntityDetails(t).slice(0,n),o=l.find(i=>i.label==="Description"),c=l.filter(i=>i.label==="Description"?!1:!["Connection","Database","Schema"].includes(i.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)}),o&&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:o.value})]}),c.length>0&&e.jsx("div",{className:"space-y-0.5",children:c.map((i,d)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[i.label,":"]}),e.jsx("span",{className:"font-mono",children:i.value})]},d))})]})})}function Oo({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),l=r.find(c=>c.label==="Description"),o=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)}),l&&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:l.value})]}),o.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:o.map((c,i)=>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})]},i))})]},`remaining-${a.type}-${a.name}-${n}`)})})]})})}function Fo({isVisible:t,onToggleVisibility:a}){const[n,r]=I.useState(!1),[l,o]=I.useState(!1),[c,i]=I.useState(!0),d=s.useEditorStore(f=>f.card.dataSource);we();const{updateDataSource:u}=s.useEditorActions(),m={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},h={...m,...d,selectedEntities:(d==null?void 0:d.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":!c}),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(!c),className:"h-6 w-6 p-0",children:c?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 ${c?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[h.selectedEntities.length>0&&e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[h.selectedEntities.slice(0,3).map((f,g)=>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(f),e.jsx("button",{onClick:j=>{j.stopPropagation();const p=h.selectedEntities.filter(y=>!(y.name===f.name&&y.type===f.type));u({...m,...d,selectedEntities:p})},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(Ro,{entity:f})]},`${f.type}-${f.name}-${g}`)),h.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:["+",h.selectedEntities.length-3," more"]})}),e.jsx(Oo,{entities:h.selectedEntities.slice(3)})]})]})}),e.jsx(Mo,{})]})]}),e.jsx(To,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:h,fallbackDataSource:m}),e.jsx(Lo,{open:l,onOpenChange:o})]})}const ps=[{id:"table",icon:Qe,label:"Table"},{id:"pivotTable",icon:Qe,label:"Pivot Table"},{id:"aggregateTable",icon:Qe,label:"Aggregate Table"},{id:"bar",icon:Ns,label:"Bar Chart"},{id:"line",icon:Cs,label:"Line Chart"},{id:"area",icon:Vt,label:"Area Chart"},{id:"stackedBar",icon:qs,label:"Stacked Bar Chart"},{id:"combo",icon:cn,label:"Combo Chart"},{id:"stackedLine",icon:lt,label:"Stacked Line Chart"},{id:"scatter",icon:Gs,label:"Scatter Chart"},{id:"bubble",icon:nt,label:"Bubble Chart"},{id:"pie",icon:Ss,label:"Pie Chart"},{id:"doughnut",icon:Hs,label:"Doughnut Chart"},{id:"funnel",icon:rt,label:"Funnel Chart"},{id:"radar",icon:Qs,label:"Radar Chart"},{id:"polarArea",icon:at,label:"Polar Area Chart"},{id:"tornado",icon:Ws,label:"Tornado Chart"},{id:"range",icon:Ys,label:"Range Chart"},{id:"kpi",icon:ot,label:"KPI"},{id:"text",icon:zt,label:"Text"},{id:"map",icon:Ks,label:"Map"}],mt=t=>{const a=t.toLowerCase();for(const n of ps)if(n.id==="doughnut"){if(a.includes("doughnut")||a.includes("donut")){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return I.createElement(r,{className:"h-4 w-4"})}return null},Bo="chart-selector-standard-first";function Po(){const[t,a]=s.useLocalStorageState(Bo,!0);return{standardFirst:t,updatePreference:a}}const Ot=({pluginVisual:t,index:a,onSelect:n})=>{const r=ks(t.icon||""),l=t.name.charAt(0).toUpperCase(),o=mt(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"}):o||e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded bg-muted text-xs font-medium",children:l}),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}`)},Ft=["default","standardPlugin","customPlugin"];function zo({selectedChart:t,onChartChange:a}){var O;const[n,r]=I.useState(!1),{data:l}=Sa();Po();const c=((O=s.useEditorStore(N=>N.card).customCardPreferences)==null?void 0:O.url)||"";Xs(c);const{setCardType:i,setCardPreferences:d,setIsDevMode:u}=s.useEditorStore(N=>N.actions),{setCardCustomCfg:m,setCustomCardPreferences:h,setQueryConfig:f}=s.useEditorActions(),[g,j]=s.useLocalStorageState("chart-section-active",null),p=I.useMemo(()=>g?[g,...Ft.filter(N=>N!==g)]:Ft,[g]);function y(N){m(null),d({}),i(N),["custom","text","map"].includes(N)&&(u(!0),f(void 0)),a(N),r(!1)}function x(N){m(null),d({}),i("custom"),h({type:"component",visualType:"single",url:N.url,componentName:N.name,icon:N.icon,pluginChartType:N.chartType}),f(void 0),a("custom"),r(!1)}const b=()=>{var C;if(t==="custom"){const v=s.useEditorStore.getState().card;return((C=v==null?void 0:v.customCardPreferences)==null?void 0:C.componentName)||"Custom Visual"}const N=ps.find(v=>v.id===t);return(N==null?void 0:N.label)||"Select chart type"},k=()=>{var C,v;if(t==="custom"){const D=s.useEditorStore.getState().card,E=(C=D==null?void 0:D.customCardPreferences)==null?void 0:C.icon,L=(v=D==null?void 0:D.customCardPreferences)==null?void 0:v.componentName;if(E&&L)return e.jsx(Vo,{icon:E,componentName:L});if(L){const w=mt(L);if(w)return w}return e.jsx(ts,{className:"h-4 w-4"})}const N=ps.find(D=>D.id===t);if(N){const D=N.icon;return e.jsx(D,{className:"h-4 w-4"})}return e.jsx(ts,{className:"h-4 w-4"})};return e.jsx("div",{className:"mb-6",children:e.jsxs(s.Popover,{open:n,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[k(),e.jsx("span",{children:b()})]}),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."}),p.map(N=>{if(N==="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:g==="default",onCheckedChange:C=>j(C?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ps.map(C=>{const v=C.icon;return e.jsx(s.CommandItem,{value:`${C.label} ${C.id} chart graph visualization`,onSelect:()=>y(C.id),className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4"}),e.jsx("span",{children:C.label})]})},C.id)})},"default");if(N==="standardPlugin"){const C=l.filter(v=>v.pluginType==="standard");return C.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:g==="standardPlugin",onCheckedChange:v=>j(v?"standardPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:C.filter(v=>v.componentType==="chart").map((v,D)=>e.jsx(Ot,{pluginVisual:v,index:D,onSelect:()=>x(v)},`${v.url}-${v.name}-${D}`))},"standardPlugin"):null}if(N==="customPlugin"){const C=l.filter(v=>v.pluginType==="custom");return C.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:g==="customPlugin",onCheckedChange:v=>j(v?"customPlugin":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:C.map((v,D)=>e.jsx(Ot,{pluginVisual:v,index:D,onSelect:()=>x(v)},`${v.url}-${v.name}-${D}`))},"customPlugin"):null}return null})]})]})})]})})}const Vo=({icon:t,componentName:a})=>{const n=ks(),r=mt(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(ts,{className:"h-4 w-4"})},ht=({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(ge,{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(Ce,{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(_e,{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(ge,{className:"h-3 w-3"})})};function _o({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=I.useState(t),[l,o]=I.useState(!1),c=(d=s.useEditorStore(u=>{var m;return(m=u.card.config)==null?void 0:m.pivotByColumns}))==null?void 0:d[0],i=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:i,value:l?n:t,onChange:u=>{r(u.target.value),o(!0)},onFocus:()=>o(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&l&&n!==t?(a(n),o(!1)):u.key==="Escape"&&(r(t),o(!1))},"aria-label":"Edit alias template"}),l&&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),o(!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),o(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Uo({valueAliases:t,onValueAliasesChange:a}){const[n,r]=I.useState(null),[l,o]=I.useState(""),[c,i]=I.useState(""),d=()=>{a({...t,"":""})},u=h=>{const f={...t};delete f[h],a(f)},m=h=>{const f={...t};delete f[h],f[l]=c,a(f),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,f],g)=>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:l,onChange:j=>o(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?m(h):j.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:j=>i(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?m(h):j.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:()=>m(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),o(h),i(f)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:f,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),o(h),i(f)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+g)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function $o({field:t,searchQuery:a="",limit:n=500}){const{authToken:r}=s.useSemaphorContext(),l=s.useEditorStore(d=>d.card),o=l==null?void 0:l.dataSource,c=["attribute-values",t.entityName,t.name,a,n],i=s.useQuery({queryKey:c,queryFn:async()=>{if(!(o!=null&&o.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const d={groupByColumns:[{...t,role:"groupby"}],metricColumns:[],filters:a?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:t,operator:"contains",value:a}],groups:[]}:void 0,rowLimit:n},u={connection_id:o.connectionId,cardConfig:d,cardDataSource:o,cache_config:s.getCacheConfig({card:l})};console.log("requestBody",u);const m=await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(r==null?void 0:r.accessToken)||"",u);if(m!=null&&m.error)return console.error("Error fetching attribute values:",m.error),[];const h=t.name;return((m==null?void 0:m.records)||[]).map(g=>{const j=g[h]||g[t.alias||h]||g[t.label];return{id:j||"",value:j||"",label:String(j||"(empty)")}})}catch(d){return console.error("Error fetching attribute values:",d),[]}},enabled:!!t&&!!(o!=null&&o.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:i.data||[],isLoading:i.isLoading,isFetching:i.isFetching,isError:i.isError,error:i.error,refetch:i.refetch}}function qo({open:t,onOpenChange:a,availableFields:n,existingFilters:r,editingCondition:l,onSave:o}){var k,O;const c=!!l,[i,d]=I.useState(c?"values":"fields"),[u,m]=I.useState(""),[h,f]=I.useState({id:(l==null?void 0:l.id)||s.v4(),field:(l==null?void 0:l.field)||null,selectedValues:l?Array.isArray(l.value)?l.value:[l.value]:[]}),g=n.filter(N=>{var v;return c?!1:!((v=r==null?void 0:r.conditions)==null?void 0:v.some(D=>D.field.id===N.id))&&N.label.toLowerCase().includes(u.toLowerCase())}),j=N=>{f({...h,field:N}),d("values")},p=()=>{if(h.field&&h.selectedValues.length>0){const N={id:h.id,field:h.field,operator:"in",value:h.selectedValues};let C;if(c){const v=((r==null?void 0:r.conditions)||[]).map(D=>D.id===l.id?N:D);C={...r,conditions:v}}else{const v=(r==null?void 0:r.conditions)||[];C={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...v,N],groups:[]}}o(C),a(!1)}},y=()=>{if(!c||!l)return;const N=((r==null?void 0:r.conditions)||[]).filter(C=>C.id!==l.id);if(N.length>0){const C={...r,conditions:N};o(C)}else o(void 0);a(!1)},x=N=>{f({...h,selectedValues:N})},b=()=>{c&&l?(f({id:l.id,field:l.field,selectedValues:Array.isArray(l.value)?l.value:[l.value]}),d("values")):(f({id:s.v4(),field:null,selectedValues:[]}),d("fields")),m("")};return I.useEffect(()=>{t&&b()},[t,c,l]),e.jsx(s.Dialog,{open:t,onOpenChange:a,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:c?`Edit Filter: ${(k=h.field)==null?void 0:k.label}`:i==="fields"?"Select Field to Filter":`Select Values for ${(O=h.field)==null?void 0:O.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!c&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&i==="fields"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.conditions.map(N=>e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[e.jsxs("span",{className:"font-medium",children:[N.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(N.value)?`${N.value.length} values`:String(N.value)})]},N.id))})]}),i==="fields"&&!c?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search fields...",value:u,onChange:N=>m(N.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:g.map(N=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>j(N),children:[e.jsx(ht,{dataType:s.getDataType(N.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:N.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[N.entityName,".",N.name]})]})]},N.id))}),g.length===0&&u&&e.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:['No fields found matching "',u,'"']}),g.length===0&&!u&&n.length>0&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"All available fields are already filtered"})]}):e.jsx(Yo,{field:h.field,selectedValues:h.selectedValues,onValuesChange:x,onBack:c?void 0:()=>d("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:c?e.jsx(s.Button,{variant:"destructive",onClick:y,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:b,children:"Reset"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:p,disabled:!h.field||h.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function Yo({field:t,selectedValues:a,onValuesChange:n,onBack:r}){const[l,o]=I.useState(""),{values:c,isLoading:i,isFetching:d}=$o({field:t,searchQuery:l,limit:500}),u=l?c.filter(f=>String(f.value).toLowerCase().includes(l.toLowerCase())):c,m=f=>{const g=a.includes(f);n(g?a.filter(j=>j!==f):[...a,f])},h=()=>{a.length===u.length&&u.length>0?n([]):n(u.map(f=>f.value))};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:r,children:"← Back"}),e.jsxs(s.Label,{className:"text-sm font-medium",children:["Select values for ",t.label]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search values...",value:l,onChange:f=>o(f.target.value),className:"pl-10"})]}),i||d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(s.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(s.Checkbox,{checked:a.length===u.length&&u.length>0,onCheckedChange:h}),e.jsxs(s.Label,{className:"text-sm",children:["Select All (",u.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:u.map(f=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>m(f.value),children:[e.jsx(s.Checkbox,{checked:a.includes(f.value),onCheckedChange:()=>m(f.value)}),e.jsx(Ds,{className:"text-sm",children:f.label})]},f.id))})]})]})}function Go({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:o=!1,cardType:c}){var ft,gt,jt;const{attributes:i,listeners:d,setNodeRef:u,transform:m,transition:h,isDragging:f}=s.useSortable({id:t.id}),g=s.useEditorStore(H=>H.card),{updateLabel:j,handleAggregationChange:p,handleDateFormatChange:y,handleGranularityChange:x,handleAliasTemplateChange:b,handleValueAliasesChange:k,removeField:O,handleKpiComparisonTypeChange:N,handleKpiShowTrendlineChange:C,handleKpiTrendlineWindowChange:v,handleKpiTrendlineGranularityChange:D,handleKpiTargetValueChange:E}=ut(g),[L,w]=I.useState(!1),[F,S]=I.useState(!1),[T,A]=I.useState(null),[B,M]=I.useState(t.dateFormat||"YYYY-MM-DD"),[R,z]=I.useState(t.customFormat||""),[V,J]=I.useState(!!t.customFormat),[Z,W]=I.useState(t.granularity||"day"),[q,G]=I.useState(t.aliasTemplate||""),[P,_]=I.useState(t.valueAliases||{}),[U,Y]=I.useState((ft=t.parameters)==null?void 0:ft.filters),X=H=>{H==="custom"?J(!0):(J(!1),M(H),a==="groupBy"&&y(n,H,""))},$=H=>{z(H),a==="groupBy"&&y(n,"custom",H)},ee=H=>{var ue;W(H);const oe=(ue=Te(H)[0])==null?void 0:ue.value;oe&&!V&&(M(oe),a==="groupBy"&&y(n,oe,"")),a==="groupBy"&&x(n,H)},te=H=>{G(H),a==="metrics"&&b(n,H)},ie=H=>{_(H),a==="metrics"&&k(n,H)},K=H=>{j(a,n,H)},Q=H=>{var le;if(Y(H),a==="metrics"){const oe={...t,parameters:{...t.parameters,filters:H}},ue=[...((le=g.config)==null?void 0:le.metricColumns)||[]];ue[n]=oe,s.useEditorStore.getState().actions.updateCardConfig(g.id,{metricColumns:ue})}S(!1)},ne=()=>{O(a,n)},de={transform:s.CSS.Transform.toString(m),transition:h},Fe=s.getDataType(t.dataType),ke=Fe==="date",De=c==="kpi",Te=H=>{switch(H){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..."}]}},ae=Te(Z),he=a!=="pivotBy",ls=ke&&a==="groupBy",os=!De&&ke&&a==="groupBy",is=De&&ke&&a==="groupBy",Xe=De&&a==="metrics"&&((gt=g.config)==null?void 0:gt.comparisonType)==="target",Ee=a==="metrics",ce=()=>e.jsx("div",{onPointerDown:H=>{H.stopPropagation()},className:"cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),$a=()=>he?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(be,{value:t.label??"",onSave:K,placeholder:"Display label...",type:"text"})]}):null,pt=()=>ls?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:ee,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(H=>e.jsx(s.SelectItem,{className:"text-xs",value:H,children:s.toTitleCase(H)},H))})]})]}):null,qa=()=>os?e.jsxs(e.Fragment,{children:[pt(),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:V?"custom":B,onValueChange:X,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:ae.map(H=>e.jsx(s.SelectItem,{className:"text-xs",value:H.value,children:H.label},H.value))})]}),V&&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:R,onChange:H=>{H.stopPropagation(),$(H.target.value)},onClick:H=>H.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,Ya=()=>{var H,le,oe,ue,Ie;return is?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:((H=g.config)==null?void 0:H.comparisonType)||"none",onValueChange:N,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:((le=g.config)==null?void 0:le.showTrendline)||!1,onCheckedChange:C})]})}),((oe=g.config)==null?void 0:oe.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=g.config)==null?void 0:ue.trendlineWindow)||30,onChange:cs=>{const Wa=parseInt(cs.target.value)||30;v(Wa)},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:((Ie=g.config)==null?void 0:Ie.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},Ga=()=>{var H,le;return Xe?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(be,{value:((H=g.config)==null?void 0:H.targetValue)!==void 0&&((le=g.config)==null?void 0:le.targetValue)!==null?String(g.config.targetValue):"",onSave:oe=>{!isNaN(Number(oe))&&oe!==null?E(Number(oe)):E(0)},placeholder:"Enter target value...",type:"text"})]}):null},Ha=()=>Ee?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:H=>{p(n,H)},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.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(U==null?void 0:U.conditions)&&U.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:U.conditions.map(H=>e.jsxs("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{A(H),S(!0)},children:[e.jsxs("span",{className:"font-medium",children:[H.field.label,":"]}),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(H.value)?H.value.length===1?String(H.value[0]):H.value.length<=2?H.value.join(", "):`${H.value.slice(0,2).join(", ")} +${H.value.length-2}`:String(H.value)})}),Array.isArray(H.value)&&H.value.length>1&&e.jsx(s.TooltipContent,{side:"top",className:"max-w-[300px]",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"mb-1 font-medium",children:["Selected values (",H.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:H.value.map((le,oe)=>e.jsx("div",{children:String(le)},oe))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:le=>{var ue;le.stopPropagation();const oe=U.conditions.filter(Ie=>Ie.id!==H.id);if(oe.length>0){const Ie={...U,conditions:oe};Q(Ie)}else if(Y(void 0),a==="metrics"){const Ie={...t,parameters:{...t.parameters,filters:void 0}},cs=[...((ue=g.config)==null?void 0:ue.metricColumns)||[]];cs[n]=Ie,s.useEditorStore.getState().actions.updateCardConfig(g.id,{metricColumns:cs})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},H.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{A(null),S(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(za,{column:t}),o&&e.jsxs(e.Fragment,{children:[e.jsx(_o,{aliasTemplate:q,onAliasTemplateChange:te}),e.jsx(Uo,{valueAliases:P,onValueAliasesChange:ie})]})]}):null,{columns:Ka=[]}=s.useColumns(),Qa=(U==null?void 0:U.conditions)&&U.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:de,...i,...d,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 ${f?"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(ht,{dataType:Fe}),e.jsx(Ds,{className:s.cn("w-[140px] flex-1 text-sm",Qa&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),a==="metrics"&&((jt=U==null?void 0:U.conditions)==null?void 0:jt.length)&&!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-1 rounded bg-primary/10 px-1.5 py-0.5 text-xs",children:[e.jsx(s.Filter,{className:"h-3 w-3"}),e.jsx("span",{children:U.conditions.length})]})}),e.jsx(s.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:U.conditions.map(H=>e.jsxs("div",{children:[H.field.label,":"," ",Array.isArray(H.value)?`${H.value.length} values`:String(H.value)]},H.id))})})]})}),a!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:H=>{H.stopPropagation(),w(!L)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${L?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:H=>{H.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const le=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",le),l(le)},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:H=>{H.stopPropagation(),ne()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),L&&e.jsxs("div",{className:"space-y-3",children:[ce(),$a(),c==="kpi"&&pt(),qa(),Ya(),Ga(),Ha()]})]}),F&&e.jsx(qo,{open:F,onOpenChange:H=>{S(H),H||A(null)},availableFields:Ka,existingFilters:U,editingCondition:T,onSave:H=>{var le;if(H)Q(H);else if(Y(void 0),a==="metrics"){const oe={...t,parameters:{...t.parameters,filters:void 0}},ue=[...((le=g.config)==null?void 0:le.metricColumns)||[]];ue[n]=oe,s.useEditorStore.getState().actions.updateCardConfig(g.id,{metricColumns:ue})}A(null)}})]})}function Ho({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 ms({zone:t,fields:a,label:n,placeholder:r,shouldShow:l,hasPivotColumns:o=!1}){const{isOver:c,setNodeRef:i}=s.useDroppable({id:t}),{updateSortByColumn:d}=s.useEditorActions(),u=s.useEditorStore(j=>j.card),m=s.useEditorStore(j=>j.card.type),h=a.length>0,f=(j,p)=>{var x;!((x=u.config)!=null&&x.sortByColumns)||u.config.sortByColumns.findIndex(b=>b.id===j)===-1||d(u.id,j,{direction:p})};if(t==="sortBy"&&l===!1)return null;const g=t!=="sortBy"&&m!=="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}),g&&e.jsx(Ho,{concept:t})]}),e.jsx("div",{ref:i,className:`rounded-lg border-2 border-dashed p-1 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":"min-h-[60px] 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(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:a.map((j,p)=>{const x=j.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(Go,{field:j,zone:t,index:p,sortDirection:x,onSortDirectionChange:b=>f(j.id,b),hasPivotColumns:o,cardType:m})})},j.id)})})})})]})}const Bt=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Ko=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function Bs({value:t,onChange:a,label:n}){const[r,l]=I.useState(!1),[o,c]=I.useState(!1),i=()=>{const d=Bt.find(u=>u.value===t);return d?d.color:t.startsWith("#")?t:Bt[2].color};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:r,onOpenChange:l,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"size-5 rounded border-2 border-input shadow-sm transition-all hover:scale-110 hover:border-gray-400",style:{backgroundColor:i()},"aria-label":`Change color for ${n}`})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-3 items-center justify-items-center gap-1",children:Ko.map(d=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",i()===d?"border-gray-900":"border-transparent"),style:{backgroundColor:d},onClick:()=>{a(d),l(!1)},children:e.jsx("span",{className:"sr-only",children:d})},d))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{c(!0),l(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:n})]}),o&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>c(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(La,{color:i(),onColorChange:d=>{a(d),c(!1)},onClose:()=>c(!1)})})]})]})}const hs={difference:{label:"Difference",description:"Shows the exact difference between two values.",formula:"Primary - Secondary",example:"Sales increased by $5,000 compared to last year."},change:{label:"Change",description:"Shows the percentage increase or decrease between two values.",formula:"(Primary - Secondary) / Secondary × 100%",example:"Year-over-year sales change of 25%."},change_difference:{label:"Change (difference)",description:"Shows both the percentage change and the exact difference between two values.",formula:`% Change: (Primary - Secondary) / Secondary × 100%
|
|
421
|
-
Difference: Primary - Secondary`,example:"Sales grew by 25% ($5,000) compared to last year."},ratio:{label:"Ratio",description:"Shows how much of one value is covered by another — useful for quotas and benchmarks.",formula:"Primary / Secondary × 100%",example:"You've achieved 80% of your sales quota."}};function Qo(){var i,d,u,m,h,f,g,j,p,y;const t=s.useEditorStore(x=>x.card),{setCardPreferences:a}=s.useEditorActions(),n=((i=t.config)==null?void 0:i.metricColumns)||[],r=((d=t.config)==null?void 0:d.groupByColumns)||[];if(!(t.type==="kpi"&&(n.length>=2&&r.length===0||n.length>=1&&r.length>0)))return null;const o=((m=(u=t.preferences)==null?void 0:u.kpiVisualOptions)==null?void 0:m.metricComparison)||{},c=x=>{var k;const b={...t.preferences,kpiVisualOptions:{...(k=t.preferences)==null?void 0:k.kpiVisualOptions,metricComparison:{...o,...x}}};a(b)};return e.jsxs(s.AccordionItem,{value:"comparison",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bn,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"enable-comparison",className:"text-xs",children:"Enable Metric Comparison"}),e.jsx(s.SmallSwitch,{id:"enable-comparison",checked:o.enabled||!1,onCheckedChange:x=>c({enabled:x,...x&&!o.calculationType?{calculationType:"difference"}:{}})})]}),o.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"calculation-type",className:"text-xs font-medium uppercase text-muted-foreground",children:"Calculated as"}),e.jsxs(s.Select,{value:o.calculationType||"difference",onValueChange:x=>c({calculationType:x}),children:[e.jsx(s.SelectTrigger,{id:"calculation-type",className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Object.entries(hs).map(([x,b])=>e.jsx(s.SelectItem,{value:x,className:"text-xs",children:b.label},x))})]}),(()=>{var b,k,O;const x=o.calculationType||"difference";return e.jsxs("div",{className:"space-y-2 rounded-md bg-muted/50 p-2 text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:(b=hs[x])==null?void 0:b.description}),e.jsxs("div",{className:"text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Formula:"})," ",e.jsx("code",{className:"rounded bg-background px-1 py-0.5 text-[10px]",children:(k=hs[x])==null?void 0:k.formula})]}),e.jsxs("div",{className:"border-t pt-1 italic text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",(O=hs[x])==null?void 0:O.example]})]})})()]}),e.jsx(ct,{formatOptions:o.formatOptions||{},onFormatOptionsChange:x=>c({formatOptions:x}),showTitle:!0,title:"COMPARISON FORMAT"}),e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Indicator"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Position"}),e.jsxs(s.Select,{value:o.position||"left",onValueChange:x=>c({position:x}),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",className:"text-xs",children:"Top"}),e.jsx(s.SelectItem,{value:"left",className:"text-xs",children:"Left"}),e.jsx(s.SelectItem,{value:"right",className:"text-xs",children:"Right"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-arrow",checked:o.showArrow!==!1,onCheckedChange:x=>c({showArrow:x})}),e.jsx(s.Label,{htmlFor:"show-arrow",className:"cursor-pointer text-xs text-muted-foreground",children:"Arrow"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-color",checked:o.showColor!==!1,onCheckedChange:x=>c({showColor:x})}),e.jsx(s.Label,{htmlFor:"show-color",className:"cursor-pointer text-xs text-muted-foreground",children:"Color"})]}),o.showColor!==!1&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-3",children:[e.jsx(Bs,{value:((h=o.colorConfig)==null?void 0:h.increase)||"green",onChange:x=>c({colorConfig:{...o.colorConfig,increase:x}}),label:"Primary > Secondary"}),e.jsx(Bs,{value:((f=o.colorConfig)==null?void 0:f.decrease)||"red",onChange:x=>c({colorConfig:{...o.colorConfig,decrease:x}}),label:"Primary < Secondary"}),e.jsx(Bs,{value:((g=o.colorConfig)==null?void 0:g.noChange)||"neutral",onChange:x=>c({colorConfig:{...o.colorConfig,noChange:x}}),label:"Primary = Secondary"})]})]}),e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Label"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"conditional-label",checked:o.conditionalLabel||!1,onCheckedChange:x=>c({conditionalLabel:x})}),e.jsx(s.Label,{htmlFor:"conditional-label",className:"cursor-pointer text-xs text-muted-foreground",children:"Conditional"})]}),o.conditionalLabel?e.jsxs("div",{className:"space-y-3 border-l-2 border-muted pl-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-increase",className:"text-xs text-muted-foreground",children:["Primary ",">"," Secondary"]}),e.jsx(s.Input,{id:"label-increase",type:"text",value:((j=o.conditionalLabels)==null?void 0:j.increase)??"Increase",onChange:x=>c({conditionalLabels:{...o.conditionalLabels,increase:x.target.value}}),placeholder:"Increase",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-decrease",className:"text-xs text-muted-foreground",children:["Primary ","<"," Secondary"]}),e.jsx(s.Input,{id:"label-decrease",type:"text",value:((p=o.conditionalLabels)==null?void 0:p.decrease)??"Decrease",onChange:x=>c({conditionalLabels:{...o.conditionalLabels,decrease:x.target.value}}),placeholder:"Decrease",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-no-change",className:"text-xs text-muted-foreground",children:"Primary = Secondary"}),e.jsx(s.Input,{id:"label-no-change",type:"text",value:((y=o.conditionalLabels)==null?void 0:y.noChange)??"No change",onChange:x=>c({conditionalLabels:{...o.conditionalLabels,noChange:x.target.value}}),placeholder:"No change",className:"h-7 text-xs"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-name",className:"text-xs text-muted-foreground",children:"Name"}),e.jsx(s.Input,{id:"label-name",type:"text",value:o.labelName??"",onChange:x=>c({labelName:x.target.value}),placeholder:"e.g. Versus, Compared to",className:"h-7 text-xs"})]})]})]})]})]})}function Wo(){var l,o;const t=s.useEditorStore(c=>c.card),{setCardPreferences:a}=s.useEditorActions();if(t.type!=="kpi")return null;const n=((o=(l=t.preferences)==null?void 0:l.kpiVisualOptions)==null?void 0:o.formatOptions)||{},r=c=>{var d;const i={...t.preferences,kpiVisualOptions:{...(d=t.preferences)==null?void 0:d.kpiVisualOptions,formatOptions:c}};a(i)};return e.jsxs(s.AccordionItem,{value:"kpi-format",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"}),e.jsx("span",{children:"Number Format"})]})}),e.jsx(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:e.jsx(ct,{formatOptions:n,onFormatOptionsChange:r,showTitle:!1})})]})}function Jo({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r}){const l=s.useEditorStore(j=>{var p;return((p=j.card.customCardPreferences)==null?void 0:p.url)&&j.card.type==="custom"}),o=s.useEditorStore(j=>j.card),c=o==null?void 0:o.type,i=t.length>0||n.length>0,d=c!=="kpi",u=c!=="kpi"&&i,m=["pie","doughnut","polar","funnel"].includes(c),h=d&&!m,f=()=>c==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},g=()=>c==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Metrics",placeholder:"Drop fields to measure"};return e.jsxs(s.Accordion,{type:"single",collapsible:!0,defaultValue:"fields",className:"w-full",children:[e.jsxs(s.AccordionItem,{value:"fields",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(In,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"FIELDS"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsx(ms,{zone:"groupBy",fields:t,label:f().label,placeholder:f().placeholder}),h&&e.jsx(ms,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(ms,{zone:"metrics",fields:n,label:g().label,placeholder:g().placeholder,hasPivotColumns:a.length>0}),u&&e.jsx(ms,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields from Rows or Metrics"})]})]}),!l&&e.jsxs(s.AccordionItem,{value:"configuration",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Settings,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"CONFIGURATION"})]})}),e.jsx(s.AccordionContent,{className:"rounded-md border border-border bg-muted/50 px-3 py-0",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[e.jsx(Wo,{}),e.jsx(Qo,{}),e.jsx(Ra,{}),e.jsx(Oa,{}),e.jsx(Fa,{}),e.jsx(Ba,{})]})})]})]})}function Xo({selectedChart:t,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:l,sortByFields:o}){const c=s.useEditorStore(h=>h.showAIDialog),i=n.length>0||r.length>0||l.length>0,{setShowAIDialog:d}=s.useEditorActions(),u=s.useEditorStore(h=>h.card),{data:m}=s.useDashboardCardQuery(u);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(zo,{selectedChart:t,onChartChange:a})]}),e.jsxs("div",{className:s.cn("flex justify-end gap-2 px-6 py-6"),children:[e.jsx("div",{className:s.cn("invisible",{visible:i||m}),children:e.jsx(ws,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(s.Sparkles,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6 pb-6",children:[e.jsx(Jo,{groupByFields:n,pivotByFields:r,metricsFields:l,sortByFields:o}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Zo({initialFilters:t,availableFields:a}={}){const[n,r]=I.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(N=>N.card.dataSource);const{columns:l,isLoading:o}=s.useColumns(),i=a||l||[],d={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=N=>{const C=v=>{if(v.id===N){const D=i[0]||d;return{...v,conditions:[...v.conditions,{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}]}}return{...v,groups:v.groups.map(C)}};r(C(n))},m=N=>{const C=v=>{if(v.id===N){const D=i[0]||d;return{...v,groups:[...v.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:D,operator:"=",value:""}],groups:[]}]}}return{...v,groups:v.groups.map(C)}};r(C(n))},h=(N,C)=>{const v=D=>D.id===N?{...D,conditions:D.conditions.filter(E=>E.id!==C)}:{...D,groups:D.groups.map(v)};r(v(n))},f=(N,C)=>{const v=D=>D.id===N?{...D,groups:D.groups.filter(E=>E.id!==C)}:{...D,groups:D.groups.map(v)};r(v(n))},g=(N,C,v,D)=>{if(v==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const E=L=>L.id===N?{...L,conditions:L.conditions.map(w=>w.id===C?{...w,[v]:D}:w)}:{...L,groups:L.groups.map(E)};r(E(n))},j=(N,C,v)=>{const D=E=>E.id===N?{...E,conditions:E.conditions.map(L=>L.id===C?{...L,...v}:L)}:{...E,groups:E.groups.map(D)};r(D(n))},p=(N,C)=>{const v=D=>D.id===N?{...D,logicalOperator:C}:{...D,groups:D.groups.map(v)};r(v(n))},y=(N,C)=>{const v=D=>D.id===N?{...D,negate:C}:{...D,groups:D.groups.map(v)};r(v(n))},x=(N,C,v)=>{const D=E=>E.id===N?{...E,conditions:s.arrayMove(E.conditions,C,v)}:{...E,groups:E.groups.map(D)};r(D(n))},b=(N,C,v)=>{const D=E=>E.id===N?{...E,groups:s.arrayMove(E.groups,C,v)}:{...E,groups:E.groups.map(D)};r(D(n))},k=N=>{if(!N||N.conditions.length===0&&N.groups.length===0)return"-- No filters defined";const C=D=>{let E="";typeof D.field=="object"?E=D.field.entityName?`${D.field.entityName}.${D.field.name}`:D.field.name:E=String(D.field);const L=D.operator;let w=D.value;if(D.field.dataType==="string"&&!["in","not in"].includes(D.operator))typeof w=="string"?w=`'${w}'`:Array.isArray(w)&&(w=`'${w.join(", ")}'`);else if(D.field.dataType==="date")(typeof w=="string"||w instanceof Date)&&(w=`DATE('${w}')`);else if(["in","not in"].includes(D.operator)){let F=[];Array.isArray(w)?F=w.map(S=>typeof S=="string"?`'${S}'`:String(S)):typeof w=="string"?F=w.split(",").map(S=>{const T=S.trim();return D.field.dataType==="string"?`'${T}'`:T}):typeof w=="number"&&(F=[String(w)]),w=`(${F.join(", ")})`}switch(L){case"contains":return typeof w=="string"?`${E} LIKE '%${w.replace(/'/g,"")}'`:`${E} LIKE '%${String(w)}'`;case"startsWith":return typeof w=="string"?`${E} LIKE '${w.replace(/'/g,"")}%'`:`${E} LIKE '${String(w)}%'`;case"endsWith":return typeof w=="string"?`${E} LIKE '%${w.replace(/'/g,"")}'`:`${E} LIKE '%${String(w)}'`;default:return`${E} ${L} ${w}`}},v=D=>{const E=D.conditions.map(C),L=D.groups.map(T=>v(T)),w=[...E,...L].filter(Boolean);if(w.length===0)return"";const F=w.join(` ${D.logicalOperator} `),S=w.length>1?`(${F})`:F;return D.negate?`NOT ${S}`:S};return v(N)},O=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:i,isLoading:o,addCondition:u,addGroup:m,removeCondition:h,removeGroup:f,updateCondition:g,updateConditionFields:j,updateGroupOperator:p,updateGroupNegate:y,reorderConditions:x,reorderGroups:b,generateSQLPreview:k,hasAnyFilters:O}}function ei({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(jn,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},ti=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function ai({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:l="w-64"}){const[o,c]=I.useState(!1),i=I.useMemo(()=>{const d={};return n.forEach(u=>{const m=ti(u);d[m]||(d[m]={}),d[m][u.entityId]||(d[m][u.entityId]=[]),d[m][u.entityId].push(u)}),d},[n]);return e.jsxs(s.Popover,{modal:!0,open:o,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:s.cn("justify-between",!t&&"text-muted-foreground",l),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(ei,{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(i).map(([d,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(u).map(([m,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((f,g)=>e.jsxs(s.CommandItem,{value:f.id,onSelect:()=>{a(f),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)===f.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:f.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:f.description&&e.jsx("span",{children:f.description})})]})]},f.id+g))]},`${d}-${m}`))},d))})]})})]})}function xt(t){var j;const a=s.useEditorStore(p=>p.card),{authToken:n}=s.useSemaphorContext(),r=s.useEditorStore(p=>p.card.config),l=r==null?void 0:r.joinPlan,o={...t,alias:t.name,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},i={...o,role:"sortby",direction:"asc"},d={joinPlan:l,groupByColumns:[o],metricColumns:[c],sortByColumns:[i]},u=((j=a.dataSource)==null?void 0:j.connectionId)||a.connectionId,{data:m,isPending:h,error:f}=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:u,cardConfig:d,cardDataSource:a.dataSource})}catch(p){console.log(t),console.error("error",p)}},enabled:!!u,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((m==null?void 0:m.records)||[]).map(p=>({label:p[t.name]||"BLANK",value:p[t.name]||"BLANK",count:(p==null?void 0:p.count)||0})),isPending:h,error:f}}function ni({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:l}){const[o,c]=xe.useState(!1),{filterValues:i}=xt(t),d=m=>{n(a.filter(h=>h!==m))},u=m=>{a.includes(m)?n(a.filter(h=>h!==m)):n([...a,m])};return e.jsx("div",{className:s.cn("w-full",l),children:e.jsxs(s.Popover,{open:o,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,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(m=>{const h=i.find(f=>f.value===m);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:f=>{f.key==="Enter"&&d(m)},onMouseDown:f=>{f.preventDefault(),f.stopPropagation()},onClick:f=>{f.stopPropagation(),d(m)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},m)}):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:i.map((m,h)=>e.jsxs(s.CommandItem,{onSelect:()=>u(m.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(m.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.count})]})]},m.value+h))})]})]})})]})})}const _a=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=_a(n)}),a};function ri({field:t,value:a,onChange:n,placeholder:r="Select value...",className:l}){const{filterValues:o,isPending:c,error:i}=xt(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..."]}):i?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:l||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:a})}),e.jsx(s.SelectContent,{children:o.map((d,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+u))})]})}const li=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],oi=["=","!=","contains","startsWith","endsWith","in","not in"],ii=["=","!=",">",">=","<","<=","in","not in"],ci=["=","!="],di=["=","!=",">",">=","<","<=","in","not in"];function ui(t){switch(t){case"string":return oi;case"number":return ii;case"boolean":return ci;case"date":return di;default:return li}}function Ua({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:l,onRemoveCondition:o,onUpdateGroupOperator:c,availableFields:i,updateConditionFields:d}){const{attributes:u,listeners:m,setNodeRef:h,transform:f,transition:g,isDragging:j}=s.useSortable({id:t.id}),{isPending:p,error:y}=xt(t.field),x={transform:s.CSS.Transform.toString(f),transition:g};return e.jsxs("div",{ref:h,style:x,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${j?"z-50 opacity-50":""}`,children:[e.jsx("div",{...u,...m,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:b=>c(n,b),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(ai,{value:t.field,onValueChange:b=>{d(n,t.id,{field:b,value:""})},availableFields:i,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:b=>{b==="in"||b==="not in"?d(n,t.id,{operator:b,value:[]}):d(n,t.id,{operator:b,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ui(s.getDataType(t.field.dataType)).map(b=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:b,children:b},b))})]}),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..."]}):y?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(ni,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(b=>typeof b=="string")?t.value:[],onChange:b=>d(n,t.id,{value:b}),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:b=>d(n,t.id,{value:b.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(ri,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:b=>d(n,t.id,{value:b}),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:b=>d(n,t.id,{value:b==="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:b=>l(n,t.id,"value",b.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:()=>o(n,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function mi({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:l,onRemoveGroup:o,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onReorderConditions:u,onReorderGroups:m,onAddCondition:h,onAddGroup:f,availableFields:g,renderFilterGroup:j,updateConditionFields:p}){const{attributes:y,listeners:x,setNodeRef:b,transform:k,transition:O,isDragging:N}=s.useSortable({id:t.id}),C={transform:s.CSS.Transform.toString(k),transition:O},v=E=>{const{active:L,over:w}=E;if(w&&L.id!==w.id){const F=t.conditions.findIndex(T=>T.id===L.id),S=t.conditions.findIndex(T=>T.id===w.id);F!==-1&&S!==-1&&u(t.id,F,S)}},D=E=>{const{active:L,over:w}=E;if(w&&L.id!==w.id&&n){const F=t.groups.findIndex(T=>T.id===L.id),S=t.groups.findIndex(T=>T.id===w.id);F!==-1&&S!==-1&&m(n,F,S)}};return e.jsxs("div",{ref:b,style:C,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${N?"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",{...y,...x,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:()=>l(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:E=>r(t.id,E),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&&o(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:v,children:e.jsx(s.SortableContext,{items:t.conditions.map(E=>E.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((E,L)=>e.jsx(Ua,{condition:E,index:L,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:g,updateConditionFields:p},E.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(E=>E.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(E=>j(E,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:()=>f(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function hi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:l}){const{currentFilters:o,availableFields:c,isLoading:i,addCondition:d,addGroup:u,removeCondition:m,removeGroup:h,updateCondition:f,updateConditionFields:g,updateGroupOperator:j,updateGroupNegate:p,reorderConditions:y,reorderGroups:x,generateSQLPreview:b,hasAnyFilters:k,setCurrentFilters:O}=Zo({initialFilters:t,availableFields:a}),N=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[C,v]=I.useState(!1),D=(w,F,S)=>{const T=A=>A.id===w?{...A,conditions:A.conditions.map(B=>B.id===F?{...B,field:S,dataType:S.dataType}:B)}:{...A,groups:A.groups.map(T)};O(T(o))},E=(w,F=0,S)=>F===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:N,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:A,over:B}=T;if(B&&A.id!==B.id){const M=w.conditions.findIndex(z=>z.id===A.id),R=w.conditions.findIndex(z=>z.id===B.id);M!==-1&&R!==-1&&y(w.id,M,R)}},children:e.jsx(s.SortableContext,{items:w.conditions.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.conditions.map((T,A)=>e.jsx(Ua,{condition:T,index:A,groupId:w.id,groupLogicalOperator:w.logicalOperator,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onUpdateGroupOperator:j,availableFields:c,updateConditionFields:g},T.id))})}),e.jsx(s.DndContext,{sensors:N,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:A,over:B}=T;if(B&&A.id!==B.id){const M=w.groups.findIndex(z=>z.id===A.id),R=w.groups.findIndex(z=>z.id===B.id);M!==-1&&R!==-1&&x(w.id,M,R)}},children:e.jsx(s.SortableContext,{items:w.groups.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.groups.map(T=>E(T,F+1,w.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:()=>d(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),C&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},w.id):e.jsx(mi,{group:w,depth:F,parentGroupId:S,onUpdateGroupOperator:j,onUpdateGroupNegate:p,onRemoveGroup:h,onUpdateCondition:f,onUpdateField:D,onRemoveCondition:m,onReorderConditions:y,onReorderGroups:x,onAddCondition:d,onAddGroup:u,availableFields:c,renderFilterGroup:E,updateConditionFields:g},w.id),L=_a(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:[i?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..."})]}):E(o),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:C,onCheckedChange:w=>v(!!w)}),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:b(o)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:l,children:"Cancel"}),L>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(k?o:null),children:"Apply Filters"})]})]})}function xi({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:l,isOpen:o,onOpenChange:c}){const i=u=>{n(t,u),c(!1)},d=()=>{r(t),c(!1)};return e.jsxs(s.Dialog,{modal:!1,open:o,onOpenChange:c,children:[o&&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:u=>{u.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(hi,{filters:a,availableFields:l,onSave:i,onCancel:()=>c(!1),onClearAll:d})]})]})}function pi({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var g;const[l,o]=I.useState(null),c=s.useEditorStore(j=>j.card),i=(g=c==null?void 0:c.config)==null?void 0:g.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],u=I.useCallback(j=>j.startsWith("card-")?null:j.startsWith("source-")||a.find(p=>p.id===j)?"source":n("groupBy").find(p=>p.id===j)?"groupBy":n("metrics").find(p=>p.id===j)?"metrics":n("pivotBy").find(p=>p.id===j)?"pivotBy":n("sortBy").find(p=>p.id===j)?"sortBy":null,[a,n]),m=I.useCallback(j=>{o(j.active.id)},[]),h=I.useCallback(j=>{const{active:p,over:y}=j;if(!y||!t){o(null);return}const x=p.id,b=y.id,k=u(x),O=u(b)||b;if(k==="source"&&O==="sortBy"){o(null);return}if(k==="source"&&O!=="source"&&O!=="sortBy"){const N=[...a].find(E=>E.id===x);if(!N){o(null);return}const C=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(C.length>0){const E=C[0].qualifiedEntityName;if(!E){o(null);return}if(E!==N.qualifiedEntityName&&N.qualifiedEntityName)if(i){if(!s.areEntitiesJoined(E,N.qualifiedEntityName,i)){s.showJoinRequiredNotification(),o(null);return}}else{s.showJoinRequiredNotification(),o(null);return}}const v=n(O);if(s.fieldAlreadyExists(N,v)){o(null);return}const D=s.getNewField(N,O,v);o(null),r(O,[...v,D]);return}if(k&&O&&k!=="source"&&O!=="source"&&k!==O){const N=n(k),C=n(O),v=N.find(L=>L.id===x);if(!v){o(null);return}const D=s.getNewField(v,O,C);if(o(null),O==="sortBy"){if(k==="pivotBy"){o(null);return}s.fieldAlreadyExists(v,C)||r(O,[...C,D]);return}const E=N.filter(L=>L.id!==x);r(k,E),r(O,[...C,D]);return}if(k&&O&&k===O&&k!=="source"){const N=n(k),C=N.findIndex(D=>D.id===x),v=N.findIndex(D=>D.id===b);if(C!==v){const D=s.arrayMove(N,C,v);r(k,D)}}o(null)},[t,a,n,r,u,i]),f=l?d.find(j=>j.id===l):null;return{activeId:l,activeField:f,handleDragStart:m,handleDragEnd:h}}function fi({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const{currentUser:r}=we();r==null||r.role;const[l,o]=I.useState(!1),c=s.useEditorStore(x=>x.isDevMode),i=s.useEditorStore(x=>x.card),d=s.useEditorStore(x=>x.card.dataSource);s.isExplorerCard(i);const{config:u}=I.useContext(s.SemaphorContext).tokenProps,m=(u==null?void 0:u.showAdvancedMode)!==!1,{setIsDevMode:h}=s.useEditorActions(),f=s.useEditorStore(x=>x.showAIDialog),g=s.useEditorStore(x=>x.frame),j=s.useManagementStore(x=>x.selectedVisual),p=(j==null?void 0:j.id)===(g==null?void 0:g.id),{setShowAIDialog:y}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",f&&"justify-end",!m&&"justify-end"),children:[m&&t&&!f&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{className:s.cn("",{}),checked:c,onCheckedChange:()=>h(!c),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:[(r==null?void 0:r.type)!=="tenant"&&e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 p-0",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>{o(!0)},children:[e.jsx(s.Database,{className:"mr-2 h-4 w-4"}),"Set Data Context"]})})]}),e.jsx(tt,{}),n&&!p&&e.jsx(st,{variant:"default"}),p&&e.jsx(hl,{}),a&&s.isDevEnv]}),l&&e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],open:l,onOpenChange:o,dataSource:d||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function gi({activeView:t,onViewChange:a}){const n=s.useEditorStore(l=>l.card),{errorMessage:r}=s.useDashboardCardQuery(n);return e.jsx(s.Tabs,{value:t,onValueChange:l=>a(l),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 ji=[{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 yi(){var d,u;const t=s.useEditorStore(m=>m.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=I.useState(!1),[l,o]=I.useState(""),c=m=>{if(m==="custom"){r(!0);return}r(!1),a(t.id,parseInt(m))},i=m=>{const h=m.target.value;o(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:l,onChange:i,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((u=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:u.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:ji.map(m=>e.jsx(s.SelectItem,{value:m.value,children:m.label},m.value))})]})})}function vi({isOpen:t,onClose:a}){const n=na(a,{enabled:t}),r=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.url)||""}),l=s.useEditorStore(m=>m.card),o=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(m=>{var h;return((h=m.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:i}=s.useDashboardCardQuery(l),{getCard:d}=s.useCustomVisual(r),u=I.useMemo(()=>!r||r.trim()===""?null:d("Chart Settings"),[d,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:u&&e.jsx(I.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(u,{chartData:(i==null?void 0:i.records)||[],chartType:o,settings:c})})})]})})}function bi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:l,onClear:o,onAdvancedToggle:c,onFiltersClick:i,filterCount:d,activeCard:u,columns:m,columnsLoading:h,columnsError:f}){var B;const g=s.useEditorStore(M=>M.card);s.useEditorStore(M=>M.frame);const j=s.useDashboardStore(M=>M.filterValues),{updateCardConfig:p,setCard:y,updateCardInFrame:x}=s.useEditorActions(),b=s.useEditorStore(M=>M.showAIDialog),[k,O]=I.useState(!1),N=s.useEditorStore(M=>{var R;return((R=M.card.customCardPreferences)==null?void 0:R.url)&&M.card.type==="custom"}),{data:C,errorMessage:v,isPending:D,isLoading:E,isFetching:L,pagination:w}=s.useDashboardCardQuery(u),F=(M,R)=>{const z={...u,paginationConfig:{page:M+1,pageSize:R}};y(z),x(z)};function S(){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(g.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(j||{},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(u.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",m.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":f?"Error loading columns":JSON.stringify(m.slice(0,5),null,2)})]})]})})}const T=M=>{if(!g.config)return;if(!M.length){p(g.id,{...g.config,sortByColumns:[]});return}const R=g.config,z=M.map(({id:V,desc:J})=>{var G,P;const Z=(G=R.metricColumns)==null?void 0:G.find(_=>_.label===V),W=(P=R.groupByColumns)==null?void 0:P.find(_=>_.label===V),q=Z||W;return q?{id:s.getFieldId("sortBy",q),name:q.name,dataType:q.dataType,label:q.label,qualifiedEntityName:q.qualifiedEntityName,entityId:q.entityId,entityName:q.entityName,entityType:q.entityType,role:"sortby",direction:J?"desc":"asc"}:null}).filter(V=>V!==null);p(g.id,{...R,sortByColumns:z})},A=I.useMemo(()=>{var M,R;return(R=(M=g.config)==null?void 0:M.sortByColumns)==null?void 0:R.map(z=>({id:z.label,desc:z.direction==="desc"}))},[(B=g.config)==null?void 0:B.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(fi,{showDebug:n,onDebugToggle:r,onAccept:l,onClear:o,onAdvancedToggle:c,onFiltersClick:i,filterCount:d}),n&&S(),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"&&b&&e.jsx(ka,{variant:"outline"}),e.jsx(gi,{activeView:t,onViewChange:a}),i&&e.jsxs(s.IconButton,{tooltip:"Card Filters",className:"h-8 gap-1",onClick:i,children:[e.jsx(s.Filter,{className:"h-3.5 w-3.5"}),d>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:d})]}),e.jsx("div",{className:"ml-2",children:e.jsx(yi,{})}),b&&e.jsx(ws,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(Da,{})})]}),!k&&N&&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(s.Settings2,{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(Ta,{})}),t==="table"&&(C==null?void 0:C.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:u,data:(C==null?void 0:C.records)||[],paginationMetadata:w,onPaginationChange:F,isLoading:E||L,onSortChange:T,sortState:A})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(C==null?void 0:C.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(ga,{sql:C==null?void 0:C.sql,error:v})]})})]}),e.jsx(vi,{isOpen:k,onClose:()=>O(!1)})]})]})}function Ni({activeField:t}){const[a,n]=I.useState(!0);return I.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(ht,{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 Ci=()=>{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 l;if((l=r.reason)!=null&&l.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 Si(){var W,q;const[t,a]=I.useState("chart"),[n,r]=I.useState(!1),[l,o]=I.useState(!1),[c,i]=I.useState(!0),d=s.useEditorStore(G=>G.showAIDialog),u=s.useDashboardStore(G=>G.isVisualEditing),{setCardType:m}=s.useEditorActions(),h=s.useEditorStore(G=>G.card.type);I.useEffect(()=>Ci(),[]);const f=()=>{console.log("Accept clicked - would save/apply current configuration")},g=()=>{console.log("Clear clicked - would reset all configurations")},j=()=>{console.log("Advanced mode toggled")},p=()=>{o(!0)},y=G=>{m(G)},x=s.useEditorStore(G=>G.frame),b=s.useEditorStore(G=>G.card);s.useEditorStore(G=>G.activeTabCardId),s.useEditorStore(G=>G.actions.getAvailableFields);const{addCard:k,removeCard:O,updateCard:N,setActiveCard:C,updateFilters:v}=s.useEditorActions(),{columns:D=[],isLoading:E,error:L}=s.useColumns(),w=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),F=b,{getFieldsForContainer:S,setFieldsForContainer:T}=ut(F),{activeField:A,handleDragStart:B,handleDragEnd:M}=pi({activeCardId:x.activeCardId,sourceFields:D,getFieldsForContainer:S,setFieldsForContainer:T}),R=(G,P)=>{P&&v(G,P)},z=G=>{var P;N(G,{config:{...(P=x.cards.find(_=>_.id===G))==null?void 0:P.config,filters:void 0}})},V=D,J=G=>{if(!G)return 0;let P=G.conditions.length;return G.groups.forEach(_=>{P+=J(_)}),P},Z=J(((W=F==null?void 0:F.config)==null?void 0:W.filters)||null);return e.jsxs(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragStart:B,onDragEnd:M,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(Fo,{isVisible:c,onToggleVisibility:()=>i(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(Xo,{selectedChart:h,onChartChange:y,groupByFields:S("groupBy"),pivotByFields:S("pivotBy"),metricsFields:S("metrics"),sortByFields:S("sortBy")}),e.jsx(bi,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:f,onClear:g,onAdvancedToggle:j,onFiltersClick:p,filterCount:Z,activeCard:F,dataSourceState:b.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:E,columnsError:L,getFieldsForContainer:S,cards:x.cards,activeCardId:x.activeCardId,addCard:k,setActiveCard:C})]}),!c&&u&&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:()=>i(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),F&&e.jsx(xi,{cardId:F.id,filters:((q=F.config)==null?void 0:q.filters)||null,onFiltersChange:R,onClearFilters:z,availableFields:V,isOpen:l,onOpenChange:o}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Ni,{activeField:A||null})})]})}function wi({authToken:t,onSave:a,onClose:n}){const r=I.useRef(null),l=s.useEditorStore(b=>b.showAIDialog),o=s.useEditorStore(b=>b.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:u}=s.useEditorActions(),{handleDragOver:m,handleDragEnd:h,handleDragStart:f,handleDragCancel:g,sensors:j}=Zr();I.useEffect(()=>{a&&d(a),n&&u(n)},[a,d,n,u]),I.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),I.useEffect(()=>{var b,k;l?((b=r.current)==null||b.resize(40),i(!0)):(i(!1),(k=r.current)==null||k.resize(0))},[l,i]);function p(b){b<1?i(!1):l||i(!0)}function y(){return e.jsxs(e.Fragment,{children:[e.jsx(pa,{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(No,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(Lt,{})})]})]})}function x(){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(Si,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(Lt,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:o?e.jsx(s.DndContext,{sensors:j,onDragStart:f,onDragEnd:h,onDragOver:m,onDragCancel:g,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:y()})}):x()})}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 l(c){t&&(r(t,c),a(!1))}function o(){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(wi,{onSave:l,onClose:o})})}function Di({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(Ce,{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(_e,{className:"size-3 text-muted-foreground"}):t.data_type.startsWith("json")?e.jsx(on,{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 Ti(){const t=s.useEditorStore(o=>o.selectedDatabaseName),a=s.useEditorStore(o=>o.selectedTableName),n=s.useDashboardStore(o=>o.dashboard.filters)||[],{columns:r}=s.useEditorAside(),{assignFilter:l}=it();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(o=>{const c=n==null?void 0:n.find(i=>i.column===s.fmt(o.column_name)&&i.table===a&&i.database===t);return e.jsx("div",{onClick:()=>l(o),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(Di,{column:o}),e.jsx("span",{children:o.column_name})]})},o.column_name)})})}function Ei({dataType:t}){const a=s.getDataType(t);return a==="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(ge,{className:"h-3 w-3"})}):a==="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(Ce,{className:"h-3 w-3"})}):a==="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"})}):a==="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(_e,{className:"h-3 w-3"})}):a==="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(es,{className:"h-3 w-3"})}):a==="geo"?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(ss,{className:"h-3 w-3"})}):a==="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(rs,{className:"h-3 w-3"})}):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(ge,{className:"h-3 w-3"})})}function Ii(){const[t,a]=I.useState(""),[n,r]=I.useState("all"),l=s.useDashboardStore(x=>x.dashboard.filters)||[],{assignFilter:o}=it(),c=s.useEditorStore(x=>x.card.dataSource),{columns:i=[],isLoading:d,error:u}=s.useColumns(),m=i.filter(x=>x.name.toLowerCase().includes(t.toLowerCase())||x.dataType.toLowerCase().includes(t.toLowerCase())||x.label&&x.label.toLowerCase().includes(t.toLowerCase())),h=x=>{const b=s.getDataType(x.dataType);return b==="number"?"metrics":(["date","string","boolean"].includes(b),"dimensions")},f=n==="all"?m:m.filter(x=>h(x)===n),g=m.filter(x=>h(x)==="dimensions").length,j=m.filter(x=>h(x)==="metrics").length,p=x=>{const b={column_name:x.name,data_type:x.dataType,label:x.label,description:x.description};o(b,"dashboard",x)};if(d)return e.jsx("div",{className:"flex h-full grow flex-col items-center justify-center px-3",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading fields"})});if(u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-3",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"})]});if(!c||!c.selectedEntities||c.selectedEntities.length===0)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-6 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"})]});if(i.length===0)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-6 py-8 text-center",children:[e.jsx("p",{className:"text-sm text-gray-500",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"})]});const y=m.length>0;return e.jsxs("div",{className:"flex h-full grow flex-col pb-4",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-3 px-3 pt-3",children:[i.length>0&&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 transform text-muted-foreground"}),e.jsx(s.Input$1,{className:"pl-10",type:"text",placeholder:"Search fields...",value:t,onChange:x=>a(x.target.value)})]}),y&&e.jsx(s.Tabs,{defaultValue:"all",value:n,onValueChange:x=>r(x),children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-3",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:g})]}),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:j})]})]})})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3 pt-3",children:[f.length===0&&t&&e.jsxs("div",{className:"py-4 text-center text-sm text-gray-500",children:['No fields found matching "',t,'"']}),f.length===0&&!t&&n!=="all"&&e.jsxs("div",{className:"py-4 text-center text-sm text-gray-500",children:["No ",n," fields found"]}),f.map(x=>{const b=l==null?void 0:l.some(k=>{var O;return k.title===x.name||((O=k.column)==null?void 0:O.includes(x.name))});return e.jsx("div",{onClick:()=>p(x),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":b}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ei,{dataType:x.dataType}),e.jsx("span",{children:x.label||x.name})]})},x.id)})]})]})}function Ai(){var r;const t=s.useDashboardStore(l=>l.actions.setShowFilters),a=s.useCurrentActiveCard(),n=a&&((r=a.dataSource)==null?void 0:r.selectedEntities)&&a.dataSource.selectedEntities.length>0;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:n?e.jsx(Ii,{}):e.jsx(pa,{type:"filter",ColumnsComponent:()=>e.jsx(Ti,{})})})]})}function Mi(){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 Li(){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(Mi,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ai,{})})]})}function Ri(){const t=s.useDashboardStore(l=>l.dashboard),a=s.useDashboardStore(l=>l.actions.setDashboard),n=s.useDashboardStore(l=>l.showDashboardJSON),r=s.useDashboardStore(l=>l.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:l=>{if(l)try{JSON.parse(l),a(JSON.parse(l))}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 Oi({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(Ri,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(Hr,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(ki,{}),e.jsx(Li,{})]})]})]})]})})}exports.DashboardPlus=Oi;exports.ResourceManagementPanel=ha;exports.ScheduleDashboard=Wt;exports.SelectComponent=Ke;exports.cleanCard=Ht;exports.downloadPdf=Qt;exports.getDashbaordStateWithoutData=fs;
|