react-semaphor 0.0.337 → 0.0.338

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.
@@ -1,4 +1,4 @@
1
- "use strict";const e=require("./index-D0bAJoup.js"),S=require("react");require("react-dom");function Ps(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const He=Ps(S);/**
1
+ "use strict";const e=require("./index-D0bAJoup.js"),S=require("react");require("react-dom");function Hs(s){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return r.default=s,Object.freeze(r)}const He=Hs(S);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,7 +8,12 @@
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const Ke=e.createLucideIcon("ChartArea",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M7 11.207a.5.5 0 0 1 .146-.353l2-2a.5.5 0 0 1 .708 0l3.292 3.292a.5.5 0 0 0 .708 0l4.292-4.292a.5.5 0 0 1 .854.353V16a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z",key:"q0gr47"}]]);/**
11
+ */const Ke=e.createLucideIcon("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
12
+ * @license lucide-react v0.453.0 - ISC
13
+ *
14
+ * This source code is licensed under the ISC license.
15
+ * See the LICENSE file in the root directory of this source tree.
16
+ */const We=e.createLucideIcon("ChartArea",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M7 11.207a.5.5 0 0 1 .146-.353l2-2a.5.5 0 0 1 .708 0l3.292 3.292a.5.5 0 0 0 .708 0l4.292-4.292a.5.5 0 0 1 .854.353V16a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z",key:"q0gr47"}]]);/**
12
17
  * @license lucide-react v0.453.0 - ISC
13
18
  *
14
19
  * This source code is licensed under the ISC license.
@@ -38,17 +43,17 @@
38
43
  *
39
44
  * This source code is licensed under the ISC license.
40
45
  * See the LICENSE file in the root directory of this source tree.
41
- */const We=e.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
46
+ */const Ye=e.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
42
47
  * @license lucide-react v0.453.0 - ISC
43
48
  *
44
49
  * This source code is licensed under the ISC license.
45
50
  * See the LICENSE file in the root directory of this source tree.
46
- */const Ye=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"}]]);/**
51
+ */const Xe=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"}]]);/**
47
52
  * @license lucide-react v0.453.0 - ISC
48
53
  *
49
54
  * This source code is licensed under the ISC license.
50
55
  * See the LICENSE file in the root directory of this source tree.
51
- */const Xe=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"}]]);/**
56
+ */const Ze=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"}]]);/**
52
57
  * @license lucide-react v0.453.0 - ISC
53
58
  *
54
59
  * This source code is licensed under the ISC license.
@@ -58,47 +63,47 @@
58
63
  *
59
64
  * This source code is licensed under the ISC license.
60
65
  * See the LICENSE file in the root directory of this source tree.
61
- */const Ze=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"}]]);/**
66
+ */const es=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"}]]);/**
62
67
  * @license lucide-react v0.453.0 - ISC
63
68
  *
64
69
  * This source code is licensed under the ISC license.
65
70
  * See the LICENSE file in the root directory of this source tree.
66
- */const es=e.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
71
+ */const ss=e.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
67
72
  * @license lucide-react v0.453.0 - ISC
68
73
  *
69
74
  * This source code is licensed under the ISC license.
70
75
  * See the LICENSE file in the root directory of this source tree.
71
- */const ss=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"}]]);/**
76
+ */const ts=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"}]]);/**
72
77
  * @license lucide-react v0.453.0 - ISC
73
78
  *
74
79
  * This source code is licensed under the ISC license.
75
80
  * See the LICENSE file in the root directory of this source tree.
76
- */const ts=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"}]]);/**
81
+ */const ns=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"}]]);/**
77
82
  * @license lucide-react v0.453.0 - ISC
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 ns=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"}]]);/**
86
+ */const rs=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"}]]);/**
82
87
  * @license lucide-react v0.453.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 rs=e.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
91
+ */const os=e.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
87
92
  * @license lucide-react v0.453.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 os=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"}]]);/**
96
+ */const is=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"}]]);/**
92
97
  * @license lucide-react v0.453.0 - ISC
93
98
  *
94
99
  * This source code is licensed under the ISC license.
95
100
  * See the LICENSE file in the root directory of this source tree.
96
- */const is=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"}]]);/**
101
+ */const as=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"}]]);/**
97
102
  * @license lucide-react v0.453.0 - ISC
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 as=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"}]]);/**
106
+ */const ls=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"}]]);/**
102
107
  * @license lucide-react v0.453.0 - ISC
103
108
  *
104
109
  * This source code is licensed under the ISC license.
@@ -113,27 +118,27 @@
113
118
  *
114
119
  * This source code is licensed under the ISC license.
115
120
  * See the LICENSE file in the root directory of this source tree.
116
- */const ls=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"}]]);/**
121
+ */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"}]]);/**
117
122
  * @license lucide-react v0.453.0 - ISC
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 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"}]]);/**
126
+ */const xs=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"}]]);/**
122
127
  * @license lucide-react v0.453.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 xs=e.createLucideIcon("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
131
+ */const us=e.createLucideIcon("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/**
127
132
  * @license lucide-react v0.453.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 us=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 0Z",key:"wtfw2c"}]]);/**
136
+ */const ds=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 0Z",key:"wtfw2c"}]]);/**
132
137
  * @license lucide-react v0.453.0 - ISC
133
138
  *
134
139
  * This source code is licensed under the ISC license.
135
140
  * See the LICENSE file in the root directory of this source tree.
136
- */const ds=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"}]]);/**
141
+ */const ms=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"}]]);/**
137
142
  * @license lucide-react v0.453.0 - ISC
138
143
  *
139
144
  * This source code is licensed under the ISC license.
@@ -143,27 +148,27 @@
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 ms=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 ps=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.453.0 - ISC
148
153
  *
149
154
  * This source code is licensed under the ISC license.
150
155
  * See the LICENSE file in the root directory of this source tree.
151
- */const ps=e.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
156
+ */const js=e.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
152
157
  * @license lucide-react v0.453.0 - ISC
153
158
  *
154
159
  * This source code is licensed under the ISC license.
155
160
  * See the LICENSE file in the root directory of this source tree.
156
- */const js=e.createLucideIcon("SwatchBook",[["path",{d:"M11 17a4 4 0 0 1-8 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2Z",key:"1ldrpk"}],["path",{d:"M16.7 13H19a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H7",key:"11i5po"}],["path",{d:"M 7 17h.01",key:"1euzgo"}],["path",{d:"m11 8 2.3-2.3a2.4 2.4 0 0 1 3.404.004L18.6 7.6a2.4 2.4 0 0 1 .026 3.434L9.9 19.8",key:"o2gii7"}]]);/**
161
+ */const hs=e.createLucideIcon("SwatchBook",[["path",{d:"M11 17a4 4 0 0 1-8 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2Z",key:"1ldrpk"}],["path",{d:"M16.7 13H19a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2H7",key:"11i5po"}],["path",{d:"M 7 17h.01",key:"1euzgo"}],["path",{d:"m11 8 2.3-2.3a2.4 2.4 0 0 1 3.404.004L18.6 7.6a2.4 2.4 0 0 1 .026 3.434L9.9 19.8",key:"o2gii7"}]]);/**
157
162
  * @license lucide-react v0.453.0 - ISC
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 hs=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 Es=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.453.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 Es=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 fs=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.453.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 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 _e(s){var r;return{...s,sheets:(r=s==null?void 0:s.sheets)==null?void 0:r.map(t=>{var n;return{...t,frames:(n=t.frames)==null?void 0:n.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(x=>gs(x))}})}})}}function gs(s){var r,t,n,o;return{...s,cfg:{...s.cfg,data:{...(r=s.cfg)==null?void 0:r.data,labels:[],datasets:(o=(n=(t=s.cfg)==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:Hs(s.customCfg),data:[]}}function Hs(s){var r,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(r=s==null?void 0:s.data)==null?void 0:r.datasets)==null?void 0:t.map(n=>({...n,data:[]}))}}:null}async function Gs(s,r,t,n){if(!n)return null;const o=JSON.stringify(r);return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{name:s,template:o,filterValues:t,operation:"create"})}async function Ae(s,r){if(!r)return null;const{id:t,template:n,filterValues:o,isDefault:i,shared:x}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{lensId:t,template:n,filterValues:o,isDefault:i,shared:x,operation:"update"})}async function $s(s,r){return r?await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{operation:"delete",lensId:s}):null}function Us(){const[s,r]=S.useState(""),[t,n]=S.useState(!1),o=e.useDashboardStore(b=>b.lenses),{setLenses:i,setSelectedLensId:x}=e.useDashboardActions(),[a,l]=S.useState(!1),[m,c]=S.useState(!1),E=e.useDashboardStore(b=>b.dashboard),h=e.useDashboardStore(b=>b.filterValues),{authToken:u}=e.useSemaphorContext();async function j(){l(!0);const b=_e(E),k=await Gs(s,b,h,u==null?void 0:u.accessToken);k&&(i([...o||[],k]),x(k.id),c(!1)),l(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:m,onOpenChange:c,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:b=>{r(b.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:j,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Qs(){const[s,r]=S.useState(!1),t=e.useDashboardStore(c=>c.lenses),n=e.useDashboardStore(c=>c.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:x}=e.useSemaphorContext();async function a(c){i(c)}async function l(c){if(await $s(c,x==null?void 0:x.accessToken)){const h=t==null?void 0:t.filter(u=>u.id!==c);o(h||[]),i("original")}}async function m(c){const E=t==null?void 0:t.map(j=>j.id===c.id?{...j,isDefault:!c.isDefault}:{...j,isDefault:!1});o(E||[]);const h={...c,isDefault:!c.isDefault};await Ae(h,x==null?void 0:x.accessToken);const u=t==null?void 0:t.find(j=>j.isDefault);if(u&&u.id!==c.id){const j={...u,isDefault:!1};await Ae(j,x==null?void 0:x.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:r,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(ss,{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:n,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(c=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:c.id,children:[e.jsxRuntimeExports.jsx("p",{children:c.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(rs,{onClick:E=>{E.preventDefault(),m(c)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!c.isDefault,"text-green-500":c.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:E=>{E.preventDefault(),l(c.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},c.id))]})]})]})}function Js({iconClassName:s}){const[r,t]=S.useState(!1),{authToken:n}=e.useSemaphorContext(),o=e.useDashboardStore(a=>a.theme),i=e.useDashboardStore(a=>a.filterValues);async function x(){{t(!0);const a=new URLSearchParams;a.set("token",(n==null?void 0:n.accessToken)||""),a.set("theme",o||"light"),a.set("filterValues",JSON.stringify(i));const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(a.toString())}`,c=await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${n==null?void 0:n.accessToken}`}})).blob(),E=URL.createObjectURL(c);window.open(E,"_blank"),t(!1)}}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:x,children:r?e.jsxRuntimeExports.jsx(ae,{className:e.cn("size-3.5 animate-spin",s)}):e.jsxRuntimeExports.jsx(e.Download,{className:e.cn("size-3.5",s),strokeWidth:1.5})})}function Ks(){S.useState(!1);const{authToken:s}=e.useSemaphorContext();e.useDashboardStore(p=>p.theme);const r=e.useDashboardStore(p=>p.lenses),t=e.useDashboardStore(p=>p.selectedLensId),n=r==null?void 0:r.find(p=>p.id===t),o=e.useDashboardStore(p=>p.dashboard);e.useDashboardStore(p=>p.selectedSheetId);const i=e.useDashboardStore(p=>p.isDashboardEditing),x=e.useEditorStore(p=>p.selectedConnectionId),[a,l]=S.useState(!1),m=e.useDashboardStore(p=>p.filterValues),c=e.useDashboardStore(p=>p.isVisualEditing),E=e.useDashboardStore(p=>p.showFilters);e.useDashboardStore(p=>p.showDashboardJSON);const h=e.useDashboardStore(p=>p.onSaveFunction),u=e.useDashboardStore(p=>p.actions.setShowFilters),{addFrame:j,setSelectedFrameId:b}=e.useDashboardStore(p=>p.actions),{getSelectedSheet:k,setIsDashboardEditing:g,setShowDashboardJSON:T}=e.useDashboardStore(p=>p.actions),I=k(),{tenantId:O,endUserId:y}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),D=S.useMemo(()=>O||y,[O,y]),A=()=>{if(!i||!I)return;const p={connectionId:x,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},w={id:e.v4(),cards:[p],activeCardId:p.id};j(I.id,w),b(w.id)},d=()=>{g(!0)};async function R(){if(l(!0),!t||!n)return;const p=_e(o),w=JSON.stringify(p),C={...n,template:w,filterValues:m};await Ae(C,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),h==null||h(p),l(!1)}return c?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:[!c&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:n==null?void 0:n.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Js,{}),i&&!c&&D&&e.jsxRuntimeExports.jsx(Us,{}),!c&&D&&e.jsxRuntimeExports.jsx(Qs,{}),i&&!c&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:A,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:d,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!c&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{g(!1),T(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!c&&D&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:a,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ds,{className:"h-4 w-4",strokeWidth:1.5})}),!E&&!c&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>u(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!c&&i&&!1,!c&&!1]})]})}function pe({title:s,items:r,value:t,isLoading:n,isError:o,connectionTooltip:i,onChange:x,showNone:a=!1,className:l,showIcon:m=!0,disabled:c=!1}){const E=n?"Loading...":o?"Error":t;function h(){if(s==="Connection")return e.jsxRuntimeExports.jsx(us,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Xe,{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(Je,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:i?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:h()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:i})]}):h()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:c,value:E,onValueChange:x,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",l),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:n?"Loading...":o?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[n?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"),r&&r.map((u,j)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.id,children:u.name},j))]}),(n||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:E,children:E})]})})]})]})}function Ws({column:s}){const[r,t]=S.useState(!1),n=e.useEditorStore(u=>u.selectedTableName),o=e.useEditorStore(u=>u.selectedSchemaName),i=e.useEditorStore(u=>u.selectedDatamodelId),x=e.useEditorStore(u=>u.sqlGen),{modelItems:a}=le(),l=e.useEditorStore(u=>u.actions.setSqlGen),m=e.useEditorStore(u=>u.actions.setCardSql),c=e.useEditorStore(u=>u.actions.setRunSql);function E(u,j){var T;const b=e.createSqlGenConfig(u,x,j),k=(T=a==null?void 0:a.find(I=>I.id===i))==null?void 0:T.name;l(b);const g=e.getSql(b,e.fmt(o||""),e.fmt(n),k);g&&(m(g),c(!0)),t(!1)}function h(){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:r,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{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:h()})]})}function Rs({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(De,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(ns,{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(Es,{className:"size-3"}):e.jsxRuntimeExports.jsx(ms,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Ys({schemaName:s,tableName:r,columns:t,status:n}){const o=e.useEditorStore(d=>d.sqlGen),i=e.useEditorStore(d=>d.selectedConnectionId),x=e.useEditorStore(d=>d.selectedDatabaseName),a=e.useEditorStore(d=>d.selectedSchemaName),l=e.useEditorStore(d=>d.selectedTableName),m=e.useEditorStore(d=>d.selectedDatamodelId),c=e.useDashboardStore(d=>d.dashboard.aiScopeTables),{setAIScopeTables:E}=e.useDashboardStore(d=>d.actions),h=e.useEditorStore(d=>d.actions.setRunSql),u=e.useEditorStore(d=>d.actions.setSqlGen),j=e.useEditorStore(d=>d.actions.setIsShowingVisual),b=e.useEditorStore(d=>d.actions.setCardSql),{connectionType:k,modelItems:g}=le();function T(d){var C;const R=e.createSqlGenConfig(d,o);u(R);const p=(C=g==null?void 0:g.find(F=>F.id===m))==null?void 0:C.name,w=e.getSql(R,e.fmt(s),e.fmt(r),p);w&&(b(w),h(!0))}function I(){return(c==null?void 0:c.find(d=>d.connectinonId===i&&d.tableName===l))!==void 0}function O(d){if(d===!0&&l&&i){const R={connectinonId:i,connectionType:k,databaseName:x,schemaName:a,tableName:l},w=[...c||[],R].filter((C,F,M)=>M.findIndex(B=>B.connectinonId===C.connectinonId&&B.tableName===C.tableName)===F);E(w),e.ce.success(`Added '${l}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const R=(c||[]).filter(p=>p.connectinonId!==i&&p.tableName!==l);E(R),e.ce(`Removed '${l}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function y(){var C;let d=e.getQualifiedTableName(s,r);const R=(C=g==null?void 0:g.find(F=>F.id===m))==null?void 0:C.name;m&&m!=="none"&&(d=`${e.DATAMODEL_NAMESPCACE}.${R}`);let p=d;return(F=>/[A-Z]/.test(F))(r)&&(p=p.split(".").map(M=>`"${M}"`).join(".")),p}function D(){const d=y();j(!1);const R=k==="MSSQL"?`SELECT top 10 * FROM ${d}`:`SELECT * FROM ${d} LIMIT 10`;b(R),h(!0)}function A(){const d=y();b(`SELECT COUNT(*) as count FROM ${d}`),h(!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:`${I()?"Remove from":"Add to"} AI Scope`,pressed:I(),onPressedChange:O,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":I(),"text-muted-foreground":!I()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:D,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(ps,{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(d=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>T(d),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(d,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:R=>R.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(d.data_type)&&e.jsxRuntimeExports.jsx(Ws,{column:d})})]},d.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function le(s,r){var ie,be,fe,ye,Se;let t=S.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,o=e.useEditorStore(v=>v.selectedConnectionId),i=e.useEditorStore(v=>v.selectedDatamodelId),x=e.useEditorStore(v=>v.selectedDatabaseName),a=e.useEditorStore(v=>v.selectedSchemaName),l=e.useEditorStore(v=>v.selectedTableName),m=e.useEditorStore(v=>v.actions.setCurrentColumns),c=e.useEditorStore(v=>v.actions.setSelectedConnectionId),E=e.useEditorStore(v=>v.actions.setSelectedDatamodelId),h=e.useEditorStore(v=>v.actions.setSelectedDatabaseName),u=e.useEditorStore(v=>v.actions.setSelectedSchemaName),j=e.useEditorStore(v=>v.actions.setSelectedTableName),b=e.useEditorStore(v=>v.actions.setCardSql);function k(v){return o&&x&&a&&x!=="NA"?!0:o&&v==="API"?!1:!!(o&&v==="S3")}function g(v){return!!(o&&x&&x!=="NA"&&a&&l||o&&(v==="S3"||v==="API")||i&&i)}function T(v){return o&&v?!(v==="API"||v==="S3"):!1}const{data:I,isLoading:O,isError:y}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)}),{data:D,isLoading:A,isError:d}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:o}),enabled:!!(n!=null&&n.accessToken)&&!!o}),R=I==null?void 0:I.connections.find(v=>v.id===o),p=R==null?void 0:R.type,w=(R==null?void 0:R.type)==="API"||(R==null?void 0:R.type)==="S3",{data:C,isLoading:F,isFetching:M,isError:B,refetch:P}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:o}),enabled:T(p)}),{data:_,isLoading:$,isFetching:N,isError:V,refetch:G}=e.useQuery({queryKey:["schemas",o,x],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:o,database_name:x}),enabled:!!o&&!!x&&!w&&x!=="NA"}),{data:z,isLoading:L,isFetching:U,isError:q,refetch:Q}=e.useQuery({queryKey:["tables",o,x,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:o,database_name:x,schema_name:a}),enabled:k(p)}),{data:K,isLoading:X,isFetching:Z,isError:ee}=e.useQuery({queryKey:["columns",o,x,i,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:x,schema_name:a,table_name:l}),enabled:g(p)});S.useEffect(()=>{m(t)},[K,m,t]),S.useEffect(()=>{},[w,b,j,u,h,R]);const re=(R==null?void 0:R.type)==="API"?(ie=R==null?void 0:R.type)==null?void 0:ie.toLowerCase():l||"",oe=w?"":a||"";function xe(v){u(v),j("")}function se(v){h(v==="none"?"":v),u(""),j(""),v!=="none"&&v!==""&&E("")}function H(v){c(v)}function ue(v){E(v==="none"?"":v),v!=="none"&&v!==""&&h("")}C&&((be=C==null?void 0:C.databases)==null?void 0:be.length)>0,_&&((fe=_==null?void 0:_.schemas)==null?void 0:fe.length)>0,K&&((ye=K==null?void 0:K.columns)==null?void 0:ye.length)>0&&(t=K.columns.map(v=>({...v,data_type:v.data_type.toLowerCase()}))),B&&(t=[]),(ee||y)&&(t=[]);const de=I==null?void 0:I.connections.map(v=>({id:v.id,name:v.name,type:v.type})),Re=(Se=D==null?void 0:D.datamodels)==null?void 0:Se.map(v=>({id:v.id,name:v.name})),me=C==null?void 0:C.databases.map(v=>({id:v.database_name,name:v.database_name})),he=_==null?void 0:_.schemas.map(v=>({id:v.schema_name,name:v.schema_name})),Ee=z==null?void 0:z.tables.map(v=>({id:v.table_name,name:v.table_name}));return{connectionItems:de,isConnectionsLoading:O,isConnectionsError:y,modelItems:Re,isModelsLoading:A,isModelsError:d,databaseItems:me,isDatabasesLoadingOrFetching:F||M,isDatabaseError:B,schemaItems:he,isSchemaLoadingOrFetching:$||N,isSchemaError:V,tableItems:Ee,isTableLoadingOrFetching:L||U,isTableError:q,columns:t,isColumnsLoadingOrFetching:X||Z,isColumnsError:ee,isNonDbConnection:w,connectionType:p,tableName:re,schemaName:oe,handleConnectionChange:H,handleDatamodelChange:ue,handleDatabaseChange:se,handleSchemaChange:xe}}function bs({ColumnsComponent:s}){var U;const r=e.useEditorStore(q=>q.selectedConnectionId),t=e.useEditorStore(q=>q.selectedDatamodelId),n=e.useEditorStore(q=>q.selectedDatabaseName),o=e.useEditorStore(q=>q.selectedSchemaName),i=e.useEditorStore(q=>q.selectedTableName),x=e.useEditorStore(q=>q.actions.setSelectedTableName),{connectionItems:a,modelItems:l,schemaItems:m,databaseItems:c,tableItems:E,columns:h,isConnectionsLoading:u,isModelsLoading:j,isConnectionsError:b,isModelsError:k,isDatabasesLoadingOrFetching:g,isDatabaseError:T,isSchemaLoadingOrFetching:I,isSchemaError:O,isColumnsError:y,isColumnsLoadingOrFetching:D,isTableLoadingOrFetching:A,isTableError:d,connectionType:R,isNonDbConnection:p,handleConnectionChange:w,handleDatabaseChange:C,handleSchemaChange:F,handleDatamodelChange:M,tableName:B,schemaName:P}=le();function _(){return s?s(P,B,h):e.jsxRuntimeExports.jsx(Ys,{schemaName:P,tableName:B,columns:h,status:D?"Loading...":y?"Error":"Success"})}function $(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function N(){if(!r||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:C,isError:T,isLoading:g,items:c,value:n||"",title:"Database"})}function V(){if(r&&!p&&(!n||n==="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 G(){if(!r||R==="S3"||R==="API")return null;if(!n||n==="none")return e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:M,isError:k,isLoading:j,items:l,value:t||"",title:"Model"})}function z(){return!r||R==="S3"||R==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:F,isError:O,isLoading:I,items:m,value:o||"",title:"Schema"})}function L(){function q(){let Q=!1;return R==="API"?(Q=!1,Q):((R==="S3"||r&&n&&n!=="none"&&o)&&(Q=!0),Q)}return q()?e.jsxRuntimeExports.jsx(pe,{onChange:x,isError:d,items:E,isLoading:A,value:i||"",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(pe,{items:a,title:"Connection",value:r||"",onChange:w,isLoading:u,isError:b,connectionTooltip:((U=a==null?void 0:a.find(q=>q.id===r))==null?void 0:U.type)||""}),G(),V(),N(),z(),L()]}),_(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:$,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(ls,{className:"mr-2 size-4"}),"Help"]})})]})}function Xs(s){const r=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),n=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let i=s.length;if(o!==-1&&(i=o),n!==-1&&n<i&&(i=n),r!==-1){const x=s.substring(0,r),a=s.substring(r);return`${x} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const x=s.substring(0,t),a=s.substring(t);return`${x} {{ filters | where }} ${a}`}else{const x=s.substring(0,i),a=s.substring(i);return`${x} {{ filters | where }} ${a}`}}function Zs({error:s,setShowAIDialog:r,setUserInputforAI:t,setTriggerAIRun:n}){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(We,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",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:()=>{r(!0),t(s),n(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ts,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}const et=`
181
+ */const gs=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 _e(s){var r;return{...s,sheets:(r=s==null?void 0:s.sheets)==null?void 0:r.map(t=>{var n;return{...t,frames:(n=t.frames)==null?void 0:n.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(x=>Rs(x))}})}})}}function Rs(s){var r,t,n,o;return{...s,cfg:{...s.cfg,data:{...(r=s.cfg)==null?void 0:r.data,labels:[],datasets:(o=(n=(t=s.cfg)==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:Gs(s.customCfg),data:[]}}function Gs(s){var r,t;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(t=(r=s==null?void 0:s.data)==null?void 0:r.datasets)==null?void 0:t.map(n=>({...n,data:[]}))}}:null}async function $s(s,r,t,n){if(!n)return null;const o=JSON.stringify(r);return await e.postRequest("https://semaphor.cloud/api/v1/lens",n,{name:s,template:o,filterValues:t,operation:"create"})}async function Ae(s,r){if(!r)return null;const{id:t,template:n,filterValues:o,isDefault:i,shared:x}=s;return await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{lensId:t,template:n,filterValues:o,isDefault:i,shared:x,operation:"update"})}async function Us(s,r){return r?await e.postRequest("https://semaphor.cloud/api/v1/lens",r,{operation:"delete",lensId:s}):null}function Qs(){const[s,r]=S.useState(""),[t,n]=S.useState(!1),o=e.useDashboardStore(b=>b.lenses),{setLenses:i,setSelectedLensId:x}=e.useDashboardActions(),[a,l]=S.useState(!1),[m,c]=S.useState(!1),E=e.useDashboardStore(b=>b.dashboard),h=e.useDashboardStore(b=>b.filterValues),{authToken:u}=e.useSemaphorContext();async function j(){l(!0);const b=_e(E),k=await $s(s,b,h,u==null?void 0:u.accessToken);k&&(i([...o||[],k]),x(k.id),c(!1)),l(!1)}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:m,onOpenChange:c,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:b=>{r(b.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:j,disabled:a,children:a?"Creating...":"Add"})})]})]})}function Js(){const[s,r]=S.useState(!1),t=e.useDashboardStore(c=>c.lenses),n=e.useDashboardStore(c=>c.selectedLensId),{setLenses:o,setSelectedLensId:i}=e.useDashboardActions(),{authToken:x}=e.useSemaphorContext();async function a(c){i(c)}async function l(c){if(await Us(c,x==null?void 0:x.accessToken)){const h=t==null?void 0:t.filter(u=>u.id!==c);o(h||[]),i("original")}}async function m(c){const E=t==null?void 0:t.map(j=>j.id===c.id?{...j,isDefault:!c.isDefault}:{...j,isDefault:!1});o(E||[]);const h={...c,isDefault:!c.isDefault};await Ae(h,x==null?void 0:x.accessToken);const u=t==null?void 0:t.find(j=>j.isDefault);if(u&&u.id!==c.id){const j={...u,isDefault:!1};await Ae(j,x==null?void 0:x.accessToken)}}return e.jsxRuntimeExports.jsxs(e.DropdownMenu,{open:s,onOpenChange:r,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(ts,{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:n,onValueChange:a,children:[e.jsxRuntimeExports.jsx(e.DropdownMenuRadioItem,{value:"original",children:"Original"}),t==null?void 0:t.map(c=>e.jsxRuntimeExports.jsxs(e.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:c.id,children:[e.jsxRuntimeExports.jsx("p",{children:c.name}),e.jsxRuntimeExports.jsxs("span",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(os,{onClick:E=>{E.preventDefault(),m(c)},className:e.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!c.isDefault,"text-green-500":c.isDefault}),strokeWidth:1.5}),e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:E=>{E.preventDefault(),l(c.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},c.id))]})]})]})}function Ks({iconClassName:s}){const[r,t]=S.useState(!1),{authToken:n}=e.useSemaphorContext(),o=e.useDashboardStore(a=>a.theme),i=e.useDashboardStore(a=>a.filterValues);async function x(){{t(!0);const a=new URLSearchParams;a.set("token",(n==null?void 0:n.accessToken)||""),a.set("theme",o||"light"),a.set("filterValues",JSON.stringify(i));const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(a.toString())}`,c=await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${n==null?void 0:n.accessToken}`}})).blob(),E=URL.createObjectURL(c);window.open(E,"_blank"),t(!1)}}return e.jsxRuntimeExports.jsx(e.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:x,children:r?e.jsxRuntimeExports.jsx(ae,{className:e.cn("size-3.5 animate-spin",s)}):e.jsxRuntimeExports.jsx(e.Download,{className:e.cn("size-3.5",s),strokeWidth:1.5})})}function Ws(){S.useState(!1);const{authToken:s}=e.useSemaphorContext();e.useDashboardStore(p=>p.theme);const r=e.useDashboardStore(p=>p.lenses),t=e.useDashboardStore(p=>p.selectedLensId),n=r==null?void 0:r.find(p=>p.id===t),o=e.useDashboardStore(p=>p.dashboard);e.useDashboardStore(p=>p.selectedSheetId);const i=e.useDashboardStore(p=>p.isDashboardEditing),x=e.useEditorStore(p=>p.selectedConnectionId),[a,l]=S.useState(!1),m=e.useDashboardStore(p=>p.filterValues),c=e.useDashboardStore(p=>p.isVisualEditing),E=e.useDashboardStore(p=>p.showFilters);e.useDashboardStore(p=>p.showDashboardJSON);const h=e.useDashboardStore(p=>p.onSaveFunction),u=e.useDashboardStore(p=>p.actions.setShowFilters),{addFrame:j,setSelectedFrameId:b}=e.useDashboardStore(p=>p.actions),{getSelectedSheet:k,setIsDashboardEditing:g,setShowDashboardJSON:T}=e.useDashboardStore(p=>p.actions),I=k(),{tenantId:O,endUserId:y}=S.useMemo(()=>e.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),D=S.useMemo(()=>O||y,[O,y]),A=()=>{if(!i||!I)return;const p={connectionId:x,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},w={id:e.v4(),cards:[p],activeCardId:p.id};j(I.id,w),b(w.id)},d=()=>{g(!0)};async function R(){if(l(!0),!t||!n)return;const p=_e(o),w=JSON.stringify(p),C={...n,template:w,filterValues:m};await Ae(C,s==null?void 0:s.accessToken),e.ce.success("Lens saved"),h==null||h(p),l(!1)}return c?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:[!c&&e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-3",children:e.jsxRuntimeExports.jsx(e.Label,{children:n==null?void 0:n.name})}),e.jsxRuntimeExports.jsxs("div",{className:"flex gap-2",children:[e.jsxRuntimeExports.jsx(Ks,{}),i&&!c&&D&&e.jsxRuntimeExports.jsx(Qs,{}),!c&&D&&e.jsxRuntimeExports.jsx(Js,{}),i&&!c&&e.jsxRuntimeExports.jsxs(e.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:A,children:[e.jsxRuntimeExports.jsx(e.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",className:"h-7 p-2",onClick:d,size:"sm",children:e.jsxRuntimeExports.jsx(e.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!c&&e.jsxRuntimeExports.jsx(e.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{g(!1),T(!1)},size:"sm",children:e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!c&&D&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",disabled:a,onClick:R,size:"sm",children:e.jsxRuntimeExports.jsx(ms,{className:"h-4 w-4",strokeWidth:1.5})}),!E&&!c&&i&&e.jsxRuntimeExports.jsx(e.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>u(!0),size:"sm",children:e.jsxRuntimeExports.jsx(e.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!c&&i&&!1,!c&&!1]})]})}function pe({title:s,items:r,value:t,isLoading:n,isError:o,connectionTooltip:i,onChange:x,showNone:a=!1,className:l,showIcon:m=!0,disabled:c=!1}){const E=n?"Loading...":o?"Error":t;function h(){if(s==="Connection")return e.jsxRuntimeExports.jsx(ds,{className:"size-4 rotate-90"});if(s==="Database")return e.jsxRuntimeExports.jsx(Ze,{className:"size-4"});if(s==="Schema")return e.jsxRuntimeExports.jsx(xs,{className:"size-4"});if(s==="Table")return e.jsxRuntimeExports.jsx(e.Table,{className:"size-4"});if(s==="Model")return e.jsxRuntimeExports.jsx(Je,{className:"size-4"})}return e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[m&&e.jsxRuntimeExports.jsx("div",{className:"shrink-0",children:i?e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger,{children:h()}),e.jsxRuntimeExports.jsx(e.TooltipContent,{className:"text-xs",align:"start",children:i})]}):h()}),e.jsxRuntimeExports.jsxs(e.Select,{disabled:c,value:E,onValueChange:x,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("h-9 w-full focus:ring-1 focus:ring-offset-0",l),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:n?"Loading...":o?"Error":`Select ${s}`})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[n?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"),r&&r.map((u,j)=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:u.id,children:u.name},j))]}),(n||o)&&e.jsxRuntimeExports.jsx(e.SelectItem,{value:E,children:E})]})})]})]})}function Ys({column:s}){const[r,t]=S.useState(!1),n=e.useEditorStore(u=>u.selectedTableName),o=e.useEditorStore(u=>u.selectedSchemaName),i=e.useEditorStore(u=>u.selectedDatamodelId),x=e.useEditorStore(u=>u.sqlGen),{modelItems:a}=le(),l=e.useEditorStore(u=>u.actions.setSqlGen),m=e.useEditorStore(u=>u.actions.setCardSql),c=e.useEditorStore(u=>u.actions.setRunSql);function E(u,j){var T;const b=e.createSqlGenConfig(u,x,j),k=(T=a==null?void 0:a.find(I=>I.id===i))==null?void 0:T.name;l(b);const g=e.getSql(b,e.fmt(o||""),e.fmt(n),k);g&&(m(g),c(!0)),t(!1)}function h(){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:r,onOpenChange:t,children:[e.jsxRuntimeExports.jsx(e.HoverCardTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{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:h()})]})}function bs({column:s}){return e.jsxRuntimeExports.jsxs(e.Tooltip,{children:[e.jsxRuntimeExports.jsx(e.TooltipTrigger$1,{asChild:!0,children:e.TEXT_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(De,{className:"size-3"}):e.NUMBER_DATA_TYPES.includes(s.data_type.toLowerCase())?e.jsxRuntimeExports.jsx(rs,{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(fs,{className:"size-3"}):s.data_type.toLowerCase()==="json"?e.jsxRuntimeExports.jsx(Ke,{className:"size-3"}):e.jsxRuntimeExports.jsx(ps,{className:"size-3"})}),e.jsxRuntimeExports.jsx(e.TooltipContent,{children:e.jsxRuntimeExports.jsx("p",{className:"font-mono text-xs",children:s.data_type})})]})}function Xs({schemaName:s,tableName:r,columns:t,status:n}){const o=e.useEditorStore(d=>d.sqlGen),i=e.useEditorStore(d=>d.selectedConnectionId),x=e.useEditorStore(d=>d.selectedDatabaseName),a=e.useEditorStore(d=>d.selectedSchemaName),l=e.useEditorStore(d=>d.selectedTableName),m=e.useEditorStore(d=>d.selectedDatamodelId),c=e.useDashboardStore(d=>d.dashboard.aiScopeTables),{setAIScopeTables:E}=e.useDashboardStore(d=>d.actions),h=e.useEditorStore(d=>d.actions.setRunSql),u=e.useEditorStore(d=>d.actions.setSqlGen),j=e.useEditorStore(d=>d.actions.setIsShowingVisual),b=e.useEditorStore(d=>d.actions.setCardSql),{connectionType:k,modelItems:g}=le();function T(d){var C;const R=e.createSqlGenConfig(d,o);u(R);const p=(C=g==null?void 0:g.find(F=>F.id===m))==null?void 0:C.name,w=e.getSql(R,e.fmt(s),e.fmt(r),p);w&&(b(w),h(!0))}function I(){return(c==null?void 0:c.find(d=>d.connectinonId===i&&d.tableName===l))!==void 0}function O(d){if(d===!0&&l&&i){const R={connectinonId:i,connectionType:k,databaseName:x,schemaName:a,tableName:l},w=[...c||[],R].filter((C,F,M)=>M.findIndex(B=>B.connectinonId===C.connectinonId&&B.tableName===C.tableName)===F);E(w),e.ce.success(`Added '${l}' to AI Scope`,{position:"top-right",duration:2500,richColors:!0})}else{const R=(c||[]).filter(p=>p.connectinonId!==i&&p.tableName!==l);E(R),e.ce(`Removed '${l}' from AI Scope`,{position:"top-right",duration:2e3,richColors:!0})}}function y(){var C;let d=e.getQualifiedTableName(s,r);const R=(C=g==null?void 0:g.find(F=>F.id===m))==null?void 0:C.name;m&&m!=="none"&&(d=`${e.DATAMODEL_NAMESPCACE}.${R}`);let p=d;return(F=>/[A-Z]/.test(F))(r)&&(p=p.split(".").map(M=>`"${M}"`).join(".")),p}function D(){const d=y();j(!1);const R=k==="MSSQL"?`SELECT top 10 * FROM ${d}`:`SELECT * FROM ${d} LIMIT 10`;b(R),h(!0)}function A(){const d=y();b(`SELECT COUNT(*) as count FROM ${d}`),h(!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:`${I()?"Remove from":"Add to"} AI Scope`,pressed:I(),onPressedChange:O,variant:"outline",className:"h-9 px-2",children:e.jsxRuntimeExports.jsx(e.Bot,{className:e.cn("size-4",{"text-primary":I(),"text-muted-foreground":!I()})})}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:D,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(hs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxRuntimeExports.jsxs(e.Button,{disabled:n!=="Success",onClick:A,size:"sm",variant:"secondary",className:"flex",children:[n!=="Success"?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(js,{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(d=>e.jsxRuntimeExports.jsxs("div",{onClick:()=>T(d),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(d,o)}),children:[e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(bs,{column:d}),e.jsxRuntimeExports.jsx("span",{children:d.column_name})]}),e.jsxRuntimeExports.jsx("div",{onClick:R=>R.stopPropagation(),className:"flex items-center justify-end",children:e.NUMBER_DATA_TYPES.includes(d.data_type)&&e.jsxRuntimeExports.jsx(Ys,{column:d})})]},d.column_name)),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"vertical"}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function le(s,r){var ie,be,fe,ye,Se;let t=S.useMemo(()=>[],[]);const n=e.useSemaphorContext().authToken||s,o=e.useEditorStore(v=>v.selectedConnectionId),i=e.useEditorStore(v=>v.selectedDatamodelId),x=e.useEditorStore(v=>v.selectedDatabaseName),a=e.useEditorStore(v=>v.selectedSchemaName),l=e.useEditorStore(v=>v.selectedTableName),m=e.useEditorStore(v=>v.actions.setCurrentColumns),c=e.useEditorStore(v=>v.actions.setSelectedConnectionId),E=e.useEditorStore(v=>v.actions.setSelectedDatamodelId),h=e.useEditorStore(v=>v.actions.setSelectedDatabaseName),u=e.useEditorStore(v=>v.actions.setSelectedSchemaName),j=e.useEditorStore(v=>v.actions.setSelectedTableName),b=e.useEditorStore(v=>v.actions.setCardSql);function k(v){return o&&x&&a&&x!=="NA"?!0:o&&v==="API"?!1:!!(o&&v==="S3")}function g(v){return!!(o&&x&&x!=="NA"&&a&&l||o&&(v==="S3"||v==="API")||i&&i)}function T(v){return o&&v?!(v==="API"||v==="S3"):!1}const{data:I,isLoading:O,isError:y}=e.useQuery({queryKey:["connections"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/connections",(n==null?void 0:n.accessToken)||""),enabled:!!(n!=null&&n.accessToken)}),{data:D,isLoading:A,isError:d}=e.useQuery({queryKey:["models",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/datamodels",(n==null?void 0:n.accessToken)||"",{connection_id:o}),enabled:!!(n!=null&&n.accessToken)&&!!o}),R=I==null?void 0:I.connections.find(v=>v.id===o),p=R==null?void 0:R.type,w=(R==null?void 0:R.type)==="API"||(R==null?void 0:R.type)==="S3",{data:C,isLoading:F,isFetching:M,isError:B,refetch:P}=e.useQuery({queryKey:["databases",o],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/databases",(n==null?void 0:n.accessToken)||"",{connection_id:o}),enabled:T(p)}),{data:_,isLoading:$,isFetching:N,isError:V,refetch:G}=e.useQuery({queryKey:["schemas",o,x],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/schemas",(n==null?void 0:n.accessToken)||"",{connection_id:o,database_name:x}),enabled:!!o&&!!x&&!w&&x!=="NA"}),{data:z,isLoading:L,isFetching:U,isError:q,refetch:Q}=e.useQuery({queryKey:["tables",o,x,a],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/tables",(n==null?void 0:n.accessToken)||"",{connection_id:o,database_name:x,schema_name:a}),enabled:k(p)}),{data:K,isLoading:X,isFetching:Z,isError:ee}=e.useQuery({queryKey:["columns",o,x,i,a,l],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/columns",(n==null?void 0:n.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:x,schema_name:a,table_name:l}),enabled:g(p)});S.useEffect(()=>{m(t)},[K,m,t]),S.useEffect(()=>{},[w,b,j,u,h,R]);const re=(R==null?void 0:R.type)==="API"?(ie=R==null?void 0:R.type)==null?void 0:ie.toLowerCase():l||"",oe=w?"":a||"";function xe(v){u(v),j("")}function se(v){h(v==="none"?"":v),u(""),j(""),v!=="none"&&v!==""&&E("")}function H(v){c(v)}function ue(v){E(v==="none"?"":v),v!=="none"&&v!==""&&h("")}C&&((be=C==null?void 0:C.databases)==null?void 0:be.length)>0,_&&((fe=_==null?void 0:_.schemas)==null?void 0:fe.length)>0,K&&((ye=K==null?void 0:K.columns)==null?void 0:ye.length)>0&&(t=K.columns.map(v=>({...v,data_type:v.data_type.toLowerCase()}))),B&&(t=[]),(ee||y)&&(t=[]);const de=I==null?void 0:I.connections.map(v=>({id:v.id,name:v.name,type:v.type})),Re=(Se=D==null?void 0:D.datamodels)==null?void 0:Se.map(v=>({id:v.id,name:v.name})),me=C==null?void 0:C.databases.map(v=>({id:v.database_name,name:v.database_name})),he=_==null?void 0:_.schemas.map(v=>({id:v.schema_name,name:v.schema_name})),Ee=z==null?void 0:z.tables.map(v=>({id:v.table_name,name:v.table_name}));return{connectionItems:de,isConnectionsLoading:O,isConnectionsError:y,modelItems:Re,isModelsLoading:A,isModelsError:d,databaseItems:me,isDatabasesLoadingOrFetching:F||M,isDatabaseError:B,schemaItems:he,isSchemaLoadingOrFetching:$||N,isSchemaError:V,tableItems:Ee,isTableLoadingOrFetching:L||U,isTableError:q,columns:t,isColumnsLoadingOrFetching:X||Z,isColumnsError:ee,isNonDbConnection:w,connectionType:p,tableName:re,schemaName:oe,handleConnectionChange:H,handleDatamodelChange:ue,handleDatabaseChange:se,handleSchemaChange:xe}}function ys({ColumnsComponent:s}){var U;const r=e.useEditorStore(q=>q.selectedConnectionId),t=e.useEditorStore(q=>q.selectedDatamodelId),n=e.useEditorStore(q=>q.selectedDatabaseName),o=e.useEditorStore(q=>q.selectedSchemaName),i=e.useEditorStore(q=>q.selectedTableName),x=e.useEditorStore(q=>q.actions.setSelectedTableName),{connectionItems:a,modelItems:l,schemaItems:m,databaseItems:c,tableItems:E,columns:h,isConnectionsLoading:u,isModelsLoading:j,isConnectionsError:b,isModelsError:k,isDatabasesLoadingOrFetching:g,isDatabaseError:T,isSchemaLoadingOrFetching:I,isSchemaError:O,isColumnsError:y,isColumnsLoadingOrFetching:D,isTableLoadingOrFetching:A,isTableError:d,connectionType:R,isNonDbConnection:p,handleConnectionChange:w,handleDatabaseChange:C,handleSchemaChange:F,handleDatamodelChange:M,tableName:B,schemaName:P}=le();function _(){return s?s(P,B,h):e.jsxRuntimeExports.jsx(Xs,{schemaName:P,tableName:B,columns:h,status:D?"Loading...":y?"Error":"Success"})}function $(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function N(){if(!r||R==="S3"||R==="API")return null;if(!t||t==="none")return e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:C,isError:T,isLoading:g,items:c,value:n||"",title:"Database"})}function V(){if(r&&!p&&(!n||n==="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 G(){if(!r||R==="S3"||R==="API")return null;if(!n||n==="none")return e.jsxRuntimeExports.jsx(pe,{showNone:!0,onChange:M,isError:k,isLoading:j,items:l,value:t||"",title:"Model"})}function z(){return!r||R==="S3"||R==="API"||!n||n==="none"?null:e.jsxRuntimeExports.jsx(pe,{onChange:F,isError:O,isLoading:I,items:m,value:o||"",title:"Schema"})}function L(){function q(){let Q=!1;return R==="API"?(Q=!1,Q):((R==="S3"||r&&n&&n!=="none"&&o)&&(Q=!0),Q)}return q()?e.jsxRuntimeExports.jsx(pe,{onChange:x,isError:d,items:E,isLoading:A,value:i||"",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(pe,{items:a,title:"Connection",value:r||"",onChange:w,isLoading:u,isError:b,connectionTooltip:((U=a==null?void 0:a.find(q=>q.id===r))==null?void 0:U.type)||""}),G(),V(),N(),z(),L()]}),_(),e.jsxRuntimeExports.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxRuntimeExports.jsxs(e.Button,{onClick:$,size:"sm",variant:"secondary",className:"w-full",children:[e.jsxRuntimeExports.jsx(cs,{className:"mr-2 size-4"}),"Help"]})})]})}function Zs(s){const r=s.toUpperCase().indexOf("WHERE"),t=s.toUpperCase().indexOf("GROUP BY"),n=s.toUpperCase().indexOf("LIMIT"),o=s.toUpperCase().indexOf("ORDER BY");let i=s.length;if(o!==-1&&(i=o),n!==-1&&n<i&&(i=n),r!==-1){const x=s.substring(0,r),a=s.substring(r);return`${x} {{ filters | where }} AND ${a.substring(6)}`}else if(t!==-1){const x=s.substring(0,t),a=s.substring(t);return`${x} {{ filters | where }} ${a}`}else{const x=s.substring(0,i),a=s.substring(i);return`${x} {{ filters | where }} ${a}`}}function et({error:s,setShowAIDialog:r,setUserInputforAI:t,setTriggerAIRun:n}){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(Ye,{className:"h-4 w-4 text-red-500"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",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:()=>{r(!0),t(s),n(!0)},size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(ns,{className:"mr-2 h-4 w-4"}),"Debug with AI"]})]})})})]})}const st=`
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,7 +224,7 @@ SELECT label, measure FROM table
219
224
 
220
225
  - Label - Category
221
226
  - Measure - Number
222
- `;function st({open:s,setOpen:r,userInput:t,setUserInput:n,triggerAIRun:o,setTriggerAIRun:i}){const x=S.useRef(null),a=S.useRef(null),{authToken:l}=e.useSemaphorContext(),[m,c]=S.useState(!1),E=e.useEditorStore(N=>N.actions.setCardSql),h=e.useDashboardStore(N=>N.dashboard.baseQueries),u=e.useEditorStore(N=>N.actions.setRunSql),j=e.useEditorStore(N=>N.actions.setCardType),[b,k]=S.useState([]),g=e.useEditorStore(N=>N.currentColumns),T=e.useEditorStore(N=>N.card.sql),I=e.useEditorStore(N=>N.selectedTableName),O=`
227
+ `;function tt({open:s,setOpen:r,userInput:t,setUserInput:n,triggerAIRun:o,setTriggerAIRun:i}){const x=S.useRef(null),a=S.useRef(null),{authToken:l}=e.useSemaphorContext(),[m,c]=S.useState(!1),E=e.useEditorStore(N=>N.actions.setCardSql),h=e.useDashboardStore(N=>N.dashboard.baseQueries),u=e.useEditorStore(N=>N.actions.setRunSql),j=e.useEditorStore(N=>N.actions.setCardType),[b,k]=S.useState([]),g=e.useEditorStore(N=>N.currentColumns),T=e.useEditorStore(N=>N.card.sql),I=e.useEditorStore(N=>N.selectedTableName),O=`
223
228
  ${t}
224
229
 
225
230
  Database Query Dialect: ${I==="api"||I==="s3"?"DuckDb":""}
@@ -227,4 +232,4 @@ SELECT label, measure FROM table
227
232
  Table Columns: ${g==null?void 0:g.map(N=>`${N.column_name} | ${N.data_type}`).join(", ")}
228
233
  User SQL: ${T}
229
234
  ${h&&`Base Queries: ${JSON.stringify(h)} `}`,y=` 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: ${et}`,{data:D,isLoading:A,isFetching:d,isError:R,refetch:p}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${O} ${m?y:""}`}),enabled:!1});function w(N){if(N.toLowerCase().includes("bar"))j("bar");else if(N.toLowerCase().includes("line"))j("line");else if(N.toLowerCase().includes("bubble"))j("bubble");else if(N.toLowerCase().includes("scatter"))j("scatter");else if(N.toLowerCase().includes("stacked"))j("stackedBar");else if(N.toLowerCase().includes("pie"))j("pie");else if(N.toLowerCase().includes("donut")||N.toLowerCase().includes("doughnut"))j("doughnut");else if(N.toLowerCase().includes("radar"))j("radar");else return j("bar"),!1;return!0}S.useEffect(()=>{D&&k(N=>[...N,{role:"ai",content:D.response}])},[D]),S.useEffect(()=>{const N=setTimeout(()=>{var V;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(V=x.current)==null||V.focus())},100);return()=>clearTimeout(N)},[b]);function C(){t&&(k(N=>[...N,{role:"user",content:t}]),w(t)&&c(!0),n(""),p())}S.useEffect(()=>{o&&(C(),i(!1))},[o,i]);const F={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},M={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},P={p:({node:N,...V})=>e.jsxRuntimeExports.jsx("p",{style:F,...V}),code:({node:N,...V})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...V}),pre:({node:N,...V})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:M,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:V.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:_,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:G=>{const z=_(G);z&&(r(!1),E(z),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:N,...V})=>e.jsxRuntimeExports.jsx("li",{style:B,...V})};function _(N){const V=N.currentTarget.closest("pre");if(!V)return;const G=V.textContent||V.innerText;return navigator.clipboard.writeText(G).then(()=>console.log("Text copied to clipboard")).catch(z=>console.error("Error in copying text: ",z)),G}function $(){return b==null?void 0:b.map((N,V)=>N.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:N.content})]},V):N.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:P,children:D==null?void 0:D.response.replace(/DuckDB/gi,"Semaphor")},V):e.jsxRuntimeExports.jsx("div",{},V))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,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:$()})}),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:x,onKeyDown:N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),n(""),C())},placeholder:"Type your question here...",onFocus:N=>{const V=N.target,G=V.value.length;V.setSelectionRange(G,G)},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:A||d,value:t,onChange:N=>n(N.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:C,children:!A&&!d?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var ys={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ge=S.createContext&&S.createContext(ys),tt=["attr","size","title"];function nt(s,r){if(s==null)return{};var t=rt(s,r),n,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(o=0;o<i.length;o++)n=i[o],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function rt(s,r){if(s==null)return{};var t={};for(var n in s)if(Object.prototype.hasOwnProperty.call(s,n)){if(r.indexOf(n)>=0)continue;t[n]=s[n]}return t}function Ne(){return Ne=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ne.apply(this,arguments)}function $e(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,n)}return t}function we(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?$e(Object(t),!0).forEach(function(n){ot(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):$e(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function ot(s,r,t){return r=it(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function it(s){var r=at(s,"string");return typeof r=="symbol"?r:r+""}function at(s,r){if(typeof s!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function Ss(s){return s&&s.map((r,t)=>S.createElement(r.tag,we({key:t},r.attr),Ss(r.child)))}function Y(s){return r=>S.createElement(lt,Ne({attr:we({},s.attr)},r),Ss(s.child))}function lt(s){var r=t=>{var{attr:n,size:o,title:i}=s,x=nt(s,tt),a=o||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",Ne({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,x,{className:l,style:we(we({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),i&&S.createElement("title",null,i),s.children)};return Ge!==void 0?S.createElement(Ge.Consumer,null,t=>r(t)):r(ys)}function ct(s){return Y({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 xt({sql:s}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{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(e.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"end",className:"w-full min-w-fit max-w-[700px] p-3 pt-2",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-xs font-semibold",children:"Resolved Query"}),e.jsxRuntimeExports.jsx("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 font-mono text-xs leading-relaxed",children:s})})})]})})]})}function ut(){const[s,r]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),n=e.useQueryClient(),o=S.useRef(),i=e.Le(),[x,a]=S.useState(!1),[l,m]=S.useState(!1),[c,E]=S.useState(!1),[h,u]=S.useState(""),[j,b]=S.useState(!1),k=e.useDashboardStore(f=>f.selectedSheetId);e.useDashboardStore(f=>f.dashboard.baseQueries);const g=e.useEditorStore(f=>f.card),T=e.useDashboardStore(f=>f.theme),I=e.useEditorStore(f=>f.isShowingVisual);e.useDashboardStore(f=>f.onAcceptChanges);const O=e.useEditorStore(f=>f.selectedConnectionId),y=e.useEditorStore(f=>f.selectedDatabaseName),D=e.useEditorStore(f=>f.selectedDatamodelId),A=e.useEditorStore(f=>f.selectedSchemaName);e.useDashboardStore(f=>f.actions.updateFrameCard);const d=e.useEditorStore(f=>f.selectedTableName),R=e.useEditorStore(f=>f.card.sql),p=e.useEditorStore(f=>f.sqlGen),w=e.useEditorStore(f=>f.card.python),C=e.useEditorStore(f=>f.frame),F=e.useDashboardStore(f=>f.dashboard.filters),M=e.useDashboardStore(f=>f.filterValues),B=F==null?void 0:F.filter(f=>f.sheetId===k||!f.sheetId),P=M==null?void 0:M.filter(f=>(B==null?void 0:B.some(J=>J.id===f.filterId))||f.filterId.endsWith(k)),_=e.useEditorStore(f=>f.applyFilters),{setCardCustomCfg:$,setQueryResultColumns:N,setFilterValues:V,setCardSql:G,setCard:z,setCardPython:L,setQueryError:U,setPythonStdOut:q,setCardPreferences:Q,setCardType:K}=e.useEditorStore(f=>f.actions),X=e.useEditorStore(f=>f.onSave);e.useEditorStore(f=>f.actions.setApplyFilters);const Z=e.useEditorStore(f=>f.onClose),ee=e.useEditorStore(f=>f.actions.setSqlGen),re=e.useEditorStore(f=>f.runSql),oe=e.useEditorStore(f=>f.actions.setRunSql),xe=e.useEditorStore(f=>f.actions.setCardCfg),se=e.useEditorStore(f=>f.actions.setIsSqlRunning),{data:H,isLoading:ue,isFetching:de,isSuccess:Re,isError:me,error:he,queryKey:Ee,refetch:ie}=e.useDashboardCardQuery(g);S.useEffect(()=>{if(H&&(H.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),q((H==null?void 0:H.output)||""),H.records.length>0)){const{dimensionKeys:f}=e.getKeys(H.records);N(f)}},[H,N,q]),S.useEffect(()=>{(ue||de)&&se(!0),(me||Re)&&se(!1),me?(U(he.message),N([]),q("")):U("")},[ue,de,H,q,me,Re,se,N,U,he]),S.useEffect(()=>{re&&(ie(),oe(!1))},[re,ie,oe]);function be(){const f=n.getQueryData(Ee);s.queryData||r({queryKey:Ee,queryData:f}),n.setQueryData(Ee,null),G(""),ee({}),xe(void 0),$(""),Q({}),K("bar")}const fe=f=>{o.current=f};function ye(f,J){if(f.length===0)return"";if(J){const te=f.find(ne=>ne.id===J);if(te){const ne=te.tabTitle;if(ne=="All__Header")return f[0].id;if(ne&&ne.endsWith("__Header")){const _s=ne.split("__")[0],Pe=f.find(Bs=>Bs.tabTitle===_s);return Pe?Pe.id:f[0].id}return J}}return f[0].id}function Se(){let f=R;R&&!R.includes("{{")&&(f=Xs(R),G(f));const J={...g,lastSelectedSchema:A,lastSelectedDatamodelId:D,lastSelectedDatabase:y,lastSelectedTable:d,connectionId:O,type:I?g.type:"table",sql:f,customCfg:I?g.customCfg:null},te=C.cards.map(Te=>Te.id===g.id?J:Te),ne={...C,cards:te,activeCardId:ye(te,C.activeCardId)};X==null||X(ne)}function v(){const{queryKey:f,queryData:J}=s;f&&J&&n.setQueryData(f,J),Z==null||Z()}S.useEffect(()=>{if(!i)return;const f=o.current,J=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",te=T==="system"?J:T;return i.editor.defineTheme("default",{base:te==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":te==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default"),f&&i&&f.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return ie(),!1}),()=>{}},[t,T,i]);function Vs(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[l&&e.jsxRuntimeExports.jsx("div",{className:"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(e.Label,{className:"ml-6 text-xs font-semibold",children:"Filters"}),P&&l&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>m(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:f=>{if(f)try{JSON.parse(f),V(JSON.parse(f))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(P,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}},T)]})}),P&&!l&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>m(!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":_})})]})}function qs(){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:x?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:f=>{G(f),e.isObjectEmpty(p)||ee({})},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:fe})}),x&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),x&&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:f=>{L(f&&f.trim()||"")},value:w||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",onMount:fe})}),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:[qs(),Vs()]}),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:ue||de,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[ue||de?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(xs,{className:"mr-2 h-4 w-4"}),"Run"]}),me&&e.jsxRuntimeExports.jsx(Zs,{error:he.message,setShowAIDialog:E,setTriggerAIRun:b,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(Ze,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:x,onPressedChange:f=>a(f),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ct,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(st,{open:c,setOpen:E,userInput:h,triggerAIRun:j,setTriggerAIRun:b,setUserInput:f=>u(f)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(H==null?void 0:H.sql)&&e.jsxRuntimeExports.jsx(xt,{sql:H.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:v,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Se,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function dt({data:s}){var x;const[r,t]=S.useState([]),o=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:l})=>{const m=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.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]})})}})),i=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxRuntimeExports.jsxs("table",{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:i.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(x=i.getRowModel().rows)!=null&&x.length?i.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.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 mt({card:s}){var g,T,I,O,y,D,A,d,R,p,w;const[r,t]=S.useState(!1),[n,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),x=e.getTokenParams(i==null?void 0:i.accessToken),a=e.useDashboardStore(C=>C.themeStyle),l={colors:((T=(g=a==null?void 0:a.chart)==null?void 0:g.dataset)==null?void 0:T.backgroundColor)||[]};(I=s.customCardPreferences)!=null&&I.inputData;const{getCard:m}=e.useCustomVisual(((O=s.customCardPreferences)==null?void 0:O.url)||""),c=((y=s.customCardPreferences)==null?void 0:y.visualType)||"single",E=e.useEditorStore(C=>C.frame);e.useEditorActions();const{data:h}=e.useDashboardCardQuery(s),u=S.useCallback((C,F)=>{o(M=>({...M,[C]:F}))},[]);if(!((D=s.customCardPreferences)!=null&&D.componentName))return null;const j=m((A=s.customCardPreferences)==null?void 0:A.componentName);function b(C){t(C)}const k=Object.keys(((d=s.customCardPreferences)==null?void 0:d.dataInputCardIds)||{}).map(C=>{var B,P,_;const F=(P=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:P[C].cardId,M=(_=E==null?void 0:E.cards)==null?void 0:_.find($=>$.id===F);return M||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[j&&c==="single"&&e.jsxRuntimeExports.jsx(j,{params:x,theme:l,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:u,data:(h==null?void 0:h.records)||[]}),j&&c==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((p=s.customCardPreferences)==null?void 0:p.dataInputCardIds)||{}).map(C=>{var B,P,_;const F=(P=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:P[C].cardId,M=(_=E==null?void 0:E.cards)==null?void 0:_.find($=>$.id===F);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:b,onDataChange:u,dataInputIndex:C,card:M},M.id+C)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(j,{theme:l,onDataChange:u,settings:k.map(C=>{var F;return(F=C==null?void 0:C.customCardPreferences)==null?void 0:F.settings}),data:k.map(C=>C!=null&&C.id?n==null?void 0:n[C.id]:[])})})]})]},(w=s.customCardPreferences)==null?void 0:w.componentName)})}function vs({className:s,...r}){var k;const t=e.useEditorStore(g=>g.card),n=((k=t.customCardPreferences)==null?void 0:k.showCardHeader)??!0,o=e.useEditorStore(g=>g.frame),i=e.useDashboardStore(g=>g.dashboard.filters);e.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:x}=e.useDashboardActions(),a=i==null?void 0:i.find(g=>g.id===o.filterId),{data:l,isLoading:m,isFetching:c}=e.useDashboardCardQuery(t),{setCard:E}=e.useEditorActions(),{data:h}=e.useTopoJson(t);if(!t.id)return null;let u;l!=null&&l.records&&(l==null?void 0:l.records.length)>0&&(u=e.createChartConfig({data:l==null?void 0:l.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:h}));function j(g){return e.jsxRuntimeExports.jsx(mt,{card:g})}function b(){var g;if(l!=null&&l.records&&(l==null?void 0:l.records.length)===0&&!m&&!c)return e.jsxRuntimeExports.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsx(e.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(t.type==="custom")return j(t);if(!["table","custom"].includes(t.type)&&u)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:u},JSON.stringify(u)+JSON.stringify(t.preferences)+((g=t==null?void 0:t.preferences)==null?void 0:g.customVisualCode));if(t.type==="table"&&(l!=null&&l.records)&&(l==null?void 0:l.records.length)>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:l==null?void 0:l.records}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[n&&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:t.title,onSave:g=>E({...t,title:g}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:g=>E({...t,description:g}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),a&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:a.title||a.column,onSave:g=>x({...a,title:g}),children:e.jsxRuntimeExports.jsx(e.Label,{children:a.title})}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:a})]})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"flex grow flex-col",children:b()})]})}function pt(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[o,i]=S.useState(""),[x,a]=S.useState(""),[l,m]=S.useState(""),c=e.useEditorStore(y=>y.card),E=e.useEditorStore(y=>y.card.customCfg),{data:h}=e.useDashboardCardQuery(c),{data:u}=e.useTopoJson(c),{setCardCustomCfg:j,setCustomVisualCode:b}=e.useEditorActions();function k(y){var d,R;const D={...y,data:{...y==null?void 0:y.data,datasets:(R=(d=y==null?void 0:y.data)==null?void 0:d.datasets)==null?void 0:R.map(p=>({...p,data:[]}))}};return JSON.stringify(D,null,1)}function g(){var D,A;if(!(h!=null&&h.records)||(h==null?void 0:h.records.length)===0)return;const y=e.createChartConfig({data:h==null?void 0:h.records,cardType:c.type,cfg:c.cfg,preferences:c.preferences,topoJson:u});y&&(n(JSON.stringify(y,null,1)),(D=c==null?void 0:c.preferences)!=null&&D.customVisualCode&&a((A=c==null?void 0:c.preferences)==null?void 0:A.customVisualCode),E&&i(JSON.stringify(E,null,1)))}function T(){if(x&&b(x),!!o)try{const y=JSON.parse(o);return y?(j(y),m(""),i(""),y):void 0}catch(y){console.log(y),m("Invalid JSON")}}function I(){i(""),j(null)}function O(){let y;if(E){const D=e._.cloneDeep(c.cfg),A=e._.merge(D,E);return y=k(A),y}return t?(y=k(JSON.parse(t)),y):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:g,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.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"})}),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(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{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=>i(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:x,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:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!E,onClick:I,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:T,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!1),variant:"outline",children:"Close"})]})]})]})}function Cs(s){return Y({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 Ns(s){return Y({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function ws(s){return Y({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 ks(s){return Y({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Is(s){return Y({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 Ds(s){return Y({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 Ls(s){return Y({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 Y({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 As(s){const[r,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-B38IO6DT.js")))[s];t(i)})()},[s]),r}function zs(){const{authToken:s}=e.useSemaphorContext(),{data:r,isLoading:t,isFetching:n,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:r,isLoading:t,isFetching:n,isError:o}}function jt({onChartTypeChange:s}){const[r,t]=S.useState([]),{data:n}=zs();return S.useEffect(()=>{(async()=>{var i;if(n){const a=(await Promise.all((i=n==null?void 0:n.plugins)==null?void 0:i.map(async l=>(await e.loadManifest(l.value)).visuals.map(E=>({name:E.name,icon:E.icon,url:l.value}))))).flat();t(a)}})()},[n]),r.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:r.map((o,i)=>e.jsxRuntimeExports.jsx(ht,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const ht=({text:s,icon:r,onClick:t})=>{const n=As(r||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:n?e.jsxRuntimeExports.jsx(n,{className:"h-4 w-4"}):o})};function Et(){var c,E;const[s,r]=S.useState(!1),t=e.useEditorStore(h=>h.card),n=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(h=>h.actions),{setCardCustomCfg:a,setCustomCardPreferences:l}=e.useEditorActions();function m(h,u){a(null),i({}),o(h),u&&l({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(ft,{className:"h-4 w-4",chartType:n,customIcon:(c=t.customCardPreferences)==null?void 0:c.icon,componentName:(E=t.customCardPreferences)==null?void 0:E.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Fe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ns,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Cs,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ws,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(jt,{onChartTypeChange:m})]})]})}function ft({chartType:s,className:r,customIcon:t,componentName:n}){const o=As(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(ke,{className:r});case"line":return e.jsxRuntimeExports.jsx(Ie,{className:r});case"pie":return e.jsxRuntimeExports.jsx(Oe,{className:r});case"radar":return e.jsxRuntimeExports.jsx(Cs,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(Fe,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(ks,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(Ns,{className:r});case"stackedBar":return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Is,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(ws,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(Ts,{className:r});case"range":return e.jsxRuntimeExports.jsx(ze,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(Ls,{className:r});case"text":return e.jsxRuntimeExports.jsx(De,{className:r});case"map":return e.jsxRuntimeExports.jsx(Ve,{className:r});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:r}):n?n==null?void 0:n.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(qe,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function gt(){var r;const s=e.useEditorStore(t=>t.card);return(r=s.customCardPreferences)==null||r.showCardHeader,e.useEditorActions(),e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(e.IdCard,{className:"size-5"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})})]})}function Ue(){const s=e.useEditorStore(d=>d.frame),r=e.useEditorStore(d=>d.card),t=e.useEditorStore(d=>d.isShowingVisual),n=e.useEditorStore(d=>d.isSqlRunning),o=e.useEditorStore(d=>d.queryError),i=e.useEditorStore(d=>d.pythonStdOut),x=e.useEditorStore(d=>d.actions.setRunSql);e.useEditorStore(d=>d.onSave),e.useEditorStore(d=>d.onClose),e.useEditorStore(d=>d.actions.setCardSql),e.useEditorStore(d=>d.actions.setCardType),e.useEditorStore(d=>d.actions.setSqlGen);const{setFrame:a,setCard:l,updateCardInFrame:m}=e.useEditorActions(),{data:c,isLoading:E,isFetching:h}=e.useDashboardCardQuery(r);if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function u(){const d={connectionId:r.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};j(d)}function j(d){const R={...s,cards:[...s.cards,d],activeCardId:d.id};a(R),l(d)}function b(){const d={...r,id:e.v4(),title:`${r.title} Copy`,tabTitle:`${r.tabTitle||r.title} Copy`};j(d)}function k(d){const R=s.cards.filter(C=>C.id!==d),p=R[0],w={...s,cards:R,activeCardId:p.id};a(w),l(p)}function g(d){const R={...s,cards:s.cards.map(w=>w.id===r.id?r:w),activeCardId:d};a(R);const p=R.cards.find(w=>w.id===d);p.sql&&x(!0),l(p)}const T=(d,R)=>{console.log("handleDragStart",R),d.dataTransfer.setData("tabIndex",R.toString())},I=d=>{d.preventDefault()},O=(d,R)=>{const p=d.dataTransfer.getData("tabIndex");if(p===R.toString())return;const w=Array.from(s.cards),[C]=w.splice(parseInt(p),1);w.splice(R,0,C),a({...s,cards:w})};function y(d,R){return d.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||d.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const p=R.displayTab===void 0?!1:!R.displayTab;l({...R,displayTab:p}),m({...R,displayTab:p})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(e.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function D(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:g,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(d=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:d.id,children:A()},d.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((d,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:d.tabTitle||d.title,onSave:p=>{l({...r,tabTitle:p}),m({...r,tabTitle:p})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:p=>T(p,R),onDragOver:I,onDrop:p=>O(p,R),className:"",value:d.id,children:[y(s,d),d.tabTitle||d.title,s.activeCardId===d.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>k(d.id)})]})},d.id)),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(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:b,children:e.jsxRuntimeExports.jsx(Ye,{className:"h-4 w-4"})})]})})]})}function A(){return r.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,{card:r,data:c==null?void 0:c.records})})}):r.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.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:n,card:r,data:c==null?void 0:c.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(vs,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(E||h)&&e.jsxRuntimeExports.jsx(ae,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 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:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(Et,{}),!["table","custom"].includes(r.type)&&e.jsxRuntimeExports.jsx(pt,{}),e.jsxRuntimeExports.jsx(gt,{})]}),e.jsxRuntimeExports.jsx(bt,{})]}),t?D():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsxRuntimeExports.jsx(Rt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{})]}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsxRuntimeExports.jsx(dt,{data:(c==null?void 0:c.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:o}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Rt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsxRuntimeExports.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:r}}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function bt(){const s=e.useEditorStore(t=>t.isShowingVisual),r=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:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function yt({options:s,value:r,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:r,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:n.value,id:n.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:n.value,children:n.label})]},n.value))})}function W({label:s,options:r,value:t,onValueChange:n,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:n,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),r.map(i=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function ge({children:s,summary:r,open:t,className:n}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",n),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function St(){var b,k;const s=e.useEditorStore(g=>g.card.customCardPreferences),{data:r}=zs(),t=(r==null?void 0:r.plugins)||[],n=e.useEditorStore(g=>g.card),o=e.useEditorStore(g=>g.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:x}=e.useEditorActions(),{components:a,manifest:l}=e.useCustomVisual((s==null?void 0:s.url)||""),m=(b=l==null?void 0:l.visuals)==null?void 0:b.find(g=>g.name===(s==null?void 0:s.componentName));function c(g,T){if(!s)return;const O={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:T,hookRef:null}};x({...s,dataInputCardIds:O})}function E(g){var I,O;const T=(I=o==null?void 0:o.cards)==null?void 0:I.filter(y=>{var D;return((D=y==null?void 0:y.customCardPreferences)==null?void 0:D.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(O=g==null?void 0:g.dataInputs)==null?void 0:O.map((y,D)=>{var A,d;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(W,{className:"col-span-6 h-8 w-full justify-between",label:"",options:T||[],value:((d=(A=s==null?void 0:s.dataInputCardIds)==null?void 0:A[D])==null?void 0:d.cardId)||"",onValueChange:R=>c(D,R)})]},D+Math.random())})})}function h(g,T,I=[]){var O,y;return s?g==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((O=s==null?void 0:s.settings)==null?void 0:O[T])||"",onChange:D=>{x({...s,settings:{...s==null?void 0:s.settings,[T]:D.target.value}})}},T):g==="select"?e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:I,value:((y=s==null?void 0:s.settings)==null?void 0:y[T])||"",onValueChange:D=>{x({...s,settings:{...s==null?void 0:s.settings,[T]:D}})}}):null:null}function u(g){const T=Object.entries((g==null?void 0:g.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:T.map(([I,O])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:O.title}),h(O.ui,I,O.options)]},I))})}function j(g){s&&x({...s,visualType:g,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(ge,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:g=>x({...s||{url:"",componentName:""},url:g})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(yt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:j}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:a&&e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:(a==null?void 0:a.filter(g=>g.type===i).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),x({...s,componentName:g})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((k=n==null?void 0:n.customCardPreferences)==null?void 0:k.componentName)&&e.jsxRuntimeExports.jsxs(ge,{summary:"Component Settings",children:[m&&m.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:E(m)})]}),m&&m.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:u(m)})})]})]})}function ce(){const[s,r]=S.useState([]);e.useEditorStore(c=>c.card.cfg);const t=e.useEditorStore(c=>c.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(c=>c.actions),x=e.useEditorStore(c=>c.queryResultColumns);e.useEditorStore(c=>{var E;return(E=c.card.preferences)==null?void 0:E.filterOnClickColumnIndex}),S.useEffect(()=>{x&&r(new Array(x.length).fill(!1))},[x]);function a(c,E){var h,u;E?t!=null&&t.onClickFilter&&((h=t==null?void 0:t.onClickFilter)==null?void 0:h.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:c,expression:""}]}):i({...t,onClickFilter:[{columnIndex:c,expression:""}]}):(i({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(j=>j.columnIndex!==c)}),r(j=>{const b=[...j];return b[c]=!1,b}))}function l(c,E){var u;const h=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(j=>j.columnIndex===c?{...j,expression:E.target.value}:j);i({...t,onClickFilter:h})}function m(c){var E,h,u,j;if(s!=null&&s[c]||(h=(E=t==null?void 0:t.onClickFilter)==null?void 0:E.find(b=>b.columnIndex===c))!=null&&h.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(j=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(b=>b.columnIndex===c))==null?void 0:j.expression,onChange:b=>l(c,b),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"}),x==null?void 0:x.map((c,E)=>{var h,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:!!((h=t==null?void 0:t.onClickFilter)!=null&&h.find(j=>j.columnIndex===E)),onCheckedChange:j=>a(E,j)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:c}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(j=>j.columnIndex===E))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{r(j=>{const b=[...j];return b[E]=!j[E],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(E)]})},c)})]})}function Le(){var x,a,l;const s=e.useEditorStore(m=>m.card.preferences),r=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(x=r==null?void 0:r.options)!=null&&x.indexAxis;function i(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:i,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 ve="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Qe(s,r){var n,o,i;const t=e.getNumberAxis(s,r);return((i=(o=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:o[t])==null?void 0:i.type)||"linear"}function Os(){var P,_,$,N,V,G;const[s,r]=S.useState(!1),t=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.preferences}),n=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.cfg}),o=e.getNumberAxis(t,n),[i,x]=S.useState(Qe(t)),[a,l]=S.useState((($=(_=(P=t==null?void 0:t.chartOptions)==null?void 0:P.scales)==null?void 0:_[o])==null?void 0:$.min)||""),[m,c]=S.useState(((G=(V=(N=t==null?void 0:t.chartOptions)==null?void 0:N.scales)==null?void 0:V[o])==null?void 0:G.max)||""),[E,h]=S.useState(a||m?"custom":"auto"),[u,j]=S.useState(""),[b,k]=S.useState(0),[g,T]=S.useState(""),[I,O]=S.useState(""),[y,D]=S.useState(""),A=e.useEditorStore(z=>z.actions.setCardPreferences),{updateCardInFrame:d}=e.useEditorActions(),R=e.useEditorStore(z=>z.card),p=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.type}),w=["pie","doughnut","polarArea"].includes(p);S.useEffect(()=>{var z,L,U,q,Q,K,X,Z,ee,re,oe,xe,se,H;x(Qe(t)),l(((U=(L=(z=t==null?void 0:t.chartOptions)==null?void 0:z.scales)==null?void 0:L[o])==null?void 0:U.min)===0?0:""),c(((K=(Q=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:Q[o])==null?void 0:K.max)||""),j(((re=(ee=(Z=(X=t==null?void 0:t.chartOptions)==null?void 0:X.scales)==null?void 0:Z[o])==null?void 0:ee.ticks)==null?void 0:re.stepSize)||""),k(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.decimalPlaces)||0),T(((xe=t==null?void 0:t.numberAxisFormat)==null?void 0:xe.suffix)||""),O(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.currency)||""),D(((H=t==null?void 0:t.numberAxisFormat)==null?void 0:H.locale)||"")},[s,t,o]);function C(z,L){return L===""||/^[0-9\b]+$/.test(L)?Number(L):Number(z)}function F(){const z=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(L=>L.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:I||"none",onValueChange:L=>O(L==="none"?"":L),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"}),z.map(L=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:L,children:L},L))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:L=>D(L),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(L=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:L.locale,children:L.locale},L.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:b,onChange:L=>k(Number(L.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ve}`})]})]})}function M(){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:z=>l(L=>C(L,z.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:z=>c(L=>C(L,z.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ve}`})]}),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:z=>j(L=>C(L,z.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function B(){var q;let z={};E==="custom"&&(z={min:a,max:m,ticks:{stepSize:u}});const L={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales,[o]:{type:i,...i==="linear"?z:{}}}},numberAxisFormat:{decimalPlaces:b,suffix:g,currency:I,locale:y}};console.log(L),A(L);const U={...R,preferences:L};d(U)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:z=>r(z),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:w,value:i,onValueChange:z=>x(z),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"})]})})]})]}),i=="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:w,id:"scale-option",value:E,onValueChange:z=>h(z),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"&&i=="linear"&&M(),F(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function vt({idx:s}){var a;const r=e.useEditorStore(l=>{var m;return(m=l.card)==null?void 0:m.preferences}),t=e.useEditorStore(l=>{var m;return(m=l.card.preferences)==null?void 0:m.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),o=(a=r==null?void 0:r.chartOptions)==null?void 0:a.indexAxis,i=t==null?void 0:t.find(l=>l.idx===s);function x(l,m){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const c={display:l!=="none",align:l,anchor:l,clamp:!0};if(!i)n({...r,datasetOptions:[...t||[],{idx:m,datalabels:c}]});else{const E={...i};E.datalabels=c;const h=t==null?void 0:t.map(u=>u.idx===m?E:u);n({...r,datasetOptions:h})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(hs,{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:()=>x("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:()=>x("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(os,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(as,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(is,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Fs(){const s=e.useEditorStore(m=>m.card),r=e.useEditorStore(m=>{var c,E,h;return(h=(E=(c=m==null?void 0:m.card)==null?void 0:c.preferences)==null?void 0:E.chartOptions)==null?void 0:h.indexAxis}),{data:t}=e.useDashboardCardQuery(s),n=r==="y"?"Y axis":"X axis",o=r==="y"?"X axis":"Y axis",{keys:i,metricKeys:x,dimensionKeys:a}=e.getKeys((t==null?void 0:t.records)||[]);let l=x;if(["stackedBar","stackedLine"].includes(s.type)){const m=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:l[0]}),{metricKeys:c}=e.getKeys(m);l=c}return i.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:n}),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:a[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:o}),e.jsxRuntimeExports.jsx(Os,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:l.map((m,c)=>e.jsxRuntimeExports.jsx(Ct,{col:m,idx:c},m))})]})]})}function Ct({col:s,idx:r}){const t=e.useEditorStore(a=>{var l;return(l=a.card)==null?void 0:l.preferences}),n=e.useEditorStore(a=>{var l;return(l=a.card.preferences)==null?void 0:l.datasetOptions}),o=n==null?void 0:n.find(a=>a.idx===r),{setCardPreferences:i}=e.useEditorStore(a=>a.actions);function x(a){if(!o)i({...t,datasetOptions:[...n||[],{idx:r,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const l={...o};l.type=a==="area"?"line":a,l.fill=a==="area"?"origin":"";const m=n==null?void 0:n.map(c=>c.idx===r?l:c);i({...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(ke,{onClick:()=>x("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ie,{onClick:()=>x("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ke,{onClick:()=>x("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(vt,{idx:r})]})]})}function Ms(){const s=e.useEditorStore(h=>h.selectedConnectionId),r=e.useEditorStore(h=>h.selectedDatamodelId),t=e.useEditorStore(h=>h.selectedDatabaseName),n=e.useEditorStore(h=>h.selectedSchemaName),o=e.useEditorStore(h=>h.selectedTableName),i=e.useDashboardStore(h=>h.dashboard.filters)||[],x=e.useDashboardStore(h=>h.actions.addFilter),a=e.useDashboardStore(h=>h.actions.removeFilter),{removeFilterValues:l}=e.useDashboardActions(),{modelItems:m,tableName:c}=le();function E(h,u="dashboard"){var D;const j=e.fmt(h.column_name),b=e.fmt(t||""),k=e.fmt(n||""),g=e.fmt(c);let T=e.getQualifiedTableName(k,g),I=`${T}.${j}`;const O=(D=m==null?void 0:m.find(A=>A.id===r))==null?void 0:D.name;r&&r!=="none"&&(I=`${e.DATAMODEL_NAMESPCACE}.${O}.${j}`,T=`${e.DATAMODEL_NAMESPCACE}.${O}`);const y=i==null?void 0:i.find(A=>A.column===I&&A.table===g&&(A.database===b||A.database===t));if(y)l(y.id),a(y.id);else{const A=e.v4();return c==="api"&&s?(x({location:u,id:A,column:I,title:h.column_name,dataType:h.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(h.data_type,T,j)}),A):(x({id:A,location:u,column:I,title:h.column_name,dataType:h.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(h.data_type,T,j)}),A)}}return{assignFilter:E}}function je(){const s=e.useDashboardStore(a=>a.dashboard.filters),r=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=le(),{assignFilter:o}=Ms();function i(a){const l=o(a,"frame");t({...r,filterId:l})}const x=s==null?void 0:s.find(a=>a.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(Nt,{onSelect:i,columns:n}),x&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:x})]})}function Nt({columns:s,onSelect:r}){var x;const[t,n]=He.useState(!1),[o,i]=He.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,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?(x=s.find(a=>a.column_name===o))==null?void 0:x.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:l=>{const m=l===o?"":l;i(m),n(!1),m&&r(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 wt({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:r=>r.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(Le,{}),e.jsxRuntimeExports.jsx(Fs,{})]})]}),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(je,{})]})]})]})})}function Be(){var o,i,x;const s=e.useEditorStore(a=>a.card.cfg),r=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function n(a){var c;const l={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(c=s==null?void 0:s.options)==null?void 0:c.plugins,...l}}};r(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(Os,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(x=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:x.anchor,onValueChange:n,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 kt({cardType:s}){function r(t){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"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis 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:"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:i=>i.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:r(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(Be,{})})]}),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(je,{})]})]})]})})}const It={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Dt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Lt(){const s=e.useEditorStore(r=>r.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:Tt(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Le,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Be,{}),e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(je,{})]})]})}function Tt(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(It,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(Dt,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 At(){var l,m,c,E,h;const s=e.useEditorStore(u=>u.card.preferences),r=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.decimalPlaces});const n=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.locale}),o=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const i=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.colorRanges})||[],x=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:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:u=>{r({...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:n||"none",onValueChange:u=>{var j,b,k;return t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",u,((k=s==null?void 0:s.formatNumber)==null?void 0:k.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.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),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 j,b,k;console.log("currency",u),t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,u==="none"?"":u,((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.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=(c=s==null?void 0:s.formatNumber)==null?void 0:c.decimalPlaces)==null?void 0:E.toString())||"0",onValueChange:u=>{var j,b,k;return t(Number(u),((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.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:((h=s==null?void 0:s.formatNumber)==null?void 0:h.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 j,b,k;return t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:x})]})]})}function zt(){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(At,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Ot=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],Ft=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Mt=Ft.map(s=>({label:s,value:s}));function Vt(){var l,m,c,E,h,u,j,b,k,g,T,I,O,y,D,A,d,R;const s=e.useEditorStore(p=>p.card),r=(m=(l=s==null?void 0:s.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:m.topoJsonUrl,[t,n]=S.useState(((E=(c=s==null?void 0:s.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:E.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),x=Object.keys((i==null?void 0:i.objects)||{}).map(p=>({label:p,value:p}))||[],a=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(ge,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ge,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(W,{className:"h-9",options:a,onValueChange:p=>{console.log("value",p),o({...s.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:r||"",label:"Select Map"}),r==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:p=>{n(p.target.value)},onBlur:()=>{var p;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(p=s.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:x,value:((u=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,objectKey:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:Ot,value:((b=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:b.projection)||"",label:"Projection",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projection:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:Mt,value:((g=(k=s.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ge,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((I=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:I.projectionScale)||1,onChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((D=(y=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:D[0])||0,onChange:p=>{var w,C,F,M;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(p.target.value),((M=(F=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:M[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(d=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:d.projectionOffset)==null?void 0:R[1])||0,onChange:p=>{var w,C,F,M;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((M=(F=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:M[0])||0,Number(p.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ce,{})]})}function qt(){var n;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=e.useEditorStore(o=>o.actions);function t(o){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.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 Ce({cardType:s,docContent:r,suffix:t="Chart"}){let n="pie-chart";return s==="radar"&&(n="radar-chart"),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:r||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:o=>o.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/concepts/visuals#${n}`,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(Le,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Be,{}),s==="text"&&e.jsxRuntimeExports.jsx(qt,{})]})]}),!["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(je,{})]})]})]})})}function _t(){const s=e.useEditorStore(n=>{var o,i;return(i=(o=n==null?void 0:n.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:r}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(W,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:n=>{r(n)}})]})}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:n=>n.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(Le,{}),t(),e.jsxRuntimeExports.jsx(Fs,{})]})]}),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(je,{})]})]})]})})}function Bt({}){const s=e.useEditorStore(n=>{var o;return(o=n.card)==null?void 0:o.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};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(je,{})]})]})}),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 Pt=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."]})]}),Ht=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."]})]}),Gt=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 $t(){const s=e.useEditorStore(t=>t.card.type);function r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(_t,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ce,{docContent:Pt,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(zt,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(wt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ce,{docContent:Ht,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ce,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(kt,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Bt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ce,{docContent:Gt,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(Vt,{});case"custom":return e.jsxRuntimeExports.jsx(St,{});default:return e.jsxRuntimeExports.jsx(Lt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function Ut(){const s=e.useEditorStore(r=>r.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(ut,{})}),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($t,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ue,{})})]}):e.jsxRuntimeExports.jsx(Ue,{})})]})}function Qt({authToken:s,onSave:r,onClose:t}){e.useDashboardStore(x=>x.themeStyle);const n=e.useEditorStore(x=>x.actions.setOnSave),o=e.useEditorStore(x=>x.actions.setOnClose),i=e.useDashboardStore(x=>x.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&o(t)},[r,n,t,o]),S.useEffect(()=>{s&&s.accessToken&&i(s)},[s,i]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(bs,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Ut,{})})]})})}function Jt(){e.useDashboardStore(x=>x.selectedCardId);const s=e.useDashboardStore(x=>x.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(x=>x.actions),t=e.useDashboardStore(x=>x.isVisualEditing),n=e.useDashboardStore(x=>x.actions.updateFrame);function o(x){s&&(n(s,x),r(!1))}function i(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx(Qt,{onSave:o,onClose:i})})}function Kt(){const s=e.useEditorStore(i=>i.selectedDatabaseName),r=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:n}=le(),{assignFilter:o}=Ms();return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:n==null?void 0:n.map(i=>{const x=t==null?void 0:t.find(a=>a.column===e.fmt(i.column_name)&&a.table===r&&a.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>o(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":x}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(Rs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Wt(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex min-w-72 grow flex-col border-l px-1",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"px-2 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(bs,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Kt,{})})})]})}function Yt(){const s=e.useDashboardStore(n=>n.dashboard.filters),r=e.useDashboardStore(n=>n.theme),t=s==null?void 0:s.filter(n=>n.hide);return t!=null&&t.length?e.jsxRuntimeExports.jsx("div",{className:e.cn("mb-1 flex items-center gap-2 border-y pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":r==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":r==="dark"}),children:t==null?void 0:t.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex w-[250px] flex-col gap-1 p-2",children:[e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:n}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:n})]},n.id))}):null}function Xt(){const s=e.useDashboardStore(n=>n.showFilters),r=e.useDashboardStore(n=>n.isVisualEditing),t=e.useDashboardStore(n=>n.isDashboardEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":r,"flex grow":!r}),children:[e.jsxRuntimeExports.jsxs("section",{className:"flex grow flex-col",children:[t&&e.jsxRuntimeExports.jsx(Yt,{}),e.jsxRuntimeExports.jsx(e.DashboardTabs,{})]}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Wt,{})})]})}function Zt(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}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 en({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(Zt,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ks,{}),e.jsxRuntimeExports.jsx(Jt,{}),e.jsxRuntimeExports.jsx(Xt,{})]})]})]})})}exports.Box=Je;exports.ChartArea=Ke;exports.ChartColumnIncreasing=ke;exports.ChartLine=Ie;exports.ChartNoAxesGantt=ze;exports.ChartPie=Oe;exports.ChartScatter=Fe;exports.CircleX=We;exports.CopyPlus=Ye;exports.DashboardPlus=en;exports.Database=Xe;exports.EllipsisVertical=Me;exports.Eraser=Ze;exports.EyeClosed=es;exports.Glasses=ss;exports.Hammer=ts;exports.Hash=ns;exports.House=rs;exports.ListEnd=os;exports.ListStart=is;exports.ListX=as;exports.LoaderCircle=ae;exports.Map=Ve;exports.MessageSquareMore=ls;exports.Network=cs;exports.Play=xs;exports.Plug2=us;exports.Save=ds;exports.SelectComponent=pe;exports.Shapes=qe;exports.ShieldQuestion=ms;exports.Sigma=ps;exports.SwatchBook=js;exports.Tag=hs;exports.ToggleLeft=Es;exports.Type=De;exports.User=fs;exports.cleanCard=gs;exports.getDashbaordStateWithoutData=_e;exports.useEditorAside=le;
235
+ Visual Query Syntax: ${st}`,{data:D,isLoading:A,isFetching:d,isError:R,refetch:p}=e.useQuery({queryKey:["ai-query"],queryFn:()=>e.getRequest("https://semaphor.cloud/api/v1/ai",(l==null?void 0:l.accessToken)||"",{user_content:`userContent: ${O} ${m?y:""}`}),enabled:!1});function w(N){if(N.toLowerCase().includes("bar"))j("bar");else if(N.toLowerCase().includes("line"))j("line");else if(N.toLowerCase().includes("bubble"))j("bubble");else if(N.toLowerCase().includes("scatter"))j("scatter");else if(N.toLowerCase().includes("stacked"))j("stackedBar");else if(N.toLowerCase().includes("pie"))j("pie");else if(N.toLowerCase().includes("donut")||N.toLowerCase().includes("doughnut"))j("doughnut");else if(N.toLowerCase().includes("radar"))j("radar");else return j("bar"),!1;return!0}S.useEffect(()=>{D&&k(N=>[...N,{role:"ai",content:D.response}])},[D]),S.useEffect(()=>{const N=setTimeout(()=>{var V;a.current&&(a.current.scroll({top:a.current.scrollHeight,behavior:"smooth"}),(V=x.current)==null||V.focus())},100);return()=>clearTimeout(N)},[b]);function C(){t&&(k(N=>[...N,{role:"user",content:t}]),w(t)&&c(!0),n(""),p())}S.useEffect(()=>{o&&(C(),i(!1))},[o,i]);const F={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,width:"100%"},M={fontFamily:"monospace",fontSize:14,lineHeight:1.6},B={fontFamily:"Arial, sans-serif",lineHeight:1.6,fontSize:15,padding:"2px 0",marginLeft:20,listStyleType:"disc"},P={p:({node:N,...V})=>e.jsxRuntimeExports.jsx("p",{style:F,...V}),code:({node:N,...V})=>e.jsxRuntimeExports.jsx("code",{className:"rounded-sm bg-muted px-2 py-1 text-sm",...V}),pre:({node:N,...V})=>e.jsxRuntimeExports.jsxs("pre",{className:"space-y-2 rounded-sm bg-muted/50 p-3",style:M,children:[e.jsxRuntimeExports.jsx("code",{className:"whitespace-normal text-sm",children:V.children}),e.jsxRuntimeExports.jsxs("div",{className:"flex justify-start gap-2",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:_,size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.ClipboardCopyIcon,{})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:G=>{const z=_(G);z&&(r(!1),E(z),u(!0))},size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(e.PlayIcon,{})})]})]}),li:({node:N,...V})=>e.jsxRuntimeExports.jsx("li",{style:B,...V})};function _(N){const V=N.currentTarget.closest("pre");if(!V)return;const G=V.textContent||V.innerText;return navigator.clipboard.writeText(G).then(()=>console.log("Text copied to clipboard")).catch(z=>console.error("Error in copying text: ",z)),G}function $(){return b==null?void 0:b.map((N,V)=>N.role==="user"?e.jsxRuntimeExports.jsxs("div",{className:"flex items-start rounded-md bg-muted p-3 text-sm",children:[e.jsxRuntimeExports.jsx(gs,{className:"mr-2 h-5 w-5"}),e.jsxRuntimeExports.jsx("div",{children:N.content})]},V):N.role==="ai"?e.jsxRuntimeExports.jsx(e.Markdown,{className:"w-full overflow-auto py-1",components:P,children:D==null?void 0:D.response.replace(/DuckDB/gi,"Semaphor")},V):e.jsxRuntimeExports.jsx("div",{},V))}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,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:$()})}),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:x,onKeyDown:N=>{N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),n(""),C())},placeholder:"Type your question here...",onFocus:N=>{const V=N.target,G=V.value.length;V.setSelectionRange(G,G)},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:A||d,value:t,onChange:N=>n(N.target.value)})," ",e.jsxRuntimeExports.jsx(e.Button,{className:"h-8",size:"sm",variant:"ghost",onClick:C,children:!A&&!d?e.jsxRuntimeExports.jsx(e.PaperPlaneIcon,{}):e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"})})]})})]})]})}var Ss={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ge=S.createContext&&S.createContext(Ss),nt=["attr","size","title"];function rt(s,r){if(s==null)return{};var t=ot(s,r),n,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(s);for(o=0;o<i.length;o++)n=i[o],!(r.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(s,n)&&(t[n]=s[n])}return t}function ot(s,r){if(s==null)return{};var t={};for(var n in s)if(Object.prototype.hasOwnProperty.call(s,n)){if(r.indexOf(n)>=0)continue;t[n]=s[n]}return t}function Ne(){return Ne=Object.assign?Object.assign.bind():function(s){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n])}return s},Ne.apply(this,arguments)}function $e(s,r){var t=Object.keys(s);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(s);r&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(s,o).enumerable})),t.push.apply(t,n)}return t}function we(s){for(var r=1;r<arguments.length;r++){var t=arguments[r]!=null?arguments[r]:{};r%2?$e(Object(t),!0).forEach(function(n){it(s,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(t)):$e(Object(t)).forEach(function(n){Object.defineProperty(s,n,Object.getOwnPropertyDescriptor(t,n))})}return s}function it(s,r,t){return r=at(r),r in s?Object.defineProperty(s,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):s[r]=t,s}function at(s){var r=lt(s,"string");return typeof r=="symbol"?r:r+""}function lt(s,r){if(typeof s!="object"||!s)return s;var t=s[Symbol.toPrimitive];if(t!==void 0){var n=t.call(s,r||"default");if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(s)}function vs(s){return s&&s.map((r,t)=>S.createElement(r.tag,we({key:t},r.attr),vs(r.child)))}function Y(s){return r=>S.createElement(ct,Ne({attr:we({},s.attr)},r),vs(s.child))}function ct(s){var r=t=>{var{attr:n,size:o,title:i}=s,x=rt(s,nt),a=o||t.size||"1em",l;return t.className&&(l=t.className),s.className&&(l=(l?l+" ":"")+s.className),S.createElement("svg",Ne({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,n,x,{className:l,style:we(we({color:s.color||t.color},t.style),s.style),height:a,width:a,xmlns:"http://www.w3.org/2000/svg"}),i&&S.createElement("title",null,i),s.children)};return Ge!==void 0?S.createElement(Ge.Consumer,null,t=>r(t)):r(Ss)}function xt(s){return Y({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 ut({sql:s}){return e.jsxRuntimeExports.jsxs(e.HoverCard,{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(e.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsxRuntimeExports.jsx(e.HoverCardContent,{align:"end",className:"w-full min-w-fit max-w-[700px] p-3 pt-2",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"text-xs font-semibold",children:"Resolved Query"}),e.jsxRuntimeExports.jsx("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 font-mono text-xs leading-relaxed",children:s})})})]})})]})}function dt(){const[s,r]=S.useState({queryKey:[],queryData:null}),{theme:t}=e.useTheme(),n=e.useQueryClient(),o=S.useRef(),i=e.Le(),[x,a]=S.useState(!1),[l,m]=S.useState(!1),[c,E]=S.useState(!1),[h,u]=S.useState(""),[j,b]=S.useState(!1),k=e.useDashboardStore(f=>f.selectedSheetId);e.useDashboardStore(f=>f.dashboard.baseQueries);const g=e.useEditorStore(f=>f.card),T=e.useDashboardStore(f=>f.theme),I=e.useEditorStore(f=>f.isShowingVisual);e.useDashboardStore(f=>f.onAcceptChanges);const O=e.useEditorStore(f=>f.selectedConnectionId),y=e.useEditorStore(f=>f.selectedDatabaseName),D=e.useEditorStore(f=>f.selectedDatamodelId),A=e.useEditorStore(f=>f.selectedSchemaName);e.useDashboardStore(f=>f.actions.updateFrameCard);const d=e.useEditorStore(f=>f.selectedTableName),R=e.useEditorStore(f=>f.card.sql),p=e.useEditorStore(f=>f.sqlGen),w=e.useEditorStore(f=>f.card.python),C=e.useEditorStore(f=>f.frame),F=e.useDashboardStore(f=>f.dashboard.filters),M=e.useDashboardStore(f=>f.filterValues),B=F==null?void 0:F.filter(f=>f.sheetId===k||!f.sheetId),P=M==null?void 0:M.filter(f=>(B==null?void 0:B.some(J=>J.id===f.filterId))||f.filterId.endsWith(k)),_=e.useEditorStore(f=>f.applyFilters),{setCardCustomCfg:$,setQueryResultColumns:N,setFilterValues:V,setCardSql:G,setCard:z,setCardPython:L,setQueryError:U,setPythonStdOut:q,setCardPreferences:Q,setCardType:K}=e.useEditorStore(f=>f.actions),X=e.useEditorStore(f=>f.onSave);e.useEditorStore(f=>f.actions.setApplyFilters);const Z=e.useEditorStore(f=>f.onClose),ee=e.useEditorStore(f=>f.actions.setSqlGen),re=e.useEditorStore(f=>f.runSql),oe=e.useEditorStore(f=>f.actions.setRunSql),xe=e.useEditorStore(f=>f.actions.setCardCfg),se=e.useEditorStore(f=>f.actions.setIsSqlRunning),{data:H,isLoading:ue,isFetching:de,isSuccess:Re,isError:me,error:he,queryKey:Ee,refetch:ie}=e.useDashboardCardQuery(g);S.useEffect(()=>{if(H&&(H.rowLimitExceeded&&e.ce.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),q((H==null?void 0:H.output)||""),H.records.length>0)){const{dimensionKeys:f}=e.getKeys(H.records);N(f)}},[H,N,q]),S.useEffect(()=>{(ue||de)&&se(!0),(me||Re)&&se(!1),me?(U(he.message),N([]),q("")):U("")},[ue,de,H,q,me,Re,se,N,U,he]),S.useEffect(()=>{re&&(ie(),oe(!1))},[re,ie,oe]);function be(){const f=n.getQueryData(Ee);s.queryData||r({queryKey:Ee,queryData:f}),n.setQueryData(Ee,null),G(""),ee({}),xe(void 0),$(""),Q({}),K("bar")}const fe=f=>{o.current=f};function ye(f,J){if(f.length===0)return"";if(J){const te=f.find(ne=>ne.id===J);if(te){const ne=te.tabTitle;if(ne=="All__Header")return f[0].id;if(ne&&ne.endsWith("__Header")){const Bs=ne.split("__")[0],Pe=f.find(Ps=>Ps.tabTitle===Bs);return Pe?Pe.id:f[0].id}return J}}return f[0].id}function Se(){let f=R;R&&!R.includes("{{")&&(f=Zs(R),G(f));const J={...g,lastSelectedSchema:A,lastSelectedDatamodelId:D,lastSelectedDatabase:y,lastSelectedTable:d,connectionId:O,type:I?g.type:"table",sql:f,customCfg:I?g.customCfg:null},te=C.cards.map(Te=>Te.id===g.id?J:Te),ne={...C,cards:te,activeCardId:ye(te,C.activeCardId)};X==null||X(ne)}function v(){const{queryKey:f,queryData:J}=s;f&&J&&n.setQueryData(f,J),Z==null||Z()}S.useEffect(()=>{if(!i)return;const f=o.current,J=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",te=T==="system"?J:T;return i.editor.defineTheme("default",{base:te==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":te==="light"?"#ffffff":e.hslStringToHex("240 10% 10%")}}),i.editor.setTheme("default"),f&&i&&f.addCommand(i.KeyMod.Shift|i.KeyCode.Enter,function(){return ie(),!1}),()=>{}},[t,T,i]);function qs(){return e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[l&&e.jsxRuntimeExports.jsx("div",{className:"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(e.Label,{className:"ml-6 text-xs font-semibold",children:"Filters"}),P&&l&&e.jsxRuntimeExports.jsx(e.Cross2Icon,{onClick:()=>m(!1),className:"bg-background/50 text-foreground/50 hover:cursor-pointer hover:text-foreground"})]}),e.jsxRuntimeExports.jsx(e.Ft,{theme:"default",onChange:f=>{if(f)try{JSON.parse(f),V(JSON.parse(f))}catch{}},defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:JSON.stringify(P,null,2),options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}},T)]})}),P&&!l&&e.jsxRuntimeExports.jsx(e.Filter,{onClick:()=>m(!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":_})})]})}function _s(){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:x?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:f=>{G(f),e.isObjectEmpty(p)||ee({})},value:R,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:fe})}),x&&e.jsxRuntimeExports.jsx("code",{className:"absolute right-6 top-3 text-sm text-muted-foreground/70",children:"sql"})]}),x&&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:f=>{L(f&&f.trim()||"")},value:w||e.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:14,renderLineHighlight:"none"},defaultLanguage:"python",onMount:fe})}),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:[_s(),qs()]}),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:ue||de,onClick:()=>{ie()},className:"shrink-0",size:"sm",variant:"outline",children:[ue||de?e.jsxRuntimeExports.jsx(ae,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsxRuntimeExports.jsx(us,{className:"mr-2 h-4 w-4"}),"Run"]}),me&&e.jsxRuntimeExports.jsx(et,{error:he.message,setShowAIDialog:E,setTriggerAIRun:b,setUserInputforAI:u}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:be,className:"",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(es,{className:"mr-2 size-4"}),"Clear"]}),e.jsxRuntimeExports.jsx(e.Toggle,{pressed:x,onPressedChange:f=>a(f),className:"",size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(xt,{className:"size-4 text-foreground/70"})}),e.jsxRuntimeExports.jsx(tt,{open:c,setOpen:E,userInput:h,triggerAIRun:j,setTriggerAIRun:b,setUserInput:f=>u(f)})]}),e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[(H==null?void 0:H.sql)&&e.jsxRuntimeExports.jsx(ut,{sql:H.sql}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:v,className:"w-full",size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxRuntimeExports.jsxs(e.Button,{onClick:Se,size:"sm",variant:"outline",children:[e.jsxRuntimeExports.jsx(e.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function mt({data:s}){var x;const[r,t]=S.useState([]),o=Object.keys(s[0]).map(a=>({accessorKey:a,header:({column:l})=>{const m=l.getIsSorted();return e.jsxRuntimeExports.jsx("div",{className:"flex gap-2",children:e.jsxRuntimeExports.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.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]})})}})),i=e.useReactTable({data:s,columns:o,getCoreRowModel:e.getCoreRowModel(),getPaginationRowModel:e.getPaginationRowModel(),onSortingChange:t,getSortedRowModel:e.getSortedRowModel(),manualPagination:!0,state:{sorting:r}});return e.jsxRuntimeExports.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxRuntimeExports.jsxs("table",{className:"w-full",children:[e.jsxRuntimeExports.jsx(e.TableHeader,{children:i.getHeaderGroups().map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{children:a.headers.map(l=>e.jsxRuntimeExports.jsx(e.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:l.isPlaceholder?null:e.flexRender(l.column.columnDef.header,l.getContext())},l.id))},a.id))}),e.jsxRuntimeExports.jsx(e.TableBody,{children:(x=i.getRowModel().rows)!=null&&x.length?i.getRowModel().rows.map(a=>e.jsxRuntimeExports.jsx(e.TableRow,{className:"whitespace-nowrap py-2","data-state":a.getIsSelected()&&"selected",children:a.getVisibleCells().map(l=>e.jsxRuntimeExports.jsx(e.TableCell,{className:"py-3",children:e.flexRender(l.column.columnDef.cell,l.getContext())},l.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 pt({card:s}){var g,T,I,O,y,D,A,d,R,p,w;const[r,t]=S.useState(!1),[n,o]=S.useState([]),{authToken:i}=e.useSemaphorContext(),x=e.getTokenParams(i==null?void 0:i.accessToken),a=e.useDashboardStore(C=>C.themeStyle),l={colors:((T=(g=a==null?void 0:a.chart)==null?void 0:g.dataset)==null?void 0:T.backgroundColor)||[]};(I=s.customCardPreferences)!=null&&I.inputData;const{getCard:m}=e.useCustomVisual(((O=s.customCardPreferences)==null?void 0:O.url)||""),c=((y=s.customCardPreferences)==null?void 0:y.visualType)||"single",E=e.useEditorStore(C=>C.frame);e.useEditorActions();const{data:h}=e.useDashboardCardQuery(s),u=S.useCallback((C,F)=>{o(M=>({...M,[C]:F}))},[]);if(!((D=s.customCardPreferences)!=null&&D.componentName))return null;const j=m((A=s.customCardPreferences)==null?void 0:A.componentName);function b(C){t(C)}const k=Object.keys(((d=s.customCardPreferences)==null?void 0:d.dataInputCardIds)||{}).map(C=>{var B,P,_;const F=(P=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:P[C].cardId,M=(_=E==null?void 0:E.cards)==null?void 0:_.find($=>$.id===F);return M||null});return e.jsxRuntimeExports.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxRuntimeExports.jsxs(S.Suspense,{fallback:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{}),children:[j&&c==="single"&&e.jsxRuntimeExports.jsx(j,{params:x,theme:l,settings:(R=s.customCardPreferences)==null?void 0:R.settings,onDataChange:u,data:(h==null?void 0:h.records)||[]}),j&&c==="multiple"&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[Object.keys(((p=s.customCardPreferences)==null?void 0:p.dataInputCardIds)||{}).map(C=>{var B,P,_;const F=(P=(B=s.customCardPreferences)==null?void 0:B.dataInputCardIds)==null?void 0:P[C].cardId,M=(_=E==null?void 0:E.cards)==null?void 0:_.find($=>$.id===F);if(M)return e.jsxRuntimeExports.jsx(e.MultiInputEmptyRenderer,{onLoadingStatus:b,onDataChange:u,dataInputIndex:C,card:M},M.id+C)}),e.jsxRuntimeExports.jsx("div",{className:"flex flex-col gap-2",children:e.jsxRuntimeExports.jsx(j,{theme:l,onDataChange:u,settings:k.map(C=>{var F;return(F=C==null?void 0:C.customCardPreferences)==null?void 0:F.settings}),data:k.map(C=>C!=null&&C.id?n==null?void 0:n[C.id]:[])})})]})]},(w=s.customCardPreferences)==null?void 0:w.componentName)})}function Cs({className:s,...r}){var k;const t=e.useEditorStore(g=>g.card),n=((k=t.customCardPreferences)==null?void 0:k.showCardHeader)??!0,o=e.useEditorStore(g=>g.frame),i=e.useDashboardStore(g=>g.dashboard.filters);e.useEditorStore(g=>g.actions.setRunSql);const{updateFilter:x}=e.useDashboardActions(),a=i==null?void 0:i.find(g=>g.id===o.filterId),{data:l,isLoading:m,isFetching:c}=e.useDashboardCardQuery(t),{setCard:E}=e.useEditorActions(),{data:h}=e.useTopoJson(t);if(!t.id)return null;let u;l!=null&&l.records&&(l==null?void 0:l.records.length)>0&&(u=e.createChartConfig({data:l==null?void 0:l.records,cardType:t.type,cfg:t.cfg,customCfg:t.customCfg,preferences:t.preferences,topoJson:h}));function j(g){return e.jsxRuntimeExports.jsx(pt,{card:g})}function b(){var g;if(l!=null&&l.records&&(l==null?void 0:l.records.length)===0&&!m&&!c)return e.jsxRuntimeExports.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsxRuntimeExports.jsx(e.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsxRuntimeExports.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(t.type==="custom")return j(t);if(!["table","custom"].includes(t.type)&&u)return e.jsxRuntimeExports.jsx(e.ChartJsVisual,{cfg:u},JSON.stringify(u)+JSON.stringify(t.preferences)+((g=t==null?void 0:t.preferences)==null?void 0:g.customVisualCode));if(t.type==="table"&&(l!=null&&l.records)&&(l==null?void 0:l.records.length)>0)return e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsxRuntimeExports.jsx(e.TableVisual,{card:t,data:l==null?void 0:l.records}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})}return e.jsxRuntimeExports.jsxs(e.Card,{role:"editor-visual-card",className:e.cn("relative flex h-full flex-col rounded-none",s),...r,children:[n&&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:t.title,onSave:g=>E({...t,title:g}),children:e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-5",children:e.jsxRuntimeExports.jsx(e.CardTitle,{className:"text-base",children:t.title||"Edit title..."})})},t.title),e.jsxRuntimeExports.jsx(e.Editable,{text:t.description||"",onSave:g=>E({...t,description:g}),children:e.jsxRuntimeExports.jsx(e.CardDescription,{children:t.description||"Edit description..."})},t.description)]}),a&&e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Editable,{className:"my-1",text:a.title||a.column,onSave:g=>x({...a,title:g}),children:e.jsxRuntimeExports.jsx(e.Label,{children:a.title})}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:a})]})]}),e.jsxRuntimeExports.jsx(e.CardContent,{className:"flex grow flex-col",children:b()})]})}function jt(){const[s,r]=S.useState(!1),[t,n]=S.useState(""),[o,i]=S.useState(""),[x,a]=S.useState(""),[l,m]=S.useState(""),c=e.useEditorStore(y=>y.card),E=e.useEditorStore(y=>y.card.customCfg),{data:h}=e.useDashboardCardQuery(c),{data:u}=e.useTopoJson(c),{setCardCustomCfg:j,setCustomVisualCode:b}=e.useEditorActions();function k(y){var d,R;const D={...y,data:{...y==null?void 0:y.data,datasets:(R=(d=y==null?void 0:y.data)==null?void 0:d.datasets)==null?void 0:R.map(p=>({...p,data:[]}))}};return JSON.stringify(D,null,1)}function g(){var D,A;if(!(h!=null&&h.records)||(h==null?void 0:h.records.length)===0)return;const y=e.createChartConfig({data:h==null?void 0:h.records,cardType:c.type,cfg:c.cfg,preferences:c.preferences,topoJson:u});y&&(n(JSON.stringify(y,null,1)),(D=c==null?void 0:c.preferences)!=null&&D.customVisualCode&&a((A=c==null?void 0:c.preferences)==null?void 0:A.customVisualCode),E&&i(JSON.stringify(E,null,1)))}function T(){if(x&&b(x),!!o)try{const y=JSON.parse(o);return y?(j(y),m(""),i(""),y):void 0}catch(y){console.log(y),m("Invalid JSON")}}function I(){i(""),j(null)}function O(){let y;if(E){const D=e._.cloneDeep(c.cfg),A=e._.merge(D,E);return y=k(A),y}return t?(y=k(JSON.parse(t)),y):""}return e.jsxRuntimeExports.jsxs(e.Dialog,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.DialogTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{onClick:g,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.jsx("div",{className:"flex items-center gap-2",children:e.jsxRuntimeExports.jsx(e.DialogTitle,{children:"Customize Card"})}),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(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(Cs,{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=>i(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:x,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:l}),e.jsxRuntimeExports.jsx(e.Button,{disabled:!E,onClick:I,variant:"outline",children:"Reset"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:T,variant:"outline",children:"Apply"}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>r(!1),variant:"outline",children:"Close"})]})]})]})}function Ns(s){return Y({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 ws(s){return Y({tag:"svg",attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24a8,8,0,0,0-8,8V88a8,8,0,0,0,8,8,32,32,0,1,1-27.72,16,8,8,0,0,0-2.93-10.93l-48.5-28A8,8,0,0,0,37.92,76,104,104,0,1,0,128,24ZM48.09,91.1,83,111.26A48.09,48.09,0,0,0,80,128c0,1.53.08,3,.22,4.52L41.28,143A88.16,88.16,0,0,1,48.09,91.1Zm-2.67,67.31,39-10.44A48.1,48.1,0,0,0,120,175.32v40.31A88.2,88.2,0,0,1,45.42,158.41ZM136,215.63V175.32a48,48,0,0,0,0-94.65V40.36a88,88,0,0,1,0,175.27Z"},child:[]}]})(s)}function ks(s){return Y({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 Is(s){return Y({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function Ds(s){return Y({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 Ls(s){return Y({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 Ts(s){return Y({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 As(s){return Y({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 zs(s){const[r,t]=S.useState(null);return S.useEffect(()=>{s&&(async()=>{const i=(await Promise.resolve().then(()=>require("./lucide-react-ByJO9o6C.js")))[s];t(i)})()},[s]),r}function Os(){const{authToken:s}=e.useSemaphorContext(),{data:r,isLoading:t,isFetching:n,isError:o}=e.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>e.getPlugins(s==null?void 0:s.accessToken)});return{data:r,isLoading:t,isFetching:n,isError:o}}function ht({onChartTypeChange:s}){const[r,t]=S.useState([]),{data:n}=Os();return S.useEffect(()=>{(async()=>{var i;if(n){const a=(await Promise.all((i=n==null?void 0:n.plugins)==null?void 0:i.map(async l=>(await e.loadManifest(l.value)).visuals.map(E=>({name:E.name,icon:E.icon,url:l.value}))))).flat();t(a)}})()},[n]),r.length===0?null:e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.Separator,{className:"my-2"}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-4 place-items-center",children:r.map((o,i)=>e.jsxRuntimeExports.jsx(Et,{text:o.name,onClick:()=>s("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Et=({text:s,icon:r,onClick:t})=>{const n=zs(r||""),o=s.charAt(0).toUpperCase();return e.jsxRuntimeExports.jsx(e.Button,{onClick:t,title:s,variant:"ghost",children:n?e.jsxRuntimeExports.jsx(n,{className:"h-4 w-4"}):o})};function ft(){var c,E;const[s,r]=S.useState(!1),t=e.useEditorStore(h=>h.card),n=t.type,{setCardType:o,setCardPreferences:i,setChartOrientation:x}=e.useEditorStore(h=>h.actions),{setCardCustomCfg:a,setCustomCardPreferences:l}=e.useEditorActions();function m(h,u){a(null),i({}),o(h),u&&l({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),r(!1)}return e.jsxRuntimeExports.jsxs(e.Popover,{open:s,onOpenChange:r,children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(e.Button,{size:"sm",variant:"outline",children:e.jsxRuntimeExports.jsx(gt,{className:"h-4 w-4",chartType:n,customIcon:(c=t.customCardPreferences)==null?void 0:c.icon,componentName:(E=t.customCardPreferences)==null?void 0:E.componentName})})}),e.jsxRuntimeExports.jsxs(e.PopoverContent,{className:"w-50",children:[e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bar"),className:"font-normal",variant:"ghost",children:e.jsxRuntimeExports.jsx(ke,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("line"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ie,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedBar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ls,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("stackedLine"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ds,{className:"size-5",strokeWidth:0})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("scatter"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Fe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("bubble"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Is,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pie"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Oe,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("doughnut"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ws,{className:"size-5",strokeWidth:1})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("radar"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ns,{className:"size-5 font-extralight",strokeWidth:.5})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("polarArea"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ks,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("pyramid"),variant:"ghost",children:e.jsxRuntimeExports.jsx(As,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("range"),variant:"ghost",children:e.jsxRuntimeExports.jsx(ze,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("table"),variant:"ghost",children:e.jsxRuntimeExports.jsx(e.Table,{className:"size-5"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("kpi"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ts,{className:"size-6"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("text"),variant:"ghost",children:e.jsxRuntimeExports.jsx(De,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("map"),variant:"ghost",children:e.jsxRuntimeExports.jsx(Ve,{className:"size-4"})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>m("custom"),variant:"ghost",children:e.jsxRuntimeExports.jsx(qe,{className:"size-4"})})]}),e.jsxRuntimeExports.jsx(ht,{onChartTypeChange:m})]})]})}function gt({chartType:s,className:r,customIcon:t,componentName:n}){const o=zs(t||"");switch(s){case"bar":return e.jsxRuntimeExports.jsx(ke,{className:r});case"line":return e.jsxRuntimeExports.jsx(Ie,{className:r});case"pie":return e.jsxRuntimeExports.jsx(Oe,{className:r});case"radar":return e.jsxRuntimeExports.jsx(Ns,{className:r});case"scatter":return e.jsxRuntimeExports.jsx(Fe,{className:r});case"bubble":return e.jsxRuntimeExports.jsx(Is,{className:r});case"doughnut":return e.jsxRuntimeExports.jsx(ws,{className:r});case"stackedBar":return e.jsxRuntimeExports.jsx(Ls,{className:"size-4 text-foreground/70"});case"stackedLine":return e.jsxRuntimeExports.jsx(Ds,{className:"size-4 text-foreground/70"});case"polarArea":return e.jsxRuntimeExports.jsx(ks,{className:r});case"pyramid":return e.jsxRuntimeExports.jsx(As,{className:r});case"range":return e.jsxRuntimeExports.jsx(ze,{className:r});case"kpi":return e.jsxRuntimeExports.jsx(Ts,{className:r});case"text":return e.jsxRuntimeExports.jsx(De,{className:r});case"map":return e.jsxRuntimeExports.jsx(Ve,{className:r});case"custom":return t&&o?e.jsxRuntimeExports.jsx(o,{className:r}):n?n==null?void 0:n.charAt(0).toUpperCase():e.jsxRuntimeExports.jsx(qe,{className:r});default:return e.jsxRuntimeExports.jsx(e.Table,{className:r})}}function Rt(){var r;const s=e.useEditorStore(t=>t.card);return(r=s.customCardPreferences)==null||r.showCardHeader,e.useEditorActions(),e.jsxRuntimeExports.jsxs(e.DropdownMenu,{children:[e.jsxRuntimeExports.jsx(e.DropdownMenuTrigger,{asChild:!0,children:e.jsxRuntimeExports.jsx(Me,{className:"size-4 cursor-pointer text-muted-foreground/70 transition-colors hover:text-muted-foreground"})}),e.jsxRuntimeExports.jsx(e.DropdownMenuContent,{align:"start",className:"w-40 text-muted-foreground",children:e.jsxRuntimeExports.jsxs(e.DropdownMenuItem,{onClick:()=>{navigator.clipboard.writeText(s.id),e.ce.success("Card ID copied to clipboard")},className:"cursor-pointer space-x-2",children:[e.jsxRuntimeExports.jsx(e.IdCard,{className:"size-5"}),e.jsxRuntimeExports.jsx("span",{children:"Copy Card ID"})]})})]})}function Ue(){const s=e.useEditorStore(d=>d.frame),r=e.useEditorStore(d=>d.card),t=e.useEditorStore(d=>d.isShowingVisual),n=e.useEditorStore(d=>d.isSqlRunning),o=e.useEditorStore(d=>d.queryError),i=e.useEditorStore(d=>d.pythonStdOut),x=e.useEditorStore(d=>d.actions.setRunSql);e.useEditorStore(d=>d.onSave),e.useEditorStore(d=>d.onClose),e.useEditorStore(d=>d.actions.setCardSql),e.useEditorStore(d=>d.actions.setCardType),e.useEditorStore(d=>d.actions.setSqlGen);const{setFrame:a,setCard:l,updateCardInFrame:m}=e.useEditorActions(),{data:c,isLoading:E,isFetching:h}=e.useDashboardCardQuery(r);if(!r)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:"No Active Card"});function u(){const d={connectionId:r.connectionId,id:e.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};j(d)}function j(d){const R={...s,cards:[...s.cards,d],activeCardId:d.id};a(R),l(d)}function b(){const d={...r,id:e.v4(),title:`${r.title} Copy`,tabTitle:`${r.tabTitle||r.title} Copy`};j(d)}function k(d){const R=s.cards.filter(C=>C.id!==d),p=R[0],w={...s,cards:R,activeCardId:p.id};a(w),l(p)}function g(d){const R={...s,cards:s.cards.map(w=>w.id===r.id?r:w),activeCardId:d};a(R);const p=R.cards.find(w=>w.id===d);p.sql&&x(!0),l(p)}const T=(d,R)=>{console.log("handleDragStart",R),d.dataTransfer.setData("tabIndex",R.toString())},I=d=>{d.preventDefault()},O=(d,R)=>{const p=d.dataTransfer.getData("tabIndex");if(p===R.toString())return;const w=Array.from(s.cards),[C]=w.splice(parseInt(p),1);w.splice(R,0,C),a({...s,cards:w})};function y(d,R){return d.cards.length===1&&(R.displayTab===!0||R.displayTab===void 0)||d.activeCardId!==R.id&&(R.displayTab===!0||R.displayTab===void 0)?null:e.jsxRuntimeExports.jsx("div",{onClick:()=>{const p=R.displayTab===void 0?!1:!R.displayTab;l({...R,displayTab:p}),m({...R,displayTab:p})},children:R.displayTab===!0||R.displayTab===void 0?e.jsxRuntimeExports.jsx(e.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsxRuntimeExports.jsx(ss,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function D(){return e.jsxRuntimeExports.jsxs(e.Tabs,{onValueChange:g,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(d=>e.jsxRuntimeExports.jsx(e.TabsContent,{className:"mt-0 grow",value:d.id,children:A()},d.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((d,R)=>e.jsxRuntimeExports.jsx(e.Editable,{text:d.tabTitle||d.title,onSave:p=>{l({...r,tabTitle:p}),m({...r,tabTitle:p})},children:e.jsxRuntimeExports.jsxs(e.TabsTrigger,{draggable:!0,onDragStart:p=>T(p,R),onDragOver:I,onDrop:p=>O(p,R),className:"",value:d.id,children:[y(s,d),d.tabTitle||d.title,s.activeCardId===d.id&&s.cards.length>1&&e.jsxRuntimeExports.jsx(e.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>k(d.id)})]})},d.id)),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(e.Plus,{className:"h-4 w-4"})}),e.jsxRuntimeExports.jsx(e.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:b,children:e.jsxRuntimeExports.jsx(Xe,{className:"h-4 w-4"})})]})})]})}function A(){return r.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,{card:r,data:c==null?void 0:c.records})})}):r.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.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsxRuntimeExports.jsx(e.TextCard,{isLoading:n,card:r,data:c==null?void 0:c.records})})})}):e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.FallbackEditorCard,children:e.jsxRuntimeExports.jsx(Cs,{className:"grow border-none shadow-none"})})}return e.jsxRuntimeExports.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(E||h)&&e.jsxRuntimeExports.jsx(ae,{className:"absolute bottom-0 left-0 right-0 top-0 z-50 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:[t&&e.jsxRuntimeExports.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxRuntimeExports.jsx(ft,{}),!["table","custom"].includes(r.type)&&e.jsxRuntimeExports.jsx(jt,{}),e.jsxRuntimeExports.jsx(Rt,{})]}),e.jsxRuntimeExports.jsx(yt,{})]}),t?D():e.jsxRuntimeExports.jsxs(e.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:i&&e.jsxRuntimeExports.jsx(bt,{})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{})]}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(c==null?void 0:c.records)&&(c==null?void 0:c.records.length)>0&&e.jsxRuntimeExports.jsx(mt,{data:(c==null?void 0:c.records)||[]}),o&&e.jsxRuntimeExports.jsx("span",{className:"font-mono text-xs",children:o}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})})]})]})}function bt(){const s=e.useEditorStore(t=>t.pythonStdOut);if(!s)return null;const r=s.replace(/\n/g,"<br>");return e.jsxRuntimeExports.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsxRuntimeExports.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxRuntimeExports.jsxs(e.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:r}}),e.jsxRuntimeExports.jsx(e.ScrollBar,{orientation:"horizontal"})]})]})}function yt(){const s=e.useEditorStore(t=>t.isShowingVisual),r=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:()=>r(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function St({options:s,value:r,onValueChange:t}){return e.jsxRuntimeExports.jsx(e.RadioGroup,{value:r,onValueChange:t,className:"flex gap-4",defaultValue:s[0].value,children:s.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsxRuntimeExports.jsx(e.RadioGroupItem,{value:n.value,id:n.value}),e.jsxRuntimeExports.jsx("label",{className:"text-sm",htmlFor:n.value,children:n.label})]},n.value))})}function W({label:s,options:r,value:t,onValueChange:n,className:o}){return e.jsxRuntimeExports.jsxs(e.Select,{value:t,onValueChange:n,children:[e.jsxRuntimeExports.jsx(e.SelectTrigger,{className:e.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxRuntimeExports.jsx(e.SelectValue,{placeholder:s})}),e.jsxRuntimeExports.jsx(e.SelectContent,{children:e.jsxRuntimeExports.jsxs(e.SelectGroup,{children:[e.jsxRuntimeExports.jsx(e.SelectLabel,{children:s}),r.map(i=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function ge({children:s,summary:r,open:t,className:n}){return e.jsxRuntimeExports.jsxs("details",{open:t,className:e.cn("space-y-4 [&_summary>svg]:open:-rotate-180",n),children:[e.jsxRuntimeExports.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsxRuntimeExports.jsx(e.Label,{children:r}),e.jsxRuntimeExports.jsx(e.ChevronUp,{className:"h-4 w-4"})]}),e.jsxRuntimeExports.jsx("div",{className:"transition-all ease-in-out",children:s})]})}function vt(){var b,k;const s=e.useEditorStore(g=>g.card.customCardPreferences),{data:r}=Os(),t=(r==null?void 0:r.plugins)||[],n=e.useEditorStore(g=>g.card),o=e.useEditorStore(g=>g.frame),i=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:x}=e.useEditorActions(),{components:a,manifest:l}=e.useCustomVisual((s==null?void 0:s.url)||""),m=(b=l==null?void 0:l.visuals)==null?void 0:b.find(g=>g.name===(s==null?void 0:s.componentName));function c(g,T){if(!s)return;const O={...(s==null?void 0:s.dataInputCardIds)||{},[g]:{cardId:T,hookRef:null}};x({...s,dataInputCardIds:O})}function E(g){var I,O;const T=(I=o==null?void 0:o.cards)==null?void 0:I.filter(y=>{var D;return((D=y==null?void 0:y.customCardPreferences)==null?void 0:D.visualType)!=="multiple"}).map(y=>({value:y.id,label:y.tabTitle||y.title}));return e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:(O=g==null?void 0:g.dataInputs)==null?void 0:O.map((y,D)=>{var A,d;return e.jsxRuntimeExports.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsxRuntimeExports.jsx("div",{className:"col-span-4 flex items-center",children:y}),e.jsxRuntimeExports.jsx(W,{className:"col-span-6 h-8 w-full justify-between",label:"",options:T||[],value:((d=(A=s==null?void 0:s.dataInputCardIds)==null?void 0:A[D])==null?void 0:d.cardId)||"",onValueChange:R=>c(D,R)})]},D+Math.random())})})}function h(g,T,I=[]){var O,y;return s?g==="input"?e.jsxRuntimeExports.jsx(e.Input,{className:`h-8 w-full ${e.removeRing}`,value:((O=s==null?void 0:s.settings)==null?void 0:O[T])||"",onChange:D=>{x({...s,settings:{...s==null?void 0:s.settings,[T]:D.target.value}})}},T):g==="select"?e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:I,value:((y=s==null?void 0:s.settings)==null?void 0:y[T])||"",onValueChange:D=>{x({...s,settings:{...s==null?void 0:s.settings,[T]:D}})}}):null:null}function u(g){const T=Object.entries((g==null?void 0:g.settings)||{});return e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:T.map(([I,O])=>e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:O.title}),h(O.ui,I,O.options)]},I))})}function j(g){s&&x({...s,visualType:g,componentName:""})}return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(ge,{summary:"Plugin Settings",children:e.jsxRuntimeExports.jsx("div",{className:"space-y-4 text-sm",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxRuntimeExports.jsx("div",{className:"space-y-2",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:t,value:(s==null?void 0:s.url)||"",onValueChange:g=>x({...s||{url:"",componentName:""},url:g})})})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsxRuntimeExports.jsx(St,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:j}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Component"}),e.jsxRuntimeExports.jsx("div",{className:"space-y-2 px-2",children:a&&e.jsxRuntimeExports.jsx(W,{className:"h-8 w-full",label:"",options:(a==null?void 0:a.filter(g=>g.type===i).map(g=>({value:g.name,label:g.name})))||[],value:s.componentName,onValueChange:g=>{console.log("changing value",g),x({...s,componentName:g})}})})]})})]})})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),((k=n==null?void 0:n.customCardPreferences)==null?void 0:k.componentName)&&e.jsxRuntimeExports.jsxs(ge,{summary:"Component Settings",children:[m&&m.dataInputs&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Input Mapping"}),e.jsxRuntimeExports.jsx("div",{className:"px-2",children:E(m)})]}),m&&m.settings&&e.jsxRuntimeExports.jsx("div",{className:"space-y-3",children:e.jsxRuntimeExports.jsx("div",{className:"px-2",children:u(m)})})]})]})}function ce(){const[s,r]=S.useState([]);e.useEditorStore(c=>c.card.cfg);const t=e.useEditorStore(c=>c.card.preferences),{setCardCfg:n,setFilterOnClickColumnIndex:o,setCardPreferences:i}=e.useEditorStore(c=>c.actions),x=e.useEditorStore(c=>c.queryResultColumns);e.useEditorStore(c=>{var E;return(E=c.card.preferences)==null?void 0:E.filterOnClickColumnIndex}),S.useEffect(()=>{x&&r(new Array(x.length).fill(!1))},[x]);function a(c,E){var h,u;E?t!=null&&t.onClickFilter&&((h=t==null?void 0:t.onClickFilter)==null?void 0:h.length)>0?i({...t,onClickFilter:[...t.onClickFilter,{columnIndex:c,expression:""}]}):i({...t,onClickFilter:[{columnIndex:c,expression:""}]}):(i({...t,onClickFilter:(u=t==null?void 0:t.onClickFilter)==null?void 0:u.filter(j=>j.columnIndex!==c)}),r(j=>{const b=[...j];return b[c]=!1,b}))}function l(c,E){var u;const h=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.map(j=>j.columnIndex===c?{...j,expression:E.target.value}:j);i({...t,onClickFilter:h})}function m(c){var E,h,u,j;if(s!=null&&s[c]||(h=(E=t==null?void 0:t.onClickFilter)==null?void 0:E.find(b=>b.columnIndex===c))!=null&&h.expression)return e.jsxRuntimeExports.jsx(e.Input,{value:(j=(u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(b=>b.columnIndex===c))==null?void 0:j.expression,onChange:b=>l(c,b),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"}),x==null?void 0:x.map((c,E)=>{var h,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:!!((h=t==null?void 0:t.onClickFilter)!=null&&h.find(j=>j.columnIndex===E)),onCheckedChange:j=>a(E,j)}),e.jsxRuntimeExports.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:c}),e.jsxRuntimeExports.jsx("div",{className:"flex items-center gap-2",children:((u=t==null?void 0:t.onClickFilter)==null?void 0:u.find(j=>j.columnIndex===E))&&e.jsxRuntimeExports.jsx(e.Pencil,{onClick:()=>{r(j=>{const b=[...j];return b[E]=!j[E],b})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),m(E)]})},c)})]})}function Le(){var x,a,l;const s=e.useEditorStore(m=>m.card.preferences),r=e.useEditorStore(m=>m.card.cfg),{setCardCfg:t,setCardPreferences:n,setChartOrientation:o}=e.useEditorStore(m=>m.actions);(x=r==null?void 0:r.options)!=null&&x.indexAxis;function i(m){o(m)}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:((a=s==null?void 0:s.chartOptions)==null?void 0:a.indexAxis)||((l=r==null?void 0:r.options)==null?void 0:l.indexAxis)||"x",onValueChange:i,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 ve="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Qe(s,r){var n,o,i;const t=e.getNumberAxis(s,r);return((i=(o=(n=s==null?void 0:s.chartOptions)==null?void 0:n.scales)==null?void 0:o[t])==null?void 0:i.type)||"linear"}function Fs(){var P,_,$,N,V,G;const[s,r]=S.useState(!1),t=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.preferences}),n=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.cfg}),o=e.getNumberAxis(t,n),[i,x]=S.useState(Qe(t)),[a,l]=S.useState((($=(_=(P=t==null?void 0:t.chartOptions)==null?void 0:P.scales)==null?void 0:_[o])==null?void 0:$.min)||""),[m,c]=S.useState(((G=(V=(N=t==null?void 0:t.chartOptions)==null?void 0:N.scales)==null?void 0:V[o])==null?void 0:G.max)||""),[E,h]=S.useState(a||m?"custom":"auto"),[u,j]=S.useState(""),[b,k]=S.useState(0),[g,T]=S.useState(""),[I,O]=S.useState(""),[y,D]=S.useState(""),A=e.useEditorStore(z=>z.actions.setCardPreferences),{updateCardInFrame:d}=e.useEditorActions(),R=e.useEditorStore(z=>z.card),p=e.useEditorStore(z=>{var L;return(L=z.card)==null?void 0:L.type}),w=["pie","doughnut","polarArea"].includes(p);S.useEffect(()=>{var z,L,U,q,Q,K,X,Z,ee,re,oe,xe,se,H;x(Qe(t)),l(((U=(L=(z=t==null?void 0:t.chartOptions)==null?void 0:z.scales)==null?void 0:L[o])==null?void 0:U.min)===0?0:""),c(((K=(Q=(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales)==null?void 0:Q[o])==null?void 0:K.max)||""),j(((re=(ee=(Z=(X=t==null?void 0:t.chartOptions)==null?void 0:X.scales)==null?void 0:Z[o])==null?void 0:ee.ticks)==null?void 0:re.stepSize)||""),k(((oe=t==null?void 0:t.numberAxisFormat)==null?void 0:oe.decimalPlaces)||0),T(((xe=t==null?void 0:t.numberAxisFormat)==null?void 0:xe.suffix)||""),O(((se=t==null?void 0:t.numberAxisFormat)==null?void 0:se.currency)||""),D(((H=t==null?void 0:t.numberAxisFormat)==null?void 0:H.locale)||"")},[s,t,o]);function C(z,L){return L===""||/^[0-9\b]+$/.test(L)?Number(L):Number(z)}function F(){const z=[...new Set(e.LOCALE_CURRENCY_PAIRS.map(L=>L.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:I||"none",onValueChange:L=>O(L==="none"?"":L),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"}),z.map(L=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:L,children:L},L))]})})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:y,onValueChange:L=>D(L),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(L=>e.jsxRuntimeExports.jsx(e.SelectItem,{value:L.locale,children:L.locale},L.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:b,onChange:L=>k(Number(L.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ve}`})]})]})}function M(){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:z=>l(L=>C(L,z.target.value)),className:`col-span-1 h-8 w-full ${ve}`}),e.jsxRuntimeExports.jsx(e.Input,{value:m,onChange:z=>c(L=>C(L,z.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ve}`})]}),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:z=>j(L=>C(L,z.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ve}`})]})]})}function B(){var q;let z={};E==="custom"&&(z={min:a,max:m,ticks:{stepSize:u}});const L={...t||{},chartOptions:{...t==null?void 0:t.chartOptions,scales:{...(q=t==null?void 0:t.chartOptions)==null?void 0:q.scales,[o]:{type:i,...i==="linear"?z:{}}}},numberAxisFormat:{decimalPlaces:b,suffix:g,currency:I,locale:y}};console.log(L),A(L);const U={...R,preferences:L};d(U)}return e.jsxRuntimeExports.jsxs(e.Popover,{onOpenChange:z=>r(z),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:w,value:i,onValueChange:z=>x(z),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"})]})})]})]}),i=="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:w,id:"scale-option",value:E,onValueChange:z=>h(z),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"&&i=="linear"&&M(),F(),e.jsxRuntimeExports.jsx(e.SelectSeparator,{}),e.jsxRuntimeExports.jsx("div",{className:"grid grid-cols-3",children:e.jsxRuntimeExports.jsx(e.Button,{onClick:B,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Ct({idx:s}){var a;const r=e.useEditorStore(l=>{var m;return(m=l.card)==null?void 0:m.preferences}),t=e.useEditorStore(l=>{var m;return(m=l.card.preferences)==null?void 0:m.datasetOptions}),n=e.useEditorStore(l=>l.actions.setCardPreferences),o=(a=r==null?void 0:r.chartOptions)==null?void 0:a.indexAxis,i=t==null?void 0:t.find(l=>l.idx===s);function x(l,m){(l==="end"||l==="start")&&e.getContrastColor(e.getCanvasBackgroundColor());const c={display:l!=="none",align:l,anchor:l,clamp:!0};if(!i)n({...r,datasetOptions:[...t||[],{idx:m,datalabels:c}]});else{const E={...i};E.datalabels=c;const h=t==null?void 0:t.map(u=>u.idx===m?E:u);n({...r,datasetOptions:h})}}return e.jsxRuntimeExports.jsxs(e.Popover,{children:[e.jsxRuntimeExports.jsx(e.PopoverTrigger,{children:e.jsxRuntimeExports.jsx(Es,{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:()=>x("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:()=>x("start",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(is,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("center",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(ls,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsxRuntimeExports.jsx(e.Button,{onClick:()=>x("end",s),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsxRuntimeExports.jsx(as,{className:e.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function Ms(){const s=e.useEditorStore(m=>m.card),r=e.useEditorStore(m=>{var c,E,h;return(h=(E=(c=m==null?void 0:m.card)==null?void 0:c.preferences)==null?void 0:E.chartOptions)==null?void 0:h.indexAxis}),{data:t}=e.useDashboardCardQuery(s),n=r==="y"?"Y axis":"X axis",o=r==="y"?"X axis":"Y axis",{keys:i,metricKeys:x,dimensionKeys:a}=e.getKeys((t==null?void 0:t.records)||[]);let l=x;if(["stackedBar","stackedLine"].includes(s.type)){const m=e.pivotData({dataArray:(t==null?void 0:t.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:l[0]}),{metricKeys:c}=e.getKeys(m);l=c}return i.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:n}),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:a[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:o}),e.jsxRuntimeExports.jsx(Fs,{})]}),e.jsxRuntimeExports.jsx("div",{className:"my-1 space-y-1",children:l.map((m,c)=>e.jsxRuntimeExports.jsx(Nt,{col:m,idx:c},m))})]})]})}function Nt({col:s,idx:r}){const t=e.useEditorStore(a=>{var l;return(l=a.card)==null?void 0:l.preferences}),n=e.useEditorStore(a=>{var l;return(l=a.card.preferences)==null?void 0:l.datasetOptions}),o=n==null?void 0:n.find(a=>a.idx===r),{setCardPreferences:i}=e.useEditorStore(a=>a.actions);function x(a){if(!o)i({...t,datasetOptions:[...n||[],{idx:r,type:a==="area"?"line":a,fill:a==="area"?"origin":""}]});else{const l={...o};l.type=a==="area"?"line":a,l.fill=a==="area"?"origin":"";const m=n==null?void 0:n.map(c=>c.idx===r?l:c);i({...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(ke,{onClick:()=>x("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ie,{onClick:()=>x("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(We,{onClick:()=>x("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsxRuntimeExports.jsx(Ct,{idx:r})]})]})}function Vs(){const s=e.useEditorStore(h=>h.selectedConnectionId),r=e.useEditorStore(h=>h.selectedDatamodelId),t=e.useEditorStore(h=>h.selectedDatabaseName),n=e.useEditorStore(h=>h.selectedSchemaName),o=e.useEditorStore(h=>h.selectedTableName),i=e.useDashboardStore(h=>h.dashboard.filters)||[],x=e.useDashboardStore(h=>h.actions.addFilter),a=e.useDashboardStore(h=>h.actions.removeFilter),{removeFilterValues:l}=e.useDashboardActions(),{modelItems:m,tableName:c}=le();function E(h,u="dashboard"){var D;const j=e.fmt(h.column_name),b=e.fmt(t||""),k=e.fmt(n||""),g=e.fmt(c);let T=e.getQualifiedTableName(k,g),I=`${T}.${j}`;const O=(D=m==null?void 0:m.find(A=>A.id===r))==null?void 0:D.name;r&&r!=="none"&&(I=`${e.DATAMODEL_NAMESPCACE}.${O}.${j}`,T=`${e.DATAMODEL_NAMESPCACE}.${O}`);const y=i==null?void 0:i.find(A=>A.column===I&&A.table===g&&(A.database===b||A.database===t));if(y)l(y.id),a(y.id);else{const A=e.v4();return c==="api"&&s?(x({location:u,id:A,column:I,title:h.column_name,dataType:h.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:e.getDefaultFilterSql(h.data_type,T,j)}),A):(x({id:A,location:u,column:I,title:h.column_name,dataType:h.data_type,table:o||"",database:t||"",connectionId:s||"",operation:"in",sql:e.getDefaultFilterSql(h.data_type,T,j)}),A)}}return{assignFilter:E}}function je(){const s=e.useDashboardStore(a=>a.dashboard.filters),r=e.useEditorStore(a=>a.frame),{setFrame:t}=e.useEditorActions(),{columns:n}=le(),{assignFilter:o}=Vs();function i(a){const l=o(a,"frame");t({...r,filterId:l})}const x=s==null?void 0:s.find(a=>a.id===r.filterId);return e.jsxRuntimeExports.jsxs("div",{className:"space-y-3",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Card Filter"}),e.jsxRuntimeExports.jsx(wt,{onSelect:i,columns:n}),x&&e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:x})]})}function wt({columns:s,onSelect:r}){var x;const[t,n]=He.useState(!1),[o,i]=He.useState("");return e.jsxRuntimeExports.jsxs(e.Popover,{open:t,onOpenChange:n,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?(x=s.find(a=>a.column_name===o))==null?void 0:x.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:l=>{const m=l===o?"":l;i(m),n(!1),m&&r(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 kt({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:r=>r.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(Le,{}),e.jsxRuntimeExports.jsx(Ms,{})]})]}),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(je,{})]})]})]})})}function Be(){var o,i,x;const s=e.useEditorStore(a=>a.card.cfg),r=e.useEditorStore(a=>a.actions.setCardCfg),t=e.useEditorStore(a=>a.card.type);function n(a){var c;const l={datalabels:{display:a!=="none",align:a,anchor:a,clamp:!0}},m={...s,options:{...s==null?void 0:s.options,plugins:{...(c=s==null?void 0:s.options)==null?void 0:c.plugins,...l}}};r(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(Fs,{})]}),e.jsxRuntimeExports.jsxs(e.Select,{value:(x=(i=(o=s==null?void 0:s.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:x.anchor,onValueChange:n,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 It({cardType:s}){function r(t){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"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis 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:"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:i=>i.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:r(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(Be,{})})]}),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(je,{})]})]})]})})}const Dt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Lt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Tt(){const s=e.useEditorStore(r=>r.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:At(s)}),e.jsxRuntimeExports.jsx("section",{className:"",children:["line","bar"].includes(s)&&e.jsxRuntimeExports.jsx(Le,{})}),!["kpi"].includes(s)&&e.jsxRuntimeExports.jsxs("div",{className:"space-y-4",children:[e.jsxRuntimeExports.jsx(Be,{}),e.jsxRuntimeExports.jsx(ce,{}),e.jsxRuntimeExports.jsx(je,{})]})]})}function At(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(Dt,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(Lt,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 zt(){var l,m,c,E,h;const s=e.useEditorStore(u=>u.card.preferences),r=e.useEditorStore(u=>u.actions.setCardPreferences),t=e.useEditorStore(u=>u.actions.setNumberFormat);e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.decimalPlaces});const n=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.locale}),o=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.currency});e.useEditorStore(u=>u.actions.setFilterOnClickField);const i=e.useEditorStore(u=>{var j,b;return(b=(j=u.card.preferences)==null?void 0:j.formatNumber)==null?void 0:b.colorRanges})||[],x=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:!!((l=s==null?void 0:s.formatNumber)!=null&&l.enabled),onCheckedChange:u=>{r({...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:n||"none",onValueChange:u=>{var j,b,k;return t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",u,((k=s==null?void 0:s.formatNumber)==null?void 0:k.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.jsxRuntimeExports.jsx(e.SelectItem,{value:"none",children:"None"},"none"),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 j,b,k;console.log("currency",u),t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,u==="none"?"":u,((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.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=(c=s==null?void 0:s.formatNumber)==null?void 0:c.decimalPlaces)==null?void 0:E.toString())||"0",onValueChange:u=>{var j,b,k;return t(Number(u),((j=s==null?void 0:s.formatNumber)==null?void 0:j.currency)||"",((b=s==null?void 0:s.formatNumber)==null?void 0:b.locale)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.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:((h=s==null?void 0:s.formatNumber)==null?void 0:h.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 j,b,k;return t(((j=s==null?void 0:s.formatNumber)==null?void 0:j.decimalPlaces)||0,((b=s==null?void 0:s.formatNumber)==null?void 0:b.currency)||"",((k=s==null?void 0:s.formatNumber)==null?void 0:k.locale)||"",u.target.value)}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-3"}),e.jsxRuntimeExports.jsx(e.ColorFormat,{colorRanges:i,setColorRanges:x})]})]})}function Ot(){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(zt,{})}),e.jsxRuntimeExports.jsx("div",{}),e.jsxRuntimeExports.jsx("div",{})]})}const Ft=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],Mt=["blues","brBG","buGn","buPu","cividis","cool","cubehelixDefault","gnBu","greens","greys","inferno","magma","orRd","oranges","pRGn","piYG","plasma","puBu","puBuGn","puOr","puRd","purples","rainbow","rdBu","rdGy","rdPu","rdYlBu","rdYlGn","reds","sinebow","spectral","turbo","viridis","warm","ylGn","ylGnBu","ylOrBr","ylOrRd"],Vt=Mt.map(s=>({label:s,value:s}));function qt(){var l,m,c,E,h,u,j,b,k,g,T,I,O,y,D,A,d,R;const s=e.useEditorStore(p=>p.card),r=(m=(l=s==null?void 0:s.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:m.topoJsonUrl,[t,n]=S.useState(((E=(c=s==null?void 0:s.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:E.customTopoJsonUrl)||""),{setCardPreferences:o}=e.useEditorActions(),{data:i}=e.useTopoJson(s),x=Object.keys((i==null?void 0:i.objects)||{}).map(p=>({label:p,value:p}))||[],a=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxRuntimeExports.jsxs("div",{className:"p-6",children:[e.jsxRuntimeExports.jsx(ge,{summary:"Map Query",children:e.jsxRuntimeExports.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ge,{open:!0,summary:"Settings",children:e.jsxRuntimeExports.jsxs("div",{className:"space-y-3 px-2",children:[e.jsxRuntimeExports.jsx(W,{className:"h-9",options:a,onValueChange:p=>{console.log("value",p),o({...s.preferences,mapVisualOptions:{topoJsonUrl:p}})},value:r||"",label:"Select Map"}),r==="custom"&&e.jsxRuntimeExports.jsx(e.Input,{onChange:p=>{n(p.target.value)},onBlur:()=>{var p;console.log("onBlur",t),o({...s.preferences,mapVisualOptions:{...(p=s.preferences)==null?void 0:p.mapVisualOptions,customTopoJsonUrl:t}})},value:t,className:`h-9 w-full ${e.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxRuntimeExports.jsxs(e.jsxRuntimeExports.Fragment,{children:[e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Map Object"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:x,value:((u=(h=s.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:u.objectKey)||"",label:"Map Object",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,objectKey:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Projection"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:Ft,value:((b=(j=s.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:b.projection)||"",label:"Projection",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projection:p}})}})]}),e.jsxRuntimeExports.jsxs("div",{className:"space-y-1",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Colors"}),e.jsxRuntimeExports.jsx(W,{className:"h-9",options:Vt,value:((g=(k=s.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:g.colorScale)||"",label:"Select Color Scale",onValueChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,colorScale:p}})}})]})]})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ge,{className:"",summary:"Scale Options",children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:.1,value:((I=(T=s.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:I.projectionScale)||1,onChange:p=>{var w;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionScale:Number(p.target.value)}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"X"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((D=(y=(O=s.preferences)==null?void 0:O.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:D[0])||0,onChange:p=>{var w,C,F,M;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[Number(p.target.value),((M=(F=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:M[1])||0]}})}}),e.jsxRuntimeExports.jsx(e.Label,{children:"Y"}),e.jsxRuntimeExports.jsx(e.Input,{className:`h-9 w-full ${e.removeRing}`,type:"number",step:10,value:((R=(d=(A=s.preferences)==null?void 0:A.mapVisualOptions)==null?void 0:d.projectionOffset)==null?void 0:R[1])||0,onChange:p=>{var w,C,F,M;o({...s.preferences,mapVisualOptions:{...(w=s.preferences)==null?void 0:w.mapVisualOptions,projectionOffset:[((M=(F=(C=s.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:F.projectionOffset)==null?void 0:M[0])||0,Number(p.target.value)]}})}})]})}),e.jsxRuntimeExports.jsx(e.Separator,{className:"my-4"}),e.jsxRuntimeExports.jsx(ce,{})]})}function _t(){var n;const s=e.useEditorStore(o=>o.card.preferences),{setCardPreferences:r}=e.useEditorStore(o=>o.actions);function t(o){r({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxRuntimeExports.jsxs(e.RadioGroup,{value:(n=s==null?void 0:s.textVisualOptions)!=null&&n.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 Ce({cardType:s,docContent:r,suffix:t="Chart"}){let n="pie-chart";return s==="radar"&&(n="radar-chart"),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:r||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:o=>o.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/concepts/visuals#${n}`,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(Le,{}),s!=="text"&&e.jsxRuntimeExports.jsx(Be,{}),s==="text"&&e.jsxRuntimeExports.jsx(_t,{})]})]}),!["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(je,{})]})]})]})})}function Bt(){const s=e.useEditorStore(n=>{var o,i;return(i=(o=n==null?void 0:n.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:r}=e.useEditorActions();function t(){return e.jsxRuntimeExports.jsxs("div",{className:"space-y-2",children:[e.jsxRuntimeExports.jsx(e.Label,{children:"Sort"}),e.jsxRuntimeExports.jsx(W,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:n=>{r(n)}})]})}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:n=>n.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(Le,{}),t(),e.jsxRuntimeExports.jsx(Ms,{})]})]}),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(je,{})]})]})]})})}function Pt({}){const s=e.useEditorStore(n=>{var o;return(o=n.card)==null?void 0:o.preferences}),r=e.useEditorStore(n=>n.actions.setCardPreferences),t=n=>{r({...s,allowDownload:n})};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(je,{})]})]})}),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 Ht=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."]})]}),Gt=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."]})]}),$t=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 Ut(){const s=e.useEditorStore(t=>t.card.type);function r(t){switch(t){case"stackedBar":case"stackedLine":return e.jsxRuntimeExports.jsx(Bt,{});case"pyramid":return e.jsxRuntimeExports.jsx(Ce,{docContent:Ht,cardType:t});case"kpi":return e.jsxRuntimeExports.jsx(Ot,{});case"line":case"bar":return e.jsxRuntimeExports.jsx(kt,{cardType:t});case"range":return e.jsxRuntimeExports.jsx(Ce,{docContent:Gt,cardType:t});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsxRuntimeExports.jsx(Ce,{cardType:t});case"bubble":case"scatter":return e.jsxRuntimeExports.jsx(It,{cardType:t});case"table":return e.jsxRuntimeExports.jsx(Pt,{cardType:t});case"text":return e.jsxRuntimeExports.jsx(Ce,{docContent:$t,cardType:t,suffix:"Visual"});case"map":return e.jsxRuntimeExports.jsx(qt,{});case"custom":return e.jsxRuntimeExports.jsx(vt,{});default:return e.jsxRuntimeExports.jsx(Tt,{})}}return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"h-full w-full text-sm",children:r(s)})}function Qt(){const s=e.useEditorStore(r=>r.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(dt,{})}),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(Ut,{})})}),e.jsxRuntimeExports.jsx(e.ResizableHandle,{className:"border"}),e.jsxRuntimeExports.jsx(e.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsxRuntimeExports.jsx(Ue,{})})]}):e.jsxRuntimeExports.jsx(Ue,{})})]})}function Jt({authToken:s,onSave:r,onClose:t}){e.useDashboardStore(x=>x.themeStyle);const n=e.useEditorStore(x=>x.actions.setOnSave),o=e.useEditorStore(x=>x.actions.setOnClose),i=e.useDashboardStore(x=>x.actions.setAuthToken);return S.useEffect(()=>{r&&n(r),t&&o(t)},[r,n,t,o]),S.useEffect(()=>{s&&s.accessToken&&i(s)},[s,i]),e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.EditorPanel,{style:{},className:"rounded-none",role:"editor-panel",children:[e.jsxRuntimeExports.jsx(e.EditorAside,{className:"rounded-none border-r-[1.5px]",children:e.jsxRuntimeExports.jsx(ys,{})}),e.jsxRuntimeExports.jsx(e.EditorMain,{children:e.jsxRuntimeExports.jsx(Qt,{})})]})})}function Kt(){e.useDashboardStore(x=>x.selectedCardId);const s=e.useDashboardStore(x=>x.selectedSheetId),{setIsVisualEditing:r}=e.useDashboardStore(x=>x.actions),t=e.useDashboardStore(x=>x.isVisualEditing),n=e.useDashboardStore(x=>x.actions.updateFrame);function o(x){s&&(n(s,x),r(!1))}function i(){r(!1)}return e.jsxRuntimeExports.jsx("div",{role:"editor-container",className:e.cn("flex grow",{"max-h-0 overflow-hidden":!t}),children:e.jsxRuntimeExports.jsx(Jt,{onSave:o,onClose:i})})}function Wt(){const s=e.useEditorStore(i=>i.selectedDatabaseName),r=e.useEditorStore(i=>i.selectedTableName),t=e.useDashboardStore(i=>i.dashboard.filters)||[],{columns:n}=le(),{assignFilter:o}=Vs();return e.jsxRuntimeExports.jsx(e.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:n==null?void 0:n.map(i=>{const x=t==null?void 0:t.find(a=>a.column===e.fmt(i.column_name)&&a.table===r&&a.database===s);return e.jsxRuntimeExports.jsx("div",{onClick:()=>o(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":x}),children:e.jsxRuntimeExports.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxRuntimeExports.jsx(bs,{column:i}),e.jsxRuntimeExports.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Yt(){e.useDashboardStore(r=>r.showFilters);const s=e.useDashboardStore(r=>r.actions.setShowFilters);return e.jsxRuntimeExports.jsxs("section",{className:"relative flex min-w-72 grow flex-col border-l px-1",children:[e.jsxRuntimeExports.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsxRuntimeExports.jsx(e.Label,{className:"px-2 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(ys,{ColumnsComponent:()=>e.jsxRuntimeExports.jsx(Wt,{})})})]})}function Xt(){const s=e.useDashboardStore(n=>n.dashboard.filters),r=e.useDashboardStore(n=>n.theme),t=s==null?void 0:s.filter(n=>n.hide);return t!=null&&t.length?e.jsxRuntimeExports.jsx("div",{className:e.cn("mb-1 flex items-center gap-2 border-y pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":r==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":r==="dark"}),children:t==null?void 0:t.map(n=>e.jsxRuntimeExports.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsxRuntimeExports.jsx(e.FilterHeader,{filter:n}),e.jsxRuntimeExports.jsx(e.FilterComponent,{filter:n})]},n.id))}):null}function Zt(){const s=e.useDashboardStore(n=>n.showFilters),r=e.useDashboardStore(n=>n.isVisualEditing),t=e.useDashboardStore(n=>n.isDashboardEditing);return e.jsxRuntimeExports.jsxs("div",{role:"dashboard-plus-main",className:e.cn("",{"max-h-0 overflow-hidden":r,"flex grow":!r}),children:[e.jsxRuntimeExports.jsxs("section",{className:"flex grow flex-col",children:[t&&e.jsxRuntimeExports.jsx(Xt,{}),e.jsxRuntimeExports.jsx(e.DashboardTabs,{})]}),s&&e.jsxRuntimeExports.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsxRuntimeExports.jsx(Yt,{})})]})}function en(){const s=e.useDashboardStore(n=>n.dashboard),r=e.useDashboardStore(n=>n.actions.setDashboard),t=e.useDashboardStore(n=>n.showDashboardJSON);return e.useDashboardStore(n=>n.actions.setShowDashboardJSON),e.jsxRuntimeExports.jsx("div",{className:e.cn(" p-2",{hidden:!t}),children:e.jsxRuntimeExports.jsx(e.de,{onChange:n=>{if(n)try{JSON.parse(n),r(JSON.parse(n))}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 sn({showControls:s=!1,showFooter:r=!0,...t}){return e.jsxRuntimeExports.jsx(e.ErrorBoundary,{FallbackComponent:e.Fallback,children:e.jsxRuntimeExports.jsxs(e.SemaphorContextProvider,{dashboardProps:t,children:[e.jsxRuntimeExports.jsx(e.Oe,{}),e.jsxRuntimeExports.jsxs(e.UXProvider,{children:[e.jsxRuntimeExports.jsx(en,{}),e.jsxRuntimeExports.jsxs(e.DashboardPanel,{...t,children:[s&&e.jsxRuntimeExports.jsx(Ws,{}),e.jsxRuntimeExports.jsx(Kt,{}),e.jsxRuntimeExports.jsx(Zt,{})]})]})]})})}exports.Box=Je;exports.Braces=Ke;exports.ChartArea=We;exports.ChartColumnIncreasing=ke;exports.ChartLine=Ie;exports.ChartNoAxesGantt=ze;exports.ChartPie=Oe;exports.ChartScatter=Fe;exports.CircleX=Ye;exports.CopyPlus=Xe;exports.DashboardPlus=sn;exports.Database=Ze;exports.EllipsisVertical=Me;exports.Eraser=es;exports.EyeClosed=ss;exports.Glasses=ts;exports.Hammer=ns;exports.Hash=rs;exports.House=os;exports.ListEnd=is;exports.ListStart=as;exports.ListX=ls;exports.LoaderCircle=ae;exports.Map=Ve;exports.MessageSquareMore=cs;exports.Network=xs;exports.Play=us;exports.Plug2=ds;exports.Save=ms;exports.SelectComponent=pe;exports.Shapes=qe;exports.ShieldQuestion=ps;exports.Sigma=js;exports.SwatchBook=hs;exports.Tag=Es;exports.ToggleLeft=fs;exports.Type=De;exports.User=gs;exports.cleanCard=Rs;exports.getDashbaordStateWithoutData=_e;exports.useEditorAside=le;