react-semaphor 0.0.397 → 0.0.399
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-BRkLiLoa.js → index-CW6yUvdJ.js} +82 -82
- package/dist/chunks/{index-DcSez0Uh.js → index-CdM_qEx2.js} +6615 -6610
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +49 -39
- package/dist/index.js +1751 -1717
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-CW6yUvdJ.js"),e=require("react/jsx-runtime"),C=require("react");require("react-dom");function Cs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const ue=Cs(C);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -88,22 +88,32 @@
|
|
|
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 zs=s.createLucideIcon("CircleArrowRight",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m12 16 4-4-4-4",key:"1i9zcv"}]]);/**
|
|
92
|
+
* @license lucide-react v0.453.0 - ISC
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the ISC license.
|
|
95
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
91
96
|
*/const Ue=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
|
|
92
97
|
* @license lucide-react v0.453.0 - ISC
|
|
93
98
|
*
|
|
94
99
|
* This source code is licensed under the ISC license.
|
|
95
100
|
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
-
*/const
|
|
101
|
+
*/const Os=s.createLucideIcon("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/**
|
|
102
|
+
* @license lucide-react v0.453.0 - ISC
|
|
103
|
+
*
|
|
104
|
+
* This source code is licensed under the ISC license.
|
|
105
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
+
*/const Fs=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
97
107
|
* @license lucide-react v0.453.0 - ISC
|
|
98
108
|
*
|
|
99
109
|
* This source code is licensed under the ISC license.
|
|
100
110
|
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
-
*/const
|
|
111
|
+
*/const Rs=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
|
|
102
112
|
* @license lucide-react v0.453.0 - ISC
|
|
103
113
|
*
|
|
104
114
|
* This source code is licensed under the ISC license.
|
|
105
115
|
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
-
*/const
|
|
116
|
+
*/const Vs=s.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"}]]);/**
|
|
107
117
|
* @license lucide-react v0.453.0 - ISC
|
|
108
118
|
*
|
|
109
119
|
* This source code is licensed under the ISC license.
|
|
@@ -118,77 +128,77 @@
|
|
|
118
128
|
*
|
|
119
129
|
* This source code is licensed under the ISC license.
|
|
120
130
|
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
-
*/const
|
|
131
|
+
*/const qs=s.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"}]]);/**
|
|
122
132
|
* @license lucide-react v0.453.0 - ISC
|
|
123
133
|
*
|
|
124
134
|
* This source code is licensed under the ISC license.
|
|
125
135
|
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
-
*/const
|
|
136
|
+
*/const Bs=s.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
|
|
127
137
|
* @license lucide-react v0.453.0 - ISC
|
|
128
138
|
*
|
|
129
139
|
* This source code is licensed under the ISC license.
|
|
130
140
|
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
-
*/const
|
|
141
|
+
*/const Ps=s.createLucideIcon("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
|
|
132
142
|
* @license lucide-react v0.453.0 - ISC
|
|
133
143
|
*
|
|
134
144
|
* This source code is licensed under the ISC license.
|
|
135
145
|
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
-
*/const
|
|
146
|
+
*/const _s=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
137
147
|
* @license lucide-react v0.453.0 - ISC
|
|
138
148
|
*
|
|
139
149
|
* This source code is licensed under the ISC license.
|
|
140
150
|
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
-
*/const
|
|
151
|
+
*/const Hs=s.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
142
152
|
* @license lucide-react v0.453.0 - ISC
|
|
143
153
|
*
|
|
144
154
|
* This source code is licensed under the ISC license.
|
|
145
155
|
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
-
*/const
|
|
156
|
+
*/const Gs=s.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
|
|
147
157
|
* @license lucide-react v0.453.0 - ISC
|
|
148
158
|
*
|
|
149
159
|
* This source code is licensed under the ISC license.
|
|
150
160
|
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
-
*/const
|
|
161
|
+
*/const $s=s.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
|
|
152
162
|
* @license lucide-react v0.453.0 - ISC
|
|
153
163
|
*
|
|
154
164
|
* This source code is licensed under the ISC license.
|
|
155
165
|
* See the LICENSE file in the root directory of this source tree.
|
|
156
|
-
*/const
|
|
166
|
+
*/const Us=s.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"}]]);/**
|
|
157
167
|
* @license lucide-react v0.453.0 - ISC
|
|
158
168
|
*
|
|
159
169
|
* This source code is licensed under the ISC license.
|
|
160
170
|
* See the LICENSE file in the root directory of this source tree.
|
|
161
|
-
*/const
|
|
171
|
+
*/const Qs=s.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
|
|
162
172
|
* @license lucide-react v0.453.0 - ISC
|
|
163
173
|
*
|
|
164
174
|
* This source code is licensed under the ISC license.
|
|
165
175
|
* See the LICENSE file in the root directory of this source tree.
|
|
166
|
-
*/const
|
|
176
|
+
*/const Js=s.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
|
|
167
177
|
* @license lucide-react v0.453.0 - ISC
|
|
168
178
|
*
|
|
169
179
|
* This source code is licensed under the ISC license.
|
|
170
180
|
* See the LICENSE file in the root directory of this source tree.
|
|
171
|
-
*/const
|
|
181
|
+
*/const Ks=s.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
|
|
172
182
|
* @license lucide-react v0.453.0 - ISC
|
|
173
183
|
*
|
|
174
184
|
* This source code is licensed under the ISC license.
|
|
175
185
|
* See the LICENSE file in the root directory of this source tree.
|
|
176
|
-
*/const
|
|
186
|
+
*/const Ws=s.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
|
|
177
187
|
* @license lucide-react v0.453.0 - ISC
|
|
178
188
|
*
|
|
179
189
|
* This source code is licensed under the ISC license.
|
|
180
190
|
* See the LICENSE file in the root directory of this source tree.
|
|
181
|
-
*/const
|
|
191
|
+
*/const ie=s.createLucideIcon("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
182
192
|
* @license lucide-react v0.453.0 - ISC
|
|
183
193
|
*
|
|
184
194
|
* This source code is licensed under the ISC license.
|
|
185
195
|
* See the LICENSE file in the root directory of this source tree.
|
|
186
|
-
*/const
|
|
196
|
+
*/const Zs=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
|
|
187
197
|
* @license lucide-react v0.453.0 - ISC
|
|
188
198
|
*
|
|
189
199
|
* This source code is licensed under the ISC license.
|
|
190
200
|
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
-
*/const
|
|
201
|
+
*/const Ys=s.createLucideIcon("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
|
|
192
202
|
* @license lucide-react v0.453.0 - ISC
|
|
193
203
|
*
|
|
194
204
|
* This source code is licensed under the ISC license.
|
|
@@ -198,27 +208,27 @@
|
|
|
198
208
|
*
|
|
199
209
|
* This source code is licensed under the ISC license.
|
|
200
210
|
* See the LICENSE file in the root directory of this source tree.
|
|
201
|
-
*/const
|
|
211
|
+
*/const Xs=s.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
|
|
202
212
|
* @license lucide-react v0.453.0 - ISC
|
|
203
213
|
*
|
|
204
214
|
* This source code is licensed under the ISC license.
|
|
205
215
|
* See the LICENSE file in the root directory of this source tree.
|
|
206
|
-
*/const
|
|
216
|
+
*/const et=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
|
|
207
217
|
* @license lucide-react v0.453.0 - ISC
|
|
208
218
|
*
|
|
209
219
|
* This source code is licensed under the ISC license.
|
|
210
220
|
* See the LICENSE file in the root directory of this source tree.
|
|
211
|
-
*/const
|
|
221
|
+
*/const st=s.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
|
|
212
222
|
* @license lucide-react v0.453.0 - ISC
|
|
213
223
|
*
|
|
214
224
|
* This source code is licensed under the ISC license.
|
|
215
225
|
* See the LICENSE file in the root directory of this source tree.
|
|
216
|
-
*/const
|
|
226
|
+
*/const tt=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
|
|
217
227
|
* @license lucide-react v0.453.0 - ISC
|
|
218
228
|
*
|
|
219
229
|
* This source code is licensed under the ISC license.
|
|
220
230
|
* See the LICENSE file in the root directory of this source tree.
|
|
221
|
-
*/const
|
|
231
|
+
*/const at=s.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0Z",key:"wtfw2c"}]]);/**
|
|
222
232
|
* @license lucide-react v0.453.0 - ISC
|
|
223
233
|
*
|
|
224
234
|
* This source code is licensed under the ISC license.
|
|
@@ -228,42 +238,42 @@
|
|
|
228
238
|
*
|
|
229
239
|
* This source code is licensed under the ISC license.
|
|
230
240
|
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
-
*/const
|
|
241
|
+
*/const Ze=s.createLucideIcon("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
232
242
|
* @license lucide-react v0.453.0 - ISC
|
|
233
243
|
*
|
|
234
244
|
* This source code is licensed under the ISC license.
|
|
235
245
|
* See the LICENSE file in the root directory of this source tree.
|
|
236
|
-
*/const
|
|
246
|
+
*/const nt=s.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
|
|
237
247
|
* @license lucide-react v0.453.0 - ISC
|
|
238
248
|
*
|
|
239
249
|
* This source code is licensed under the ISC license.
|
|
240
250
|
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
-
*/const
|
|
251
|
+
*/const rt=s.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"}]]);/**
|
|
242
252
|
* @license lucide-react v0.453.0 - ISC
|
|
243
253
|
*
|
|
244
254
|
* This source code is licensed under the ISC license.
|
|
245
255
|
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
-
*/const
|
|
256
|
+
*/const ot=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
247
257
|
* @license lucide-react v0.453.0 - ISC
|
|
248
258
|
*
|
|
249
259
|
* This source code is licensed under the ISC license.
|
|
250
260
|
* See the LICENSE file in the root directory of this source tree.
|
|
251
|
-
*/const
|
|
261
|
+
*/const Ye=s.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
|
|
252
262
|
* @license lucide-react v0.453.0 - ISC
|
|
253
263
|
*
|
|
254
264
|
* This source code is licensed under the ISC license.
|
|
255
265
|
* See the LICENSE file in the root directory of this source tree.
|
|
256
|
-
*/const
|
|
266
|
+
*/const it=s.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"}]]);/**
|
|
257
267
|
* @license lucide-react v0.453.0 - ISC
|
|
258
268
|
*
|
|
259
269
|
* This source code is licensed under the ISC license.
|
|
260
270
|
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
-
*/const
|
|
271
|
+
*/const lt=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
|
|
262
272
|
* @license lucide-react v0.453.0 - ISC
|
|
263
273
|
*
|
|
264
274
|
* This source code is licensed under the ISC license.
|
|
265
275
|
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
-
*/const
|
|
276
|
+
*/const ct=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
267
277
|
* @license lucide-react v0.453.0 - ISC
|
|
268
278
|
*
|
|
269
279
|
* This source code is licensed under the ISC license.
|
|
@@ -273,12 +283,12 @@
|
|
|
273
283
|
*
|
|
274
284
|
* This source code is licensed under the ISC license.
|
|
275
285
|
* See the LICENSE file in the root directory of this source tree.
|
|
276
|
-
*/const
|
|
286
|
+
*/const dt=s.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
|
|
277
287
|
* @license lucide-react v0.453.0 - ISC
|
|
278
288
|
*
|
|
279
289
|
* This source code is licensed under the ISC license.
|
|
280
290
|
* See the LICENSE file in the root directory of this source tree.
|
|
281
|
-
*/const
|
|
291
|
+
*/const ut=s.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
|
|
282
292
|
* @license lucide-react v0.453.0 - ISC
|
|
283
293
|
*
|
|
284
294
|
* This source code is licensed under the ISC license.
|
|
@@ -288,12 +298,12 @@
|
|
|
288
298
|
*
|
|
289
299
|
* This source code is licensed under the ISC license.
|
|
290
300
|
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
-
*/const
|
|
301
|
+
*/const ht=s.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"}]]);/**
|
|
292
302
|
* @license lucide-react v0.453.0 - ISC
|
|
293
303
|
*
|
|
294
304
|
* This source code is licensed under the ISC license.
|
|
295
305
|
* See the LICENSE file in the root directory of this source tree.
|
|
296
|
-
*/const es=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 Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(l=>ss(l))}})}})}}function ss(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:ut(t.customCfg),data:[]}}function ut(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function ht(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:i,shared:l}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:i,shared:l,operation:"update"})}async function mt(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function xt(){const[t,n]=S.useState(""),[a,r]=S.useState(!1),o=s.useDashboardStore(m=>m.lenses),{setLenses:i,setSelectedLensId:l}=s.useDashboardActions(),[d,h]=S.useState(!1),[g,u]=S.useState(!1),f=s.useDashboardStore(m=>m.dashboard),b=s.useDashboardStore(m=>m.filterValues),{authToken:c}=s.useSemaphorContext();async function p(){h(!0);const m=Ie(f),y=await ht(t,m,b,c==null?void 0:c.accessToken);y&&(i([...o||[],y]),l(y.id),u(!1)),h(!1)}return e.jsxs(s.Dialog,{open:g,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:m=>{n(m.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:p,disabled:d,children:d?"Creating...":"Add"})})]})]})}function pt(){const[t,n]=S.useState(!1),a=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:l}=s.useSemaphorContext();async function d(u){i(u)}async function h(u){if(await mt(u,l==null?void 0:l.accessToken)){const b=a==null?void 0:a.filter(c=>c.id!==u);o(b||[]),i("original")}}async function g(u){const f=a==null?void 0:a.map(p=>p.id===u.id?{...p,isDefault:!u.isDefault}:{...p,isDefault:!1});o(f||[]);const b={...u,isDefault:!u.isDefault};await ve(b,l==null?void 0:l.accessToken);const c=a==null?void 0:a.find(p=>p.isDefault);if(c&&c.id!==u.id){const p={...c,isDefault:!1};await ve(p,l==null?void 0:l.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Bs,{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"}),a==null?void 0:a.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(Gs,{onClick:f=>{f.preventDefault(),g(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:f=>{f.preventDefault(),h(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 ts(){var i;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(i=s.useDashboardStore.getState().dashboard)==null?void 0:i.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:n||"light",filterValues:a,dashboardTitle:r||"",selectedSheetId:o||""}}async function as(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:n,theme:a,filterValues:r,dashboardTitle:o,selectedSheetId:i}=ts();if(t)return;const l=new URLSearchParams;l.set("token",(n==null?void 0:n.accessToken)||""),l.set("theme",a),l.set("filterValues",JSON.stringify(r)),l.set("selectedSheetId",i||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${n==null?void 0:n.accessToken}`}})).json()).url,f=document.createElement("a");f.href=u;const b=`${o}-${new Date().toISOString()}.pdf`;f.download=b,f.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function ft({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await as()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:a?e.jsx(ue,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function ee({defaultValue:t,label:n,options:a,value:r,onValueChange:o,className: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",i),children:e.jsx(s.SelectValue,{placeholder:n})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}const Oe=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"monthly",label:"Monthly"}];function ns(){const{authToken:t}=s.useSemaphorContext(),{data:n,handleScheduleSubscription:a,handleDeleteSubscription:r,status:o,error:i}=gt(),[l,d]=S.useState(""),[h,g]=S.useState(Oe[0].value),[u,f]=S.useState("00:00"),[b,c]=S.useState(""),p=s.useDashboardStore(m=>m.dashboard.title);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:"h-7 p-2",children:e.jsx(s.Calendar,{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:"Set up email subscription for your dashboard"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:l,onChange:m=>d(m.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:b||p,onChange:m=>c(m.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:"frequency",children:"Frequency"}),e.jsx(ee,{className:"col-span-2",label:"Select Frequency",options:Oe,value:h,onValueChange:m=>g(m)})]}),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:u,onChange:m=>f(m.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:()=>a({email:l,frequency:h,time:u,subject:b}),className:"h-8 p-2",disabled:o==="loading"||!l,children:[o==="loading"&&e.jsx(ue,{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(Ue,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:i})})]}),"Schedule"]})}),n&&n.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Separator,{className:"my-2"}),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"})]}),e.jsx("div",{className:"grid gap-2",children:n==null?void 0:n.map(m=>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(m.frequency)," "]}),e.jsx(s.Label,{children:m.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Fe,{tooltip:`${m.endUserEmail}`,children:e.jsx(Ws,{className:"size-3.5"})}),e.jsx(Fe,{tooltip:`Next Run: ${new Date(m.nextRun).toLocaleString()} ${m.timezone}`,children:e.jsx(s.Info,{className:"size-3.5"})}),e.jsx(dt,{onClick:()=>r(m.id),className:"size-3.5 cursor-pointer"})]})]},m.id))})]})]})]})})]})})}const Fe=({children:t,tooltip:n})=>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:n})]})});function gt(){const t=s.useDashboardStore(m=>m.authToken),n=s.useDashboardStore(m=>m.dashboard.id),{endUserId:a}=s.getTenantAndEndUserId((t==null?void 0:t.accessToken)||""),r="https://semaphor.cloud/api/v1/subscriptions/get",o={dashboardId:n,endUserId:a},{data:i,isLoading:l,isError:d,refetch:h}=s.useQuery({queryKey:["subscriptions",n,a],queryFn:()=>s.getRequest(r,(t==null?void 0:t.accessToken)||"",o),enabled:!!(t!=null&&t.accessToken)&&!!n&&!!a}),[g,u]=S.useState("idle"),[f,b]=S.useState("");async function c({email:m,subject:y,frequency:j,time:I}){const{authToken:C,...E}=ts(),D=Intl.DateTimeFormat().resolvedOptions().timeZone,O={email:m,frequency:j,time:I,timezone:D,endUserId:a,endUserEmail:m,subject:y,dashboardId:n,dashboardParams:E};u("loading");const V="https://semaphor.cloud/api/v1/subscriptions/create";try{const R=await s.postRequestRegular(V,(C==null?void 0:C.accessToken)||"",{...O});u("success"),b(""),h(),setTimeout(()=>{u("idle")},2e3)}catch(R){console.error(R),u("error"),b(R.message)}}async function p(m){const y="https://semaphor.cloud/api/v1/subscriptions/delete";try{await s.postRequestRegular(y,(t==null?void 0:t.accessToken)||"",{id:m}),h()}catch(j){console.error(j),u("error"),b(j.message)}}return{data:i,isLoading:l,isError:d,refetch:h,handleScheduleSubscription:c,handleDeleteSubscription:p,status:g,error:f}}function jt(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(x=>x.theme);const n=s.useDashboardStore(x=>x.lenses),a=s.useDashboardStore(x=>x.selectedLensId),r=n==null?void 0:n.find(x=>x.id===a),o=s.useDashboardStore(x=>x.dashboard);s.useDashboardStore(x=>x.selectedSheetId);const i=s.useDashboardStore(x=>x.isDashboardEditing),l=s.useEditorStore(x=>x.selectedConnectionId),[d,h]=S.useState(!1),g=s.useDashboardStore(x=>x.filterValues),u=s.useDashboardStore(x=>x.isVisualEditing),f=s.useDashboardStore(x=>x.showFilters);s.useDashboardStore(x=>x.showDashboardJSON);const b=s.useDashboardStore(x=>x.onSaveFunction),c=s.useDashboardStore(x=>x.actions.setShowFilters),{addFrame:p,setSelectedFrameId:m}=s.useDashboardStore(x=>x.actions),{getSelectedSheet:y,setIsDashboardEditing:j,setShowDashboardJSON:I}=s.useDashboardStore(x=>x.actions),C=y(),{tenantId:E,endUserId:D}=S.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),O=S.useMemo(()=>E||D,[E,D]),V=()=>{if(!i||!C)return;const x={connectionId:l,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},A={id:s.v4(),cards:[x],activeCardId:x.id};p(C.id,A),m(A.id)},R=()=>{j(!0)};async function B(){if(h(!0),!a||!r)return;const x=Ie(o),A=JSON.stringify(x),P={...r,template:A,filterValues:g};await ve(P,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),b==null||b(x),h(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-2 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,e.jsx(ft,{}),e.jsx(ns,{}),i&&!u&&O&&e.jsx(xt,{}),!u&&O&&e.jsx(pt,{}),i&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:V,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!i&&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"})}),i&&!u&&e.jsx(s.IconButton,{className:"h-7 p-2",onClick:()=>{j(!1),I(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),i&&!u&&O&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:B,size:"sm",children:e.jsx(nt,{className:"h-4 w-4"})}),!f&&!u&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),!u&&i&&!1,!u&&!1]})]})}function bt({name:t,items:n,value:a,onChange:r,isLoading:o,isError:i,refetch:l,className:d,showNone:h=!1}){const g=de.useRef(null),[u,f]=de.useState(!1),[b,c]=de.useState("100%"),p=h?[...n||[],{id:"none",name:"None"}]:n;de.useLayoutEffect(()=>{g.current&&c(g.current.offsetWidth)},[]);function m(){var j;return o?"Loading...":i?"Error":a?(j=n==null?void 0:n.find(I=>I.id===a))==null?void 0:j.name:`Select ${t}`}function y(j,I){r(I),f(!1)}return e.jsxs(s.Popover,{open:u,onOpenChange:f,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:g,variant:"outline",role:"combobox","aria-expanded":u,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",d),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:m()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:b},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:l,children:e.jsx(Ye,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:p==null?void 0:p.map(j=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:j.name,onSelect:I=>y(I,j.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===j.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:j.name,children:j.name})]})},j.id))})]})]})})]})}function ce({title:t,items:n,value:a,isLoading:r,isError:o,refetch:i,connectionTooltip:l,onChange:d,showNone:h=!1,className:g,showIcon:u=!0,disabled:f=!1,type:b="select"}){const c=r?"Loading...":o?"Error":a;function p(){if(t==="Connection")return e.jsx(st,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(Fs,{className:"size-4"});if(t==="Schema")return e.jsx(et,{className:"size-4"});if(t==="Table")return e.jsx(ke,{className:"size-4"});if(t==="Model")return e.jsx(Ls,{className:"size-4"})}function m(){return e.jsxs(s.Select,{disabled:f,value:c,onValueChange:d,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",g),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(Ye,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:i})]}),e.jsxs(e.Fragment,{children:[h&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((j,I)=>e.jsx(s.SelectItem,{value:j.id,children:j.name},I))]}),(r||o)&&e.jsx(s.SelectItem,{value:c,children:c})]})})]})}function y(){return e.jsx(bt,{items:n,value:c,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:i,name:t,showNone:h})}return e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:p()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):p()}),b==="combobox"?y():m()]})}function yt({column:t}){const[n,a]=S.useState(!1),r=s.useEditorStore(p=>p.selectedTableName),o=s.useEditorStore(p=>p.selectedSchemaName),i=s.useEditorStore(p=>p.selectedDatamodelId),l=s.useEditorStore(p=>p.sqlGen),{modelItems:d,connectionType:h}=ae(),g=s.useEditorStore(p=>p.actions.setSqlGen),u=s.useEditorStore(p=>p.actions.setCardSql),f=s.useEditorStore(p=>p.actions.setRunSql);function b(p,m){var C;const y=s.createSqlGenConfig(p,l,m),j=(C=d==null?void 0:d.find(E=>E.id===i))==null?void 0:C.name;g(y);const I=s.getSql(y,s.fmt(o||""),s.fmt(r),j,h);I&&(u(I),f(!0)),a(!1)}function c(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>b(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>b(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>b(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>b(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>b(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(Je,{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:c()})]})}function rs({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(es,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Hs,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(ct,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(As,{className:"size-3"}):e.jsx(rt,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function St({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(x=>x.sqlGen),i=s.useEditorStore(x=>x.selectedConnectionId),l=s.useEditorStore(x=>x.selectedDatabaseName),d=s.useEditorStore(x=>x.selectedSchemaName),h=s.useEditorStore(x=>x.selectedTableName),g=s.useEditorStore(x=>x.selectedDatamodelId),u=s.useDashboardStore(x=>x.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:c}=s.useDashboardStore(x=>x.actions),p=s.useEditorStore(x=>x.actions.setRunSql),m=s.useEditorStore(x=>x.actions.setSqlGen),y=s.useEditorStore(x=>x.actions.setIsShowingVisual),j=s.useEditorStore(x=>x.actions.setCardSql),{connectionType:I,modelItems:C,selectedDatamodelName:E}=ae();function D(x){var q;const A=s.createSqlGenConfig(x,o);m(A);const P=(q=C==null?void 0:C.find(G=>G.id===g))==null?void 0:q.name,z=s.getSql(A,s.fmt(t),s.fmt(n),P,I);z&&(j(z),p(!0))}function O(){return(u==null?void 0:u.find(x=>x.connectionId===i&&(x.tableName===h||x.datamodelName===E)))!==void 0}function V(x){x===!0&&(h||E)&&i?(f({connectionId:i,connectionType:I==="S3"||I==="API"?"DuckDb":I,databaseName:l||"",schemaName:d||"",tableName:h||"",datamodelName:s.resolveDatamodelName(E),datamodelId:g||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:i||"",connectionType:I||"",tableName:h||"",datamodelName:s.resolveDatamodelName(E),datamodelId:g||"",databaseName:l||"",schemaName:d||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function R(){const x=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:E,connectionType:I});y(!1);const A=I==="MSSQL"?`SELECT top 10 * FROM ${x}`:`SELECT * FROM ${x} LIMIT 10`;j(A),p(!0)}function B(){const x=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:E,connectionType:I});j(`SELECT COUNT(*) as count FROM ${x}`),p(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${O()?"Remove from":"Add to"} Assistant Scope`,pressed:O(),onPressedChange:V,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":O(),"text-muted-foreground":!O()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ue,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ks,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:B,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ue,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(ot,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(x=>e.jsxs("div",{onClick:()=>D(x),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(x,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(rs,{column:x}),e.jsx("span",{children:x.column_name})]}),e.jsx("div",{onClick:A=>A.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(x.data_type)&&e.jsx(yt,{column:x})})]},x.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ae(t,n){var De,Te,Le,Ae,Me,ze;let a=S.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(w=>w.selectedConnectionId),i=s.useEditorStore(w=>w.selectedDatamodelId),l=s.useEditorStore(w=>w.selectedDatabaseName),d=s.useEditorStore(w=>w.selectedSchemaName),h=s.useEditorStore(w=>w.selectedTableName),g=s.useEditorStore(w=>w.actions.setCurrentColumns),u=s.useEditorStore(w=>w.actions.setSelectedConnectionId),f=s.useEditorStore(w=>w.actions.setSelectedDatamodelId),b=s.useEditorStore(w=>w.actions.setSelectedDatabaseName),c=s.useEditorStore(w=>w.actions.setSelectedSchemaName),p=s.useEditorStore(w=>w.actions.setSelectedTableName);s.useEditorStore(w=>w.actions.setCardSql);function m(w){return o&&l&&d&&l!=="NA"?!0:o&&w==="API"?!1:!!(o&&w==="S3")}function y(w){return!!(o&&l&&l!=="NA"&&d&&h||o&&(w==="S3"||w==="API")||i&&i)}function j(w){return o&&w?!(w==="API"||w==="S3"):!1}const{refetch:I,data:C,isLoading:E,isError:D}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:O,data:V,isLoading:R,isError:B}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),x=C==null?void 0:C.connections.find(w=>w.id===o),A=x==null?void 0:x.type,P=(x==null?void 0:x.type)==="API"||(x==null?void 0:x.type)==="S3",{data:z,isLoading:q,isFetching:G,isError:v,refetch:N}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:j(A)}),{data:T,isLoading:H,isFetching:U,isError:Q,refetch:F}=s.useQuery({queryKey:["schemas",o,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l}),enabled:!!o&&!!l&&!P&&l!=="NA"}),{data:M,isLoading:J,isFetching:k,isError:_,refetch:W}=s.useQuery({queryKey:["tables",o,l,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l,schema_name:d}),enabled:m(A)}),{data:K,isLoading:te,isFetching:se,isError:$,refetch:Y}=s.useQuery({queryKey:["columns",o,l,i,d,h],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:l,schema_name:d,table_name:h}),enabled:y(A)});S.useEffect(()=>{g(a)},[K,g,a]),S.useEffect(()=>{(A==="S3"||A==="API")&&(b(""),c(""),f(""),A==="API"&&p("api"))},[A,p,b,c,f]);const le=(x==null?void 0:x.type)==="API"?(De=x==null?void 0:x.type)==null?void 0:De.toLowerCase():h||"",ne=P?"":d||"";function re(w){c(w),p("")}function L(w){b(w==="none"?"":w),c(""),p(""),w!=="none"&&w!==""&&f("")}function Z(w){u(w)}function oe(w){f(w==="none"?"":w),w!=="none"&&w!==""&&b("")}z&&((Te=z==null?void 0:z.databases)==null?void 0:Te.length)>0,T&&((Le=T==null?void 0:T.schemas)==null?void 0:Le.length)>0,K&&((Ae=K==null?void 0:K.columns)==null?void 0:Ae.length)>0&&(a=K.columns.map(w=>({...w,data_type:w.data_type.toLowerCase()}))),v&&(a=[]),($||D)&&(a=[]);const X=C==null?void 0:C.connections.map(w=>({id:w.id,name:w.name,type:w.type})),xe=(Me=V==null?void 0:V.datamodels)==null?void 0:Me.map(w=>({id:w.id,name:w.name})),Se=z==null?void 0:z.databases.map(w=>({id:w.database_name,name:w.database_name})),fe=T==null?void 0:T.schemas.map(w=>({id:w.schema_name,name:w.schema_name})),Ce=M==null?void 0:M.tables.map(w=>({id:w.table_name,name:w.table_name})),Ss=(ze=V==null?void 0:V.datamodels.find(w=>w.id===i))==null?void 0:ze.name;return{connectionItems:X,isConnectionsLoading:E,isConnectionsError:D,modelItems:xe,selectedDatamodelId:i,selectedDatamodelName:Ss,isModelsLoading:R,isModelsError:B,databaseItems:Se,isDatabasesLoadingOrFetching:q||G,isDatabaseError:v,schemaItems:fe,isSchemaLoadingOrFetching:H||U,isSchemaError:Q,tableItems:Ce,isTableLoadingOrFetching:J||k,isTableError:_,columns:a,isColumnsLoadingOrFetching:te||se,isColumnsError:$,isNonDbConnection:P,connectionType:A,tableName:le,schemaName:ne,refetchConnections:I,refetchModels:O,refetchDatabases:N,refetchSchemas:F,refetchTables:W,refetchColumns:Y,handleConnectionChange:Z,handleDatamodelChange:oe,handleDatabaseChange:L,handleSchemaChange:re}}function os({ColumnsComponent:t}){var se;const n=s.useEditorStore($=>$.selectedConnectionId),a=s.useEditorStore($=>$.selectedDatamodelId),r=s.useEditorStore($=>$.selectedDatabaseName),o=s.useEditorStore($=>$.selectedSchemaName),i=s.useEditorStore($=>$.selectedTableName),l=s.useEditorStore($=>$.actions.setSelectedTableName),{connectionItems:d,modelItems:h,schemaItems:g,databaseItems:u,tableItems:f,columns:b,isConnectionsLoading:c,isModelsLoading:p,isConnectionsError:m,isModelsError:y,isDatabasesLoadingOrFetching:j,isDatabaseError:I,isSchemaLoadingOrFetching:C,isSchemaError:E,isColumnsError:D,isColumnsLoadingOrFetching:O,isTableLoadingOrFetching:V,isTableError:R,connectionType:B,isNonDbConnection:x,refetchDatabases:A,refetchModels:P,refetchSchemas:z,refetchTables:q,refetchColumns:G,refetchConnections:v,handleConnectionChange:N,handleDatabaseChange:T,handleSchemaChange:H,handleDatamodelChange:U,tableName:Q,schemaName:F}=ae();function M(){return t?t(F,Q,b):e.jsx(St,{schemaName:F,tableName:Q,columns:b,status:O?"Loading...":D?"Error":"Success"})}function J(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||B==="S3"||B==="API")return null;if(!a||a==="none")return e.jsx(ce,{refetch:A,showNone:!0,onChange:T,isError:I,isLoading:j,items:u,value:r||"",title:"Database",type:"combobox"})}function _(){if(n&&!x&&(!r||r==="none")&&(!a||a==="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 W(){if(!n||B==="S3"||B==="API")return null;if(!r||r==="none")return e.jsx(ce,{refetch:P,showNone:!0,onChange:U,isError:y,isLoading:p,items:h,value:a||"",title:"Model",type:"combobox"})}function K(){return!n||B==="S3"||B==="API"||!r||r==="none"?null:e.jsx(ce,{refetch:z,onChange:H,isError:E,isLoading:C,items:g,value:o||"",title:"Schema",type:"combobox"})}function te(){function $(){let Y=!1;return B==="API"?(Y=!1,Y):((B==="S3"||n&&r&&r!=="none"&&o)&&(Y=!0),Y)}return $()?e.jsx(ce,{refetch:q,onChange:l,isError:R,items:f,isLoading:V,value:i||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:"flex h-full min-w-[300px] flex-col justify-between rounded-none border-r-[1px]",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ce,{refetch:v,items:d,title:"Connection",value:n||"",onChange:N,isLoading:c,isError:m,type:"combobox",connectionTooltip:((se=d==null?void 0:d.find($=>$.id===n))==null?void 0:se.type)||""}),k(),_(),W(),K(),te()]}),M(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:J,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Ys,{className:"mr-2 size-4"}),"Help"]})})]})}function Ct(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const l=t.substring(0,n),d=t.substring(n);return`${l} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const l=t.substring(0,a),d=t.substring(a);return`${l} {{ filters | where }} ${d}`}else{const l=t.substring(0,i),d=t.substring(i);return console.log("beforeClause",l),console.log("afterClause",d),d?`${l} {{ filters | where }} ${d}`:`${l.replace(/;$/,"")} {{ filters | where }}`}}function vt({sql:t,error:n,onClick:a}){return!t&&!n?null:e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(Ue,{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:[n&&n,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("span",{className:"font-mono",children:t})]})]}),n&&e.jsxs(s.Button,{onClick:a,size:"sm",variant:"secondary",children:[e.jsx(_s,{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},Re=S.createContext&&S.createContext(is),Nt=["attr","size","title"];function wt(t,n){if(t==null)return{};var a=kt(t,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function kt(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function be(){return be=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},be.apply(this,arguments)}function Ve(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ye(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Ve(Object(a),!0).forEach(function(r){It(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ve(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function It(t,n,a){return n=Et(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function Et(t){var n=Dt(t,"string");return typeof n=="symbol"?n:n+""}function Dt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ls(t){return t&&t.map((n,a)=>S.createElement(n.tag,ye({key:a},n.attr),ls(n.child)))}function he(t){return n=>S.createElement(Tt,be({attr:ye({},t.attr)},n),ls(t.child))}function Tt(t){var n=a=>{var{attr:r,size:o,title:i}=t,l=wt(t,Nt),d=o||a.size||"1em",h;return a.className&&(h=a.className),t.className&&(h=(h?h+" ":"")+t.className),S.createElement("svg",be({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,l,{className:h,style:ye(ye({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),i&&S.createElement("title",null,i),t.children)};return Re!==void 0?S.createElement(Re.Consumer,null,a=>n(a)):n(is)}function Lt(t){return he({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 cs(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(m=>m.theme),r=s.useEditorStore(m=>m.frame),o=s.useEditorStore(m=>m.card),i=s.useEditorStore(m=>m.activeTabCardId),l=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:h,setRunSql:g}=s.useEditorActions(),u=S.useRef(),f=S.useRef({}),b=r.cards.find(m=>m.id===i),c=S.useCallback(()=>{let m="";return t==="python"&&(m=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(m=(b==null?void 0:b.sql)||""),m},[t,b]);S.useEffect(()=>{if(i&&o.id&&o.id!==i){if(u.current&&l){const m=u.current.getModel();m&&(f.current[o.id]=m);let y=f.current[i];if(!y){const j=c();y=l.editor.createModel(j,t),f.current[i]=y}u.current.setModel(y)}h(i,o),g(!0)}},[i,o,h,l,g,t,c]),S.useEffect(()=>{if(!l)return;const m=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=a==="system"?m:a;l.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[n,a,l]),S.useEffect(()=>{const m=u.current;m&&l&&o&&m.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return d(),!1})},[l,d,o]);function p(m,y){if(u.current=m,!f.current[o.id]){const j=m.getModel(),I=c();f.current[o.id]=j||(y==null?void 0:y.editor.createModel(I,t))||m.getModel()}m.setModel(f.current[o.id])}return{handleEditorDidMount:p}}function At(){const t=s.useEditorStore(l=>l.card.sql),n=s.useEditorStore(l=>l.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=cs("sql");function i(l){a(l),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function Mt(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=cs("python");function r(o){n(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:a})}function zt({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 ds(t){const[n,a]=S.useState(""),[r,o]=S.useState(null),{authToken:i}=s.useSemaphorContext(),l=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.sql}),d=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.python}),h=s.useEditorStore(k=>k.actions.setCardSql),g=s.useEditorStore(k=>k.actions.setRunSql),u=s.useEditorStore(k=>k.actions.switchCardType),f=s.useEditorStore(k=>k.currentAssitantScope)||[],b=s.useEditorStore(k=>k.userInputForAI),c=s.useEditorStore(k=>k.triggerAIRun),p=s.useEditorStore(k=>k.selectedDatabaseName),m=s.useEditorStore(k=>k.selectedTableName),y=s.useEditorStore(k=>k.selectedConnectionId),j=s.useEditorStore(k=>k.selectedSchemaName),I=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:C,setCurrentAssitantScope:E}=s.useEditorActions(),{selectedDatamodelName:D,connectionType:O,selectedDatamodelId:V}=ae(),{messages:R,setMessages:B,reload:x,append:A,input:P,setInput:z,status:q,handleInputChange:G,handleSubmit:v,stop:N}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${i==null?void 0:i.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:T,onFinish(k,_){H(_.usage),a(""),_.finishReason==="stop"&&a("")}});S.useEffect(()=>{c&&b&&(G({target:{value:b}}),setTimeout(()=>{v(),C(!1)},100))},[c,v,b,C,G]);async function T({toolCall:k}){if(k.toolName==="createChart"){const _=k.args.sql,W=k.args.chartType;return u(W),h(_),g(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")a("Getting table columns...");else{if(k.toolName==="getUserSql")return l?{status:"success",sql:l,python:d||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return a("Getting table scope..."),M(),{status:"success",tables:f};a("Analyzing...")}}function H(k){o(_=>_?{promptTokens:_.promptTokens+k.promptTokens,completionTokens:_.completionTokens+k.completionTokens,totalTokens:_.totalTokens+k.totalTokens}:k)}function U(k){const _=s.removeFromScopeArray(f,k);Q(_)}function Q(k){const _=s.sanitizeAIScope(k);E(_),B(W=>[...W,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(_)}`}])}function F(){const k={databaseName:p||"",schemaName:j||"",tableName:m||"",datamodelId:V||"",datamodelName:s.resolveDatamodelName(D),connectionId:y||"",connectionType:O||""},_=s.dedup([...f,k]);Q(_)}function M(){const k={databaseName:p||"",schemaName:j||"",tableName:m||"",datamodelName:s.resolveDatamodelName(D),connectionId:y||"",connectionType:O||"",datamodelId:V||""};if(!s.isInAiScopeArray([...I||[],...f],k)||f.length===0){const W=s.dedup([...I||[],...f,k]).filter(K=>K.connectionId===k.connectionId);Q(W)}}const J=!["ready","error"].includes(q);return{messages:R,setMessages:B,reload:x,append:A,input:P,setInput:z,isLoading:J,handleSetAIScope:M,handleAddCurrentTableToScope:F,removeFromCurrentSelections:U,currentAssitantScope:f,setCurrentAssitantScope:E,handleInputChange:G,handleSubmit:v,stop:N,chatStatus:q,toolStatus:n,llmUsage:r,onFinish:t}}function Ot(){var re;const[t,n]=S.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=S.useState(!1),[i,l]=S.useState(!1),d=s.useEditorStore(L=>L.frame),h=s.useEditorStore(L=>L.card),g=s.useEditorStore(L=>L.isShowingVisual),u=s.useEditorStore(L=>L.selectedConnectionId),f=s.useEditorStore(L=>L.selectedDatabaseName),b=s.useEditorStore(L=>L.selectedDatamodelId),c=s.useEditorStore(L=>L.selectedSchemaName),p=s.useEditorStore(L=>L.showAIDialog),m=s.useEditorStore(L=>L.selectedTableName),y=s.useEditorStore(L=>{var Z;return(Z=L==null?void 0:L.card)==null?void 0:Z.sql}),{sheetFilterValues:j}=s.useSheetFilterValues(),{setCardCustomCfg:I,setQueryResultColumns:C,setCardSql:E,setPythonStdOut:D,setCardPreferences:O,setCardType:V,setCardPython:R,runAssistant:B,setShowAIDialog:x}=s.useEditorActions(),A=s.useEditorStore(L=>L.onSave),P=s.useEditorStore(L=>L.onClose),z=s.useEditorStore(L=>L.actions.setSqlGen),q=s.useEditorStore(L=>L.runSql),G=s.useEditorStore(L=>L.actions.setRunSql),v=s.useEditorStore(L=>L.actions.setCardCfg),N=s.useEditorStore(L=>L.actions.setIsSqlRunning),{data:T,isLoading:H,isFetching:U,isSuccess:Q,isError:F,error:M,queryKey:J,refetch:k}=s.useDashboardCardQuery(h),{handleSetAIScope:_}=ds();S.useEffect(()=>{if(T&&(T.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),D((T==null?void 0:T.output)||""),T.records.length>0)){const{dimensionKeys:L}=s.getKeys(T.records);C(L)}},[T,C,D]),S.useEffect(()=>{(H||U)&&N(!0),(F||Q)&&N(!1),F&&(C([]),D(""))},[H,U,T,D,F,Q,N,C,M]),S.useEffect(()=>{q&&(a.getQueryData(J)||k(),G(!1))},[q,k,G,J,a]);function W(){const L=a.getQueryData(J);t.queryData||n({queryKey:J,queryData:L}),a.setQueryData(J,null),a.removeQueries({queryKey:J,exact:!0}),E(""),z({}),R(""),v(void 0),I(""),O({}),V("bar")}function K(L,Z){if(L.length===0)return"";if(Z){const oe=L.find(X=>X.id===Z);if(oe){const X=oe.tabTitle;if(X=="All__Header")return L[0].id;if(X&&X.endsWith("__Header")){const Se=X.split("__")[0],fe=L.find(Ce=>Ce.tabTitle===Se);return fe?fe.id:L[0].id}return Z}}return L[0].id}function te(){let L=y;y&&!y.includes("{{")&&(L=Ct(y),E(L));const Z={...h,lastSelectedSchema:c,lastSelectedDatamodelId:b,lastSelectedDatabase:f,lastSelectedTable:m,connectionId:u,type:g?h.type:"table",sql:L,customCfg:g?h.customCfg:null},oe=d.cards.map(xe=>xe.id===h.id?Z:xe),X={...d,cards:oe,activeCardId:K(oe,d.activeCardId)};A==null||A(X)}function se(){const{queryKey:L,queryData:Z}=t;L&&Z&&a.setQueryData(L,Z),z({}),P==null||P()}async function $(){const L=`Can you help me debug this query in the current table scope?
|
|
306
|
+
*/const es=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 Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>ss(i))}})}})}}function ss(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(l=>({...l,data:[]}))}},customCfg:mt(t.customCfg),data:[]}}function mt(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function xt(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:l,shared:i}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function pt(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function ft(){const[t,n]=C.useState(""),[a,r]=C.useState(!1),o=s.useDashboardStore(g=>g.lenses),{setLenses:l,setSelectedLensId:i}=s.useDashboardActions(),[d,h]=C.useState(!1),[f,u]=C.useState(!1),p=s.useDashboardStore(g=>g.dashboard),b=s.useDashboardStore(g=>g.filterValues),{authToken:c}=s.useSemaphorContext();async function m(){h(!0);const g=Ie(p),S=await xt(t,g,b,c==null?void 0:c.accessToken);S&&(l([...o||[],S]),i(S.id),u(!1)),h(!1)}return e.jsxs(s.Dialog,{open:f,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:g=>{n(g.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:m,disabled:d,children:d?"Creating...":"Add"})})]})]})}function gt(){const[t,n]=C.useState(!1),a=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 h(u){if(await pt(u,i==null?void 0:i.accessToken)){const b=a==null?void 0:a.filter(c=>c.id!==u);o(b||[]),l("original")}}async function f(u){const p=a==null?void 0:a.map(m=>m.id===u.id?{...m,isDefault:!u.isDefault}:{...m,isDefault:!1});o(p||[]);const b={...u,isDefault:!u.isDefault};await ve(b,i==null?void 0:i.accessToken);const c=a==null?void 0:a.find(m=>m.isDefault);if(c&&c.id!==u.id){const m={...c,isDefault:!1};await ve(m,i==null?void 0:i.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(_s,{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"}),a==null?void 0:a.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(Us,{onClick:p=>{p.preventDefault(),f(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:p=>{p.preventDefault(),h(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 ts(){var l;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(l=s.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:n||"light",filterValues:a,dashboardTitle:r||"",selectedSheetId:o||""}}async function as(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:n,theme:a,filterValues:r,dashboardTitle:o,selectedSheetId:l}=ts();if(t)return;const i=new URLSearchParams;i.set("token",(n==null?void 0:n.accessToken)||""),i.set("theme",a),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 ${n==null?void 0:n.accessToken}`}})).json()).url,p=document.createElement("a");p.href=u;const b=`${o}-${new Date().toISOString()}.pdf`;p.download=b,p.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function jt({iconClassName:t}){const{authToken:n}=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 a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await as()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:a?e.jsx(ie,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function ee({defaultValue:t,label:n,options:a,value:r,onValueChange:o,className:l}){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.jsx(s.SelectValue,{placeholder:n})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}const Oe=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function ns(){const{data:t,handleScheduleSubscription:n,handleDeleteSubscription:a,status:r,error:o,isDeleting:l}=bt(),[i,d]=C.useState(""),[h,f]=C.useState(Oe[0].value),[u,p]=C.useState("00:00"),[b,c]=C.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:"h-7 p-2",children:e.jsx(Os,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:i,onChange:m=>d(m.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:b,onChange:m=>{c(m.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(ee,{className:"col-span-2 h-8",label:"Select Frequency",options:Oe,value:h,onValueChange:m=>f(m)})]}),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:u,onChange:m=>p(m.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await n({email:i,frequency:h,time:u,subject:b}),p("00:00"),d(""),c("")},className:"h-8 p-2",disabled:r==="loading"||!i,children:[r==="loading"&&e.jsx(ie,{className:"mr-2 size-4 animate-spin"}),r==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),r==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(Ue,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:o})})]}),"Schedule"]})}),t&&t.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",{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.isDev]})}),e.jsx("div",{className:"grid gap-2",children:t==null?void 0:t.map(m=>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(m.frequency)," "]}),e.jsx(s.Label,{children:m.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Fe,{tooltip:`Next Run: ${new Date(m.nextRun).toLocaleString()} ${m.timezone}`,children:e.jsx(zs,{className:"size-3.5"})}),e.jsx(Fe,{tooltip:`${m.endUserEmail}`,children:e.jsx(Ys,{className:"size-3.5"})}),l===m.id?e.jsx(ie,{className:"size-3.5 animate-spin"}):e.jsx(ht,{onClick:()=>a(m.id),className:"size-3.5 cursor-pointer"})]})]},m.id))})]})]})]})})]})})}const Fe=({children:t,tooltip:n})=>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:n})]})});function bt(){const[t,n]=C.useState("idle"),[a,r]=C.useState(""),[o,l]=C.useState(null),i=s.useDashboardStore(y=>y.authToken),d=s.useDashboardStore(y=>y.dashboard.id),h=s.useDashboardStore(y=>y.dashboard.title),{endUserId:f}=s.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",p={dashboardId:d,endUserId:f},{data:b,isLoading:c,isError:m,isFetching:g,refetch:S}=s.useQuery({queryKey:["subscriptions",d,f],queryFn:()=>s.getRequest(u,(i==null?void 0:i.accessToken)||"",p),enabled:!!(i!=null&&i.accessToken)&&!!d&&!!f});async function j({email:y,subject:D,frequency:E,time:O}){const{authToken:V,...R}=ts(),B=Intl.DateTimeFormat().resolvedOptions().timeZone,x={email:y,frequency:E,time:O,timezone:B,endUserId:f,endUserEmail:y,subject:D||h||"Scheduled Dashboard",dashboardId:d,dashboardParams:R};n("loading");const T="https://semaphor.cloud/api/v1/subscriptions/create";try{const q=await s.postRequestRegular(T,(V==null?void 0:V.accessToken)||"",{...x});n("success"),r(""),S(),setTimeout(()=>{n("idle")},2e3)}catch(q){console.error(q),n("error"),r(q.message)}}async function I(y){const D="https://semaphor.cloud/api/v1/subscriptions/delete";l(y);try{await s.postRequestRegular(D,(i==null?void 0:i.accessToken)||"",{id:y}),S(),setTimeout(()=>{l(null)},2e3)}catch(E){console.error(E),l(null),n("error"),r(E.message)}}return{data:b,isLoading:c,isFetching:g,isError:m,isDeleting:o,refetch:S,handleScheduleSubscription:j,handleDeleteSubscription:I,status:t,error:a}}function yt(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(x=>x.theme);const n=s.useDashboardStore(x=>x.lenses),a=s.useDashboardStore(x=>x.selectedLensId),r=n==null?void 0:n.find(x=>x.id===a),o=s.useDashboardStore(x=>x.dashboard);s.useDashboardStore(x=>x.selectedSheetId);const l=s.useDashboardStore(x=>x.isDashboardEditing),i=s.useEditorStore(x=>x.selectedConnectionId),[d,h]=C.useState(!1),f=s.useDashboardStore(x=>x.filterValues),u=s.useDashboardStore(x=>x.isVisualEditing),p=s.useDashboardStore(x=>x.showFilters);s.useDashboardStore(x=>x.showDashboardJSON);const b=s.useDashboardStore(x=>x.onSaveFunction),c=s.useDashboardStore(x=>x.actions.setShowFilters),{addFrame:m,setSelectedFrameId:g}=s.useDashboardStore(x=>x.actions),{getSelectedSheet:S,setIsDashboardEditing:j,setShowDashboardJSON:I}=s.useDashboardStore(x=>x.actions),y=S(),{tenantId:D,endUserId:E}=C.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),O=C.useMemo(()=>D||E,[D,E]),V=()=>{if(!l||!y)return;const x={connectionId:i,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},T={id:s.v4(),cards:[x],activeCardId:x.id};m(y.id,T),g(T.id)},R=()=>{j(!0)};async function B(){if(h(!0),!a||!r)return;const x=Ie(o),T=JSON.stringify(x),q={...r,template:T,filterValues:f};await ve(q,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),b==null||b(x),h(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-2 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(jt,{}),!u&&e.jsx(ns,{}),l&&!u&&O&&e.jsx(ft,{}),!u&&O&&e.jsx(gt,{}),l&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:V,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:()=>{j(!1),I(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),l&&!u&&O&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:B,size:"sm",children:e.jsx(ot,{className:"h-4 w-4"})}),!p&&!u&&l&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>c(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4"})}),!u&&l&&!1,!u&&!1]})]})}function St({name:t,items:n,value:a,onChange:r,isLoading:o,isError:l,refetch:i,className:d,showNone:h=!1}){const f=ue.useRef(null),[u,p]=ue.useState(!1),[b,c]=ue.useState("100%"),m=h?[...n||[],{id:"none",name:"None"}]:n;ue.useLayoutEffect(()=>{f.current&&c(f.current.offsetWidth)},[]);function g(){var j;return o?"Loading...":l?"Error":a?(j=n==null?void 0:n.find(I=>I.id===a))==null?void 0:j.name:`Select ${t}`}function S(j,I){r(I),p(!1)}return e.jsxs(s.Popover,{open:u,onOpenChange:p,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:f,variant:"outline",role:"combobox","aria-expanded":u,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",d),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:g()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:b},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(Ze,{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:m==null?void 0:m.map(j=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:j.name,onSelect:I=>S(I,j.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===j.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:j.name,children:j.name})]})},j.id))})]})]})})]})}function de({title:t,items:n,value:a,isLoading:r,isError:o,refetch:l,connectionTooltip:i,onChange:d,showNone:h=!1,className:f,showIcon:u=!0,disabled:p=!1,type:b="combobox"}){const c=r?"Loading...":o?"Error":a;function m(){if(t==="Connection")return e.jsx(at,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(Vs,{className:"size-4"});if(t==="Schema")return e.jsx(tt,{className:"size-4"});if(t==="Table")return e.jsx(ke,{className:"size-4"});if(t==="Model")return e.jsx(Ls,{className:"size-4"})}function g(){return e.jsxs(s.Select,{disabled:p,value:c,onValueChange:d,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",f),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(Ze,{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:[h&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((j,I)=>e.jsx(s.SelectItem,{value:j.id,children:j.name},I))]}),(r||o)&&e.jsx(s.SelectItem,{value:c,children:c})]})})]})}function S(){return e.jsx(St,{items:n,value:c,onChange:d||(()=>{}),isLoading:r,isError:o,refetch:l,name:t,showNone:h})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"shrink-0",children:i?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:m()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:i})]}):m()}),b==="select"?g():S()]})})}function Ct({column:t}){const[n,a]=C.useState(!1),r=s.useEditorStore(m=>m.selectedTableName),o=s.useEditorStore(m=>m.selectedSchemaName),l=s.useEditorStore(m=>m.selectedDatamodelId),i=s.useEditorStore(m=>m.sqlGen),{modelItems:d,connectionType:h}=ae(),f=s.useEditorStore(m=>m.actions.setSqlGen),u=s.useEditorStore(m=>m.actions.setCardSql),p=s.useEditorStore(m=>m.actions.setRunSql);function b(m,g){var y;const S=s.createSqlGenConfig(m,i,g),j=(y=d==null?void 0:d.find(D=>D.id===l))==null?void 0:y.name;f(S);const I=s.getSql(S,s.fmt(o||""),s.fmt(r),j,h);I&&(u(I),p(!0)),a(!1)}function c(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>b(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>b(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>b(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>b(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>b(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(Je,{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:c()})]})}function rs({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(es,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx($s,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(ut,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(As,{className:"size-3"}):e.jsx(it,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function vt({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(x=>x.sqlGen),l=s.useEditorStore(x=>x.selectedConnectionId),i=s.useEditorStore(x=>x.selectedDatabaseName),d=s.useEditorStore(x=>x.selectedSchemaName),h=s.useEditorStore(x=>x.selectedTableName),f=s.useEditorStore(x=>x.selectedDatamodelId),u=s.useDashboardStore(x=>x.dashboard.aiScopeTables),{addToAIScope:p,removeFromAIScope:b}=s.useDashboardActions(),{setAIScopeTables:c}=s.useDashboardStore(x=>x.actions),m=s.useEditorStore(x=>x.actions.setRunSql),g=s.useEditorStore(x=>x.actions.setSqlGen),S=s.useEditorStore(x=>x.actions.setIsShowingVisual),j=s.useEditorStore(x=>x.actions.setCardSql),{connectionType:I,modelItems:y,selectedDatamodelName:D}=ae();function E(x){var P;const T=s.createSqlGenConfig(x,o);g(T);const q=(P=y==null?void 0:y.find(G=>G.id===f))==null?void 0:P.name,z=s.getSql(T,s.fmt(t),s.fmt(n),q,I);z&&(j(z),m(!0))}function O(){return(u==null?void 0:u.find(x=>x.connectionId===l&&(x.tableName===h||x.datamodelName===D)))!==void 0}function V(x){x===!0&&(h||D)&&l?(p({connectionId:l,connectionType:I==="S3"||I==="API"?"DuckDb":I,databaseName:i||"",schemaName:d||"",tableName:h||"",datamodelName:s.resolveDatamodelName(D),datamodelId:f||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(b({connectionId:l||"",connectionType:I||"",tableName:h||"",datamodelName:s.resolveDatamodelName(D),datamodelId:f||"",databaseName:i||"",schemaName:d||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function R(){const x=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:D,connectionType:I});S(!1);const T=I==="MSSQL"?`SELECT top 10 * FROM ${x}`:`SELECT * FROM ${x} LIMIT 10`;j(T),m(!0)}function B(){const x=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:D,connectionType:I});j(`SELECT COUNT(*) as count FROM ${x}`),m(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${O()?"Remove from":"Add to"} Assistant Scope`,pressed:O(),onPressedChange:V,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":O(),"text-muted-foreground":!O()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:R,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Zs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:B,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(lt,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(x=>e.jsxs("div",{onClick:()=>E(x),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(x,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(rs,{column:x}),e.jsx("span",{children:x.column_name})]}),e.jsx("div",{onClick:T=>T.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(x.data_type)&&e.jsx(Ct,{column:x})})]},x.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ae(t,n){var De,Te,Le,Ae,Me,ze;let a=C.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(w=>w.selectedConnectionId),l=s.useEditorStore(w=>w.selectedDatamodelId),i=s.useEditorStore(w=>w.selectedDatabaseName),d=s.useEditorStore(w=>w.selectedSchemaName),h=s.useEditorStore(w=>w.selectedTableName),f=s.useEditorStore(w=>w.actions.setCurrentColumns),u=s.useEditorStore(w=>w.actions.setSelectedConnectionId),p=s.useEditorStore(w=>w.actions.setSelectedDatamodelId),b=s.useEditorStore(w=>w.actions.setSelectedDatabaseName),c=s.useEditorStore(w=>w.actions.setSelectedSchemaName),m=s.useEditorStore(w=>w.actions.setSelectedTableName);s.useEditorStore(w=>w.actions.setCardSql);function g(w){return o&&i&&d&&i!=="NA"?!0:o&&w==="API"?!1:!!(o&&w==="S3")}function S(w){return!!(o&&i&&i!=="NA"&&d&&h||o&&(w==="S3"||w==="API")||l&&l)}function j(w){return o&&w?!(w==="API"||w==="S3"):!1}const{refetch:I,data:y,isLoading:D,isError:E}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:O,data:V,isLoading:R,isError:B}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),x=y==null?void 0:y.connections.find(w=>w.id===o),T=x==null?void 0:x.type,q=(x==null?void 0:x.type)==="API"||(x==null?void 0:x.type)==="S3",{data:z,isLoading:P,isFetching:G,isError:v,refetch:N}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:j(T)}),{data:L,isLoading:H,isFetching:U,isError:Q,refetch:F}=s.useQuery({queryKey:["schemas",o,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!q&&i!=="NA"}),{data:M,isLoading:J,isFetching:k,isError:_,refetch:W}=s.useQuery({queryKey:["tables",o,i,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:d}),enabled:g(T)}),{data:K,isLoading:te,isFetching:se,isError:$,refetch:Z}=s.useQuery({queryKey:["columns",o,i,l,d,h],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:i,schema_name:d,table_name:h}),enabled:S(T)});C.useEffect(()=>{f(a)},[K,f,a]),C.useEffect(()=>{(T==="S3"||T==="API")&&(b(""),c(""),p(""),T==="API"&&m("api"))},[T,m,b,c,p]);const ce=(x==null?void 0:x.type)==="API"?(De=x==null?void 0:x.type)==null?void 0:De.toLowerCase():h||"",ne=q?"":d||"";function re(w){c(w),m("")}function A(w){b(w==="none"?"":w),c(""),m(""),w!=="none"&&w!==""&&p("")}function Y(w){u(w)}function oe(w){p(w==="none"?"":w),w!=="none"&&w!==""&&b("")}z&&((Te=z==null?void 0:z.databases)==null?void 0:Te.length)>0,L&&((Le=L==null?void 0:L.schemas)==null?void 0:Le.length)>0,K&&((Ae=K==null?void 0:K.columns)==null?void 0:Ae.length)>0&&(a=K.columns.map(w=>({...w,data_type:w.data_type.toLowerCase()}))),v&&(a=[]),($||E)&&(a=[]);const X=y==null?void 0:y.connections.map(w=>({id:w.id,name:w.name,type:w.type})),xe=(Me=V==null?void 0:V.datamodels)==null?void 0:Me.map(w=>({id:w.id,name:w.name})),Se=z==null?void 0:z.databases.map(w=>({id:w.database_name,name:w.database_name})),fe=L==null?void 0:L.schemas.map(w=>({id:w.schema_name,name:w.schema_name})),Ce=M==null?void 0:M.tables.map(w=>({id:w.table_name,name:w.table_name})),Ss=(ze=V==null?void 0:V.datamodels.find(w=>w.id===l))==null?void 0:ze.name;return{connectionItems:X,isConnectionsLoading:D,isConnectionsError:E,modelItems:xe,selectedDatamodelId:l,selectedDatamodelName:Ss,isModelsLoading:R,isModelsError:B,databaseItems:Se,isDatabasesLoadingOrFetching:P||G,isDatabaseError:v,schemaItems:fe,isSchemaLoadingOrFetching:H||U,isSchemaError:Q,tableItems:Ce,isTableLoadingOrFetching:J||k,isTableError:_,columns:a,isColumnsLoadingOrFetching:te||se,isColumnsError:$,isNonDbConnection:q,connectionType:T,tableName:ce,schemaName:ne,refetchConnections:I,refetchModels:O,refetchDatabases:N,refetchSchemas:F,refetchTables:W,refetchColumns:Z,handleConnectionChange:Y,handleDatamodelChange:oe,handleDatabaseChange:A,handleSchemaChange:re}}function os({ColumnsComponent:t}){var se;const n=s.useEditorStore($=>$.selectedConnectionId),a=s.useEditorStore($=>$.selectedDatamodelId),r=s.useEditorStore($=>$.selectedDatabaseName),o=s.useEditorStore($=>$.selectedSchemaName),l=s.useEditorStore($=>$.selectedTableName),i=s.useEditorStore($=>$.actions.setSelectedTableName),{connectionItems:d,modelItems:h,schemaItems:f,databaseItems:u,tableItems:p,columns:b,isConnectionsLoading:c,isModelsLoading:m,isConnectionsError:g,isModelsError:S,isDatabasesLoadingOrFetching:j,isDatabaseError:I,isSchemaLoadingOrFetching:y,isSchemaError:D,isColumnsError:E,isColumnsLoadingOrFetching:O,isTableLoadingOrFetching:V,isTableError:R,connectionType:B,isNonDbConnection:x,refetchDatabases:T,refetchModels:q,refetchSchemas:z,refetchTables:P,refetchColumns:G,refetchConnections:v,handleConnectionChange:N,handleDatabaseChange:L,handleSchemaChange:H,handleDatamodelChange:U,tableName:Q,schemaName:F}=ae();function M(){return t?t(F,Q,b):e.jsx(vt,{schemaName:F,tableName:Q,columns:b,status:O?"Loading...":E?"Error":"Success"})}function J(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||B==="S3"||B==="API")return null;if(!a||a==="none")return e.jsx(de,{refetch:T,showNone:!0,onChange:L,isError:I,isLoading:j,items:u,value:r||"",title:"Database",type:"combobox"})}function _(){if(n&&!x&&(!r||r==="none")&&(!a||a==="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 W(){if(!n||B==="S3"||B==="API")return null;if(!r||r==="none")return e.jsx(de,{refetch:q,showNone:!0,onChange:U,isError:S,isLoading:m,items:h,value:a||"",title:"Model",type:"combobox"})}function K(){return!n||B==="S3"||B==="API"||!r||r==="none"?null:e.jsx(de,{refetch:z,onChange:H,isError:D,isLoading:y,items:f,value:o||"",title:"Schema",type:"combobox"})}function te(){function $(){let Z=!1;return B==="API"?(Z=!1,Z):((B==="S3"||n&&r&&r!=="none"&&o)&&(Z=!0),Z)}return $()?e.jsx(de,{refetch:P,onChange:i,isError:R,items:p,isLoading:V,value:l||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:"flex h-full min-w-[300px] flex-col justify-between rounded-none border-r-[1px]",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(de,{refetch:v,items:d,title:"Connection",value:n||"",onChange:N,isLoading:c,isError:g,type:"combobox",connectionTooltip:((se=d==null?void 0:d.find($=>$.id===n))==null?void 0:se.type)||""}),k(),_(),W(),K(),te()]}),M(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:J,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Xs,{className:"mr-2 size-4"}),"Help"]})})]})}function Nt(t){const n=t.toUpperCase().indexOf("WHERE"),a=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),n!==-1){const i=t.substring(0,n),d=t.substring(n);return`${i} {{ filters | where }} AND ${d.substring(6)}`}else if(a!==-1){const i=t.substring(0,a),d=t.substring(a);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 wt({sql:t,error:n,onClick:a}){return!t&&!n?null:e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(Ue,{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:[n&&n,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("span",{className:"font-mono",children:t})]})]}),n&&e.jsxs(s.Button,{onClick:a,size:"sm",variant:"secondary",children:[e.jsx(Gs,{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},Re=C.createContext&&C.createContext(is),kt=["attr","size","title"];function It(t,n){if(t==null)return{};var a=Et(t,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(t);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function Et(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function be(){return be=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},be.apply(this,arguments)}function Ve(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ye(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Ve(Object(a),!0).forEach(function(r){Dt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Ve(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function Dt(t,n,a){return n=Tt(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function Tt(t){var n=Lt(t,"string");return typeof n=="symbol"?n:n+""}function Lt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function ls(t){return t&&t.map((n,a)=>C.createElement(n.tag,ye({key:a},n.attr),ls(n.child)))}function he(t){return n=>C.createElement(At,be({attr:ye({},t.attr)},n),ls(t.child))}function At(t){var n=a=>{var{attr:r,size:o,title:l}=t,i=It(t,kt),d=o||a.size||"1em",h;return a.className&&(h=a.className),t.className&&(h=(h?h+" ":"")+t.className),C.createElement("svg",be({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,i,{className:h,style:ye(ye({color:t.color||a.color},a.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),l&&C.createElement("title",null,l),t.children)};return Re!==void 0?C.createElement(Re.Consumer,null,a=>n(a)):n(is)}function Mt(t){return he({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 cs(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(g=>g.theme),r=s.useEditorStore(g=>g.frame),o=s.useEditorStore(g=>g.card),l=s.useEditorStore(g=>g.activeTabCardId),i=s.Le(),{refetch:d}=s.useDashboardCardQuery(o),{updateCardTab:h,setRunSql:f}=s.useEditorActions(),u=C.useRef(),p=C.useRef({}),b=r.cards.find(g=>g.id===l),c=C.useCallback(()=>{let g="";return t==="python"&&(g=(b==null?void 0:b.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(g=(b==null?void 0:b.sql)||""),g},[t,b]);C.useEffect(()=>{if(l&&o.id&&o.id!==l){if(u.current&&i){const g=u.current.getModel();g&&(p.current[o.id]=g);let S=p.current[l];if(!S){const j=c();S=i.editor.createModel(j,t),p.current[l]=S}u.current.setModel(S)}h(l,o),f(!0)}},[l,o,h,i,f,t,c]),C.useEffect(()=>{if(!i)return;const g=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=a==="system"?g:a;i.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[n,a,i]),C.useEffect(()=>{const g=u.current;g&&i&&o&&g.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return d(),!1})},[i,d,o]);function m(g,S){if(u.current=g,!p.current[o.id]){const j=g.getModel(),I=c();p.current[o.id]=j||(S==null?void 0:S.editor.createModel(I,t))||g.getModel()}g.setModel(p.current[o.id])}return{handleEditorDidMount:m}}function zt(){const t=s.useEditorStore(i=>i.card.sql),n=s.useEditorStore(i=>i.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=cs("sql");function l(i){a(i),s.isObjectEmpty(n)||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 Ot(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=cs("python");function r(o){n(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:a})}function Ft({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 ds(t){const[n,a]=C.useState(""),[r,o]=C.useState(null),{authToken:l}=s.useSemaphorContext(),i=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.sql}),d=s.useEditorStore(k=>{var _;return(_=k==null?void 0:k.card)==null?void 0:_.python}),h=s.useEditorStore(k=>k.actions.setCardSql),f=s.useEditorStore(k=>k.actions.setRunSql),u=s.useEditorStore(k=>k.actions.switchCardType),p=s.useEditorStore(k=>k.currentAssitantScope)||[],b=s.useEditorStore(k=>k.userInputForAI),c=s.useEditorStore(k=>k.triggerAIRun),m=s.useEditorStore(k=>k.selectedDatabaseName),g=s.useEditorStore(k=>k.selectedTableName),S=s.useEditorStore(k=>k.selectedConnectionId),j=s.useEditorStore(k=>k.selectedSchemaName),I=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:y,setCurrentAssitantScope:D}=s.useEditorActions(),{selectedDatamodelName:E,connectionType:O,selectedDatamodelId:V}=ae(),{messages:R,setMessages:B,reload:x,append:T,input:q,setInput:z,status:P,handleInputChange:G,handleSubmit:v,stop:N}=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:L,onFinish(k,_){H(_.usage),a(""),_.finishReason==="stop"&&a("")}});C.useEffect(()=>{c&&b&&(G({target:{value:b}}),setTimeout(()=>{v(),y(!1)},100))},[c,v,b,y,G]);async function L({toolCall:k}){if(k.toolName==="createChart"){const _=k.args.sql,W=k.args.chartType;return u(W),h(_),f(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")a("Getting table columns...");else{if(k.toolName==="getUserSql")return i?{status:"success",sql:i,python:d||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return a("Getting table scope..."),M(),{status:"success",tables:p};a("Analyzing...")}}function H(k){o(_=>_?{promptTokens:_.promptTokens+k.promptTokens,completionTokens:_.completionTokens+k.completionTokens,totalTokens:_.totalTokens+k.totalTokens}:k)}function U(k){const _=s.removeFromScopeArray(p,k);Q(_)}function Q(k){const _=s.sanitizeAIScope(k);D(_),B(W=>[...W,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(_)}`}])}function F(){const k={databaseName:m||"",schemaName:j||"",tableName:g||"",datamodelId:V||"",datamodelName:s.resolveDatamodelName(E),connectionId:S||"",connectionType:O||""},_=s.dedup([...p,k]);Q(_)}function M(){const k={databaseName:m||"",schemaName:j||"",tableName:g||"",datamodelName:s.resolveDatamodelName(E),connectionId:S||"",connectionType:O||"",datamodelId:V||""};if(!s.isInAiScopeArray([...I||[],...p],k)||p.length===0){const W=s.dedup([...I||[],...p,k]).filter(K=>K.connectionId===k.connectionId);Q(W)}}const J=!["ready","error"].includes(P);return{messages:R,setMessages:B,reload:x,append:T,input:q,setInput:z,isLoading:J,handleSetAIScope:M,handleAddCurrentTableToScope:F,removeFromCurrentSelections:U,currentAssitantScope:p,setCurrentAssitantScope:D,handleInputChange:G,handleSubmit:v,stop:N,chatStatus:P,toolStatus:n,llmUsage:r,onFinish:t}}function Rt(){var re;const[t,n]=C.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=C.useState(!1),[l,i]=C.useState(!1),d=s.useEditorStore(A=>A.frame),h=s.useEditorStore(A=>A.card),f=s.useEditorStore(A=>A.isShowingVisual),u=s.useEditorStore(A=>A.selectedConnectionId),p=s.useEditorStore(A=>A.selectedDatabaseName),b=s.useEditorStore(A=>A.selectedDatamodelId),c=s.useEditorStore(A=>A.selectedSchemaName),m=s.useEditorStore(A=>A.showAIDialog),g=s.useEditorStore(A=>A.selectedTableName),S=s.useEditorStore(A=>{var Y;return(Y=A==null?void 0:A.card)==null?void 0:Y.sql}),{sheetFilterValues:j}=s.useSheetFilterValues(),{setCardCustomCfg:I,setQueryResultColumns:y,setCardSql:D,setPythonStdOut:E,setCardPreferences:O,setCardType:V,setCardPython:R,runAssistant:B,setShowAIDialog:x}=s.useEditorActions(),T=s.useEditorStore(A=>A.onSave),q=s.useEditorStore(A=>A.onClose),z=s.useEditorStore(A=>A.actions.setSqlGen),P=s.useEditorStore(A=>A.runSql),G=s.useEditorStore(A=>A.actions.setRunSql),v=s.useEditorStore(A=>A.actions.setCardCfg),N=s.useEditorStore(A=>A.actions.setIsSqlRunning),{data:L,isLoading:H,isFetching:U,isSuccess:Q,isError:F,error:M,queryKey:J,refetch:k}=s.useDashboardCardQuery(h),{handleSetAIScope:_}=ds();C.useEffect(()=>{if(L&&(L.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),E((L==null?void 0:L.output)||""),L.records.length>0)){const{dimensionKeys:A}=s.getKeys(L.records);y(A)}},[L,y,E]),C.useEffect(()=>{(H||U)&&N(!0),(F||Q)&&N(!1),F&&(y([]),E(""))},[H,U,L,E,F,Q,N,y,M]),C.useEffect(()=>{P&&(a.getQueryData(J)||k(),G(!1))},[P,k,G,J,a]);function W(){const A=a.getQueryData(J);t.queryData||n({queryKey:J,queryData:A}),a.setQueryData(J,null),a.removeQueries({queryKey:J,exact:!0}),D(""),z({}),R(""),v(void 0),I(""),O({}),V("bar")}function K(A,Y){if(A.length===0)return"";if(Y){const oe=A.find(X=>X.id===Y);if(oe){const X=oe.tabTitle;if(X=="All__Header")return A[0].id;if(X&&X.endsWith("__Header")){const Se=X.split("__")[0],fe=A.find(Ce=>Ce.tabTitle===Se);return fe?fe.id:A[0].id}return Y}}return A[0].id}function te(){let A=S;S&&!S.includes("{{")&&(A=Nt(S),D(A));const Y={...h,lastSelectedSchema:c,lastSelectedDatamodelId:b,lastSelectedDatabase:p,lastSelectedTable:g,connectionId:u,type:f?h.type:"table",sql:A,customCfg:f?h.customCfg:null},oe=d.cards.map(xe=>xe.id===h.id?Y:xe),X={...d,cards:oe,activeCardId:K(oe,d.activeCardId)};T==null||T(X)}function se(){const{queryKey:A,queryData:Y}=t;A&&Y&&a.setQueryData(A,Y),z({}),q==null||q()}async function $(){const A=`Can you help me debug this query in the current table scope?
|
|
297
307
|
|
|
298
308
|
Error:
|
|
299
309
|
|
|
@@ -301,7 +311,7 @@
|
|
|
301
311
|
|
|
302
312
|
Query:
|
|
303
313
|
|
|
304
|
-
${
|
|
314
|
+
${S}
|
|
305
315
|
|
|
306
|
-
`;B(L)}function Y(){return e.jsxs(e.Fragment,{children:[i&&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(zt,{jsonString:JSON.stringify(j,null,2)})})}),j&&j.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!i),className:"absolute bottom-0 right-6 size-7 p-1",children:i?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function le(){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:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(At,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&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(Mt,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const ne=(M==null?void 0:M.message)||((re=T==null?void 0:T.error)==null?void 0:re.message);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:[le(),Y()]}),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:H||U,onClick:()=>{k()},className:"shrink-0",size:"sm",children:[H||U?e.jsx(ue,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(vt,{sql:T==null?void 0:T.sql,error:ne,onClick:$}),e.jsxs(s.Button,{onClick:W,className:"",size:"sm",variant:"secondary",children:[e.jsx(Rs,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:L=>o(L),className:"",size:"sm",children:e.jsx(Lt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:p,onClick:()=>{_(),x(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:p?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:se,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:te,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Ft({data:t}){var l;const[n,a]=S.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:h})=>{const g=h.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>h.toggleSorting(h.getIsSorted()==="asc"),children:[d,g==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):g==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(h=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:h.isPlaceholder?null:s.flexRender(h.column.columnDef.header,h.getContext())},h.id))},d.id))}),e.jsx(s.TableBody,{children:(l=i.getRowModel().rows)!=null&&l.length?i.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(h=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function Rt({card:t}){var I,C,E,D,O,V,R,B,x,A,P;const[n,a]=S.useState(!1),[r,o]=S.useState([]),{authToken:i}=s.useSemaphorContext(),l=s.getTokenParams(i==null?void 0:i.accessToken),d=s.useDashboardStore(z=>z.themeStyle),h={colors:((C=(I=d==null?void 0:d.chart)==null?void 0:I.dataset)==null?void 0:C.backgroundColor)||[]};(E=t.customCardPreferences)!=null&&E.inputData;const{getCard:g}=s.useCustomVisual(((D=t.customCardPreferences)==null?void 0:D.url)||""),u=((O=t.customCardPreferences)==null?void 0:O.visualType)||"single",f=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:c}=s.useDashboardCardQuery(t),p=S.useCallback((z,q)=>{o(G=>({...G,[z]:q}))},[]);if(!((V=t.customCardPreferences)!=null&&V.componentName))return null;const m=g((R=t.customCardPreferences)==null?void 0:R.componentName);function y(z){a(z)}const j=Object.keys(((B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)||{}).map(z=>{var v,N,T;const q=(N=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:N[z].cardId,G=(T=f==null?void 0:f.cards)==null?void 0:T.find(H=>H.id===q);return G||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(S.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[m&&u==="single"&&e.jsx(m,{params:l,theme:h,settings:(x=t.customCardPreferences)==null?void 0:x.settings,onDataChange:p,data:(c==null?void 0:c.records)||[]}),m&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)||{}).map(z=>{var v,N,T;const q=(N=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:N[z].cardId,G=(T=f==null?void 0:f.cards)==null?void 0:T.find(H=>H.id===q);if(G)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:y,onDataChange:p,dataInputIndex:z,card:G},G.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(m,{theme:h,onDataChange:p,settings:j.map(z=>{var q;return(q=z==null?void 0:z.customCardPreferences)==null?void 0:q.settings}),data:j.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(P=t.customCardPreferences)==null?void 0:P.componentName)})}function us({className:t,...n}){var y;const a=s.useEditorStore(j=>j.card),r=((y=a.customCardPreferences)==null?void 0:y.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),i=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:l}=s.useDashboardActions(),d=i==null?void 0:i.find(j=>j.id===o.filterId),{data:h,isLoading:g,isFetching:u}=s.useDashboardCardQuery(a),{setCard:f}=s.useEditorActions(),{data:b}=s.useTopoJson(a);if(!a.id)return null;let c;h!=null&&h.records&&(h==null?void 0:h.records.length)>0&&(c=s.createChartConfig({data:h==null?void 0:h.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}));function p(j){return e.jsx(Rt,{card:j})}function m(){var j;if(h!=null&&h.records&&(h==null?void 0:h.records.length)===0&&!g&&!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(a.type==="custom")return p(a);if(!["table","custom"].includes(a.type)&&c)return e.jsx(s.ChartJsVisual,{cfg:c},JSON.stringify(c)+JSON.stringify(a.preferences)+((j=a==null?void 0:a.preferences)==null?void 0:j.customVisualCode));if(a.type==="table"&&(h!=null&&h.records)&&(h==null?void 0:h.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:a,data:h==null?void 0:h.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),...n,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:a.title,onSave:j=>f({...a,title:j}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:j=>f({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.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:j=>l({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:m()})]})}const qe=({language:t,value:n,onChange:a,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:n,onChange:a}),Vt=()=>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."})]})]}),qt=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>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-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(qe,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(qe,{language:"javascript",value:t,onChange:r})})]}),Bt=({error:t,hasCustomConfig:n,onReset:a,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:!n,onClick:a,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 Pt(){const[t,n]=S.useState(!1),[a,r]=S.useState(""),[o,i]=S.useState(""),[l,d]=S.useState(""),[h,g]=S.useState(""),u=s.useEditorStore(C=>C.card),f=s.useEditorStore(C=>C.card.customCfg),{data:b}=s.useDashboardCardQuery(u),{data:c}=s.useTopoJson(u),{setCardCustomCfg:p,setCustomVisualCode:m}=s.useEditorActions(),y=C=>{var E,D;return JSON.stringify({...C,data:{...C.data,datasets:(D=(E=C.data)==null?void 0:E.datasets)==null?void 0:D.map(O=>({...O,data:[]}))}},null,2)},j=()=>{var E,D;if(!((E=b==null?void 0:b.records)!=null&&E.length))return;const C=s.createChartConfig({data:b.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:c});if(C){r(y(C)),d(((D=u.preferences)==null?void 0:D.customVisualCode)||"");const O=s.merge(C,f);i(y(O))}},I=()=>{try{if(l&&m(l),o){const C=JSON.parse(o),E=s.getObjectDiff(JSON.parse(a),C);p(E),g("")}}catch{g("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:j,className:f?"text-green-600 hover:text-green-700":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Vt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(qt,{customCode:l,customConfig:o,onConfigChange:C=>i(C??""),onCodeChange:C=>d(C??"")})]}),e.jsx(Bt,{error:h,hasCustomConfig:!!f,onReset:()=>{i(a),p(null)},onApply:I,onClose:()=>n(!1)})]})]})}function hs(t){return he({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 _t(t){return he({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 ms(t){return he({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 xs(t){return he({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 ps(t){return he({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 fs(t){const[n,a]=S.useState(null);return n}function gs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,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:n,isLoading:a,isFetching:r,isError:o}}function Ht({onChartTypeChange:t}){const[n,a]=S.useState([]),{data:r}=gs();return S.useEffect(()=>{(async()=>{var i;if(r){const d=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async h=>(await s.loadManifest(h.value)).visuals.map(f=>({name:f.name,icon:f.icon,url:h.value}))))).flat();a(d)}})()},[r]),n.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:n.map((o,i)=>e.jsx(Gt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Gt=({text:t,icon:n,onClick:a})=>{const r=fs(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function $t(){var f,b;const[t,n]=S.useState(!1),a=s.useEditorStore(c=>c.card),r=a.type,o=s.useDashboardStore(c=>c.isVisualEditing),{setCardType:i,setCardPreferences:l,setChartOrientation:d}=s.useEditorStore(c=>c.actions),{setCardCustomCfg:h,setCustomCardPreferences:g}=s.useEditorActions();function u(c,p){h(null),l({}),i(c),p&&g({type:"component",visualType:"single",url:p.url,componentName:p.name,icon:p.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(Ut,{className:"size-4",chartType:r,customIcon:(f=a.customCardPreferences)==null?void 0:f.icon,componentName:(b=a.customCardPreferences)==null?void 0:b.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(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(xs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx($e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(ms,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(hs,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>u("pyramid"),className:"h-10 p-4",children:e.jsx(Xe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(ps,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(Ts,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(Ze,{className:"size-5"})})]}),e.jsx(Ht,{onChartTypeChange:u})]})]})}function Ut({chartType:t,className:n,customIcon:a,componentName:r}){const o=fs();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(Ge,{className:n});case"radar":return e.jsx(We,{className:n});case"scatter":return e.jsx($e,{className:n});case"bubble":return e.jsx(ms,{className:n});case"doughnut":return e.jsx(Qe,{className:n});case"stackedBar":return e.jsx(_e,{className:n});case"stackedLine":return e.jsx(xs,{className:n});case"polarArea":return e.jsx(hs,{className:n});case"pyramid":return e.jsx(Xe,{className:n});case"range":return e.jsx(He,{className:n});case"kpi":return e.jsx(ps,{className:n});case"text":return e.jsx(es,{className:n});case"map":return e.jsx(Ke,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ze,{className:n});default:return e.jsx(ke,{className:n})}}const ge="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Be(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function Qt(){var v,N,T,H,U,Q;const[t,n]=S.useState(!1),a=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.preferences}),r=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.cfg}),o=s.getNumberAxis(a,r),[i,l]=S.useState(Be(a)),[d,h]=S.useState(((T=(N=(v=a==null?void 0:a.chartOptions)==null?void 0:v.scales)==null?void 0:N[o])==null?void 0:T.min)||""),[g,u]=S.useState(((Q=(U=(H=a==null?void 0:a.chartOptions)==null?void 0:H.scales)==null?void 0:U[o])==null?void 0:Q.max)||""),[f,b]=S.useState(d||g?"custom":"auto"),[c,p]=S.useState(""),[m,y]=S.useState(0),[j,I]=S.useState(""),[C,E]=S.useState(""),[D,O]=S.useState(""),V=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:R}=s.useEditorActions(),B=s.useEditorStore(F=>F.card),x=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.type}),A=["pie","doughnut","polarArea"].includes(x);S.useEffect(()=>{var F,M,J,k,_,W,K,te,se,$,Y,le,ne,re;l(Be(a)),h(((J=(M=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:M[o])==null?void 0:J.min)===0?0:""),u(((W=(_=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:_[o])==null?void 0:W.max)||""),p((($=(se=(te=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:te[o])==null?void 0:se.ticks)==null?void 0:$.stepSize)||""),y(((Y=a==null?void 0:a.numberAxisFormat)==null?void 0:Y.decimalPlaces)||0),I(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),E(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.currency)||""),O(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function P(F,M){return M===""||/^[0-9\b]+$/.test(M)?Number(M):Number(F)}function z(){const F=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(M=>M.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:C||"none",onValueChange:M=>E(M==="none"?"":M),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"}),F.map(M=>e.jsx(s.SelectItem,{value:M,children:M},M))]})})]}),e.jsxs(s.Select,{value:D,onValueChange:M=>O(M),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(M=>e.jsx(s.SelectItem,{value:M.locale,children:M.locale},M.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:m,onChange:M=>y(Number(M.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function q(){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:d,onChange:F=>h(M=>P(M,F.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(s.Input,{value:g,onChange:F=>u(M=>P(M,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),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:c,onChange:F=>p(M=>P(M,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function G(){var k;let F={};f==="custom"&&(F={min:d,max:g,ticks:{stepSize:c}});const M={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales,[o]:{type:i,...i==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:m,suffix:j,currency:C,locale:D}};console.log(M),V(M);const J={...B,preferences:M};R(J)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(at,{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:A,value:i,onValueChange:F=>l(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{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"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:A,id:"scale-option",value:f,onValueChange:F=>b(F),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"})]})]})]}),f==="custom"&&i=="linear"&&q(),z(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:G,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Jt(){const t=s.useEditorStore(d=>{var h,g,u,f;return(f=(u=(g=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:g.plugins)==null?void 0:u.legend)==null?void 0:f.position}),n=s.useEditorStore(d=>{var h,g,u,f;return(f=(u=(g=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:g.plugins)==null?void 0:u.legend)==null?void 0:f.align}),a=s.useEditorStore(d=>{var h,g,u,f;return(f=(u=(g=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:g.plugins)==null?void 0:u.legend)==null?void 0:f.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},i=d=>{r({display:a,position:d,align:n})},l=d=>{r({display:a,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($s,{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:a,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:()=>i("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>i("left"),children:e.jsx(Is,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>i("bottom"),children:e.jsx(ks,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>i("right"),children:e.jsx(Es,{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:()=>l("start"),children:e.jsx(Ns,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>l("center"),children:e.jsx(vs,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>l("end"),children:e.jsx(ws,{className:"size-4"})})]})]})]})]})})]})}function Kt(){var d,h,g;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(u=>u.actions);(d=n==null?void 0:n.options)!=null&&d.indexAxis;function i(u){o(u)}const l=((h=t==null?void 0:t.chartOptions)==null?void 0:h.indexAxis)||((g=n==null?void 0:n.options)==null?void 0:g.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>i(l==="y"?"x":"y"),tooltip:"Chart Orientation",children:l==="y"?e.jsx(Xs,{className:"size-4"}):e.jsx(Zs,{className:"size-4"})})}function Wt(){const t=s.useEditorStore(l=>l.card),n=s.useEditorStore(l=>l.isShowingVisual),a=s.useEditorStore(l=>{var d,h;return(h=(d=l.card)==null?void 0:d.preferences)==null?void 0:h.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function i(){const l=["xy","none","x","y"],h=(l.indexOf(r)+1)%l.length;o(l[h])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Kt,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Qt,{}),e.jsx(Jt,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:i,children:[(r==="xy"||!r)&&e.jsx(Ps,{className:"size-4"}),r==="x"&&e.jsx(zs,{className:"size-4"}),r==="y"&&e.jsx(tt,{className:"size-4"}),r==="none"&&e.jsx(it,{className:"size-4"})]})]}):null}function Pe(){var G;const t=s.useEditorStore(v=>v.frame),n=s.useEditorStore(v=>v.card),a=s.useEditorStore(v=>v.isShowingVisual),r=s.useDashboardStore(v=>v.isVisualEditing),o=s.useEditorStore(v=>v.isSqlRunning),i=s.useEditorStore(v=>v.pythonStdOut),l=s.useEditorStore(v=>{var N;return(N=v.card.preferences)==null?void 0:N.chartOptions});s.useEditorStore(v=>v.actions.setRunSql),s.getChartGridStyle(l);const{setFrame:d,setCard:h,updateCardInFrame:g,setActiveTabCardId:u,runAssistant:f,setChartGrid:b}=s.useEditorActions(),{data:c,isLoading:p,isFetching:m,error:y}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function j(){const v={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};I(v)}function I(v){const N={...t,cards:[...t.cards,v],activeCardId:v.id};d(N),u(v.id)}function C(){const v={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};I(v)}function E(v){const N=t.cards.filter(U=>U.id!==v),T=N[0],H={...t,cards:N,activeCardId:T.id};d(H),u(T.id),h(T)}function D(v){u(v)}const O=(v,N)=>{console.log("handleDragStart",N),v.dataTransfer.setData("tabIndex",N.toString())},V=v=>{v.preventDefault()},R=(v,N)=>{const T=v.dataTransfer.getData("tabIndex");if(T===N.toString())return;const H=Array.from(t.cards),[U]=H.splice(parseInt(T),1);H.splice(N,0,U),d({...t,cards:H})};function B(v,N){return v.cards.length===1&&(N.displayTab===!0||N.displayTab===void 0)||v.activeCardId!==N.id&&(N.displayTab===!0||N.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const T=N.displayTab===void 0?!1:!N.displayTab;h({...N,displayTab:T}),g({...N,displayTab:T})},children:N.displayTab===!0||N.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Vs,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function x(){return e.jsxs(s.Tabs,{onValueChange:D,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(v=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:v.id,children:A()},v.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((v,N)=>e.jsx(s.Editable,{text:v.tabTitle||v.title,onSave:T=>{h({...n,tabTitle:T}),g({...n,tabTitle:T})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:T=>O(T,N),onDragOver:V,onDrop:T=>R(T,N),className:"",value:v.id,children:[B(t,v),v.tabTitle||v.title,t.activeCardId===v.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>E(v.id)})]})},v.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,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:C,children:e.jsx(Os,{className:"h-4 w-4"})})]})})]})}function A(){return n.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:n,data:c==null?void 0:c.records})})}):n.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:o,card:n,data:c==null?void 0:c.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"grow border-none shadow-none"})})}function P(){const v=JSON.stringify(c==null?void 0:c.records,null,2),N=new Blob([v],{type:"application/json"}),T=URL.createObjectURL(N),H=document.createElement("a");H.href=T,H.download=`${n.title}.json`,H.click()}function z(){const N=[Object.keys(c==null?void 0:c.records.reduce((Q,F)=>({...Q,...F}),{})).join(","),...((c==null?void 0:c.records)||[]).map(Q=>Object.values(Q).join(","))].join(`
|
|
307
|
-
`),T=new Blob([N],{type:"text/csv"}),H=URL.createObjectURL(T),U=document.createElement("a");U.href=H,U.download=`${n.title}.csv`,U.click()}function q(){const v=`Can you get the documentation for ${n.type} chart?`;f(v)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(p||m)&&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(ue,{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:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx($t,{}),r&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:q,children:e.jsx(Ds,{className:"size-4"})}),!["table","custom"].includes(n.type)&&r&&e.jsx(Pt,{})]}),!a&&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:z,children:e.jsx(_t,{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:P,children:e.jsx(qs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(c==null?void 0:c.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Wt,{}),e.jsx(Zt,{})]}),a?x():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(Yt,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsx(Ft,{data:(c==null?void 0:c.records)||[]}),(y||(c==null?void 0:c.error))&&e.jsx("span",{className:"font-mono text-xs",children:(y==null?void 0:y.message)||((G=c==null?void 0:c.error)==null?void 0:G.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Yt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=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:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Zt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.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:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Xt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function pe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,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:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function ea(){var m,y;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=gs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:l}=s.useEditorActions(),{components:d,manifest:h}=s.useCustomVisual((t==null?void 0:t.url)||""),g=(m=h==null?void 0:h.visuals)==null?void 0:m.find(j=>j.name===(t==null?void 0:t.componentName));function u(j,I){if(!t)return;const E={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:I,hookRef:null}};l({...t,dataInputCardIds:E})}function f(j){var C,E;const I=(C=o==null?void 0:o.cards)==null?void 0:C.filter(D=>{var O;return((O=D==null?void 0:D.customCardPreferences)==null?void 0:O.visualType)!=="multiple"}).map(D=>({value:D.id,label:D.tabTitle||D.title}));return e.jsx("div",{className:"space-y-2",children:(E=j==null?void 0:j.dataInputs)==null?void 0:E.map((D,O)=>{var V,R;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:D}),e.jsx(ee,{className:"col-span-6 h-8 w-full justify-between",label:"",options:I||[],value:((R=(V=t==null?void 0:t.dataInputCardIds)==null?void 0:V[O])==null?void 0:R.cardId)||"",onValueChange:B=>u(O,B)})]},O+Math.random())})})}function b(j,I,C=[]){var E,D;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((E=t==null?void 0:t.settings)==null?void 0:E[I])||"",onChange:O=>{l({...t,settings:{...t==null?void 0:t.settings,[I]:O.target.value}})}},I):j==="select"?e.jsx(ee,{className:"h-8 w-full",label:"",options:C,value:((D=t==null?void 0:t.settings)==null?void 0:D[I])||"",onValueChange:O=>{l({...t,settings:{...t==null?void 0:t.settings,[I]:O}})}}):null:null}function c(j){const I=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:I.map(([C,E])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:E.title}),b(E.ui,C,E.options)]},C))})}function p(j){t&&l({...t,visualType:j,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(pe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ee,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>l({...t||{url:"",componentName:""},url:j})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Xt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:p}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:d&&e.jsx(ee,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(j=>j.type===i).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),l({...t,componentName:j})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxs(pe,{summary:"Component Settings",children:[g&&g.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:f(g)})]}),g&&g.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(g)})})]})]})}function ie(){const[t,n]=S.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(u=>u.actions),l=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var f;return(f=u.card.preferences)==null?void 0:f.filterOnClickColumnIndex}),S.useEffect(()=>{l&&n(new Array(l.length).fill(!1))},[l]);function d(u,f){var b,c;f?a!=null&&a.onClickFilter&&((b=a==null?void 0:a.onClickFilter)==null?void 0:b.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):i({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(i({...a,onClickFilter:(c=a==null?void 0:a.onClickFilter)==null?void 0:c.filter(p=>p.columnIndex!==u)}),n(p=>{const m=[...p];return m[u]=!1,m}))}function h(u,f){var c;const b=(c=a==null?void 0:a.onClickFilter)==null?void 0:c.map(p=>p.columnIndex===u?{...p,expression:f.target.value}:p);i({...a,onClickFilter:b})}function g(u){var f,b,c,p;if(t!=null&&t[u]||(b=(f=a==null?void 0:a.onClickFilter)==null?void 0:f.find(m=>m.columnIndex===u))!=null&&b.expression)return e.jsx(s.Input,{value:(p=(c=a==null?void 0:a.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===u))==null?void 0:p.expression,onChange:m=>h(u,m),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((u,f)=>{var b,c;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:!!((b=a==null?void 0:a.onClickFilter)!=null&&b.find(p=>p.columnIndex===f)),onCheckedChange:p=>d(f,p)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((c=a==null?void 0:a.onClickFilter)==null?void 0:c.find(p=>p.columnIndex===f))&&e.jsx(s.Pencil,{onClick:()=>{n(p=>{const m=[...p];return m[f]=!p[f],m})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),g(f)]})},u)})]})}function sa({idx:t}){var d;const n=s.useEditorStore(h=>{var g;return(g=h.card)==null?void 0:g.preferences}),a=s.useEditorStore(h=>{var g;return(g=h.card.preferences)==null?void 0:g.datasetOptions}),r=s.useEditorStore(h=>h.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,i=a==null?void 0:a.find(h=>h.idx===t);function l(h,g){(h==="end"||h==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:h!=="none",align:h,anchor:h,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:g,datalabels:u}]});else{const f={...i};f.datalabels=u;const b=a==null?void 0:a.map(c=>c.idx===g?f:c);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(lt,{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:()=>l("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:()=>l("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Us,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Js,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Qs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function js(){const t=s.useEditorStore(g=>g.card),n=s.useEditorStore(g=>{var u,f,b;return(b=(f=(u=g==null?void 0:g.card)==null?void 0:u.preferences)==null?void 0:f.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:l,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let h=l;if(["stackedBar","stackedLine"].includes(t.type)){const g=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:h[0]}),{metricKeys:u}=s.getKeys(g);h=u}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:d[0],children:bs(d[0])})})})]}),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:h.map((g,u)=>e.jsx(ta,{col:g,idx:u},g))})]})]})}function bs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function ta({col:t,idx:n}){const a=s.useEditorStore(d=>{var h;return(h=d.card)==null?void 0:h.preferences}),r=s.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:i}=s.useEditorStore(d=>d.actions);function l(d){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const h={...o};h.type=d==="area"?"line":d,h.fill=d==="area"?"origin":"";const g=r==null?void 0:r.map(u=>u.idx===n?h:u);i({...a,datasetOptions:g})}}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:bs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ms,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(sa,{idx:n})]})]})}function ys(){const t=s.useEditorStore(c=>c.selectedConnectionId),n=s.useEditorStore(c=>c.selectedDatamodelId),a=s.useEditorStore(c=>c.selectedDatabaseName),r=s.useEditorStore(c=>c.selectedSchemaName),o=s.useEditorStore(c=>c.selectedTableName),i=s.useDashboardStore(c=>c.dashboard.filters)||[],l=s.useDashboardStore(c=>c.actions.addFilter),d=s.useDashboardStore(c=>c.actions.removeFilter),{removeFilterValues:h}=s.useDashboardActions(),{modelItems:g,tableName:u,connectionType:f}=ae();function b(c,p="dashboard"){var V;const m=s.fmt(c.column_name),y=s.fmt(a||""),j=s.fmt(r||""),I=s.fmt(u);let C=s.getQualifiedTableName(j,I,f),E=`${C}.${m}`;const D=(V=g==null?void 0:g.find(R=>R.id===n))==null?void 0:V.name;n&&n!=="none"&&(E=`${s.DATAMODEL_NAMESPCACE}.${D}.${m}`,C=`${s.DATAMODEL_NAMESPCACE}.${D}`);const O=i==null?void 0:i.find(R=>R.column===E&&R.table===I&&(R.database===y||R.database===a));if(O)h(O.id),d(O.id);else{const R=s.v4();return u==="api"&&t?(l({location:p,id:R,column:E,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(c.data_type,C,m)}),R):(l({id:R,location:p,column:E,title:c.column_name,dataType:c.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(c.data_type,C,m)}),R)}}return{assignFilter:b}}function me(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ys();function i(d){const h=o(d,"frame");a({...n,filterId:h})}const l=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(aa,{onSelect:i,columns:r}),l&&e.jsx(s.FilterHeader,{filter:l})]})}function aa({columns:t,onSelect:n}){var l;const[a,r]=de.useState(!1),[o,i]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(l=t.find(d=>d.column_name===o))==null?void 0:l.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.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:h=>{const g=h===o?"":h;i(g),r(!1),g&&n(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 na({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:n=>n.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(js,{})})]}),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(ie,{}),e.jsx(me,{})]})]})]})})}function Ee(){var o,i,l;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var u;const h={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},g={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...h}}};n(g),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:(l=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:l.anchor,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"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function ra({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="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"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(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(Ee,{})})]}),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(ie,{}),e.jsx(me,{})]})]})]})})}const oa={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ia={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function la(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:ca(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(ie,{}),e.jsx(me,{})]})]})}function ca(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(oa,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(ia,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 da(){var h,g,u,f,b;const t=s.useEditorStore(c=>c.card.preferences),n=s.useEditorStore(c=>c.actions.setCardPreferences),a=s.useEditorStore(c=>c.actions.setNumberFormat);s.useEditorStore(c=>{var p,m;return(m=(p=c.card.preferences)==null?void 0:p.formatNumber)==null?void 0:m.decimalPlaces});const r=s.useEditorStore(c=>{var p,m;return(m=(p=c.card.preferences)==null?void 0:p.formatNumber)==null?void 0:m.locale}),o=s.useEditorStore(c=>{var p,m;return(m=(p=c.card.preferences)==null?void 0:p.formatNumber)==null?void 0:m.currency});s.useEditorStore(c=>c.actions.setFilterOnClickField);const i=s.useEditorStore(c=>{var p,m;return(m=(p=c.card.preferences)==null?void 0:p.formatNumber)==null?void 0:m.colorRanges})||[],l=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:!!((h=t==null?void 0:t.formatNumber)!=null&&h.enabled),onCheckedChange:c=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:c}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((g=t==null?void 0:t.formatNumber)==null?void 0:g.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 p,m,y;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((m=t==null?void 0:t.formatNumber)==null?void 0:m.currency)||"",c,((y=t==null?void 0:t.formatNumber)==null?void 0:y.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 p,m,y;console.log("currency",c),a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,c==="none"?"":c,((m=t==null?void 0:t.formatNumber)==null?void 0:m.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.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:((f=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:c=>{var p,m,y;return a(Number(c),((p=t==null?void 0:t.formatNumber)==null?void 0:p.currency)||"",((m=t==null?void 0:t.formatNumber)==null?void 0:m.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.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:((b=t==null?void 0:t.formatNumber)==null?void 0:b.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 p,m,y;return a(((p=t==null?void 0:t.formatNumber)==null?void 0:p.decimalPlaces)||0,((m=t==null?void 0:t.formatNumber)==null?void 0:m.currency)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.locale)||"",c.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:l})]})]})}function ua(){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(da,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const ha=[{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"}],ma=["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"],xa=ma.map(t=>({label:t,value:t}));function pa(){var h,g,u,f,b,c,p,m,y,j,I,C,E,D,O,V,R,B;const t=s.useEditorStore(x=>x.card),n=(g=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:g.topoJsonUrl,[a,r]=S.useState(((f=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),l=Object.keys((i==null?void 0:i.objects)||{}).map(x=>({label:x,value:x}))||[],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(pe,{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(pe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ee,{className:"h-9",options:d,onValueChange:x=>{console.log("value",x),o({...t.preferences,mapVisualOptions:{topoJsonUrl:x}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:x=>{r(x.target.value)},onBlur:()=>{var x;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(x=t.preferences)==null?void 0:x.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(ee,{className:"h-9",options:l,value:((c=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:x=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,objectKey:x}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ee,{className:"h-9",options:ha,value:((m=(p=t.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:m.projection)||"",label:"Projection",onValueChange:x=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projection:x}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ee,{className:"h-9",options:xa,value:((j=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:x=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,colorScale:x}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(pe,{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:((C=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:C.projectionScale)||1,onChange:x=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionScale:Number(x.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((O=(D=(E=t.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:D.projectionOffset)==null?void 0:O[0])||0,onChange:x=>{var A,P,z,q;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[Number(x.target.value),((q=(z=(P=t.preferences)==null?void 0:P.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:q[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((B=(R=(V=t.preferences)==null?void 0:V.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:B[1])||0,onChange:x=>{var A,P,z,q;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[((q=(z=(P=t.preferences)==null?void 0:P.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:q[0])||0,Number(x.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function fa(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...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:a,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 je({cardType:t,docContent:n,suffix:a="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)} ${a}`}),e.jsx(s.AccordionContent,{children:n||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(Ee,{}),t==="text"&&e.jsx(fa,{})]})]}),!["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(ie,{}),e.jsx(me,{})]})]})]})})}function ga(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ee,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(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:[a(),e.jsx(js,{})]})]}),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(ie,{}),e.jsx(me,{})]})]})]})})}function ja({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,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(ie,{}),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 ba=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."]})]}),ya=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."]})]}),Sa=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 Ca(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ga,{});case"pyramid":return e.jsx(je,{docContent:ba,cardType:a});case"kpi":return e.jsx(ua,{});case"line":case"bar":return e.jsx(na,{cardType:a});case"range":return e.jsx(je,{docContent:ya,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(ra,{cardType:a});case"table":return e.jsx(ja,{cardType:a});case"text":return e.jsx(je,{docContent:Sa,cardType:a,suffix:"Visual"});case"map":return e.jsx(pa,{});case"custom":return e.jsx(ea,{});default:return e.jsx(la,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function va(){const t=S.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return S.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Ot,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(Ca,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Pe,{})})]}):e.jsx(Pe,{})})]})}const Na=!1,wa=[{title:"Write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function ka(){const t=S.useRef(null),n=S.useRef(null),[a,r]=S.useState(!1),[o,i]=S.useState(Na),[l,d]=S.useState(!1),h=s.useEditorStore(N=>N.actions.setCardSql),g=s.useEditorStore(N=>N.actions.setRunSql),u=s.useEditorStore(N=>N.showAIDialog),{setShowAIDialog:f}=s.useEditorActions(),{messages:b,setMessages:c,reload:p,append:m,input:y,setInput:j,isLoading:I,handleAddCurrentTableToScope:C,removeFromCurrentSelections:E,currentAssitantScope:D,handleInputChange:O,handleSubmit:V,stop:R,chatStatus:B,toolStatus:x,llmUsage:A}=ds();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:b}),S.useEffect(()=>{var N;u&&((N=n.current)==null||N.focus())},[u]);function P(N){h(N),g(!0)}function z(N){const T={role:"user",content:N.title+" "+N.subtitle};m(T)}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(Je,{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:a,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:l,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"}),D&&D.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:D==null?void 0:D.map((N,T)=>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:N.schemaName||"",tableName:N.tableName||"",modelName:N.datamodelName||"",connectionType:N.connectionType||""}),e.jsx("button",{onClick:()=>{E(N)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},T))}),(D==null?void 0:D.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:C,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const v=(y==null?void 0:y.length)===0&&(b==null?void 0:b.filter(N=>N.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:[q(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),p()},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:()=>{f(!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:b,showTools:o,handleRun:P,showSystemMessage:l}),e.jsx(s.ChatStatus,{status:s.getStatus(B,x),isLoading:I})]})}),v&&e.jsx(s.Placeholders,{onClick:z,placeholders:wa}),e.jsx(s.ChatInput,{onFocus:()=>{C()},stop:R,ref:n,setInput:j,input:y,handleInputChange:O,handleSubmit:V,isLoading:I}),A&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",A.promptTokens," prompt tokens,"," ",A.completionTokens," completion tokens,"," ",A.totalTokens," total tokens"]})})]})}function Ia({authToken:t,onSave:n,onClose:a}){const r=S.useRef(null),o=s.useEditorStore(f=>f.showAIDialog),{setAuthToken:i}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:d,setOnClose:h}=s.useEditorActions();S.useEffect(()=>{n&&d(n),a&&h(a)},[n,d,a,h]),S.useEffect(()=>{t&&t.accessToken&&i(t)},[t,i]),S.useEffect(()=>{var f,b;o?((f=r.current)==null||f.resize(40),l(!0)):(l(!1),(b=r.current)==null||b.resize(0))},[o,l]);function g(f){f<1?l(!1):o||l(!0)}function u(){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(va,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:g,defaultSize:0,children:e.jsx(ka,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(os,{}),u()]})})}function Ea(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(l=>l.actions),a=s.useDashboardStore(l=>l.isVisualEditing),r=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){t&&(r(t,l),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Ia,{onSave:o,onClose:i})})}function Da(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ys();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const l=a==null?void 0:a.find(d=>d.column===s.fmt(i.column_name)&&d.table===n&&d.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(rs,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Ta(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.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(os,{ColumnsComponent:()=>e.jsx(Da,{})})})]})}function La(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.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)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.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 Aa(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(La,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ta,{})})]})}function Ma(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),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),n(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 za({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(Ma,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(jt,{}),e.jsx(Ea,{}),e.jsx(Aa,{})]})]})]})})}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=ns;exports.SelectComponent=ce;exports.Surfboard=za;exports.cleanCard=ss;exports.downloadPdf=as;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ae;
|
|
316
|
+
`;B(A)}function Z(){return e.jsxs(e.Fragment,{children:[l&&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(Ft,{jsonString:JSON.stringify(j,null,2)})})}),j&&j.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>i(!l),className:"absolute bottom-0 right-6 size-7 p-1",children:l?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function ce(){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:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(zt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&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(Ot,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const ne=(M==null?void 0:M.message)||((re=L==null?void 0:L.error)==null?void 0:re.message);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:[ce(),Z()]}),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:H||U,onClick:()=>{k()},className:"shrink-0",size:"sm",children:[H||U?e.jsx(ie,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(wt,{sql:L==null?void 0:L.sql,error:ne,onClick:$}),e.jsxs(s.Button,{onClick:W,className:"",size:"sm",variant:"secondary",children:[e.jsx(qs,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:A=>o(A),className:"",size:"sm",children:e.jsx(Mt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:m,onClick:()=>{_(),x(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:m?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:se,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:te,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Vt({data:t}){var i;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:h})=>{const f=h.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>h.toggleSorting(h.getIsSorted()==="asc"),children:[d,f==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):f==="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:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:l.getHeaderGroups().map(d=>e.jsx(s.TableRow,{children:d.headers.map(h=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:h.isPlaceholder?null:s.flexRender(h.column.columnDef.header,h.getContext())},h.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:"whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(h=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(h.column.columnDef.cell,h.getContext())},h.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function qt({card:t}){var I,y,D,E,O,V,R,B,x,T,q;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:l}=s.useSemaphorContext(),i=s.getTokenParams(l==null?void 0:l.accessToken),d=s.useDashboardStore(z=>z.themeStyle),h={colors:((y=(I=d==null?void 0:d.chart)==null?void 0:I.dataset)==null?void 0:y.backgroundColor)||[]};(D=t.customCardPreferences)!=null&&D.inputData;const{getCard:f}=s.useCustomVisual(((E=t.customCardPreferences)==null?void 0:E.url)||""),u=((O=t.customCardPreferences)==null?void 0:O.visualType)||"single",p=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:b}=s.useEditorActions(),{data:c}=s.useDashboardCardQuery(t),m=C.useCallback((z,P)=>{o(G=>({...G,[z]:P}))},[]);if(!((V=t.customCardPreferences)!=null&&V.componentName))return null;const g=f((R=t.customCardPreferences)==null?void 0:R.componentName);function S(z){a(z)}const j=Object.keys(((B=t.customCardPreferences)==null?void 0:B.dataInputCardIds)||{}).map(z=>{var v,N,L;const P=(N=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:N[z].cardId,G=(L=p==null?void 0:p.cards)==null?void 0:L.find(H=>H.id===P);return G||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(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[g&&u==="single"&&e.jsx(g,{params:i,theme:h,settings:(x=t.customCardPreferences)==null?void 0:x.settings,onDataChange:m,data:(c==null?void 0:c.records)||[]}),g&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((T=t.customCardPreferences)==null?void 0:T.dataInputCardIds)||{}).map(z=>{var v,N,L;const P=(N=(v=t.customCardPreferences)==null?void 0:v.dataInputCardIds)==null?void 0:N[z].cardId,G=(L=p==null?void 0:p.cards)==null?void 0:L.find(H=>H.id===P);if(G)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:m,dataInputIndex:z,card:G},G.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(g,{theme:h,onDataChange:m,settings:j.map(z=>{var P;return(P=z==null?void 0:z.customCardPreferences)==null?void 0:P.settings}),data:j.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(q=t.customCardPreferences)==null?void 0:q.componentName)})}function us({className:t,...n}){var S;const a=s.useEditorStore(j=>j.card),r=((S=a.customCardPreferences)==null?void 0:S.showCardHeader)??!0,o=s.useEditorStore(j=>j.frame),l=s.useDashboardStore(j=>j.dashboard.filters);s.useEditorStore(j=>j.actions.setRunSql);const{updateFilter:i}=s.useDashboardActions(),d=l==null?void 0:l.find(j=>j.id===o.filterId),{data:h,isLoading:f,isFetching:u}=s.useDashboardCardQuery(a),{setCard:p}=s.useEditorActions(),{data:b}=s.useTopoJson(a);if(!a.id)return null;let c;h!=null&&h.records&&(h==null?void 0:h.records.length)>0&&(c=s.createChartConfig({data:h==null?void 0:h.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:b}));function m(j){return e.jsx(qt,{card:j})}function g(){var j;if(h!=null&&h.records&&(h==null?void 0:h.records.length)===0&&!f&&!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(a.type==="custom")return m(a);if(!["table","custom"].includes(a.type)&&c)return e.jsx(s.ChartJsVisual,{cfg:c},JSON.stringify(c)+JSON.stringify(a.preferences)+((j=a==null?void 0:a.preferences)==null?void 0:j.customVisualCode));if(a.type==="table"&&(h!=null&&h.records)&&(h==null?void 0:h.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:a,data:h==null?void 0:h.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),...n,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:a.title,onSave:j=>p({...a,title:j}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:j=>p({...a,description:j}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.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:j=>i({...d,title:j}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:g()})]})}const qe=({language:t,value:n,onChange:a,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:n,onChange:a}),Bt=()=>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."})]})]}),Pt=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>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-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(qe,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(qe,{language:"javascript",value:t,onChange:r})})]}),_t=({error:t,hasCustomConfig:n,onReset:a,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:!n,onClick:a,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 Ht(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,l]=C.useState(""),[i,d]=C.useState(""),[h,f]=C.useState(""),u=s.useEditorStore(y=>y.card),p=s.useEditorStore(y=>y.card.customCfg),{data:b}=s.useDashboardCardQuery(u),{data:c}=s.useTopoJson(u),{setCardCustomCfg:m,setCustomVisualCode:g}=s.useEditorActions(),S=y=>{var D,E;return JSON.stringify({...y,data:{...y.data,datasets:(E=(D=y.data)==null?void 0:D.datasets)==null?void 0:E.map(O=>({...O,data:[]}))}},null,2)},j=()=>{var D,E;if(!((D=b==null?void 0:b.records)!=null&&D.length))return;const y=s.createChartConfig({data:b.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:c});if(y){r(S(y)),d(((E=u.preferences)==null?void 0:E.customVisualCode)||"");const O=s.merge(y,p);l(S(O))}},I=()=>{try{if(i&&g(i),o){const y=JSON.parse(o),D=s.getObjectDiff(JSON.parse(a),y);m(D),f("")}}catch{f("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:j,className:p?"text-green-600 hover:text-green-700":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Bt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Pt,{customCode:i,customConfig:o,onConfigChange:y=>l(y??""),onCodeChange:y=>d(y??"")})]}),e.jsx(_t,{error:h,hasCustomConfig:!!p,onReset:()=>{l(a),m(null)},onApply:I,onClose:()=>n(!1)})]})]})}function hs(t){return he({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 Gt(t){return he({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 ms(t){return he({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 xs(t){return he({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 ps(t){return he({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 fs(t){const[n,a]=C.useState(null);return n}function gs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,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:n,isLoading:a,isFetching:r,isError:o}}function $t({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=gs();return C.useEffect(()=>{(async()=>{var l;if(r){const d=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async h=>(await s.loadManifest(h.value)).visuals.map(p=>({name:p.name,icon:p.icon,url:h.value}))))).flat();a(d)}})()},[r]),n.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:n.map((o,l)=>e.jsx(Ut,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+l))})]})}const Ut=({text:t,icon:n,onClick:a})=>{const r=fs(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function Qt(){var p,b;const[t,n]=C.useState(!1),a=s.useEditorStore(c=>c.card),r=a.type,o=s.useDashboardStore(c=>c.isVisualEditing),{setCardType:l,setCardPreferences:i,setChartOrientation:d}=s.useEditorStore(c=>c.actions),{setCardCustomCfg:h,setCustomCardPreferences:f}=s.useEditorActions();function u(c,m){h(null),i({}),l(c),m&&f({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(Jt,{className:"size-4",chartType:r,customIcon:(p=a.customCardPreferences)==null?void 0:p.icon,componentName:(b=a.customCardPreferences)==null?void 0:b.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(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>u("line"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>u("stackedBar"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>u("stackedLine"),className:"h-10 p-4",children:e.jsx(xs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>u("scatter"),className:"h-10 p-4",children:e.jsx($e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>u("bubble"),className:"h-10 p-4",children:e.jsx(ms,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>u("pie"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>u("doughnut"),className:"h-10 p-4",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>u("radar"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>u("polarArea"),className:"h-10 p-4",children:e.jsx(hs,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>u("pyramid"),className:"h-10 p-4",children:e.jsx(Xe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>u("range"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>u("table"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>u("kpi"),className:"h-10 p-4",children:e.jsx(ps,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>u("text"),className:"h-10 p-4",children:e.jsx(Ts,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>u("map"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>u("custom"),className:"h-10 p-4",children:e.jsx(Ye,{className:"size-5"})})]}),e.jsx($t,{onChartTypeChange:u})]})]})}function Jt({chartType:t,className:n,customIcon:a,componentName:r}){const o=fs();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(Ge,{className:n});case"radar":return e.jsx(We,{className:n});case"scatter":return e.jsx($e,{className:n});case"bubble":return e.jsx(ms,{className:n});case"doughnut":return e.jsx(Qe,{className:n});case"stackedBar":return e.jsx(_e,{className:n});case"stackedLine":return e.jsx(xs,{className:n});case"polarArea":return e.jsx(hs,{className:n});case"pyramid":return e.jsx(Xe,{className:n});case"range":return e.jsx(He,{className:n});case"kpi":return e.jsx(ps,{className:n});case"text":return e.jsx(es,{className:n});case"map":return e.jsx(Ke,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(Ye,{className:n});default:return e.jsx(ke,{className:n})}}const ge="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Be(t,n){var r,o,l;const a=s.getNumberAxis(t,n);return((l=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:l.type)||"linear"}function Kt(){var v,N,L,H,U,Q;const[t,n]=C.useState(!1),a=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.preferences}),r=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.cfg}),o=s.getNumberAxis(a,r),[l,i]=C.useState(Be(a)),[d,h]=C.useState(((L=(N=(v=a==null?void 0:a.chartOptions)==null?void 0:v.scales)==null?void 0:N[o])==null?void 0:L.min)||""),[f,u]=C.useState(((Q=(U=(H=a==null?void 0:a.chartOptions)==null?void 0:H.scales)==null?void 0:U[o])==null?void 0:Q.max)||""),[p,b]=C.useState(d||f?"custom":"auto"),[c,m]=C.useState(""),[g,S]=C.useState(0),[j,I]=C.useState(""),[y,D]=C.useState(""),[E,O]=C.useState(""),V=s.useEditorStore(F=>F.actions.setCardPreferences),{updateCardInFrame:R}=s.useEditorActions(),B=s.useEditorStore(F=>F.card),x=s.useEditorStore(F=>{var M;return(M=F.card)==null?void 0:M.type}),T=["pie","doughnut","polarArea"].includes(x);C.useEffect(()=>{var F,M,J,k,_,W,K,te,se,$,Z,ce,ne,re;i(Be(a)),h(((J=(M=(F=a==null?void 0:a.chartOptions)==null?void 0:F.scales)==null?void 0:M[o])==null?void 0:J.min)===0?0:""),u(((W=(_=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:_[o])==null?void 0:W.max)||""),m((($=(se=(te=(K=a==null?void 0:a.chartOptions)==null?void 0:K.scales)==null?void 0:te[o])==null?void 0:se.ticks)==null?void 0:$.stepSize)||""),S(((Z=a==null?void 0:a.numberAxisFormat)==null?void 0:Z.decimalPlaces)||0),I(((ce=a==null?void 0:a.numberAxisFormat)==null?void 0:ce.suffix)||""),D(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.currency)||""),O(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function q(F,M){return M===""||/^[0-9\b]+$/.test(M)?Number(M):Number(F)}function z(){const F=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(M=>M.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:y||"none",onValueChange:M=>D(M==="none"?"":M),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"}),F.map(M=>e.jsx(s.SelectItem,{value:M,children:M},M))]})})]}),e.jsxs(s.Select,{value:E,onValueChange:M=>O(M),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(M=>e.jsx(s.SelectItem,{value:M.locale,children:M.locale},M.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:g,onChange:M=>S(Number(M.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function P(){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:d,onChange:F=>h(M=>q(M,F.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(s.Input,{value:f,onChange:F=>u(M=>q(M,F.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),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:c,onChange:F=>m(M=>q(M,F.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function G(){var k;let F={};p==="custom"&&(F={min:d,max:f,ticks:{stepSize:c}});const M={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales,[o]:{type:l,...l==="linear"?F:{}}}},numberAxisFormat:{decimalPlaces:g,suffix:j,currency:y,locale:E}};console.log(M),V(M);const J={...B,preferences:M};R(J)}return e.jsxs(s.Popover,{onOpenChange:F=>n(F),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(rt,{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:T,value:l,onValueChange:F=>i(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{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"})]})})]})]}),l=="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:T,id:"scale-option",value:p,onValueChange:F=>b(F),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"})]})]})]}),p==="custom"&&l=="linear"&&P(),z(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:G,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Wt(){const t=s.useEditorStore(d=>{var h,f,u,p;return(p=(u=(f=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:f.plugins)==null?void 0:u.legend)==null?void 0:p.position}),n=s.useEditorStore(d=>{var h,f,u,p;return(p=(u=(f=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:f.plugins)==null?void 0:u.legend)==null?void 0:p.align}),a=s.useEditorStore(d=>{var h,f,u,p;return(p=(u=(f=(h=d.card.preferences)==null?void 0:h.chartOptions)==null?void 0:f.plugins)==null?void 0:u.legend)==null?void 0:p.display}),{setLegendOptions:r}=s.useEditorActions(),o=d=>{r({display:d,position:t,align:n})},l=d=>{r({display:a,position:d,align:n})},i=d=>{r({display:a,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(Qs,{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:a,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(Is,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(ks,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(Es,{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(Ns,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(vs,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(ws,{className:"size-4"})})]})]})]})]})})]})}function Zt(){var d,h,f;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(u=>u.actions);(d=n==null?void 0:n.options)!=null&&d.indexAxis;function l(u){o(u)}const i=((h=t==null?void 0:t.chartOptions)==null?void 0:h.indexAxis)||((f=n==null?void 0:n.options)==null?void 0:f.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>l(i==="y"?"x":"y"),tooltip:"Chart Orientation",children:i==="y"?e.jsx(st,{className:"size-4"}):e.jsx(et,{className:"size-4"})})}function Yt(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>i.isShowingVisual),a=s.useEditorStore(i=>{var d,h;return(h=(d=i.card)==null?void 0:d.preferences)==null?void 0:h.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function l(){const i=["xy","none","x","y"],h=(i.indexOf(r)+1)%i.length;o(i[h])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Zt,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{}),e.jsx(Wt,{})]}),!["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(Hs,{className:"size-4"}),r==="x"&&e.jsx(Fs,{className:"size-4"}),r==="y"&&e.jsx(nt,{className:"size-4"}),r==="none"&&e.jsx(ct,{className:"size-4"})]})]}):null}function Pe(){var G;const t=s.useEditorStore(v=>v.frame),n=s.useEditorStore(v=>v.card),a=s.useEditorStore(v=>v.isShowingVisual),r=s.useDashboardStore(v=>v.isVisualEditing),o=s.useEditorStore(v=>v.isSqlRunning),l=s.useEditorStore(v=>v.pythonStdOut),i=s.useEditorStore(v=>{var N;return(N=v.card.preferences)==null?void 0:N.chartOptions});s.useEditorStore(v=>v.actions.setRunSql),s.getChartGridStyle(i);const{setFrame:d,setCard:h,updateCardInFrame:f,setActiveTabCardId:u,runAssistant:p,setChartGrid:b}=s.useEditorActions(),{data:c,isLoading:m,isFetching:g,error:S}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function j(){const v={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};I(v)}function I(v){const N={...t,cards:[...t.cards,v],activeCardId:v.id};d(N),u(v.id)}function y(){const v={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};I(v)}function D(v){const N=t.cards.filter(U=>U.id!==v),L=N[0],H={...t,cards:N,activeCardId:L.id};d(H),u(L.id),h(L)}function E(v){u(v)}const O=(v,N)=>{console.log("handleDragStart",N),v.dataTransfer.setData("tabIndex",N.toString())},V=v=>{v.preventDefault()},R=(v,N)=>{const L=v.dataTransfer.getData("tabIndex");if(L===N.toString())return;const H=Array.from(t.cards),[U]=H.splice(parseInt(L),1);H.splice(N,0,U),d({...t,cards:H})};function B(v,N){return v.cards.length===1&&(N.displayTab===!0||N.displayTab===void 0)||v.activeCardId!==N.id&&(N.displayTab===!0||N.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const L=N.displayTab===void 0?!1:!N.displayTab;h({...N,displayTab:L}),f({...N,displayTab:L})},children:N.displayTab===!0||N.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Bs,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function x(){return e.jsxs(s.Tabs,{onValueChange:E,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(v=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:v.id,children:T()},v.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((v,N)=>e.jsx(s.Editable,{text:v.tabTitle||v.title,onSave:L=>{h({...n,tabTitle:L}),f({...n,tabTitle:L})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:L=>O(L,N),onDragOver:V,onDrop:L=>R(L,N),className:"",value:v.id,children:[B(t,v),v.tabTitle||v.title,t.activeCardId===v.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>D(v.id)})]})},v.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:j,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:y,children:e.jsx(Rs,{className:"h-4 w-4"})})]})})]})}function T(){return n.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:n,data:c==null?void 0:c.records})})}):n.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:o,card:n,data:c==null?void 0:c.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(us,{className:"grow border-none shadow-none"})})}function q(){const v=JSON.stringify(c==null?void 0:c.records,null,2),N=new Blob([v],{type:"application/json"}),L=URL.createObjectURL(N),H=document.createElement("a");H.href=L,H.download=`${n.title}.json`,H.click()}function z(){const N=[Object.keys(c==null?void 0:c.records.reduce((Q,F)=>({...Q,...F}),{})).join(","),...((c==null?void 0:c.records)||[]).map(Q=>Object.values(Q).join(","))].join(`
|
|
317
|
+
`),L=new Blob([N],{type:"text/csv"}),H=URL.createObjectURL(L),U=document.createElement("a");U.href=H,U.download=`${n.title}.csv`,U.click()}function P(){const v=`Can you get the documentation for ${n.type} chart?`;p(v)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(m||g)&&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(ie,{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:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Qt,{}),r&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:P,children:e.jsx(Ds,{className:"size-4"})}),!["table","custom"].includes(n.type)&&r&&e.jsx(Ht,{})]}),!a&&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:z,children:e.jsx(Gt,{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(Ps,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(c==null?void 0:c.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Yt,{}),e.jsx(ea,{})]}),a?x():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[l&&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:l&&e.jsx(Xt,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsx(Vt,{data:(c==null?void 0:c.records)||[]}),(S||(c==null?void 0:c.error))&&e.jsx("span",{className:"font-mono text-xs",children:(S==null?void 0:S.message)||((G=c==null?void 0:c.error)==null?void 0:G.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Xt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=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:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ea(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.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:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function sa({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function pe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,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:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function ta(){var g,S;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=gs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(j=>j.card),o=s.useEditorStore(j=>j.frame),l=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:i}=s.useEditorActions(),{components:d,manifest:h}=s.useCustomVisual((t==null?void 0:t.url)||""),f=(g=h==null?void 0:h.visuals)==null?void 0:g.find(j=>j.name===(t==null?void 0:t.componentName));function u(j,I){if(!t)return;const D={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:I,hookRef:null}};i({...t,dataInputCardIds:D})}function p(j){var y,D;const I=(y=o==null?void 0:o.cards)==null?void 0:y.filter(E=>{var O;return((O=E==null?void 0:E.customCardPreferences)==null?void 0:O.visualType)!=="multiple"}).map(E=>({value:E.id,label:E.tabTitle||E.title}));return e.jsx("div",{className:"space-y-2",children:(D=j==null?void 0:j.dataInputs)==null?void 0:D.map((E,O)=>{var V,R;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:E}),e.jsx(ee,{className:"col-span-6 h-8 w-full justify-between",label:"",options:I||[],value:((R=(V=t==null?void 0:t.dataInputCardIds)==null?void 0:V[O])==null?void 0:R.cardId)||"",onValueChange:B=>u(O,B)})]},O+Math.random())})})}function b(j,I,y=[]){var D,E;return t?j==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[I])||"",onChange:O=>{i({...t,settings:{...t==null?void 0:t.settings,[I]:O.target.value}})}},I):j==="select"?e.jsx(ee,{className:"h-8 w-full",label:"",options:y,value:((E=t==null?void 0:t.settings)==null?void 0:E[I])||"",onValueChange:O=>{i({...t,settings:{...t==null?void 0:t.settings,[I]:O}})}}):null:null}function c(j){const I=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:I.map(([y,D])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:D.title}),b(D.ui,y,D.options)]},y))})}function m(j){t&&i({...t,visualType:j,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(pe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(ee,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>i({...t||{url:"",componentName:""},url:j})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(sa,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:l,onValueChange:m}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:d&&e.jsx(ee,{className:"h-8 w-full",label:"",options:(d==null?void 0:d.filter(j=>j.type===l).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),i({...t,componentName:j})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(pe,{summary:"Component Settings",children:[f&&f.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:p(f)})]}),f&&f.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:c(f)})})]})]})}function le(){const[t,n]=C.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=s.useEditorStore(u=>u.actions),i=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var p;return(p=u.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),C.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function d(u,p){var b,c;p?a!=null&&a.onClickFilter&&((b=a==null?void 0:a.onClickFilter)==null?void 0:b.length)>0?l({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):l({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(l({...a,onClickFilter:(c=a==null?void 0:a.onClickFilter)==null?void 0:c.filter(m=>m.columnIndex!==u)}),n(m=>{const g=[...m];return g[u]=!1,g}))}function h(u,p){var c;const b=(c=a==null?void 0:a.onClickFilter)==null?void 0:c.map(m=>m.columnIndex===u?{...m,expression:p.target.value}:m);l({...a,onClickFilter:b})}function f(u){var p,b,c,m;if(t!=null&&t[u]||(b=(p=a==null?void 0:a.onClickFilter)==null?void 0:p.find(g=>g.columnIndex===u))!=null&&b.expression)return e.jsx(s.Input,{value:(m=(c=a==null?void 0:a.onClickFilter)==null?void 0:c.find(g=>g.columnIndex===u))==null?void 0:m.expression,onChange:g=>h(u,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(s.Label,{children:"On Click"}),i==null?void 0:i.map((u,p)=>{var b,c;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:!!((b=a==null?void 0:a.onClickFilter)!=null&&b.find(m=>m.columnIndex===p)),onCheckedChange:m=>d(p,m)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((c=a==null?void 0:a.onClickFilter)==null?void 0:c.find(m=>m.columnIndex===p))&&e.jsx(s.Pencil,{onClick:()=>{n(m=>{const g=[...m];return g[p]=!m[p],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),f(p)]})},u)})]})}function aa({idx:t}){var d;const n=s.useEditorStore(h=>{var f;return(f=h.card)==null?void 0:f.preferences}),a=s.useEditorStore(h=>{var f;return(f=h.card.preferences)==null?void 0:f.datasetOptions}),r=s.useEditorStore(h=>h.actions.setCardPreferences),o=(d=n==null?void 0:n.chartOptions)==null?void 0:d.indexAxis,l=a==null?void 0:a.find(h=>h.idx===t);function i(h,f){(h==="end"||h==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:h!=="none",align:h,anchor:h,clamp:!0};if(!l)r({...n,datasetOptions:[...a||[],{idx:f,datalabels:u}]});else{const p={...l};p.datalabels=u;const b=a==null?void 0:a.map(c=>c.idx===f?p:c);r({...n,datasetOptions:b})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(dt,{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(Js,{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(Ws,{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(Ks,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function js(){const t=s.useEditorStore(f=>f.card),n=s.useEditorStore(f=>{var u,p,b;return(b=(p=(u=f==null?void 0:f.card)==null?void 0:u.preferences)==null?void 0:p.chartOptions)==null?void 0:b.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:l,metricKeys:i,dimensionKeys:d}=s.getKeys((a==null?void 0:a.records)||[]);let h=i;if(["stackedBar","stackedLine"].includes(t.type)){const f=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:d[0],pivotKey:d[1],valueKey:h[0]}),{metricKeys:u}=s.getKeys(f);h=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:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:d[0],children:bs(d[0])})})})]}),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:h.map((f,u)=>e.jsx(na,{col:f,idx:u},f))})]})]})}function bs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function na({col:t,idx:n}){const a=s.useEditorStore(d=>{var h;return(h=d.card)==null?void 0:h.preferences}),r=s.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.datasetOptions}),o=r==null?void 0:r.find(d=>d.idx===n),{setCardPreferences:l}=s.useEditorStore(d=>d.actions);function i(d){if(!o)l({...a,datasetOptions:[...r||[],{idx:n,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const h={...o};h.type=d==="area"?"line":d,h.fill=d==="area"?"origin":"";const f=r==null?void 0:r.map(u=>u.idx===n?h:u);l({...a,datasetOptions:f})}}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:bs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ms,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(aa,{idx:n})]})]})}function ys(){const t=s.useEditorStore(c=>c.selectedConnectionId),n=s.useEditorStore(c=>c.selectedDatamodelId),a=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:h}=s.useDashboardActions(),{modelItems:f,tableName:u,connectionType:p}=ae();function b(c,m="dashboard"){var V;const g=s.fmt(c.column_name),S=s.fmt(a||""),j=s.fmt(r||""),I=s.fmt(u);let y=s.getQualifiedTableName(j,I,p),D=`${y}.${g}`;const E=(V=f==null?void 0:f.find(R=>R.id===n))==null?void 0:V.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${E}.${g}`,y=`${s.DATAMODEL_NAMESPCACE}.${E}`);const O=l==null?void 0:l.find(R=>R.column===D&&R.table===I&&(R.database===S||R.database===a));if(O)h(O.id),d(O.id);else{const R=s.v4();return u==="api"&&t?(i({location:m,id:R,column:D,title:c.column_name,dataType:c.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(c.data_type,y,g)}),R):(i({id:R,location:m,column:D,title:c.column_name,dataType:c.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(c.data_type,y,g)}),R)}}return{assignFilter:b}}function me(){const t=s.useDashboardStore(d=>d.dashboard.filters),n=s.useEditorStore(d=>d.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ys();function l(d){const h=o(d,"frame");a({...n,filterId:h})}const i=t==null?void 0:t.find(d=>d.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(ra,{onSelect:l,columns:r}),i&&e.jsx(s.FilterHeader,{filter:i})]})}function ra({columns:t,onSelect:n}){var i;const[a,r]=ue.useState(!1),[o,l]=ue.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,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.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:h=>{const f=h===o?"":h;l(f),r(!1),f&&n(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 oa({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:n=>n.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(js,{})})]}),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(le,{}),e.jsx(me,{})]})]})]})})}function Ee(){var o,l,i;const t=s.useEditorStore(d=>d.card.cfg),n=s.useEditorStore(d=>d.actions.setCardCfg),a=s.useEditorStore(d=>d.card.type);function r(d){var u;const h={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},f={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...h}}};n(f),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=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,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"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function ia({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="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"}),a==="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:n(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(Ee,{})})]}),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(le,{}),e.jsx(me,{})]})]})]})})}const la={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},ca={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function da(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:ua(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(le,{}),e.jsx(me,{})]})]})}function ua(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(la,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(ca,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 ha(){var h,f,u,p,b;const t=s.useEditorStore(c=>c.card.preferences),n=s.useEditorStore(c=>c.actions.setCardPreferences),a=s.useEditorStore(c=>c.actions.setNumberFormat);s.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.decimalPlaces});const r=s.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.locale}),o=s.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.currency});s.useEditorStore(c=>c.actions.setFilterOnClickField);const l=s.useEditorStore(c=>{var m,g;return(g=(m=c.card.preferences)==null?void 0:m.formatNumber)==null?void 0:g.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:!!((h=t==null?void 0:t.formatNumber)!=null&&h.enabled),onCheckedChange:c=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:c}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((f=t==null?void 0:t.formatNumber)==null?void 0:f.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 m,g,S;return a(((m=t==null?void 0:t.formatNumber)==null?void 0:m.decimalPlaces)||0,((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",c,((S=t==null?void 0:t.formatNumber)==null?void 0:S.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 m,g,S;console.log("currency",c),a(((m=t==null?void 0:t.formatNumber)==null?void 0:m.decimalPlaces)||0,c==="none"?"":c,((g=t==null?void 0:t.formatNumber)==null?void 0:g.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.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:((p=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:p.toString())||"0",onValueChange:c=>{var m,g,S;return a(Number(c),((m=t==null?void 0:t.formatNumber)==null?void 0:m.currency)||"",((g=t==null?void 0:t.formatNumber)==null?void 0:g.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.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:((b=t==null?void 0:t.formatNumber)==null?void 0:b.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 m,g,S;return a(((m=t==null?void 0:t.formatNumber)==null?void 0:m.decimalPlaces)||0,((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",c.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function ma(){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(ha,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const xa=[{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"}],pa=["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"],fa=pa.map(t=>({label:t,value:t}));function ga(){var h,f,u,p,b,c,m,g,S,j,I,y,D,E,O,V,R,B;const t=s.useEditorStore(x=>x.card),n=(f=(h=t==null?void 0:t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:f.topoJsonUrl,[a,r]=C.useState(((p=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:p.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:l}=s.useTopoJson(t),i=Object.keys((l==null?void 0:l.objects)||{}).map(x=>({label:x,value:x}))||[],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(pe,{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(pe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(ee,{className:"h-9",options:d,onValueChange:x=>{console.log("value",x),o({...t.preferences,mapVisualOptions:{topoJsonUrl:x}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:x=>{r(x.target.value)},onBlur:()=>{var x;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(x=t.preferences)==null?void 0:x.mapVisualOptions,customTopoJsonUrl:a}})},value:a,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(ee,{className:"h-9",options:i,value:((c=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:c.objectKey)||"",label:"Map Object",onValueChange:x=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,objectKey:x}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(ee,{className:"h-9",options:xa,value:((g=(m=t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:g.projection)||"",label:"Projection",onValueChange:x=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projection:x}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(ee,{className:"h-9",options:fa,value:((j=(S=t.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:x=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,colorScale:x}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(pe,{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:((y=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:y.projectionScale)||1,onChange:x=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionScale:Number(x.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((O=(E=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:O[0])||0,onChange:x=>{var T,q,z,P;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionOffset:[Number(x.target.value),((P=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:P[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((B=(R=(V=t.preferences)==null?void 0:V.mapVisualOptions)==null?void 0:R.projectionOffset)==null?void 0:B[1])||0,onChange:x=>{var T,q,z,P;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionOffset:[((P=(z=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:P[0])||0,Number(x.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(le,{})]})}function ja(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...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:a,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 je({cardType:t,docContent:n,suffix:a="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)} ${a}`}),e.jsx(s.AccordionContent,{children:n||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(Ee,{}),t==="text"&&e.jsx(ja,{})]})]}),!["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(le,{}),e.jsx(me,{})]})]})]})})}function ba(){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:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(ee,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(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:[a(),e.jsx(js,{})]})]}),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(le,{}),e.jsx(me,{})]})]})]})})}function ya({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,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(le,{}),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 Sa=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."]})]}),Ca=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."]})]}),va=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 Na(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ba,{});case"pyramid":return e.jsx(je,{docContent:Sa,cardType:a});case"kpi":return e.jsx(ma,{});case"line":case"bar":return e.jsx(oa,{cardType:a});case"range":return e.jsx(je,{docContent:Ca,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(ia,{cardType:a});case"table":return e.jsx(ya,{cardType:a});case"text":return e.jsx(je,{docContent:va,cardType:a,suffix:"Visual"});case"map":return e.jsx(ga,{});case"custom":return e.jsx(ta,{});default:return e.jsx(da,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function wa(){const t=C.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return C.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Rt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(Na,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Pe,{})})]}):e.jsx(Pe,{})})]})}const ka=!1,Ia=[{title:"Write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Ea(){const t=C.useRef(null),n=C.useRef(null),[a,r]=C.useState(!1),[o,l]=C.useState(ka),[i,d]=C.useState(!1),h=s.useEditorStore(N=>N.actions.setCardSql),f=s.useEditorStore(N=>N.actions.setRunSql),u=s.useEditorStore(N=>N.showAIDialog),{setShowAIDialog:p}=s.useEditorActions(),{messages:b,setMessages:c,reload:m,append:g,input:S,setInput:j,isLoading:I,handleAddCurrentTableToScope:y,removeFromCurrentSelections:D,currentAssitantScope:E,handleInputChange:O,handleSubmit:V,stop:R,chatStatus:B,toolStatus:x,llmUsage:T}=ds();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:b}),C.useEffect(()=>{var N;u&&((N=n.current)==null||N.focus())},[u]);function q(N){h(N),f(!0)}function z(N){const L={role:"user",content:N.title+" "+N.subtitle};g(L)}function P(){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(Je,{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:a,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 G(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),E&&E.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:E==null?void 0:E.map((N,L)=>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:N.schemaName||"",tableName:N.tableName||"",modelName:N.datamodelName||"",connectionType:N.connectionType||""}),e.jsx("button",{onClick:()=>{D(N)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},L))}),(E==null?void 0:E.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:y,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const v=(S==null?void 0:S.length)===0&&(b==null?void 0:b.filter(N=>N.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:[P(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{c([]),m()},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:()=>{p(!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:b,showTools:o,handleRun:q,showSystemMessage:i}),e.jsx(s.ChatStatus,{status:s.getStatus(B,x),isLoading:I})]})}),v&&e.jsx(s.Placeholders,{onClick:z,placeholders:Ia}),e.jsx(s.ChatInput,{onFocus:()=>{y()},stop:R,ref:n,setInput:j,input:S,handleInputChange:O,handleSubmit:V,isLoading:I}),T&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",T.promptTokens," prompt tokens,"," ",T.completionTokens," completion tokens,"," ",T.totalTokens," total tokens"]})})]})}function Da({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null),o=s.useEditorStore(p=>p.showAIDialog),{setAuthToken:l}=s.useDashboardActions(),{setShowAIDialog:i,setOnSave:d,setOnClose:h}=s.useEditorActions();C.useEffect(()=>{n&&d(n),a&&h(a)},[n,d,a,h]),C.useEffect(()=>{t&&t.accessToken&&l(t)},[t,l]),C.useEffect(()=>{var p,b;o?((p=r.current)==null||p.resize(40),i(!0)):(i(!1),(b=r.current)==null||b.resize(0))},[o,i]);function f(p){p<1?i(!1):o||i(!0)}function u(){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(wa,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:f,defaultSize:0,children:e.jsx(Ea,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(os,{}),u()]})})}function Ta(){s.useDashboardStore(i=>i.selectedCardId);const t=s.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(i=>i.actions),a=s.useDashboardStore(i=>i.isVisualEditing),r=s.useDashboardStore(i=>i.actions.updateFrame);function o(i){t&&(r(t,i),n(!1))}function l(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Da,{onSave:o,onClose:l})})}function La(){const t=s.useEditorStore(l=>l.selectedDatabaseName),n=s.useEditorStore(l=>l.selectedTableName),a=s.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ys();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=a==null?void 0:a.find(d=>d.column===s.fmt(l.column_name)&&d.table===n&&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(rs,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function Aa(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.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(os,{ColumnsComponent:()=>e.jsx(La,{})})})]})}function Ma(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.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)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.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 za(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(Ma,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Aa,{})})]})}function Oa(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),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),n(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 Fa({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(Oa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(yt,{}),e.jsx(Ta,{}),e.jsx(za,{})]})]})]})})}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=ns;exports.SelectComponent=de;exports.Surfboard=Fa;exports.cleanCard=ss;exports.downloadPdf=as;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ae;
|