react-semaphor 0.0.571 → 0.0.573
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-CIPiUNal.js +431 -0
- package/dist/chunks/{dashboard-plus-C32xyi1Z.js → dashboard-plus-k1blZbG_.js} +7468 -6692
- package/dist/chunks/{index-BSZ4q0Db.js → index-B5zRA1gM.js} +20405 -20174
- package/dist/chunks/index-CO-2JzLZ.js +653 -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 +26 -2
- package/dist/types/main.d.ts +26 -15
- package/dist/types/surfboard.d.ts +26 -2
- package/dist/types/types.d.ts +26 -2
- package/package.json +1 -1
- package/dist/chunks/dashboard-plus-BoQnT85A.js +0 -455
- package/dist/chunks/index-sMMR87WC.js +0 -648
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
"use strict";var rt=t=>{throw TypeError(t)};var ps=(t,a,n)=>a.has(t)||rt("Cannot "+n);var re=(t,a,n)=>(ps(t,a,"read from private field"),n?n.call(t):a.get(t)),Fe=(t,a,n)=>a.has(t)?rt("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),Pe=(t,a,n,r)=>(ps(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),ze=(t,a,n)=>(ps(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-sMMR87WC.js"),M=require("react");require("react-dom");function $n(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 me=$n(M);var Se,we,de,ye,ve,ss,Ss,kt,qn=(kt=class extends s.Subscribable{constructor(a,n){super();Fe(this,ve);Fe(this,Se);Fe(this,we);Fe(this,de);Fe(this,ye);Pe(this,Se,a),this.setOptions(n),this.bindMethods(),ze(this,ve,ss).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,Se).defaultMutationOptions(a),s.shallowEqualObjects(this.options,n)||re(this,Se).getMutationCache().notify({type:"observerOptionsUpdated",mutation:re(this,de),observer:this}),n!=null&&n.mutationKey&&this.options.mutationKey&&s.hashKey(n.mutationKey)!==s.hashKey(this.options.mutationKey)?this.reset():((r=re(this,de))==null?void 0:r.state.status)==="pending"&&re(this,de).setOptions(this.options)}onUnsubscribe(){var a;this.hasListeners()||(a=re(this,de))==null||a.removeObserver(this)}onMutationUpdate(a){ze(this,ve,ss).call(this),ze(this,ve,Ss).call(this,a)}getCurrentResult(){return re(this,we)}reset(){var a;(a=re(this,de))==null||a.removeObserver(this),Pe(this,de,void 0),ze(this,ve,ss).call(this),ze(this,ve,Ss).call(this)}mutate(a,n){var r;return Pe(this,ye,n),(r=re(this,de))==null||r.removeObserver(this),Pe(this,de,re(this,Se).getMutationCache().build(re(this,Se),this.options)),re(this,de).addObserver(this),re(this,de).execute(a)}},Se=new WeakMap,we=new WeakMap,de=new WeakMap,ye=new WeakMap,ve=new WeakSet,ss=function(){var n;const a=((n=re(this,de))==null?void 0:n.state)??s.getDefaultState();Pe(this,we,{...a,isPending:a.status==="pending",isSuccess:a.status==="success",isError:a.status==="error",isIdle:a.status==="idle",mutate:this.mutate,reset:this.reset})},Ss=function(a){s.notifyManager.batch(()=>{var n,r,l,o,c,i,d,m;if(re(this,ye)&&this.hasListeners()){const u=re(this,we).variables,h=re(this,we).context;(a==null?void 0:a.type)==="success"?((r=(n=re(this,ye)).onSuccess)==null||r.call(n,a.data,u,h),(o=(l=re(this,ye)).onSettled)==null||o.call(l,a.data,null,u,h)):(a==null?void 0:a.type)==="error"&&((i=(c=re(this,ye)).onError)==null||i.call(c,a.error,u,h),(m=(d=re(this,ye)).onSettled)==null||m.call(d,void 0,a.error,u,h))}this.listeners.forEach(u=>{u(re(this,we))})})},kt);function Oe(t,a){const n=s.useQueryClient(),[r]=me.useState(()=>new qn(n,t));me.useEffect(()=>{r.setOptions(t)},[r,t]);const l=me.useSyncExternalStore(me.useCallback(c=>r.subscribe(s.notifyManager.batchCalls(c)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),o=me.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 Yn=s.createLucideIcon("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
7
|
-
* @license lucide-react v0.453.0 - ISC
|
|
8
|
-
*
|
|
9
|
-
* This source code is licensed under the ISC license.
|
|
10
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const Gn=s.createLucideIcon("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
12
|
-
* @license lucide-react v0.453.0 - ISC
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the ISC license.
|
|
15
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const Hn=s.createLucideIcon("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
17
|
-
* @license lucide-react v0.453.0 - ISC
|
|
18
|
-
*
|
|
19
|
-
* This source code is licensed under the ISC license.
|
|
20
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const Kn=s.createLucideIcon("ArrowDown10",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M17 10V4h-2",key:"zcsr5x"}],["path",{d:"M15 10h4",key:"id2lce"}],["rect",{x:"15",y:"14",width:"4",height:"6",ry:"2",key:"33xykx"}]]);/**
|
|
22
|
-
* @license lucide-react v0.453.0 - ISC
|
|
23
|
-
*
|
|
24
|
-
* This source code is licensed under the ISC license.
|
|
25
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const Qn=s.createLucideIcon("ArrowDownZA",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M15 4h5l-5 6h5",key:"8asdl1"}],["path",{d:"M15 20v-3.5a2.5 2.5 0 0 1 5 0V20",key:"r6l5cz"}],["path",{d:"M20 18h-5",key:"18j1r2"}]]);/**
|
|
27
|
-
* @license lucide-react v0.453.0 - ISC
|
|
28
|
-
*
|
|
29
|
-
* This source code is licensed under the ISC license.
|
|
30
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const Wn=s.createLucideIcon("ArrowLeftRight",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);/**
|
|
32
|
-
* @license lucide-react v0.453.0 - ISC
|
|
33
|
-
*
|
|
34
|
-
* This source code is licensed under the ISC license.
|
|
35
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const Jn=s.createLucideIcon("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
37
|
-
* @license lucide-react v0.453.0 - ISC
|
|
38
|
-
*
|
|
39
|
-
* This source code is licensed under the ISC license.
|
|
40
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const Xn=s.createLucideIcon("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
|
|
42
|
-
* @license lucide-react v0.453.0 - ISC
|
|
43
|
-
*
|
|
44
|
-
* This source code is licensed under the ISC license.
|
|
45
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const Zn=s.createLucideIcon("ArrowUp01",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["rect",{x:"15",y:"4",width:"4",height:"6",ry:"2",key:"1bwicg"}],["path",{d:"M17 20v-6h-2",key:"1qp1so"}],["path",{d:"M15 20h4",key:"1j968p"}]]);/**
|
|
47
|
-
* @license lucide-react v0.453.0 - ISC
|
|
48
|
-
*
|
|
49
|
-
* This source code is licensed under the ISC license.
|
|
50
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const ea=s.createLucideIcon("ArrowUpAZ",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
|
|
52
|
-
* @license lucide-react v0.453.0 - ISC
|
|
53
|
-
*
|
|
54
|
-
* This source code is licensed under the ISC license.
|
|
55
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const sa=s.createLucideIcon("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);/**
|
|
57
|
-
* @license lucide-react v0.453.0 - ISC
|
|
58
|
-
*
|
|
59
|
-
* This source code is licensed under the ISC license.
|
|
60
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const ta=s.createLucideIcon("BookOpenText",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M16 12h2",key:"7q9ll5"}],["path",{d:"M16 8h2",key:"msurwy"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}],["path",{d:"M6 12h2",key:"32wvfc"}],["path",{d:"M6 8h2",key:"30oboj"}]]);/**
|
|
62
|
-
* @license lucide-react v0.453.0 - ISC
|
|
63
|
-
*
|
|
64
|
-
* This source code is licensed under the ISC license.
|
|
65
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const Dt=s.createLucideIcon("BookType",[["path",{d:"M10 13h4",key:"ytezjc"}],["path",{d:"M12 6v7",key:"1f6ttz"}],["path",{d:"M16 8V6H8v2",key:"x8j6u4"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
|
|
67
|
-
* @license lucide-react v0.453.0 - ISC
|
|
68
|
-
*
|
|
69
|
-
* This source code is licensed under the ISC license.
|
|
70
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const na=s.createLucideIcon("Box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/**
|
|
72
|
-
* @license lucide-react v0.453.0 - ISC
|
|
73
|
-
*
|
|
74
|
-
* This source code is licensed under the ISC license.
|
|
75
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
-
*/const aa=s.createLucideIcon("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
|
|
77
|
-
* @license lucide-react v0.453.0 - ISC
|
|
78
|
-
*
|
|
79
|
-
* This source code is licensed under the ISC license.
|
|
80
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
-
*/const lt=s.createLucideIcon("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]);/**
|
|
82
|
-
* @license lucide-react v0.453.0 - ISC
|
|
83
|
-
*
|
|
84
|
-
* This source code is licensed under the ISC license.
|
|
85
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
-
*/const Et=s.createLucideIcon("Calculator",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["line",{x1:"8",x2:"16",y1:"6",y2:"6",key:"x4nwl0"}],["line",{x1:"16",x2:"16",y1:"14",y2:"18",key:"wjye3r"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M8 18h.01",key:"lrp35t"}]]);/**
|
|
87
|
-
* @license lucide-react v0.453.0 - ISC
|
|
88
|
-
*
|
|
89
|
-
* This source code is licensed under the ISC license.
|
|
90
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
-
*/const Tt=s.createLucideIcon("ChartArea",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M7 11.207a.5.5 0 0 1 .146-.353l2-2a.5.5 0 0 1 .708 0l3.292 3.292a.5.5 0 0 0 .708 0l4.292-4.292a.5.5 0 0 1 .854.353V16a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z",key:"q0gr47"}]]);/**
|
|
92
|
-
* @license lucide-react v0.453.0 - ISC
|
|
93
|
-
*
|
|
94
|
-
* This source code is licensed under the ISC license.
|
|
95
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
-
*/const ds=s.createLucideIcon("ChartColumnIncreasing",[["path",{d:"M13 17V9",key:"1fwyjl"}],["path",{d:"M18 17V5",key:"sfb6ij"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
|
|
97
|
-
* @license lucide-react v0.453.0 - ISC
|
|
98
|
-
*
|
|
99
|
-
* This source code is licensed under the ISC license.
|
|
100
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
-
*/const Ms=s.createLucideIcon("ChartColumnStacked",[["path",{d:"M11 13H7",key:"t0o9gq"}],["path",{d:"M19 9h-4",key:"rera1j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["rect",{x:"15",y:"5",width:"4",height:"12",rx:"1",key:"q8uenq"}],["rect",{x:"7",y:"8",width:"4",height:"9",rx:"1",key:"sr5ea"}]]);/**
|
|
102
|
-
* @license lucide-react v0.453.0 - ISC
|
|
103
|
-
*
|
|
104
|
-
* This source code is licensed under the ISC license.
|
|
105
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
-
*/const us=s.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
|
|
107
|
-
* @license lucide-react v0.453.0 - ISC
|
|
108
|
-
*
|
|
109
|
-
* This source code is licensed under the ISC license.
|
|
110
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
-
*/const ra=s.createLucideIcon("ChartNoAxesCombined",[["path",{d:"M12 16v5",key:"zza2cw"}],["path",{d:"M16 14v7",key:"1g90b9"}],["path",{d:"M20 10v11",key:"1iqoj0"}],["path",{d:"m22 3-8.646 8.646a.5.5 0 0 1-.708 0L9.354 8.354a.5.5 0 0 0-.707 0L2 15",key:"1fw8x9"}],["path",{d:"M4 18v3",key:"1yp0dc"}],["path",{d:"M8 14v7",key:"n3cwzv"}]]);/**
|
|
112
|
-
* @license lucide-react v0.453.0 - ISC
|
|
113
|
-
*
|
|
114
|
-
* This source code is licensed under the ISC license.
|
|
115
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
-
*/const Ls=s.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
117
|
-
* @license lucide-react v0.453.0 - ISC
|
|
118
|
-
*
|
|
119
|
-
* This source code is licensed under the ISC license.
|
|
120
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const ms=s.createLucideIcon("ChartPie",[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]]);/**
|
|
122
|
-
* @license lucide-react v0.453.0 - ISC
|
|
123
|
-
*
|
|
124
|
-
* This source code is licensed under the ISC license.
|
|
125
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const Os=s.createLucideIcon("ChartScatter",[["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}],["circle",{cx:"18.5",cy:"5.5",r:".5",fill:"currentColor",key:"lysivs"}],["circle",{cx:"11.5",cy:"11.5",r:".5",fill:"currentColor",key:"byv1b8"}],["circle",{cx:"7.5",cy:"16.5",r:".5",fill:"currentColor",key:"nkw3mc"}],["circle",{cx:"17.5",cy:"14.5",r:".5",fill:"currentColor",key:"1gjh6j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}]]);/**
|
|
127
|
-
* @license lucide-react v0.453.0 - ISC
|
|
128
|
-
*
|
|
129
|
-
* This source code is licensed under the ISC license.
|
|
130
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const la=s.createLucideIcon("CircleArrowRight",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m12 16 4-4-4-4",key:"1i9zcv"}]]);/**
|
|
132
|
-
* @license lucide-react v0.453.0 - ISC
|
|
133
|
-
*
|
|
134
|
-
* This source code is licensed under the ISC license.
|
|
135
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const It=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
|
|
137
|
-
* @license lucide-react v0.453.0 - ISC
|
|
138
|
-
*
|
|
139
|
-
* This source code is licensed under the ISC license.
|
|
140
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const ot=s.createLucideIcon("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
|
|
142
|
-
* @license lucide-react v0.453.0 - ISC
|
|
143
|
-
*
|
|
144
|
-
* This source code is licensed under the ISC license.
|
|
145
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
-
*/const oa=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
147
|
-
* @license lucide-react v0.453.0 - ISC
|
|
148
|
-
*
|
|
149
|
-
* This source code is licensed under the ISC license.
|
|
150
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
-
*/const ia=s.createLucideIcon("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
|
|
152
|
-
* @license lucide-react v0.453.0 - ISC
|
|
153
|
-
*
|
|
154
|
-
* This source code is licensed under the ISC license.
|
|
155
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
-
*/const ca=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
|
|
157
|
-
* @license lucide-react v0.453.0 - ISC
|
|
158
|
-
*
|
|
159
|
-
* This source code is licensed under the ISC license.
|
|
160
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
161
|
-
*/const da=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"}]]);/**
|
|
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 ua=s.createLucideIcon("DollarSign",[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]]);/**
|
|
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 Rs=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"}]]);/**
|
|
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 At=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"}]]);/**
|
|
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 ma=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"}]]);/**
|
|
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 ha=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"}]]);/**
|
|
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 xa=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"}]]);/**
|
|
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 pa=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"}]]);/**
|
|
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 fa=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"}]]);/**
|
|
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 ga=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"}]]);/**
|
|
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 ja=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"}]]);/**
|
|
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 ya=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"}]]);/**
|
|
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 va=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"}]]);/**
|
|
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 Ge=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"}]]);/**
|
|
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 ba=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"}]]);/**
|
|
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 Mt=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"}]]);/**
|
|
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 Na=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"}]]);/**
|
|
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 Ca=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"}]]);/**
|
|
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 Sa=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"}]]);/**
|
|
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 wa=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"}]]);/**
|
|
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 Lt=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"}]]);/**
|
|
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 ka=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"}]]);/**
|
|
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 Da=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"}]]);/**
|
|
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 it=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"}]]);/**
|
|
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 Bs=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"}]]);/**
|
|
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 Ea=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"}]]);/**
|
|
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 Ta=s.createLucideIcon("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
|
|
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 ct=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
|
|
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 dt=s.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
|
|
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 Ia=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"}]]);/**
|
|
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 Aa=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"}]]);/**
|
|
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 Ma=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"}]]);/**
|
|
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 La=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"}]]);/**
|
|
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 Fs=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"}]]);/**
|
|
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 Ot=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"}]]);/**
|
|
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 Oa=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"}]]);/**
|
|
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 ws=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
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 Ra=s.createLucideIcon("Settings2",[["path",{d:"M20 7h-9",key:"3s1dr2"}],["path",{d:"M14 17H5",key:"gfn3mx"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]);/**
|
|
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 He=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"}]]);/**
|
|
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 Ke=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"}]]);/**
|
|
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 Ba=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"}]]);/**
|
|
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 Fa=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"}]]);/**
|
|
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 Rt=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"}]]);/**
|
|
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 Pa=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"}]]);/**
|
|
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 za=s.createLucideIcon("Sparkles",[["path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z",key:"4pj2yx"}],["path",{d:"M20 3v4",key:"1olli1"}],["path",{d:"M22 5h-4",key:"1gvqau"}],["path",{d:"M4 17v2",key:"vumght"}],["path",{d:"M5 18H3",key:"zchphs"}]]);/**
|
|
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 Va=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
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 _e=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"}]]);/**
|
|
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 Bt=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"}]]);/**
|
|
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 _a=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"}]]);/**
|
|
402
|
-
* @license lucide-react v0.453.0 - ISC
|
|
403
|
-
*
|
|
404
|
-
* This source code is licensed under the ISC license.
|
|
405
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
406
|
-
*/const Ua=s.createLucideIcon("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);/**
|
|
407
|
-
* @license lucide-react v0.453.0 - ISC
|
|
408
|
-
*
|
|
409
|
-
* This source code is licensed under the ISC license.
|
|
410
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
411
|
-
*/const ns=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"}]]);/**
|
|
412
|
-
* @license lucide-react v0.453.0 - ISC
|
|
413
|
-
*
|
|
414
|
-
* This source code is licensed under the ISC license.
|
|
415
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
416
|
-
*/const Ps=s.createLucideIcon("Tornado",[["path",{d:"M21 4H3",key:"1hwok0"}],["path",{d:"M18 8H6",key:"41n648"}],["path",{d:"M19 12H9",key:"1g4lpz"}],["path",{d:"M16 16h-6",key:"1j5d54"}],["path",{d:"M11 20H9",key:"39obr8"}]]);/**
|
|
417
|
-
* @license lucide-react v0.453.0 - ISC
|
|
418
|
-
*
|
|
419
|
-
* This source code is licensed under the ISC license.
|
|
420
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
421
|
-
*/const Qe=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
|
|
422
|
-
* @license lucide-react v0.453.0 - ISC
|
|
423
|
-
*
|
|
424
|
-
* This source code is licensed under the ISC license.
|
|
425
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
426
|
-
*/const De=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"}]]);/**
|
|
427
|
-
* @license lucide-react v0.453.0 - ISC
|
|
428
|
-
*
|
|
429
|
-
* This source code is licensed under the ISC license.
|
|
430
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
431
|
-
*/const be=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"}]]);/**
|
|
432
|
-
* @license lucide-react v0.453.0 - ISC
|
|
433
|
-
*
|
|
434
|
-
* This source code is licensed under the ISC license.
|
|
435
|
-
* See the LICENSE file in the root directory of this source tree.
|
|
436
|
-
*/const $a=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 as(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=>Ft(c))}})}})}}function Ft(t){return{...t,customCfg:qa(t.customCfg),data:[]}}function qa(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 Ya(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 ks(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 Ga(t,a){return a?await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:t}):null}function Ha(){const[t,a]=M.useState(""),[n,r]=M.useState(!1),l=s.useDashboardStore(p=>p.lenses),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),[i,d]=M.useState(!1),[m,u]=M.useState(!1),h=s.useDashboardStore(p=>p.dashboard),x=s.useDashboardStore(p=>p.filterValues),{authToken:f}=s.useSemaphorContext();async function j(){d(!0);const p=as(h),y=await Ya(t,p,x,f==null?void 0:f.accessToken);y&&(o([...l||[],y]),c(y.id),u(!1)),d(!1)}return e.jsxs(s.Dialog,{open:m,onOpenChange:u,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 Ka(){const[t,a]=M.useState(!1),n=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:l,setSelectedLensId:o}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function i(u){o(u)}async function d(u){if(await Ga(u,c==null?void 0:c.accessToken)){const x=n==null?void 0:n.filter(f=>f.id!==u);l(x||[]),o("original")}}async function m(u){const h=n==null?void 0:n.map(j=>j.id===u.id?{...j,isDefault:!u.isDefault}:{...j,isDefault:!1});l(h||[]);const x={...u,isDefault:!u.isDefault};await ks(x,c==null?void 0:c.accessToken);const f=n==null?void 0:n.find(j=>j.isDefault);if(f&&f.id!==u.id){const j={...f,isDefault:!1};await ks(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(ja,{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(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:h=>{h.preventDefault(),m(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),d(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function Pt(){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 zt(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:l,selectedSheetId:o}=Pt();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 u=(await(await fetch(i,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,h=document.createElement("a");h.href=u;const x=`${l}-${new Date().toISOString()}.pdf`;h.download=x,h.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Qa({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 zt()}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 xe({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 ut=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Vt({triggerButtonClassName:t}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:l,error:o,isDeleting:c}=Wa(),[i,d]=M.useState(""),[m,u]=M.useState(ut[0].value),[h,x]=M.useState("06:00"),[f,j]=M.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(s.Clock,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value: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:f,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(xe,{className:"col-span-2 h-8",label:"Select Frequency",options:ut,value:m,onValueChange:p=>u(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"time",children:"Time"}),e.jsx(s.Input,{id:"time",type:"time",value:h,onChange:p=>x(p.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await n({email:i,frequency:m,time:h,subject:f}),x("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(It,{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(mt,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(la,{className:"size-3.5"})}),e.jsx(mt,{tooltip:`${p.endUserEmail}`,children:e.jsx(Da,{className:"size-3.5"})}),c===p.id?e.jsx(s.LoaderCircle,{className:"size-3.5 animate-spin"}):e.jsx(s.Trash2,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const mt=({children:t,tooltip:a})=>e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:t}),e.jsx(s.TooltipContent,{children:a})]})});function Wa(){const[t,a]=M.useState("idle"),[n,r]=M.useState(""),[l,o]=M.useState(null),c=s.useDashboardStore(E=>E.authToken),i=s.useDashboardStore(E=>E.dashboard.id),d=s.useDashboardStore(E=>E.dashboard.title),{endUserId:m}=s.getTenantAndEndUserId((c==null?void 0:c.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",h={dashboardId:i,endUserId:m},{data:x,isLoading:f,isError:j,isFetching:p,refetch:y}=s.useQuery({queryKey:["subscriptions",i,m],queryFn:()=>s.getRequest(u,(c==null?void 0:c.accessToken)||"",h),enabled:!!(c!=null&&c.accessToken)&&!!i&&!!m});async function g({email:E,subject:B,frequency:S,time:N}){const{authToken:v,...I}=Pt(),D=Intl.DateTimeFormat().resolvedOptions().timeZone,R={email:E,frequency:S,time:N,timezone:D,endUserId:m,endUserEmail:E,subject:B||d||"Scheduled Dashboard",dashboardId:i,dashboardParams:I};a("loading");const w="https://semaphor.cloud/api/v1/subscriptions/create";try{const F=await s.postRequestRegular(w,(v==null?void 0:v.accessToken)||"",{...R});a("success"),r(""),y(),setTimeout(()=>{a("idle")},2e3)}catch(F){console.error(F),a("error"),r(F.message)}}async function C(E){const B="https://semaphor.cloud/api/v1/subscriptions/delete";o(E);try{await s.postRequestRegular(B,(c==null?void 0:c.accessToken)||"",{id:E}),y(),setTimeout(()=>{o(null)},2e3)}catch(S){console.error(S),o(null),a("error"),r(S.message)}}return{data:x,isLoading:f,isFetching:p,isError:j,isDeleting:l,refetch:y,handleScheduleSubscription:g,handleDeleteSubscription:C,status:t,error:n}}function Ne(){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 _t(){return e.jsx(s.ScrollArea,{className:"w-full flex-1",children:e.jsxs("div",{className:"space-y-4 px-4",children:[e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"animate-pulse",children:e.jsx("div",{className:"h-8 w-full rounded bg-muted"})}),e.jsx("div",{className:"space-y-2",children:[...Array(4)].map((t,a)=>e.jsx("div",{className:"animate-pulse",children:e.jsxs("div",{className:"group relative flex items-start gap-3 px-4 py-3",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-muted"})}),e.jsxs("div",{className:"flex w-full items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"h-4 w-32 rounded bg-muted"})}),e.jsx("div",{className:"shrink-0",children:e.jsx("div",{className:"h-3.5 w-3.5 rounded bg-muted"})})]}),e.jsx("div",{className:"mt-0.5",children:e.jsx("div",{className:"h-3 w-48 rounded bg-muted"})})]}),e.jsx("div",{className:"absolute right-3 top-2",children:e.jsx("div",{className:"flex items-center opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:e.jsx("div",{className:"h-6 w-6 rounded bg-muted"})})})]})]})},a))})]})})}var ee=(t=>(t.DASHBOARD="dashboard",t.VISUAL="visual",t))(ee||{});const Ja=async(t,a,n,r,l,o)=>{const c={},i={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${i[a]}`,t,c)},Xa=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}`,t,n)},Za=async(t,a,n,r)=>{const l={[ee.DASHBOARD]:"dashboards",[ee.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()},er=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.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()},sr=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/duplicate`,t,{})},tr=async(t,a,n,r)=>{const l={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.postRequestRegular(`https://semaphor.cloud/api/management/v1/${l[a]}/${n}/share`,t,r)},nr=async(t,a,n,r)=>{const l={[ee.DASHBOARD]:"dashboards",[ee.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()},ar=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}/shares`,t)},rr=async(t,a,n)=>{const r={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return s.getRequest(`https://semaphor.cloud/api/management/v1/${r[a]}/${n}`,t)};function lr(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 or(t,a,n,r,l){const{authToken:o}=s.useSemaphorContext(),{currentUser:c}=Ne();return s.useQuery({queryKey:[t,a,n,r,l],queryFn:()=>Ja((o==null?void 0:o.accessToken)||"",t),enabled:!!(o!=null&&o.accessToken)&&!!c})}function ir(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Oe({mutationFn:l=>Xa((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 Ut(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Oe({mutationFn:({resourceId:r,data:l})=>Za((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 cr(t,a){const{authToken:n}=s.useSemaphorContext(),r=s.useQueryClient();return Oe({mutationFn:l=>er((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 dr(t){const{authToken:a}=s.useSemaphorContext(),n=s.useQueryClient();return Oe({mutationFn:r=>sr((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 ur(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Oe({mutationFn:({resourceType:n,resourceId:r,data:l})=>tr((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 mr(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Oe({mutationFn:({resourceType:n,resourceId:r,data:l})=>nr((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 hr(t,a){const{authToken:n}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-shares",t,a],queryFn:()=>ar((n==null?void 0:n.accessToken)||"",t,a),enabled:!!(n!=null&&n.accessToken)&&!!a})}function xr(t,a,n){const{authToken:r}=s.useSemaphorContext();return s.useQuery({queryKey:["resource-by-id",t,a],queryFn:()=>rr((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 pr(t,a){return xr(ee.VISUAL,t,a)}function $t(){const[t,a]=M.useState(new Map),n=M.useCallback((o,c)=>{a(i=>{const d=new Map(i),m=new Set(d.get(o)||[]);return c?m.add(c):(m.add("title"),m.add("description")),d.set(o,m),d})},[]),r=M.useCallback((o,c)=>{a(i=>{const d=new Map(i),m=new Set(d.get(o)||[]);return c?m.delete(c):m.clear(),m.size===0?d.delete(o):d.set(o,m),d})},[]),l=M.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 zs(t,a,n){var h;const r=or(t),l=ir(t,n),o=Ut(t),c=cr(t,a),i=dr(t),d=ur(),m=mr(),u={[ee.DASHBOARD]:"dashboards",[ee.VISUAL]:"visuals"};return{resources:((h=r.data)==null?void 0:h[u[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:m.mutate,isCreating:l.isPending,isUpdating:o.isPending,isDeleting:c.isPending,isDuplicating:i.isPending,isSharing:d.isPending,isRemovingShares:m.isPending,isUpdatingShares:d.isPending,refetch:r.refetch}}function fr(t,a){return zs(ee.DASHBOARD,t,a)}function gr(t,a){return zs(ee.VISUAL,t,a)}function jr(){const{authToken:t}=s.useSemaphorContext(),a=s.useQueryClient();return Oe({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 yr({visual:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:l=!1,onAddVisual:o,onEditVisual:c,onUpdateVisual:i,onDeleteClick:d,onDuplicateVisual:m,onShareVisual:u,formatDate:h}){var N;const{selectVisual:x}=s.useManagementActions(),f=s.useIsVisualSelected(t.id),j=s.useDashboardStore(v=>v.actions.setIsDashboardPanelOpen),[p,y]=M.useState(!1),[g,C]=M.useState(!1);M.useEffect(()=>{n?(y(!0),C(!0)):g&&(y(!1),C(!1))},[n,g]);const E=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx(Lt,{className:"h-3 w-3 text-purple-500"}):e.jsx(be,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(De,{className:"h-3.5 w-3.5 text-slate-500"}),B=()=>e.jsx(s.ChartColumn,{className:"h-4 w-4 text-slate-400"}),S=()=>{x(t),c==null||c(t)};return e.jsxs("div",{className:s.cn("group relative flex cursor-pointer items-start gap-3 px-4 py-3 dark:border-slate-800","cursor-pointer transition-colors duration-150 hover:bg-slate-50 dark:hover:bg-slate-900/50",t.ownership.isOwner&&"border-blue-200 dark:border-blue-800",f&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:S,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:B()})}),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&&f,isPending:r,placeholder:"Untitled Visual",displayClassName:"line-clamp-1 max-w-[150px] text-sm font-medium text-slate-900 dark:text-slate-100"})}),e.jsx("div",{className:"shrink-0",children:E()})]}),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&&f,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(),m(t.id)},disabled:n,children:[n?e.jsx(s.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(s.Copy,{className:"mr-2 h-3 w-3"}),n?"Duplicating...":"Duplicate"]}),t.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),c==null||c(t)},children:[e.jsx(Ma,{className:"mr-2 h-3 w-3"}),"Edit"]}),e.jsxs(s.DropdownMenuItem,{onClick:v=>{v.stopPropagation(),u(t)},children:[e.jsx(be,{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(De,{className:"h-3 w-3"}),e.jsx("span",{children:((N=t.ownership.createdBy)==null?void 0:N.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 qt({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 rs({currentRole:t,onRoleChange:a,roleOptions:n,disabled:r=!1,className:l="",allowDropdown:o=!0}){var d;const c=((d=n.find(m=>m.value===t))==null?void 0:d.label)||t,i=n.filter(m=>m.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(m=>e.jsx(s.DropdownMenuItem,{onClick:()=>{console.log("Dropdown item clicked:",{currentRole:t,newRole:m.value,disabled:r}),a(m.value)},disabled:r,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]})},m.value))})]}):e.jsx(s.Badge,{variant:"outline",className:`text-xs ${l}`,children:c})}function Yt({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(rs,{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 Gt({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 Ht({usersToUpdate:t,allUsers:a,onRemove:n,getRoleOptions:r}){if(t.length===0)return null;const l=r("tenant"),o=i=>{const d=a.find(m=>m.id===i);return(d==null?void 0:d.name)||"Unknown User"},c=i=>{const d=l.find(m=>m.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(be,{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 Kt(t,a={}){const{enabled:n=!0,eventType:r="mousedown"}=a,l=M.useRef(null);return M.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 fe(t,a){var n;return((n=a.find(r=>r.value===t))==null?void 0:n.label)||t}function vr(t){return["POWER_USER","ADMIN","EDITOR"].includes(t)}function Qt(t){return"tenantId"in t&&t.tenantId?"tenant":"organization"}function br(t,a,n){const r=Qt(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 Nr({user:t}){return Qt(t)==="tenant"?e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:t.role==="POWER_USER"?"Power User":"Viewer"}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:t.role==="ADMIN"?"Admin":t.role==="POWER_USER"?"Power User":"Viewer"})}function Cr({user:t,userShare:a,usersToUpdate:n,currentUser:r,getRoleOptions:l,handleUpdateAccess:o}){if(!(a!=null&&a.role))return null;const c=vr((r==null?void 0:r.type)||""),i=n.some(h=>h.id===t.id),d=n.find(h=>h.id===t.id),m=d?d.newRole:a==null?void 0:a.role,u=l(t.type);return a?e.jsx("div",{className:"flex items-center gap-2",children:c?e.jsx(rs,{currentRole:m,onRoleChange:h=>{o(t.id,a.role,h)},roleOptions:u,disabled:!c,allowDropdown:c,className:i?"border-orange-300 bg-orange-100":""}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:fe(m,u)})}):e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:"Unknown"})}function Sr({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(Ke,{className:"mr-1 h-3 w-3"}),"Will Share"]})]})}function wr({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 kr({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||[],m=c.orgWide||[],u=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((x,f)=>{var g,C;const j=((g=a.find(E=>E.id===x.orgUserId))==null?void 0:g.name)||"Unknown User",p=((C=a.find(E=>E.id===x.orgUserId))==null?void 0:C.type)||"",y=fe(x.role,n(p));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:j}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:y})]},f)}),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((x,f)=>{var g,C;const j=((g=a.find(E=>E.id===x.tenantUserId))==null?void 0:g.name)||"Unknown User",p=((C=a.find(E=>E.id===x.tenantUserId))==null?void 0:C.type)||"",y=fe(x.role,n(p));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:j}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:y})]},f)}),d.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",d.length-3," more users"]})]})]}),m.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-purple-600",children:"All Org Users"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:m.map((x,f)=>{const j=fe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Organization Users"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:j})]},f)})})]}),u.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:u.map((x,f)=>{const j=fe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Org Users Only"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:j})]},f)})})]}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium text-indigo-600",children:"All Tenants"}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:h.map((x,f)=>{const j=fe(x.role,n(""));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"All Tenants"}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:j})]},f)})})]}),!i.length&&!d.length&&!m.length&&!u.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,m)=>{var f,j;const u=((f=a.find(p=>p.id===d.tenantUserId))==null?void 0:f.name)||"Unknown User",h=((j=a.find(p=>p.id===d.tenantUserId))==null?void 0:j.type)||"",x=fe(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:u}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:x})]},m)}),c.length>3&&e.jsxs("div",{className:"text-xs italic text-muted-foreground",children:["+",c.length-3," more users"]})]})]}),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,m)=>{const u=fe(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:u})]},m)})})]}),!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 x,f;const m=((x=a.find(j=>j.id===i.tenantUserId))==null?void 0:x.name)||"Unknown User",u=((f=a.find(j=>j.id===i.tenantUserId))==null?void 0:f.type)||"",h=fe(i.role,n(u));return e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"truncate text-muted-foreground",children:m}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 shrink-0 px-2 py-0.5 text-xs",children:h})]},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 m=fe(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:m})]},d)})})]}),!o.length&&!c.length&&e.jsx("div",{className:"text-xs italic text-muted-foreground",children:"No users currently have access"})]})]})}}function Dr({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 Er({user:t,userShare:a,isUserRemoving:n,hasAccess:r,hasAccessFromAPI:l,isSelected:o,selectedUser:c,roleOptions:i,currentUser:d,usersToUpdate:m,handleUserToggle:u,handleRemoveAccess:h,handleUpdateAccess:x,handleUserRoleChange:f}){return e.jsxs("div",{className:s.cn("flex items-center space-x-3 rounded-lg p-2 transition-colors",r&&!n?"border border-green-200 bg-green-50":n?"border border-red-200 bg-red-50":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?u(t.id):h(t.id):u(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(Nr,{user:t})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[r&&!n?e.jsx(rs,{currentRole:a==null?void 0:a.role,onRoleChange:j=>x(t.id,a.role,j),roleOptions:i,disabled:!1,allowDropdown:!0}):e.jsx(Cr,{user:t,userShare:a,usersToUpdate:m,currentUser:d,getRoleOptions:()=>i,handleUpdateAccess:x}),o&&!l&&e.jsx("div",{onClick:j=>j.stopPropagation(),children:e.jsx(rs,{currentRole:(c==null?void 0:c.role)||"VIEWER",onRoleChange:j=>f(t.id,j),roleOptions:i,disabled:!1})})]})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.email}),e.jsx(Sr,{hasAccess:r,isUserRemoving:n,isSelected:o,hasAccessFromAPI:l}),e.jsx(wr,{isUserRemoving:n,isSelected:o,hasAccess:r,isRemoving:!1,isSharing:!1})]})]})}function Wt({existingShares:t,isInitialLoading:a,isSearching:n,getRoleOptions:r,allUsers:l=[],currentUser:o,handleUserToggle:c,handleUserRoleChange:i,handleRemoveAccess:d,handleUpdateAccess:m}){const u=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate(),f=s.useShareSearchQuery(),j=s.useShareManagementActions(),p=c||(S=>{const N=u.some(I=>I.id===S),v=h.includes(S);N?j.removeSelectedUser(S):v?j.removeUserFromRemove(S):j.addSelectedUser({id:S,role:"VIEWER"})}),y=i||j.updateSelectedUserRole,g=d||j.addUserToRemove,C=m||((S,N,v)=>{j.addUserToUpdate({id:S,currentRole:N,newRole:v})}),E=l,B=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 (",(E??[]).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(kr,{existingShares:t,allUsers:l,getRoleOptions:r,currentUser:o})})]})})]}),(E==null?void 0:E.length)>0&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>{u.length===E.length?j.setSelectedUsers([]):j.setSelectedUsers(E.map(S=>({id:S.id,role:"VIEWER"})))},className:"h-auto p-1 text-xs",children:u.length===E.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(Dr,{isInitialLoading:a,isSearching:n,searchQuery:f,availableUsers:E||[]}),!a&&!n&&(E==null?void 0:E.length)>0&&E.map(S=>{const N=t?br(S,t,o):void 0,v=B.includes(S.id),I=!!N,D=I&&!v,R=u.some(k=>k.id===S.id),w=u.find(k=>k.id===S.id),F=r(S.type);return e.jsx(Er,{user:S,userShare:N,isUserRemoving:v,hasAccess:D,hasAccessFromAPI:I,isSelected:R,selectedUser:w,roleOptions:F,currentUser:o,usersToUpdate:x,handleUserToggle:p,handleRemoveAccess:g,handleUpdateAccess:C,handleUserRoleChange:y},S.id)})]})]})}function Jt({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(De,{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 Ie=()=>[{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 Tr({currentUser:t,currentShare:a,isSharing:n,onUpdateAccess:r,allUsersToUpdate:l=null,allUsersToRemove:o=!1,isUpdating:c=!1,isRemoving:i=!1}){const d=s.useShareCurrentMode(),m=Ie().filter(C=>C.value==="VIEWER"||C.value==="EDITOR"||C.value==="CONTRIBUTOR"),u=a.role!=="NONE"?a.role:"NONE",h=l?l.newRole:u,x=a.role!=="NONE"&&!o&&(!l||l.newRole===u),f=l!==null&&l.newRole!==u,j=o,p=u==="NONE"||!u,y=C=>{switch(C){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(Ba,{className:"h-4 w-4"});default:return e.jsx(s.Eye,{className:"h-4 w-4"})}},g=C=>{r(u,C)};return e.jsx("div",{className:"space-y-4",children:e.jsxs(s.Card,{className:s.cn("pb-6",f&&!j&&!p?"border-orange-300 bg-orange-50":x?"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(be,{className:"h-5 w-5"}),"Share with All"," ",d==="allOrgUsers"?"Organization":d==="allTenantUsers"?"Tenant":d==="specificOrgUsers"?"Org":"Tenant"," ","Users",x&&e.jsx(s.Badge,{variant:"default",className:"ml-2 border-green-400 bg-green-100 text-green-800",children:"Active"}),f&&e.jsx(s.Badge,{variant:"secondary",className:"ml-2 border-orange-400 bg-orange-100 text-orange-800",children:"Pending Update"}),(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:m.map(C=>e.jsxs(s.Button,{variant:h===C.value?"default":"outline",className:"h-auto flex-col items-start gap-2 p-3",onClick:()=>g(C.value),disabled:n||c||i,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[y(C.value),e.jsx("span",{className:"font-medium",children:C.label})]}),e.jsx("p",{className:"text-left text-xs text-muted-foreground",children:C.description})]},C.value))})]})})]})})}function Xt({currentUser:t,currentShare:a,isSharing:n,isUpdating:r,isRemoving:l,onUpdateAccess:o,onRemoveAccess:c,allUsersToUpdate:i,allUsersToRemove:d}){const m=p=>p==="OWNER"?"CONTRIBUTOR":p,h=a?{role:m(a.role)}:{role:"NONE"},x=i?{currentRole:m(i.currentRole),newRole:m(i.newRole)}:null,f=(p,y)=>{o(p,y)},j=()=>{c()};return e.jsx(Tr,{currentUser:t,currentShare:h,isSharing:n,isUpdating:r,isRemoving:l,onUpdateAccess:f,onRemoveAccess:j,allUsersToUpdate:x,allUsersToRemove:d})}const Ir=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 Ar(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:()=>Ir((a==null?void 0:a.accessToken)||"",t),enabled:!!(a!=null&&a.accessToken)&&!!r,retry:(d,m)=>m instanceof Error&&m.message.includes("401")||m instanceof Error&&m.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 Ee(t){const{debouncedSearchQuery:a,resourceId:n,resourceType:r=ee.DASHBOARD,userType:l,tenantId:o}=t,c=M.useMemo(()=>({search:a,active:!0,...l?{type:l}:{},...l==="tenant"&&o?{tenantId:o}:{}}),[a,l,o]),{users:i,isLoading:d,isError:m}=Ar(c),u=hr(r,n);return{allUsers:i,isLoadingUsers:d,isErrorLoadingUsers:m,existingShares:u.data,isLoadingShares:u.isLoading,isErrorLoadingShares:u.isError,isFetchingShares:u.isFetching}}function Mr({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:l=!1,isUpdating:o=!1,isRemoving:c=!1}){var W,$;const i=s.useShareSelectedTab(),d=s.useShareSelectedTenant(),{searchQuery:m,setSearchQuery:u,debouncedSearchQuery:h}=s.useShareSearchWithDebounce(),x=s.useShareSelectedUsers(),f=s.useShareUsersToRemove(),j=s.useShareUsersToUpdate(),p=s.useShareCurrentMode(),y=s.useShareOrgWideRole(),g=s.useShareManagementActions(),[C,E]=M.useState("specific_users"),B=()=>{if(i==="org")return"organization";if(i==="tenant")return"tenant"},S=()=>{if(i==="tenant"&&d)return d},{allUsers:N,existingShares:v,isLoadingUsers:I}=Ee({debouncedSearchQuery:h,resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:B(),tenantId:S()});M.useEffect(()=>{g.setCurrentContext("org-tab"),g.setCurrentMode(C==="all_users"?"allOrgUsers":"specificOrgUsers")},[g,C]);const D=q=>{var U,P;const H=q;if(E(H),r==null||r(H),g.setCurrentContext("org-tab"),H==="specific_users")g.setCurrentMode("specificOrgUsers");else if(H==="all_users"){g.setCurrentMode("allOrgUsers");const Y=(P=(U=v==null?void 0:v.shares)==null?void 0:U.orgUsersOnly)==null?void 0:P[0];Y&&Y.role!==void 0&&g.setOrgWideRole(Y.role)}},R=N.filter(q=>q.name.toLowerCase().includes(m.toLowerCase())||q.email.toLowerCase().includes(m.toLowerCase())),w=N.filter(q=>x.some(H=>H.id===q.id)),F=q=>{var Y,G;const H=x.some(X=>X.id===q),U=f.includes(q),P=(G=(Y=v==null?void 0:v.shares)==null?void 0:Y.specificOrgUsers)==null?void 0:G.some(X=>X.orgUserId===q);H?g.removeSelectedUser(q):U?g.removeUserFromRemove(q):P||g.addSelectedUser({id:q,role:"VIEWER"})},k=(q,H)=>{g.updateSelectedUserRole(q,H)},T=q=>{g.addUserToRemove(q),g.removeSelectedUser(q)},b=q=>{g.removeUserFromRemove(q)},L=q=>{g.removeUserFromUpdate(q)},A=(q,H)=>{g.setOrgWideRole(H)},O=()=>{g.setOrgWideRole((z==null?void 0:z.role)||"NONE")},z=($=(W=v==null?void 0:v.shares)==null?void 0:W.orgUsersOnly)==null?void 0:$[0];M.useEffect(()=>{C==="all_users"&&z&&z.role!==void 0&&g.setOrgWideRole(z.role)},[C,z,g]);const _=I,Q=!1;return n?e.jsxs(e.Fragment,{children:[e.jsx(Jt,{shareType:C,onShareTypeChange:D,currentUser:n,options:[{value:"specific_users",label:"Specific Org User",description:"Choose individual users to share with",icon:e.jsx(De,{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(be,{className:"mb-3 h-6 w-6 text-indigo-500"}),disabled:!["POWER_USER","ADMIN","AUTHOR","SUPER_ADMIN"].includes(n.role??"")}]}),C==="specific_users"?e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsx(qt,{value:m,onChange:u}),e.jsx(Yt,{selectedUsers:x,selectedUserObjects:w,onRemove:F,onRoleChange:k,getRoleOptions:Ie}),e.jsx(Gt,{usersToRemove:f,allUsers:R,onRemove:b}),e.jsx(Ht,{usersToUpdate:j,allUsers:R,onRemove:L,getRoleOptions:Ie}),e.jsx(Wt,{existingShares:v,isInitialLoading:_,isSearching:Q,resource:t,onShare:()=>{},getRoleOptions:Ie,allUsers:R,currentUser:n,handleUserToggle:F,handleUserRoleChange:k,handleRemoveAccess:T,handleUpdateAccess:(q,H,U)=>{g.addUserToUpdate({id:q,currentRole:H,newRole:U})}})]}):e.jsx("div",{className:"mt-3",children:e.jsx(Xt,{currentUser:n,currentShare:z,isSharing:l,isUpdating:o,isRemoving:c,onUpdateAccess:A,onRemoveAccess:O,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 ht({resource:t,resourceType:a,currentUser:n,onShareTabTypeChange:r,isSharing:l=!1,isUpdating:o=!1,isRemoving:c=!1}){var Y;const{searchQuery:i,debouncedSearchQuery:d,setSearchQuery:m}=s.useShareSearchWithDebounce(),u=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate(),f=s.useShareCurrentMode(),j=s.useShareTenantWideRole(),p=s.useShareAllTenantsRole(),y=s.useShareSelectedTenant(),g=s.useShareManagementActions(),{data:C,isLoading:E}=lr({enabled:(n==null?void 0:n.type)==="organization"}),[B,S]=M.useState((n==null?void 0:n.type)==="organization"?"all_tenants":"specific_tenant_users");M.useEffect(()=>{(n==null?void 0:n.type)==="tenant"?(g.setCurrentContext("tenant-dialog"),g.setCurrentMode("specificTenantUsers")):(g.setCurrentContext("tenant-tab"),g.setCurrentMode("allTenants"))},[g,n==null?void 0:n.type]);const N=G=>{var se,ae,te,le;S(G);let X;if(G==="specific_tenant_users"?X="specific_users":G==="all_tenant_users"||G==="all_tenants"?X="all_users":X="specific_users",r==null||r(X),(n==null?void 0:n.type)==="tenant"?(g.setCurrentContext("tenant-dialog"),G==="specific_tenant_users"?g.setCurrentMode("specificTenantUsers"):G==="all_tenant_users"&&(g.setCurrentMode("allTenantUsers"),n!=null&&n.tenantId&&g.setSelectedTenant(n.tenantId))):(g.setCurrentContext("tenant-tab"),G==="specific_tenant_users"?g.setCurrentMode("specificTenantUsers"):G==="all_tenant_users"?g.setCurrentMode("allTenantUsers"):G==="all_tenants"&&g.setCurrentMode("allTenants")),G==="all_tenant_users"){const K=(ae=(se=D==null?void 0:D.shares)==null?void 0:se.tenantWide)==null?void 0:ae[0];K&&K.role!==void 0&&g.setTenantWideRole(K.role)}else if(G==="all_tenants"){const K=(le=(te=D==null?void 0:D.shares)==null?void 0:te.allTenantsOnly)==null?void 0:le[0];K&&K.role!==void 0&&g.setAllTenantsRole(K.role)}},v=G=>{g.setSelectedTenant(G)},{allUsers:I,existingShares:D,isLoadingUsers:R,isErrorLoadingUsers:w,isLoadingShares:F,isErrorLoadingShares:k}=Ee({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=G=>{var te,le;const X=u.some(K=>K.id===G),se=h.includes(G),ae=(le=(te=D==null?void 0:D.shares)==null?void 0:te.specificTenantUsers)==null?void 0:le.some(K=>K.tenantUserId===G);X?g.removeSelectedUser(G):se?g.removeUserFromRemove(G):ae||g.addSelectedUser({id:G,role:"VIEWER"})},b=(G,X)=>{g.updateSelectedUserRole(G,X)},L=G=>{g.addUserToRemove(G),g.removeSelectedUser(G)},A=G=>{g.removeUserFromRemove(G)},O=G=>{g.removeUserFromUpdate(G)},z=(G,X,se)=>{g.addUserToUpdate({id:G,currentRole:X,newRole:se})},_=(G,X)=>{B==="all_tenant_users"?g.setTenantWideRole(X):B==="all_tenants"&&g.setAllTenantsRole(X)},Q=()=>{B==="all_tenant_users"?g.setTenantWideRole("VIEWER"):B==="all_tenants"&&g.setAllTenantsRole("VIEWER")},$=(()=>{var G,X,se,ae;return f==="allTenants"?(X=(G=D==null?void 0:D.shares)==null?void 0:G.allTenantsOnly)==null?void 0:X[0]:f==="allTenantUsers"?(ae=(se=D==null?void 0:D.shares)==null?void 0:se.tenantWide)==null?void 0:ae[0]:null})();M.useEffect(()=>{var G,X,se,ae;if(B==="all_tenant_users"){const te=(X=(G=D==null?void 0:D.shares)==null?void 0:G.tenantWide)==null?void 0:X[0];te&&te.role!==void 0&&g.setTenantWideRole(te.role)}else if(B==="all_tenants"){const te=(ae=(se=D==null?void 0:D.shares)==null?void 0:se.allTenantsOnly)==null?void 0:ae[0];te&&te.role!==void 0&&g.setAllTenantsRole(te.role)}},[B,D,g]);const q=I.filter(G=>u.some(X=>X.id===G.id)),H=R||F,U=w||k,P=()=>(n==null?void 0:n.type)==="tenant"||B==="all_tenants"?!0:y&&(B==="specific_tenant_users"||B==="all_tenant_users");return e.jsxs(e.Fragment,{children:[U&&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"})]})}),!U&&n&&e.jsxs("div",{className:"max-h-[500px] space-y-4 overflow-y-auto",children:[e.jsx(Jt,{shareType:B,onShareTypeChange:N,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(be,{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(De,{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(lt,{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(De,{className:"mb-3 h-6 w-6 text-orange-500"})}]}),(n==null?void 0:n.type)==="organization"&&(B==="specific_tenant_users"||B==="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:E,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:E?"Loading tenants...":"Select a tenant..."})}),e.jsx(s.SelectContent,{className:"z-[51]",children:(Y=C==null?void 0:C.tenants)==null?void 0:Y.map(G=>e.jsx(s.SelectItem,{value:G.id,children:G.name},G.id))})]})]}),P()?e.jsx(e.Fragment,{children:B==="specific_tenant_users"?e.jsxs("div",{className:"space-y-4",children:[e.jsx(qt,{value:i,onChange:m}),e.jsx(Yt,{selectedUsers:u,selectedUserObjects:q,onRemove:G=>T(G),onRoleChange:b,getRoleOptions:Ie}),e.jsx(Gt,{usersToRemove:h,allUsers:I,onRemove:A}),e.jsx(Ht,{usersToUpdate:x,allUsers:I,onRemove:O,getRoleOptions:Ie}),e.jsx(Wt,{existingShares:D,isInitialLoading:!!H,isSearching:!1,resource:t,onShare:()=>{},getRoleOptions:Ie,allUsers:I,currentUser:n,handleUserToggle:T,handleUserRoleChange:b,handleRemoveAccess:L,handleUpdateAccess:z})]}):B==="all_tenant_users"||B==="all_tenants"?e.jsx("div",{className:"mt-6",children:e.jsx(Xt,{currentUser:n,currentShare:$,isSharing:l,isUpdating:o,isRemoving:c,onUpdateAccess:_,onRemoveAccess:Q,allUsersToUpdate:f==="allTenantUsers"&&(($==null?void 0:$.role)===void 0||j!==$.role)||f==="allTenants"&&(($==null?void 0:$.role)===void 0||p!==$.role)?{currentRole:($==null?void 0:$.role)||"VIEWER",newRole:f==="allTenantUsers"?j:p}:null,allUsersToRemove:f==="allTenantUsers"&&($==null?void 0:$.role)===void 0||f==="allTenants"&&($==null?void 0:$.role)===void 0})}):null}):(n==null?void 0:n.type)==="organization"&&(B==="specific_tenant_users"||B==="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(lt,{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 Zt=()=>{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(),m=M.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]),u=M.useMemo(()=>x=>s.validateShareData(x),[]),h=M.useMemo(()=>{if(!t||!a)return!1;switch(t){case"org-tab":return a==="specificOrgUsers"?n.length>0||r.length>0||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:m,validateShareData:u,isCurrentStateValid:h,currentContext:t,currentMode:a,selectedUsers:n,usersToRemove:r,usersToUpdate:l,selectedTenant:o,orgWideRole:c,allTenantsRole:i,tenantWideRole:d}};function xt({resource:t,existingShares:a,isSharing:n,isRemoving:r,isUpdating:l,onShare:o,onClose:c,shareTabType:i,currentAllUsersShare:d,onRemoveAccess:m}){const u=s.useShareSelectedUsers(),h=s.useShareUsersToRemove(),x=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const f=s.useShareSelectedTenant();s.useShareSelectedTab();const j=s.useShareOrgWideRole(),p=s.useShareAllTenantsRole(),y=s.useShareTenantWideRole(),{buildShareData:g,validateShareData:C,isCurrentStateValid:E}=Zt(),B=n||r||l,S=()=>{var R,w,F,k;if(B)return"Updating...";if(i==="specific_users"){if(u.length===0&&h.length===0&&x.length===0)return"Select users to share with";const T=u.length+h.length+x.length;return T===0?"Select users to share with":u.length>0&&h.length>0?`Update access for ${T} user${T!==1?"s":""}`:h.length>0&&u.length===0&&x.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:u.length>0&&h.length===0&&x.length===0?`Share with ${u.length} user${u.length!==1?"s":""}`:x.length>0&&u.length===0&&h.length===0?`Update access for ${x.length} user${x.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=(R=a==null?void 0:a.shares)==null?void 0:R.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0)return"Share with All Tenants";const b=T.role;return p===b?"Remove Access":"Update Access"}else if(i==="all_tenant_users"){const T=(k=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:k[0];if(!T||T.role===void 0)return"Share with All Tenant Users";const b=T.role;return y===b?"Remove Access":"Update Access"}else if(i==="specific_tenant_users"){if(u.length===0&&h.length===0&&x.length===0)return"Select users to share with";const T=u.length+h.length+x.length;return T===0?"Select users to share with":u.length>0&&h.length>0?`Update access for ${T} user${T!==1?"s":""}`:h.length>0&&u.length===0&&x.length===0?`Remove access for ${h.length} user${h.length!==1?"s":""}`:u.length>0&&h.length===0&&x.length===0?`Share with ${u.length} user${u.length!==1?"s":""}`:x.length>0&&u.length===0&&h.length===0?`Update access for ${x.length} user${x.length!==1?"s":""}`:`Update access for ${T} user${T!==1?"s":""}`}return"Share"},N=()=>B||!t||i==="all_tenant_users"&&!f||i==="specific_tenant_users"&&!f?!0:!E,v=()=>{const R=g();R&&C(R)&&o(R)},I=()=>{var R,w,F,k;if(i==="all_users")if(!d||d.role===void 0){const T=g();T&&C(T)&&o(T)}else{const T=d.role;if(j===T)m==null||m();else{const L=g();if(L&&C(L)){const A={...L,updateAccess:!0};o(A)}}}else if(i==="all_tenants"){const T=(w=(R=a==null?void 0:a.shares)==null?void 0:R.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0){const b=g();b&&C(b)&&o(b)}else{const b=T.role;if(p===b)m==null||m();else{const A=g();if(A&&C(A)){const O={...A,updateAccess:!0};o(O)}}}}else if(i==="all_tenant_users"){const T=(k=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:k[0];if(!T||T.role===void 0){const b=g();b&&C(b)&&o(b)}else{const b=T.role;if(y===b)m==null||m();else{const A=g();if(A&&C(A)){const O={...A,updateAccess:!0};o(O)}}}}},D=()=>{var R,w,F,k;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=(R=a==null?void 0:a.shares)==null?void 0:R.allTenantsOnly)==null?void 0:w[0];if(!T||T.role===void 0)return"default";const b=T.role;return p===b?"destructive":"default"}else if(i==="all_tenant_users"){const T=(k=(F=a==null?void 0:a.shares)==null?void 0:F.tenantWide)==null?void 0:k[0];if(!T||T.role===void 0)return"default";const b=T.role;return y===b?"destructive":"default"}return"default"};return e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:c,disabled:B,children:"Close"}),(i==="specific_users"||i==="specific_tenant_users")&&e.jsx(e.Fragment,{children:(u.length>0||h.length>0||x.length>0)&&e.jsxs(s.Button,{onClick:v,disabled:!t||B,variant:"default",children:[B?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Ke,{className:"mr-2 h-4 w-4"}),!B&&S()]})}),(i==="all_users"||i==="all_tenants"||i==="all_tenant_users")&&e.jsxs(s.Button,{onClick:I,disabled:N(),variant:D(),children:[B?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(be,{className:"mr-2 h-4 w-4"}),!B&&S()]})]})}function Lr({resource:t,isSharing:a,isRemoving:n,isUpdating:r,onShare:l,onClose:o,shareTabType:c,currentAllUsersShare:i}){const d=s.useShareSelectedUsers(),m=s.useShareUsersToRemove(),u=s.useShareUsersToUpdate();s.useShareCurrentMode(),s.useShareCurrentContext();const h=s.useShareTenantWideRole();s.useShareSelectedTenant();const{buildShareData:x,validateShareData:f,isCurrentStateValid:j}=Zt(),p=a||n||r,y=()=>{if(p)return"Updating...";if(c==="specific_users"){if(d.length===0&&m.length===0&&u.length===0)return"Select users to share with";const S=d.length+m.length+u.length;return S===0?"Select users to share with":d.length>0&&m.length>0?`Update access for ${S} user${S!==1?"s":""}`:m.length>0&&d.length===0&&u.length===0?`Remove access for ${m.length} user${m.length!==1?"s":""}`:d.length>0&&m.length===0&&u.length===0?`Share with ${d.length} user${d.length!==1?"s":""}`:u.length>0&&d.length===0&&m.length===0?`Update access for ${u.length} user${u.length!==1?"s":""}`:`Update access for ${S} user${S!==1?"s":""}`}else if(c==="all_users"){if(!i||i.role==="NONE")return"Share with All Users";const S=i.role;return h===S?"Remove Access":"Update Access"}return"Share"},g=()=>p||!t?!0:!j,C=()=>{const S=x();S&&f(S)&&l(S)},E=()=>{if(!i||i.role==="NONE"){const S=x();S&&f(S)&&l(S)}else{const S=i.role;if(h===S){const v=x();if(v&&f(v)){const I={...v,removeAccess:!0};l(I)}}else{const v=x();if(v&&f(v)){const I={...v,updateAccess:!0};l(I)}}}},B=()=>!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||m.length>0||u.length>0)&&e.jsxs(s.Button,{onClick:C,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(Ke,{className:"mr-2 h-4 w-4"}),!p&&y()]})}),c==="all_users"&&e.jsxs(s.Button,{onClick:E,disabled:g(),variant:B(),children:[p?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Updating..."]}):e.jsx(Ke,{className:"mr-2 h-4 w-4"}),!p&&y()]})]})}function en({resource:t,resourceType:a,isSharing:n,isRemoving:r,isUpdating:l,onClose:o,onShare:c,onRemoveAccess:i}){var v,I,D,R;const{currentUser:d}=Ne(),[m,u]=M.useState("specific_users"),[h,x]=M.useState("specific_users"),f=s.useShareManagementActions(),j=s.useShareSelectedTab(),p=s.useShareCurrentMode(),{existingShares:y}=Ee({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"tenant"}),{existingShares:g}=Ee({debouncedSearchQuery:"",resourceId:(t==null?void 0:t.id)||"",resourceType:a,userType:"organization"}),C=(I=(v=y==null?void 0:y.shares)==null?void 0:v.tenantWide)==null?void 0:I[0],E=(R=(D=g==null?void 0:g.shares)==null?void 0:D.orgUsersOnly)==null?void 0:R[0],B=()=>{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"}},S=M.useCallback(()=>{f.resetShareState(),o()},[f,o]),N=(d==null?void 0:d.type)==="organization";return e.jsx(s.Dialog,{open:!0,onOpenChange:S,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(Ke,{className:"h-5 w-5"}),' Share "',t==null?void 0:t.title,'"']})}),e.jsx(s.DialogDescription,{children:N?"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."})]}),N?e.jsxs(s.Tabs,{value:j,onValueChange:w=>{const F=w;f.setSelectedTab(F),f.resetUserSelections()},className:"mb-4 min-h-0 flex-1",children:[e.jsxs(s.TabsList,{className:"mb-2 grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"org",children:"Org Users"}),e.jsx(s.TabsTrigger,{value:"tenant",children:"Tenant Users"})]}),e.jsx(s.TabsContent,{value:"org",className:"min-h-0 flex-1 overflow-hidden",children:e.jsx("div",{className:"h-full overflow-y-auto",children:e.jsx(Mr,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:x,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(ht,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:w=>u(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(ht,{resource:t,resourceType:a,currentUser:d,onShareTabTypeChange:w=>u(w),isSharing:n,isUpdating:l,isRemoving:r})})}),e.jsx("div",{className:"mt-auto flex-shrink-0",children:N?j==="org"?e.jsx(xt,{resource:t,existingShares:g,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:h,currentAllUsersShare:E,onRemoveAccess:i}):e.jsx(xt,{resource:t,existingShares:y,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:B(),currentAllUsersShare:C,onRemoveAccess:i}):e.jsx(Lr,{resource:t,isSharing:n,isRemoving:r,isUpdating:l,onShare:c,onClose:o,shareTabType:m,currentAllUsersShare:C,onRemoveAccess:i})})]})})}function he(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function ke(t,a,n){return{resourceType:t,resourceId:a,data:{shares:n}}}function sn(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 m=he(r,l,[{scope:"org_users_only",role:t.orgWideRole}]);o(m,{onSuccess:()=>{d()}})}else if(t.mode==="specificOrgUsers"){const{selectedUsers:m,usersToRemove:u,usersToUpdate:h}=t;if(m&&m.length>0){const x=he(r,l,m.map(f=>({scope:"specific_org_user",orgUserId:f.id,role:f.role})));o(x,{onSuccess:()=>{d()}})}if(u&&u.length>0){const x=ke(r,l,u.map(f=>{var p,y;const j=(y=(p=i==null?void 0:i.shares)==null?void 0:p.specificOrgUsers)==null?void 0:y.find(g=>g.orgUserId===f);return{scope:"specific_org_user",orgUserId:f,role:(j==null?void 0:j.role)||"VIEWER"}}));c(x,{onSuccess:()=>{d()}})}h&&h.length>0&&h.forEach(x=>{const f=he(r,l,[{scope:"specific_org_user",orgUserId:x.id,role:x.newRole}]);o(f,{onSuccess:()=>{d()}})})}break;case"tenant-tab":if(t.mode==="allTenants"){const m=he(r,l,[{scope:"all_tenants_only",role:t.allTenantsRole}]);o(m,{onSuccess:()=>{d()}})}else if(t.mode==="allTenantUsers"){const m=he(r,l,[{scope:"all_tenant_users",tenantId:t.tenantId,role:t.tenantWideRole}]);o(m,{onSuccess:()=>{d()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:m,usersToRemove:u,usersToUpdate:h,tenantId:x}=t;if(u&&u.length>0){const f=ke(r,l,u.map(j=>{var y,g;const p=(g=(y=i==null?void 0:i.shares)==null?void 0:y.specificTenantUsers)==null?void 0:g.find(C=>C.tenantUserId===j);return{scope:"specific_tenant_user",tenantUserId:j,tenantId:x,role:(p==null?void 0:p.role)||"VIEWER"}}));c(f,{onSuccess:()=>{d()}})}if(h&&h.length>0&&h.forEach(f=>{const j=he(r,l,[{scope:"specific_tenant_user",tenantUserId:f.id,tenantId:x,role:f.newRole}]);o(j,{onSuccess:()=>{d()}})}),m&&m.length>0){const f=he(r,l,m.map(j=>({scope:"specific_tenant_user",tenantUserId:j.id,tenantId:x,role:j.role})));o(f,{onSuccess:()=>{d()}})}}break;case"tenant-dialog":if(t.mode==="allTenantUsers")if(t.removeAccess){const m=ke(r,l,[{scope:"all_tenant_users",role:"VIEWER"}]);c(m,{onSuccess:()=>{d()}})}else if(t.updateAccess){const m=he(r,l,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);o(m,{onSuccess:()=>{d()}})}else{const m=he(r,l,[{scope:"all_tenant_users",tenantId:n==null?void 0:n.tenantId,role:t.tenantWideRole}]);o(m,{onSuccess:()=>{d()}})}else if(t.mode==="specificTenantUsers"){const{selectedUsers:m,usersToRemove:u,usersToUpdate:h}=t;if(m&&m.length>0){const x=he(r,l,m.map(f=>({scope:"specific_tenant_user",tenantUserId:f.id,role:f.role})));o(x,{onSuccess:()=>{d()}})}if(u&&u.length>0){const x=ke(r,l,u.map(f=>{var p,y;const j=(y=(p=i==null?void 0:i.shares)==null?void 0:p.specificTenantUsers)==null?void 0:y.find(g=>g.tenantUserId===f);return{scope:"specific_tenant_user",tenantUserId:f,role:(j==null?void 0:j.role)||"VIEWER"}}));c(x,{onSuccess:()=>{d()}})}h&&h.length>0&&h.forEach(x=>{const f=he(r,l,[{scope:"specific_tenant_user",tenantUserId:x.id,role:x.newRole}]);o(f,{onSuccess:()=>{d()}})})}break}}function tn(t,a,n,r){var m,u,h,x,f,j;const{resourceType:l,resourceId:o,removeMutation:c,existingShares:i,resetUserSelections:d}=r;if(o)if(t.length>0){const p=ke(l,o,t.map(y=>{var C,E;const g=(E=(C=i==null?void 0:i.shares)==null?void 0:C.specificTenantUsers)==null?void 0:E.find(B=>B.tenantUserId===y);return{scope:"specific_tenant_user",tenantUserId:y,role:(g==null?void 0:g.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 g=(u=(m=i==null?void 0:i.shares)==null?void 0:m.allTenantsOnly)==null?void 0:u[0];if(g){const C=ke(l,o,[{scope:"all_tenants_only",role:g.role}]);c(C,{onSuccess:()=>{d()},onError:E=>{console.error("Remove all-tenants access failed:",E)}})}}else if(y){const g=(x=(h=i==null?void 0:i.shares)==null?void 0:h.tenantWide)==null?void 0:x[0];if(g){const C=ke(l,o,[{scope:"all_tenant_users",role:g.role}]);c(C,{onSuccess:()=>{d()},onError:E=>{console.error("Remove all-tenant-users access failed:",E)}})}}else{const g=(j=(f=i==null?void 0:i.shares)==null?void 0:f.orgUsersOnly)==null?void 0:j[0];if(g){const C=ke(l,o,[{scope:"org_users_only",role:g.role}]);c(C,{onSuccess:()=>{d()},onError:E=>{console.error("Remove org-wide access failed:",E)}})}}}}function Or(t,a,n){const r=s.useShareManagementActions(),l=s.useShareUsersToRemove(),o=s.useShareSelectedTab(),c=s.useShareCurrentMode(),{currentUser:i}=Ne(),{existingShares:d}=Ee({debouncedSearchQuery:"",resourceId:t||"",resourceType:ee.DASHBOARD,userType:"tenant"}),m=M.useCallback(()=>{r.resetUserSelections()},[r]),u=M.useCallback(x=>{if(!t)return;const f={resourceType:ee.DASHBOARD,resourceId:t,shareMutation:a,removeMutation:n,existingShares:d,resetUserSelections:m};sn(x,f,i)},[t,a,n,d,m,i]),h=M.useCallback(()=>{if(!t)return;const x={resourceType:ee.DASHBOARD,resourceId:t,removeMutation:n,existingShares:d,resetUserSelections:m};tn(l,o||"",c||"",x)},[t,a,n,d,m,l,o,c]);return{handleShareSubmit:u,handleRemoveAccess:h}}function Rr(t,a,n){const{currentUser:r}=Ne(),l=s.useShareManagementActions(),o=s.useShareUsersToRemove(),c=s.useShareSelectedTab(),i=s.useShareCurrentMode(),{existingShares:d}=Ee({debouncedSearchQuery:"",resourceId:t||"",resourceType:ee.VISUAL,userType:"tenant"}),m=M.useCallback(()=>{l.resetUserSelections()},[l]),u=M.useCallback(x=>{if(!t)return;const f={resourceType:ee.VISUAL,resourceId:t,shareMutation:a,removeMutation:n,existingShares:d,resetUserSelections:m};sn(x,f,r)},[t,a,n,d,m,r]),h=M.useCallback(()=>{if(!t)return;const x={resourceType:ee.VISUAL,resourceId:t,removeMutation:n,existingShares:d,resetUserSelections:m};tn(o,c||"",i||"",x)},[t,a,n,d,m,o,c,i]);return{handleShareSubmit:u,handleRemoveAccess:h}}function Br(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 Vs(t){const[a,n]=M.useState(null),[r,l]=M.useState(null);return M.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 Fr(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 pt(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 Pr(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 zr(){var x;const{setCardSql:t}=s.useEditorActions(),a=s.useEditorStore(f=>f.frame),n=s.useEditorStore(f=>f.card),r=Vs(((x=n.customCardPreferences)==null?void 0:x.url)||""),l=s.useEditorStore(f=>f.selectedSchemaName),o=s.useEditorStore(f=>f.selectedDatamodelId),c=s.useEditorStore(f=>f.selectedDatabaseName),i=s.useEditorStore(f=>f.selectedTableName),d=s.useEditorStore(f=>f.selectedConnectionId),m=s.useEditorStore(f=>f.isShowingVisual),u=n.sql;return{getUpdatedFrame:M.useCallback(()=>{var g;let f=u;u&&!u.includes("{{")&&(f=Br(u),t(f));const j=(g=r==null?void 0:r.getState())==null?void 0:g.settings,p={...n,dataSource:n.dataSource||{mode:"directSource"},lastSelectedSchema:l,lastSelectedDatamodelId:o,lastSelectedDatabase:c,lastSelectedTable:i,connectionId:d,sql:f,customCfg:m?n.customCfg:null,...j&&{customCardPreferences:{...n.customCardPreferences,settings:j}}},y=a.cards.map(C=>C.id===n.id?p:C);return{...a,cards:y,activeCardId:Fr(y,a.activeCardId)}},[n,a,m,l,o,c,i,d,t,r,u])}}function _s(){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:m,setIsDashboardPanelOpen:u}=s.useDashboardActions(),h=s.useDashboardStore(p=>p.selectedSheetId),x=pr((n==null?void 0:n.id)||"",{enabled:!!(n!=null&&n.id)&&!!(t!=null&&t.accessToken)}),f=M.useCallback(async p=>{try{r(p);const{data:y,fromCache:g}=await pt((t==null?void 0:t.accessToken)||"",p.id,a);return Pr(y,l,o,c,i),{success:!0,fromCache:g}}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=M.useCallback(async p=>{try{if(r(p),!h)return{success:!1,error:"No sheet selected. Please select a sheet first."};const{data:y,fromCache:g}=await pt((t==null?void 0:t.accessToken)||"",p.id,a),C=y.frameObject;if(!C)return{success:!1,error:"Visual has no frame data"};const E={...C,id:s.v4()};return m(h,E,"end"),c(!0),d(E.id),u(!1),{success:!0,fromCache:g}}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,m,c,d,u]);return{visual:x.data,isLoading:x.isLoading,isError:x.isError,error:x.error,handleEditLibraryVisual:f,handleAddLibraryVisual:j,getUpdatedFrame:zr().getUpdatedFrame,refetch:x.refetch}}function Vr(){const[t,a]=M.useState(""),[n,r]=M.useState(!1),[l,o]=M.useState(""),[c,i]=M.useState(""),[d,m]=M.useState(!1),[u,h]=M.useState(null),[x,f]=M.useState(!1),[j,p]=M.useState(null),[y,g]=M.useState(null),{setIsDashboardEditing:C,setIsVisualEditing:E}=s.useDashboardActions(),{handleEditLibraryVisual:B,handleAddLibraryVisual:S}=_s(),{resources:N,isLoading:v,isError:I,createResource:D,updateResource:R,deleteResource:w,duplicateResource:F,shareResource:k,isCreating:T,isDeleting:b,removeResourceShares:L,isSharing:A,isRemovingShares:O,isUpdatingShares:z}=gr(()=>{f(!1),p(null)},()=>{r(!1),o(""),i("")}),{handleShareSubmit:_,handleRemoveAccess:Q}=Rr((u==null?void 0:u.id)||null,k,L);Ne();const W=N.filter(V=>{var Z,oe;return((Z=V==null?void 0:V.title)==null?void 0:Z.toLowerCase().includes(t.toLowerCase()))||((oe=V==null?void 0:V.description)==null?void 0:oe.toLowerCase().includes(t.toLowerCase()))}),$=V=>new Date(V).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),q=()=>{l.trim()&&D({title:l,description:c,isPrivate:!1})},H=V=>{p(V),f(!0)},U=()=>{j&&w(j.id)},{startUpdating:P,stopUpdating:Y,isUpdating:G}=$t(),X=(V,Z)=>{const oe=Z.title!==void 0?"title":"description";P(V,oe),R({resourceId:V,data:Z},{onSuccess:()=>{Y(V,oe)},onError:()=>{Y(V,oe)}})},se=V=>{g(V),F(V,{onSettled:()=>g(null)})},ae=V=>{B(V)},te=V=>{S(V)},le=V=>{const Z=N.find(oe=>oe.id===V);Z&&R({resourceId:V,data:{isPrivate:!Z.isPrivate}})},K=V=>{h(V),m(!0)};return s.useShareUsersToRemove(),s.useShareManagementActions(),Ee({debouncedSearchQuery:"",resourceId:(u==null?void 0:u.id)||"",resourceType:ee.VISUAL,userType:"tenant"}),v?e.jsx(_t,{}):I?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:V=>o(V.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:V=>i(V.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:V=>a(V.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:W.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(ms,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No visuals found"})]}):W.map(V=>e.jsx(yr,{visual:V,onAddVisual:te,onEditVisual:ae,onUpdateVisual:X,onDeleteClick:H,onDuplicateVisual:se,onTogglePrivacy:le,onShareVisual:K,isDeleting:b,isDuplicating:y===V.id,isTitleUpdating:G(V.id,"title"),isDescriptionUpdating:G(V.id,"description"),formatDate:$},V.id))})}),d&&u&&e.jsx(en,{resource:u,resourceType:ee.VISUAL,onShare:_,isSharing:A,isRemoving:O,isUpdating:z,onClose:()=>{m(!1),h(null)},onRemoveAccess:Q}),e.jsx(s.AlertDialog,{open:x,onOpenChange:V=>{!V&&b||(f(V),V||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:b,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:V=>{V.preventDefault(),V.stopPropagation(),U()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:b,children:b?"Deleting...":"Delete"})]})]})})]})}function _r({dashboard:t,isDeleting:a,isDuplicating:n,isTitleUpdating:r=!1,isDescriptionUpdating:l=!1,onLoadDashboard:o,onUpdateDashboard:c,onDeleteClick:i,onDuplicateDashboard:d,onShareDashboard:m,formatDate:u,onDashboardItemClick:h}){var N;const{selectDashboard:x}=s.useManagementActions(),f=s.useIsDashboardSelected(t.id),[j,p]=M.useState(!1),[y,g]=M.useState(!1),C=s.useDashboardStore(v=>v.actions.setIsDashboardPanelOpen);M.useEffect(()=>{n?(p(!0),g(!0)):y&&(p(!1),g(!1))},[n,y]);const E=()=>t.ownership.isOwner?t.ownership.status==="private"?e.jsx(Lt,{className:"h-3 w-3 text-purple-500"}):e.jsx(be,{className:"h-3.5 w-3.5 text-blue-600"}):e.jsx(De,{className:"h-3.5 w-3.5 text-slate-500"}),B=()=>e.jsx(s.LayoutDashboard,{className:"h-4 w-4 text-slate-400"}),S=()=>{x(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",f&&"rounded-md bg-slate-50 ring-1 ring-inset ring-border dark:bg-slate-900/50"),tabIndex:0,onClick:S,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:B()})}),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&&f,isPending:r,placeholder:"Untitled Dashboard",displayClassName:"line-clamp-1 max-w-[220px] text-sm font-medium text-slate-900 dark:text-slate-100"})}),e.jsx("div",{className:"shrink-0",children:E()})]}),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&&f,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(),m(t)},children:[e.jsx(be,{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),C(!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(De,{className:"h-3 w-3"}),e.jsx("span",{children:((N=t.ownership.createdBy)==null?void 0:N.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:u(t.lastModified)})]})]})]})]})})})]})]},t.id)}function Ur({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 $r(t){const[a,n]=M.useState(""),[r,l]=M.useState(!1),[o,c]=M.useState(""),[i,d]=M.useState(""),[m,u]=M.useState(!1),[h,x]=M.useState(null),[f,j]=M.useState(!1),[p,y]=M.useState(null),[g,C]=M.useState(null),E=s.useManagementStore(K=>K.lastSelectedDashboard),B=s.useManagementStore(K=>K.actions.selectDashboard);s.useShareManagementActions(),s.useShareUsersToRemove(),s.useShareSelectedTab(),s.useShareCurrentMode();const{resources:S,isLoading:N,isError:v,createResource:I,updateResource:D,deleteResource:R,duplicateResource:w,isCreating:F,isDeleting:k,isSharing:T,isRemovingShares:b,isUpdatingShares:L,shareResource:A,removeResourceShares:O}=fr(()=>{j(!1),y(null),E&&B(E)},()=>{l(!1),c(""),d("")}),{handleShareSubmit:z,handleRemoveAccess:_}=Or((h==null?void 0:h.id)||null,A,O),{currentUser:Q}=Ne(),W=S.filter(K=>{var V,Z;return((V=K==null?void 0:K.title)==null?void 0:V.toLowerCase().includes(a.toLowerCase()))||((Z=K==null?void 0:K.description)==null?void 0:Z.toLowerCase().includes(a.toLowerCase()))}),$=K=>new Date(K).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),q=()=>{o.trim()&&I({title:o,description:i,isPrivate:!1})},H=K=>{var V;(V=t.onLoadDashboard)==null||V.call(t,K)},U=K=>{y(K),j(!0)},P=()=>{p&&R(p.id)},Y=K=>{C(K),w(K,{onSettled:()=>C(null)})},{startUpdating:G,stopUpdating:X,isUpdating:se}=$t(),ae=(K,V)=>{const Z=V.title!==void 0?"title":"description";G(K,Z),D({resourceId:K,data:V},{onSuccess:()=>{X(K,Z)},onError:()=>{X(K,Z)}})},te=K=>{const V=S.find(Z=>Z.id===K);V&&D({resourceId:K,data:{isPrivate:!V.isPrivate}})},le=K=>{x(K),Q==null||Q.type,u(!0)};return Ee({debouncedSearchQuery:"",resourceId:(h==null?void 0:h.id)||"",resourceType:ee.DASHBOARD,userType:"tenant"}),N?e.jsx(_t,{}):v?e.jsx(Ur,{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:W.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx(ga,{className:"mx-auto mb-2 h-8 w-8 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No dashboards found"})]}):W.map(K=>e.jsx(_r,{dashboard:K,isDeleting:k,isDuplicating:g===K.id,isTitleUpdating:se(K.id,"title"),isDescriptionUpdating:se(K.id,"description"),onLoadDashboard:H,onEditDashboard:t.onEditDashboard,onUpdateDashboard:ae,onDeleteClick:U,onDuplicateDashboard:Y,onTogglePrivacy:te,onShareDashboard:le,formatDate:$,onDashboardItemClick:t.onDashboardItemClick},K.id))})}),m&&h&&e.jsx(en,{resource:h,resourceType:ee.DASHBOARD,onShare:z,isSharing:T,isRemoving:b,isUpdating:L,onClose:()=>{u(!1),x(null)},onRemoveAccess:_}),e.jsx(s.AlertDialog,{open:f,onOpenChange:K=>{!K&&k||(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:k,children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:K=>{K.preventDefault(),K.stopPropagation(),P()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:k,children:k?"Deleting...":"Delete"})]})]})})]})}function nn({isOpen:t,onClose:a,className:n,onDashboardItemClick:r}){s.useDashboardStore(f=>f.dashboard);const{setDashboard:l,addSheet:o}=s.useDashboardStore(f=>f.actions),{currentUser:c}=Ne(),i=c,[d,m]=s.useLocalStorageState("resource-management-active-tab","dashboards"),u=Kt(a,{enabled:t}),h=f=>{},x=f=>{console.log("Editing dashboard:",f)};return e.jsx(s.TooltipProvider$1,{children:e.jsxs("div",{ref:u,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:m,className:"flex h-9 grow flex-col",children:[e.jsx("div",{className:"px-5",children:e.jsxs(s.TabsList,{className:"grid h-8 w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"dashboards",className:"h-6",children:"Dashboards"}),e.jsx(s.TabsTrigger,{value:"visuals",className:"h-6",children:"Visuals"})]})}),e.jsx(s.TabsContent,{value:"dashboards",className:"flex-1",children:e.jsx($r,{onLoadDashboard:h,onEditDashboard:x,onDashboardItemClick:r})}),e.jsx(s.TabsContent,{value:"visuals",className:"flex-1",children:e.jsx(Vr,{})})]})})]})})}function qr(){var H,U;const{authToken:t,tokenProps:a}=s.useSemaphorContext();s.useDashboardStore(P=>P.theme);const n=s.useDashboardStore(P=>P.lenses),r=s.useDashboardStore(P=>P.selectedLensId),l=n==null?void 0:n.find(P=>P.id===r),o=s.useDashboardStore(P=>P.dashboard);s.useDashboardStore(P=>P.selectedSheetId);const c=s.useDashboardStore(P=>P.isDashboardEditing),i=s.useEditorStore(P=>P.card),d=s.useEditorStore(P=>P.selectedConnectionId),[m,u]=M.useState(!1),h=s.useDashboardStore(P=>P.isDashboardPanelOpen),x=s.useDashboardStore(P=>P.actions.setIsDashboardPanelOpen),f=s.useDashboardStore(P=>P.filterValues),j=s.useDashboardStore(P=>P.isVisualEditing),p=s.useManagementStore(P=>P.selectedDashboard),y=s.useManagementStore(P=>P.initialDashboard),g=p?(U=p==null?void 0:p.permissions)==null?void 0:U.canEdit:(H=y==null?void 0:y.permissions)==null?void 0:H.canEdit,C=s.useDashboardStore(P=>P.showFilters);s.useDashboardStore(P=>P.showDashboardJSON);const E=s.useDashboardStore(P=>P.onSaveFunction),B=s.useDashboardStore(P=>P.actions.setShowFilters),{addFrame:S,setSelectedFrameId:N}=s.useDashboardStore(P=>P.actions),{getSelectedSheet:v,setIsDashboardEditing:I,setShowDashboardJSON:D}=s.useDashboardStore(P=>P.actions),R=v(),{setInitialDashboard:w}=s.useManagementStore(P=>P.actions),{resources:F}=zs(ee.DASHBOARD);M.useEffect(()=>{if(F&&F.length>0){const P=o==null?void 0:o.id;if(P){const Y=F.find(G=>G.id===P);Y&&w(Y)}}},[F,o==null?void 0:o.id,w]);const k=a.orgUserId||a.tenantId,T=c&&!j&&k&&g;function b(){var X,se;const P=i.dataSource;if(P)return P;const Y=(se=(X=o.aiContext)==null?void 0:X.selectedEntities)==null?void 0:se[0],G=Y==null?void 0:Y.type;if(Y)return{connectionId:Y.connectionId,connectionType:Y.connectionType,type:G,selectedEntities:[Y]}}const L=()=>{if(!c||!R)return;const Y={dataSource:b(),mode:"explorer",connectionId:d,id:s.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},G={id:s.v4(),cards:[Y],activeCardId:Y.id};S(R.id,G),N(G.id)},A=()=>{I(!0)},[O,z]=M.useState(!1),_=Ut(ee.DASHBOARD);async function Q(){const P=as(o);z(!0);const Y={template:P};_.mutate({resourceId:P.id,data:Y},{onSuccess:()=>{z(!1),s.ue.success("Dashboard saved!")},onError:()=>{z(!1),s.ue.error("Failed to save dashboard")}})}async function W(){if(u(!0),!r||!l)return;const P=as(o),Y=JSON.stringify(P),G={...l,template:Y,filterValues:f};await ks(G,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),E==null||E(P),u(!1)}if(j)return null;const $=(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:()=>x(!0),className:"h-7 p-2",children:e.jsx(ba,{className:"h-4 w-4"})}),!j&&e.jsx(s.Label,{children:$})]}),e.jsxs("div",{className:"flex gap-2",children:[!1,!j&&e.jsx(Qa,{}),!j&&e.jsx(Vt,{}),c&&!j&&k&&e.jsx(Ha,{}),!j&&k&&e.jsx(Ka,{}),c&&!j&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:L,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:A,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:()=>{I(!1),D(!1)},children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),c&&!j&&k&&l&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:m,onClick:W,size:"sm",children:[e.jsx(ws,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),T&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"outline",disabled:O,onClick:Q,size:"sm",children:[O?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ws,{className:"mr-2 h-4 w-4"}),O?"Saving...":"Save"]}),!C&&!j&&c&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>B(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),!j&&c&&!1,!j&&!1,!j&&e.jsx(nn,{isOpen:h,onClose:()=>x(!1)})]})]})}function Yr({name:t,items:a,value:n,onChange:r,isLoading:l,isError:o,refetch:c,className:i,icon:d,showNone:m=!1}){const u=me.useRef(null),[h,x]=me.useState(!1),[f,j]=me.useState("100%"),p=m?[...a||[],{id:"none",name:"None"}]:a;me.useLayoutEffect(()=>{u.current&&j(u.current.offsetWidth)},[]);function y(){var C;return l?"Loading...":o?"Error":n?(C=a==null?void 0:a.find(E=>E.id===n))==null?void 0:C.name:`Select ${t}`}function g(C,E){r(E),x(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:x,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:u,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:f},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx(Ot,{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(C=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:C.name,onSelect:E=>g(E,C.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",n===C.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:C.name,children:C.name})]})},C.id))})]})]})})]})}function Ve({title:t,items:a,value:n,isLoading:r,isError:l,refetch:o,onChange:c,showNone:i=!1,className:d,disabled:m=!1,type:u="combobox"}){const h=r?"Loading...":l?"Error":n;function x(){if(t==="Connection")return e.jsx(La,{className:"size-4"});if(t==="Database")return e.jsx(s.Database,{className:"size-4"});if(t==="Schema")return e.jsx(Ia,{className:"size-4"});if(t==="Table")return e.jsx(_e,{className:"size-4"});if(t==="Model")return e.jsx(na,{className:"size-4"})}function f(){return e.jsxs(s.Select,{disabled:m,value:h,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",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(Ot,{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(Yr,{icon:x(),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:u==="select"?f():j()})})}function Gr({column:t}){const[a,n]=M.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:m}=s.useEditorAside(),u=s.useEditorStore(p=>p.actions.setSqlGen),h=s.useEditorStore(p=>p.actions.setCardSql),x=s.useEditorStore(p=>p.actions.setRunSql);function f(p,y){var B;const g=s.createSqlGenConfig(p,i,y),C=(B=d==null?void 0:d.find(S=>S.id===c))==null?void 0:B.name;u(g);const E=s.getSql(g,s.fmt(l||""),s.fmt(r),C||"",m,o||"");E&&(h(E),x(!0)),n(!1)}function j(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>f(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>f(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>f(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>f(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>f(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:j()})]})}function Us({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(Ge,{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(ns,{className:"size-3 text-muted-foreground"}):t.data_type.startsWith("json")?e.jsx(aa,{className:"size-3 text-muted-foreground"}):e.jsx(s.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:t.data_type})})]})}function fs({column:t,className:a}){return e.jsxs("div",{className:s.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(Us,{column:t}),e.jsx("span",{children:t.column_name})]})}function Hr({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 Kr({onClick:t,column:a}){const n=s.useDndStore(u=>u.activeId),r=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.groupByColumns}),l=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.metricColumns}),o=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.filterColumns});function c(u){return i(u)||d(u)||m(u)}function i(u){return r==null?void 0:r.some(h=>h.name===u.column_name)}function d(u){return l==null?void 0:l.some(h=>h.name===u.column_name)}function m(u){return o==null?void 0:o.some(h=>h.name===u.column_name)}return e.jsxs("div",{onClick:()=>t(a),className:s.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":c(a)}),children:[n===a.column_name&&e.jsx(s.DragOverlay,{children:e.jsx(fs,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(fs,{column:a})}),e.jsx(Hr,{id:a.column_name,type:"column",children:e.jsx(fs,{column:a})})]})}const gs={id:"__placeholder__",role:"groupby",type:"string"},js={id:"__placeholder__",role:"groupby",type:"string"},ys={id:"__placeholder__",role:"metric",type:"number"},vs={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},an={id:"__placeholder__"},Ae="droppable-group-by",Me="droppable-metrics",Le="droppable-pivot-by",ls="sortable-group-by",Ds="sortable-metrics",os="sortable-pivot-by",Es="droppable-filters",Ts="sortable-filters",$s="sortable-order-by";function Qr(){const t=s.useDndStore(T=>T.insertIndex),a=s.useEditorStore(T=>{var b;return((b=T.card.queryConfig)==null?void 0:b.groupByColumns)||[]}),n=s.useEditorStore(T=>{var b;return((b=T.card.queryConfig)==null?void 0:b.metricColumns)||[]}),r=s.useEditorStore(T=>{var b;return((b=T.card.queryConfig)==null?void 0:b.filterColumns)||[]}),l=s.useEditorStore(T=>{var b;return((b=T.card.queryConfig)==null?void 0:b.orderBy)||[]}),o=s.useEditorStore(T=>{var b;return((b=T.card.queryConfig)==null?void 0:b.pivotColumns)||[]}),{setInsertIndex:c,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:m,setPreviewFilterColumns:u,setPreviewPivotColumns:h}=s.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setFilterColumns:j,setOrderByColumns:p,setPivotByColumns:y}=s.useEditorActions(),{columns:g}=s.useDataColumns(),{formattedTableName:C}=s.useEditorAside(),E=s.useSensors(s.useSensor(s.MouseSensor,{activationConstraint:{distance:1}})),B=T=>{var A;const{active:b,over:L}=T;if(((A=b.data.current)==null?void 0:A.type)==="column"&&L){const O=L.id,z=g.find($=>$.column_name===b.id);if(!z)return;const _=s.isNumberDataType(z.data_type),Q=s.isTextDataType(z.data_type),W=s.isDateDataType(z.data_type);if(Q||W){if(a.some(q=>q.id===O)){const q=a.findIndex(U=>U.id===O);c(q);const H=a.filter(U=>U.id!==gs.id);H.splice(q,0,gs),d(H)}else if(L.id===Ae){c(a.length);const q=[...a,gs];d(q),m(n),u(r)}}if(Q||W){if(o.some(q=>q.id===O)){const q=o.findIndex(U=>U.id===O);c(q);const H=o.filter(U=>U.id!==js.id);H.splice(q,0,js),h(H)}else if(L.id===Le){c(o.length);const q=[...o,js];h(q),d(a),m(n),u(r)}}if(_||Q){if(n.some(q=>q.id===O)){console.log("isOverMetricSortable",O);const q=n.findIndex(U=>U.id===O);c(q);const H=n.filter(U=>U.id!==ys.id);H.splice(q,0,ys),m(H)}else if(L.id===Me){c(n.length);const q=[...n,ys];m(q),u(r),d(a),h(o)}}if(N(z)){if(r.some(q=>q.id===O)){const q=r.findIndex(U=>U.id===O);c(q);const H=r.filter(U=>U.id!==vs.id);H.splice(q,0,vs),u(H)}else if(L.id===Es){c(r.length);const q=[...r,vs];u(q),m(n),d(a),h(o)}}}else d(a),m(n),u(r),h(o)};function S(T){i(T.active.id),c(null),d(a),m(n),u(r),h(o)}function N(T){return!r.some(b=>b.name===T.column_name)}function v(T,b="SUM"){const{column_name:L,data_type:A}=T,O=[...n],z=t!==null?t:n.length,_={...T,id:ge(L),name:L,label:We(L,b),type:A,role:"metric",aggregate:b};O.splice(z,0,_),f(O)}function I(T){const b=s.isTextDataType(T.data_type);s.isDateDataType(T.data_type);const L=[...o],A=t!==null?t:o.length;let O;b?O={...T,id:ge(T.column_name),name:T.column_name,type:T.data_type,role:"groupby"}:O={...T,id:ge(T.column_name),name:T.column_name,type:T.data_type,role:"groupby",label:Ue(T.column_name,"month"),granularity:"month"},L.splice(A,0,O),y(L)}function D(T){const b=s.isTextDataType(T.data_type);s.isDateDataType(T.data_type);const L=[...a],A=t!==null?t:a.length;let O;b?O={...T,id:ge(T.column_name),name:T.column_name,type:T.data_type,role:"groupby"}:O={...T,id:ge(T.column_name),name:T.column_name,type:T.data_type,role:"groupby",label:Ue(T.column_name,"month"),granularity:"month"},L.splice(A,0,O),x(L)}function R(T){const b=[...r],L=t!==null?t:r.length,A={...T,id:ge(T.column_name),name:T.column_name,type:T.data_type,sql:s.getDefaultFilterSql(T.data_type,C,s.fmt(T.column_name)),role:"filter"};b.splice(L,0,A),j(b)}function w(T){var O,z,_,Q,W,$,q,H;const{active:b,over:L}=T,A=b.data.current;if((A==null?void 0:A.type)==="column"&&L){const U=g.find(X=>X.column_name===b.id);if(!U)return;const P=s.isNumberDataType(U.data_type),Y=s.isTextDataType(U.data_type),G=s.isDateDataType(U.data_type);(Y||G)&&(L.id===Ae||((O=L.data.current)==null?void 0:O.type)===ls)&&D(U),(Y||G)&&(L.id===Le||((z=L.data.current)==null?void 0:z.type)===os)?I(U):(P||Y)&&(L.id===Me||((_=L.data.current)==null?void 0:_.type)===Ds)?(P&&v(U),Y&&v(U,"COUNT")):N(U)&&(L.id===Es||((Q=L.data.current)==null?void 0:Q.type)===Ts)&&R(U)}if(L&&((W=L.data.current)==null?void 0:W.type)===ls&&a.some(U=>U.id===b.id)){const U=a.findIndex(Y=>Y.id===b.id),P=a.findIndex(Y=>Y.id===L.id);if(U!==-1&&P!==-1&&U!==P){const Y=[...a],[G]=Y.splice(U,1);Y.splice(P,0,G),x(Y)}}if(L&&(($=L.data.current)==null?void 0:$.type)===os&&o.some(U=>U.id===b.id)){const U=o.findIndex(Y=>Y.id===b.id),P=o.findIndex(Y=>Y.id===L.id);if(U!==-1&&P!==-1&&U!==P){const Y=[...o],[G]=Y.splice(U,1);Y.splice(P,0,G),y(Y)}}if(L&&((q=L.data.current)==null?void 0:q.type)===Ds&&n.some(U=>U.id===b.id)){const U=n.findIndex(Y=>Y.id===b.id),P=n.findIndex(Y=>Y.id===L.id);if(U!==-1&&P!==-1&&U!==P){const Y=[...n],[G]=Y.splice(U,1);Y.splice(P,0,G),f(Y)}}if(L&&((H=L.data.current)==null?void 0:H.type)===Ts&&r.some(U=>U.id===b.id)){const U=r.findIndex(Y=>Y.id===b.id),P=r.findIndex(Y=>Y.id===L.id);if(U!==-1&&P!==-1&&U!==P){const Y=[...r],[G]=Y.splice(U,1);Y.splice(P,0,G),j(Y)}}F(T),i(null),c(null),d(a),m(n),u(r),h(o)}function F(T){const{active:b,over:L}=T,A=b.data.current;if((A==null?void 0:A.type)===$s&&L){const O=l.findIndex(_=>Ye(_.columnId)===b.id),z=l.findIndex(_=>Ye(_.columnId)===L.id);if(O!==-1&&z!==-1&&O!==z){const _=[...l],[Q]=_.splice(O,1);_.splice(z,0,Q),p(_)}}}function k(){i(null),c(null),d(a),m(n),u(r)}return{handleDragOver:B,handleDragEnd:w,handleDragStart:S,handleDragCancel:k,sensors:E}}function ge(t){return`${t}-${s.v4()}`}function We(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 Ye(t){return`${$s}-${t}`}function Ue(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 Wr({schemaName:t,tableName:a,columns:n,status:r}){const l=s.useEditorStore(b=>b.sqlGen),o=s.useEditorStore(b=>b.isDevMode),c=s.useEditorStore(b=>b.selectedConnectionId),i=s.useEditorStore(b=>{var L,A;return(A=(L=b.card)==null?void 0:L.queryConfig)==null?void 0:A.metricColumns});s.useEditorStore(b=>{var L,A;return(A=(L=b.card)==null?void 0:L.queryConfig)==null?void 0:A.groupByColumns});const d=s.useEditorStore(b=>b.selectedDatabaseName),m=s.useEditorStore(b=>b.selectedSchemaName),u=s.useEditorStore(b=>b.selectedTableName),h=s.useEditorStore(b=>b.selectedDatamodelId),x=s.useDashboardStore(b=>b.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:j}=s.useDashboardActions(),{addColumnToMetricColumns:p,addColumnToGroupBy:y,setCardSql:g,setRunSql:C,setSqlGen:E,setIsShowingVisual:B}=s.useEditorActions(),{connectionType:S,modelItems:N,selectedDatamodelName:v}=s.useEditorAside();function I(b){var L;if(o){const A=s.createSqlGenConfig(b,l);E(A);const O=(L=N==null?void 0:N.find(_=>_.id===h))==null?void 0:L.name,z=s.getSql(A,s.fmt(t),s.fmt(a),O||"",S,d||"");z&&(g(z),C(!0))}if(!o){if(s.isTextDataType(b.data_type))if(i&&i.length>0){const A={...b,role:"groupby",id:ge(b.column_name),name:b.column_name,type:b.data_type};y(A)}else{const A={...b,role:"metric",id:ge(b.column_name),name:b.column_name,label:We(b.column_name,"COUNT"),type:b.data_type,aggregate:"COUNT"};p(A)}if(s.isDateDataType(b.data_type)){const A={...b,role:"groupby",id:ge(b.column_name),name:b.column_name,type:b.data_type,label:Ue(b.column_name,"month"),granularity:"month"};y(A)}if(s.isNumberDataType(b.data_type)){const A={...b,role:"metric",id:ge(b.column_name),name:b.column_name,label:We(b.column_name,"SUM"),type:b.data_type,aggregate:"SUM"};p(A)}}}function D(b){b===!0&&(u||v)&&c?(f({connectionId:c,connectionType:S==="S3"||S==="API"?"DuckDb":S||"",databaseName:d||"",schemaName:m||"",tableName:u||"",datamodelName:s.resolveDatamodelName(v),datamodelId:h||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(j({connectionId:c||"",connectionType:S||"",tableName:u||"",datamodelName:s.resolveDatamodelName(v),datamodelId:h||"",databaseName:d||"",schemaName:m||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function R(){const b=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:v,connectionType:S,databaseName:d||""});B(!1);const L=S==="MSSQL"?`SELECT top 10 * FROM ${b}`:`SELECT * FROM ${b} LIMIT 10`;g(L),C(!0)}function w(){const b=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:v,connectionType:S,databaseName:d||""});g(`SELECT COUNT(*) as count FROM ${b}`),C(!0)}function F(){return(x==null?void 0:x.find(b=>b.connectionId===c&&(b.tableName===u||b.datamodelName===v)))!==void 0}function k(b){return o?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>I(b),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Us,{column:b}),e.jsx("span",{children:b.column_name})]}),e.jsx("div",{onClick:L=>L.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(b.data_type)&&e.jsx(Gr,{column:b})})]}):e.jsx(Kr,{onClick:I,column:b})}function T(){return e.jsxs(e.Fragment,{children:[e.jsxs(s.Toggle,{title:`${F()?"Remove from":"Add to"} Assistant Scope`,pressed:F(),onPressedChange:D,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":F(),"text-muted-foreground":!F()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ka,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:w,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Rt,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-6",children:Array.from({length:3}).map((b,L)=>e.jsx(s.Skeleton,{className:"h-7 w-full"},L))}):e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[o&&e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:T()}),e.jsxs(s.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-2 py-0",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(b=>e.jsx("div",{className:s.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:k(b)},b.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function rn({ColumnsComponent:t,type:a}){var Te;const n=s.useEditorStore(ne=>ne.card),r=s.useEditorStore(ne=>ne.selectedConnectionId),l=s.useDashboardStore(ne=>ne.showFilters),o=s.useEditorStore(ne=>ne.selectedDatamodelId),c=s.useEditorStore(ne=>ne.selectedDatabaseName),i=s.useEditorStore(ne=>ne.selectedSchemaName),d=s.useEditorStore(ne=>ne.selectedTableName),m=s.useEditorStore(ne=>ne.isDevMode),{setSelectedTableName:u,setIsDevMode:h,setCardSql:x}=s.useEditorActions(),{connectionItems:f,modelItems:j,schemaItems:p,databaseItems:y,tableItems:g,columns:C,isConnectionsLoading:E,isModelsLoading:B,isConnectionsError:S,isModelsError:N,isDatabasesLoadingOrFetching:v,isDatabaseError:I,isSchemaLoadingOrFetching:D,isSchemaError:R,isColumnsError:w,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:k,isTableError:T,connectionType:b,isNonDbConnection:L,refetchDatabases:A,refetchModels:O,refetchSchemas:z,refetchTables:_,refetchColumns:Q,refetchConnections:W,handleConnectionChange:$,handleDatabaseChange:q,handleSchemaChange:H,handleDatamodelChange:U,handleTableChange:P,tableName:Y,schemaName:G}=s.useEditorAside(),{data:X,refetch:se}=s.useDashboardCardQuery(n);function ae(){return t?t(G,Y,C):e.jsx(Wr,{schemaName:G,tableName:Y,columns:C,status:F?"Loading...":w?"Error":"Success"})}function te(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function le(ne){ne===!0?X&&(x(X.userSql),setTimeout(()=>{se()},100)):x(""),h(ne)}function K(){if(!r||b==="S3"||b==="API")return null;if(!o||o==="none")return e.jsx(Ve,{refetch:A,showNone:!0,onChange:q,isError:I,isLoading:v,items:y,value:c||"",title:"Database",type:"combobox"})}function V(){if(r&&!L&&(!c||c==="none")&&(!o||o==="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 Z(){if(!r||b==="S3"||b==="API")return null;if(!c||c==="none")return e.jsx(Ve,{refetch:O,showNone:!0,onChange:U,isError:N,isLoading:B,items:j,value:o||"",title:"Model",type:"combobox"})}function oe(){return!r||b==="S3"||b==="API"||!c||c==="none"?null:e.jsx(Ve,{refetch:z,onChange:H,isError:R,isLoading:D,items:p,value:i||"",title:"Schema",type:"combobox"})}function Ce(){function ne(){let ie=!1;return b==="API"?(ie=!1,ie):((b==="S3"||r&&c&&c!=="none"&&i)&&(ie=!0),ie)}return ne()?e.jsx(Ve,{refetch:_,onChange:P,isError:T,items:g,isLoading:k,value:d||"",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]":!l}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(Ve,{refetch:W,items:f,title:"Connection",value:r||"",onChange:$,isLoading:E,isError:S,type:"combobox",connectionTooltip:((Te=f==null?void 0:f.find(ne=>ne.id===r))==null?void 0:Te.type)||""}),K(),V(),Z(),oe(),Ce()]}),ae(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:m,onCheckedChange:le,id:"dev-mode"}),e.jsx(s.Label,{htmlFor:"dev-mode",children:"Advanced Mode"})]}),e.jsxs(s.Button,{onClick:te,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(Ea,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function ln({error:t,className:a="",textClassName:n="",copyButtonClassName:r=""}){const[l,o]=M.useState(!1),c=M.useRef(null),i=M.useRef(!1);function d(){t&&!i.current&&navigator.clipboard.writeText(t)}function m(x){(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),d())}function u(){const x=window.getSelection();if(x&&x.toString().trim()!==""){const f=x.toString();navigator.clipboard.writeText(f),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:m,onMouseUp:u,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 on({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(ln,{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(ha,{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(va,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function cn({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(It,{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(on,{sql:t,error:a,onDebugWithAssistant:n})})]})}var dn={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ft=M.createContext&&M.createContext(dn),Jr=["attr","size","title"];function Xr(t,a){if(t==null)return{};var n=Zr(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 Zr(t,a){if(t==null)return{};var n={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(a.indexOf(r)>=0)continue;n[r]=t[r]}return n}function is(){return is=Object.assign?Object.assign.bind():function(t){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},is.apply(this,arguments)}function gt(t,a){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);a&&(r=r.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,r)}return n}function cs(t){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?gt(Object(n),!0).forEach(function(r){el(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):gt(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function el(t,a,n){return a=sl(a),a in t?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,t}function sl(t){var a=tl(t,"string");return typeof a=="symbol"?a:a+""}function tl(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 un(t){return t&&t.map((a,n)=>M.createElement(a.tag,cs({key:n},a.attr),un(a.child)))}function Re(t){return a=>M.createElement(nl,is({attr:cs({},t.attr)},a),un(t.child))}function nl(t){var a=n=>{var{attr:r,size:l,title:o}=t,c=Xr(t,Jr),i=l||n.size||"1em",d;return n.className&&(d=n.className),t.className&&(d=(d?d+" ":"")+t.className),M.createElement("svg",is({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,c,{className:d,style:cs(cs({color:t.color||n.color},n.style),t.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),o&&M.createElement("title",null,o),t.children)};return ft!==void 0?M.createElement(ft.Consumer,null,n=>a(n)):a(dn)}function al(t){return Re({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function mn(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:m}=s.useEditorActions(),u=M.useRef(),h=M.useRef({}),x=r.cards.find(p=>p.id===o),f=M.useCallback(()=>{let p="";return t==="python"&&(p=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(p=(x==null?void 0:x.sql)||""),p},[t,x]);M.useEffect(()=>{if(o&&l.id&&l.id!==o){if(u.current&&c){const p=u.current.getModel();p&&(h.current[l.id]=p);let y=h.current[o];if(!y){const g=f();y=c.editor.createModel(g,t),h.current[o]=y}u.current.setModel(y)}d(o,l),m(!0)}},[o,l,d,c,m,t,f]),M.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]),M.useEffect(()=>{const p=u.current;p&&c&&l&&p.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return i(),!1})},[c,i,l]);function j(p,y){if(u.current=p,!h.current[l.id]){const g=p.getModel(),C=f();h.current[l.id]=g||(y==null?void 0:y.editor.createModel(C,t))||p.getModel()}p.setModel(h.current[l.id])}return{handleEditorDidMount:j}}function rl(){const t=s.useEditorStore(c=>c.card.sql),a=s.useEditorStore(c=>c.sqlGen),{setCardSql:n,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:l}=mn("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 ll(){const t=s.useEditorStore(l=>l.card.python),{setCardPython:a}=s.useEditorActions(),{handleEditorDidMount:n}=mn("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 ol({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function qs({variant:t="outline"}){var c;const{setCardSql:a}=s.useEditorActions();s.useEditorStore(i=>i.frame);const n=s.useEditorStore(i=>i.card);Vs(((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}=_s();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 il(){const t=s.useQueryClient(),[a,n]=M.useState(!1),r=s.useDashboardStore(m=>m.actions.setIsDashboardPanelOpen),{setIsVisualEditing:l}=s.useDashboardActions(),{getUpdatedFrame:o}=_s(),c=s.useSelectedVisual(),i=jr(),d=()=>{const m=o();if(!(c!=null&&c.id)){s.ue.error("No visual selected");return}n(!0),i.mutate({visualId:c.id,data:{frameObject:m}},{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(ws,{className:"mr-2 size-4 font-bold"}),"Save"]})]})}function Ys(){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:m}=r;d&&m&&n.setQueryData(d,m)}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 hs(){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:m,setCardPreferences:u,updateDataSource:h,clearQueryConfig:x,setCardConfig:f,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({}),x(),f(void 0),d(""),m(""),u({}),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 cl(){const t=s.useQueryClient(),[a,n]=M.useState(!1),[r,l]=M.useState(!1);s.useEditorStore(_=>_.frame);const o=s.useEditorStore(_=>_.card);s.useEditorStore(_=>_.isShowingVisual),s.useEditorStore(_=>_.selectedConnectionId),s.useEditorStore(_=>_.tempQueryData),s.useEditorStore(_=>_.selectedDatabaseName),s.useEditorStore(_=>_.selectedDatamodelId),s.useEditorStore(_=>_.selectedSchemaName);const c=s.useEditorStore(_=>_.showAIDialog);s.useEditorStore(_=>_.selectedTableName);const i=s.useEditorStore(_=>{var Q;return(Q=_==null?void 0:_.card)==null?void 0:Q.sql}),d=s.useEditorStore(_=>{var Q;return(Q=_==null?void 0:_.card)==null?void 0:Q.python}),{sheetFilterValues:m}=s.useSheetFilterValues(),{setCardCustomCfg:u,setQueryResultColumns:h,setCardSql:x,setTempQueryData:f,setPythonStdOut:j,setCardPreferences:p,setCardType:y,setCardPython:g,runAssistant:C,setShowAIDialog:E}=s.useEditorActions();s.useEditorStore(_=>_.onSave),s.useEditorStore(_=>_.onClose),s.useEditorStore(_=>_.actions.setSqlGen);const B=s.useEditorStore(_=>_.runSql),S=s.useEditorStore(_=>_.actions.setRunSql),N=s.useEditorStore(_=>_.actions.setIsSqlRunning),{data:v,isLoading:I,isFetching:D,isSuccess:R,isError:w,error:F,queryKey:k,refetch:T,errorMessage:b}=s.useDashboardCardQuery(o);M.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:_}=s.getKeys(v.records);h(_)}},[v,h,j]),M.useEffect(()=>{(I||D)&&N(!0),(w||R)&&N(!1),w&&(h([]),j(""))},[I,D,v,j,w,R,N,h,F]),M.useEffect(()=>{B&&(t.getQueryData(k)||T(),S(!1))},[B,T,S,k,t]);async function L(){const _=`Can you help me debug this query in the current table scope?
|
|
437
|
-
|
|
438
|
-
Error:
|
|
439
|
-
|
|
440
|
-
${b}
|
|
441
|
-
|
|
442
|
-
Query:
|
|
443
|
-
|
|
444
|
-
${i}
|
|
445
|
-
|
|
446
|
-
${d?`Python:
|
|
447
|
-
${d}`:""}
|
|
448
|
-
`;C(_)}function A(){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(ol,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.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 O(){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(rl,{})}),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(ll,{})}),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:I||D,onClick:()=>{T()},className:"h-8 shrink-0",size:"sm",children:[I||D?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(cn,{sql:v==null?void 0:v.sql,error:b,onDebugWithAssistant:L}),e.jsx(hs,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:_=>n(_),className:"",size:"sm",children:e.jsx(al,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:c,onClick:()=>{E(!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(Ys,{}),e.jsx(qs,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[O(),A()]}),z()]})}function dl({data:t}){var c;const[a,n]=M.useState([]),l=Object.keys(t[0]).map(i=>({accessorKey:i,header:({column:d})=>{const m=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[i,m==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),o=s.useReactTable({data:t,columns:l,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsxs(s.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:[e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:o.getHeaderGroups().map(i=>e.jsx(s.TableRow,{className:"",children:i.headers.map(d=>e.jsx(s.TableHead,{className:"h-11 font-semibold text-foreground",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},i.id))}),e.jsx(s.TableBody,{children:(c=o.getRowModel().rows)!=null&&c.length?o.getRowModel().rows.map(i=>e.jsx(s.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":i.getIsSelected()&&"selected",children:i.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-2",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},i.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:l.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ul({card:t}){var C,E,B,S,N,v,I,D,R,w,F;const[a,n]=M.useState(!1),[r,l]=M.useState([]),{authToken:o}=s.useSemaphorContext(),c=s.getTokenParams(o==null?void 0:o.accessToken),i=s.useDashboardStore(k=>k.themeStyle),d={colors:((E=(C=i==null?void 0:i.chart)==null?void 0:C.dataset)==null?void 0:E.backgroundColor)||[]};(B=t.customCardPreferences)!=null&&B.inputData;const{getCard:m}=s.useCustomVisual(((S=t.customCardPreferences)==null?void 0:S.url)||""),u=((N=t.customCardPreferences)==null?void 0:N.visualType)||"single",h=s.useEditorStore(k=>k.frame),{setCustomCardPreferences:x}=s.useEditorActions(),{data:f}=s.useDashboardCardQuery(t),j=M.useCallback((k,T)=>{l(b=>({...b,[k]:T}))},[]);if(!((v=t.customCardPreferences)!=null&&v.componentName))return null;const p=m((I=t.customCardPreferences)==null?void 0:I.componentName);function y(k){n(k)}const g=Object.keys(((D=t.customCardPreferences)==null?void 0:D.dataInputCardIds)||{}).map(k=>{var L,A,O;const T=(A=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:A[k].cardId,b=(O=h==null?void 0:h.cards)==null?void 0:O.find(z=>z.id===T);return b||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(M.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&u==="single"&&e.jsx(p,{editing:!0,params:c,theme:d,settings:(R=t.customCardPreferences)==null?void 0:R.settings,onDataChange:j,data:(f==null?void 0:f.records)||[]}),p&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((w=t.customCardPreferences)==null?void 0:w.dataInputCardIds)||{}).map(k=>{var L,A,O;const T=(A=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:A[k].cardId,b=(O=h==null?void 0:h.cards)==null?void 0:O.find(z=>z.id===T);if(b)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:y,onDataChange:j,dataInputIndex:k,card:b},b.id+k)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:d,onDataChange:j,settings:g.map(k=>{var T;return(T=k==null?void 0:k.customCardPreferences)==null?void 0:T.settings}),data:g.map(k=>k!=null&&k.id?r==null?void 0:r[k.id]:[])})})]})]},(F=t.customCardPreferences)==null?void 0:F.componentName)})}function hn({className:t,...a}){var I;const n=s.useEditorStore(D=>D.card),r=s.isExplorerCard(n),l=((I=n.customCardPreferences)==null?void 0:I.showCardHeader)??!0,o=s.useEditorStore(D=>D.frame),c=s.useDashboardStore(D=>D.dashboard.filters),i=s.useEditorStore(D=>D.actions.setRunSql),{updateFilter:d}=s.useDashboardActions(),m=c==null?void 0:c.find(D=>D.id===o.filterId),{data:u,isLoading:h,isFetching:x,errorMessage:f,pagination:j,refetch:p}=s.useDashboardCardQuery(n),{setCard:y,updateCardInFrame:g}=s.useEditorActions(),{data:C}=s.useTopoJson(n),E=M.useMemo(()=>n.type==="pivotTable"&&(u!=null&&u.records)&&(u==null?void 0:u.records.length)>0?s.getPivotTableConfig({card:n,data:{records:(u==null?void 0:u.records)||[],columnSubtotalMeta:u==null?void 0:u.columnSubtotalMeta,subtotalColumns:u==null?void 0:u.subtotalColumns,pivotSchema:(u==null?void 0:u.pivotSchema)||[],groupByColumns:u==null?void 0:u.groupByColumns}}):null,[n,u==null?void 0:u.records,u==null?void 0:u.columnSubtotalMeta,u==null?void 0:u.subtotalColumns,u==null?void 0:u.pivotSchema,u==null?void 0:u.groupByColumns]),B=(D,R)=>{var F,k;const w={...n,paginationConfig:{page:D+1,pageSize:R}};y(w),g(w),n.sql&&((k=(F=n.preferences)==null?void 0:F.tablePrefs)!=null&&k.enableDevModePagination)&&i(!0)},S=M.useMemo(()=>!n.id||!(u!=null&&u.records)?null:s.createChartConfig({card:n,data:u==null?void 0:u.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:C}),[n.id,u==null?void 0:u.records,n.type,n.queryConfig,n.customCfg,n.preferences,C]);function N(D){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(ul,{card:D})})}function v(){if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!h&&!x)return f?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.SearchX,{className:"size-8 text-destructive"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r?"Error fetching data. Please check your chart configuration":"Error fetching data. Please check your SQL or Python code."})]}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No results to display"})]});if((h||x)&&n.type!=="table")return e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!n.id)return null;if(n.type==="custom")return N(n);if(!["table","pivotTable","aggregateTable","custom"].includes(n.type)&&S)return e.jsx(e.Fragment,{children:h||x?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:S})});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:(u==null?void 0:u.records)||[],paginationMetadata:j,onPaginationChange:B,isLoading:h||x})});if(n.type==="pivotTable"&&E)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:E.data,options:E.options,onAggregationChange:D=>{const R=s.handleAggregationChange(D,n.config),w={...n,config:R};y(w),g(w)},onAggregationLabelChange:D=>{const R=s.handleAggregationLabelChange(D,n.config),w={...n,config:R};y(w),g(w)}})});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:(u==null?void 0:u.records)||[],groupByColumns:u==null?void 0:u.groupByColumns,pivotSchema:u==null?void 0:u.pivotSchema,paginationMetadata:j,onPaginationChange:B,onAggregationChange:D=>{const R=s.handleAggregationChange(D,n.config),w={...n,config:R};y(w),g(w)},isLoading:h||x})})}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:D=>y({...n,title:D}),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:D=>y({...n,description:D}),children:e.jsx(s.CardDescription,{children:n.description||"Add description"})},n.description)]}),m&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{enabled:!0,className:"my-1",text:m.title||m.column,onSave:D=>d({...m,title:D}),children:e.jsx(s.Label,{children:m.title})}),e.jsx(s.FilterComponent,{filter:m})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:v()})]})}const bs=({language:t,value:a,onChange:n,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:a,onChange:n}),ml=()=>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."})]})]}),hl=({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(bs,{language:"json",value:n,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(bs,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(bs,{language:"javascript",value:t,onChange:l})})]}),xl=({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 pl(){const[t,a]=M.useState(!1),[n,r]=M.useState(""),[l,o]=M.useState(""),[c,i]=M.useState(""),[d,m]=M.useState(""),u=s.useEditorStore(S=>S.card),h=s.useEditorStore(S=>S.card.customCfg),x=h?JSON.stringify(h,null,2):"",{data:f}=s.useDashboardCardQuery(u),{data:j}=s.useTopoJson(u),{setCardCustomCfg:p,setCustomVisualCode:y}=s.useEditorActions(),g=S=>{var N,v;return JSON.stringify({...S,data:{...S.data,datasets:(v=(N=S.data)==null?void 0:N.datasets)==null?void 0:v.map(I=>({...I,data:[]}))}},null,2)},C=()=>{var N,v;if(!((N=f==null?void 0:f.records)!=null&&N.length))return;const S=s.createChartConfig({card:u,data:f.records,cardType:u.type,queryConfig:u.queryConfig,preferences:u.preferences,topoJson:j});if(S){r(g(S)),i(((v=u.preferences)==null?void 0:v.customVisualCode)||"");const I=s.merge(S,h);o(g(I))}},E=()=>{try{if(c&&y(c),l){const S=JSON.parse(l),N=s.getObjectDiff(JSON.parse(n),S);p(N),m("")}}catch{m("Invalid JSON configuration")}},B=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:C,className:B?"":"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(ml,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(hn,{className:"w-1/2 rounded shadow-none"})}),e.jsx(hl,{customCode:c,cardCustomCfgString:x,mergedConfig:l,onConfigChange:S=>o(S??""),onCodeChange:S=>i(S??"")})]}),e.jsx(xl,{error:d,hasCardCustomConfig:!!h,onReset:()=>{o(n),p(null)},onApply:E,onClose:()=>a(!1)})]})]})}function xs(t){const[a,n]=M.useState(null);return a}function xn(){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 pn(){const{data:t,isLoading:a,isError:n}=xn(),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 m;if(i.isLoading&&(o=!0),i.isError&&(c=!0),i.data&&((m=t==null?void 0:t.plugins)!=null&&m[d])){const u=t.plugins[d],h=i.data.visuals.map(x=>({name:x.name,pluginName:u.label,componentType:x.componentType,pluginType:u.type,icon:x.icon,chartType:x.chartType,url:u.value}));l.push(...h)}}),{data:l,isLoading:o,isError:c}}function fl({onChartTypeChange:t}){const{setCardCustomCfg:a,setCardPreferences:n,setCardType:r,setCustomCardPreferences:l}=s.useEditorActions(),{data:o,isLoading:c,isError:i}=pn(),d=M.useCallback((m,u)=>{a(null),n({}),r(m),u&&l({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.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((m,u)=>e.jsx(gl,{text:m.name,onClick:()=>d("custom",m),icon:m.icon},`${m.url}-${m.name}-${u}`))})]})}const gl=({text:t,icon:a,onClick:n})=>{const r=xs(),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 Gs(t){return Re({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function jl(t){return Re({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function Hs(t){return Re({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function Ks(t){return Re({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4.387 3h15.226a1 1 0 0 1 .948 1.316l-5.105 15.316a2 2 0 0 1 -1.898 1.368h-3.116a2 2 0 0 1 -1.898 -1.368l-5.104 -15.316a1 1 0 0 1 .947 -1.316"},child:[]},{tag:"path",attr:{d:"M5 9h14"},child:[]},{tag:"path",attr:{d:"M7 15h10"},child:[]}]})(t)}function Qs(t){return Re({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function Ws(t){return Re({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function fn({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:l}=s.useEditorStore(u=>u.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:i}=s.useEditorActions();function d(u,h){o(null),r({}),n(u),["custom","text","map"].includes(u)&&(l(!0),i(void 0)),t==null||t()}const m=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(s.IconButton,{openDelay:m,tooltip:"Table",onClick:()=>d("table"),className:"h-10 p-4",children:e.jsx(_e,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bar Chart",onClick:()=>d("bar"),className:"h-10 p-4",children:e.jsx(ds,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Line Chart",onClick:()=>d("line"),className:"h-10 p-4",children:e.jsx(us,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Bar Chart",onClick:()=>d("stackedBar"),className:"h-10 p-4",children:e.jsx(Ms,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Line Chart",onClick:()=>d("stackedLine"),className:"h-10 p-4",children:e.jsx(Qs,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Scatter Chart",onClick:()=>d("scatter"),className:"h-10 p-4",children:e.jsx(Os,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bubble Chart",onClick:()=>d("bubble"),className:"h-10 p-4",children:e.jsx(Hs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Pie Chart",onClick:()=>d("pie"),className:"h-10 p-4",children:e.jsx(ms,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Doughnut Chart",onClick:()=>d("doughnut"),className:"h-10 p-4",children:e.jsx(Rs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Funnel Chart",onClick:()=>d("funnel"),className:"h-10 p-4",children:e.jsx(Ks,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Radar Chart",onClick:()=>d("radar"),className:"h-10 p-4",children:e.jsx(Fs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Polar Area Chart",onClick:()=>d("polarArea"),className:"h-10 p-4",children:e.jsx(Gs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Tornado Chart",onClick:()=>d("tornado"),className:"h-10 p-4",children:e.jsx(Ps,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>d("range"),className:"h-10 p-4",children:e.jsx(Ls,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"KPI",onClick:()=>d("kpi"),className:"h-10 p-4",children:e.jsx(Ws,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Text",onClick:()=>d("text"),className:"h-10 p-4",children:e.jsx(Dt,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>d("map"),className:"h-10 p-4",children:e.jsx(Bs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Custom",onClick:()=>d("custom"),className:"h-10 p-4",children:e.jsx(He,{className:s.cn("size-5",a)})})]})}function yl({chartType:t,className:a,customIcon:n,componentName:r}){const l=xs();switch(t){case"bar":return e.jsx(ds,{className:a});case"line":return e.jsx(us,{className:a});case"pie":return e.jsx(ms,{className:a});case"radar":return e.jsx(Fs,{className:a});case"scatter":return e.jsx(Os,{className:a});case"bubble":return e.jsx(Hs,{className:a});case"doughnut":return e.jsx(Rs,{className:a});case"stackedBar":return e.jsx(Ms,{className:a});case"stackedLine":return e.jsx(Qs,{className:a});case"polarArea":return e.jsx(Gs,{className:a});case"funnel":return e.jsx(Ks,{className:a});case"tornado":case"pyramid":return e.jsx(Ps,{className:a});case"range":return e.jsx(Ls,{className:a});case"kpi":return e.jsx(Ws,{className:a});case"text":return e.jsx(Qe,{className:a});case"map":return e.jsx(Bs,{className:a});case"custom":return n&&l?e.jsx(l,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(He,{className:a});default:return e.jsx(_e,{className:a})}}function gn({variant:t="ghost"}){var o,c;const[a,n]=M.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(yl,{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(fn,{onChartTypeChange:()=>n(!1)}),e.jsx(fl,{onChartTypeChange:()=>n(!1)})]})]})}const Je="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function jt(t,a){var r,l,o;const n=s.getNumberAxis(t,{});return["pie","doughnut","polarArea","funnel"].includes(a)?"category":((o=(l=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:l[n])==null?void 0:o.type)||"linear"}function vl(){var L,A,O,z,_,Q;const[t,a]=M.useState(!1),n=s.useEditorStore(W=>{var $;return($=W.card)==null?void 0:$.preferences}),r=s.useEditorStore(W=>{var $;return($=W.card)==null?void 0:$.type}),l=s.getNumberAxis(n,{}),[o,c]=M.useState(jt(n,r)),[i,d]=M.useState(((O=(A=(L=n==null?void 0:n.chartOptions)==null?void 0:L.scales)==null?void 0:A[l])==null?void 0:O.min)||""),[m,u]=M.useState(((Q=(_=(z=n==null?void 0:n.chartOptions)==null?void 0:z.scales)==null?void 0:_[l])==null?void 0:Q.max)||""),[h,x]=M.useState(i||m?"custom":"auto"),[f,j]=M.useState(""),[p,y]=M.useState(0),[g,C]=M.useState(""),[E,B]=M.useState(""),[S,N]=M.useState(""),v=s.useEditorStore(W=>W.actions.setCardPreferences),{updateCardInFrame:I}=s.useEditorActions(),D=s.useEditorStore(W=>W.card),R=["pie","doughnut","polarArea","funnel"].includes(r);M.useEffect(()=>{var W,$,q,H,U,P,Y,G,X,se,ae,te,le,K;c(jt(n,r)),d(((q=($=(W=n==null?void 0:n.chartOptions)==null?void 0:W.scales)==null?void 0:$[l])==null?void 0:q.min)===0?0:""),u(((P=(U=(H=n==null?void 0:n.chartOptions)==null?void 0:H.scales)==null?void 0:U[l])==null?void 0:P.max)||""),j(((se=(X=(G=(Y=n==null?void 0:n.chartOptions)==null?void 0:Y.scales)==null?void 0:G[l])==null?void 0:X.ticks)==null?void 0:se.stepSize)||""),y(((ae=n==null?void 0:n.numberAxisFormat)==null?void 0:ae.decimalPlaces)||0),C(((te=n==null?void 0:n.numberAxisFormat)==null?void 0:te.suffix)||""),B(((le=n==null?void 0:n.numberAxisFormat)==null?void 0:le.currency)||""),N(((K=n==null?void 0:n.numberAxisFormat)==null?void 0:K.locale)||"")},[t,n,l,r]);function w(W,$){return $===""||/^[0-9\b]+$/.test($)?Number($):Number(W)}function F(){const W=[...new Set(s.LOCALE_CURRENCY_PAIRS.map($=>$.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:E||"none",onValueChange:$=>B($==="none"?"":$),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),W.map($=>e.jsx(s.SelectItem,{value:$,children:$},$))]})})]}),e.jsxs(s.Select,{value:S,onValueChange:$=>N($),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map($=>e.jsx(s.SelectItem,{value:$.locale,children:$.locale},$.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:p,onChange:$=>y(Number($.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${Je}`})]})]})}function k(){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for number axis"})}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:R,value:o,onValueChange:W=>c(W),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"}),e.jsx(s.SelectItem,{value:"category",children:"Category"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:R,id:"scale-option",value:h,onValueChange:W=>x(W),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&o=="linear"&&T()]})}function T(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:i,onChange:W=>d($=>w($,W.target.value)),className:`col-span-1 h-8 w-full ${Je}`}),e.jsx(s.Input,{value:m,onChange:W=>u($=>w($,W.target.value)),id:"max",className:`col-span-1 h-8 w-full ${Je}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:f,onChange:W=>j($=>w($,W.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${Je}`})]})]})}function b(){var H;let W={};h==="custom"&&(W={min:i,max:m,ticks:{stepSize:f}});const $={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(H=n==null?void 0:n.chartOptions)==null?void 0:H.scales,[l]:{type:o,...o==="linear"?W:{}}}},numberAxisFormat:{decimalPlaces:p,suffix:g,currency:E,locale:S}};console.log($),v($);const q={...D,preferences:$};I(q)}return e.jsxs(s.Popover,{onOpenChange:W=>a(W),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Format Number",children:e.jsx(ua,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"max-w-65 z-[51]",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Format Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the format for number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[F(),k(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:b,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function bl(){const t=s.useEditorStore(i=>{var d,m,u,h;return(h=(u=(m=(d=i.card.preferences)==null?void 0:d.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.position}),a=s.useEditorStore(i=>{var d,m,u,h;return(h=(u=(m=(d=i.card.preferences)==null?void 0:d.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.align}),n=s.useEditorStore(i=>{var d,m,u,h;return(h=(u=(m=(d=i.card.preferences)==null?void 0:d.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.display}),{setLegendOptions:r}=s.useEditorActions(),l=i=>{r({display:i,position:t,align:a})},o=i=>{r({display:n,position:i,align:a})},c=i=>{r({display:n,position:t,align:i})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(Mt,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"z-[51] w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:n,onCheckedChange:l,id:"displayLegend"})})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>o("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>o("left"),children:e.jsx(Jn,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>o("bottom"),children:e.jsx(s.ArrowDown,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>o("right"),children:e.jsx(Xn,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>c("start"),children:e.jsx(Gn,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>c("center"),children:e.jsx(Yn,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>c("end"),children:e.jsx(Hn,{className:"size-4"})})]})]})]})]})]})})]})}function Nl(){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(dt,{className:"size-4"}):e.jsx(ct,{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(dt,{className:"size-4"}):e.jsx(ct,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?l():r()})}function jn(){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(Nl,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(vl,{}),e.jsx(bl,{})]}),!["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(ya,{className:"size-4"}),r==="x"&&e.jsx(oa,{className:"size-4"}),r==="y"&&e.jsx(Oa,{className:"size-4"}),r==="none"&&e.jsx(Va,{className:"size-4"})]})]}):null}function Cl(){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 g=Array.from(t.cards),[C]=g.splice(parseInt(y),1);g.splice(p,0,C),n({...t,cards:g})};function m(j){const p=t.cards.filter(C=>C.id!==j),y=p[0],g={...t,cards:p,activeCardId:y.id};n(g),r(y.id),l(y)}function u(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`};u(a,j)}function x(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"};u(j,p)}function f(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(ma,{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:[f(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:()=>m(j.id)})]},j.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>x(a),children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:h,children:e.jsx(ca,{className:"h-4 w-4"})})]})})}function yn(){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:m,isLoading:u,isFetching:h}=s.useDashboardCardQuery(a);function x(p){const y=t.cards.find(g=>g.id===p);if(y!=null&&y.sql){r||i(!0),o(p);return}if(y!=null&&y.queryConfig){r&&i(!1),f(p),o(p);return}r||f(p),o(p)}function f(p){const y={...t,cards:t.cards.map(C=>C.id===a.id?a:C),activeCardId:p};l(y);const g=y.cards.find(C=>C.id===p);g.sql&&d(!0),c(g)}function j(){return a.type==="kpi"?u||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border border-border",children:e.jsx(s.KPICard,{card:a,data:m==null?void 0:m.records,isPending:u||h})})}):a.type==="text"?u||h?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:n,card:a,data:m==null?void 0:m.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(hn,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:x,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(p=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:p.id,children:j()},p.id)),e.jsx(Cl,{})]})}function Xe({children:t}){var B,S;s.useEditorStore(N=>N.frame);const a=s.useEditorStore(N=>N.card),n=s.useEditorStore(N=>N.isDevMode),r=s.useEditorStore(N=>N.isShowingVisual),l=s.useDashboardStore(N=>N.isVisualEditing),o=s.useEditorStore(N=>N.pythonStdOut);s.useEditorStore(N=>N.actions.setRunSql);const{setFrame:c,setCard:i,setActiveTabCardId:d,runAssistant:m,setIsDevMode:u,setCardPreferences:h}=s.useEditorActions(),{data:x,isLoading:f,isFetching:j,errorMessage:p,refetch:y}=s.useDashboardCardQuery(a);function g(){const N=JSON.stringify(x==null?void 0:x.records,null,2),v=new Blob([N],{type:"application/json"}),I=URL.createObjectURL(v),D=document.createElement("a");D.href=I,D.download=`${a.title}.json`,D.click()}function C(){const v=[Object.keys(x==null?void 0:x.records.reduce((w,F)=>({...w,...F}),{})).join(","),...((x==null?void 0:x.records)||[]).map(w=>Object.values(w).join(","))].join(`
|
|
449
|
-
`),I=new Blob([v],{type:"text/csv"}),D=URL.createObjectURL(I),R=document.createElement("a");R.href=D,R.download=`${a.title}.csv`,R.click()}function E(){const N=`Can you get the documentation for ${a.type} chart?`;m(N)}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(gn,{}),l&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:E,children:e.jsx(ta,{className:"size-4"})}),!["table","custom"].includes(a.type)&&l&&e.jsx(pl,{})]}),!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:C,children:e.jsx(jl,{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:g,children:e.jsx(xa,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(x==null?void 0:x.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(jn,{})]}),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:((S=(B=a.preferences)==null?void 0:B.tablePrefs)==null?void 0:S.enableDevModePagination)??!1,onCheckedChange:N=>{var v;h({...a.preferences,tablePrefs:{...(v=a.preferences)==null?void 0:v.tablePrefs,enableDevModePagination:N}}),y()}}),e.jsx(s.Label,{htmlFor:"pagination",children:"Paginate Results"})]}),n&&e.jsx(wl,{})]}),r?e.jsx(yn,{}):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(Sl,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsx(dl,{data:(x==null?void 0:x.records)||[]}),p&&e.jsx(ln,{error:p})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function Sl(){const t=s.useEditorStore(n=>n.pythonStdOut);if(!t)return null;const a=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function wl(){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 kl(){var p,y;const t=s.useEditorStore(g=>g.card.customCardPreferences),{data:a}=xn(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(g=>g.card),l=s.useEditorStore(g=>g.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)||""),m=(p=d==null?void 0:d.visuals)==null?void 0:p.find(g=>g.name===(t==null?void 0:t.componentName));function u(g,C){if(!t)return;const B={...(t==null?void 0:t.dataInputCardIds)||{},[g]:{cardId:C,hookRef:null}};c({...t,dataInputCardIds:B})}function h(g){var E,B;const C=(E=l==null?void 0:l.cards)==null?void 0:E.filter(S=>{var N;return((N=S==null?void 0:S.customCardPreferences)==null?void 0:N.visualType)!=="multiple"}).map(S=>({value:S.id,label:S.tabTitle||S.title}));return e.jsx("div",{className:"space-y-2",children:(B=g==null?void 0:g.dataInputs)==null?void 0:B.map((S,N)=>{var v,I;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:S}),e.jsx(xe,{className:"col-span-6 h-8 w-full justify-between",label:"",options:C||[],value:((I=(v=t==null?void 0:t.dataInputCardIds)==null?void 0:v[N])==null?void 0:I.cardId)||"",onValueChange:D=>u(N,D)})]},N+Math.random())})})}function x(g,C,E=[],B=""){var S,N;return t?g==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((S=t==null?void 0:t.settings)==null?void 0:S[C])||B,onChange:v=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:v.target.value}})}},C):g==="select"?e.jsx(xe,{className:"h-8 w-full",label:"",options:E,value:((N=t==null?void 0:t.settings)==null?void 0:N[C])||B,onValueChange:v=>{c({...t,settings:{...t==null?void 0:t.settings,[C]:v}})}}):null:null}function f(g){const C=Object.entries((g==null?void 0:g.settings)||{});return e.jsx("div",{className:"space-y-3",children:C.map(([E,B])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:B.title}),x(B.ui,E,B.options,B.defaultValue)]},E))})}function j(g){t&&c({...t,visualType:g,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(xe,{icon:e.jsx(sa,{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:g=>c({...t||{url:"",componentName:""},url:g})}),((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(xe,{icon:e.jsx(ia,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(g=>g.type===o).map(g=>({value:g.name,label:g.name})))||[],value:t.componentName,onValueChange:g=>{console.log("changing value",g),c({...t,componentName:g})}})})]})})]}),((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:[m&&m.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:h(m)})]}),m&&m.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:f(m)})})]})]})]})}function Be(){const[t,a]=M.useState([]),n=s.useEditorStore(m=>m.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:l}=s.useEditorStore(m=>m.actions),o=s.useEditorStore(m=>m.queryResultColumns);s.useEditorStore(m=>{var u;return(u=m.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),M.useEffect(()=>{o&&a(new Array(o.length).fill(!1))},[o]);function c(m,u){var h,x;u?n!=null&&n.onClickFilter&&((h=n==null?void 0:n.onClickFilter)==null?void 0:h.length)>0?l({...n,onClickFilter:[...n.onClickFilter,{columnIndex:m,expression:""}]}):l({...n,onClickFilter:[{columnIndex:m,expression:""}]}):(l({...n,onClickFilter:(x=n==null?void 0:n.onClickFilter)==null?void 0:x.filter(f=>f.columnIndex!==m)}),a(f=>{const j=[...f];return j[m]=!1,j}))}function i(m,u){var x;const h=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.map(f=>f.columnIndex===m?{...f,expression:u.target.value}:f);l({...n,onClickFilter:h})}function d(m){var u,h,x,f;if(t!=null&&t[m]||(h=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(j=>j.columnIndex===m))!=null&&h.expression)return e.jsx(s.Input,{value:(f=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(j=>j.columnIndex===m))==null?void 0:f.expression,onChange:j=>i(m,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((m,u)=>{var h,x;return e.jsx("div",{className:"group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((h=n==null?void 0:n.onClickFilter)!=null&&h.find(f=>f.columnIndex===u)),onCheckedChange:f=>c(u,f)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:m}),e.jsx("div",{className:"flex items-center gap-2",children:((x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(f=>f.columnIndex===u))&&e.jsx(s.Pencil,{onClick:()=>{a(f=>{const j=[...f];return j[u]=!f[u],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),d(u)]})},m)})]})}function Dl({idx:t}){var i;const a=s.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),n=s.useEditorStore(d=>{var m;return(m=d.card.preferences)==null?void 0:m.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,m){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:d!=="none",align:d,anchor:d,clamp:!0};if(!o)r({...a,datasetOptions:[...n||[],{idx:m,datalabels:u}]});else{const h={...o};h.datalabels=u;const x=n==null?void 0:n.map(f=>f.idx===m?h:f);r({...a,datasetOptions:x})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Bt,{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(Na,{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(Sa,{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(Ca,{className:s.cn("h-4 w-4",{"rotate-90":l==="y"})})})]})})]})}function El(){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 Js({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function vn(){const t=s.useEditorStore(d=>d.card),a=s.useEditorStore(d=>{var m,u,h;return(h=(u=(m=d==null?void 0:d.card)==null?void 0:m.preferences)==null?void 0:u.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}=El();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:bn(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,m)=>e.jsx(Nn,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:d,idx:m},d))})]})]})}function bn(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function Nn({col:t,idx:a,className:n,iconClassName:r,children:l}){const o=s.useEditorStore(u=>{var h;return(h=u.card)==null?void 0:h.preferences}),c=s.useEditorStore(u=>{var h,x;return(x=(h=u.card)==null?void 0:h.preferences)==null?void 0:x.datasetOptions}),i=c==null?void 0:c.find(u=>u.idx===a),{setCardPreferences:d}=s.useEditorStore(u=>u.actions);function m(u){if(!i)d({...o,datasetOptions:[...c||[],{idx:a,type:u==="area"?"line":u,fill:u==="area"?"origin":""}]});else{const h={...i};h.type=u==="area"?"line":u,h.fill=u==="area"?"origin":"";const x=c==null?void 0:c.map(f=>f.idx===a?h:f);d({...o,datasetOptions:x})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[l||e.jsx(Js,{className:"max-w-[100px]",title:t,children:bn(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ds,{onClick:()=>m("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(us,{onClick:()=>m("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Tt,{onClick:()=>m("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Dl,{idx:a})]})]})}function Cn(){const t=s.useEditorStore(f=>f.selectedConnectionId),a=s.useEditorStore(f=>f.selectedDatamodelId),n=s.useEditorStore(f=>f.selectedDatabaseName),r=s.useEditorStore(f=>f.selectedSchemaName),l=s.useEditorStore(f=>f.selectedTableName),o=s.useDashboardStore(f=>f.dashboard.filters)||[],c=s.useDashboardStore(f=>f.actions.addFilter),i=s.useDashboardStore(f=>f.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:m,tableName:u,connectionType:h}=s.useEditorAside();function x(f,j="dashboard"){var v;const p=s.fmt(f.column_name),y=s.fmt(n||""),g=s.fmt(r||""),C=s.fmt(u);let E=s.getQualifiedTableName({schemaName:g,tableName:C,connectionType:h,databaseName:y}),B=`${E}.${p}`;const S=(v=m==null?void 0:m.find(I=>I.id===a))==null?void 0:v.name;a&&a!=="none"&&(B=`${s.DATAMODEL_NAMESPCACE}.${S}.${p}`,E=`${s.DATAMODEL_NAMESPCACE}.${S}`);const N=o==null?void 0:o.find(I=>I.column===B&&I.table===C&&(I.database===y||I.database===n));if(N)d(N.id),i(N.id);else{const I=s.v4();return u==="api"&&t?(c({location:j,id:I,column:B,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(f.data_type,E,p)}),I):(c({id:I,location:j,column:B,title:f.column_name,dataType:f.data_type,table:l||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(f.data_type,E,p)}),I)}}return{assignFilter:x}}function $e(){const t=s.useDashboardStore(i=>i.dashboard.filters),a=s.useEditorStore(i=>i.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:l}=Cn();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(Tl,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function Tl({columns:t,onSelect:a}){var c;const[n,r]=me.useState(!1),[l,o]=me.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 m=d===l?"":d;o(m),r(!1),m&&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 Il({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(vn,{})})]}),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(Be,{}),e.jsx($e,{})]})]})]})})}function Al({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(Be,{}),e.jsx($e,{})]})]})]})})}function Sn(){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 u;const d={datalabels:{display:i!=="none",align:i,anchor:i,clamp:!0}},m={...n,chartOptions:{...n==null?void 0:n.chartOptions,plugins:{...(u=n==null?void 0:n.chartOptions)==null?void 0:u.plugins,...d}}};r(m)}function o(){var i,d,m;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((m=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:m.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,m;return e.jsx("div",{children:e.jsxs(s.Select,{value:((m=(d=(i=n==null?void 0:n.chartOptions)==null?void 0:i.plugins)==null?void 0:d.datalabels)==null?void 0:m.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 Ml={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Ll={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ol(){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:Rl(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Sn,{}),e.jsx(Be,{}),e.jsx($e,{})]})]})}function Rl(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(Ml,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(Ll,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 Bl(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(s.FormatNumberSetting,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ns({children:t,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:a}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const Fl=[{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"}],Pl=["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"],zl=Pl.map(t=>({label:t,value:t}));function Vl(){var d,m,u,h,x,f,j,p,y,g,C,E,B,S,N,v,I,D;const t=s.useEditorStore(R=>R.card),a=(m=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:m.topoJsonUrl,[n,r]=M.useState(((h=(u=t==null?void 0:t.preferences)==null?void 0:u.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(R=>({label:R,value:R}))||[],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(Ns,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ns,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(xe,{className:"h-9",options:i,onValueChange:R=>{console.log("value",R),l({...t.preferences,mapVisualOptions:{topoJsonUrl:R}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:R=>{r(R.target.value)},onBlur:()=>{var R;console.log("onBlur",n),l({...t.preferences,mapVisualOptions:{...(R=t.preferences)==null?void 0:R.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(xe,{className:"h-9",options:c,value:((f=(x=t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:f.objectKey)||"",label:"Map Object",onValueChange:R=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,objectKey:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(xe,{className:"h-9",options:Fl,value:((p=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:R=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projection:R}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(xe,{className:"h-9",options:zl,value:((g=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:R=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,colorScale:R}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ns,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((E=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:E.projectionScale)||1,onChange:R=>{var w;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(R.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((N=(S=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:N[0])||0,onChange:R=>{var w,F,k,T;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(R.target.value),((T=(k=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:k.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:((D=(I=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:D[1])||0,onChange:R=>{var w,F,k,T;l({...t.preferences,mapVisualOptions:{...(w=t.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((T=(k=(F=t.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:k.projectionOffset)==null?void 0:T[0])||0,Number(R.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Be,{})]})}function _l(){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 Ze({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(_l,{})})]}),!["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(Be,{}),e.jsx($e,{})]})]})]})})}function Ul(){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(xe,{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(vn,{})]})]}),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(Be,{}),e.jsx($e,{})]})]})]})})}function $l({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(Be,{}),e.jsx($e,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}function ql({color:t,onColorChange:a,onClose:n}){const[r,l]=M.useState(0),[o,c]=M.useState(100),[i,d]=M.useState(50),[m,u]=M.useState(t);M.useEffect(()=>{const y=yt(t);if(y){const g=vt(y.r,y.g,y.b);l(g.h),c(g.s),d(g.l),u(t)}},[t]);const h=y=>{l(y),f(y,o,i)},x=y=>{const g=y.currentTarget.getBoundingClientRect(),C=Math.max(0,Math.min(1,(y.clientX-g.left)/g.width)),E=Math.max(0,Math.min(1,(y.clientY-g.top)/g.height)),B=C*100,S=(1-E)*100;c(B),d(S),f(r,B,S)},f=(y,g,C)=>{const E=Gl(y,g,C),B=Yl(E.r,E.g,E.b);u(B)},j=y=>{if(u(y),/^#[0-9A-Fa-f]{6}$/.test(y)){const g=yt(y);if(g){const C=vt(g.r,g.g,g.b);l(C.h),c(C.s),d(C.l)}}},p=()=>{/^#[0-9A-Fa-f]{6}$/.test(m)&&(a(m),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:x,onMouseMove:y=>{y.buttons===1&&x(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:m}})]}),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:m,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:m}}),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 yt(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 Yl(t,a,n){return"#"+((1<<24)+(t<<16)+(a<<8)+n).toString(16).slice(1)}function vt(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 Gl(t,a,n){t/=360,a/=100,n/=100;let r,l,o;if(a===0)r=l=o=n;else{const c=(m,u,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?m+(u-m)*6*h:h<.5?u:h<.6666666666666666?m+(u-m)*(.6666666666666666-h)*6:m),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 Hl=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function wn(){var E,B,S,N,v,I,D,R,w,F;const t=s.useEditorStore(k=>k.card),a=s.useEditorStore(k=>{var T;return(T=k.card)==null?void 0:T.preferences}),{setCardPreferences:n,updateCardInFrame:r}=s.useEditorActions(),{data:l}=s.useDashboardCardQuery(t),[o,c]=M.useState({}),[i,d]=M.useState(null),[m,u]=M.useState(null),h=M.useMemo(()=>{var L,A,O,z,_,Q,W;if(!(l!=null&&l.records)||l.records.length===0)return[];const k=(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",b=((L=t==null?void 0:t.config)==null?void 0:L.pivotByColumns)&&t.config.pivotByColumns.length>0;if((k||T)&&b){if(l.pivotSchema&&Array.isArray(l.pivotSchema)){const $=new Set;return l.pivotSchema.forEach(q=>{q.alias&&$.add(q.alias)}),Array.from($)}if(l.records.length>0){const $=l.records[0],q=Object.keys($),H=new Set;(A=t==null?void 0:t.config)!=null&&A.groupByColumns&&t.config.groupByColumns.forEach(Y=>{H.add(Y.label||Y.name),H.add(Y.alias||Y.name)});const U=new Set;return(O=t==null?void 0:t.config)!=null&&O.metricColumns&&t.config.metricColumns.forEach(Y=>{const G=Y.alias||Y.name;U.add(G),U.add(`${G}_count`),U.add(`${G}_sum`),U.add(`${G}_avg`),U.add(`${G}_min`),U.add(`${G}_max`);const X=Y.entityName||Y.qualifiedEntityName;X&&(U.add(`${X}_${G}`),U.add(`${X}_${G}_count`))}),q.filter(Y=>!H.has(Y)&&!U.has(Y))}}if((T||k)&&!b&&((_=(z=t==null?void 0:t.config)==null?void 0:z.metricColumns)!=null&&_.length))return t.config.metricColumns.map($=>$.alias||$.label||$.name);if((W=(Q=t==null?void 0:t.config)==null?void 0:Q.groupByColumns)!=null&&W.length){const $=t.config.groupByColumns[0],q=$.label||$.name,H=new Set;return l.records.forEach(U=>{const P=U[q];P!=null&&H.add(String(P))}),Array.from(H)}return[]},[l,(E=t==null?void 0:t.config)==null?void 0:E.groupByColumns,(B=t==null?void 0:t.config)==null?void 0:B.pivotByColumns,(S=t==null?void 0:t.config)==null?void 0:S.metricColumns,t==null?void 0:t.type]),x=M.useMemo(()=>s.getDefaultChartColors(),[]);M.useEffect(()=>{const k={};h.forEach((T,b)=>{k[T]=s.getColorForValue(T,b,a==null?void 0:a.colorConfig)}),c(k)},[h,a==null?void 0:a.colorConfig,x]);const f=(k,T)=>{const b={...o,[k]:T};c(b);const L={...a||{},colorConfig:{segments:b}};n(L);const A={...t,preferences:L};r(A)},j=(k,T)=>{var _;const b=x[T%x.length],{[k]:L,...A}=((_=a==null?void 0:a.colorConfig)==null?void 0:_.segments)||{},O={...a||{},colorConfig:{segments:A}};n(O);const z={...t,preferences:O};r(z),c(Q=>({...Q,[k]:b}))};if(!h.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((v=(N=t==null?void 0:t.config)==null?void 0:N.groupByColumns)==null?void 0:v.length)||((D=(I=t==null?void 0:t.config)==null?void 0:I.pivotByColumns)==null?void 0:D.length):(w=(R=t==null?void 0:t.config)==null?void 0:R.groupByColumns)==null?void 0:w.length)||["table","kpi","text","custom"].includes(t.type))return null;const g=()=>{const k={...a||{},colorConfig:{segments:{}}};n(k);const T={...t,preferences:k};r(T);const b={};h.forEach((L,A)=>{b[L]=s.getColorForValue(L,A,void 0)}),c(b)},C=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(Aa,{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:C&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:g,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((k,T)=>{const b=s.isDefaultColor(o[k],T),L=!b;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===k,onOpenChange:A=>d(A?k: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[k]}})}),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:x.slice(0,10).map((A,O)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",o[k]===A?"border-gray-900":"border-transparent"),style:{backgroundColor:A},onClick:()=>{f(k,A),d(null)},children:[O===T%x.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:A})]},`default-${O}`))})]}),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:Hl.map((A,O)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",o[k]===A?"border-2 border-gray-900":A==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:A},onClick:()=>{f(k,A),d(null)},children:e.jsx("span",{className:"sr-only",children:A})},`preset-${O}`))})]}),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:()=>{u({value:k,color:o[k]}),d(null)},children:"Custom color"}),!b&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{j(k,T),d(null)},children:[e.jsx(s.RotateCcw,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:k}),L&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},k)})}),m&&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:()=>u(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(ql,{color:m.color,onColorChange:k=>{f(m.value,k),u(null)},onClose:()=>u(null)})})]})]})})]})}function ue({value:t,onSave:a,placeholder:n="",type:r="text",className:l=""}){const[o,c]=M.useState(t??""),[i,d]=M.useState(!1);M.useEffect(()=>{c(t??"")},[t]);const m=()=>{a(o),d(!1)},u=()=>{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?m():h.key==="Escape"&&u()},"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:m,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:u,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function bt({axis:t,label:a,type:n,config:r,onChange:l}){var y,g,C,E,B,S,N,v,I,D,R,w,F,k,T,b,L,A;const o=(O,z)=>{l({...r,[O]:z})},c=(O,z)=>{var _,Q;l({...r,name:{enabled:O==="enabled"?z:((_=r==null?void 0:r.name)==null?void 0:_.enabled)??!1,text:O==="text"?z:(Q=r==null?void 0:r.name)==null?void 0:Q.text}})},i=(O,z)=>{var _,Q;l({...r,labels:{enabled:O==="enabled"?z:((_=r==null?void 0:r.labels)==null?void 0:_.enabled)??!0,rotation:O==="rotation"?z:(Q=r==null?void 0:r.labels)==null?void 0:Q.rotation}})},d=(O,z)=>{l({...r,scale:{...r==null?void 0:r.scale,[O]:z===""?"auto":Number(z)}})},m=O=>{l({...r,format:O,formatOptions:void 0})},u=(O,z)=>{l({...r,formatOptions:{...r==null?void 0:r.formatOptions,[O]:z}})},h=t==="x"?["auto","top","bottom"]:["auto","left","right"],x=["auto","0","45","90","-45","-90"],f=["auto","number","currency","percent"],j=[{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"}],p=[{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"}];return e.jsxs(s.AccordionItem,{value:`${t}-axis`,className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full flex-row-reverse items-center justify-between gap-3 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("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:O=>o("enabled",O),onClick:O=>O.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:((y=r==null?void 0:r.name)==null?void 0:y.enabled)??!1,onCheckedChange:O=>c("enabled",O)})]}),((g=r==null?void 0:r.name)==null?void 0:g.enabled)&&e.jsx(ue,{placeholder:`${a} title`,value:((C=r==null?void 0:r.name)==null?void 0:C.text)||"",onSave:O=>c("text",O),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:O=>o("position",O),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:h.map(O=>e.jsx(s.SelectItem,{value:O,className:"text-xs",children:O==="auto"?"Auto (Default)":s.titleCase(O)},O))})]})]}),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:((E=r==null?void 0:r.labels)==null?void 0:E.enabled)!==!1,onCheckedChange:O=>i("enabled",O)})]}),((B=r==null?void 0:r.labels)==null?void 0:B.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(((S=r==null?void 0:r.labels)==null?void 0:S.rotation)||"auto"),onValueChange:O=>i("rotation",O==="auto"?"auto":Number(O)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:x.map(O=>e.jsx(s.SelectItem,{value:O,className:"text-xs",children:O==="auto"?"Auto (Default)":`${O}°`},O))})]})]})]}),n==="value"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"NUMBER FORMAT"}),e.jsxs(s.Select,{value:(r==null?void 0:r.format)||"auto",onValueChange:m,children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:f.map(O=>e.jsx(s.SelectItem,{value:O,className:"text-xs",children:O==="auto"?"Auto (Default)":s.titleCase(O)},O))})]})]}),(r==null?void 0:r.format)&&r.format!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent"].includes(r.format)&&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(ue,{type:"number",placeholder:"0",value:String(((N=r==null?void 0:r.formatOptions)==null?void 0:N.decimalPlaces)??(r.format==="currency"?2:r.format==="percent"?1:0)),onSave:O=>u("decimalPlaces",Number(O)),className:""})})]}),r.format==="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:((v=r==null?void 0:r.formatOptions)==null?void 0:v.currency)||"USD",onValueChange:O=>u("currency",O),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:j.map(O=>e.jsx(s.SelectItem,{value:O.value,className:"text-xs",children:O.label},O.value))})]})]}),["number","currency"].includes(r.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:((I=r==null?void 0:r.formatOptions)==null?void 0:I.useSuffix)??!1,onCheckedChange:O=>u("useSuffix",O)})]}),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:((D=r==null?void 0:r.formatOptions)==null?void 0:D.locale)||"en-US",onValueChange:O=>u("locale",O),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:p.map(O=>e.jsx(s.SelectItem,{value:O.value,className:"text-xs",children:O.label},O.value))})]})]}),r.format==="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(ue,{placeholder:"e.g., $",value:((R=r==null?void 0:r.formatOptions)==null?void 0:R.prefix)||"",onSave:O=>u("prefix",O),className:""})})]}),r.format==="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(ue,{placeholder:"e.g., units",value:((w=r==null?void 0:r.formatOptions)==null?void 0:w.suffix)||"",onSave:O=>u("suffix",O),className:""})})]})]})]}),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(ue,{type:"number",placeholder:"auto",value:((F=r==null?void 0:r.scale)==null?void 0:F.min)==="auto"||((k=r==null?void 0:r.scale)==null?void 0:k.min)===void 0?"":String(r.scale.min),onSave:O=>d("min",O),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(ue,{type:"number",placeholder:"auto",value:((T=r==null?void 0:r.scale)==null?void 0:T.max)==="auto"||((b=r==null?void 0:r.scale)==null?void 0:b.max)===void 0?"":String(r.scale.max),onSave:O=>d("max",O),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(ue,{type:"number",placeholder:"auto",value:((L=r==null?void 0:r.scale)==null?void 0:L.stepSize)==="auto"||((A=r==null?void 0:r.scale)==null?void 0:A.stepSize)===void 0?"":String(r.scale.stepSize),onSave:O=>d("stepSize",O),className:""})})]})]})]})]})]})}function kn(){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||t.type==="tornado"||t.type==="pyramid")return null;const l=s.AxisConfigurator.getAxisInfo(t.type,a);if(!l.hasXAxis&&!l.hasYAxis)return null;const o=(c,i)=>{const m={...a||{},[c==="x"?"xAxisConfig":"yAxisConfig"]:i};n(m);const u={...t,preferences:m};r(u)};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(Pa,{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(bt,{axis:"x",label:"X-Axis",type:l.xAxisType,config:a==null?void 0:a.xAxisConfig,onChange:c=>o("x",c)}),l.hasYAxis&&e.jsx(bt,{axis:"y",label:"Y-Axis",type:l.yAxisType,config:a==null?void 0:a.yAxisConfig,onChange:c=>o("y",c)})]})})]})}function Dn(){const t=s.useEditorStore(m=>m.card),a=s.useEditorStore(m=>{var u,h,x,f;return(f=(x=(h=(u=m.card)==null?void 0:u.preferences)==null?void 0:h.chartOptions)==null?void 0:x.plugins)==null?void 0:f.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=(m,u)=>{const h={...a,[m]:u};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(Mt,{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:m=>c("display",m)})]}),((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:m=>c("position",m),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:i.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:"Alignment"}),e.jsxs(s.Select,{value:(a==null?void 0:a.align)||l,onValueChange:m=>c("align",m),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:d.map(m=>e.jsx(s.SelectItem,{value:m,className:"text-xs",children:s.titleCase(m)},m))})]})]})]})]})})]})}function En(){var I,D,R,w,F,k,T,b,L;const t=s.useEditorStore(A=>A.card),a=s.useEditorStore(A=>{var O,z;return(z=(O=A.card)==null?void 0:O.preferences)==null?void 0:z.dataLabelsConfig}),n=s.useEditorStore(A=>{var O;return(O=A.card)==null?void 0:O.preferences}),{setCardPreferences:r,updateCardInFrame:l}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const o=((I=n==null?void 0:n.chartOptions)==null?void 0:I.indexAxis)==="y",c=t.type==="stackedBar"||t.type==="stackedLine",i=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",d=!i,m=(R=(D=n==null?void 0:n.chartOptions)==null?void 0:D.plugins)==null?void 0:R.datalabels,u=(m==null?void 0:m.display)!==!1&&((m==null?void 0:m.anchor)||(m==null?void 0:m.align)),h=(a==null?void 0:a.enabled)!==void 0?a.enabled:u,x=(A,O)=>{const z={...a,[A]:O},_={...t.preferences||{},dataLabelsConfig:z};r(_);const Q={...t,preferences:_};l(Q)},f=(A,O)=>{const z={...a,font:{...a==null?void 0:a.font,[A]:O}},_={...t.preferences||{},dataLabelsConfig:z};r(_);const Q={...t,preferences:_};l(Q)},j=(A,O)=>{const z={...a,formatOptions:{...a==null?void 0:a.formatOptions,[A]:O}},_={...t.preferences||{},dataLabelsConfig:z};r(_);const Q={...t,preferences:_};l(Q)},y=(()=>{const A=t.type;return A==="stackedBar"||A==="stackedLine"||A==="pie"||A==="doughnut"?"center":o?"right":"top"})();let g=[];c||i?g=["center"]:g=["auto",...(o?["center","left","right"]:["center","top","bottom"]).filter(O=>O!==y),"custom"];const C=()=>s.titleCase(y),E=["center","start","end"],B=["center","start","end","top","bottom"],S=d?["auto","number","currency","percent","none"]:["number","currency","percent","none"],N=[{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(_a,{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:A=>x("enabled",A)})]}),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:A=>x("position",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:g.map(A=>e.jsx(s.SelectItem,{value:A,className:"text-xs",children:A==="auto"?C():A==="custom"?"Custom (Advanced)":s.titleCase(A)},A))})]})]}),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:A=>x("showTotal",A)})]}),(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:A=>x("anchor",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:E.map(A=>e.jsx(s.SelectItem,{value:A,className:"text-xs",children:s.titleCase(A)},A))})]})]}),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:A=>x("align",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:B.map(A=>e.jsx(s.SelectItem,{value:A,className:"text-xs",children:s.titleCase(A)},A))})]})]})]}),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:A=>x("format",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:S.map(A=>e.jsx(s.SelectItem,{value:A,className:"text-xs",children:A==="auto"&&d?"Auto (Use Axis)":A==="none"?"None (Raw Value)":s.titleCase(A)},A))})]})]}),(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(ue,{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:A=>j("decimalPlaces",Number(A)),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:A=>j("currency",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:N.map(A=>e.jsx(s.SelectItem,{value:A.value,className:"text-xs",children:A.label},A.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:((k=a==null?void 0:a.formatOptions)==null?void 0:k.useSuffix)??!1,onCheckedChange:A=>j("useSuffix",A)})]}),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:A=>j("locale",A),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:v.map(A=>e.jsx(s.SelectItem,{value:A.value,className:"text-xs",children:A.label},A.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(ue,{type:"number",placeholder:"12",value:String(((b=a==null?void 0:a.font)==null?void 0:b.size)||12),onSave:A=>f("size",Number(A)),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:((L=a==null?void 0:a.font)==null?void 0:L.weight)||"normal",onValueChange:A=>f("weight",A),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:A=>{A==="auto"&&x("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(ue,{type:"number",placeholder:"0",value:String((a==null?void 0:a.rotation)||0),onSave:A=>x("rotation",Number(A)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}function Kl(){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(wn,{}),e.jsx(kn,{}),e.jsx(Dn,{}),e.jsx(En,{})]})]})}const Ql=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."]})]}),Wl=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."]})]}),Jl=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 Xl(){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(Kl,{})]});switch(n){case"stackedBar":case"stackedLine":return l(e.jsx(Ul,{}));case"tornado":case"pyramid":return l(e.jsx(Ze,{docContent:Ql,cardType:n}));case"kpi":return e.jsx(Bl,{});case"line":case"bar":return l(e.jsx(Il,{cardType:n}));case"range":return l(e.jsx(Ze,{docContent:Wl,cardType:n}));case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return l(e.jsx(Ze,{cardType:n}));case"bubble":case"scatter":return l(e.jsx(Al,{cardType:n}));case"table":return e.jsx($l,{cardType:n});case"text":return e.jsx(Ze,{docContent:Jl,cardType:n,suffix:"Visual"});case"map":return e.jsx(Vl,{});case"custom":return e.jsx(kl,{});default:return l(e.jsx(Ol,{}))}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Tn({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(xe,{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 Zl=[{label:"Sum",value:"SUM",logo:e.jsx(Rt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(Ge,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(fa,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Wn,{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 eo({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions();let n=Zl;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:We(t.name,l)};a(t.id,o)}return e.jsx(Tn,{column:t,functions:n,onFunctionChange:l=>r(l),label:"Aggregation"})}const so=[{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 to({column:t}){const{updateGroupByColumnOld:a}=s.useEditorActions();function n(r){const l={...t,granularity:r,label:Ue(t.name,r)};a(t.id,l)}return e.jsx(Tn,{column:t,functions:so,onFunctionChange:r=>n(r),label:"Granularity"})}function no({col:t,onChange:a,droppableId:n}){const{columns:r}=s.useDataColumns(),l=M.useMemo(()=>{let i=[];(n===Ae||n===Me||n===Le)&&(i=r);const d=i==null?void 0:i.filter(m=>m.column_name!==t.name);return d==null?void 0:d.map(m=>({id:m.column_name,value:m.column_name}))},[r,n,t.name]),o=[{id:t.name,value:t.name}];function c(i){const d=r==null?void 0:r.find(m=>{var u;return m.column_name===((u=i[0])==null?void 0:u.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 In({column:t}){const a=s.useEditorStore(d=>d.card.type),n=s.useEditorStore(d=>{var m,u;return(u=(m=d.card)==null?void 0:m.config)==null?void 0:u.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(Nn,{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(Sn,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(a)&&c(),["pie","doughnut"].includes(a)&&i()]})}function ao({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[l,o]=M.useState(!1),{updateGroupByColumnOld:c,updateMetricColumnOld:i,updatePivotByColumnOld:d}=s.useEditorActions(),{attributes:m,listeners:u,setNodeRef:h,transform:x,transition:f,isDragging:j}=s.useSortable({id:t.id,data:{type:a}}),p=x?{opacity:j?.5:void 0,transform:s.CSS.Translate.toString(x),transition:f}:void 0,y=s.isTextDataType(t.type);function g(N){const v=s.isNumberDataType(N.data_type),I=s.isTextDataType(N.data_type),D=s.isDateDataType(N.data_type),R=v?"number":I?"string":D?"date":"string";if(r===Ae){if(I){const w={id:t.id,name:N.column_name,type:R,role:"groupby"};c(t.id,w)}if(D){const w={id:t.id,name:N.column_name,type:R,role:"groupby",label:Ue(N.column_name,"month"),granularity:"month"};c(t.id,w)}}if(r===Le){if(I){const w={id:t.id,name:N.column_name,type:R,role:"groupby"};d(t.id,w)}if(D){const w={id:t.id,name:N.column_name,type:R,label:Ue(N.column_name,"month"),granularity:"month",role:"groupby"};d(t.id,w)}}if(r===Me){const w={id:t.id,name:N.column_name,type:R,role:"metric",label:We(N.column_name,"SUM"),aggregate:v?"SUM":"COUNT"};i(t.id,w)}}function C(){if(r===Me)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(In,{column:t})})}function E(){const N=s.isDateDataType(t.type);if(r===Me)return e.jsx(eo,{column:t});if((r===Ae||r===Le)&&N)return e.jsx(to,{column:t})}function B(){return e.jsx("div",{className:s.cn("grow",{"pl-3":(r===Ae||r===Le)&&y}),children:e.jsx(no,{col:t,onChange:g,droppableId:r})})}function S(){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(Fa,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(At,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...u,...m,ref:h,style:p,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted",children:[S(),E(),B()]}),l&&C()]}),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 Cs({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}),m=s.useDndStore(g=>g.activeId),u=s.useEditorStore(g=>{var C;return(C=g.card)==null?void 0:C.type}),h=i||((y=(p=d==null?void 0:d.data)==null?void 0:p.current)==null?void 0:y.type)===l,x=m?r:n,f=l===ls?"Rows":l===os?"Pivot Columns":"Columns";function j(){if(!x||x.length===0)return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(g=>g.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}),u!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:f})]}),j(),e.jsx("div",{className:"space-y-2",children:x==null?void 0:x.map(g=>g.id===an.id?e.jsx(ro,{},g.id):e.jsx(ao,{droppableId:t,type:l,column:g,onRemoveColumn:o},g.id))})]})})}function ro(){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 An({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}}),m=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:m,children:t})}function lo(){const t=s.useEditorStore(g=>{var C;return(C=g.card.queryConfig)==null?void 0:C.orderBy})||[],a=s.useEditorStore(g=>{var C;return(C=g.card.queryConfig)==null?void 0:C.groupByColumns})||[],n=s.useEditorStore(g=>{var C;return(C=g.card.queryConfig)==null?void 0:C.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(ea,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(Qn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=e.jsx(Zn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(Kn,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=c==null?void 0:c.filter(g=>!t.some(C=>C.columnId===g.id)).map(g=>({id:g.id,value:g.label||g.name}));function x(g,C){const E=f(g);return E?E.role==="metric"?C==="asc"?m:u:C==="asc"?i:d:null}function f(g){return c.find(C=>C.id===g)}function j(g){const C=t.find(E=>E.columnId===g);if(C){const E={...C,direction:C.direction==="asc"?"desc":"asc"};o(E)}}const p=g=>{r({columnId:g.id,direction:"asc"})};function y(g){const C=t.find(E=>E.columnId===g);C&&l(C)}return e.jsx(s.SortableContext,{items:t.map(g=>Ye(g.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:g=>p(g[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),t.map(g=>{var C,E;return e.jsx(An,{id:Ye(g.columnId),type:$s,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(At,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Js,{className:"w-[175px] text-sm",children:((C=f(g.columnId))==null?void 0:C.label)||((E=f(g.columnId))==null?void 0:E.name)})]}),e.jsx("button",{title:g.direction==="asc"?"Ascending":"Descending",onClick:()=>j(g.columnId),className:"rounded-sm p-0",children:x(g.columnId,g.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>y(g.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"})})})]})},g.columnId)},Ye(g.columnId))})]})})}function oo(){const t=s.useEditorStore(y=>{var g;return((g=y.card.queryConfig)==null?void 0:g.groupByColumns)||[]}),a=s.useEditorStore(y=>y.card.type),n=s.useDndStore(y=>y.previewGroupByColumns),r=s.useEditorStore(y=>{var g;return((g=y.card.queryConfig)==null?void 0:g.metricColumns)||[]}),l=s.useDndStore(y=>y.previewMetricColumns),o=s.useEditorStore(y=>{var g;return((g=y.card.queryConfig)==null?void 0:g.pivotColumns)||[]}),c=s.useDndStore(y=>y.previewPivotColumns),{removeColumnFromGroupBy:i,removeColumnFromMetricColumns:d,removeColumnFromPivotBy:m}=s.useEditorActions();function u(y){i(y)}function h(y){d(y)}function x(y){m(y)}let f="Group By",j="Metrics",p="Stack By";return a==="table"&&(f="Rows",j="Metrics",p="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(fn,{iconClassName:"size-[19px]"}),e.jsxs(s.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(Cs,{onRemoveColumn:u,sortableType:ls,id:Ae,label:f,columns:t,previewColumns:n}),e.jsx(Cs,{onRemoveColumn:x,sortableType:os,id:Le,label:p,columns:o,previewColumns:c}),e.jsx(Cs,{onRemoveColumn:h,sortableType:Ds,id:Me,label:j,columns:r,previewColumns:l}),e.jsx(lo,{})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Xs({children:t,column:a,id:n,sortableType:r,className:l}){const[o,c]=M.useState(!1),{removeEditorFilter:i,clearEditorFilter:d}=s.useEditorActions(),m=s.useEditorStore(h=>{var x,f;return(f=(x=h.card.queryConfig)==null?void 0:x.filters)==null?void 0:f.some(j=>j.filterColumnName===a.name)});function u(h){i(h)}return e.jsx(An,{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}),m&&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:()=>u(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 io({column:t,sortableType:a}){const n=s.useDashboardStore(E=>E.themeStyle),r=s.useEditorStore(E=>{var B,S;return(S=(B=E.card)==null?void 0:B.queryConfig)==null?void 0:S.filters}),l=s.useEditorStore(E=>{var B,S;return(S=(B=E.card.queryConfig)==null?void 0:B.filterColumns)==null?void 0:S.find(N=>N.name===t.name)}),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:i}=s.useEditorAside(),d=M.useMemo(()=>{var E;return(E=r==null?void 0:r.find(B=>B.filterColumnName===t.name))==null?void 0:E.filterValue},[r,t.name]),m=M.useMemo(()=>Array.isArray(d)?d.map(E=>({id:E,value:E})):[],[d]),{updateEditorFilterValue:u}=s.useEditorActions(),h={column:t.name,sql:t.sql,id:t.name,connectionId:o,dataType:t.type},{data:x,isLoading:f,isFetching:j,isError:p}=s.useFilterQuery(h),y=M.useMemo(()=>{var B;return h.column?(B=x==null?void 0:x.records)==null?void 0:B.map(S=>{let N=h.column.split(".").slice(-1)[0].replace(/"/g,"");return S[N]===void 0&&(N=N.toLowerCase()),{id:S[N],value:S[N]}}):[]},[x,h.column]);function g(E){const B=E.map(S=>S.id);u(t.name,B)}function C(){return f||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(co,{columnName:t.name}),showNegativeIndicator:(l==null?void 0:l.mode)==="exclude",options:y,onChange:g,selectedOptions:m,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Xs,{className:"w-60",id:t.id,sortableType:a,column:t,children:C()})}function co({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 uo({column:t,sortableType:a}){const[n,r]=M.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:m,isError:u,data:h}=s.useFilterQuery(i),x=h==null?void 0:h.records,{dateRange:f,setDateRange:j,initialDateRange:p}=s.useDateRangeFromRecords(x),{updateEditorFilterValue:y}=s.useEditorActions();function g(B){var N,v;const S={gte:(N=B==null?void 0:B.from)==null?void 0:N.toISOString(),lte:(v=B==null?void 0:B.to)==null?void 0:v.toISOString()};y(t.name,S)}function C(){y(t.name,null,!0),j(p)}function E(){return d||m?e.jsx("div",{children:e.jsx(s.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):u?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):x?e.jsx(s.DateRangePopover,{title:i.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:f,setDateRange:j,onApply:g,onClear:C}):e.jsx(s.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Xs,{className:"w-72",id:t.id,sortableType:a,column:t,children:E()})}function mo({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),m={},u=c||((p=(j=i==null?void 0:i.data)==null?void 0:j.current)==null?void 0:p.type)===l;function h(){if(!f||f.length===0)return e.jsx("div",{className:"flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}function x(y){const g=s.isDateDataType(y.type);return y.id===an.id?e.jsx(Xs,{id:y.id,sortableType:l,column:y,children:e.jsx(ho,{})},y.id):g?e.jsx(uo,{droppableId:t,sortableType:l,column:y},y.id):e.jsx(io,{droppableId:t,sortableType:l,column:y},y.id)}const f=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",u&&"border border-muted-foreground/20"),ref:o,style:m,children:[e.jsx(s.Label,{className:"text-sm",children:a}),h(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:f==null?void 0:f.map(y=>x(y))})]})})}function ho(){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 xo(){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(mo,{onRemoveColumn:r,sortableType:Ts,id:Es,label:"Filters",columns:t,previewColumns:a})})}function po(){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(hs,{}),!a&&e.jsxs(s.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(Ta,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(cn,{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(Ys,{}),e.jsx(qs,{variant:"default"})]})]})}function fo(){const t=M.useRef(null),a=M.useRef(null),n=s.useEditorStore(i=>i.isShowingVisual),r=s.useEditorStore(i=>i.showAIDialog),l=s.useEditorStore(i=>i.isDevMode);M.useEffect(()=>{var i,d,m,u;r?((i=t.current)==null||i.resize(0),(d=a.current)==null||d.resize(0)):((m=t.current)==null||m.resize(25),(u=a.current)==null||u.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(cl,{})}),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(Xl,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Xe,{})})]}):e.jsx(Xe,{})})]})}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(oo,{})})}),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(po,{}),e.jsx(xo,{})]}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(Xe,{})})]})})]}):e.jsx(Xe,{})})})}return e.jsx(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:l?o():c()})}function go(t){const a=s.useAIInteractionStore(V=>V.currentAIContext),[n,r]=M.useState(""),[l,o]=M.useState(null),{authToken:c}=s.useSemaphorContext(),i=s.useEditorStore(V=>{var Z;return(Z=V==null?void 0:V.card)==null?void 0:Z.sql}),d=s.useEditorStore(V=>V.isDevMode),m=s.useEditorStore(V=>{var Z;return(Z=V==null?void 0:V.card)==null?void 0:Z.python}),{setCardPython:u,setCardSql:h,setRunSql:x,switchCardType:f,setQueryConfig:j}=s.useEditorActions(),p=s.useEditorStore(V=>V.currentAssitantScope)||[],y=s.useEditorStore(V=>V.userInputForAI),g=s.useEditorStore(V=>V.triggerAIRun),C=s.useEditorStore(V=>V.card),E=s.useEditorStore(V=>V.selectedDatabaseName),B=s.useEditorStore(V=>V.selectedTableName),S=s.useEditorStore(V=>V.selectedConnectionId),N=s.useEditorStore(V=>V.selectedSchemaName),v=s.useDashboardStore(V=>V.dashboard.aiScopeTables),{errorMessage:I,refetch:D,data:R}=s.useDashboardCardQuery(C),{setTriggerAIRun:w,setCurrentAssitantScope:F,setCardConfig:k}=s.useEditorActions(),{selectedDatamodelName:T,connectionType:b,selectedDatamodelId:L}=s.useEditorAside(),{messages:A,setMessages:O,reload:z,error:_,append:Q,input:W,setInput:$,status:q,handleInputChange:H,handleSubmit:U,stop:P}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant",isDevMode:d,aiContext:a},maxSteps:10,onError:V=>{console.log("on error",V)},onToolCall:Y,onFinish(V,Z){G(Z.usage),r(""),Z.finishReason==="stop"&&r("")}});M.useEffect(()=>{g&&y&&(Q({role:"user",content:y}),w(!1))},[g,y,Q,w]);async function Y({toolCall:V}){var Z,oe,Ce,Te;if(["createChartFromSql","createForecast"].includes(V.toolName)){const ne=V.args.sql,ie=V.args.python,ce=V.args.chartType;return f(ce),h(ne),u(ie),x(!0),{status:"success",message:"Let the user know that chart is created"}}else if(V.toolName==="getTableColumns")r("Getting table columns...");else{if(V.toolName==="getUserSql")return i?{status:"success",sql:i,python:m||""}:{status:"error",message:"No SQL found"};if(V.toolName==="getCurrentTableScope")return r("Getting table scope..."),te(),{status:"success",tables:p};if(V.toolName==="generateQueryConfig"){r("Generating query config...");const ne=V.args.chartType,ie=V.args.queryConfig;V.args.cardConfig,f(ne),k(ie),h(void 0),u(void 0);const ce=await D();return(Z=ce==null?void 0:ce.data)!=null&&Z.error?{status:"error",queryConfig:ie,message:(oe=ce==null?void 0:ce.data)==null?void 0:oe.error.message}:(Ce=ce==null?void 0:ce.data)!=null&&Ce.records?{status:"success",queryConfig:ie,message:"The data has been visualized"}:{status:"success",queryConfig:ie,message:"The data has been visualized",records:(Te=ce==null?void 0:ce.data)==null?void 0:Te.records}}else r("Analyzing...")}}function G(V){o(Z=>Z?{promptTokens:Z.promptTokens+V.promptTokens,completionTokens:Z.completionTokens+V.completionTokens,totalTokens:Z.totalTokens+V.totalTokens}:V)}function X(V){const Z=s.removeFromScopeArray(p,V);se(Z)}function se(V){const Z=s.sanitizeAIScope(V);F(Z),O(oe=>[...oe,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(Z)}`}])}function ae(){const V={databaseName:E||"",schemaName:N||"",tableName:B||"",datamodelId:L||"",datamodelName:s.resolveDatamodelName(T),connectionId:S||"",connectionType:b||""},Z=s.dedup([...p,V]);se(Z)}function te(){const V={databaseName:E||"",schemaName:N||"",tableName:B||"",datamodelName:s.resolveDatamodelName(T),connectionId:S||"",connectionType:b||"",datamodelId:L||""};if(!s.isInAiScopeArray([...v||[],...p],V)||p.length===0){const oe=s.dedup([...v||[],...p,V]).filter(Ce=>Ce.connectionId===V.connectionId);se(oe)}}const le=!["ready","error"].includes(q),K=s.getErrorMessage(_);return{messages:A,setMessages:O,reload:z,append:Q,input:W,setInput:$,isLoading:le,handleSetAIScope:te,handleAddCurrentTableToScope:ae,removeFromCurrentSelections:X,currentAssitantScope:p,setCurrentAssitantScope:F,handleInputChange:H,handleSubmit:U,stop:P,chatStatus:q,toolStatus:n,llmUsage:l,onFinish:t,errorMessage:K}}const jo=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Nt(){const t=M.useRef(null),a=M.useRef(null),[n,r]=M.useState(!1),[l,o]=M.useState(s.isDevEnv),[c,i]=M.useState(!1),[d,m]=M.useState(!1),u=s.useCurrentAIContext(),{setCurrentAIContext:h}=s.useAIActions(),x=s.useDashboardStore(P=>P.dashboard.aiContext),f=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),g=s.useDashboardStore(P=>P.handleOpenAssistantProfile),{setShowAIDialog:C,setCardPython:E}=s.useEditorActions(),{setDataSource:B}=s.useEditorActions(),{assistantProfile:S}=s.useAssistantProfile(),{messages:N,setMessages:v,reload:I,append:D,input:R,setInput:w,isLoading:F,handleInputChange:k,handleSubmit:T,stop:b,chatStatus:L,llmUsage:A,errorMessage:O}=go();s.useAssistantScroll({scrollContainerRef:t,inputRef:a,messages:N}),M.useEffect(()=>{var P;y&&((P=a.current)==null||P.focus(),h({selectedEntities:(f==null?void 0:f.selectedEntities)||[]}))},[y,f,h]);function z(P,Y){Y==="sql"?(j(P),p(!0)):Y==="python"&&(E(P),p(!0))}function _(){var P;(P=x==null?void 0:x.selectedEntities)==null||P[0],m(!0)}function Q(){u.selectedEntities.length===0&&h({selectedEntities:(x==null?void 0:x.selectedEntities)||[]})}function W(P){Q();const Y={role:"user",content:P.title+" "+P.subtitle};D(Y)}function $(P){Q(),D({role:"user",content:P})}function q(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",variant:"ghost",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:i,children:"System Message"})]})]})}function H(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const U=(R==null?void 0:R.length)===0&&(N==null?void 0:N.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:[H(),g&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:g,children:(S==null?void 0:S.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center gap-2",children:[q(),e.jsx(s.IconButton,{tooltip:"Add Context",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:_,children:e.jsx(s.Settings,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{v([]),I()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-8 text-muted-foreground hover:text-foreground",size:"sm",onClick:()=>{C(!1)},children:e.jsx(s.EyeOff,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"mt-2 flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:N,showTools:l,handleRun:z,showSystemMessage:c}),e.jsx(s.ChatStatus,{messages:N,chatStatus:L,errorMessage:O})]})}),e.jsxs("div",{className:"mb-3",children:[U&&!S&&e.jsx(s.Placeholders,{onClick:W,placeholders:jo}),e.jsx("div",{children:U&&S&&e.jsx(s.SeedQuestions,{seedQuestions:S.seedQuestions||[],handleSeedQuestionClick:$})})]}),e.jsx(s.ChatInputWithContext,{ref:a,setInput:w,stop:b,input:R,handleInputChange:k,handleSubmit:P=>{Q(),T(P)},isLoading:F,onFocus:()=>{}}),A&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",A.promptTokens," prompt tokens,"," ",A.completionTokens," completion tokens,"," ",A.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(f==null?void 0:f.selectedEntities)||[],open:d,onOpenChange:m,dataSource:f||s.EMPTY_DATA_SOURCE,fallbackDataSource:s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function Mn(t,a,n){var r;return!n||!((r=n.baseEntity)!=null&&r.name)||!n.joins?!1:t===a||t===n.baseEntity.name||a===n.baseEntity.name?!0:n.joins.some(l=>{const o=s.getQualifiedEntityName(l.source),c=s.getQualifiedEntityName(l.target);return o===t&&c===a||o===a&&c===t})}function yo(t,a,n){if(a.length===0)return{isValid:!0};const r=a[0].qualifiedEntityName;if(!r)return{isValid:!0};if(r!==t.qualifiedEntityName&&t.qualifiedEntityName)if(n){if(!Mn(r,t.qualifiedEntityName,n))return{isValid:!1,showError:!0}}else return{isValid:!1,showError:!0};return{isValid:!0}}function Is(){s.ue.error("Join Configuration Required",{richColors:!0,description:"To combine fields from two different tables, you need to define a join between them first.",position:"top-center",duration:4e3})}function As(t,a){return a.some(n=>n.name===t.name&&n.qualifiedEntityName===t.qualifiedEntityName)}const Zs=t=>{var w;const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:l,updateSortByColumn:o,removeGroupByColumn:c,removeMetricColumn:i,removePivotByColumn:d,removeSortByColumn:m}=s.useEditorActions(),u=s.useEditorStore(F=>F.card.type),h=t==null?void 0:t.id,x=M.useCallback(F=>{if(!(t!=null&&t.config))return[];switch(F){case"groupBy":return(t.config.groupByColumns||[]).map(k=>({id:k.id,name:k.name,dataType:k.dataType,label:k.label!==void 0?k.label:k.name,qualifiedEntityName:k.qualifiedEntityName,entityId:k.entityId,entityName:k.entityName,entityType:k.entityType,dateFormat:k.dateFormat,customFormat:k.customFormat,granularity:k.granularity}));case"metrics":return t.config.metricColumns||[];case"pivotBy":return(t.config.pivotByColumns||[]).map(k=>({id:k.id,name:k.name,dataType:k.dataType,label:k.label!==void 0?k.label:k.name,qualifiedEntityName:k.qualifiedEntityName,entityId:k.entityId,entityName:k.entityName,entityType:k.entityType}));case"sortBy":return(t.config.sortByColumns||[]).map(k=>({id:k.id,name:k.name,dataType:k.dataType,label:k.label!==void 0?k.label:k.name,qualifiedEntityName:k.qualifiedEntityName,entityId:k.entityId,entityName:k.entityName,entityType:k.entityType,direction:k.direction}));case"source":return[];default:return[]}},[t]),f=M.useCallback((F,k)=>{if(h)switch(F){case"groupBy":{a(h,{groupByColumns:k});break}case"metrics":{a(h,{metricColumns:k});break}case"pivotBy":{a(h,{pivotByColumns:k});break}case"sortBy":{a(h,{sortByColumns:k});break}}},[h,a]),j=M.useCallback((F,k,T)=>{if(!h)return;const L=x(F)[k];if(L)switch(F){case"groupBy":n(h,L.id,{label:T});break;case"metrics":r(h,L.id,{label:T});break;case"pivotBy":l(h,L.id,{label:T});break;case"sortBy":o(h,L.id,{label:T});break}},[h,x,n,r,l,o]),p=M.useCallback((F,k)=>{if(!h)return;const b=x("metrics")[F];b&&r(h,b.id,{aggregate:k,label:s.getAggregationLabel(b.name,k)})},[h,x,r]),y=M.useCallback((F,k,T)=>{if(!h)return;const L=x("groupBy")[F];if(!L)return;const A={dateFormat:k};k==="custom"&&T?A.customFormat=T:A.customFormat=void 0,n(h,L.id,A)},[h,x,n]),g=M.useCallback((F,k)=>{if(!h)return;const b=x("groupBy")[F];b&&n(h,b.id,{granularity:k})},[h,x,n]),C=M.useCallback((F,k)=>{if(!h)return;const b=x("metrics")[F];b&&r(h,b.id,{aliasTemplate:k})},[h,x,r]),E=M.useCallback((F,k)=>{if(console.log("handleValueAliasesChange",F,k),!h)return;console.log("handleValueAliasesChange",F,k);const b=x("metrics")[F];b&&(console.log("handleValueAliasesChange",k),r(h,b.id,{valueAliases:k}))},[h,x,r]),B=M.useCallback(F=>{h&&a(h,{comparisonType:F})},[h,a]),S=M.useCallback(F=>{h&&a(h,{showTrendline:F})},[h,a]),N=M.useCallback(F=>{h&&a(h,{trendlineWindow:F})},[h,a]),v=M.useCallback(F=>{h&&a(h,{trendlineGranularity:F})},[h,a]),I=M.useCallback(F=>{h&&a(h,{targetValue:F})},[h,a]),D=M.useCallback(F=>{var z;if(!h)return;const k=[...x("groupBy"),...x("pivotBy"),...x("metrics"),...x("sortBy")],T=(z=t==null?void 0:t.config)==null?void 0:z.joinPlan,b=yo(F,k,T);if(!b.isValid){b.showError&&Is();return}const L=s.getSmartContainerForField(F),A=x(L);if(As(F,A))return;const O=s.getNewField(F,L);O&&f(L,[...A,O])},[h,(w=t==null?void 0:t.config)==null?void 0:w.joinPlan,x,f]),R=M.useCallback((F,k)=>{if(!h)return;const b=x(F)[k];if(b){if(F!=="sortBy"){const L=x("sortBy"),A=L.filter(O=>!(O.name===b.name&&O.qualifiedEntityName===b.qualifiedEntityName));A.length!==L.length&&a(h,{sortByColumns:A})}switch(F){case"groupBy":c(h,b.id);break;case"metrics":i(h,b.id);break;case"pivotBy":d(h,b.id);break;case"sortBy":m(h,b.id);break}}},[h,x,c,i,d,m,a]);return{getFieldsForContainer:x,setFieldsForContainer:f,updateLabel:j,handleAggregationChange:p,handleDateFormatChange:y,handleGranularityChange:g,handleAliasTemplateChange:C,handleValueAliasesChange:E,removeField:R,handleFieldClick:D,handleKpiComparisonTypeChange:B,handleKpiShowTrendlineChange:S,handleKpiTrendlineWindowChange:N,handleKpiTrendlineGranularityChange:v,handleKpiTargetValueChange:I,cardType:u}};function vo({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 bo({field:t}){const{attributes:a,listeners:n,setNodeRef:r,transform:l,transition:o,isDragging:c}=s.useSortable({id:t.id}),[i,d]=M.useState(!1),m=s.useEditorStore(j=>j.card),{handleFieldClick:u}=Zs(m),h={transform:s.CSS.Transform.toString(l),transition:o};s.getDataType(t.dataType);const x=j=>{const p=(j||"").toLowerCase();switch(s.getDataType(p)){case"number":return Ge;case"date":return s.Calendar;case"boolean":return ns;case"json":return ot;case"geo":return it;default:return Qe}},f=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(Qe,{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(Ge,{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(ns,{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(ot,{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(it,{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(Et,{className:"h-3 w-3"})}):null};return x(t.dataType),e.jsxs("div",{ref:r,style:h,...a,...n,className:`group/container overflow-hidden rounded-lg transition-all ${c?"scale-95 opacity-50":"border border-transparent hover:bg-muted"}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3 p-2",onClick:()=>u(t),children:[f(t.dataType),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:e.jsx("span",{className:`block text-sm text-foreground/80 hover:text-foreground dark:text-muted-foreground ${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(vo,{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(Bt,{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(Ua,{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 No(){const[t,a]=M.useState(""),[n,r]=M.useState("all"),l=s.useEditorStore(E=>E.card.dataSource),{columns:o=[],columnGroups:c=[],isLoading:i,error:d}=s.useColumns(),m=o.filter(E=>E.name.toLowerCase().includes(t.toLowerCase())||E.dataType.toLowerCase().includes(t.toLowerCase())||E.qualifiedEntityName&&E.qualifiedEntityName.toLowerCase().includes(t.toLowerCase())),u=E=>{if(E.dataType==="number"||E.dataType==="integer"||E.dataType==="float"||E.dataType==="decimal"||E.dataType==="currency")return"metrics";const B=s.getDataType(E.dataType);return["date","string","boolean"].includes(B)?"dimensions":B==="number"?"metrics":"dimensions"},x=(n==="all"?m:m.filter(E=>u(E)===n)).reduce((E,B)=>{const S=B.qualifiedEntityName||"Other Fields";return E[S]||(E[S]={label:s.toLabel(B.entityName),fields:[]}),E[S].fields.push(B),E},{}),j=Object.keys(x),p=m.filter(E=>u(E)==="dimensions").length,y=m.filter(E=>u(E)==="metrics").length,g=m.filter(E=>u(E)==="calculated").length,C=m.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:E=>a(E.target.value)})]}),C&&e.jsx(s.Tabs,{defaultValue:"all",value:n,onValueChange:E=>r(E),className:"mb-4",children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-4",children:[e.jsxs(s.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:m.length})]}),e.jsxs(s.TabsTrigger,{value:"dimensions",className:"text-xs",children:[e.jsx(s.Layers,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:p})]}),e.jsxs(s.TabsTrigger,{value:"metrics",className:"text-xs",children:[e.jsx(s.ChartColumn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:y})]}),e.jsxs(s.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(Et,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:g})]})]})})]}),e.jsxs(s.CustomScrollArea,{className:"py-2",children:[e.jsx(s.Accordion,{type:"multiple",defaultValue:j,className:"space-y-2",children:Object.entries(x).map(([E,B])=>{const S=c.find(N=>N.entityName===E)||{entityName:E,label:B.label};return e.jsxs(s.AccordionItem,{value:E,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:S.label||S.entityName}),e.jsx(s.Badge,{variant:"secondary",className:"rounded-full text-xs text-muted-foreground group-hover:bg-background",children:B.fields.length})]})}),e.jsx(s.AccordionContent,{className:"pb-2",children:e.jsx("div",{className:"space-y-1",children:B.fields.map(N=>e.jsx(bo,{field:N},N.id))})})]},E)})}),Object.keys(x).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(x).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 Co(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(No,{})," "]})}function So({initialJoinPlan:t,availableDataSources:a}){const[n,r]=M.useState(t),[l,o]=M.useState(new Set),c=()=>{const N=n.joins.length>0?Math.max(...n.joins.map(I=>I.sequence))+1:1,v={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:N,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=N=>{r({...n,joins:n.joins.filter(v=>v.id!==N)}),o(new Set([...l].filter(v=>v!==N)))},d=(N,v)=>{var w,F;const I=n.joins.find(k=>k.id===N);if(!I)return;const D={...I,...v},R=n.joins.map(k=>k.id===N?D:k);if((w=D.source)!=null&&w.name&&((F=D.target)!=null&&F.name)&&D.joinKeyGroups[0].keys.length===0){const k=a.find(A=>{var O;return A.name===((O=D.source)==null?void 0:O.name)}),T=a.find(A=>{var O;return A.name===((O=D.target)==null?void 0:O.name)}),b={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",entityId:(k==null?void 0:k.name)||"",entityName:(k==null?void 0:k.name)||"",entityType:(k==null?void 0:k.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(T==null?void 0:T.name)||"",entityName:(T==null?void 0:T.name)||"",entityType:(T==null?void 0:T.type)||"table"},operator:"="},L=[...D.joinKeyGroups];L[0]={...L[0],keys:[b]},D.joinKeyGroups=L,R[R.findIndex(A=>A.id===N)]=D}r({...n,joins:R})};return{joinPlan:n,expandedJoins:l,setJoinPlan:r,addJoin:c,removeJoin:i,updateJoin:d,moveJoinUp:N=>{const v=n.joins.findIndex(I=>I.id===N);if(v>0){const I=[...n.joins],D={...I[v]},R={...I[v-1]};I[v]=R,I[v-1]=D,I.forEach((F,k)=>{F.sequence=k+1});const w={...n,joins:I};r(w)}},moveJoinDown:N=>{const v=n.joins.findIndex(I=>I.id===N);if(v<n.joins.length-1){const I=[...n.joins],D={...I[v]},R={...I[v+1]};I[v]=R,I[v+1]=D,I.forEach((F,k)=>{F.sequence=k+1});const w={...n,joins:I};r(w)}},toggleJoinExpansion:N=>{const v=new Set(l);v.has(N)?v.delete(N):v.add(N),o(v)},getAvailableSourceEntities:N=>{if(n.joins.length===0)return a;const v=n.joins.findIndex(D=>D.id===N);if(v===0)return a;const I=new Set;return n.baseEntity.name&&I.add(n.baseEntity.name),n.joins.slice(0,v).forEach(D=>{I.add(D.source.name),I.add(D.target.name)}),a.filter(D=>I.has(D.name))},getAvailableTargetEntities:N=>a.filter(v=>v.name!==N),addJoinKeyGroup:N=>{const v=n.joins.find(D=>D.id===N);if(!v)return;const I=[...v.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];d(N,{joinKeyGroups:I})},updateGroupOperator:(N,v,I)=>{const D=n.joins.find(w=>w.id===N);if(!D)return;const R=[...D.joinKeyGroups];R[v]={...R[v],operator:I},d(N,{joinKeyGroups:R})},removeJoinKeyGroup:(N,v)=>{const I=n.joins.find(R=>R.id===N);if(!I)return;const D=[...I.joinKeyGroups];D.splice(v,1),d(N,{joinKeyGroups:D})},addJoinKey:(N,v)=>{const I=n.joins.find(k=>k.id===N);if(!I)return;const D=a.find(k=>k.name===I.source.name),R=a.find(k=>k.name===I.target.name),w=[...I.joinKeyGroups],F={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",entityId:(D==null?void 0:D.name)||"",entityName:(D==null?void 0:D.name)||"",entityType:(D==null?void 0:D.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(R==null?void 0:R.name)||"",entityName:(R==null?void 0:R.name)||"",entityType:(R==null?void 0:R.type)||"table"},operator:"="};w[v]={...w[v],keys:[...w[v].keys,F]},d(N,{joinKeyGroups:w})},updateJoinKey:(N,v,I,D,R)=>{const w=n.joins.find(L=>L.id===N);if(!w)return;const F=a.find(L=>L.name===w.source.name),k=a.find(L=>L.name===w.target.name),T=[...w.joinKeyGroups],b=T[v].keys[I];D==="sourceColumnName"&&F?T[v].keys[I]={...b,source:{...b.source,name:R}}:D==="targetColumnName"&&k?T[v].keys[I]={...b,target:{...b.target,name:R}}:D==="operator"&&(T[v].keys[I]={...b,operator:R}),d(N,{joinKeyGroups:T})},removeJoinKey:(N,v,I)=>{const D=n.joins.find(w=>w.id===N);if(!D)return;const R=[...D.joinKeyGroups];R[v].keys.splice(I,1),d(N,{joinKeyGroups:R})},generateSQLPreview:()=>{const N=[...n.joins].sort((D,R)=>D.sequence-R.sequence),v=n.baseEntity;if(!v.name)return"SELECT * FROM table -- Please select a base entity";let I=`SELECT *
|
|
450
|
-
FROM ${v.name}`;return N.forEach(D=>{const R=a.find(k=>k.name===D.target.name);if(!R)return;const w=D.joinKeyGroups.filter(k=>k.keys&&k.keys.length>0).map(k=>{const T=k.keys.filter(b=>{var L,A,O,z;return((L=b.source)==null?void 0:L.name)&&((A=b.target)==null?void 0:A.name)&&((O=b.source)==null?void 0:O.entityName)&&((z=b.target)==null?void 0:z.entityName)}).map(b=>`${b.source.entityName}.${b.source.name} ${b.operator} ${b.target.entityName}.${b.target.name}`);return T.length>1?`(${T.join(` ${k.operator} `)})`:T[0]}).filter(Boolean),F=w.length>1?w.join(" OR "):w[0]||"condition_here";I+=`
|
|
451
|
-
${D.joinType} JOIN ${R.name}
|
|
452
|
-
ON ${F}`}),I},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(D=>!D.source.name||!D.target.name)||n.joins.some(D=>D.joinKeyGroups.some(R=>R.keys.length===0))||n.joins.some(D=>D.joinKeyGroups.some(R=>R.keys.some(w=>!w.source.name||!w.target.name||!w.operator))))}}function wo({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:m,addJoin:u,removeJoin:h,updateJoin:x,moveJoinUp:f,moveJoinDown:j,toggleJoinExpansion:p,getAvailableSourceEntities:y,getAvailableTargetEntities:g,addJoinKeyGroup:C,updateGroupOperator:E,removeJoinKeyGroup:B,addJoinKey:S,updateJoinKey:N,removeJoinKey:v,generateSQLPreview:I,isValidConfiguration:D}=So({initialJoinPlan:t,availableDataSources:a}),R=w=>{const F=c.find(k=>k.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(k=>k.name===w);m({...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:I()})]}),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:u,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(b=>b.name===w.source.name),k=a.find(b=>b.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&&k&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",F.name," → ",k.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>f(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:b=>{const L=a.find(A=>A.name===b);x(w.id,{source:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:b,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:y(w.id).map(b=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:b.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:b.type}),b.name]})},b.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:w.joinType,onValueChange:b=>x(w.id,{joinType:b}),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:b=>{const L=a.find(A=>A.name===b);x(w.id,{target:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:b,database:L==null?void 0:L.database,schema:L==null?void 0:L.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?g(w.source.name).map(b=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:b.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:b.type}),b.name,b.name===w.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},b.name)):[]})]})]})]}),w.source.name&&w.target.name&&F&&k&&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:()=>C(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((b,L)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",L+1]}),L>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:b.operator,onValueChange:A=>E(w.id,L,A),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:()=>B(w.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[b.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:b.keys.map((A,O)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[O>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:b.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:A.source.name,onValueChange:z=>N(w.id,L,O,"sourceColumnName",z),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:R(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:A.operator,onValueChange:z=>N(w.id,L,O,"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:A.target.name,onValueChange:z=>N(w.id,L,O,"targetColumnName",z),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:R(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,L,O),children:e.jsx(s.X,{className:"size-3.5"})})]},A.id||O))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>S(w.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},b.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:!D(),children:"Save"})]})]})}function Ct({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(wo,{joinPlan:r,availableDataSources:l,onSave:c,onCancel:i,onRemove:o})]}),t]})}function ko({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,m)=>d+m.keys.length,0)," ","condition",l.joinKeyGroups.reduce((d,m)=>d+m.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 Do(){var u,h;const t=s.useEditorStore(x=>x.card),a=s.useEditorStore(x=>x.actions.updateCardConfig),n=((u=t==null?void 0:t.config)==null?void 0:u.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[r,l]=M.useState(!1),o=((h=t==null?void 0:t.dataSource)==null?void 0:h.selectedEntities)||[],c=x=>{a(t.id,{...t==null?void 0:t.config,joinPlan:x}),l(!1)},i=()=>{a(t.id,{...t==null?void 0:t.config,joinPlan:void 0})},d=()=>{l(!1)},m=()=>{const x=[...n.joins].sort((p,y)=>p.sequence-y.sequence),f=n.baseEntity;if(!f.name)return"SELECT * FROM table -- Please select a base entity";let j=`SELECT *
|
|
453
|
-
FROM ${f.name}`;return x.forEach(p=>{const y=o.find(E=>E.name===p.target.name);if(!y)return;const g=p.joinKeyGroups.filter(E=>E.keys&&E.keys.length>0).map(E=>{const B=E.keys.filter(S=>{var N,v,I,D;return((N=S.source)==null?void 0:N.name)&&((v=S.target)==null?void 0:v.name)&&((I=S.source)==null?void 0:I.entityName)&&((D=S.target)==null?void 0:D.entityName)}).map(S=>`${S.source.entityName}.${S.source.name} ${S.operator} ${S.target.entityName}.${S.target.name}`);return B.length>1?`(${B.join(` ${E.operator} `)})`:B[0]}).filter(Boolean),C=g.length>1?g.join(" OR "):g[0]||"condition_here";j+=`
|
|
454
|
-
${p.joinType} JOIN ${y.name}
|
|
455
|
-
ON ${C}`}),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(ko,{joins:n.joins,baseEntityId:n.baseEntity.name,availableDataSources:o,generateSQLPreview:m})})]})}),e.jsx(Ct,{open:r,onOpenChange:l,joinPlan:n,availableDataSources:o,onSave:c,onCancel:d,onRemove:i,children:e.jsx("div",{})})]}),n.joins.length===0&&e.jsx(Ct,{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 Eo({open:t,onOpenChange:a}){const[n,r]=M.useState([]),{updateDataSource:l}=s.useEditorActions(),o=s.useDashboardStore(p=>p.dashboard.aiContext),c=(o==null?void 0:o.selectedEntities)||[];M.useEffect(()=>{t&&r([])},[t]);const i=p=>{r(y=>y.some(C=>C.name===p.name&&C.type===p.type)?y.filter(C=>!(C.name===p.name&&C.type===p.type)):[...y,p])},d=()=>{r([...c])},m=()=>{r([])},u=()=>{if(n.length===0)return;const p=n[0],y=p.connectionId||"",g=p.connectionType||"",E=n.some(S=>S.type==="dataset")?"semanticDomain":"database";l({connectionId:y,connectionType:g,mode:E,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($a,{className:"h-4 w-4"});case"model":return e.jsx(da,{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"})}},x=p=>"label"in p&&p.label?p.label:p.name,f=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:m,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:x(p)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:f(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:u,disabled:n.length===0,children:["Select"," ",n.length>0?`(${n.length})`:""]})]})})})]})})}function To({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 Io({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 Ao({isVisible:t,onToggleVisibility:a}){const[n,r]=M.useState(!1),[l,o]=M.useState(!1),[c,i]=M.useState(!0),d=s.useEditorStore(x=>x.card.dataSource);Ne();const{updateDataSource:m}=s.useEditorActions(),u={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},h={...u,...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((x,f)=>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(x),e.jsx("button",{onClick:j=>{j.stopPropagation();const p=h.selectedEntities.filter(y=>!(y.name===x.name&&y.type===x.type));m({...u,...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(To,{entity:x})]},`${x.type}-${x.name}-${f}`)),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(Io,{entities:h.selectedEntities.slice(3)})]})]})}),e.jsx(Do,{})]})]}),e.jsx(Co,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(d==null?void 0:d.selectedEntities)||[],dialogMode:"dataSource",open:n,onOpenChange:r,dataSource:h,fallbackDataSource:u}),e.jsx(Eo,{open:l,onOpenChange:o})]})}const ts=[{id:"table",icon:_e,label:"Table"},{id:"pivotTable",icon:_e,label:"Pivot Table"},{id:"aggregateTable",icon:_e,label:"Aggregate Table"},{id:"bar",icon:ds,label:"Bar Chart"},{id:"line",icon:us,label:"Line Chart"},{id:"area",icon:Tt,label:"Area Chart"},{id:"stackedBar",icon:Ms,label:"Stacked Bar Chart"},{id:"combo",icon:ra,label:"Combo Chart"},{id:"stackedLine",icon:Qs,label:"Stacked Line Chart"},{id:"scatter",icon:Os,label:"Scatter Chart"},{id:"bubble",icon:Hs,label:"Bubble Chart"},{id:"pie",icon:ms,label:"Pie Chart"},{id:"doughnut",icon:Rs,label:"Doughnut Chart"},{id:"funnel",icon:Ks,label:"Funnel Chart"},{id:"radar",icon:Fs,label:"Radar Chart"},{id:"polarArea",icon:Gs,label:"Polar Area Chart"},{id:"tornado",icon:Ps,label:"Tornado Chart"},{id:"range",icon:Ls,label:"Range Chart"},{id:"kpi",icon:Ws,label:"KPI"},{id:"text",icon:Dt,label:"Text"},{id:"map",icon:Bs,label:"Map"}],et=t=>{const a=t.toLowerCase();for(const n of ts)if(n.id==="doughnut"){if(a.includes("doughnut")||a.includes("donut")){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}}else if(a.includes(n.id.toLowerCase())){const r=n.icon;return M.createElement(r,{className:"h-4 w-4"})}return null},Mo="chart-selector-standard-first";function Lo(){const[t,a]=s.useLocalStorageState(Mo,!0);return{standardFirst:t,updatePreference:a}}const St=({pluginVisual:t,index:a,onSelect:n})=>{const r=xs(t.icon||""),l=t.name.charAt(0).toUpperCase(),o=et(t.name);return e.jsx(s.CommandItem,{value:`${t.name} custom visual plugin component`,onSelect:n,className:"group flex items-center gap-2",children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsx(r,{className:"h-4 w-4"}):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}`)},wt=["default","standardPlugin","customPlugin"];function Oo({selectedChart:t,onChartChange:a}){var B;const[n,r]=M.useState(!1),{data:l}=pn();Lo();const c=((B=s.useEditorStore(S=>S.card).customCardPreferences)==null?void 0:B.url)||"";Vs(c);const{setCardType:i,setCardPreferences:d,setIsDevMode:m}=s.useEditorStore(S=>S.actions),{setCardCustomCfg:u,setCustomCardPreferences:h,setQueryConfig:x}=s.useEditorActions(),[f,j]=s.useLocalStorageState("chart-section-active",null),p=M.useMemo(()=>f?[f,...wt.filter(S=>S!==f)]:wt,[f]);function y(S){u(null),d({}),i(S),["custom","text","map"].includes(S)&&(m(!0),x(void 0)),a(S),r(!1)}function g(S){u(null),d({}),i("custom"),h({type:"component",visualType:"single",url:S.url,componentName:S.name,icon:S.icon,pluginChartType:S.chartType}),x(void 0),a("custom"),r(!1)}const C=()=>{var N;if(t==="custom"){const v=s.useEditorStore.getState().card;return((N=v==null?void 0:v.customCardPreferences)==null?void 0:N.componentName)||"Custom Visual"}const S=ts.find(v=>v.id===t);return(S==null?void 0:S.label)||"Select chart type"},E=()=>{var N,v;if(t==="custom"){const I=s.useEditorStore.getState().card,D=(N=I==null?void 0:I.customCardPreferences)==null?void 0:N.icon,R=(v=I==null?void 0:I.customCardPreferences)==null?void 0:v.componentName;if(D&&R)return e.jsx(Ro,{icon:D,componentName:R});if(R){const w=et(R);if(w)return w}return e.jsx(He,{className:"h-4 w-4"})}const S=ts.find(I=>I.id===t);if(S){const I=S.icon;return e.jsx(I,{className:"h-4 w-4"})}return e.jsx(He,{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:[E(),e.jsx("span",{children:C()})]}),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(S=>{if(S==="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:f==="default",onCheckedChange:N=>j(N?"default":null),className:"scale-75"})]})]}),className:"[&_[cmdk-group-heading]]:text-sm [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",children:ts.map(N=>{const v=N.icon;return e.jsx(s.CommandItem,{value:`${N.label} ${N.id} chart graph visualization`,onSelect:()=>y(N.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:N.label})]})},N.id)})},"default");if(S==="standardPlugin"){const N=l.filter(v=>v.pluginType==="standard");return N.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:f==="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:N.filter(v=>v.componentType==="chart").map((v,I)=>e.jsx(St,{pluginVisual:v,index:I,onSelect:()=>g(v)},`${v.url}-${v.name}-${I}`))},"standardPlugin"):null}if(S==="customPlugin"){const N=l.filter(v=>v.pluginType==="custom");return N.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:f==="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:N.map((v,I)=>e.jsx(St,{pluginVisual:v,index:I,onSelect:()=>g(v)},`${v.url}-${v.name}-${I}`))},"customPlugin"):null}return null})]})]})})]})})}const Ro=({icon:t,componentName:a})=>{const n=xs(),r=et(a);return n?e.jsx(n,{className:"h-4 w-4"}):r||e.jsx(He,{className:"h-4 w-4"})},Ln=({dataType:t})=>{const a=s.getDataType(t);return a==="string"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-blue-100 text-xs text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:e.jsx(Qe,{className:"h-3 w-3"})}):a==="number"?e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-green-100 text-xs text-green-700 dark:bg-green-950 dark:text-green-300",children:e.jsx(Ge,{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(ns,{className:"h-3 w-3"})}):e.jsx("span",{className:"flex size-6 shrink-0 items-center justify-center rounded-sm bg-gray-100 text-xs text-gray-700 dark:bg-gray-950 dark:text-gray-300",children:e.jsx(Qe,{className:"h-3 w-3"})})};function Bo({aliasTemplate:t,onAliasTemplateChange:a}){var d;const[n,r]=M.useState(t),[l,o]=M.useState(!1),c=(d=s.useEditorStore(m=>{var u;return(u=m.card.config)==null?void 0:u.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:m=>{r(m.target.value),o(!0)},onFocus:()=>o(!0),onPointerDown:m=>m.stopPropagation(),className:"h-8 text-xs",onKeyDown:m=>{m.key==="Enter"&&l&&n!==t?(a(n),o(!1)):m.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 Fo({valueAliases:t,onValueAliasesChange:a}){const[n,r]=M.useState(null),[l,o]=M.useState(""),[c,i]=M.useState(""),d=()=>{a({...t,"":""})},m=h=>{const x={...t};delete x[h],a(x)},u=h=>{const x={...t};delete x[h],x[l]=c,a(x),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([h,x],f)=>e.jsx("div",{className:"flex items-center gap-2",children:n===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:l,onChange:j=>o(j.target.value),className:"h-8 w-24 text-xs",onPointerDown:j=>j.stopPropagation(),onKeyDown:j=>{j.key==="Enter"?u(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"?u(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:()=>u(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(x)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:x,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),o(h),i(x)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>m(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+f)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:d,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Po({field:t,zone:a,index:n,sortDirection:r,onSortDirectionChange:l,hasPivotColumns:o=!1,cardType:c}){var nt;const{attributes:i,listeners:d,setNodeRef:m,transform:u,transition:h,isDragging:x}=s.useSortable({id:t.id}),f=s.useEditorStore(J=>J.card),{updateLabel:j,handleAggregationChange:p,handleDateFormatChange:y,handleGranularityChange:g,handleAliasTemplateChange:C,handleValueAliasesChange:E,removeField:B,handleKpiComparisonTypeChange:S,handleKpiShowTrendlineChange:N,handleKpiTrendlineWindowChange:v,handleKpiTrendlineGranularityChange:I,handleKpiTargetValueChange:D}=Zs(f),[R,w]=M.useState(!1),[F,k]=M.useState(t.dateFormat||"YYYY-MM-DD"),[T,b]=M.useState(t.customFormat||""),[L,A]=M.useState(!!t.customFormat),[O,z]=M.useState(t.granularity||"day"),[_,Q]=M.useState(t.aliasTemplate||""),[W,$]=M.useState(t.valueAliases||{}),q=J=>{J==="custom"?A(!0):(A(!1),k(J),a==="groupBy"&&y(n,J,""))},H=J=>{b(J),a==="groupBy"&&y(n,"custom",J)},U=J=>{var qe;z(J);const pe=(qe=K(J)[0])==null?void 0:qe.value;pe&&!L&&(k(pe),a==="groupBy"&&y(n,pe,"")),a==="groupBy"&&g(n,J)},P=J=>{Q(J),a==="metrics"&&C(n,J)},Y=J=>{$(J),a==="metrics"&&E(n,J)},G=J=>{j(a,n,J)},X=()=>{B(a,n)},se={transform:s.CSS.Transform.toString(u),transition:h},ae=s.getDataType(t.dataType),te=ae==="date",le=c==="kpi",K=J=>{switch(J){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..."}]}},V=K(O),Z=!le&&a!=="pivotBy",oe=te&&a==="groupBy",Ce=!le&&te&&a==="groupBy",Te=le&&te&&a==="groupBy",ne=le&&a==="metrics"&&((nt=f.config)==null?void 0:nt.comparisonType)==="target",ie=a==="metrics",ce=()=>e.jsx("div",{onPointerDown:J=>{J.stopPropagation()},className:"cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),Bn=()=>Z?e.jsx(ue,{value:t.label??"",onSave:G,placeholder:"Display label...",type:"text"}):null,tt=()=>oe?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:O,onValueChange:U,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(J=>e.jsx(s.SelectItem,{className:"text-xs",value:J,children:s.toTitleCase(J)},J))})]})]}):null,Fn=()=>Ce?e.jsxs(e.Fragment,{children:[tt(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:L?"custom":F,onValueChange:q,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:V.map(J=>e.jsx(s.SelectItem,{className:"text-xs",value:J.value,children:J.label},J.value))})]}),L&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:T,onChange:J=>{J.stopPropagation(),H(J.target.value)},onClick:J=>J.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,Pn=()=>{var J,je,pe,qe,at;return Te?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:((J=f.config)==null?void 0:J.comparisonType)||"none",onValueChange:S,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:((je=f.config)==null?void 0:je.showTrendline)||!1,onCheckedChange:N})]})}),((pe=f.config)==null?void 0:pe.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:((qe=f.config)==null?void 0:qe.trendlineWindow)||30,onChange:_n=>{const Un=parseInt(_n.target.value)||30;v(Un)},className:"h-8 text-xs",placeholder:"30"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Granularity"}),e.jsxs(s.Select,{value:((at=f.config)==null?void 0:at.trendlineGranularity)||"day",onValueChange:I,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},zn=()=>{var J,je;return ne?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(ue,{value:((J=f.config)==null?void 0:J.targetValue)!==void 0&&((je=f.config)==null?void 0:je.targetValue)!==null?String(f.config.targetValue):"",onSave:pe=>{!isNaN(Number(pe))&&pe!==null?D(Number(pe)):D(0)},placeholder:"Enter target value...",type:"text"})]}):null},Vn=()=>ie?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:J=>{p(n,J)},children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select function..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"COUNT",children:"Count"}),e.jsx(s.SelectItem,{className:"text-xs",value:"DISTINCT",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{className:"text-xs",value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MEDIAN",children:"Median"})]})]})]})]}),e.jsx(In,{column:t}),o&&e.jsxs(e.Fragment,{children:[e.jsx(Bo,{aliasTemplate:_,onAliasTemplateChange:P}),e.jsx(Fo,{valueAliases:W,onValueAliasesChange:Y})]})]}):null;return e.jsxs("div",{ref:m,style:se,...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 ${x?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Ln,{dataType:ae}),e.jsx(Js,{className:"w-[140px] flex-1 text-sm",children:t.label||t.name}),a!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:J=>{J.stopPropagation(),w(!R)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${R?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:J=>{J.stopPropagation(),console.log("DraggableField - Current sortDirection:",r);const je=r==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",je),l(je)},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:J=>{J.stopPropagation(),X()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),R&&e.jsxs("div",{className:"space-y-3",children:[ce(),Bn(),c==="kpi"&&tt(),Fn(),Pn(),zn(),Vn()]})]})}function zo({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 es({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(),m=s.useEditorStore(j=>j.card),u=s.useEditorStore(j=>j.card.type),h=a.length>0,x=(j,p)=>{var g;!((g=m.config)!=null&&g.sortByColumns)||m.config.sortByColumns.findIndex(C=>C.id===j)===-1||d(m.id,j,{direction:p})};if(t==="sortBy"&&l===!1)return null;const f=t!=="sortBy"&&u!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:n}),f&&e.jsx(zo,{concept:t})]}),e.jsx("div",{ref:i,className:`min-h-[60px] rounded-lg border-2 border-dashed p-2 transition-all ${c?"border-blue-500 bg-blue-50 dark:bg-blue-950":h?"border-blue-200 bg-blue-50/30 dark:border-blue-800 dark:bg-blue-950/30":"border-muted-foreground/20 bg-background"}`,children:a.length===0?e.jsx("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:r}):e.jsx(s.SortableContext,{items:a.map(j=>j.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((j,p)=>{const g=j.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(Po,{field:j,zone:t,index:p,sortDirection:g,onSortDirectionChange:C=>x(j.id,C),hasPivotColumns:o,cardType:u})})},j.id)})})})})]})}function Vo({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r}){const l=s.useEditorStore(x=>{var f;return((f=x.card.customCardPreferences)==null?void 0:f.url)&&x.card.type==="custom"}),o=s.useEditorStore(x=>x.card),c=o==null?void 0:o.type,i=t.length>0||n.length>0,d=c!=="kpi",m=c!=="kpi"&&i,u=()=>c==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},h=()=>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:"mt-4 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(wa,{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(es,{zone:"groupBy",fields:t,label:u().label,placeholder:u().placeholder}),d&&e.jsx(es,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data"}),e.jsx(es,{zone:"metrics",fields:n,label:h().label,placeholder:h().placeholder,hasPivotColumns:a.length>0}),m&&e.jsx(es,{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 bg-muted/50 px-3 pt-2",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[e.jsx(wn,{}),e.jsx(kn,{}),e.jsx(Dn,{}),e.jsx(En,{})]})})]})]})}function _o({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(),m=s.useEditorStore(h=>h.card),{data:u}=s.useDashboardCardQuery(m);return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col",children:[e.jsxs("div",{className:"space-y-4 px-6 pt-4",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})}),e.jsx(Oo,{selectedChart:t,onChartChange:a})]}),e.jsxs("div",{className:s.cn("flex justify-end gap-2 px-6 pt-6"),children:[e.jsx("div",{className:s.cn("invisible",{visible:i||u}),children:e.jsx(hs,{})}),!c&&e.jsxs(s.Button,{onClick:()=>d(!c),variant:"outline",className:"h-8",size:"sm",children:[e.jsx(za,{className:"mr-2 size-4"}),"AI"]})]}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6",children:[e.jsx(Vo,{groupByFields:n,pivotByFields:r,metricsFields:l,sortByFields:o}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Uo({initialFilters:t,availableFields:a}={}){const[n,r]=M.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(S=>S.card.dataSource);const{columns:l,isLoading:o}=s.useColumns(),i=a||l||[],d={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},m=S=>{const N=v=>{if(v.id===S){const I=i[0]||d;return{...v,conditions:[...v.conditions,{id:`condition-${Date.now()}`,field:I,operator:"=",value:""}]}}return{...v,groups:v.groups.map(N)}};r(N(n))},u=S=>{const N=v=>{if(v.id===S){const I=i[0]||d;return{...v,groups:[...v.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:I,operator:"=",value:""}],groups:[]}]}}return{...v,groups:v.groups.map(N)}};r(N(n))},h=(S,N)=>{const v=I=>I.id===S?{...I,conditions:I.conditions.filter(D=>D.id!==N)}:{...I,groups:I.groups.map(v)};r(v(n))},x=(S,N)=>{const v=I=>I.id===S?{...I,groups:I.groups.filter(D=>D.id!==N)}:{...I,groups:I.groups.map(v)};r(v(n))},f=(S,N,v,I)=>{if(v==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const D=R=>R.id===S?{...R,conditions:R.conditions.map(w=>w.id===N?{...w,[v]:I}:w)}:{...R,groups:R.groups.map(D)};r(D(n))},j=(S,N,v)=>{const I=D=>D.id===S?{...D,conditions:D.conditions.map(R=>R.id===N?{...R,...v}:R)}:{...D,groups:D.groups.map(I)};r(I(n))},p=(S,N)=>{const v=I=>I.id===S?{...I,logicalOperator:N}:{...I,groups:I.groups.map(v)};r(v(n))},y=(S,N)=>{const v=I=>I.id===S?{...I,negate:N}:{...I,groups:I.groups.map(v)};r(v(n))},g=(S,N,v)=>{const I=D=>D.id===S?{...D,conditions:s.arrayMove(D.conditions,N,v)}:{...D,groups:D.groups.map(I)};r(I(n))},C=(S,N,v)=>{const I=D=>D.id===S?{...D,groups:s.arrayMove(D.groups,N,v)}:{...D,groups:D.groups.map(I)};r(I(n))},E=S=>{if(!S||S.conditions.length===0&&S.groups.length===0)return"-- No filters defined";const N=I=>{let D="";typeof I.field=="object"?D=I.field.entityName?`${I.field.entityName}.${I.field.name}`:I.field.name:D=String(I.field);const R=I.operator;let w=I.value;if(I.field.dataType==="string"&&!["in","not in"].includes(I.operator))typeof w=="string"?w=`'${w}'`:Array.isArray(w)&&(w=`'${w.join(", ")}'`);else if(I.field.dataType==="date")(typeof w=="string"||w instanceof Date)&&(w=`DATE('${w}')`);else if(["in","not in"].includes(I.operator)){let F=[];Array.isArray(w)?F=w.map(k=>typeof k=="string"?`'${k}'`:String(k)):typeof w=="string"?F=w.split(",").map(k=>{const T=k.trim();return I.field.dataType==="string"?`'${T}'`:T}):typeof w=="number"&&(F=[String(w)]),w=`(${F.join(", ")})`}switch(R){case"contains":return typeof w=="string"?`${D} LIKE '%${w.replace(/'/g,"")}'`:`${D} LIKE '%${String(w)}'`;case"startsWith":return typeof w=="string"?`${D} LIKE '${w.replace(/'/g,"")}%'`:`${D} LIKE '${String(w)}%'`;case"endsWith":return typeof w=="string"?`${D} LIKE '%${w.replace(/'/g,"")}'`:`${D} LIKE '%${String(w)}'`;default:return`${D} ${R} ${w}`}},v=I=>{const D=I.conditions.map(N),R=I.groups.map(T=>v(T)),w=[...D,...R].filter(Boolean);if(w.length===0)return"";const F=w.join(` ${I.logicalOperator} `),k=w.length>1?`(${F})`:F;return I.negate?`NOT ${k}`:k};return v(S)},B=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:i,isLoading:o,addCondition:m,addGroup:u,removeCondition:h,removeGroup:x,updateCondition:f,updateConditionFields:j,updateGroupOperator:p,updateGroupNegate:y,reorderConditions:g,reorderGroups:C,generateSQLPreview:E,hasAnyFilters:B}}function $o({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 qo=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(pa,{className:"h-3 w-3"});default:return e.jsx(s.Table,{className:"h-3 w-3"})}},Yo=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Go({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:l="w-64"}){const[o,c]=M.useState(!1),i=M.useMemo(()=>{const d={};return n.forEach(m=>{const u=Yo(m);d[u]||(d[u]={}),d[u][m.entityId]||(d[u][m.entityId]=[]),d[u][m.entityId].push(m)}),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($o,{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,m])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),d]}),children:Object.entries(m).map(([u,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:[qo(h[0].entityType),e.jsx("span",{children:h[0].entityName})]}),h.map((x,f)=>e.jsxs(s.CommandItem,{value:x.id,onSelect:()=>{a(x),c(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===x.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"",children:x.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:x.description&&e.jsx("span",{children:x.description})})]})]},x.id+f))]},`${d}-${u}`))},d))})]})})]})}function st(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]},m=((j=a.dataSource)==null?void 0:j.connectionId)||a.connectionId,{data:u,isPending:h,error:x}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:m,cardConfig:d,cardDataSource:a.dataSource})}catch(p){console.log(t),console.error("error",p)}},enabled:!!m,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((u==null?void 0:u.records)||[]).map(p=>({label:p[t.name]||"BLANK",value:p[t.name]||"BLANK",count:(p==null?void 0:p.count)||0})),isPending:h,error:x}}function Ho({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:l}){const[o,c]=me.useState(!1),{filterValues:i}=st(t),d=u=>{n(a.filter(h=>h!==u))},m=u=>{a.includes(u)?n(a.filter(h=>h!==u)):n([...a,u])};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(u=>{const h=i.find(x=>x.value===u);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:x=>{x.key==="Enter"&&d(u)},onMouseDown:x=>{x.preventDefault(),x.stopPropagation()},onClick:x=>{x.stopPropagation(),d(u)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},u)}):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((u,h)=>e.jsxs(s.CommandItem,{onSelect:()=>m(u.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(u.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:u.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:u.count})]})]},u.value+h))})]})]})})]})})}const On=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=On(n)}),a};function Ko({field:t,value:a,onChange:n,placeholder:r="Select value...",className:l}){const{filterValues:o,isPending:c,error:i}=st(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):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,m)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:d.value,children:d.label},d.value+m))})]})}const Qo=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Wo=["=","!=","contains","startsWith","endsWith","in","not in"],Jo=["=","!=",">",">=","<","<=","in","not in"],Xo=["=","!="],Zo=["=","!=",">",">=","<","<=","in","not in"];function ei(t){switch(t){case"string":return Wo;case"number":return Jo;case"boolean":return Xo;case"date":return Zo;default:return Qo}}function Rn({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:l,onRemoveCondition:o,onUpdateGroupOperator:c,availableFields:i,updateConditionFields:d}){const{attributes:m,listeners:u,setNodeRef:h,transform:x,transition:f,isDragging:j}=s.useSortable({id:t.id}),{isPending:p,error:y}=st(t.field),g={transform:s.CSS.Transform.toString(x),transition:f};return e.jsxs("div",{ref:h,style:g,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${j?"z-50 opacity-50":""}`,children:[e.jsx("div",{...m,...u,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:C=>c(n,C),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(Go,{value:t.field,onValueChange:C=>{d(n,t.id,{field:C,value:""})},availableFields:i,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:C=>{C==="in"||C==="not in"?d(n,t.id,{operator:C,value:[]}):d(n,t.id,{operator:C,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ei(s.getDataType(t.field.dataType)).map(C=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:C,children:C},C))})]}),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(Ho,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(C=>typeof C=="string")?t.value:[],onChange:C=>d(n,t.id,{value:C}),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:C=>d(n,t.id,{value:C.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Ko,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:C=>d(n,t.id,{value:C}),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:C=>d(n,t.id,{value:C==="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:C=>l(n,t.id,"value",C.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 si({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:l,onRemoveGroup:o,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onReorderConditions:m,onReorderGroups:u,onAddCondition:h,onAddGroup:x,availableFields:f,renderFilterGroup:j,updateConditionFields:p}){const{attributes:y,listeners:g,setNodeRef:C,transform:E,transition:B,isDragging:S}=s.useSortable({id:t.id}),N={transform:s.CSS.Transform.toString(E),transition:B},v=D=>{const{active:R,over:w}=D;if(w&&R.id!==w.id){const F=t.conditions.findIndex(T=>T.id===R.id),k=t.conditions.findIndex(T=>T.id===w.id);F!==-1&&k!==-1&&m(t.id,F,k)}},I=D=>{const{active:R,over:w}=D;if(w&&R.id!==w.id&&n){const F=t.groups.findIndex(T=>T.id===R.id),k=t.groups.findIndex(T=>T.id===w.id);F!==-1&&k!==-1&&u(n,F,k)}};return e.jsxs("div",{ref:C,style:N,className:`rounded-lg ${a>0?"mt-2 border border-border":""} ${S?"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,...g,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:D=>r(t.id,D),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(D=>D.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((D,R)=>e.jsx(Rn,{condition:D,index:R,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:i,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:f,updateConditionFields:p},D.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:I,children:e.jsx(s.SortableContext,{items:t.groups.map(D=>D.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(D=>j(D,a+1,t.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>x(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function ti({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:l}){const{currentFilters:o,availableFields:c,isLoading:i,addCondition:d,addGroup:m,removeCondition:u,removeGroup:h,updateCondition:x,updateConditionFields:f,updateGroupOperator:j,updateGroupNegate:p,reorderConditions:y,reorderGroups:g,generateSQLPreview:C,hasAnyFilters:E,setCurrentFilters:B}=Uo({initialFilters:t,availableFields:a}),S=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[N,v]=M.useState(!1),I=(w,F,k)=>{const T=b=>b.id===w?{...b,conditions:b.conditions.map(L=>L.id===F?{...L,field:k,dataType:k.dataType}:L)}:{...b,groups:b.groups.map(T)};B(T(o))},D=(w,F=0,k)=>F===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:S,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:b,over:L}=T;if(L&&b.id!==L.id){const A=w.conditions.findIndex(z=>z.id===b.id),O=w.conditions.findIndex(z=>z.id===L.id);A!==-1&&O!==-1&&y(w.id,A,O)}},children:e.jsx(s.SortableContext,{items:w.conditions.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.conditions.map((T,b)=>e.jsx(Rn,{condition:T,index:b,groupId:w.id,groupLogicalOperator:w.logicalOperator,onUpdateCondition:x,onUpdateField:I,onRemoveCondition:u,onUpdateGroupOperator:j,availableFields:c,updateConditionFields:f},T.id))})}),e.jsx(s.DndContext,{sensors:S,collisionDetection:s.closestCenter,onDragEnd:T=>{const{active:b,over:L}=T;if(L&&b.id!==L.id){const A=w.groups.findIndex(z=>z.id===b.id),O=w.groups.findIndex(z=>z.id===L.id);A!==-1&&O!==-1&&g(w.id,A,O)}},children:e.jsx(s.SortableContext,{items:w.groups.map(T=>T.id),strategy:s.verticalListSortingStrategy,children:w.groups.map(T=>D(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"]}),N&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(w.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},w.id):e.jsx(si,{group:w,depth:F,parentGroupId:k,onUpdateGroupOperator:j,onUpdateGroupNegate:p,onRemoveGroup:h,onUpdateCondition:x,onUpdateField:I,onRemoveCondition:u,onReorderConditions:y,onReorderGroups:g,onAddCondition:d,onAddGroup:m,availableFields:c,renderFilterGroup:D,updateConditionFields:f},w.id),R=On(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..."})]}):D(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:N,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)"})]})}),E&&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:C(o)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:l,children:"Cancel"}),R>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(E?o:null),children:"Apply Filters"})]})]})}function ni({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:l,isOpen:o,onOpenChange:c}){const i=m=>{n(t,m),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:m=>{m.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(ti,{filters:a,availableFields:l,onSave:i,onCancel:()=>c(!1),onClearAll:d})]})]})}function ai({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var f;const[l,o]=M.useState(null),c=s.useEditorStore(j=>j.card),i=(f=c==null?void 0:c.config)==null?void 0:f.joinPlan,d=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],m=M.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]),u=M.useCallback(j=>{o(j.active.id)},[]),h=M.useCallback(j=>{const{active:p,over:y}=j;if(!y||!t){o(null);return}const g=p.id,C=y.id,E=m(g),B=m(C)||C;if(E==="source"&&B==="sortBy"){o(null);return}if(E==="source"&&B!=="source"&&B!=="sortBy"){const S=[...a].find(D=>D.id===g);if(!S){o(null);return}const N=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(N.length>0){const D=N[0].qualifiedEntityName;if(!D){o(null);return}if(D!==S.qualifiedEntityName&&S.qualifiedEntityName)if(i){if(!Mn(D,S.qualifiedEntityName,i)){Is(),o(null);return}}else{Is(),o(null);return}}const v=n(B);if(As(S,v)){o(null);return}const I=s.getNewField(S,B);o(null),r(B,[...v,I]);return}if(E&&B&&E!=="source"&&B!=="source"&&E!==B){const S=n(E),N=n(B),v=S.find(R=>R.id===g);if(!v){o(null);return}const I=s.getNewField(v,B);if(o(null),B==="sortBy"){if(E==="pivotBy"){o(null);return}As(v,N)||r(B,[...N,I]);return}const D=S.filter(R=>R.id!==g);r(E,D),r(B,[...N,I]);return}if(E&&B&&E===B&&E!=="source"){const S=n(E),N=S.findIndex(I=>I.id===g),v=S.findIndex(I=>I.id===C);if(N!==v){const I=s.arrayMove(S,N,v);r(E,I)}}o(null)},[t,a,n,r,m,i]),x=l?d.find(j=>j.id===l):null;return{activeId:l,activeField:x,handleDragStart:u,handleDragEnd:h}}function ri({onAdvancedToggle:t,onDebugToggle:a,onAccept:n}){const{currentUser:r}=Ne();r==null||r.role;const[l,o]=M.useState(!1),c=s.useEditorStore(g=>g.isDevMode),i=s.useEditorStore(g=>g.card),d=s.useEditorStore(g=>g.card.dataSource);s.isExplorerCard(i);const{config:m}=M.useContext(s.SemaphorContext).tokenProps,u=(m==null?void 0:m.showAdvancedMode)!==!1,{setIsDevMode:h}=s.useEditorActions(),x=s.useEditorStore(g=>g.showAIDialog),f=s.useEditorStore(g=>g.frame),j=s.useManagementStore(g=>g.selectedVisual),p=(j==null?void 0:j.id)===(f==null?void 0:f.id),{setShowAIDialog:y}=s.useEditorActions();return e.jsxs("div",{className:s.cn("flex items-center justify-between px-6 py-3",x&&"justify-end",!u&&"justify-end"),children:[u&&t&&!x&&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(Ys,{}),n&&!p&&e.jsx(qs,{variant:"default"}),p&&e.jsx(il,{}),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 li({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 oi=[{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 ii(){var d,m;const t=s.useEditorStore(u=>u.card),{updateRowLimit:a}=s.useEditorActions(),[n,r]=M.useState(!1),[l,o]=M.useState(""),c=u=>{if(u==="custom"){r(!0);return}r(!1),a(t.id,parseInt(u))},i=u=>{const h=u.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:((m=(d=t.config)==null?void 0:d.rowLimit)==null?void 0:m.toString())||"100",onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:oi.map(u=>e.jsx(s.SelectItem,{value:u.value,children:u.label},u.value))})]})})}function ci({isOpen:t,onClose:a}){const n=Kt(a,{enabled:t}),r=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.url)||""}),l=s.useEditorStore(u=>u.card),o=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.pluginChartType)||""}),c=s.useEditorStore(u=>{var h;return((h=u.card.customCardPreferences)==null?void 0:h.settings)||{}}),{data:i}=s.useDashboardCardQuery(l),{getCard:d}=s.useCustomVisual(r),m=M.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:m&&e.jsx(M.Suspense,{fallback:e.jsx("div",{children:"Loading chart settings..."}),children:e.jsx(m,{chartData:(i==null?void 0:i.records)||[],chartType:o,settings:c})})})]})})}function di({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:l,onClear:o,onAdvancedToggle:c,onFiltersClick:i,filterCount:d,activeCard:m,columns:u,columnsLoading:h,columnsError:x}){var L;const f=s.useEditorStore(A=>A.card);s.useEditorStore(A=>A.frame);const j=s.useDashboardStore(A=>A.filterValues),{updateCardConfig:p,setCard:y,updateCardInFrame:g}=s.useEditorActions(),C=s.useEditorStore(A=>A.showAIDialog),[E,B]=M.useState(!1),S=s.useEditorStore(A=>{var O;return((O=A.card.customCardPreferences)==null?void 0:O.url)&&A.card.type==="custom"}),{data:N,errorMessage:v,isPending:I,isLoading:D,isFetching:R,pagination:w}=s.useDashboardCardQuery(m),F=(A,O)=>{const z={...m,paginationConfig:{page:A+1,pageSize:O}};y(z),g(z)};function k(){return e.jsx("div",{className:"border-b border-border bg-background p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Active Card Config"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(f.config||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Dashboard Filters"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(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(m.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",u.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:h?"Loading...":x?"Error loading columns":JSON.stringify(u.slice(0,5),null,2)})]})]})})}const T=A=>{if(!f.config)return;if(!A.length){p(f.id,{...f.config,sortByColumns:[]});return}const O=f.config,z=A.map(({id:_,desc:Q})=>{var H,U;const W=(H=O.metricColumns)==null?void 0:H.find(P=>P.label===_),$=(U=O.groupByColumns)==null?void 0:U.find(P=>P.label===_),q=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:Q?"desc":"asc"}:null}).filter(_=>_!==null);p(f.id,{...O,sortByColumns:z})},b=M.useMemo(()=>{var A,O;return(O=(A=f.config)==null?void 0:A.sortByColumns)==null?void 0:O.map(z=>({id:z.label,desc:z.direction==="desc"}))},[(L=f.config)==null?void 0:L.sortByColumns]);return e.jsxs("div",{className:"relative flex w-0 grow flex-col",children:[e.jsx(ri,{showDebug:n,onDebugToggle:r,onAccept:l,onClear:o,onAdvancedToggle:c,onFiltersClick:i,filterCount:d}),n&&k(),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"&&C&&e.jsx(gn,{variant:"outline"}),e.jsx(li,{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(ii,{})}),C&&e.jsx(hs,{})]}),e.jsx("div",{className:s.cn("flex grow items-center justify-end"),children:t==="chart"&&e.jsx(jn,{})})]}),!E&&S&&e.jsx(s.IconButton,{"aria-label":"Open Chart Settings",tooltip:"Open Chart Settings",onClick:()=>B(!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(Ra,{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(yn,{})}),t==="table"&&(N==null?void 0:N.records)&&e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:m,data:(N==null?void 0:N.records)||[],paginationMetadata:w,onPaginationChange:F,isLoading:D||R,onSortChange:T,sortState:b})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md bg-background",children:[(N==null?void 0:N.sql)&&e.jsx("h3",{className:"mb-3 text-sm font-medium",children:"Generated SQL Query"}),e.jsx(on,{sql:N==null?void 0:N.sql,error:v})]})})]}),e.jsx(ci,{isOpen:E,onClose:()=>B(!1)})]})]})}function ui({activeField:t}){const[a,n]=M.useState(!0);return M.useEffect(()=>{t&&n(!0)},[t]),t?e.jsxs("div",{className:`flex max-w-[300px] items-center gap-2 rounded-lg border border-blue-500 bg-background p-2 shadow-lg transition-all duration-200 ${a?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(s.GripVertical,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Ln,{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 mi=()=>{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 hi(){var $,q;const[t,a]=M.useState("chart"),[n,r]=M.useState(!1),[l,o]=M.useState(!1),[c,i]=M.useState(!0),d=s.useEditorStore(H=>H.showAIDialog),m=s.useDashboardStore(H=>H.isVisualEditing),{setCardType:u}=s.useEditorActions(),h=s.useEditorStore(H=>H.card.type);M.useEffect(()=>mi(),[]);const x=()=>{console.log("Accept clicked - would save/apply current configuration")},f=()=>{console.log("Clear clicked - would reset all configurations")},j=()=>{console.log("Advanced mode toggled")},p=()=>{o(!0)},y=H=>{u(H)},g=s.useEditorStore(H=>H.frame),C=s.useEditorStore(H=>H.card);s.useEditorStore(H=>H.activeTabCardId),s.useEditorStore(H=>H.actions.getAvailableFields);const{addCard:E,removeCard:B,updateCard:S,setActiveCard:N,updateFilters:v}=s.useEditorActions(),{columns:I=[],isLoading:D,error:R}=s.useColumns(),w=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),F=C,{getFieldsForContainer:k,setFieldsForContainer:T}=Zs(F),{activeField:b,handleDragStart:L,handleDragEnd:A}=ai({activeCardId:g.activeCardId,sourceFields:I,getFieldsForContainer:k,setFieldsForContainer:T}),O=(H,U)=>{U&&v(H,U)},z=H=>{var U;S(H,{config:{...(U=g.cards.find(P=>P.id===H))==null?void 0:U.config,filters:void 0}})},_=I,Q=H=>{if(!H)return 0;let U=H.conditions.length;return H.groups.forEach(P=>{U+=Q(P)}),U},W=Q((($=F==null?void 0:F.config)==null?void 0:$.filters)||null);return e.jsxs(s.DndContext,{sensors:w,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:A,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(Ao,{isVisible:c,onToggleVisibility:()=>i(!c)}),e.jsxs("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:[!d&&e.jsx(_o,{selectedChart:h,onChartChange:y,groupByFields:k("groupBy"),pivotByFields:k("pivotBy"),metricsFields:k("metrics"),sortByFields:k("sortBy")}),e.jsx(di,{selectedChart:h,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:x,onClear:f,onAdvancedToggle:j,onFiltersClick:p,filterCount:W,activeCard:F,dataSourceState:C.dataSource||s.EMPTY_DATA_SOURCE,columns:I,columnsLoading:D,columnsError:R,getFieldsForContainer:k,cards:g.cards,activeCardId:g.activeCardId,addCard:E,setActiveCard:N})]}),!c&&m&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>i(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),F&&e.jsx(ni,{cardId:F.id,filters:((q=F.config)==null?void 0:q.filters)||null,onFiltersChange:O,onClearFilters:z,availableFields:_,isOpen:l,onOpenChange:o}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(ui,{activeField:b||null})})]})}function xi({authToken:t,onSave:a,onClose:n}){const r=M.useRef(null),l=s.useEditorStore(C=>C.showAIDialog),o=s.useEditorStore(C=>C.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:m}=s.useEditorActions(),{handleDragOver:u,handleDragEnd:h,handleDragStart:x,handleDragCancel:f,sensors:j}=Qr();M.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),M.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),M.useEffect(()=>{var C,E;l?((C=r.current)==null||C.resize(40),i(!0)):(i(!1),(E=r.current)==null||E.resize(0))},[l,i]);function p(C){C<1?i(!1):l||i(!0)}function y(){return e.jsxs(e.Fragment,{children:[e.jsx(rn,{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(fo,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(Nt,{})})]})]})}function g(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(hi,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(Nt,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:o?e.jsx(s.DndContext,{sensors:j,onDragStart:x,onDragEnd:h,onDragOver:u,onDragCancel:f,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:y()})}):g()})}function pi(){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(xi,{onSave:l,onClose:o})})}function fi(){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}=Cn();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(Us,{column:o}),e.jsx("span",{children:o.column_name})]})},o.column_name)})})}function gi(){s.useDashboardStore(a=>a.showFilters);const t=s.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(rn,{type:"filter",ColumnsComponent:()=>e.jsx(fi,{})})})]})}function ji(){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 yi(){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(ji,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(gi,{})})]})}function vi(){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 bi({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(vi,{}),e.jsxs("main",{className:"relative flex h-full w-full flex-col",children:[t&&e.jsx(qr,{}),e.jsxs(s.DashboardPanel,{...n,children:[e.jsx(pi,{}),e.jsx(yi,{})]})]})]})]})})}exports.DashboardPlus=bi;exports.ResourceManagementPanel=nn;exports.ScheduleDashboard=Vt;exports.SelectComponent=Ve;exports.cleanCard=Ft;exports.downloadPdf=zt;exports.getDashbaordStateWithoutData=as;
|