react-semaphor 0.0.429 → 0.0.430

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/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-Ct4NEcDa.js"),e=require("react/jsx-runtime"),I=require("react");require("react-dom");function Kt(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const de=Kt(I);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/index-C3DZLzu-.js"),e=require("react/jsx-runtime"),D=require("react");require("react-dom");function Kt(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const ce=Kt(D);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -88,7 +88,7 @@
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 Pe=t.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
91
+ */const qe=t.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
92
92
  * @license lucide-react v0.453.0 - ISC
93
93
  *
94
94
  * This source code is licensed under the ISC license.
@@ -158,7 +158,12 @@
158
158
  *
159
159
  * This source code is licensed under the ISC license.
160
160
  * See the LICENSE file in the root directory of this source tree.
161
- */const js=t.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
161
+ */const js=t.createLucideIcon("Expand",[["path",{d:"m21 21-6-6m6 6v-4.8m0 4.8h-4.8",key:"1c15vz"}],["path",{d:"M3 16.2V21m0 0h4.8M3 21l6-6",key:"1fsnz2"}],["path",{d:"M21 7.8V3m0 0h-4.8M21 3l-6 6",key:"hawz9i"}],["path",{d:"M3 7.8V3m0 0h4.8M3 3l6 6",key:"u9ee12"}]]);/**
162
+ * @license lucide-react v0.453.0 - ISC
163
+ *
164
+ * This source code is licensed under the ISC license.
165
+ * See the LICENSE file in the root directory of this source tree.
166
+ */const ys=t.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
162
167
  * @license lucide-react v0.453.0 - ISC
163
168
  *
164
169
  * This source code is licensed under the ISC license.
@@ -173,22 +178,22 @@
173
178
  *
174
179
  * This source code is licensed under the ISC license.
175
180
  * See the LICENSE file in the root directory of this source tree.
176
- */const ys=t.createLucideIcon("Fingerprint",[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]]);/**
181
+ */const Ss=t.createLucideIcon("Fingerprint",[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]]);/**
177
182
  * @license lucide-react v0.453.0 - ISC
178
183
  *
179
184
  * This source code is licensed under the ISC license.
180
185
  * See the LICENSE file in the root directory of this source tree.
181
- */const Ss=t.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
186
+ */const Cs=t.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
182
187
  * @license lucide-react v0.453.0 - ISC
183
188
  *
184
189
  * This source code is licensed under the ISC license.
185
190
  * See the LICENSE file in the root directory of this source tree.
186
- */const Cs=t.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
191
+ */const vs=t.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
187
192
  * @license lucide-react v0.453.0 - ISC
188
193
  *
189
194
  * This source code is licensed under the ISC license.
190
195
  * See the LICENSE file in the root directory of this source tree.
191
- */const vs=t.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
196
+ */const Ns=t.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
192
197
  * @license lucide-react v0.453.0 - ISC
193
198
  *
194
199
  * This source code is licensed under the ISC license.
@@ -198,17 +203,17 @@
198
203
  *
199
204
  * This source code is licensed under the ISC license.
200
205
  * See the LICENSE file in the root directory of this source tree.
201
- */const Ns=t.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
206
+ */const ws=t.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
202
207
  * @license lucide-react v0.453.0 - ISC
203
208
  *
204
209
  * This source code is licensed under the ISC license.
205
210
  * See the LICENSE file in the root directory of this source tree.
206
- */const ws=t.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
211
+ */const ks=t.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
207
212
  * @license lucide-react v0.453.0 - ISC
208
213
  *
209
214
  * This source code is licensed under the ISC license.
210
215
  * See the LICENSE file in the root directory of this source tree.
211
- */const ks=t.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
216
+ */const Ds=t.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
212
217
  * @license lucide-react v0.453.0 - ISC
213
218
  *
214
219
  * This source code is licensed under the ISC license.
@@ -218,7 +223,7 @@
218
223
  *
219
224
  * This source code is licensed under the ISC license.
220
225
  * See the LICENSE file in the root directory of this source tree.
221
- */const Ds=t.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
226
+ */const Es=t.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
222
227
  * @license lucide-react v0.453.0 - ISC
223
228
  *
224
229
  * This source code is licensed under the ISC license.
@@ -228,12 +233,12 @@
228
233
  *
229
234
  * This source code is licensed under the ISC license.
230
235
  * See the LICENSE file in the root directory of this source tree.
231
- */const Es=t.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
236
+ */const Ts=t.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
232
237
  * @license lucide-react v0.453.0 - ISC
233
238
  *
234
239
  * This source code is licensed under the ISC license.
235
240
  * See the LICENSE file in the root directory of this source tree.
