react-semaphor 0.0.251 → 0.0.252

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.
@@ -28,47 +28,52 @@
28
28
  *
29
29
  * This source code is licensed under the ISC license.
30
30
  * See the LICENSE file in the root directory of this source tree.
31
- */const ms=e.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
31
+ */const ms=e.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
32
32
  * @license lucide-react v0.379.0 - ISC
33
33
  *
34
34
  * This source code is licensed under the ISC license.
35
35
  * See the LICENSE file in the root directory of this source tree.
36
- */const ps=e.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
36
+ */const ps=e.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
37
37
  * @license lucide-react v0.379.0 - ISC
38
38
  *
39
39
  * This source code is licensed under the ISC license.
40
40
  * See the LICENSE file in the root directory of this source tree.
41
- */const js=e.createLucideIcon("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);/**
41
+ */const js=e.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
42
42
  * @license lucide-react v0.379.0 - ISC
43
43
  *
44
44
  * This source code is licensed under the ISC license.
45
45
  * See the LICENSE file in the root directory of this source tree.
46
- */const qe=e.createLucideIcon("GanttChart",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
46
+ */const hs=e.createLucideIcon("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);/**
47
47
  * @license lucide-react v0.379.0 - ISC
48
48
  *
49
49
  * This source code is licensed under the ISC license.
50
50
  * See the LICENSE file in the root directory of this source tree.
51
- */const hs=e.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"}]]);/**
51
+ */const Ve=e.createLucideIcon("GanttChart",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
52
52
  * @license lucide-react v0.379.0 - ISC
53
53
  *
54
54
  * This source code is licensed under the ISC license.
55
55
  * See the LICENSE file in the root directory of this source tree.
56
- */const Es=e.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"}]]);/**
56
+ */const Es=e.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"}]]);/**
57
57
  * @license lucide-react v0.379.0 - ISC
58
58
  *
59
59
  * This source code is licensed under the ISC license.
60
60
  * See the LICENSE file in the root directory of this source tree.
61
- */const fs=e.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
61
+ */const fs=e.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"}]]);/**
62
62
  * @license lucide-react v0.379.0 - ISC
63
63
  *
64
64
  * This source code is licensed under the ISC license.
65
65
  * See the LICENSE file in the root directory of this source tree.
66
- */const gs=e.createLucideIcon("Home",[["path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"y5dka4"}],["polyline",{points:"9 22 9 12 15 12 15 22",key:"e2us08"}]]);/**
66
+ */const gs=e.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
67
67
  * @license lucide-react v0.379.0 - ISC
68
68
  *
69
69
  * This source code is licensed under the ISC license.
70
70
  * See the LICENSE file in the root directory of this source tree.
71
- */const Rs=e.createLucideIcon("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);/**
71
+ */const Rs=e.createLucideIcon("Home",[["path",{d:"m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"y5dka4"}],["polyline",{points:"9 22 9 12 15 12 15 22",key:"e2us08"}]]);/**
72
+ * @license lucide-react v0.379.0 - ISC
73
+ *
74
+ * This source code is licensed under the ISC license.
75
+ * See the LICENSE file in the root directory of this source tree.
76
+ */const bs=e.createLucideIcon("Key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]);/**
72
77
  * @license lucide-react v0.379.0 - ISC
73
78
  *
74
79
  * This source code is licensed under the ISC license.
@@ -78,17 +83,17 @@
78
83
  *
79
84
  * This source code is licensed under the ISC license.
80
85
  * See the LICENSE file in the root directory of this source tree.
81
- */const bs=e.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"}]]);/**
86
+ */const Ss=e.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"}]]);/**
82
87
  * @license lucide-react v0.379.0 - ISC
83
88
  *
84
89
  * This source code is licensed under the ISC license.
85
90
  * See the LICENSE file in the root directory of this source tree.
86
- */const Ss=e.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
91
+ */const ys=e.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
87
92
  * @license lucide-react v0.379.0 - ISC
88
93
  *
89
94
  * This source code is licensed under the ISC license.
90
95
  * See the LICENSE file in the root directory of this source tree.
91
- */const ys=e.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"}]]);/**
96
+ */const vs=e.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"}]]);/**
92
97
  * @license lucide-react v0.379.0 - ISC
93
98
  *
94
99
  * This source code is licensed under the ISC license.
@@ -98,17 +103,17 @@
98
103
  *
99
104
  * This source code is licensed under the ISC license.
100
105
  * See the LICENSE file in the root directory of this source tree.
101
- */const vs=e.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
106
+ */const Cs=e.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
102
107
  * @license lucide-react v0.379.0 - ISC
103
108
  *
104
109
  * This source code is licensed under the ISC license.
105
110
  * See the LICENSE file in the root directory of this source tree.
106
- */const Cs=e.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"}]]);/**
111
+ */const Ns=e.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"}]]);/**
107
112
  * @license lucide-react v0.379.0 - ISC
108
113
  *
109
114
  * This source code is licensed under the ISC license.
110
115
  * See the LICENSE file in the root directory of this source tree.
111
- */const Ve=e.createLucideIcon("Pencil",[["path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z",key:"5qss01"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
116
+ */const qe=e.createLucideIcon("Pencil",[["path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z",key:"5qss01"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/**
112
117
  * @license lucide-react v0.379.0 - ISC
113
118
  *
114
119
  * This source code is licensed under the ISC license.
@@ -118,17 +123,17 @@
118
123
  *
119
124
  * This source code is licensed under the ISC license.
120
125
  * See the LICENSE file in the root directory of this source tree.
121
- */const Ns=e.createLucideIcon("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
126
+ */const ws=e.createLucideIcon("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
122
127
  * @license lucide-react v0.379.0 - ISC
123
128
  *
124
129
  * This source code is licensed under the ISC license.
125
130
  * See the LICENSE file in the root directory of this source tree.
126
- */const ws=e.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0v0Z",key:"nd4hoy"}]]);/**
131
+ */const ks=e.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0v0Z",key:"nd4hoy"}]]);/**
127
132
  * @license lucide-react v0.379.0 - ISC
128
133
  *
129
134
  * This source code is licensed under the ISC license.
130
135
  * See the LICENSE file in the root directory of this source tree.
131
- */const ks=e.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
136
+ */const Ls=e.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
132
137
  * @license lucide-react v0.379.0 - ISC
133
138
  *
134
139
  * This source code is licensed under the ISC license.
@@ -143,7 +148,7 @@
143
148
  *
144
149
  * This source code is licensed under the ISC license.
145
150
  * See the LICENSE file in the root directory of this source tree.
146
- */const Ls=e.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"}]]);/**
151
+ */const Ds=e.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"}]]);/**
147
152
  * @license lucide-react v0.379.0 - ISC
148
153
  *
149
154
  * This source code is licensed under the ISC license.
@@ -158,12 +163,12 @@
158
163
  *
159
164
  * This source code is licensed under the ISC license.
160
165
  * See the LICENSE file in the root directory of this source tree.
161
- */const Ds=e.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"}]]);/**
166
+ */const Ts=e.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"}]]);/**
162
167
  * @license lucide-react v0.379.0 - ISC
163
168
  *
164
169
  * This source code is licensed under the ISC license.
165
170
  * See the LICENSE file in the root directory of this source tree.
166
- */const Ts=e.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"}]]);/**
171
+ */const zs=e.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"}]]);/**
167
172
  * @license lucide-react v0.379.0 - ISC
168
173
  *
169
174
  * This source code is licensed under the ISC license.
@@ -173,7 +178,7 @@
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 zs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function Ie(s){var n;return{...s,sheets:(n=s==null?void 0:s.sheets)==null?void 0:n.map(t=>{var r;return{...t,frames:(r=t.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>Pe(i))}})}})}}function Pe(s){var n,t,r,o;return{...s,cfg:{...s.cfg,data:{...(n=s.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(t=s.cfg)==null?void 0:t.data)==null?void 0:r.datasets)==null?void 0:o.map(l=>({...l,data:[]}))}},customCfg:Fs(s.customCfg),data:[]}}function Fs(s){var n,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(n=s==null?void 0:s.data)==null?void 0:n.datasets)==null?void 0:t.map(r=>({...r,data:[]}))}}:null}async function Os(s,n,t,r){if(!r)return null;const o=JSON.stringify(n),l="https://semaphor.cloud/api/v1/lens";return await e.postRequest(l,r,{name:s,template:o,filterValues:t,operation:"create"})}async function Ne(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:l,shared:i}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,n,{lensId:t,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Ms(s,n){if(!n)return null;const t="https://semaphor.cloud/api/v1/lens";return await e.postRequest(t,n,{operation:"delete",lensId:s})}function qs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(R=>R.lenses),{setLenses:l,setSelectedLensId:i}=e.useDashboardActions(),[a,c]=S.useState(!1),[m,d]=S.useState(!1),h=e.useDashboardStore(R=>R.dashboard),E=e.useDashboardStore(R=>R.filterValues),{authToken:u}=e.useSemaphorContext();async function x(){c(!0);const R=Ie(h),j=await Os(s,R,E,u==null?void 0:u.accessToken);j&&(l([...o||[],j]),i(j.id),d(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:m,onOpenChange:d,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:R=>{n(R.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:x,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Vs(){const[s,n]=S.useState(!1),t=e.useDashboardStore(d=>d.lenses),r=e.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:l}=e.useDashboardActions(),{authToken:i}=e.useSemaphorContext();async function a(d){l(d)}async function c(d){if(await Ms(d,i==null?void 0:i.accessToken)){const E=t==null?void 0:t.filter(u=>u.id!==d);o(E||[]),l("original")}}async function m(d){const h=t==null?void 0:t.map(x=>x.id===d.id?{...x,isDefault:!d.isDefault}:{...x,isDefault:!1});o(h||[]);const E={...d,isDefault:!d.isDefault};await Ne(E,i==null?void 0:i.accessToken);const u=t==null?void 0:t.find(x=>x.isDefault);if(u&&u.id!==d.id){const x={...u,isDefault:!1};await Ne(x,i==null?void 0:i.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(hs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:r,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(d=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between",value:d.id,children:[e.jsxRuntimeExports.jsx("p",{children:d.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(gs,{onClick:h=>{h.preventDefault(),m(d)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:h=>{h.preventDefault(),c(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}function _s(){const{authToken:s}=e.useSemaphorContext(),n=e.useDashboardStore(f=>f.lenses),t=e.useDashboardStore(f=>f.selectedLensId),r=n==null?void 0:n.find(f=>f.id===t),o=e.useDashboardStore(f=>f.dashboard);e.useDashboardStore(f=>f.selectedSheetId);const l=e.useDashboardStore(f=>f.isDashboardEditing),[i,a]=S.useState(!1),c=e.useDashboardStore(f=>f.filterValues),m=e.useDashboardStore(f=>f.isVisualEditing),d=e.useDashboardStore(f=>f.showFilters);e.useDashboardStore(f=>f.showDashboardJSON);const h=e.useDashboardStore(f=>f.onSaveFunction),E=e.useDashboardStore(f=>f.actions.setShowFilters),{addFrame:u,setSelectedFrameId:x}=e.useDashboardStore(f=>f.actions),{getSelectedSheet:R,setIsDashboardEditing:j,setShowDashboardJSON:w}=e.useDashboardStore(f=>f.actions),L=R(),{tenantId:b,endUserId:z}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),T=S.useMemo(()=>b||z,[b,z]),F=()=>{if(!l||!L)return;const f={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},O={id:e.v4(),cards:[f],activeCardId:f.id};u(L.id,O),x(O.id)},k=()=>{j(!0)};async function y(){if(a(!0),!t||!r)return;const f=Ie(o),O=JSON.stringify(f),M={...r,template:O,filterValues:c};await Ne(M,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),h==null||h(f),a(!1)}return m?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!m&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[l&&!m&&T&&e.jsxRuntimeExports.jsx(qs,{}),!m&&T&&e.jsxRuntimeExports.jsx(Vs,{}),l&&!m&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:F,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:k,size:"sm",children:e.jsxRuntimeExports.jsx(Ve,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!m&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{j(!1),w(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!m&&T&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:i,onClick:y,size:"sm",children:e.jsxRuntimeExports.jsx(ks,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&!m&&l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>E(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!m&&l&&!1,!m&&!1]})]})}function ae({title:s,items:n,value:t,isLoading:r,isError:o,connectionTooltip:l,onChange:i,showNone:a=!1,className:c,showIcon:m=!0,disabled:d=!1}){const h=r?"Loading...":o?"Error":t;function E(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ws,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(ms,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Cs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:l?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:E()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:l})]}):E()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:d,value:h,onValueChange:i,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((u,x)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.id,children:u.name},x))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:h,children:h})]})})]})]})}function Bs({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),o=e.useEditorStore(u=>u.selectedSchemaName),l=e.useEditorStore(u=>u.selectedDatamodelId),i=e.useEditorStore(u=>u.sqlGen),{modelItems:a}=oe(),c=e.useEditorStore(u=>u.actions.setSqlGen),m=e.useEditorStore(u=>u.actions.setCardSql),d=e.useEditorStore(u=>u.actions.setRunSql);function h(u,x){var L;const R=e.createSqlGenConfig(u,i,x),j=(L=a==null?void 0:a.find(b=>b.id===l))==null?void 0:L.name;c(R);const w=e.getSql(R,e.fmt(o||""),e.fmt(r),j);w&&(m(w),d(!0)),t(!1)}function E(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>h(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(ps,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:E()})]})}function $e({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(fs,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Ts,{className:"size-3"}):e.jsxRuntimeExports.jsx(Ls,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Hs({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(y=>y.sqlGen),l=e.useEditorStore(y=>y.selectedConnectionId),i=e.useEditorStore(y=>y.selectedDatabaseName),a=e.useEditorStore(y=>y.selectedSchemaName),c=e.useEditorStore(y=>y.selectedTableName),m=e.useEditorStore(y=>y.selectedDatamodelId),d=e.useDashboardStore(y=>y.dashboard.aiScopeTables),{setAIScopeTables:h}=e.useDashboardStore(y=>y.actions),E=e.useEditorStore(y=>y.actions.setRunSql),u=e.useEditorStore(y=>y.actions.setSqlGen),x=e.useEditorStore(y=>y.actions.setIsShowingVisual),R=e.useEditorStore(y=>y.actions.setCardSql),{connectionType:j,modelItems:w}=oe();function L(y){var A;const f=e.createSqlGenConfig(y,o);u(f);const O=(A=w==null?void 0:w.find(q=>q.id===m))==null?void 0:A.name,M=e.getSql(f,e.fmt(s),e.fmt(n),O);M&&(R(M),E(!0))}function b(){return(d==null?void 0:d.find(y=>y.connectinonId===l&&y.tableName===c))!==void 0}function z(y){if(y===!0&&c&&l){const f={connectinonId:l,connectionType:j,databaseName:i,schemaName:a,tableName:c},M=[...d||[],f].filter((A,q,P)=>P.findIndex(_=>_.connectinonId===A.connectinonId&&_.tableName===A.tableName)===q);h(M),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const f=(d||[]).filter(O=>O.connectinonId!==l&&O.tableName!==c);h(f),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function T(){var A;let y=e.getQualifiedTableName(s,n);const f=(A=w==null?void 0:w.find(q=>q.id===m))==null?void 0:A.name;console.log("modelName",f),m&&m!=="none"&&(y=`${e.DATAMODEL_NAMESPCACE}.${f}`);let O=y;return(q=>/[A-Z]/.test(q))(n)&&(O=O.split(".").map(P=>`"${P}"`).join(".")),O}function F(){const y=T();x(!1);const f=j==="MSSQL"?`SELECT top 10 * FROM ${y}`:`SELECT * FROM ${y} LIMIT 10`;R(f),E(!0)}function k(){const y=T();R(`SELECT COUNT(*) as count FROM ${y}`),E(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${b()?"Remove from":"Add to"} AI Scope`,pressed:b(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":b(),"text-muted-foreground":!b()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:F,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(As,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:k,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Is,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(y=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>L(y),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(y,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx($e,{column:y}),e.jsxRuntimeExports.jsx("span",{children:y.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:f=>f.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(y.data_type)&&e.jsxRuntimeExports.jsx(Bs,{column:y})})]},y.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,n){var me,ue,pe,je,p;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(g=>g.selectedConnectionId),l=e.useEditorStore(g=>g.selectedDatamodelId),i=e.useEditorStore(g=>g.selectedDatabaseName),a=e.useEditorStore(g=>g.selectedSchemaName),c=e.useEditorStore(g=>g.selectedTableName),m=e.useEditorStore(g=>g.actions.setCurrentColumns),d=e.useEditorStore(g=>g.actions.setSelectedConnectionId),h=e.useEditorStore(g=>g.actions.setSelectedDatamodelId),E=e.useEditorStore(g=>g.actions.setSelectedDatabaseName),u=e.useEditorStore(g=>g.actions.setSelectedSchemaName),x=e.useEditorStore(g=>g.actions.setSelectedTableName),R=e.useEditorStore(g=>g.actions.setCardSql);function j(g){return o&&i&&a&&i!=="NA"?!0:o&&g==="API"?!1:!!(o&&g==="S3")}function w(g){return!!(o&&i&&i!=="NA"&&a&&c||o&&(g==="S3"||g==="API")||l&&l)}function L(g){return o&&g?!(g==="API"||g==="S3"):!1}const{data:b,isLoading:z,isError:T}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:F,isLoading:k,isError:y}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),f=b==null?void 0:b.connections.find(g=>g.id===o),O=f==null?void 0:f.type,M=(f==null?void 0:f.type)==="API"||(f==null?void 0:f.type)==="S3",{data:A,isLoading:q,isFetching:P,isError:_,refetch:K}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:L(O)}),{data:V,isLoading:W,isFetching:v,isError:I,refetch:H}=e.useQuery({queryKey:["schemas",o,i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!M&&i!=="NA"}),{data:N,isLoading:C,isFetching:$,isError:D,refetch:G}=e.useQuery({queryKey:["tables",o,i,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:a}),enabled:j(O)}),{data:U,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",o,i,l,a,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:i,schema_name:a,table_name:c}),enabled:w(O)});S.useEffect(()=>{m(t)},[U,m,t]),S.useEffect(()=>{},[M,R,x,u,E,f]);const J=(f==null?void 0:f.type)==="API"?(me=f==null?void 0:f.type)==null?void 0:me.toLowerCase():c||"",Y=M?"":a||"";function ne(g){u(g),x("")}function Z(g){E(g==="none"?"":g),u(""),x(""),g!=="none"&&g!==""&&h("")}function se(g){d(g)}function De(g){h(g==="none"?"":g),g!=="none"&&g!==""&&E("")}A&&((ue=A==null?void 0:A.databases)==null?void 0:ue.length)>0,V&&((pe=V==null?void 0:V.schemas)==null?void 0:pe.length)>0,U&&((je=U==null?void 0:U.columns)==null?void 0:je.length)>0&&(t=U.columns.map(g=>({...g,data_type:g.data_type.toLowerCase()}))),_&&(t=[]),(B||T)&&(t=[]);const ie=b==null?void 0:b.connections.map(g=>({id:g.id,name:g.name,type:g.type})),be=(p=F==null?void 0:F.datamodels)==null?void 0:p.map(g=>({id:g.id,name:g.name})),de=A==null?void 0:A.databases.map(g=>({id:g.database_name,name:g.database_name})),Se=V==null?void 0:V.schemas.map(g=>({id:g.schema_name,name:g.schema_name})),ye=N==null?void 0:N.tables.map(g=>({id:g.table_name,name:g.table_name}));return{connectionItems:ie,isConnectionsLoading:z,isConnectionsError:T,modelItems:be,isModelsLoading:k,isModelsError:y,databaseItems:de,isDatabasesLoadingOrFetching:q||P,isDatabaseError:_,schemaItems:Se,isSchemaLoadingOrFetching:W||v,isSchemaError:I,tableItems:ye,isTableLoadingOrFetching:C||$,isTableError:D,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:M,connectionType:O,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:De,handleDatabaseChange:Z,handleSchemaChange:ne}}function Ge({ColumnsComponent:s}){var $;const n=e.useEditorStore(D=>D.selectedConnectionId),t=e.useEditorStore(D=>D.selectedDatamodelId),r=e.useEditorStore(D=>D.selectedDatabaseName),o=e.useEditorStore(D=>D.selectedSchemaName),l=e.useEditorStore(D=>D.selectedTableName),i=e.useEditorStore(D=>D.actions.setSelectedTableName),{connectionItems:a,modelItems:c,schemaItems:m,databaseItems:d,tableItems:h,columns:E,isConnectionsLoading:u,isModelsLoading:x,isConnectionsError:R,isModelsError:j,isDatabasesLoadingOrFetching:w,isDatabaseError:L,isSchemaLoadingOrFetching:b,isSchemaError:z,isColumnsError:T,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:k,isTableError:y,connectionType:f,isNonDbConnection:O,handleConnectionChange:M,handleDatabaseChange:A,handleSchemaChange:q,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function V(){return s?s(K,_,E):e.jsxRuntimeExports.jsx(Hs,{schemaName:K,tableName:_,columns:E,status:F?"Loading...":T?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function v(){if(!n||f==="S3"||f==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:A,isError:L,isLoading:w,items:d,value:r||"",title:"Database"})}function I(){if(n&&!O&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function H(){if(!n||f==="S3"||f==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:P,isError:j,isLoading:x,items:c,value:t||"",title:"Model"})}function N(){return!n||f==="S3"||f==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ae,{onChange:q,isError:z,isLoading:b,items:m,value:o||"",title:"Schema"})}function C(){function D(){let G=!1;return f==="API"?(G=!1,G):((f==="S3"||n&&r&&r!=="none"&&o)&&(G=!0),G)}return D()?e.jsxRuntimeExports.jsx(ae,{onChange:i,isError:y,items:h,isLoading:k,value:l||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ae,{items:a,title:"Connection",value:n||"",onChange:M,isLoading:u,isError:R,connectionTooltip:(($=a==null?void 0:a.find(D=>D.id===n))==null?void 0:$.type)||""}),H(),I(),v(),N(),C()]}),V(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(vs,{className:"mr-2 size-4"}),"Help"]})})]})}function Ps(s){const n=s.toUpperCase().indexOf("WHERE"),t=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),n!==-1){const i=s.substring(0,n),a=s.substring(n);return`${i} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const i=s.substring(0,t),a=s.substring(t);return`${i} {{ filters | where }} ${a}`}else{const i=s.substring(0,l),a=s.substring(l);return`${i} {{ filters | where }} ${a}`}}function $s({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(ds,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Es,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Gs({text:s,onCheckedChange:n,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:n}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Us(){const{authToken:s}=e.useSemaphorContext(),n=e.useEditorStore(l=>l.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),r=t==null?void 0:t.connections.find(l=>l.id===n);return r==null?void 0:r.type}function Qs(){const{authToken:s}=e.useSemaphorContext(),n=S.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[r,o]=S.useState(""),l=e.useEditorStore(c=>c.filterValues),i=e.useEditorStore(c=>c.card.sql),a=Us();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const m=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:i,active_filters:l,connection_type:a});console.log(m),m.sql?(console.log(m.records),o(m.sql)):o("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Ks=`
181
+ */const Fs=e.createLucideIcon("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function De(s){var n;return{...s,sheets:(n=s==null?void 0:s.sheets)==null?void 0:n.map(t=>{var r;return{...t,frames:(r=t.frames)==null?void 0:r.map(o=>{var l;return{...o,cards:(l=o.cards)==null?void 0:l.map(i=>Pe(i))}})}})}}function Pe(s){var n,t,r,o;return{...s,cfg:{...s.cfg,data:{...(n=s.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(t=s.cfg)==null?void 0:t.data)==null?void 0:r.datasets)==null?void 0:o.map(l=>({...l,data:[]}))}},customCfg:Os(s.customCfg),data:[]}}function Os(s){var n,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(n=s==null?void 0:s.data)==null?void 0:n.datasets)==null?void 0:t.map(r=>({...r,data:[]}))}}:null}async function Ms(s,n,t,r){if(!r)return null;const o=JSON.stringify(n),l="https://semaphor.cloud/api/v1/lens";return await e.postRequest(l,r,{name:s,template:o,filterValues:t,operation:"create"})}async function Ne(s,n){if(!n)return null;const{id:t,template:r,filterValues:o,isDefault:l,shared:i}=s,a="https://semaphor.cloud/api/v1/lens";return await e.postRequest(a,n,{lensId:t,template:r,filterValues:o,isDefault:l,shared:i,operation:"update"})}async function Vs(s,n){if(!n)return null;const t="https://semaphor.cloud/api/v1/lens";return await e.postRequest(t,n,{operation:"delete",lensId:s})}function qs(){const[s,n]=S.useState(""),[t,r]=S.useState(!1),o=e.useDashboardStore(R=>R.lenses),{setLenses:l,setSelectedLensId:i}=e.useDashboardActions(),[a,c]=S.useState(!1),[m,d]=S.useState(!1),E=e.useDashboardStore(R=>R.dashboard),f=e.useDashboardStore(R=>R.filterValues),{authToken:u}=e.useSemaphorContext();async function x(){c(!0);const R=De(E),L=await Ms(s,R,f,u==null?void 0:u.accessToken);L&&(l([...o||[],L]),i(L.id),d(!1)),c(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:m,onOpenChange:d,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Create Lens"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsxRuntimeExports.jsx("div",{className:"grid gap-4 py-4",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-right",children:"Name"}),e.jsxRuntimeExports.jsx(e.Input,{value:s,onChange:R=>{n(R.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),t&&e.jsxRuntimeExports.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsxRuntimeExports.jsx(e.DialogFooter,{children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",type:"submit",onClick:x,disabled:a,children:a?"Creating...":"Add"})})]})]})}function _s(){const[s,n]=S.useState(!1),t=e.useDashboardStore(d=>d.lenses),r=e.useDashboardStore(d=>d.selectedLensId),{setLenses:o,setSelectedLensId:l}=e.useDashboardActions(),{authToken:i}=e.useSemaphorContext();async function a(d){l(d)}async function c(d){if(await Vs(d,i==null?void 0:i.accessToken)){const f=t==null?void 0:t.filter(u=>u.id!==d);o(f||[]),l("original")}}async function m(d){const E=t==null?void 0:t.map(x=>x.id===d.id?{...x,isDefault:!d.isDefault}:{...x,isDefault:!1});o(E||[]);const f={...d,isDefault:!d.isDefault};await Ne(f,i==null?void 0:i.accessToken);const u=t==null?void 0:t.find(x=>x.isDefault);if(u&&u.id!==d.id){const x={...u,isDefault:!1};await Ne(x,i==null?void 0:i.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsxRuntimeExports.jsx(Es,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxRuntimeExports.jsxs(e.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsxRuntimeExports.jsx(e.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsxRuntimeExports.jsx(e.DropdownMenuSeparator,{}),e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioGroup,{value:r,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(d=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between",value:d.id,children:[e.jsxRuntimeExports.jsx("p",{children:d.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(Rs,{onClick:E=>{E.preventDefault(),m(d)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:E=>{E.preventDefault(),c(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}function Bs(){const{authToken:s}=e.useSemaphorContext(),n=e.useDashboardStore(h=>h.lenses),t=e.useDashboardStore(h=>h.selectedLensId),r=n==null?void 0:n.find(h=>h.id===t),o=e.useDashboardStore(h=>h.dashboard);e.useDashboardStore(h=>h.selectedSheetId);const l=e.useDashboardStore(h=>h.isDashboardEditing),[i,a]=S.useState(!1),c=e.useDashboardStore(h=>h.filterValues),m=e.useDashboardStore(h=>h.isVisualEditing),d=e.useDashboardStore(h=>h.showFilters);e.useDashboardStore(h=>h.showDashboardJSON);const E=e.useDashboardStore(h=>h.onSaveFunction),f=e.useDashboardStore(h=>h.actions.setShowFilters),{addFrame:u,setSelectedFrameId:x}=e.useDashboardStore(h=>h.actions),{getSelectedSheet:R,setIsDashboardEditing:L,setShowDashboardJSON:I}=e.useDashboardStore(h=>h.actions),O=R(),{tenantId:y,endUserId:z}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),j=S.useMemo(()=>y||z,[y,z]),k=()=>{if(!l||!O)return;const h={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},F={id:e.v4(),cards:[h],activeCardId:h.id};u(O.id,F),x(F.id)},C=()=>{L(!0)};async function b(){if(a(!0),!t||!r)return;const h=De(o),F=JSON.stringify(h),M={...r,template:F,filterValues:c};await Ne(M,s==null?void 0:s.accessToken),e.Jt.success("Lens saved"),E==null||E(h),a(!1)}return m?null:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-2 border-b bg-muted/50 py-2 pl-3 pr-2",role:"dashboard-controls",children:[!m&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:r==null?void 0:r.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[l&&!m&&j&&e.jsxRuntimeExports.jsx(qs,{}),!m&&j&&e.jsxRuntimeExports.jsx(_s,{}),l&&!m&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!l,onClick:k,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!l&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:C,size:"sm",children:e.jsxRuntimeExports.jsx(qe,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!m&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{L(!1),I(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),l&&!m&&j&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:i,onClick:b,size:"sm",children:e.jsxRuntimeExports.jsx(Ls,{className:"h-4 w-4",strokeWidth:1.5})}),!d&&!m&&l&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>f(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!m&&l&&!1,!m&&!1]})]})}function ae({title:s,items:n,value:t,isLoading:r,isError:o,connectionTooltip:l,onChange:i,showNone:a=!1,className:c,showIcon:m=!0,disabled:d=!1}){const E=r?"Loading...":o?"Error":t;function f(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ks,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(ps,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(Ns,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:l?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:f()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:l})]}):f()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:d,value:E,onValueChange:i,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",c),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[r?e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Loading..."}):e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[a&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((u,x)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.id,children:u.name},x))]}),(r||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:E,children:E})]})})]})]})}function Hs({column:s}){const[n,t]=S.useState(!1),r=e.useEditorStore(u=>u.selectedTableName),o=e.useEditorStore(u=>u.selectedSchemaName),l=e.useEditorStore(u=>u.selectedDatamodelId),i=e.useEditorStore(u=>u.sqlGen),{modelItems:a}=oe(),c=e.useEditorStore(u=>u.actions.setSqlGen),m=e.useEditorStore(u=>u.actions.setCardSql),d=e.useEditorStore(u=>u.actions.setRunSql);function E(u,x){var O;const R=e.createSqlGenConfig(u,i,x),L=(O=a==null?void 0:a.find(y=>y.id===l))==null?void 0:O.name;c(R);const I=e.getSql(R,e.fmt(o||""),e.fmt(r),L);I&&(m(I),d(!0)),t(!1)}function f(){return e.jsxRuntimeExports.jsxs("ul",{className:"text-xs",children:[e.jsxRuntimeExports.jsx("li",{onClick:()=>E(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>E(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>E(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>E(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsxRuntimeExports.jsx("li",{onClick:()=>E(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,open:n,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(js,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:f()})]})}function $e({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.$a093c7e1ec25a057$export$8c610744efcf8a1d,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(Le,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(gs,{className:"size-3"}):e.DATE_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(e.Calendar,{className:"size-3"}):e.BOOLEAN_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(zs,{className:"size-3"}):e.jsxRuntimeExports.jsx(Ds,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ps({schemaName:s,tableName:n,columns:t,status:r}){const o=e.useEditorStore(b=>b.sqlGen),l=e.useEditorStore(b=>b.selectedConnectionId),i=e.useEditorStore(b=>b.selectedDatabaseName),a=e.useEditorStore(b=>b.selectedSchemaName),c=e.useEditorStore(b=>b.selectedTableName),m=e.useEditorStore(b=>b.selectedDatamodelId),d=e.useDashboardStore(b=>b.dashboard.aiScopeTables),{setAIScopeTables:E}=e.useDashboardStore(b=>b.actions),f=e.useEditorStore(b=>b.actions.setRunSql),u=e.useEditorStore(b=>b.actions.setSqlGen),x=e.useEditorStore(b=>b.actions.setIsShowingVisual),R=e.useEditorStore(b=>b.actions.setCardSql),{connectionType:L,modelItems:I}=oe();function O(b){var A;const h=e.createSqlGenConfig(b,o);u(h);const F=(A=I==null?void 0:I.find(V=>V.id===m))==null?void 0:A.name,M=e.getSql(h,e.fmt(s),e.fmt(n),F);M&&(R(M),f(!0))}function y(){return(d==null?void 0:d.find(b=>b.connectinonId===l&&b.tableName===c))!==void 0}function z(b){if(b===!0&&c&&l){const h={connectinonId:l,connectionType:L,databaseName:i,schemaName:a,tableName:c},M=[...d||[],h].filter((A,V,P)=>P.findIndex(_=>_.connectinonId===A.connectinonId&&_.tableName===A.tableName)===V);E(M),e.Jt.success(`Added '${c}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const h=(d||[]).filter(F=>F.connectinonId!==l&&F.tableName!==c);E(h),e.Jt(`Removed '${c}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function j(){var A;let b=e.getQualifiedTableName(s,n);const h=(A=I==null?void 0:I.find(V=>V.id===m))==null?void 0:A.name;console.log("modelName",h),m&&m!=="none"&&(b=`${e.DATAMODEL_NAMESPCACE}.${h}`);let F=b;return(V=>/[A-Z]/.test(V))(n)&&(F=F.split(".").map(P=>`"${P}"`).join(".")),F}function k(){const b=j();x(!1);const h=L==="MSSQL"?`SELECT top 10 * FROM ${b}`:`SELECT * FROM ${b} LIMIT 10`;R(h),f(!0)}function C(){const b=j();R(`SELECT COUNT(*) as count FROM ${b}`),f(!0)}return e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsxRuntimeExports.jsx(e.Toggle,{title:`${y()?"Remove from":"Add to"} AI Scope`,pressed:y(),onPressedChange:z,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":y(),"text-muted-foreground":!y()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:k,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(As,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:r!=="Success",onClick:C,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Is,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"flex-1 basis-0 overflow-y-auto border-b border-t border-muted py-3",children:[t==null?void 0:t.map(b=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>O(b),className:e.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":e.isColumnInSqlGen(b,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx($e,{column:b}),e.jsxRuntimeExports.jsx("span",{children:b.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:h=>h.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(b.data_type)&&e.jsxRuntimeExports.jsx(Hs,{column:b})})]},b.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function oe(s,n){var me,ue,pe,je,p;let t=S.useMemo(()=>[],[]);const r=e.useSemaphorContext().authToken||s,o=e.useEditorStore(g=>g.selectedConnectionId),l=e.useEditorStore(g=>g.selectedDatamodelId),i=e.useEditorStore(g=>g.selectedDatabaseName),a=e.useEditorStore(g=>g.selectedSchemaName),c=e.useEditorStore(g=>g.selectedTableName),m=e.useEditorStore(g=>g.actions.setCurrentColumns),d=e.useEditorStore(g=>g.actions.setSelectedConnectionId),E=e.useEditorStore(g=>g.actions.setSelectedDatamodelId),f=e.useEditorStore(g=>g.actions.setSelectedDatabaseName),u=e.useEditorStore(g=>g.actions.setSelectedSchemaName),x=e.useEditorStore(g=>g.actions.setSelectedTableName),R=e.useEditorStore(g=>g.actions.setCardSql);function L(g){return o&&i&&a&&i!=="NA"?!0:o&&g==="API"?!1:!!(o&&g==="S3")}function I(g){return!!(o&&i&&i!=="NA"&&a&&c||o&&(g==="S3"||g==="API")||l&&l)}function O(g){return o&&g?!(g==="API"||g==="S3"):!1}const{data:y,isLoading:z,isError:j}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{data:k,isLoading:C,isError:b}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),h=y==null?void 0:y.connections.find(g=>g.id===o),F=h==null?void 0:h.type,M=(h==null?void 0:h.type)==="API"||(h==null?void 0:h.type)==="S3",{data:A,isLoading:V,isFetching:P,isError:_,refetch:K}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:O(F)}),{data:q,isLoading:W,isFetching:v,isError:D,refetch:H}=e.useQuery({queryKey:["schemas",o,i],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i}),enabled:!!o&&!!i&&!M&&i!=="NA"}),{data:w,isLoading:N,isFetching:$,isError:T,refetch:G}=e.useQuery({queryKey:["tables",o,i,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:i,schema_name:a}),enabled:L(F)}),{data:U,isLoading:te,isFetching:ee,isError:B}=e.useQuery({queryKey:["columns",o,i,l,a,c],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:l||"",database_name:i,schema_name:a,table_name:c}),enabled:I(F)});S.useEffect(()=>{m(t)},[U,m,t]),S.useEffect(()=>{},[M,R,x,u,f,h]);const J=(h==null?void 0:h.type)==="API"?(me=h==null?void 0:h.type)==null?void 0:me.toLowerCase():c||"",Y=M?"":a||"";function ne(g){u(g),x("")}function Z(g){f(g==="none"?"":g),u(""),x(""),g!=="none"&&g!==""&&E("")}function se(g){d(g)}function Ae(g){E(g==="none"?"":g),g!=="none"&&g!==""&&f("")}A&&((ue=A==null?void 0:A.databases)==null?void 0:ue.length)>0,q&&((pe=q==null?void 0:q.schemas)==null?void 0:pe.length)>0,U&&((je=U==null?void 0:U.columns)==null?void 0:je.length)>0&&(t=U.columns.map(g=>({...g,data_type:g.data_type.toLowerCase()}))),_&&(t=[]),(B||j)&&(t=[]);const ie=y==null?void 0:y.connections.map(g=>({id:g.id,name:g.name,type:g.type})),be=(p=k==null?void 0:k.datamodels)==null?void 0:p.map(g=>({id:g.id,name:g.name})),de=A==null?void 0:A.databases.map(g=>({id:g.database_name,name:g.database_name})),Se=q==null?void 0:q.schemas.map(g=>({id:g.schema_name,name:g.schema_name})),ye=w==null?void 0:w.tables.map(g=>({id:g.table_name,name:g.table_name}));return{connectionItems:ie,isConnectionsLoading:z,isConnectionsError:j,modelItems:be,isModelsLoading:C,isModelsError:b,databaseItems:de,isDatabasesLoadingOrFetching:V||P,isDatabaseError:_,schemaItems:Se,isSchemaLoadingOrFetching:W||v,isSchemaError:D,tableItems:ye,isTableLoadingOrFetching:N||$,isTableError:T,columns:t,isColumnsLoadingOrFetching:te||ee,isColumnsError:B,isNonDbConnection:M,connectionType:F,tableName:J,schemaName:Y,handleConnectionChange:se,handleDatamodelChange:Ae,handleDatabaseChange:Z,handleSchemaChange:ne}}function Ge({ColumnsComponent:s}){var $;const n=e.useEditorStore(T=>T.selectedConnectionId),t=e.useEditorStore(T=>T.selectedDatamodelId),r=e.useEditorStore(T=>T.selectedDatabaseName),o=e.useEditorStore(T=>T.selectedSchemaName),l=e.useEditorStore(T=>T.selectedTableName),i=e.useEditorStore(T=>T.actions.setSelectedTableName),{connectionItems:a,modelItems:c,schemaItems:m,databaseItems:d,tableItems:E,columns:f,isConnectionsLoading:u,isModelsLoading:x,isConnectionsError:R,isModelsError:L,isDatabasesLoadingOrFetching:I,isDatabaseError:O,isSchemaLoadingOrFetching:y,isSchemaError:z,isColumnsError:j,isColumnsLoadingOrFetching:k,isTableLoadingOrFetching:C,isTableError:b,connectionType:h,isNonDbConnection:F,handleConnectionChange:M,handleDatabaseChange:A,handleSchemaChange:V,handleDatamodelChange:P,tableName:_,schemaName:K}=oe();function q(){return s?s(K,_,f):e.jsxRuntimeExports.jsx(Ps,{schemaName:K,tableName:_,columns:f,status:k?"Loading...":j?"Error":"Success"})}function W(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function v(){if(!n||h==="S3"||h==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:A,isError:O,isLoading:I,items:d,value:r||"",title:"Database"})}function D(){if(n&&!F&&(!r||r==="none")&&(!t||t==="none"))return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Label,{children:"OR"})}),e.jsxRuntimeExports.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsxRuntimeExports.jsx(e.Separator,{})})]})}function H(){if(!n||h==="S3"||h==="API")return null;if(!r||r==="none")return e.jsxRuntimeExports.jsx(ae,{showNone:!0,onChange:P,isError:L,isLoading:x,items:c,value:t||"",title:"Model"})}function w(){return!n||h==="S3"||h==="API"||!r||r==="none"?null:e.jsxRuntimeExports.jsx(ae,{onChange:V,isError:z,isLoading:y,items:m,value:o||"",title:"Schema"})}function N(){function T(){let G=!1;return h==="API"?(G=!1,G):((h==="S3"||n&&r&&r!=="none"&&o)&&(G=!0),G)}return T()?e.jsxRuntimeExports.jsx(ae,{onChange:i,isError:b,items:E,isLoading:C,value:l||"",title:"Table"}):null}return e.jsxRuntimeExports.jsxs("aside",{className:"xbg-red-100 flex grow flex-col justify-between",children:[e.jsxRuntimeExports.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsxRuntimeExports.jsx(ae,{items:a,title:"Connection",value:n||"",onChange:M,isLoading:u,isError:R,connectionTooltip:(($=a==null?void 0:a.find(T=>T.id===n))==null?void 0:$.type)||""}),H(),D(),v(),w(),N()]}),q(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:W,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(Cs,{className:"mr-2 size-4"}),"Help"]})})]})}function $s(s){const n=s.toUpperCase().indexOf("WHERE"),t=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),n!==-1){const i=s.substring(0,n),a=s.substring(n);return`${i} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const i=s.substring(0,t),a=s.substring(t);return`${i} {{ filters | where }} ${a}`}else{const i=s.substring(0,l),a=s.substring(l);return`${i} {{ filters | where }} ${a}`}}function Gs({error:s,setShowAIDialog:n,setUserInputforAI:t,setTriggerAIRun:r}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"h-5 p-0",children:e.jsxRuntimeExports.jsx(ds,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"min-w-fit max-w-[500px]",children:e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll",children:e.jsxRuntimeExports.jsx("p",{className:"overflow-auto rounded-md bg-muted p-2 text-xs leading-relaxed",children:s})}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:()=>{n(!0),t(s),r(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(fs,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}function Us({text:s,onCheckedChange:n,checked:t}){return e.jsxRuntimeExports.jsxs("div",{className:"xbg-red-100 ml-6 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:t,onCheckedChange:n}),e.jsxRuntimeExports.jsx("label",{className:"text-xs leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:s})]})}function Qs(){const{authToken:s}=e.useSemaphorContext(),n=e.useEditorStore(l=>l.selectedConnectionId),{data:t}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(s==null?void 0:s.accessToken)||""),enabled:!!(s!=null&&s.accessToken)}),r=t==null?void 0:t.connections.find(l=>l.id===n);return r==null?void 0:r.type}function Ks(){const{authToken:s}=e.useSemaphorContext(),n=S.useRef(null),t=e.useEditorStore(c=>c.applyFilters),[r,o]=S.useState(""),l=e.useEditorStore(c=>c.filterValues),i=e.useEditorStore(c=>c.card.sql),a=Qs();return e.jsxRuntimeExports.jsxs(e.HoverCard,{openDelay:0,onOpenChange:async c=>{if(!c)return;console.log("onOpenChange");const m=await e.postRequest("https://semaphor.cloud/api/v1/filter-sql",(s==null?void 0:s.accessToken)||"",{sql:i,active_filters:l,connection_type:a});console.log(m),m.sql?(console.log(m.records),o(m.sql)):o("Error")},children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:t&&e.jsxRuntimeExports.jsx("p",{className:"p-0 text-xs hover:cursor-pointer",children:"|  Filter Query"})}),e.jsxRuntimeExports.jsxs(e.HoverCardContent,{align:"end",className:"w-[600px]",children:[e.jsxRuntimeExports.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-sm bg-muted p-2",children:e.jsxRuntimeExports.jsxs("code",{ref:n,className:"font-mono text-sm",children:[r,e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{onClick:()=>e.copyToClipboard(n),className:"ml-3 inline-block h-4 w-4 opacity-70 hover:cursor-pointer hover:opacity-100"})]})})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxRuntimeExports.jsx(e.InfoCircledIcon,{className:"h-4 w-4 opacity-70"}),e.jsxRuntimeExports.jsx("span",{className:"text-xs text-muted-foreground",children:"A preview of the query with filters applied."})]})]})]})}const Ws=`
177
182
 
178
183
  Use the following syntax to create a chart query. Please replace the x-axis, y-axis, stack-by, label, and measure with the actual column names of the table.
179
184
 
@@ -219,12 +224,12 @@ SELECT label, measure FROM table
219
224
 
220
225
  - Label - Category
221
226
  - Measure - Number
222
- `;function Ws({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:o,setTriggerAIRun:l}){const i=S.useRef(null),a=S.useRef(null),{authToken:c}=e.useSemaphorContext(),[m,d]=S.useState(!1),h=e.useEditorStore(v=>v.actions.setCardSql),E=e.useDashboardStore(v=>v.dashboard.baseQueries),u=e.useEditorStore(v=>v.actions.setRunSql),x=e.useEditorStore(v=>v.actions.setCardType),[R,j]=S.useState([]),w=e.useEditorStore(v=>v.currentColumns),L=e.useEditorStore(v=>v.card.sql),b=e.useEditorStore(v=>v.selectedTableName),z=`
227
+ `;function Js({open:s,setOpen:n,userInput:t,setUserInput:r,triggerAIRun:o,setTriggerAIRun:l}){const i=S.useRef(null),a=S.useRef(null),{authToken:c}=e.useSemaphorContext(),[m,d]=S.useState(!1),E=e.useEditorStore(v=>v.actions.setCardSql),f=e.useDashboardStore(v=>v.dashboard.baseQueries),u=e.useEditorStore(v=>v.actions.setRunSql),x=e.useEditorStore(v=>v.actions.setCardType),[R,L]=S.useState([]),I=e.useEditorStore(v=>v.currentColumns),O=e.useEditorStore(v=>v.card.sql),y=e.useEditorStore(v=>v.selectedTableName),z=`
223
228
  ${t}
224
229
 
225
- Database Query Dialect: ${b==="api"||b==="s3"?"DuckDb":""}
226
- Table Name: ${b}
227
- Table Columns: ${w==null?void 0:w.map(v=>`${v.column_name} | ${v.data_type}`).join(", ")}
228
- User SQL: ${L}
229
- ${E&&`Base Queries: ${JSON.stringify(E)} `}`,T=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
230
- Visual Query Syntax: ${Ks}`,{data:F,isLoading:k,isFetching:y,isError:f,refetch:O}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${z} ${m?T:""}`}),enabled:!1});function M(v){if(v.toLowerCase().includes("bar"))x("bar");else if(v.toLowerCase().includes("line"))x("line");else if(v.toLowerCase().includes("bubble"))x("bubble");else if(v.toLowerCase().includes("scatter"))x("scatter");else if(v.toLowerCase().includes("stacked"))x("stackedBar");else if(v.toLowerCase().includes("pie"))x("pie");else if(v.toLowerCase().includes("donut")||v.toLowerCase().includes("doughnut"))x("doughnut");else if(v.toLowerCase().includes("radar"))x("radar");else return x("bar"),!1;return!0}S.useEffect(()=>{F&&j(v=>[...v,{role:"ai",content:F.response}])},[F]),S.useEffect(()=>{const v=setTimeout(()=>{var I;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(I=i.current)==null||I.focus())},100);return()=>clearTimeout(v)},[R]);function A(){t&&(j(v=>[...v,{role:"user",content:t}]),M(t)&&d(!0),r(""),O())}S.useEffect(()=>{o&&(A(),l(!1))},[o,l]);const q={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},P={fontFamily:"monospace",fontSize:14,lineHeight:1.6},_={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:v,...I})=>e.jsxRuntimeExports.jsx("p",{style:q,...I}),code:({node:v,...I})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...I}),pre:({node:v,...I})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:P,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:I.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:V,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:H=>{const N=V(H);N&&(n(!1),h(N),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:v,...I})=>e.jsxRuntimeExports.jsx("li",{style:_,...I})};function V(v){const I=v.currentTarget.closest("pre");if(!I)return;const H=I.textContent||I.innerText;return navigator.clipboard.writeText(H).then(()=>console.log("Text copied to clipboard")).catch(N=>console.error("Error in copying text: ",N)),H}function W(){return R==null?void 0:R.map((v,I)=>v.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(zs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:v.content})]},I):v.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:F==null?void 0:F.response.replace(/DuckDB/gi,"Semaphor")},I):e.jsxRuntimeExports.jsx("div",{},I))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:W()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:i,onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),r(""),A())},placeholder:"Type your question here...",onFocus:v=>{const I=v.target,H=I.value.length;I.setSelectionRange(H,H)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:k||y,value:t,onChange:v=>r(v.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:A,children:!k&&!y?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Ue={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ze=S.createContext&&S.createContext(Ue),Js=["attr","size","title"];function Ys(s,n){if(s==null)return{};var t=Zs(s,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Zs(s,n){if(s==null)return{};var t={},r=Object.keys(s),o,l;for(l=0;l<r.length;l++)o=r[l],!(n.indexOf(o)>=0)&&(t[o]=s[o]);return t}function fe(){return fe=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},fe.apply(this,arguments)}function Fe(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function ge(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Fe(Object(t),!0).forEach(function(r){Xs(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Fe(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function Xs(s,n,t){return n=et(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function et(s){var n=st(s,"string");return typeof n=="symbol"?n:String(n)}function st(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function Qe(s){return s&&s.map((n,t)=>S.createElement(n.tag,ge({key:t},n.attr),Qe(n.child)))}function X(s){return n=>S.createElement(tt,fe({attr:ge({},s.attr)},n),Qe(s.child))}function tt(s){var n=t=>{var{attr:r,size:o,title:l}=s,i=Ys(s,Js),a=o||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,i,{className:c,style:ge(ge({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),l&&S.createElement("title",null,l),s.children)};return ze!==void 0?S.createElement(ze.Consumer,null,t=>n(t)):n(Ue)}function nt(s){return X({tag:"svg",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 rt(){const{theme:s}=e.useTheme(),n=S.useRef(),t=S.useRef(),[r,o]=S.useState(!1),[l,i]=S.useState(!1),[a,c]=S.useState(!1),[m,d]=S.useState(""),[h,E]=S.useState(!1),{authToken:u}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const x=e.useDashboardStore(p=>p.dashboard.baseQueries),R=e.useEditorStore(p=>p.card),j=e.useDashboardStore(p=>p.theme),w=e.useEditorStore(p=>p.isShowingVisual);e.useDashboardStore(p=>p.onAcceptChanges);const L=e.useEditorStore(p=>p.selectedConnectionId),b=e.useEditorStore(p=>p.selectedDatabaseName),z=e.useEditorStore(p=>p.selectedDatamodelId),T=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const F=e.useEditorStore(p=>p.selectedTableName),k=e.useEditorStore(p=>p.card.sql),y=e.useEditorStore(p=>p.card.python),f=e.resolveBaseQuery(k,x),O=e.useEditorStore(p=>p.selectedConnectionId),M=e.useEditorStore(p=>p.frame),A=e.useDashboardStore(p=>p.filterValues),q=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:P,setQueryResultColumns:_,setFilterValues:K,setCardSql:V,setCardPython:W,setQueryError:v,setPythonStdOut:I,setCardPreferences:H}=e.useEditorStore(p=>p.actions),N=e.useEditorStore(p=>p.onSave),C=e.useEditorStore(p=>p.actions.setApplyFilters),$=e.useEditorStore(p=>p.onClose),D=e.useEditorStore(p=>p.actions.setCardData),G=e.useEditorStore(p=>p.actions.setSqlGen),U=e.useEditorStore(p=>p.runSql),te=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:J,isFetching:Y,isSuccess:ne,isError:Z,error:se,status:De,refetch:ie}=e.useQuery({queryKey:[f,y],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(u==null?void 0:u.accessToken)||"",{connection_id:O,sql:f,python:y===e.PYTHON_DEFAULT_CODE?"":y,active_filters:q?A:[]}),enabled:!1,retry:!1});S.useEffect(()=>{if(B&&(D(B.records),B.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),I((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);_(p)}},[B,D,_,I]),S.useEffect(()=>{U&&(ie(),te(!1))},[U,ie,te]),S.useEffect(()=>{(J||Y)&&ee(!0),(Z||ne)&&ee(!1),Z?(v(se.message),D([]),_([]),I("")):v("")},[J,Y,B,I,Z,ne,ee,D,_,v,se]);function be(){V(""),D([]),G({}),P(""),H({})}const de=p=>{t.current=p};function Se(p,g){if(p.length===0)return"";if(g){const re=p.find(Q=>Q.id===g);if(re){const Q=re.tabTitle;if(Q=="All__Header")return p[0].id;if(Q&&Q.endsWith("__Header")){const is=Q.split("__")[0],Te=p.find(as=>as.tabTitle===is);return Te?Te.id:p[0].id}return g}}return p[0].id}function ye(){let p=k;k&&!k.includes("{{")&&(p=Ps(k),V(p));const g={...R,lastSelectedSchema:T,lastSelectedDatamodelId:z,lastSelectedDatabase:b,lastSelectedTable:F,connectionId:L,type:w?R.type:"table",sql:p,customCfg:w?R.customCfg:null},re=M.cards.map(ve=>ve.id===R.id?g:ve),Q={...M,cards:re,activeCardId:Se(re,M.activeCardId)};N==null||N(Q)}function me(){$==null||$()}S.useEffect(()=>{const p=n.current,g=t.current;if(p){const re=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Q=j==="system"?re:j;p.editor.defineTheme("default",{base:Q==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":Q==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),p.editor.setTheme("default")}return g&&p&&g.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ie(),!1}),()=>{}},[s,j,n.current]);function ue(p){n.current=p}function pe(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[l&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Gs,{checked:q,onCheckedChange:()=>C(!q),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Qs,{}),A&&l&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>i(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:p=>{if(p)try{JSON.parse(p),K(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(A,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),A&&!l&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>i(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":q})})]})}function je(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:p=>{V(p)},value:k,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:ue,onMount:de})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:p=>{W(p&&p.trim()||"")},value:y||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:ue,onMount:de})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[je(),pe()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:J||Y,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[J||Y?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(Ns,{className:"mr-2 h-4 w-4"}),"Run"]}),Z&&e.jsxRuntimeExports.jsx($s,{error:se.message,setShowAIDialog:c,setTriggerAIRun:E,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:p=>o(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(nt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Ws,{open:a,setOpen:c,userInput:m,triggerAIRun:h,setTriggerAIRun:E,setUserInput:p=>d(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:me,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function ot({data:s}){var i;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:c})=>{const m=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[a,m==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:l.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},a.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function Ke({className:s,...n}){var u;S.useState(0);const t=e.useDashboardStore(x=>x.themeStyle),r=e.useEditorStore(x=>x.card),o=e.useEditorStore(x=>x.frame),l=e.useDashboardStore(x=>x.dashboard.filters),i=e.useDashboardStore(x=>x.filterValues),a=e.useEditorStore(x=>x.actions.setRunSql),{updateFilter:c}=e.useDashboardActions(),m=l==null?void 0:l.find(x=>x.id===o.filterId),d=e.useEditorStore(x=>x.actions.setCard);if(S.useEffect(()=>{r.sql&&a(!0)},[i]),S.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let h;r.data&&r.data.length>0&&(h=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences}));function E(x){return e.jsxRuntimeExports.jsx(e.CustomVisual,{card:x})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:x=>d({...r,title:x}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:x=>d({...r,description:x}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),m&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:m.title||m.column,onSave:x=>c({...m,title:x}),children:e.jsxRuntimeExports.jsx(e.Label,{children:m.title})}),e.getFilterComponent(m)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[r.type==="custom"&&E(r),!["table","custom"].includes(r.type)&&h&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:h},JSON.stringify(h)+JSON.stringify(r.preferences)+((u=r==null?void 0:r.preferences)==null?void 0:u.customVisualCode)),r.type==="table"&&r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:r,data:r==null?void 0:r.data})})]})]})}function it(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,l]=S.useState(""),[i,a]=S.useState(""),[c,m]=S.useState(""),d=e.useEditorStore(b=>b.card),h=e.useEditorStore(b=>b.card.customCfg),{setCardCustomCfg:E,setCustomVisualCode:u}=e.useEditorActions();function x(b){var F,k;const z={...b,data:{...b==null?void 0:b.data,datasets:(k=(F=b==null?void 0:b.data)==null?void 0:F.datasets)==null?void 0:k.map(y=>({...y,data:[]}))}};return JSON.stringify(z,null,1)}function R(){var z,T;if(!d.data||d.data.length===0)return;const b=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences});b&&(r(JSON.stringify(b,null,1)),(z=d==null?void 0:d.preferences)!=null&&z.customVisualCode&&a((T=d==null?void 0:d.preferences)==null?void 0:T.customVisualCode),h&&l(JSON.stringify(h,null,1)))}function j(){if(i&&u(i),!!o)try{const b=JSON.parse(o);return b?(E(b),m(""),l(""),b):void 0}catch(b){console.log(b),m("Invalid JSON")}}function w(){l(""),E(null)}function L(){let b;if(h){const z=e._.cloneDeep(d.cfg),T=e._.merge(z,h);return b=x(T),b}return t?(b=x(JSON.parse(t)),b):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:R,className:` ${h&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(Rs,{onClick:()=>{navigator.clipboard.writeText(d.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ke,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[h&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),h?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:L(),onChange:b=>l(b)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:i,onChange:b=>a(b||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!h,onClick:w,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:j,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function We(s){return X({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Je(s){return X({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Ye(s){return X({tag:"svg",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 Ze(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},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 Xe(s){return X({tag:"svg",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 es(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function ss(s){return X({tag:"svg",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 ts(s){return X({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function at(){const[s,n]=S.useState(!1),t=e.useEditorStore(c=>c.card.type),{setCardType:r,setCardPreferences:o,setChartOrientation:l}=e.useEditorStore(c=>c.actions),i=e.useEditorStore(c=>c.actions.setCardCustomCfg);function a(c){i(null),o({}),r(c),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(lt,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(He,{className:"size-4"})})]})})]})}function lt({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:n});case"line":return e.jsxRuntimeExports.jsx(ke,{className:n});case"pie":return e.jsxRuntimeExports.jsx(_e,{className:n});case"radar":return e.jsxRuntimeExports.jsx(We,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Je,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(es,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Xe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ye,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(ts,{className:n});case"range":return e.jsxRuntimeExports.jsx(qe,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(ss,{className:n});case"text":return e.jsxRuntimeExports.jsx(Le,{className:n});case"custom":return e.jsxRuntimeExports.jsx(He,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function Oe(){const s=e.useEditorStore(j=>j.frame),n=e.useEditorStore(j=>j.card),t=e.useEditorStore(j=>j.card.data),r=e.useEditorStore(j=>j.isShowingVisual),o=e.useEditorStore(j=>j.isSqlRunning),l=e.useEditorStore(j=>j.queryError),i=e.useEditorStore(j=>j.pythonStdOut),a=e.useEditorStore(j=>j.actions.setRunSql);e.useEditorStore(j=>j.onSave),e.useEditorStore(j=>j.onClose),e.useEditorStore(j=>j.actions.setCardSql),e.useEditorStore(j=>j.actions.setCardType),e.useEditorStore(j=>j.actions.setSqlGen);const{setFrame:c,setCard:m,updateCardInFrame:d}=e.useEditorActions();if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function h(){const j={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},w={...s,cards:[...s.cards,j],activeCardId:j.id};c(w),m(j)}function E(j){const w=s.cards.filter(z=>z.id!==j),L=w[0],b={...s,cards:w,activeCardId:L.id};c(b),m(L)}function u(j){const w={...s,cards:s.cards.map(b=>b.id===n.id?n:b),activeCardId:j};c(w);const L=w.cards.find(b=>b.id===j);m(L),L.sql&&(console.log("newActiveCard.sql",L.sql),L.data&&L.data.length===0&&a(!0))}function x(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:u,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(j=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:j.id,children:R()},j.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map(j=>e.jsxRuntimeExports.jsx(e.Editable,{text:j.tabTitle||j.title,onSave:w=>{m({...n,tabTitle:w}),d({...n,tabTitle:w})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{className:"",value:j.id,children:[j.tabTitle||j.title,s.activeCardId===j.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>E(j.id)})]})},j.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:h,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})})]})})]})}function R(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:o,card:n})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:o,card:n})})}):e.jsxRuntimeExports.jsx(Ke,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[o&&e.jsxRuntimeExports.jsx(le,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(at,{}),n.type!=="table"&&e.jsxRuntimeExports.jsx(it,{})]}),e.jsxRuntimeExports.jsx(xt,{})]}),r?x():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[i&&e.jsxRuntimeExports.jsx(ct,{}),n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(ot,{data:t||[]}),l&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:l})]})]})}function ct(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function xt(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function ut({value:s,onValueChange:n,components:t}){var l;const[r,o]=Ce.useState(!1);return e.jsxRuntimeExports.jsxs(e.Popover,{open:r,onOpenChange:o,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",role:"combobox","aria-expanded":r,className:"h-8 w-full justify-between",children:[s?(l=t.find(i=>i.value===s))==null?void 0:l.label:"Select Component...",e.jsxRuntimeExports.jsx(us,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-full p-2.5",children:e.jsxRuntimeExports.jsxs(e.Command,{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search component..."}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No component found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:t.map(i=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:i.value,onSelect:a=>{n(a===s.toLowerCase()?"":i.value),o(!1)},children:[e.jsxRuntimeExports.jsx(e.Check,{className:e.cn("mr-2 h-4 w-4",s===i.value?"opacity-100":"opacity-0")}),i.label]},i.value))})]})]})})]})}function dt(){const s=e.useEditorStore(o=>o.card.customCardPreferences),{setCustomCardPreferences:n}=e.useEditorActions(),{components:t}=e.useCustomVisual((s==null?void 0:s.url)||"");function r(o){n({...s||{url:"",componentName:""},type:o})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-6 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx(mt,{value:(s==null?void 0:s.type)||"component",onValueChange:r})}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:`${(s==null?void 0:s.type)==="component"?"Code":"Iframe"} URL`}),e.jsxRuntimeExports.jsx(e.Input,{value:s==null?void 0:s.url,onChange:o=>n({...s||{url:"",componentName:""},url:o.target.value}),className:`h-8 w-full ${e.removeRing}`})]}),(s==null?void 0:s.type)==="component"&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx(ut,{components:(t==null?void 0:t.map(o=>({value:o.name,label:o.name})))||[],value:s==null?void 0:s.componentName,onValueChange:o=>n({...s,componentName:o})})]})]})}function mt({value:s,onValueChange:n}){return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:s,onValueChange:n,className:"flex gap-4",defaultValue:"component",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"component",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Component"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"iframe",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Iframe"})]})]})}function ce(){const[s,n]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=e.useEditorStore(d=>d.actions),i=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var h;return(h=d.card.preferences)==null?void 0:h.filterOnClickColumnIndex}),S.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function a(d,h){var E,u;h?t!=null&&t.onClickFilter&&((E=t==null?void 0:t.onClickFilter)==null?void 0:E.length)>0?l({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):l({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(l({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(x=>x.columnIndex!==d)}),n(x=>{const R=[...x];return R[d]=!1,R}))}function c(d,h){var u;const E=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(x=>x.columnIndex===d?{...x,expression:h.target.value}:x);l({...t,onClickFilter:E})}function m(d){var h,E,u,x;if(s!=null&&s[d]||(E=(h=t==null?void 0:t.onClickFilter)==null?void 0:h.find(R=>R.columnIndex===d))!=null&&E.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(x=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(R=>R.columnIndex===d))==null?void 0:x.expression,onChange:R=>c(d,R),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.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),i==null?void 0:i.map((d,h)=>{var E,u;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((E=t==null?void 0:t.onClickFilter)!=null&&E.find(x=>x.columnIndex===h)),onCheckedChange:x=>a(h,x)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(x=>x.columnIndex===h))&&e.jsxRuntimeExports.jsx(Ve,{onClick:()=>{n(x=>{const R=[...x];return R[h]=!x[h],R})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(h)]})},d)})]})}function Re(){var i,a,c;const s=e.useEditorStore(m=>m.card.preferences),n=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const he="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Me(s,n){var r,o,l;const t=e.getNumberAxis(s,n);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:l.type)||"linear"}function ns(){var K,V,W,v,I,H;const[s,n]=S.useState(!1),t=e.useEditorStore(N=>{var C;return(C=N.card)==null?void 0:C.preferences}),r=e.useEditorStore(N=>{var C;return(C=N.card)==null?void 0:C.cfg}),o=e.getNumberAxis(t,r),[l,i]=S.useState(Me(t)),[a,c]=S.useState(((W=(V=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:V[o])==null?void 0:W.min)||""),[m,d]=S.useState(((H=(I=(v=t==null?void 0:t.chartOptions)==null?void 0:v.scales)==null?void 0:I[o])==null?void 0:H.max)||""),[h,E]=S.useState(a||m?"custom":"auto"),[u,x]=S.useState(""),[R,j]=S.useState(0),[w,L]=S.useState(""),[b,z]=S.useState(""),[T,F]=S.useState(""),k=e.useEditorStore(N=>N.actions.setCardPreferences),{updateCardInFrame:y}=e.useEditorActions(),f=e.useEditorStore(N=>N.card),O=e.useEditorStore(N=>{var C;return(C=N.card)==null?void 0:C.type}),M=["pie","doughnut","polarArea"].includes(O);S.useEffect(()=>{var N,C,$,D,G,U,te,ee,B,J,Y,ne,Z,se;i(Me(t)),c((($=(C=(N=t==null?void 0:t.chartOptions)==null?void 0:N.scales)==null?void 0:C[o])==null?void 0:$.min)===0?0:""),d(((U=(G=(D=t==null?void 0:t.chartOptions)==null?void 0:D.scales)==null?void 0:G[o])==null?void 0:U.max)||""),x(((J=(B=(ee=(te=t==null?void 0:t.chartOptions)==null?void 0:te.scales)==null?void 0:ee[o])==null?void 0:B.ticks)==null?void 0:J.stepSize)||""),j(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.decimalPlaces)||0),L(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),z(((Z=t==null?void 0:t.numberAxisFormat)==null?void 0:Z.currency)||""),F(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.locale)||"")},[s,t,o]);function A(N,C){return C===""||/^[0-9\b]+$/.test(C)?Number(C):Number(N)}function q(){const N=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(C=>C.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:b||"none",onValueChange:C=>z(C==="none"?"":C),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),N.map(C=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:C,children:C},C))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:T,onValueChange:C=>F(C),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(C=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:C.locale,children:C.locale},C.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:R,onChange:C=>j(Number(C.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${he}`})]})]})}function P(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:a,onChange:N=>c(C=>A(C,N.target.value)),className:`col-span-1 h-8 w-full ${he}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:N=>d(C=>A(C,N.target.value)),id:"max",className:`col-span-1 h-8 w-full ${he}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:u,onChange:N=>x(C=>A(C,N.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${he}`})]})]})}function _(){var D;let N={};h==="custom"&&(N={min:a,max:m,ticks:{stepSize:u}});const C={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(D=t==null?void 0:t.chartOptions)==null?void 0:D.scales,[o]:{type:l,...l==="linear"?N:{}}}},numberAxisFormat:{decimalPlaces:R,suffix:w,currency:b,locale:T}};console.log(C),k(C);const $={...f,preferences:C};y($)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:N=>n(N),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:M,value:l,onValueChange:N=>i(N),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:M,id:"scale-option",value:h,onValueChange:N=>E(N),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&l=="linear"&&P(),q(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function pt({idx:s}){var a;const n=e.useEditorStore(c=>{var m;return(m=c.card)==null?void 0:m.preferences}),t=e.useEditorStore(c=>{var m;return(m=c.card.preferences)==null?void 0:m.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),o=(a=n==null?void 0:n.chartOptions)==null?void 0:a.indexAxis,l=t==null?void 0:t.find(c=>c.idx===s);function i(c,m){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:c!=="none",align:c,anchor:c,clamp:!0};if(!l)r({...n,datasetOptions:[...t||[],{idx:m,datalabels:d}]});else{const h={...l};h.datalabels=d;const E=t==null?void 0:t.map(u=>u.idx===m?h:u);r({...n,datasetOptions:E})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ds,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(bs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function rs(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var m,d,h;return(h=(d=(m=c==null?void 0:c.card)==null?void 0:m.preferences)==null?void 0:d.chartOptions)==null?void 0:h.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:o,metricKeys:l,dimensionKeys:i}=e.getKeys(s.data||[]);let a=l;if(["stackedBar","stackedLine"].includes(s.type)){const c=e.pivotData({dataArray:s.data||[],groupKey:i[0],pivotKey:i[1],valueKey:a[0]}),{metricKeys:m}=e.getKeys(c);a=m}return o.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:i[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(ns,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((c,m)=>e.jsxRuntimeExports.jsx(jt,{col:c,idx:m},c))})]})]})}function jt({col:s,idx:n}){const t=e.useEditorStore(a=>{var c;return(c=a.card)==null?void 0:c.preferences}),r=e.useEditorStore(a=>{var c;return(c=a.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(a=>a.idx===n),{setCardPreferences:l}=e.useEditorStore(a=>a.actions);function i(a){if(!o)l({...t,datasetOptions:[...r||[],{idx:n,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const c={...o};c.type=a==="area"?"line":a,c.fill=a==="area"?"origin":"";const m=r==null?void 0:r.map(d=>d.idx===n?c:d);l({...t,datasetOptions:m})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(we,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ke,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(cs,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(pt,{idx:n})]})]})}function os(){const s=e.useEditorStore(E=>E.selectedConnectionId),n=e.useEditorStore(E=>E.selectedDatamodelId),t=e.useEditorStore(E=>E.selectedDatabaseName),r=e.useEditorStore(E=>E.selectedSchemaName),o=e.useEditorStore(E=>E.selectedTableName),l=e.useDashboardStore(E=>E.dashboard.filters)||[],i=e.useDashboardStore(E=>E.actions.addFilter),a=e.useDashboardStore(E=>E.actions.removeFilter),c=e.useDashboardStore(E=>E.actions.removeFilterValue),{modelItems:m,tableName:d}=oe();function h(E,u="dashboard"){var F;const x=e.fmt(E.column_name),R=e.fmt(t||""),j=e.fmt(r||""),w=e.fmt(d);let L=e.getQualifiedTableName(j,w),b=`${L}.${x}`;const z=(F=m==null?void 0:m.find(k=>k.id===n))==null?void 0:F.name;n&&n!=="none"&&(b=`${e.DATAMODEL_NAMESPCACE}.${z}.${x}`,L=`${e.DATAMODEL_NAMESPCACE}.${z}`);const T=l==null?void 0:l.find(k=>k.column===b&&k.table===w&&(k.database===R||k.database===t));if(T)c(T.id),a(T.id);else{const k=e.v4();return d==="api"&&s?(i({location:u,id:k,column:b,title:E.column_name,dataType:E.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,x)}),k):(i({id:k,location:u,column:b,title:E.column_name,dataType:E.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(E.data_type,L,x)}),k)}}return{assignFilter:h}}function xe(){const s=e.useDashboardStore(a=>a.dashboard.filters),n=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=oe(),{assignFilter:o}=os();function l(a){const c=o(a,"frame");t({...n,filterId:c})}const i=s==null?void 0:s.find(a=>a.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(ht,{onSelect:l,columns:r}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function ht({columns:s,onSelect:n}){var i;const[t,r]=Ce.useState(!1),[o,l]=Ce.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(i=s.find(a=>a.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(a=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:a.column_name,onSelect:c=>{const m=c===o?"":c;l(m),r(!1),m&&n(a)},children:[a.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===a.column_name?"opacity-100":"opacity-0")})]},a.column_name))})]})]})})]})}function Et({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(rs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function Ae(){var o,l,i;const s=e.useEditorStore(a=>a.card.cfg),n=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function r(a){var d;const c={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...c}}};n(m),console.log(a)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(ns,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(i=(l=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function ft({cardType:s}){function n(t){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?r:o}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Ae,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}const gt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Rt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function bt(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:St(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Re,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Ae,{}),e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})}function St(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(gt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.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.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(Rt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function yt(){var c,m,d,h,E;const s=e.useEditorStore(u=>u.card.preferences),n=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.decimalPlaces});const r=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.locale}),o=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const l=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.colorRanges})||[],i=e.useEditorStore(u=>u.actions.setColorRanges),a=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:u=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:u}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((m=s==null?void 0:s.formatNumber)==null?void 0:m.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"en-US",onValueChange:u=>{var x,R,j;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",u||"en-US",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:u=>{var x,R,j;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,u==="none"?"":u,((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),a.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((h=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:h.toString())||"0",onValueChange:u=>{var x,R,j;return t(Number(u),((x=s==null?void 0:s.formatNumber)==null?void 0:x.currency)||"",((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((E=s==null?void 0:s.formatNumber)==null?void 0:E.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:u=>{var x,R,j;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",((j=s==null?void 0:s.formatNumber)==null?void 0:j.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function vt(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(yt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Ct(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ee({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Re,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Ae,{}),s==="text"&&e.jsxRuntimeExports.jsx(Ct,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function Nt(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(rs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function wt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.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 kt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Lt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),It=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function At(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Nt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ee,{docContent:kt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(vt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(Et,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ee,{docContent:Lt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ee,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(ft,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(wt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ee,{docContent:It,cardType:t,suffix:"Visual"});case"custom":return e.jsxRuntimeExports.jsx(dt,{});default:return e.jsxRuntimeExports.jsx(bt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Dt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(rt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(At,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Oe,{})})]}):e.jsxRuntimeExports.jsx(Oe,{})})]})}function Tt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),l=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ge,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Dt,{})})]})}function zt(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),r=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),n(!1))}function l(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(Tt,{onSave:o,onClose:l})})}function Ft(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[];e.useDashboardStore(i=>i.actions.addFilter),e.useDashboardStore(i=>i.actions.removeFilter),e.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=oe(),{assignFilter:l}=os();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:o==null?void 0:o.map(i=>{const a=t==null?void 0:t.find(c=>c.column===e.fmt(i.column_name)&&c.table===n&&c.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>l(i),className:e.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":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx($e,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Ot(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ge,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Ft,{})})})]})}function Mt(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Ot,{})})]})}function qt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}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 Vt({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(qt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(_s,{}),e.jsxRuntimeExports.jsx(zt,{}),e.jsxRuntimeExports.jsx(Mt,{})]})]})]})}exports.DashboardPlus=Vt;exports.LoaderCircle=le;exports.SelectComponent=ae;exports.cleanCard=Pe;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=oe;
230
+ Database Query Dialect: ${y==="api"||y==="s3"?"DuckDb":""}
231
+ Table Name: ${y}
232
+ Table Columns: ${I==null?void 0:I.map(v=>`${v.column_name} | ${v.data_type}`).join(", ")}
233
+ User SQL: ${O}
234
+ ${f&&`Base Queries: ${JSON.stringify(f)} `}`,j=` When the user asks for a specific chart please use the following query structure to generate the chart query. Do not make up the column names. Use only the table columns provided above for the query. Replace x-axis, y-axis, and lables with the appropriate column names.
235
+ Visual Query Syntax: ${Ws}`,{data:k,isLoading:C,isFetching:b,isError:h,refetch:F}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(c==null?void 0:c.accessToken)||"",{user_content:`userContent: ${z} ${m?j:""}`}),enabled:!1});function M(v){if(v.toLowerCase().includes("bar"))x("bar");else if(v.toLowerCase().includes("line"))x("line");else if(v.toLowerCase().includes("bubble"))x("bubble");else if(v.toLowerCase().includes("scatter"))x("scatter");else if(v.toLowerCase().includes("stacked"))x("stackedBar");else if(v.toLowerCase().includes("pie"))x("pie");else if(v.toLowerCase().includes("donut")||v.toLowerCase().includes("doughnut"))x("doughnut");else if(v.toLowerCase().includes("radar"))x("radar");else return x("bar"),!1;return!0}S.useEffect(()=>{k&&L(v=>[...v,{role:"ai",content:k.response}])},[k]),S.useEffect(()=>{const v=setTimeout(()=>{var D;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(D=i.current)==null||D.focus())},100);return()=>clearTimeout(v)},[R]);function A(){t&&(L(v=>[...v,{role:"user",content:t}]),M(t)&&d(!0),r(""),F())}S.useEffect(()=>{o&&(A(),l(!1))},[o,l]);const V={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},P={fontFamily:"monospace",fontSize:14,lineHeight:1.6},_={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},K={p:({node:v,...D})=>e.jsxRuntimeExports.jsx("p",{style:V,...D}),code:({node:v,...D})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...D}),pre:({node:v,...D})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:P,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:D.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:q,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:H=>{const w=q(H);w&&(n(!1),E(w),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:v,...D})=>e.jsxRuntimeExports.jsx("li",{style:_,...D})};function q(v){const D=v.currentTarget.closest("pre");if(!D)return;const H=D.textContent||D.innerText;return navigator.clipboard.writeText(H).then(()=>console.log("Text copied to clipboard")).catch(w=>console.error("Error in copying text: ",w)),H}function W(){return R==null?void 0:R.map((v,D)=>v.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(Fs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:v.content})]},D):v.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:K,children:k==null?void 0:k.response.replace(/DuckDB/gi,"Semaphor")},D):e.jsxRuntimeExports.jsx("div",{},D))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",className:"w-full justify-start border font-normal text-muted-foreground focus-visible:ring-0 focus-visible:ring-offset-0",variant:"secondary",children:"Type your question here..."})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"flex flex-col justify-between overflow-auto sm:max-w-[425px] md:max-h-[625px] md:min-w-[625px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Assistant"}),e.jsxRuntimeExports.jsx(e.DialogDescription,{children:"What can I help you with?"})]}),e.jsxRuntimeExports.jsx("div",{ref:a,className:"h-[625px] w-full overflow-auto border-t border-t-muted",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 py-2 pr-3",role:"messages",children:W()})}),e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"flex w-full items-center rounded-md border",children:[e.jsxRuntimeExports.jsx(e.Textarea,{autoFocus:!0,ref:i,onKeyDown:v=>{v.key==="Enter"&&!v.shiftKey&&(v.preventDefault(),r(""),A())},placeholder:"Type your question here...",onFocus:v=>{const D=v.target,H=D.value.length;D.setSelectionRange(H,H)},className:e.cn("max-h-10 min-h-7 resize-none border-none focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"),disabled:C||b,value:t,onChange:v=>r(v.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:A,children:!C&&!b?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Ue={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ze=S.createContext&&S.createContext(Ue),Ys=["attr","size","title"];function Zs(s,n){if(s==null)return{};var t=Xs(s,n),r,o;if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(s);for(o=0;o<l.length;o++)r=l[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(t[r]=s[r])}return t}function Xs(s,n){if(s==null)return{};var t={},r=Object.keys(s),o,l;for(l=0;l<r.length;l++)o=r[l],!(n.indexOf(o)>=0)&&(t[o]=s[o]);return t}function fe(){return fe=Object.assign?Object.assign.bind():function(s){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},fe.apply(this,arguments)}function Fe(s,n){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,r)}return t}function ge(s){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Fe(Object(t),!0).forEach(function(r){et(s,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):Fe(Object(t)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(t,r))})}return s}function et(s,n,t){return n=st(n),n in s?Object.defineProperty(s,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[n]=t,s}function st(s){var n=tt(s,"string");return typeof n=="symbol"?n:String(n)}function tt(s,n){if(typeof s!="object"||s===null)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var r=t.call(s,n||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(s)}function Qe(s){return s&&s.map((n,t)=>S.createElement(n.tag,ge({key:t},n.attr),Qe(n.child)))}function X(s){return n=>S.createElement(nt,fe({attr:ge({},s.attr)},n),Qe(s.child))}function nt(s){var n=t=>{var{attr:r,size:o,title:l}=s,i=Zs(s,Ys),a=o||t.size||"1em",c;return t.className&&(c=t.className),s.className&&(c=(c?c+" ":"")+s.className),S.createElement("svg",fe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,r,i,{className:c,style:ge(ge({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),l&&S.createElement("title",null,l),s.children)};return ze!==void 0?S.createElement(ze.Consumer,null,t=>n(t)):n(Ue)}function rt(s){return X({tag:"svg",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 ot(){const{theme:s}=e.useTheme(),n=S.useRef(),t=S.useRef(),[r,o]=S.useState(!1),[l,i]=S.useState(!1),[a,c]=S.useState(!1),[m,d]=S.useState(""),[E,f]=S.useState(!1),{authToken:u}=e.useSemaphorContext();e.useDashboardStore(p=>p.selectedSheetId);const x=e.useDashboardStore(p=>p.dashboard.baseQueries),R=e.useEditorStore(p=>p.card),L=e.useDashboardStore(p=>p.theme),I=e.useEditorStore(p=>p.isShowingVisual);e.useDashboardStore(p=>p.onAcceptChanges);const O=e.useEditorStore(p=>p.selectedConnectionId),y=e.useEditorStore(p=>p.selectedDatabaseName),z=e.useEditorStore(p=>p.selectedDatamodelId),j=e.useEditorStore(p=>p.selectedSchemaName);e.useDashboardStore(p=>p.actions.updateFrameCard);const k=e.useEditorStore(p=>p.selectedTableName),C=e.useEditorStore(p=>p.card.sql),b=e.useEditorStore(p=>p.card.python),h=e.resolveBaseQuery(C,x),F=e.useEditorStore(p=>p.selectedConnectionId),M=e.useEditorStore(p=>p.frame),A=e.useDashboardStore(p=>p.filterValues),V=e.useEditorStore(p=>p.applyFilters),{setCardCustomCfg:P,setQueryResultColumns:_,setFilterValues:K,setCardSql:q,setCardPython:W,setQueryError:v,setPythonStdOut:D,setCardPreferences:H}=e.useEditorStore(p=>p.actions),w=e.useEditorStore(p=>p.onSave),N=e.useEditorStore(p=>p.actions.setApplyFilters),$=e.useEditorStore(p=>p.onClose),T=e.useEditorStore(p=>p.actions.setCardData),G=e.useEditorStore(p=>p.actions.setSqlGen),U=e.useEditorStore(p=>p.runSql),te=e.useEditorStore(p=>p.actions.setRunSql),ee=e.useEditorStore(p=>p.actions.setIsSqlRunning),{data:B,isLoading:J,isFetching:Y,isSuccess:ne,isError:Z,error:se,status:Ae,refetch:ie}=e.useQuery({queryKey:[h,b],queryFn:()=>e.postRequest("https://semaphor.cloud/api/v1/query",(u==null?void 0:u.accessToken)||"",{connection_id:F,sql:h,python:b===e.PYTHON_DEFAULT_CODE?"":b,active_filters:V?A:[]}),enabled:!1,retry:!1});S.useEffect(()=>{if(B&&(T(B.records),B.rowLimitExceeded&&e.Jt.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),D((B==null?void 0:B.output)||""),B.records.length>0)){const{dimensionKeys:p}=e.getKeys(B.records);_(p)}},[B,T,_,D]),S.useEffect(()=>{U&&(ie(),te(!1))},[U,ie,te]),S.useEffect(()=>{(J||Y)&&ee(!0),(Z||ne)&&ee(!1),Z?(v(se.message),T([]),_([]),D("")):v("")},[J,Y,B,D,Z,ne,ee,T,_,v,se]);function be(){q(""),T([]),G({}),P(""),H({})}const de=p=>{t.current=p};function Se(p,g){if(p.length===0)return"";if(g){const re=p.find(Q=>Q.id===g);if(re){const Q=re.tabTitle;if(Q=="All__Header")return p[0].id;if(Q&&Q.endsWith("__Header")){const is=Q.split("__")[0],Te=p.find(as=>as.tabTitle===is);return Te?Te.id:p[0].id}return g}}return p[0].id}function ye(){let p=C;C&&!C.includes("{{")&&(p=$s(C),q(p));const g={...R,lastSelectedSchema:j,lastSelectedDatamodelId:z,lastSelectedDatabase:y,lastSelectedTable:k,connectionId:O,type:I?R.type:"table",sql:p,customCfg:I?R.customCfg:null},re=M.cards.map(ve=>ve.id===R.id?g:ve),Q={...M,cards:re,activeCardId:Se(re,M.activeCardId)};w==null||w(Q)}function me(){$==null||$()}S.useEffect(()=>{const p=n.current,g=t.current;if(p){const re=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",Q=L==="system"?re:L;p.editor.defineTheme("default",{base:Q==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":Q==="light"?"#ffffff":e.getCssVariableValue("--semaphor-background")}}),p.editor.setTheme("default")}return g&&p&&g.addCommand(p.KeyMod.Shift|p.KeyCode.Enter,function(){return console.log("Executing query..."),ie(),!1}),()=>{}},[s,L,n.current]);function ue(p){n.current=p}function pe(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[l&&e.jsxRuntimeExports.jsx("div",{className:"xbg-yellow-100 relative flex w-1/3 min-w-0 grow overflow-hidden border-l p-1 text-xs",role:"editor-filter-container",children:e.jsxRuntimeExports.jsxs("div",{className:"w-[99%]",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[e.jsxRuntimeExports.jsx(Us,{checked:V,onCheckedChange:()=>N(!V),text:"Apply Filters"}),e.jsxRuntimeExports.jsx(Ks,{}),A&&l&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>i(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:p=>{if(p)try{JSON.parse(p),K(JSON.parse(p))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(A,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}),A&&!l&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>i(!0),className:e.cn("absolute bottom-4 right-6 h-3 w-3 text-foreground/50 hover:cursor-pointer hover:text-foreground",{"font-bold text-red-800":V})})]})}function je(){return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"sql-container",className:"relative flex w-[99%]",children:e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",className:"pt-3",onChange:p=>{q(p)},value:C,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",beforeMount:ue,onMount:de})}),r&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),r&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsxs(e.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsxRuntimeExports.jsx("div",{role:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"pt-3",theme:"default",onChange:p=>{W(p&&p.trim()||"")},value:b||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",beforeMount:ue,onMount:de})}),e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"python"})]})]})]})}return e.jsxRuntimeExports.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxRuntimeExports.jsxs("div",{role:"sql-editor",className:"relative flex grow justify-between overflow-y-scroll",children:[je(),pe()]}),e.jsxRuntimeExports.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{title:"Shift + Enter",disabled:J||Y,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[J||Y?e.jsxRuntimeExports.jsx(le,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ws,{className:"mr-2 h-4 w-4"}),"Run"]}),Z&&e.jsxRuntimeExports.jsx(Gs,{error:se.message,setShowAIDialog:c,setTriggerAIRun:f,setUserInputforAI:d}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(hs,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:r,onPressedChange:p=>o(p),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(rt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(Js,{open:a,setOpen:c,userInput:m,triggerAIRun:E,setTriggerAIRun:f,setUserInput:p=>d(p)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxRuntimeExports.jsxs(e.Button,{onClick:ye,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:me,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]})]})]})]})}function it({data:s}){var i;const[n,t]=S.useState([]),o=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:c})=>{const m=c.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[a,m==="asc"?e.jsxRuntimeExports.jsx(e.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsxRuntimeExports.jsx(e.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),l=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsxRuntimeExports.jsxs(e.Table$1,{children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:l.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(c=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 bg-muted",children:c.isPlaceholder?null:e.flexRender(c.column.columnDef.header,c.getContext())},c.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(i=l.getRowModel().rows)!=null&&i.length?l.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(c=>e.jsxRuntimeExports.jsx(e.TableCell,{children:e.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},a.id)):e.jsxRuntimeExports.jsx(e.TableRow,{children:e.jsxRuntimeExports.jsx(e.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})}function Ke({className:s,...n}){var u;S.useState(0);const t=e.useDashboardStore(x=>x.themeStyle),r=e.useEditorStore(x=>x.card),o=e.useEditorStore(x=>x.frame),l=e.useDashboardStore(x=>x.dashboard.filters),i=e.useDashboardStore(x=>x.filterValues),a=e.useEditorStore(x=>x.actions.setRunSql),{updateFilter:c}=e.useDashboardActions(),m=l==null?void 0:l.find(x=>x.id===o.filterId),d=e.useEditorStore(x=>x.actions.setCard);if(S.useEffect(()=>{r.sql&&a(!0)},[i]),S.useEffect(()=>{},[r.data,r.type,r.cfg,r.customCfg,t,r.preferences]),!r.id)return null;let E;r.data&&r.data.length>0&&(E=e.createChartConfig({data:r.data,cardType:r.type,cfg:r.cfg,customCfg:r.customCfg,preferences:r.preferences}));function f(x){return e.jsxRuntimeExports.jsx(e.CustomVisual,{card:x})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...n,children:[e.jsxRuntimeExports.jsxs(e.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsx(e.Editable,{text:r.title,onSave:x=>d({...r,title:x}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:r.title})})},r.title),e.jsxRuntimeExports.jsx(e.Editable,{text:r.description||"",onSave:x=>d({...r,description:x}),children:e.jsxRuntimeExports.jsxs(e.CardDescription,{children:[" ",r.description]})},r.description)]}),m&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:m.title||m.column,onSave:x=>c({...m,title:x}),children:e.jsxRuntimeExports.jsx(e.Label,{children:m.title})}),e.getFilterComponent(m)]})]}),e.jsxRuntimeExports.jsxs(e.CardContent,{className:"flex grow flex-col",children:[r.type==="custom"&&f(r),!["table","custom"].includes(r.type)&&E&&e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:E},JSON.stringify(E)+JSON.stringify(r.preferences)+((u=r==null?void 0:r.preferences)==null?void 0:u.customVisualCode)),r.type==="table"&&r.data&&r.data.length>0&&e.jsxRuntimeExports.jsx(e.$57acba87d6e25586$export$ccf8d8d7bbf3c2cc,{className:"flex min-h-0 flex-1 grow basis-0",children:e.jsxRuntimeExports.jsx(e.TableVisual,{card:r,data:r==null?void 0:r.data})})]})]})}function at(){const[s,n]=S.useState(!1),[t,r]=S.useState(""),[o,l]=S.useState(""),[i,a]=S.useState(""),[c,m]=S.useState(""),d=e.useEditorStore(y=>y.card),E=e.useEditorStore(y=>y.card.customCfg),{setCardCustomCfg:f,setCustomVisualCode:u}=e.useEditorActions();function x(y){var k,C;const z={...y,data:{...y==null?void 0:y.data,datasets:(C=(k=y==null?void 0:y.data)==null?void 0:k.datasets)==null?void 0:C.map(b=>({...b,data:[]}))}};return JSON.stringify(z,null,1)}function R(){var z,j;if(!d.data||d.data.length===0)return;const y=e.createChartConfig({data:d.data,cardType:d.type,cfg:d.cfg,preferences:d.preferences});y&&(r(JSON.stringify(y,null,1)),(z=d==null?void 0:d.preferences)!=null&&z.customVisualCode&&a((j=d==null?void 0:d.preferences)==null?void 0:j.customVisualCode),E&&l(JSON.stringify(E,null,1)))}function L(){if(i&&u(i),!!o)try{const y=JSON.parse(o);return y?(f(y),m(""),l(""),y):void 0}catch(y){console.log(y),m("Invalid JSON")}}function I(){l(""),f(null)}function O(){let y;if(E){const z=e._.cloneDeep(d.cfg),j=e._.merge(z,E);return y=x(j),y}return t?(y=x(JSON.parse(t)),y):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:R,className:` ${E&&"border-foreground/50 dark:border-foreground/70"}`,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.Settings,{className:"h-4 w-4"})})}),e.jsxRuntimeExports.jsxs(e.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsxRuntimeExports.jsxs(e.DialogHeader,{className:"",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"}),e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:e.jsxRuntimeExports.jsx(bs,{onClick:()=>{navigator.clipboard.writeText(d.id)},className:"size-3 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{side:"right",align:"center",children:e.jsxRuntimeExports.jsx("p",{className:"text-xs",children:"Copy Card ID"})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogDescription,{children:["See the configuration options and documentation",e.jsxRuntimeExports.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex grow gap-2",children:[e.jsxRuntimeExports.jsx(Ke,{className:"w-1/2 rounded shadow-none"}),e.jsxRuntimeExports.jsxs(e.Tabs,{defaultValue:"custom-config",className:"flex w-1/2 flex-col",children:[e.jsxRuntimeExports.jsxs(e.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsxRuntimeExports.jsxs(e.TabsTrigger,{value:"custom-config",children:[E&&e.jsxRuntimeExports.jsx(e.CheckIcon,{className:"mr-1 h-5 w-5 text-green-600"}),E?"Custom Config":"Default Config"]}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"output",children:"Output"}),e.jsxRuntimeExports.jsx(e.TabsTrigger,{className:"",value:"custom-code",children:"Custom Code"})]}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"bg-red-x mt-0 grow rounded-b border border-t-0 p-2",value:"output",children:e.jsxRuntimeExports.jsx(e.Textarea,{disabled:!0,value:t,className:"h-full resize-none border-none font-mono focus-visible:ring-0 focus-visible:ring-offset-0"})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-config",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"json",value:O(),onChange:y=>l(y)})}),e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow rounded-b border border-t-0",value:"custom-code",children:e.jsxRuntimeExports.jsx(e.Ft,{className:"h-full w-full overflow-hidden",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"javascript",value:i,onChange:y=>a(y||"")})})]})]}),e.jsxRuntimeExports.jsxs(e.DialogFooter,{className:"flex items-center",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"mr-2 text-red-500",children:c}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!E,onClick:I,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:L,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>n(!1),variant:"outline",children:"Close"})]})]})]})}function We(s){return X({tag:"svg",attr:{viewBox:"0 0 1024 1024"},child:[{tag:"path",attr:{d:"M926.8 397.1l-396-288a31.81 31.81 0 0 0-37.6 0l-396 288a31.99 31.99 0 0 0-11.6 35.8l151.3 466a32 32 0 0 0 30.4 22.1h489.5c13.9 0 26.1-8.9 30.4-22.1l151.3-466c4.2-13.2-.5-27.6-11.7-35.8zM838.6 417l-98.5 32-200-144.7V199.9L838.6 417zM466 567.2l-89.1 122.3-55.2-169.2L466 567.2zm-116.3-96.8L484 373.3v140.8l-134.3-43.7zM512 599.2l93.9 128.9H418.1L512 599.2zm28.1-225.9l134.2 97.1L540.1 514V373.3zM558 567.2l144.3-46.9-55.2 169.2L558 567.2zm-74-367.3v104.4L283.9 449l-98.5-32L484 199.9zM169.3 470.8l86.5 28.1 80.4 246.4-53.8 73.9-113.1-348.4zM327.1 853l50.3-69h269.3l50.3 69H327.1zm414.5-33.8l-53.8-73.9 80.4-246.4 86.5-28.1-113.1 348.4z"},child:[]}]})(s)}function Je(s){return X({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M137.39,24.06A16,16,0,0,0,120,40V80.67a15.86,15.86,0,0,0,13.25,15.76A32,32,0,1,1,96,129.68c-.41-8.22,1.27-15,5-20.26h0a15.86,15.86,0,0,0-1.69-20.47L71.69,60.68a16,16,0,0,0-23.63,1.1A103.6,103.6,0,0,0,55,202.05,103.24,103.24,0,0,0,128,232h1.49A104.3,104.3,0,0,0,232,129.48C232.75,75.18,191.19,28.88,137.39,24.06ZM60.32,71.94l27.61,28.19,0,.06A43.29,43.29,0,0,0,80.44,120H40.36A87.13,87.13,0,0,1,60.32,71.94ZM40.37,136h40.3A48,48,0,0,0,120,175.34v40.3A88,88,0,0,1,40.37,136Zm149.77,54.14A87.45,87.45,0,0,1,136,215.61V175.34a47.55,47.55,0,0,0,24.73-12.23A48,48,0,0,0,136,80.66L136,40c45.52,4.08,80.67,43.28,80,89.25A87.45,87.45,0,0,1,190.14,190.14Z"},child:[]}]})(s)}function Ye(s){return X({tag:"svg",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 Ze(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{stroke:"none",d:"M0 0h24v24H0z",fill:"none"},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 Xe(s){return X({tag:"svg",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 es(s){return X({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"M4 9h4v11H4zM4 4h4v4H4zM10 7h4v4h-4zM16 10h4v4h-4zM16 15h4v5h-4zM10 12h4v8h-4z"},child:[]}]})(s)}function ss(s){return X({tag:"svg",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 ts(s){return X({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M217 25v14h78V25h-78zm0 32v46h14V71h50v32h14V57h-78zm32 32v14h14V89h-14zm-64 32v46h30v-46h-30zm48 0v14h46v-14h-46zm64 0v46h30v-46h-30zm-64 32v14h46v-14h-46zm-80 32v46h62v-46h-62zm80 0v14h46v-14h-46zm64 0v46h62v-46h-62zm-64 32v14h46v-14h-46zm-112 32v46h94v-46h-94zm112 0v14h46v-14h-46zm64 0v46h94v-46h-94zm-64 32v14h46v-14h-46zM89 313v46h126v-46H89zm144 0v14h46v-14h-46zm64 0v46h126v-46H297zm-64 32v14h46v-14h-46zM57 377v46h158v-46H57zm176 0v14h46v-14h-46zm64 0v46h158v-46H297zm-64 32v14h46v-14h-46zM25 441v46h190v-46H25zm208 0v14h46v-14h-46zm64 0v46h190v-46H297zm-64 32v14h46v-14h-46z"},child:[]}]})(s)}function lt(){const[s,n]=S.useState(!1),t=e.useEditorStore(c=>c.card.type),{setCardType:r,setCardPreferences:o,setChartOrientation:l}=e.useEditorStore(c=>c.actions),i=e.useEditorStore(c=>c.actions.setCardCustomCfg);function a(c){i(null),o({}),r(c),n(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:n,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ct,{className:"h-4 w-4",chartType:t})})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-50",children:e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(we,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(es,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Xe,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Be,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ze,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(_e,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Je,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(We,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ye,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ts,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ss,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Le,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>a("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(He,{className:"size-4"})})]})})]})}function ct({chartType:s,className:n}){switch(s){case"bar":return e.jsxRuntimeExports.jsx(we,{className:n});case"line":return e.jsxRuntimeExports.jsx(ke,{className:n});case"pie":return e.jsxRuntimeExports.jsx(_e,{className:n});case"radar":return e.jsxRuntimeExports.jsx(We,{className:n});case"scatter":return e.jsxRuntimeExports.jsx(Be,{className:n});case"bubble":return e.jsxRuntimeExports.jsx(Ze,{className:n});case"doughnut":return e.jsxRuntimeExports.jsx(Je,{className:n});case"stackedBar":return e.jsxRuntimeExports.jsx(es,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Xe,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(Ye,{className:n});case"pyramid":return e.jsxRuntimeExports.jsx(ts,{className:n});case"range":return e.jsxRuntimeExports.jsx(Ve,{className:n});case"kpi":return e.jsxRuntimeExports.jsx(ss,{className:n});case"text":return e.jsxRuntimeExports.jsx(Le,{className:n});case"custom":return e.jsxRuntimeExports.jsx(He,{className:n});default:return e.jsxRuntimeExports.jsx(e.Table,{className:n})}}function Oe(){const s=e.useEditorStore(j=>j.frame),n=e.useEditorStore(j=>j.card),t=e.useEditorStore(j=>j.card.data),r=e.useEditorStore(j=>j.isShowingVisual),o=e.useEditorStore(j=>j.isSqlRunning),l=e.useEditorStore(j=>j.queryError),i=e.useEditorStore(j=>j.pythonStdOut),a=e.useEditorStore(j=>j.actions.setRunSql);e.useEditorStore(j=>j.onSave),e.useEditorStore(j=>j.onClose),e.useEditorStore(j=>j.actions.setCardSql),e.useEditorStore(j=>j.actions.setCardType),e.useEditorStore(j=>j.actions.setSqlGen);const{setFrame:c,setCard:m,updateCardInFrame:d}=e.useEditorActions();if(!n)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function E(){const j={id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};f(j)}function f(j){const k={...s,cards:[...s.cards,j],activeCardId:j.id};c(k),m(j)}function u(){const j={...n,id:e.v4(),title:`${n.title} Copy`};f(j)}function x(j){const k=s.cards.filter(h=>h.id!==j),C=k[0],b={...s,cards:k,activeCardId:C.id};c(b),m(C)}function R(j){const k={...s,cards:s.cards.map(b=>b.id===n.id?n:b),activeCardId:j};c(k);const C=k.cards.find(b=>b.id===j);m(C),C.sql&&(console.log("newActiveCard.sql",C.sql),C.data&&C.data.length===0&&a(!0))}const L=(j,k)=>{console.log("handleDragStart",k),j.dataTransfer.setData("tabIndex",k.toString())},I=j=>{j.preventDefault()},O=(j,k)=>{const C=j.dataTransfer.getData("tabIndex");if(C===k.toString())return;const b=Array.from(s.cards),[h]=b.splice(parseInt(C),1);b.splice(k,0,h),c({...s,cards:b})};function y(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:R,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(j=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:j.id,children:z()},j.id)),e.jsxRuntimeExports.jsx(e.TabsList,{className:"group mx-6 justify-between",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center",children:[s.cards.map((j,k)=>e.jsxRuntimeExports.jsx(e.Editable,{text:j.tabTitle||j.title,onSave:C=>{m({...n,tabTitle:C}),d({...n,tabTitle:C})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:C=>L(C,k),onDragOver:I,onDrop:C=>O(C,k),className:"",value:j.id,children:[j.tabTitle||j.title,s.activeCardId===j.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>x(j.id)})]})},j.id)),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:E,children:e.jsxRuntimeExports.jsx(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:u,children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4"})})]})})]})}function z(){return n.type==="kpi"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.KPICard,{isLoading:o,card:n})})}):n.type==="text"?e.jsxRuntimeExports.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxRuntimeExports.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:o,card:n})})}):e.jsxRuntimeExports.jsx(Ke,{className:"grow border-none shadow-none"})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[o&&e.jsxRuntimeExports.jsx(le,{className:"absolute bottom-0 left-0 right-0 top-0 z-10 m-auto h-10 w-10 animate-spin text-foreground/10"}),e.jsxRuntimeExports.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[r&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(lt,{}),n.type!=="table"&&e.jsxRuntimeExports.jsx(at,{})]}),e.jsxRuntimeExports.jsx(ut,{})]}),r?y():e.jsxRuntimeExports.jsxs("div",{className:"flex min-h-0 w-full flex-1 grow basis-0 px-6",children:[i&&e.jsxRuntimeExports.jsx(xt,{}),n.data&&n.data.length>0&&e.jsxRuntimeExports.jsx(it,{data:t||[]}),l&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-sm",children:l})]})]})}function xt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const n=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("p",{className:"font-mono text-sm",children:"Output:"}),e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n},className:"bg-muted p-2 font-mono text-sm"}),e.jsxRuntimeExports.jsx(e.Separator,{className:"mb-2"})]})}function ut(){const s=e.useEditorStore(t=>t.isShowingVisual),n=e.useEditorStore(t=>t.actions.setIsShowingVisual);return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"visualize",children:"Chart"}),e.jsxRuntimeExports.jsx(e.Switch,{checked:s,onCheckedChange:()=>n(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function dt({value:s,onValueChange:n,components:t}){var l;const[r,o]=Ce.useState(!1);return e.jsxRuntimeExports.jsxs(e.Popover,{open:r,onOpenChange:o,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{variant:"outline",role:"combobox","aria-expanded":r,className:"h-8 w-full justify-between",children:[s?(l=t.find(i=>i.value===s))==null?void 0:l.label:"Select Component...",e.jsxRuntimeExports.jsx(us,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-full p-2.5",children:e.jsxRuntimeExports.jsxs(e.Command,{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search component..."}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No component found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:t.map(i=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:i.value,onSelect:a=>{n(a===s.toLowerCase()?"":i.value),o(!1)},children:[e.jsxRuntimeExports.jsx(e.Check,{className:e.cn("mr-2 h-4 w-4",s===i.value?"opacity-100":"opacity-0")}),i.label]},i.value))})]})]})})]})}function mt(){const s=e.useEditorStore(o=>o.card.customCardPreferences),{setCustomCardPreferences:n}=e.useEditorActions(),{components:t}=e.useCustomVisual((s==null?void 0:s.url)||"");function r(o){n({...s||{url:"",componentName:""},type:o})}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-6 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx(pt,{value:(s==null?void 0:s.type)||"component",onValueChange:r})}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:`${(s==null?void 0:s.type)==="component"?"Code":"Iframe"} URL`}),e.jsxRuntimeExports.jsx(e.Input,{value:s==null?void 0:s.url,onChange:o=>n({...s||{url:"",componentName:""},url:o.target.value}),className:`h-8 w-full ${e.removeRing}`})]}),(s==null?void 0:s.type)==="component"&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx(dt,{components:(t==null?void 0:t.map(o=>({value:o.name,label:o.name})))||[],value:s==null?void 0:s.componentName,onValueChange:o=>n({...s,componentName:o})})]})]})}function pt({value:s,onValueChange:n}){return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:s,onValueChange:n,className:"flex gap-4",defaultValue:"component",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"component",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Component"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"iframe",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Iframe"})]})]})}function ce(){const[s,n]=S.useState([]);e.useEditorStore(d=>d.card.cfg);const t=e.useEditorStore(d=>d.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:l}=e.useEditorStore(d=>d.actions),i=e.useEditorStore(d=>d.queryResultColumns);e.useEditorStore(d=>{var E;return(E=d.card.preferences)==null?void 0:E.filterOnClickColumnIndex}),S.useEffect(()=>{i&&n(new Array(i.length).fill(!1))},[i]);function a(d,E){var f,u;E?t!=null&&t.onClickFilter&&((f=t==null?void 0:t.onClickFilter)==null?void 0:f.length)>0?l({...t,onClickFilter:[...t.onClickFilter,{columnIndex:d,expression:""}]}):l({...t,onClickFilter:[{columnIndex:d,expression:""}]}):(l({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(x=>x.columnIndex!==d)}),n(x=>{const R=[...x];return R[d]=!1,R}))}function c(d,E){var u;const f=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(x=>x.columnIndex===d?{...x,expression:E.target.value}:x);l({...t,onClickFilter:f})}function m(d){var E,f,u,x;if(s!=null&&s[d]||(f=(E=t==null?void 0:t.onClickFilter)==null?void 0:E.find(R=>R.columnIndex===d))!=null&&f.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(x=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(R=>R.columnIndex===d))==null?void 0:x.expression,onChange:R=>c(d,R),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.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"On Click"}),i==null?void 0:i.map((d,E)=>{var f,u;return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxRuntimeExports.jsxs("div",{className:"grow",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((f=t==null?void 0:t.onClickFilter)!=null&&f.find(x=>x.columnIndex===E)),onCheckedChange:x=>a(E,x)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:d}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(x=>x.columnIndex===E))&&e.jsxRuntimeExports.jsx(qe,{onClick:()=>{n(x=>{const R=[...x];return R[E]=!x[E],R})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(E)]})},d)})]})}function Re(){var i,a,c;const s=e.useEditorStore(m=>m.card.preferences),n=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:r,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(i=n==null?void 0:n.options)!=null&&i.indexAxis;function l(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((c=n==null?void 0:n.options)==null?void 0:c.indexAxis)||"x",onValueChange:l,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"x",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Vertical"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"y",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Horizontal"})]})]})}const he="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Me(s,n){var r,o,l;const t=e.getNumberAxis(s,n);return((l=(o=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:o[t])==null?void 0:l.type)||"linear"}function ns(){var K,q,W,v,D,H;const[s,n]=S.useState(!1),t=e.useEditorStore(w=>{var N;return(N=w.card)==null?void 0:N.preferences}),r=e.useEditorStore(w=>{var N;return(N=w.card)==null?void 0:N.cfg}),o=e.getNumberAxis(t,r),[l,i]=S.useState(Me(t)),[a,c]=S.useState(((W=(q=(K=t==null?void 0:t.chartOptions)==null?void 0:K.scales)==null?void 0:q[o])==null?void 0:W.min)||""),[m,d]=S.useState(((H=(D=(v=t==null?void 0:t.chartOptions)==null?void 0:v.scales)==null?void 0:D[o])==null?void 0:H.max)||""),[E,f]=S.useState(a||m?"custom":"auto"),[u,x]=S.useState(""),[R,L]=S.useState(0),[I,O]=S.useState(""),[y,z]=S.useState(""),[j,k]=S.useState(""),C=e.useEditorStore(w=>w.actions.setCardPreferences),{updateCardInFrame:b}=e.useEditorActions(),h=e.useEditorStore(w=>w.card),F=e.useEditorStore(w=>{var N;return(N=w.card)==null?void 0:N.type}),M=["pie","doughnut","polarArea"].includes(F);S.useEffect(()=>{var w,N,$,T,G,U,te,ee,B,J,Y,ne,Z,se;i(Me(t)),c((($=(N=(w=t==null?void 0:t.chartOptions)==null?void 0:w.scales)==null?void 0:N[o])==null?void 0:$.min)===0?0:""),d(((U=(G=(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales)==null?void 0:G[o])==null?void 0:U.max)||""),x(((J=(B=(ee=(te=t==null?void 0:t.chartOptions)==null?void 0:te.scales)==null?void 0:ee[o])==null?void 0:B.ticks)==null?void 0:J.stepSize)||""),L(((Y=t==null?void 0:t.numberAxisFormat)==null?void 0:Y.decimalPlaces)||0),O(((ne=t==null?void 0:t.numberAxisFormat)==null?void 0:ne.suffix)||""),z(((Z=t==null?void 0:t.numberAxisFormat)==null?void 0:Z.currency)||""),k(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.locale)||"")},[s,t,o]);function A(w,N){return N===""||/^[0-9\b]+$/.test(N)?Number(N):Number(w)}function V(){const w=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(N=>N.currency))];return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsxRuntimeExports.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxRuntimeExports.jsxs(e.Select,{value:y||"none",onValueChange:N=>z(N==="none"?"":N),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),w.map(N=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:N,children:N},N))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:j,onValueChange:N=>k(N),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Locale"}),e.LOCALE_CURRENCY_PAIRS.map(N=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:N.locale,children:N.locale},N.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsxRuntimeExports.jsx(e.Input,{value:R,onChange:N=>L(Number(N.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${he}`})]})]})}function P(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"range",children:"Range"}),e.jsxRuntimeExports.jsx(e.Input,{id:"min",value:a,onChange:w=>c(N=>A(N,w.target.value)),className:`col-span-1 h-8 w-full ${he}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:w=>d(N=>A(N,w.target.value)),id:"max",className:`col-span-1 h-8 w-full ${he}`})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsxRuntimeExports.jsx(e.Input,{value:u,onChange:w=>x(N=>A(N,w.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${he}`})]})]})}function _(){var T;let w={};E==="custom"&&(w={min:a,max:m,ticks:{stepSize:u}});const N={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(T=t==null?void 0:t.chartOptions)==null?void 0:T.scales,[o]:{type:l,...l==="linear"?w:{}}}},numberAxisFormat:{decimalPlaces:R,suffix:I,currency:y,locale:j}};console.log(N),C(N);const $={...h,preferences:N};b($)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:w=>n(w),children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.SliderIcon,{className:"size-4 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxRuntimeExports.jsxs("div",{className:"grid gap-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxRuntimeExports.jsxs("div",{className:"grid gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale",children:"Type"}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:M,value:l,onValueChange:w=>i(w),children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{id:"type",children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Option"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"linear",children:"Linear"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),l=="linear"&&e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsxRuntimeExports.jsx(e.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxRuntimeExports.jsxs(e.RadioGroup,{disabled:M,id:"scale-option",value:E,onValueChange:w=>f(w),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"auto",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"custom",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),E==="custom"&&l=="linear"&&P(),V(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:_,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function jt({idx:s}){var a;const n=e.useEditorStore(c=>{var m;return(m=c.card)==null?void 0:m.preferences}),t=e.useEditorStore(c=>{var m;return(m=c.card.preferences)==null?void 0:m.datasetOptions}),r=e.useEditorStore(c=>c.actions.setCardPreferences),o=(a=n==null?void 0:n.chartOptions)==null?void 0:a.indexAxis,l=t==null?void 0:t.find(c=>c.idx===s);function i(c,m){(c==="end"||c==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const d={display:c!=="none",align:c,anchor:c,clamp:!0};if(!l)r({...n,datasetOptions:[...t||[],{idx:m,datalabels:d}]});else{const E={...l};E.datalabels=d;const f=t==null?void 0:t.map(u=>u.idx===m?E:u);r({...n,datasetOptions:f})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Ts,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-fit p-1",children:e.jsxRuntimeExports.jsxs("div",{className:"flex gap-1",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("none",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(e.X,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(Ss,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(vs,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>i("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ys,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function rs(){const s=e.useEditorStore(c=>c.card),n=e.useEditorStore(c=>{var m,d,E;return(E=(d=(m=c==null?void 0:c.card)==null?void 0:m.preferences)==null?void 0:d.chartOptions)==null?void 0:E.indexAxis}),t=n==="y"?"Y axis":"X axis",r=n==="y"?"X axis":"Y axis",{keys:o,metricKeys:l,dimensionKeys:i}=e.getKeys(s.data||[]);let a=l;if(["stackedBar","stackedLine"].includes(s.type)){const c=e.pivotData({dataArray:s.data||[],groupKey:i[0],pivotKey:i[1],valueKey:a[0]}),{metricKeys:m}=e.getKeys(c);a=m}return o.length===0?null:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:t}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:e.jsxRuntimeExports.jsx("div",{className:"rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:e.jsxRuntimeExports.jsx("p",{children:i[0]})})})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between gap-5",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(ns,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:a.map((c,m)=>e.jsxRuntimeExports.jsx(ht,{col:c,idx:m},c))})]})]})}function ht({col:s,idx:n}){const t=e.useEditorStore(a=>{var c;return(c=a.card)==null?void 0:c.preferences}),r=e.useEditorStore(a=>{var c;return(c=a.card.preferences)==null?void 0:c.datasetOptions}),o=r==null?void 0:r.find(a=>a.idx===n),{setCardPreferences:l}=e.useEditorStore(a=>a.actions);function i(a){if(!o)l({...t,datasetOptions:[...r||[],{idx:n,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const c={...o};c.type=a==="area"?"line":a,c.fill=a==="area"?"origin":"";const m=r==null?void 0:r.map(d=>d.idx===n?c:d);l({...t,datasetOptions:m})}}return e.jsxRuntimeExports.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-2 py-1 hover:bg-muted",children:[e.jsxRuntimeExports.jsx("p",{children:s}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(we,{onClick:()=>i("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(ke,{onClick:()=>i("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(cs,{onClick:()=>i("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(e.Separator,{orientation:"vertical",className:"invisible size-4 cursor-pointer py-2 text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(jt,{idx:n})]})]})}function os(){const s=e.useEditorStore(f=>f.selectedConnectionId),n=e.useEditorStore(f=>f.selectedDatamodelId),t=e.useEditorStore(f=>f.selectedDatabaseName),r=e.useEditorStore(f=>f.selectedSchemaName),o=e.useEditorStore(f=>f.selectedTableName),l=e.useDashboardStore(f=>f.dashboard.filters)||[],i=e.useDashboardStore(f=>f.actions.addFilter),a=e.useDashboardStore(f=>f.actions.removeFilter),c=e.useDashboardStore(f=>f.actions.removeFilterValue),{modelItems:m,tableName:d}=oe();function E(f,u="dashboard"){var k;const x=e.fmt(f.column_name),R=e.fmt(t||""),L=e.fmt(r||""),I=e.fmt(d);let O=e.getQualifiedTableName(L,I),y=`${O}.${x}`;const z=(k=m==null?void 0:m.find(C=>C.id===n))==null?void 0:k.name;n&&n!=="none"&&(y=`${e.DATAMODEL_NAMESPCACE}.${z}.${x}`,O=`${e.DATAMODEL_NAMESPCACE}.${z}`);const j=l==null?void 0:l.find(C=>C.column===y&&C.table===I&&(C.database===R||C.database===t));if(j)c(j.id),a(j.id);else{const C=e.v4();return d==="api"&&s?(i({location:u,id:C,column:y,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(f.data_type,O,x)}),C):(i({id:C,location:u,column:y,title:f.column_name,dataType:f.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(f.data_type,O,x)}),C)}}return{assignFilter:E}}function xe(){const s=e.useDashboardStore(a=>a.dashboard.filters),n=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:r}=oe(),{assignFilter:o}=os();function l(a){const c=o(a,"frame");t({...n,filterId:c})}const i=s==null?void 0:s.find(a=>a.id===n.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(Et,{onSelect:l,columns:r}),i&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:i})]})}function Et({columns:s,onSelect:n}){var i;const[t,r]=Ce.useState(!1),[o,l]=Ce.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsxs(e.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":t,className:"w-full justify-between font-normal",children:[o?(i=s.find(a=>a.column_name===o))==null?void 0:i.column_name:"Select Column...",e.jsxRuntimeExports.jsx(e.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsxRuntimeExports.jsx(e.PopoverContent,{className:"w-[200px] p-0",children:e.jsxRuntimeExports.jsxs(e.Command,{children:[e.jsxRuntimeExports.jsx(e.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxRuntimeExports.jsxs(e.CommandList,{children:[e.jsxRuntimeExports.jsx(e.CommandEmpty,{children:"No framework found."}),e.jsxRuntimeExports.jsx(e.CommandGroup,{children:s.map(a=>e.jsxRuntimeExports.jsxs(e.CommandItem,{value:a.column_name,onSelect:c=>{const m=c===o?"":c;l(m),r(!1),m&&n(a)},children:[a.column_name,e.jsxRuntimeExports.jsx(e.CheckIcon,{className:e.cn("ml-auto h-4 w-4",o===a.column_name?"opacity-100":"opacity-0")})]},a.column_name))})]})]})})]})}function ft({cardType:s}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis1 - number"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis2 - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#line-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(rs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function Ie(){var o,l,i;const s=e.useEditorStore(a=>a.card.cfg),n=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function r(a){var d;const c={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(d=s==null?void 0:s.options)==null?void 0:d.plugins,...c}}};n(m),console.log(a)}return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxRuntimeExports.jsx("label",{className:"font-medium",children:"Data Labels"}),!["pyramid"].includes(t)&&e.jsxRuntimeExports.jsx(ns,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(i=(l=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:l.datalabels)==null?void 0:i.anchor,onValueChange:r,defaultValue:"none",children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:"Select position"})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Data Labels"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"start",children:"Start"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"center",children:"Center"}),t!=="pyramid"&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:"end",children:"End"})]})})]})]})}function gt({cardType:s}){function n(t){const r="SELECT label, [group], x-axis, y-axis, radius FROM table",o="SELECT label, [group], x-axis, y-axis FROM table";return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:t==="bubble"?r:o}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"group - category"}),e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - category"}),t==="bubble"&&e.jsxRuntimeExports.jsx("li",{children:"radius - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:l=>l.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})}return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} Chart`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(s)})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsx(e.AccordionContent,{className:"px-2",children:e.jsxRuntimeExports.jsx(Ie,{})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}const Rt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},bt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function St(){const s=e.useEditorStore(n=>n.card.type);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 p-6",children:[e.jsxRuntimeExports.jsx(e.Accordion,{className:" ",type:"single",collapsible:!0,children:yt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Re,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Ie,{}),e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})}function yt(s){if(["line","bar"].includes(s))return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsx("p",{children:"Chart Query"})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(Rt,null,2)})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxRuntimeExports.jsxs("p",{children:["Click ",e.jsxRuntimeExports.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsxRuntimeExports.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.jsxRuntimeExports.jsx("pre",{children:JSON.stringify(bt,null,2)})]})]})]});if(s==="bubble")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsxRuntimeExports.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(s==="scatter")return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:["How to create a ",e.jsxRuntimeExports.jsx("span",{children:s})," chart query?"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsxRuntimeExports.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsxRuntimeExports.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(s))return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"font-normal",children:e.jsxRuntimeExports.jsxs("p",{children:[e.jsxRuntimeExports.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:" ",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"Label - Category (ex. city)"}),e.jsxRuntimeExports.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function vt(){var c,m,d,E,f;const s=e.useEditorStore(u=>u.card.preferences),n=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.decimalPlaces});const r=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.locale}),o=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const l=e.useEditorStore(u=>{var x,R;return(R=(x=u.card.preferences)==null?void 0:x.formatNumber)==null?void 0:R.colorRanges})||[],i=e.useEditorStore(u=>u.actions.setColorRanges),a=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxRuntimeExports.jsxs("div",{children:[e.jsxRuntimeExports.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:u=>{n({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:u}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Format Number"})]}),((m=s==null?void 0:s.formatNumber)==null?void 0:m.enabled)===!0&&e.jsxRuntimeExports.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxRuntimeExports.jsx("div",{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Locale"}),e.jsxRuntimeExports.jsxs(e.Select,{value:r||"en-US",onValueChange:u=>{var x,R,L;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",u||"en-US",((L=s==null?void 0:s.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Format"}),e.LOCALE_CURRENCY_PAIRS.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.locale,children:u.locale},u.locale))]})})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Currency"}),e.jsxRuntimeExports.jsxs(e.Select,{value:o||"none",onValueChange:u=>{var x,R,L;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,u==="none"?"":u,((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:"Currency"}),e.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),a.map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))]})})]})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Decimals"}),e.jsxRuntimeExports.jsxs(e.Select,{value:((E=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:E.toString())||"0",onValueChange:u=>{var x,R,L;return t(Number(u),((x=s==null?void 0:s.formatNumber)==null?void 0:x.currency)||"",((R=s==null?void 0:s.formatNumber)==null?void 0:R.locale)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.suffix)||"")},children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsxRuntimeExports.jsx(e.SelectValue,{})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:["0","1","2","3","4"].map(u=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u,children:u},u))})]})]}),e.jsxRuntimeExports.jsxs("div",{className:"w-full space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Suffix"}),e.jsxRuntimeExports.jsx(e.Input,{value:((f=s==null?void 0:s.formatNumber)==null?void 0:f.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var x,R,L;return t(((x=s==null?void 0:s.formatNumber)==null?void 0:x.decimalPlaces)||0,((R=s==null?void 0:s.formatNumber)==null?void 0:R.currency)||"",((L=s==null?void 0:s.formatNumber)==null?void 0:L.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:l,setColorRanges:i})]})]})}function Ct(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{type:"single",collapsible:!0,children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"font-mono",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"current - number"}),e.jsxRuntimeExports.jsx("li",{children:"previous - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#kpi",children:"example"})," in the docs."]})]})]})}),e.jsxRuntimeExports.jsx("section",{className:"",children:e.jsxRuntimeExports.jsx(vt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}function Nt(){var r;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=e.useEditorStore(o=>o.actions);function t(o){n({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(r=s==null?void 0:s.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:t,className:"flex gap-3",defaultValue:"x",children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"static",id:"r1"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Ee({cardType:s,docContent:n,suffix:t="Chart"}){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:`${e.titleCase(s)} ${t}`}),e.jsxRuntimeExports.jsx(e.AccordionContent,{children:n||e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"label - category"}),e.jsxRuntimeExports.jsx("li",{children:"measure - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pie-chart",children:"example"})," in the docs."]})]})})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[s==="range"&&e.jsxRuntimeExports.jsx(Re,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Ie,{}),s==="text"&&e.jsxRuntimeExports.jsx(Nt,{})]})]}),!["range","text"].includes(s)&&e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function wt(){return e.jsxRuntimeExports.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxRuntimeExports.jsxs(e.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-1",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Stacked Chart"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxRuntimeExports.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsxRuntimeExports.jsx("li",{children:"x-axis - category"}),e.jsxRuntimeExports.jsx("li",{children:"stack by - category"}),e.jsxRuntimeExports.jsx("li",{children:"y-axis - number"})]}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#stacked-chart",children:"example"})," in the docs."]})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-2",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Settings"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(Re,{}),e.jsxRuntimeExports.jsx(rs,{})]})]}),e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})]})})}function kt({}){const s=e.useEditorStore(r=>{var o;return(o=r.card)==null?void 0:o.preferences}),n=e.useEditorStore(r=>r.actions.setCardPreferences),t=r=>{n({...s,allowDownload:r})};return e.jsxRuntimeExports.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxRuntimeExports.jsx(e.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxRuntimeExports.jsxs(e.AccordionItem,{value:"item-3",children:[e.jsxRuntimeExports.jsx(e.AccordionTrigger,{children:"Filters"}),e.jsxRuntimeExports.jsxs(e.AccordionContent,{className:"space-y-4 px-2",children:[e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(xe,{})]})]})}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.Checkbox,{onCheckedChange:t,id:"allow-download"}),e.jsxRuntimeExports.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 Lt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#pyramid-chart",children:"example"})," in the docs."]})]}),Dt=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.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.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#range-charts",children:"example"})," in the docs."]})]}),It=e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsxRuntimeExports.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxRuntimeExports.jsxs("div",{children:["See ",e.jsxRuntimeExports.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/concepts/visuals#text-visual",children:"example"})," in the docs."]})]});function At(){const s=e.useEditorStore(t=>t.card.type);function n(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(wt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ee,{docContent:Lt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Ct,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(ft,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ee,{docContent:Dt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ee,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(gt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(kt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ee,{docContent:It,cardType:t,suffix:"Visual"});case"custom":return e.jsxRuntimeExports.jsx(mt,{});default:return e.jsxRuntimeExports.jsx(St,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:n(s)})}function Tt(){const s=e.useEditorStore(n=>n.isShowingVisual);return e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsxRuntimeExports.jsx(ot,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:s?e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{direction:"horizontal",children:[e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsx(e.ResizablePanel,{className:"flex min-w-[275px]",minSize:20,defaultSize:25,maxSize:30,children:e.jsxRuntimeExports.jsx(At,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Oe,{})})]}):e.jsxRuntimeExports.jsx(Oe,{})})]})}function zt({authToken:s,onSave:n,onClose:t}){const r=e.useEditorStore(i=>i.actions.setOnSave),o=e.useEditorStore(i=>i.actions.setOnClose),l=e.useDashboardStore(i=>i.actions.setAuthToken);return S.useEffect(()=>{n&&r(n),t&&o(t)},[n,r,t,o]),S.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),e.jsxRuntimeExports.jsxs(e.EditorPanel,{className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(Ge,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Tt,{})})]})}function Ft(){e.useDashboardStore(i=>i.selectedCardId);const s=e.useDashboardStore(i=>i.selectedSheetId),{setIsVisualEditing:n}=e.useDashboardStore(i=>i.actions),t=e.useDashboardStore(i=>i.isVisualEditing),r=e.useDashboardStore(i=>i.actions.updateFrame);function o(i){s&&(r(s,i),n(!1))}function l(){n(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{block:t,hidden:!t}),children:e.jsxRuntimeExports.jsx(zt,{onSave:o,onClose:l})})}function Ot(){e.useEditorStore(i=>i.selectedConnectionId),e.useEditorStore(i=>i.selectedDatamodelId);const s=e.useEditorStore(i=>i.selectedDatabaseName);e.useEditorStore(i=>i.selectedSchemaName);const n=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[];e.useDashboardStore(i=>i.actions.addFilter),e.useDashboardStore(i=>i.actions.removeFilter),e.useDashboardStore(i=>i.actions.removeFilterValue);const{modelItems:r,columns:o}=oe(),{assignFilter:l}=os();return e.jsxRuntimeExports.jsx("div",{className:"xbg-red-100 flex-1 basis-0 flex-col overflow-scroll px-3",children:o==null?void 0:o.map(i=>{const a=t==null?void 0:t.find(c=>c.column===e.fmt(i.column_name)&&c.table===n&&c.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>l(i),className:e.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":a}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx($e,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Mt(){e.useDashboardStore(n=>n.showFilters);const s=e.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex grow flex-col border-l px-4",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-lg",children:"Filters"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{})})]}),e.jsxRuntimeExports.jsx("div",{className:"flex grow",children:e.jsxRuntimeExports.jsx(Ge,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Ot,{})})})]})}function Vt(){const s=e.useDashboardStore(t=>t.showFilters),n=e.useDashboardStore(t=>t.isVisualEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("grow",{hidden:n,flex:!n}),children:[e.jsxRuntimeExports.jsx(e.DashboardTabs,{}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Mt,{})})]})}function qt(){const s=e.useDashboardStore(r=>r.dashboard),n=e.useDashboardStore(r=>r.actions.setDashboard),t=e.useDashboardStore(r=>r.showDashboardJSON);return e.useDashboardStore(r=>r.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:r=>{if(r)try{JSON.parse(r),n(JSON.parse(r))}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 _t({showControls:s=!1,showFooter:n=!0,...t}){return e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Te,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(qt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Bs,{}),e.jsxRuntimeExports.jsx(Ft,{}),e.jsxRuntimeExports.jsx(Vt,{})]})]})]})}exports.DashboardPlus=_t;exports.LoaderCircle=le;exports.SelectComponent=ae;exports.cleanCard=Pe;exports.getDashbaordStateWithoutData=De;exports.useEditorAside=oe;