react-semaphor 0.0.422 → 0.0.423
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/{index-B83SwU1c.js → index-BVBbWA3V.js} +78 -78
- package/dist/chunks/{index-CLv0skGQ.js → index-DLAi6G9R.js} +65 -33
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +80 -70
- package/dist/index.js +2513 -2354
- package/dist/style.css +1 -1
- package/dist/types/dashboard.d.ts +15 -11
- package/dist/types/main.d.ts +22 -11
- package/dist/types/surfboard.d.ts +15 -11
- package/dist/types/types.d.ts +15 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,342 +1,352 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-BVBbWA3V.js"),e=require("react/jsx-runtime"),k=require("react");require("react-dom");function Qt(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const de=Qt(k);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
5
5
|
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/const
|
|
6
|
+
*/const Jt=t.createLucideIcon("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
7
7
|
* @license lucide-react v0.453.0 - ISC
|
|
8
8
|
*
|
|
9
9
|
* This source code is licensed under the ISC license.
|
|
10
10
|
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
-
*/const
|
|
11
|
+
*/const Kt=t.createLucideIcon("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
12
12
|
* @license lucide-react v0.453.0 - ISC
|
|
13
13
|
*
|
|
14
14
|
* This source code is licensed under the ISC license.
|
|
15
15
|
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
-
*/const
|
|
16
|
+
*/const Wt=t.createLucideIcon("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
17
17
|
* @license lucide-react v0.453.0 - ISC
|
|
18
18
|
*
|
|
19
19
|
* This source code is licensed under the ISC license.
|
|
20
20
|
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
-
*/const
|
|
21
|
+
*/const Yt=t.createLucideIcon("ArrowDownToLine",[["path",{d:"M12 17V3",key:"1cwfxf"}],["path",{d:"m6 11 6 6 6-6",key:"12ii2o"}],["path",{d:"M19 21H5",key:"150jfl"}]]);/**
|
|
22
22
|
* @license lucide-react v0.453.0 - ISC
|
|
23
23
|
*
|
|
24
24
|
* This source code is licensed under the ISC license.
|
|
25
25
|
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
-
*/const
|
|
26
|
+
*/const Xt=t.createLucideIcon("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
|
|
27
27
|
* @license lucide-react v0.453.0 - ISC
|
|
28
28
|
*
|
|
29
29
|
* This source code is licensed under the ISC license.
|
|
30
30
|
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
-
*/const
|
|
31
|
+
*/const Zt=t.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
32
|
* @license lucide-react v0.453.0 - ISC
|
|
33
33
|
*
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
-
*/const
|
|
36
|
+
*/const es=t.createLucideIcon("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
37
37
|
* @license lucide-react v0.453.0 - ISC
|
|
38
38
|
*
|
|
39
39
|
* This source code is licensed under the ISC license.
|
|
40
40
|
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
-
*/const
|
|
41
|
+
*/const ts=t.createLucideIcon("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
|
|
42
42
|
* @license lucide-react v0.453.0 - ISC
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the ISC license.
|
|
45
45
|
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const
|
|
46
|
+
*/const ss=t.createLucideIcon("ArrowUpToLine",[["path",{d:"M5 3h14",key:"7usisc"}],["path",{d:"m18 13-6-6-6 6",key:"1kf1n9"}],["path",{d:"M12 7v14",key:"1akyts"}]]);/**
|
|
47
47
|
* @license lucide-react v0.453.0 - ISC
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the ISC license.
|
|
50
50
|
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/const
|
|
51
|
+
*/const ns=t.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"}]]);/**
|
|
52
52
|
* @license lucide-react v0.453.0 - ISC
|
|
53
53
|
*
|
|
54
54
|
* This source code is licensed under the ISC license.
|
|
55
55
|
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
-
*/const
|
|
56
|
+
*/const as=t.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"}]]);/**
|
|
57
57
|
* @license lucide-react v0.453.0 - ISC
|
|
58
58
|
*
|
|
59
59
|
* This source code is licensed under the ISC license.
|
|
60
60
|
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
-
*/const
|
|
61
|
+
*/const rs=t.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"}]]);/**
|
|
62
62
|
* @license lucide-react v0.453.0 - ISC
|
|
63
63
|
*
|
|
64
64
|
* This source code is licensed under the ISC license.
|
|
65
65
|
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
-
*/const
|
|
66
|
+
*/const os=t.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"}]]);/**
|
|
67
67
|
* @license lucide-react v0.453.0 - ISC
|
|
68
68
|
*
|
|
69
69
|
* This source code is licensed under the ISC license.
|
|
70
70
|
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
-
*/const
|
|
71
|
+
*/const is=t.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"}]]);/**
|
|
72
72
|
* @license lucide-react v0.453.0 - ISC
|
|
73
73
|
*
|
|
74
74
|
* This source code is licensed under the ISC license.
|
|
75
75
|
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
-
*/const
|
|
76
|
+
*/const ls=t.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"}]]);/**
|
|
77
77
|
* @license lucide-react v0.453.0 - ISC
|
|
78
78
|
*
|
|
79
79
|
* This source code is licensed under the ISC license.
|
|
80
80
|
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
-
*/const Ve=
|
|
81
|
+
*/const Ve=t.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"}]]);/**
|
|
82
82
|
* @license lucide-react v0.453.0 - ISC
|
|
83
83
|
*
|
|
84
84
|
* This source code is licensed under the ISC license.
|
|
85
85
|
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
-
*/const
|
|
86
|
+
*/const nt=t.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"}]]);/**
|
|
87
87
|
* @license lucide-react v0.453.0 - ISC
|
|
88
88
|
*
|
|
89
89
|
* This source code is licensed under the ISC license.
|
|
90
90
|
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
-
*/const
|
|
91
|
+
*/const Be=t.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"}]]);/**
|
|
92
92
|
* @license lucide-react v0.453.0 - ISC
|
|
93
93
|
*
|
|
94
94
|
* This source code is licensed under the ISC license.
|
|
95
95
|
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
-
*/const
|
|
96
|
+
*/const at=t.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
97
97
|
* @license lucide-react v0.453.0 - ISC
|
|
98
98
|
*
|
|
99
99
|
* This source code is licensed under the ISC license.
|
|
100
100
|
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
-
*/const
|
|
101
|
+
*/const rt=t.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"}]]);/**
|
|
102
102
|
* @license lucide-react v0.453.0 - ISC
|
|
103
103
|
*
|
|
104
104
|
* This source code is licensed under the ISC license.
|
|
105
105
|
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
-
*/const
|
|
106
|
+
*/const ot=t.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"}]]);/**
|
|
107
107
|
* @license lucide-react v0.453.0 - ISC
|
|
108
108
|
*
|
|
109
109
|
* This source code is licensed under the ISC license.
|
|
110
110
|
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
-
*/const
|
|
111
|
+
*/const cs=t.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"}]]);/**
|
|
112
112
|
* @license lucide-react v0.453.0 - ISC
|
|
113
113
|
*
|
|
114
114
|
* This source code is licensed under the ISC license.
|
|
115
115
|
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
-
*/const
|
|
116
|
+
*/const it=t.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"}]]);/**
|
|
117
117
|
* @license lucide-react v0.453.0 - ISC
|
|
118
118
|
*
|
|
119
119
|
* This source code is licensed under the ISC license.
|
|
120
120
|
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const
|
|
121
|
+
*/const ds=t.createLucideIcon("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/**
|
|
122
122
|
* @license lucide-react v0.453.0 - ISC
|
|
123
123
|
*
|
|
124
124
|
* This source code is licensed under the ISC license.
|
|
125
125
|
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const
|
|
126
|
+
*/const us=t.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"}]]);/**
|
|
127
127
|
* @license lucide-react v0.453.0 - ISC
|
|
128
128
|
*
|
|
129
129
|
* This source code is licensed under the ISC license.
|
|
130
130
|
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const
|
|
131
|
+
*/const ms=t.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"}]]);/**
|
|
132
132
|
* @license lucide-react v0.453.0 - ISC
|
|
133
133
|
*
|
|
134
134
|
* This source code is licensed under the ISC license.
|
|
135
135
|
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const
|
|
136
|
+
*/const hs=t.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"}]]);/**
|
|
137
137
|
* @license lucide-react v0.453.0 - ISC
|
|
138
138
|
*
|
|
139
139
|
* This source code is licensed under the ISC license.
|
|
140
140
|
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const
|
|
141
|
+
*/const ps=t.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
|
|
142
142
|
* @license lucide-react v0.453.0 - ISC
|
|
143
143
|
*
|
|
144
144
|
* This source code is licensed under the ISC license.
|
|
145
145
|
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
-
*/const
|
|
146
|
+
*/const lt=t.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"}]]);/**
|
|
147
147
|
* @license lucide-react v0.453.0 - ISC
|
|
148
148
|
*
|
|
149
149
|
* This source code is licensed under the ISC license.
|
|
150
150
|
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
-
*/const
|
|
151
|
+
*/const ct=t.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
|
|
152
152
|
* @license lucide-react v0.453.0 - ISC
|
|
153
153
|
*
|
|
154
154
|
* This source code is licensed under the ISC license.
|
|
155
155
|
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
-
*/const
|
|
156
|
+
*/const xs=t.createLucideIcon("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);/**
|
|
157
157
|
* @license lucide-react v0.453.0 - ISC
|
|
158
158
|
*
|
|
159
159
|
* This source code is licensed under the ISC license.
|
|
160
160
|
* See the LICENSE file in the root directory of this source tree.
|
|
161
|
-
*/const
|
|
161
|
+
*/const fs=t.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"}]]);/**
|
|
162
162
|
* @license lucide-react v0.453.0 - ISC
|
|
163
163
|
*
|
|
164
164
|
* This source code is licensed under the ISC license.
|
|
165
165
|
* See the LICENSE file in the root directory of this source tree.
|
|
166
|
-
*/const
|
|
166
|
+
*/const gs=t.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"}]]);/**
|
|
167
167
|
* @license lucide-react v0.453.0 - ISC
|
|
168
168
|
*
|
|
169
169
|
* This source code is licensed under the ISC license.
|
|
170
170
|
* See the LICENSE file in the root directory of this source tree.
|
|
171
|
-
*/const
|
|
171
|
+
*/const dt=t.createLucideIcon("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
|
|
172
172
|
* @license lucide-react v0.453.0 - ISC
|
|
173
173
|
*
|
|
174
174
|
* This source code is licensed under the ISC license.
|
|
175
175
|
* See the LICENSE file in the root directory of this source tree.
|
|
176
|
-
*/const
|
|
176
|
+
*/const js=t.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"}]]);/**
|
|
177
177
|
* @license lucide-react v0.453.0 - ISC
|
|
178
178
|
*
|
|
179
179
|
* This source code is licensed under the ISC license.
|
|
180
180
|
* See the LICENSE file in the root directory of this source tree.
|
|
181
|
-
*/const
|
|
181
|
+
*/const ys=t.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"}]]);/**
|
|
182
182
|
* @license lucide-react v0.453.0 - ISC
|
|
183
183
|
*
|
|
184
184
|
* This source code is licensed under the ISC license.
|
|
185
185
|
* See the LICENSE file in the root directory of this source tree.
|
|
186
|
-
*/const
|
|
186
|
+
*/const bs=t.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"}]]);/**
|
|
187
187
|
* @license lucide-react v0.453.0 - ISC
|
|
188
188
|
*
|
|
189
189
|
* This source code is licensed under the ISC license.
|
|
190
190
|
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
-
*/const
|
|
191
|
+
*/const Ss=t.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"}]]);/**
|
|
192
192
|
* @license lucide-react v0.453.0 - ISC
|
|
193
193
|
*
|
|
194
194
|
* This source code is licensed under the ISC license.
|
|
195
195
|
* See the LICENSE file in the root directory of this source tree.
|
|
196
|
-
*/const
|
|
196
|
+
*/const ut=t.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"}]]);/**
|
|
197
197
|
* @license lucide-react v0.453.0 - ISC
|
|
198
198
|
*
|
|
199
199
|
* This source code is licensed under the ISC license.
|
|
200
200
|
* See the LICENSE file in the root directory of this source tree.
|
|
201
|
-
*/const
|
|
201
|
+
*/const Cs=t.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
|
|
202
202
|
* @license lucide-react v0.453.0 - ISC
|
|
203
203
|
*
|
|
204
204
|
* This source code is licensed under the ISC license.
|
|
205
205
|
* See the LICENSE file in the root directory of this source tree.
|
|
206
|
-
*/const
|
|
206
|
+
*/const vs=t.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"}]]);/**
|
|
207
207
|
* @license lucide-react v0.453.0 - ISC
|
|
208
208
|
*
|
|
209
209
|
* This source code is licensed under the ISC license.
|
|
210
210
|
* See the LICENSE file in the root directory of this source tree.
|
|
211
|
-
*/const
|
|
211
|
+
*/const Ns=t.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"}]]);/**
|
|
212
212
|
* @license lucide-react v0.453.0 - ISC
|
|
213
213
|
*
|
|
214
214
|
* This source code is licensed under the ISC license.
|
|
215
215
|
* See the LICENSE file in the root directory of this source tree.
|
|
216
|
-
*/const
|
|
216
|
+
*/const ws=t.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"}]]);/**
|
|
217
217
|
* @license lucide-react v0.453.0 - ISC
|
|
218
218
|
*
|
|
219
219
|
* This source code is licensed under the ISC license.
|
|
220
220
|
* See the LICENSE file in the root directory of this source tree.
|
|
221
|
-
*/const
|
|
221
|
+
*/const ks=t.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"}]]);/**
|
|
222
222
|
* @license lucide-react v0.453.0 - ISC
|
|
223
223
|
*
|
|
224
224
|
* This source code is licensed under the ISC license.
|
|
225
225
|
* See the LICENSE file in the root directory of this source tree.
|
|
226
|
-
*/const
|
|
226
|
+
*/const re=t.createLucideIcon("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
227
227
|
* @license lucide-react v0.453.0 - ISC
|
|
228
228
|
*
|
|
229
229
|
* This source code is licensed under the ISC license.
|
|
230
230
|
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
-
*/const
|
|
231
|
+
*/const Is=t.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"}]]);/**
|
|
232
232
|
* @license lucide-react v0.453.0 - ISC
|
|
233
233
|
*
|
|
234
234
|
* This source code is licensed under the ISC license.
|
|
235
235
|
* See the LICENSE file in the root directory of this source tree.
|
|
236
|
-
*/const
|
|
236
|
+
*/const Ds=t.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"}]]);/**
|
|
237
237
|
* @license lucide-react v0.453.0 - ISC
|
|
238
238
|
*
|
|
239
239
|
* This source code is licensed under the ISC license.
|
|
240
240
|
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
-
*/const
|
|
241
|
+
*/const mt=t.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"}]]);/**
|
|
242
242
|
* @license lucide-react v0.453.0 - ISC
|
|
243
243
|
*
|
|
244
244
|
* This source code is licensed under the ISC license.
|
|
245
245
|
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
-
*/const
|
|
246
|
+
*/const Es=t.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"}]]);/**
|
|
247
247
|
* @license lucide-react v0.453.0 - ISC
|
|
248
248
|
*
|
|
249
249
|
* This source code is licensed under the ISC license.
|
|
250
250
|
* See the LICENSE file in the root directory of this source tree.
|
|
251
|
-
*/const
|
|
251
|
+
*/const Ts=t.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"}]]);/**
|
|
252
252
|
* @license lucide-react v0.453.0 - ISC
|
|
253
253
|
*
|
|
254
254
|
* This source code is licensed under the ISC license.
|
|
255
255
|
* See the LICENSE file in the root directory of this source tree.
|
|
256
|
-
*/const
|
|
256
|
+
*/const As=t.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"}]]);/**
|
|
257
257
|
* @license lucide-react v0.453.0 - ISC
|
|
258
258
|
*
|
|
259
259
|
* This source code is licensed under the ISC license.
|
|
260
260
|
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
-
*/const
|
|
261
|
+
*/const Ms=t.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"}]]);/**
|
|
262
262
|
* @license lucide-react v0.453.0 - ISC
|
|
263
263
|
*
|
|
264
264
|
* This source code is licensed under the ISC license.
|
|
265
265
|
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
-
*/const
|
|
266
|
+
*/const Ls=t.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"}]]);/**
|
|
267
267
|
* @license lucide-react v0.453.0 - ISC
|
|
268
268
|
*
|
|
269
269
|
* This source code is licensed under the ISC license.
|
|
270
270
|
* See the LICENSE file in the root directory of this source tree.
|
|
271
|
-
*/const
|
|
271
|
+
*/const ht=t.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"}]]);/**
|
|
272
272
|
* @license lucide-react v0.453.0 - ISC
|
|
273
273
|
*
|
|
274
274
|
* This source code is licensed under the ISC license.
|
|
275
275
|
* See the LICENSE file in the root directory of this source tree.
|
|
276
|
-
*/const
|
|
276
|
+
*/const pt=t.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"}]]);/**
|
|
277
277
|
* @license lucide-react v0.453.0 - ISC
|
|
278
278
|
*
|
|
279
279
|
* This source code is licensed under the ISC license.
|
|
280
280
|
* See the LICENSE file in the root directory of this source tree.
|
|
281
|
-
*/const
|
|
281
|
+
*/const Os=t.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"}]]);/**
|
|
282
282
|
* @license lucide-react v0.453.0 - ISC
|
|
283
283
|
*
|
|
284
284
|
* This source code is licensed under the ISC license.
|
|
285
285
|
* See the LICENSE file in the root directory of this source tree.
|
|
286
|
-
*/const
|
|
286
|
+
*/const zs=t.createLucideIcon("Ruler",[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]]);/**
|
|
287
287
|
* @license lucide-react v0.453.0 - ISC
|
|
288
288
|
*
|
|
289
289
|
* This source code is licensed under the ISC license.
|
|
290
290
|
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
-
*/const
|
|
291
|
+
*/const Fs=t.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"}]]);/**
|
|
292
292
|
* @license lucide-react v0.453.0 - ISC
|
|
293
293
|
*
|
|
294
294
|
* This source code is licensed under the ISC license.
|
|
295
295
|
* See the LICENSE file in the root directory of this source tree.
|
|
296
|
-
*/const
|
|
296
|
+
*/const xt=t.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"}]]);/**
|
|
297
297
|
* @license lucide-react v0.453.0 - ISC
|
|
298
298
|
*
|
|
299
299
|
* This source code is licensed under the ISC license.
|
|
300
300
|
* See the LICENSE file in the root directory of this source tree.
|
|
301
|
-
*/const
|
|
301
|
+
*/const Rs=t.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
|
|
302
302
|
* @license lucide-react v0.453.0 - ISC
|
|
303
303
|
*
|
|
304
304
|
* This source code is licensed under the ISC license.
|
|
305
305
|
* See the LICENSE file in the root directory of this source tree.
|
|
306
|
-
*/const
|
|
306
|
+
*/const ft=t.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"}]]);/**
|
|
307
307
|
* @license lucide-react v0.453.0 - ISC
|
|
308
308
|
*
|
|
309
309
|
* This source code is licensed under the ISC license.
|
|
310
310
|
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
-
*/const
|
|
311
|
+
*/const _s=t.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
312
312
|
* @license lucide-react v0.453.0 - ISC
|
|
313
313
|
*
|
|
314
314
|
* This source code is licensed under the ISC license.
|
|
315
315
|
* See the LICENSE file in the root directory of this source tree.
|
|
316
|
-
*/const
|
|
316
|
+
*/const qe=t.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"}]]);/**
|
|
317
317
|
* @license lucide-react v0.453.0 - ISC
|
|
318
318
|
*
|
|
319
319
|
* This source code is licensed under the ISC license.
|
|
320
320
|
* See the LICENSE file in the root directory of this source tree.
|
|
321
|
-
*/const
|
|
321
|
+
*/const Vs=t.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"}]]);/**
|
|
322
322
|
* @license lucide-react v0.453.0 - ISC
|
|
323
323
|
*
|
|
324
324
|
* This source code is licensed under the ISC license.
|
|
325
325
|
* See the LICENSE file in the root directory of this source tree.
|
|
326
|
-
*/const
|
|
326
|
+
*/const Bs=t.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"}]]);/**
|
|
327
327
|
* @license lucide-react v0.453.0 - ISC
|
|
328
328
|
*
|
|
329
329
|
* This source code is licensed under the ISC license.
|
|
330
330
|
* See the LICENSE file in the root directory of this source tree.
|
|
331
|
-
*/const js=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"}]]);function Pe(t){var a;return{...t,sheets:(a=t==null?void 0:t.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>ys(i))}})}})}}function ys(t){return{...t,customCfg:Bt(t.customCfg),data:[]}}function Bt(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 Vt(t,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:n,operation:"create"})}async function Me(t,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:l,shared:i}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function qt(t,a){return a?await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:t}):null}function Pt(){const[t,a]=I.useState(""),[n,r]=I.useState(!1),o=s.useDashboardStore(h=>h.lenses),{setLenses:l,setSelectedLensId:i}=s.useDashboardActions(),[d,m]=I.useState(!1),[p,u]=I.useState(!1),x=s.useDashboardStore(h=>h.dashboard),f=s.useDashboardStore(h=>h.filterValues),{authToken:c}=s.useSemaphorContext();async function y(){m(!0);const h=Pe(x),C=await Vt(t,h,f,c==null?void 0:c.accessToken);C&&(l([...o||[],C]),i(C.id),u(!1)),m(!1)}return e.jsxs(s.Dialog,{open:p,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:h=>{a(h.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:y,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Ht(){const[t,a]=I.useState(!1),n=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=s.useDashboardActions(),{authToken:i}=s.useSemaphorContext();async function d(u){l(u)}async function m(u){if(await qt(u,i==null?void 0:i.accessToken)){const f=n==null?void 0:n.filter(c=>c.id!==u);o(f||[]),l("original")}}async function p(u){const x=n==null?void 0:n.map(y=>y.id===u.id?{...y,isDefault:!u.isDefault}:{...y,isDefault:!1});o(x||[]);const f={...u,isDefault:!u.isDefault};await Me(f,i==null?void 0:i.accessToken);const c=n==null?void 0:n.find(y=>y.isDefault);if(c&&c.id!==u.id){const y={...c,isDefault:!1};await Me(y,i==null?void 0:i.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(ft,{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:d,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(yt,{onClick:x=>{x.preventDefault(),p(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:x=>{x.preventDefault(),m(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 bs(){var l;const t=s.useDashboardStore.getState().authToken,a=s.useDashboardStore.getState().theme,n=s.useDashboardStore.getState().filterValues,r=(l=s.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function Ss(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:l}=bs();if(t)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,x=document.createElement("a");x.href=u;const f=`${o}-${new Date().toISOString()}.pdf`;x.download=f,x.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Gt({iconClassName:t}){const{authToken:a}=s.useSemaphorContext();s.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const n=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ss()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(re,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function Y({defaultValue:t,label:a,options:n,value:r,onValueChange:o,className:l,icon:i}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:o,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",l),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("div",{className:"mr-2",children: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 We=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Cs({triggerButtonClassName:t}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:l,isDeleting:i}=Ut(),[d,m]=I.useState(""),[p,u]=I.useState(We[0].value),[x,f]=I.useState("06:00"),[c,y]=I.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(it,{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:d,onChange:h=>m(h.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:c,onChange:h=>{y(h.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(Y,{className:"col-span-2 h-8",label:"Select Frequency",options:We,value:p,onValueChange:h=>u(h)})]}),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:x,onChange:h=>f(h.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:d,frequency:p,time:x,subject:c}),f("00:00"),m(""),y("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(re,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(is,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:l})})]}),"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(h=>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(h.frequency)," "]}),e.jsx(s.Label,{children:h.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Ye,{tooltip:`Next Run: ${new Date(h.nextRun).toLocaleString()} ${h.timezone}`,children:e.jsx(ot,{className:"size-3.5"})}),e.jsx(Ye,{tooltip:`${h.endUserEmail}`,children:e.jsx(wt,{className:"size-3.5"})}),i===h.id?e.jsx(re,{className:"size-3.5 animate-spin"}):e.jsx(_t,{onClick:()=>r(h.id),className:"size-3.5 cursor-pointer"})]})]},h.id))})]})]})]})})]})})}const Ye=({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 Ut(){const[t,a]=I.useState("idle"),[n,r]=I.useState(""),[o,l]=I.useState(null),i=s.useDashboardStore(D=>D.authToken),d=s.useDashboardStore(D=>D.dashboard.id),m=s.useDashboardStore(D=>D.dashboard.title),{endUserId:p}=s.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",x={dashboardId:d,endUserId:p},{data:f,isLoading:c,isError:y,isFetching:h,refetch:C}=s.useQuery({queryKey:["subscriptions",d,p],queryFn:()=>s.getRequest(u,(i==null?void 0:i.accessToken)||"",x),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!p});async function v({email:D,subject:L,frequency:k,time:A}){const{authToken:B,...R}=bs(),G=Intl.DateTimeFormat().resolvedOptions().timeZone,g={email:D,frequency:k,time:A,timezone:G,endUserId:p,endUserEmail:D,subject:L||m||"Scheduled Dashboard",dashboardId:d,dashboardParams:R};a("loading");const N="https://semaphor.cloud/api/v1/subscriptions/create";try{const T=await s.postRequestRegular(N,(B==null?void 0:B.accessToken)||"",{...g});a("success"),r(""),C(),setTimeout(()=>{a("idle")},2e3)}catch(T){console.error(T),a("error"),r(T.message)}}async function M(D){const L="https://semaphor.cloud/api/v1/subscriptions/delete";l(D);try{await s.postRequestRegular(L,(i==null?void 0:i.accessToken)||"",{id:D}),C(),setTimeout(()=>{l(null)},2e3)}catch(k){console.error(k),l(null),a("error"),r(k.message)}}return{data:f,isLoading:c,isFetching:h,isError:y,isDeleting:o,refetch:C,handleScheduleSubscription:v,handleDeleteSubscription:M,status:t,error:n}}function $t(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(g=>g.theme);const a=s.useDashboardStore(g=>g.lenses),n=s.useDashboardStore(g=>g.selectedLensId),r=a==null?void 0:a.find(g=>g.id===n),o=s.useDashboardStore(g=>g.dashboard);s.useDashboardStore(g=>g.selectedSheetId);const l=s.useDashboardStore(g=>g.isDashboardEditing),i=s.useEditorStore(g=>g.selectedConnectionId),[d,m]=I.useState(!1),p=s.useDashboardStore(g=>g.filterValues),u=s.useDashboardStore(g=>g.isVisualEditing),x=s.useDashboardStore(g=>g.showFilters);s.useDashboardStore(g=>g.showDashboardJSON);const f=s.useDashboardStore(g=>g.onSaveFunction),c=s.useDashboardStore(g=>g.actions.setShowFilters),{addFrame:y,setSelectedFrameId:h}=s.useDashboardStore(g=>g.actions),{getSelectedSheet:C,setIsDashboardEditing:v,setShowDashboardJSON:M}=s.useDashboardStore(g=>g.actions),D=C(),{tenantId:L,endUserId:k}=I.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),A=I.useMemo(()=>L||k,[L,k]),B=()=>{if(!l||!D)return;const g={connectionId:i,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},N={id:s.v4(),cards:[g],activeCardId:g.id};y(D.id,N),h(N.id)},R=()=>{v(!0)};async function G(){if(m(!0),!n||!r)return;const g=Pe(o),N=JSON.stringify(g),T={...r,template:N,filterValues:p};await Me(T,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),f==null||f(g),m(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!u&&e.jsx(Gt,{}),!u&&e.jsx(Cs,{}),l&&!u&&A&&e.jsx(Pt,{}),!u&&A&&e.jsx(Ht,{}),l&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:B,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!l&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:R,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4"})}),l&&!u&&e.jsx(s.IconButton,{className:"h-7 p-2",onClick:()=>{v(!1),M(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),l&&!u&&A&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:G,size:"sm",children:e.jsx(Lt,{className:"h-4 w-4"})}),!x&&!u&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsx(ds,{className:"h-4 w-4"})}),!u&&l&&!1,!u&&!1]})]})}function Qt({name:t,items:a,value:n,onChange:r,isLoading:o,isError:l,refetch:i,className:d,icon:m,showNone:p=!1}){const u=de.useRef(null),[x,f]=de.useState(!1),[c,y]=de.useState("100%"),h=p?[...a||[],{id:"none",name:"None"}]:a;de.useLayoutEffect(()=>{u.current&&y(u.current.offsetWidth)},[]);function C(){var M;return o?"Loading...":l?"Error":n?(M=a==null?void 0:a.find(D=>D.id===n))==null?void 0:M.name:`Select ${t}`}function v(M,D){r(D),f(!1)}return e.jsxs(s.Popover,{open:x,onOpenChange:f,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:u,variant:"outline",role:"combobox","aria-expanded":x,className:s.cn("flex h-9 w-full justify-between",d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsx("div",{className:"mr-2",children:m}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:C()})]}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:c},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:i,children:e.jsx(ps,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:h==null?void 0:h.map(M=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:M.name,onSelect:D=>v(D,M.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",n===M.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:M.name,children:M.name})]})},M.id))})]})]})})]})}function le({title:t,items:a,value:n,isLoading:r,isError:o,refetch:l,onChange:i,showNone:d=!1,className:m,disabled:p=!1,type:u="combobox"}){const x=r?"Loading...":o?"Error":n;function f(){if(t==="Connection")return e.jsx(Tt,{className:"size-4"});if(t==="Database")return e.jsx(ut,{className:"size-4"});if(t==="Schema")return e.jsx(Et,{className:"size-4"});if(t==="Table")return e.jsx(qe,{className:"size-4"});if(t==="Model")return e.jsx(nt,{className:"size-4"})}function c(){return e.jsxs(s.Select,{disabled:p,value:x,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",m),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(ps,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((h,C)=>e.jsx(s.SelectItem,{value:h.id,children:h.name},C))]}),(r||o)&&e.jsx(s.SelectItem,{value:x,children:x})]})})]})}function y(){return e.jsx(Qt,{icon:f(),items:a,value:x,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:l,name:t,showNone:d})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:u==="select"?c():y()})})}function Jt({column:t}){const[a,n]=I.useState(!1),r=s.useEditorStore(h=>h.selectedTableName),o=s.useEditorStore(h=>h.selectedSchemaName),l=s.useEditorStore(h=>h.selectedDatabaseName),i=s.useEditorStore(h=>h.selectedDatamodelId),d=s.useEditorStore(h=>h.sqlGen),{modelItems:m,connectionType:p}=ne(),u=s.useEditorStore(h=>h.actions.setSqlGen),x=s.useEditorStore(h=>h.actions.setCardSql),f=s.useEditorStore(h=>h.actions.setRunSql);function c(h,C){var L;const v=s.createSqlGenConfig(h,d,C),M=(L=m==null?void 0:m.find(k=>k.id===i))==null?void 0:L.name;u(v);const D=s.getSql(v,s.fmt(o||""),s.fmt(r),M,p,l||"");D&&(x(D),f(!0)),n(!1)}function y(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>c(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>c(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>c(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>c(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>c(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(cs,{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:y()})]})}function He({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(js,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(us,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Rt,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(at,{className:"size-3"}):e.jsx(Ot,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function ge({column:t,className:a}){return e.jsxs("div",{className:s.cn("flex h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(He,{column:t}),e.jsx("span",{children:t.column_name})]})}function Kt({id:t,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:l,transform:i}=s.useDraggable({id:t,data:{type:n}}),d=i?{translate:s.CSS.Translate.toString(i),transform:s.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:l,style:d,...o,...r,children:a})}function Wt({onClick:t,column:a}){const n=s.useDndStore(f=>f.activeId),r=s.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.groupByColumns}),o=s.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.trendByColumns}),l=s.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.metricColumns}),i=s.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.filterColumns});function d(f){return m(f)||u(f)||p(f)||x(f)}function m(f){return r==null?void 0:r.some(c=>c.name===f.column_name)}function p(f){return o==null?void 0:o.some(c=>c.name===f.column_name)}function u(f){return l==null?void 0:l.some(c=>c.name===f.column_name)}function x(f){return i==null?void 0:i.some(c=>c.name===f.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":d(a)}),children:[n===a.column_name&&e.jsx(s.DragOverlay,{children:e.jsx(ge,{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(ge,{column:a})}),e.jsx(Kt,{id:a.column_name,type:"column",children:e.jsx(ge,{column:a})})]})}function ae(t){return`${t}-${s.v4()}`}function je(t,a){return t==="SUM"?`Sum of ${a}`:t==="AVG"?`Avg of ${a}`:t==="COUNT"?`Count of ${a}`:t==="MAX"?`Max of ${a}`:t==="MIN"?`Min of ${a}`:t==="DISTINCT"?`Distinct ${a}`:a}function Yt({schemaName:t,tableName:a,columns:n,status:r}){const o=s.useEditorStore(S=>S.sqlGen),l=s.useEditorStore(S=>S.isDevMode),i=s.useEditorStore(S=>S.selectedConnectionId),d=s.useEditorStore(S=>S.selectedDatabaseName),m=s.useEditorStore(S=>S.selectedSchemaName),p=s.useEditorStore(S=>S.selectedTableName),u=s.useEditorStore(S=>S.selectedDatamodelId),x=s.useDashboardStore(S=>S.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:c}=s.useDashboardActions(),{addColumnToMetricColumns:y,addColumnToTrendByColumns:h,setCardSql:C,setRunSql:v,setSqlGen:M,setIsShowingVisual:D}=s.useEditorActions(),{connectionType:L,modelItems:k,selectedDatamodelName:A}=ne();function B(S){var q;if(l){const P=s.createSqlGenConfig(S,o);M(P);const U=(q=k==null?void 0:k.find(w=>w.id===u))==null?void 0:q.name,V=s.getSql(P,s.fmt(t),s.fmt(a),U,L,d||"");V&&(C(V),v(!0))}if(!l){if(s.isTextDataType(S.data_type)){const P={...S,role:"metric",id:ae(S.column_name),name:S.column_name,label:je("COUNT",S.column_name),type:S.data_type,aggregate:"COUNT"};y(P)}if(s.isNumberDataType(S.data_type)){const P={...S,role:"metric",id:ae(S.column_name),name:S.column_name,label:je("SUM",S.column_name),type:S.data_type,aggregate:"SUM"};y(P)}if(s.isDateDataType(S.data_type)){const P={...S,role:"trendby",id:ae(S.column_name),name:S.column_name,type:S.data_type};h(P)}}}function R(S){S===!0&&(p||A)&&i?(f({connectionId:i,connectionType:L==="S3"||L==="API"?"DuckDb":L,databaseName:d||"",schemaName:m||"",tableName:p||"",datamodelName:s.resolveDatamodelName(A),datamodelId:u||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(c({connectionId:i||"",connectionType:L||"",tableName:p||"",datamodelName:s.resolveDatamodelName(A),datamodelId:u||"",databaseName:d||"",schemaName:m||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function G(){const S=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:A,connectionType:L,databaseName:d||""});D(!1);const q=L==="MSSQL"?`SELECT top 10 * FROM ${S}`:`SELECT * FROM ${S} LIMIT 10`;C(q),v(!0)}function g(){const S=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:A,connectionType:L,databaseName:d||""});C(`SELECT COUNT(*) as count FROM ${S}`),v(!0)}function N(){return(x==null?void 0:x.find(S=>S.connectionId===i&&(S.tableName===p||S.datamodelName===A)))!==void 0}function T(S){return l?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>B(S),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(He,{column:S}),e.jsx("span",{children:S.column_name})]}),e.jsx("div",{onClick:q=>q.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(S.data_type)&&e.jsx(Jt,{column:S})})]}):e.jsx(Wt,{onClick:B,column:S})}function O(){return e.jsxs(e.Fragment,{children:[e.jsxs(s.Toggle,{title:`${N()?"Remove from":"Add to"} Assistant Scope`,pressed:N(),onPressedChange:R,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":N(),"text-muted-foreground":!N()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:G,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Nt,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:g,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(fs,{className:"mr-2 size-4"}),"Count"]})]})}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:O()}),e.jsxs(s.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted px-2 py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(S=>e.jsx("div",{className:s.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:T(S)},S.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function vs(){const t=s.useDashboardStore(d=>d.authToken),a=s.useEditorStore(d=>d.selectedConnectionId),{refetch:n,data:r,isLoading:o,isError:l}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(t==null?void 0:t.accessToken)||""),enabled:!!(t!=null&&t.accessToken)}),i=r==null?void 0:r.connections.find(d=>d.id===a);return{connectionsData:r,isConnectionsLoading:o,isConnectionsError:l,refetchConnections:n,currentConnection:i}}function Ns(){var h;const t=s.useEditorStore(C=>C.selectedConnectionId),a=s.useEditorStore(C=>C.selectedDatabaseName),n=s.useEditorStore(C=>C.selectedDatamodelId),r=s.useEditorStore(C=>C.selectedSchemaName),o=s.useEditorStore(C=>C.selectedTableName),l=s.useDashboardStore(C=>C.authToken),{currentConnection:i}=vs(),d=i==null?void 0:i.type,{data:m,isLoading:p,isFetching:u,isError:x,refetch:f}=s.useQuery({queryKey:["columns",t,a,n,r,o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(l==null?void 0:l.accessToken)||"",{connection_id:t,datamodel_id:n||"",database_name:a,schema_name:r,table_name:o}),enabled:c(d)});function c(C){return l!=null&&l.accessToken?!!(t&&a&&a!=="NA"&&r&&o||t&&(C==="S3"||C==="API")||n&&n):!1}return{columns:(h=m==null?void 0:m.columns)==null?void 0:h.map(C=>({...C,data_type:C.data_type.toLowerCase()})),isColumnsLoading:p,isColumnsFetching:u,isColumnsError:x,refetchColumns:f}}function ne(t,a){var Ue,$e,Qe,Je,Ke;const n=s.useSemaphorContext().authToken||t,r=s.useEditorStore(z=>z.selectedConnectionId),o=s.useEditorStore(z=>z.selectedDatamodelId),l=s.useEditorStore(z=>z.selectedDatabaseName),i=s.useEditorStore(z=>z.selectedSchemaName),d=s.useEditorStore(z=>z.selectedTableName),m=s.useEditorStore(z=>z.actions.setSelectedConnectionId),p=s.useEditorStore(z=>z.actions.setSelectedDatamodelId),u=s.useEditorStore(z=>z.actions.setSelectedDatabaseName),x=s.useEditorStore(z=>z.actions.setSelectedSchemaName),f=s.useEditorStore(z=>z.actions.setSelectedTableName);s.useEditorStore(z=>z.actions.setCardSql);function c(z){return r&&l&&i&&l!=="NA"?!0:r&&z==="API"?!1:!!(r&&z==="S3")}function y(z){return r&&z?!(z==="API"||z==="S3"):!1}const{refetchConnections:h,connectionsData:C,isConnectionsLoading:v,isConnectionsError:M,currentConnection:D}=vs(),{refetch:L,data:k,isLoading:A,isError:B}=s.useQuery({queryKey:["models",r],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:!!(n!=null&&n.accessToken)&&!!r}),R=D==null?void 0:D.type,G=(D==null?void 0:D.type)==="API"||(D==null?void 0:D.type)==="S3",{data:g,isLoading:N,isFetching:T,isError:O,refetch:S}=s.useQuery({queryKey:["databases",r],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:y(R)}),{data:q,isLoading:P,isFetching:U,isError:V,refetch:w}=s.useQuery({queryKey:["schemas",r,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l}),enabled:!!r&&!!l&&!G&&l!=="NA"}),{data:j,isLoading:E,isFetching:b,isError:H,refetch:_}=s.useQuery({queryKey:["tables",r,l,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l,schema_name:i}),enabled:c(R)}),{columns:J,isColumnsLoading:W,isColumnsFetching:Z,isColumnsError:ee,refetchColumns:se}=Ns();I.useEffect(()=>{(R==="S3"||R==="API")&&(u(""),x(""),p(""),R==="API"&&f("api"))},[R,f,u,x,p]);const F=(D==null?void 0:D.type)==="API"?(Ue=D==null?void 0:D.type)==null?void 0:Ue.toLowerCase():d||"",$=G?"":i||"";function K(z){x(z),f("")}function te(z){u(z==="none"?"":z),x(""),f(""),z!=="none"&&z!==""&&p("")}function ie(z){m(z)}function ve(z){p(z==="none"?"":z),z!=="none"&&z!==""&&u("")}g&&(($e=g==null?void 0:g.databases)==null?void 0:$e.length)>0,q&&((Qe=q==null?void 0:q.schemas)==null?void 0:Qe.length)>0;const Ne=C==null?void 0:C.connections.map(z=>({id:z.id,name:z.name,type:z.type})),he=(Je=k==null?void 0:k.datamodels)==null?void 0:Je.map(z=>({id:z.id,name:z.name})),Q=g==null?void 0:g.databases.map(z=>({id:z.database_name,name:z.database_name})),X=q==null?void 0:q.schemas.map(z=>({id:z.schema_name,name:z.schema_name})),Us=j==null?void 0:j.tables.map(z=>({id:z.table_name,name:z.table_name})),$s=(Ke=k==null?void 0:k.datamodels.find(z=>z.id===o))==null?void 0:Ke.name;return{connectionItems:Ne,isConnectionsLoading:v,isConnectionsError:M,modelItems:he,selectedDatamodelId:o,selectedDatamodelName:$s,isModelsLoading:A,isModelsError:B,databaseItems:Q,isDatabasesLoadingOrFetching:N||T,isDatabaseError:O,schemaItems:X,isSchemaLoadingOrFetching:P||U,isSchemaError:V,tableItems:Us,isTableLoadingOrFetching:E||b,isTableError:H,columns:J,isColumnsLoadingOrFetching:W||Z,isColumnsError:ee,isNonDbConnection:G,connectionType:R,tableName:F,schemaName:$,refetchConnections:h,refetchModels:L,refetchDatabases:S,refetchSchemas:w,refetchTables:_,refetchColumns:se,handleConnectionChange:ie,handleDatamodelChange:ve,handleDatabaseChange:te,handleSchemaChange:K}}function ws({ColumnsComponent:t,type:a}){var he;const n=s.useEditorStore(Q=>Q.card),r=s.useEditorStore(Q=>Q.selectedConnectionId),o=s.useDashboardStore(Q=>Q.showFilters),l=s.useEditorStore(Q=>Q.selectedDatamodelId),i=s.useEditorStore(Q=>Q.selectedDatabaseName),d=s.useEditorStore(Q=>Q.selectedSchemaName),m=s.useEditorStore(Q=>Q.selectedTableName);s.useEditorStore(Q=>Q.isDevMode);const{setSelectedTableName:p,setIsDevMode:u,setCardSql:x}=s.useEditorActions(),{connectionItems:f,modelItems:c,schemaItems:y,databaseItems:h,tableItems:C,columns:v,isConnectionsLoading:M,isModelsLoading:D,isConnectionsError:L,isModelsError:k,isDatabasesLoadingOrFetching:A,isDatabaseError:B,isSchemaLoadingOrFetching:R,isSchemaError:G,isColumnsError:g,isColumnsLoadingOrFetching:N,isTableLoadingOrFetching:T,isTableError:O,connectionType:S,isNonDbConnection:q,refetchDatabases:P,refetchModels:U,refetchSchemas:V,refetchTables:w,refetchColumns:j,refetchConnections:E,handleConnectionChange:b,handleDatabaseChange:H,handleSchemaChange:_,handleDatamodelChange:J,tableName:W,schemaName:Z}=ne(),{data:ee,refetch:se}=s.useDashboardCardQuery(n);function F(){return t?t(Z,W,v):e.jsx(Yt,{schemaName:Z,tableName:W,columns:v,status:N?"Loading...":g?"Error":"Success"})}function $(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function K(){if(!r||S==="S3"||S==="API")return null;if(!l||l==="none")return e.jsx(le,{refetch:P,showNone:!0,onChange:H,isError:B,isLoading:A,items:h,value:i||"",title:"Database",type:"combobox"})}function te(){if(r&&!q&&(!i||i==="none")&&(!l||l==="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 ie(){if(!r||S==="S3"||S==="API")return null;if(!i||i==="none")return e.jsx(le,{refetch:U,showNone:!0,onChange:J,isError:k,isLoading:D,items:c,value:l||"",title:"Model",type:"combobox"})}function ve(){return!r||S==="S3"||S==="API"||!i||i==="none"?null:e.jsx(le,{refetch:V,onChange:_,isError:G,isLoading:R,items:y,value:d||"",title:"Schema",type:"combobox"})}function Ne(){function Q(){let X=!1;return S==="API"?(X=!1,X):((S==="S3"||r&&i&&i!=="none"&&d)&&(X=!0),X)}return Q()?e.jsx(le,{refetch:w,onChange:p,isError:O,items:C,isLoading:T,value:m||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:s.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(le,{refetch:E,items:f,title:"Connection",value:r||"",onChange:b,isLoading:M,isError:L,type:"combobox",connectionTooltip:((he=f==null?void 0:f.find(Q=>Q.id===r))==null?void 0:he.type)||""}),K(),te(),ie(),ve(),Ne()]}),F(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[s.isDevEnv,e.jsxs(s.Button,{onClick:$,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(kt,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function ks({sql:t,error:a,onClick:n}){return!t&&!a?null: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(is,{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:"w-full min-w-fit max-w-[700px]",children: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&&a,t&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(s.CodeHighlighter,{code:t,language:"sql"})})]})]}),a&&n&&e.jsxs(s.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(jt,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var Is={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ze=I.createContext&&I.createContext(Is),Zt=["attr","size","title"];function Xt(t,a){if(t==null)return{};var n=en(t,a),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function en(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 ye(){return ye=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},ye.apply(this,arguments)}function Xe(t,a){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),n.push.apply(n,r)}return n}function be(t){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Xe(Object(n),!0).forEach(function(r){sn(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Xe(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function sn(t,a,n){return a=tn(a),a in t?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,t}function tn(t){var a=nn(t,"string");return typeof a=="symbol"?a:a+""}function nn(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 Ds(t){return t&&t.map((a,n)=>I.createElement(a.tag,be({key:n},a.attr),Ds(a.child)))}function ue(t){return a=>I.createElement(an,ye({attr:be({},t.attr)},a),Ds(t.child))}function an(t){var a=n=>{var{attr:r,size:o,title:l}=t,i=Xt(t,Zt),d=o||n.size||"1em",m;return n.className&&(m=n.className),t.className&&(m=(m?m+" ":"")+t.className),I.createElement("svg",ye({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:m,style:be(be({color:t.color||n.color},n.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&I.createElement("title",null,l),t.children)};return Ze!==void 0?I.createElement(Ze.Consumer,null,n=>a(n)):a(Is)}function rn(t){return ue({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 Es(t){const{theme:a}=s.useTheme(),n=s.useDashboardStore(h=>h.theme),r=s.useEditorStore(h=>h.frame),o=s.useEditorStore(h=>h.card),l=s.useEditorStore(h=>h.activeTabCardId),i=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:m,setRunSql:p}=s.useEditorActions(),u=I.useRef(),x=I.useRef({}),f=r.cards.find(h=>h.id===l),c=I.useCallback(()=>{let h="";return t==="python"&&(h=(f==null?void 0:f.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(h=(f==null?void 0:f.sql)||""),h},[t,f]);I.useEffect(()=>{if(l&&o.id&&o.id!==l){if(u.current&&i){const h=u.current.getModel();h&&(x.current[o.id]=h);let C=x.current[l];if(!C){const v=c();C=i.editor.createModel(v,t),x.current[l]=C}u.current.setModel(C)}m(l,o),p(!0)}},[l,o,m,i,p,t,c]),I.useEffect(()=>{if(!i)return;const h=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",C=n==="system"?h:n;i.editor.defineTheme("default",{base:C==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":C==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),I.useEffect(()=>{const h=u.current;h&&i&&o&&h.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function y(h,C){if(u.current=h,!x.current[o.id]){const v=h.getModel(),M=c();x.current[o.id]=v||(C==null?void 0:C.editor.createModel(M,t))||h.getModel()}h.setModel(x.current[o.id])}return{handleEditorDidMount:y}}function on(){const t=s.useEditorStore(i=>i.card.sql),a=s.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=Es("sql");function l(i){n(i),s.isObjectEmpty(a)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:l,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function ln(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:a}=s.useEditorActions(),{handleEditorDidMount:n}=Es("python");function r(o){a(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function cn({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 Ts(t){var Z,ee,se;const[a,n]=I.useState(""),[r,o]=I.useState(null),{authToken:l}=s.useSemaphorContext(),i=s.useEditorStore(F=>{var $;return($=F==null?void 0:F.card)==null?void 0:$.sql}),d=s.useEditorStore(F=>{var $;return($=F==null?void 0:F.card)==null?void 0:$.python}),m=s.useEditorStore(F=>F.actions.setCardSql),p=s.useEditorStore(F=>F.actions.setRunSql),u=s.useEditorStore(F=>F.actions.switchCardType),x=s.useEditorStore(F=>F.currentAssitantScope)||[],f=s.useEditorStore(F=>F.userInputForAI),c=s.useEditorStore(F=>F.triggerAIRun),y=s.useEditorStore(F=>F.selectedDatabaseName),h=s.useEditorStore(F=>F.selectedTableName),C=s.useEditorStore(F=>F.selectedConnectionId),v=s.useEditorStore(F=>F.selectedSchemaName),M=s.useDashboardStore(F=>F.dashboard.aiScopeTables),{setTriggerAIRun:D,setCurrentAssitantScope:L}=s.useEditorActions(),{selectedDatamodelName:k,connectionType:A,selectedDatamodelId:B}=ne(),{messages:R,setMessages:G,reload:g,error:N,append:T,input:O,setInput:S,status:q,handleInputChange:P,handleSubmit:U,stop:V}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:w,onFinish(F,$){j($.usage),n(""),$.finishReason==="stop"&&n("")}});I.useEffect(()=>{c&&f&&(P({target:{value:f}}),setTimeout(()=>{U(),D(!1)},100))},[c,U,f,D,P]);async function w({toolCall:F}){if(F.toolName==="createChartFromSql"){const $=F.args.sql,K=F.args.chartType;return u(K),m($),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(F.toolName==="getTableColumns")n("Getting table columns...");else{if(F.toolName==="getUserSql")return i?{status:"success",sql:i,python:d||""}:{status:"error",message:"No SQL found"};if(F.toolName==="getCurrentTableScope")return n("Getting table scope..."),_(),{status:"success",tables:x};n("Analyzing...")}}function j(F){o($=>$?{promptTokens:$.promptTokens+F.promptTokens,completionTokens:$.completionTokens+F.completionTokens,totalTokens:$.totalTokens+F.totalTokens}:F)}function E(F){const $=s.removeFromScopeArray(x,F);b($)}function b(F){const $=s.sanitizeAIScope(F);L($),G(K=>[...K,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify($)}`}])}function H(){const F={databaseName:y||"",schemaName:v||"",tableName:h||"",datamodelId:B||"",datamodelName:s.resolveDatamodelName(k),connectionId:C||"",connectionType:A||""},$=s.dedup([...x,F]);b($)}function _(){const F={databaseName:y||"",schemaName:v||"",tableName:h||"",datamodelName:s.resolveDatamodelName(k),connectionId:C||"",connectionType:A||"",datamodelId:B||""};if(!s.isInAiScopeArray([...M||[],...x],F)||x.length===0){const K=s.dedup([...M||[],...x,F]).filter(te=>te.connectionId===F.connectionId);b(K)}}const J=!["ready","error"].includes(q),W=(se=(ee=(Z=JSON.parse((N==null?void 0:N.message)||"{}"))==null?void 0:Z.error)==null?void 0:ee.lastError)==null?void 0:se.message;return{messages:R,setMessages:G,reload:g,append:T,input:O,setInput:S,isLoading:J,handleSetAIScope:_,handleAddCurrentTableToScope:H,removeFromCurrentSelections:E,currentAssitantScope:x,setCurrentAssitantScope:L,handleInputChange:P,handleSubmit:U,stop:V,chatStatus:q,toolStatus:a,llmUsage:r,onFinish:t,errorMessage:W}}function dn(t){const a=t.toUpperCase().indexOf("WHERE"),n=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let l=t.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),a!==-1){const i=t.substring(0,a),d=t.substring(a);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(n!==-1){const i=t.substring(0,n),d=t.substring(n);return`${i} {{ filters | where }} ${d}`}else{const i=t.substring(0,l),d=t.substring(l);return console.log("beforeClause",i),console.log("afterClause",d),d?`${i} {{ filters | where }} ${d}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function As({variant:t="secondary"}){const{setCardSql:a}=s.useEditorActions(),n=s.useEditorStore(c=>c.frame),r=s.useEditorStore(c=>c.card),o=s.useEditorStore(c=>c.selectedSchemaName),l=s.useEditorStore(c=>c.selectedDatamodelId),i=s.useEditorStore(c=>c.selectedDatabaseName),d=s.useEditorStore(c=>c.selectedTableName),m=s.useEditorStore(c=>c.selectedConnectionId),p=s.useEditorStore(c=>c.isShowingVisual),u=r.sql,x=s.useEditorStore(c=>c.onSave);function f(){let c=u;u&&!u.includes("{{")&&(c=dn(u),a(c));const y={...r,lastSelectedSchema:o,lastSelectedDatamodelId:l,lastSelectedDatabase:i,lastSelectedTable:d,connectionId:m,type:p?r.type:"table",sql:c,customCfg:p?r.customCfg:null},h=n.cards.map(v=>v.id===r.id?y:v),C={...n,cards:h,activeCardId:un(h,n.activeCardId)};x==null||x(C)}return e.jsxs(s.Button,{onClick:f,size:"sm",variant:t,children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Ms(){const{setTempQueryData:t,setSqlGen:a}=s.useEditorActions(),n=s.useQueryClient(),r=s.useEditorStore(m=>m.tempQueryData),o=s.useEditorStore(m=>m.onClose),l=s.useEditorStore(m=>m.card),{queryKey:i}=s.useDashboardCardQuery(l);function d(){if(r){const{queryKey:m,queryData:p}=r;m&&p&&n.setQueryData(m,p)}a({}),o==null||o()}return e.jsxs(s.Button,{onClick:d,size:"sm",variant:"secondary",children:[e.jsx(s.X,{className:"mr-2 size-4"}),"Close"]})}function Ls(){const{setTempQueryData:t}=s.useEditorActions(),a=s.useQueryClient(),n=s.useEditorStore(c=>c.tempQueryData),r=s.useEditorStore(c=>c.card),{queryKey:o}=s.useDashboardCardQuery(r),{setCardSql:l,setSqlGen:i,setCardPython:d,setCardCustomCfg:m,setCardPreferences:p,setCardType:u,clearQueryConfig:x}=s.useEditorActions();function f(){const c=a.getQueryData(o);n!=null&&n.queryData||t({queryKey:o,queryData:c}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),l(""),i({}),x(),d(""),m(""),p({})}return e.jsxs(s.Button,{onClick:f,className:"",size:"sm",variant:"secondary",children:[e.jsx(mt,{className:"mr-2 size-4"}),"Clear"]})}function un(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 l=r.split("__")[0],i=t.find(d=>d.tabTitle===l);return i?i.id:t[0].id}return a}}return t[0].id}function mn(){const t=s.useQueryClient(),[a,n]=I.useState(!1),[r,o]=I.useState(!1);s.useEditorStore(j=>j.frame);const l=s.useEditorStore(j=>j.card);s.useEditorStore(j=>j.isShowingVisual),s.useEditorStore(j=>j.selectedConnectionId),s.useEditorStore(j=>j.tempQueryData),s.useEditorStore(j=>j.selectedDatabaseName),s.useEditorStore(j=>j.selectedDatamodelId),s.useEditorStore(j=>j.selectedSchemaName);const i=s.useEditorStore(j=>j.showAIDialog);s.useEditorStore(j=>j.selectedTableName);const d=s.useEditorStore(j=>{var E;return(E=j==null?void 0:j.card)==null?void 0:E.sql}),{sheetFilterValues:m}=s.useSheetFilterValues(),{setCardCustomCfg:p,setQueryResultColumns:u,setCardSql:x,setTempQueryData:f,setPythonStdOut:c,setCardPreferences:y,setCardType:h,setCardPython:C,runAssistant:v,setShowAIDialog:M}=s.useEditorActions();s.useEditorStore(j=>j.onSave),s.useEditorStore(j=>j.onClose),s.useEditorStore(j=>j.actions.setSqlGen);const D=s.useEditorStore(j=>j.runSql),L=s.useEditorStore(j=>j.actions.setRunSql),k=s.useEditorStore(j=>j.actions.setIsSqlRunning),{data:A,isLoading:B,isFetching:R,isSuccess:G,isError:g,error:N,queryKey:T,refetch:O,errorMessage:S}=s.useDashboardCardQuery(l),{handleSetAIScope:q}=Ts();I.useEffect(()=>{if(A&&(A.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),c((A==null?void 0:A.output)||""),A.records.length>0)){const{dimensionKeys:j}=s.getKeys(A.records);u(j)}},[A,u,c]),I.useEffect(()=>{(B||R)&&k(!0),(g||G)&&k(!1),g&&(u([]),c(""))},[B,R,A,c,g,G,k,u,N]),I.useEffect(()=>{D&&(t.getQueryData(T)||O(),L(!1))},[D,O,L,T,t]);async function P(){const j=`Can you help me debug this query in the current table scope?
|
|
331
|
+
*/const gt=t.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"}]]);/**
|
|
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 qs=t.createLucideIcon("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
|
|
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 jt=t.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"}]]);function Pe(s){var a;return{...s,sheets:(a=s==null?void 0:s.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>yt(i))}})}})}}function yt(s){return{...s,customCfg:Ps(s.customCfg),data:[]}}function Ps(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Hs(s,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:n,operation:"create"})}async function Me(s,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:l,shared:i}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Gs(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Us(){const[s,a]=k.useState(""),[n,r]=k.useState(!1),o=t.useDashboardStore(h=>h.lenses),{setLenses:l,setSelectedLensId:i}=t.useDashboardActions(),[d,m]=k.useState(!1),[p,u]=k.useState(!1),x=t.useDashboardStore(h=>h.dashboard),f=t.useDashboardStore(h=>h.filterValues),{authToken:c}=t.useSemaphorContext();async function g(){m(!0);const h=Pe(x),j=await Hs(s,h,f,c==null?void 0:c.accessToken);j&&(l([...o||[],j]),i(j.id),u(!1)),m(!1)}return e.jsxs(t.Dialog,{open:p,onOpenChange:u,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.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(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:h=>{a(h.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(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:d,children:d?"Creating...":"Add"})})]})]})}function $s(){const[s,a]=k.useState(!1),n=t.useDashboardStore(u=>u.lenses),r=t.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:l}=t.useDashboardActions(),{authToken:i}=t.useSemaphorContext();async function d(u){l(u)}async function m(u){if(await Gs(u,i==null?void 0:i.accessToken)){const f=n==null?void 0:n.filter(c=>c.id!==u);o(f||[]),l("original")}}async function p(u){const x=n==null?void 0:n.map(g=>g.id===u.id?{...g,isDefault:!u.isDefault}:{...g,isDefault:!1});o(x||[]);const f={...u,isDefault:!u.isDefault};await Me(f,i==null?void 0:i.accessToken);const c=n==null?void 0:n.find(g=>g.isDefault);if(c&&c.id!==u.id){const g={...c,isDefault:!1};await Me(g,i==null?void 0:i.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(ys,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(u=>e.jsxs(t.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(Cs,{onClick:x=>{x.preventDefault(),p(u)},className:t.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(t.Cross2Icon,{onClick:x=>{x.preventDefault(),m(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 bt(){var l;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(l=t.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function St(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:l}=bt();if(s)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",l||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,x=document.createElement("a");x.href=u;const f=`${o}-${new Date().toISOString()}.pdf`;x.download=f,x.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Qs({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),t.useDashboardStore(o=>o.theme),t.useDashboardStore(o=>o.filterValues);const n=t.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await St()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(re,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function X({defaultValue:s,label:a,options:n,value:r,onValueChange:o,className:l,icon:i}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:o,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",l),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("div",{className:"mr-2",children:i}),e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(d=>e.jsx(t.SelectItem,{value:d.value,children:d.label},d.value))]})})]})}const Ye=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Ct({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:l,isDeleting:i}=Js(),[d,m]=k.useState(""),[p,u]=k.useState(Ye[0].value),[x,f]=k.useState("06:00"),[c,g]=k.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(ds,{className:"size-4"})})}),e.jsx(t.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(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:d,onChange:h=>m(h.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:c,onChange:h=>{g(h.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(X,{className:"col-span-2 h-8",label:"Select Frequency",options:Ye,value:p,onValueChange:h=>u(h)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:x,onChange:h=>f(h.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:d,frequency:p,time:x,subject:c}),f("00:00"),m(""),g("")},className:"h-8 p-2",disabled:o==="loading"||!d,children:[o==="loading"&&e.jsx(re,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(it,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:l})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.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"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(h=>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:[t.titleCase(h.frequency)," "]}),e.jsx(t.Label,{children:h.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Xe,{tooltip:`Next Run: ${new Date(h.nextRun).toLocaleString()} ${h.timezone}`,children:e.jsx(cs,{className:"size-3.5"})}),e.jsx(Xe,{tooltip:`${h.endUserEmail}`,children:e.jsx(Ds,{className:"size-3.5"})}),i===h.id?e.jsx(re,{className:"size-3.5 animate-spin"}):e.jsx(qs,{onClick:()=>r(h.id),className:"size-3.5 cursor-pointer"})]})]},h.id))})]})]})]})})]})})}const Xe=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function Js(){const[s,a]=k.useState("idle"),[n,r]=k.useState(""),[o,l]=k.useState(null),i=t.useDashboardStore(E=>E.authToken),d=t.useDashboardStore(E=>E.dashboard.id),m=t.useDashboardStore(E=>E.dashboard.title),{endUserId:p}=t.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",x={dashboardId:d,endUserId:p},{data:f,isLoading:c,isError:g,isFetching:h,refetch:j}=t.useQuery({queryKey:["subscriptions",d,p],queryFn:()=>t.getRequest(u,(i==null?void 0:i.accessToken)||"",x),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!p});async function b({email:E,subject:z,frequency:w,time:M}){const{authToken:R,...F}=bt(),H=Intl.DateTimeFormat().resolvedOptions().timeZone,S={email:E,frequency:w,time:M,timezone:H,endUserId:p,endUserEmail:E,subject:z||m||"Scheduled Dashboard",dashboardId:d,dashboardParams:F};a("loading");const N="https://semaphor.cloud/api/v1/subscriptions/create";try{const A=await t.postRequestRegular(N,(R==null?void 0:R.accessToken)||"",{...S});a("success"),r(""),j(),setTimeout(()=>{a("idle")},2e3)}catch(A){console.error(A),a("error"),r(A.message)}}async function O(E){const z="https://semaphor.cloud/api/v1/subscriptions/delete";l(E);try{await t.postRequestRegular(z,(i==null?void 0:i.accessToken)||"",{id:E}),j(),setTimeout(()=>{l(null)},2e3)}catch(w){console.error(w),l(null),a("error"),r(w.message)}}return{data:f,isLoading:c,isFetching:h,isError:g,isDeleting:o,refetch:j,handleScheduleSubscription:b,handleDeleteSubscription:O,status:s,error:n}}function Ks(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(S=>S.theme);const a=t.useDashboardStore(S=>S.lenses),n=t.useDashboardStore(S=>S.selectedLensId),r=a==null?void 0:a.find(S=>S.id===n),o=t.useDashboardStore(S=>S.dashboard);t.useDashboardStore(S=>S.selectedSheetId);const l=t.useDashboardStore(S=>S.isDashboardEditing),i=t.useEditorStore(S=>S.selectedConnectionId),[d,m]=k.useState(!1),p=t.useDashboardStore(S=>S.filterValues),u=t.useDashboardStore(S=>S.isVisualEditing),x=t.useDashboardStore(S=>S.showFilters);t.useDashboardStore(S=>S.showDashboardJSON);const f=t.useDashboardStore(S=>S.onSaveFunction),c=t.useDashboardStore(S=>S.actions.setShowFilters),{addFrame:g,setSelectedFrameId:h}=t.useDashboardStore(S=>S.actions),{getSelectedSheet:j,setIsDashboardEditing:b,setShowDashboardJSON:O}=t.useDashboardStore(S=>S.actions),E=j(),{tenantId:z,endUserId:w}=k.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),M=k.useMemo(()=>z||w,[z,w]),R=()=>{if(!l||!E)return;const S={connectionId:i,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},N={id:t.v4(),cards:[S],activeCardId:S.id};g(E.id,N),h(N.id)},F=()=>{b(!0)};async function H(){if(m(!0),!n||!r)return;const S=Pe(o),N=JSON.stringify(S),A={...r,template:N,filterValues:p};await Me(A,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),f==null||f(S),m(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!u&&e.jsx(Qs,{}),!u&&e.jsx(Ct,{}),l&&!u&&M&&e.jsx(Us,{}),!u&&M&&e.jsx($s,{}),l&&!u&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:R,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!l&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:F,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),l&&!u&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{b(!1),O(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),l&&!u&&M&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:H,size:"sm",children:e.jsx(Fs,{className:"h-4 w-4"})}),!x&&!u&&l&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsx(dt,{className:"h-4 w-4"})}),!u&&l&&!1,!u&&!1]})]})}function Ws({name:s,items:a,value:n,onChange:r,isLoading:o,isError:l,refetch:i,className:d,icon:m,showNone:p=!1}){const u=de.useRef(null),[x,f]=de.useState(!1),[c,g]=de.useState("100%"),h=p?[...a||[],{id:"none",name:"None"}]:a;de.useLayoutEffect(()=>{u.current&&g(u.current.offsetWidth)},[]);function j(){var O;return o?"Loading...":l?"Error":n?(O=a==null?void 0:a.find(E=>E.id===n))==null?void 0:O.name:`Select ${s}`}function b(O,E){r(E),f(!1)}return e.jsxs(t.Popover,{open:x,onOpenChange:f,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:u,variant:"outline",role:"combobox","aria-expanded":x,className:t.cn("flex h-9 w-full justify-between",d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsx("div",{className:"mr-2",children:m}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:j()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:c},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:i,children:e.jsx(pt,{className:t.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:h==null?void 0:h.map(O=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:O.name,onSelect:E=>b(E,O.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===O.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:O.name,children:O.name})]})},O.id))})]})]})})]})}function le({title:s,items:a,value:n,isLoading:r,isError:o,refetch:l,onChange:i,showNone:d=!1,className:m,disabled:p=!1,type:u="combobox"}){const x=r?"Loading...":o?"Error":n;function f(){if(s==="Connection")return e.jsx(Ls,{className:"size-4"});if(s==="Database")return e.jsx(ps,{className:"size-4"});if(s==="Schema")return e.jsx(Ms,{className:"size-4"});if(s==="Table")return e.jsx(qe,{className:"size-4"});if(s==="Model")return e.jsx(os,{className:"size-4"})}function c(){return e.jsxs(t.Select,{disabled:p,value:x,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",m),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(pt,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((h,j)=>e.jsx(t.SelectItem,{value:h.id,children:h.name},j))]}),(r||o)&&e.jsx(t.SelectItem,{value:x,children:x})]})})]})}function g(){return e.jsx(Ws,{icon:f(),items:a,value:x,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:l,name:s,showNone:d})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:u==="select"?c():g()})})}function Ys({column:s}){const[a,n]=k.useState(!1),r=t.useEditorStore(h=>h.selectedTableName),o=t.useEditorStore(h=>h.selectedSchemaName),l=t.useEditorStore(h=>h.selectedDatabaseName),i=t.useEditorStore(h=>h.selectedDatamodelId),d=t.useEditorStore(h=>h.sqlGen),{modelItems:m,connectionType:p}=Z(),u=t.useEditorStore(h=>h.actions.setSqlGen),x=t.useEditorStore(h=>h.actions.setCardSql),f=t.useEditorStore(h=>h.actions.setRunSql);function c(h,j){var z;const b=t.createSqlGenConfig(h,d,j),O=(z=m==null?void 0:m.find(w=>w.id===i))==null?void 0:z.name;u(b);const E=t.getSql(b,t.fmt(o||""),t.fmt(r),O,p,l||"");E&&(x(E),f(!0)),n(!1)}function g(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>c(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>c(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>c(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>c(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>c(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(ct,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:g()})]})}function He({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(jt,{className:"size-3"}):t.isNumberDataType(s.data_type)?e.jsx(ut,{className:"size-3"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3"}):t.isBooleanDataType(s.data_type)?e.jsx(Bs,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsx(is,{className:"size-3"}):e.jsx(Rs,{className:"size-3"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ne({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(He,{column:s}),e.jsx("span",{children:s.column_name})]})}function Xs({id:s,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:l,transform:i}=t.useDraggable({id:s,data:{type:n}}),d=i?{translate:t.CSS.Translate.toString(i),transform:t.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:l,style:d,...o,...r,children:a})}function Zs({onClick:s,column:a}){const n=t.useDndStore(f=>f.activeId),r=t.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.groupByColumns}),o=t.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.trendByColumns}),l=t.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.metricColumns}),i=t.useEditorStore(f=>{var c;return(c=f.card.queryConfig)==null?void 0:c.filterColumns});function d(f){return m(f)||u(f)||p(f)||x(f)}function m(f){return r==null?void 0:r.some(c=>c.name===f.column_name)}function p(f){return o==null?void 0:o.some(c=>c.name===f.column_name)}function u(f){return l==null?void 0:l.some(c=>c.name===f.column_name)}function x(f){return i==null?void 0:i.some(c=>c.name===f.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":d(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(Ne,{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(Ne,{column:a})}),e.jsx(Xs,{id:a.column_name,type:"column",children:e.jsx(Ne,{column:a})})]})}function ae(s){return`${s}-${t.v4()}`}function ge(s,a){return s==="SUM"?`Sum of ${a}`:s==="AVG"?`Avg of ${a}`:s==="COUNT"?`Count of ${a}`:s==="MAX"?`Max of ${a}`:s==="MIN"?`Min of ${a}`:s==="DISTINCT"?`Distinct ${a}`:a}function en({schemaName:s,tableName:a,columns:n,status:r}){const o=t.useEditorStore(y=>y.sqlGen),l=t.useEditorStore(y=>y.isDevMode),i=t.useEditorStore(y=>y.selectedConnectionId),d=t.useEditorStore(y=>y.selectedDatabaseName),m=t.useEditorStore(y=>y.selectedSchemaName),p=t.useEditorStore(y=>y.selectedTableName),u=t.useEditorStore(y=>y.selectedDatamodelId),x=t.useDashboardStore(y=>y.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:c}=t.useDashboardActions(),{addColumnToMetricColumns:g,addColumnToTrendByColumns:h,setCardSql:j,setRunSql:b,setSqlGen:O,setIsShowingVisual:E}=t.useEditorActions(),{connectionType:z,modelItems:w,selectedDatamodelName:M}=Z();function R(y){var B;if(l){const G=t.createSqlGenConfig(y,o);O(G);const $=(B=w==null?void 0:w.find(I=>I.id===u))==null?void 0:B.name,q=t.getSql(G,t.fmt(s),t.fmt(a),$,z,d||"");q&&(j(q),b(!0))}if(!l){if(t.isTextDataType(y.data_type)){const G={...y,role:"metric",id:ae(y.column_name),name:y.column_name,label:ge("COUNT",y.column_name),type:y.data_type,aggregate:"COUNT"};g(G)}if(t.isNumberDataType(y.data_type)){const G={...y,role:"metric",id:ae(y.column_name),name:y.column_name,label:ge("SUM",y.column_name),type:y.data_type,aggregate:"SUM"};g(G)}if(t.isDateDataType(y.data_type)){const G={...y,role:"trendby",id:ae(y.column_name),name:y.column_name,type:y.data_type};h(G)}}}function F(y){y===!0&&(p||M)&&i?(f({connectionId:i,connectionType:z==="S3"||z==="API"?"DuckDb":z,databaseName:d||"",schemaName:m||"",tableName:p||"",datamodelName:t.resolveDatamodelName(M),datamodelId:u||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(c({connectionId:i||"",connectionType:z||"",tableName:p||"",datamodelName:t.resolveDatamodelName(M),datamodelId:u||"",databaseName:d||"",schemaName:m||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function H(){const y=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:M,connectionType:z,databaseName:d||""});E(!1);const B=z==="MSSQL"?`SELECT top 10 * FROM ${y}`:`SELECT * FROM ${y} LIMIT 10`;j(B),b(!0)}function S(){const y=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:M,connectionType:z,databaseName:d||""});j(`SELECT COUNT(*) as count FROM ${y}`),b(!0)}function N(){return(x==null?void 0:x.find(y=>y.connectionId===i&&(y.tableName===p||y.datamodelName===M)))!==void 0}function A(y){return l?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>R(y),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(He,{column:y}),e.jsx("span",{children:y.column_name})]}),e.jsx("div",{onClick:B=>B.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(y.data_type)&&e.jsx(Ys,{column:y})})]}):e.jsx(Zs,{onClick:R,column:y})}function D(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${N()?"Remove from":"Add to"} Assistant Scope`,pressed:N(),onPressedChange:F,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":N(),"text-muted-foreground":!N()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:H,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Is,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:S,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ft,{className:"mr-2 size-4"}),"Count"]})]})}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:D()}),e.jsxs(t.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted px-2 py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(y=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:A(y)},y.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function vt(){const s=t.useDashboardStore(d=>d.authToken),a=t.useEditorStore(d=>d.selectedConnectionId),{refetch:n,data:r,isLoading:o,isError:l}=t.useQuery({queryKey:["connections"],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),i=r==null?void 0:r.connections.find(d=>d.id===a);return{connectionsData:r,isConnectionsLoading:o,isConnectionsError:l,refetchConnections:n,currentConnection:i}}function Nt(){var h;const s=t.useEditorStore(j=>j.selectedConnectionId),a=t.useEditorStore(j=>j.selectedDatabaseName),n=t.useEditorStore(j=>j.selectedDatamodelId),r=t.useEditorStore(j=>j.selectedSchemaName),o=t.useEditorStore(j=>j.selectedTableName),l=t.useDashboardStore(j=>j.authToken),{currentConnection:i}=vt(),d=i==null?void 0:i.type,{data:m,isLoading:p,isFetching:u,isError:x,refetch:f}=t.useQuery({queryKey:["columns",s,a,n,r,o],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/columns",(l==null?void 0:l.accessToken)||"",{connection_id:s,datamodel_id:n||"",database_name:a,schema_name:r,table_name:o}),enabled:c(d)});function c(j){return l!=null&&l.accessToken?!!(s&&a&&a!=="NA"&&r&&o||s&&(j==="S3"||j==="API")||n&&n):!1}return{columns:(h=m==null?void 0:m.columns)==null?void 0:h.map(j=>({...j,data_type:j.data_type.toLowerCase()})),isColumnsLoading:p,isColumnsFetching:u,isColumnsError:x,refetchColumns:f}}function Z(s,a){var $e,Qe,Je,Ke,We;const n=t.useSemaphorContext().authToken||s,r=t.useEditorStore(V=>V.selectedConnectionId),o=t.useEditorStore(V=>V.selectedDatamodelId),l=t.useEditorStore(V=>V.selectedDatabaseName),i=t.useEditorStore(V=>V.selectedSchemaName),d=t.useEditorStore(V=>V.selectedTableName),m=t.useEditorStore(V=>V.actions.setSelectedConnectionId),p=t.useEditorStore(V=>V.actions.setSelectedDatamodelId),u=t.useEditorStore(V=>V.actions.setSelectedDatabaseName),x=t.useEditorStore(V=>V.actions.setSelectedSchemaName),f=t.useEditorStore(V=>V.actions.setSelectedTableName);t.useEditorStore(V=>V.actions.setCardSql);function c(V){return r&&l&&i&&l!=="NA"?!0:r&&V==="API"?!1:!!(r&&V==="S3")}function g(V){return r&&V?!(V==="API"||V==="S3"):!1}const{refetchConnections:h,connectionsData:j,isConnectionsLoading:b,isConnectionsError:O,currentConnection:E}=vt(),{refetch:z,data:w,isLoading:M,isError:R}=t.useQuery({queryKey:["models",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:!!(n!=null&&n.accessToken)&&!!r}),F=E==null?void 0:E.type,H=(E==null?void 0:E.type)==="API"||(E==null?void 0:E.type)==="S3",{data:S,isLoading:N,isFetching:A,isError:D,refetch:y}=t.useQuery({queryKey:["databases",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:g(F)}),{data:B,isLoading:G,isFetching:$,isError:q,refetch:I}=t.useQuery({queryKey:["schemas",r,l],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l}),enabled:!!r&&!!l&&!H&&l!=="NA"}),{data:C,isLoading:v,isFetching:T,isError:L,refetch:U}=t.useQuery({queryKey:["tables",r,l,i],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l,schema_name:i}),enabled:c(F)}),{columns:P,isColumnsLoading:K,isColumnsFetching:W,isColumnsError:te,refetchColumns:se}=Nt();k.useEffect(()=>{(F==="S3"||F==="API")&&(u(""),x(""),p(""),F==="API"&&f("api"))},[F,f,u,x,p]);const _=(E==null?void 0:E.type)==="API"?($e=E==null?void 0:E.type)==null?void 0:$e.toLowerCase():d||"",Q=H?"":i||"";function Y(V){x(V),f("")}function ne(V){u(V==="none"?"":V),x(""),f(""),V!=="none"&&V!==""&&p("")}function ie(V){m(V)}function Ce(V){p(V==="none"?"":V),V!=="none"&&V!==""&&u("")}S&&((Qe=S==null?void 0:S.databases)==null?void 0:Qe.length)>0,B&&((Je=B==null?void 0:B.schemas)==null?void 0:Je.length)>0;const ve=j==null?void 0:j.connections.map(V=>({id:V.id,name:V.name,type:V.type})),he=(Ke=w==null?void 0:w.datamodels)==null?void 0:Ke.map(V=>({id:V.id,name:V.name})),J=S==null?void 0:S.databases.map(V=>({id:V.database_name,name:V.database_name})),ee=B==null?void 0:B.schemas.map(V=>({id:V.schema_name,name:V.schema_name})),Ut=C==null?void 0:C.tables.map(V=>({id:V.table_name,name:V.table_name})),Ue=(We=w==null?void 0:w.datamodels.find(V=>V.id===o))==null?void 0:We.name,$t=t.getFormattedTableNameForQuery({schemaName:Q,tableName:_,modelName:Ue,connectionType:F,databaseName:l||""});return{connectionItems:ve,selectedConnectionId:r,isConnectionsLoading:b,isConnectionsError:O,modelItems:he,selectedDatamodelId:o,selectedDatamodelName:Ue,isModelsLoading:M,isModelsError:R,selectedDatabaseName:l,databaseItems:J,isDatabasesLoadingOrFetching:N||A,isDatabaseError:D,schemaItems:ee,selectedSchemaName:i,isSchemaLoadingOrFetching:G||$,isSchemaError:q,tableItems:Ut,selectedTableName:d,isTableLoadingOrFetching:v||T,isTableError:L,columns:P,isColumnsLoadingOrFetching:K||W,isColumnsError:te,isNonDbConnection:H,connectionType:F,tableName:_,formattedTableName:$t,schemaName:Q,refetchConnections:h,refetchModels:z,refetchDatabases:y,refetchSchemas:I,refetchTables:U,refetchColumns:se,handleConnectionChange:ie,handleDatamodelChange:Ce,handleDatabaseChange:ne,handleSchemaChange:Y}}function wt({ColumnsComponent:s,type:a}){var he;const n=t.useEditorStore(J=>J.card),r=t.useEditorStore(J=>J.selectedConnectionId),o=t.useDashboardStore(J=>J.showFilters),l=t.useEditorStore(J=>J.selectedDatamodelId),i=t.useEditorStore(J=>J.selectedDatabaseName),d=t.useEditorStore(J=>J.selectedSchemaName),m=t.useEditorStore(J=>J.selectedTableName);t.useEditorStore(J=>J.isDevMode);const{setSelectedTableName:p,setIsDevMode:u,setCardSql:x}=t.useEditorActions(),{connectionItems:f,modelItems:c,schemaItems:g,databaseItems:h,tableItems:j,columns:b,isConnectionsLoading:O,isModelsLoading:E,isConnectionsError:z,isModelsError:w,isDatabasesLoadingOrFetching:M,isDatabaseError:R,isSchemaLoadingOrFetching:F,isSchemaError:H,isColumnsError:S,isColumnsLoadingOrFetching:N,isTableLoadingOrFetching:A,isTableError:D,connectionType:y,isNonDbConnection:B,refetchDatabases:G,refetchModels:$,refetchSchemas:q,refetchTables:I,refetchColumns:C,refetchConnections:v,handleConnectionChange:T,handleDatabaseChange:L,handleSchemaChange:U,handleDatamodelChange:P,tableName:K,schemaName:W}=Z(),{data:te,refetch:se}=t.useDashboardCardQuery(n);function _(){return s?s(W,K,b):e.jsx(en,{schemaName:W,tableName:K,columns:b,status:N?"Loading...":S?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function Y(){if(!r||y==="S3"||y==="API")return null;if(!l||l==="none")return e.jsx(le,{refetch:G,showNone:!0,onChange:L,isError:R,isLoading:M,items:h,value:i||"",title:"Database",type:"combobox"})}function ne(){if(r&&!B&&(!i||i==="none")&&(!l||l==="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(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function ie(){if(!r||y==="S3"||y==="API")return null;if(!i||i==="none")return e.jsx(le,{refetch:$,showNone:!0,onChange:P,isError:w,isLoading:E,items:c,value:l||"",title:"Model",type:"combobox"})}function Ce(){return!r||y==="S3"||y==="API"||!i||i==="none"?null:e.jsx(le,{refetch:q,onChange:U,isError:H,isLoading:F,items:g,value:d||"",title:"Schema",type:"combobox"})}function ve(){function J(){let ee=!1;return y==="API"?(ee=!1,ee):((y==="S3"||r&&i&&i!=="none"&&d)&&(ee=!0),ee)}return J()?e.jsx(le,{refetch:I,onChange:p,isError:D,items:j,isLoading:A,value:m||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(le,{refetch:v,items:f,title:"Connection",value:r||"",onChange:T,isLoading:O,isError:z,type:"combobox",connectionTooltip:((he=f==null?void 0:f.find(J=>J.id===r))==null?void 0:he.type)||""}),Y(),ne(),ie(),Ce(),ve()]}),_(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[t.isDevEnv,e.jsxs(t.Button,{onClick:Q,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(Es,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function kt({sql:s,error:a,onClick:n}){return!s&&!a?null:e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(it,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children: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(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})]})]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(Ss,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var It={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ze=k.createContext&&k.createContext(It),tn=["attr","size","title"];function sn(s,a){if(s==null)return{};var n=nn(s,a),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function nn(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function je(){return je=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},je.apply(this,arguments)}function et(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),n.push.apply(n,r)}return n}function ye(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?et(Object(n),!0).forEach(function(r){an(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):et(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function an(s,a,n){return a=rn(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function rn(s){var a=on(s,"string");return typeof a=="symbol"?a:a+""}function on(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function Dt(s){return s&&s.map((a,n)=>k.createElement(a.tag,ye({key:n},a.attr),Dt(a.child)))}function ue(s){return a=>k.createElement(ln,je({attr:ye({},s.attr)},a),Dt(s.child))}function ln(s){var a=n=>{var{attr:r,size:o,title:l}=s,i=sn(s,tn),d=o||n.size||"1em",m;return n.className&&(m=n.className),s.className&&(m=(m?m+" ":"")+s.className),k.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:m,style:ye(ye({color:s.color||n.color},n.style),s.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&k.createElement("title",null,l),s.children)};return Ze!==void 0?k.createElement(Ze.Consumer,null,n=>a(n)):a(It)}function cn(s){return ue({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:[]}]})(s)}function Et(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(h=>h.theme),r=t.useEditorStore(h=>h.frame),o=t.useEditorStore(h=>h.card),l=t.useEditorStore(h=>h.activeTabCardId),i=t.Le(),{refetch:d}=t.useDashboardCardQuery(o),{updateCardTab:m,setRunSql:p}=t.useEditorActions(),u=k.useRef(),x=k.useRef({}),f=r.cards.find(h=>h.id===l),c=k.useCallback(()=>{let h="";return s==="python"&&(h=(f==null?void 0:f.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(h=(f==null?void 0:f.sql)||""),h},[s,f]);k.useEffect(()=>{if(l&&o.id&&o.id!==l){if(u.current&&i){const h=u.current.getModel();h&&(x.current[o.id]=h);let j=x.current[l];if(!j){const b=c();j=i.editor.createModel(b,s),x.current[l]=j}u.current.setModel(j)}m(l,o),p(!0)}},[l,o,m,i,p,s,c]),k.useEffect(()=>{if(!i)return;const h=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",j=n==="system"?h:n;i.editor.defineTheme("default",{base:j==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":j==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),k.useEffect(()=>{const h=u.current;h&&i&&o&&h.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function g(h,j){if(u.current=h,!x.current[o.id]){const b=h.getModel(),O=c();x.current[o.id]=b||(j==null?void 0:j.editor.createModel(O,s))||h.getModel()}h.setModel(x.current[o.id])}return{handleEditorDidMount:g}}function dn(){const s=t.useEditorStore(i=>i.card.sql),a=t.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:o}=Et("sql");function l(i){n(i),t.isObjectEmpty(a)||r({})}return e.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:l,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function un(){const s=t.useEditorStore(o=>o.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=Et("python");function r(o){a(o)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function mn({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function Tt(s){var W,te,se;const[a,n]=k.useState(""),[r,o]=k.useState(null),{authToken:l}=t.useSemaphorContext(),i=t.useEditorStore(_=>{var Q;return(Q=_==null?void 0:_.card)==null?void 0:Q.sql}),d=t.useEditorStore(_=>{var Q;return(Q=_==null?void 0:_.card)==null?void 0:Q.python}),m=t.useEditorStore(_=>_.actions.setCardSql),p=t.useEditorStore(_=>_.actions.setRunSql),u=t.useEditorStore(_=>_.actions.switchCardType),x=t.useEditorStore(_=>_.currentAssitantScope)||[],f=t.useEditorStore(_=>_.userInputForAI),c=t.useEditorStore(_=>_.triggerAIRun),g=t.useEditorStore(_=>_.selectedDatabaseName),h=t.useEditorStore(_=>_.selectedTableName),j=t.useEditorStore(_=>_.selectedConnectionId),b=t.useEditorStore(_=>_.selectedSchemaName),O=t.useDashboardStore(_=>_.dashboard.aiScopeTables),{setTriggerAIRun:E,setCurrentAssitantScope:z}=t.useEditorActions(),{selectedDatamodelName:w,connectionType:M,selectedDatamodelId:R}=Z(),{messages:F,setMessages:H,reload:S,error:N,append:A,input:D,setInput:y,status:B,handleInputChange:G,handleSubmit:$,stop:q}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:I,onFinish(_,Q){C(Q.usage),n(""),Q.finishReason==="stop"&&n("")}});k.useEffect(()=>{c&&f&&(G({target:{value:f}}),setTimeout(()=>{$(),E(!1)},100))},[c,$,f,E,G]);async function I({toolCall:_}){if(_.toolName==="createChartFromSql"){const Q=_.args.sql,Y=_.args.chartType;return u(Y),m(Q),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(_.toolName==="getTableColumns")n("Getting table columns...");else{if(_.toolName==="getUserSql")return i?{status:"success",sql:i,python:d||""}:{status:"error",message:"No SQL found"};if(_.toolName==="getCurrentTableScope")return n("Getting table scope..."),U(),{status:"success",tables:x};n("Analyzing...")}}function C(_){o(Q=>Q?{promptTokens:Q.promptTokens+_.promptTokens,completionTokens:Q.completionTokens+_.completionTokens,totalTokens:Q.totalTokens+_.totalTokens}:_)}function v(_){const Q=t.removeFromScopeArray(x,_);T(Q)}function T(_){const Q=t.sanitizeAIScope(_);z(Q),H(Y=>[...Y,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(Q)}`}])}function L(){const _={databaseName:g||"",schemaName:b||"",tableName:h||"",datamodelId:R||"",datamodelName:t.resolveDatamodelName(w),connectionId:j||"",connectionType:M||""},Q=t.dedup([...x,_]);T(Q)}function U(){const _={databaseName:g||"",schemaName:b||"",tableName:h||"",datamodelName:t.resolveDatamodelName(w),connectionId:j||"",connectionType:M||"",datamodelId:R||""};if(!t.isInAiScopeArray([...O||[],...x],_)||x.length===0){const Y=t.dedup([...O||[],...x,_]).filter(ne=>ne.connectionId===_.connectionId);T(Y)}}const P=!["ready","error"].includes(B),K=(se=(te=(W=JSON.parse((N==null?void 0:N.message)||"{}"))==null?void 0:W.error)==null?void 0:te.lastError)==null?void 0:se.message;return{messages:F,setMessages:H,reload:S,append:A,input:D,setInput:y,isLoading:P,handleSetAIScope:U,handleAddCurrentTableToScope:L,removeFromCurrentSelections:v,currentAssitantScope:x,setCurrentAssitantScope:z,handleInputChange:G,handleSubmit:$,stop:q,chatStatus:B,toolStatus:a,llmUsage:r,onFinish:s,errorMessage:K}}function hn(s){const a=s.toUpperCase().indexOf("WHERE"),n=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),a!==-1){const i=s.substring(0,a),d=s.substring(a);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(n!==-1){const i=s.substring(0,n),d=s.substring(n);return`${i} {{ filters | where }} ${d}`}else{const i=s.substring(0,l),d=s.substring(l);return console.log("beforeClause",i),console.log("afterClause",d),d?`${i} {{ filters | where }} ${d}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function At({variant:s="secondary"}){const{setCardSql:a}=t.useEditorActions(),n=t.useEditorStore(c=>c.frame),r=t.useEditorStore(c=>c.card),o=t.useEditorStore(c=>c.selectedSchemaName),l=t.useEditorStore(c=>c.selectedDatamodelId),i=t.useEditorStore(c=>c.selectedDatabaseName),d=t.useEditorStore(c=>c.selectedTableName),m=t.useEditorStore(c=>c.selectedConnectionId),p=t.useEditorStore(c=>c.isShowingVisual),u=r.sql,x=t.useEditorStore(c=>c.onSave);function f(){let c=u;u&&!u.includes("{{")&&(c=hn(u),a(c));const g={...r,lastSelectedSchema:o,lastSelectedDatamodelId:l,lastSelectedDatabase:i,lastSelectedTable:d,connectionId:m,type:p?r.type:"table",sql:c,customCfg:p?r.customCfg:null},h=n.cards.map(b=>b.id===r.id?g:b),j={...n,cards:h,activeCardId:pn(h,n.activeCardId)};x==null||x(j)}return e.jsxs(t.Button,{onClick:f,size:"sm",variant:s,children:[e.jsx(t.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Mt(){const{setTempQueryData:s,setSqlGen:a}=t.useEditorActions(),n=t.useQueryClient(),r=t.useEditorStore(m=>m.tempQueryData),o=t.useEditorStore(m=>m.onClose),l=t.useEditorStore(m=>m.card),{queryKey:i}=t.useDashboardCardQuery(l);function d(){if(r){const{queryKey:m,queryData:p}=r;m&&p&&n.setQueryData(m,p)}a({}),o==null||o()}return e.jsxs(t.Button,{onClick:d,size:"sm",variant:"secondary",children:[e.jsx(t.X,{className:"mr-2 size-4"}),"Close"]})}function Lt(){const{setTempQueryData:s}=t.useEditorActions(),a=t.useQueryClient(),n=t.useEditorStore(c=>c.tempQueryData),r=t.useEditorStore(c=>c.card),{queryKey:o}=t.useDashboardCardQuery(r),{setCardSql:l,setSqlGen:i,setCardPython:d,setCardCustomCfg:m,setCardPreferences:p,setCardType:u,clearQueryConfig:x}=t.useEditorActions();function f(){const c=a.getQueryData(o);n!=null&&n.queryData||s({queryKey:o,queryData:c}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),l(""),i({}),x(),d(""),m(""),p({})}return e.jsxs(t.Button,{onClick:f,className:"",size:"sm",variant:"secondary",children:[e.jsx(xs,{className:"mr-2 size-4"}),"Clear"]})}function pn(s,a){if(s.length===0)return"";if(a){const n=s.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return s[0].id;if(r&&r.endsWith("__Header")){const l=r.split("__")[0],i=s.find(d=>d.tabTitle===l);return i?i.id:s[0].id}return a}}return s[0].id}function xn(){const s=t.useQueryClient(),[a,n]=k.useState(!1),[r,o]=k.useState(!1);t.useEditorStore(C=>C.frame);const l=t.useEditorStore(C=>C.card);t.useEditorStore(C=>C.isShowingVisual),t.useEditorStore(C=>C.selectedConnectionId),t.useEditorStore(C=>C.tempQueryData),t.useEditorStore(C=>C.selectedDatabaseName),t.useEditorStore(C=>C.selectedDatamodelId),t.useEditorStore(C=>C.selectedSchemaName);const i=t.useEditorStore(C=>C.showAIDialog);t.useEditorStore(C=>C.selectedTableName);const d=t.useEditorStore(C=>{var v;return(v=C==null?void 0:C.card)==null?void 0:v.sql}),{sheetFilterValues:m}=t.useSheetFilterValues(),{setCardCustomCfg:p,setQueryResultColumns:u,setCardSql:x,setTempQueryData:f,setPythonStdOut:c,setCardPreferences:g,setCardType:h,setCardPython:j,runAssistant:b,setShowAIDialog:O}=t.useEditorActions();t.useEditorStore(C=>C.onSave),t.useEditorStore(C=>C.onClose),t.useEditorStore(C=>C.actions.setSqlGen);const E=t.useEditorStore(C=>C.runSql),z=t.useEditorStore(C=>C.actions.setRunSql),w=t.useEditorStore(C=>C.actions.setIsSqlRunning),{data:M,isLoading:R,isFetching:F,isSuccess:H,isError:S,error:N,queryKey:A,refetch:D,errorMessage:y}=t.useDashboardCardQuery(l),{handleSetAIScope:B}=Tt();k.useEffect(()=>{if(M&&(M.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),c((M==null?void 0:M.output)||""),M.records.length>0)){const{dimensionKeys:C}=t.getKeys(M.records);u(C)}},[M,u,c]),k.useEffect(()=>{(R||F)&&w(!0),(S||H)&&w(!1),S&&(u([]),c(""))},[R,F,M,c,S,H,w,u,N]),k.useEffect(()=>{E&&(s.getQueryData(A)||D(),z(!1))},[E,D,z,A,s]);async function G(){const C=`Can you help me debug this query in the current table scope?
|
|
332
342
|
|
|
333
343
|
Error:
|
|
334
344
|
|
|
335
|
-
${
|
|
345
|
+
${y}
|
|
336
346
|
|
|
337
347
|
Query:
|
|
338
348
|
|
|
339
349
|
${d}
|
|
340
350
|
|
|
341
|
-
`;v(j)}function U(){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(cn,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(ds,{className:"size-3.5 text-muted-foreground"})})]})}function V(){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(on,{})}),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(ln,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function w(){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:B||R,onClick:()=>{O()},className:"shrink-0",size:"sm",children:[B||R?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(ks,{sql:A==null?void 0:A.sql,error:S,onClick:P}),e.jsx(Ls,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:j=>n(j),className:"",size:"sm",children:e.jsx(rn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{q(),M(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ms,{}),e.jsx(As,{})]})]})}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:[V(),U()]}),w()]})}function hn({data:t}){var i;const[a,n]=I.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:m})=>{const p=m.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>m.toggleSorting(m.getIsSorted()==="asc"),children:[d,p==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsx(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:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{className:"",children:d.headers.map(m=>e.jsx(s.TableHead,{className:"h-11 font-semibold text-foreground",children:m.isPlaceholder?null:s.flexRender(m.column.columnDef.header,m.getContext())},m.id))},d.id))}),e.jsx(s.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(m=>e.jsx(s.TableCell,{className:"py-2",children:s.flexRender(m.column.columnDef.cell,m.getContext())},m.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function pn({card:t}){var M,D,L,k,A,B,R,G,g,N,T;const[a,n]=I.useState(!1),[r,o]=I.useState([]),{authToken:l}=s.useSemaphorContext(),i=s.getTokenParams(l==null?void 0:l.accessToken),d=s.useDashboardStore(O=>O.themeStyle),m={colors:((D=(M=d==null?void 0:d.chart)==null?void 0:M.dataset)==null?void 0:D.backgroundColor)||[]};(L=t.customCardPreferences)!=null&&L.inputData;const{getCard:p}=s.useCustomVisual(((k=t.customCardPreferences)==null?void 0:k.url)||""),u=((A=t.customCardPreferences)==null?void 0:A.visualType)||"single",x=s.useEditorStore(O=>O.frame),{setCustomCardPreferences:f}=s.useEditorActions(),{data:c}=s.useDashboardCardQuery(t),y=I.useCallback((O,S)=>{o(q=>({...q,[O]:S}))},[]);if(!((B=t.customCardPreferences)!=null&&B.componentName))return null;const h=p((R=t.customCardPreferences)==null?void 0:R.componentName);function C(O){n(O)}const v=Object.keys(((G=t.customCardPreferences)==null?void 0:G.dataInputCardIds)||{}).map(O=>{var P,U,V;const S=(U=(P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:U[O].cardId,q=(V=x==null?void 0:x.cards)==null?void 0:V.find(w=>w.id===S);return q||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(I.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[h&&u==="single"&&e.jsx(h,{params:i,theme:m,settings:(g=t.customCardPreferences)==null?void 0:g.settings,onDataChange:y,data:(c==null?void 0:c.records)||[]}),h&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((N=t.customCardPreferences)==null?void 0:N.dataInputCardIds)||{}).map(O=>{var P,U,V;const S=(U=(P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)==null?void 0:U[O].cardId,q=(V=x==null?void 0:x.cards)==null?void 0:V.find(w=>w.id===S);if(q)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:C,onDataChange:y,dataInputIndex:O,card:q},q.id+O)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(h,{theme:m,onDataChange:y,settings:v.map(O=>{var S;return(S=O==null?void 0:O.customCardPreferences)==null?void 0:S.settings}),data:v.map(O=>O!=null&&O.id?r==null?void 0:r[O.id]:[])})})]})]},(T=t.customCardPreferences)==null?void 0:T.componentName)})}function Os({className:t,...a}){var C;const n=s.useEditorStore(v=>v.card),r=((C=n.customCardPreferences)==null?void 0:C.showCardHeader)??!0,o=s.useEditorStore(v=>v.frame),l=s.useDashboardStore(v=>v.dashboard.filters);s.useEditorStore(v=>v.actions.setRunSql);const{updateFilter:i}=s.useDashboardActions(),d=l==null?void 0:l.find(v=>v.id===o.filterId),{data:m,isLoading:p,isFetching:u}=s.useDashboardCardQuery(n),{setCard:x}=s.useEditorActions(),{data:f}=s.useTopoJson(n),c=I.useMemo(()=>!n.id||!(m!=null&&m.records)?null:s.createChartConfig({data:m==null?void 0:m.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:f}),[n.id,m==null?void 0:m.records,n.type,n.customCfg,n.preferences,f]);function y(v){return e.jsx(pn,{card:v})}function h(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!p&&!u)return 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 records to display"})]});if(!n.id)return null;if(n.type==="custom")return y(n);if(!["table","custom"].includes(n.type)&&c)return e.jsx(e.Fragment,{children:p||u?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:c})});if(n.type==="table"&&(m!=null&&m.records)&&(m==null?void 0:m.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:n,data:m==null?void 0:m.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:n.title,onSave:v=>x({...n,title:v}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsx(s.Editable,{text:n.description||"",onSave:v=>x({...n,description:v}),children:e.jsx(s.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:d.title||d.column,onSave:v=>i({...d,title:v}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:h()})]})}const we=({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}),xn=()=>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."})]})]}),fn=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(we,{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(we,{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(we,{language:"javascript",value:t,onChange:o})})]}),gn=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function jn(){const[t,a]=I.useState(!1),[n,r]=I.useState(""),[o,l]=I.useState(""),[i,d]=I.useState(""),[m,p]=I.useState(""),u=s.useEditorStore(k=>k.card),x=s.useEditorStore(k=>k.card.customCfg),f=x?JSON.stringify(x,null,2):"",{data:c}=s.useDashboardCardQuery(u),{data:y}=s.useTopoJson(u),{setCardCustomCfg:h,setCustomVisualCode:C}=s.useEditorActions(),v=k=>{var A,B;return JSON.stringify({...k,data:{...k.data,datasets:(B=(A=k.data)==null?void 0:A.datasets)==null?void 0:B.map(R=>({...R,data:[]}))}},null,2)},M=()=>{var A,B;if(!((A=c==null?void 0:c.records)!=null&&A.length))return;const k=s.createChartConfig({data:c.records,cardType:u.type,preferences:u.preferences,topoJson:y});if(k){r(v(k)),d(((B=u.preferences)==null?void 0:B.customVisualCode)||"");const R=s.merge(k,x);l(v(R))}},D=()=>{try{if(i&&C(i),o){const k=JSON.parse(o),A=s.getObjectDiff(JSON.parse(n),k);h(A),p("")}}catch{p("Invalid JSON configuration")}},L=Object.keys(x||{}).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:M,className:L?"":"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(xn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Os,{className:"w-1/2 rounded shadow-none"})}),e.jsx(fn,{customCode:i,cardCustomCfgString:f,mergedConfig:o,onConfigChange:k=>l(k??""),onCodeChange:k=>d(k??"")})]}),e.jsx(gn,{error:m,hasCardCustomConfig:!!x,onReset:()=>{l(n),h(null)},onApply:D,onClose:()=>a(!1)})]})]})}function zs(t){return ue({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 yn(t){return ue({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 Fs(t){return ue({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 Rs(t){return ue({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 _s(t){return ue({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 Bs(t){const[a,n]=I.useState(null);return a}function Vs(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function bn({onChartTypeChange:t}){const[a,n]=I.useState([]),{data:r}=Vs();return I.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async m=>(await s.loadManifest(m.value)).visuals.map(x=>({name:x.name,icon:x.icon,url:m.value}))))).flat();n(d)}})()},[r]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((o,l)=>e.jsx(Sn,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const Sn=({text:t,icon:a,onClick:n})=>{const r=Bs(),o=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function Cn(){var x,f;const[t,a]=I.useState(!1),n=s.useEditorStore(c=>c.card),r=n.type,o=s.useDashboardStore(c=>c.isVisualEditing),{setCardType:l,setCardPreferences:i,setChartOrientation:d}=s.useEditorStore(c=>c.actions),{setCardCustomCfg:m,setCustomCardPreferences:p}=s.useEditorActions();function u(c,y){m(null),i({}),l(c),y&&p({type:"component",visualType:"single",url:y.url,componentName:y.name,icon:y.icon}),a(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:a,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(vn,{className:"size-4",chartType:r,customIcon:(x=n.customCardPreferences)==null?void 0:x.icon,componentName:(f=n.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:c=>c.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{tooltip:"Bar Chart",onClick:()=>u("bar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(ns,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(Rs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx(os,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(Fs,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(rs,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(ls,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(hs,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(zs,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>u("pyramid"),className:"h-10 p-4",children:e.jsx(gs,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(as,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(qe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(_s,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(tt,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(ms,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(xs,{className:"size-5"})})]}),e.jsx(bn,{onChartTypeChange:u})]})]})}function vn({chartType:t,className:a,customIcon:n,componentName:r}){const o=Bs();switch(t){case"bar":return e.jsx(Be,{className:a});case"line":return e.jsx(Ve,{className:a});case"pie":return e.jsx(rs,{className:a});case"radar":return e.jsx(hs,{className:a});case"scatter":return e.jsx(os,{className:a});case"bubble":return e.jsx(Fs,{className:a});case"doughnut":return e.jsx(ls,{className:a});case"stackedBar":return e.jsx(ns,{className:a});case"stackedLine":return e.jsx(Rs,{className:a});case"polarArea":return e.jsx(zs,{className:a});case"pyramid":return e.jsx(gs,{className:a});case"range":return e.jsx(as,{className:a});case"kpi":return e.jsx(_s,{className:a});case"text":return e.jsx(js,{className:a});case"map":return e.jsx(ms,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(xs,{className:a});default:return e.jsx(qe,{className:a})}}const pe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function es(t,a){var r,o,l;const n=s.getNumberAxis(t,a);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:l.type)||"linear"}function Nn(){var q,P,U,V,w,j;const[t,a]=I.useState(!1),n=s.useEditorStore(E=>{var b;return(b=E.card)==null?void 0:b.preferences}),r=s.getNumberAxis(n,{}),[o,l]=I.useState(es(n)),[i,d]=I.useState(((U=(P=(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales)==null?void 0:P[r])==null?void 0:U.min)||""),[m,p]=I.useState(((j=(w=(V=n==null?void 0:n.chartOptions)==null?void 0:V.scales)==null?void 0:w[r])==null?void 0:j.max)||""),[u,x]=I.useState(i||m?"custom":"auto"),[f,c]=I.useState(""),[y,h]=I.useState(0),[C,v]=I.useState(""),[M,D]=I.useState(""),[L,k]=I.useState(""),A=s.useEditorStore(E=>E.actions.setCardPreferences),{updateCardInFrame:B}=s.useEditorActions(),R=s.useEditorStore(E=>E.card),G=s.useEditorStore(E=>{var b;return(b=E.card)==null?void 0:b.type}),g=["pie","doughnut","polarArea"].includes(G);I.useEffect(()=>{var E,b,H,_,J,W,Z,ee,se,F,$,K,te,ie;l(es(n)),d(((H=(b=(E=n==null?void 0:n.chartOptions)==null?void 0:E.scales)==null?void 0:b[r])==null?void 0:H.min)===0?0:""),p(((W=(J=(_=n==null?void 0:n.chartOptions)==null?void 0:_.scales)==null?void 0:J[r])==null?void 0:W.max)||""),c(((F=(se=(ee=(Z=n==null?void 0:n.chartOptions)==null?void 0:Z.scales)==null?void 0:ee[r])==null?void 0:se.ticks)==null?void 0:F.stepSize)||""),h((($=n==null?void 0:n.numberAxisFormat)==null?void 0:$.decimalPlaces)||0),v(((K=n==null?void 0:n.numberAxisFormat)==null?void 0:K.suffix)||""),D(((te=n==null?void 0:n.numberAxisFormat)==null?void 0:te.currency)||""),k(((ie=n==null?void 0:n.numberAxisFormat)==null?void 0:ie.locale)||"")},[t,n,r]);function N(E,b){return b===""||/^[0-9\b]+$/.test(b)?Number(b):Number(E)}function T(){const E=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(b=>b.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:M||"none",onValueChange:b=>D(b==="none"?"":b),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"}),E.map(b=>e.jsx(s.SelectItem,{value:b,children:b},b))]})})]}),e.jsxs(s.Select,{value:L,onValueChange:b=>k(b),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(b=>e.jsx(s.SelectItem,{value:b.locale,children:b.locale},b.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:y,onChange:b=>h(Number(b.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${pe}`})]})]})}function O(){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:E=>d(b=>N(b,E.target.value)),className:`col-span-1 h-8 w-full ${pe}`}),e.jsx(s.Input,{value:m,onChange:E=>p(b=>N(b,E.target.value)),id:"max",className:`col-span-1 h-8 w-full ${pe}`})]}),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:E=>c(b=>N(b,E.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${pe}`})]})]})}function S(){var _;let E={};u==="custom"&&(E={min:i,max:m,ticks:{stepSize:f}});const b={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(_=n==null?void 0:n.chartOptions)==null?void 0:_.scales,[r]:{type:o,...o==="linear"?E:{}}}},numberAxisFormat:{decimalPlaces:y,suffix:C,currency:M,locale:L}};console.log(b),A(b);const H={...R,preferences:b};B(H)}return e.jsxs(s.Popover,{onOpenChange:E=>a(E),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(Mt,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContentCustom,{align:"center",className:"max-w-65",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:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:g,value:o,onValueChange:E=>l(E),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"})]})})]})]}),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:g,id:"scale-option",value:u,onValueChange:E=>x(E),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"})]})]})]}),u==="custom"&&o=="linear"&&O(),T(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:S,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function wn(){const t=s.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.position}),a=s.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.align}),n=s.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:a})},l=d=>{r({display:n,position:d,align:a})},i=d=>{r({display:n,position:t,align:d})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(bt,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:n,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),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:()=>l("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>l("left"),children:e.jsx(Ys,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(ts,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(Zs,{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:()=>i("start"),children:e.jsx(Ks,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Js,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(Ws,{className:"size-4"})})]})]})]})]})})]})}function kn(){var l;const t=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:a,setChartOrientation:n}=s.useEditorStore(i=>i.actions);function r(i){n(i)}const o=((l=t==null?void 0:t.chartOptions)==null?void 0:l.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(Dt,{className:"size-4"}):e.jsx(It,{className:"size-4"})})}function In(){const t=s.useEditorStore(i=>i.card),a=s.useEditorStore(i=>i.isShowingVisual),n=s.useEditorStore(i=>{var d,m;return(m=(d=i.card)==null?void 0:d.preferences)==null?void 0:m.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:o}=s.useEditorActions();function l(){const i=["xy","none","x","y"],m=(i.indexOf(r)+1)%i.length;o(i[m])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(kn,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Nn,{}),e.jsx(wn,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:l,children:[(r==="xy"||!r)&&e.jsx(gt,{className:"size-4"}),r==="x"&&e.jsx(lt,{className:"size-4"}),r==="y"&&e.jsx(At,{className:"size-4"}),r==="none"&&e.jsx(zt,{className:"size-4"})]})]}):null}function xe(){var V;const t=s.useEditorStore(w=>w.frame),a=s.useEditorStore(w=>w.card),n=s.useEditorStore(w=>w.isDevMode),r=s.useEditorStore(w=>w.isShowingVisual),o=s.useDashboardStore(w=>w.isVisualEditing),l=s.useEditorStore(w=>w.isSqlRunning),i=s.useEditorStore(w=>w.pythonStdOut),d=s.useEditorStore(w=>{var j;return(j=w.card.preferences)==null?void 0:j.chartOptions}),m=s.useEditorStore(w=>w.actions.setRunSql);s.getChartGridStyle(d);const{setFrame:p,setCard:u,updateCardInFrame:x,setActiveTabCardId:f,runAssistant:c,setChartGrid:y}=s.useEditorActions(),{data:h,isLoading:C,isFetching:v,error:M}=s.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function D(){const w={connectionId:a.connectionId,lastSelectedDatabase:a.lastSelectedDatabase,lastSelectedSchema:a.lastSelectedSchema,lastSelectedTable:a.lastSelectedTable,lastSelectedDatamodelId:a.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};L(w)}function L(w){const j={...t,cards:[...t.cards,w],activeCardId:w.id};p(j),u(w),f(w.id)}function k(){const w={...a,id:s.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};L(w)}function A(w){const j=t.cards.filter(H=>H.id!==w),E=j[0],b={...t,cards:j,activeCardId:E.id};p(b),f(E.id),u(E)}function B(w){n||R(w),f(w)}function R(w){const j={...t,cards:t.cards.map(b=>b.id===a.id?a:b),activeCardId:w};p(j);const E=j.cards.find(b=>b.id===w);E.sql&&m(!0),u(E)}const G=(w,j)=>{console.log("handleDragStart",j),w.dataTransfer.setData("tabIndex",j.toString())},g=w=>{w.preventDefault()},N=(w,j)=>{const E=w.dataTransfer.getData("tabIndex");if(E===j.toString())return;const b=Array.from(t.cards),[H]=b.splice(parseInt(E),1);b.splice(j,0,H),p({...t,cards:b})};function T(w,j){return w.cards.length===1&&(j.displayTab===!0||j.displayTab===void 0)||w.activeCardId!==j.id&&(j.displayTab===!0||j.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const E=j.displayTab===void 0?!1:!j.displayTab;u({...j,displayTab:E}),x({...j,displayTab:E})},children:j.displayTab===!0||j.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(ht,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function O(){return e.jsxs(s.Tabs,{onValueChange:B,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(w=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:w.id,children:S()},w.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((w,j)=>e.jsx(s.Editable,{text:w.tabTitle||w.title,onSave:E=>{u({...a,tabTitle:E}),x({...a,tabTitle:E})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:E=>G(E,j),onDragOver:g,onDrop:E=>N(E,j),className:"",value:w.id,children:[T(t,w),w.tabTitle||w.title,t.activeCardId===w.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>A(w.id)})]})},w.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:D,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:k,children:e.jsx(dt,{className:"h-4 w-4"})})]})})]})}function S(){return a.type==="kpi"?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.KPICard,{card:a,data:h==null?void 0:h.records})})}):a.type==="text"?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:l,card:a,data:h==null?void 0:h.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(Os,{className:"grow border-none shadow-none"})})}function q(){const w=JSON.stringify(h==null?void 0:h.records,null,2),j=new Blob([w],{type:"application/json"}),E=URL.createObjectURL(j),b=document.createElement("a");b.href=E,b.download=`${a.title}.json`,b.click()}function P(){const j=[Object.keys(h==null?void 0:h.records.reduce((_,J)=>({..._,...J}),{})).join(","),...((h==null?void 0:h.records)||[]).map(_=>Object.values(_).join(","))].join(`
|
|
342
|
-
`),E=new Blob([j],{type:"text/csv"}),b=URL.createObjectURL(E),H=document.createElement("a");H.href=b,H.download=`${a.title}.csv`,H.click()}function U(){const w=`Can you get the documentation for ${a.type} chart?`;c(w)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(C||v)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),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(Cn,{}),o&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:U,children:e.jsx(st,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(jn,{})]}),!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:P,children:e.jsx(yn,{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:q,children:e.jsx(pt,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(In,{}),e.jsx(En,{})]}),r?O():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(Dn,{})}),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:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(hn,{data:(h==null?void 0:h.records)||[]}),(M||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(M==null?void 0:M.message)||((V=h==null?void 0:h.error)==null?void 0:V.message)})]})]})]})}function Dn(){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 En(){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 Tn(){var h,C;const t=s.useEditorStore(v=>v.card.customCardPreferences),{data:a}=Vs(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(v=>v.card),o=s.useEditorStore(v=>v.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=s.useEditorActions(),{components:d,manifest:m}=s.useCustomVisual((t==null?void 0:t.url)||""),p=(h=m==null?void 0:m.visuals)==null?void 0:h.find(v=>v.name===(t==null?void 0:t.componentName));function u(v,M){if(!t)return;const L={...(t==null?void 0:t.dataInputCardIds)||{},[v]:{cardId:M,hookRef:null}};i({...t,dataInputCardIds:L})}function x(v){var D,L;const M=(D=o==null?void 0:o.cards)==null?void 0:D.filter(k=>{var A;return((A=k==null?void 0:k.customCardPreferences)==null?void 0:A.visualType)!=="multiple"}).map(k=>({value:k.id,label:k.tabTitle||k.title}));return e.jsx("div",{className:"space-y-2",children:(L=v==null?void 0:v.dataInputs)==null?void 0:L.map((k,A)=>{var B,R;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:k}),e.jsx(Y,{className:"col-span-6 h-8 w-full justify-between",label:"",options:M||[],value:((R=(B=t==null?void 0:t.dataInputCardIds)==null?void 0:B[A])==null?void 0:R.cardId)||"",onValueChange:G=>u(A,G)})]},A+Math.random())})})}function f(v,M,D=[],L=""){var k,A;return t?v==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((k=t==null?void 0:t.settings)==null?void 0:k[M])||L,onChange:B=>{i({...t,settings:{...t==null?void 0:t.settings,[M]:B.target.value}})}},M):v==="select"?e.jsx(Y,{className:"h-8 w-full",label:"",options:D,value:((A=t==null?void 0:t.settings)==null?void 0:A[M])||L,onValueChange:B=>{i({...t,settings:{...t==null?void 0:t.settings,[M]:B}})}}):null:null}function c(v){const M=Object.entries((v==null?void 0:v.settings)||{});return e.jsx("div",{className:"space-y-3",children:M.map(([D,L])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:L.title}),f(L.ui,D,L.options,L.defaultValue)]},D))})}function y(v){t&&i({...t,visualType:v,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(Y,{icon:e.jsx(et,{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:v=>i({...t||{url:"",componentName:""},url:v})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:l,onValueChange:y,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:d&&e.jsx(Y,{icon:e.jsx(ct,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(d==null?void 0:d.filter(v=>v.type===l).map(v=>({value:v.name,label:v.name})))||[],value:t.componentName,onValueChange:v=>{console.log("changing value",v),i({...t,componentName:v})}})})]})})]}),((C=r==null?void 0:r.customCardPreferences)==null?void 0:C.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(p)})})]})]})]})}function oe(){const[t,a]=I.useState([]),n=s.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=s.useEditorStore(p=>p.actions),l=s.useEditorStore(p=>p.queryResultColumns);s.useEditorStore(p=>{var u;return(u=p.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),I.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(p,u){var x,f;u?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:p,expression:""}]}):o({...n,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(c=>c.columnIndex!==p)}),a(c=>{const y=[...c];return y[p]=!1,y}))}function d(p,u){var f;const x=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(c=>c.columnIndex===p?{...c,expression:u.target.value}:c);o({...n,onClickFilter:x})}function m(p){var u,x,f,c;if(t!=null&&t[p]||(x=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(y=>y.columnIndex===p))!=null&&x.expression)return e.jsx(s.Input,{value:(c=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(y=>y.columnIndex===p))==null?void 0:c.expression,onChange:y=>d(p,y),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:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),l==null?void 0:l.map((p,u)=>{var x,f;return e.jsx("div",{className:"xbg-red-100 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:!!((x=n==null?void 0:n.onClickFilter)!=null&&x.find(c=>c.columnIndex===u)),onCheckedChange:c=>i(u,c)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(c=>c.columnIndex===u))&&e.jsx(s.Pencil,{onClick:()=>{a(c=>{const y=[...c];return y[u]=!c[u],y})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(u)]})},p)})]})}function An({idx:t}){var d;const a=s.useEditorStore(m=>{var p;return(p=m.card)==null?void 0:p.preferences}),n=s.useEditorStore(m=>{var p;return(p=m.card.preferences)==null?void 0:p.datasetOptions}),r=s.useEditorStore(m=>m.actions.setCardPreferences),o=(d=a==null?void 0:a.chartOptions)==null?void 0:d.indexAxis,l=n==null?void 0:n.find(m=>m.idx===t);function i(m,p){(m==="end"||m==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:m!=="none",align:m,anchor:m,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:p,datalabels:u}]});else{const x={...l};x.datalabels=u;const f=n==null?void 0:n.map(c=>c.idx===p?x:c);r({...a,datasetOptions:f})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Ft,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>i("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>i("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(St,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(vt,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>i("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ct,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function qs(){const t=s.useEditorStore(p=>p.card),a=s.useEditorStore(p=>{var u,x,f;return(f=(x=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:x.chartOptions)==null?void 0:f.indexAxis}),{data:n}=s.useDashboardCardQuery(t),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:l,metricKeys:i,dimensionKeys:d}=s.getKeys((n==null?void 0:n.records)||[]);let m=i;if(["stackedBar","stackedLine"].includes(t.type)){const p=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:m[0]}),{metricKeys:u}=s.getKeys(p);m=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:d.map(p=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:p,children:Ps(p)},p))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:m.map((p,u)=>e.jsx(Mn,{col:p,idx:u},p))})]})]})}function Ps(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function Mn({col:t,idx:a}){const n=s.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),r=s.useEditorStore(d=>{var m;return(m=d.card.preferences)==null?void 0:m.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===a),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function i(d){if(!o)l({...n,datasetOptions:[...r||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const m={...o};m.type=d==="area"?"line":d,m.fill=d==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===a?m:u);l({...n,datasetOptions:p})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:Ps(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Be,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ve,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(rt,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(An,{idx:a})]})]})}function Hs(){const t=s.useEditorStore(c=>c.selectedConnectionId),a=s.useEditorStore(c=>c.selectedDatamodelId),n=s.useEditorStore(c=>c.selectedDatabaseName),r=s.useEditorStore(c=>c.selectedSchemaName),o=s.useEditorStore(c=>c.selectedTableName),l=s.useDashboardStore(c=>c.dashboard.filters)||[],i=s.useDashboardStore(c=>c.actions.addFilter),d=s.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:m}=s.useDashboardActions(),{modelItems:p,tableName:u,connectionType:x}=ne();function f(c,y="dashboard"){var B;const h=s.fmt(c.column_name),C=s.fmt(n||""),v=s.fmt(r||""),M=s.fmt(u);let D=s.getQualifiedTableName({schemaName:v,tableName:M,connectionType:x,databaseName:C}),L=`${D}.${h}`;const k=(B=p==null?void 0:p.find(R=>R.id===a))==null?void 0:B.name;a&&a!=="none"&&(L=`${s.DATAMODEL_NAMESPCACE}.${k}.${h}`,D=`${s.DATAMODEL_NAMESPCACE}.${k}`);const A=l==null?void 0:l.find(R=>R.column===L&&R.table===M&&(R.database===C||R.database===n));if(A)m(A.id),d(A.id);else{const R=s.v4();return u==="api"&&t?(i({location:y,id:R,column:L,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(c.data_type,D,h)}),R):(i({id:R,location:y,column:L,title:c.column_name,dataType:c.data_type,table:o||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(c.data_type,D,h)}),R)}}return{assignFilter:f}}function me(){const t=s.useDashboardStore(d=>d.dashboard.filters),a=s.useEditorStore(d=>d.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=ne(),{assignFilter:o}=Hs();function l(d){const m=o(d,"frame");n({...a,filterId:m})}const i=t==null?void 0:t.find(d=>d.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Ln,{onSelect:l,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function Ln({columns:t,onSelect:a}){var i;const[n,r]=de.useState(!1),[o,l]=de.useState("");return e.jsxs(s.Popover,{open:n,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=t.find(d=>d.column_name===o))==null?void 0:i.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(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:m=>{const p=m===o?"":m;l(p),r(!1),p&&a(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function On({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(qs,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Ge(){var o,l,i;const t=s.useEditorStore(d=>d.card.type),a=s.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=s.useEditorStore(d=>d.actions);function r(d){var u;const m={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},p={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(u=a==null?void 0:a.chartOptions)==null?void 0:u.plugins,...m}}};n(p),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((i=(l=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,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"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function zn({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:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ge,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}const Fn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Rn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function _n(){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:Bn(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ge,{}),e.jsx(oe,{}),e.jsx(me,{})]})]})}function Bn(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(Fn,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(Rn,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"].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 Vn(){var m,p,u,x,f;const t=s.useEditorStore(c=>c.card.preferences),a=s.useEditorStore(c=>c.actions.setCardPreferences),n=s.useEditorStore(c=>c.actions.setNumberFormat);s.useEditorStore(c=>{var y,h;return(h=(y=c.card.preferences)==null?void 0:y.formatNumber)==null?void 0:h.decimalPlaces});const r=s.useEditorStore(c=>{var y,h;return(h=(y=c.card.preferences)==null?void 0:y.formatNumber)==null?void 0:h.locale}),o=s.useEditorStore(c=>{var y,h;return(h=(y=c.card.preferences)==null?void 0:y.formatNumber)==null?void 0:h.currency});s.useEditorStore(c=>c.actions.setFilterOnClickField);const l=s.useEditorStore(c=>{var y,h;return(h=(y=c.card.preferences)==null?void 0:y.formatNumber)==null?void 0:h.colorRanges})||[],i=s.useEditorStore(c=>c.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((m=t==null?void 0:t.formatNumber)!=null&&m.enabled),onCheckedChange:c=>{a({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:c}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((p=t==null?void 0:t.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:c=>{var y,h,C;return n(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((h=t==null?void 0:t.formatNumber)==null?void 0:h.currency)||"",c,((C=t==null?void 0:t.formatNumber)==null?void 0:C.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(c=>e.jsx(s.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:c=>{var y,h,C;console.log("currency",c),n(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,c==="none"?"":c,((h=t==null?void 0:t.formatNumber)==null?void 0:h.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(c=>e.jsx(s.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((x=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:c=>{var y,h,C;return n(Number(c),((y=t==null?void 0:t.formatNumber)==null?void 0:y.currency)||"",((h=t==null?void 0:t.formatNumber)==null?void 0:h.locale)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsx(s.SelectItem,{value:c,children:c},c))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((f=t==null?void 0:t.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var y,h,C;return n(((y=t==null?void 0:t.formatNumber)==null?void 0:y.decimalPlaces)||0,((h=t==null?void 0:t.formatNumber)==null?void 0:h.currency)||"",((C=t==null?void 0:t.formatNumber)==null?void 0:C.locale)||"",c.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function qn(){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(Vn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function ke({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 Pn=[{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"}],Hn=["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"],Gn=Hn.map(t=>({label:t,value:t}));function Un(){var m,p,u,x,f,c,y,h,C,v,M,D,L,k,A,B,R,G;const t=s.useEditorStore(g=>g.card),a=(p=(m=t==null?void 0:t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.topoJsonUrl,[n,r]=I.useState(((x=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),i=Object.keys((l==null?void 0:l.objects)||{}).map(g=>({label:g,value:g}))||[],d=[{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(ke,{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(ke,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(Y,{className:"h-9",options:d,onValueChange:g=>{console.log("value",g),o({...t.preferences,mapVisualOptions:{topoJsonUrl:g}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:g=>{r(g.target.value)},onBlur:()=>{var g;console.log("onBlur",n),o({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(Y,{className:"h-9",options:i,value:((c=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:g=>{var N;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,objectKey:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(Y,{className:"h-9",options:Pn,value:((h=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:h.projection)||"",label:"Projection",onValueChange:g=>{var N;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,projection:g}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(Y,{className:"h-9",options:Gn,value:((v=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:v.colorScale)||"",label:"Select Color Scale",onValueChange:g=>{var N;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,colorScale:g}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ke,{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:((D=(M=t.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:g=>{var N;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,projectionScale:Number(g.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((A=(k=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:k.projectionOffset)==null?void 0:A[0])||0,onChange:g=>{var N,T,O,S;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[Number(g.target.value),((S=(O=(T=t.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:S[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((G=(R=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:G[1])||0,onChange:g=>{var N,T,O,S;o({...t.preferences,mapVisualOptions:{...(N=t.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[((S=(O=(T=t.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:S[0])||0,Number(g.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function $n(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=s.useEditorStore(o=>o.actions);function n(o){a({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function fe({cardType:t,docContent:a,suffix:n="Chart"}){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)} ${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:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(Ge,{}),t==="text"&&e.jsx($n,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Qn(){const t=s.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:a}=s.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(Y,{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(qs,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Jn({cardType:t="table"}){console.log("cardType",t);const a=s.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),n=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Kn=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."]})]}),Wn=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."]})]}),Yn=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 Zn(){const t=s.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Qn,{});case"pyramid":return e.jsx(fe,{docContent:Kn,cardType:n});case"kpi":return e.jsx(qn,{});case"line":case"bar":return e.jsx(On,{cardType:n});case"range":return e.jsx(fe,{docContent:Wn,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(fe,{cardType:n});case"bubble":case"scatter":return e.jsx(zn,{cardType:n});case"table":return e.jsx(Jn,{cardType:n});case"text":return e.jsx(fe,{docContent:Yn,cardType:n,suffix:"Visual"});case"map":return e.jsx(Un,{});case"custom":return e.jsx(Tn,{});default:return e.jsx(_n,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}const Ie={id:"__placeholder__",role:"groupby",type:"string"},De={id:"__placeholder__",role:"metric",type:"number"},Ee={id:"__placeholder__",role:"trendby",type:"date"},Te={id:"__placeholder__",role:"filter",type:"string"},Xn={id:"__placeholder__"},Se="droppable-group-by",Ce="droppable-metrics",Le="sortable-group-by",Oe="sortable-metrics",ze="droppable-trend-by",Fe="sortable-trend-by",Re="droppable-filters",_e="sortable-filters";function ea(){const t=s.useDndStore(g=>g.insertIndex),a=s.useEditorStore(g=>{var N;return((N=g.card.queryConfig)==null?void 0:N.groupByColumns)||[]}),n=s.useEditorStore(g=>{var N;return((N=g.card.queryConfig)==null?void 0:N.metricColumns)||[]}),r=s.useEditorStore(g=>{var N;return((N=g.card.queryConfig)==null?void 0:N.trendByColumns)||[]}),o=s.useEditorStore(g=>{var N;return((N=g.card.queryConfig)==null?void 0:N.filterColumns)||[]}),{setInsertIndex:l,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:m,setPreviewTrendByColumns:p,setPreviewFilterColumns:u}=s.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setTrendByColumns:c,setFilterColumns:y}=s.useEditorActions(),{columns:h}=Ns(),C=s.useSensors(s.useSensor(s.MouseSensor,{activationConstraint:{distance:1}})),v=g=>{var O;const{active:N,over:T}=g;if(((O=N.data.current)==null?void 0:O.type)==="column"&&T){const S=T.id,q=h.find(w=>w.column_name===N.id);if(!q)return;const P=s.isNumberDataType(q.data_type),U=s.isTextDataType(q.data_type),V=s.isDateDataType(q.data_type);if(U){if(a.some(j=>j.id===S)){const j=a.findIndex(b=>b.id===S);l(j);const E=a.filter(b=>b.id!==Ie.id);E.splice(j,0,Ie),d(E)}else if(T.id===Se){l(a.length);const j=[...a,Ie];d(j),m(n),p(r),u(o)}}if(P||U){if(n.some(j=>j.id===S)){console.log("isOverMetricSortable",S);const j=n.findIndex(b=>b.id===S);l(j);const E=n.filter(b=>b.id!==De.id);E.splice(j,0,De),m(E)}else if(T.id===Ce){l(n.length);const j=[...n,De];m(j),p(r),u(o),d(a)}}if(V){if(r.some(j=>j.id===S)){const j=r.findIndex(b=>b.id===S);l(j);const E=r.filter(b=>b.id!==Ee.id);E.splice(j,0,Ee),p(E)}else if(T.id===ze){l(r.length);const j=[...r,Ee];p(j),m(n),u(o),d(a)}}if(D(q)){if(o.some(j=>j.id===S)){const j=o.findIndex(b=>b.id===S);l(j);const E=o.filter(b=>b.id!==Te.id);E.splice(j,0,Te),u(E)}else if(T.id===Re){l(o.length);const j=[...o,Te];u(j),m(n),p(r),d(a)}}}else d(a),m(n),p(r),u(o)};function M(g){i(g.active.id),l(null),d(a),m(n),p(r),u(o)}function D(g){return!o.some(N=>N.name===g.column_name)}function L(g,N="SUM"){const{column_name:T,data_type:O}=g,S=[...n],q=t!==null?t:n.length,P={...g,id:ae(T),name:T,label:je(N,T),type:O,role:"metric",aggregate:N};S.splice(q,0,P),f(S)}function k(g){const N=[...a],T=t!==null?t:a.length,O={...g,id:ae(g.column_name),name:g.column_name,type:g.data_type,role:"groupby"};N.splice(T,0,O),x(N)}function A(g){const N=[...r],T=t!==null?t:r.length,O={...g,id:ae(g.column_name),name:g.column_name,type:g.data_type,role:"trendby"};N.splice(T,0,O),c(N)}function B(g){const N=[...o],T=t!==null?t:o.length,O={...g,id:ae(g.column_name),name:g.column_name,type:g.data_type,role:"filter"};N.splice(T,0,O),y(N)}function R(g){var S,q,P,U,V,w,j,E;const{active:N,over:T}=g,O=N.data.current;if((O==null?void 0:O.type)==="column"&&T){const b=h.find(W=>W.column_name===N.id);if(!b)return;const H=s.isNumberDataType(b.data_type),_=s.isTextDataType(b.data_type),J=s.isDateDataType(b.data_type);_&&(T.id===Se||((S=T.data.current)==null?void 0:S.type)===Le)?k(b):(H||_)&&(T.id===Ce||((q=T.data.current)==null?void 0:q.type)===Oe)?(H&&L(b),_&&L(b,"COUNT")):J&&(T.id===ze||((P=T.data.current)==null?void 0:P.type)===Fe)?A(b):D(b)&&(T.id===Re||((U=T.data.current)==null?void 0:U.type)===_e)&&B(b)}if(T&&((V=T.data.current)==null?void 0:V.type)===Le&&a.some(b=>b.id===N.id)){const b=a.findIndex(_=>_.id===N.id),H=a.findIndex(_=>_.id===T.id);if(b!==-1&&H!==-1&&b!==H){const _=[...a],[J]=_.splice(b,1);_.splice(H,0,J),x(_)}}if(T&&((w=T.data.current)==null?void 0:w.type)===Oe&&n.some(b=>b.id===N.id)){const b=n.findIndex(_=>_.id===N.id),H=n.findIndex(_=>_.id===T.id);if(b!==-1&&H!==-1&&b!==H){const _=[...n],[J]=_.splice(b,1);_.splice(H,0,J),f(_)}}if(T&&((j=T.data.current)==null?void 0:j.type)===Fe&&r.some(b=>b.id===N.id)){const b=r.findIndex(_=>_.id===N.id),H=r.findIndex(_=>_.id===T.id);if(b!==-1&&H!==-1&&b!==H){const _=[...r],[J]=_.splice(b,1);_.splice(H,0,J),c(_)}}if(T&&((E=T.data.current)==null?void 0:E.type)===_e&&o.some(b=>b.id===N.id)){const b=o.findIndex(_=>_.id===N.id),H=o.findIndex(_=>_.id===T.id);if(b!==-1&&H!==-1&&b!==H){const _=[...o],[J]=_.splice(b,1);_.splice(H,0,J),y(_)}}i(null),l(null),d(a),m(n),p(r),u(o)}function G(){i(null),l(null),d(a),m(n),p(r),u(o)}return{handleDragOver:v,handleDragEnd:R,handleDragStart:M,handleDragCancel:G,sensors:C}}const ce=[{label:"Sum",value:"SUM",logo:e.jsx(fs,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(us,{className:"size-3.5"})},{label:"Count Distinct",value:"DISTINCT",logo:e.jsx(xt,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Xs,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(ts,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(s.ArrowUp,{className:"size-3.5"})}];function Gs({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=I.useState(!1),[i,d]=I.useState(ce[0]),{attributes:m,listeners:p,setNodeRef:u,transform:x,transition:f,isDragging:c}=s.useSortable({id:t.id,data:{type:a}}),y=x?{opacity:c?.5:void 0,transform:s.CSS.Translate.toString(x),transition:f}:void 0;function h(){return e.jsx("div",{"data-setting-container":"",className:"h-32 rounded-b-md border-x border-b border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}return e.jsxs("div",{...p,...m,ref:u,style:y,children:[e.jsxs("div",{className:s.cn("group flex h-9 items-center rounded-t-md bg-muted pl-0.5 pr-2.5",!o&&"rounded-b-md",o&&"border border-border",{"pl-2":r===Se}),children:[r===Ce&&e.jsx(ta,{column:t}),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:"max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",children:e.jsx(sa,{col:t})}),e.jsxs("div",{"data-setting-actions":"",className:"hidden h-full items-center gap-2 group-hover:flex",children:[e.jsx("button",{onClick:()=>l(!o),children:e.jsx(s.ChevronDown,{className:s.cn("ml-1 size-4 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground",o&&"rotate-180")})}),e.jsx("button",{onClick:()=>n(t.id),children:e.jsx(s.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground"})})]})]}),o&&h()]})}function sa({col:t}){return e.jsx(s.Editable,{text:t.label||t.name,className:"h-6 rounded-none",onSave:a=>{console.log("saved",a)},children:e.jsx("span",{className:"w-[250px] truncate text-ellipsis whitespace-nowrap text-sm",children:t.label||t.name})})}function ta({column:t}){const[a,n]=I.useState(ce[0]),{updateMetricColumn:r}=s.useEditorActions();let o=ce;s.isTextDataType(t.type)&&(o=o.filter(i=>["COUNT","DISTINCT"].includes(i.value))),s.isNumberDataType(t.type)&&(o=o.filter(i=>!["DISTINCT","COUNT"].includes(i.value))),I.useEffect(()=>{n(ce.find(i=>i.value===t.aggregate)||ce[0])},[t]);function l(i){const d=ce.find(p=>p.value===i);if(!d)return;n(d);const m={...t,aggregate:i,label:je(i,t.name)};r(t.id,m)}return e.jsx(Y,{className:"size-7 overflow-clip rounded-none rounded-l-md border-none bg-muted px-2",icon:a.logo,options:o,value:a.value,onValueChange:i=>l(i),label:"Aggregation"})}function Ae({id:t,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=s.useDroppable({id:t}),d=s.useDndStore(u=>u.activeId),m={},p=d?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(u=>u.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:m,children:[e.jsx(s.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:p==null?void 0:p.map(u=>u.id===Xn.id?e.jsx(na,{},u.id):e.jsx(Gs,{droppableId:t,type:o,column:u,onRemoveColumn:l},u.id))})]})})}function na(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function ss(){const t=s.useEditorStore(c=>{var y;return((y=c.card.queryConfig)==null?void 0:y.groupByColumns)||[]}),a=s.useDndStore(c=>c.previewGroupByColumns),n=s.useEditorStore(c=>{var y;return((y=c.card.queryConfig)==null?void 0:y.metricColumns)||[]}),r=s.useDndStore(c=>c.previewMetricColumns),o=s.useEditorStore(c=>{var y;return((y=c.card.queryConfig)==null?void 0:y.trendByColumns)||[]}),l=s.useDndStore(c=>c.previewTrendByColumns),{setSelectedConnectionId:i,removeColumnFromGroupBy:d,removeColumnFromMetricColumns:m,removeColumnFromTrendByColumns:p}=s.useEditorActions();I.useEffect(()=>{i("c_2d3646f0-68a6-47e7-942d-d9cbc80fb7d4")},[i]);function u(c){d(c)}function x(c){p(c)}function f(c){m(c)}return e.jsxs("div",{className:"h-full w-full space-y-2 p-4",children:[e.jsx(Ae,{onRemoveColumn:u,sortableType:Le,id:Se,label:"Group By",columns:t,previewColumns:a}),e.jsx(Ae,{onRemoveColumn:x,sortableType:Fe,id:ze,label:"Trend By",columns:o,previewColumns:l}),e.jsx(Ae,{onRemoveColumn:f,sortableType:Oe,id:Ce,label:"Metrics",columns:n,previewColumns:r})]})}function aa({id:t,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i,isOver:d}=s.useDroppable({id:t}),m=s.useDndStore(x=>x.activeId),p={borderColor:d?"green":void 0},u=m?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:p,children:[e.jsx(s.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap gap-4",children:u==null?void 0:u.map(x=>e.jsx(Gs,{droppableId:t,type:o,column:x,onRemoveColumn:l},x.id))})]})})}function ra(){const t=s.useEditorStore(o=>{var l;return((l=o.card.queryConfig)==null?void 0:l.filterColumns)||[]}),a=s.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=s.useEditorActions();function r(o){n(o)}return e.jsx("div",{className:"size-full p-4",children:e.jsx(aa,{onRemoveColumn:r,sortableType:_e,id:Re,label:"Filters",renderComponent:o=>e.jsx(ge,{className:"rounded-md bg-muted",column:{column_name:o.name,data_type:o.type}}),columns:t,previewColumns:a})})}function oa(){const t=s.useEditorStore(r=>r.card),{data:a,errorMessage:n}=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(Ls,{}),e.jsx(ks,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(Ms,{}),e.jsx(As,{variant:"default"})]})]})}function ia(){const t=I.useRef(null),a=s.useEditorStore(i=>i.isShowingVisual),n=s.useEditorStore(i=>i.showAIDialog),r=s.useEditorStore(i=>i.isDevMode);I.useEffect(()=>{var i,d;n?(i=t.current)==null||i.resize(0):(d=t.current)==null||d.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(mn,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?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:r?e.jsx(Zn,{}):e.jsx(ss,{})})}),!n&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(xe,{})})]}):e.jsx(xe,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(ss,{})})}),!n&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,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(oa,{}),e.jsx(ra,{})]}),e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:20,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:r?o():l()})}const la=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function ca(){const t=I.useRef(null),a=I.useRef(null),[n,r]=I.useState(!1),[o,l]=I.useState(s.isDevEnv),[i,d]=I.useState(!1),m=s.useEditorStore(V=>V.actions.setCardSql),p=s.useEditorStore(V=>V.actions.setRunSql),u=s.useEditorStore(V=>V.showAIDialog),{setShowAIDialog:x}=s.useEditorActions(),{messages:f,setMessages:c,reload:y,append:h,input:C,setInput:v,isLoading:M,handleAddCurrentTableToScope:D,removeFromCurrentSelections:L,currentAssitantScope:k,handleInputChange:A,handleSubmit:B,stop:R,chatStatus:G,toolStatus:g,llmUsage:N,errorMessage:T}=Ts();s.useAssistantScroll({scrollContainerRef:t,inputRef:a,messages:f}),I.useEffect(()=>{var V;u&&((V=a.current)==null||V.focus())},[u]);function O(V){m(V),p(!0)}function S(V){const w={role:"user",content:V.title+" "+V.subtitle};h(w)}function q(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(cs,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"System Message"})]})]})}function P(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),k&&k.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:k==null?void 0:k.map((V,w)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:V.schemaName||"",tableName:V.tableName||"",modelName:V.datamodelName||"",connectionType:V.connectionType||"",databaseName:V.databaseName||""}),e.jsx("button",{onClick:()=>{L(V)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},w))}),(k==null?void 0:k.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:D,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const U=(C==null?void 0:C.length)===0&&(f==null?void 0:f.filter(V=>V.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[P(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[q(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),y()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{x(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"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:f,showTools:o,handleRun:O,showSystemMessage:i}),e.jsx(s.ChatStatus,{status:s.getStatus(G,g),isLoading:M})]})}),U&&e.jsx(s.Placeholders,{onClick:S,placeholders:la}),e.jsx(s.ChatInput,{onFocus:()=>{D()},stop:R,ref:a,setInput:v,input:C,handleInputChange:A,handleSubmit:B,isLoading:M}),N&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",N.promptTokens," prompt tokens,"," ",N.completionTokens," completion tokens,"," ",N.totalTokens," total tokens"]})}),T&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:T})})]})}function da({authToken:t,onSave:a,onClose:n}){const r=I.useRef(null),o=s.useEditorStore(C=>C.showAIDialog),{setAuthToken:l}=s.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:m}=s.useEditorActions(),{handleDragOver:p,handleDragEnd:u,handleDragStart:x,handleDragCancel:f,sensors:c}=ea();I.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),I.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),I.useEffect(()=>{var C,v;o?((C=r.current)==null||C.resize(40),i(!0)):(i(!1),(v=r.current)==null||v.resize(0))},[o,i]);function y(C){C<1?i(!1):o||i(!0)}function h(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ia,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:y,defaultSize:0,children:e.jsx(ca,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsx(s.DndContext,{sensors:c,onDragStart:x,onDragEnd:u,onDragOver:p,onDragCancel:f,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(ws,{type:"main"}),h()]})})})}function ua(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=s.useDashboardStore(i=>i.actions),n=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function o(i){t&&(r(t,i),a(!1))}function l(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(da,{onSave:o,onClose:l})})}function ma(){const t=s.useEditorStore(l=>l.selectedDatabaseName),a=s.useEditorStore(l=>l.selectedTableName),n=s.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=ne(),{assignFilter:o}=Hs();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=n==null?void 0:n.find(d=>d.column===s.fmt(l.column_name)&&d.table===a&&d.database===t);return e.jsx("div",{onClick:()=>o(l),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":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ha(){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(ws,{type:"filter",ColumnsComponent:()=>e.jsx(ma,{})})})]})}function pa(){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 xa(){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(pa,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ha,{})})]})}function fa(){const t=s.useDashboardStore(o=>o.dashboard),a=s.useDashboardStore(o=>o.actions.setDashboard),n=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!n}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function ga({showControls:t=!1,showFooter:a=!0,...n}){return 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(fa,{}),e.jsxs(s.DashboardPanel,{...n,children:[t&&e.jsx($t,{}),e.jsx(ua,{}),e.jsx(xa,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.resolveDatamodelName=s.resolveDatamodelName;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.ScheduleDashboard=Cs;exports.SelectComponent=le;exports.Surfboard=ga;exports.cleanCard=ys;exports.downloadPdf=Ss;exports.getDashbaordStateWithoutData=Pe;exports.useEditorAside=ne;
|
|
351
|
+
`;b(C)}function $(){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(mn,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(t.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(t.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(dt,{className:"size-3.5 text-muted-foreground"})})]})}function q(){return e.jsxs(t.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(t.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(dn,{})}),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(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(t.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(un,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function I(){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(t.Button,{title:"Shift + Enter",disabled:R||F,onClick:()=>{D()},className:"shrink-0",size:"sm",children:[R||F?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(kt,{sql:M==null?void 0:M.sql,error:y,onClick:G}),e.jsx(Lt,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:C=>n(C),className:"",size:"sm",children:e.jsx(cn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{B(),O(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Mt,{}),e.jsx(At,{})]})]})}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:[q(),$()]}),I()]})}function fn({data:s}){var i;const[a,n]=k.useState([]),o=Object.keys(s[0]).map(d=>({accessorKey:d,header:({column:m})=>{const p=m.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>m.toggleSorting(m.getIsSorted()==="asc"),children:[d,p==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=t.useReactTable({data:s,columns:o,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsx(t.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(t.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:l.getHeaderGroups().map(d=>e.jsx(t.TableRow,{className:"",children:d.headers.map(m=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:m.isPlaceholder?null:t.flexRender(m.column.columnDef.header,m.getContext())},m.id))},d.id))}),e.jsx(t.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(d=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(m=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(m.column.columnDef.cell,m.getContext())},m.id))},d.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function gn({card:s}){var O,E,z,w,M,R,F,H,S,N,A;const[a,n]=k.useState(!1),[r,o]=k.useState([]),{authToken:l}=t.useSemaphorContext(),i=t.getTokenParams(l==null?void 0:l.accessToken),d=t.useDashboardStore(D=>D.themeStyle),m={colors:((E=(O=d==null?void 0:d.chart)==null?void 0:O.dataset)==null?void 0:E.backgroundColor)||[]};(z=s.customCardPreferences)!=null&&z.inputData;const{getCard:p}=t.useCustomVisual(((w=s.customCardPreferences)==null?void 0:w.url)||""),u=((M=s.customCardPreferences)==null?void 0:M.visualType)||"single",x=t.useEditorStore(D=>D.frame),{setCustomCardPreferences:f}=t.useEditorActions(),{data:c}=t.useDashboardCardQuery(s),g=k.useCallback((D,y)=>{o(B=>({...B,[D]:y}))},[]);if(!((R=s.customCardPreferences)!=null&&R.componentName))return null;const h=p((F=s.customCardPreferences)==null?void 0:F.componentName);function j(D){n(D)}const b=Object.keys(((H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)||{}).map(D=>{var G,$,q;const y=($=(G=s.customCardPreferences)==null?void 0:G.dataInputCardIds)==null?void 0:$[D].cardId,B=(q=x==null?void 0:x.cards)==null?void 0:q.find(I=>I.id===y);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(k.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[h&&u==="single"&&e.jsx(h,{params:i,theme:m,settings:(S=s.customCardPreferences)==null?void 0:S.settings,onDataChange:g,data:(c==null?void 0:c.records)||[]}),h&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((N=s.customCardPreferences)==null?void 0:N.dataInputCardIds)||{}).map(D=>{var G,$,q;const y=($=(G=s.customCardPreferences)==null?void 0:G.dataInputCardIds)==null?void 0:$[D].cardId,B=(q=x==null?void 0:x.cards)==null?void 0:q.find(I=>I.id===y);if(B)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:j,onDataChange:g,dataInputIndex:D,card:B},B.id+D)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(h,{theme:m,onDataChange:g,settings:b.map(D=>{var y;return(y=D==null?void 0:D.customCardPreferences)==null?void 0:y.settings}),data:b.map(D=>D!=null&&D.id?r==null?void 0:r[D.id]:[])})})]})]},(A=s.customCardPreferences)==null?void 0:A.componentName)})}function Ot({className:s,...a}){var j;const n=t.useEditorStore(b=>b.card),r=((j=n.customCardPreferences)==null?void 0:j.showCardHeader)??!0,o=t.useEditorStore(b=>b.frame),l=t.useDashboardStore(b=>b.dashboard.filters);t.useEditorStore(b=>b.actions.setRunSql);const{updateFilter:i}=t.useDashboardActions(),d=l==null?void 0:l.find(b=>b.id===o.filterId),{data:m,isLoading:p,isFetching:u}=t.useDashboardCardQuery(n),{setCard:x}=t.useEditorActions(),{data:f}=t.useTopoJson(n),c=k.useMemo(()=>!n.id||!(m!=null&&m.records)?null:t.createChartConfig({data:m==null?void 0:m.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:f}),[n.id,m==null?void 0:m.records,n.type,n.customCfg,n.preferences,f]);function g(b){return e.jsx(gn,{card:b})}function h(){if(m!=null&&m.records&&(m==null?void 0:m.records.length)===0&&!p&&!u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(t.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(!n.id)return null;if(n.type==="custom")return g(n);if(!["table","custom"].includes(n.type)&&c)return e.jsx(e.Fragment,{children:p||u?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:c})});if(n.type==="table"&&(m!=null&&m.records)&&(m==null?void 0:m.records.length)>0)return e.jsxs(t.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(t.TableVisual,{card:n,data:m==null?void 0:m.records}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",s),...a,children:[r&&e.jsxs(t.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(t.Editable,{text:n.title,onSave:b=>x({...n,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(t.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsx(t.Editable,{text:n.description||"",onSave:b=>x({...n,description:b}),children:e.jsx(t.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{className:"my-1",text:d.title||d.column,onSave:b=>i({...d,title:b}),children:e.jsx(t.Label,{children:d.title})}),e.jsx(t.FilterComponent,{filter:d})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:h()})]})}const we=({language:s,value:a,onChange:n,readonly:r})=>e.jsx(t.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:s,value:a,onChange:n}),jn=()=>e.jsxs(t.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(t.DialogTitle,{children:"Customize Card"})}),e.jsxs(t.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."})]})]}),yn=({customCode:s,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(we,{language:"json",value:n,onChange:r})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(we,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(we,{language:"javascript",value:s,onChange:o})})]}),bn=({error:s,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(t.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:o,variant:"outline",children:"Close"})]});function Sn(){const[s,a]=k.useState(!1),[n,r]=k.useState(""),[o,l]=k.useState(""),[i,d]=k.useState(""),[m,p]=k.useState(""),u=t.useEditorStore(w=>w.card),x=t.useEditorStore(w=>w.card.customCfg),f=x?JSON.stringify(x,null,2):"",{data:c}=t.useDashboardCardQuery(u),{data:g}=t.useTopoJson(u),{setCardCustomCfg:h,setCustomVisualCode:j}=t.useEditorActions(),b=w=>{var M,R;return JSON.stringify({...w,data:{...w.data,datasets:(R=(M=w.data)==null?void 0:M.datasets)==null?void 0:R.map(F=>({...F,data:[]}))}},null,2)},O=()=>{var M,R;if(!((M=c==null?void 0:c.records)!=null&&M.length))return;const w=t.createChartConfig({data:c.records,cardType:u.type,preferences:u.preferences,topoJson:g});if(w){r(b(w)),d(((R=u.preferences)==null?void 0:R.customVisualCode)||"");const F=t.merge(w,x);l(b(F))}},E=()=>{try{if(i&&j(i),o){const w=JSON.parse(o),M=t.getObjectDiff(JSON.parse(n),w);h(M),p("")}}catch{p("Invalid JSON configuration")}},z=Object.keys(x||{}).length===0;return e.jsxs(t.Dialog,{open:s,onOpenChange:a,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Customize Visual",onClick:O,className:z?"":"text-green-600 hover:text-green-700",children:e.jsx(t.Settings,{className:"h-4 w-4"})})}),e.jsxs(t.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(jn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Ot,{className:"w-1/2 rounded shadow-none"})}),e.jsx(yn,{customCode:i,cardCustomCfgString:f,mergedConfig:o,onConfigChange:w=>l(w??""),onCodeChange:w=>d(w??"")})]}),e.jsx(bn,{error:m,hasCardCustomConfig:!!x,onReset:()=>{l(n),h(null)},onApply:E,onClose:()=>a(!1)})]})]})}function zt(s){return ue({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:[]}]})(s)}function Cn(s){return ue({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:[]}]})(s)}function Ft(s){return ue({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:[]}]})(s)}function Rt(s){return ue({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:[]}]})(s)}function _t(s){return ue({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:[]}]})(s)}function Vt(s){const[a,n]=k.useState(null);return a}function Bt(){const{authToken:s}=t.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=t.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>t.getPlugins(s==null?void 0:s.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function vn({onChartTypeChange:s}){const[a,n]=k.useState([]),{data:r}=Bt();return k.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async m=>(await t.loadManifest(m.value)).visuals.map(x=>({name:x.name,icon:x.icon,url:m.value}))))).flat();n(d)}})()},[r]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((o,l)=>e.jsx(Nn,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+l))})]})}const Nn=({text:s,icon:a,onClick:n})=>{const r=Vt(),o=s.charAt(0).toUpperCase();return e.jsx(t.IconButton,{onClick:n,tooltip:s,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function wn(){var x,f;const[s,a]=k.useState(!1),n=t.useEditorStore(c=>c.card),r=n.type,o=t.useDashboardStore(c=>c.isVisualEditing),{setCardType:l,setCardPreferences:i,setChartOrientation:d}=t.useEditorStore(c=>c.actions),{setCardCustomCfg:m,setCustomCardPreferences:p}=t.useEditorActions();function u(c,g){m(null),i({}),l(c),g&&p({type:"component",visualType:"single",url:g.url,componentName:g.name,icon:g.icon}),a(!1)}return e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(kn,{className:"size-4",chartType:r,customIcon:(x=n.customCardPreferences)==null?void 0:x.icon,componentName:(f=n.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:c=>c.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(t.IconButton,{tooltip:"Bar Chart",onClick:()=>u("bar"),className:"h-10 p-4",children:e.jsx(Ve,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(nt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(Rt,{className:"size-5",strokeWidth:0})}),e.jsx(t.IconButton,{tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx(ot,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(Ft,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(rt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(lt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(ht,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(zt,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Pyramid Chart",onClick:()=>u("pyramid"),className:"h-10 p-4",children:e.jsx(gt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(at,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(qe,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(_t,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(rs,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(mt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(xt,{className:"size-5"})})]}),e.jsx(vn,{onChartTypeChange:u})]})]})}function kn({chartType:s,className:a,customIcon:n,componentName:r}){const o=Vt();switch(s){case"bar":return e.jsx(Ve,{className:a});case"line":return e.jsx(Be,{className:a});case"pie":return e.jsx(rt,{className:a});case"radar":return e.jsx(ht,{className:a});case"scatter":return e.jsx(ot,{className:a});case"bubble":return e.jsx(Ft,{className:a});case"doughnut":return e.jsx(lt,{className:a});case"stackedBar":return e.jsx(nt,{className:a});case"stackedLine":return e.jsx(Rt,{className:a});case"polarArea":return e.jsx(zt,{className:a});case"pyramid":return e.jsx(gt,{className:a});case"range":return e.jsx(at,{className:a});case"kpi":return e.jsx(_t,{className:a});case"text":return e.jsx(jt,{className:a});case"map":return e.jsx(mt,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(xt,{className:a});default:return e.jsx(qe,{className:a})}}const pe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function tt(s,a){var r,o,l;const n=t.getNumberAxis(s,a);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:l.type)||"linear"}function In(){var B,G,$,q,I,C;const[s,a]=k.useState(!1),n=t.useEditorStore(v=>{var T;return(T=v.card)==null?void 0:T.preferences}),r=t.getNumberAxis(n,{}),[o,l]=k.useState(tt(n)),[i,d]=k.useState((($=(G=(B=n==null?void 0:n.chartOptions)==null?void 0:B.scales)==null?void 0:G[r])==null?void 0:$.min)||""),[m,p]=k.useState(((C=(I=(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales)==null?void 0:I[r])==null?void 0:C.max)||""),[u,x]=k.useState(i||m?"custom":"auto"),[f,c]=k.useState(""),[g,h]=k.useState(0),[j,b]=k.useState(""),[O,E]=k.useState(""),[z,w]=k.useState(""),M=t.useEditorStore(v=>v.actions.setCardPreferences),{updateCardInFrame:R}=t.useEditorActions(),F=t.useEditorStore(v=>v.card),H=t.useEditorStore(v=>{var T;return(T=v.card)==null?void 0:T.type}),S=["pie","doughnut","polarArea"].includes(H);k.useEffect(()=>{var v,T,L,U,P,K,W,te,se,_,Q,Y,ne,ie;l(tt(n)),d(((L=(T=(v=n==null?void 0:n.chartOptions)==null?void 0:v.scales)==null?void 0:T[r])==null?void 0:L.min)===0?0:""),p(((K=(P=(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales)==null?void 0:P[r])==null?void 0:K.max)||""),c(((_=(se=(te=(W=n==null?void 0:n.chartOptions)==null?void 0:W.scales)==null?void 0:te[r])==null?void 0:se.ticks)==null?void 0:_.stepSize)||""),h(((Q=n==null?void 0:n.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),b(((Y=n==null?void 0:n.numberAxisFormat)==null?void 0:Y.suffix)||""),E(((ne=n==null?void 0:n.numberAxisFormat)==null?void 0:ne.currency)||""),w(((ie=n==null?void 0:n.numberAxisFormat)==null?void 0:ie.locale)||"")},[s,n,r]);function N(v,T){return T===""||/^[0-9\b]+$/.test(T)?Number(T):Number(v)}function A(){const v=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(T=>T.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(t.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(t.Select,{value:O||"none",onValueChange:T=>E(T==="none"?"":T),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),v.map(T=>e.jsx(t.SelectItem,{value:T,children:T},T))]})})]}),e.jsxs(t.Select,{value:z,onValueChange:T=>w(T),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Locale"}),t.LOCALE_CURRENCY_PAIRS.map(T=>e.jsx(t.SelectItem,{value:T.locale,children:T.locale},T.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(t.Input,{value:g,onChange:T=>h(Number(T.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${pe}`})]})]})}function D(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"range",children:"Range"}),e.jsx(t.Input,{id:"min",value:i,onChange:v=>d(T=>N(T,v.target.value)),className:`col-span-1 h-8 w-full ${pe}`}),e.jsx(t.Input,{value:m,onChange:v=>p(T=>N(T,v.target.value)),id:"max",className:`col-span-1 h-8 w-full ${pe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(t.Input,{value:f,onChange:v=>c(T=>N(T,v.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${pe}`})]})]})}function y(){var U;let v={};u==="custom"&&(v={min:i,max:m,ticks:{stepSize:f}});const T={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales,[r]:{type:o,...o==="linear"?v:{}}}},numberAxisFormat:{decimalPlaces:g,suffix:j,currency:O,locale:z}};console.log(T),M(T);const L={...F,preferences:T};R(L)}return e.jsxs(t.Popover,{onOpenChange:v=>a(v),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Scale Options",children:e.jsx(zs,{className:"size-4 rotate-45"})})}),e.jsx(t.PopoverContentCustom,{align:"center",className:"max-w-65",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:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(t.Select,{disabled:S,value:o,onValueChange:v=>l(v),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{id:"type",children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Option"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(t.RadioGroup,{disabled:S,id:"scale-option",value:u,onValueChange:v=>x(v),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.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(t.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),u==="custom"&&o=="linear"&&D(),A(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:y,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Dn(){const s=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.position}),a=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.align}),n=t.useEditorStore(d=>{var m,p,u,x;return(x=(u=(p=(m=d.card.preferences)==null?void 0:m.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:x.display}),{setLegendOptions:r}=t.useEditorActions(),o=d=>{r({display:d,position:s,align:a})},l=d=>{r({display:n,position:d,align:a})},i=d=>{r({display:n,position:s,align:d})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(vs,{className:"size-4"})})}),e.jsx(t.PopoverContentCustom,{className:"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(t.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(t.SmallSwitch,{checked:n,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Top",onClick:()=>l("top"),children:e.jsx(t.ArrowUp,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Left",onClick:()=>l("left"),children:e.jsx(es,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(Xt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(ts,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Start",onClick:()=>i("start"),children:e.jsx(Kt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Jt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(Wt,{className:"size-4"})})]})]})]})]})})]})}function En(){var l;const s=t.useEditorStore(i=>i.card.preferences),{setCardPreferences:a,setChartOrientation:n}=t.useEditorStore(i=>i.actions);function r(i){n(i)}const o=((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||"x";return e.jsx(t.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(As,{className:"size-4"}):e.jsx(Ts,{className:"size-4"})})}function Tn(){const s=t.useEditorStore(i=>i.card),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>{var d,m;return(m=(d=i.card)==null?void 0:d.preferences)==null?void 0:m.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:o}=t.useEditorActions();function l(){const i=["xy","none","x","y"],m=(i.indexOf(r)+1)%i.length;o(i[m])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(s.type)&&e.jsx(En,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(In,{}),e.jsx(Dn,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(s.type)&&e.jsxs(t.IconButton,{tooltip:"Grid Style",onClick:l,children:[(r==="xy"||!r)&&e.jsx(bs,{className:"size-4"}),r==="x"&&e.jsx(us,{className:"size-4"}),r==="y"&&e.jsx(Os,{className:"size-4"}),r==="none"&&e.jsx(_s,{className:"size-4"})]})]}):null}function xe(){var q;const s=t.useEditorStore(I=>I.frame),a=t.useEditorStore(I=>I.card),n=t.useEditorStore(I=>I.isDevMode),r=t.useEditorStore(I=>I.isShowingVisual),o=t.useDashboardStore(I=>I.isVisualEditing),l=t.useEditorStore(I=>I.isSqlRunning),i=t.useEditorStore(I=>I.pythonStdOut),d=t.useEditorStore(I=>{var C;return(C=I.card.preferences)==null?void 0:C.chartOptions}),m=t.useEditorStore(I=>I.actions.setRunSql);t.getChartGridStyle(d);const{setFrame:p,setCard:u,updateCardInFrame:x,setActiveTabCardId:f,runAssistant:c,setChartGrid:g}=t.useEditorActions(),{data:h,isLoading:j,isFetching:b,error:O}=t.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function E(){const I={connectionId:a.connectionId,lastSelectedDatabase:a.lastSelectedDatabase,lastSelectedSchema:a.lastSelectedSchema,lastSelectedTable:a.lastSelectedTable,lastSelectedDatamodelId:a.lastSelectedDatamodelId,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};z(I)}function z(I){const C={...s,cards:[...s.cards,I],activeCardId:I.id};p(C),u(I),f(I.id)}function w(){const I={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};z(I)}function M(I){const C=s.cards.filter(L=>L.id!==I),v=C[0],T={...s,cards:C,activeCardId:v.id};p(T),f(v.id),u(v)}function R(I){n||F(I),f(I)}function F(I){const C={...s,cards:s.cards.map(T=>T.id===a.id?a:T),activeCardId:I};p(C);const v=C.cards.find(T=>T.id===I);v.sql&&m(!0),u(v)}const H=(I,C)=>{console.log("handleDragStart",C),I.dataTransfer.setData("tabIndex",C.toString())},S=I=>{I.preventDefault()},N=(I,C)=>{const v=I.dataTransfer.getData("tabIndex");if(v===C.toString())return;const T=Array.from(s.cards),[L]=T.splice(parseInt(v),1);T.splice(C,0,L),p({...s,cards:T})};function A(I,C){return I.cards.length===1&&(C.displayTab===!0||C.displayTab===void 0)||I.activeCardId!==C.id&&(C.displayTab===!0||C.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=C.displayTab===void 0?!1:!C.displayTab;u({...C,displayTab:v}),x({...C,displayTab:v})},children:C.displayTab===!0||C.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(fs,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function D(){return e.jsxs(t.Tabs,{onValueChange:R,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(I=>e.jsx(t.TabsContent,{className:"mt-0 grow",value:I.id,children:y()},I.id)),e.jsx(t.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[s.cards.map((I,C)=>e.jsx(t.Editable,{text:I.tabTitle||I.title,onSave:v=>{u({...a,tabTitle:v}),x({...a,tabTitle:v})},children:e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:v=>H(v,C),onDragOver:S,onDrop:v=>N(v,C),className:"",value:I.id,children:[A(s,I),I.tabTitle||I.title,s.activeCardId===I.id&&s.cards.length>1&&e.jsx(t.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>M(I.id)})]})},I.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:E,children:e.jsx(t.Plus,{className:"h-4 w-4"})}),e.jsx(t.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:w,children:e.jsx(hs,{className:"h-4 w-4"})})]})})]})}function y(){return a.type==="kpi"?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(t.KPICard,{card:a,data:h==null?void 0:h.records})})}):a.type==="text"?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(t.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(t.TextCard,{isLoading:l,card:a,data:h==null?void 0:h.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Ot,{className:"grow border-none shadow-none"})})}function B(){const I=JSON.stringify(h==null?void 0:h.records,null,2),C=new Blob([I],{type:"application/json"}),v=URL.createObjectURL(C),T=document.createElement("a");T.href=v,T.download=`${a.title}.json`,T.click()}function G(){const C=[Object.keys(h==null?void 0:h.records.reduce((U,P)=>({...U,...P}),{})).join(","),...((h==null?void 0:h.records)||[]).map(U=>Object.values(U).join(","))].join(`
|
|
352
|
+
`),v=new Blob([C],{type:"text/csv"}),T=URL.createObjectURL(v),L=document.createElement("a");L.href=T,L.download=`${a.title}.csv`,L.click()}function $(){const I=`Can you get the documentation for ${a.type} chart?`;c(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(j||b)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),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(wn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:$,children:e.jsx(as,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(Sn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.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(Cn,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:B,children:e.jsx(gs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Tn,{}),e.jsx(Mn,{})]}),r?D():e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(An,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(fn,{data:(h==null?void 0:h.records)||[]}),(O||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(O==null?void 0:O.message)||((q=h==null?void 0:h.error)==null?void 0:q.message)})]})]})]})}function An(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.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(t.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(t.ScrollBar,{orientation:"horizontal"})]})]})}function Mn(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ln(){var h,j;const s=t.useEditorStore(b=>b.card.customCardPreferences),{data:a}=Bt(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(b=>b.card),o=t.useEditorStore(b=>b.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:d,manifest:m}=t.useCustomVisual((s==null?void 0:s.url)||""),p=(h=m==null?void 0:m.visuals)==null?void 0:h.find(b=>b.name===(s==null?void 0:s.componentName));function u(b,O){if(!s)return;const z={...(s==null?void 0:s.dataInputCardIds)||{},[b]:{cardId:O,hookRef:null}};i({...s,dataInputCardIds:z})}function x(b){var E,z;const O=(E=o==null?void 0:o.cards)==null?void 0:E.filter(w=>{var M;return((M=w==null?void 0:w.customCardPreferences)==null?void 0:M.visualType)!=="multiple"}).map(w=>({value:w.id,label:w.tabTitle||w.title}));return e.jsx("div",{className:"space-y-2",children:(z=b==null?void 0:b.dataInputs)==null?void 0:z.map((w,M)=>{var R,F;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:w}),e.jsx(X,{className:"col-span-6 h-8 w-full justify-between",label:"",options:O||[],value:((F=(R=s==null?void 0:s.dataInputCardIds)==null?void 0:R[M])==null?void 0:F.cardId)||"",onValueChange:H=>u(M,H)})]},M+Math.random())})})}function f(b,O,E=[],z=""){var w,M;return s?b==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((w=s==null?void 0:s.settings)==null?void 0:w[O])||z,onChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R.target.value}})}},O):b==="select"?e.jsx(X,{className:"h-8 w-full",label:"",options:E,value:((M=s==null?void 0:s.settings)==null?void 0:M[O])||z,onValueChange:R=>{i({...s,settings:{...s==null?void 0:s.settings,[O]:R}})}}):null:null}function c(b){const O=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:O.map(([E,z])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:z.title}),f(z.ui,E,z.options,z.defaultValue)]},E))})}function g(b){s&&i({...s,visualType:b,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.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(X,{icon:e.jsx(ns,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:b=>i({...s||{url:"",componentName:""},url:b})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:g,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:d&&e.jsx(X,{icon:e.jsx(ms,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(d==null?void 0:d.filter(b=>b.type===l).map(b=>({value:b.name,label:b.name})))||[],value:s.componentName,onValueChange:b=>{console.log("changing value",b),i({...s,componentName:b})}})})]})})]}),((j=r==null?void 0:r.customCardPreferences)==null?void 0:j.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:x(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(p)})})]})]})]})}function oe(){const[s,a]=k.useState([]),n=t.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(p=>p.actions),l=t.useEditorStore(p=>p.queryResultColumns);t.useEditorStore(p=>{var u;return(u=p.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),k.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(p,u){var x,f;u?n!=null&&n.onClickFilter&&((x=n==null?void 0:n.onClickFilter)==null?void 0:x.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:p,expression:""}]}):o({...n,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...n,onClickFilter:(f=n==null?void 0:n.onClickFilter)==null?void 0:f.filter(c=>c.columnIndex!==p)}),a(c=>{const g=[...c];return g[p]=!1,g}))}function d(p,u){var f;const x=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.map(c=>c.columnIndex===p?{...c,expression:u.target.value}:c);o({...n,onClickFilter:x})}function m(p){var u,x,f,c;if(s!=null&&s[p]||(x=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===p))!=null&&x.expression)return e.jsx(t.Input,{value:(c=(f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(g=>g.columnIndex===p))==null?void 0:c.expression,onChange:g=>d(p,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((p,u)=>{var x,f;return e.jsx("div",{className:"xbg-red-100 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(t.Checkbox,{checked:!!((x=n==null?void 0:n.onClickFilter)!=null&&x.find(c=>c.columnIndex===u)),onCheckedChange:c=>i(u,c)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((f=n==null?void 0:n.onClickFilter)==null?void 0:f.find(c=>c.columnIndex===u))&&e.jsx(t.Pencil,{onClick:()=>{a(c=>{const g=[...c];return g[u]=!c[u],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(u)]})},p)})]})}function On({idx:s}){var d;const a=t.useEditorStore(m=>{var p;return(p=m.card)==null?void 0:p.preferences}),n=t.useEditorStore(m=>{var p;return(p=m.card.preferences)==null?void 0:p.datasetOptions}),r=t.useEditorStore(m=>m.actions.setCardPreferences),o=(d=a==null?void 0:a.chartOptions)==null?void 0:d.indexAxis,l=n==null?void 0:n.find(m=>m.idx===s);function i(m,p){(m==="end"||m==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const u={display:m!=="none",align:m,anchor:m,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:p,datalabels:u}]});else{const x={...l};x.datalabels=u;const f=n==null?void 0:n.map(c=>c.idx===p?x:c);r({...a,datasetOptions:f})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Vs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(t.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-4"})}),e.jsx(t.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ns,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ks,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ws,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function qt(){const s=t.useEditorStore(p=>p.card),a=t.useEditorStore(p=>{var u,x,f;return(f=(x=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:x.chartOptions)==null?void 0:f.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:l,metricKeys:i,dimensionKeys:d}=t.getKeys((n==null?void 0:n.records)||[]);let m=i;if(["stackedBar","stackedLine"].includes(s.type)){const p=t.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:m[0]}),{metricKeys:u}=t.getKeys(p);m=u}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:d.map(p=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:p,children:Pt(p)},p))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:m.map((p,u)=>e.jsx(zn,{col:p,idx:u},p))})]})]})}function Pt(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function zn({col:s,idx:a}){const n=t.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),r=t.useEditorStore(d=>{var m;return(m=d.card.preferences)==null?void 0:m.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===a),{setCardPreferences:l}=t.useEditorStore(d=>d.actions);function i(d){if(!o)l({...n,datasetOptions:[...r||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const m={...o};m.type=d==="area"?"line":d,m.fill=d==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===a?m:u);l({...n,datasetOptions:p})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:s,children:Pt(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ve,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Be,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ls,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(On,{idx:a})]})]})}function Ht(){const s=t.useEditorStore(c=>c.selectedConnectionId),a=t.useEditorStore(c=>c.selectedDatamodelId),n=t.useEditorStore(c=>c.selectedDatabaseName),r=t.useEditorStore(c=>c.selectedSchemaName),o=t.useEditorStore(c=>c.selectedTableName),l=t.useDashboardStore(c=>c.dashboard.filters)||[],i=t.useDashboardStore(c=>c.actions.addFilter),d=t.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:m}=t.useDashboardActions(),{modelItems:p,tableName:u,connectionType:x}=Z();function f(c,g="dashboard"){var R;const h=t.fmt(c.column_name),j=t.fmt(n||""),b=t.fmt(r||""),O=t.fmt(u);let E=t.getQualifiedTableName({schemaName:b,tableName:O,connectionType:x,databaseName:j}),z=`${E}.${h}`;const w=(R=p==null?void 0:p.find(F=>F.id===a))==null?void 0:R.name;a&&a!=="none"&&(z=`${t.DATAMODEL_NAMESPCACE}.${w}.${h}`,E=`${t.DATAMODEL_NAMESPCACE}.${w}`);const M=l==null?void 0:l.find(F=>F.column===z&&F.table===O&&(F.database===j||F.database===n));if(M)m(M.id),d(M.id);else{const F=t.v4();return u==="api"&&s?(i({location:g,id:F,column:z,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F):(i({id:F,location:g,column:z,title:c.column_name,dataType:c.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(c.data_type,E,h)}),F)}}return{assignFilter:f}}function me(){const s=t.useDashboardStore(d=>d.dashboard.filters),a=t.useEditorStore(d=>d.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=Z(),{assignFilter:o}=Ht();function l(d){const m=o(d,"frame");n({...a,filterId:m})}const i=s==null?void 0:s.find(d=>d.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Fn,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Fn({columns:s,onSelect:a}){var i;const[n,r]=de.useState(!1),[o,l]=de.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=s.find(d=>d.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(d=>e.jsxs(t.CommandItem,{value:d.column_name,onSelect:m=>{const p=m===o?"":m;l(p),r(!1),p&&a(d)},children:[d.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function Rn({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(qt,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Ge(){var o,l,i;const s=t.useEditorStore(d=>d.card.type),a=t.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=t.useEditorStore(d=>d.actions);function r(d){var u;const m={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},p={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(u=a==null?void 0:a.chartOptions)==null?void 0:u.plugins,...m}}};n(p),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((i=(l=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function _n({cardType:s}){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:l=>l.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(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx(Ge,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}const Vn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Bn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function qn(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Pn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ge,{}),e.jsx(oe,{}),e.jsx(me,{})]})]})}function Pn(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.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(Vn,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.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(Bn,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.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(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.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"].includes(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.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 Hn(){var m,p,u,x,f;const s=t.useEditorStore(c=>c.card.preferences),a=t.useEditorStore(c=>c.actions.setCardPreferences),n=t.useEditorStore(c=>c.actions.setNumberFormat);t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.decimalPlaces});const r=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.locale}),o=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.currency});t.useEditorStore(c=>c.actions.setFilterOnClickField);const l=t.useEditorStore(c=>{var g,h;return(h=(g=c.card.preferences)==null?void 0:g.formatNumber)==null?void 0:h.colorRanges})||[],i=t.useEditorStore(c=>c.actions.setColorRanges),d=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(c=>c.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((m=s==null?void 0:s.formatNumber)!=null&&m.enabled),onCheckedChange:c=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:c}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:c=>{var g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",c,((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(c=>e.jsx(t.SelectItem,{value:c.locale,children:c.locale},c.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:o||"none",onValueChange:c=>{var g,h,j;console.log("currency",c),n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,c==="none"?"":c,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),d.map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((x=(u=s==null?void 0:s.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:x.toString())||"0",onValueChange:c=>{var g,h,j;return n(Number(c),((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(c=>e.jsx(t.SelectItem,{value:c,children:c},c))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:c=>{var g,h,j;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",c.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Gn(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.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:s=>s.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(Hn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function ke({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.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(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Un=[{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"}],$n=["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"],Qn=$n.map(s=>({label:s,value:s}));function Jn(){var m,p,u,x,f,c,g,h,j,b,O,E,z,w,M,R,F,H;const s=t.useEditorStore(S=>S.card),a=(p=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:p.topoJsonUrl,[n,r]=k.useState(((x=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:x.customTopoJsonUrl)||""),{setCardPreferences:o}=t.useEditorActions(),{data:l}=t.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(S=>({label:S,value:S}))||[],d=[{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(ke,{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(t.Separator,{className:"my-4"}),e.jsx(ke,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(X,{className:"h-9",options:d,onValueChange:S=>{console.log("value",S),o({...s.preferences,mapVisualOptions:{topoJsonUrl:S}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:S=>{r(S.target.value)},onBlur:()=>{var S;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(S=s.preferences)==null?void 0:S.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(X,{className:"h-9",options:i,value:((c=(f=s.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:S=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,objectKey:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(X,{className:"h-9",options:Un,value:((h=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:h.projection)||"",label:"Projection",onValueChange:S=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projection:S}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(X,{className:"h-9",options:Qn,value:((b=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:S=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,colorScale:S}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(ke,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionScale)||1,onChange:S=>{var N;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionScale:Number(S.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((M=(w=(z=s.preferences)==null?void 0:z.mapVisualOptions)==null?void 0:w.projectionOffset)==null?void 0:M[0])||0,onChange:S=>{var N,A,D,y;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[Number(S.target.value),((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((H=(F=(R=s.preferences)==null?void 0:R.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:H[1])||0,onChange:S=>{var N,A,D,y;o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,projectionOffset:[((y=(D=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:y[0])||0,Number(S.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function Kn(){var r;const s=t.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=t.useEditorStore(o=>o.actions);function n(o){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.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(t.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(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function fe({cardType:s,docContent:a,suffix:n="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.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:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx(Ge,{}),s==="text"&&e.jsx(Kn,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Wn(){const s=t.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:a}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(X,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(qt,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Yn({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),n=t.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Xn=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:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),Zn=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:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),ea=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:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function ta(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Wn,{});case"pyramid":return e.jsx(fe,{docContent:Xn,cardType:n});case"kpi":return e.jsx(Gn,{});case"line":case"bar":return e.jsx(Rn,{cardType:n});case"range":return e.jsx(fe,{docContent:Zn,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(fe,{cardType:n});case"bubble":case"scatter":return e.jsx(_n,{cardType:n});case"table":return e.jsx(Yn,{cardType:n});case"text":return e.jsx(fe,{docContent:ea,cardType:n,suffix:"Visual"});case"map":return e.jsx(Jn,{});case"custom":return e.jsx(Ln,{});default:return e.jsx(qn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Ie={id:"__placeholder__",role:"groupby",type:"string"},De={id:"__placeholder__",role:"metric",type:"number"},Ee={id:"__placeholder__",role:"trendby",type:"date"},Te={id:"__placeholder__",role:"filter",type:"string"},Gt={id:"__placeholder__"},be="droppable-group-by",Se="droppable-metrics",Le="sortable-group-by",Oe="sortable-metrics",ze="droppable-trend-by",Fe="sortable-trend-by",Re="droppable-filters",_e="sortable-filters";function sa(){const s=t.useDndStore(N=>N.insertIndex),a=t.useEditorStore(N=>{var A;return((A=N.card.queryConfig)==null?void 0:A.groupByColumns)||[]}),n=t.useEditorStore(N=>{var A;return((A=N.card.queryConfig)==null?void 0:A.metricColumns)||[]}),r=t.useEditorStore(N=>{var A;return((A=N.card.queryConfig)==null?void 0:A.trendByColumns)||[]}),o=t.useEditorStore(N=>{var A;return((A=N.card.queryConfig)==null?void 0:A.filterColumns)||[]}),{setInsertIndex:l,setActiveId:i,setPreviewGroupByColumns:d,setPreviewMetricColumns:m,setPreviewTrendByColumns:p,setPreviewFilterColumns:u}=t.useDndActions(),{setGroupByColumns:x,setMetricColumns:f,setTrendByColumns:c,setFilterColumns:g}=t.useEditorActions(),{columns:h}=Nt(),{formattedTableName:j}=Z(),b=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),O=N=>{var y;const{active:A,over:D}=N;if(((y=A.data.current)==null?void 0:y.type)==="column"&&D){const B=D.id,G=h.find(C=>C.column_name===A.id);if(!G)return;const $=t.isNumberDataType(G.data_type),q=t.isTextDataType(G.data_type),I=t.isDateDataType(G.data_type);if(q){if(a.some(v=>v.id===B)){const v=a.findIndex(L=>L.id===B);l(v);const T=a.filter(L=>L.id!==Ie.id);T.splice(v,0,Ie),d(T)}else if(D.id===be){l(a.length);const v=[...a,Ie];d(v),m(n),p(r),u(o)}}if($||q){if(n.some(v=>v.id===B)){console.log("isOverMetricSortable",B);const v=n.findIndex(L=>L.id===B);l(v);const T=n.filter(L=>L.id!==De.id);T.splice(v,0,De),m(T)}else if(D.id===Se){l(n.length);const v=[...n,De];m(v),p(r),u(o),d(a)}}if(I){if(r.some(v=>v.id===B)){const v=r.findIndex(L=>L.id===B);l(v);const T=r.filter(L=>L.id!==Ee.id);T.splice(v,0,Ee),p(T)}else if(D.id===ze){l(r.length);const v=[...r,Ee];p(v),m(n),u(o),d(a)}}if(z(G)){if(o.some(v=>v.id===B)){const v=o.findIndex(L=>L.id===B);l(v);const T=o.filter(L=>L.id!==Te.id);T.splice(v,0,Te),u(T)}else if(D.id===Re){l(o.length);const v=[...o,Te];u(v),m(n),p(r),d(a)}}}else d(a),m(n),p(r),u(o)};function E(N){i(N.active.id),l(null),d(a),m(n),p(r),u(o)}function z(N){return!o.some(A=>A.name===N.column_name)}function w(N,A="SUM"){const{column_name:D,data_type:y}=N,B=[...n],G=s!==null?s:n.length,$={...N,id:ae(D),name:D,label:ge(A,D),type:y,role:"metric",aggregate:A};B.splice(G,0,$),f(B)}function M(N){const A=[...a],D=s!==null?s:a.length,y={...N,id:ae(N.column_name),name:N.column_name,type:N.data_type,role:"groupby"};A.splice(D,0,y),x(A)}function R(N){const A=[...r],D=s!==null?s:r.length,y={...N,id:ae(N.column_name),name:N.column_name,type:N.data_type,role:"trendby"};A.splice(D,0,y),c(A)}function F(N){const A=[...o],D=s!==null?s:o.length,y={...N,id:ae(N.column_name),name:N.column_name,type:N.data_type,sql:t.getDefaultFilterSql(N.data_type,j,t.fmt(N.column_name)),role:"filter"};A.splice(D,0,y),g(A)}function H(N){var B,G,$,q,I,C,v,T;const{active:A,over:D}=N,y=A.data.current;if((y==null?void 0:y.type)==="column"&&D){const L=h.find(W=>W.column_name===A.id);if(!L)return;const U=t.isNumberDataType(L.data_type),P=t.isTextDataType(L.data_type),K=t.isDateDataType(L.data_type);P&&(D.id===be||((B=D.data.current)==null?void 0:B.type)===Le)?M(L):(U||P)&&(D.id===Se||((G=D.data.current)==null?void 0:G.type)===Oe)?(U&&w(L),P&&w(L,"COUNT")):K&&(D.id===ze||(($=D.data.current)==null?void 0:$.type)===Fe)?R(L):z(L)&&(D.id===Re||((q=D.data.current)==null?void 0:q.type)===_e)&&F(L)}if(D&&((I=D.data.current)==null?void 0:I.type)===Le&&a.some(L=>L.id===A.id)){const L=a.findIndex(P=>P.id===A.id),U=a.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...a],[K]=P.splice(L,1);P.splice(U,0,K),x(P)}}if(D&&((C=D.data.current)==null?void 0:C.type)===Oe&&n.some(L=>L.id===A.id)){const L=n.findIndex(P=>P.id===A.id),U=n.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...n],[K]=P.splice(L,1);P.splice(U,0,K),f(P)}}if(D&&((v=D.data.current)==null?void 0:v.type)===Fe&&r.some(L=>L.id===A.id)){const L=r.findIndex(P=>P.id===A.id),U=r.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...r],[K]=P.splice(L,1);P.splice(U,0,K),c(P)}}if(D&&((T=D.data.current)==null?void 0:T.type)===_e&&o.some(L=>L.id===A.id)){const L=o.findIndex(P=>P.id===A.id),U=o.findIndex(P=>P.id===D.id);if(L!==-1&&U!==-1&&L!==U){const P=[...o],[K]=P.splice(L,1);P.splice(U,0,K),g(P)}}i(null),l(null),d(a),m(n),p(r),u(o)}function S(){i(null),l(null),d(a),m(n),p(r),u(o)}return{handleDragOver:O,handleDragEnd:H,handleDragStart:E,handleDragCancel:S,sensors:b}}const ce=[{label:"Sum",value:"SUM",logo:e.jsx(ft,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(ut,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(js,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Zt,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(Yt,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(ss,{className:"size-3.5"})}];function na({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=k.useState(!1),[i,d]=k.useState(ce[0]),{attributes:m,listeners:p,setNodeRef:u,transform:x,transition:f,isDragging:c}=t.useSortable({id:s.id,data:{type:a}}),g=x?{opacity:c?.5:void 0,transform:t.CSS.Translate.toString(x),transition:f}:void 0;function h(){return e.jsx("div",{"data-setting-container":"",className:"h-32 rounded-b-md border-x border-b border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}return e.jsxs("div",{...p,...m,ref:u,style:g,children:[e.jsxs("div",{className:t.cn("group flex h-8 items-center rounded-t-md bg-muted px-2",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),r===Se&&e.jsx(ra,{column:s}),e.jsx("div",{className:t.cn("max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",{"pl-2":r===be}),children:e.jsx(aa,{col:s})}),e.jsxs("div",{"data-setting-actions":"",className:"hidden h-full items-center gap-2 group-hover:flex",children:[e.jsx("button",{onClick:()=>l(!o),children:e.jsx(t.ChevronDown,{className:t.cn("ml-1 size-4 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground",o&&"rotate-180")})}),e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground"})})]})]}),o&&h()]})}function aa({col:s}){return e.jsx(t.Editable,{text:s.label||s.name,className:"h-6 rounded-none",onSave:a=>{console.log("saved",a)},children:e.jsx("span",{className:"w-[250px] truncate text-ellipsis whitespace-nowrap text-sm",children:s.label||s.name})})}function ra({column:s}){const[a,n]=k.useState(ce[0]),{updateMetricColumn:r}=t.useEditorActions();let o=ce;t.isTextDataType(s.type)&&(o=o.filter(i=>["COUNT","DISTINCT"].includes(i.value))),t.isNumberDataType(s.type)&&(o=o.filter(i=>!["DISTINCT","COUNT"].includes(i.value))),k.useEffect(()=>{n(ce.find(i=>i.value===s.aggregate)||ce[0])},[s]);function l(i){const d=ce.find(p=>p.value===i);if(!d)return;n(d);const m={...s,aggregate:i,label:ge(i,s.name)};r(s.id,m)}return e.jsx(X,{className:"size-7 overflow-clip rounded-none rounded-l-md border-none bg-muted px-2",icon:a.logo,options:o,value:a.value,onValueChange:i=>l(i),label:"Aggregation"})}function Ae({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),d=t.useDndStore(u=>u.activeId),m={},p=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(u=>u.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:p==null?void 0:p.map(u=>u.id===Gt.id?e.jsx(oa,{},u.id):e.jsx(na,{droppableId:s,type:o,column:u,onRemoveColumn:l},u.id))})]})})}function oa(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function st(){const s=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.groupByColumns)||[]}),a=t.useDndStore(c=>c.previewGroupByColumns),n=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.metricColumns)||[]}),r=t.useDndStore(c=>c.previewMetricColumns),o=t.useEditorStore(c=>{var g;return((g=c.card.queryConfig)==null?void 0:g.trendByColumns)||[]}),l=t.useDndStore(c=>c.previewTrendByColumns),{setSelectedConnectionId:i,removeColumnFromGroupBy:d,removeColumnFromMetricColumns:m,removeColumnFromTrendByColumns:p}=t.useEditorActions();k.useEffect(()=>{i("c_2d3646f0-68a6-47e7-942d-d9cbc80fb7d4")},[i]);function u(c){d(c)}function x(c){p(c)}function f(c){m(c)}return e.jsxs("div",{className:"h-full w-full space-y-2 p-4",children:[e.jsx(Ae,{onRemoveColumn:u,sortableType:Le,id:be,label:"Group By",columns:s,previewColumns:a}),e.jsx(Ae,{onRemoveColumn:x,sortableType:Fe,id:ze,label:"Trend By",columns:o,previewColumns:l}),e.jsx(Ae,{onRemoveColumn:f,sortableType:Oe,id:Se,label:"Metrics",columns:n,previewColumns:r})]})}function ia({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:d,isDragging:m}=t.useSortable({id:a,data:{type:n}}),p=i?{opacity:m?.5:void 0,transform:t.CSS.Translate.toString(i),transition:d}:void 0;return e.jsx("div",{...o,...r,ref:l,style:p,children:s})}function la({column:s,type:a}){const n=t.useDashboardStore(R=>R.themeStyle),[r,o]=k.useState(!1),l=t.useEditorStore(R=>{var F,H;return(H=(F=R.card)==null?void 0:F.queryConfig)==null?void 0:H.filters}),{selectedConnectionId:i,selectedDatabaseName:d,selectedTableName:m}=Z(),p=t.isTextDataType(s.type);t.isNumberDataType(s.type),t.isDateDataType(s.type);const u=k.useMemo(()=>{var R;return(R=l==null?void 0:l.find(F=>F.filterColumnName===s.name))==null?void 0:R.filterValue},[l,s.name]),x=k.useMemo(()=>Array.isArray(u)?u.map(R=>({id:R,value:R})):[],[u]),{updateEditorCardFilterValue:f,removeEditorCardFilter:c}=t.useEditorActions(),g={column:s.name,sql:s.sql,id:s.name,connectionId:i,dataType:s.type},{data:h,isLoading:j,isFetching:b,isError:O}=t.useFilterQuery(g),E=k.useMemo(()=>{var F;return g.column?(F=h==null?void 0:h.records)==null?void 0:F.map(H=>{let S=g.column.split(".").slice(-1)[0].replace(/"/g,"");return H[S]===void 0&&(S=S.toLowerCase()),{id:H[S],value:H[S]}}):[]},[h,g.column]);function z(R){const F=R.map(H=>H.id);f(s.name,F)}function w(R){c(R)}function M(){return j||b?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 w-60 bg-foreground/10"}):O?e.jsx("div",{className:"flex h-8 w-60 items-center bg-muted px-2 text-sm",children:"Error"}):p?e.jsx(t.ComboBoxMultiSelect,{options:E,onChange:z,selectedOptions:x,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}}):e.jsx("div",{children:"Not implemented"})}return e.jsx(ia,{id:s.id,type:a,children:e.jsxs("div",{className:"group w-60 space-y-1 rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:s.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>w(s),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.cn("group flex items-center rounded-t-md text-sm",!r&&"rounded-b-md",r&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.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:"max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",children:M()})]})]})})}function ca({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l,isOver:i}=t.useDroppable({id:s}),d=t.useDndStore(x=>x.activeId),m={borderColor:i?"green":void 0};function p(x){return x.id===Gt.id?e.jsx(da,{}):e.jsx(la,{droppableId:s,type:o,column:x},x.id)}const u=d?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:m,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:u==null?void 0:u.map(x=>p(x))})]})})}function da(){return e.jsx("div",{className:"flex h-7 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function ua(){const s=t.useEditorStore(o=>{var l;return((l=o.card.queryConfig)==null?void 0:l.filterColumns)||[]}),a=t.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(o){n(o)}return e.jsx("div",{className:"size-full p-4",children:e.jsx(ca,{onRemoveColumn:r,sortableType:_e,id:Re,label:"Filters",columns:s,previewColumns:a})})}function ma(){const s=t.useEditorStore(r=>r.card),{data:a,errorMessage:n}=t.useDashboardCardQuery(s);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(Lt,{}),e.jsx(kt,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 bg-muted px-3 py-1 text-xs font-medium",children:"Early Preview"}),e.jsx(Mt,{}),e.jsx(At,{variant:"default"})]})]})}function ha(){const s=k.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);k.useEffect(()=>{var i,d;n?(i=s.current)==null||i.resize(0):(d=s.current)==null||d.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(xn,{})}),e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:r?e.jsx(ta,{}):e.jsx(st,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(xe,{})})]}):e.jsx(xe,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(st,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(ma,{}),e.jsx(ua,{})]}),e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(xe,{})})]})})]}):e.jsx(xe,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const pa=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function xa(){const s=k.useRef(null),a=k.useRef(null),[n,r]=k.useState(!1),[o,l]=k.useState(t.isDevEnv),[i,d]=k.useState(!1),m=t.useEditorStore(q=>q.actions.setCardSql),p=t.useEditorStore(q=>q.actions.setRunSql),u=t.useEditorStore(q=>q.showAIDialog),{setShowAIDialog:x}=t.useEditorActions(),{messages:f,setMessages:c,reload:g,append:h,input:j,setInput:b,isLoading:O,handleAddCurrentTableToScope:E,removeFromCurrentSelections:z,currentAssitantScope:w,handleInputChange:M,handleSubmit:R,stop:F,chatStatus:H,toolStatus:S,llmUsage:N,errorMessage:A}=Tt();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:f}),k.useEffect(()=>{var q;u&&((q=a.current)==null||q.focus())},[u]);function D(q){m(q),p(!0)}function y(q){const I={role:"user",content:q.title+" "+q.subtitle};h(I)}function B(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(ct,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"System Message"})]})]})}function G(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),w&&w.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:w==null?void 0:w.map((q,I)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[t.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||"",databaseName:q.databaseName||""}),e.jsx("button",{onClick:()=>{z(q)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(w==null?void 0:w.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(t.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:E,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const $=(j==null?void 0:j.length)===0&&(f==null?void 0:f.filter(q=>q.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[G(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[B(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),g()},children:e.jsx(t.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{x(!1)},children:e.jsx(t.X,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(t.PrintMessages,{messages:f,showTools:o,handleRun:D,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(H,S),isLoading:O})]})}),$&&e.jsx(t.Placeholders,{onClick:y,placeholders:pa}),e.jsx(t.ChatInput,{onFocus:()=>{E()},stop:F,ref:a,setInput:b,input:j,handleInputChange:M,handleSubmit:R,isLoading:O}),N&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",N.promptTokens," prompt tokens,"," ",N.completionTokens," completion tokens,"," ",N.totalTokens," total tokens"]})}),A&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:A})})]})}function fa({authToken:s,onSave:a,onClose:n}){const r=k.useRef(null),o=t.useEditorStore(j=>j.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:m}=t.useEditorActions(),{handleDragOver:p,handleDragEnd:u,handleDragStart:x,handleDragCancel:f,sensors:c}=sa();k.useEffect(()=>{a&&d(a),n&&m(n)},[a,d,n,m]),k.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),k.useEffect(()=>{var j,b;o?((j=r.current)==null||j.resize(40),i(!0)):(i(!1),(b=r.current)==null||b.resize(0))},[o,i]);function g(j){j<1?i(!1):o||i(!0)}function h(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ha,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:g,defaultSize:0,children:e.jsx(xa,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:c,onDragStart:x,onDragEnd:u,onDragOver:p,onDragCancel:f,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(wt,{type:"main"}),h()]})})})}function ga(){t.useDashboardStore(i=>i.selectedCardId);const s=t.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(i=>i.actions),n=t.useDashboardStore(i=>i.isVisualEditing),r=t.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),a(!1))}function l(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(fa,{onSave:o,onClose:l})})}function ja(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=Z(),{assignFilter:o}=Ht();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=n==null?void 0:n.find(d=>d.column===t.fmt(l.column_name)&&d.table===a&&d.database===s);return e.jsx("div",{onClick:()=>o(l),className:t.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":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function ya(){t.useDashboardStore(a=>a.showFilters);const s=t.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(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(wt,{type:"filter",ColumnsComponent:()=>e.jsx(ja,{})})})]})}function ba(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.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(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function Sa(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.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(ba,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ya,{})})]})}function Ca(){const s=t.useDashboardStore(o=>o.dashboard),a=t.useDashboardStore(o=>o.actions.setDashboard),n=t.useDashboardStore(o=>o.showDashboardJSON),r=t.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.de,{onChange:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function va({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(Ca,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(Ks,{}),e.jsx(ga,{}),e.jsx(Sa,{})]})]})]})})}exports.Dashboard=t.Dashboard;exports.DashboardWC=t.DashboardWC;exports.SemaphorDataProvider=t.SemaphorQueryClient;exports.SemaphorQueryClient=t.SemaphorQueryClient;exports.createSqlGenConfig=t.createSqlGenConfig;exports.fmt=t.fmt;exports.getColumnDataType=t.getColumnDataType;exports.getFilterValueType=t.getFilterValueType;exports.getFormattedTableNameForQuery=t.getFormattedTableNameForQuery;exports.getQualifiedTableName=t.getQualifiedTableName;exports.getSql=t.getSql;exports.invalidateToken=t.invalidateToken;exports.isBooleanDataType=t.isBooleanDataType;exports.isColumnInSqlGen=t.isColumnInSqlGen;exports.isDateDataType=t.isDateDataType;exports.isNumberDataType=t.isNumberDataType;exports.isTextDataType=t.isTextDataType;exports.resolveDataType=t.resolveDataType;exports.resolveDatamodelName=t.resolveDatamodelName;exports.useCard=t.useCard;exports.useDashboardActions=t.useDashboardActions;exports.useDashboardStore=t.useDashboardStore;exports.useDateFilterHook=t.useDateFilterHook;exports.useEditorActions=t.useEditorActions;exports.useEditorStore=t.useEditorStore;exports.useTextFilterHook=t.useTextFilterHook;exports.ScheduleDashboard=Ct;exports.SelectComponent=le;exports.Surfboard=va;exports.cleanCard=yt;exports.downloadPdf=St;exports.getDashbaordStateWithoutData=Pe;exports.useEditorAside=Z;
|