236
- */const Ts=t.createLucideIcon("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
241
+ */const Ms=t.createLucideIcon("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
237
242
  * @license lucide-react v0.453.0 - ISC
238
243
  *
239
244
  * This source code is licensed under the ISC license.
@@ -248,22 +253,22 @@
248
253
  *
249
254
  * This source code is licensed under the ISC license.
250
255
  * See the LICENSE file in the root directory of this source tree.
251
- */const Ms=t.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
256
+ */const Ls=t.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
252
257
  * @license lucide-react v0.453.0 - ISC
253
258
  *
254
259
  * This source code is licensed under the ISC license.
255
260
  * See the LICENSE file in the root directory of this source tree.
256
- */const Ls=t.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
261
+ */const Os=t.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
257
262
  * @license lucide-react v0.453.0 - ISC
258
263
  *
259
264
  * This source code is licensed under the ISC license.
260
265
  * See the LICENSE file in the root directory of this source tree.
261
- */const Os=t.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
266
+ */const zs=t.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
262
267
  * @license lucide-react v0.453.0 - ISC
263
268
  *
264
269
  * This source code is licensed under the ISC license.
265
270
  * See the LICENSE file in the root directory of this source tree.
266
- */const zs=t.createLucideIcon("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
271
+ */const Fs=t.createLucideIcon("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
267
272
  * @license lucide-react v0.453.0 - ISC
268
273
  *
269
274
  * This source code is licensed under the ISC license.
@@ -278,12 +283,12 @@
278
283
  *
279
284
  * This source code is licensed under the ISC license.
280
285
  * See the LICENSE file in the root directory of this source tree.
281
- */const Fs=t.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
286
+ */const Rs=t.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
282
287
  * @license lucide-react v0.453.0 - ISC
283
288
  *
284
289
  * This source code is licensed under the ISC license.
285
290
  * See the LICENSE file in the root directory of this source tree.
286
- */const Rs=t.createLucideIcon("Ruler",[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]]);/**
291
+ */const _s=t.createLucideIcon("Ruler",[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]]);/**
287
292
  * @license lucide-react v0.453.0 - ISC
288
293
  *
289
294
  * This source code is licensed under the ISC license.
@@ -298,7 +303,12 @@
298
303
  *
299
304
  * This source code is licensed under the ISC license.
300
305
  * See the LICENSE file in the root directory of this source tree.
301
- */const _s=t.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
306
+ */const Bs=t.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
307
+ * @license lucide-react v0.453.0 - ISC
308
+ *
309
+ * This source code is licensed under the ISC license.
310
+ * See the LICENSE file in the root directory of this source tree.
311
+ */const qs=t.createLucideIcon("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);/**
302
312
  * @license lucide-react v0.453.0 - ISC
303
313
  *
304
314
  * This source code is licensed under the ISC license.
@@ -308,45 +318,45 @@
308
318
  *
309
319
  * This source code is licensed under the ISC license.
310
320
  * See the LICENSE file in the root directory of this source tree.
311
- */const qs=t.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
321
+ */const Ps=t.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
312
322
  * @license lucide-react v0.453.0 - ISC
313
323
  *
314
324
  * This source code is licensed under the ISC license.
315
325
  * See the LICENSE file in the root directory of this source tree.
316
- */const He=t.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
326
+ */const Pe=t.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
317
327
  * @license lucide-react v0.453.0 - ISC
318
328
  *
319
329
  * This source code is licensed under the ISC license.
320
330
  * See the LICENSE file in the root directory of this source tree.
321
- */const Bs=t.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
331
+ */const Hs=t.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
322
332
  * @license lucide-react v0.453.0 - ISC
323
333
  *
324
334
  * This source code is licensed under the ISC license.
325
335
  * See the LICENSE file in the root directory of this source tree.
326
- */const Ps=t.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
336
+ */const Gs=t.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
327
337
  * @license lucide-react v0.453.0 - ISC
328
338
  *
329
339
  * This source code is licensed under the ISC license.
330
340
  * See the LICENSE file in the root directory of this source tree.
331
- */const bt=t.createLucideIcon("Tornado",[["path",{d:"M21 4H3",key:"1hwok0"}],["path",{d:"M18 8H6",key:"41n648"}],["path",{d:"M19 12H9",key:"1g4lpz"}],["path",{d:"M16 16h-6",key:"1j5d54"}],["path",{d:"M11 20H9",key:"39obr8"}]]);/**
341
+ */const yt=t.createLucideIcon("Tornado",[["path",{d:"M21 4H3",key:"1hwok0"}],["path",{d:"M18 8H6",key:"41n648"}],["path",{d:"M19 12H9",key:"1g4lpz"}],["path",{d:"M16 16h-6",key:"1j5d54"}],["path",{d:"M11 20H9",key:"39obr8"}]]);/**
332
342
  * @license lucide-react v0.453.0 - ISC
333
343
  *
334
344
  * This source code is licensed under the ISC license.
335
345
  * See the LICENSE file in the root directory of this source tree.
336
- */const Hs=t.createLucideIcon("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
346
+ */const Us=t.createLucideIcon("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);/**
337
347
  * @license lucide-react v0.453.0 - ISC
338
348
  *
339
349
  * This source code is licensed under the ISC license.
340
350
  * See the LICENSE file in the root directory of this source tree.
341
- */const yt=t.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ge(s){var a;return{...s,sheets:(a=s==null?void 0:s.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>St(i))}})}})}}function St(s){return{...s,customCfg:Gs(s.customCfg),data:[]}}function Gs(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Us(s,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:n,operation:"create"})}async function Oe(s,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:l,shared:i}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function $s(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Qs(){const[s,a]=I.useState(""),[n,r]=I.useState(!1),o=t.useDashboardStore(h=>h.lenses),{setLenses:l,setSelectedLensId:i}=t.useDashboardActions(),[c,u]=I.useState(!1),[p,m]=I.useState(!1),f=t.useDashboardStore(h=>h.dashboard),x=t.useDashboardStore(h=>h.filterValues),{authToken:d}=t.useSemaphorContext();async function j(){u(!0);const h=Ge(f),S=await Us(s,h,x,d==null?void 0:d.accessToken);S&&(l([...o||[],S]),i(S.id),m(!1)),u(!1)}return e.jsxs(t.Dialog,{open:p,onOpenChange:m,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:h=>{a(h.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:j,disabled:c,children:c?"Creating...":"Add"})})]})]})}function Js(){const[s,a]=I.useState(!1),n=t.useDashboardStore(m=>m.lenses),r=t.useDashboardStore(m=>m.selectedLensId),{setLenses:o,setSelectedLensId:l}=t.useDashboardActions(),{authToken:i}=t.useSemaphorContext();async function c(m){l(m)}async function u(m){if(await $s(m,i==null?void 0:i.accessToken)){const x=n==null?void 0:n.filter(d=>d.id!==m);o(x||[]),l("original")}}async function p(m){const f=n==null?void 0:n.map(j=>j.id===m.id?{...j,isDefault:!m.isDefault}:{...j,isDefault:!1});o(f||[]);const x={...m,isDefault:!m.isDefault};await Oe(x,i==null?void 0:i.accessToken);const d=n==null?void 0:n.find(j=>j.isDefault);if(d&&d.id!==m.id){const j={...d,isDefault:!1};await Oe(j,i==null?void 0:i.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Ss,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:c,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(m=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[e.jsx("p",{children:m.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Ns,{onClick:f=>{f.preventDefault(),p(m)},className:t.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:f=>{f.preventDefault(),u(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})]})}function Ct(){var l;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(l=t.useDashboardStore.getState().dashboard)==null?void 0:l.title,o=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function vt(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:l}=Ct();if(s)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",l||"");const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const m=(await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,f=document.createElement("a");f.href=m;const x=`${o}-${new Date().toISOString()}.pdf`;f.download=x,f.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Ks({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(o=>{var l;return(l=o.dashboard)==null?void 0:l.title}),t.useDashboardStore(o=>o.theme),t.useDashboardStore(o=>o.filterValues);const n=t.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await vt()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(re,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function X({defaultValue:s,label:a,options:n,value:r,onValueChange:o,className:l,icon:i}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:o,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",l),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("div",{className:"mr-2",children:i}),e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(c=>e.jsx(t.SelectItem,{value:c.value,children:c.label},c.value))]})})]})}const Ze=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Nt({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:l,isDeleting:i}=Ws(),[c,u]=I.useState(""),[p,m]=I.useState(Ze[0].value),[f,x]=I.useState("06:00"),[d,j]=I.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(ms,{className:"size-4"})})}),e.jsx(t.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:c,onChange:h=>u(h.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:d,onChange:h=>{j(h.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(X,{className:"col-span-2 h-8",label:"Select Frequency",options:Ze,value:p,onValueChange:h=>m(h)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:f,onChange:h=>x(h.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:c,frequency:p,time:f,subject:d}),x("00:00"),u(""),j("")},className:"h-8 p-2",disabled:o==="loading"||!c,children:[o==="loading"&&e.jsx(re,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(ct,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:l})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(h=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[t.titleCase(h.frequency)," "]}),e.jsx(t.Label,{children:h.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(et,{tooltip:`Next Run: ${new Date(h.nextRun).toLocaleString()} ${h.timezone}`,children:e.jsx(us,{className:"size-3.5"})}),e.jsx(et,{tooltip:`${h.endUserEmail}`,children:e.jsx(Ts,{className:"size-3.5"})}),i===h.id?e.jsx(re,{className:"size-3.5 animate-spin"}):e.jsx(Hs,{onClick:()=>r(h.id),className:"size-3.5 cursor-pointer"})]})]},h.id))})]})]})]})})]})})}const et=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function Ws(){const[s,a]=I.useState("idle"),[n,r]=I.useState(""),[o,l]=I.useState(null),i=t.useDashboardStore(N=>N.authToken),c=t.useDashboardStore(N=>N.dashboard.id),u=t.useDashboardStore(N=>N.dashboard.title),{endUserId:p}=t.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),m="https://semaphor.cloud/api/v1/subscriptions/get",f={dashboardId:c,endUserId:p},{data:x,isLoading:d,isError:j,isFetching:h,refetch:S}=t.useQuery({queryKey:["subscriptions",c,p],queryFn:()=>t.getRequest(m,(i==null?void 0:i.accessToken)||"",f),enabled:!!(i!=null&&i.accessToken)&&!!c&&!!p});async function g({email:N,subject:A,frequency:C,time:L}){const{authToken:q,..._}=Ct(),U=Intl.DateTimeFormat().resolvedOptions().timeZone,v={email:N,frequency:C,time:L,timezone:U,endUserId:p,endUserEmail:N,subject:A||u||"Scheduled Dashboard",dashboardId:c,dashboardParams:_};a("loading");const k="https://semaphor.cloud/api/v1/subscriptions/create";try{const O=await t.postRequestRegular(k,(q==null?void 0:q.accessToken)||"",{...v});a("success"),r(""),S(),setTimeout(()=>{a("idle")},2e3)}catch(O){console.error(O),a("error"),r(O.message)}}async function T(N){const A="https://semaphor.cloud/api/v1/subscriptions/delete";l(N);try{await t.postRequestRegular(A,(i==null?void 0:i.accessToken)||"",{id:N}),S(),setTimeout(()=>{l(null)},2e3)}catch(C){console.error(C),l(null),a("error"),r(C.message)}}return{data:x,isLoading:d,isFetching:h,isError:j,isDeleting:o,refetch:S,handleScheduleSubscription:g,handleDeleteSubscription:T,status:s,error:n}}function Ys(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(v=>v.theme);const a=t.useDashboardStore(v=>v.lenses),n=t.useDashboardStore(v=>v.selectedLensId),r=a==null?void 0:a.find(v=>v.id===n),o=t.useDashboardStore(v=>v.dashboard);t.useDashboardStore(v=>v.selectedSheetId);const l=t.useDashboardStore(v=>v.isDashboardEditing),i=t.useEditorStore(v=>v.selectedConnectionId),[c,u]=I.useState(!1),p=t.useDashboardStore(v=>v.filterValues),m=t.useDashboardStore(v=>v.isVisualEditing),f=t.useDashboardStore(v=>v.showFilters);t.useDashboardStore(v=>v.showDashboardJSON);const x=t.useDashboardStore(v=>v.onSaveFunction),d=t.useDashboardStore(v=>v.actions.setShowFilters),{addFrame:j,setSelectedFrameId:h}=t.useDashboardStore(v=>v.actions),{getSelectedSheet:S,setIsDashboardEditing:g,setShowDashboardJSON:T}=t.useDashboardStore(v=>v.actions),N=S(),{tenantId:A,endUserId:C}=I.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),L=I.useMemo(()=>A||C,[A,C]),q=()=>{if(!l||!N)return;const v={connectionId:i,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},k={id:t.v4(),cards:[v],activeCardId:v.id};j(N.id,k),h(k.id)},_=()=>{g(!0)};async function U(){if(u(!0),!n||!r)return;const v=Ge(o),k=JSON.stringify(v),O={...r,template:k,filterValues:p};await Oe(O,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),x==null||x(v),u(!1)}return m?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!m&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!m&&e.jsx(Ks,{}),!m&&e.jsx(Nt,{}),l&&!m&&L&&e.jsx(Qs,{}),!m&&L&&e.jsx(Js,{}),l&&!m&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:q,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!l&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:_,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),l&&!m&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{g(!1),T(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),l&&!m&&L&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:c,onClick:U,size:"sm",children:e.jsx(Vs,{className:"h-4 w-4"})}),!f&&!m&&l&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>d(!0),size:"sm",children:e.jsx(mt,{className:"h-4 w-4"})}),!m&&l&&!1,!m&&!1]})]})}function Xs({name:s,items:a,value:n,onChange:r,isLoading:o,isError:l,refetch:i,className:c,icon:u,showNone:p=!1}){const m=de.useRef(null),[f,x]=de.useState(!1),[d,j]=de.useState("100%"),h=p?[...a||[],{id:"none",name:"None"}]:a;de.useLayoutEffect(()=>{m.current&&j(m.current.offsetWidth)},[]);function S(){var T;return o?"Loading...":l?"Error":n?(T=a==null?void 0:a.find(N=>N.id===n))==null?void 0:T.name:`Select ${s}`}function g(T,N){r(N),x(!1)}return e.jsxs(t.Popover,{open:f,onOpenChange:x,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:m,variant:"outline",role:"combobox","aria-expanded":f,className:t.cn("flex h-9 w-full justify-between",c),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"mr-2",children:u}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:S()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:d},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:i,children:e.jsx(ft,{className:t.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:h==null?void 0:h.map(T=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:T.name,onSelect:N=>g(N,T.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===T.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:T.name,children:T.name})]})},T.id))})]})]})})]})}function le({title:s,items:a,value:n,isLoading:r,isError:o,refetch:l,onChange:i,showNone:c=!1,className:u,disabled:p=!1,type:m="combobox"}){const f=r?"Loading...":o?"Error":n;function x(){if(s==="Connection")return e.jsx(zs,{className:"size-4"});if(s==="Database")return e.jsx(fs,{className:"size-4"});if(s==="Schema")return e.jsx(Os,{className:"size-4"});if(s==="Table")return e.jsx(He,{className:"size-4"});if(s==="Model")return e.jsx(ls,{className:"size-4"})}function d(){return e.jsxs(t.Select,{disabled:p,value:f,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",u),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(ft,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:l})]}),e.jsxs(e.Fragment,{children:[c&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((h,S)=>e.jsx(t.SelectItem,{value:h.id,children:h.name},S))]}),(r||o)&&e.jsx(t.SelectItem,{value:f,children:f})]})})]})}function j(){return e.jsx(Xs,{icon:x(),items:a,value:f,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:l,name:s,showNone:c})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:m==="select"?d():j()})})}function Zs({column:s}){const[a,n]=I.useState(!1),r=t.useEditorStore(h=>h.selectedTableName),o=t.useEditorStore(h=>h.selectedSchemaName),l=t.useEditorStore(h=>h.selectedDatabaseName),i=t.useEditorStore(h=>h.selectedDatamodelId),c=t.useEditorStore(h=>h.sqlGen),{modelItems:u,connectionType:p}=Z(),m=t.useEditorStore(h=>h.actions.setSqlGen),f=t.useEditorStore(h=>h.actions.setCardSql),x=t.useEditorStore(h=>h.actions.setRunSql);function d(h,S){var A;const g=t.createSqlGenConfig(h,c,S),T=(A=u==null?void 0:u.find(C=>C.id===i))==null?void 0:A.name;m(g);const N=t.getSql(g,t.fmt(o||""),t.fmt(r),T,p,l||"");N&&(f(N),x(!0)),n(!1)}function j(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>d(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>d(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>d(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>d(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>d(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(ut,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:j()})]})}function Ue({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(yt,{className:"size-3"}):t.isNumberDataType(s.data_type)?e.jsx(ht,{className:"size-3"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3"}):t.isBooleanDataType(s.data_type)?e.jsx(Ps,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsx(cs,{className:"size-3"}):e.jsx(_s,{className:"size-3"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function ke({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(Ue,{column:s}),e.jsx("span",{children:s.column_name})]})}function en({id:s,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:l,transform:i}=t.useDraggable({id:s,data:{type:n}}),c=i?{translate:t.CSS.Translate.toString(i),transform:t.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:l,style:c,...o,...r,children:a})}function tn({onClick:s,column:a}){const n=t.useDndStore(x=>x.activeId),r=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.groupByColumns}),o=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.trendByColumns}),l=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.metricColumns}),i=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.filterColumns});function c(x){return u(x)||m(x)||p(x)||f(x)}function u(x){return r==null?void 0:r.some(d=>d.name===x.column_name)}function p(x){return o==null?void 0:o.some(d=>d.name===x.column_name)}function m(x){return l==null?void 0:l.some(d=>d.name===x.column_name)}function f(x){return i==null?void 0:i.some(d=>d.name===x.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":c(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(ke,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(ke,{column:a})}),e.jsx(en,{id:a.column_name,type:"column",children:e.jsx(ke,{column:a})})]})}function ae(s){return`${s}-${t.v4()}`}function ge(s,a){return s==="SUM"?`Sum of ${a}`:s==="AVG"?`Avg of ${a}`:s==="COUNT"?`Count of ${a}`:s==="MAX"?`Max of ${a}`:s==="MIN"?`Min of ${a}`:s==="DISTINCT"?`Distinct ${a}`:a}function sn({schemaName:s,tableName:a,columns:n,status:r}){const o=t.useEditorStore(b=>b.sqlGen),l=t.useEditorStore(b=>b.isDevMode),i=t.useEditorStore(b=>b.selectedConnectionId),c=t.useEditorStore(b=>b.selectedDatabaseName),u=t.useEditorStore(b=>b.selectedSchemaName),p=t.useEditorStore(b=>b.selectedTableName),m=t.useEditorStore(b=>b.selectedDatamodelId),f=t.useDashboardStore(b=>b.dashboard.aiScopeTables),{addToAIScope:x,removeFromAIScope:d}=t.useDashboardActions(),{addColumnToMetricColumns:j,addColumnToTrendByColumns:h,setCardSql:S,setRunSql:g,setSqlGen:T,setIsShowingVisual:N}=t.useEditorActions(),{connectionType:A,modelItems:C,selectedDatamodelName:L}=Z();function q(b){var F;if(l){const H=t.createSqlGenConfig(b,o);T(H);const $=(F=C==null?void 0:C.find(D=>D.id===m))==null?void 0:F.name,B=t.getSql(H,t.fmt(s),t.fmt(a),$,A,c||"");B&&(S(B),g(!0))}if(!l){if(t.isTextDataType(b.data_type)){const H={...b,role:"metric",id:ae(b.column_name),name:b.column_name,label:ge("COUNT",b.column_name),type:b.data_type,aggregate:"COUNT"};j(H)}if(t.isNumberDataType(b.data_type)){const H={...b,role:"metric",id:ae(b.column_name),name:b.column_name,label:ge("SUM",b.column_name),type:b.data_type,aggregate:"SUM"};j(H)}if(t.isDateDataType(b.data_type)){const H={...b,role:"trendby",id:ae(b.column_name),name:b.column_name,type:b.data_type};h(H)}}}function _(b){b===!0&&(p||L)&&i?(x({connectionId:i,connectionType:A==="S3"||A==="API"?"DuckDb":A,databaseName:c||"",schemaName:u||"",tableName:p||"",datamodelName:t.resolveDatamodelName(L),datamodelId:m||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(d({connectionId:i||"",connectionType:A||"",tableName:p||"",datamodelName:t.resolveDatamodelName(L),datamodelId:m||"",databaseName:c||"",schemaName:u||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function U(){const b=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:L,connectionType:A,databaseName:c||""});N(!1);const F=A==="MSSQL"?`SELECT top 10 * FROM ${b}`:`SELECT * FROM ${b} LIMIT 10`;S(F),g(!0)}function v(){const b=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:L,connectionType:A,databaseName:c||""});S(`SELECT COUNT(*) as count FROM ${b}`),g(!0)}function k(){return(f==null?void 0:f.find(b=>b.connectionId===i&&(b.tableName===p||b.datamodelName===L)))!==void 0}function O(b){return l?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>q(b),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ue,{column:b}),e.jsx("span",{children:b.column_name})]}),e.jsx("div",{onClick:F=>F.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(b.data_type)&&e.jsx(Zs,{column:b})})]}):e.jsx(tn,{onClick:q,column:b})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${k()?"Remove from":"Add to"} Assistant Scope`,pressed:k(),onPressedChange:_,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":k(),"text-muted-foreground":!k()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:U,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Es,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:v,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(jt,{className:"mr-2 size-4"}),"Count"]})]})}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:E()}),e.jsxs(t.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted px-2 py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(b=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:O(b)},b.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function wt(s){const a=t.useDashboardStore(u=>u.authToken)||s,n=t.useEditorStore(u=>u.selectedConnectionId),{refetch:r,data:o,isLoading:l,isError:i}=t.useQuery({queryKey:["connections"],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/connections",(a==null?void 0:a.accessToken)||""),enabled:!!(a!=null&&a.accessToken)}),c=o==null?void 0:o.connections.find(u=>u.id===n);return{connectionsData:o,isConnectionsLoading:l,isConnectionsError:i,refetchConnections:r,currentConnection:c}}function kt(s){var S;const a=t.useDashboardStore(g=>g.authToken)||s,n=t.useEditorStore(g=>g.selectedConnectionId),r=t.useEditorStore(g=>g.selectedDatabaseName),o=t.useEditorStore(g=>g.selectedDatamodelId),l=t.useEditorStore(g=>g.selectedSchemaName),i=t.useEditorStore(g=>g.selectedTableName),{currentConnection:c}=wt(),u=c==null?void 0:c.type,{data:p,isLoading:m,isFetching:f,isError:x,refetch:d}=t.useQuery({queryKey:["columns",n,r,o,l,i],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/columns",(a==null?void 0:a.accessToken)||"",{connection_id:n,datamodel_id:o||"",database_name:r,schema_name:l,table_name:i}),enabled:j(u)});function j(g){return a!=null&&a.accessToken?!!(n&&r&&r!=="NA"&&l&&i||n&&(g==="S3"||g==="API")||o&&o):!1}return{columns:(S=p==null?void 0:p.columns)==null?void 0:S.map(g=>({...g,data_type:g.data_type.toLowerCase()})),isColumnsLoading:m,isColumnsFetching:f,isColumnsError:x,refetchColumns:d}}function Z(s,a){var Je,Ke,We,Ye,Xe;const n=t.useSemaphorContext().authToken||s,r=t.useEditorStore(V=>V.selectedConnectionId),o=t.useEditorStore(V=>V.selectedDatamodelId),l=t.useEditorStore(V=>V.selectedDatabaseName),i=t.useEditorStore(V=>V.selectedSchemaName),c=t.useEditorStore(V=>V.selectedTableName),u=t.useEditorStore(V=>V.actions.setSelectedConnectionId),p=t.useEditorStore(V=>V.actions.setSelectedDatamodelId),m=t.useEditorStore(V=>V.actions.setSelectedDatabaseName),f=t.useEditorStore(V=>V.actions.setSelectedSchemaName),x=t.useEditorStore(V=>V.actions.setSelectedTableName);t.useEditorStore(V=>V.actions.setCardSql);function d(V){return r&&l&&i&&l!=="NA"?!0:r&&V==="API"?!1:!!(r&&V==="S3")}function j(V){return r&&V?!(V==="API"||V==="S3"):!1}const{refetchConnections:h,connectionsData:S,isConnectionsLoading:g,isConnectionsError:T,currentConnection:N}=wt(s),{refetch:A,data:C,isLoading:L,isError:q}=t.useQuery({queryKey:["models",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:!!(n!=null&&n.accessToken)&&!!r}),_=N==null?void 0:N.type,U=(N==null?void 0:N.type)==="API"||(N==null?void 0:N.type)==="S3",{data:v,isLoading:k,isFetching:O,isError:E,refetch:b}=t.useQuery({queryKey:["databases",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:j(_)}),{data:F,isLoading:H,isFetching:$,isError:B,refetch:D}=t.useQuery({queryKey:["schemas",r,l],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l}),enabled:!!r&&!!l&&!U&&l!=="NA"}),{data:y,isLoading:w,isFetching:M,isError:z,refetch:G}=t.useQuery({queryKey:["tables",r,l,i],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:l,schema_name:i}),enabled:d(_)}),{columns:P,isColumnsLoading:K,isColumnsFetching:W,isColumnsError:ee,refetchColumns:te}=kt(s);I.useEffect(()=>{(_==="S3"||_==="API")&&(m(""),f(""),p(""),_==="API"&&x("api"))},[_,x,m,f,p]);const R=(N==null?void 0:N.type)==="API"?(Je=N==null?void 0:N.type)==null?void 0:Je.toLowerCase():c||"",Q=U?"":i||"";function Y(V){f(V),x("")}function ne(V){m(V==="none"?"":V),f(""),x(""),V!=="none"&&V!==""&&p("")}function ie(V){u(V)}function Ce(V){p(V==="none"?"":V),V!=="none"&&V!==""&&m("")}v&&((Ke=v==null?void 0:v.databases)==null?void 0:Ke.length)>0,F&&((We=F==null?void 0:F.schemas)==null?void 0:We.length)>0;const ve=S==null?void 0:S.connections.map(V=>({id:V.id,name:V.name,type:V.type})),Ne=(Ye=C==null?void 0:C.datamodels)==null?void 0:Ye.map(V=>({id:V.id,name:V.name})),we=v==null?void 0:v.databases.map(V=>({id:V.database_name,name:V.database_name})),he=F==null?void 0:F.schemas.map(V=>({id:V.schema_name,name:V.schema_name})),J=y==null?void 0:y.tables.map(V=>({id:V.table_name,name:V.table_name})),se=(Xe=C==null?void 0:C.datamodels.find(V=>V.id===o))==null?void 0:Xe.name,Jt=t.getFormattedTableNameForQuery({schemaName:Q,tableName:R,modelName:se,connectionType:_,databaseName:l||""});return{connectionItems:ve,selectedConnectionId:r,isConnectionsLoading:g,isConnectionsError:T,modelItems:Ne,selectedDatamodelId:o,selectedDatamodelName:se,isModelsLoading:L,isModelsError:q,selectedDatabaseName:l,databaseItems:we,isDatabasesLoadingOrFetching:k||O,isDatabaseError:E,schemaItems:he,selectedSchemaName:i,isSchemaLoadingOrFetching:H||$,isSchemaError:B,tableItems:J,selectedTableName:c,isTableLoadingOrFetching:w||M,isTableError:z,columns:P,isColumnsLoadingOrFetching:K||W,isColumnsError:ee,isNonDbConnection:U,connectionType:_,tableName:R,formattedTableName:Jt,schemaName:Q,refetchConnections:h,refetchModels:A,refetchDatabases:b,refetchSchemas:D,refetchTables:G,refetchColumns:te,handleConnectionChange:ie,handleDatamodelChange:Ce,handleDatabaseChange:ne,handleSchemaChange:Y}}function It({ColumnsComponent:s,type:a}){var he;const n=t.useEditorStore(J=>J.card),r=t.useEditorStore(J=>J.selectedConnectionId),o=t.useDashboardStore(J=>J.showFilters),l=t.useEditorStore(J=>J.selectedDatamodelId),i=t.useEditorStore(J=>J.selectedDatabaseName),c=t.useEditorStore(J=>J.selectedSchemaName),u=t.useEditorStore(J=>J.selectedTableName),p=t.useEditorStore(J=>J.isDevMode),{setSelectedTableName:m,setIsDevMode:f,setCardSql:x}=t.useEditorActions(),{connectionItems:d,modelItems:j,schemaItems:h,databaseItems:S,tableItems:g,columns:T,isConnectionsLoading:N,isModelsLoading:A,isConnectionsError:C,isModelsError:L,isDatabasesLoadingOrFetching:q,isDatabaseError:_,isSchemaLoadingOrFetching:U,isSchemaError:v,isColumnsError:k,isColumnsLoadingOrFetching:O,isTableLoadingOrFetching:E,isTableError:b,connectionType:F,isNonDbConnection:H,refetchDatabases:$,refetchModels:B,refetchSchemas:D,refetchTables:y,refetchColumns:w,refetchConnections:M,handleConnectionChange:z,handleDatabaseChange:G,handleSchemaChange:P,handleDatamodelChange:K,tableName:W,schemaName:ee}=Z(),{data:te,refetch:R}=t.useDashboardCardQuery(n);function Q(){return s?s(ee,W,T):e.jsx(sn,{schemaName:ee,tableName:W,columns:T,status:O?"Loading...":k?"Error":"Success"})}function Y(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function ne(J){J===!0?te&&(x(te.userSql),setTimeout(()=>{R()},500)):x(""),f(J)}function ie(){if(!r||F==="S3"||F==="API")return null;if(!l||l==="none")return e.jsx(le,{refetch:$,showNone:!0,onChange:G,isError:_,isLoading:q,items:S,value:i||"",title:"Database",type:"combobox"})}function Ce(){if(r&&!H&&(!i||i==="none")&&(!l||l==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function ve(){if(!r||F==="S3"||F==="API")return null;if(!i||i==="none")return e.jsx(le,{refetch:B,showNone:!0,onChange:K,isError:L,isLoading:A,items:j,value:l||"",title:"Model",type:"combobox"})}function Ne(){return!r||F==="S3"||F==="API"||!i||i==="none"?null:e.jsx(le,{refetch:D,onChange:P,isError:v,isLoading:U,items:h,value:c||"",title:"Schema",type:"combobox"})}function we(){function J(){let se=!1;return F==="API"?(se=!1,se):((F==="S3"||r&&i&&i!=="none"&&c)&&(se=!0),se)}return J()?e.jsx(le,{refetch:y,onChange:m,isError:b,items:g,isLoading:E,value:u||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(le,{refetch:M,items:d,title:"Connection",value:r||"",onChange:z,isLoading:N,isError:C,type:"combobox",connectionTooltip:((he=d==null?void 0:d.find(J=>J.id===r))==null?void 0:he.type)||""}),ie(),Ce(),ve(),Ne(),we()]}),Q(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:p,onCheckedChange:ne,id:"dev-mode"}),e.jsx(t.Label,{htmlFor:"dev-mode",children:"Dev Mode"})]}),e.jsxs(t.Button,{onClick:Y,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(As,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function Dt({sql:s,error:a,onClick:n}){return!s&&!a?null:e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(ct,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})]})]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(vs,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var Et={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},tt=I.createContext&&I.createContext(Et),nn=["attr","size","title"];function an(s,a){if(s==null)return{};var n=rn(s,a),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function rn(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function je(){return je=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},je.apply(this,arguments)}function st(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),n.push.apply(n,r)}return n}function be(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?st(Object(n),!0).forEach(function(r){on(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):st(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function on(s,a,n){return a=ln(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function ln(s){var a=cn(s,"string");return typeof a=="symbol"?a:a+""}function cn(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function Tt(s){return s&&s.map((a,n)=>I.createElement(a.tag,be({key:n},a.attr),Tt(a.child)))}function ue(s){return a=>I.createElement(dn,je({attr:be({},s.attr)},a),Tt(s.child))}function dn(s){var a=n=>{var{attr:r,size:o,title:l}=s,i=an(s,nn),c=o||n.size||"1em",u;return n.className&&(u=n.className),s.className&&(u=(u?u+" ":"")+s.className),I.createElement("svg",je({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:u,style:be(be({color:s.color||n.color},n.style),s.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),l&&I.createElement("title",null,l),s.children)};return tt!==void 0?I.createElement(tt.Consumer,null,n=>a(n)):a(Et)}function un(s){return ue({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function At(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(h=>h.theme),r=t.useEditorStore(h=>h.frame),o=t.useEditorStore(h=>h.card),l=t.useEditorStore(h=>h.activeTabCardId),i=t.Le(),{refetch:c}=t.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:p}=t.useEditorActions(),m=I.useRef(),f=I.useRef({}),x=r.cards.find(h=>h.id===l),d=I.useCallback(()=>{let h="";return s==="python"&&(h=(x==null?void 0:x.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(h=(x==null?void 0:x.sql)||""),h},[s,x]);I.useEffect(()=>{if(l&&o.id&&o.id!==l){if(m.current&&i){const h=m.current.getModel();h&&(f.current[o.id]=h);let S=f.current[l];if(!S){const g=d();S=i.editor.createModel(g,s),f.current[l]=S}m.current.setModel(S)}u(l,o),p(!0)}},[l,o,u,i,p,s,d]),I.useEffect(()=>{if(!i)return;const h=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=n==="system"?h:n;i.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),I.useEffect(()=>{const h=m.current;h&&i&&o&&h.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return c(),!1})},[i,c,o]);function j(h,S){if(m.current=h,!f.current[o.id]){const g=h.getModel(),T=d();f.current[o.id]=g||(S==null?void 0:S.editor.createModel(T,s))||h.getModel()}h.setModel(f.current[o.id])}return{handleEditorDidMount:j}}function mn(){const s=t.useEditorStore(i=>i.card.sql),a=t.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:o}=At("sql");function l(i){n(i),t.isObjectEmpty(a)||r({})}return e.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:l,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function hn(){const s=t.useEditorStore(o=>o.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=At("python");function r(o){a(o)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function pn({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function Mt(s){var W,ee,te;const[a,n]=I.useState(""),[r,o]=I.useState(null),{authToken:l}=t.useSemaphorContext(),i=t.useEditorStore(R=>{var Q;return(Q=R==null?void 0:R.card)==null?void 0:Q.sql}),c=t.useEditorStore(R=>{var Q;return(Q=R==null?void 0:R.card)==null?void 0:Q.python}),u=t.useEditorStore(R=>R.actions.setCardSql),p=t.useEditorStore(R=>R.actions.setRunSql),m=t.useEditorStore(R=>R.actions.switchCardType),f=t.useEditorStore(R=>R.currentAssitantScope)||[],x=t.useEditorStore(R=>R.userInputForAI),d=t.useEditorStore(R=>R.triggerAIRun),j=t.useEditorStore(R=>R.selectedDatabaseName),h=t.useEditorStore(R=>R.selectedTableName),S=t.useEditorStore(R=>R.selectedConnectionId),g=t.useEditorStore(R=>R.selectedSchemaName),T=t.useDashboardStore(R=>R.dashboard.aiScopeTables),{setTriggerAIRun:N,setCurrentAssitantScope:A}=t.useEditorActions(),{selectedDatamodelName:C,connectionType:L,selectedDatamodelId:q}=Z(),{messages:_,setMessages:U,reload:v,error:k,append:O,input:E,setInput:b,status:F,handleInputChange:H,handleSubmit:$,stop:B}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:D,onFinish(R,Q){y(Q.usage),n(""),Q.finishReason==="stop"&&n("")}});I.useEffect(()=>{d&&x&&(H({target:{value:x}}),setTimeout(()=>{$(),N(!1)},100))},[d,$,x,N,H]);async function D({toolCall:R}){if(R.toolName==="createChartFromSql"){const Q=R.args.sql,Y=R.args.chartType;return m(Y),u(Q),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(R.toolName==="getTableColumns")n("Getting table columns...");else{if(R.toolName==="getUserSql")return i?{status:"success",sql:i,python:c||""}:{status:"error",message:"No SQL found"};if(R.toolName==="getCurrentTableScope")return n("Getting table scope..."),G(),{status:"success",tables:f};n("Analyzing...")}}function y(R){o(Q=>Q?{promptTokens:Q.promptTokens+R.promptTokens,completionTokens:Q.completionTokens+R.completionTokens,totalTokens:Q.totalTokens+R.totalTokens}:R)}function w(R){const Q=t.removeFromScopeArray(f,R);M(Q)}function M(R){const Q=t.sanitizeAIScope(R);A(Q),U(Y=>[...Y,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(Q)}`}])}function z(){const R={databaseName:j||"",schemaName:g||"",tableName:h||"",datamodelId:q||"",datamodelName:t.resolveDatamodelName(C),connectionId:S||"",connectionType:L||""},Q=t.dedup([...f,R]);M(Q)}function G(){const R={databaseName:j||"",schemaName:g||"",tableName:h||"",datamodelName:t.resolveDatamodelName(C),connectionId:S||"",connectionType:L||"",datamodelId:q||""};if(!t.isInAiScopeArray([...T||[],...f],R)||f.length===0){const Y=t.dedup([...T||[],...f,R]).filter(ne=>ne.connectionId===R.connectionId);M(Y)}}const P=!["ready","error"].includes(F),K=(te=(ee=(W=JSON.parse((k==null?void 0:k.message)||"{}"))==null?void 0:W.error)==null?void 0:ee.lastError)==null?void 0:te.message;return{messages:_,setMessages:U,reload:v,append:O,input:E,setInput:b,isLoading:P,handleSetAIScope:G,handleAddCurrentTableToScope:z,removeFromCurrentSelections:w,currentAssitantScope:f,setCurrentAssitantScope:A,handleInputChange:H,handleSubmit:$,stop:B,chatStatus:F,toolStatus:a,llmUsage:r,onFinish:s,errorMessage:K}}function xn(s){const a=s.toUpperCase().indexOf("WHERE"),n=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let l=s.length;if(o!==-1&&(l=o),r!==-1&&r<l&&(l=r),a!==-1){const i=s.substring(0,a),c=s.substring(a);return`${i} {{ filters | where }} AND ${c.substring(6)}`}else if(n!==-1){const i=s.substring(0,n),c=s.substring(n);return`${i} {{ filters | where }} ${c}`}else{const i=s.substring(0,l),c=s.substring(l);return console.log("beforeClause",i),console.log("afterClause",c),c?`${i} {{ filters | where }} ${c}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function Lt({variant:s="secondary"}){const{setCardSql:a}=t.useEditorActions(),n=t.useEditorStore(d=>d.frame),r=t.useEditorStore(d=>d.card),o=t.useEditorStore(d=>d.selectedSchemaName),l=t.useEditorStore(d=>d.selectedDatamodelId),i=t.useEditorStore(d=>d.selectedDatabaseName),c=t.useEditorStore(d=>d.selectedTableName),u=t.useEditorStore(d=>d.selectedConnectionId),p=t.useEditorStore(d=>d.isShowingVisual),m=r.sql,f=t.useEditorStore(d=>d.onSave);function x(){let d=m;m&&!m.includes("{{")&&(d=xn(m),a(d));const j={...r,lastSelectedSchema:o,lastSelectedDatamodelId:l,lastSelectedDatabase:i,lastSelectedTable:c,connectionId:u,type:p?r.type:"table",sql:d,customCfg:p?r.customCfg:null},h=n.cards.map(g=>g.id===r.id?j:g),S={...n,cards:h,activeCardId:fn(h,n.activeCardId)};f==null||f(S)}return e.jsxs(t.Button,{onClick:x,size:"sm",variant:s,children:[e.jsx(t.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Ot(){const{setTempQueryData:s,setSqlGen:a}=t.useEditorActions(),n=t.useQueryClient(),r=t.useEditorStore(u=>u.tempQueryData),o=t.useEditorStore(u=>u.onClose),l=t.useEditorStore(u=>u.card),{queryKey:i}=t.useDashboardCardQuery(l);function c(){if(r){const{queryKey:u,queryData:p}=r;u&&p&&n.setQueryData(u,p)}a({}),o==null||o()}return e.jsxs(t.Button,{onClick:c,size:"sm",variant:"secondary",children:[e.jsx(t.X,{className:"mr-2 size-4"}),"Close"]})}function zt(){const{setTempQueryData:s}=t.useEditorActions(),a=t.useQueryClient(),n=t.useEditorStore(d=>d.tempQueryData),r=t.useEditorStore(d=>d.card),{queryKey:o}=t.useDashboardCardQuery(r),{setCardSql:l,setSqlGen:i,setCardPython:c,setCardCustomCfg:u,setCardPreferences:p,setCardType:m,clearQueryConfig:f}=t.useEditorActions();function x(){const d=a.getQueryData(o);n!=null&&n.queryData||s({queryKey:o,queryData:d}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),l(""),i({}),f(),c(""),u(""),p({})}return e.jsxs(t.Button,{onClick:x,className:"",size:"sm",variant:"secondary",children:[e.jsx(gs,{className:"mr-2 size-4"}),"Clear"]})}function fn(s,a){if(s.length===0)return"";if(a){const n=s.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return s[0].id;if(r&&r.endsWith("__Header")){const l=r.split("__")[0],i=s.find(c=>c.tabTitle===l);return i?i.id:s[0].id}return a}}return s[0].id}function gn(){const s=t.useQueryClient(),[a,n]=I.useState(!1),[r,o]=I.useState(!1);t.useEditorStore(y=>y.frame);const l=t.useEditorStore(y=>y.card);t.useEditorStore(y=>y.isShowingVisual),t.useEditorStore(y=>y.selectedConnectionId),t.useEditorStore(y=>y.tempQueryData),t.useEditorStore(y=>y.selectedDatabaseName),t.useEditorStore(y=>y.selectedDatamodelId),t.useEditorStore(y=>y.selectedSchemaName);const i=t.useEditorStore(y=>y.showAIDialog);t.useEditorStore(y=>y.selectedTableName);const c=t.useEditorStore(y=>{var w;return(w=y==null?void 0:y.card)==null?void 0:w.sql}),{sheetFilterValues:u}=t.useSheetFilterValues(),{setCardCustomCfg:p,setQueryResultColumns:m,setCardSql:f,setTempQueryData:x,setPythonStdOut:d,setCardPreferences:j,setCardType:h,setCardPython:S,runAssistant:g,setShowAIDialog:T}=t.useEditorActions();t.useEditorStore(y=>y.onSave),t.useEditorStore(y=>y.onClose),t.useEditorStore(y=>y.actions.setSqlGen);const N=t.useEditorStore(y=>y.runSql),A=t.useEditorStore(y=>y.actions.setRunSql),C=t.useEditorStore(y=>y.actions.setIsSqlRunning),{data:L,isLoading:q,isFetching:_,isSuccess:U,isError:v,error:k,queryKey:O,refetch:E,errorMessage:b}=t.useDashboardCardQuery(l),{handleSetAIScope:F}=Mt();I.useEffect(()=>{if(L&&(L.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),d((L==null?void 0:L.output)||""),L.records.length>0)){const{dimensionKeys:y}=t.getKeys(L.records);m(y)}},[L,m,d]),I.useEffect(()=>{(q||_)&&C(!0),(v||U)&&C(!1),v&&(m([]),d(""))},[q,_,L,d,v,U,C,m,k]),I.useEffect(()=>{N&&(s.getQueryData(O)||E(),A(!1))},[N,E,A,O,s]);async function H(){const y=`Can you help me debug this query in the current table scope?
351
+ */const bt=t.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function He(s){var a;return{...s,sheets:(a=s==null?void 0:s.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(o=>{var c;return{...o,cards:(c=o.cards)==null?void 0:c.map(i=>St(i))}})}})}}function St(s){return{...s,customCfg:$s(s.customCfg),data:[]}}function $s(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Qs(s,a,n,r){if(!r)return null;const o=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:o,filterValues:n,operation:"create"})}async function Le(s,a){if(!a)return null;const{id:n,template:r,filterValues:o,isDefault:c,shared:i}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:o,isDefault:c,shared:i,operation:"update"})}async function Js(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Ks(){const[s,a]=D.useState(""),[n,r]=D.useState(!1),o=t.useDashboardStore(p=>p.lenses),{setLenses:c,setSelectedLensId:i}=t.useDashboardActions(),[l,u]=D.useState(!1),[h,m]=D.useState(!1),f=t.useDashboardStore(p=>p.dashboard),x=t.useDashboardStore(p=>p.filterValues),{authToken:d}=t.useSemaphorContext();async function j(){u(!0);const p=He(f),b=await Qs(s,p,x,d==null?void 0:d.accessToken);b&&(c([...o||[],b]),i(b.id),m(!1)),u(!1)}return e.jsxs(t.Dialog,{open:h,onOpenChange:m,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:p=>{a(p.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:j,disabled:l,children:l?"Creating...":"Add"})})]})]})}function Ws(){const[s,a]=D.useState(!1),n=t.useDashboardStore(m=>m.lenses),r=t.useDashboardStore(m=>m.selectedLensId),{setLenses:o,setSelectedLensId:c}=t.useDashboardActions(),{authToken:i}=t.useSemaphorContext();async function l(m){c(m)}async function u(m){if(await Js(m,i==null?void 0:i.accessToken)){const x=n==null?void 0:n.filter(d=>d.id!==m);o(x||[]),c("original")}}async function h(m){const f=n==null?void 0:n.map(j=>j.id===m.id?{...j,isDefault:!m.isDefault}:{...j,isDefault:!1});o(f||[]);const x={...m,isDefault:!m.isDefault};await Le(x,i==null?void 0:i.accessToken);const d=n==null?void 0:n.find(j=>j.isDefault);if(d&&d.id!==m.id){const j={...d,isDefault:!1};await Le(j,i==null?void 0:i.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Cs,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:l,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(m=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:m.id,children:[e.jsx("p",{children:m.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(ws,{onClick:f=>{f.preventDefault(),h(m)},className:t.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!m.isDefault,"text-green-500":m.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:f=>{f.preventDefault(),u(m.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},m.id))]})]})]})}function Ct(){var c;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(c=t.useDashboardStore.getState().dashboard)==null?void 0:c.title,o=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:o||""}}async function vt(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:o,selectedSheetId:c}=Ct();if(s)return;const i=new URLSearchParams;i.set("token",(a==null?void 0:a.accessToken)||""),i.set("theme",n),i.set("filterValues",JSON.stringify(r)),i.set("selectedSheetId",c||"");const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(i.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const m=(await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,f=document.createElement("a");f.href=m;const x=`${o}-${new Date().toISOString()}.pdf`;f.download=x,f.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Ys({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(o=>{var c;return(c=o.dashboard)==null?void 0:c.title}),t.useDashboardStore(o=>o.theme),t.useDashboardStore(o=>o.filterValues);const n=t.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await vt()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(re,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function X({defaultValue:s,label:a,options:n,value:r,onValueChange:o,className:c,icon:i,showPlaceholderLabel:l=!0}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:o,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",c),children:e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsx("span",{children:i}),l&&e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(u=>e.jsx(t.SelectItem,{value:u.value,children:u.label},u.value))]})})]})}const Ze=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function Nt({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:o,error:c,isDeleting:i}=Xs(),[l,u]=D.useState(""),[h,m]=D.useState(Ze[0].value),[f,x]=D.useState("06:00"),[d,j]=D.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(ms,{className:"size-4"})})}),e.jsx(t.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:l,onChange:p=>u(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:d,onChange:p=>{j(p.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(X,{className:"col-span-2 h-8",label:"Select Frequency",options:Ze,value:h,onValueChange:p=>m(p)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:f,onChange:p=>x(p.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:l,frequency:h,time:f,subject:d}),x("00:00"),u(""),j("")},className:"h-8 p-2",disabled:o==="loading"||!l,children:[o==="loading"&&e.jsx(re,{className:"mr-2 size-4 animate-spin"}),o==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),o==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(ct,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:c})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(p=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[t.titleCase(p.frequency)," "]}),e.jsx(t.Label,{children:p.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(et,{tooltip:`Next Run: ${new Date(p.nextRun).toLocaleString()} ${p.timezone}`,children:e.jsx(us,{className:"size-3.5"})}),e.jsx(et,{tooltip:`${p.endUserEmail}`,children:e.jsx(Ms,{className:"size-3.5"})}),i===p.id?e.jsx(re,{className:"size-3.5 animate-spin"}):e.jsx(Us,{onClick:()=>r(p.id),className:"size-3.5 cursor-pointer"})]})]},p.id))})]})]})]})})]})})}const et=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function Xs(){const[s,a]=D.useState("idle"),[n,r]=D.useState(""),[o,c]=D.useState(null),i=t.useDashboardStore(v=>v.authToken),l=t.useDashboardStore(v=>v.dashboard.id),u=t.useDashboardStore(v=>v.dashboard.title),{endUserId:h}=t.getTenantAndEndUserId((i==null?void 0:i.accessToken)||""),m="https://semaphor.cloud/api/v1/subscriptions/get",f={dashboardId:l,endUserId:h},{data:x,isLoading:d,isError:j,isFetching:p,refetch:b}=t.useQuery({queryKey:["subscriptions",l,h],queryFn:()=>t.getRequest(m,(i==null?void 0:i.accessToken)||"",f),enabled:!!(i!=null&&i.accessToken)&&!!l&&!!h});async function g({email:v,subject:M,frequency:y,time:L}){const{authToken:B,...V}=Ct(),G=Intl.DateTimeFormat().resolvedOptions().timeZone,N={email:v,frequency:y,time:L,timezone:G,endUserId:h,endUserEmail:v,subject:M||u||"Scheduled Dashboard",dashboardId:l,dashboardParams:V};a("loading");const k="https://semaphor.cloud/api/v1/subscriptions/create";try{const O=await t.postRequestRegular(k,(B==null?void 0:B.accessToken)||"",{...N});a("success"),r(""),b(),setTimeout(()=>{a("idle")},2e3)}catch(O){console.error(O),a("error"),r(O.message)}}async function T(v){const M="https://semaphor.cloud/api/v1/subscriptions/delete";c(v);try{await t.postRequestRegular(M,(i==null?void 0:i.accessToken)||"",{id:v}),b(),setTimeout(()=>{c(null)},2e3)}catch(y){console.error(y),c(null),a("error"),r(y.message)}}return{data:x,isLoading:d,isFetching:p,isError:j,isDeleting:o,refetch:b,handleScheduleSubscription:g,handleDeleteSubscription:T,status:s,error:n}}function Zs(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(N=>N.theme);const a=t.useDashboardStore(N=>N.lenses),n=t.useDashboardStore(N=>N.selectedLensId),r=a==null?void 0:a.find(N=>N.id===n),o=t.useDashboardStore(N=>N.dashboard);t.useDashboardStore(N=>N.selectedSheetId);const c=t.useDashboardStore(N=>N.isDashboardEditing),i=t.useEditorStore(N=>N.selectedConnectionId),[l,u]=D.useState(!1),h=t.useDashboardStore(N=>N.filterValues),m=t.useDashboardStore(N=>N.isVisualEditing),f=t.useDashboardStore(N=>N.showFilters);t.useDashboardStore(N=>N.showDashboardJSON);const x=t.useDashboardStore(N=>N.onSaveFunction),d=t.useDashboardStore(N=>N.actions.setShowFilters),{addFrame:j,setSelectedFrameId:p}=t.useDashboardStore(N=>N.actions),{getSelectedSheet:b,setIsDashboardEditing:g,setShowDashboardJSON:T}=t.useDashboardStore(N=>N.actions),v=b(),{tenantId:M,endUserId:y}=D.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),L=D.useMemo(()=>M||y,[M,y]),B=()=>{if(!c||!v)return;const N={connectionId:i,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},k={id:t.v4(),cards:[N],activeCardId:N.id};j(v.id,k),p(k.id)},V=()=>{g(!0)};async function G(){if(u(!0),!n||!r)return;const N=He(o),k=JSON.stringify(N),O={...r,template:k,filterValues:h};await Le(O,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),x==null||x(N),u(!1)}return m?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!m&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!m&&e.jsx(Ys,{}),!m&&e.jsx(Nt,{}),c&&!m&&L&&e.jsx(Ks,{}),!m&&L&&e.jsx(Ws,{}),c&&!m&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!c,onClick:B,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!c&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:V,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),c&&!m&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{g(!1),T(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),c&&!m&&L&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:G,size:"sm",children:e.jsx(Vs,{className:"h-4 w-4"})}),!f&&!m&&c&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>d(!0),size:"sm",children:e.jsx(mt,{className:"h-4 w-4"})}),!m&&c&&!1,!m&&!1]})]})}function en({name:s,items:a,value:n,onChange:r,isLoading:o,isError:c,refetch:i,className:l,icon:u,showNone:h=!1}){const m=ce.useRef(null),[f,x]=ce.useState(!1),[d,j]=ce.useState("100%"),p=h?[...a||[],{id:"none",name:"None"}]:a;ce.useLayoutEffect(()=>{m.current&&j(m.current.offsetWidth)},[]);function b(){var T;return o?"Loading...":c?"Error":n?(T=a==null?void 0:a.find(v=>v.id===n))==null?void 0:T.name:`Select ${s}`}function g(T,v){r(v),x(!1)}return e.jsxs(t.Popover,{open:f,onOpenChange:x,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:m,variant:"outline",role:"combobox","aria-expanded":f,className:t.cn("flex h-9 w-full justify-between",l),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"mr-2",children:u}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:b()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:d},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:i,children:e.jsx(ft,{className:t.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:p==null?void 0:p.map(T=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:T.name,onSelect:v=>g(v,T.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===T.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:T.name,children:T.name})]})},T.id))})]})]})})]})}function le({title:s,items:a,value:n,isLoading:r,isError:o,refetch:c,onChange:i,showNone:l=!1,className:u,disabled:h=!1,type:m="combobox"}){const f=r?"Loading...":o?"Error":n;function x(){if(s==="Connection")return e.jsx(Fs,{className:"size-4"});if(s==="Database")return e.jsx(fs,{className:"size-4"});if(s==="Schema")return e.jsx(zs,{className:"size-4"});if(s==="Table")return e.jsx(Pe,{className:"size-4"});if(s==="Model")return e.jsx(ls,{className:"size-4"})}function d(){return e.jsxs(t.Select,{disabled:h,value:f,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",u),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(ft,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:c})]}),e.jsxs(e.Fragment,{children:[l&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((p,b)=>e.jsx(t.SelectItem,{value:p.id,children:p.name},b))]}),(r||o)&&e.jsx(t.SelectItem,{value:f,children:f})]})})]})}function j(){return e.jsx(en,{icon:x(),items:a,value:f,onChange:i||(()=>{}),isLoading:r,isError:o,refetch:c,name:s,showNone:l})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:m==="select"?d():j()})})}function tn({column:s}){const[a,n]=D.useState(!1),r=t.useEditorStore(p=>p.selectedTableName),o=t.useEditorStore(p=>p.selectedSchemaName),c=t.useEditorStore(p=>p.selectedDatabaseName),i=t.useEditorStore(p=>p.selectedDatamodelId),l=t.useEditorStore(p=>p.sqlGen),{modelItems:u,connectionType:h}=Z(),m=t.useEditorStore(p=>p.actions.setSqlGen),f=t.useEditorStore(p=>p.actions.setCardSql),x=t.useEditorStore(p=>p.actions.setRunSql);function d(p,b){var M;const g=t.createSqlGenConfig(p,l,b),T=(M=u==null?void 0:u.find(y=>y.id===i))==null?void 0:M.name;m(g);const v=t.getSql(g,t.fmt(o||""),t.fmt(r),T,h,c||"");v&&(f(v),x(!0)),n(!1)}function j(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>d(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>d(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>d(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>d(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>d(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(ut,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:j()})]})}function Ge({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(bt,{className:"size-3"}):t.isNumberDataType(s.data_type)?e.jsx(ht,{className:"size-3"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3"}):t.isBooleanDataType(s.data_type)?e.jsx(Gs,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsx(cs,{className:"size-3"}):e.jsx(Bs,{className:"size-3"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function we({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(Ge,{column:s}),e.jsx("span",{children:s.column_name})]})}function sn({id:s,children:a,type:n="column"}){const{attributes:r,listeners:o,setNodeRef:c,transform:i}=t.useDraggable({id:s,data:{type:n}}),l=i?{translate:t.CSS.Translate.toString(i),transform:t.CSS.Transform.toString(i)}:void 0;return e.jsx("div",{ref:c,style:l,...o,...r,children:a})}function nn({onClick:s,column:a}){const n=t.useDndStore(x=>x.activeId),r=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.groupByColumns}),o=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.trendByColumns}),c=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.metricColumns}),i=t.useEditorStore(x=>{var d;return(d=x.card.queryConfig)==null?void 0:d.filterColumns});function l(x){return u(x)||m(x)||h(x)||f(x)}function u(x){return r==null?void 0:r.some(d=>d.name===x.column_name)}function h(x){return o==null?void 0:o.some(d=>d.name===x.column_name)}function m(x){return c==null?void 0:c.some(d=>d.name===x.column_name)}function f(x){return i==null?void 0:i.some(d=>d.name===x.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":l(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(we,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(we,{column:a})}),e.jsx(sn,{id:a.column_name,type:"column",children:e.jsx(we,{column:a})})]})}function ae(s){return`${s}-${t.v4()}`}function Oe(s,a){return s==="SUM"?`Sum of ${a}`:s==="AVG"?`Avg of ${a}`:s==="COUNT"?`Count of ${a}`:s==="MAX"?`Max of ${a}`:s==="MIN"?`Min of ${a}`:s==="DISTINCT"?`Distinct ${a}`:a}function an({schemaName:s,tableName:a,columns:n,status:r}){const o=t.useEditorStore(S=>S.sqlGen),c=t.useEditorStore(S=>S.isDevMode),i=t.useEditorStore(S=>S.selectedConnectionId),l=t.useEditorStore(S=>S.selectedDatabaseName),u=t.useEditorStore(S=>S.selectedSchemaName),h=t.useEditorStore(S=>S.selectedTableName),m=t.useEditorStore(S=>S.selectedDatamodelId),f=t.useDashboardStore(S=>S.dashboard.aiScopeTables),{addToAIScope:x,removeFromAIScope:d}=t.useDashboardActions(),{addColumnToMetricColumns:j,addColumnToTrendByColumns:p,setCardSql:b,setRunSql:g,setSqlGen:T,setIsShowingVisual:v}=t.useEditorActions(),{connectionType:M,modelItems:y,selectedDatamodelName:L}=Z();function B(S){var F;if(c){const H=t.createSqlGenConfig(S,o);T(H);const $=(F=y==null?void 0:y.find(I=>I.id===m))==null?void 0:F.name,q=t.getSql(H,t.fmt(s),t.fmt(a),$,M,l||"");q&&(b(q),g(!0))}if(!c){if(t.isTextDataType(S.data_type)){const H={...S,role:"metric",id:ae(S.column_name),name:S.column_name,label:Oe("COUNT",S.column_name),type:S.data_type,aggregate:"COUNT"};j(H)}if(t.isNumberDataType(S.data_type)){const H={...S,role:"metric",id:ae(S.column_name),name:S.column_name,label:Oe("SUM",S.column_name),type:S.data_type,aggregate:"SUM"};j(H)}if(t.isDateDataType(S.data_type)){const H={...S,role:"trendby",id:ae(S.column_name),name:S.column_name,type:S.data_type};p(H)}}}function V(S){S===!0&&(h||L)&&i?(x({connectionId:i,connectionType:M==="S3"||M==="API"?"DuckDb":M,databaseName:l||"",schemaName:u||"",tableName:h||"",datamodelName:t.resolveDatamodelName(L),datamodelId:m||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(d({connectionId:i||"",connectionType:M||"",tableName:h||"",datamodelName:t.resolveDatamodelName(L),datamodelId:m||"",databaseName:l||"",schemaName:u||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function G(){const S=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:L,connectionType:M,databaseName:l||""});v(!1);const F=M==="MSSQL"?`SELECT top 10 * FROM ${S}`:`SELECT * FROM ${S} LIMIT 10`;b(F),g(!0)}function N(){const S=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:L,connectionType:M,databaseName:l||""});b(`SELECT COUNT(*) as count FROM ${S}`),g(!0)}function k(){return(f==null?void 0:f.find(S=>S.connectionId===i&&(S.tableName===h||S.datamodelName===L)))!==void 0}function O(S){return c?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>B(S),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ge,{column:S}),e.jsx("span",{children:S.column_name})]}),e.jsx("div",{onClick:F=>F.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(S.data_type)&&e.jsx(tn,{column:S})})]}):e.jsx(nn,{onClick:B,column:S})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${k()?"Remove from":"Add to"} Assistant Scope`,pressed:k(),onPressedChange:V,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":k(),"text-muted-foreground":!k()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:G,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ts,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:N,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(jt,{className:"mr-2 size-4"}),"Count"]})]})}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:E()}),e.jsxs(t.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted px-2 py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(S=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:O(S)},S.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function wt(s){const a=t.useDashboardStore(u=>u.authToken)||s,n=t.useEditorStore(u=>u.selectedConnectionId),{refetch:r,data:o,isLoading:c,isError:i}=t.useQuery({queryKey:["connections"],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/connections",(a==null?void 0:a.accessToken)||""),enabled:!!(a!=null&&a.accessToken)}),l=o==null?void 0:o.connections.find(u=>u.id===n);return{connectionsData:o,isConnectionsLoading:c,isConnectionsError:i,refetchConnections:r,currentConnection:l}}function Ue(s){var b;const a=t.useDashboardStore(g=>g.authToken)||s,n=t.useEditorStore(g=>g.selectedConnectionId),r=t.useEditorStore(g=>g.selectedDatabaseName),o=t.useEditorStore(g=>g.selectedDatamodelId),c=t.useEditorStore(g=>g.selectedSchemaName),i=t.useEditorStore(g=>g.selectedTableName),{currentConnection:l}=wt(),u=l==null?void 0:l.type,{data:h,isLoading:m,isFetching:f,isError:x,refetch:d}=t.useQuery({queryKey:["columns",n,r,o,c,i],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/columns",(a==null?void 0:a.accessToken)||"",{connection_id:n,datamodel_id:o||"",database_name:r,schema_name:c,table_name:i}),enabled:j(u)});function j(g){return a!=null&&a.accessToken?!!(n&&r&&r!=="NA"&&c&&i||n&&(g==="S3"||g==="API")||o&&o):!1}return{columns:(b=h==null?void 0:h.columns)==null?void 0:b.map(g=>({...g,data_type:g.data_type.toLowerCase()})),isColumnsLoading:m,isColumnsFetching:f,isColumnsError:x,refetchColumns:d}}function Z(s,a){var Je,Ke,We,Ye,Xe;const n=t.useSemaphorContext().authToken||s,r=t.useEditorStore(_=>_.selectedConnectionId),o=t.useEditorStore(_=>_.selectedDatamodelId),c=t.useEditorStore(_=>_.selectedDatabaseName),i=t.useEditorStore(_=>_.selectedSchemaName),l=t.useEditorStore(_=>_.selectedTableName),u=t.useEditorStore(_=>_.actions.setSelectedConnectionId),h=t.useEditorStore(_=>_.actions.setSelectedDatamodelId),m=t.useEditorStore(_=>_.actions.setSelectedDatabaseName),f=t.useEditorStore(_=>_.actions.setSelectedSchemaName),x=t.useEditorStore(_=>_.actions.setSelectedTableName);t.useEditorStore(_=>_.actions.setCardSql);function d(_){return r&&c&&i&&c!=="NA"?!0:r&&_==="API"?!1:!!(r&&_==="S3")}function j(_){return r&&_?!(_==="API"||_==="S3"):!1}const{refetchConnections:p,connectionsData:b,isConnectionsLoading:g,isConnectionsError:T,currentConnection:v}=wt(s),{refetch:M,data:y,isLoading:L,isError:B}=t.useQuery({queryKey:["models",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:!!(n!=null&&n.accessToken)&&!!r}),V=v==null?void 0:v.type,G=(v==null?void 0:v.type)==="API"||(v==null?void 0:v.type)==="S3",{data:N,isLoading:k,isFetching:O,isError:E,refetch:S}=t.useQuery({queryKey:["databases",r],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:r}),enabled:j(V)}),{data:F,isLoading:H,isFetching:$,isError:q,refetch:I}=t.useQuery({queryKey:["schemas",r,c],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:c}),enabled:!!r&&!!c&&!G&&c!=="NA"}),{data:C,isLoading:w,isFetching:A,isError:z,refetch:U}=t.useQuery({queryKey:["tables",r,c,i],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:r,database_name:c,schema_name:i}),enabled:d(V)}),{columns:P,isColumnsLoading:K,isColumnsFetching:W,isColumnsError:ee,refetchColumns:te}=Ue(s);D.useEffect(()=>{(V==="S3"||V==="API")&&(m(""),f(""),h(""),V==="API"&&x("api"))},[V,x,m,f,h]);const R=(v==null?void 0:v.type)==="API"?(Je=v==null?void 0:v.type)==null?void 0:Je.toLowerCase():l||"",Q=G?"":i||"";function Y(_){f(_),x("")}function ne(_){m(_==="none"?"":_),f(""),x(""),_!=="none"&&_!==""&&h("")}function ie(_){u(_)}function Se(_){h(_==="none"?"":_),_!=="none"&&_!==""&&m("")}N&&((Ke=N==null?void 0:N.databases)==null?void 0:Ke.length)>0,F&&((We=F==null?void 0:F.schemas)==null?void 0:We.length)>0;const Ce=b==null?void 0:b.connections.map(_=>({id:_.id,name:_.name,type:_.type})),ve=(Ye=y==null?void 0:y.datamodels)==null?void 0:Ye.map(_=>({id:_.id,name:_.name})),Ne=N==null?void 0:N.databases.map(_=>({id:_.database_name,name:_.database_name})),xe=F==null?void 0:F.schemas.map(_=>({id:_.schema_name,name:_.schema_name})),J=C==null?void 0:C.tables.map(_=>({id:_.table_name,name:_.table_name})),se=(Xe=y==null?void 0:y.datamodels.find(_=>_.id===o))==null?void 0:Xe.name,Jt=t.getFormattedTableNameForQuery({schemaName:Q,tableName:R,modelName:se,connectionType:V,databaseName:c||""});return{connectionItems:Ce,selectedConnectionId:r,isConnectionsLoading:g,isConnectionsError:T,modelItems:ve,selectedDatamodelId:o,selectedDatamodelName:se,isModelsLoading:L,isModelsError:B,selectedDatabaseName:c,databaseItems:Ne,isDatabasesLoadingOrFetching:k||O,isDatabaseError:E,schemaItems:xe,selectedSchemaName:i,isSchemaLoadingOrFetching:H||$,isSchemaError:q,tableItems:J,selectedTableName:l,isTableLoadingOrFetching:w||A,isTableError:z,columns:P,isColumnsLoadingOrFetching:K||W,isColumnsError:ee,isNonDbConnection:G,connectionType:V,tableName:R,formattedTableName:Jt,schemaName:Q,refetchConnections:p,refetchModels:M,refetchDatabases:S,refetchSchemas:I,refetchTables:U,refetchColumns:te,handleConnectionChange:ie,handleDatamodelChange:Se,handleDatabaseChange:ne,handleSchemaChange:Y}}function kt({ColumnsComponent:s,type:a}){var xe;const n=t.useEditorStore(J=>J.card),r=t.useEditorStore(J=>J.selectedConnectionId),o=t.useDashboardStore(J=>J.showFilters),c=t.useEditorStore(J=>J.selectedDatamodelId),i=t.useEditorStore(J=>J.selectedDatabaseName),l=t.useEditorStore(J=>J.selectedSchemaName),u=t.useEditorStore(J=>J.selectedTableName),h=t.useEditorStore(J=>J.isDevMode),{setSelectedTableName:m,setIsDevMode:f,setCardSql:x}=t.useEditorActions(),{connectionItems:d,modelItems:j,schemaItems:p,databaseItems:b,tableItems:g,columns:T,isConnectionsLoading:v,isModelsLoading:M,isConnectionsError:y,isModelsError:L,isDatabasesLoadingOrFetching:B,isDatabaseError:V,isSchemaLoadingOrFetching:G,isSchemaError:N,isColumnsError:k,isColumnsLoadingOrFetching:O,isTableLoadingOrFetching:E,isTableError:S,connectionType:F,isNonDbConnection:H,refetchDatabases:$,refetchModels:q,refetchSchemas:I,refetchTables:C,refetchColumns:w,refetchConnections:A,handleConnectionChange:z,handleDatabaseChange:U,handleSchemaChange:P,handleDatamodelChange:K,tableName:W,schemaName:ee}=Z(),{data:te,refetch:R}=t.useDashboardCardQuery(n);function Q(){return s?s(ee,W,T):e.jsx(an,{schemaName:ee,tableName:W,columns:T,status:O?"Loading...":k?"Error":"Success"})}function Y(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function ne(J){J===!0?te&&(x(te.userSql),setTimeout(()=>{R()},500)):x(""),f(J)}function ie(){if(!r||F==="S3"||F==="API")return null;if(!c||c==="none")return e.jsx(le,{refetch:$,showNone:!0,onChange:U,isError:V,isLoading:B,items:b,value:i||"",title:"Database",type:"combobox"})}function Se(){if(r&&!H&&(!i||i==="none")&&(!c||c==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function Ce(){if(!r||F==="S3"||F==="API")return null;if(!i||i==="none")return e.jsx(le,{refetch:q,showNone:!0,onChange:K,isError:L,isLoading:M,items:j,value:c||"",title:"Model",type:"combobox"})}function ve(){return!r||F==="S3"||F==="API"||!i||i==="none"?null:e.jsx(le,{refetch:I,onChange:P,isError:N,isLoading:G,items:p,value:l||"",title:"Schema",type:"combobox"})}function Ne(){function J(){let se=!1;return F==="API"?(se=!1,se):((F==="S3"||r&&i&&i!=="none"&&l)&&(se=!0),se)}return J()?e.jsx(le,{refetch:C,onChange:m,isError:S,items:g,isLoading:E,value:u||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.cn("flex h-full min-w-[300px] flex-col justify-between rounded-none",{"border-r-[1px]":!o}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(le,{refetch:A,items:d,title:"Connection",value:r||"",onChange:z,isLoading:v,isError:y,type:"combobox",connectionTooltip:((xe=d==null?void 0:d.find(J=>J.id===r))==null?void 0:xe.type)||""}),ie(),Se(),Ce(),ve(),Ne()]}),Q(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:h,onCheckedChange:ne,id:"dev-mode"}),e.jsx(t.Label,{htmlFor:"dev-mode",children:"Dev Mode"})]}),e.jsxs(t.Button,{onClick:Y,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(As,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function Dt({sql:s,error:a,onClick:n}){return!s&&!a?null:e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(ct,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})]})]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(Ns,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var It={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},tt=D.createContext&&D.createContext(It),rn=["attr","size","title"];function on(s,a){if(s==null)return{};var n=ln(s,a),r,o;if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(s);for(o=0;o<c.length;o++)r=c[o],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function ln(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function ye(){return ye=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},ye.apply(this,arguments)}function st(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),n.push.apply(n,r)}return n}function be(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?st(Object(n),!0).forEach(function(r){cn(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):st(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function cn(s,a,n){return a=dn(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function dn(s){var a=un(s,"string");return typeof a=="symbol"?a:a+""}function un(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function Et(s){return s&&s.map((a,n)=>D.createElement(a.tag,be({key:n},a.attr),Et(a.child)))}function he(s){return a=>D.createElement(mn,ye({attr:be({},s.attr)},a),Et(s.child))}function mn(s){var a=n=>{var{attr:r,size:o,title:c}=s,i=on(s,rn),l=o||n.size||"1em",u;return n.className&&(u=n.className),s.className&&(u=(u?u+" ":"")+s.className),D.createElement("svg",ye({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:u,style:be(be({color:s.color||n.color},n.style),s.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),c&&D.createElement("title",null,c),s.children)};return tt!==void 0?D.createElement(tt.Consumer,null,n=>a(n)):a(It)}function hn(s){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:[]}]})(s)}function Tt(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(p=>p.theme),r=t.useEditorStore(p=>p.frame),o=t.useEditorStore(p=>p.card),c=t.useEditorStore(p=>p.activeTabCardId),i=t.Le(),{refetch:l}=t.useDashboardCardQuery(o),{updateCardTab:u,setRunSql:h}=t.useEditorActions(),m=D.useRef(),f=D.useRef({}),x=r.cards.find(p=>p.id===c),d=D.useCallback(()=>{let p="";return s==="python"&&(p=(x==null?void 0:x.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(p=(x==null?void 0:x.sql)||""),p},[s,x]);D.useEffect(()=>{if(c&&o.id&&o.id!==c){if(m.current&&i){const p=m.current.getModel();p&&(f.current[o.id]=p);let b=f.current[c];if(!b){const g=d();b=i.editor.createModel(g,s),f.current[c]=b}m.current.setModel(b)}u(c,o),h(!0)}},[c,o,u,i,h,s,d]),D.useEffect(()=>{if(!i)return;const p=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",b=n==="system"?p:n;i.editor.defineTheme("default",{base:b==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":b==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default")},[a,n,i]),D.useEffect(()=>{const p=m.current;p&&i&&o&&p.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return l(),!1})},[i,l,o]);function j(p,b){if(m.current=p,!f.current[o.id]){const g=p.getModel(),T=d();f.current[o.id]=g||(b==null?void 0:b.editor.createModel(T,s))||p.getModel()}p.setModel(f.current[o.id])}return{handleEditorDidMount:j}}function pn(){const s=t.useEditorStore(i=>i.card.sql),a=t.useEditorStore(i=>i.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:o}=Tt("sql");function c(i){n(i),t.isObjectEmpty(a)||r({})}return e.jsx(t.Ft,{theme:"default",className:"pt-3",onChange:c,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function xn(){const s=t.useEditorStore(o=>o.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=Tt("python");function r(o){a(o)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function fn({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function Mt(s){var W,ee,te;const[a,n]=D.useState(""),[r,o]=D.useState(null),{authToken:c}=t.useSemaphorContext(),i=t.useEditorStore(R=>{var Q;return(Q=R==null?void 0:R.card)==null?void 0:Q.sql}),l=t.useEditorStore(R=>{var Q;return(Q=R==null?void 0:R.card)==null?void 0:Q.python}),u=t.useEditorStore(R=>R.actions.setCardSql),h=t.useEditorStore(R=>R.actions.setRunSql),m=t.useEditorStore(R=>R.actions.switchCardType),f=t.useEditorStore(R=>R.currentAssitantScope)||[],x=t.useEditorStore(R=>R.userInputForAI),d=t.useEditorStore(R=>R.triggerAIRun),j=t.useEditorStore(R=>R.selectedDatabaseName),p=t.useEditorStore(R=>R.selectedTableName),b=t.useEditorStore(R=>R.selectedConnectionId),g=t.useEditorStore(R=>R.selectedSchemaName),T=t.useDashboardStore(R=>R.dashboard.aiScopeTables),{setTriggerAIRun:v,setCurrentAssitantScope:M}=t.useEditorActions(),{selectedDatamodelName:y,connectionType:L,selectedDatamodelId:B}=Z(),{messages:V,setMessages:G,reload:N,error:k,append:O,input:E,setInput:S,status:F,handleInputChange:H,handleSubmit:$,stop:q}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${c==null?void 0:c.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:I,onFinish(R,Q){C(Q.usage),n(""),Q.finishReason==="stop"&&n("")}});D.useEffect(()=>{d&&x&&(H({target:{value:x}}),setTimeout(()=>{$(),v(!1)},100))},[d,$,x,v,H]);async function I({toolCall:R}){if(R.toolName==="createChartFromSql"){const Q=R.args.sql,Y=R.args.chartType;return m(Y),u(Q),h(!0),{status:"success",message:"Let the user know that chart is created"}}else if(R.toolName==="getTableColumns")n("Getting table columns...");else{if(R.toolName==="getUserSql")return i?{status:"success",sql:i,python:l||""}:{status:"error",message:"No SQL found"};if(R.toolName==="getCurrentTableScope")return n("Getting table scope..."),U(),{status:"success",tables:f};n("Analyzing...")}}function C(R){o(Q=>Q?{promptTokens:Q.promptTokens+R.promptTokens,completionTokens:Q.completionTokens+R.completionTokens,totalTokens:Q.totalTokens+R.totalTokens}:R)}function w(R){const Q=t.removeFromScopeArray(f,R);A(Q)}function A(R){const Q=t.sanitizeAIScope(R);M(Q),G(Y=>[...Y,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(Q)}`}])}function z(){const R={databaseName:j||"",schemaName:g||"",tableName:p||"",datamodelId:B||"",datamodelName:t.resolveDatamodelName(y),connectionId:b||"",connectionType:L||""},Q=t.dedup([...f,R]);A(Q)}function U(){const R={databaseName:j||"",schemaName:g||"",tableName:p||"",datamodelName:t.resolveDatamodelName(y),connectionId:b||"",connectionType:L||"",datamodelId:B||""};if(!t.isInAiScopeArray([...T||[],...f],R)||f.length===0){const Y=t.dedup([...T||[],...f,R]).filter(ne=>ne.connectionId===R.connectionId);A(Y)}}const P=!["ready","error"].includes(F),K=(te=(ee=(W=JSON.parse((k==null?void 0:k.message)||"{}"))==null?void 0:W.error)==null?void 0:ee.lastError)==null?void 0:te.message;return{messages:V,setMessages:G,reload:N,append:O,input:E,setInput:S,isLoading:P,handleSetAIScope:U,handleAddCurrentTableToScope:z,removeFromCurrentSelections:w,currentAssitantScope:f,setCurrentAssitantScope:M,handleInputChange:H,handleSubmit:$,stop:q,chatStatus:F,toolStatus:a,llmUsage:r,onFinish:s,errorMessage:K}}function gn(s){const a=s.toUpperCase().indexOf("WHERE"),n=s.toUpperCase().indexOf("GROUP BY"),r=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let c=s.length;if(o!==-1&&(c=o),r!==-1&&r<c&&(c=r),a!==-1){const i=s.substring(0,a),l=s.substring(a);return`${i} {{ filters | where }} AND ${l.substring(6)}`}else if(n!==-1){const i=s.substring(0,n),l=s.substring(n);return`${i} {{ filters | where }} ${l}`}else{const i=s.substring(0,c),l=s.substring(c);return console.log("beforeClause",i),console.log("afterClause",l),l?`${i} {{ filters | where }} ${l}`:`${i.replace(/;$/,"")} {{ filters | where }}`}}function At({variant:s="secondary"}){const{setCardSql:a}=t.useEditorActions(),n=t.useEditorStore(d=>d.frame),r=t.useEditorStore(d=>d.card),o=t.useEditorStore(d=>d.selectedSchemaName),c=t.useEditorStore(d=>d.selectedDatamodelId),i=t.useEditorStore(d=>d.selectedDatabaseName),l=t.useEditorStore(d=>d.selectedTableName),u=t.useEditorStore(d=>d.selectedConnectionId),h=t.useEditorStore(d=>d.isShowingVisual),m=r.sql,f=t.useEditorStore(d=>d.onSave);function x(){let d=m;m&&!m.includes("{{")&&(d=gn(m),a(d));const j={...r,lastSelectedSchema:o,lastSelectedDatamodelId:c,lastSelectedDatabase:i,lastSelectedTable:l,connectionId:u,type:h?r.type:"table",sql:d,customCfg:h?r.customCfg:null},p=n.cards.map(g=>g.id===r.id?j:g),b={...n,cards:p,activeCardId:jn(p,n.activeCardId)};f==null||f(b)}return e.jsxs(t.Button,{onClick:x,size:"sm",variant:s,children:[e.jsx(t.Check,{className:"mr-2 size-4 font-bold"}),"Accept"]})}function Lt(){const{setTempQueryData:s,setSqlGen:a}=t.useEditorActions(),n=t.useQueryClient(),r=t.useEditorStore(u=>u.tempQueryData),o=t.useEditorStore(u=>u.onClose),c=t.useEditorStore(u=>u.card),{queryKey:i}=t.useDashboardCardQuery(c);function l(){if(r){const{queryKey:u,queryData:h}=r;u&&h&&n.setQueryData(u,h)}a({}),o==null||o()}return e.jsxs(t.Button,{onClick:l,size:"sm",variant:"secondary",children:[e.jsx(t.X,{className:"mr-2 size-4"}),"Close"]})}function Ot(){const{setTempQueryData:s}=t.useEditorActions(),a=t.useQueryClient(),n=t.useEditorStore(d=>d.tempQueryData),r=t.useEditorStore(d=>d.card),{queryKey:o}=t.useDashboardCardQuery(r),{setCardSql:c,setSqlGen:i,setCardPython:l,setCardCustomCfg:u,setCardPreferences:h,setCardType:m,clearQueryConfig:f}=t.useEditorActions();function x(){const d=a.getQueryData(o);n!=null&&n.queryData||s({queryKey:o,queryData:d}),a.setQueryData(o,null),a.removeQueries({queryKey:o,exact:!0}),c(""),i({}),f(),l(""),u(""),h({})}return e.jsxs(t.Button,{onClick:x,className:"",size:"sm",variant:"secondary",children:[e.jsx(gs,{className:"mr-2 size-4"}),"Clear"]})}function jn(s,a){if(s.length===0)return"";if(a){const n=s.find(r=>r.id===a);if(n){const r=n.tabTitle;if(r=="All__Header")return s[0].id;if(r&&r.endsWith("__Header")){const c=r.split("__")[0],i=s.find(l=>l.tabTitle===c);return i?i.id:s[0].id}return a}}return s[0].id}function yn(){const s=t.useQueryClient(),[a,n]=D.useState(!1),[r,o]=D.useState(!1);t.useEditorStore(C=>C.frame);const c=t.useEditorStore(C=>C.card);t.useEditorStore(C=>C.isShowingVisual),t.useEditorStore(C=>C.selectedConnectionId),t.useEditorStore(C=>C.tempQueryData),t.useEditorStore(C=>C.selectedDatabaseName),t.useEditorStore(C=>C.selectedDatamodelId),t.useEditorStore(C=>C.selectedSchemaName);const i=t.useEditorStore(C=>C.showAIDialog);t.useEditorStore(C=>C.selectedTableName);const l=t.useEditorStore(C=>{var w;return(w=C==null?void 0:C.card)==null?void 0:w.sql}),{sheetFilterValues:u}=t.useSheetFilterValues(),{setCardCustomCfg:h,setQueryResultColumns:m,setCardSql:f,setTempQueryData:x,setPythonStdOut:d,setCardPreferences:j,setCardType:p,setCardPython:b,runAssistant:g,setShowAIDialog:T}=t.useEditorActions();t.useEditorStore(C=>C.onSave),t.useEditorStore(C=>C.onClose),t.useEditorStore(C=>C.actions.setSqlGen);const v=t.useEditorStore(C=>C.runSql),M=t.useEditorStore(C=>C.actions.setRunSql),y=t.useEditorStore(C=>C.actions.setIsSqlRunning),{data:L,isLoading:B,isFetching:V,isSuccess:G,isError:N,error:k,queryKey:O,refetch:E,errorMessage:S}=t.useDashboardCardQuery(c),{handleSetAIScope:F}=Mt();D.useEffect(()=>{if(L&&(L.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),d((L==null?void 0:L.output)||""),L.records.length>0)){const{dimensionKeys:C}=t.getKeys(L.records);m(C)}},[L,m,d]),D.useEffect(()=>{(B||V)&&y(!0),(N||G)&&y(!1),N&&(m([]),d(""))},[B,V,L,d,N,G,y,m,k]),D.useEffect(()=>{v&&(s.getQueryData(O)||E(),M(!1))},[v,E,M,O,s]);async function H(){const C=`Can you help me debug this query in the current table scope?
342
352
 
343
353
  Error:
344
354
 
345
- ${b}
355
+ ${S}
346
356
 
347
357
  Query:
348
358
 
349
- ${c}
359
+ ${l}
350
360
 
351
- `;g(y)}function $(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(pn,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.length>0&&e.jsx(t.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(t.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(mt,{className:"size-3.5 text-muted-foreground"})})]})}function B(){return e.jsxs(t.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(t.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(mn,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(t.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(hn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function D(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(t.Button,{title:"Shift + Enter",disabled:q||_,onClick:()=>{E()},className:"shrink-0",size:"sm",children:[q||_?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(Dt,{sql:L==null?void 0:L.sql,error:b,onClick:H}),e.jsx(zt,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:y=>n(y),className:"",size:"sm",children:e.jsx(un,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{F(),T(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ot,{}),e.jsx(Lt,{})]})]})}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:[B(),$()]}),D()]})}function jn({data:s}){var i;const[a,n]=I.useState([]),o=Object.keys(s[0]).map(c=>({accessorKey:c,header:({column:u})=>{const p=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[c,p==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=t.useReactTable({data:s,columns:o,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsx(t.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(t.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:l.getHeaderGroups().map(c=>e.jsx(t.TableRow,{className:"",children:c.headers.map(u=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:u.isPlaceholder?null:t.flexRender(u.column.columnDef.header,u.getContext())},u.id))},c.id))}),e.jsx(t.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(c=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(u=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},c.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function bn({card:s}){var T,N,A,C,L,q,_,U,v,k,O;const[a,n]=I.useState(!1),[r,o]=I.useState([]),{authToken:l}=t.useSemaphorContext(),i=t.getTokenParams(l==null?void 0:l.accessToken),c=t.useDashboardStore(E=>E.themeStyle),u={colors:((N=(T=c==null?void 0:c.chart)==null?void 0:T.dataset)==null?void 0:N.backgroundColor)||[]};(A=s.customCardPreferences)!=null&&A.inputData;const{getCard:p}=t.useCustomVisual(((C=s.customCardPreferences)==null?void 0:C.url)||""),m=((L=s.customCardPreferences)==null?void 0:L.visualType)||"single",f=t.useEditorStore(E=>E.frame),{setCustomCardPreferences:x}=t.useEditorActions(),{data:d}=t.useDashboardCardQuery(s),j=I.useCallback((E,b)=>{o(F=>({...F,[E]:b}))},[]);if(!((q=s.customCardPreferences)!=null&&q.componentName))return null;const h=p((_=s.customCardPreferences)==null?void 0:_.componentName);function S(E){n(E)}const g=Object.keys(((U=s.customCardPreferences)==null?void 0:U.dataInputCardIds)||{}).map(E=>{var H,$,B;const b=($=(H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:$[E].cardId,F=(B=f==null?void 0:f.cards)==null?void 0:B.find(D=>D.id===b);return F||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(I.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[h&&m==="single"&&e.jsx(h,{params:i,theme:u,settings:(v=s.customCardPreferences)==null?void 0:v.settings,onDataChange:j,data:(d==null?void 0:d.records)||[]}),h&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((k=s.customCardPreferences)==null?void 0:k.dataInputCardIds)||{}).map(E=>{var H,$,B;const b=($=(H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:$[E].cardId,F=(B=f==null?void 0:f.cards)==null?void 0:B.find(D=>D.id===b);if(F)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:j,dataInputIndex:E,card:F},F.id+E)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(h,{theme:u,onDataChange:j,settings:g.map(E=>{var b;return(b=E==null?void 0:E.customCardPreferences)==null?void 0:b.settings}),data:g.map(E=>E!=null&&E.id?r==null?void 0:r[E.id]:[])})})]})]},(O=s.customCardPreferences)==null?void 0:O.componentName)})}function Ft({className:s,...a}){var S;const n=t.useEditorStore(g=>g.card),r=((S=n.customCardPreferences)==null?void 0:S.showCardHeader)??!0,o=t.useEditorStore(g=>g.frame),l=t.useDashboardStore(g=>g.dashboard.filters);t.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:i}=t.useDashboardActions(),c=l==null?void 0:l.find(g=>g.id===o.filterId),{data:u,isLoading:p,isFetching:m}=t.useDashboardCardQuery(n),{setCard:f}=t.useEditorActions(),{data:x}=t.useTopoJson(n),d=I.useMemo(()=>!n.id||!(u!=null&&u.records)?null:t.createChartConfig({data:u==null?void 0:u.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:x}),[n.id,u==null?void 0:u.records,n.type,n.customCfg,n.preferences,x]);function j(g){return e.jsx(bn,{card:g})}function h(){if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!p&&!m)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(t.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(!n.id)return null;if(n.type==="custom")return j(n);if(!["table","custom"].includes(n.type)&&d)return e.jsx(e.Fragment,{children:p||m?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:d})});if(n.type==="table"&&(u!=null&&u.records)&&(u==null?void 0:u.records.length)>0)return e.jsxs(t.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(t.TableVisual,{card:n,data:u==null?void 0:u.records}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",s),...a,children:[r&&e.jsxs(t.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(t.Editable,{text:n.title,onSave:g=>f({...n,title:g}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(t.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsx(t.Editable,{text:n.description||"",onSave:g=>f({...n,description:g}),children:e.jsx(t.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),c&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{className:"my-1",text:c.title||c.column,onSave:g=>i({...c,title:g}),children:e.jsx(t.Label,{children:c.title})}),e.jsx(t.FilterComponent,{filter:c})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:h()})]})}const Ie=({language:s,value:a,onChange:n,readonly:r})=>e.jsx(t.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:s,value:a,onChange:n}),yn=()=>e.jsxs(t.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(t.DialogTitle,{children:"Customize Card"})}),e.jsxs(t.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),Sn=({customCode:s,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{language:"json",value:n,onChange:r})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ie,{language:"javascript",value:s,onChange:o})})]}),Cn=({error:s,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(t.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:o,variant:"outline",children:"Close"})]});function vn(){const[s,a]=I.useState(!1),[n,r]=I.useState(""),[o,l]=I.useState(""),[i,c]=I.useState(""),[u,p]=I.useState(""),m=t.useEditorStore(C=>C.card),f=t.useEditorStore(C=>C.card.customCfg),x=f?JSON.stringify(f,null,2):"",{data:d}=t.useDashboardCardQuery(m),{data:j}=t.useTopoJson(m),{setCardCustomCfg:h,setCustomVisualCode:S}=t.useEditorActions(),g=C=>{var L,q;return JSON.stringify({...C,data:{...C.data,datasets:(q=(L=C.data)==null?void 0:L.datasets)==null?void 0:q.map(_=>({..._,data:[]}))}},null,2)},T=()=>{var L,q;if(!((L=d==null?void 0:d.records)!=null&&L.length))return;const C=t.createChartConfig({data:d.records,cardType:m.type,preferences:m.preferences,topoJson:j});if(C){r(g(C)),c(((q=m.preferences)==null?void 0:q.customVisualCode)||"");const _=t.merge(C,f);l(g(_))}},N=()=>{try{if(i&&S(i),o){const C=JSON.parse(o),L=t.getObjectDiff(JSON.parse(n),C);h(L),p("")}}catch{p("Invalid JSON configuration")}},A=Object.keys(f||{}).length===0;return e.jsxs(t.Dialog,{open:s,onOpenChange:a,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Customize Visual",onClick:T,className:A?"":"text-green-600 hover:text-green-700",children:e.jsx(t.Settings,{className:"h-4 w-4"})})}),e.jsxs(t.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(yn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Ft,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Sn,{customCode:i,cardCustomCfgString:x,mergedConfig:o,onConfigChange:C=>l(C??""),onCodeChange:C=>c(C??"")})]}),e.jsx(Cn,{error:u,hasCardCustomConfig:!!f,onReset:()=>{l(n),h(null)},onApply:N,onClose:()=>a(!1)})]})]})}function Rt(s){const[a,n]=I.useState(null);return a}function Vt(){const{authToken:s}=t.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=t.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>t.getPlugins(s==null?void 0:s.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function Nn({onChartTypeChange:s}){const[a,n]=I.useState([]),{data:r}=Vt();return I.useEffect(()=>{(async()=>{var l;if(r){const c=(await Promise.all((l=r==null?void 0:r.plugins)==null?void 0:l.map(async u=>(await t.loadManifest(u.value)).visuals.map(f=>({name:f.name,icon:f.icon,url:u.value}))))).flat();n(c)}})()},[r]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((o,l)=>e.jsx(wn,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+l))})]})}const wn=({text:s,icon:a,onClick:n})=>{const r=Rt(),o=s.charAt(0).toUpperCase();return e.jsx(t.IconButton,{onClick:n,tooltip:s,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function _t(s){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function kn(s){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(s)}function qt(s){return ue({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Bt(s){return ue({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function Pt(s){return ue({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function Ht({onChartTypeChange:s}){const{setCardType:a,setCardPreferences:n,setChartOrientation:r}=t.useEditorStore(c=>c.actions),{setCardCustomCfg:o,setCustomCardPreferences:l}=t.useEditorActions();function i(c,u){o(null),n({}),a(c),s==null||s()}return e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(t.IconButton,{tooltip:"Bar Chart",onClick:()=>i("bar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Line Chart",onClick:()=>i("line"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>i("stackedBar"),className:"h-10 p-4",children:e.jsx(rt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>i("stackedLine"),className:"h-10 p-4",children:e.jsx(Bt,{className:"size-5",strokeWidth:0})}),e.jsx(t.IconButton,{tooltip:"Scatter Chart",onClick:()=>i("scatter"),className:"h-10 p-4",children:e.jsx(lt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Bubble Chart",onClick:()=>i("bubble"),className:"h-10 p-4",children:e.jsx(qt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Pie Chart",onClick:()=>i("pie"),className:"h-10 p-4",children:e.jsx(it,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Doughnut Chart",onClick:()=>i("doughnut"),className:"h-10 p-4",children:e.jsx(dt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Radar Chart",onClick:()=>i("radar"),className:"h-10 p-4",children:e.jsx(xt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Polar Area Chart",onClick:()=>i("polarArea"),className:"h-10 p-4",children:e.jsx(_t,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Pyramid Chart",onClick:()=>i("pyramid"),className:"h-10 p-4",children:e.jsx(bt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>i("range"),className:"h-10 p-4",children:e.jsx(ot,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Table",onClick:()=>i("table"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"KPI",onClick:()=>i("kpi"),className:"h-10 p-4",children:e.jsx(Pt,{className:"size-6"})}),e.jsx(t.IconButton,{tooltip:"Text",onClick:()=>i("text"),className:"h-10 p-4",children:e.jsx(is,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>i("map"),className:"h-10 p-4",children:e.jsx(pt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Custom",onClick:()=>i("custom"),className:"h-10 p-4",children:e.jsx(gt,{className:"size-5"})})]})}function In({chartType:s,className:a,customIcon:n,componentName:r}){const o=Rt();switch(s){case"bar":return e.jsx(Be,{className:a});case"line":return e.jsx(Pe,{className:a});case"pie":return e.jsx(it,{className:a});case"radar":return e.jsx(xt,{className:a});case"scatter":return e.jsx(lt,{className:a});case"bubble":return e.jsx(qt,{className:a});case"doughnut":return e.jsx(dt,{className:a});case"stackedBar":return e.jsx(rt,{className:a});case"stackedLine":return e.jsx(Bt,{className:a});case"polarArea":return e.jsx(_t,{className:a});case"pyramid":return e.jsx(bt,{className:a});case"range":return e.jsx(ot,{className:a});case"kpi":return e.jsx(Pt,{className:a});case"text":return e.jsx(yt,{className:a});case"map":return e.jsx(pt,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(gt,{className:a});default:return e.jsx(He,{className:a})}}function Dn(){var i,c;const[s,a]=I.useState(!1),n=t.useEditorStore(u=>u.card),r=n.type,o=t.useDashboardStore(u=>u.isVisualEditing);function l(){a(!1)}return e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(In,{className:"size-4",chartType:r,customIcon:(i=n.customCardPreferences)==null?void 0:i.icon,componentName:(c=n.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:u=>u.preventDefault(),className:"w-50",children:[e.jsx(Ht,{onChartTypeChange:l}),e.jsx(Nn,{onChartTypeChange:l})]})]})}const pe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function nt(s,a){var r,o,l;const n=t.getNumberAxis(s,a);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:l.type)||"linear"}function En(){var F,H,$,B,D,y;const[s,a]=I.useState(!1),n=t.useEditorStore(w=>{var M;return(M=w.card)==null?void 0:M.preferences}),r=t.getNumberAxis(n,{}),[o,l]=I.useState(nt(n)),[i,c]=I.useState((($=(H=(F=n==null?void 0:n.chartOptions)==null?void 0:F.scales)==null?void 0:H[r])==null?void 0:$.min)||""),[u,p]=I.useState(((y=(D=(B=n==null?void 0:n.chartOptions)==null?void 0:B.scales)==null?void 0:D[r])==null?void 0:y.max)||""),[m,f]=I.useState(i||u?"custom":"auto"),[x,d]=I.useState(""),[j,h]=I.useState(0),[S,g]=I.useState(""),[T,N]=I.useState(""),[A,C]=I.useState(""),L=t.useEditorStore(w=>w.actions.setCardPreferences),{updateCardInFrame:q}=t.useEditorActions(),_=t.useEditorStore(w=>w.card),U=t.useEditorStore(w=>{var M;return(M=w.card)==null?void 0:M.type}),v=["pie","doughnut","polarArea"].includes(U);I.useEffect(()=>{var w,M,z,G,P,K,W,ee,te,R,Q,Y,ne,ie;l(nt(n)),c(((z=(M=(w=n==null?void 0:n.chartOptions)==null?void 0:w.scales)==null?void 0:M[r])==null?void 0:z.min)===0?0:""),p(((K=(P=(G=n==null?void 0:n.chartOptions)==null?void 0:G.scales)==null?void 0:P[r])==null?void 0:K.max)||""),d(((R=(te=(ee=(W=n==null?void 0:n.chartOptions)==null?void 0:W.scales)==null?void 0:ee[r])==null?void 0:te.ticks)==null?void 0:R.stepSize)||""),h(((Q=n==null?void 0:n.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),g(((Y=n==null?void 0:n.numberAxisFormat)==null?void 0:Y.suffix)||""),N(((ne=n==null?void 0:n.numberAxisFormat)==null?void 0:ne.currency)||""),C(((ie=n==null?void 0:n.numberAxisFormat)==null?void 0:ie.locale)||"")},[s,n,r]);function k(w,M){return M===""||/^[0-9\b]+$/.test(M)?Number(M):Number(w)}function O(){const w=[...new Set(t.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(t.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(t.Select,{value:T||"none",onValueChange:M=>N(M==="none"?"":M),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),w.map(M=>e.jsx(t.SelectItem,{value:M,children:M},M))]})})]}),e.jsxs(t.Select,{value:A,onValueChange:M=>C(M),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Locale"}),t.LOCALE_CURRENCY_PAIRS.map(M=>e.jsx(t.SelectItem,{value:M.locale,children:M.locale},M.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(t.Input,{value:j,onChange:M=>h(Number(M.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${pe}`})]})]})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"range",children:"Range"}),e.jsx(t.Input,{id:"min",value:i,onChange:w=>c(M=>k(M,w.target.value)),className:`col-span-1 h-8 w-full ${pe}`}),e.jsx(t.Input,{value:u,onChange:w=>p(M=>k(M,w.target.value)),id:"max",className:`col-span-1 h-8 w-full ${pe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(t.Input,{value:x,onChange:w=>d(M=>k(M,w.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${pe}`})]})]})}function b(){var G;let w={};m==="custom"&&(w={min:i,max:u,ticks:{stepSize:x}});const M={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(G=n==null?void 0:n.chartOptions)==null?void 0:G.scales,[r]:{type:o,...o==="linear"?w:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:S,currency:T,locale:A}};console.log(M),L(M);const z={..._,preferences:M};q(z)}return e.jsxs(t.Popover,{onOpenChange:w=>a(w),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Scale Options",children:e.jsx(Rs,{className:"size-4 rotate-45"})})}),e.jsx(t.PopoverContentCustom,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(t.Select,{disabled:v,value:o,onValueChange:w=>l(w),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{id:"type",children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Option"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(t.RadioGroup,{disabled:v,id:"scale-option",value:m,onValueChange:w=>f(w),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),m==="custom"&&o=="linear"&&E(),O(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:b,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Tn(){const s=t.useEditorStore(c=>{var u,p,m,f;return(f=(m=(p=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:m.legend)==null?void 0:f.position}),a=t.useEditorStore(c=>{var u,p,m,f;return(f=(m=(p=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:m.legend)==null?void 0:f.align}),n=t.useEditorStore(c=>{var u,p,m,f;return(f=(m=(p=(u=c.card.preferences)==null?void 0:u.chartOptions)==null?void 0:p.plugins)==null?void 0:m.legend)==null?void 0:f.display}),{setLegendOptions:r}=t.useEditorActions(),o=c=>{r({display:c,position:s,align:a})},l=c=>{r({display:n,position:c,align:a})},i=c=>{r({display:n,position:s,align:c})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(ws,{className:"size-4"})})}),e.jsx(t.PopoverContentCustom,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(t.SmallSwitch,{checked:n,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Top",onClick:()=>l("top"),children:e.jsx(t.ArrowUp,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Left",onClick:()=>l("left"),children:e.jsx(ss,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>l("bottom"),children:e.jsx(es,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>l("right"),children:e.jsx(ns,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Start",onClick:()=>i("start"),children:e.jsx(Yt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Wt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(Xt,{className:"size-4"})})]})]})]})]})})]})}function An(){var l;const s=t.useEditorStore(i=>i.card.preferences),{setCardPreferences:a,setChartOrientation:n}=t.useEditorStore(i=>i.actions);function r(i){n(i)}const o=((l=s==null?void 0:s.chartOptions)==null?void 0:l.indexAxis)||"x";return e.jsx(t.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(Ls,{className:"size-4"}):e.jsx(Ms,{className:"size-4"})})}function Mn(){const s=t.useEditorStore(i=>i.card),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>{var c,u;return(u=(c=i.card)==null?void 0:c.preferences)==null?void 0:u.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:o}=t.useEditorActions();function l(){const i=["xy","none","x","y"],u=(i.indexOf(r)+1)%i.length;o(i[u])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(s.type)&&e.jsx(An,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(En,{}),e.jsx(Tn,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(s.type)&&e.jsxs(t.IconButton,{tooltip:"Grid Style",onClick:l,children:[(r==="xy"||!r)&&e.jsx(Cs,{className:"size-4"}),r==="x"&&e.jsx(hs,{className:"size-4"}),r==="y"&&e.jsx(Fs,{className:"size-4"}),r==="none"&&e.jsx(qs,{className:"size-4"})]})]}):null}function xe(){var B;const s=t.useEditorStore(D=>D.frame),a=t.useEditorStore(D=>D.card),n=t.useEditorStore(D=>D.isDevMode),r=t.useEditorStore(D=>D.isShowingVisual),o=t.useDashboardStore(D=>D.isVisualEditing),l=t.useEditorStore(D=>D.isSqlRunning),i=t.useEditorStore(D=>D.pythonStdOut),c=t.useEditorStore(D=>{var y;return(y=D.card.preferences)==null?void 0:y.chartOptions}),u=t.useEditorStore(D=>D.actions.setRunSql);t.getChartGridStyle(c);const{setFrame:p,setCard:m,updateCardInFrame:f,setActiveTabCardId:x,runAssistant:d,setChartGrid:j}=t.useEditorActions(),{data:h,isLoading:S,isFetching:g,error:T}=t.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function N(){const D={connectionId:a.connectionId,lastSelectedDatabase:a.lastSelectedDatabase,lastSelectedSchema:a.lastSelectedSchema,lastSelectedTable:a.lastSelectedTable,lastSelectedDatamodelId:a.lastSelectedDatamodelId,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};A(D)}function A(D){const y={...s,cards:[...s.cards,D],activeCardId:D.id};p(y),m(D),x(D.id)}function C(){const D={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};A(D)}function L(D){const y=s.cards.filter(z=>z.id!==D),w=y[0],M={...s,cards:y,activeCardId:w.id};p(M),x(w.id),m(w)}function q(D){n||_(D),x(D)}function _(D){const y={...s,cards:s.cards.map(M=>M.id===a.id?a:M),activeCardId:D};p(y);const w=y.cards.find(M=>M.id===D);w.sql&&u(!0),m(w)}const U=(D,y)=>{console.log("handleDragStart",y),D.dataTransfer.setData("tabIndex",y.toString())},v=D=>{D.preventDefault()},k=(D,y)=>{const w=D.dataTransfer.getData("tabIndex");if(w===y.toString())return;const M=Array.from(s.cards),[z]=M.splice(parseInt(w),1);M.splice(y,0,z),p({...s,cards:M})};function O(D,y){return D.cards.length===1&&(y.displayTab===!0||y.displayTab===void 0)||D.activeCardId!==y.id&&(y.displayTab===!0||y.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const w=y.displayTab===void 0?!1:!y.displayTab;m({...y,displayTab:w}),f({...y,displayTab:w})},children:y.displayTab===!0||y.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(js,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function E(){return e.jsxs(t.Tabs,{onValueChange:q,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(D=>e.jsx(t.TabsContent,{className:"mt-0 grow",value:D.id,children:b()},D.id)),e.jsx(t.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[s.cards.map((D,y)=>e.jsx(t.Editable,{text:D.tabTitle||D.title,onSave:w=>{m({...a,tabTitle:w}),f({...a,tabTitle:w})},children:e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:w=>U(w,y),onDragOver:v,onDrop:w=>k(w,y),className:"",value:D.id,children:[O(s,D),D.tabTitle||D.title,s.activeCardId===D.id&&s.cards.length>1&&e.jsx(t.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>L(D.id)})]})},D.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:N,children:e.jsx(t.Plus,{className:"h-4 w-4"})}),e.jsx(t.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:C,children:e.jsx(xs,{className:"h-4 w-4"})})]})})]})}function b(){return a.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.KPICard,{card:a,data:h==null?void 0:h.records})})}):a.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(t.TextCard,{isLoading:l,card:a,data:h==null?void 0:h.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(Ft,{className:"grow border-none shadow-none"})})}function F(){const D=JSON.stringify(h==null?void 0:h.records,null,2),y=new Blob([D],{type:"application/json"}),w=URL.createObjectURL(y),M=document.createElement("a");M.href=w,M.download=`${a.title}.json`,M.click()}function H(){const y=[Object.keys(h==null?void 0:h.records.reduce((G,P)=>({...G,...P}),{})).join(","),...((h==null?void 0:h.records)||[]).map(G=>Object.values(G).join(","))].join(`
352
- `),w=new Blob([y],{type:"text/csv"}),M=URL.createObjectURL(w),z=document.createElement("a");z.href=M,z.download=`${a.title}.csv`,z.click()}function $(){const D=`Can you get the documentation for ${a.type} chart?`;d(D)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(S||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(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Dn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:$,children:e.jsx(os,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(vn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:H,children:e.jsx(kn,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:F,children:e.jsx(bs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(h==null?void 0:h.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Mn,{}),e.jsx(On,{})]}),r?E():e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(Ln,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(h==null?void 0:h.records)&&(h==null?void 0:h.records.length)>0&&e.jsx(jn,{data:(h==null?void 0:h.records)||[]}),(T||(h==null?void 0:h.error))&&e.jsx("span",{className:"font-mono text-xs",children:(T==null?void 0:T.message)||((B=h==null?void 0:h.error)==null?void 0:B.message)})]})]})]})}function Ln(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(t.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function On(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function zn(){var h,S;const s=t.useEditorStore(g=>g.card.customCardPreferences),{data:a}=Vt(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(g=>g.card),o=t.useEditorStore(g=>g.frame),l=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:c,manifest:u}=t.useCustomVisual((s==null?void 0:s.url)||""),p=(h=u==null?void 0:u.visuals)==null?void 0:h.find(g=>g.name===(s==null?void 0:s.componentName));function m(g,T){if(!s)return;const A={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:T,hookRef:null}};i({...s,dataInputCardIds:A})}function f(g){var N,A;const T=(N=o==null?void 0:o.cards)==null?void 0:N.filter(C=>{var L;return((L=C==null?void 0:C.customCardPreferences)==null?void 0:L.visualType)!=="multiple"}).map(C=>({value:C.id,label:C.tabTitle||C.title}));return e.jsx("div",{className:"space-y-2",children:(A=g==null?void 0:g.dataInputs)==null?void 0:A.map((C,L)=>{var q,_;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:C}),e.jsx(X,{className:"col-span-6 h-8 w-full justify-between",label:"",options:T||[],value:((_=(q=s==null?void 0:s.dataInputCardIds)==null?void 0:q[L])==null?void 0:_.cardId)||"",onValueChange:U=>m(L,U)})]},L+Math.random())})})}function x(g,T,N=[],A=""){var C,L;return s?g==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((C=s==null?void 0:s.settings)==null?void 0:C[T])||A,onChange:q=>{i({...s,settings:{...s==null?void 0:s.settings,[T]:q.target.value}})}},T):g==="select"?e.jsx(X,{className:"h-8 w-full",label:"",options:N,value:((L=s==null?void 0:s.settings)==null?void 0:L[T])||A,onValueChange:q=>{i({...s,settings:{...s==null?void 0:s.settings,[T]:q}})}}):null:null}function d(g){const T=Object.entries((g==null?void 0:g.settings)||{});return e.jsx("div",{className:"space-y-3",children:T.map(([N,A])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:A.title}),x(A.ui,N,A.options,A.defaultValue)]},N))})}function j(g){s&&i({...s,visualType:g,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{icon:e.jsx(rs,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:g=>i({...s||{url:"",componentName:""},url:g})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:l,onValueChange:j,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:c&&e.jsx(X,{icon:e.jsx(ps,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(c==null?void 0:c.filter(g=>g.type===l).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),i({...s,componentName:g})}})})]})})]}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:f(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:d(p)})})]})]})]})}function oe(){const[s,a]=I.useState([]),n=t.useEditorStore(p=>p.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(p=>p.actions),l=t.useEditorStore(p=>p.queryResultColumns);t.useEditorStore(p=>{var m;return(m=p.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),I.useEffect(()=>{l&&a(new Array(l.length).fill(!1))},[l]);function i(p,m){var f,x;m?n!=null&&n.onClickFilter&&((f=n==null?void 0:n.onClickFilter)==null?void 0:f.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:p,expression:""}]}):o({...n,onClickFilter:[{columnIndex:p,expression:""}]}):(o({...n,onClickFilter:(x=n==null?void 0:n.onClickFilter)==null?void 0:x.filter(d=>d.columnIndex!==p)}),a(d=>{const j=[...d];return j[p]=!1,j}))}function c(p,m){var x;const f=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.map(d=>d.columnIndex===p?{...d,expression:m.target.value}:d);o({...n,onClickFilter:f})}function u(p){var m,f,x,d;if(s!=null&&s[p]||(f=(m=n==null?void 0:n.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===p))!=null&&f.expression)return e.jsx(t.Input,{value:(d=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(j=>j.columnIndex===p))==null?void 0:d.expression,onChange:j=>c(p,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),l==null?void 0:l.map((p,m)=>{var f,x;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(t.Checkbox,{checked:!!((f=n==null?void 0:n.onClickFilter)!=null&&f.find(d=>d.columnIndex===m)),onCheckedChange:d=>i(m,d)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:p}),e.jsx("div",{className:"flex items-center gap-2",children:((x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(d=>d.columnIndex===m))&&e.jsx(t.Pencil,{onClick:()=>{a(d=>{const j=[...d];return j[m]=!d[m],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(m)]})},p)})]})}function Fn({idx:s}){var c;const a=t.useEditorStore(u=>{var p;return(p=u.card)==null?void 0:p.preferences}),n=t.useEditorStore(u=>{var p;return(p=u.card.preferences)==null?void 0:p.datasetOptions}),r=t.useEditorStore(u=>u.actions.setCardPreferences),o=(c=a==null?void 0:a.chartOptions)==null?void 0:c.indexAxis,l=n==null?void 0:n.find(u=>u.idx===s);function i(u,p){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const m={display:u!=="none",align:u,anchor:u,clamp:!0};if(!l)r({...a,datasetOptions:[...n||[],{idx:p,datalabels:m}]});else{const f={...l};f.datalabels=m;const x=n==null?void 0:n.map(d=>d.idx===p?f:d);r({...a,datasetOptions:x})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Bs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(t.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-4"})}),e.jsx(t.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(ks,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ds,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Is,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Gt(){const s=t.useEditorStore(p=>p.card),a=t.useEditorStore(p=>{var m,f,x;return(x=(f=(m=p==null?void 0:p.card)==null?void 0:m.preferences)==null?void 0:f.chartOptions)==null?void 0:x.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:l,metricKeys:i,dimensionKeys:c}=t.getKeys((n==null?void 0:n.records)||[]);let u=i;if(["stackedBar","stackedLine"].includes(s.type)){const p=t.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:u[0]}),{metricKeys:m}=t.getKeys(p);u=m}return l.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:c.map(p=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:p,children:Ut(p)},p))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((p,m)=>e.jsx(Rn,{col:p,idx:m},p))})]})]})}function Ut(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function Rn({col:s,idx:a}){const n=t.useEditorStore(c=>{var u;return(u=c.card)==null?void 0:u.preferences}),r=t.useEditorStore(c=>{var u;return(u=c.card.preferences)==null?void 0:u.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===a),{setCardPreferences:l}=t.useEditorStore(c=>c.actions);function i(c){if(!o)l({...n,datasetOptions:[...r||[],{idx:a,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const u={...o};u.type=c==="area"?"line":c,u.fill=c==="area"?"origin":"";const p=r==null?void 0:r.map(m=>m.idx===a?u:m);l({...n,datasetOptions:p})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:s,children:Ut(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Be,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Pe,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ds,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Fn,{idx:a})]})]})}function $t(){const s=t.useEditorStore(d=>d.selectedConnectionId),a=t.useEditorStore(d=>d.selectedDatamodelId),n=t.useEditorStore(d=>d.selectedDatabaseName),r=t.useEditorStore(d=>d.selectedSchemaName),o=t.useEditorStore(d=>d.selectedTableName),l=t.useDashboardStore(d=>d.dashboard.filters)||[],i=t.useDashboardStore(d=>d.actions.addFilter),c=t.useDashboardStore(d=>d.actions.removeFilter),{removeFilterValues:u}=t.useDashboardActions(),{modelItems:p,tableName:m,connectionType:f}=Z();function x(d,j="dashboard"){var q;const h=t.fmt(d.column_name),S=t.fmt(n||""),g=t.fmt(r||""),T=t.fmt(m);let N=t.getQualifiedTableName({schemaName:g,tableName:T,connectionType:f,databaseName:S}),A=`${N}.${h}`;const C=(q=p==null?void 0:p.find(_=>_.id===a))==null?void 0:q.name;a&&a!=="none"&&(A=`${t.DATAMODEL_NAMESPCACE}.${C}.${h}`,N=`${t.DATAMODEL_NAMESPCACE}.${C}`);const L=l==null?void 0:l.find(_=>_.column===A&&_.table===T&&(_.database===S||_.database===n));if(L)u(L.id),c(L.id);else{const _=t.v4();return m==="api"&&s?(i({location:j,id:_,column:A,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(d.data_type,N,h)}),_):(i({id:_,location:j,column:A,title:d.column_name,dataType:d.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(d.data_type,N,h)}),_)}}return{assignFilter:x}}function me(){const s=t.useDashboardStore(c=>c.dashboard.filters),a=t.useEditorStore(c=>c.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=Z(),{assignFilter:o}=$t();function l(c){const u=o(c,"frame");n({...a,filterId:u})}const i=s==null?void 0:s.find(c=>c.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Vn,{onSelect:l,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Vn({columns:s,onSelect:a}){var i;const[n,r]=de.useState(!1),[o,l]=de.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=s.find(c=>c.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(c=>e.jsxs(t.CommandItem,{value:c.column_name,onSelect:u=>{const p=u===o?"":u;l(p),r(!1),p&&a(c)},children:[c.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function _n({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Gt,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function $e(){var o,l,i;const s=t.useEditorStore(c=>c.card.type),a=t.useEditorStore(c=>c.card.preferences),{setCardPreferences:n}=t.useEditorStore(c=>c.actions);function r(c){var m;const u={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},p={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.chartOptions)==null?void 0:m.plugins,...u}}};n(p),console.log(c)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((i=(l=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function qn({cardType:s}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx($e,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}const Bn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Pn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Hn(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Gn(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{}),e.jsx(oe,{}),e.jsx(me,{})]})]})}function Gn(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Bn,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Pn,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Un(){var u,p,m,f,x;const s=t.useEditorStore(d=>d.card.preferences),a=t.useEditorStore(d=>d.actions.setCardPreferences),n=t.useEditorStore(d=>d.actions.setNumberFormat);t.useEditorStore(d=>{var j,h;return(h=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:h.decimalPlaces});const r=t.useEditorStore(d=>{var j,h;return(h=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:h.locale}),o=t.useEditorStore(d=>{var j,h;return(h=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:h.currency});t.useEditorStore(d=>d.actions.setFilterOnClickField);const l=t.useEditorStore(d=>{var j,h;return(h=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:h.colorRanges})||[],i=t.useEditorStore(d=>d.actions.setColorRanges),c=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((u=s==null?void 0:s.formatNumber)!=null&&u.enabled),onCheckedChange:d=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((p=s==null?void 0:s.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:d=>{var j,h,S;return n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",d,((S=s==null?void 0:s.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(d=>e.jsx(t.SelectItem,{value:d.locale,children:d.locale},d.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:o||"none",onValueChange:d=>{var j,h,S;console.log("currency",d),n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,d==="none"?"":d,((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((S=s==null?void 0:s.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),c.map(d=>e.jsx(t.SelectItem,{value:d,children:d},d))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((f=(m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:d=>{var j,h,S;return n(Number(d),((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((h=s==null?void 0:s.formatNumber)==null?void 0:h.locale)||"",((S=s==null?void 0:s.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(d=>e.jsx(t.SelectItem,{value:d,children:d},d))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((x=s==null?void 0:s.formatNumber)==null?void 0:x.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:d=>{var j,h,S;return n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((h=s==null?void 0:s.formatNumber)==null?void 0:h.currency)||"",((S=s==null?void 0:s.formatNumber)==null?void 0:S.locale)||"",d.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function $n(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Un,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function De({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Qn=[{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"}],Jn=["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"],Kn=Jn.map(s=>({label:s,value:s}));function Wn(){var u,p,m,f,x,d,j,h,S,g,T,N,A,C,L,q,_,U;const s=t.useEditorStore(v=>v.card),a=(p=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:p.topoJsonUrl,[n,r]=I.useState(((f=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=t.useEditorActions(),{data:l}=t.useTopoJson(s),i=Object.keys((l==null?void 0:l.objects)||{}).map(v=>({label:v,value:v}))||[],c=[{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(De,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(X,{className:"h-9",options:c,onValueChange:v=>{console.log("value",v),o({...s.preferences,mapVisualOptions:{topoJsonUrl:v}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:v=>{r(v.target.value)},onBlur:()=>{var v;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(v=s.preferences)==null?void 0:v.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(X,{className:"h-9",options:i,value:((d=(x=s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:v=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,objectKey:v}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(X,{className:"h-9",options:Qn,value:((h=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:h.projection)||"",label:"Projection",onValueChange:v=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projection:v}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(X,{className:"h-9",options:Kn,value:((g=(S=s.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:v=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,colorScale:v}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((N=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:N.projectionScale)||1,onChange:v=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionScale:Number(v.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((L=(C=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:C.projectionOffset)==null?void 0:L[0])||0,onChange:v=>{var k,O,E,b;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionOffset:[Number(v.target.value),((b=(E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:b[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((U=(_=(q=s.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:_.projectionOffset)==null?void 0:U[1])||0,onChange:v=>{var k,O,E,b;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionOffset:[((b=(E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:b[0])||0,Number(v.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function Yn(){var r;const s=t.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=t.useEditorStore(o=>o.actions);function n(o){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function fe({cardType:s,docContent:a,suffix:n="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx($e,{}),s==="text"&&e.jsx(Yn,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Xn(){const s=t.useEditorStore(r=>{var o,l;return(l=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:l.sortChart}),{setSortChart:a}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(X,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(Gt,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})]})})}function Zn({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(o=>{var l;return(l=o.card)==null?void 0:l.preferences}),n=t.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(me,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const ea=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),ta=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),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:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function na(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Xn,{});case"pyramid":return e.jsx(fe,{docContent:ea,cardType:n});case"kpi":return e.jsx($n,{});case"line":case"bar":return e.jsx(_n,{cardType:n});case"range":return e.jsx(fe,{docContent:ta,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(fe,{cardType:n});case"bubble":case"scatter":return e.jsx(qn,{cardType:n});case"table":return e.jsx(Zn,{cardType:n});case"text":return e.jsx(fe,{docContent:sa,cardType:n,suffix:"Visual"});case"map":return e.jsx(Wn,{});case"custom":return e.jsx(zn,{});default:return e.jsx(Hn,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Ee={id:"__placeholder__",role:"groupby",type:"string"},Te={id:"__placeholder__",role:"metric",type:"number"},Ae={id:"__placeholder__",role:"trendby",type:"date"},Me={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},Qt={id:"__placeholder__"},ye="droppable-group-by",Se="droppable-metrics",ze="sortable-group-by",Fe="sortable-metrics",Re="droppable-trend-by",Ve="sortable-trend-by",_e="droppable-filters",qe="sortable-filters";function aa(){const s=t.useDndStore(k=>k.insertIndex),a=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.groupByColumns)||[]}),n=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.metricColumns)||[]}),r=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.trendByColumns)||[]}),o=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.filterColumns)||[]}),{setInsertIndex:l,setActiveId:i,setPreviewGroupByColumns:c,setPreviewMetricColumns:u,setPreviewTrendByColumns:p,setPreviewFilterColumns:m}=t.useDndActions(),{setGroupByColumns:f,setMetricColumns:x,setTrendByColumns:d,setFilterColumns:j}=t.useEditorActions(),{columns:h}=kt(),{formattedTableName:S}=Z(),g=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),T=k=>{var b;const{active:O,over:E}=k;if(((b=O.data.current)==null?void 0:b.type)==="column"&&E){const F=E.id,H=h.find(y=>y.column_name===O.id);if(!H)return;const $=t.isNumberDataType(H.data_type),B=t.isTextDataType(H.data_type),D=t.isDateDataType(H.data_type);if(B){if(a.some(w=>w.id===F)){const w=a.findIndex(z=>z.id===F);l(w);const M=a.filter(z=>z.id!==Ee.id);M.splice(w,0,Ee),c(M)}else if(E.id===ye){l(a.length);const w=[...a,Ee];c(w),u(n),p(r),m(o)}}if($||B){if(n.some(w=>w.id===F)){console.log("isOverMetricSortable",F);const w=n.findIndex(z=>z.id===F);l(w);const M=n.filter(z=>z.id!==Te.id);M.splice(w,0,Te),u(M)}else if(E.id===Se){l(n.length);const w=[...n,Te];u(w),p(r),m(o),c(a)}}if(D){if(r.some(w=>w.id===F)){const w=r.findIndex(z=>z.id===F);l(w);const M=r.filter(z=>z.id!==Ae.id);M.splice(w,0,Ae),p(M)}else if(E.id===Re){l(r.length);const w=[...r,Ae];p(w),u(n),m(o),c(a)}}if(A(H)){if(o.some(w=>w.id===F)){const w=o.findIndex(z=>z.id===F);l(w);const M=o.filter(z=>z.id!==Me.id);M.splice(w,0,Me),m(M)}else if(E.id===_e){l(o.length);const w=[...o,Me];m(w),u(n),p(r),c(a)}}}else c(a),u(n),p(r),m(o)};function N(k){i(k.active.id),l(null),c(a),u(n),p(r),m(o)}function A(k){return!o.some(O=>O.name===k.column_name)}function C(k,O="SUM"){const{column_name:E,data_type:b}=k,F=[...n],H=s!==null?s:n.length,$={...k,id:ae(E),name:E,label:ge(O,E),type:b,role:"metric",aggregate:O};F.splice(H,0,$),x(F)}function L(k){const O=[...a],E=s!==null?s:a.length,b={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,role:"groupby"};O.splice(E,0,b),f(O)}function q(k){const O=[...r],E=s!==null?s:r.length,b={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,role:"trendby"};O.splice(E,0,b),d(O)}function _(k){const O=[...o],E=s!==null?s:o.length,b={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,sql:t.getDefaultFilterSql(k.data_type,S,t.fmt(k.column_name)),role:"filter"};O.splice(E,0,b),j(O)}function U(k){var F,H,$,B,D,y,w,M;const{active:O,over:E}=k,b=O.data.current;if((b==null?void 0:b.type)==="column"&&E){const z=h.find(W=>W.column_name===O.id);if(!z)return;const G=t.isNumberDataType(z.data_type),P=t.isTextDataType(z.data_type),K=t.isDateDataType(z.data_type);P&&(E.id===ye||((F=E.data.current)==null?void 0:F.type)===ze)?L(z):(G||P)&&(E.id===Se||((H=E.data.current)==null?void 0:H.type)===Fe)?(G&&C(z),P&&C(z,"COUNT")):K&&(E.id===Re||(($=E.data.current)==null?void 0:$.type)===Ve)?q(z):A(z)&&(E.id===_e||((B=E.data.current)==null?void 0:B.type)===qe)&&_(z)}if(E&&((D=E.data.current)==null?void 0:D.type)===ze&&a.some(z=>z.id===O.id)){const z=a.findIndex(P=>P.id===O.id),G=a.findIndex(P=>P.id===E.id);if(z!==-1&&G!==-1&&z!==G){const P=[...a],[K]=P.splice(z,1);P.splice(G,0,K),f(P)}}if(E&&((y=E.data.current)==null?void 0:y.type)===Fe&&n.some(z=>z.id===O.id)){const z=n.findIndex(P=>P.id===O.id),G=n.findIndex(P=>P.id===E.id);if(z!==-1&&G!==-1&&z!==G){const P=[...n],[K]=P.splice(z,1);P.splice(G,0,K),x(P)}}if(E&&((w=E.data.current)==null?void 0:w.type)===Ve&&r.some(z=>z.id===O.id)){const z=r.findIndex(P=>P.id===O.id),G=r.findIndex(P=>P.id===E.id);if(z!==-1&&G!==-1&&z!==G){const P=[...r],[K]=P.splice(z,1);P.splice(G,0,K),d(P)}}if(E&&((M=E.data.current)==null?void 0:M.type)===qe&&o.some(z=>z.id===O.id)){const z=o.findIndex(P=>P.id===O.id),G=o.findIndex(P=>P.id===E.id);if(z!==-1&&G!==-1&&z!==G){const P=[...o],[K]=P.splice(z,1);P.splice(G,0,K),j(P)}}i(null),l(null),c(a),u(n),p(r),m(o)}function v(){i(null),l(null),c(a),u(n),p(r),m(o)}return{handleDragOver:T,handleDragEnd:U,handleDragStart:N,handleDragCancel:v,sensors:g}}const ce=[{label:"Sum",value:"SUM",logo:e.jsx(jt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(ht,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(ys,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(ts,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(Zt,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(as,{className:"size-3.5"})}];function ra({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,l]=I.useState(!1),[i,c]=I.useState(ce[0]),{attributes:u,listeners:p,setNodeRef:m,transform:f,transition:x,isDragging:d}=t.useSortable({id:s.id,data:{type:a}}),j=f?{opacity:d?.5:void 0,transform:t.CSS.Translate.toString(f),transition:x}:void 0;function h(){return e.jsx("div",{"data-setting-container":"",className:"h-32 rounded-b-md border-x border-b border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}return e.jsxs("div",{...p,...u,ref:m,style:j,children:[e.jsxs("div",{className:t.cn("group flex h-8 items-center rounded-t-md bg-muted px-2",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),r===Se&&e.jsx(ia,{column:s}),e.jsx("div",{className:t.cn("max-w-[250px] grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",{"pl-2":r===ye}),children:e.jsx(oa,{col:s})}),e.jsxs("div",{"data-setting-actions":"",className:"hidden h-full items-center gap-2 group-hover:flex",children:[e.jsx("button",{onClick:()=>l(!o),children:e.jsx(t.ChevronDown,{className:t.cn("ml-1 size-4 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground",o&&"rotate-180")})}),e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm bg-muted text-muted-foreground"})})]})]}),o&&h()]})}function oa({col:s}){return e.jsx(t.Editable,{text:s.label||s.name,className:"h-6 rounded-none",onSave:a=>{console.log("saved",a)},children:e.jsx("span",{className:"w-[250px] truncate text-ellipsis whitespace-nowrap text-sm",children:s.label||s.name})})}function ia({column:s}){const[a,n]=I.useState(ce[0]),{updateMetricColumn:r}=t.useEditorActions();let o=ce;t.isTextDataType(s.type)&&(o=o.filter(i=>["COUNT","DISTINCT"].includes(i.value))),t.isNumberDataType(s.type)&&(o=o.filter(i=>!["DISTINCT","COUNT"].includes(i.value))),I.useEffect(()=>{n(ce.find(i=>i.value===s.aggregate)||ce[0])},[s]);function l(i){const c=ce.find(p=>p.value===i);if(!c)return;n(c);const u={...s,aggregate:i,label:ge(i,s.name)};r(s.id,u)}return e.jsx(X,{className:"size-7 overflow-clip rounded-none rounded-l-md border-none bg-muted px-2",icon:a.logo,options:o,value:a.value,onValueChange:i=>l(i),label:"Aggregation"})}function Le({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:l}){const{setNodeRef:i}=t.useDroppable({id:s}),c=t.useDndStore(m=>m.activeId),u={},p=c?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(m=>m.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:i,style:u,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:p==null?void 0:p.map(m=>m.id===Qt.id?e.jsx(la,{},m.id):e.jsx(ra,{droppableId:s,type:o,column:m,onRemoveColumn:l},m.id))})]})})}function la(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function at(){const s=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.groupByColumns)||[]}),a=t.useDndStore(x=>x.previewGroupByColumns),n=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.metricColumns)||[]}),r=t.useDndStore(x=>x.previewMetricColumns),o=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.trendByColumns)||[]}),l=t.useDndStore(x=>x.previewTrendByColumns),{removeColumnFromGroupBy:i,removeColumnFromMetricColumns:c,removeColumnFromTrendByColumns:u}=t.useEditorActions();function p(x){i(x)}function m(x){u(x)}function f(x){c(x)}return e.jsxs("div",{className:"h-full w-full space-y-4 p-4",children:[e.jsx(Ht,{}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Le,{onRemoveColumn:p,sortableType:ze,id:ye,label:"Group By",columns:s,previewColumns:a}),e.jsx(Le,{onRemoveColumn:m,sortableType:Ve,id:Re,label:"Trend By",columns:o,previewColumns:l}),e.jsx(Le,{onRemoveColumn:f,sortableType:Fe,id:Se,label:"Metrics",columns:n,previewColumns:r})]})]})}function ca({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:l,transform:i,transition:c,isDragging:u}=t.useSortable({id:a,data:{type:n}}),p=i?{opacity:u?.5:void 0,transform:t.CSS.Translate.toString(i),transition:c}:void 0;return e.jsx("div",{...o,...r,ref:l,style:p,children:s})}function Qe({children:s,column:a,id:n,sortableType:r,className:o}){const[l,i]=I.useState(!1),{removeEditorFilter:c}=t.useEditorActions();function u(p){c(p)}return e.jsx(ca,{id:n,type:r,children:e.jsxs("div",{className:t.cn("group space-y-1 rounded-md border border-border px-3 py-2",{"border-border":l}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:a.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>u(a),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.cn("group flex items-center rounded-t-md text-sm",!l&&"rounded-b-md",l&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:t.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",o),children:s})]})]})})}function da({column:s,sortableType:a}){const n=t.useDashboardStore(T=>T.themeStyle),r=t.useEditorStore(T=>{var N,A;return(A=(N=T.card)==null?void 0:N.queryConfig)==null?void 0:A.filters}),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=Z(),c=I.useMemo(()=>{var T;return(T=r==null?void 0:r.find(N=>N.filterColumnName===s.name))==null?void 0:T.filterValue},[r,s.name]),u=I.useMemo(()=>Array.isArray(c)?c.map(T=>({id:T,value:T})):[],[c]),{updateEditorFilterValue:p}=t.useEditorActions(),m={column:s.name,sql:s.sql,id:s.name,connectionId:o,dataType:s.type},{data:f,isLoading:x,isFetching:d,isError:j}=t.useFilterQuery(m),h=I.useMemo(()=>{var N;return m.column?(N=f==null?void 0:f.records)==null?void 0:N.map(A=>{let C=m.column.split(".").slice(-1)[0].replace(/"/g,"");return A[C]===void 0&&(C=C.toLowerCase()),{id:A[C],value:A[C]}}):[]},[f,m.column]);function S(T){const N=T.map(A=>A.id);p(s.name,N)}function g(){return x||d?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):j?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(t.ComboBoxMultiSelect,{options:h,onChange:S,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Qe,{className:"w-60",id:s.id,sortableType:a,column:s,children:g()})}function ua({column:s,sortableType:a}){const[n,r]=I.useState(!1),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:i}=Z(),c={column:s.name,sql:s.sql,id:s.name,connectionId:o,title:"",dataType:s.type},{isLoading:u,isFetching:p,isError:m,data:f}=t.useFilterQuery(c),x=f==null?void 0:f.records,{dateRange:d,setDateRange:j,initialDateRange:h}=t.useDateRangeFromRecords(x),{updateEditorFilterValue:S}=t.useEditorActions();function g(A){var L,q;const C={gte:(L=A==null?void 0:A.from)==null?void 0:L.toISOString(),lte:(q=A==null?void 0:A.to)==null?void 0:q.toISOString()};S(s.name,C)}function T(){S(s.name,null,!0),j(h)}function N(){return u||p?e.jsx("div",{children:e.jsx(t.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):m?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):x?e.jsx(t.DateRangePopover,{title:c.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:d,setDateRange:j,onApply:g,onClear:T}):e.jsx(t.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Qe,{className:"w-72",id:s.id,sortableType:a,column:s,children:N()})}function ma({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:l}=t.useDroppable({id:s}),i=t.useDndStore(m=>m.activeId),c={};function u(m){const f=t.isDateDataType(m.type);return m.id===Qt.id?e.jsx(Qe,{id:m.id,sortableType:o,column:m,children:e.jsx(ha,{})},m.id):f?e.jsx(ua,{droppableId:s,sortableType:o,column:m},m.id):e.jsx(da,{droppableId:s,sortableType:o,column:m},m.id)}const p=i?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(m=>m.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:l,style:c,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:p==null?void 0:p.map(m=>u(m))})]})})}function ha(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function pa(){const s=t.useEditorStore(o=>{var l;return((l=o.card.queryConfig)==null?void 0:l.filterColumns)||[]}),a=t.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(o){n(o)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(ma,{onRemoveColumn:r,sortableType:qe,id:_e,label:"Filters",columns:s,previewColumns:a})})}function xa(){const s=t.useEditorStore(r=>r.card),{data:a,errorMessage:n}=t.useDashboardCardQuery(s);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(zt,{}),e.jsx(Dt,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium",children:"Early Preview"}),e.jsx(Ot,{}),e.jsx(Lt,{variant:"default"})]})]})}function fa(){const s=I.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);I.useEffect(()=>{var i,c;n?(i=s.current)==null||i.resize(0):(c=s.current)==null||c.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(gn,{})}),e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:r?e.jsx(na,{}):e.jsx(at,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(xe,{})})]}):e.jsx(xe,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(at,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(xa,{}),e.jsx(pa,{})]}),e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(xe,{})})]})})]}):e.jsx(xe,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():l()})}const ga=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function ja(){const s=I.useRef(null),a=I.useRef(null),[n,r]=I.useState(!1),[o,l]=I.useState(t.isDevEnv),[i,c]=I.useState(!1),u=t.useEditorStore(B=>B.actions.setCardSql),p=t.useEditorStore(B=>B.actions.setRunSql),m=t.useEditorStore(B=>B.showAIDialog),{setShowAIDialog:f}=t.useEditorActions(),{messages:x,setMessages:d,reload:j,append:h,input:S,setInput:g,isLoading:T,handleAddCurrentTableToScope:N,removeFromCurrentSelections:A,currentAssitantScope:C,handleInputChange:L,handleSubmit:q,stop:_,chatStatus:U,toolStatus:v,llmUsage:k,errorMessage:O}=Mt();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:x}),I.useEffect(()=>{var B;m&&((B=a.current)==null||B.focus())},[m]);function E(B){u(B),p(!0)}function b(B){const D={role:"user",content:B.title+" "+B.subtitle};h(D)}function F(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(ut,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:l,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:c,children:"System Message"})]})]})}function H(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),C&&C.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:C==null?void 0:C.map((B,D)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[t.getFormattedTableNameForQuery({schemaName:B.schemaName||"",tableName:B.tableName||"",modelName:B.datamodelName||"",connectionType:B.connectionType||"",databaseName:B.databaseName||""}),e.jsx("button",{onClick:()=>{A(B)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},D))}),(C==null?void 0:C.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(t.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:N,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const $=(S==null?void 0:S.length)===0&&(x==null?void 0:x.filter(B=>B.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:[H(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[F(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{d([]),j()},children:e.jsx(t.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(t.X,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(t.PrintMessages,{messages:x,showTools:o,handleRun:E,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(U,v),isLoading:T})]})}),$&&e.jsx(t.Placeholders,{onClick:b,placeholders:ga}),e.jsx(t.ChatInput,{onFocus:()=>{N()},stop:_,ref:a,setInput:g,input:S,handleInputChange:L,handleSubmit:q,isLoading:T}),k&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",k.promptTokens," prompt tokens,"," ",k.completionTokens," completion tokens,"," ",k.totalTokens," total tokens"]})}),O&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:O})})]})}function ba({authToken:s,onSave:a,onClose:n}){const r=I.useRef(null),o=t.useEditorStore(S=>S.showAIDialog),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:c,setOnClose:u}=t.useEditorActions(),{handleDragOver:p,handleDragEnd:m,handleDragStart:f,handleDragCancel:x,sensors:d}=aa();I.useEffect(()=>{a&&c(a),n&&u(n)},[a,c,n,u]),I.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),I.useEffect(()=>{var S,g;o?((S=r.current)==null||S.resize(40),i(!0)):(i(!1),(g=r.current)==null||g.resize(0))},[o,i]);function j(S){S<1?i(!1):o||i(!0)}function h(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(fa,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:j,defaultSize:0,children:e.jsx(ja,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:d,onDragStart:f,onDragEnd:m,onDragOver:p,onDragCancel:x,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(It,{type:"main"}),h()]})})})}function ya(){t.useDashboardStore(i=>i.selectedCardId);const s=t.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(i=>i.actions),n=t.useDashboardStore(i=>i.isVisualEditing),r=t.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),a(!1))}function l(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(ba,{onSave:o,onClose:l})})}function Sa(){const s=t.useEditorStore(l=>l.selectedDatabaseName),a=t.useEditorStore(l=>l.selectedTableName),n=t.useDashboardStore(l=>l.dashboard.filters)||[],{columns:r}=Z(),{assignFilter:o}=$t();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(l=>{const i=n==null?void 0:n.find(c=>c.column===t.fmt(l.column_name)&&c.table===a&&c.database===s);return e.jsx("div",{onClick:()=>o(l),className:t.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ue,{column:l}),e.jsx("span",{children:l.column_name})]})},l.column_name)})})}function Ca(){t.useDashboardStore(a=>a.showFilters);const s=t.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(It,{type:"filter",ColumnsComponent:()=>e.jsx(Sa,{})})})]})}function va(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function Na(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(va,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ca,{})})]})}function wa(){const s=t.useDashboardStore(o=>o.dashboard),a=t.useDashboardStore(o=>o.actions.setDashboard),n=t.useDashboardStore(o=>o.showDashboardJSON),r=t.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.de,{onChange:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function ka({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(wa,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(Ys,{}),e.jsx(ya,{}),e.jsx(Na,{})]})]})]})})}exports.Dashboard=t.Dashboard;exports.DashboardWC=t.DashboardWC;exports.SemaphorDataProvider=t.SemaphorQueryClient;exports.SemaphorQueryClient=t.SemaphorQueryClient;exports.createSqlGenConfig=t.createSqlGenConfig;exports.fmt=t.fmt;exports.getColumnDataType=t.getColumnDataType;exports.getFilterValueType=t.getFilterValueType;exports.getFormattedTableNameForQuery=t.getFormattedTableNameForQuery;exports.getQualifiedTableName=t.getQualifiedTableName;exports.getSql=t.getSql;exports.invalidateToken=t.invalidateToken;exports.isBooleanDataType=t.isBooleanDataType;exports.isColumnInSqlGen=t.isColumnInSqlGen;exports.isDateDataType=t.isDateDataType;exports.isNumberDataType=t.isNumberDataType;exports.isTextDataType=t.isTextDataType;exports.resolveDataType=t.resolveDataType;exports.resolveDatamodelName=t.resolveDatamodelName;exports.useCard=t.useCard;exports.useDashboardActions=t.useDashboardActions;exports.useDashboardStore=t.useDashboardStore;exports.useDateFilterHook=t.useDateFilterHook;exports.useEditorActions=t.useEditorActions;exports.useEditorStore=t.useEditorStore;exports.useTextFilterHook=t.useTextFilterHook;exports.ScheduleDashboard=Nt;exports.SelectComponent=le;exports.Surfboard=ka;exports.cleanCard=St;exports.downloadPdf=vt;exports.getDashbaordStateWithoutData=Ge;exports.useEditorAside=Z;
361
+ `;g(C)}function $(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(fn,{jsonString:JSON.stringify(u,null,2)})})}),u&&u.length>0&&e.jsx(t.Button,{variant:"ghost",onClick:()=>o(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(t.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(mt,{className:"size-3.5 text-muted-foreground"})})]})}function q(){return e.jsxs(t.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(t.ResizablePanel,{id:"1",order:1,defaultSize:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(pn,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(t.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(xn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function I(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(t.Button,{title:"Shift + Enter",disabled:B||V,onClick:()=>{E()},className:"shrink-0",size:"sm",children:[B||V?e.jsx(re,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(Dt,{sql:L==null?void 0:L.sql,error:S,onClick:H}),e.jsx(Ot,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:C=>n(C),className:"",size:"sm",children:e.jsx(hn,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:i,onClick:()=>{F(),T(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:i?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lt,{}),e.jsx(At,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[q(),$()]}),I()]})}function bn({data:s}){var i;const[a,n]=D.useState([]),o=Object.keys(s[0]).map(l=>({accessorKey:l,header:({column:u})=>{const h=u.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>u.toggleSorting(u.getIsSorted()==="asc"),children:[l,h==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),c=t.useReactTable({data:s,columns:o,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsx(t.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(t.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:c.getHeaderGroups().map(l=>e.jsx(t.TableRow,{className:"",children:l.headers.map(u=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:u.isPlaceholder?null:t.flexRender(u.column.columnDef.header,u.getContext())},u.id))},l.id))}),e.jsx(t.TableBody,{children:(i=c.getRowModel().rows)!=null&&i.length?c.getRowModel().rows.map(l=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(u=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(u.column.columnDef.cell,u.getContext())},u.id))},l.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function Sn({card:s}){var T,v,M,y,L,B,V,G,N,k,O;const[a,n]=D.useState(!1),[r,o]=D.useState([]),{authToken:c}=t.useSemaphorContext(),i=t.getTokenParams(c==null?void 0:c.accessToken),l=t.useDashboardStore(E=>E.themeStyle),u={colors:((v=(T=l==null?void 0:l.chart)==null?void 0:T.dataset)==null?void 0:v.backgroundColor)||[]};(M=s.customCardPreferences)!=null&&M.inputData;const{getCard:h}=t.useCustomVisual(((y=s.customCardPreferences)==null?void 0:y.url)||""),m=((L=s.customCardPreferences)==null?void 0:L.visualType)||"single",f=t.useEditorStore(E=>E.frame),{setCustomCardPreferences:x}=t.useEditorActions(),{data:d}=t.useDashboardCardQuery(s),j=D.useCallback((E,S)=>{o(F=>({...F,[E]:S}))},[]);if(!((B=s.customCardPreferences)!=null&&B.componentName))return null;const p=h((V=s.customCardPreferences)==null?void 0:V.componentName);function b(E){n(E)}const g=Object.keys(((G=s.customCardPreferences)==null?void 0:G.dataInputCardIds)||{}).map(E=>{var H,$,q;const S=($=(H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:$[E].cardId,F=(q=f==null?void 0:f.cards)==null?void 0:q.find(I=>I.id===S);return F||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(D.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[p&&m==="single"&&e.jsx(p,{params:i,theme:u,settings:(N=s.customCardPreferences)==null?void 0:N.settings,onDataChange:j,data:(d==null?void 0:d.records)||[]}),p&&m==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((k=s.customCardPreferences)==null?void 0:k.dataInputCardIds)||{}).map(E=>{var H,$,q;const S=($=(H=s.customCardPreferences)==null?void 0:H.dataInputCardIds)==null?void 0:$[E].cardId,F=(q=f==null?void 0:f.cards)==null?void 0:q.find(I=>I.id===S);if(F)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:b,onDataChange:j,dataInputIndex:E,card:F},F.id+E)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(p,{theme:u,onDataChange:j,settings:g.map(E=>{var S;return(S=E==null?void 0:E.customCardPreferences)==null?void 0:S.settings}),data:g.map(E=>E!=null&&E.id?r==null?void 0:r[E.id]:[])})})]})]},(O=s.customCardPreferences)==null?void 0:O.componentName)})}function zt({className:s,...a}){var b;const n=t.useEditorStore(g=>g.card),r=((b=n.customCardPreferences)==null?void 0:b.showCardHeader)??!0,o=t.useEditorStore(g=>g.frame),c=t.useDashboardStore(g=>g.dashboard.filters);t.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:i}=t.useDashboardActions(),l=c==null?void 0:c.find(g=>g.id===o.filterId),{data:u,isLoading:h,isFetching:m}=t.useDashboardCardQuery(n),{setCard:f}=t.useEditorActions(),{data:x}=t.useTopoJson(n),d=D.useMemo(()=>!n.id||!(u!=null&&u.records)?null:t.createChartConfig({data:u==null?void 0:u.records,cardType:n.type,customCfg:n.customCfg,preferences:n.preferences,topoJson:x}),[n.id,u==null?void 0:u.records,n.type,n.customCfg,n.preferences,x]);function j(g){return e.jsx(Sn,{card:g})}function p(){if(u!=null&&u.records&&(u==null?void 0:u.records.length)===0&&!h&&!m)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(t.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(!n.id)return null;if(n.type==="custom")return j(n);if(!["table","custom"].includes(n.type)&&d)return e.jsx(e.Fragment,{children:h||m?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:d})});if(n.type==="table"&&(u!=null&&u.records)&&(u==null?void 0:u.records.length)>0)return e.jsxs(t.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(t.TableVisual,{card:n,data:u==null?void 0:u.records}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",s),...a,children:[r&&e.jsxs(t.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(t.Editable,{text:n.title,onSave:g=>f({...n,title:g}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(t.CardTitle,{className:"text-base",children:n.title||"Edit title..."})})},n.title),e.jsx(t.Editable,{text:n.description||"",onSave:g=>f({...n,description:g}),children:e.jsx(t.CardDescription,{children:n.description||"Edit description..."})},n.description)]}),l&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{className:"my-1",text:l.title||l.column,onSave:g=>i({...l,title:g}),children:e.jsx(t.Label,{children:l.title})}),e.jsx(t.FilterComponent,{filter:l})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:p()})]})}const ke=({language:s,value:a,onChange:n,readonly:r})=>e.jsx(t.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:s,value:a,onChange:n}),Cn=()=>e.jsxs(t.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(t.DialogTitle,{children:"Customize Card"})}),e.jsxs(t.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),vn=({customCode:s,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:o})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(ke,{language:"json",value:n,onChange:r})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(ke,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(ke,{language:"javascript",value:s,onChange:o})})]}),Nn=({error:s,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:o})=>e.jsxs(t.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:o,variant:"outline",children:"Close"})]});function wn(){const[s,a]=D.useState(!1),[n,r]=D.useState(""),[o,c]=D.useState(""),[i,l]=D.useState(""),[u,h]=D.useState(""),m=t.useEditorStore(y=>y.card),f=t.useEditorStore(y=>y.card.customCfg),x=f?JSON.stringify(f,null,2):"",{data:d}=t.useDashboardCardQuery(m),{data:j}=t.useTopoJson(m),{setCardCustomCfg:p,setCustomVisualCode:b}=t.useEditorActions(),g=y=>{var L,B;return JSON.stringify({...y,data:{...y.data,datasets:(B=(L=y.data)==null?void 0:L.datasets)==null?void 0:B.map(V=>({...V,data:[]}))}},null,2)},T=()=>{var L,B;if(!((L=d==null?void 0:d.records)!=null&&L.length))return;const y=t.createChartConfig({data:d.records,cardType:m.type,preferences:m.preferences,topoJson:j});if(y){r(g(y)),l(((B=m.preferences)==null?void 0:B.customVisualCode)||"");const V=t.merge(y,f);c(g(V))}},v=()=>{try{if(i&&b(i),o){const y=JSON.parse(o),L=t.getObjectDiff(JSON.parse(n),y);p(L),h("")}}catch{h("Invalid JSON configuration")}},M=Object.keys(f||{}).length===0;return e.jsxs(t.Dialog,{open:s,onOpenChange:a,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Customize Visual",onClick:T,className:M?"":"text-green-600 hover:text-green-700",children:e.jsx(t.Settings,{className:"h-4 w-4"})})}),e.jsxs(t.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Cn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(zt,{className:"w-1/2 rounded shadow-none"})}),e.jsx(vn,{customCode:i,cardCustomCfgString:x,mergedConfig:o,onConfigChange:y=>c(y??""),onCodeChange:y=>l(y??"")})]}),e.jsx(Nn,{error:u,hasCardCustomConfig:!!f,onReset:()=>{c(n),p(null)},onApply:v,onClose:()=>a(!1)})]})]})}function Ft(s){const[a,n]=D.useState(null);return a}function Rt(){const{authToken:s}=t.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:o}=t.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>t.getPlugins(s==null?void 0:s.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:o}}function kn({onChartTypeChange:s}){const[a,n]=D.useState([]),{setCardCustomCfg:r,setCardPreferences:o,setCardType:c,setCustomCardPreferences:i}=t.useEditorActions(),{data:l}=Rt();function u(h,m){r(null),o({}),c(h),m&&i({type:"component",visualType:"single",url:m.url,componentName:m.name,icon:m.icon}),s==null||s()}return D.useEffect(()=>{(async()=>{var m;if(l){const x=(await Promise.all((m=l==null?void 0:l.plugins)==null?void 0:m.map(async d=>(await t.loadManifest(d.value)).visuals.map(b=>({name:b.name,icon:b.icon,url:d.value}))))).flat();n(x)}})()},[l]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((h,m)=>e.jsx(Dn,{text:h.name,onClick:()=>u("custom",h),icon:h.icon},h.url+h.name+m))})]})}const Dn=({text:s,icon:a,onClick:n})=>{const r=Ft(),o=s.charAt(0).toUpperCase();return e.jsx(t.IconButton,{onClick:n,tooltip:s,children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function _t(s){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:[]}]})(s)}function In(s){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:[]}]})(s)}function Vt(s){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:[]}]})(s)}function Bt(s){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:[]}]})(s)}function qt(s){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:[]}]})(s)}function Pt({onChartTypeChange:s}){const{setCardType:a,setCardPreferences:n,setChartOrientation:r}=t.useEditorStore(u=>u.actions),{setCardCustomCfg:o,setCustomCardPreferences:c}=t.useEditorActions();function i(u,h){o(null),n({}),a(u),s==null||s()}const l=1e3;return e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(t.IconButton,{openDelay:l,tooltip:"Bar Chart",onClick:()=>i("bar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Line Chart",onClick:()=>i("line"),className:"h-10 p-4",children:e.jsx(qe,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Stacked Bar Chart",onClick:()=>i("stackedBar"),className:"h-10 p-4",children:e.jsx(rt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Stacked Line Chart",onClick:()=>i("stackedLine"),className:"h-10 p-4",children:e.jsx(Bt,{className:"size-5",strokeWidth:0})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Scatter Chart",onClick:()=>i("scatter"),className:"h-10 p-4",children:e.jsx(lt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Bubble Chart",onClick:()=>i("bubble"),className:"h-10 p-4",children:e.jsx(Vt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Pie Chart",onClick:()=>i("pie"),className:"h-10 p-4",children:e.jsx(it,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Doughnut Chart",onClick:()=>i("doughnut"),className:"h-10 p-4",children:e.jsx(dt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Radar Chart",onClick:()=>i("radar"),className:"h-10 p-4",children:e.jsx(xt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Polar Area Chart",onClick:()=>i("polarArea"),className:"h-10 p-4",children:e.jsx(_t,{className:"size-6"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Pyramid Chart",onClick:()=>i("pyramid"),className:"h-10 p-4",children:e.jsx(yt,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>i("range"),className:"h-10 p-4",children:e.jsx(ot,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Table",onClick:()=>i("table"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"KPI",onClick:()=>i("kpi"),className:"h-10 p-4",children:e.jsx(qt,{className:"size-6"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Text",onClick:()=>i("text"),className:"h-10 p-4",children:e.jsx(is,{className:"size-5"})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>i("map"),className:"h-10 p-4",children:e.jsx(pt,{className:"size-5"})}),e.jsx(t.IconButton,{openDelay:l,tooltip:"Custom",onClick:()=>i("custom"),className:"h-10 p-4",children:e.jsx(gt,{className:"size-5"})})]})}function En({chartType:s,className:a,customIcon:n,componentName:r}){const o=Ft();switch(s){case"bar":return e.jsx(Be,{className:a});case"line":return e.jsx(qe,{className:a});case"pie":return e.jsx(it,{className:a});case"radar":return e.jsx(xt,{className:a});case"scatter":return e.jsx(lt,{className:a});case"bubble":return e.jsx(Vt,{className:a});case"doughnut":return e.jsx(dt,{className:a});case"stackedBar":return e.jsx(rt,{className:a});case"stackedLine":return e.jsx(Bt,{className:a});case"polarArea":return e.jsx(_t,{className:a});case"pyramid":return e.jsx(yt,{className:a});case"range":return e.jsx(ot,{className:a});case"kpi":return e.jsx(qt,{className:a});case"text":return e.jsx(bt,{className:a});case"map":return e.jsx(pt,{className:a});case"custom":return n&&o?e.jsx(o,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(gt,{className:a});default:return e.jsx(Pe,{className:a})}}function Tn(){var c,i;const[s,a]=D.useState(!1),n=t.useEditorStore(l=>l.card),r=n.type,o=t.useDashboardStore(l=>l.isVisualEditing);return e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:o?"ghost":"outline",children:e.jsx(En,{className:"size-4",chartType:r,customIcon:(c=n.customCardPreferences)==null?void 0:c.icon,componentName:(i=n.customCardPreferences)==null?void 0:i.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:l=>l.preventDefault(),className:"w-50",children:[e.jsx(Pt,{onChartTypeChange:()=>a(!1)}),e.jsx(kn,{onChartTypeChange:()=>a(!1)})]})]})}const fe="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function nt(s,a){var r,o,c;const n=t.getNumberAxis(s,a);return((c=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[n])==null?void 0:c.type)||"linear"}function Mn(){var F,H,$,q,I,C;const[s,a]=D.useState(!1),n=t.useEditorStore(w=>{var A;return(A=w.card)==null?void 0:A.preferences}),r=t.getNumberAxis(n,{}),[o,c]=D.useState(nt(n)),[i,l]=D.useState((($=(H=(F=n==null?void 0:n.chartOptions)==null?void 0:F.scales)==null?void 0:H[r])==null?void 0:$.min)||""),[u,h]=D.useState(((C=(I=(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales)==null?void 0:I[r])==null?void 0:C.max)||""),[m,f]=D.useState(i||u?"custom":"auto"),[x,d]=D.useState(""),[j,p]=D.useState(0),[b,g]=D.useState(""),[T,v]=D.useState(""),[M,y]=D.useState(""),L=t.useEditorStore(w=>w.actions.setCardPreferences),{updateCardInFrame:B}=t.useEditorActions(),V=t.useEditorStore(w=>w.card),G=t.useEditorStore(w=>{var A;return(A=w.card)==null?void 0:A.type}),N=["pie","doughnut","polarArea"].includes(G);D.useEffect(()=>{var w,A,z,U,P,K,W,ee,te,R,Q,Y,ne,ie;c(nt(n)),l(((z=(A=(w=n==null?void 0:n.chartOptions)==null?void 0:w.scales)==null?void 0:A[r])==null?void 0:z.min)===0?0:""),h(((K=(P=(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales)==null?void 0:P[r])==null?void 0:K.max)||""),d(((R=(te=(ee=(W=n==null?void 0:n.chartOptions)==null?void 0:W.scales)==null?void 0:ee[r])==null?void 0:te.ticks)==null?void 0:R.stepSize)||""),p(((Q=n==null?void 0:n.numberAxisFormat)==null?void 0:Q.decimalPlaces)||0),g(((Y=n==null?void 0:n.numberAxisFormat)==null?void 0:Y.suffix)||""),v(((ne=n==null?void 0:n.numberAxisFormat)==null?void 0:ne.currency)||""),y(((ie=n==null?void 0:n.numberAxisFormat)==null?void 0:ie.locale)||"")},[s,n,r]);function k(w,A){return A===""||/^[0-9\b]+$/.test(A)?Number(A):Number(w)}function O(){const w=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(A=>A.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(t.Select,{value:T||"none",onValueChange:A=>v(A==="none"?"":A),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),w.map(A=>e.jsx(t.SelectItem,{value:A,children:A},A))]})})]}),e.jsxs(t.Select,{value:M,onValueChange:A=>y(A),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Locale"}),t.LOCALE_CURRENCY_PAIRS.map(A=>e.jsx(t.SelectItem,{value:A.locale,children:A.locale},A.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(t.Input,{value:j,onChange:A=>p(Number(A.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${fe}`})]})]})}function E(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"range",children:"Range"}),e.jsx(t.Input,{id:"min",value:i,onChange:w=>l(A=>k(A,w.target.value)),className:`col-span-1 h-8 w-full ${fe}`}),e.jsx(t.Input,{value:u,onChange:w=>h(A=>k(A,w.target.value)),id:"max",className:`col-span-1 h-8 w-full ${fe}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(t.Input,{value:x,onChange:w=>d(A=>k(A,w.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${fe}`})]})]})}function S(){var U;let w={};m==="custom"&&(w={min:i,max:u,ticks:{stepSize:x}});const A={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(U=n==null?void 0:n.chartOptions)==null?void 0:U.scales,[r]:{type:o,...o==="linear"?w:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:b,currency:T,locale:M}};console.log(A),L(A);const z={...V,preferences:A};B(z)}return e.jsxs(t.Popover,{onOpenChange:w=>a(w),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Scale Options",children:e.jsx(_s,{className:"size-4 rotate-45"})})}),e.jsx(t.PopoverContentCustom,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(t.Select,{disabled:N,value:o,onValueChange:w=>c(w),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{id:"type",children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Option"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(t.RadioGroup,{disabled:N,id:"scale-option",value:m,onValueChange:w=>f(w),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),m==="custom"&&o=="linear"&&E(),O(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:S,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function An(){const s=t.useEditorStore(l=>{var u,h,m,f;return(f=(m=(h=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:m.legend)==null?void 0:f.position}),a=t.useEditorStore(l=>{var u,h,m,f;return(f=(m=(h=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:m.legend)==null?void 0:f.align}),n=t.useEditorStore(l=>{var u,h,m,f;return(f=(m=(h=(u=l.card.preferences)==null?void 0:u.chartOptions)==null?void 0:h.plugins)==null?void 0:m.legend)==null?void 0:f.display}),{setLegendOptions:r}=t.useEditorActions(),o=l=>{r({display:l,position:s,align:a})},c=l=>{r({display:n,position:l,align:a})},i=l=>{r({display:n,position:s,align:l})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(ks,{className:"size-4"})})}),e.jsx(t.PopoverContentCustom,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(t.SmallSwitch,{checked:n,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Top",onClick:()=>c("top"),children:e.jsx(t.ArrowUp,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Left",onClick:()=>c("left"),children:e.jsx(ss,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>c("bottom"),children:e.jsx(es,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>c("right"),children:e.jsx(ns,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Start",onClick:()=>i("start"),children:e.jsx(Yt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>i("center"),children:e.jsx(Wt,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>i("end"),children:e.jsx(Xt,{className:"size-4"})})]})]})]})]})})]})}function Ln(){var c;const s=t.useEditorStore(i=>i.card.preferences),{setCardPreferences:a,setChartOrientation:n}=t.useEditorStore(i=>i.actions);function r(i){n(i)}const o=((c=s==null?void 0:s.chartOptions)==null?void 0:c.indexAxis)||"x";return e.jsx(t.IconButton,{onClick:()=>r(o==="y"?"x":"y"),tooltip:"Chart Orientation",children:o==="y"?e.jsx(Os,{className:"size-4"}):e.jsx(Ls,{className:"size-4"})})}function On(){const s=t.useEditorStore(i=>i.card),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>{var l,u;return(u=(l=i.card)==null?void 0:l.preferences)==null?void 0:u.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:o}=t.useEditorActions();function c(){const i=["xy","none","x","y"],u=(i.indexOf(r)+1)%i.length;o(i[u])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(s.type)&&e.jsx(Ln,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Mn,{}),e.jsx(An,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(s.type)&&e.jsxs(t.IconButton,{tooltip:"Grid Style",onClick:c,children:[(r==="xy"||!r)&&e.jsx(vs,{className:"size-4"}),r==="x"&&e.jsx(hs,{className:"size-4"}),r==="y"&&e.jsx(Rs,{className:"size-4"}),r==="none"&&e.jsx(Ps,{className:"size-4"})]})]}):null}function ge(){var q;const s=t.useEditorStore(I=>I.frame),a=t.useEditorStore(I=>I.card),n=t.useEditorStore(I=>I.isDevMode),r=t.useEditorStore(I=>I.isShowingVisual),o=t.useDashboardStore(I=>I.isVisualEditing),c=t.useEditorStore(I=>I.isSqlRunning),i=t.useEditorStore(I=>I.pythonStdOut),l=t.useEditorStore(I=>{var C;return(C=I.card.preferences)==null?void 0:C.chartOptions}),u=t.useEditorStore(I=>I.actions.setRunSql);t.getChartGridStyle(l);const{setFrame:h,setCard:m,updateCardInFrame:f,setActiveTabCardId:x,runAssistant:d,setChartGrid:j}=t.useEditorActions(),{data:p,isLoading:b,isFetching:g,error:T}=t.useDashboardCardQuery(a);if(!a)return e.jsx(e.Fragment,{children:"No Active Card"});function v(){const I={connectionId:a.connectionId,lastSelectedDatabase:a.lastSelectedDatabase,lastSelectedSchema:a.lastSelectedSchema,lastSelectedTable:a.lastSelectedTable,lastSelectedDatamodelId:a.lastSelectedDatamodelId,id:t.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};M(I)}function M(I){const C={...s,cards:[...s.cards,I],activeCardId:I.id};h(C),m(I),x(I.id)}function y(){const I={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};M(I)}function L(I){const C=s.cards.filter(z=>z.id!==I),w=C[0],A={...s,cards:C,activeCardId:w.id};h(A),x(w.id),m(w)}function B(I){n||V(I),x(I)}function V(I){const C={...s,cards:s.cards.map(A=>A.id===a.id?a:A),activeCardId:I};h(C);const w=C.cards.find(A=>A.id===I);w.sql&&u(!0),m(w)}const G=(I,C)=>{console.log("handleDragStart",C),I.dataTransfer.setData("tabIndex",C.toString())},N=I=>{I.preventDefault()},k=(I,C)=>{const w=I.dataTransfer.getData("tabIndex");if(w===C.toString())return;const A=Array.from(s.cards),[z]=A.splice(parseInt(w),1);A.splice(C,0,z),h({...s,cards:A})};function O(I,C){return I.cards.length===1&&(C.displayTab===!0||C.displayTab===void 0)||I.activeCardId!==C.id&&(C.displayTab===!0||C.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const w=C.displayTab===void 0?!1:!C.displayTab;m({...C,displayTab:w}),f({...C,displayTab:w})},children:C.displayTab===!0||C.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(ys,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function E(){return e.jsxs(t.Tabs,{onValueChange:B,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(I=>e.jsx(t.TabsContent,{className:"mt-0 grow",value:I.id,children:S()},I.id)),e.jsx(t.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[s.cards.map((I,C)=>e.jsx(t.Editable,{text:I.tabTitle||I.title,onSave:w=>{m({...a,tabTitle:w}),f({...a,tabTitle:w})},children:e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:w=>G(w,C),onDragOver:N,onDrop:w=>k(w,C),className:"",value:I.id,children:[O(s,I),I.tabTitle||I.title,s.activeCardId===I.id&&s.cards.length>1&&e.jsx(t.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>L(I.id)})]})},I.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:v,children:e.jsx(t.Plus,{className:"h-4 w-4"})}),e.jsx(t.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:y,children:e.jsx(xs,{className:"h-4 w-4"})})]})})]})}function S(){return a.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.KPICard,{card:a,data:p==null?void 0:p.records})})}):a.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(t.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(t.TextCard,{isLoading:c,card:a,data:p==null?void 0:p.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(zt,{className:"grow border-none shadow-none"})})}function F(){const I=JSON.stringify(p==null?void 0:p.records,null,2),C=new Blob([I],{type:"application/json"}),w=URL.createObjectURL(C),A=document.createElement("a");A.href=w,A.download=`${a.title}.json`,A.click()}function H(){const C=[Object.keys(p==null?void 0:p.records.reduce((U,P)=>({...U,...P}),{})).join(","),...((p==null?void 0:p.records)||[]).map(U=>Object.values(U).join(","))].join(`
362
+ `),w=new Blob([C],{type:"text/csv"}),A=URL.createObjectURL(w),z=document.createElement("a");z.href=A,z.download=`${a.title}.csv`,z.click()}function $(){const I=`Can you get the documentation for ${a.type} chart?`;d(I)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-3",children:[(b||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(re,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Tn,{}),o&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:$,children:e.jsx(os,{className:"size-4"})}),!["table","custom"].includes(a.type)&&o&&e.jsx(wn,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:H,children:e.jsx(In,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:F,children:e.jsx(bs,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(p==null?void 0:p.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(On,{}),e.jsx(Fn,{})]}),r?E():e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsx(zn,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(p==null?void 0:p.records)&&(p==null?void 0:p.records.length)>0&&e.jsx(bn,{data:(p==null?void 0:p.records)||[]}),(T||(p==null?void 0:p.error))&&e.jsx("span",{className:"font-mono text-xs",children:(T==null?void 0:T.message)||((q=p==null?void 0:p.error)==null?void 0:q.message)})]})]})]})}function zn(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(t.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function Fn(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Rn(){var p,b;const s=t.useEditorStore(g=>g.card.customCardPreferences),{data:a}=Rt(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(g=>g.card),o=t.useEditorStore(g=>g.frame),c=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:i}=t.useEditorActions(),{components:l,manifest:u}=t.useCustomVisual((s==null?void 0:s.url)||""),h=(p=u==null?void 0:u.visuals)==null?void 0:p.find(g=>g.name===(s==null?void 0:s.componentName));function m(g,T){if(!s)return;const M={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:T,hookRef:null}};i({...s,dataInputCardIds:M})}function f(g){var v,M;const T=(v=o==null?void 0:o.cards)==null?void 0:v.filter(y=>{var L;return((L=y==null?void 0:y.customCardPreferences)==null?void 0:L.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsx("div",{className:"space-y-2",children:(M=g==null?void 0:g.dataInputs)==null?void 0:M.map((y,L)=>{var B,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsx(X,{className:"col-span-6 h-8 w-full justify-between",label:"",options:T||[],value:((V=(B=s==null?void 0:s.dataInputCardIds)==null?void 0:B[L])==null?void 0:V.cardId)||"",onValueChange:G=>m(L,G)})]},L+Math.random())})})}function x(g,T,v=[],M=""){var y,L;return s?g==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((y=s==null?void 0:s.settings)==null?void 0:y[T])||M,onChange:B=>{i({...s,settings:{...s==null?void 0:s.settings,[T]:B.target.value}})}},T):g==="select"?e.jsx(X,{className:"h-8 w-full",label:"",options:v,value:((L=s==null?void 0:s.settings)==null?void 0:L[T])||M,onValueChange:B=>{i({...s,settings:{...s==null?void 0:s.settings,[T]:B}})}}):null:null}function d(g){const T=Object.entries((g==null?void 0:g.settings)||{});return e.jsx("div",{className:"space-y-3",children:T.map(([v,M])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:M.title}),x(M.ui,v,M.options,M.defaultValue)]},v))})}function j(g){s&&i({...s,visualType:g,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{icon:e.jsx(rs,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:g=>i({...s||{url:"",componentName:""},url:g})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:c,onValueChange:j,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:l&&e.jsx(X,{icon:e.jsx(ps,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(l==null?void 0:l.filter(g=>g.type===c).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),i({...s,componentName:g})}})})]})})]}),((b=r==null?void 0:r.customCardPreferences)==null?void 0:b.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:f(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:d(h)})})]})]})]})}function oe(){const[s,a]=D.useState([]),n=t.useEditorStore(h=>h.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:o}=t.useEditorStore(h=>h.actions),c=t.useEditorStore(h=>h.queryResultColumns);t.useEditorStore(h=>{var m;return(m=h.card.preferences)==null?void 0:m.filterOnClickColumnIndex}),D.useEffect(()=>{c&&a(new Array(c.length).fill(!1))},[c]);function i(h,m){var f,x;m?n!=null&&n.onClickFilter&&((f=n==null?void 0:n.onClickFilter)==null?void 0:f.length)>0?o({...n,onClickFilter:[...n.onClickFilter,{columnIndex:h,expression:""}]}):o({...n,onClickFilter:[{columnIndex:h,expression:""}]}):(o({...n,onClickFilter:(x=n==null?void 0:n.onClickFilter)==null?void 0:x.filter(d=>d.columnIndex!==h)}),a(d=>{const j=[...d];return j[h]=!1,j}))}function l(h,m){var x;const f=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.map(d=>d.columnIndex===h?{...d,expression:m.target.value}:d);o({...n,onClickFilter:f})}function u(h){var m,f,x,d;if(s!=null&&s[h]||(f=(m=n==null?void 0:n.onClickFilter)==null?void 0:m.find(j=>j.columnIndex===h))!=null&&f.expression)return e.jsx(t.Input,{value:(d=(x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(j=>j.columnIndex===h))==null?void 0:d.expression,onChange:j=>l(h,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"On Click"}),c==null?void 0:c.map((h,m)=>{var f,x;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(t.Checkbox,{checked:!!((f=n==null?void 0:n.onClickFilter)!=null&&f.find(d=>d.columnIndex===m)),onCheckedChange:d=>i(m,d)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((x=n==null?void 0:n.onClickFilter)==null?void 0:x.find(d=>d.columnIndex===m))&&e.jsx(t.Pencil,{onClick:()=>{a(d=>{const j=[...d];return j[m]=!d[m],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),u(m)]})},h)})]})}function _n({idx:s}){var l;const a=t.useEditorStore(u=>{var h;return(h=u.card)==null?void 0:h.preferences}),n=t.useEditorStore(u=>{var h;return(h=u.card.preferences)==null?void 0:h.datasetOptions}),r=t.useEditorStore(u=>u.actions.setCardPreferences),o=(l=a==null?void 0:a.chartOptions)==null?void 0:l.indexAxis,c=n==null?void 0:n.find(u=>u.idx===s);function i(u,h){(u==="end"||u==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const m={display:u!=="none",align:u,anchor:u,clamp:!0};if(!c)r({...a,datasetOptions:[...n||[],{idx:h,datalabels:m}]});else{const f={...c};f.datalabels=m;const x=n==null?void 0:n.map(d=>d.idx===h?f:d);r({...a,datasetOptions:x})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Hs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(t.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(t.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-4"})}),e.jsx(t.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Ds,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Es,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(t.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Is,{className:t.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Ht(){const s=t.useEditorStore(h=>h.card),a=t.useEditorStore(h=>{var m,f,x;return(x=(f=(m=h==null?void 0:h.card)==null?void 0:m.preferences)==null?void 0:f.chartOptions)==null?void 0:x.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",o=a==="y"?"Dimension":"Metric",{keys:c,metricKeys:i,dimensionKeys:l}=t.getKeys((n==null?void 0:n.records)||[]);let u=i;if(["stackedBar","stackedLine"].includes(s.type)){const h=t.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:u[0]}),{metricKeys:m}=t.getKeys(h);u=m}return c.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:l.map(h=>e.jsx("p",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",title:h,children:Gt(h)},h))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:u.map((h,m)=>e.jsx(Vn,{col:h,idx:m},h))})]})]})}function Gt(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function Vn({col:s,idx:a}){const n=t.useEditorStore(l=>{var u;return(u=l.card)==null?void 0:u.preferences}),r=t.useEditorStore(l=>{var u;return(u=l.card.preferences)==null?void 0:u.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===a),{setCardPreferences:c}=t.useEditorStore(l=>l.actions);function i(l){if(!o)c({...n,datasetOptions:[...r||[],{idx:a,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const u={...o};u.type=l==="area"?"line":l,u.fill=l==="area"?"origin":"";const h=r==null?void 0:r.map(m=>m.idx===a?u:m);c({...n,datasetOptions:h})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:s,children:Gt(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Be,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(qe,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ds,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(_n,{idx:a})]})]})}function Ut(){const s=t.useEditorStore(d=>d.selectedConnectionId),a=t.useEditorStore(d=>d.selectedDatamodelId),n=t.useEditorStore(d=>d.selectedDatabaseName),r=t.useEditorStore(d=>d.selectedSchemaName),o=t.useEditorStore(d=>d.selectedTableName),c=t.useDashboardStore(d=>d.dashboard.filters)||[],i=t.useDashboardStore(d=>d.actions.addFilter),l=t.useDashboardStore(d=>d.actions.removeFilter),{removeFilterValues:u}=t.useDashboardActions(),{modelItems:h,tableName:m,connectionType:f}=Z();function x(d,j="dashboard"){var B;const p=t.fmt(d.column_name),b=t.fmt(n||""),g=t.fmt(r||""),T=t.fmt(m);let v=t.getQualifiedTableName({schemaName:g,tableName:T,connectionType:f,databaseName:b}),M=`${v}.${p}`;const y=(B=h==null?void 0:h.find(V=>V.id===a))==null?void 0:B.name;a&&a!=="none"&&(M=`${t.DATAMODEL_NAMESPCACE}.${y}.${p}`,v=`${t.DATAMODEL_NAMESPCACE}.${y}`);const L=c==null?void 0:c.find(V=>V.column===M&&V.table===T&&(V.database===b||V.database===n));if(L)u(L.id),l(L.id);else{const V=t.v4();return m==="api"&&s?(i({location:j,id:V,column:M,title:d.column_name,dataType:d.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(d.data_type,v,p)}),V):(i({id:V,location:j,column:M,title:d.column_name,dataType:d.data_type,table:o||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(d.data_type,v,p)}),V)}}return{assignFilter:x}}function pe(){const s=t.useDashboardStore(l=>l.dashboard.filters),a=t.useEditorStore(l=>l.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=Z(),{assignFilter:o}=Ut();function c(l){const u=o(l,"frame");n({...a,filterId:u})}const i=s==null?void 0:s.find(l=>l.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(Bn,{onSelect:c,columns:r}),i&&e.jsx(t.FilterHeader,{filter:i})]})}function Bn({columns:s,onSelect:a}){var i;const[n,r]=ce.useState(!1),[o,c]=ce.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[o?(i=s.find(l=>l.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(l=>e.jsxs(t.CommandItem,{value:l.column_name,onSelect:u=>{const h=u===o?"":u;c(h),r(!1),h&&a(l)},children:[l.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function qn({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Ht,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(pe,{})]})]})]})})}function $e(){var o,c,i;const s=t.useEditorStore(l=>l.card.type),a=t.useEditorStore(l=>l.card.preferences),{setCardPreferences:n}=t.useEditorStore(l=>l.actions);function r(l){var m;const u={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},h={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(m=a==null?void 0:a.chartOptions)==null?void 0:m.plugins,...u}}};n(h),console.log(l)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((i=(c=(o=a==null?void 0:a.chartOptions)==null?void 0:o.plugins)==null?void 0:c.datalabels)==null?void 0:i.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),s!=="pyramid"&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function Pn({cardType:s}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:c=>c.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx($e,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(pe,{})]})]})]})})}const Hn={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Gn={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Un(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:$n(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx($e,{}),e.jsx(oe,{}),e.jsx(pe,{})]})]})}function $n(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Hn,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Gn,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Qn(){var u,h,m,f,x;const s=t.useEditorStore(d=>d.card.preferences),a=t.useEditorStore(d=>d.actions.setCardPreferences),n=t.useEditorStore(d=>d.actions.setNumberFormat);t.useEditorStore(d=>{var j,p;return(p=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:p.decimalPlaces});const r=t.useEditorStore(d=>{var j,p;return(p=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:p.locale}),o=t.useEditorStore(d=>{var j,p;return(p=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:p.currency});t.useEditorStore(d=>d.actions.setFilterOnClickField);const c=t.useEditorStore(d=>{var j,p;return(p=(j=d.card.preferences)==null?void 0:j.formatNumber)==null?void 0:p.colorRanges})||[],i=t.useEditorStore(d=>d.actions.setColorRanges),l=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(d=>d.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((u=s==null?void 0:s.formatNumber)!=null&&u.enabled),onCheckedChange:d=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:d}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:d=>{var j,p,b;return n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",d,((b=s==null?void 0:s.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(d=>e.jsx(t.SelectItem,{value:d.locale,children:d.locale},d.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:o||"none",onValueChange:d=>{var j,p,b;console.log("currency",d),n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,d==="none"?"":d,((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),l.map(d=>e.jsx(t.SelectItem,{value:d,children:d},d))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((f=(m=s==null?void 0:s.formatNumber)==null?void 0:m.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:d=>{var j,p,b;return n(Number(d),((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((p=s==null?void 0:s.formatNumber)==null?void 0:p.locale)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(d=>e.jsx(t.SelectItem,{value:d,children:d},d))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((x=s==null?void 0:s.formatNumber)==null?void 0:x.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:d=>{var j,p,b;return n(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((p=s==null?void 0:s.formatNumber)==null?void 0:p.currency)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",d.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:c,setColorRanges:i})]})]})}function Jn(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Qn,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function De({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Kn=[{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"}],Wn=["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"],Yn=Wn.map(s=>({label:s,value:s}));function Xn(){var u,h,m,f,x,d,j,p,b,g,T,v,M,y,L,B,V,G;const s=t.useEditorStore(N=>N.card),a=(h=(u=s==null?void 0:s.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:h.topoJsonUrl,[n,r]=D.useState(((f=(m=s==null?void 0:s.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=t.useEditorActions(),{data:c}=t.useTopoJson(s),i=Object.keys((c==null?void 0:c.objects)||{}).map(N=>({label:N,value:N}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(De,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(X,{className:"h-9",options:l,onValueChange:N=>{console.log("value",N),o({...s.preferences,mapVisualOptions:{topoJsonUrl:N}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:N=>{r(N.target.value)},onBlur:()=>{var N;console.log("onBlur",n),o({...s.preferences,mapVisualOptions:{...(N=s.preferences)==null?void 0:N.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),c&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(X,{className:"h-9",options:i,value:((d=(x=s.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:d.objectKey)||"",label:"Map Object",onValueChange:N=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,objectKey:N}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(X,{className:"h-9",options:Kn,value:((p=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:p.projection)||"",label:"Projection",onValueChange:N=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projection:N}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(X,{className:"h-9",options:Yn,value:((g=(b=s.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:N=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,colorScale:N}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(De,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((v=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:N=>{var k;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionScale:Number(N.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((L=(y=(M=s.preferences)==null?void 0:M.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:L[0])||0,onChange:N=>{var k,O,E,S;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionOffset:[Number(N.target.value),((S=(E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:S[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((G=(V=(B=s.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:G[1])||0,onChange:N=>{var k,O,E,S;o({...s.preferences,mapVisualOptions:{...(k=s.preferences)==null?void 0:k.mapVisualOptions,projectionOffset:[((S=(E=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:S[0])||0,Number(N.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(oe,{})]})}function Zn(){var r;const s=t.useEditorStore(o=>o.card.preferences),{setCardPreferences:a}=t.useEditorStore(o=>o.actions);function n(o){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function je({cardType:s,docContent:a,suffix:n="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx($e,{}),s==="text"&&e.jsx(Zn,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(pe,{})]})]})]})})}function ea(){const s=t.useEditorStore(r=>{var o,c;return(c=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:c.sortChart}),{setSortChart:a}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(X,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(Ht,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(pe,{})]})]})]})})}function ta({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.preferences}),n=t.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{n({...a,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(oe,{}),e.jsx(pe,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const 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:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),na=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),aa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function ra(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(ea,{});case"pyramid":return e.jsx(je,{docContent:sa,cardType:n});case"kpi":return e.jsx(Jn,{});case"line":case"bar":return e.jsx(qn,{cardType:n});case"range":return e.jsx(je,{docContent:na,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:n});case"bubble":case"scatter":return e.jsx(Pn,{cardType:n});case"table":return e.jsx(ta,{cardType:n});case"text":return e.jsx(je,{docContent:aa,cardType:n,suffix:"Visual"});case"map":return e.jsx(Xn,{});case"custom":return e.jsx(Rn,{});default:return e.jsx(Un,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}const Ie={id:"__placeholder__",role:"groupby",type:"string"},Ee={id:"__placeholder__",role:"metric",type:"number"},Te={id:"__placeholder__",role:"trendby",type:"date"},Me={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},$t={id:"__placeholder__"},de="droppable-group-by",ue="droppable-metrics",ze="sortable-group-by",Fe="sortable-metrics",me="droppable-trend-by",Re="sortable-trend-by",_e="droppable-filters",Ve="sortable-filters";function oa(){const s=t.useDndStore(k=>k.insertIndex),a=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.groupByColumns)||[]}),n=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.metricColumns)||[]}),r=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.trendByColumns)||[]}),o=t.useEditorStore(k=>{var O;return((O=k.card.queryConfig)==null?void 0:O.filterColumns)||[]}),{setInsertIndex:c,setActiveId:i,setPreviewGroupByColumns:l,setPreviewMetricColumns:u,setPreviewTrendByColumns:h,setPreviewFilterColumns:m}=t.useDndActions(),{setGroupByColumns:f,setMetricColumns:x,setTrendByColumns:d,setFilterColumns:j}=t.useEditorActions(),{columns:p}=Ue(),{formattedTableName:b}=Z(),g=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),T=k=>{var S;const{active:O,over:E}=k;if(((S=O.data.current)==null?void 0:S.type)==="column"&&E){const F=E.id,H=p.find(C=>C.column_name===O.id);if(!H)return;const $=t.isNumberDataType(H.data_type),q=t.isTextDataType(H.data_type),I=t.isDateDataType(H.data_type);if(q){if(a.some(w=>w.id===F)){const w=a.findIndex(z=>z.id===F);c(w);const A=a.filter(z=>z.id!==Ie.id);A.splice(w,0,Ie),l(A)}else if(E.id===de){c(a.length);const w=[...a,Ie];l(w),u(n),h(r),m(o)}}if($||q){if(n.some(w=>w.id===F)){console.log("isOverMetricSortable",F);const w=n.findIndex(z=>z.id===F);c(w);const A=n.filter(z=>z.id!==Ee.id);A.splice(w,0,Ee),u(A)}else if(E.id===ue){c(n.length);const w=[...n,Ee];u(w),h(r),m(o),l(a)}}if(I){if(r.some(w=>w.id===F)){const w=r.findIndex(z=>z.id===F);c(w);const A=r.filter(z=>z.id!==Te.id);A.splice(w,0,Te),h(A)}else if(E.id===me){c(r.length);const w=[...r,Te];h(w),u(n),m(o),l(a)}}if(M(H)){if(o.some(w=>w.id===F)){const w=o.findIndex(z=>z.id===F);c(w);const A=o.filter(z=>z.id!==Me.id);A.splice(w,0,Me),m(A)}else if(E.id===_e){c(o.length);const w=[...o,Me];m(w),u(n),h(r),l(a)}}}else l(a),u(n),h(r),m(o)};function v(k){i(k.active.id),c(null),l(a),u(n),h(r),m(o)}function M(k){return!o.some(O=>O.name===k.column_name)}function y(k,O="SUM"){const{column_name:E,data_type:S}=k,F=[...n],H=s!==null?s:n.length,$={...k,id:ae(E),name:E,label:Oe(O,E),type:S,role:"metric",aggregate:O};F.splice(H,0,$),x(F)}function L(k){const O=[...a],E=s!==null?s:a.length,S={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,role:"groupby"};O.splice(E,0,S),f(O)}function B(k){const O=[...r],E=s!==null?s:r.length,S={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,role:"trendby"};O.splice(E,0,S),d(O)}function V(k){const O=[...o],E=s!==null?s:o.length,S={...k,id:ae(k.column_name),name:k.column_name,type:k.data_type,sql:t.getDefaultFilterSql(k.data_type,b,t.fmt(k.column_name)),role:"filter"};O.splice(E,0,S),j(O)}function G(k){var F,H,$,q,I,C,w,A;const{active:O,over:E}=k,S=O.data.current;if((S==null?void 0:S.type)==="column"&&E){const z=p.find(W=>W.column_name===O.id);if(!z)return;const U=t.isNumberDataType(z.data_type),P=t.isTextDataType(z.data_type),K=t.isDateDataType(z.data_type);P&&(E.id===de||((F=E.data.current)==null?void 0:F.type)===ze)?L(z):(U||P)&&(E.id===ue||((H=E.data.current)==null?void 0:H.type)===Fe)?(U&&y(z),P&&y(z,"COUNT")):K&&(E.id===me||(($=E.data.current)==null?void 0:$.type)===Re)?B(z):M(z)&&(E.id===_e||((q=E.data.current)==null?void 0:q.type)===Ve)&&V(z)}if(E&&((I=E.data.current)==null?void 0:I.type)===ze&&a.some(z=>z.id===O.id)){const z=a.findIndex(P=>P.id===O.id),U=a.findIndex(P=>P.id===E.id);if(z!==-1&&U!==-1&&z!==U){const P=[...a],[K]=P.splice(z,1);P.splice(U,0,K),f(P)}}if(E&&((C=E.data.current)==null?void 0:C.type)===Fe&&n.some(z=>z.id===O.id)){const z=n.findIndex(P=>P.id===O.id),U=n.findIndex(P=>P.id===E.id);if(z!==-1&&U!==-1&&z!==U){const P=[...n],[K]=P.splice(z,1);P.splice(U,0,K),x(P)}}if(E&&((w=E.data.current)==null?void 0:w.type)===Re&&r.some(z=>z.id===O.id)){const z=r.findIndex(P=>P.id===O.id),U=r.findIndex(P=>P.id===E.id);if(z!==-1&&U!==-1&&z!==U){const P=[...r],[K]=P.splice(z,1);P.splice(U,0,K),d(P)}}if(E&&((A=E.data.current)==null?void 0:A.type)===Ve&&o.some(z=>z.id===O.id)){const z=o.findIndex(P=>P.id===O.id),U=o.findIndex(P=>P.id===E.id);if(z!==-1&&U!==-1&&z!==U){const P=[...o],[K]=P.splice(z,1);P.splice(U,0,K),j(P)}}i(null),c(null),l(a),u(n),h(r),m(o)}function N(){i(null),c(null),l(a),u(n),h(r),m(o)}return{handleDragOver:T,handleDragEnd:G,handleDragStart:v,handleDragCancel:N,sensors:g}}function Qt({label:s,column:a,options:n,onValueChange:r}){const[o,c]=D.useState(n[0]);D.useEffect(()=>{"aggregate"in a?c(n.find(l=>l.value===a.aggregate)||n[0]):"granularity"in a&&c(n.find(l=>l.value===a.granularity)||n[0])},[a,n]);function i(l){c(n.find(u=>u.value===l)||n[0]),r(l)}return e.jsx(X,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:o.logo,options:n,value:o.value,onValueChange:l=>i(l),label:s,showPlaceholderLabel:!1})}const ia=[{label:"Sum",value:"SUM",logo:e.jsx(jt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(ht,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(Ss,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(ts,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(Zt,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(as,{className:"size-3.5"})}];function la(s,a){const n=t.toTitleCase(s.name.replace(/_/g," "));switch(a){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function ca({column:s}){const{updateMetricColumn:a}=t.useEditorActions();let n=ia;t.isTextDataType(s.type)&&(n=n.filter(o=>["COUNT","DISTINCT"].includes(o.value))),t.isNumberDataType(s.type)&&(n=n.filter(o=>!["DISTINCT"].includes(o.value)));function r(o){const c={...s,aggregate:o,label:la(s,o)};a(s.id,c)}return e.jsx(Qt,{column:s,options:n,onValueChange:o=>r(o),label:"Aggregation"})}const da=[{label:"Day (D)",value:"day",logo:e.jsx("span",{className:"size-3",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx("span",{className:"size-3",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx("span",{className:"size-3",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx("span",{className:"size-3",children:"Y"})}];function ua(s,a){const n=t.toTitleCase(s.name.replace(/_/g," "));switch(a){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function ma({column:s}){const{updateTrendByColumn:a}=t.useEditorActions();function n(r){const o={...s,granularity:r,label:ua(s,r)};a(s.id,o)}return e.jsx(Qt,{column:s,options:da,onValueChange:r=>n(r),label:"Granularity"})}function ha({col:s,onChange:a,droppableId:n}){const{columns:r}=Ue(),o=D.useMemo(()=>{let l=[];n===ue&&(l=(r==null?void 0:r.filter(h=>t.isNumberDataType(h.data_type)))||[]),n===me&&(l=(r==null?void 0:r.filter(h=>t.isDateDataType(h.data_type)))||[]),n===de&&(l=r);const u=l==null?void 0:l.filter(h=>h.column_name!==s.name);return u==null?void 0:u.map(h=>({id:h.column_name,value:h.column_name}))},[r,n,s.name]),c=[{id:s.name,value:s.name}];function i(l){const u=r==null?void 0:r.find(h=>{var m;return h.column_name===((m=l[0])==null?void 0:m.id)});u&&a(u)}return o!=null&&o.length?e.jsx(t.ComboBox2,{multiple:!1,options:o,selectedOptions:c,onChange:i,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted px-0"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:s.name})}function pa({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[o,c]=D.useState(!1),{updateGroupByColumn:i,updateMetricColumn:l,updateTrendByColumn:u}=t.useEditorActions(),{attributes:h,listeners:m,setNodeRef:f,transform:x,transition:d,isDragging:j}=t.useSortable({id:s.id,data:{type:a}}),p=x?{opacity:j?.5:void 0,transform:t.CSS.Translate.toString(x),transition:d}:void 0;function b(y){const L=t.isNumberDataType(y.data_type),B=t.isTextDataType(y.data_type),V=t.isDateDataType(y.data_type);if(console.log("dataColumn",y),r===de){const G={id:s.id,name:y.column_name,type:L?"number":B?"string":V?"date":"string",role:"groupby"};i(s.id,G)}if(r===ue&&L){const G={id:s.id,name:y.column_name,type:"number",role:"metric",aggregate:"SUM"};l(s.id,G)}if(r===me&&V){const G={id:s.id,name:y.column_name,type:"date",role:"trendby",granularity:"month"};u(s.id,G)}}function g(){return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 h-32 rounded-md border border-border p-3 text-sm",children:e.jsx(e.Fragment,{})})}function T(){if(r===ue)return e.jsx(ca,{column:s});if(r===me)return e.jsx(ma,{column:s})}function v(){return e.jsx("div",{className:t.cn("grow",{"pl-3":r===de}),children:e.jsx(ha,{col:s,onChange:b,droppableId:r})})}function M(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{onClick:()=>c(!o),children:o?e.jsx(qs,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(js,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...m,...h,ref:f,style:p,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted pl-2",children:[M(),T(),v()]}),o&&g()]}),e.jsx("div",{className:t.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:o}),children:e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function Ae({id:s,label:a,columns:n,previewColumns:r,sortableType:o,onRemoveColumn:c}){const{setNodeRef:i}=t.useDroppable({id:s}),l=t.useDndStore(m=>m.activeId),u={},h=l?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(m=>m.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-4",ref:i,style:u,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"space-y-2",children:h==null?void 0:h.map(m=>m.id===$t.id?e.jsx(xa,{},m.id):e.jsx(pa,{droppableId:s,type:o,column:m,onRemoveColumn:c},m.id))})]})})}function xa(){return e.jsx("div",{className:"flex h-7 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function at(){const s=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.groupByColumns)||[]}),a=t.useDndStore(x=>x.previewGroupByColumns),n=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.metricColumns)||[]}),r=t.useDndStore(x=>x.previewMetricColumns),o=t.useEditorStore(x=>{var d;return((d=x.card.queryConfig)==null?void 0:d.trendByColumns)||[]}),c=t.useDndStore(x=>x.previewTrendByColumns),{removeColumnFromGroupBy:i,removeColumnFromMetricColumns:l,removeColumnFromTrendByColumns:u}=t.useEditorActions();function h(x){i(x)}function m(x){u(x)}function f(x){l(x)}return e.jsxs("div",{className:"h-full w-full space-y-4 p-4",children:[e.jsx(Pt,{}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(Ae,{onRemoveColumn:h,sortableType:ze,id:de,label:"Group By",columns:s,previewColumns:a}),e.jsx(Ae,{onRemoveColumn:m,sortableType:Re,id:me,label:"Trend By",columns:o,previewColumns:c}),e.jsx(Ae,{onRemoveColumn:f,sortableType:Fe,id:ue,label:"Metrics",columns:n,previewColumns:r})]})]})}function fa({children:s,id:a,type:n}){const{attributes:r,listeners:o,setNodeRef:c,transform:i,transition:l,isDragging:u}=t.useSortable({id:a,data:{type:n}}),h=i?{opacity:u?.5:void 0,transform:t.CSS.Translate.toString(i),transition:l}:void 0;return e.jsx("div",{...o,...r,ref:c,style:h,children:s})}function Qe({children:s,column:a,id:n,sortableType:r,className:o}){const[c,i]=D.useState(!1),{removeEditorFilter:l}=t.useEditorActions();function u(h){l(h)}return e.jsx(fa,{id:n,type:r,children:e.jsxs("div",{className:t.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":c}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{className:"text-sm",children:a.name}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>u(a),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.cn("group flex items-center rounded-t-md text-sm",!c&&"rounded-b-md",c&&"border border-border"),children:[e.jsx("div",{children:e.jsx(t.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:t.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",o),children:s})]})]})})}function ga({column:s,sortableType:a}){const n=t.useDashboardStore(T=>T.themeStyle),r=t.useEditorStore(T=>{var v,M;return(M=(v=T.card)==null?void 0:v.queryConfig)==null?void 0:M.filters}),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:i}=Z(),l=D.useMemo(()=>{var T;return(T=r==null?void 0:r.find(v=>v.filterColumnName===s.name))==null?void 0:T.filterValue},[r,s.name]),u=D.useMemo(()=>Array.isArray(l)?l.map(T=>({id:T,value:T})):[],[l]),{updateEditorFilterValue:h}=t.useEditorActions(),m={column:s.name,sql:s.sql,id:s.name,connectionId:o,dataType:s.type},{data:f,isLoading:x,isFetching:d,isError:j}=t.useFilterQuery(m),p=D.useMemo(()=>{var v;return m.column?(v=f==null?void 0:f.records)==null?void 0:v.map(M=>{let y=m.column.split(".").slice(-1)[0].replace(/"/g,"");return M[y]===void 0&&(y=y.toLowerCase()),{id:M[y],value:M[y]}}):[]},[f,m.column]);function b(T){const v=T.map(M=>M.id);h(s.name,v)}function g(){return x||d?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):j?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(t.ComboBox2,{options:p,onChange:b,selectedOptions:u,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Qe,{className:"w-60",id:s.id,sortableType:a,column:s,children:g()})}function ja({column:s,sortableType:a}){const[n,r]=D.useState(!1),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:i}=Z(),l={column:s.name,sql:s.sql,id:s.name,connectionId:o,title:"",dataType:s.type},{isLoading:u,isFetching:h,isError:m,data:f}=t.useFilterQuery(l),x=f==null?void 0:f.records,{dateRange:d,setDateRange:j,initialDateRange:p}=t.useDateRangeFromRecords(x),{updateEditorFilterValue:b}=t.useEditorActions();function g(M){var L,B;const y={gte:(L=M==null?void 0:M.from)==null?void 0:L.toISOString(),lte:(B=M==null?void 0:M.to)==null?void 0:B.toISOString()};b(s.name,y)}function T(){b(s.name,null,!0),j(p)}function v(){return u||h?e.jsx("div",{children:e.jsx(t.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):m?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):x?e.jsx(t.DateRangePopover,{title:l.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:d,setDateRange:j,onApply:g,onClear:T}):e.jsx(t.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Qe,{className:"w-72",id:s.id,sortableType:a,column:s,children:v()})}function ya({id:s,label:a,columns:n,previewColumns:r,sortableType:o}){const{setNodeRef:c}=t.useDroppable({id:s}),i=t.useDndStore(m=>m.activeId),l={};function u(m){const f=t.isDateDataType(m.type);return m.id===$t.id?e.jsx(Qe,{id:m.id,sortableType:o,column:m,children:e.jsx(ba,{})},m.id):f?e.jsx(ja,{droppableId:s,sortableType:o,column:m},m.id):e.jsx(ga,{droppableId:s,sortableType:o,column:m},m.id)}const h=i?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(m=>m.id),children:e.jsxs("div",{className:"space-y-2 rounded-md border-2 border-dashed p-5",ref:c,style:l,children:[e.jsx(t.Label,{className:"text-sm",children:a}),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:h==null?void 0:h.map(m=>u(m))})]})})}function ba(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm"})}function Sa(){const s=t.useEditorStore(o=>{var c;return((c=o.card.queryConfig)==null?void 0:c.filterColumns)||[]}),a=t.useDndStore(o=>o.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(o){n(o)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(ya,{onRemoveColumn:r,sortableType:Ve,id:_e,label:"Filters",columns:s,previewColumns:a})})}function Ca(){const s=t.useEditorStore(r=>r.card),{data:a,errorMessage:n}=t.useDashboardCardQuery(s);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ot,{}),e.jsx(Dt,{sql:a==null?void 0:a.sql,error:n})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium",children:"Early Preview"}),e.jsx(Lt,{}),e.jsx(At,{variant:"default"})]})]})}function va(){const s=D.useRef(null),a=t.useEditorStore(i=>i.isShowingVisual),n=t.useEditorStore(i=>i.showAIDialog),r=t.useEditorStore(i=>i.isDevMode);D.useEffect(()=>{var i,l;n?(i=s.current)==null||i.resize(0):(l=s.current)==null||l.resize(25)},[n]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(yn,{})}),e.jsx(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:r?e.jsx(ra,{}):e.jsx(at,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ge,{})})]}):e.jsx(ge,{})})]})}function c(){return e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{className:"pb-1","data-biz-mode-container":"",minSize:0,defaultSize:100,children:a&&!n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex min-w-[320px]",defaultSize:25,maxSize:30,children:e.jsx(at,{})})}),!n&&e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(Ca,{}),e.jsx(Sa,{})]}),e.jsx(t.ResizableHandle,{className:"border"}),e.jsx(t.ResizablePanel,{minSize:20,defaultSize:80,children:e.jsx(ge,{})})]})})]}):e.jsx(ge,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:r?o():c()})}const Na=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function wa(){const s=D.useRef(null),a=D.useRef(null),[n,r]=D.useState(!1),[o,c]=D.useState(t.isDevEnv),[i,l]=D.useState(!1),u=t.useEditorStore(q=>q.actions.setCardSql),h=t.useEditorStore(q=>q.actions.setRunSql),m=t.useEditorStore(q=>q.showAIDialog),{setShowAIDialog:f}=t.useEditorActions(),{messages:x,setMessages:d,reload:j,append:p,input:b,setInput:g,isLoading:T,handleAddCurrentTableToScope:v,removeFromCurrentSelections:M,currentAssitantScope:y,handleInputChange:L,handleSubmit:B,stop:V,chatStatus:G,toolStatus:N,llmUsage:k,errorMessage:O}=Mt();t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:x}),D.useEffect(()=>{var q;m&&((q=a.current)==null||q.focus())},[m]);function E(q){u(q),h(!0)}function S(q){const I={role:"user",content:q.title+" "+q.subtitle};p(I)}function F(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(ut,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:c,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:l,children:"System Message"})]})]})}function H(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),y&&y.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:y==null?void 0:y.map((q,I)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[t.getFormattedTableNameForQuery({schemaName:q.schemaName||"",tableName:q.tableName||"",modelName:q.datamodelName||"",connectionType:q.connectionType||"",databaseName:q.databaseName||""}),e.jsx("button",{onClick:()=>{M(q)},children:e.jsx(t.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},I))}),(y==null?void 0:y.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(t.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:v,children:[e.jsx(t.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const $=(b==null?void 0:b.length)===0&&(x==null?void 0:x.filter(q=>q.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[H(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[F(),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{d([]),j()},children:e.jsx(t.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(t.X,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(t.PrintMessages,{messages:x,showTools:o,handleRun:E,showSystemMessage:i}),e.jsx(t.ChatStatus,{status:t.getStatus(G,N),isLoading:T})]})}),$&&e.jsx(t.Placeholders,{onClick:S,placeholders:Na}),e.jsx(t.ChatInput,{onFocus:()=>{v()},stop:V,ref:a,setInput:g,input:b,handleInputChange:L,handleSubmit:B,isLoading:T}),k&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",k.promptTokens," prompt tokens,"," ",k.completionTokens," completion tokens,"," ",k.totalTokens," total tokens"]})}),O&&e.jsx("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:e.jsx("span",{children:O})})]})}function ka({authToken:s,onSave:a,onClose:n}){const r=D.useRef(null),o=t.useEditorStore(b=>b.showAIDialog),{setAuthToken:c}=t.useDashboardActions(),{setShowAIDialog:i,setOnSave:l,setOnClose:u}=t.useEditorActions(),{handleDragOver:h,handleDragEnd:m,handleDragStart:f,handleDragCancel:x,sensors:d}=oa();D.useEffect(()=>{a&&l(a),n&&u(n)},[a,l,n,u]),D.useEffect(()=>{s&&s.accessToken&&c(s)},[s,c]),D.useEffect(()=>{var b,g;o?((b=r.current)==null||b.resize(40),i(!0)):(i(!1),(g=r.current)==null||g.resize(0))},[o,i]);function j(b){b<1?i(!1):o||i(!0)}function p(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(va,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:j,defaultSize:0,children:e.jsx(wa,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsx(t.DndContext,{sensors:d,onDragStart:f,onDragEnd:m,onDragOver:h,onDragCancel:x,children:e.jsxs("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:[e.jsx(kt,{type:"main"}),p()]})})})}function Da(){t.useDashboardStore(i=>i.selectedCardId);const s=t.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(i=>i.actions),n=t.useDashboardStore(i=>i.isVisualEditing),r=t.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),a(!1))}function c(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(ka,{onSave:o,onClose:c})})}function Ia(){const s=t.useEditorStore(c=>c.selectedDatabaseName),a=t.useEditorStore(c=>c.selectedTableName),n=t.useDashboardStore(c=>c.dashboard.filters)||[],{columns:r}=Z(),{assignFilter:o}=Ut();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(c=>{const i=n==null?void 0:n.find(l=>l.column===t.fmt(c.column_name)&&l.table===a&&l.database===s);return e.jsx("div",{onClick:()=>o(c),className:t.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":i}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ge,{column:c}),e.jsx("span",{children:c.column_name})]})},c.column_name)})})}function Ea(){t.useDashboardStore(a=>a.showFilters);const s=t.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(kt,{type:"filter",ColumnsComponent:()=>e.jsx(Ia,{})})})]})}function Ta(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function Ma(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(Ta,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Ea,{})})]})}function Aa(){const s=t.useDashboardStore(o=>o.dashboard),a=t.useDashboardStore(o=>o.actions.setDashboard),n=t.useDashboardStore(o=>o.showDashboardJSON),r=t.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.de,{onChange:o=>{if(o)try{JSON.parse(o),a(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function La({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(Aa,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(Zs,{}),e.jsx(Da,{}),e.jsx(Ma,{})]})]})]})})}exports.Dashboard=t.Dashboard;exports.DashboardWC=t.DashboardWC;exports.SemaphorDataProvider=t.SemaphorQueryClient;exports.SemaphorQueryClient=t.SemaphorQueryClient;exports.createSqlGenConfig=t.createSqlGenConfig;exports.fmt=t.fmt;exports.getColumnDataType=t.getColumnDataType;exports.getFilterValueType=t.getFilterValueType;exports.getFormattedTableNameForQuery=t.getFormattedTableNameForQuery;exports.getQualifiedTableName=t.getQualifiedTableName;exports.getSql=t.getSql;exports.invalidateToken=t.invalidateToken;exports.isBooleanDataType=t.isBooleanDataType;exports.isColumnInSqlGen=t.isColumnInSqlGen;exports.isDateDataType=t.isDateDataType;exports.isNumberDataType=t.isNumberDataType;exports.isTextDataType=t.isTextDataType;exports.resolveDataType=t.resolveDataType;exports.resolveDatamodelName=t.resolveDatamodelName;exports.useCard=t.useCard;exports.useDashboardActions=t.useDashboardActions;exports.useDashboardStore=t.useDashboardStore;exports.useDateFilterHook=t.useDateFilterHook;exports.useEditorActions=t.useEditorActions;exports.useEditorStore=t.useEditorStore;exports.useTextFilterHook=t.useTextFilterHook;exports.ScheduleDashboard=Nt;exports.SelectComponent=le;exports.Surfboard=La;exports.cleanCard=St;exports.downloadPdf=vt;exports.getDashbaordStateWithoutData=He;exports.useEditorAside=Z;