react-semaphor 0.0.394 → 0.0.396

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,29 +1,59 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-B6jeQRvN.js"),e=require("react/jsx-runtime"),C=require("react");require("react-dom");function gs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const de=gs(C);/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./chunks/index-BFOGQwAt.js"),e=require("react/jsx-runtime"),C=require("react");require("react-dom");function gs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const de=gs(C);/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const js=s.createLucideIcon("BookOpenText",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M16 12h2",key:"7q9ll5"}],["path",{d:"M16 8h2",key:"msurwy"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}],["path",{d:"M6 12h2",key:"32wvfc"}],["path",{d:"M6 8h2",key:"30oboj"}]]);/**
6
+ */const js=s.createLucideIcon("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
7
7
  * @license lucide-react v0.453.0 - ISC
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const bs=s.createLucideIcon("BookType",[["path",{d:"M10 13h4",key:"ytezjc"}],["path",{d:"M12 6v7",key:"1f6ttz"}],["path",{d:"M16 8V6H8v2",key:"x8j6u4"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
11
+ */const bs=s.createLucideIcon("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
12
12
  * @license lucide-react v0.453.0 - ISC
13
13
  *
14
14
  * This source code is licensed under the ISC license.
15
15
  * See the LICENSE file in the root directory of this source tree.
16
- */const ys=s.createLucideIcon("Box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/**
16
+ */const ys=s.createLucideIcon("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
17
17
  * @license lucide-react v0.453.0 - ISC
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Ss=s.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"}]]);/**
21
+ */const Ss=s.createLucideIcon("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
22
22
  * @license lucide-react v0.453.0 - ISC
23
23
  *
24
24
  * This source code is licensed under the ISC license.
25
25
  * See the LICENSE file in the root directory of this source tree.
26
- */const Cs=s.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"}]]);/**
26
+ */const Cs=s.createLucideIcon("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
27
+ * @license lucide-react v0.453.0 - ISC
28
+ *
29
+ * This source code is licensed under the ISC license.
30
+ * See the LICENSE file in the root directory of this source tree.
31
+ */const vs=s.createLucideIcon("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
32
+ * @license lucide-react v0.453.0 - ISC
33
+ *
34
+ * This source code is licensed under the ISC license.
35
+ * See the LICENSE file in the root directory of this source tree.
36
+ */const Ns=s.createLucideIcon("BookOpenText",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M16 12h2",key:"7q9ll5"}],["path",{d:"M16 8h2",key:"msurwy"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}],["path",{d:"M6 12h2",key:"32wvfc"}],["path",{d:"M6 8h2",key:"30oboj"}]]);/**
37
+ * @license lucide-react v0.453.0 - ISC
38
+ *
39
+ * This source code is licensed under the ISC license.
40
+ * See the LICENSE file in the root directory of this source tree.
41
+ */const ks=s.createLucideIcon("BookType",[["path",{d:"M10 13h4",key:"ytezjc"}],["path",{d:"M12 6v7",key:"1f6ttz"}],["path",{d:"M16 8V6H8v2",key:"x8j6u4"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
42
+ * @license lucide-react v0.453.0 - ISC
43
+ *
44
+ * This source code is licensed under the ISC license.
45
+ * See the LICENSE file in the root directory of this source tree.
46
+ */const ws=s.createLucideIcon("Box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/**
47
+ * @license lucide-react v0.453.0 - ISC
48
+ *
49
+ * This source code is licensed under the ISC license.
50
+ * See the LICENSE file in the root directory of this source tree.
51
+ */const Is=s.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"}]]);/**
52
+ * @license lucide-react v0.453.0 - ISC
53
+ *
54
+ * This source code is licensed under the ISC license.
55
+ * See the LICENSE file in the root directory of this source tree.
56
+ */const Es=s.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"}]]);/**
27
57
  * @license lucide-react v0.453.0 - ISC
28
58
  *
29
59
  * This source code is licensed under the ISC license.
@@ -38,7 +68,7 @@
38
68
  *
39
69
  * This source code is licensed under the ISC license.
40
70
  * See the LICENSE file in the root directory of this source tree.
41
- */const we=s.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
71
+ */const ke=s.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
42
72
  * @license lucide-react v0.453.0 - ISC
43
73
  *
44
74
  * This source code is licensed under the ISC license.
@@ -58,22 +88,22 @@
58
88
  *
59
89
  * This source code is licensed under the ISC license.
60
90
  * See the LICENSE file in the root directory of this source tree.
61
- */const vs=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
91
+ */const Ds=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
62
92
  * @license lucide-react v0.453.0 - ISC
63
93
  *
64
94
  * This source code is licensed under the ISC license.
65
95
  * See the LICENSE file in the root directory of this source tree.
66
- */const Ns=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
96
+ */const Ts=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
67
97
  * @license lucide-react v0.453.0 - ISC
68
98
  *
69
99
  * This source code is licensed under the ISC license.
70
100
  * See the LICENSE file in the root directory of this source tree.
71
- */const ws=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
101
+ */const As=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
72
102
  * @license lucide-react v0.453.0 - ISC
73
103
  *
74
104
  * This source code is licensed under the ISC license.
75
105
  * See the LICENSE file in the root directory of this source tree.
76
- */const ks=s.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
106
+ */const Ls=s.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
77
107
  * @license lucide-react v0.453.0 - ISC
78
108
  *
79
109
  * This source code is licensed under the ISC license.
@@ -83,67 +113,67 @@
83
113
  *
84
114
  * This source code is licensed under the ISC license.
85
115
  * See the LICENSE file in the root directory of this source tree.
86
- */const $e=s.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
116
+ */const Ue=s.createLucideIcon("EllipsisVertical",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]]);/**
87
117
  * @license lucide-react v0.453.0 - ISC
88
118
  *
89
119
  * This source code is licensed under the ISC license.
90
120
  * See the LICENSE file in the root directory of this source tree.
91
- */const Is=s.createLucideIcon("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);/**
121
+ */const Ms=s.createLucideIcon("Eraser",[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]]);/**
92
122
  * @license lucide-react v0.453.0 - ISC
93
123
  *
94
124
  * This source code is licensed under the ISC license.
95
125
  * See the LICENSE file in the root directory of this source tree.
96
- */const Es=s.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
126
+ */const zs=s.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
97
127
  * @license lucide-react v0.453.0 - ISC
98
128
  *
99
129
  * This source code is licensed under the ISC license.
100
130
  * See the LICENSE file in the root directory of this source tree.
101
- */const Ds=s.createLucideIcon("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
131
+ */const Os=s.createLucideIcon("FileJson2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"fq0c9t"}],["path",{d:"M8 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"4gibmv"}]]);/**
102
132
  * @license lucide-react v0.453.0 - ISC
103
133
  *
104
134
  * This source code is licensed under the ISC license.
105
135
  * See the LICENSE file in the root directory of this source tree.
106
- */const Ts=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
136
+ */const Fs=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
107
137
  * @license lucide-react v0.453.0 - ISC
108
138
  *
109
139
  * This source code is licensed under the ISC license.
110
140
  * See the LICENSE file in the root directory of this source tree.
111
- */const As=s.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
141
+ */const Rs=s.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
112
142
  * @license lucide-react v0.453.0 - ISC
113
143
  *
114
144
  * This source code is licensed under the ISC license.
115
145
  * See the LICENSE file in the root directory of this source tree.
116
- */const Ls=s.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
146
+ */const Vs=s.createLucideIcon("Hammer",[["path",{d:"m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9",key:"eefl8a"}],["path",{d:"m18 15 4-4",key:"16gjal"}],["path",{d:"m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",key:"b7pghm"}]]);/**
117
147
  * @license lucide-react v0.453.0 - ISC
118
148
  *
119
149
  * This source code is licensed under the ISC license.
120
150
  * See the LICENSE file in the root directory of this source tree.
121
- */const Ms=s.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
151
+ */const qs=s.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
122
152
  * @license lucide-react v0.453.0 - ISC
123
153
  *
124
154
  * This source code is licensed under the ISC license.
125
155
  * See the LICENSE file in the root directory of this source tree.
126
- */const Os=s.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
156
+ */const Bs=s.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
127
157
  * @license lucide-react v0.453.0 - ISC
128
158
  *
129
159
  * This source code is licensed under the ISC license.
130
160
  * See the LICENSE file in the root directory of this source tree.
131
- */const zs=s.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
161
+ */const Ps=s.createLucideIcon("LayoutList",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]]);/**
132
162
  * @license lucide-react v0.453.0 - ISC
133
163
  *
134
164
  * This source code is licensed under the ISC license.
135
165
  * See the LICENSE file in the root directory of this source tree.
136
- */const Fs=s.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
166
+ */const _s=s.createLucideIcon("ListEnd",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M10 18H3",key:"13769t"}],["path",{d:"M21 6v10a2 2 0 0 1-2 2h-5",key:"ilrcs8"}],["path",{d:"m16 16-2 2 2 2",key:"kkc6pm"}]]);/**
137
167
  * @license lucide-react v0.453.0 - ISC
138
168
  *
139
169
  * This source code is licensed under the ISC license.
140
170
  * See the LICENSE file in the root directory of this source tree.
141
- */const Rs=s.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
171
+ */const Hs=s.createLucideIcon("ListStart",[["path",{d:"M16 12H3",key:"1a2rj7"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"M10 6H3",key:"lf8lx7"}],["path",{d:"M21 18V8a2 2 0 0 0-2-2h-5",key:"1hghli"}],["path",{d:"m16 8-2-2 2-2",key:"160uvd"}]]);/**
142
172
  * @license lucide-react v0.453.0 - ISC
143
173
  *
144
174
  * This source code is licensed under the ISC license.
145
175
  * See the LICENSE file in the root directory of this source tree.
146
- */const Vs=s.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
176
+ */const Gs=s.createLucideIcon("ListX",[["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 6H3",key:"1wxfjs"}],["path",{d:"M16 18H3",key:"12xzn7"}],["path",{d:"m19 10-4 4",key:"1tz659"}],["path",{d:"m15 10 4 4",key:"1n7nei"}]]);/**
147
177
  * @license lucide-react v0.453.0 - ISC
148
178
  *
149
179
  * This source code is licensed under the ISC license.
@@ -153,37 +183,37 @@
153
183
  *
154
184
  * This source code is licensed under the ISC license.
155
185
  * See the LICENSE file in the root directory of this source tree.
156
- */const qs=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
186
+ */const Us=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
157
187
  * @license lucide-react v0.453.0 - ISC
158
188
  *
159
189
  * This source code is licensed under the ISC license.
160
190
  * See the LICENSE file in the root directory of this source tree.
161
- */const Ue=s.createLucideIcon("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
191
+ */const $e=s.createLucideIcon("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
162
192
  * @license lucide-react v0.453.0 - ISC
163
193
  *
164
194
  * This source code is licensed under the ISC license.
165
195
  * See the LICENSE file in the root directory of this source tree.
166
- */const Bs=s.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
196
+ */const $s=s.createLucideIcon("MessageSquareMore",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M16 10h.01",key:"1m94wz"}]]);/**
167
197
  * @license lucide-react v0.453.0 - ISC
168
198
  *
169
199
  * This source code is licensed under the ISC license.
170
200
  * See the LICENSE file in the root directory of this source tree.
171
- */const Ps=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
201
+ */const Qs=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
172
202
  * @license lucide-react v0.453.0 - ISC
173
203
  *
174
204
  * This source code is licensed under the ISC license.
175
205
  * See the LICENSE file in the root directory of this source tree.
176
- */const _s=s.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
206
+ */const Js=s.createLucideIcon("MoveVertical",[["path",{d:"M12 2v20",key:"t6zp3m"}],["path",{d:"m8 18 4 4 4-4",key:"bh5tu3"}],["path",{d:"m8 6 4-4 4 4",key:"ybng9g"}]]);/**
177
207
  * @license lucide-react v0.453.0 - ISC
178
208
  *
179
209
  * This source code is licensed under the ISC license.
180
210
  * See the LICENSE file in the root directory of this source tree.
181
- */const Hs=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
211
+ */const Ws=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
182
212
  * @license lucide-react v0.453.0 - ISC
183
213
  *
184
214
  * This source code is licensed under the ISC license.
185
215
  * See the LICENSE file in the root directory of this source tree.
186
- */const Gs=s.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0Z",key:"wtfw2c"}]]);/**
216
+ */const Ks=s.createLucideIcon("Plug2",[["path",{d:"M9 2v6",key:"17ngun"}],["path",{d:"M15 2v6",key:"s7yy2p"}],["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M5 8h14",key:"pcz4l3"}],["path",{d:"M6 11V8h12v3a6 6 0 1 1-12 0Z",key:"wtfw2c"}]]);/**
187
217
  * @license lucide-react v0.453.0 - ISC
188
218
  *
189
219
  * This source code is licensed under the ISC license.
@@ -198,17 +228,17 @@
198
228
  *
199
229
  * This source code is licensed under the ISC license.
200
230
  * See the LICENSE file in the root directory of this source tree.
201
- */const $s=s.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
231
+ */const Xs=s.createLucideIcon("Rows3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]]);/**
202
232
  * @license lucide-react v0.453.0 - ISC
203
233
  *
204
234
  * This source code is licensed under the ISC license.
205
235
  * See the LICENSE file in the root directory of this source tree.
206
- */const Us=s.createLucideIcon("Ruler",[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]]);/**
236
+ */const Zs=s.createLucideIcon("Ruler",[["path",{d:"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z",key:"icamh8"}],["path",{d:"m14.5 12.5 2-2",key:"inckbg"}],["path",{d:"m11.5 9.5 2-2",key:"fmmyf7"}],["path",{d:"m8.5 6.5 2-2",key:"vc6u1g"}],["path",{d:"m17.5 15.5 2-2",key:"wo5hmg"}]]);/**
207
237
  * @license lucide-react v0.453.0 - ISC
208
238
  *
209
239
  * This source code is licensed under the ISC license.
210
240
  * See the LICENSE file in the root directory of this source tree.
211
- */const Qs=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
241
+ */const Ys=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
212
242
  * @license lucide-react v0.453.0 - ISC
213
243
  *
214
244
  * This source code is licensed under the ISC license.
@@ -218,37 +248,37 @@
218
248
  *
219
249
  * This source code is licensed under the ISC license.
220
250
  * See the LICENSE file in the root directory of this source tree.
221
- */const Js=s.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
251
+ */const et=s.createLucideIcon("ShieldQuestion",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
222
252
  * @license lucide-react v0.453.0 - ISC
223
253
  *
224
254
  * This source code is licensed under the ISC license.
225
255
  * See the LICENSE file in the root directory of this source tree.
226
- */const Ws=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
256
+ */const st=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
227
257
  * @license lucide-react v0.453.0 - ISC
228
258
  *
229
259
  * This source code is licensed under the ISC license.
230
260
  * See the LICENSE file in the root directory of this source tree.
231
- */const Ks=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
261
+ */const tt=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
232
262
  * @license lucide-react v0.453.0 - ISC
233
263
  *
234
264
  * This source code is licensed under the ISC license.
235
265
  * See the LICENSE file in the root directory of this source tree.
236
- */const ke=s.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
266
+ */const we=s.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
237
267
  * @license lucide-react v0.453.0 - ISC
238
268
  *
239
269
  * This source code is licensed under the ISC license.
240
270
  * See the LICENSE file in the root directory of this source tree.
241
- */const Xs=s.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
271
+ */const at=s.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
242
272
  * @license lucide-react v0.453.0 - ISC
243
273
  *
244
274
  * This source code is licensed under the ISC license.
245
275
  * See the LICENSE file in the root directory of this source tree.
246
- */const Zs=s.createLucideIcon("TicketX",[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"m9.5 14.5 5-5",key:"qviqfa"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
276
+ */const nt=s.createLucideIcon("TicketX",[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"m9.5 14.5 5-5",key:"qviqfa"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
247
277
  * @license lucide-react v0.453.0 - ISC
248
278
  *
249
279
  * This source code is licensed under the ISC license.
250
280
  * See the LICENSE file in the root directory of this source tree.
251
- */const Ys=s.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
281
+ */const rt=s.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
252
282
  * @license lucide-react v0.453.0 - ISC
253
283
  *
254
284
  * This source code is licensed under the ISC license.
@@ -258,7 +288,7 @@
258
288
  *
259
289
  * This source code is licensed under the ISC license.
260
290
  * See the LICENSE file in the root directory of this source tree.
261
- */const Xe=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(c=>Ze(c))}})}})}}function Ze(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:et(t.customCfg),data:[]}}function et(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function st(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:i,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:i,shared:c,operation:"update"})}async function tt(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function at(){const[t,n]=C.useState(""),[a,r]=C.useState(!1),o=s.useDashboardStore(f=>f.lenses),{setLenses:i,setSelectedLensId:c}=s.useDashboardActions(),[l,d]=C.useState(!1),[p,u]=C.useState(!1),g=s.useDashboardStore(f=>f.dashboard),x=s.useDashboardStore(f=>f.filterValues),{authToken:h}=s.useSemaphorContext();async function j(){d(!0);const f=Ie(g),S=await st(t,f,x,h==null?void 0:h.accessToken);S&&(i([...o||[],S]),c(S.id),u(!1)),d(!1)}return e.jsxs(s.Dialog,{open:p,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:f=>{n(f.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:j,disabled:l,children:l?"Creating...":"Add"})})]})]})}function nt(){const[t,n]=C.useState(!1),a=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function l(u){i(u)}async function d(u){if(await tt(u,c==null?void 0:c.accessToken)){const x=a==null?void 0:a.filter(h=>h.id!==u);o(x||[]),i("original")}}async function p(u){const g=a==null?void 0:a.map(j=>j.id===u.id?{...j,isDefault:!u.isDefault}:{...j,isDefault:!1});o(g||[]);const x={...u,isDefault:!u.isDefault};await ve(x,c==null?void 0:c.accessToken);const h=a==null?void 0:a.find(j=>j.isDefault);if(h&&h.id!==u.id){const j={...h,isDefault:!1};await ve(j,c==null?void 0:c.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(Ts,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:l,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Os,{onClick:g=>{g.preventDefault(),p(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:g=>{g.preventDefault(),d(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}async function Ye(){var h;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(h=s.useDashboardStore.getState().dashboard)==null?void 0:h.title,o=s.useDashboardStore.getState().isDownloadingPdf,i=s.useDashboardStore.getState().selectedSheetId;if(o)return;const c=new URLSearchParams;c.set("token",(t==null?void 0:t.accessToken)||""),c.set("theme",n||"light"),c.set("filterValues",JSON.stringify(a)),c.set("selectedSheetId",i||"");const l=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(l,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,g=document.createElement("a");g.href=u;const x=`${r}-${new Date().toISOString()}.pdf`;g.download=x,g.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function rt({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ye()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(pe,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function ot(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(m=>m.theme);const n=s.useDashboardStore(m=>m.lenses),a=s.useDashboardStore(m=>m.selectedLensId),r=n==null?void 0:n.find(m=>m.id===a),o=s.useDashboardStore(m=>m.dashboard);s.useDashboardStore(m=>m.selectedSheetId);const i=s.useDashboardStore(m=>m.isDashboardEditing),c=s.useEditorStore(m=>m.selectedConnectionId),[l,d]=C.useState(!1),p=s.useDashboardStore(m=>m.filterValues),u=s.useDashboardStore(m=>m.isVisualEditing),g=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const x=s.useDashboardStore(m=>m.onSaveFunction),h=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:j,setSelectedFrameId:f}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:S,setIsDashboardEditing:b,setShowDashboardJSON:I}=s.useDashboardStore(m=>m.actions),v=S(),{tenantId:w,endUserId:M}=C.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),F=C.useMemo(()=>w||M,[w,M]),q=()=>{if(!i||!v)return;const m={connectionId:c,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},T={id:s.v4(),cards:[m],activeCardId:m.id};j(v.id,T),f(T.id)},V=()=>{b(!0)};async function P(){if(d(!0),!a||!r)return;const m=Ie(o),T=JSON.stringify(m),_={...r,template:T,filterValues:p};await ve(_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),x==null||x(m),d(!1)}return u?null:e.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:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:s.invalidateToken,children:e.jsx(Zs,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(rt,{}),i&&!u&&F&&e.jsx(at,{}),!u&&F&&e.jsx(nt,{}),i&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:q,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:V,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!u&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{b(!1),I(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!u&&F&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:l,onClick:P,size:"sm",children:e.jsx(Qs,{className:"h-4 w-4",strokeWidth:1.5})}),!g&&!u&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>h(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&i&&!1,!u&&!1]})]})}function it({name:t,items:n,value:a,onChange:r,isLoading:o,isError:i,refetch:c,className:l,showNone:d=!1}){const p=de.useRef(null),[u,g]=de.useState(!1),[x,h]=de.useState("100%"),j=d?[...n||[],{id:"none",name:"None"}]:n;de.useLayoutEffect(()=>{p.current&&h(p.current.offsetWidth)},[]);function f(){var b;return o?"Loading...":i?"Error":a?(b=n==null?void 0:n.find(I=>I.id===a))==null?void 0:b.name:`Select ${t}`}function S(b,I){r(I),g(!1)}return e.jsxs(s.Popover,{open:u,onOpenChange:g,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:p,variant:"outline",role:"combobox","aria-expanded":u,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",l),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:f()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:x},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx(Je,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:j==null?void 0:j.map(b=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:b.name,onSelect:I=>S(I,b.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===b.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:b.name,children:b.name})]})},b.id))})]})]})})]})}function ce({title:t,items:n,value:a,isLoading:r,isError:o,refetch:i,connectionTooltip:c,onChange:l,showNone:d=!1,className:p,showIcon:u=!0,disabled:g=!1,type:x="select"}){const h=r?"Loading...":o?"Error":a;function j(){if(t==="Connection")return e.jsx(Gs,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(ks,{className:"size-4"});if(t==="Schema")return e.jsx(Hs,{className:"size-4"});if(t==="Table")return e.jsx(ke,{className:"size-4"});if(t==="Model")return e.jsx(ys,{className:"size-4"})}function f(){return e.jsxs(s.Select,{disabled:g,value:h,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",p),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(Je,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:i})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((b,I)=>e.jsx(s.SelectItem,{value:b.id,children:b.name},I))]}),(r||o)&&e.jsx(s.SelectItem,{value:h,children:h})]})})]})}function S(){return e.jsx(it,{items:n,value:h,onChange:l||(()=>{}),isLoading:r,isError:o,refetch:i,name:t,showNone:d})}return e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"shrink-0",children:c?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:j()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:c})]}):j()}),x==="combobox"?S():f()]})}function lt({column:t}){const[n,a]=C.useState(!1),r=s.useEditorStore(j=>j.selectedTableName),o=s.useEditorStore(j=>j.selectedSchemaName),i=s.useEditorStore(j=>j.selectedDatamodelId),c=s.useEditorStore(j=>j.sqlGen),{modelItems:l,connectionType:d}=ae(),p=s.useEditorStore(j=>j.actions.setSqlGen),u=s.useEditorStore(j=>j.actions.setCardSql),g=s.useEditorStore(j=>j.actions.setRunSql);function x(j,f){var v;const S=s.createSqlGenConfig(j,c,f),b=(v=l==null?void 0:l.find(w=>w.id===i))==null?void 0:v.name;p(S);const I=s.getSql(S,s.fmt(o||""),s.fmt(r),b,d);I&&(u(I),g(!0)),a(!1)}function h(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>x(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>x(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>x(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>x(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>x(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx($e,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:h()})]})}function es({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(Xe,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(Ms,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(Ys,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Ss,{className:"size-3"}):e.jsx(Js,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function ct({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),i=s.useEditorStore(m=>m.selectedConnectionId),c=s.useEditorStore(m=>m.selectedDatabaseName),l=s.useEditorStore(m=>m.selectedSchemaName),d=s.useEditorStore(m=>m.selectedTableName),p=s.useEditorStore(m=>m.selectedDatamodelId),u=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:g,removeFromAIScope:x}=s.useDashboardActions(),{setAIScopeTables:h}=s.useDashboardStore(m=>m.actions),j=s.useEditorStore(m=>m.actions.setRunSql),f=s.useEditorStore(m=>m.actions.setSqlGen),S=s.useEditorStore(m=>m.actions.setIsShowingVisual),b=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:I,modelItems:v,selectedDatamodelName:w}=ae();function M(m){var B;const T=s.createSqlGenConfig(m,o);f(T);const _=(B=v==null?void 0:v.find(y=>y.id===p))==null?void 0:B.name,O=s.getSql(T,s.fmt(t),s.fmt(n),_,I);O&&(b(O),j(!0))}function F(){return(u==null?void 0:u.find(m=>m.connectionId===i&&(m.tableName===d||m.datamodelName===w)))!==void 0}function q(m){m===!0&&(d||w)&&i?(g({connectionId:i,connectionType:I==="S3"||I==="API"?"DuckDb":I,databaseName:c||"",schemaName:l||"",tableName:d||"",datamodelName:s.resolveDatamodelName(w),datamodelId:p||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(x({connectionId:i||"",connectionType:I||"",tableName:d||"",datamodelName:s.resolveDatamodelName(w),datamodelId:p||"",databaseName:c||"",schemaName:l||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function V(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:w,connectionType:I});S(!1);const T=I==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;b(T),j(!0)}function P(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:w,connectionType:I});b(`SELECT COUNT(*) as count FROM ${m}`),j(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${F()?"Remove from":"Add to"} Assistant Scope`,pressed:F(),onPressedChange:q,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":F(),"text-muted-foreground":!F()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(qs,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:P,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Ws,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(m=>e.jsxs("div",{onClick:()=>M(m),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(m,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(es,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:T=>T.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(lt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ae(t,n){var De,Te,Ae,Le,Me,Oe;let a=C.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),i=s.useEditorStore(N=>N.selectedDatamodelId),c=s.useEditorStore(N=>N.selectedDatabaseName),l=s.useEditorStore(N=>N.selectedSchemaName),d=s.useEditorStore(N=>N.selectedTableName),p=s.useEditorStore(N=>N.actions.setCurrentColumns),u=s.useEditorStore(N=>N.actions.setSelectedConnectionId),g=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),x=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),h=s.useEditorStore(N=>N.actions.setSelectedSchemaName),j=s.useEditorStore(N=>N.actions.setSelectedTableName);s.useEditorStore(N=>N.actions.setCardSql);function f(N){return o&&c&&l&&c!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function S(N){return!!(o&&c&&c!=="NA"&&l&&d||o&&(N==="S3"||N==="API")||i&&i)}function b(N){return o&&N?!(N==="API"||N==="S3"):!1}const{refetch:I,data:v,isLoading:w,isError:M}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:F,data:q,isLoading:V,isError:P}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),m=v==null?void 0:v.connections.find(N=>N.id===o),T=m==null?void 0:m.type,_=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:O,isLoading:B,isFetching:y,isError:L,refetch:E}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:b(T)}),{data:z,isLoading:G,isFetching:U,isError:J,refetch:R}=s.useQuery({queryKey:["schemas",o,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c}),enabled:!!o&&!!c&&!_&&c!=="NA"}),{data:A,isLoading:Q,isFetching:k,isError:H,refetch:K}=s.useQuery({queryKey:["tables",o,c,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:c,schema_name:l}),enabled:f(T)}),{data:W,isLoading:te,isFetching:ee,isError:$,refetch:X}=s.useQuery({queryKey:["columns",o,c,i,l,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:c,schema_name:l,table_name:d}),enabled:S(T)});C.useEffect(()=>{p(a)},[W,p,a]),C.useEffect(()=>{(T==="S3"||T==="API")&&(x(""),h(""),g(""),T==="API"&&j("api"))},[T,j,x,h,g]);const le=(m==null?void 0:m.type)==="API"?(De=m==null?void 0:m.type)==null?void 0:De.toLowerCase():d||"",ne=_?"":l||"";function re(N){h(N),j("")}function D(N){x(N==="none"?"":N),h(""),j(""),N!=="none"&&N!==""&&g("")}function Z(N){u(N)}function oe(N){g(N==="none"?"":N),N!=="none"&&N!==""&&x("")}O&&((Te=O==null?void 0:O.databases)==null?void 0:Te.length)>0,z&&((Ae=z==null?void 0:z.schemas)==null?void 0:Ae.length)>0,W&&((Le=W==null?void 0:W.columns)==null?void 0:Le.length)>0&&(a=W.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),L&&(a=[]),($||M)&&(a=[]);const Y=v==null?void 0:v.connections.map(N=>({id:N.id,name:N.name,type:N.type})),me=(Me=q==null?void 0:q.datamodels)==null?void 0:Me.map(N=>({id:N.id,name:N.name})),Se=O==null?void 0:O.databases.map(N=>({id:N.database_name,name:N.database_name})),fe=z==null?void 0:z.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),Ce=A==null?void 0:A.tables.map(N=>({id:N.table_name,name:N.table_name})),fs=(Oe=q==null?void 0:q.datamodels.find(N=>N.id===i))==null?void 0:Oe.name;return{connectionItems:Y,isConnectionsLoading:w,isConnectionsError:M,modelItems:me,selectedDatamodelId:i,selectedDatamodelName:fs,isModelsLoading:V,isModelsError:P,databaseItems:Se,isDatabasesLoadingOrFetching:B||y,isDatabaseError:L,schemaItems:fe,isSchemaLoadingOrFetching:G||U,isSchemaError:J,tableItems:Ce,isTableLoadingOrFetching:Q||k,isTableError:H,columns:a,isColumnsLoadingOrFetching:te||ee,isColumnsError:$,isNonDbConnection:_,connectionType:T,tableName:le,schemaName:ne,refetchConnections:I,refetchModels:F,refetchDatabases:E,refetchSchemas:R,refetchTables:K,refetchColumns:X,handleConnectionChange:Z,handleDatamodelChange:oe,handleDatabaseChange:D,handleSchemaChange:re}}function ss({ColumnsComponent:t}){var ee;const n=s.useEditorStore($=>$.selectedConnectionId),a=s.useEditorStore($=>$.selectedDatamodelId),r=s.useEditorStore($=>$.selectedDatabaseName),o=s.useEditorStore($=>$.selectedSchemaName),i=s.useEditorStore($=>$.selectedTableName),c=s.useEditorStore($=>$.actions.setSelectedTableName),{connectionItems:l,modelItems:d,schemaItems:p,databaseItems:u,tableItems:g,columns:x,isConnectionsLoading:h,isModelsLoading:j,isConnectionsError:f,isModelsError:S,isDatabasesLoadingOrFetching:b,isDatabaseError:I,isSchemaLoadingOrFetching:v,isSchemaError:w,isColumnsError:M,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:q,isTableError:V,connectionType:P,isNonDbConnection:m,refetchDatabases:T,refetchModels:_,refetchSchemas:O,refetchTables:B,refetchColumns:y,refetchConnections:L,handleConnectionChange:E,handleDatabaseChange:z,handleSchemaChange:G,handleDatamodelChange:U,tableName:J,schemaName:R}=ae();function A(){return t?t(R,J,x):e.jsx(ct,{schemaName:R,tableName:J,columns:x,status:F?"Loading...":M?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||P==="S3"||P==="API")return null;if(!a||a==="none")return e.jsx(ce,{refetch:T,showNone:!0,onChange:z,isError:I,isLoading:b,items:u,value:r||"",title:"Database",type:"combobox"})}function H(){if(n&&!m&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function K(){if(!n||P==="S3"||P==="API")return null;if(!r||r==="none")return e.jsx(ce,{refetch:_,showNone:!0,onChange:U,isError:S,isLoading:j,items:d,value:a||"",title:"Model",type:"combobox"})}function W(){return!n||P==="S3"||P==="API"||!r||r==="none"?null:e.jsx(ce,{refetch:O,onChange:G,isError:w,isLoading:v,items:p,value:o||"",title:"Schema",type:"combobox"})}function te(){function $(){let X=!1;return P==="API"?(X=!1,X):((P==="S3"||n&&r&&r!=="none"&&o)&&(X=!0),X)}return $()?e.jsx(ce,{refetch:B,onChange:c,isError:V,items:g,isLoading:q,value:i||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:"flex h-full min-w-[300px] flex-col justify-between rounded-none border-r-[1px]",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ce,{refetch:L,items:l,title:"Connection",value:n||"",onChange:E,isLoading:h,isError:f,type:"combobox",connectionTooltip:((ee=l==null?void 0:l.find($=>$.id===n))==null?void 0:ee.type)||""}),k(),H(),K(),W(),te()]}),A(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:Q,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx(Bs,{className:"mr-2 size-4"}),"Help"]})})]})}function dt(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const c=t.substring(0,n),l=t.substring(n);return`${c} {{ filters | where }} AND ${l.substring(6)}`}else if(a!==-1){const c=t.substring(0,a),l=t.substring(a);return`${c} {{ filters | where }} ${l}`}else{const c=t.substring(0,i),l=t.substring(i);return console.log("beforeClause",c),console.log("afterClause",l),l?`${c} {{ filters | where }} ${l}`:`${c.replace(/;$/,"")} {{ filters | where }}`}}function ut({sql:t,error:n,onClick:a}){return!t&&!n?null:e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(vs,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[n&&n,t&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("span",{className:"font-mono",children:t})]})]}),n&&e.jsxs(s.Button,{onClick:a,size:"sm",variant:"secondary",children:[e.jsx(Ls,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var ts={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},ze=C.createContext&&C.createContext(ts),ht=["attr","size","title"];function mt(t,n){if(t==null)return{};var a=xt(t,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function xt(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function be(){return be=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},be.apply(this,arguments)}function Fe(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ye(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Fe(Object(a),!0).forEach(function(r){pt(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Fe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function pt(t,n,a){return n=ft(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function ft(t){var n=gt(t,"string");return typeof n=="symbol"?n:n+""}function gt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function as(t){return t&&t.map((n,a)=>C.createElement(n.tag,ye({key:a},n.attr),as(n.child)))}function ue(t){return n=>C.createElement(jt,be({attr:ye({},t.attr)},n),as(t.child))}function jt(t){var n=a=>{var{attr:r,size:o,title:i}=t,c=mt(t,ht),l=o||a.size||"1em",d;return a.className&&(d=a.className),t.className&&(d=(d?d+" ":"")+t.className),C.createElement("svg",be({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,c,{className:d,style:ye(ye({color:t.color||a.color},a.style),t.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),i&&C.createElement("title",null,i),t.children)};return ze!==void 0?C.createElement(ze.Consumer,null,a=>n(a)):n(ts)}function bt(t){return ue({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function ns(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(f=>f.theme),r=s.useEditorStore(f=>f.frame),o=s.useEditorStore(f=>f.card),i=s.useEditorStore(f=>f.activeTabCardId),c=s.Le(),{refetch:l}=s.useDashboardCardQuery(o),{updateCardTab:d,setRunSql:p}=s.useEditorActions(),u=C.useRef(),g=C.useRef({}),x=r.cards.find(f=>f.id===i),h=C.useCallback(()=>{let f="";return t==="python"&&(f=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(f=(x==null?void 0:x.sql)||""),f},[t,x]);C.useEffect(()=>{if(i&&o.id&&o.id!==i){if(u.current&&c){const f=u.current.getModel();f&&(g.current[o.id]=f);let S=g.current[i];if(!S){const b=h();S=c.editor.createModel(b,t),g.current[i]=S}u.current.setModel(S)}d(i,o),p(!0)}},[i,o,d,c,p,t,h]),C.useEffect(()=>{if(!c)return;const f=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=a==="system"?f:a;c.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[n,a,c]),C.useEffect(()=>{const f=u.current;f&&c&&o&&f.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return l(),!1})},[c,l,o]);function j(f,S){if(u.current=f,!g.current[o.id]){const b=f.getModel(),I=h();g.current[o.id]=b||(S==null?void 0:S.editor.createModel(I,t))||f.getModel()}f.setModel(g.current[o.id])}return{handleEditorDidMount:j}}function yt(){const t=s.useEditorStore(c=>c.card.sql),n=s.useEditorStore(c=>c.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=ns("sql");function i(c){a(c),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function St(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=ns("python");function r(o){n(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function Ct({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function rs(t){const[n,a]=C.useState(""),[r,o]=C.useState(null),{authToken:i}=s.useSemaphorContext(),c=s.useEditorStore(k=>{var H;return(H=k==null?void 0:k.card)==null?void 0:H.sql}),l=s.useEditorStore(k=>{var H;return(H=k==null?void 0:k.card)==null?void 0:H.python}),d=s.useEditorStore(k=>k.actions.setCardSql),p=s.useEditorStore(k=>k.actions.setRunSql),u=s.useEditorStore(k=>k.actions.switchCardType),g=s.useEditorStore(k=>k.currentAssitantScope)||[],x=s.useEditorStore(k=>k.userInputForAI),h=s.useEditorStore(k=>k.triggerAIRun),j=s.useEditorStore(k=>k.selectedDatabaseName),f=s.useEditorStore(k=>k.selectedTableName),S=s.useEditorStore(k=>k.selectedConnectionId),b=s.useEditorStore(k=>k.selectedSchemaName),I=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:v,setCurrentAssitantScope:w}=s.useEditorActions(),{selectedDatamodelName:M,connectionType:F,selectedDatamodelId:q}=ae(),{messages:V,setMessages:P,reload:m,append:T,input:_,setInput:O,status:B,handleInputChange:y,handleSubmit:L,stop:E}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${i==null?void 0:i.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:z,onFinish(k,H){G(H.usage),a(""),H.finishReason==="stop"&&a("")}});C.useEffect(()=>{h&&x&&(y({target:{value:x}}),setTimeout(()=>{L(),v(!1)},100))},[h,L,x,v,y]);async function z({toolCall:k}){if(k.toolName==="createChart"){const H=k.args.sql,K=k.args.chartType;return u(K),d(H),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")a("Getting table columns...");else{if(k.toolName==="getUserSql")return c?{status:"success",sql:c,python:l||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return a("Getting table scope..."),A(),{status:"success",tables:g};a("Analyzing...")}}function G(k){o(H=>H?{promptTokens:H.promptTokens+k.promptTokens,completionTokens:H.completionTokens+k.completionTokens,totalTokens:H.totalTokens+k.totalTokens}:k)}function U(k){const H=s.removeFromScopeArray(g,k);J(H)}function J(k){const H=s.sanitizeAIScope(k);w(H),P(K=>[...K,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(H)}`}])}function R(){const k={databaseName:j||"",schemaName:b||"",tableName:f||"",datamodelId:q||"",datamodelName:s.resolveDatamodelName(M),connectionId:S||"",connectionType:F||""},H=s.dedup([...g,k]);J(H)}function A(){const k={databaseName:j||"",schemaName:b||"",tableName:f||"",datamodelName:s.resolveDatamodelName(M),connectionId:S||"",connectionType:F||"",datamodelId:q||""};if(!s.isInAiScopeArray([...I||[],...g],k)||g.length===0){const K=s.dedup([...I||[],...g,k]).filter(W=>W.connectionId===k.connectionId);J(K)}}const Q=!["ready","error"].includes(B);return{messages:V,setMessages:P,reload:m,append:T,input:_,setInput:O,isLoading:Q,handleSetAIScope:A,handleAddCurrentTableToScope:R,removeFromCurrentSelections:U,currentAssitantScope:g,setCurrentAssitantScope:w,handleInputChange:y,handleSubmit:L,stop:E,chatStatus:B,toolStatus:n,llmUsage:r,onFinish:t}}function vt(){var re;const[t,n]=C.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=C.useState(!1),[i,c]=C.useState(!1),l=s.useEditorStore(D=>D.frame),d=s.useEditorStore(D=>D.card),p=s.useEditorStore(D=>D.isShowingVisual),u=s.useEditorStore(D=>D.selectedConnectionId),g=s.useEditorStore(D=>D.selectedDatabaseName),x=s.useEditorStore(D=>D.selectedDatamodelId),h=s.useEditorStore(D=>D.selectedSchemaName),j=s.useEditorStore(D=>D.showAIDialog),f=s.useEditorStore(D=>D.selectedTableName),S=s.useEditorStore(D=>{var Z;return(Z=D==null?void 0:D.card)==null?void 0:Z.sql}),{sheetFilterValues:b}=s.useSheetFilterValues(),{setCardCustomCfg:I,setQueryResultColumns:v,setCardSql:w,setPythonStdOut:M,setCardPreferences:F,setCardType:q,setCardPython:V,runAssistant:P,setShowAIDialog:m}=s.useEditorActions(),T=s.useEditorStore(D=>D.onSave),_=s.useEditorStore(D=>D.onClose),O=s.useEditorStore(D=>D.actions.setSqlGen),B=s.useEditorStore(D=>D.runSql),y=s.useEditorStore(D=>D.actions.setRunSql),L=s.useEditorStore(D=>D.actions.setCardCfg),E=s.useEditorStore(D=>D.actions.setIsSqlRunning),{data:z,isLoading:G,isFetching:U,isSuccess:J,isError:R,error:A,queryKey:Q,refetch:k}=s.useDashboardCardQuery(d),{handleSetAIScope:H}=rs();C.useEffect(()=>{if(z&&(z.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),M((z==null?void 0:z.output)||""),z.records.length>0)){const{dimensionKeys:D}=s.getKeys(z.records);v(D)}},[z,v,M]),C.useEffect(()=>{(G||U)&&E(!0),(R||J)&&E(!1),R&&(v([]),M(""))},[G,U,z,M,R,J,E,v,A]),C.useEffect(()=>{B&&(a.getQueryData(Q)||k(),y(!1))},[B,k,y,Q,a]);function K(){const D=a.getQueryData(Q);t.queryData||n({queryKey:Q,queryData:D}),a.setQueryData(Q,null),a.removeQueries({queryKey:Q,exact:!0}),w(""),O({}),V(""),L(void 0),I(""),F({}),q("bar")}function W(D,Z){if(D.length===0)return"";if(Z){const oe=D.find(Y=>Y.id===Z);if(oe){const Y=oe.tabTitle;if(Y=="All__Header")return D[0].id;if(Y&&Y.endsWith("__Header")){const Se=Y.split("__")[0],fe=D.find(Ce=>Ce.tabTitle===Se);return fe?fe.id:D[0].id}return Z}}return D[0].id}function te(){let D=S;S&&!S.includes("{{")&&(D=dt(S),w(D));const Z={...d,lastSelectedSchema:h,lastSelectedDatamodelId:x,lastSelectedDatabase:g,lastSelectedTable:f,connectionId:u,type:p?d.type:"table",sql:D,customCfg:p?d.customCfg:null},oe=l.cards.map(me=>me.id===d.id?Z:me),Y={...l,cards:oe,activeCardId:W(oe,l.activeCardId)};T==null||T(Y)}function ee(){const{queryKey:D,queryData:Z}=t;D&&Z&&a.setQueryData(D,Z),O({}),_==null||_()}async function $(){const D=`Can you help me debug this query in the current table scope?
291
+ */const Xe=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ie(t){var n;return{...t,sheets:(n=t==null?void 0:t.sheets)==null?void 0:n.map(a=>{var r;return{...a,frames:(r=a.frames)==null?void 0:r.map(o=>{var i;return{...o,cards:(i=o.cards)==null?void 0:i.map(l=>Ze(l))}})}})}}function Ze(t){var n,a,r,o;return{...t,cfg:{...t.cfg,data:{...(n=t.cfg)==null?void 0:n.data,labels:[],datasets:(o=(r=(a=t.cfg)==null?void 0:a.data)==null?void 0:r.datasets)==null?void 0:o.map(i=>({...i,data:[]}))}},customCfg:ot(t.customCfg),data:[]}}function ot(t){var n,a;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(a=(n=t==null?void 0:t.data)==null?void 0:n.datasets)==null?void 0:a.map(r=>({...r,data:[]}))}}:null}async function it(t,n,a,r){if(!r)return null;const o=JSON.stringify(n);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:o,filterValues:a,operation:"create"})}async function ve(t,n){if(!n)return null;const{id:a,template:r,filterValues:o,isDefault:i,shared:l}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{lensId:a,template:r,filterValues:o,isDefault:i,shared:l,operation:"update"})}async function lt(t,n){return n?await s.postRequest("https://semaphor.cloud/api/v1/lens",n,{operation:"delete",lensId:t}):null}function ct(){const[t,n]=C.useState(""),[a,r]=C.useState(!1),o=s.useDashboardStore(j=>j.lenses),{setLenses:i,setSelectedLensId:l}=s.useDashboardActions(),[c,d]=C.useState(!1),[p,u]=C.useState(!1),f=s.useDashboardStore(j=>j.dashboard),x=s.useDashboardStore(j=>j.filterValues),{authToken:h}=s.useSemaphorContext();async function g(){d(!0);const j=Ie(f),y=await it(t,j,x,h==null?void 0:h.accessToken);y&&(i([...o||[],y]),l(y.id),u(!1)),d(!1)}return e.jsxs(s.Dialog,{open:p,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:j=>{n(j.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:c,children:c?"Creating...":"Add"})})]})]})}function dt(){const[t,n]=C.useState(!1),a=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:o,setSelectedLensId:i}=s.useDashboardActions(),{authToken:l}=s.useSemaphorContext();async function c(u){i(u)}async function d(u){if(await lt(u,l==null?void 0:l.accessToken)){const x=a==null?void 0:a.filter(h=>h.id!==u);o(x||[]),i("original")}}async function p(u){const f=a==null?void 0:a.map(g=>g.id===u.id?{...g,isDefault:!u.isDefault}:{...g,isDefault:!1});o(f||[]);const x={...u,isDefault:!u.isDefault};await ve(x,l==null?void 0:l.accessToken);const h=a==null?void 0:a.find(g=>g.isDefault);if(h&&h.id!==u.id){const g={...h,isDefault:!1};await ve(g,l==null?void 0:l.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:n,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",children:e.jsx(Fs,{className:"h-4 w-4",strokeWidth:1.5})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Bs,{onClick:f=>{f.preventDefault(),p(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:f=>{f.preventDefault(),d(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}async function Ye(){var h;const t=s.useDashboardStore.getState().authToken,n=s.useDashboardStore.getState().theme,a=s.useDashboardStore.getState().filterValues,r=(h=s.useDashboardStore.getState().dashboard)==null?void 0:h.title,o=s.useDashboardStore.getState().isDownloadingPdf,i=s.useDashboardStore.getState().selectedSheetId;if(o)return;const l=new URLSearchParams;l.set("token",(t==null?void 0:t.accessToken)||""),l.set("theme",n||"light"),l.set("filterValues",JSON.stringify(a)),l.set("selectedSheetId",i||"");const c=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(c,{method:"GET",headers:{Authorization:`Bearer ${t==null?void 0:t.accessToken}`}})).json()).url,f=document.createElement("a");f.href=u;const x=`${r}-${new Date().toISOString()}.pdf`;f.download=x,f.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function ut({iconClassName:t}){const{authToken:n}=s.useSemaphorContext();s.useDashboardStore(o=>{var i;return(i=o.dashboard)==null?void 0:i.title}),s.useDashboardStore(o=>o.theme),s.useDashboardStore(o=>o.filterValues);const a=s.useDashboardStore(o=>o.isDownloadingPdf);async function r(){await Ye()}return e.jsx(s.Button,{variant:"link",className:"group h-7 p-2",size:"sm",onClick:r,children:a?e.jsx(pe,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-3.5",t),strokeWidth:1.5})})}function ht(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(m=>m.theme);const n=s.useDashboardStore(m=>m.lenses),a=s.useDashboardStore(m=>m.selectedLensId),r=n==null?void 0:n.find(m=>m.id===a),o=s.useDashboardStore(m=>m.dashboard);s.useDashboardStore(m=>m.selectedSheetId);const i=s.useDashboardStore(m=>m.isDashboardEditing),l=s.useEditorStore(m=>m.selectedConnectionId),[c,d]=C.useState(!1),p=s.useDashboardStore(m=>m.filterValues),u=s.useDashboardStore(m=>m.isVisualEditing),f=s.useDashboardStore(m=>m.showFilters);s.useDashboardStore(m=>m.showDashboardJSON);const x=s.useDashboardStore(m=>m.onSaveFunction),h=s.useDashboardStore(m=>m.actions.setShowFilters),{addFrame:g,setSelectedFrameId:j}=s.useDashboardStore(m=>m.actions),{getSelectedSheet:y,setIsDashboardEditing:b,setShowDashboardJSON:w}=s.useDashboardStore(m=>m.actions),v=y(),{tenantId:D,endUserId:T}=C.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),F=C.useMemo(()=>D||T,[D,T]),q=()=>{if(!i||!v)return;const m={connectionId:l,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"select COUNT(*) from YOUR_TABLE",data:[]},A={id:s.v4(),cards:[m],activeCardId:m.id};g(v.id,A),j(A.id)},V=()=>{b(!0)};async function P(){if(d(!0),!a||!r)return;const m=Ie(o),A=JSON.stringify(m),_={...r,template:A,filterValues:p};await ve(_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),x==null||x(m),d(!1)}return u?null:e.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:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:s.invalidateToken,children:e.jsx(nt,{className:"h-4 w-4",strokeWidth:1.5})}),e.jsx(ut,{}),i&&!u&&F&&e.jsx(ct,{}),!u&&F&&e.jsx(dt,{}),i&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!i,onClick:q,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4",strokeWidth:1.5}),"Frame"]}),!i&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:V,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!u&&e.jsx(s.Button,{variant:"ghost",role:"close",className:"h-7 p-2",onClick:()=>{b(!1),w(!1)},size:"sm",children:e.jsx(s.Cross2Icon,{className:"h-4 w-4",strokeWidth:1.5})}),i&&!u&&F&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:c,onClick:P,size:"sm",children:e.jsx(Ys,{className:"h-4 w-4",strokeWidth:1.5})}),!f&&!u&&i&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>h(!0),size:"sm",children:e.jsx(s.Filter,{className:"h-4 w-4",strokeWidth:1.5})}),!u&&i&&!1,!u&&!1]})]})}function mt({name:t,items:n,value:a,onChange:r,isLoading:o,isError:i,refetch:l,className:c,showNone:d=!1}){const p=de.useRef(null),[u,f]=de.useState(!1),[x,h]=de.useState("100%"),g=d?[...n||[],{id:"none",name:"None"}]:n;de.useLayoutEffect(()=>{p.current&&h(p.current.offsetWidth)},[]);function j(){var b;return o?"Loading...":i?"Error":a?(b=n==null?void 0:n.find(w=>w.id===a))==null?void 0:b.name:`Select ${t}`}function y(b,w){r(w),f(!1)}return e.jsxs(s.Popover,{open:u,onOpenChange:f,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:p,variant:"outline",role:"combobox","aria-expanded":u,className:s.cn("flex h-9 w-full max-w-[226px] justify-between",c),children:[e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap",children:j()}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:x},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:l,children:e.jsx(Je,{className:s.cn("size-3.5 opacity-50",o&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:g==null?void 0:g.map(b=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:b.name,onSelect:w=>y(w,b.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",a===b.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:b.name,children:b.name})]})},b.id))})]})]})})]})}function ce({title:t,items:n,value:a,isLoading:r,isError:o,refetch:i,connectionTooltip:l,onChange:c,showNone:d=!1,className:p,showIcon:u=!0,disabled:f=!1,type:x="select"}){const h=r?"Loading...":o?"Error":a;function g(){if(t==="Connection")return e.jsx(Ks,{className:"size-4 rotate-90"});if(t==="Database")return e.jsx(Ls,{className:"size-4"});if(t==="Schema")return e.jsx(Ws,{className:"size-4"});if(t==="Table")return e.jsx(we,{className:"size-4"});if(t==="Model")return e.jsx(ws,{className:"size-4"})}function j(){return e.jsxs(s.Select,{disabled:f,value:h,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",p),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":o?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(Je,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:i})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),n&&n.map((b,w)=>e.jsx(s.SelectItem,{value:b.id,children:b.name},w))]}),(r||o)&&e.jsx(s.SelectItem,{value:h,children:h})]})})]})}function y(){return e.jsx(mt,{items:n,value:h,onChange:c||(()=>{}),isLoading:r,isError:o,refetch:i,name:t,showNone:d})}return e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("div",{className:"shrink-0",children:l?e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:g()}),e.jsx(s.TooltipContent,{className:"text-xs",align:"start",children:l})]}):g()}),x==="combobox"?y():j()]})}function xt({column:t}){const[n,a]=C.useState(!1),r=s.useEditorStore(g=>g.selectedTableName),o=s.useEditorStore(g=>g.selectedSchemaName),i=s.useEditorStore(g=>g.selectedDatamodelId),l=s.useEditorStore(g=>g.sqlGen),{modelItems:c,connectionType:d}=ae(),p=s.useEditorStore(g=>g.actions.setSqlGen),u=s.useEditorStore(g=>g.actions.setCardSql),f=s.useEditorStore(g=>g.actions.setRunSql);function x(g,j){var v;const y=s.createSqlGenConfig(g,l,j),b=(v=c==null?void 0:c.find(D=>D.id===i))==null?void 0:v.name;p(y);const w=s.getSql(y,s.fmt(o||""),s.fmt(r),b,d);w&&(u(w),f(!0)),a(!1)}function h(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>x(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>x(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>x(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>x(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>x(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:n,onOpenChange:a,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(Ue,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:h()})]})}function es({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(Xe,{className:"size-3"}):s.isNumberDataType(t.data_type)?e.jsx(qs,{className:"size-3"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3"}):s.isBooleanDataType(t.data_type)?e.jsx(rt,{className:"size-3"}):t.data_type.toLowerCase()==="json"?e.jsx(Is,{className:"size-3"}):e.jsx(et,{className:"size-3"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"font-mono text-xs",children:t.data_type})})]})}function pt({schemaName:t,tableName:n,columns:a,status:r}){const o=s.useEditorStore(m=>m.sqlGen),i=s.useEditorStore(m=>m.selectedConnectionId),l=s.useEditorStore(m=>m.selectedDatabaseName),c=s.useEditorStore(m=>m.selectedSchemaName),d=s.useEditorStore(m=>m.selectedTableName),p=s.useEditorStore(m=>m.selectedDatamodelId),u=s.useDashboardStore(m=>m.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:x}=s.useDashboardActions(),{setAIScopeTables:h}=s.useDashboardStore(m=>m.actions),g=s.useEditorStore(m=>m.actions.setRunSql),j=s.useEditorStore(m=>m.actions.setSqlGen),y=s.useEditorStore(m=>m.actions.setIsShowingVisual),b=s.useEditorStore(m=>m.actions.setCardSql),{connectionType:w,modelItems:v,selectedDatamodelName:D}=ae();function T(m){var B;const A=s.createSqlGenConfig(m,o);j(A);const _=(B=v==null?void 0:v.find(S=>S.id===p))==null?void 0:B.name,z=s.getSql(A,s.fmt(t),s.fmt(n),_,w);z&&(b(z),g(!0))}function F(){return(u==null?void 0:u.find(m=>m.connectionId===i&&(m.tableName===d||m.datamodelName===D)))!==void 0}function q(m){m===!0&&(d||D)&&i?(f({connectionId:i,connectionType:w==="S3"||w==="API"?"DuckDb":w,databaseName:l||"",schemaName:c||"",tableName:d||"",datamodelName:s.resolveDatamodelName(D),datamodelId:p||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(x({connectionId:i||"",connectionType:w||"",tableName:d||"",datamodelName:s.resolveDatamodelName(D),datamodelId:p||"",databaseName:l||"",schemaName:c||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function V(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:D,connectionType:w});y(!1);const A=w==="MSSQL"?`SELECT top 10 * FROM ${m}`:`SELECT * FROM ${m} LIMIT 10`;b(A),g(!0)}function P(){const m=s.getFormattedTableNameForQuery({schemaName:t,tableName:n,modelName:D,connectionType:w});b(`SELECT COUNT(*) as count FROM ${m}`),g(!0)}return e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[e.jsxs("div",{className:"mx-2 flex items-center justify-center gap-2",children:[e.jsxs(s.Toggle,{title:`${F()?"Remove from":"Add to"} Assistant Scope`,pressed:F(),onPressedChange:q,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":F(),"text-muted-foreground":!F()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:V,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Us,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:P,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(st,{className:"mr-2 size-4"}),"Count"]})]}),e.jsxs(s.ScrollArea,{className:"flex-1 basis-0 border-b border-t border-muted py-3",children:[e.jsx("div",{className:"flex flex-col gap-1",children:a==null?void 0:a.map(m=>e.jsxs("div",{onClick:()=>T(m),className:s.cn("group mx-3 flex cursor-pointer items-center justify-between rounded px-2 py-1 text-sm transition-colors hover:bg-muted/50",{"border border-dashed border-muted-foreground bg-muted":s.isColumnInSqlGen(m,o)}),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(es,{column:m}),e.jsx("span",{children:m.column_name})]}),e.jsx("div",{onClick:A=>A.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(m.data_type)&&e.jsx(xt,{column:m})})]},m.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function ae(t,n){var De,Te,Ae,Le,Me,ze;let a=C.useMemo(()=>[],[]);const r=s.useSemaphorContext().authToken||t,o=s.useEditorStore(N=>N.selectedConnectionId),i=s.useEditorStore(N=>N.selectedDatamodelId),l=s.useEditorStore(N=>N.selectedDatabaseName),c=s.useEditorStore(N=>N.selectedSchemaName),d=s.useEditorStore(N=>N.selectedTableName),p=s.useEditorStore(N=>N.actions.setCurrentColumns),u=s.useEditorStore(N=>N.actions.setSelectedConnectionId),f=s.useEditorStore(N=>N.actions.setSelectedDatamodelId),x=s.useEditorStore(N=>N.actions.setSelectedDatabaseName),h=s.useEditorStore(N=>N.actions.setSelectedSchemaName),g=s.useEditorStore(N=>N.actions.setSelectedTableName);s.useEditorStore(N=>N.actions.setCardSql);function j(N){return o&&l&&c&&l!=="NA"?!0:o&&N==="API"?!1:!!(o&&N==="S3")}function y(N){return!!(o&&l&&l!=="NA"&&c&&d||o&&(N==="S3"||N==="API")||i&&i)}function b(N){return o&&N?!(N==="API"||N==="S3"):!1}const{refetch:w,data:v,isLoading:D,isError:T}=s.useQuery({queryKey:["connections"],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/connections",(r==null?void 0:r.accessToken)||""),enabled:!!(r!=null&&r.accessToken)}),{refetch:F,data:q,isLoading:V,isError:P}=s.useQuery({queryKey:["models",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:!!(r!=null&&r.accessToken)&&!!o}),m=v==null?void 0:v.connections.find(N=>N.id===o),A=m==null?void 0:m.type,_=(m==null?void 0:m.type)==="API"||(m==null?void 0:m.type)==="S3",{data:z,isLoading:B,isFetching:S,isError:M,refetch:I}=s.useQuery({queryKey:["databases",o],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(r==null?void 0:r.accessToken)||"",{connection_id:o}),enabled:b(A)}),{data:O,isLoading:G,isFetching:$,isError:J,refetch:R}=s.useQuery({queryKey:["schemas",o,l],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l}),enabled:!!o&&!!l&&!_&&l!=="NA"}),{data:L,isLoading:Q,isFetching:k,isError:H,refetch:K}=s.useQuery({queryKey:["tables",o,l,c],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/tables",(r==null?void 0:r.accessToken)||"",{connection_id:o,database_name:l,schema_name:c}),enabled:j(A)}),{data:W,isLoading:te,isFetching:ee,isError:U,refetch:X}=s.useQuery({queryKey:["columns",o,l,i,c,d],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(r==null?void 0:r.accessToken)||"",{connection_id:o,datamodel_id:i||"",database_name:l,schema_name:c,table_name:d}),enabled:y(A)});C.useEffect(()=>{p(a)},[W,p,a]),C.useEffect(()=>{(A==="S3"||A==="API")&&(x(""),h(""),f(""),A==="API"&&g("api"))},[A,g,x,h,f]);const le=(m==null?void 0:m.type)==="API"?(De=m==null?void 0:m.type)==null?void 0:De.toLowerCase():d||"",ne=_?"":c||"";function re(N){h(N),g("")}function E(N){x(N==="none"?"":N),h(""),g(""),N!=="none"&&N!==""&&f("")}function Z(N){u(N)}function oe(N){f(N==="none"?"":N),N!=="none"&&N!==""&&x("")}z&&((Te=z==null?void 0:z.databases)==null?void 0:Te.length)>0,O&&((Ae=O==null?void 0:O.schemas)==null?void 0:Ae.length)>0,W&&((Le=W==null?void 0:W.columns)==null?void 0:Le.length)>0&&(a=W.columns.map(N=>({...N,data_type:N.data_type.toLowerCase()}))),M&&(a=[]),(U||T)&&(a=[]);const Y=v==null?void 0:v.connections.map(N=>({id:N.id,name:N.name,type:N.type})),me=(Me=q==null?void 0:q.datamodels)==null?void 0:Me.map(N=>({id:N.id,name:N.name})),Se=z==null?void 0:z.databases.map(N=>({id:N.database_name,name:N.database_name})),fe=O==null?void 0:O.schemas.map(N=>({id:N.schema_name,name:N.schema_name})),Ce=L==null?void 0:L.tables.map(N=>({id:N.table_name,name:N.table_name})),fs=(ze=q==null?void 0:q.datamodels.find(N=>N.id===i))==null?void 0:ze.name;return{connectionItems:Y,isConnectionsLoading:D,isConnectionsError:T,modelItems:me,selectedDatamodelId:i,selectedDatamodelName:fs,isModelsLoading:V,isModelsError:P,databaseItems:Se,isDatabasesLoadingOrFetching:B||S,isDatabaseError:M,schemaItems:fe,isSchemaLoadingOrFetching:G||$,isSchemaError:J,tableItems:Ce,isTableLoadingOrFetching:Q||k,isTableError:H,columns:a,isColumnsLoadingOrFetching:te||ee,isColumnsError:U,isNonDbConnection:_,connectionType:A,tableName:le,schemaName:ne,refetchConnections:w,refetchModels:F,refetchDatabases:I,refetchSchemas:R,refetchTables:K,refetchColumns:X,handleConnectionChange:Z,handleDatamodelChange:oe,handleDatabaseChange:E,handleSchemaChange:re}}function ss({ColumnsComponent:t}){var ee;const n=s.useEditorStore(U=>U.selectedConnectionId),a=s.useEditorStore(U=>U.selectedDatamodelId),r=s.useEditorStore(U=>U.selectedDatabaseName),o=s.useEditorStore(U=>U.selectedSchemaName),i=s.useEditorStore(U=>U.selectedTableName),l=s.useEditorStore(U=>U.actions.setSelectedTableName),{connectionItems:c,modelItems:d,schemaItems:p,databaseItems:u,tableItems:f,columns:x,isConnectionsLoading:h,isModelsLoading:g,isConnectionsError:j,isModelsError:y,isDatabasesLoadingOrFetching:b,isDatabaseError:w,isSchemaLoadingOrFetching:v,isSchemaError:D,isColumnsError:T,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:q,isTableError:V,connectionType:P,isNonDbConnection:m,refetchDatabases:A,refetchModels:_,refetchSchemas:z,refetchTables:B,refetchColumns:S,refetchConnections:M,handleConnectionChange:I,handleDatabaseChange:O,handleSchemaChange:G,handleDatamodelChange:$,tableName:J,schemaName:R}=ae();function L(){return t?t(R,J,x):e.jsx(pt,{schemaName:R,tableName:J,columns:x,status:F?"Loading...":T?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function k(){if(!n||P==="S3"||P==="API")return null;if(!a||a==="none")return e.jsx(ce,{refetch:A,showNone:!0,onChange:O,isError:w,isLoading:b,items:u,value:r||"",title:"Database",type:"combobox"})}function H(){if(n&&!m&&(!r||r==="none")&&(!a||a==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function K(){if(!n||P==="S3"||P==="API")return null;if(!r||r==="none")return e.jsx(ce,{refetch:_,showNone:!0,onChange:$,isError:y,isLoading:g,items:d,value:a||"",title:"Model",type:"combobox"})}function W(){return!n||P==="S3"||P==="API"||!r||r==="none"?null:e.jsx(ce,{refetch:z,onChange:G,isError:D,isLoading:v,items:p,value:o||"",title:"Schema",type:"combobox"})}function te(){function U(){let X=!1;return P==="API"?(X=!1,X):((P==="S3"||n&&r&&r!=="none"&&o)&&(X=!0),X)}return U()?e.jsx(ce,{refetch:B,onChange:l,isError:V,items:f,isLoading:q,value:i||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:"flex h-full min-w-[300px] flex-col justify-between rounded-none border-r-[1px]",children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ce,{refetch:M,items:c,title:"Connection",value:n||"",onChange:I,isLoading:h,isError:j,type:"combobox",connectionTooltip:((ee=c==null?void 0:c.find(U=>U.id===n))==null?void 0:ee.type)||""}),k(),H(),K(),W(),te()]}),L(),e.jsx("div",{className:"flex items-end justify-center gap-2 px-6 py-4",children:e.jsxs(s.Button,{onClick:Q,size:"sm",variant:"secondary",className:"w-full",children:[e.jsx($s,{className:"mr-2 size-4"}),"Help"]})})]})}function ft(t){const n=t.toUpperCase().indexOf("WHERE"),a=t.toUpperCase().indexOf("GROUP BY"),r=t.toUpperCase().indexOf("LIMIT"),o=t.toUpperCase().indexOf("ORDER BY");let i=t.length;if(o!==-1&&(i=o),r!==-1&&r<i&&(i=r),n!==-1){const l=t.substring(0,n),c=t.substring(n);return`${l} {{ filters | where }} AND ${c.substring(6)}`}else if(a!==-1){const l=t.substring(0,a),c=t.substring(a);return`${l} {{ filters | where }} ${c}`}else{const l=t.substring(0,i),c=t.substring(i);return console.log("beforeClause",l),console.log("afterClause",c),c?`${l} {{ filters | where }} ${c}`:`${l.replace(/;$/,"")} {{ filters | where }}`}}function gt({sql:t,error:n,onClick:a}){return!t&&!n?null:e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(Ds,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[n&&n,t&&e.jsxs("div",{className:"flex flex-col space-y-1.5",children:[e.jsx("span",{className:"text-xs font-semibold",children:"Resolved SQL"}),e.jsx("span",{className:"font-mono",children:t})]})]}),n&&e.jsxs(s.Button,{onClick:a,size:"sm",variant:"secondary",children:[e.jsx(Vs,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})})]})}var ts={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Oe=C.createContext&&C.createContext(ts),jt=["attr","size","title"];function bt(t,n){if(t==null)return{};var a=yt(t,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}function yt(t,n){if(t==null)return{};var a={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(n.indexOf(r)>=0)continue;a[r]=t[r]}return a}function be(){return be=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)Object.prototype.hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},be.apply(this,arguments)}function Fe(t,n){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),a.push.apply(a,r)}return a}function ye(t){for(var n=1;n<arguments.length;n++){var a=arguments[n]!=null?arguments[n]:{};n%2?Fe(Object(a),!0).forEach(function(r){St(t,r,a[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):Fe(Object(a)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(a,r))})}return t}function St(t,n,a){return n=Ct(n),n in t?Object.defineProperty(t,n,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[n]=a,t}function Ct(t){var n=vt(t,"string");return typeof n=="symbol"?n:n+""}function vt(t,n){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var r=a.call(t,n);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(n==="string"?String:Number)(t)}function as(t){return t&&t.map((n,a)=>C.createElement(n.tag,ye({key:a},n.attr),as(n.child)))}function ue(t){return n=>C.createElement(Nt,be({attr:ye({},t.attr)},n),as(t.child))}function Nt(t){var n=a=>{var{attr:r,size:o,title:i}=t,l=bt(t,jt),c=o||a.size||"1em",d;return a.className&&(d=a.className),t.className&&(d=(d?d+" ":"")+t.className),C.createElement("svg",be({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},a.attr,r,l,{className:d,style:ye(ye({color:t.color||a.color},a.style),t.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),i&&C.createElement("title",null,i),t.children)};return Oe!==void 0?C.createElement(Oe.Consumer,null,a=>n(a)):n(ts)}function kt(t){return ue({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function ns(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(j=>j.theme),r=s.useEditorStore(j=>j.frame),o=s.useEditorStore(j=>j.card),i=s.useEditorStore(j=>j.activeTabCardId),l=s.Le(),{refetch:c}=s.useDashboardCardQuery(o),{updateCardTab:d,setRunSql:p}=s.useEditorActions(),u=C.useRef(),f=C.useRef({}),x=r.cards.find(j=>j.id===i),h=C.useCallback(()=>{let j="";return t==="python"&&(j=(x==null?void 0:x.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(j=(x==null?void 0:x.sql)||""),j},[t,x]);C.useEffect(()=>{if(i&&o.id&&o.id!==i){if(u.current&&l){const j=u.current.getModel();j&&(f.current[o.id]=j);let y=f.current[i];if(!y){const b=h();y=l.editor.createModel(b,t),f.current[i]=y}u.current.setModel(y)}d(i,o),p(!0)}},[i,o,d,l,p,t,h]),C.useEffect(()=>{if(!l)return;const j=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=a==="system"?j:a;l.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[n,a,l]),C.useEffect(()=>{const j=u.current;j&&l&&o&&j.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return c(),!1})},[l,c,o]);function g(j,y){if(u.current=j,!f.current[o.id]){const b=j.getModel(),w=h();f.current[o.id]=b||(y==null?void 0:y.editor.createModel(w,t))||j.getModel()}j.setModel(f.current[o.id])}return{handleEditorDidMount:g}}function wt(){const t=s.useEditorStore(l=>l.card.sql),n=s.useEditorStore(l=>l.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:o}=ns("sql");function i(l){a(l),s.isObjectEmpty(n)||r({})}return e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:i,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:o})}function It(){const t=s.useEditorStore(o=>o.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=ns("python");function r(o){n(o)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function Et({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function rs(t){const[n,a]=C.useState(""),[r,o]=C.useState(null),{authToken:i}=s.useSemaphorContext(),l=s.useEditorStore(k=>{var H;return(H=k==null?void 0:k.card)==null?void 0:H.sql}),c=s.useEditorStore(k=>{var H;return(H=k==null?void 0:k.card)==null?void 0:H.python}),d=s.useEditorStore(k=>k.actions.setCardSql),p=s.useEditorStore(k=>k.actions.setRunSql),u=s.useEditorStore(k=>k.actions.switchCardType),f=s.useEditorStore(k=>k.currentAssitantScope)||[],x=s.useEditorStore(k=>k.userInputForAI),h=s.useEditorStore(k=>k.triggerAIRun),g=s.useEditorStore(k=>k.selectedDatabaseName),j=s.useEditorStore(k=>k.selectedTableName),y=s.useEditorStore(k=>k.selectedConnectionId),b=s.useEditorStore(k=>k.selectedSchemaName),w=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{setTriggerAIRun:v,setCurrentAssitantScope:D}=s.useEditorActions(),{selectedDatamodelName:T,connectionType:F,selectedDatamodelId:q}=ae(),{messages:V,setMessages:P,reload:m,append:A,input:_,setInput:z,status:B,handleInputChange:S,handleSubmit:M,stop:I}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${i==null?void 0:i.accessToken}`},body:{random:Math.random()},maxSteps:10,onToolCall:O,onFinish(k,H){G(H.usage),a(""),H.finishReason==="stop"&&a("")}});C.useEffect(()=>{h&&x&&(S({target:{value:x}}),setTimeout(()=>{M(),v(!1)},100))},[h,M,x,v,S]);async function O({toolCall:k}){if(k.toolName==="createChart"){const H=k.args.sql,K=k.args.chartType;return u(K),d(H),p(!0),{status:"success",message:"Let the user know that chart is created"}}else if(k.toolName==="getTableColumns")a("Getting table columns...");else{if(k.toolName==="getUserSql")return l?{status:"success",sql:l,python:c||""}:{status:"error",message:"No SQL found"};if(k.toolName==="getCurrentTableScope")return a("Getting table scope..."),L(),{status:"success",tables:f};a("Analyzing...")}}function G(k){o(H=>H?{promptTokens:H.promptTokens+k.promptTokens,completionTokens:H.completionTokens+k.completionTokens,totalTokens:H.totalTokens+k.totalTokens}:k)}function $(k){const H=s.removeFromScopeArray(f,k);J(H)}function J(k){const H=s.sanitizeAIScope(k);D(H),P(K=>[...K,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables | ${JSON.stringify(H)}`}])}function R(){const k={databaseName:g||"",schemaName:b||"",tableName:j||"",datamodelId:q||"",datamodelName:s.resolveDatamodelName(T),connectionId:y||"",connectionType:F||""},H=s.dedup([...f,k]);J(H)}function L(){const k={databaseName:g||"",schemaName:b||"",tableName:j||"",datamodelName:s.resolveDatamodelName(T),connectionId:y||"",connectionType:F||"",datamodelId:q||""};if(!s.isInAiScopeArray([...w||[],...f],k)||f.length===0){const K=s.dedup([...w||[],...f,k]).filter(W=>W.connectionId===k.connectionId);J(K)}}const Q=!["ready","error"].includes(B);return{messages:V,setMessages:P,reload:m,append:A,input:_,setInput:z,isLoading:Q,handleSetAIScope:L,handleAddCurrentTableToScope:R,removeFromCurrentSelections:$,currentAssitantScope:f,setCurrentAssitantScope:D,handleInputChange:S,handleSubmit:M,stop:I,chatStatus:B,toolStatus:n,llmUsage:r,onFinish:t}}function Dt(){var re;const[t,n]=C.useState({queryKey:[],queryData:null}),a=s.useQueryClient(),[r,o]=C.useState(!1),[i,l]=C.useState(!1),c=s.useEditorStore(E=>E.frame),d=s.useEditorStore(E=>E.card),p=s.useEditorStore(E=>E.isShowingVisual),u=s.useEditorStore(E=>E.selectedConnectionId),f=s.useEditorStore(E=>E.selectedDatabaseName),x=s.useEditorStore(E=>E.selectedDatamodelId),h=s.useEditorStore(E=>E.selectedSchemaName),g=s.useEditorStore(E=>E.showAIDialog),j=s.useEditorStore(E=>E.selectedTableName),y=s.useEditorStore(E=>{var Z;return(Z=E==null?void 0:E.card)==null?void 0:Z.sql}),{sheetFilterValues:b}=s.useSheetFilterValues(),{setCardCustomCfg:w,setQueryResultColumns:v,setCardSql:D,setPythonStdOut:T,setCardPreferences:F,setCardType:q,setCardPython:V,runAssistant:P,setShowAIDialog:m}=s.useEditorActions(),A=s.useEditorStore(E=>E.onSave),_=s.useEditorStore(E=>E.onClose),z=s.useEditorStore(E=>E.actions.setSqlGen),B=s.useEditorStore(E=>E.runSql),S=s.useEditorStore(E=>E.actions.setRunSql),M=s.useEditorStore(E=>E.actions.setCardCfg),I=s.useEditorStore(E=>E.actions.setIsSqlRunning),{data:O,isLoading:G,isFetching:$,isSuccess:J,isError:R,error:L,queryKey:Q,refetch:k}=s.useDashboardCardQuery(d),{handleSetAIScope:H}=rs();C.useEffect(()=>{if(O&&(O.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),T((O==null?void 0:O.output)||""),O.records.length>0)){const{dimensionKeys:E}=s.getKeys(O.records);v(E)}},[O,v,T]),C.useEffect(()=>{(G||$)&&I(!0),(R||J)&&I(!1),R&&(v([]),T(""))},[G,$,O,T,R,J,I,v,L]),C.useEffect(()=>{B&&(a.getQueryData(Q)||k(),S(!1))},[B,k,S,Q,a]);function K(){const E=a.getQueryData(Q);t.queryData||n({queryKey:Q,queryData:E}),a.setQueryData(Q,null),a.removeQueries({queryKey:Q,exact:!0}),D(""),z({}),V(""),M(void 0),w(""),F({}),q("bar")}function W(E,Z){if(E.length===0)return"";if(Z){const oe=E.find(Y=>Y.id===Z);if(oe){const Y=oe.tabTitle;if(Y=="All__Header")return E[0].id;if(Y&&Y.endsWith("__Header")){const Se=Y.split("__")[0],fe=E.find(Ce=>Ce.tabTitle===Se);return fe?fe.id:E[0].id}return Z}}return E[0].id}function te(){let E=y;y&&!y.includes("{{")&&(E=ft(y),D(E));const Z={...d,lastSelectedSchema:h,lastSelectedDatamodelId:x,lastSelectedDatabase:f,lastSelectedTable:j,connectionId:u,type:p?d.type:"table",sql:E,customCfg:p?d.customCfg:null},oe=c.cards.map(me=>me.id===d.id?Z:me),Y={...c,cards:oe,activeCardId:W(oe,c.activeCardId)};A==null||A(Y)}function ee(){const{queryKey:E,queryData:Z}=t;E&&Z&&a.setQueryData(E,Z),z({}),_==null||_()}async function U(){const E=`Can you help me debug this query in the current table scope?
262
292
 
263
293
  Error:
264
294
 
@@ -266,7 +296,7 @@
266
296
 
267
297
  Query:
268
298
 
269
- ${S}
299
+ ${y}
270
300
 
271
- `;P(D)}function X(){return e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(Ct,{jsonString:JSON.stringify(b,null,2)})})}),b&&b.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>c(!i),className:"absolute bottom-0 right-6 size-7 p-1",children:i?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function le(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(yt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(St,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const ne=(A==null?void 0:A.message)||((re=z==null?void 0:z.error)==null?void 0:re.message);return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[le(),X()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:G||U,onClick:()=>{k()},className:"shrink-0",size:"sm",children:[G||U?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(ut,{sql:z==null?void 0:z.sql,error:ne,onClick:$}),e.jsxs(s.Button,{onClick:K,className:"",size:"sm",variant:"secondary",children:[e.jsx(Is,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:D=>o(D),className:"",size:"sm",children:e.jsx(bt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:j,onClick:()=>{H(),m(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:j?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:ee,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:te,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Nt({data:t}){var c;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(l=>({accessorKey:l,header:({column:d})=>{const p=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[l,p==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(l=>e.jsx(s.TableRow,{children:l.headers.map(d=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},l.id))}),e.jsx(s.TableBody,{children:(c=i.getRowModel().rows)!=null&&c.length?i.getRowModel().rows.map(l=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":l.getIsSelected()&&"selected",children:l.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},l.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function wt({card:t}){var I,v,w,M,F,q,V,P,m,T,_;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:i}=s.useSemaphorContext(),c=s.getTokenParams(i==null?void 0:i.accessToken),l=s.useDashboardStore(O=>O.themeStyle),d={colors:((v=(I=l==null?void 0:l.chart)==null?void 0:I.dataset)==null?void 0:v.backgroundColor)||[]};(w=t.customCardPreferences)!=null&&w.inputData;const{getCard:p}=s.useCustomVisual(((M=t.customCardPreferences)==null?void 0:M.url)||""),u=((F=t.customCardPreferences)==null?void 0:F.visualType)||"single",g=s.useEditorStore(O=>O.frame),{setCustomCardPreferences:x}=s.useEditorActions(),{data:h}=s.useDashboardCardQuery(t),j=C.useCallback((O,B)=>{o(y=>({...y,[O]:B}))},[]);if(!((q=t.customCardPreferences)!=null&&q.componentName))return null;const f=p((V=t.customCardPreferences)==null?void 0:V.componentName);function S(O){a(O)}const b=Object.keys(((P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)||{}).map(O=>{var L,E,z;const B=(E=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:E[O].cardId,y=(z=g==null?void 0:g.cards)==null?void 0:z.find(G=>G.id===B);return y||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[f&&u==="single"&&e.jsx(f,{params:c,theme:d,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:j,data:(h==null?void 0:h.records)||[]}),f&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((T=t.customCardPreferences)==null?void 0:T.dataInputCardIds)||{}).map(O=>{var L,E,z;const B=(E=(L=t.customCardPreferences)==null?void 0:L.dataInputCardIds)==null?void 0:E[O].cardId,y=(z=g==null?void 0:g.cards)==null?void 0:z.find(G=>G.id===B);if(y)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:j,dataInputIndex:O,card:y},y.id+O)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(f,{theme:d,onDataChange:j,settings:b.map(O=>{var B;return(B=O==null?void 0:O.customCardPreferences)==null?void 0:B.settings}),data:b.map(O=>O!=null&&O.id?r==null?void 0:r[O.id]:[])})})]})]},(_=t.customCardPreferences)==null?void 0:_.componentName)})}function os({className:t,...n}){var S;const a=s.useEditorStore(b=>b.card),r=((S=a.customCardPreferences)==null?void 0:S.showCardHeader)??!0,o=s.useEditorStore(b=>b.frame),i=s.useDashboardStore(b=>b.dashboard.filters);s.useEditorStore(b=>b.actions.setRunSql);const{updateFilter:c}=s.useDashboardActions(),l=i==null?void 0:i.find(b=>b.id===o.filterId),{data:d,isLoading:p,isFetching:u}=s.useDashboardCardQuery(a),{setCard:g}=s.useEditorActions(),{data:x}=s.useTopoJson(a);if(!a.id)return null;let h;d!=null&&d.records&&(d==null?void 0:d.records.length)>0&&(h=s.createChartConfig({data:d==null?void 0:d.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:x}));function j(b){return e.jsx(wt,{card:b})}function f(){var b;if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!p&&!u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(a.type==="custom")return j(a);if(!["table","custom"].includes(a.type)&&h)return e.jsx(s.ChartJsVisual,{cfg:h},JSON.stringify(h)+JSON.stringify(a.preferences)+((b=a==null?void 0:a.preferences)==null?void 0:b.customVisualCode));if(a.type==="table"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:a,data:d==null?void 0:d.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:b=>g({...a,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:b=>g({...a,description:b}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),l&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:l.title||l.column,onSave:b=>c({...l,title:b}),children:e.jsx(s.Label,{children:l.title})}),e.jsx(s.FilterComponent,{filter:l})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:f()})]})}const Re=({language:t,value:n,onChange:a,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:n,onChange:a}),kt=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),It=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"javascript",value:t,onChange:r})})]}),Et=({error:t,hasCustomConfig:n,onReset:a,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!n,onClick:a,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function Dt(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,i]=C.useState(""),[c,l]=C.useState(""),[d,p]=C.useState(""),u=s.useEditorStore(v=>v.card),g=s.useEditorStore(v=>v.card.customCfg),{data:x}=s.useDashboardCardQuery(u),{data:h}=s.useTopoJson(u),{setCardCustomCfg:j,setCustomVisualCode:f}=s.useEditorActions(),S=v=>{var w,M;return JSON.stringify({...v,data:{...v.data,datasets:(M=(w=v.data)==null?void 0:w.datasets)==null?void 0:M.map(F=>({...F,data:[]}))}},null,2)},b=()=>{var w,M;if(!((w=x==null?void 0:x.records)!=null&&w.length))return;const v=s.createChartConfig({data:x.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:h});if(v){r(S(v)),l(((M=u.preferences)==null?void 0:M.customVisualCode)||"");const F=s.merge(v,g);i(S(F))}},I=()=>{try{if(c&&f(c),o){const v=JSON.parse(o),w=s.getObjectDiff(JSON.parse(a),v);j(w),p("")}}catch{p("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:b,className:g?"text-green-600 hover:text-green-700":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(kt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"w-1/2 rounded shadow-none"})}),e.jsx(It,{customCode:c,customConfig:o,onConfigChange:v=>i(v??""),onCodeChange:v=>l(v??"")})]}),e.jsx(Et,{error:d,hasCustomConfig:!!g,onReset:()=>{i(a),j(null)},onApply:I,onClose:()=>n(!1)})]})]})}function is(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function Tt(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function ls(t){return ue({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function cs(t){return ue({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function ds(t){return ue({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function us(t){const[n,a]=C.useState(null);return n}function hs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function At({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=hs();return C.useEffect(()=>{(async()=>{var i;if(r){const l=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async d=>(await s.loadManifest(d.value)).visuals.map(g=>({name:g.name,icon:g.icon,url:d.value}))))).flat();a(l)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsx(Lt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Lt=({text:t,icon:n,onClick:a})=>{const r=us(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function Mt(){var u,g;const[t,n]=C.useState(!1),a=s.useEditorStore(x=>x.card),r=a.type,{setCardType:o,setCardPreferences:i,setChartOrientation:c}=s.useEditorStore(x=>x.actions),{setCardCustomCfg:l,setCustomCardPreferences:d}=s.useEditorActions();function p(x,h){l(null),i({}),o(x),h&&d({type:"component",visualType:"single",url:h.url,componentName:h.name,icon:h.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",children:e.jsx(Ot,{className:"size-4",chartType:r,customIcon:(u=a.customCardPreferences)==null?void 0:u.icon,componentName:(g=a.customCardPreferences)==null?void 0:g.componentName})})}),e.jsxs(s.PopoverContent,{onOpenAutoFocus:x=>x.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{tooltip:"Bar Chart",onClick:()=>p("bar"),className:"h-10 p-4",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>p("line"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>p("stackedBar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>p("stackedLine"),className:"h-10 p-4",children:e.jsx(cs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>p("scatter"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>p("bubble"),className:"h-10 p-4",children:e.jsx(ls,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>p("pie"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>p("doughnut"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>p("radar"),className:"h-10 p-4",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>p("polarArea"),className:"h-10 p-4",children:e.jsx(is,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>p("pyramid"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>p("range"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>p("table"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>p("kpi"),className:"h-10 p-4",children:e.jsx(ds,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>p("text"),className:"h-10 p-4",children:e.jsx(bs,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>p("map"),className:"h-10 p-4",children:e.jsx(Ue,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>p("custom"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})})]}),e.jsx(At,{onChartTypeChange:p})]})]})}function Ot({chartType:t,className:n,customIcon:a,componentName:r}){const o=us();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(we,{className:n});case"pie":return e.jsx(_e,{className:n});case"radar":return e.jsx(Qe,{className:n});case"scatter":return e.jsx(He,{className:n});case"bubble":return e.jsx(ls,{className:n});case"doughnut":return e.jsx(Ge,{className:n});case"stackedBar":return e.jsx(Be,{className:n});case"stackedLine":return e.jsx(cs,{className:n});case"polarArea":return e.jsx(is,{className:n});case"pyramid":return e.jsx(Ke,{className:n});case"range":return e.jsx(Pe,{className:n});case"kpi":return e.jsx(ds,{className:n});case"text":return e.jsx(Xe,{className:n});case"map":return e.jsx(Ue,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(We,{className:n});default:return e.jsx(ke,{className:n})}}const ge="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ve(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function zt(){var L,E,z,G,U,J;const[t,n]=C.useState(!1),a=s.useEditorStore(R=>{var A;return(A=R.card)==null?void 0:A.preferences}),r=s.useEditorStore(R=>{var A;return(A=R.card)==null?void 0:A.cfg}),o=s.getNumberAxis(a,r),[i,c]=C.useState(Ve(a)),[l,d]=C.useState(((z=(E=(L=a==null?void 0:a.chartOptions)==null?void 0:L.scales)==null?void 0:E[o])==null?void 0:z.min)||""),[p,u]=C.useState(((J=(U=(G=a==null?void 0:a.chartOptions)==null?void 0:G.scales)==null?void 0:U[o])==null?void 0:J.max)||""),[g,x]=C.useState(l||p?"custom":"auto"),[h,j]=C.useState(""),[f,S]=C.useState(0),[b,I]=C.useState(""),[v,w]=C.useState(""),[M,F]=C.useState(""),q=s.useEditorStore(R=>R.actions.setCardPreferences),{updateCardInFrame:V}=s.useEditorActions(),P=s.useEditorStore(R=>R.card),m=s.useEditorStore(R=>{var A;return(A=R.card)==null?void 0:A.type}),T=["pie","doughnut","polarArea"].includes(m);C.useEffect(()=>{var R,A,Q,k,H,K,W,te,ee,$,X,le,ne,re;c(Ve(a)),d(((Q=(A=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:A[o])==null?void 0:Q.min)===0?0:""),u(((K=(H=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:H[o])==null?void 0:K.max)||""),j((($=(ee=(te=(W=a==null?void 0:a.chartOptions)==null?void 0:W.scales)==null?void 0:te[o])==null?void 0:ee.ticks)==null?void 0:$.stepSize)||""),S(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),I(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),w(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.currency)||""),F(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function _(R,A){return A===""||/^[0-9\b]+$/.test(A)?Number(A):Number(R)}function O(){const R=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(A=>A.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:v||"none",onValueChange:A=>w(A==="none"?"":A),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),R.map(A=>e.jsx(s.SelectItem,{value:A,children:A},A))]})})]}),e.jsxs(s.Select,{value:M,onValueChange:A=>F(A),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(A=>e.jsx(s.SelectItem,{value:A.locale,children:A.locale},A.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:f,onChange:A=>S(Number(A.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function B(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:l,onChange:R=>d(A=>_(A,R.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(s.Input,{value:p,onChange:R=>u(A=>_(A,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:h,onChange:R=>j(A=>_(A,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function y(){var k;let R={};g==="custom"&&(R={min:l,max:p,ticks:{stepSize:h}});const A={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales,[o]:{type:i,...i==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:f,suffix:b,currency:v,locale:M}};console.log(A),q(A);const Q={...P,preferences:A};V(Q)}return e.jsxs(s.Popover,{onOpenChange:R=>n(R),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(Us,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:T,value:i,onValueChange:R=>c(R),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:T,id:"scale-option",value:g,onValueChange:R=>x(R),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),g==="custom"&&i=="linear"&&B(),O(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:y,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function Ft(){const t=s.useEditorStore(l=>{var d,p,u,g;return(g=(u=(p=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:g.position}),n=s.useEditorStore(l=>{var d,p,u,g;return(g=(u=(p=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:g.align}),a=s.useEditorStore(l=>{var d,p,u,g;return(g=(u=(p=(d=l.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:g.display}),{setLegendOptions:r}=s.useEditorActions(),o=l=>{r({display:l,position:t,align:n})},i=l=>{r({display:a,position:l,align:n})},c=l=>{r({display:a,position:t,align:l})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(zs,{className:"size-4"})})}),e.jsx(s.PopoverContent,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:a,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs(s.Select,{value:t,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Position"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"top",children:"Top"}),e.jsx(s.SelectItem,{value:"left",children:"Left"}),e.jsx(s.SelectItem,{value:"bottom",children:"Bottom"}),e.jsx(s.SelectItem,{value:"right",children:"Right"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs(s.Select,{value:n,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select Alignment"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),e.jsx(s.SelectItem,{value:"end",children:"End"})]})]})]})]})]})})]})}function Rt(){var l,d,p;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(u=>u.actions);(l=n==null?void 0:n.options)!=null&&l.indexAxis;function i(u){o(u)}const c=((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((p=n==null?void 0:n.options)==null?void 0:p.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>i(c==="y"?"x":"y"),tooltip:"Chart Orientation",children:c==="y"?e.jsx(_s,{className:"size-4"}):e.jsx(Ps,{className:"size-4"})})}function Vt(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>c.isShowingVisual),a=s.useEditorStore(c=>{var l,d;return(d=(l=c.card)==null?void 0:l.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function i(){const c=["xy","none","x","y"],d=(c.indexOf(r)+1)%c.length;o(c[d])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Rt,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{}),e.jsx(Ft,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:i,children:[(r==="xy"||!r)&&e.jsx(As,{className:"size-4"}),r==="x"&&e.jsx(Ns,{className:"size-4"}),r==="y"&&e.jsx($s,{className:"size-4"}),r==="none"&&e.jsx(Ks,{className:"size-4"})]})]}):null}function qe(){var B;const t=s.useEditorStore(y=>y.frame),n=s.useEditorStore(y=>y.card),a=s.useEditorStore(y=>y.isShowingVisual),r=s.useEditorStore(y=>y.isSqlRunning),o=s.useEditorStore(y=>y.pythonStdOut),i=s.useEditorStore(y=>{var L;return(L=y.card.preferences)==null?void 0:L.chartOptions});s.useEditorStore(y=>y.actions.setRunSql),s.getChartGridStyle(i);const{setFrame:c,setCard:l,updateCardInFrame:d,setActiveTabCardId:p,runAssistant:u,setChartGrid:g}=s.useEditorActions(),{data:x,isLoading:h,isFetching:j,error:f}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function S(){const y={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};b(y)}function b(y){const L={...t,cards:[...t.cards,y],activeCardId:y.id};c(L),p(y.id)}function I(){const y={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};b(y)}function v(y){const L=t.cards.filter(G=>G.id!==y),E=L[0],z={...t,cards:L,activeCardId:E.id};c(z),p(E.id),l(E)}function w(y){p(y)}const M=(y,L)=>{console.log("handleDragStart",L),y.dataTransfer.setData("tabIndex",L.toString())},F=y=>{y.preventDefault()},q=(y,L)=>{const E=y.dataTransfer.getData("tabIndex");if(E===L.toString())return;const z=Array.from(t.cards),[G]=z.splice(parseInt(E),1);z.splice(L,0,G),c({...t,cards:z})};function V(y,L){return y.cards.length===1&&(L.displayTab===!0||L.displayTab===void 0)||y.activeCardId!==L.id&&(L.displayTab===!0||L.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const E=L.displayTab===void 0?!1:!L.displayTab;l({...L,displayTab:E}),d({...L,displayTab:E})},children:L.displayTab===!0||L.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(Es,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function P(){return e.jsxs(s.Tabs,{onValueChange:w,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(y=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:y.id,children:m()},y.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((y,L)=>e.jsx(s.Editable,{text:y.tabTitle||y.title,onSave:E=>{l({...n,tabTitle:E}),d({...n,tabTitle:E})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:E=>M(E,L),onDragOver:F,onDrop:E=>q(E,L),className:"",value:y.id,children:[V(t,y),y.tabTitle||y.title,t.activeCardId===y.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>v(y.id)})]})},y.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:S,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:I,children:e.jsx(ws,{className:"h-4 w-4"})})]})})]})}function m(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"grow border-none shadow-none"})})}function T(){const y=JSON.stringify(x==null?void 0:x.records,null,2),L=new Blob([y],{type:"application/json"}),E=URL.createObjectURL(L),z=document.createElement("a");z.href=E,z.download=`${n.title}.json`,z.click()}function _(){const L=[Object.keys(x==null?void 0:x.records.reduce((U,J)=>({...U,...J}),{})).join(","),...((x==null?void 0:x.records)||[]).map(U=>Object.values(U).join(","))].join(`
272
- `),E=new Blob([L],{type:"text/csv"}),z=URL.createObjectURL(E),G=document.createElement("a");G.href=z,G.download=`${n.title}.csv`,G.click()}function O(){const y=`Can you get the documentation for ${n.type} chart?`;u(y)}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(h||j)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(pe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Mt,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:O,children:e.jsx(js,{className:"size-4"})}),!["table","custom"].includes(n.type)&&e.jsx(Dt,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(Tt,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:T,children:e.jsx(Ds,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(x==null?void 0:x.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Vt,{}),e.jsx(Bt,{})]}),a?P():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(qt,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsx(Nt,{data:(x==null?void 0:x.records)||[]}),(f||(x==null?void 0:x.error))&&e.jsx("span",{className:"font-mono text-xs",children:(f==null?void 0:f.message)||((B=x==null?void 0:x.error)==null?void 0:B.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function qt(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Bt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Pt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function se({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function xe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function _t(){var f,S;const t=s.useEditorStore(b=>b.card.customCardPreferences),{data:n}=hs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(b=>b.card),o=s.useEditorStore(b=>b.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:l,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),p=(f=d==null?void 0:d.visuals)==null?void 0:f.find(b=>b.name===(t==null?void 0:t.componentName));function u(b,I){if(!t)return;const w={...(t==null?void 0:t.dataInputCardIds)||{},[b]:{cardId:I,hookRef:null}};c({...t,dataInputCardIds:w})}function g(b){var v,w;const I=(v=o==null?void 0:o.cards)==null?void 0:v.filter(M=>{var F;return((F=M==null?void 0:M.customCardPreferences)==null?void 0:F.visualType)!=="multiple"}).map(M=>({value:M.id,label:M.tabTitle||M.title}));return e.jsx("div",{className:"space-y-2",children:(w=b==null?void 0:b.dataInputs)==null?void 0:w.map((M,F)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:M}),e.jsx(se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:I||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[F])==null?void 0:V.cardId)||"",onValueChange:P=>u(F,P)})]},F+Math.random())})})}function x(b,I,v=[]){var w,M;return t?b==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((w=t==null?void 0:t.settings)==null?void 0:w[I])||"",onChange:F=>{c({...t,settings:{...t==null?void 0:t.settings,[I]:F.target.value}})}},I):b==="select"?e.jsx(se,{className:"h-8 w-full",label:"",options:v,value:((M=t==null?void 0:t.settings)==null?void 0:M[I])||"",onValueChange:F=>{c({...t,settings:{...t==null?void 0:t.settings,[I]:F}})}}):null:null}function h(b){const I=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:I.map(([v,w])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:w.title}),x(w.ui,v,w.options)]},v))})}function j(b){t&&c({...t,visualType:b,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(se,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:b=>c({...t||{url:"",componentName:""},url:b})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Pt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:j}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:l&&e.jsx(se,{className:"h-8 w-full",label:"",options:(l==null?void 0:l.filter(b=>b.type===i).map(b=>({value:b.name,label:b.name})))||[],value:t.componentName,onValueChange:b=>{console.log("changing value",b),c({...t,componentName:b})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(xe,{summary:"Component Settings",children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:g(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:h(p)})})]})]})}function ie(){const[t,n]=C.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(u=>u.actions),c=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var g;return(g=u.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),C.useEffect(()=>{c&&n(new Array(c.length).fill(!1))},[c]);function l(u,g){var x,h;g?a!=null&&a.onClickFilter&&((x=a==null?void 0:a.onClickFilter)==null?void 0:x.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):i({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(i({...a,onClickFilter:(h=a==null?void 0:a.onClickFilter)==null?void 0:h.filter(j=>j.columnIndex!==u)}),n(j=>{const f=[...j];return f[u]=!1,f}))}function d(u,g){var h;const x=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(j=>j.columnIndex===u?{...j,expression:g.target.value}:j);i({...a,onClickFilter:x})}function p(u){var g,x,h,j;if(t!=null&&t[u]||(x=(g=a==null?void 0:a.onClickFilter)==null?void 0:g.find(f=>f.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(j=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(f=>f.columnIndex===u))==null?void 0:j.expression,onChange:f=>d(u,f),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),c==null?void 0:c.map((u,g)=>{var x,h;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((x=a==null?void 0:a.onClickFilter)!=null&&x.find(j=>j.columnIndex===g)),onCheckedChange:j=>l(g,j)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(j=>j.columnIndex===g))&&e.jsx(s.Pencil,{onClick:()=>{n(j=>{const f=[...j];return f[g]=!j[g],f})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),p(g)]})},u)})]})}function Ht({idx:t}){var l;const n=s.useEditorStore(d=>{var p;return(p=d.card)==null?void 0:p.preferences}),a=s.useEditorStore(d=>{var p;return(p=d.card.preferences)==null?void 0:p.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(l=n==null?void 0:n.chartOptions)==null?void 0:l.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function c(d,p){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:p,datalabels:u}]});else{const g={...i};g.datalabels=u;const x=a==null?void 0:a.map(h=>h.idx===p?g:h);r({...n,datasetOptions:x})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(Xs,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>c("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>c("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Fs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Vs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>c("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Rs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>{var u,g,x;return(x=(g=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:g.chartOptions)==null?void 0:x.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:c,dimensionKeys:l}=s.getKeys((a==null?void 0:a.records)||[]);let d=c;if(["stackedBar","stackedLine"].includes(t.type)){const p=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:l[0],pivotKey:l[1],valueKey:d[0]}),{metricKeys:u}=s.getKeys(p);d=u}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:l[0],children:xs(l[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((p,u)=>e.jsx(Gt,{col:p,idx:u},p))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Gt({col:t,idx:n}){const a=s.useEditorStore(l=>{var d;return(d=l.card)==null?void 0:d.preferences}),r=s.useEditorStore(l=>{var d;return(d=l.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(l=>l.idx===n),{setCardPreferences:i}=s.useEditorStore(l=>l.actions);function c(l){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:l==="area"?"line":l,fill:l==="area"?"origin":""}]});else{const d={...o};d.type=l==="area"?"line":l,d.fill=l==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===n?d:u);i({...a,datasetOptions:p})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>c("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(we,{onClick:()=>c("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Cs,{onClick:()=>c("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Ht,{idx:n})]})]})}function ps(){const t=s.useEditorStore(h=>h.selectedConnectionId),n=s.useEditorStore(h=>h.selectedDatamodelId),a=s.useEditorStore(h=>h.selectedDatabaseName),r=s.useEditorStore(h=>h.selectedSchemaName),o=s.useEditorStore(h=>h.selectedTableName),i=s.useDashboardStore(h=>h.dashboard.filters)||[],c=s.useDashboardStore(h=>h.actions.addFilter),l=s.useDashboardStore(h=>h.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:p,tableName:u,connectionType:g}=ae();function x(h,j="dashboard"){var q;const f=s.fmt(h.column_name),S=s.fmt(a||""),b=s.fmt(r||""),I=s.fmt(u);let v=s.getQualifiedTableName(b,I,g),w=`${v}.${f}`;const M=(q=p==null?void 0:p.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(w=`${s.DATAMODEL_NAMESPCACE}.${M}.${f}`,v=`${s.DATAMODEL_NAMESPCACE}.${M}`);const F=i==null?void 0:i.find(V=>V.column===w&&V.table===I&&(V.database===S||V.database===a));if(F)d(F.id),l(F.id);else{const V=s.v4();return u==="api"&&t?(c({location:j,id:V,column:w,title:h.column_name,dataType:h.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(h.data_type,v,f)}),V):(c({id:V,location:j,column:w,title:h.column_name,dataType:h.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(h.data_type,v,f)}),V)}}return{assignFilter:x}}function he(){const t=s.useDashboardStore(l=>l.dashboard.filters),n=s.useEditorStore(l=>l.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ps();function i(l){const d=o(l,"frame");a({...n,filterId:d})}const c=t==null?void 0:t.find(l=>l.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx($t,{onSelect:i,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function $t({columns:t,onSelect:n}){var c;const[a,r]=de.useState(!1),[o,i]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(c=t.find(l=>l.column_name===o))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(l=>e.jsxs(s.CommandItem,{value:l.column_name,onSelect:d=>{const p=d===o?"":d;i(p),r(!1),p&&n(l)},children:[l.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===l.column_name?"opacity-100":"opacity-0")})]},l.column_name))})]})]})})]})}function Ut({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(ms,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function Ee(){var o,i,c;const t=s.useEditorStore(l=>l.card.cfg),n=s.useEditorStore(l=>l.actions.setCardCfg),a=s.useEditorStore(l=>l.card.type);function r(l){var u;const d={datalabels:{display:l!=="none",align:l,anchor:l,clamp:!0}},p={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...d}}};n(p),console.log(l)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:(c=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:c.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Qt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ee,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}const Jt={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Wt={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Kt(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Xt(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(ie,{}),e.jsx(he,{})]})]})}function Xt(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Jt,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(Wt,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Zt(){var d,p,u,g,x;const t=s.useEditorStore(h=>h.card.preferences),n=s.useEditorStore(h=>h.actions.setCardPreferences),a=s.useEditorStore(h=>h.actions.setNumberFormat);s.useEditorStore(h=>{var j,f;return(f=(j=h.card.preferences)==null?void 0:j.formatNumber)==null?void 0:f.decimalPlaces});const r=s.useEditorStore(h=>{var j,f;return(f=(j=h.card.preferences)==null?void 0:j.formatNumber)==null?void 0:f.locale}),o=s.useEditorStore(h=>{var j,f;return(f=(j=h.card.preferences)==null?void 0:j.formatNumber)==null?void 0:f.currency});s.useEditorStore(h=>h.actions.setFilterOnClickField);const i=s.useEditorStore(h=>{var j,f;return(f=(j=h.card.preferences)==null?void 0:j.formatNumber)==null?void 0:f.colorRanges})||[],c=s.useEditorStore(h=>h.actions.setColorRanges),l=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(h=>h.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:h=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:h}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((p=t==null?void 0:t.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:h=>{var j,f,S;return a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",h,((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(h=>e.jsx(s.SelectItem,{value:h.locale,children:h.locale},h.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:h=>{var j,f,S;console.log("currency",h),a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,h==="none"?"":h,((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),l.map(h=>e.jsx(s.SelectItem,{value:h,children:h},h))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((g=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:g.toString())||"0",onValueChange:h=>{var j,f,S;return a(Number(h),((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(h=>e.jsx(s.SelectItem,{value:h,children:h},h))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((x=t==null?void 0:t.formatNumber)==null?void 0:x.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:h=>{var j,f,S;return a(((j=t==null?void 0:t.formatNumber)==null?void 0:j.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",h.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:c})]})]})}function Yt(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Zt,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const ea=[{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"}],sa=["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"],ta=sa.map(t=>({label:t,value:t}));function aa(){var d,p,u,g,x,h,j,f,S,b,I,v,w,M,F,q,V,P;const t=s.useEditorStore(m=>m.card),n=(p=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:p.topoJsonUrl,[a,r]=C.useState(((g=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:g.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),c=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],l=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(se,{className:"h-9",options:l,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(se,{className:"h-9",options:c,value:((h=(x=t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:h.objectKey)||"",label:"Map Object",onValueChange:m=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(se,{className:"h-9",options:ea,value:((f=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:m=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(se,{className:"h-9",options:ta,value:((b=(S=t.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(I=t.preferences)==null?void 0:I.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var T;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((F=(M=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:F[0])||0,onChange:m=>{var T,_,O,B;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionOffset:[Number(m.target.value),((B=(O=(_=t.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:B[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((P=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:P[1])||0,onChange:m=>{var T,_,O,B;o({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,projectionOffset:[((B=(O=(_=t.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:B[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function na(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function je({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(Ee,{}),t==="text"&&e.jsx(na,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function ra(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(se,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function oa({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const ia=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),la=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),ca=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function da(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ra,{});case"pyramid":return e.jsx(je,{docContent:ia,cardType:a});case"kpi":return e.jsx(Yt,{});case"line":case"bar":return e.jsx(Ut,{cardType:a});case"range":return e.jsx(je,{docContent:la,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(Qt,{cardType:a});case"table":return e.jsx(oa,{cardType:a});case"text":return e.jsx(je,{docContent:ca,cardType:a,suffix:"Visual"});case"map":return e.jsx(aa,{});case"custom":return e.jsx(_t,{});default:return e.jsx(Kt,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ua(){const t=C.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return C.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(vt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(da,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(qe,{})})]}):e.jsx(qe,{})})]})}const ha=!1,ma=[{title:"Write a query for",subtitle:"orders over last 3 months"},{title:"Create a bar chart for",subtitle:"sales by product category"}];function xa(){const t=C.useRef(null),n=C.useRef(null),[a,r]=C.useState(!1),[o,i]=C.useState(ha),[c,l]=C.useState(!1),d=s.useEditorStore(E=>E.actions.setCardSql),p=s.useEditorStore(E=>E.actions.setRunSql),u=s.useEditorStore(E=>E.showAIDialog),{setShowAIDialog:g}=s.useEditorActions(),{messages:x,setMessages:h,reload:j,input:f,setInput:S,isLoading:b,handleAddCurrentTableToScope:I,removeFromCurrentSelections:v,currentAssitantScope:w,setCurrentAssitantScope:M,handleInputChange:F,handleSubmit:q,stop:V,chatStatus:P,toolStatus:m,llmUsage:T}=rs();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:x}),C.useEffect(()=>{var E;u&&((E=n.current)==null||E.focus())},[u]);function _(E){d(E),p(!0)}function O(E){S(E.title)}function B(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx($e,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:a,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:l,children:"System Message"})]})]})}function y(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),w&&w.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context:"}),w==null?void 0:w.map((E,z)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:E.schemaName||"",tableName:E.tableName||"",modelName:E.datamodelName||"",connectionType:E.connectionType||""}),e.jsx("button",{onClick:()=>{v(E)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},z))]}),(w==null?void 0:w.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:I,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const L=(f==null?void 0:f.length)===0&&(x==null?void 0:x.filter(E=>E.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[y(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[B(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{h([]),M([]),j()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{g(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:x,showTools:o,handleRun:_,showSystemMessage:c}),e.jsx(s.ChatStatus,{status:s.getStatus(P,m),isLoading:b})]})}),L&&e.jsx(s.Placeholders,{onClick:O,placeholders:ma}),e.jsx(s.ChatInput,{stop:V,ref:n,setInput:S,input:f,handleInputChange:F,handleSubmit:q,isLoading:b}),T&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",T.promptTokens," prompt tokens,"," ",T.completionTokens," completion tokens,"," ",T.totalTokens," total tokens"]})})]})}function pa({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null),o=s.useEditorStore(g=>g.showAIDialog),{setAuthToken:i}=s.useDashboardActions(),{setShowAIDialog:c,setOnSave:l,setOnClose:d}=s.useEditorActions();C.useEffect(()=>{n&&l(n),a&&d(a)},[n,l,a,d]),C.useEffect(()=>{t&&t.accessToken&&i(t)},[t,i]),C.useEffect(()=>{var g,x;o?((g=r.current)==null||g.resize(40),c(!0)):(c(!1),(x=r.current)==null||x.resize(0))},[o,c]);function p(g){g<1?c(!1):o||c(!0)}function u(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ua,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(xa,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(ss,{}),u()]})})}function fa(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(c=>c.actions),a=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function o(c){t&&(r(t,c),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(pa,{onSave:o,onClose:i})})}function ga(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const c=a==null?void 0:a.find(l=>l.column===s.fmt(i.column_name)&&l.table===n&&l.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function ja(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ss,{ColumnsComponent:()=>e.jsx(ga,{})})})]})}function ba(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function ya(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(ba,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ja,{})})]})}function Sa(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function Ca({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(Sa,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(ot,{}),e.jsx(fa,{}),e.jsx(ya,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.resolveDatamodelName=s.resolveDatamodelName;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=ce;exports.Surfboard=Ca;exports.cleanCard=Ze;exports.downloadPdf=Ye;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ae;
301
+ `;P(E)}function X(){return e.jsxs(e.Fragment,{children:[i&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(Et,{jsonString:JSON.stringify(b,null,2)})})}),b&&b.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>l(!i),className:"absolute bottom-0 right-6 size-7 p-1",children:i?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(s.Filter,{className:"size-3.5 text-muted-foreground"})})]})}function le(){return e.jsxs(s.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(s.ResizablePanel,{id:"1",order:1,defaultSize:r?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(wt,{})}),r&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(It,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}const ne=(L==null?void 0:L.message)||((re=O==null?void 0:O.error)==null?void 0:re.message);return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[le(),X()]}),e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:G||$,onClick:()=>{k()},className:"shrink-0",size:"sm",children:[G||$?e.jsx(pe,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(gt,{sql:O==null?void 0:O.sql,error:ne,onClick:U}),e.jsxs(s.Button,{onClick:K,className:"",size:"sm",variant:"secondary",children:[e.jsx(Ms,{className:"mr-2 size-4"}),"Clear"]}),e.jsx(s.Toggle,{pressed:r,onPressedChange:E=>o(E),className:"",size:"sm",children:e.jsx(kt,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:g,onClick:()=>{H(),m(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:g?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:ee,className:"w-full",size:"sm",variant:"secondary",children:[e.jsx(s.Cross2Icon,{className:"mr-2 size-4"}),"Close"]}),e.jsxs(s.Button,{onClick:te,size:"sm",variant:"secondary",children:[e.jsx(s.Check,{className:"mr-2 size-4 font-bold text-green-600"}),"Accept"]})]})]})]})}function Tt({data:t}){var l;const[n,a]=C.useState([]),o=Object.keys(t[0]).map(c=>({accessorKey:c,header:({column:d})=>{const p=d.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>d.toggleSorting(d.getIsSorted()==="asc"),children:[c,p==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):p==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),i=s.useReactTable({data:t,columns:o,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:a,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:n}});return e.jsx("div",{className:"font-mono text-xs text-foreground/95",children:e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{children:i.getHeaderGroups().map(c=>e.jsx(s.TableRow,{children:c.headers.map(d=>e.jsx(s.TableHead,{className:"sticky top-0 h-11 bg-muted font-semibold",children:d.isPlaceholder?null:s.flexRender(d.column.columnDef.header,d.getContext())},d.id))},c.id))}),e.jsx(s.TableBody,{children:(l=i.getRowModel().rows)!=null&&l.length?i.getRowModel().rows.map(c=>e.jsx(s.TableRow,{className:"whitespace-nowrap py-2","data-state":c.getIsSelected()&&"selected",children:c.getVisibleCells().map(d=>e.jsx(s.TableCell,{className:"py-3",children:s.flexRender(d.column.columnDef.cell,d.getContext())},d.id))},c.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:o.length,className:"h-24 text-center",children:"No results."})})})]})})}function At({card:t}){var w,v,D,T,F,q,V,P,m,A,_;const[n,a]=C.useState(!1),[r,o]=C.useState([]),{authToken:i}=s.useSemaphorContext(),l=s.getTokenParams(i==null?void 0:i.accessToken),c=s.useDashboardStore(z=>z.themeStyle),d={colors:((v=(w=c==null?void 0:c.chart)==null?void 0:w.dataset)==null?void 0:v.backgroundColor)||[]};(D=t.customCardPreferences)!=null&&D.inputData;const{getCard:p}=s.useCustomVisual(((T=t.customCardPreferences)==null?void 0:T.url)||""),u=((F=t.customCardPreferences)==null?void 0:F.visualType)||"single",f=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:x}=s.useEditorActions(),{data:h}=s.useDashboardCardQuery(t),g=C.useCallback((z,B)=>{o(S=>({...S,[z]:B}))},[]);if(!((q=t.customCardPreferences)!=null&&q.componentName))return null;const j=p((V=t.customCardPreferences)==null?void 0:V.componentName);function y(z){a(z)}const b=Object.keys(((P=t.customCardPreferences)==null?void 0:P.dataInputCardIds)||{}).map(z=>{var M,I,O;const B=(I=(M=t.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:I[z].cardId,S=(O=f==null?void 0:f.cards)==null?void 0:O.find(G=>G.id===B);return S||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(C.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[j&&u==="single"&&e.jsx(j,{params:l,theme:d,settings:(m=t.customCardPreferences)==null?void 0:m.settings,onDataChange:g,data:(h==null?void 0:h.records)||[]}),j&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)||{}).map(z=>{var M,I,O;const B=(I=(M=t.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:I[z].cardId,S=(O=f==null?void 0:f.cards)==null?void 0:O.find(G=>G.id===B);if(S)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:y,onDataChange:g,dataInputIndex:z,card:S},S.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(j,{theme:d,onDataChange:g,settings:b.map(z=>{var B;return(B=z==null?void 0:z.customCardPreferences)==null?void 0:B.settings}),data:b.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(_=t.customCardPreferences)==null?void 0:_.componentName)})}function os({className:t,...n}){var y;const a=s.useEditorStore(b=>b.card),r=((y=a.customCardPreferences)==null?void 0:y.showCardHeader)??!0,o=s.useEditorStore(b=>b.frame),i=s.useDashboardStore(b=>b.dashboard.filters);s.useEditorStore(b=>b.actions.setRunSql);const{updateFilter:l}=s.useDashboardActions(),c=i==null?void 0:i.find(b=>b.id===o.filterId),{data:d,isLoading:p,isFetching:u}=s.useDashboardCardQuery(a),{setCard:f}=s.useEditorActions(),{data:x}=s.useTopoJson(a);if(!a.id)return null;let h;d!=null&&d.records&&(d==null?void 0:d.records.length)>0&&(h=s.createChartConfig({data:d==null?void 0:d.records,cardType:a.type,cfg:a.cfg,customCfg:a.customCfg,preferences:a.preferences,topoJson:x}));function g(b){return e.jsx(At,{card:b})}function j(){var b;if(d!=null&&d.records&&(d==null?void 0:d.records.length)===0&&!p&&!u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(a.type==="custom")return g(a);if(!["table","custom"].includes(a.type)&&h)return e.jsx(s.ChartJsVisual,{cfg:h},JSON.stringify(h)+JSON.stringify(a.preferences)+((b=a==null?void 0:a.preferences)==null?void 0:b.customVisualCode));if(a.type==="table"&&(d!=null&&d.records)&&(d==null?void 0:d.records.length)>0)return e.jsxs(s.ScrollArea,{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:[e.jsx(s.TableVisual,{card:a,data:d==null?void 0:d.records}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{text:a.title,onSave:b=>f({...a,title:b}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:a.title||"Edit title..."})})},a.title),e.jsx(s.Editable,{text:a.description||"",onSave:b=>f({...a,description:b}),children:e.jsx(s.CardDescription,{children:a.description||"Edit description..."})},a.description)]}),c&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{className:"my-1",text:c.title||c.column,onSave:b=>l({...c,title:b}),children:e.jsx(s.Label,{children:c.title})}),e.jsx(s.FilterComponent,{filter:c})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:j()})]})}const Re=({language:t,value:n,onChange:a,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:n,onChange:a}),Lt=()=>e.jsxs(s.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(s.DialogTitle,{children:"Customize Card"})}),e.jsxs(s.DialogDescription,{children:["See the configuration options and documentation",e.jsx("a",{target:"_blank",className:"ml-1 text-blue-500 underline",href:"https://www.chartjs.org/docs/latest/samples/bar/vertical.html",children:"here."})]})]}),Mt=({customCode:t,customConfig:n,onConfigChange:a,onCodeChange:r})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"json",value:n,onChange:a})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Re,{language:"javascript",value:t,onChange:r})})]}),zt=({error:t,hasCustomConfig:n,onReset:a,onApply:r,onClose:o})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!n,onClick:a,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:o,variant:"outline",children:"Close"})]});function Ot(){const[t,n]=C.useState(!1),[a,r]=C.useState(""),[o,i]=C.useState(""),[l,c]=C.useState(""),[d,p]=C.useState(""),u=s.useEditorStore(v=>v.card),f=s.useEditorStore(v=>v.card.customCfg),{data:x}=s.useDashboardCardQuery(u),{data:h}=s.useTopoJson(u),{setCardCustomCfg:g,setCustomVisualCode:j}=s.useEditorActions(),y=v=>{var D,T;return JSON.stringify({...v,data:{...v.data,datasets:(T=(D=v.data)==null?void 0:D.datasets)==null?void 0:T.map(F=>({...F,data:[]}))}},null,2)},b=()=>{var D,T;if(!((D=x==null?void 0:x.records)!=null&&D.length))return;const v=s.createChartConfig({data:x.records,cardType:u.type,cfg:u.cfg,preferences:u.preferences,topoJson:h});if(v){r(y(v)),c(((T=u.preferences)==null?void 0:T.customVisualCode)||"");const F=s.merge(v,f);i(y(F))}},w=()=>{try{if(l&&j(l),o){const v=JSON.parse(o),D=s.getObjectDiff(JSON.parse(a),v);g(D),p("")}}catch{p("Invalid JSON configuration")}};return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:b,className:f?"text-green-600 hover:text-green-700":"",children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"max-h-[70vh] min-h-[70vh] overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Lt,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Mt,{customCode:l,customConfig:o,onConfigChange:v=>i(v??""),onCodeChange:v=>c(v??"")})]}),e.jsx(zt,{error:d,hasCustomConfig:!!f,onReset:()=>{i(a),g(null)},onApply:w,onClose:()=>n(!1)})]})]})}function is(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function Ft(t){return ue({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function ls(t){return ue({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function cs(t){return ue({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function ds(t){return ue({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function us(t){const[n,a]=C.useState(null);return n}function hs(){const{authToken:t}=s.useSemaphorContext(),{data:n,isLoading:a,isFetching:r,isError:o}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:n,isLoading:a,isFetching:r,isError:o}}function Rt({onChartTypeChange:t}){const[n,a]=C.useState([]),{data:r}=hs();return C.useEffect(()=>{(async()=>{var i;if(r){const c=(await Promise.all((i=r==null?void 0:r.plugins)==null?void 0:i.map(async d=>(await s.loadManifest(d.value)).visuals.map(f=>({name:f.name,icon:f.icon,url:d.value}))))).flat();a(c)}})()},[r]),n.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:n.map((o,i)=>e.jsx(Vt,{text:o.name,onClick:()=>t("custom",o),icon:o.icon},o.url+o.name+i))})]})}const Vt=({text:t,icon:n,onClick:a})=>{const r=us(),o=t.charAt(0).toUpperCase();return e.jsx(s.Button,{onClick:a,title:t,variant:"ghost",children:r?e.jsx(r,{className:"h-4 w-4"}):o})};function qt(){var u,f;const[t,n]=C.useState(!1),a=s.useEditorStore(x=>x.card),r=a.type,{setCardType:o,setCardPreferences:i,setChartOrientation:l}=s.useEditorStore(x=>x.actions),{setCardCustomCfg:c,setCustomCardPreferences:d}=s.useEditorActions();function p(x,h){c(null),i({}),o(x),h&&d({type:"component",visualType:"single",url:h.url,componentName:h.name,icon:h.icon}),n(!1)}return e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",children:e.jsx(Bt,{className:"size-4",chartType:r,customIcon:(u=a.customCardPreferences)==null?void 0:u.icon,componentName:(f=a.customCardPreferences)==null?void 0:f.componentName})})}),e.jsxs(s.PopoverContent,{onOpenAutoFocus:x=>x.preventDefault(),className:"w-50",children:[e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{tooltip:"Bar Chart",onClick:()=>p("bar"),className:"h-10 p-4",children:e.jsx(Ne,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Line Chart",onClick:()=>p("line"),className:"h-10 p-4",children:e.jsx(ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Bar Chart",onClick:()=>p("stackedBar"),className:"h-10 p-4",children:e.jsx(Be,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Stacked Line Chart",onClick:()=>p("stackedLine"),className:"h-10 p-4",children:e.jsx(cs,{className:"size-5",strokeWidth:0})}),e.jsx(s.IconButton,{tooltip:"Scatter Chart",onClick:()=>p("scatter"),className:"h-10 p-4",children:e.jsx(He,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Bubble Chart",onClick:()=>p("bubble"),className:"h-10 p-4",children:e.jsx(ls,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Pie Chart",onClick:()=>p("pie"),className:"h-10 p-4",children:e.jsx(_e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Doughnut Chart",onClick:()=>p("doughnut"),className:"h-10 p-4",children:e.jsx(Ge,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Radar Chart",onClick:()=>p("radar"),className:"h-10 p-4",children:e.jsx(Qe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Polar Area Chart",onClick:()=>p("polarArea"),className:"h-10 p-4",children:e.jsx(is,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Pyramid Chart",onClick:()=>p("pyramid"),className:"h-10 p-4",children:e.jsx(Ke,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>p("range"),className:"h-10 p-4",children:e.jsx(Pe,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Table",onClick:()=>p("table"),className:"h-10 p-4",children:e.jsx(we,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"KPI",onClick:()=>p("kpi"),className:"h-10 p-4",children:e.jsx(ds,{className:"size-6"})}),e.jsx(s.IconButton,{tooltip:"Text",onClick:()=>p("text"),className:"h-10 p-4",children:e.jsx(ks,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>p("map"),className:"h-10 p-4",children:e.jsx($e,{className:"size-5"})}),e.jsx(s.IconButton,{tooltip:"Custom",onClick:()=>p("custom"),className:"h-10 p-4",children:e.jsx(We,{className:"size-5"})})]}),e.jsx(Rt,{onChartTypeChange:p})]})]})}function Bt({chartType:t,className:n,customIcon:a,componentName:r}){const o=us();switch(t){case"bar":return e.jsx(Ne,{className:n});case"line":return e.jsx(ke,{className:n});case"pie":return e.jsx(_e,{className:n});case"radar":return e.jsx(Qe,{className:n});case"scatter":return e.jsx(He,{className:n});case"bubble":return e.jsx(ls,{className:n});case"doughnut":return e.jsx(Ge,{className:n});case"stackedBar":return e.jsx(Be,{className:n});case"stackedLine":return e.jsx(cs,{className:n});case"polarArea":return e.jsx(is,{className:n});case"pyramid":return e.jsx(Ke,{className:n});case"range":return e.jsx(Pe,{className:n});case"kpi":return e.jsx(ds,{className:n});case"text":return e.jsx(Xe,{className:n});case"map":return e.jsx($e,{className:n});case"custom":return a&&o?e.jsx(o,{className:n}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(We,{className:n});default:return e.jsx(we,{className:n})}}const ge="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Ve(t,n){var r,o,i;const a=s.getNumberAxis(t,n);return((i=(o=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:o[a])==null?void 0:i.type)||"linear"}function Pt(){var M,I,O,G,$,J;const[t,n]=C.useState(!1),a=s.useEditorStore(R=>{var L;return(L=R.card)==null?void 0:L.preferences}),r=s.useEditorStore(R=>{var L;return(L=R.card)==null?void 0:L.cfg}),o=s.getNumberAxis(a,r),[i,l]=C.useState(Ve(a)),[c,d]=C.useState(((O=(I=(M=a==null?void 0:a.chartOptions)==null?void 0:M.scales)==null?void 0:I[o])==null?void 0:O.min)||""),[p,u]=C.useState(((J=($=(G=a==null?void 0:a.chartOptions)==null?void 0:G.scales)==null?void 0:$[o])==null?void 0:J.max)||""),[f,x]=C.useState(c||p?"custom":"auto"),[h,g]=C.useState(""),[j,y]=C.useState(0),[b,w]=C.useState(""),[v,D]=C.useState(""),[T,F]=C.useState(""),q=s.useEditorStore(R=>R.actions.setCardPreferences),{updateCardInFrame:V}=s.useEditorActions(),P=s.useEditorStore(R=>R.card),m=s.useEditorStore(R=>{var L;return(L=R.card)==null?void 0:L.type}),A=["pie","doughnut","polarArea"].includes(m);C.useEffect(()=>{var R,L,Q,k,H,K,W,te,ee,U,X,le,ne,re;l(Ve(a)),d(((Q=(L=(R=a==null?void 0:a.chartOptions)==null?void 0:R.scales)==null?void 0:L[o])==null?void 0:Q.min)===0?0:""),u(((K=(H=(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales)==null?void 0:H[o])==null?void 0:K.max)||""),g(((U=(ee=(te=(W=a==null?void 0:a.chartOptions)==null?void 0:W.scales)==null?void 0:te[o])==null?void 0:ee.ticks)==null?void 0:U.stepSize)||""),y(((X=a==null?void 0:a.numberAxisFormat)==null?void 0:X.decimalPlaces)||0),w(((le=a==null?void 0:a.numberAxisFormat)==null?void 0:le.suffix)||""),D(((ne=a==null?void 0:a.numberAxisFormat)==null?void 0:ne.currency)||""),F(((re=a==null?void 0:a.numberAxisFormat)==null?void 0:re.locale)||"")},[t,a,o]);function _(R,L){return L===""||/^[0-9\b]+$/.test(L)?Number(L):Number(R)}function z(){const R=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(L=>L.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:v||"none",onValueChange:L=>D(L==="none"?"":L),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),R.map(L=>e.jsx(s.SelectItem,{value:L,children:L},L))]})})]}),e.jsxs(s.Select,{value:T,onValueChange:L=>F(L),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(L=>e.jsx(s.SelectItem,{value:L.locale,children:L.locale},L.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:j,onChange:L=>y(Number(L.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${ge}`})]})]})}function B(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:c,onChange:R=>d(L=>_(L,R.target.value)),className:`col-span-1 h-8 w-full ${ge}`}),e.jsx(s.Input,{value:p,onChange:R=>u(L=>_(L,R.target.value)),id:"max",className:`col-span-1 h-8 w-full ${ge}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:h,onChange:R=>g(L=>_(L,R.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${ge}`})]})]})}function S(){var k;let R={};f==="custom"&&(R={min:c,max:p,ticks:{stepSize:h}});const L={...a||{},chartOptions:{...a==null?void 0:a.chartOptions,scales:{...(k=a==null?void 0:a.chartOptions)==null?void 0:k.scales,[o]:{type:i,...i==="linear"?R:{}}}},numberAxisFormat:{decimalPlaces:j,suffix:b,currency:v,locale:T}};console.log(L),q(L);const Q={...P,preferences:L};V(Q)}return e.jsxs(s.Popover,{onOpenChange:R=>n(R),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Scale Options",children:e.jsx(Zs,{className:"size-4 rotate-45"})})}),e.jsx(s.PopoverContent,{align:"center",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Scale Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for the number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:A,value:i,onValueChange:R=>l(R),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"})]})})]})]}),i=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:A,id:"scale-option",value:f,onValueChange:R=>x(R),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),f==="custom"&&i=="linear"&&B(),z(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:S,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function _t(){const t=s.useEditorStore(c=>{var d,p,u,f;return(f=(u=(p=(d=c.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:f.position}),n=s.useEditorStore(c=>{var d,p,u,f;return(f=(u=(p=(d=c.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:f.align}),a=s.useEditorStore(c=>{var d,p,u,f;return(f=(u=(p=(d=c.card.preferences)==null?void 0:d.chartOptions)==null?void 0:p.plugins)==null?void 0:u.legend)==null?void 0:f.display}),{setLegendOptions:r}=s.useEditorActions(),o=c=>{r({display:c,position:t,align:n})},i=c=>{r({display:a,position:c,align:n})},l=c=>{r({display:a,position:t,align:c})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(Ps,{className:"size-4"})})}),e.jsx(s.PopoverContent,{className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:a,onCheckedChange:o,defaultChecked:!0,id:"displayLegend"})})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>i("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>i("left"),children:e.jsx(Cs,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>i("bottom"),children:e.jsx(Ss,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>i("right"),children:e.jsx(vs,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>l("start"),children:e.jsx(bs,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>l("center"),children:e.jsx(js,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>l("end"),children:e.jsx(ys,{className:"size-4"})})]})]})]})]})})]})}function Ht(){var c,d,p;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.card.cfg),{setCardCfg:a,setCardPreferences:r,setChartOrientation:o}=s.useEditorStore(u=>u.actions);(c=n==null?void 0:n.options)!=null&&c.indexAxis;function i(u){o(u)}const l=((d=t==null?void 0:t.chartOptions)==null?void 0:d.indexAxis)||((p=n==null?void 0:n.options)==null?void 0:p.indexAxis)||"x";return e.jsx(s.IconButton,{onClick:()=>i(l==="y"?"x":"y"),tooltip:"Chart Orientation",children:l==="y"?e.jsx(Js,{className:"size-4"}):e.jsx(Qs,{className:"size-4"})})}function Gt(){const t=s.useEditorStore(l=>l.card),n=s.useEditorStore(l=>l.isShowingVisual),a=s.useEditorStore(l=>{var c,d;return(d=(c=l.card)==null?void 0:c.preferences)==null?void 0:d.chartOptions}),r=s.getChartGridStyle(a),{setChartGrid:o}=s.useEditorActions();function i(){const l=["xy","none","x","y"],d=(l.indexOf(r)+1)%l.length;o(l[d])}return n?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar"].includes(t.type)&&e.jsx(Ht,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(Pt,{}),e.jsx(_t,{})]}),!["pie","doughnut","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:i,children:[(r==="xy"||!r)&&e.jsx(Rs,{className:"size-4"}),r==="x"&&e.jsx(Ts,{className:"size-4"}),r==="y"&&e.jsx(Xs,{className:"size-4"}),r==="none"&&e.jsx(tt,{className:"size-4"})]})]}):null}function qe(){var B;const t=s.useEditorStore(S=>S.frame),n=s.useEditorStore(S=>S.card),a=s.useEditorStore(S=>S.isShowingVisual),r=s.useEditorStore(S=>S.isSqlRunning),o=s.useEditorStore(S=>S.pythonStdOut),i=s.useEditorStore(S=>{var M;return(M=S.card.preferences)==null?void 0:M.chartOptions});s.useEditorStore(S=>S.actions.setRunSql),s.getChartGridStyle(i);const{setFrame:l,setCard:c,updateCardInFrame:d,setActiveTabCardId:p,runAssistant:u,setChartGrid:f}=s.useEditorActions(),{data:x,isLoading:h,isFetching:g,error:j}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function y(){const S={connectionId:n.connectionId,id:s.v4(),title:"Title",description:"Description",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};b(S)}function b(S){const M={...t,cards:[...t.cards,S],activeCardId:S.id};l(M),p(S.id)}function w(){const S={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};b(S)}function v(S){const M=t.cards.filter(G=>G.id!==S),I=M[0],O={...t,cards:M,activeCardId:I.id};l(O),p(I.id),c(I)}function D(S){p(S)}const T=(S,M)=>{console.log("handleDragStart",M),S.dataTransfer.setData("tabIndex",M.toString())},F=S=>{S.preventDefault()},q=(S,M)=>{const I=S.dataTransfer.getData("tabIndex");if(I===M.toString())return;const O=Array.from(t.cards),[G]=O.splice(parseInt(I),1);O.splice(M,0,G),l({...t,cards:O})};function V(S,M){return S.cards.length===1&&(M.displayTab===!0||M.displayTab===void 0)||S.activeCardId!==M.id&&(M.displayTab===!0||M.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const I=M.displayTab===void 0?!1:!M.displayTab;c({...M,displayTab:I}),d({...M,displayTab:I})},children:M.displayTab===!0||M.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(zs,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function P(){return e.jsxs(s.Tabs,{onValueChange:D,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(S=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:S.id,children:m()},S.id)),e.jsx(s.TabsList,{className:"group mx-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((S,M)=>e.jsx(s.Editable,{text:S.tabTitle||S.title,onSave:I=>{c({...n,tabTitle:I}),d({...n,tabTitle:I})},children:e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:I=>T(I,M),onDragOver:F,onDrop:I=>q(I,M),className:"",value:S.id,children:[V(t,S),S.tabTitle||S.title,t.activeCardId===S.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>v(S.id)})]})},S.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:y,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:w,children:e.jsx(As,{className:"h-4 w-4"})})]})})]})}function m(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:x==null?void 0:x.records})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:r,card:n,data:x==null?void 0:x.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(os,{className:"grow border-none shadow-none"})})}function A(){const S=JSON.stringify(x==null?void 0:x.records,null,2),M=new Blob([S],{type:"application/json"}),I=URL.createObjectURL(M),O=document.createElement("a");O.href=I,O.download=`${n.title}.json`,O.click()}function _(){const M=[Object.keys(x==null?void 0:x.records.reduce(($,J)=>({...$,...J}),{})).join(","),...((x==null?void 0:x.records)||[]).map($=>Object.values($).join(","))].join(`
302
+ `),I=new Blob([M],{type:"text/csv"}),O=URL.createObjectURL(I),G=document.createElement("a");G.href=O,G.download=`${n.title}.csv`,G.click()}function z(){const S=`Can you get the documentation for ${n.type} chart?`;u(S)}return e.jsxs("div",{className:"relative flex h-full flex-col py-3",children:[(h||g)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(pe,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[a&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(qt,{}),e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:z,children:e.jsx(Ns,{className:"size-4"})}),!["table","custom"].includes(n.type)&&e.jsx(Ot,{})]}),!a&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:_,children:e.jsx(Ft,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:A,children:e.jsx(Os,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(x==null?void 0:x.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsx(Gt,{}),e.jsx($t,{})]}),a?P():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(Ut,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsx(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:e.jsxs(s.ScrollArea,{className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsx(Tt,{data:(x==null?void 0:x.records)||[]}),(j||(x==null?void 0:x.error))&&e.jsx("span",{className:"font-mono text-xs",children:(j==null?void 0:j.message)||((B=x==null?void 0:x.error)==null?void 0:B.message)}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})})]})]})}function Ut(){const t=s.useEditorStore(a=>a.pythonStdOut);if(!t)return null;const n=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function $t(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>n(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Qt({options:t,value:n,onValueChange:a}){return e.jsx(s.RadioGroup,{value:n,onValueChange:a,className:"flex gap-4",defaultValue:t[0].value,children:t.map(r=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:r.value,id:r.value}),e.jsx("label",{className:"text-sm",htmlFor:r.value,children:r.label})]},r.value))})}function se({label:t,options:n,value:a,onValueChange:r,className:o}){return e.jsxs(s.Select,{value:a,onValueChange:r,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsx(s.SelectValue,{placeholder:t})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:t}),n.map(i=>e.jsx(s.SelectItem,{value:i.value,children:i.label},i.value))]})})]})}function xe({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function Jt(){var j,y;const t=s.useEditorStore(b=>b.card.customCardPreferences),{data:n}=hs(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(b=>b.card),o=s.useEditorStore(b=>b.frame),i=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:l}=s.useEditorActions(),{components:c,manifest:d}=s.useCustomVisual((t==null?void 0:t.url)||""),p=(j=d==null?void 0:d.visuals)==null?void 0:j.find(b=>b.name===(t==null?void 0:t.componentName));function u(b,w){if(!t)return;const D={...(t==null?void 0:t.dataInputCardIds)||{},[b]:{cardId:w,hookRef:null}};l({...t,dataInputCardIds:D})}function f(b){var v,D;const w=(v=o==null?void 0:o.cards)==null?void 0:v.filter(T=>{var F;return((F=T==null?void 0:T.customCardPreferences)==null?void 0:F.visualType)!=="multiple"}).map(T=>({value:T.id,label:T.tabTitle||T.title}));return e.jsx("div",{className:"space-y-2",children:(D=b==null?void 0:b.dataInputs)==null?void 0:D.map((T,F)=>{var q,V;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:T}),e.jsx(se,{className:"col-span-6 h-8 w-full justify-between",label:"",options:w||[],value:((V=(q=t==null?void 0:t.dataInputCardIds)==null?void 0:q[F])==null?void 0:V.cardId)||"",onValueChange:P=>u(F,P)})]},F+Math.random())})})}function x(b,w,v=[]){var D,T;return t?b==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((D=t==null?void 0:t.settings)==null?void 0:D[w])||"",onChange:F=>{l({...t,settings:{...t==null?void 0:t.settings,[w]:F.target.value}})}},w):b==="select"?e.jsx(se,{className:"h-8 w-full",label:"",options:v,value:((T=t==null?void 0:t.settings)==null?void 0:T[w])||"",onValueChange:F=>{l({...t,settings:{...t==null?void 0:t.settings,[w]:F}})}}):null:null}function h(b){const w=Object.entries((b==null?void 0:b.settings)||{});return e.jsx("div",{className:"space-y-3",children:w.map(([v,D])=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:D.title}),x(D.ui,v,D.options)]},v))})}function g(b){t&&l({...t,visualType:b,componentName:""})}return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Plugin Settings",children:e.jsx("div",{className:"space-y-4 text-sm",children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"px-2",children:e.jsx(se,{className:"h-8 w-full",label:"",options:a,value:(t==null?void 0:t.url)||"",onValueChange:b=>l({...t||{url:"",componentName:""},url:b})})})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(Qt,{options:[{value:"single",label:"Single Visual"},{value:"multiple",label:"Multi-Visual"}],value:i,onValueChange:g}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Component"}),e.jsx("div",{className:"space-y-2 px-2",children:c&&e.jsx(se,{className:"h-8 w-full",label:"",options:(c==null?void 0:c.filter(b=>b.type===i).map(b=>({value:b.name,label:b.name})))||[],value:t.componentName,onValueChange:b=>{console.log("changing value",b),l({...t,componentName:b})}})})]})})]})})}),e.jsx(s.Separator,{className:"my-4"}),((y=r==null?void 0:r.customCardPreferences)==null?void 0:y.componentName)&&e.jsxs(xe,{summary:"Component Settings",children:[p&&p.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:f(p)})]}),p&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:h(p)})})]})]})}function ie(){const[t,n]=C.useState([]);s.useEditorStore(u=>u.card.cfg);const a=s.useEditorStore(u=>u.card.preferences),{setCardCfg:r,setFilterOnClickColumnIndex:o,setCardPreferences:i}=s.useEditorStore(u=>u.actions),l=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var f;return(f=u.card.preferences)==null?void 0:f.filterOnClickColumnIndex}),C.useEffect(()=>{l&&n(new Array(l.length).fill(!1))},[l]);function c(u,f){var x,h;f?a!=null&&a.onClickFilter&&((x=a==null?void 0:a.onClickFilter)==null?void 0:x.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):i({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(i({...a,onClickFilter:(h=a==null?void 0:a.onClickFilter)==null?void 0:h.filter(g=>g.columnIndex!==u)}),n(g=>{const j=[...g];return j[u]=!1,j}))}function d(u,f){var h;const x=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(g=>g.columnIndex===u?{...g,expression:f.target.value}:g);i({...a,onClickFilter:x})}function p(u){var f,x,h,g;if(t!=null&&t[u]||(x=(f=a==null?void 0:a.onClickFilter)==null?void 0:f.find(j=>j.columnIndex===u))!=null&&x.expression)return e.jsx(s.Input,{value:(g=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(j=>j.columnIndex===u))==null?void 0:g.expression,onChange:j=>d(u,j),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"On Click"}),l==null?void 0:l.map((u,f)=>{var x,h;return e.jsx("div",{className:"xbg-red-100 group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((x=a==null?void 0:a.onClickFilter)!=null&&x.find(g=>g.columnIndex===f)),onCheckedChange:g=>c(f,g)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(g=>g.columnIndex===f))&&e.jsx(s.Pencil,{onClick:()=>{n(g=>{const j=[...g];return j[f]=!g[f],j})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),p(f)]})},u)})]})}function Wt({idx:t}){var c;const n=s.useEditorStore(d=>{var p;return(p=d.card)==null?void 0:p.preferences}),a=s.useEditorStore(d=>{var p;return(p=d.card.preferences)==null?void 0:p.datasetOptions}),r=s.useEditorStore(d=>d.actions.setCardPreferences),o=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,i=a==null?void 0:a.find(d=>d.idx===t);function l(d,p){(d==="end"||d==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:d!=="none",align:d,anchor:d,clamp:!0};if(!i)r({...n,datasetOptions:[...a||[],{idx:p,datalabels:u}]});else{const f={...i};f.datalabels=u;const x=a==null?void 0:a.map(h=>h.idx===p?f:h);r({...n,datasetOptions:x})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(at,{className:"invisible size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"})}),e.jsx(s.PopoverContent,{className:"w-fit p-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(s.Button,{onClick:()=>l("none",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-4"})}),e.jsx(s.Button,{onClick:()=>l("start",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(_s,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("center",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Gs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})}),e.jsx(s.Button,{onClick:()=>l("end",t),size:"sm",variant:"secondary",className:"h-7 p-1 text-xs font-normal",children:e.jsx(Hs,{className:s.cn("h-4 w-4",{"rotate-90":o==="y"})})})]})})]})}function ms(){const t=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>{var u,f,x;return(x=(f=(u=p==null?void 0:p.card)==null?void 0:u.preferences)==null?void 0:f.chartOptions)==null?void 0:x.indexAxis}),{data:a}=s.useDashboardCardQuery(t),r=n==="y"?"Y axis":"X axis",o=n==="y"?"X axis":"Y axis",{keys:i,metricKeys:l,dimensionKeys:c}=s.getKeys((a==null?void 0:a.records)||[]);let d=l;if(["stackedBar","stackedLine"].includes(t.type)){const p=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:c[0],pivotKey:c[1],valueKey:d[0]}),{metricKeys:u}=s.getKeys(p);d=u}return i.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"my-1 space-y-1",children:e.jsx("div",{className:"rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:e.jsx("p",{title:c[0],children:xs(c[0])})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:o}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:d.map((p,u)=>e.jsx(Kt,{col:p,idx:u},p))})]})]})}function xs(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Kt({col:t,idx:n}){const a=s.useEditorStore(c=>{var d;return(d=c.card)==null?void 0:d.preferences}),r=s.useEditorStore(c=>{var d;return(d=c.card.preferences)==null?void 0:d.datasetOptions}),o=r==null?void 0:r.find(c=>c.idx===n),{setCardPreferences:i}=s.useEditorStore(c=>c.actions);function l(c){if(!o)i({...a,datasetOptions:[...r||[],{idx:n,type:c==="area"?"line":c,fill:c==="area"?"origin":""}]});else{const d={...o};d.type=c==="area"?"line":c,d.fill=c==="area"?"origin":"";const p=r==null?void 0:r.map(u=>u.idx===n?d:u);i({...a,datasetOptions:p})}}return e.jsxs("div",{className:"group flex items-center justify-between gap-5 rounded-md bg-muted/70 px-3 py-2 hover:bg-muted",children:[e.jsx("p",{title:t,children:xs(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ne,{onClick:()=>l("bar"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(ke,{onClick:()=>l("line"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Es,{onClick:()=>l("area"),className:"invisible size-4 cursor-pointer text-muted-foreground hover:text-foreground group-hover:visible"}),e.jsx(Wt,{idx:n})]})]})}function ps(){const t=s.useEditorStore(h=>h.selectedConnectionId),n=s.useEditorStore(h=>h.selectedDatamodelId),a=s.useEditorStore(h=>h.selectedDatabaseName),r=s.useEditorStore(h=>h.selectedSchemaName),o=s.useEditorStore(h=>h.selectedTableName),i=s.useDashboardStore(h=>h.dashboard.filters)||[],l=s.useDashboardStore(h=>h.actions.addFilter),c=s.useDashboardStore(h=>h.actions.removeFilter),{removeFilterValues:d}=s.useDashboardActions(),{modelItems:p,tableName:u,connectionType:f}=ae();function x(h,g="dashboard"){var q;const j=s.fmt(h.column_name),y=s.fmt(a||""),b=s.fmt(r||""),w=s.fmt(u);let v=s.getQualifiedTableName(b,w,f),D=`${v}.${j}`;const T=(q=p==null?void 0:p.find(V=>V.id===n))==null?void 0:q.name;n&&n!=="none"&&(D=`${s.DATAMODEL_NAMESPCACE}.${T}.${j}`,v=`${s.DATAMODEL_NAMESPCACE}.${T}`);const F=i==null?void 0:i.find(V=>V.column===D&&V.table===w&&(V.database===y||V.database===a));if(F)d(F.id),c(F.id);else{const V=s.v4();return u==="api"&&t?(l({location:g,id:V,column:D,title:h.column_name,dataType:h.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(h.data_type,v,j)}),V):(l({id:V,location:g,column:D,title:h.column_name,dataType:h.data_type,table:o||"",database:a||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(h.data_type,v,j)}),V)}}return{assignFilter:x}}function he(){const t=s.useDashboardStore(c=>c.dashboard.filters),n=s.useEditorStore(c=>c.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=ae(),{assignFilter:o}=ps();function i(c){const d=o(c,"frame");a({...n,filterId:d})}const l=t==null?void 0:t.find(c=>c.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Xt,{onSelect:i,columns:r}),l&&e.jsx(s.FilterHeader,{filter:l})]})}function Xt({columns:t,onSelect:n}){var l;const[a,r]=de.useState(!1),[o,i]=de.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between font-normal",children:[o?(l=t.find(c=>c.column_name===o))==null?void 0:l.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t.map(c=>e.jsxs(s.CommandItem,{value:c.column_name,onSelect:d=>{const p=d===o?"":d;i(p),r(!1),p&&n(c)},children:[c.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",o===c.column_name?"opacity-100":"opacity-0")})]},c.column_name))})]})]})})]})}function Zt({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:n=>n.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(ms,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function Ee(){var o,i,l;const t=s.useEditorStore(c=>c.card.cfg),n=s.useEditorStore(c=>c.actions.setCardCfg),a=s.useEditorStore(c=>c.card.type);function r(c){var u;const d={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},p={...t,options:{...t==null?void 0:t.options,plugins:{...(u=t==null?void 0:t.options)==null?void 0:u.plugins,...d}}};n(p),console.log(c)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:(l=(i=(o=t==null?void 0:t.options)==null?void 0:o.plugins)==null?void 0:i.datalabels)==null?void 0:l.anchor,onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),a!=="pyramid"&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function Yt({cardType:t}){function n(a){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:a==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),a==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:n(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(Ee,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}const ea={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},sa={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function ta(){const t=s.useEditorStore(n=>n.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:aa(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Ee,{}),e.jsx(ie,{}),e.jsx(he,{})]})]})}function aa(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(ea,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(sa,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function na(){var d,p,u,f,x;const t=s.useEditorStore(h=>h.card.preferences),n=s.useEditorStore(h=>h.actions.setCardPreferences),a=s.useEditorStore(h=>h.actions.setNumberFormat);s.useEditorStore(h=>{var g,j;return(j=(g=h.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.decimalPlaces});const r=s.useEditorStore(h=>{var g,j;return(j=(g=h.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.locale}),o=s.useEditorStore(h=>{var g,j;return(j=(g=h.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.currency});s.useEditorStore(h=>h.actions.setFilterOnClickField);const i=s.useEditorStore(h=>{var g,j;return(j=(g=h.card.preferences)==null?void 0:g.formatNumber)==null?void 0:j.colorRanges})||[],l=s.useEditorStore(h=>h.actions.setColorRanges),c=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(h=>h.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((d=t==null?void 0:t.formatNumber)!=null&&d.enabled),onCheckedChange:h=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:h}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((p=t==null?void 0:t.formatNumber)==null?void 0:p.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:h=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",h,((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(h=>e.jsx(s.SelectItem,{value:h.locale,children:h.locale},h.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:o||"none",onValueChange:h=>{var g,j,y;console.log("currency",h),a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,h==="none"?"":h,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),c.map(h=>e.jsx(s.SelectItem,{value:h,children:h},h))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Decimals"}),e.jsxs(s.Select,{value:((f=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:f.toString())||"0",onValueChange:h=>{var g,j,y;return a(Number(h),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(h=>e.jsx(s.SelectItem,{value:h,children:h},h))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((x=t==null?void 0:t.formatNumber)==null?void 0:x.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:h=>{var g,j,y;return a(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.locale)||"",h.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:i,setColorRanges:l})]})]})}function ra(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(na,{})}),e.jsx("div",{}),e.jsx("div",{})]})}const oa=[{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"}],ia=["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"],la=ia.map(t=>({label:t,value:t}));function ca(){var d,p,u,f,x,h,g,j,y,b,w,v,D,T,F,q,V,P;const t=s.useEditorStore(m=>m.card),n=(p=(d=t==null?void 0:t.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:p.topoJsonUrl,[a,r]=C.useState(((f=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:f.customTopoJsonUrl)||""),{setCardPreferences:o}=s.useEditorActions(),{data:i}=s.useTopoJson(t),l=Object.keys((i==null?void 0:i.objects)||{}).map(m=>({label:m,value:m}))||[],c=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(xe,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(se,{className:"h-9",options:c,onValueChange:m=>{console.log("value",m),o({...t.preferences,mapVisualOptions:{topoJsonUrl:m}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:m=>{r(m.target.value)},onBlur:()=>{var m;console.log("onBlur",a),o({...t.preferences,mapVisualOptions:{...(m=t.preferences)==null?void 0:m.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(se,{className:"h-9",options:l,value:((h=(x=t.preferences)==null?void 0:x.mapVisualOptions)==null?void 0:h.objectKey)||"",label:"Map Object",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,objectKey:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(se,{className:"h-9",options:oa,value:((j=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:j.projection)||"",label:"Projection",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projection:m}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(se,{className:"h-9",options:la,value:((b=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:b.colorScale)||"",label:"Select Color Scale",onValueChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,colorScale:m}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(xe,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((v=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:v.projectionScale)||1,onChange:m=>{var A;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionScale:Number(m.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((F=(T=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:T.projectionOffset)==null?void 0:F[0])||0,onChange:m=>{var A,_,z,B;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[Number(m.target.value),((B=(z=(_=t.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((P=(V=(q=t.preferences)==null?void 0:q.mapVisualOptions)==null?void 0:V.projectionOffset)==null?void 0:P[1])||0,onChange:m=>{var A,_,z,B;o({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,projectionOffset:[((B=(z=(_=t.preferences)==null?void 0:_.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:B[0])||0,Number(m.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ie,{})]})}function da(){var r;const t=s.useEditorStore(o=>o.card.preferences),{setCardPreferences:n}=s.useEditorStore(o=>o.actions);function a(o){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:o==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:a,className:"flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"static",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Static"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function je({cardType:t,docContent:n,suffix:a="Chart"}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${a}`}),e.jsx(s.AccordionContent,{children:n||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar",children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(Ee,{}),t==="text"&&e.jsx(da,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function ua(){const t=s.useEditorStore(r=>{var o,i;return(i=(o=r==null?void 0:r.card)==null?void 0:o.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();function a(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(se,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{n(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[a(),e.jsx(ms,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})]})})}function ha({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(o=>{var i;return(i=o.card)==null?void 0:i.preferences}),a=s.useEditorStore(o=>o.actions.setCardPreferences),r=o=>{a({...n,allowDownload:o})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(ie,{}),e.jsx(he,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const ma=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),xa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),pa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function fa(){const t=s.useEditorStore(a=>a.card.type);function n(a){switch(a){case"stackedBar":case"stackedLine":return e.jsx(ua,{});case"pyramid":return e.jsx(je,{docContent:ma,cardType:a});case"kpi":return e.jsx(ra,{});case"line":case"bar":return e.jsx(Zt,{cardType:a});case"range":return e.jsx(je,{docContent:xa,cardType:a});case"pie":case"doughnut":case"polarArea":case"radar":return e.jsx(je,{cardType:a});case"bubble":case"scatter":return e.jsx(Yt,{cardType:a});case"table":return e.jsx(ha,{cardType:a});case"text":return e.jsx(je,{docContent:pa,cardType:a,suffix:"Visual"});case"map":return e.jsx(ca,{});case"custom":return e.jsx(Jt,{});default:return e.jsx(ta,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function ga(){const t=C.useRef(null),n=s.useEditorStore(r=>r.isShowingVisual),a=s.useEditorStore(r=>r.showAIDialog);return C.useEffect(()=>{var r,o;a?(r=t.current)==null||r.resize(0):(o=t.current)==null||o.resize(25)},[a]),e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(Dt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!a?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:t,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(fa,{})})}),!a&&e.jsx(s.ResizableHandle,{className:"border"}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(qe,{})})]}):e.jsx(qe,{})})]})}const ja=!1,ba=[{title:"Write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function ya(){const t=C.useRef(null),n=C.useRef(null),[a,r]=C.useState(!1),[o,i]=C.useState(ja),[l,c]=C.useState(!1),d=s.useEditorStore(I=>I.actions.setCardSql),p=s.useEditorStore(I=>I.actions.setRunSql),u=s.useEditorStore(I=>I.showAIDialog),{setShowAIDialog:f}=s.useEditorActions(),{messages:x,setMessages:h,reload:g,append:j,input:y,setInput:b,isLoading:w,handleAddCurrentTableToScope:v,removeFromCurrentSelections:D,currentAssitantScope:T,handleInputChange:F,handleSubmit:q,stop:V,chatStatus:P,toolStatus:m,llmUsage:A}=rs();s.useAssistantScroll({scrollContainerRef:t,inputRef:n,messages:x}),C.useEffect(()=>{var I;u&&((I=n.current)==null||I.focus())},[u]);function _(I){d(I),p(!0)}function z(I){const O={role:"user",content:I.title+" "+I.subtitle};j(O)}function B(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(Ue,{className:"size-3.5 text-muted-foreground/70 hover:text-muted-foreground"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:a,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:c,children:"System Message"})]})]})}function S(){return e.jsxs("div",{"data-role":"header",children:[e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"}),T&&T.length>0&&e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context:"}),T==null?void 0:T.map((I,O)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:I.schemaName||"",tableName:I.tableName||"",modelName:I.datamodelName||"",connectionType:I.connectionType||""}),e.jsx("button",{onClick:()=>{D(I)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},O))]}),(T==null?void 0:T.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:v,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}const M=(y==null?void 0:y.length)===0&&(x==null?void 0:x.filter(I=>I.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[S(),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[B(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{h([]),g()},children:e.jsx(s.RefreshCcw,{className:"size-3.5 text-muted-foreground"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{f(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:t,className:"flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:x,showTools:o,handleRun:_,showSystemMessage:l}),e.jsx(s.ChatStatus,{status:s.getStatus(P,m),isLoading:w})]})}),M&&e.jsx(s.Placeholders,{onClick:z,placeholders:ba}),e.jsx(s.ChatInput,{stop:V,ref:n,setInput:b,input:y,handleInputChange:F,handleSubmit:q,isLoading:w}),A&&a&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",A.promptTokens," prompt tokens,"," ",A.completionTokens," completion tokens,"," ",A.totalTokens," total tokens"]})})]})}function Sa({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null),o=s.useEditorStore(f=>f.showAIDialog),{setAuthToken:i}=s.useDashboardActions(),{setShowAIDialog:l,setOnSave:c,setOnClose:d}=s.useEditorActions();C.useEffect(()=>{n&&c(n),a&&d(a)},[n,c,a,d]),C.useEffect(()=>{t&&t.accessToken&&i(t)},[t,i]),C.useEffect(()=>{var f,x;o?((f=r.current)==null||f.resize(40),l(!0)):(l(!1),(x=r.current)==null||x.resize(0))},[o,l]);function p(f){f<1?l(!1):o||l(!0)}function u(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none border-x-[1px]",children:e.jsx(ga,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:p,defaultSize:0,children:e.jsx(ya,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs("section",{className:"flex h-full grow","data-content":"editor-panel",children:[e.jsx(ss,{}),u()]})})}function Ca(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(l=>l.actions),a=s.useDashboardStore(l=>l.isVisualEditing),r=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){t&&(r(t,l),n(!1))}function i(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!a}),children:e.jsx(Sa,{onSave:o,onClose:i})})}function va(){const t=s.useEditorStore(i=>i.selectedDatabaseName),n=s.useEditorStore(i=>i.selectedTableName),a=s.useDashboardStore(i=>i.dashboard.filters)||[],{columns:r}=ae(),{assignFilter:o}=ps();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(i=>{const l=a==null?void 0:a.find(c=>c.column===s.fmt(i.column_name)&&c.table===n&&c.database===t);return e.jsx("div",{onClick:()=>o(i),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{column:i}),e.jsx("span",{children:i.column_name})]})},i.column_name)})})}function Na(){s.useDashboardStore(n=>n.showFilters);const t=s.useDashboardStore(n=>n.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(ss,{ColumnsComponent:()=>e.jsx(va,{})})})]})}function ka(){const t=s.useDashboardStore(r=>r.dashboard.filters),n=s.useDashboardStore(r=>r.theme),a=t==null?void 0:t.filter(r=>r.hide);return a!=null&&a.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":n==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":n==="dark"}),children:a==null?void 0:a.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function wa(){const t=s.useDashboardStore(r=>r.showFilters),n=s.useDashboardStore(r=>r.isVisualEditing),a=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":n,"flex grow overflow-auto":!n}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[a&&e.jsx(ka,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(Na,{})})]})}function Ia(){const t=s.useDashboardStore(o=>o.dashboard),n=s.useDashboardStore(o=>o.actions.setDashboard),a=s.useDashboardStore(o=>o.showDashboardJSON),r=s.useDashboardStore(o=>o.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!a}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:o=>{if(o)try{JSON.parse(o),n(JSON.parse(o))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function Ea({showControls:t=!1,showFooter:n=!0,...a}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:a,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(Ia,{}),e.jsxs(s.DashboardPanel,{...a,children:[t&&e.jsx(ht,{}),e.jsx(Ca,{}),e.jsx(wa,{})]})]})]})})}exports.Dashboard=s.Dashboard;exports.DashboardWC=s.DashboardWC;exports.SemaphorDataProvider=s.SemaphorQueryClient;exports.SemaphorQueryClient=s.SemaphorQueryClient;exports.createSqlGenConfig=s.createSqlGenConfig;exports.fmt=s.fmt;exports.getColumnDataType=s.getColumnDataType;exports.getFilterValueType=s.getFilterValueType;exports.getFormattedTableNameForQuery=s.getFormattedTableNameForQuery;exports.getQualifiedTableName=s.getQualifiedTableName;exports.getSql=s.getSql;exports.invalidateToken=s.invalidateToken;exports.isBooleanDataType=s.isBooleanDataType;exports.isColumnInSqlGen=s.isColumnInSqlGen;exports.isDateDataType=s.isDateDataType;exports.isNumberDataType=s.isNumberDataType;exports.isTextDataType=s.isTextDataType;exports.resolveDataType=s.resolveDataType;exports.resolveDatamodelName=s.resolveDatamodelName;exports.useCard=s.useCard;exports.useDashboardActions=s.useDashboardActions;exports.useDashboardStore=s.useDashboardStore;exports.useDateFilterHook=s.useDateFilterHook;exports.useEditorActions=s.useEditorActions;exports.useEditorStore=s.useEditorStore;exports.useTextFilterHook=s.useTextFilterHook;exports.SelectComponent=ce;exports.Surfboard=Ea;exports.cleanCard=Ze;exports.downloadPdf=Ye;exports.getDashbaordStateWithoutData=Ie;exports.useEditorAside=ae;