react-semaphor 0.1.230 → 0.1.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{dashboard-controls-CIGGC81u.js → dashboard-controls-SOpHBByc.js} +1 -1
- package/dist/chunks/{dashboard-controls-uZZf2_Ms.js → dashboard-controls-tnUmHLSV.js} +4 -4
- package/dist/chunks/{dashboard-json-BSpSg-pF.js → dashboard-json-CNDfi0P6.js} +1 -1
- package/dist/chunks/{dashboard-json-BPOoq2o2.js → dashboard-json-dyymHGsv.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-BBOnX1vh.js → dashboard-summary-settings-dialog-DcPp_DEu.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-Dd-wAZsI.js → dashboard-summary-settings-dialog-o10AVX0D.js} +1 -1
- package/dist/chunks/edit-dashboard-visual-BtcoMBCD.js +182 -0
- package/dist/chunks/{edit-dashboard-visual-CmKLavr8.js → edit-dashboard-visual-CRzA5DmH.js} +3609 -3339
- package/dist/chunks/{editor-action-buttons-ujerALSP.js → editor-action-buttons-BfBZreSZ.js} +2 -2
- package/dist/chunks/{editor-action-buttons-DicV0M4e.js → editor-action-buttons-BvLi-Lae.js} +1 -1
- package/dist/chunks/index-DJfl6pgs.js +1103 -0
- package/dist/chunks/{index-SLQXKi01.js → index-DgPGwxyE.js} +22677 -22178
- package/dist/chunks/{notification-bell-BlKABlIE.js → notification-bell-C4btgW0w.js} +1 -1
- package/dist/chunks/{notification-bell-D83sUTTI.js → notification-bell-DFBFOSta.js} +3 -3
- package/dist/chunks/{resource-management-panel-TqjX5FH0.js → resource-management-panel-4MFuRJfU.js} +1 -1
- package/dist/chunks/{resource-management-panel-CJXZMjqO.js → resource-management-panel-DGe1EYhD.js} +2 -2
- package/dist/chunks/{use-visual-utils-DNfxkGiH.js → use-visual-utils-BZodveic.js} +1 -1
- package/dist/chunks/{use-visual-utils-CjUf9Xns.js → use-visual-utils-Cwqe0LWA.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +40 -3
- package/dist/types/main.d.ts +40 -3
- package/dist/types/shared.d.ts +40 -3
- package/dist/types/surfboard.d.ts +40 -3
- package/dist/types/types.d.ts +40 -3
- package/package.json +1 -1
- package/dist/chunks/edit-dashboard-visual-D0myN7lC.js +0 -182
- package/dist/chunks/index-BKtY-D8Y.js +0 -1103
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DJfl6pgs.js"),C=require("react"),Ie=require("./editor-action-buttons-BvLi-Lae.js"),tn=require("react-dom");function an(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 Ks=an(C);/**
|
|
2
|
+
* @license lucide-react v0.453.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const nn=s.createLucideIcon("ArrowDownAZ",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
|
|
7
|
+
* @license lucide-react v0.453.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const rn=s.createLucideIcon("ArrowUpAZ",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M20 8h-5",key:"1vsyxs"}],["path",{d:"M15 10V6.5a2.5 2.5 0 0 1 5 0V10",key:"ag13bf"}],["path",{d:"M15 14h5l-5 6h5",key:"ur5jdg"}]]);/**
|
|
12
|
+
* @license lucide-react v0.453.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const xa=s.createLucideIcon("Blocks",[["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["path",{d:"M10 21V8a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-5a1 1 0 0 0-1-1H3",key:"1fpvtg"}]]);/**
|
|
17
|
+
* @license lucide-react v0.453.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Js=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"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const ln=s.createLucideIcon("Component",[["path",{d:"M15.536 11.293a1 1 0 0 0 0 1.414l2.376 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1uwlt4"}],["path",{d:"M2.297 11.293a1 1 0 0 0 0 1.414l2.377 2.377a1 1 0 0 0 1.414 0l2.377-2.377a1 1 0 0 0 0-1.414L6.088 8.916a1 1 0 0 0-1.414 0z",key:"10291m"}],["path",{d:"M8.916 17.912a1 1 0 0 0 0 1.415l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.415l-2.377-2.376a1 1 0 0 0-1.414 0z",key:"1tqoq1"}],["path",{d:"M8.916 4.674a1 1 0 0 0 0 1.414l2.377 2.376a1 1 0 0 0 1.414 0l2.377-2.376a1 1 0 0 0 0-1.414l-2.377-2.377a1 1 0 0 0-1.414 0z",key:"1x6lto"}]]);/**
|
|
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 ha=s.createLucideIcon("FileCode2",[["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:"m5 12-3 3 3 3",key:"oke12k"}],["path",{d:"m9 18 3-3-3-3",key:"112psh"}]]);/**
|
|
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 on=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"}]]);/**
|
|
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 cn=s.createLucideIcon("Fullscreen",[["path",{d:"M3 7V5a2 2 0 0 1 2-2h2",key:"aa7l1z"}],["path",{d:"M17 3h2a2 2 0 0 1 2 2v2",key:"4qcy5o"}],["path",{d:"M21 17v2a2 2 0 0 1-2 2h-2",key:"6vwrx8"}],["path",{d:"M7 21H5a2 2 0 0 1-2-2v-2",key:"ioqczr"}],["rect",{width:"10",height:"8",x:"7",y:"8",rx:"1",key:"vys8me"}]]);/**
|
|
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 pa=s.createLucideIcon("GitCompareArrows",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"M12 18H7a2 2 0 0 1-2-2V9",key:"16sdep"}],["path",{d:"m9 15 3 3-3 3",key:"1m3kbl"}]]);/**
|
|
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 dn=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"}]]);/**
|
|
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 un=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"}]]);/**
|
|
57
|
+
* @license lucide-react v0.453.0 - ISC
|
|
58
|
+
*
|
|
59
|
+
* This source code is licensed under the ISC license.
|
|
60
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
+
*/const mn=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"}]]);/**
|
|
62
|
+
* @license lucide-react v0.453.0 - ISC
|
|
63
|
+
*
|
|
64
|
+
* This source code is licensed under the ISC license.
|
|
65
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
+
*/const _t=s.createLucideIcon("ListFilter",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/**
|
|
67
|
+
* @license lucide-react v0.453.0 - ISC
|
|
68
|
+
*
|
|
69
|
+
* This source code is licensed under the ISC license.
|
|
70
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
+
*/const xn=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"}]]);/**
|
|
72
|
+
* @license lucide-react v0.453.0 - ISC
|
|
73
|
+
*
|
|
74
|
+
* This source code is licensed under the ISC license.
|
|
75
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
+
*/const hn=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"}]]);/**
|
|
77
|
+
* @license lucide-react v0.453.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const Rs=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"}]]);/**
|
|
82
|
+
* @license lucide-react v0.453.0 - ISC
|
|
83
|
+
*
|
|
84
|
+
* This source code is licensed under the ISC license.
|
|
85
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
+
*/const Fs=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"}]]);/**
|
|
87
|
+
* @license lucide-react v0.453.0 - ISC
|
|
88
|
+
*
|
|
89
|
+
* This source code is licensed under the ISC license.
|
|
90
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
+
*/const pn=s.createLucideIcon("Palette",[["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.554C21.965 6.012 17.461 2 12 2z",key:"12rzf8"}]]);/**
|
|
92
|
+
* @license lucide-react v0.453.0 - ISC
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the ISC license.
|
|
95
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/const fn=s.createLucideIcon("PanelRightClose",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}],["path",{d:"m8 9 3 3-3 3",key:"12hl5m"}]]);/**
|
|
97
|
+
* @license lucide-react v0.453.0 - ISC
|
|
98
|
+
*
|
|
99
|
+
* This source code is licensed under the ISC license.
|
|
100
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
+
*/const gn=s.createLucideIcon("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
102
|
+
* @license lucide-react v0.453.0 - ISC
|
|
103
|
+
*
|
|
104
|
+
* This source code is licensed under the ISC license.
|
|
105
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
+
*/const Gt=s.createLucideIcon("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);/**
|
|
107
|
+
* @license lucide-react v0.453.0 - ISC
|
|
108
|
+
*
|
|
109
|
+
* This source code is licensed under the ISC license.
|
|
110
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
+
*/const Ss=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"}]]);/**
|
|
112
|
+
* @license lucide-react v0.453.0 - ISC
|
|
113
|
+
*
|
|
114
|
+
* This source code is licensed under the ISC license.
|
|
115
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
+
*/const jn=s.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
|
|
117
|
+
* @license lucide-react v0.453.0 - ISC
|
|
118
|
+
*
|
|
119
|
+
* This source code is licensed under the ISC license.
|
|
120
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
+
*/const bn=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"}]]);/**
|
|
122
|
+
* @license lucide-react v0.453.0 - ISC
|
|
123
|
+
*
|
|
124
|
+
* This source code is licensed under the ISC license.
|
|
125
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
+
*/const Us=s.createLucideIcon("SlidersHorizontal",[["line",{x1:"21",x2:"14",y1:"4",y2:"4",key:"obuewd"}],["line",{x1:"10",x2:"3",y1:"4",y2:"4",key:"1q6298"}],["line",{x1:"21",x2:"12",y1:"12",y2:"12",key:"1iu8h1"}],["line",{x1:"8",x2:"3",y1:"12",y2:"12",key:"ntss68"}],["line",{x1:"21",x2:"16",y1:"20",y2:"20",key:"14d8ph"}],["line",{x1:"12",x2:"3",y1:"20",y2:"20",key:"m0wm8r"}],["line",{x1:"14",x2:"14",y1:"2",y2:"6",key:"14e1ph"}],["line",{x1:"8",x2:"8",y1:"10",y2:"14",key:"1i6ji0"}],["line",{x1:"16",x2:"16",y1:"18",y2:"22",key:"1lctlv"}]]);/**
|
|
127
|
+
* @license lucide-react v0.453.0 - ISC
|
|
128
|
+
*
|
|
129
|
+
* This source code is licensed under the ISC license.
|
|
130
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
+
*/const vn=s.createLucideIcon("Spline",[["circle",{cx:"19",cy:"5",r:"2",key:"mhkx31"}],["circle",{cx:"5",cy:"19",r:"2",key:"v8kfzx"}],["path",{d:"M5 17A12 12 0 0 1 17 5",key:"1okkup"}]]);/**
|
|
132
|
+
* @license lucide-react v0.453.0 - ISC
|
|
133
|
+
*
|
|
134
|
+
* This source code is licensed under the ISC license.
|
|
135
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
136
|
+
*/const yn=s.createLucideIcon("SquareFunction",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3",key:"m1af9g"}],["path",{d:"M9 11.2h5.7",key:"3zgcl2"}]]);/**
|
|
137
|
+
* @license lucide-react v0.453.0 - ISC
|
|
138
|
+
*
|
|
139
|
+
* This source code is licensed under the ISC license.
|
|
140
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
141
|
+
*/const Nn=s.createLucideIcon("SquareSplitVertical",[["path",{d:"M5 8V5c0-1 1-2 2-2h10c1 0 2 1 2 2v3",key:"1pi83i"}],["path",{d:"M19 16v3c0 1-1 2-2 2H7c-1 0-2-1-2-2v-3",key:"ido5k7"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]]);/**
|
|
142
|
+
* @license lucide-react v0.453.0 - ISC
|
|
143
|
+
*
|
|
144
|
+
* This source code is licensed under the ISC license.
|
|
145
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
146
|
+
*/const Cn=s.createLucideIcon("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]);/**
|
|
147
|
+
* @license lucide-react v0.453.0 - ISC
|
|
148
|
+
*
|
|
149
|
+
* This source code is licensed under the ISC license.
|
|
150
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
151
|
+
*/const Sn=s.createLucideIcon("Wand",[["path",{d:"M15 4V2",key:"z1p9b7"}],["path",{d:"M15 16v-2",key:"px0unx"}],["path",{d:"M8 9h2",key:"1g203m"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M17.8 11.8 19 13",key:"yihg8r"}],["path",{d:"M15 9h.01",key:"x1ddxp"}],["path",{d:"M17.8 6.2 19 5",key:"fd4us0"}],["path",{d:"m3 21 9-9",key:"1jfql5"}],["path",{d:"M12.2 6.2 11 5",key:"i3da3b"}]]);function fa({storeValue:t,defaultValue:n="",onStoreUpdate:a,delay:r=300}){const[i,d]=C.useState(t??n),o=s.useDebounce(i,r),c=C.useRef(t),l=C.useRef(!1);C.useEffect(()=>{t!==c.current&&(d(t??n),c.current=t)},[t,n]),C.useEffect(()=>{l.current&&o!==c.current&&(a(o),c.current=o)},[o,a]);const x=C.useCallback(p=>{l.current=!0,d(p??n)},[n]);return{value:i,onChange:x}}function wn({initialJoinPlan:t,availableDataSources:n}){const[a,r]=C.useState(t),[i,d]=C.useState(new Set),o=()=>{const j=a.joins.length>0?Math.max(...a.joins.map(I=>I.sequence))+1:1,k={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:j,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...a,joins:[...a.joins,k]}),d(new Set([...i,k.id]))},c=j=>{r({...a,joins:a.joins.filter(k=>k.id!==j)}),d(new Set([...i].filter(k=>k!==j)))},l=(j,k)=>{var D,M,P,N,O;const I=a.joins.find(S=>S.id===j);if(!I)return;const f={...I,...k};if((D=f.source)!=null&&D.name&&((M=f.target)!=null&&M.name)&&f.source.name===f.target.name){s.ue.error("Self-joins are not yet supported",{description:`Joining ${f.source.name} to itself is not currently supported. Please select a different target table.`});return}const A=a.joins.filter(S=>{var R;return S.id!==j&&S.target.name===((R=f.target)==null?void 0:R.name)});if((P=f.target)!=null&&P.name&&A.length>0){s.ue.error("Duplicate join targets are not supported",{description:`The table ${f.target.name} is already used as a target in another join. Each table can only be joined once.`});return}const g=a.joins.map(S=>S.id===j?f:S);if((N=f.source)!=null&&N.name&&((O=f.target)!=null&&O.name)&&f.joinKeyGroups[0].keys.length===0){const S=n.find(U=>{var z;return U.name===((z=f.source)==null?void 0:z.name)}),R=n.find(U=>{var z;return U.name===((z=f.target)==null?void 0:z.name)}),F={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(S==null?void 0:S.name)||"",entityName:(S==null?void 0:S.name)||"",entityType:(S==null?void 0:S.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(R==null?void 0:R.name)||"",entityName:(R==null?void 0:R.name)||"",entityType:(R==null?void 0:R.type)||"table"},operator:"="},$=[...f.joinKeyGroups];$[0]={...$[0],keys:[F]},f.joinKeyGroups=$,g[g.findIndex(U=>U.id===j)]=f}r({...a,joins:g})};return{joinPlan:a,expandedJoins:i,setJoinPlan:r,addJoin:o,removeJoin:c,updateJoin:l,moveJoinUp:j=>{const k=a.joins.findIndex(I=>I.id===j);if(k>0){const I=[...a.joins],f={...I[k]},A={...I[k-1]};I[k]=A,I[k-1]=f,I.forEach((D,M)=>{D.sequence=M+1});const g={...a,joins:I};r(g)}},moveJoinDown:j=>{const k=a.joins.findIndex(I=>I.id===j);if(k<a.joins.length-1){const I=[...a.joins],f={...I[k]},A={...I[k+1]};I[k]=A,I[k+1]=f,I.forEach((D,M)=>{D.sequence=M+1});const g={...a,joins:I};r(g)}},toggleJoinExpansion:j=>{const k=new Set(i);k.has(j)?k.delete(j):k.add(j),d(k)},getAvailableSourceEntities:j=>{if(a.joins.length===0)return n;const k=a.joins.findIndex(f=>f.id===j);if(k===0)return n.filter(f=>f.name===a.baseEntity.name);const I=new Set;return a.baseEntity.name&&I.add(a.baseEntity.name),a.joins.slice(0,k).forEach(f=>{I.add(f.source.name),I.add(f.target.name)}),n.filter(f=>I.has(f.name))},getAvailableTargetEntities:j=>n.filter(k=>k.name!==j),addJoinKeyGroup:j=>{const k=a.joins.find(f=>f.id===j);if(!k)return;const I=[...k.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];l(j,{joinKeyGroups:I})},updateGroupOperator:(j,k,I)=>{const f=a.joins.find(g=>g.id===j);if(!f)return;const A=[...f.joinKeyGroups];A[k]={...A[k],operator:I},l(j,{joinKeyGroups:A})},removeJoinKeyGroup:(j,k)=>{const I=a.joins.find(A=>A.id===j);if(!I)return;const f=[...I.joinKeyGroups];f.splice(k,1),l(j,{joinKeyGroups:f})},addJoinKey:(j,k)=>{const I=a.joins.find(M=>M.id===j);if(!I)return;const f=n.find(M=>M.name===I.source.name),A=n.find(M=>M.name===I.target.name),g=[...I.joinKeyGroups],D={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(f==null?void 0:f.name)||"",entityName:(f==null?void 0:f.name)||"",entityType:(f==null?void 0:f.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(A==null?void 0:A.name)||"",entityName:(A==null?void 0:A.name)||"",entityType:(A==null?void 0:A.type)||"table"},operator:"="};g[k]={...g[k],keys:[...g[k].keys,D]},l(j,{joinKeyGroups:g})},updateJoinKey:(j,k,I,f,A)=>{const g=a.joins.find(O=>O.id===j);if(!g)return;const D=n.find(O=>O.name===g.source.name),M=n.find(O=>O.name===g.target.name),P=[...g.joinKeyGroups],N=P[k].keys[I];f==="sourceColumnName"&&D?P[k].keys[I]={...N,source:{...N.source,name:A}}:f==="targetColumnName"&&M?P[k].keys[I]={...N,target:{...N.target,name:A}}:f==="operator"&&(P[k].keys[I]={...N,operator:A}),l(j,{joinKeyGroups:P})},removeJoinKey:(j,k,I)=>{const f=a.joins.find(g=>g.id===j);if(!f)return;const A=[...f.joinKeyGroups];A[k].keys.splice(I,1),l(j,{joinKeyGroups:A})},generateSQLPreview:()=>{const j=[...a.joins].sort((f,A)=>f.sequence-A.sequence),k=a.baseEntity;if(!k.name)return"SELECT * FROM table -- Please select a base entity";let I=`SELECT *
|
|
152
|
+
FROM ${k.name}`;return j.forEach(f=>{const A=n.find(M=>M.name===f.target.name);if(!A)return;const g=f.joinKeyGroups.filter(M=>M.keys&&M.keys.length>0).map(M=>{const P=M.keys.filter(N=>{var O,S,R,F;return((O=N.source)==null?void 0:O.name)&&((S=N.target)==null?void 0:S.name)&&((R=N.source)==null?void 0:R.entityName)&&((F=N.target)==null?void 0:F.entityName)}).map(N=>`${N.source.entityName}.${N.source.name} ${N.operator} ${N.target.entityName}.${N.target.name}`);return P.length>1?`(${P.join(` ${M.operator} `)})`:P[0]}).filter(Boolean),D=g.length>1?g.join(" OR "):g[0]||"condition_here";I+=`
|
|
153
|
+
${f.joinType} JOIN ${A.name}
|
|
154
|
+
ON ${D}`}),I},isValidConfiguration:()=>!(!a.baseEntity.name||a.joins.some(f=>!f.source.name||!f.target.name)||a.joins.some(f=>f.joinKeyGroups.some(A=>A.keys.length===0))||a.joins.some(f=>f.joinKeyGroups.some(A=>A.keys.some(g=>!g.source.name||!g.target.name||!g.operator))))}}function Tn({joinPlan:t,availableDataSources:n,onSave:a,onRemove:r,onCancel:i}){const{setCardConfig:d}=s.useEditorActions();s.useEditorStore(D=>D.card.config);const{columnGroups:o}=s.useColumns(),c=o.filter(D=>D.entityName!==s.CALCULATED_FIELDS_GROUP_NAME),{joinPlan:l,expandedJoins:x,setJoinPlan:p,addJoin:h,removeJoin:m,updateJoin:y,moveJoinUp:v,moveJoinDown:u,toggleJoinExpansion:b,getAvailableSourceEntities:w,getAvailableTargetEntities:T,addJoinKeyGroup:V,updateGroupOperator:L,removeJoinKeyGroup:E,addJoinKey:j,updateJoinKey:k,removeJoinKey:I,generateSQLPreview:f,isValidConfiguration:A}=wn({initialJoinPlan:t,availableDataSources:n}),g=D=>{const M=c.find(P=>P.entityName===D);return(M==null?void 0:M.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:l.baseEntity.name,onValueChange:D=>{const M=n.find(P=>P.name===D);p({...l,baseEntity:{connectionId:(M==null?void 0:M.connectionId)||"",connectionType:(M==null?void 0:M.connectionType)||"none",type:(M==null?void 0:M.type)||"table",name:D,database:M==null?void 0:M.database,schema:M==null?void 0:M.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:n.map(D=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:D.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:D.type}),D.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},D.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:f()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",l.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:h,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),l.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:l.joins.map(D=>{const M=n.find(O=>O.name===D.source.name),P=n.find(O=>O.name===D.target.name),N=x.has(D.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:D.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",D.sequence,M&&P&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",M.name," → ",P.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>v(D.id),disabled:D.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>u(D.id),disabled:D.sequence===l.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>b(D.id),children:N?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>m(D.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),N&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:D.source.name,onValueChange:O=>{const S=n.find(R=>R.name===O);y(D.id,{source:{connectionId:(S==null?void 0:S.connectionId)||"",connectionType:(S==null?void 0:S.connectionType)||"none",type:(S==null?void 0:S.type)||"table",name:O,database:S==null?void 0:S.database,schema:S==null?void 0:S.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:w(D.id).map(O=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:O.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:O.type}),O.name]})},O.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:D.joinType,onValueChange:O=>y(D.id,{joinType:O}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:D.target.name,onValueChange:O=>{const S=n.find(R=>R.name===O);y(D.id,{target:{connectionId:(S==null?void 0:S.connectionId)||"",connectionType:(S==null?void 0:S.connectionType)||"none",type:(S==null?void 0:S.type)||"table",name:O,database:S==null?void 0:S.database,schema:S==null?void 0:S.schema}})},disabled:!D.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:D.source.name?T(D.source.name).map(O=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:O.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:O.type}),O.name,O.name===D.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},O.name)):[]})]})]})]}),D.source.name&&D.target.name&&M&&P&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>V(D.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),D.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:D.joinKeyGroups.map((O,S)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",S+1]}),S>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:O.operator,onValueChange:R=>L(D.id,S,R),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(D.id,S),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[O.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:O.keys.map((R,F)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[F>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:O.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:R.source.name,onValueChange:$=>k(D.id,S,F,"sourceColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:g(D.source.name).map($=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:$.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:$.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:$.dataType})]})},$.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:R.operator,onValueChange:$=>k(D.id,S,F,"operator",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:R.target.name,onValueChange:$=>k(D.id,S,F,"targetColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:g(D.target.name).map($=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:$.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:$.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:$.dataType})]})},$.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>I(D.id,S,F),children:e.jsx(s.X,{className:"size-3.5"})})]},R.id||F))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>j(D.id,S),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},O.id))})]})]})]},D.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),i()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>a(l),disabled:!A(),children:"Save"})]})]})}function ga({children:t,open:n,onOpenChange:a,joinPlan:r,availableDataSources:i,onRemove:d,onSave:o,onCancel:c}){return e.jsxs(s.Dialog,{open:n,onOpenChange:a,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(Tn,{joinPlan:r,availableDataSources:i,onSave:o,onCancel:c,onRemove:d})]}),t]})}function En({joins:t,baseEntityId:n,availableDataSources:a,generateSQLPreview:r}){return e.jsxs("div",{className:"my-2 max-h-[400px] divide-y divide-border overflow-y-auto",children:[t.length>0&&e.jsxs("div",{className:"px-4 py-2",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const i=[...t].sort((o,c)=>o.sequence-c.sequence),d=a.find(o=>o.name===n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:d==null?void 0:d.type}),e.jsx("span",{className:"text-xs font-medium",children:d==null?void 0:d.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),i.map(o=>{const c=a.find(l=>l.name===o.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:o.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:c==null?void 0:c.type}),e.jsx("span",{className:"text-xs font-medium",children:c==null?void 0:c.name})]})]},o.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((i,d)=>i.sequence-d.sequence).map((i,d)=>{const o=a.find(x=>x.name===i.source.name),c=a.find(x=>x.name===i.target.name),l=i.joinKeyGroups.reduce((x,p)=>x+p.keys.length,0);return e.jsxs("div",{className:"rounded-md bg-muted p-2 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:d+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:i.joinType}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto shrink-0 text-xs",children:[l," condition",l>1?"s":""]})]}),e.jsxs("div",{className:"mt-1 truncate pl-1 text-xs text-muted-foreground",children:[o==null?void 0:o.name," → ",c==null?void 0:c.name]})]},i.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function Kt({open:t,onOpenChange:n,variant:a="button"}={}){var T,V;const r=s.useEditorStore(L=>L.card),{autoJoinMetadata:i}=s.useDashboardCardQuery(r),d=s.useEditorStore(L=>L.actions.updateCardConfig),o=((T=r==null?void 0:r.config)==null?void 0:T.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[c,l]=C.useState(!1),x=t!==void 0,p=x?t:c,h=x?n:l,m=((V=r==null?void 0:r.dataSource)==null?void 0:V.selectedEntities)||[],y=L=>{d(r.id,{...r==null?void 0:r.config,joinPlan:L}),h(!1)},v=()=>{d(r.id,{...r==null?void 0:r.config,joinPlan:void 0})},u=()=>{h(!1)},b=()=>{const L=[...o.joins].sort((k,I)=>k.sequence-I.sequence),E=o.baseEntity;if(!E.name)return"SELECT * FROM table -- Please select a base entity";let j=`SELECT *
|
|
155
|
+
FROM ${E.name}`;return L.forEach(k=>{const I=m.find(g=>g.name===k.target.name);if(!I)return;const f=k.joinKeyGroups.filter(g=>g.keys&&g.keys.length>0).map(g=>{const D=g.keys.filter(M=>{var P,N,O,S;return((P=M.source)==null?void 0:P.name)&&((N=M.target)==null?void 0:N.name)&&((O=M.source)==null?void 0:O.entityName)&&((S=M.target)==null?void 0:S.entityName)}).map(M=>`${M.source.entityName}.${M.source.name} ${M.operator} ${M.target.entityName}.${M.target.name}`);return D.length>1?`(${D.join(` ${g.operator} `)})`:D[0]}).filter(Boolean),A=f.length>1?f.join(" OR "):f[0]||"condition_here";j+=`
|
|
156
|
+
${k.joinType} JOIN ${I.name}
|
|
157
|
+
ON ${A}`}),j};if(m.length<2)return null;const w=o.joins.length>0&&e.jsx(s.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(En,{joins:o.joins,baseEntityId:o.baseEntity.name,availableDataSources:m,generateSQLPreview:b})});return e.jsxs(e.Fragment,{children:[e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:a==="badge"?e.jsxs(s.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:L=>{L.stopPropagation(),h(!0)},children:[e.jsx(s.Link,{className:"h-3 w-3"}),o.joins.length]}):e.jsxs(s.Button,{onClick:()=>h(!0),variant:"outline",className:"w-full bg-muted/50",children:[e.jsx(s.Link,{className:"mr-2 h-3.5 w-3.5"}),o.joins.length===0?"Configure Joins":o.joins.length===1?"Join":"Joins",o.joins.length>0&&e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full border bg-muted-foreground px-1.5 text-xs font-medium text-background",children:o.joins.length}),(i==null?void 0:i.autoResolved)&&e.jsxs(s.Badge,{variant:"secondary",className:"ml-2 h-5 gap-1 bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:[e.jsx(s.Sparkles,{className:"h-3 w-3"}),"Auto"]})]})}),w]})}),e.jsx(ga,{open:p,onOpenChange:h,joinPlan:o,availableDataSources:m,onSave:y,onCancel:u,onRemove:v,children:e.jsx("div",{})})]})}function In({open:t,onOpenChange:n}){const[a,r]=C.useState([]),{updateDataSource:i}=s.useEditorActions(),d=s.useDashboardStore(v=>v.dashboard.aiContext),o=(d==null?void 0:d.selectedEntities)||[];C.useEffect(()=>{t&&r([])},[t]);const c=v=>{r(u=>u.some(w=>w.name===v.name&&w.type===v.type)?u.filter(w=>!(w.name===v.name&&w.type===v.type)):[...u,v])},l=()=>{r([...o])},x=()=>{r([])},p=()=>{if(a.length===0)return;const v=a[0],u=v.connectionId||"",b=v.connectionType||"",T=a.some(L=>L.type==="dataset")?"semanticDomain":"database";i({connectionId:u,connectionType:b,mode:T,selectedEntities:a}),n(!1)},h=v=>"label"in v&&v.label?v.label:v.name,m=v=>{if("description"in v&&v.description)return v.description;const u=[];return v.database&&u.push(v.database),v.schema&&u.push(v.schema),v.name&&u.push(v.name),u.join(".")},y=v=>a.some(u=>u.name===v.name&&u.type===v.type);return o.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>n(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:l,disabled:a.length===o.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:x,disabled:a.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[a.length," of ",o.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:o.map((v,u)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",y(v)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:y(v),onCheckedChange:()=>c(v)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:s.getEntityIcon(v.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:h(v)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:m(v)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:v.type})]},`${v.type}-${v.name}-${u}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:p,disabled:a.length===0,children:["Select"," ",a.length>0?`(${a.length})`:""]})]})})})]})})}function Ut({entities:t,title:n}){const{isConsoleMode:a}=s.useDashboardPreferences();return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n??`${t.length} more entities`}),e.jsx("div",{className:"space-y-1",children:t.map((r,i)=>{const d=s.getEntityDetails(r),o=d.find(l=>l.label==="Description"&&l.value),c=d.filter(l=>l.label==="Description"?!1:a?!0:!["Connection","Database","Schema"].includes(l.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(r)}),o&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:o.value})]}),c.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:c.map((l,x)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[l.label,":"]}),e.jsx("span",{className:"font-mono",children:l.value})]},x))})]},`remaining-${r.type}-${r.name}-${i}`)})})]})})}function ja(t,n){const[a,r]=C.useState(()=>{const i=localStorage.getItem(t);return i?JSON.parse(i):n});return C.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}function ba({isVisible:t}){var u,b;const n=s.useEditorStore(w=>w.isDevMode);s.useSyncLegacyEditorState();const[a,r]=C.useState(!1),[i,d]=C.useState(!1),[o,c]=ja("semaphor:data-source-collapsed",!1),l=s.useEditorStore(w=>w.card.dataSource),x=s.useEditorStore(w=>{var T,V;return(V=(T=w.card)==null?void 0:T.config)==null?void 0:V.joinPlan}),{updateDataSource:p}=s.useEditorActions(),h=((u=l==null?void 0:l.selectedEntities)==null?void 0:u.length)||0,m=((b=x==null?void 0:x.joins)==null?void 0:b.length)||0,v={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...l,selectedEntities:(l==null?void 0:l.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex shrink-0 flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"min-w-[325px]":t,"w-0":!t,"min-w-0":!t}),children:[h===0&&m===0?e.jsx("div",{className:"px-4 pt-4",children:e.jsx("div",{className:"rounded-xl border border-border/55 bg-card p-3 shadow-[0_1px_2px_rgba(15,23,42,0.05)]",children:e.jsxs(s.Button,{className:"w-full bg-background",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),"Choose Dataset"]})})}):e.jsx("div",{className:"px-4 pt-4",children:e.jsxs("div",{className:"rounded-xl border border-border/55 bg-card p-3 shadow-[0_1px_2px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:s.cn("flex cursor-pointer items-center justify-between px-1",o?"pb-0":"pb-3"),onClick:()=>c(!o),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Data Source"}),o&&e.jsxs("div",{className:"flex items-center gap-1.5",onClick:w=>w.stopPropagation(),children:[h>0&&e.jsx(s.TooltipProvider,{delayDuration:100,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"h-3 w-3"}),h]})}),e.jsx(Ut,{entities:v.selectedEntities,title:`${h} selected ${h===1?"entity":"entities"}`})]})}),m>0&&!n&&e.jsx(Kt,{variant:"badge"})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:w=>{w.stopPropagation(),c(!o)},children:o?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronUp,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden transition-all duration-200 ease-in-out",o?"max-h-0 opacity-0":"max-h-96 opacity-100"),children:[e.jsx("div",{className:"px-1",children:e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"w-full bg-background",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),h===1?"Dataset":"Datasets",e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full border bg-muted-foreground px-1.5 text-xs font-medium text-background",children:h})]})}),e.jsx(Ut,{entities:v.selectedEntities,title:`${h} selected ${h===1?"entity":"entities"}`})]})})}),!n&&h>1&&e.jsx("div",{className:"mt-3 px-1",children:e.jsx(Kt,{})})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 px-4 pb-4 pt-2",children:e.jsx("div",{className:"h-full overflow-hidden rounded-xl border border-border/55 bg-card shadow-[0_1px_2px_rgba(15,23,42,0.05)]",children:e.jsx(s.FieldsSection,{})})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(l==null?void 0:l.selectedEntities)||[],dialogMode:"dataSource",open:a,onOpenChange:r,dataSource:v}),e.jsx(In,{open:i,onOpenChange:d})]})}function kn(t){return s.GenIcon({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 va(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(u=>u.theme),r=s.useEditorStore(u=>u.frame),i=s.useEditorStore(u=>u.card),d=s.useEditorStore(u=>u.activeTabCardId),o=s.Le(),{refetch:c}=s.useDashboardCardQuery(i),{updateCardTab:l,setRunSql:x}=s.useEditorActions(),p=C.useRef(void 0),h=C.useRef({}),m=r.cards.find(u=>u.id===d),y=C.useCallback(()=>{let u="";return t==="python"&&(u=(m==null?void 0:m.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(u=(m==null?void 0:m.sql)||""),u},[t,m]);C.useEffect(()=>{if(d&&i.id&&i.id!==d){if(p.current&&o){const u=p.current.getModel();u&&(h.current[i.id]=u);let b=h.current[d];if(!b){const w=y();b=o.editor.createModel(w,t),h.current[d]=b}p.current.setModel(b)}l(d,i),x(!0)}},[d,i,l,o,x,t,y]),C.useEffect(()=>{if(!o)return;const u=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",b=a==="system"?u:a;o.editor.defineTheme("default",{base:b==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":b==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),o.editor.setTheme("default")},[n,a,o]),C.useEffect(()=>{const u=p.current;u&&o&&i&&u.addCommand(o.KeyMod.Shift|o.KeyCode.Enter,function(){return c(),!1})},[o,c,i]);function v(u,b){if(p.current=u,!h.current[i.id]){const w=u.getModel(),T=y();h.current[i.id]=w||(b==null?void 0:b.editor.createModel(T,t))||u.getModel()}u.setModel(h.current[i.id])}return{handleEditorDidMount:v}}const Dn=300;function An(){const t=s.useEditorStore(p=>p.card.sql),n=s.useEditorStore(p=>p.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:i}=va("sql"),d=C.useRef(n);d.current=n;const o=C.useCallback(p=>{a(p)},[a]),{value:c,onChange:l}=fa({storeValue:t,defaultValue:"",onStoreUpdate:o,delay:Dn});function x(p){l(p),s.isObjectEmpty(d.current)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!c&&e.jsx("div",{className:"pointer-events-none absolute left-[36px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:x,value:c,options:{minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:2,lineDecorationsWidth:0,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:i})]})}const Ln=300;function Mn(){const t=s.useEditorStore(d=>d.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=va("python"),{value:r,onChange:i}=fa({storeValue:t,defaultValue:s.PYTHON_DEFAULT_CODE,onStoreUpdate:n,delay:Ln});return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:i,value:r,options:{minimap:{enabled:!1},glyphMargin:!1,lineNumbersMinChars:2,lineDecorationsWidth:0,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}const On={async writeTextToClipboard(t){return typeof navigator>"u"||!navigator.clipboard?!1:(await navigator.clipboard.writeText(t),!0)}},Ns=50,Rn=[{target:"queryRequest",label:"Query Request"},{target:"queryResponse",label:"Query Response"},{target:"cardConfig",label:"Card Config"},{target:"dataSource",label:"Data Source"},{target:"columns",label:"Columns"},{target:"dashboardFilters",label:"Dashboard Filters"},{target:"cardMetadata",label:"Card Metadata IDs"}];function Ht(t){try{return JSON.stringify(t,null,2)}catch(n){return console.error("Unable to stringify debug payload",n),null}}function rs(t){switch(t){case"queryRequest":return"Query Request";case"queryResponse":return"Query Response";case"cardConfig":return"Card Config";case"dataSource":return"Data Source";case"cardMetadata":return"Card Metadata IDs";case"columns":return"Columns";case"dashboardFilters":return"Dashboard Filters";default:return"Payload"}}function Fn(t){if(!t||typeof t!="object")return{value:t};const n=t.records;return!Array.isArray(n)||n.length<=Ns?{value:t}:{value:{...t,records:n.slice(0,Ns),previewMeta:{truncatedRecords:!0,displayedRecords:Ns,totalRecords:n.length}},truncationMessage:`Preview showing first ${Ns} records of ${n.length}. Copy actions include full payload.`}}function ya({sql:t,showCardDetails:n=!1,debugPayloads:a,className:r}){const[i,d]=C.useState(!1),[o,c]=C.useState(null),l=s.useEditorStore(A=>A.card),x=s.useEditorStore(A=>A.frame),p=s.useEditorStore(A=>A.isDevMode),h=s.useDashboardStore(A=>A.selectedSheetId),m=s.useDashboardStore(A=>{var g;return(g=A.dashboard)==null?void 0:g.id}),{switchEditorMode:y,setRunSql:v}=s.useEditorActions(),u=C.useMemo(()=>({cardId:l.id||null,frameId:x.id||null,sheetId:h||null,dashboardId:m||null}),[l.id,x.id,h,m]),b=C.useMemo(()=>({queryRequest:a==null?void 0:a.queryRequest,queryResponse:a==null?void 0:a.queryResponse,cardConfig:l.config,dataSource:l.dataSource,columns:a==null?void 0:a.columns,dashboardFilters:a==null?void 0:a.dashboardFilters,cardMetadata:u}),[a==null?void 0:a.queryRequest,a==null?void 0:a.queryResponse,a==null?void 0:a.columns,a==null?void 0:a.dashboardFilters,l.config,l.dataSource,u]),w=n&&i&&!!a,T=C.useMemo(()=>[{label:"Card ID",value:l.id||""},{label:"Frame ID",value:x.id||""},{label:"Sheet ID",value:h||""},{label:"Dashboard ID",value:m||""}],[l.id,x.id,h,m]),V=()=>{y("dev",{sqlToLoad:t}),setTimeout(()=>{v(!0)},100)},L=A=>b[A]!==void 0,E=C.useMemo(()=>{if(!o)return null;const A=b[o];if(A===void 0)return null;const g=o==="queryResponse"?Fn(A):{value:A},D=Ht(g.value);return D?{target:o,title:rs(o),json:D,truncationMessage:g.truncationMessage}:null},[o,b]),j=E?E.title:"Preview Payload",k=async A=>{const g=b[A];if(g===void 0)return s.ue.error(`No ${rs(A).toLowerCase()} available`),!1;const D=Ht(g);if(!D)return s.ue.error(`Unable to serialize ${rs(A).toLowerCase()}`),!1;try{return await On.writeTextToClipboard(D)?(s.ue.success(`${rs(A)} copied`),!0):(s.ue.error("Clipboard is not available"),!1)}catch(M){return console.error("Failed to copy debug payload",M),s.ue.error(`Unable to copy ${rs(A).toLowerCase()}`),!1}},I=async()=>E?k(E.target):!1,f=A=>{if(b[A]===void 0){s.ue.error(`No ${rs(A).toLowerCase()} available`);return}c(A)};return e.jsxs("div",{className:s.cn("flex min-h-0 flex-1 flex-col",r),children:[!p&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:V,variant:"secondary",size:"sm",children:[e.jsx(ha,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),n&&e.jsxs(s.Button,{onClick:()=>d(!i),variant:"outline",size:"sm",children:[e.jsx(s.Info,{className:"mr-2 h-4 w-4"}),"Card Details"]})]}),i&&n&&e.jsx("div",{className:"mb-3 rounded-lg border border-border bg-muted/30 p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Card Information"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(!1),children:e.jsx(Ie.CircleX,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2",children:T.map(A=>e.jsxs("div",{className:"min-w-0 rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:A.label}),e.jsx(s.CopyButton,{text:A.value,className:"h-6 w-6 shrink-0"})]}),e.jsx("code",{title:A.value||"N/A",className:"mt-1 block whitespace-normal break-all font-mono text-xs",children:A.value||"N/A"})]},A.label))}),w&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 bg-background/70 p-3",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground",children:"Debug Tools"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8","aria-label":"Preview Payload Menu",children:[e.jsx(s.Eye,{className:"mr-1.5 h-3.5 w-3.5"}),j,e.jsx(s.ChevronDown,{className:"ml-1.5 h-3.5 w-3.5"})]})}),e.jsx(s.DropdownMenuContent,{align:"start",className:"w-56",children:Rn.map(A=>e.jsx(s.DropdownMenuItem,{disabled:!L(A.target),onSelect:()=>f(A.target),className:s.cn(o===A.target&&"bg-accent"),children:A.label},`preview-${A.target}`))})]})}),E&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs font-medium text-muted-foreground",children:[E.title," Preview"]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.CopyButton,{text:E.json,className:"h-6 w-6",ariaLabel:"Copy Payload",onCopy:I}),e.jsxs(s.Button,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>c(null),children:[e.jsx(Ie.CircleX,{className:"mr-1 h-3.5 w-3.5"}),"Hide"]})]})]}),E.truncationMessage&&e.jsx("p",{className:"text-xs text-muted-foreground",children:E.truncationMessage}),e.jsx("div",{className:"max-h-80 overflow-auto",children:e.jsx(s.CodeHighlighter,{code:E.json,language:"json"})})]})]})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto text-xs leading-relaxed text-foreground/80",children:e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsxs("div",{className:"group relative",children:[e.jsx("div",{className:"absolute right-2 top-2 z-10 rounded-md border border-border/60 bg-background/85 p-0.5 shadow-sm backdrop-blur-sm transition-opacity duration-150",children:e.jsx(s.CopyButton,{text:t,className:"h-6 w-6 px-0 text-muted-foreground/80 hover:text-foreground"})}),e.jsx(s.CodeHighlighter,{code:t,language:"sql",wrapLongLines:!0})]})})})]})}function Vn(t){const{request:n,currentSql:a,selectedTableName:r,selectedSchemaName:i,selectedDatabaseName:d}=t,o=[d?`Database: ${d}`:"",i?`Schema: ${i}`:"",r?`Table: ${r}`:""].filter(Boolean);return["You are an expert SQL writing assistant embedded in a query editor.",`Write SQL only. You may call only read-only tools when needed: ${s.INLINE_ALLOWED_TOOL_LIST}.`,"Do not call mutation tools or chart-creation tools; those require Full Assistant.","Return exactly one SQL statement inside a single ```sql fenced block.","After the code block, optionally include one short sentence.",o.length>0?`Context:
|
|
158
|
+
${o.join(`
|
|
159
|
+
`)}`:"",a?`Current SQL (revise if useful):
|
|
160
|
+
${a}`:"",`User request:
|
|
161
|
+
${n}`].filter(Boolean).join(`
|
|
162
|
+
|
|
163
|
+
`)}function Pn(t){const{request:n,failedSql:a,errorMessage:r,errorCode:i,selectedDatabaseName:d,selectedSchemaName:o,selectedTableName:c,contextEntityLabels:l}=t,x=[d?`Database: ${d}`:"",o?`Schema: ${o}`:"",c?`Table: ${c}`:"",l.length>0?`Selected context entities: ${l.join(", ")}`:""].filter(Boolean);return["You are fixing SQL after validation failed.","Return one read-only SQL statement in a single ```sql fenced block.","Do not call mutation tools.",x.length>0?`Context:
|
|
164
|
+
${x.join(`
|
|
165
|
+
`)}`:"",`Original user request:
|
|
166
|
+
${n}`,`Previous SQL draft:
|
|
167
|
+
${a}`,`Validation failure${i?` (${i})`:""}:
|
|
168
|
+
${r}`].filter(Boolean).join(`
|
|
169
|
+
|
|
170
|
+
`)}function Bn(t,n){typeof window>"u"||window.dispatchEvent(new CustomEvent("semaphor:inline-query-writer",{detail:{event:t,...n,timestamp:Date.now()}}))}const Vs={runId:0,phase:"idle",attempt:0,activeStep:"",timelineSteps:[],lastValidation:null,finalOutcome:"idle",hasTools:!1};function zn(t){if(typeof t=="string"&&(t==="SQL_EMPTY"||t==="SQL_PARSE_ERROR"||t==="SQL_MULTI_STATEMENT"||t==="SQL_READ_ONLY_VIOLATION"||t==="SQL_EXPLAIN_ERROR"||t==="SQL_CONNECTION_ERROR"))return t}function Jt(t){let n=0;for(let a=0;a<t.length;a+=1)n=(n<<5)-n+t.charCodeAt(a),n|=0;return String(n)}function Qt(t){return t==="getTableColumns"?"Discovering columns":t==="getDomainRelationships"?"Resolving relationships":t==="getChartSQLSyntax"?"Reviewing SQL syntax":t==="getUserSql"?"Inspecting current query":"Analyzing context"}function qn(t,n){return t===s.SELF_HEAL_TIMELINE_STEP&&n>0?`${s.SELF_HEAL_TIMELINE_STEP} ${n}/${s.MAX_SELF_HEAL_ATTEMPTS}`:t}function Cs(t){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`${t}-${crypto.randomUUID()}`:`${t}-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Yt(t){var n;for(let a=t.length-1;a>=0;a-=1){const r=t[a];if(r.role!=="user")continue;const i=(n=r.metadata)==null?void 0:n.inlineRunToken;if(typeof i=="string"&&i.length>0)return i}}function $n(t){if(!t)return"";const n=t.trim(),a=t.match(/```sql\s*([\s\S]*?)```/i);if(a!=null&&a[1])return a[1].trim();const r=t.match(/```[\w-]*\s*([\s\S]*?)```/i);return r!=null&&r[1]?r[1].trim():/^(select|with|insert|update|delete)\b/i.test(n)?n:""}function Wt(t){for(let n=t.length-1;n>=0;n-=1){const a=t[n];if(!(a.role!=="assistant"||!Array.isArray(a.parts)))for(let r=a.parts.length-1;r>=0;r-=1){const i=a.parts[r];if((i==null?void 0:i.type)!=="text"||typeof(i==null?void 0:i.text)!="string")continue;const d=$n(i.text);if(d)return d}}return""}function _n({currentSql:t,currentPython:n,selectedDatabaseName:a,selectedSchemaName:r,selectedTableName:i,onApplySql:d,onOpenFullAssistant:o}){var ms,Ke;const{authToken:c,tokenProps:l}=s.useSemaphorContext(),x=(ms=s.useDashboardQuery().data)==null?void 0:ms.assistantProfileId,p=s.useEditorStore(G=>G.isDevMode),h=s.useEditorStore(G=>G.selectedConnectionId),m=s.useEditorStore(G=>{var W;return(W=G.card.dataSource)==null?void 0:W.selectedEntities}),y=s.useAIInteractionStore(G=>G.currentAIContext.selectedEntities),v=y.length,{setCurrentAIContext:u}=s.useAIActions(),[b,w]=C.useState(""),[T,V]=C.useState(""),[L,E]=C.useState(""),[j,k]=C.useState({status:"idle"}),[I,f]=C.useState(Vs),[A,g]=C.useState(!1),[D,M]=C.useState(()=>Cs("inline-query-session")),P=C.useRef(null),N=C.useRef(null),O=C.useRef(null),S=C.useRef(0),R=C.useRef(0),F=C.useRef(Cs("inline-run-token")),$=C.useRef(D),U=C.useRef(new Set),z=C.useRef(new Map),H=C.useRef(0),se=C.useRef(""),Y=C.useRef(!1),ae=C.useRef(!1),q=C.useRef(Vs),J=C.useRef(!1),le=C.useRef(null),X=C.useRef(()=>{}),oe=(Ke=l.apiServiceUrl)==null?void 0:Ke.replace(/\/$/,""),me=oe?`${oe}/v1/sql/validate`:"/v1/sql/validate",Z=C.useCallback(G=>{f(W=>{const Q=G(W);return q.current=Q,Q})},[]),xe=C.useCallback((G,W)=>{Z(Q=>Q.runId===G?W(Q):Q)},[Z]),B=C.useCallback(G=>R.current===G&&!U.current.has(G),[]),ee=C.useCallback((G,W,Q)=>{xe(G,ue=>{const de=ue.timelineSteps.includes(W)?ue.timelineSteps:[...ue.timelineSteps,W];return{...ue,phase:(Q==null?void 0:Q.phase)||ue.phase,attempt:typeof(Q==null?void 0:Q.attempt)=="number"?Q.attempt:ue.attempt,activeStep:W,timelineSteps:de,finalOutcome:(Q==null?void 0:Q.finalOutcome)||ue.finalOutcome,hasTools:Q!=null&&Q.hasTools?!0:ue.hasTools}})},[xe]),ce=C.useCallback(()=>{const G=R.current+1,W=Cs("inline-run-token"),Q=Cs("inline-query-session");return R.current=G,F.current=W,$.current=Q,M(Q),U.current=new Set,z.current=new Map,H.current=0,se.current="",J.current=!1,Z(()=>({runId:G,phase:"drafting",attempt:0,activeStep:"Drafting SQL",timelineSteps:["Drafting SQL"],lastValidation:null,finalOutcome:"drafting",hasTools:!1})),{runId:G,runToken:W,chatSessionId:Q}},[Z]),he=C.useCallback(()=>{if(Y.current||ae.current||v>0)return;const G=m||[];if(G.length===0)return;const W=s.useAIInteractionStore.getState().currentAIContext;u({...W,selectedEntities:G}),ae.current=!0},[v,m,u]),ke=C.useCallback(()=>{Y.current=!0},[]),ye=C.useCallback((G,W,Q)=>{Bn(G,{runId:W,attemptCount:typeof(Q==null?void 0:Q.attemptCount)=="number"?Q.attemptCount:H.current,errorCode:Q==null?void 0:Q.errorCode,hasTools:typeof(Q==null?void 0:Q.hasTools)=="boolean"?Q.hasTools:I.hasTools,entityCount:v,finalOutcome:(Q==null?void 0:Q.finalOutcome)||I.finalOutcome})},[v,I.finalOutcome,I.hasTools]),Ee=C.useCallback((G,W)=>{const Q=O.current;if(!Q)return;const ue={inlineRunToken:W};Q({role:"user",parts:[{type:"text",text:G}],metadata:ue},{metadata:ue})},[]);C.useEffect(()=>{const G=le.current;!G||G.sessionId!==D||(le.current=null,Ee(G.message,G.runToken))},[D,Ee]);const Se=D,Pe=C.useCallback(async({toolCall:G})=>{var Le,Ue,ts,Ze,fe,He;if(Se!==$.current)return;const W=String(G.toolName||"").trim();if(!W)return;const Q=R.current;if(!B(Q)){(Le=N.current)==null||Le.call(N,{tool:W,toolCallId:G.toolCallId,output:{status:"error",message:"Inline run is no longer active; ignoring tool output."}});return}if(W==="getUserSql"){ee(Q,Qt(W),{hasTools:!0}),ye("inline_tool_step",Q,{hasTools:!0}),(Ue=N.current)==null||Ue.call(N,{tool:W,toolCallId:G.toolCallId,output:{status:"success",sql:t||"",python:n||""}});return}const ue=s.INLINE_BLOCKED_MUTATING_TOOLS.has(W),de=s.INLINE_ALLOWED_READ_ONLY_TOOLS.has(W);if(ue||!de){(ts=N.current)==null||ts.call(N,{tool:W,toolCallId:G.toolCallId,output:{status:"error",message:"This action is unavailable in inline draft mode. Open Full Assistant for this action."}});return}const ge=Qt(W);ee(Q,ge,{phase:I.phase==="self-healing"?"self-healing":"drafting",hasTools:!0}),ye("inline_tool_step",Q,{hasTools:!0});const Ce=((Ze=G.input)==null?void 0:Ze.sql)??((fe=G.args)==null?void 0:fe.sql);typeof Ce=="string"&&Ce.trim().length>0&&(J.current=!1,E(Ce.trim())),(He=N.current)==null||He.call(N,{tool:W,toolCallId:G.toolCallId,output:{status:"success",message:"Read-only tool result received."}})},[n,t,ye,I.phase,B,Se,ee]),ne=C.useCallback(({message:G,messages:W})=>{if(Se!==$.current)return;const Q=Yt(W);if(!Q||Q!==F.current)return;const ue=R.current;if(!B(ue))return;const de=Wt([G])||Wt(W);if(de){J.current=!1,E(de.trim());return}J.current&&q.current.phase==="self-healing"&&X.current(ue)},[B,Se]),je=C.useCallback(G=>{if(Se!==$.current)return;const W=R.current;B(W)&&J.current&&q.current.phase==="self-healing"&&X.current(W)},[B,Se]),{setMessages:pe,sendMessage:Te,addToolResult:Ae,status:ve,stop:Be,error:ze,clearError:De}=s.useChat({id:D,transport:new s.DefaultChatTransport({api:`${l.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${c==null?void 0:c.accessToken}`}),body:()=>{const G=s.useAIInteractionStore.getState();return{assistantId:"editor-assistant",assistantProfileId:x,isDevMode:p,aiContext:G.currentAIContext,reasoningEffort:G.reasoningEffort,showReasoning:!1}},credentials:"omit",prepareSendMessagesRequest:({messages:G,body:W,requestMetadata:Q})=>{const ue=Q==null?void 0:Q.inlineRunToken,de=Yt(G);return{body:{...W,inlineRunToken:ue||de,messages:s.cleanupIncompleteMessages(G)}}}}),onToolCall:Pe,onFinish:ne,onError:je,sendAutomaticallyWhen:s.lastAssistantMessageIsCompleteWithToolCalls});N.current=Ae,O.current=Te;const te=!["ready","error"].includes(ve),be=(ze==null?void 0:ze.message)||"Unable to generate a SQL draft right now. Try again.",Oe=C.useCallback(G=>{const W=R.current,Q=q.current.phase;if(!(Q==="drafting"||Q==="self-healing"||Q==="validating")){G==="stopped"&&te&&Be();return}U.current.add(W),J.current=!1,S.current+=1,se.current="",k({status:"idle"}),E(""),De(),pe([]),xe(W,de=>({...de,phase:"idle",activeStep:"",finalOutcome:"cancelled"})),ye("inline_self_heal_stopped",W,{finalOutcome:"cancelled"}),(te||G==="stopped")&&Be()},[De,ye,te,pe,Be,xe]),_e=C.useCallback(async(G,W)=>{var ue;if(!B(W))return null;const Q=S.current+1;S.current=Q,ee(W,"Validating SQL",{phase:"validating"}),k({status:"validating"});try{const de=await s.postRequestRegular(me,(c==null?void 0:c.accessToken)||"",{sql:G,connectionId:h||void 0});if(S.current!==Q||!B(W))return null;if((de==null?void 0:de.valid)===!0)return k({status:"valid",message:"SQL validation passed."}),xe(W,Le=>({...Le,phase:"ready",finalOutcome:"validated",lastValidation:{valid:!0}})),ye("inline_draft_validated",W,{finalOutcome:"validated"}),{status:"valid"};const ge=zn(de==null?void 0:de.errorCode)||"UNKNOWN",Ce=typeof(de==null?void 0:de.error)=="string"&&de.error||typeof((ue=de==null?void 0:de.details)==null?void 0:ue.error)=="string"&&de.details.error||"SQL validation failed. Please revise the query draft.";return k({status:"invalid",message:Ce,errorCode:ge}),xe(W,Le=>({...Le,lastValidation:{valid:!1,error:Ce,errorCode:ge}})),ye("inline_validation_failed",W,{errorCode:ge,finalOutcome:"validation_failed"}),{status:"invalid",error:Ce,errorCode:ge}}catch(de){if(S.current!==Q||!B(W))return null;const ge=typeof(de==null?void 0:de.error)=="string"&&de.error||typeof(de==null?void 0:de.detail)=="string"&&de.detail||"Validation service unavailable. You can still replace and run.";return k({status:"error",message:ge,errorCode:"SQL_CONNECTION_ERROR"}),xe(W,Ce=>({...Ce,phase:"error",finalOutcome:"error",lastValidation:{valid:!1,error:ge,errorCode:"SQL_CONNECTION_ERROR"}})),{status:"error",error:ge,errorCode:"SQL_CONNECTION_ERROR"}}},[c==null?void 0:c.accessToken,ye,B,h,me,xe,ee]),Ye=C.useCallback((G,W,Q,ue)=>{let de=Q,ge="validation_failed",Ce="Validating SQL";W==="attempt_limit"?(de=`Couldn't auto-fix after ${s.MAX_SELF_HEAL_ATTEMPTS} attempts. ${Q}`,ge="self_heal_exhausted",Ce=`Auto-fix stopped (${s.MAX_SELF_HEAL_ATTEMPTS} attempts)`):W==="duplicate"&&(de=`Auto-fix stopped (repeated validation failure). ${Q}`,ge="self_heal_duplicate_stopped",Ce="Auto-fix stopped (repeated failure)"),k({status:"invalid",message:de,errorCode:ue}),ee(G,Ce,{phase:"error",finalOutcome:ge}),xe(G,Le=>({...Le,phase:"error",finalOutcome:ge,lastValidation:{valid:!1,error:de,errorCode:ue}})),W!=="terminal"&&ye("inline_self_heal_stopped",G,{errorCode:ue,finalOutcome:ge}),J.current=!1},[ye,xe,ee]),fs=C.useCallback(G=>{const W="Auto-fix stopped (no SQL returned). Open Full Assistant to continue.",Q="self_heal_no_draft";k({status:"invalid",message:W,errorCode:"UNKNOWN"}),ee(G,"Auto-fix stopped (no SQL returned)",{phase:"error",finalOutcome:Q}),xe(G,ue=>({...ue,phase:"error",finalOutcome:Q,lastValidation:{valid:!1,error:W,errorCode:"UNKNOWN"}})),ye("inline_self_heal_stopped",G,{errorCode:"UNKNOWN",finalOutcome:Q}),J.current=!1},[ye,xe,ee]);X.current=fs,C.useEffect(()=>{const G=L.trim(),W=R.current;if(!G){if(S.current+=1,se.current="",q.current.phase==="error")return;k({status:"idle"});return}if(!B(W)||te)return;const Q=`${W}:${H.current}:${Jt(G)}`;if(se.current===Q)return;se.current=Q;let ue=!1;return(async()=>{const ge=await _e(G,W);if(!ge||ue||!B(W)||ge.status!=="invalid")return;if(!s.RECOVERABLE_SQL_ERROR_CODES.has(ge.errorCode)){Ye(W,"terminal",ge.error,ge.errorCode);return}const Ce=`${Jt(G)}::${ge.errorCode}`,Le=(z.current.get(Ce)||0)+1;if(z.current.set(Ce,Le),Le>=2){Ye(W,"duplicate",ge.error,ge.errorCode);return}if(H.current>=s.MAX_SELF_HEAL_ATTEMPTS){Ye(W,"attempt_limit",ge.error,ge.errorCode);return}const Ue=H.current+1;H.current=Ue,ee(W,s.SELF_HEAL_TIMELINE_STEP,{phase:"self-healing",attempt:Ue}),ye("inline_self_heal_attempt",W,{attemptCount:Ue,errorCode:ge.errorCode}),J.current=!0,De(),pe([]),E("");const ts=y.map(fe=>{const He=fe!=null&&fe.database?`${fe.database}.`:"",Re=fe!=null&&fe.schema?`${fe.schema}.`:"",Fe=(fe==null?void 0:fe.name)||"unknown";return`${He}${Re}${Fe}`}),Ze=Pn({request:T,failedSql:G,errorMessage:ge.error,errorCode:ge.errorCode,selectedDatabaseName:a||"",selectedSchemaName:r||"",selectedTableName:i||"",contextEntityLabels:ts});Ee(Ze,F.current)})(),()=>{ue=!0}},[De,y,ye,te,B,T,L,a,r,i,Ee,pe,Ye,ee,_e]);const ks=C.useCallback(()=>{if(te)return;const G=b.trim();if(!G)return;const{runId:W,runToken:Q,chatSessionId:ue}=ce();ye("inline_draft_started",W,{attemptCount:0,hasTools:!1,finalOutcome:"drafting"}),he(),De(),V(G),E(""),k({status:"idle"}),S.current+=1,pe([]),g(!0);const de=Vn({request:G,currentSql:t||"",selectedTableName:i||"",selectedSchemaName:r||"",selectedDatabaseName:a||""});le.current={sessionId:ue,message:de,runToken:Q}},[ce,De,t,ye,te,b,he,a,r,i,pe]),ss=C.useCallback(G=>{const W=L.trim();W&&(d(W,G),g(!1))},[d,L]),We=L.trim().length>0,gs=["valid","invalid","error"].includes(j.status),ls=We&&gs,Ds=j.status==="invalid",js=j.status==="validating",os=We&&T.length>0&&T===b.trim(),As=b.trim().length>0||T.trim().length>0||We||j.status!=="idle"||I.timelineSteps.length>0,bs=C.useCallback(()=>{if(!te){if(os&&!A){he(),g(!0);return}ks()}},[ks,os,te,A,he]),is=C.useCallback(()=>{he(),g(!0)},[he]),cs=C.useCallback(G=>{Oe("cancelled"),w(G)},[Oe]),vs=C.useCallback(()=>{te||(Oe("cancelled"),J.current=!1,S.current+=1,se.current="",H.current=0,w(""),V(""),E(""),k({status:"idle"}),De(),pe([]),Z(G=>({...Vs,runId:G.runId})))},[Oe,De,te,pe,Z]),ds=C.useCallback(G=>{G||Oe("cancelled"),g(G)},[Oe]),us=I.timelineSteps.findIndex(G=>G===I.activeStep),Ge=I.phase==="self-healing"?"Fixing validation issue":I.phase==="validating"?"Validating SQL":I.activeStep||"Drafting SQL",Xe=j.status==="valid"?{label:"Validation passed",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-700",detail:j.message}:j.status==="invalid"?{label:"Validation failed",className:"border-destructive/40 bg-destructive/10 text-destructive",detail:j.message}:j.status==="error"?{label:"Validation unavailable",className:"border-border/60 bg-muted/20 text-muted-foreground",detail:j.message}:null;return e.jsxs("div",{ref:P,className:"relative flex h-8 min-w-[320px] flex-1 items-center",children:[e.jsx(s.Input,{value:b,onChange:G=>cs(G.target.value),onFocus:is,onClick:is,onKeyDown:G=>{G.key==="Enter"&&(G.preventDefault(),bs())},placeholder:"Type your question...",className:"h-8 border-transparent bg-muted/45 pr-16 shadow-none focus-visible:border-border focus-visible:bg-background focus-visible:ring-0"}),e.jsxs(s.Popover,{open:A,onOpenChange:ds,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"absolute right-1 h-6 px-2 text-xs",onClick:G=>{G.preventDefault(),bs()},disabled:te,children:os?"Preview":"Draft"})}),e.jsx(s.PopoverContent,{align:"end",alignOffset:-4,side:"bottom",sideOffset:8,className:"w-[min(92vw,760px)] p-2.5",onOpenAutoFocus:G=>{G.preventDefault()},onInteractOutside:G=>{var Q;const W=G.target;W&&((Q=P.current)!=null&&Q.contains(W))&&G.preventDefault()},children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Composer"}),T&&e.jsx("p",{className:"line-clamp-2 text-xs text-muted-foreground",children:T})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[te&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>{Oe("stopped")},children:"Stop"}),!te&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:vs,disabled:!As,children:"Clear"})]})]}),I.timelineSteps.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1",children:[I.timelineSteps.map((G,W)=>{const Q=G===I.activeStep&&["drafting","validating","self-healing"].includes(I.phase),ue=!Q&&us>=0&&W<us;return e.jsx("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Q?"border-foreground/30 bg-foreground/10 text-foreground":ue?"border-border/60 bg-muted/20 text-muted-foreground":"border-border/50 bg-background text-muted-foreground/80"].join(" "),children:qn(G,I.attempt)},`${G}-${W}`)}),Xe&&e.jsx(s.TooltipProvider,{delayDuration:150,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:["rounded-full border px-2 py-0.5 text-[11px]",Xe.className].join(" "),children:Xe.label})}),e.jsx(s.TooltipContent,{side:"top",align:"start",className:"max-w-[680px] whitespace-pre-wrap break-words text-xs",children:Xe.detail})]})})]}),e.jsx("div",{className:"py-0.5",children:e.jsx(s.AssistantContextEntityControls,{mode:"full",compact:!0,inlineLayout:!0,inlineTriggerFirst:!0,triggerVariant:"outline",triggerIconOnly:!1,triggerLabel:"Context",onSelectionChange:ke})}),(te||I.phase==="self-healing"||j.status==="validating")&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border/60 bg-muted/20 px-3 py-2 text-xs text-muted-foreground",children:[e.jsx(s.LoaderCircle,{className:"size-3.5 animate-spin"}),Ge]}),ze&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:be}),ls?e.jsx("div",{className:"max-h-[250px] overflow-auto rounded-md border border-border/60",children:e.jsx(s.CodeHighlighter,{code:L,language:"sql"})}):We?e.jsx("div",{className:"rounded-md border border-dashed border-border/70 px-3 py-2 text-xs text-muted-foreground",children:"Validating SQL draft before preview."}):!te&&e.jsx("div",{className:"rounded-md border border-dashed border-border/70 px-3 py-2 text-xs text-muted-foreground",children:"Describe what you want to query, then press Enter or click Draft to generate a SQL preview."}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:o,children:"Open Full Assistant"}),e.jsx(s.Button,{variant:"secondary",size:"sm",className:"h-8",disabled:te||!ls,onClick:()=>ss(!1),children:"Replace SQL"}),e.jsx(s.Button,{size:"sm",className:"h-8",disabled:te||!ls||js||Ds,onClick:()=>ss(!0),children:"Replace & Run"})]})]})})]})]})}function Gn(){var oe,me;const t=s.useQueryClient(),[n,a]=C.useState(!1),r=s.useEditorStore(Z=>Z.frame),i=s.useEditorStore(Z=>Z.card);s.useEditorStore(Z=>Z.isShowingVisual),s.useEditorStore(Z=>Z.selectedConnectionId),s.useEditorStore(Z=>Z.tempQueryData);const d=s.useEditorStore(Z=>Z.selectedDatabaseName);s.useEditorStore(Z=>Z.selectedDatamodelId);const o=s.useEditorStore(Z=>Z.selectedSchemaName);s.useEditorStore(Z=>Z.showAIDialog);const c=s.useEditorStore(Z=>Z.selectedTableName),{cardFilterValues:l}=s.useCardFilterValues((i==null?void 0:i.id)??""),x=s.useDashboardStore(Z=>Z.inlineFilterValuesMap[(i==null?void 0:i.id)??""]),p=C.useMemo(()=>s.findCustomVisualConfigCard(r,i),[r,i]),{manifest:h}=s.useCustomVisual(((oe=p==null?void 0:p.customCardPreferences)==null?void 0:oe.url)||""),m=C.useMemo(()=>{var Z;return(Z=h==null?void 0:h.visuals)==null?void 0:Z.find(xe=>{var B;return xe.name===((B=p==null?void 0:p.customCardPreferences)==null?void 0:B.componentName)})},[h,(me=p==null?void 0:p.customCardPreferences)==null?void 0:me.componentName]),y=s.resolveMultiInputType(p,m),v=C.useMemo(()=>s.getCustomVisualInputCards({frame:r,configCard:p,isMultiInputVisual:y==="multiple"}),[r,p,y]),u=C.useMemo(()=>{const Z=v.findIndex(xe=>(xe==null?void 0:xe.id)===(i==null?void 0:i.id));return Z<0?-1:s.getSlotIndexForCard(i,Z)},[v,i]),b=C.useMemo(()=>!p||y!=="multiple"||u<0?i.type:s.getEffectiveCardTypeForSlot(i,u,m==null?void 0:m.slots)??i.type,[p,y,u,i,m==null?void 0:m.slots]),w=C.useMemo(()=>b!==i.type?{...i,type:b}:i,[i,b]),T=C.useRef(!0),{setCardCustomCfg:V,setQueryResultColumns:L,setCardSql:E,setTempQueryData:j,setPythonStdOut:k,setCardPreferences:I,setCardType:f,setCardPython:A,setShowAIDialog:g,setCard:D,updateCardInFrame:M}=s.useEditorActions();s.useEditorStore(Z=>Z.onSave),s.useEditorStore(Z=>Z.onClose),s.useEditorStore(Z=>Z.actions.setSqlGen);const P=s.useEditorStore(Z=>Z.runSql),N=s.useEditorStore(Z=>Z.actions.setRunSql),O=s.useEditorStore(Z=>Z.actions.setIsSqlRunning),{data:S,isLoading:R,isFetching:F,isSuccess:$,isError:U,error:z,errorSql:H,queryKey:se,refetch:Y,errorMessage:ae}=s.useDashboardCardQuery(w);C.useEffect(()=>{if(S&&(S.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),k((S==null?void 0:S.output)||""),S.records.length>0)){const{dimensionKeys:Z}=s.getKeys(S.records);L(Z)}},[S,L,k]),C.useEffect(()=>{(R||F)&&O(!0),(U||$)&&O(!1),U&&(L([]),k(""))},[R,F,S,k,U,$,O,L,z]),C.useEffect(()=>{P&&(t.getQueryData(se)||Y(),N(!1))},[P,Y,N,se,t]);const q=C.useRef(Y);q.current=Y,C.useEffect(()=>{if(T.current){T.current=!1;return}q.current()},[x]);function J(Z,xe){E(Z),xe&&N(!0)}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:n?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(An,{})}),n&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),n&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"data-[panel-group-direction=vertical]:ml-2 data-[panel-group-direction=vertical]:mr-6 data-[panel-group-direction=vertical]:w-auto"}),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(Mn,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function X(){return e.jsx("div",{role:"editor-controls",className:"item-center flex w-full flex-wrap items-center gap-2 pl-2 pr-6 py-4",children:e.jsxs("div",{className:"flex w-full items-center gap-3",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:R||F,onClick:()=>{Y()},className:"h-8 shrink-0",size:"sm",children:[R||F?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),(S==null?void 0:S.sql)&&!ae&&e.jsxs(s.HoverCard,{openDelay:300,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Info,{className:"h-4 w-4 shrink-0 cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.HoverCardContent,{align:"start",className:"w-[500px] p-0",children:e.jsx(ya,{sql:S.sql})})]}),e.jsx(Ie.EditorClearButton,{}),e.jsxs(s.Toggle,{pressed:n,onPressedChange:Z=>a(Z),className:"h-8",size:"sm",variant:"outline",children:[e.jsx(kn,{className:"mr-2 size-4 text-foreground/70"}),"Python"]}),e.jsx(_n,{currentSql:i==null?void 0:i.sql,currentPython:i==null?void 0:i.python,selectedDatabaseName:d,selectedSchemaName:o,selectedTableName:c,onApplySql:J,onOpenFullAssistant:()=>g(!0)}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-3",children:[e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 gap-1.5",onClick:()=>{g(!0)},children:[e.jsx(s.Sparkles,{className:"size-3.5 text-foreground/70"}),"Assistant"]}),l&&l.length>0&&e.jsxs(s.HoverCard,{openDelay:200,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",className:"h-8 gap-2 px-2",children:[e.jsx(s.Filter,{className:"size-4"}),e.jsx(s.Badge,{className:"h-5 min-w-5 bg-purple-100 px-1.5 text-purple-700 hover:bg-purple-100 dark:bg-purple-950 dark:text-purple-300",children:l.length})]})}),e.jsx(s.HoverCardContent,{className:"mr-4 max-h-[400px] w-[500px] overflow-auto p-0",children:e.jsxs("div",{className:"p-3",children:[e.jsx("div",{className:"mb-2 text-sm font-semibold",children:"Active Dashboard Filters"}),e.jsx(s.CodeHighlighter,{code:JSON.stringify(l,null,2),language:"json"})]})})]})]})]})})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsx("div",{className:"relative flex grow overflow-y-scroll",children:le()}),X()]})}const Kn=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:s.Grid3x3},{value:"detailTable",label:"Detail",icon:s.List}];function Un({className:t}){const n=s.useEditorStore(h=>h.card),a=s.useEditorStore(h=>h.frame),r=Ie.useEffectiveEditorCardType(),{setCard:i,updateCardInFrame:d}=s.useEditorActions(),o=["table","aggregateTable","pivotTable","detailTable"].includes(r),c=s.hasValidCardConfig(n.config),l=s.isCustomVisualConfigCard(n,a.cards);if(!o||!c||l)return null;const x=h=>{if(l)return;const m=h,y=n.config??{},v=p(r,m,y),u={...n,type:m,config:v};i(u),d(u)},p=(h,m,y)=>{var u;if(m==="detailTable"){const b=L=>L==null?void 0:L.toLowerCase().replace(/\s+/g,"").trim(),w=(L,E)=>{const j=[b(L.label),b(L.qualifiedFieldName),b(L.name)].filter(Boolean),k=[b(E.label),b(E.qualifiedFieldName),b(E.name)].filter(Boolean);return j.some(I=>k.includes(I))},T=(y.groupByColumns||[]).map(L=>({...L,role:"detail"})),V=((u=y.sortByColumns)==null?void 0:u.filter(L=>T.some(E=>w(L,E))))??[];return{...y,detailTableBackup:{groupByColumns:y.groupByColumns,metricColumns:y.metricColumns,pivotByColumns:y.pivotByColumns,sortByColumns:y.sortByColumns,rowAggregates:y.rowAggregates,columnAggregates:y.columnAggregates,comparisonType:y.comparisonType},detailColumns:T,groupByColumns:[],metricColumns:[],pivotByColumns:[],sortByColumns:V,rowAggregates:[],columnAggregates:[],comparisonType:"none"}}let v=y;if(h==="detailTable")if(y.detailTableBackup)v={...y,...y.detailTableBackup,detailColumns:[],detailTableBackup:void 0};else{const b=(y.detailColumns||[]).map(w=>({...w,role:"groupby"}));v={...y,groupByColumns:b,detailColumns:[]}}return m==="aggregateTable"?{...v,pivotByColumns:[]}:v};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:r,onValueChange:x,className:"flex flex-row items-center gap-1 border-b border-border/60",children:Kn.map(h=>{const m=h.icon,y=r===h.value;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:h.value,id:`table-type-${h.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${h.value}`,className:s.cn("flex h-8 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-b-2 border-transparent px-2 pb-1 text-xs font-medium transition-colors",y?"border-foreground text-foreground":"text-muted-foreground hover:border-foreground/30 hover:text-foreground"),children:[e.jsx(m,{className:s.cn("h-3.5 w-3.5",y?"opacity-100":"opacity-75")}),h.label]})]},h.value)})})})}function Qs({error:t,errorSql:n,errorTitle:a="Unable to load data",onOpenInEditor:r,onDebugWithAssistant:i,onSendFeedback:d,showFeedbackButton:o=!0,className:c}){const[l,x]=C.useState(!1);return e.jsx("div",{className:s.cn("rounded-lg border border-border bg-muted/40 p-4",c),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-amber-500/10 dark:bg-amber-500/20",children:e.jsx(s.TriangleAlert,{className:"h-4 w-4 text-amber-600 dark:text-amber-500"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:a}),e.jsxs("div",{className:"relative rounded-md border border-border bg-background p-3",children:[e.jsx(s.CopyButton,{text:t,className:"absolute right-2 top-2 z-10 h-6 w-6"}),e.jsx("div",{className:"max-h-40 overflow-auto pr-10",children:e.jsx("p",{className:"break-all font-mono text-xs text-muted-foreground",children:t})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.jsx(s.Collapsible,{open:l,onOpenChange:x,children:e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",children:l?e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronUp,{className:"mr-1.5 h-3.5 w-3.5"}),"Hide Details"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronDown,{className:"mr-1.5 h-3.5 w-3.5"}),"Show Details"]})})})}),r&&n&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:r,children:[e.jsx(ha,{className:"mr-1.5 h-3.5 w-3.5"}),"Open in Editor"]}),o&&d&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:d,children:[e.jsx(s.MessageSquareWarning,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Feedback"]}),i&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:i,children:[e.jsx(dn,{className:"mr-1.5 h-3.5 w-3.5"}),"Debug with Assistant"]})]}),n&&e.jsx(s.Collapsible,{open:l,onOpenChange:x,children:e.jsx(s.CollapsibleContent,{className:"space-y-2",children:e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Query"}),e.jsx(s.CopyButton,{text:n,className:"h-6 w-6"})]}),e.jsx("div",{className:"max-h-80 overflow-auto rounded-md border border-border bg-background p-2",children:e.jsx(s.CodeHighlighter,{code:n,language:"sql"})})]})})})]})]})})}function Na(t,n){const a=s.useEditorStore(x=>x.card),r=s.useEditorStore(x=>x.isDevMode),{switchEditorMode:i,setRunSql:d,runAssistant:o}=s.useEditorActions();return{isDevMode:r,handleOpenInEditor:r?void 0:()=>{const x=n||a.sql||a.python||"";i("dev",{sqlToLoad:x}),setTimeout(()=>{d(!0)},100)},handleDebugWithAssistant:r?()=>{const x=`Can you help me debug this query?
|
|
171
|
+
|
|
172
|
+
Error:
|
|
173
|
+
|
|
174
|
+
${t}
|
|
175
|
+
|
|
176
|
+
Error SQL:
|
|
177
|
+
|
|
178
|
+
${n||a.sql||a.python}
|
|
179
|
+
|
|
180
|
+
`;o(x)}:void 0}}function Ca({className:t,...n}){var X,oe,me,Z,xe;const a=s.useEditorStore(B=>B.card);s.useEditorStore(B=>B.isDevMode);const r=((X=a.customCardPreferences)==null?void 0:X.showCardHeader)??!0,i=((me=(oe=a.preferences)==null?void 0:oe.displayOptions)==null?void 0:me.showInlineFilterBar)??!0,d=s.useEditorStore(B=>B.frame),o=s.useDashboardStore(B=>B.dashboard.filters),c=s.useDashboardStore(B=>B.selectedSheetId),[l,x]=C.useState(!1),{currentUser:p}=s.useCurrentUserInfo(),{tokenProps:h}=C.useContext(s.SemaphorContext),m=s.useEditorStore(B=>B.actions.setRunSql),{updateFilter:y}=s.useDashboardActions(),v=o==null?void 0:o.find(B=>B.id===d.filterId),u=C.useMemo(()=>s.findCustomVisualConfigCard(d,a),[d,a]),{manifest:b}=s.useCustomVisual(((Z=u==null?void 0:u.customCardPreferences)==null?void 0:Z.url)||""),w=C.useMemo(()=>{var B;return(B=b==null?void 0:b.visuals)==null?void 0:B.find(ee=>{var ce;return ee.name===((ce=u==null?void 0:u.customCardPreferences)==null?void 0:ce.componentName)})},[b,(xe=u==null?void 0:u.customCardPreferences)==null?void 0:xe.componentName]),T=s.resolveMultiInputType(u,w),V=C.useMemo(()=>s.getCustomVisualInputCards({frame:d,configCard:u,isMultiInputVisual:T==="multiple"}),[d,u,T]),L=C.useMemo(()=>{const B=V.findIndex(ee=>(ee==null?void 0:ee.id)===(a==null?void 0:a.id));return B<0?-1:s.getSlotIndexForCard(a,B)},[V,a]),E=C.useMemo(()=>!u||T!=="multiple"||L<0?a.type:s.getEffectiveCardTypeForSlot(a,L,w==null?void 0:w.slots)??a.type,[u,T,L,a,w==null?void 0:w.slots]),j=E??a.type,k=C.useMemo(()=>j===a.type?a:{...a,type:j},[a,j]),I=C.useMemo(()=>E!==a.type?{...a,type:E}:a,[a,E]),{data:f,isLoading:A,isFetching:g,errorMessage:D,errorSql:M,pagination:P}=s.useDashboardCardQuery(I),{handleOpenInEditor:N,handleDebugWithAssistant:O}=Na(D,M||a.sql||a.python),S=C.useMemo(()=>(f==null?void 0:f.records)||[],[f==null?void 0:f.records]),{setCard:R,updateCardInFrame:F}=s.useEditorActions(),{data:$}=s.useTopoJson(k),U=C.useMemo(()=>{var B;return j!=="pivotTable"||!((B=f==null?void 0:f.records)!=null&&B.length)?null:{records:f.records,columnSubtotalMeta:f.columnSubtotalMeta,subtotalColumns:f.subtotalColumns||[],pivotSchema:f.pivotSchema||[],groupByColumns:f.groupByColumns}},[j,f==null?void 0:f.records,f==null?void 0:f.columnSubtotalMeta,f==null?void 0:f.subtotalColumns,f==null?void 0:f.pivotSchema,f==null?void 0:f.groupByColumns]),z=s.usePivotTableConfig(k,U),H=()=>{x(!0)},se=C.useMemo(()=>{const B=typeof window<"u"?window.location.href:"",ee=typeof navigator<"u"?navigator.userAgent:"",ce=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:s.FeedbackCategory.QUERY_GENERATION,user:p,tokenContext:h,systemState:{cardConfig:a.config,dataSource:a.dataSource,dashboardFilters:o,errorMessage:D||void 0,errorSql:M||a.sql||a.python,generatedSql:M||a.sql},metadata:{url:B,userAgent:ee,timestamp:new Date().toISOString(),viewport:ce}}},[p,h,a,o,D,M]),Y=(B,ee)=>{var he,ke;const ce={...a,paginationConfig:{page:B+1,pageSize:ee}};R(ce),F(ce),a.sql&&((ke=(he=a.preferences)==null?void 0:he.tablePrefs)!=null&&ke.enableDevModePagination)&&m(!0)},ae=B=>{var he,ke,ye,Ee,Se;const ee=s.sortStateToSortByColumns(B,(he=a.config)==null?void 0:he.metricColumns,(ke=a.config)==null?void 0:ke.groupByColumns,(ye=a.config)==null?void 0:ye.detailColumns),ce={...a,config:{...a.config||{},sortByColumns:ee}};R(ce),F(ce),a.sql&&((Se=(Ee=a.preferences)==null?void 0:Ee.tablePrefs)!=null&&Se.enableDevModePagination)&&m(!0)},q=C.useMemo(()=>!k.id||!(f!=null&&f.records)?null:s.createChartConfig({card:k,data:f==null?void 0:f.records,cardType:j,queryConfig:k.queryConfig,customCfg:k.customCfg,preferences:k.preferences,topoJson:$}),[k,f==null?void 0:f.records,j,$]);function J(B){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(s.EditorCustomVisual,{card:B})})}function le(){var B;if(f!=null&&f.records&&(f==null?void 0:f.records.length)===0&&!A&&!g)return D?e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto p-4",children:e.jsx(Qs,{error:D,errorSql:M||a.sql||a.python,onOpenInEditor:N,onDebugWithAssistant:O,onSendFeedback:H,showFeedbackButton:!0})}):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 results to display"})]});if((A||g)&&(!(f!=null&&f.records)||f.records.length===0))return j==="table"||j==="detailTable"?e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableSkeleton,{})}):e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})});if(!k.id)return null;if(j==="custom")return J(a);if(!["table","pivotTable","aggregateTable","detailTable","custom"].includes(j)&&q)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:A||g?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:q})});if(j==="table"||j==="detailTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.TableVisual,{card:k,data:S,comparisonMetadata:(B=f==null?void 0:f.metadata)==null?void 0:B.comparisonMetadata,paginationMetadata:P,onPaginationChange:Y,onSortChange:ae,isLoading:A||g})});if(j==="pivotTable"&&z)return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.PivotTableTanstack,{card:k,data:z.data,options:z.options,onAggregationChange:ee=>{const ce=s.handleAggregationChange(ee,a.config),he={...a,config:ce};R(he),F(he)},onAggregationLabelChange:ee=>{const ce=s.handleAggregationLabelChange(ee,a.config),he={...a,config:ce};R(he),F(he)}})});if(j==="aggregateTable")return e.jsx("div",{className:"relative mb-2 flex h-full min-h-0 w-full flex-1 grow basis-0",children:e.jsx(s.AggregateTable,{card:k,data:(f==null?void 0:f.records)||[],groupByColumns:f==null?void 0:f.groupByColumns,pivotSchema:f==null?void 0:f.pivotSchema,paginationMetadata:P,onPaginationChange:Y,onAggregationChange:ee=>{const ce=s.handleAggregationChange(ee,a.config),he={...a,config:ce};R(he),F(he)},isLoading:A||g})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[(A||g)&&(f==null?void 0:f.records)&&f.records.length>0&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),r&&e.jsxs(s.CardHeader,{className:s.cn("flex flex-row items-start justify-between py-4 pr-6","pl-2"),children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.CardTitle,{className:"text-base",children:e.jsx(s.EditableText,{value:a.title,onSave:B=>R({...a,title:B}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(s.InfoHover,{card:a}),e.jsx(Ie.VisualBadge,{}),e.jsx("div",{className:"ml-auto",children:e.jsx(Un,{})})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:(a.description||"").trim(),onSave:B=>R({...a,description:B.trim()}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),v&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:v.title||v.column,onSave:B=>y({...v,title:B}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:v})]})]}),i&&a.inlineFilters&&a.inlineFilters.length>0&&e.jsx("div",{className:s.cn("pb-3 pr-6","pl-2"),children:e.jsx(s.InlineFilterBar,{card:a,sheetId:c||""})}),e.jsxs(s.CardContent,{className:s.cn("flex min-h-0 grow flex-col pr-6","pl-2"),children:[e.jsx("div",{className:"min-h-0 flex-1 grow basis-0",children:le()}),s.isCardSummaryVisibleOnCard(k)&&e.jsx("div",{className:"pt-3",children:e.jsx(s.CardSummary,{card:k,mode:"editor"})})]}),e.jsx(s.FeedbackDialog,{open:l,onOpenChange:x,feedbackData:se,showDebugInfo:!0})]})}const Ps=({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}),Hn=()=>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."})]})]}),Jn=({customCode:t,cardCustomCfgString:n,mergedConfig:a,onConfigChange:r,onCodeChange:i})=>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-config",children:"Changes"}),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(Ps,{language:"json",value:a,onChange:r})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ps,{readonly:!0,language:"json",value:n,onChange:()=>{}})}),e.jsx(s.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ps,{language:"javascript",value:t,onChange:i})})]}),Qn=({error:t,hasCardCustomConfig:n,onReset:a,onApply:r,onClose:i})=>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:i,variant:"outline",children:"Close"})]});function Yn({triggerVariant:t="icon",className:n,label:a="Customize Visual"}={}){const[r,i]=C.useState(!1),[d,o]=C.useState(""),[c,l]=C.useState(""),[x,p]=C.useState(""),[h,m]=C.useState(""),y=s.useEditorStore(A=>A.card),v=Ie.useEffectiveEditorCardType(),u=s.useEditorStore(A=>A.card.customCfg),b=u?JSON.stringify(u,null,2):"",w=C.useMemo(()=>v!==y.type?{...y,type:v}:y,[y,v]),{data:T}=s.useDashboardCardQuery(w),{data:V}=s.useTopoJson(y),{setCardCustomCfg:L,setCustomVisualCode:E}=s.useEditorActions(),j=A=>{var g,D;return JSON.stringify({...A,data:{...A.data,datasets:(D=(g=A.data)==null?void 0:g.datasets)==null?void 0:D.map(M=>({...M,data:[]}))}},null,2)},k=()=>{var g,D;if(!((g=T==null?void 0:T.records)!=null&&g.length))return;const A=s.createChartConfig({card:y,data:T.records,cardType:y.type,queryConfig:y.queryConfig,preferences:y.preferences,topoJson:V});if(A){o(j(A)),p(((D=y.preferences)==null?void 0:D.customVisualCode)||"");const M=s.merge(A,u);l(j(M))}},I=()=>{try{if(x&&E(x),c){const A=JSON.parse(c),g=s.getObjectDiff(JSON.parse(d),A);L(g),m("")}}catch{m("Invalid JSON configuration")}},f=Object.keys(u||{}).length===0;return e.jsxs(s.Dialog,{open:r,onOpenChange:i,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:t==="menu"?e.jsxs(s.Button,{variant:"ghost",onClick:k,className:s.cn("h-8 w-full justify-start gap-2 px-2 text-sm",f?"":"text-green-600 hover:text-green-700",n),children:[e.jsx(s.Settings,{className:"h-4 w-4"}),e.jsx("span",{children:a})]}):e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:k,className:s.cn(f?"":"text-green-600 hover:text-green-700",n),children:e.jsx(s.Settings,{className:"h-4 w-4"})})}),e.jsxs(s.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(Hn,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Ca,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Jn,{customCode:x,cardCustomCfgString:b,mergedConfig:c,onConfigChange:A=>l(A??""),onCodeChange:A=>p(A??"")})]}),e.jsx(Qn,{error:h,hasCardCustomConfig:!!u,onReset:()=>{l(d),L(null)},onApply:I,onClose:()=>i(!1)})]})]})}function Wn({isStarred:t,onClick:n,className:a}){const r=i=>{i.stopPropagation(),i.preventDefault(),n(i)};return e.jsx("button",{type:"button",onClick:r,className:s.cn("flex items-center justify-center rounded-sm p-0.5 transition-all","hover:bg-muted/80",a),"aria-label":t?"Remove from favorites":"Add to favorites",children:e.jsx(s.Star,{className:s.cn("h-3.5 w-3.5 transition-colors",t?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-foreground")})})}function Xt({chartType:t,chartName:n,isCustom:a=!1,pluginName:r,isStarred:i,showStar:d=!0,onSelect:o,onToggleStar:c}){return e.jsxs("button",{onClick:o,className:s.cn("group relative flex flex-col items-center gap-2 rounded-lg border border-border","bg-background p-3 transition-all","hover:border-primary/50 hover:bg-muted/50 hover:shadow-sm"),children:[d&&e.jsx("div",{className:s.cn("absolute left-1 top-1 transition-opacity",i?"opacity-100":"opacity-0 group-hover:opacity-100"),children:e.jsx(Wn,{isStarred:i,onClick:()=>c()})}),a&&r&&e.jsx("div",{className:"absolute right-1 top-1",children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"flex items-center justify-center",children:e.jsx(s.Info,{className:"h-3 w-3 text-muted-foreground"})})}),e.jsx(s.TooltipContent,{side:"top",className:"text-xs",children:r})]})}),e.jsx(s.ChartIcon,{chartType:t,chartName:n,isCustom:a,className:"h-6 w-6"}),e.jsx("span",{title:n,className:"line-clamp-2 text-center text-xs font-medium text-foreground",children:n})]})}const Zt=[{id:"table",name:"Table"},{id:"bar",name:"Bar Chart"},{id:"line",name:"Line Chart"},{id:"area",name:"Area Chart"},{id:"combo",name:"Combo Chart"},{id:"stackedBar",name:"Stacked Bar"},{id:"stackedArea",name:"Stacked Area"},{id:"stackedLine",name:"Stacked Line"},{id:"scatter",name:"Scatter"},{id:"bubble",name:"Bubble"},{id:"pie",name:"Pie Chart"},{id:"doughnut",name:"Doughnut"},{id:"funnel",name:"Funnel"},{id:"radar",name:"Radar"},{id:"polarArea",name:"Polar Area"},{id:"tornado",name:"Tornado"},{id:"range",name:"Range"},{id:"bullet",name:"Bullet Chart"},{id:"treemap",name:"Treemap"},{id:"heatmap",name:"Heatmap"},{id:"kpi",name:"KPI"},{id:"text",name:"Text"},{id:"map",name:"Map"}];function Xn({onChartSelect:t,onClose:n}){const[a,r]=C.useState(""),{starredCharts:i,isStarred:d,toggleStar:o}=s.useStarredChartsStore(),{data:c=[],isLoading:l}=s.useCustomVisualsQuery(),{setCardType:x,setCardPreferences:p,setIsDevMode:h}=s.useEditorStore(f=>f.actions),m=s.useEditorStore(f=>f.card),{setCardCustomCfg:y,setCustomCardPreferences:v,setQueryConfig:u,replaceFrameCards:b,clearModeDrafts:w,initializeModeDrafts:T}=s.useEditorActions(),V=C.useMemo(()=>{if(!a)return Zt;const f=a.toLowerCase();return Zt.filter(A=>A.name.toLowerCase().includes(f))},[a]),L=C.useMemo(()=>{const f=c.filter(g=>g.componentType==="chart"&&g.pluginType!=="standard");if(!a)return f;const A=a.toLowerCase();return f.filter(g=>g.name.toLowerCase().includes(A))},[c,a]),E=f=>{y(null),p({}),x(f),["custom","text","map"].includes(f)&&(h(!0),u(void 0)),t==null||t(f),n==null||n()},j=f=>{y(null),p({}),u(void 0);const A=s.resolveMultiInputTypeFromVisual(f);if(A==="multiple"&&f.slots&&f.slots.length>0){w();const D=s.createCardsFromSlots(f.slots,f,m);b(D),D[0]&&T(D[0]),n==null||n();return}else x("custom"),v({type:"component",visualType:A,url:f.url,componentName:f.name,icon:f.icon,pluginChartType:f.chartType,minInputs:f.minInputs,maxInputs:f.maxInputs});t==null||t("custom",f),n==null||n()},k=f=>{const A={type:"default",id:f.id,name:f.name};o(A)},I=f=>{const A={type:"custom",id:f.name,url:f.url,icon:f.icon,name:f.name};o(A)};return e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 rounded-sm border border-border bg-background px-3 py-2",children:[e.jsx(s.Search,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search charts...",value:a,onChange:f=>r(f.target.value),className:"h-auto border-0 p-0 text-sm focus-visible:ring-0 focus-visible:ring-offset-0"})]}),e.jsxs("div",{className:"max-h-[350px] overflow-y-auto",children:[V.length>0&&e.jsx("div",{className:"mb-3",children:e.jsx("div",{className:"grid grid-cols-3 gap-2",children:V.map(f=>e.jsx(Xt,{chartType:f.id,chartName:f.name,isCustom:!1,isStarred:d("default",f.id),onSelect:()=>E(f.id),onToggleStar:()=>k(f)},f.id))})}),L.length>0&&e.jsxs(e.Fragment,{children:[V.length>0?e.jsx(s.Separator,{className:"my-3"}):null,e.jsxs("div",{children:[e.jsx("span",{className:"mb-2 block text-xs font-medium text-muted-foreground",children:"Custom Charts"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:L.map((f,A)=>e.jsx(Xt,{chartName:f.name,isCustom:!0,pluginName:f.pluginName,isStarred:d("custom",f.name),onSelect:()=>j(f),onToggleStar:()=>I(f)},`${f.url}-${f.name}-${A}`))})]})]}),l&&e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),e.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"Loading custom charts..."})]}),V.length===0&&L.length===0&&!l&&e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No charts found"})]})]})}function Zn({selectedChart:t,onChartChange:n}){var j,k,I,f;const a=s.useEditorStore(A=>A.card),r=s.useEditorStore(A=>A.frame),i=s.useEditorStore(A=>A.isDevMode),{replaceFrameCards:d,clearModeDrafts:o,initializeModeDrafts:c,setIsDevMode:l}=s.useEditorActions(),x=C.useMemo(()=>s.findCustomVisualConfigCard(r,a),[r,a]),{manifest:p}=s.useCustomVisual(((j=x==null?void 0:x.customCardPreferences)==null?void 0:j.url)||""),h=C.useMemo(()=>{var A;return(A=p==null?void 0:p.visuals)==null?void 0:A.find(g=>{var D;return g.name===((D=x==null?void 0:x.customCardPreferences)==null?void 0:D.componentName)})},[p,(k=x==null?void 0:x.customCardPreferences)==null?void 0:k.componentName]),m=s.resolveMultiInputType(x,h)==="multiple",y=Ie.useEffectiveEditorCardType(),v=m?y:t??a.type,u=(I=a==null?void 0:a.customCardPreferences)==null?void 0:I.componentName,b=(f=x==null?void 0:x.customCardPreferences)==null?void 0:f.componentName,w=m&&!!b,T=C.useMemo(()=>{const A=s.chartTypes.find(g=>g.id===v);return A?A.label:v==="custom"?u||"Custom Visual":"Select chart type"},[v,u]),V=C.useMemo(()=>{const A=s.chartTypes.find(g=>g.id===v);if(A){const g=A.icon;return e.jsx(g,{className:"h-4 w-4"})}if(v==="custom"&&u){const g=s.getAutoDetectedChartIcon(u);return g||e.jsx(s.ChartIcon,{chartName:u,isCustom:!0,className:"h-4 w-4"})}return e.jsx(jn,{className:"h-4 w-4"})},[v,u]);return{displayChartType:v,displayLabel:T,displayIcon:V,showBadge:w,badgeLabel:b,isMultiInputContext:m,handleChartSelect:A=>{n==null||n(A)},handleClearCustomVisual:A=>{A.stopPropagation();const g={...a,type:"bar",sql:"",python:"",config:void 0,queryConfig:void 0,customCfg:void 0,preferences:{},customCardPreferences:void 0,title:"Chart",tabTitle:"Chart",description:void 0,info:void 0};d([g]),o(),c(g),i&&l(!0),n==null||n("bar")}}}function Ys({selectedChart:t,onChartChange:n,variant:a="ghost",className:r}){const[i,d]=C.useState(!1),{displayLabel:o,displayIcon:c,showBadge:l,badgeLabel:x,handleChartSelect:p,handleClearCustomVisual:h}=Zn({selectedChart:t,onChartChange:n});return e.jsxs("div",{className:s.cn("relative w-full",r),children:[e.jsxs(s.Popover,{open:i,onOpenChange:d,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:a,role:"combobox","aria-expanded":i,className:"w-full justify-between gap-2 border-border/70 bg-background text-foreground/90",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[c,e.jsx("span",{className:"truncate",children:o})]}),e.jsx(s.ChevronDown,{className:"h-4 w-4 shrink-0 opacity-70"})]})}),e.jsx(s.PopoverContent,{className:"w-[360px] p-3",align:"start",onOpenAutoFocus:m=>m.preventDefault(),children:e.jsx(Xn,{onChartSelect:m=>p(m),onClose:()=>d(!1)})})]}),l&&e.jsxs("div",{className:"absolute right-10 top-1/2 z-10 flex max-w-[140px] -translate-y-1/2 items-center gap-1 rounded-full border bg-background py-0.5 pl-2 pr-1 text-[10px] text-muted-foreground shadow-sm",title:x,children:[e.jsx(s.Layers,{className:"h-2.5 w-2.5 shrink-0"}),e.jsx("span",{className:"truncate",children:x}),e.jsx("button",{onClick:h,className:"rounded-full p-0.5 hover:bg-muted",title:"Clear custom visual",children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]})]})}function er(){const t=s.useEditorStore(l=>{var x,p;return(p=(x=l.card.preferences)==null?void 0:x.chartOptions)==null?void 0:p.indexAxis}),n=s.useEditorStore(l=>l.card.type),{setChartOrientation:a,setCardPreferences:r}=s.useEditorStore(l=>l.actions),i=l=>{if(a(l),n!=="bullet")return;const x=l==="y"?"horizontal":"vertical",p=s.useEditorStore.getState().card.preferences,h={...p||{},bulletConfig:{...(p==null?void 0:p.bulletConfig)||{},orientation:x}};r(h)};function d(){const l=t??"x",x=()=>{i(l==="x"?"y":"x")};return e.jsx(s.IconButton,{onClick:x,tooltip:"Chart Orientation",children:l==="x"?e.jsx(Fs,{className:"size-4"}):e.jsx(Rs,{className:"size-4"})})}function o(){const l=()=>{i(t==="y"||t===void 0?"x":"y")};return e.jsx(s.IconButton,{onClick:l,tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(Fs,{className:"size-4"}):e.jsx(Rs,{className:"size-4"})})}function c(){const l=t??"y",x=()=>{i(l==="y"?"x":"y")};return e.jsx(s.IconButton,{onClick:x,tooltip:"Chart Orientation",children:l==="y"?e.jsx(Rs,{className:"size-4"}):e.jsx(Fs,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?o():n==="bullet"?c():d()})}function Ws({className:t,triggerVariant:n="icon",label:a="Display Options"}){var u,b,w,T,V,L,E,j,k,I;const r=s.useEditorStore(f=>f.card),{setCardPreferences:i,updateCardInFrame:d,setCard:o}=s.useEditorActions(),[c,l]=C.useState(!1),x=((b=(u=r.preferences)==null?void 0:u.displayOptions)==null?void 0:b.showFilterInfo)??!0,p=((T=(w=r.preferences)==null?void 0:w.displayOptions)==null?void 0:T.showCardToolbar)??!0,h=((L=(V=r.preferences)==null?void 0:V.displayOptions)==null?void 0:L.showChrome)??!0,m=((j=(E=r.preferences)==null?void 0:E.displayOptions)==null?void 0:j.allowScroll)??!0,y=((I=(k=r.preferences)==null?void 0:k.displayOptions)==null?void 0:I.showInlineFilterBar)??!0,v=(f,A)=>{var M;const g={...r.preferences,displayOptions:{...(M=r.preferences)==null?void 0:M.displayOptions,[f]:A}};i(g);const D={...r,preferences:g};o(D),d(D)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:c,onOpenChange:l,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:n==="menu"?e.jsxs(s.Button,{variant:"ghost",className:"h-8 w-full justify-start gap-2 px-2 text-sm",children:[e.jsx(Us,{className:"h-4 w-4"}),e.jsx("span",{children:a})]}):e.jsx(s.IconButton,{className:"h-8 w-8 p-0",tooltip:"Display Options",children:e.jsx(Us,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx(s.DropdownMenuLabel,{children:"Display Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx("div",{className:"px-2 py-1.5",children:e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:"Changes apply to dashboard view only"})}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:x,onCheckedChange:f=>{v("showFilterInfo",f)},onSelect:f=>f.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Filter Info"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Badge"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:p,onCheckedChange:f=>{v("showCardToolbar",f)},onSelect:f=>f.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Toolbar"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Hover actions"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:h,onCheckedChange:f=>{v("showChrome",f)},onSelect:f=>f.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Card Chrome"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Frame & padding"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:m,onCheckedChange:f=>{v("allowScroll",f)},onSelect:f=>f.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Allow Scroll"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Card content scroll"})]}),e.jsxs(s.DropdownMenuCheckboxItem,{checked:y,onCheckedChange:f=>{v("showInlineFilterBar",f)},onSelect:f=>f.preventDefault(),className:"pr-2",children:[e.jsx("span",{className:"flex-1",children:"Inline Filter Bar"}),e.jsx("span",{className:"ml-4 text-xs text-muted-foreground",children:"Card filters"})]})]})]})})}function Xs({className:t,triggerVariant:n="icon",label:a="Inline Filters"}){const[r,i]=C.useState(!1),d=s.useEditorStore(u=>u.card),o=s.useEditorStore(u=>u.selectedConnectionId),{setCard:c}=s.useEditorActions(),l=s.useDashboardStore(u=>u.actions.removeCardInlineFilterValue),x=(d==null?void 0:d.inlineFilters)||[];function p(u){var A,g,D,M,P;const b=((D=(g=(A=d==null?void 0:d.dataSource)==null?void 0:A.selectedEntities)==null?void 0:g[0])==null?void 0:D.database)||"",w=u.qualifiedFieldName||u.name;if(x.find(N=>N.column===w))return;const V=u.qualifiedFieldName?u.qualifiedFieldName.split(".").slice(0,-1).join("."):u.qualifiedEntityName||u.entityName,E=s.fmt(u.name),j=s.buildFilterFieldMeta(u),k=s.buildFilterSemanticContext(d==null?void 0:d.dataSource,{connectionId:o||((M=d==null?void 0:d.dataSource)==null?void 0:M.connectionId),connectionType:(P=d==null?void 0:d.dataSource)==null?void 0:P.connectionType}),I=s.isCalculatedFilterField(j),f={id:s.v4(),column:w,title:u.label||u.name,dataType:u.dataType,table:u.entityName||"",database:b,connectionId:o||"",operation:"in",sql:I?"":s.getDefaultFilterSql(u.dataType,V,E),fieldMeta:j,semanticContext:k,width:250};c({...d,inlineFilters:[...x,f]})}function h(u){const b=x.filter(w=>w.id!==u);c({...d,inlineFilters:b}),l(d.id,u)}function m(u,b){const w=x.map(T=>T.id===u?{...T,...b}:T);c({...d,inlineFilters:w})}if(!["bar","line","pie","doughnut","table","detailTable","stackedBar","stackedLine","horizontalBar","radar","polarArea","scatter","bubble","funnel","aggregateTable","custom"].includes(d==null?void 0:d.type))return null;const v=n==="menu";return e.jsx("div",{className:s.cn("flex items-center gap-1",v&&"w-full",t),children:e.jsxs(s.Popover,{open:r,onOpenChange:i,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:v?e.jsxs(s.Button,{variant:"ghost",className:s.cn("h-8 w-full justify-start gap-2 px-2 text-sm",x.length>0&&"text-primary"),children:[e.jsx(_t,{className:"h-4 w-4"}),e.jsx("span",{children:a}),x.length>0&&e.jsx("span",{className:"ml-auto inline-flex min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-medium text-primary-foreground",children:x.length})]}):e.jsxs(s.IconButton,{tooltip:"Add Inline Filter",className:s.cn("relative",{"text-primary":x.length>0}),children:[e.jsx(_t,{className:"h-4 w-4"}),x.length>0&&e.jsx("span",{className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] font-medium text-primary-foreground",children:x.length})]})}),e.jsx(s.PopoverContent,{align:"end",className:s.cn("w-80 p-0",v&&"z-[60]"),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"border-b px-4 py-3",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Inline Filters"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"On-card filters for fast, focused exploration."})]}),e.jsx("div",{className:"flex max-h-[300px] flex-col overflow-hidden",children:e.jsx(s.DndContext,{collisionDetection:s.closestCenter,children:e.jsx(s.SortableContext,{items:[],strategy:s.verticalListSortingStrategy,children:e.jsx(s.FieldsList,{context:"inline-filter",onFieldSelect:p,inlineFilters:x})})})}),x.length>0&&e.jsxs("div",{className:"border-t px-4 py-3",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Active Filters"}),e.jsx("div",{className:"space-y-1",children:x.map(u=>e.jsx(sr,{filter:u,onUpdate:b=>m(u.id,b),onRemove:()=>h(u.id)},u.id))})]})]})})]})})}function sr({filter:t,onUpdate:n,onRemove:a}){return e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-muted px-2 py-1.5 text-sm",children:[e.jsx("span",{className:"truncate",title:t.column,children:t.title}),e.jsxs("div",{className:"flex items-center gap-0.5",children:[e.jsx(s.CustomFilterPopover,{filter:t,variant:"inline",onAccept:r=>n(r),trigger:e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0",title:"Configure filter",children:e.jsx(s.Settings2,{className:"h-3 w-3"})})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 shrink-0 hover:bg-destructive/10 hover:text-destructive",onClick:a,children:e.jsx(s.X,{className:"h-3 w-3"})})]})]})}function Sa({showOrientation:t=!0,showGridStyle:n=!0,showInlineFilters:a=!0,showDisplayOptions:r=!0}={}){const i=s.useEditorStore(m=>m.card),d=s.useEditorStore(m=>{var y,v;return(v=(y=m.card)==null?void 0:y.preferences)==null?void 0:v.chartOptions}),o=s.getChartGridStyle(d),{setChartGrid:c}=s.useEditorActions();function l(){const m=["xy","none","x","y"],v=(m.indexOf(o)+1)%m.length;c(m[v])}const x=t&&["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(i.type),p=n&&!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(i.type);return x||p||a||r?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[x&&e.jsx(e.Fragment,{children:e.jsx(er,{})}),p&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:l,children:[(o==="xy"||!o)&&e.jsx(s.Grid3x3,{className:"size-4"}),o==="x"&&e.jsx(Js,{className:"size-4"}),o==="y"&&e.jsx(Ss,{className:"size-4"}),o==="none"&&e.jsx(s.Square,{className:"size-4"})]}),a&&e.jsx(Xs,{}),r&&e.jsx(Ws,{})]}):null}function tr({isPreviewMode:t,onPreviewToggle:n,configCard:a}){var P,N,O,S,R;const r=s.useEditorStore(F=>F.frame),i=s.useEditorStore(F=>F.card),{setFrame:d,setActiveTabCardId:o,setCard:c,updateCardInFrame:l,clearModeDrafts:x,initializeModeDrafts:p}=s.useEditorActions(),{manifest:h}=s.useCustomVisual(((P=a==null?void 0:a.customCardPreferences)==null?void 0:P.url)||""),m=(N=h==null?void 0:h.visuals)==null?void 0:N.find(F=>{var $;return F.name===(($=a==null?void 0:a.customCardPreferences)==null?void 0:$.componentName)}),v=s.resolveMultiInputType(a,m)==="multiple",u=(m==null?void 0:m.minInputs)??((O=a==null?void 0:a.customCardPreferences)==null?void 0:O.minInputs)??1,b=(m==null?void 0:m.maxInputs)??((S=a==null?void 0:a.customCardPreferences)==null?void 0:S.maxInputs),w=C.useMemo(()=>s.getCustomVisualInputCards({frame:r,configCard:a,isMultiInputVisual:v}),[r,a,v]),T=v?w.filter(Boolean).length:r.cards.length,V=b?T<b:!0,L=T>Math.max(u||1,1),E=!!((R=a==null?void 0:a.customCardPreferences)!=null&&R.dataInputCardIds),j=(F,$)=>{F.dataTransfer.setData("tabIndex",$.toString())},k=F=>{F.preventDefault()},I=(F,$)=>{const U=F.dataTransfer.getData("tabIndex");if(U===$.toString())return;const z=Array.from(r.cards),[H]=z.splice(parseInt(U),1);z.splice($,0,H),d({...r,cards:z})};function f(F){const $=(a==null?void 0:a.id)===F;if(!(E&&$?r.cards.length>1:L))return;let z=r.cards.filter(ae=>ae.id!==F);v&&!E&&(z=s.reindexSlotCards(z));const H=z[0],se={...r,cards:z,activeCardId:H.id},Y=F===i.id;Y&&x(),d(se),o(H.id),c(H),Y&&p(H)}function A(F,$){if(!V)return;const U={...r,cards:[...r.cards,$],activeCardId:F.id};d(U),o($.id)}function g(){if(v&&(a==null?void 0:a.id)===i.id){D(i);return}const F={...i,id:s.v4(),title:`${i.title} Copy`,tabTitle:`${i.tabTitle||i.title} Copy`,customCardPreferences:i.customCardPreferences?{...i.customCardPreferences,slotIndex:v?Math.max(-1,...w.map(($,U)=>s.getSlotIndexForCard($,U)))+1:i.customCardPreferences.slotIndex}:void 0};A(i,F)}function D(F){var Y;if(!V)return;let $=v?"table":"bar",U="Title",z="";const H=v?Math.max(-1,...w.map((ae,q)=>s.getSlotIndexForCard(ae,q)))+1:T;if(v&&((Y=m==null?void 0:m.slots)!=null&&Y.length)){const ae=s.getSlotDefinitionForIndex(m.slots,H);ae&&($=s.getSlotExpectedChartType(ae),U=ae.label||`Tab ${H+1}`,z=ae.description||"")}const se={dataSource:F.dataSource,connectionId:F.connectionId,lastSelectedDatabase:F.lastSelectedDatabase,lastSelectedSchema:F.lastSelectedSchema,lastSelectedTable:F.lastSelectedTable,lastSelectedDatamodelId:F.lastSelectedDatamodelId,id:s.v4(),title:U,tabTitle:U,description:z,preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:$,sql:"",data:[],mode:"explorer",...v&&{customCardPreferences:{slotIndex:H}}};A(F,se)}function M(F,$){return F.cards.length===1&&($.displayTab===!0||$.displayTab===void 0)||F.activeCardId!==$.id&&($.displayTab===!0||$.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const U=$.displayTab===void 0?!1:!$.displayTab;c({...$,displayTab:U}),l({...$,displayTab:U})},children:$.displayTab===!0||$.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(s.EyeOff,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(s.TabsList,{className:"group ml-2 mr-6 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[r.cards.map((F,$)=>{var Y,ae;const U=v?s.getSlotIndexForCard(F,$):-1,z=v&&((Y=m==null?void 0:m.slots)!=null&&Y.length)&&U>=0?s.getSlotDefinitionForIndex(m.slots,U):null,H=z?(Array.isArray(z.expectedType)?z.expectedType[0]:z.expectedType)||"table":F.type,se=v&&((ae=m==null?void 0:m.slots)==null?void 0:ae.length)&&m.slots.every(q=>typeof q.position=="number"||typeof q.position=="string"&&!q.position.includes("+"));return e.jsxs(s.TabsTrigger,{draggable:!v,onDragStart:v?void 0:q=>j(q,$),onDragOver:v?void 0:k,onDrop:v?void 0:q=>I(q,$),className:"",value:F.id,children:[v&&z?e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s.getChartIconByType(H,"size-3.5")}),e.jsx("span",{children:z.label||`Tab ${U+1}`})]})}),e.jsx(s.TooltipContent,{side:"bottom",className:"w-64 p-3 text-left",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium",children:z.label}),z.description&&e.jsx("p",{className:"whitespace-normal break-words text-xs text-muted-foreground",children:z.description}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[z.expectedType&&e.jsx("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:Array.isArray(z.expectedType)?z.expectedType.join(" / "):z.expectedType}),z.required&&e.jsx("span",{className:"inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground",children:"Required"})]})]})})]})}):e.jsxs(e.Fragment,{children:[M(r,F),e.jsx(s.Editable,{enabled:r.activeCardId===F.id,text:F.tabTitle||F.title,onSave:q=>{c({...i,tabTitle:q}),l({...i,tabTitle:q})},children:F.tabTitle||F.title},F.id)]}),r.activeCardId===F.id&&!se&&e.jsx(s.CopyPlus,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:q=>{q.stopPropagation(),g()}}),r.activeCardId===F.id&&(E&&(a==null?void 0:a.id)===F.id?r.cards.length>1:L)&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>f(F.id)})]},F.id)}),e.jsx(s.IconButton,{tooltip:"Add Card",className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",onClick:()=>D(i),disabled:!V,children:e.jsx(s.Plus,{className:"h-4 w-4"})}),v&&e.jsxs(s.Toggle,{pressed:t,onPressedChange:n,size:"sm",className:"ml-2 h-8 gap-1 px-2 data-[state=on]:bg-background data-[state=on]:text-foreground","aria-label":"Toggle preview",children:[t?e.jsx(s.EyeOff,{className:"h-4 w-4"}):e.jsx(s.Eye,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:"Preview"})]})]})})}function Hs(){var ke,ye,Ee,Se,Pe;const t=s.useEditorStore(ne=>ne.frame),n=s.useEditorStore(ne=>ne.card),[a,r]=C.useState(!1),i=C.useMemo(()=>s.findCustomVisualConfigCard(t,n),[t,n]),d=s.useEditorStore(ne=>ne.isSqlRunning);s.useEditorStore(ne=>ne.isDevMode);const{setFrame:o,setActiveTabCardId:c,setCard:l,setRunSql:x,mergeDraftsIntoCard:p,clearModeDrafts:h,initializeModeDrafts:m}=s.useEditorActions(),[y,v]=C.useState({}),[u,b]=C.useState(()=>new Set),{theme:w}=s.useTheme(),T=s.useDashboardStore(ne=>ne.themeStyle),{authToken:V}=s.useSemaphorContext(),L=s.getTokenParams(V==null?void 0:V.accessToken),E={mode:w||"system",colors:((ye=(ke=T==null?void 0:T.chart)==null?void 0:ke.dataset)==null?void 0:ye.backgroundColor)||[]},{getCard:j,manifest:k,isLoading:I}=s.useCustomVisual(((Ee=i==null?void 0:i.customCardPreferences)==null?void 0:Ee.url)||""),f=(Se=i==null?void 0:i.customCardPreferences)==null?void 0:Se.componentName,A=f?j(f):null,g=(Pe=k==null?void 0:k.visuals)==null?void 0:Pe.find(ne=>ne.name===f),D=s.resolveMultiInputType(i,g),M=a&&D==="multiple"&&!!i,P=C.useMemo(()=>s.getCustomVisualInputCards({frame:t,configCard:i,isMultiInputVisual:!0}).map(je=>(je==null?void 0:je.id)===n.id?n:je),[t,i,n]),N=C.useMemo(()=>s.buildSlotOrderedCards(P),[P]),O=C.useMemo(()=>{const ne=P.findIndex(je=>(je==null?void 0:je.id)===n.id);return ne<0?-1:s.getSlotIndexForCard(n,ne)},[P,n]),S=C.useMemo(()=>!i||D!=="multiple"||O<0?n.type:s.getEffectiveCardTypeForSlot(n,O,g==null?void 0:g.slots)??n.type,[i,D,O,n,g==null?void 0:g.slots]),R=C.useMemo(()=>M?{...n,connectionId:void 0,dataSource:void 0,sql:"",python:"",config:void 0,queryConfig:void 0}:S!==n.type?{...n,type:S}:n,[n,S,M]),{data:F,isLoading:$,isFetching:U,isError:z}=s.useDashboardCardQuery(R),H=C.useCallback((ne,je)=>{const pe=s.normalizeMultiInputPayload(je);v(Te=>({...Te,[ne]:pe}))},[]),se=C.useCallback((ne,je)=>{b(pe=>{const Te=new Set(pe);return je?Te.add(ne):Te.delete(ne),Te})},[]),Y=u.size>0,ae=s.useInteractionStore(ne=>ne.interactionStates),q=s.useDashboardStore(ne=>{var je;return(je=ne.dashboard)==null?void 0:je.id}),J=s.useDashboardStore(ne=>ne.dashboard.filters),le=s.useDashboardStore(ne=>ne.filterValues),X=s.useDashboardStore(ne=>ne.selectedSheetId),oe=s.useDashboardStore(ne=>ne.inlineFilterValuesMap[(i==null?void 0:i.id)||""]),me=C.useMemo(()=>i?s.buildInlineFilterNodes({card:i,sheetId:X||"",inlineFilterValues:oe}):[],[i,X,oe]),{cardFilters:Z,cardFilterValues:xe}=C.useMemo(()=>i?s.calculateContextAwareFilters({card:i,interactionStates:ae,currentDashboardId:q,filters:J,filterValues:le,selectedSheetId:X}):{cardFilters:[],cardFilterValues:[]},[i,ae,q,J,le,X]);function B(ne){const je=t.cards.find(pe=>pe.id===ne);je&&(p(),ee(ne),c(ne),h(),m(je))}function ee(ne){const je=s.useEditorStore.getState().card,pe=s.useEditorStore.getState().frame,Te={...pe,cards:pe.cards.map(ve=>ve.id===je.id?je:ve),activeCardId:ne};o(Te);const Ae=Te.cards.find(ve=>ve.id===ne);Ae.sql&&x(!0),l(Ae)}function ce(){if(I)return e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading manifest"})});if(!A)return e.jsx("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select a component to preview the multi-input visual."});const je=N.map((pe,Te)=>s.getEffectiveCardTypeForSlot(pe,Te,g==null?void 0:g.slots));return e.jsxs("div",{className:"relative flex h-full flex-col pl-2 pr-4",children:[P.map((pe,Te)=>{if(!pe)return null;const Ae=s.getSlotIndexForCard(pe,Te),ve=s.getEffectiveCardTypeForSlot(pe,Ae,g==null?void 0:g.slots);return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:se,onDataChange:H,card:pe,effectiveCardType:ve},`${pe.id}-${Ae}`)}),Y&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading preview"})}),e.jsx("div",{className:s.cn("flex h-full min-h-0 flex-1 flex-col gap-2",Y&&"opacity-50"),children:e.jsx(C.Suspense,{fallback:e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted"})}),children:e.jsx(A,{editing:!0,...s.buildMultiInputCustomVisualProps({configCard:i,slotOrderedCards:N,slotTypes:je,multiInputData:y,params:L,theme:E,filters:Z,filterValues:[...xe||[],...oe||[]],inlineFilters:me})})})})]})}function he(){var ne;return M?ce():n.type==="kpi"?$||U?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"w-1/2 space-y-3",children:[e.jsx("div",{className:"rounded-md border border-border",children:e.jsx(s.KPICard,{card:n,data:F==null?void 0:F.records,isPending:$||U,isError:z,comparisonMetadata:(ne=F==null?void 0:F.metadata)==null?void 0:ne.comparisonMetadata})}),s.isCardSummaryVisibleOnCard(n)&&e.jsx(s.CardSummary,{card:n,mode:"editor"})]})}):n.type==="text"?$||U?e.jsx("div",{className:"z-50 flex h-full items-center justify-center",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}):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:d,card:n,data:F==null?void 0:F.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Ca,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:B,value:t.activeCardId,className:"flex grow flex-col gap-2",children:[M?e.jsx("div",{className:"mt-0 grow",children:he()}):t.cards.map(ne=>e.jsx(s.TabsContent,{className:"mt-0 grow focus-visible:ring-0 focus-visible:ring-offset-0",value:ne.id,children:he()},ne.id)),e.jsx(tr,{isPreviewMode:M,onPreviewToggle:r,configCard:i})]})}function ea({children:t,visualAsideControl:n}){var U;const a=s.useEditorStore(z=>z.frame),r=s.useEditorStore(z=>z.card),i=r.type==="table"||r.type==="detailTable",d=s.useEditorStore(z=>z.isDevMode),o=s.useEditorStore(z=>z.isShowingVisual),c=s.useEditorStore(z=>z.actions.setIsShowingVisual),l=s.useDashboardStore(z=>z.isVisualEditing),{isConsoleMode:x}=s.useDashboardPreferences(),p=s.useEditorStore(z=>z.pythonStdOut),h=s.useEditorStore(z=>z.actions.setRunSql),m=Ie.useEffectiveEditorCardType(),{setFrame:y,setCard:v,setActiveTabCardId:u,setCardPreferences:b,mergeDraftsIntoCard:w,clearModeDrafts:T,initializeModeDrafts:V}=s.useEditorActions(),L=C.useMemo(()=>m!==r.type?{...r,type:m}:r,[r,m]),{data:E,isLoading:j,isFetching:k,errorMessage:I,errorSql:f,refetch:A,pagination:g}=s.useDashboardCardQuery(L),{handleDebugWithAssistant:D}=Na(I,f),M=C.useMemo(()=>(E==null?void 0:E.records)||[],[E==null?void 0:E.records]),[P,N]=C.useState(!1);C.useEffect(()=>{k||N(!1)},[k]),C.useEffect(()=>{i&&!o&&c(!0)},[i,o,c]);function O(z,H){var ae,q;const se={...r,paginationConfig:{page:z+1,pageSize:H}};v(se);const Y={...a,cards:a.cards.map(J=>J.id===r.id?se:J)};y(Y),r.sql&&((q=(ae=r.preferences)==null?void 0:ae.tablePrefs)!=null&&q.enableDevModePagination)&&h(!0)}function S(z){var ae,q,J,le,X;const H=s.sortStateToSortByColumns(z,(ae=r.config)==null?void 0:ae.metricColumns,(q=r.config)==null?void 0:q.groupByColumns,(J=r.config)==null?void 0:J.detailColumns),se={...r,config:{...r.config||{},sortByColumns:H}};v(se);const Y={...a,cards:a.cards.map(oe=>oe.id===r.id?se:oe)};y(Y),r.sql&&((X=(le=r.preferences)==null?void 0:le.tablePrefs)!=null&&X.enableDevModePagination)&&h(!0)}function R(){var H;const z=JSON.stringify(E==null?void 0:E.records,null,2);typeof navigator>"u"||!((H=navigator.clipboard)!=null&&H.writeText)||navigator.clipboard.writeText(z).catch(se=>{console.error("Failed to copy JSON",se)})}function F(){const z=JSON.stringify(E==null?void 0:E.records,null,2),H=new Blob([z],{type:"application/json"}),se=URL.createObjectURL(H),Y=document.createElement("a");Y.href=se,Y.download=`${r.title}.json`,Y.click()}function $(){const H=[Object.keys(E==null?void 0:E.records.reduce((q,J)=>({...q,...J}),{})).join(","),...((E==null?void 0:E.records)||[]).map(q=>Object.values(q).join(","))].join(`
|
|
181
|
+
`),se=new Blob([H],{type:"text/csv"}),Y=URL.createObjectURL(se),ae=document.createElement("a");ae.href=Y,ae.download=`${r.title}.csv`,ae.click()}return r?e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 pl-2 pr-6",children:[o&&e.jsx("div",{className:"flex grow items-center",children:e.jsxs("div",{className:"flex items-center gap-1",children:[(n==null?void 0:n.show)&&e.jsx(s.IconButton,{tooltip:n.isOpen?"Hide Visual Aside":"Show Visual Aside",className:"h-9 w-9 px-0",buttonProps:{variant:"outline"},onClick:n.onToggle,children:n.isOpen?e.jsx(s.ChevronLeft,{className:"size-4"}):e.jsx(s.ChevronRight,{className:"size-4"})}),e.jsx("div",{className:"w-[200px]",children:e.jsx(Ys,{variant:d?"secondary":"ghost"})})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(s.IconButton,{tooltip:"Refresh",disabled:j||k,onClick:()=>{N(!0),A()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":P})})}),e.jsx(Sa,{showInlineFilters:!1,showDisplayOptions:!1}),(d||x)&&e.jsxs(e.Fragment,{children:[!i&&e.jsx(rr,{}),i&&e.jsx(nr,{})]}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-8 w-8 px-0","aria-label":"More options",children:e.jsx(s.EllipsisVertical,{className:"size-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx(s.DropdownMenuLabel,{children:"More Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"px-1 py-1",children:[!["table","detailTable","custom"].includes(r.type)&&l&&e.jsx(Yn,{triggerVariant:"menu",className:"w-full"}),e.jsx(Xs,{triggerVariant:"menu",className:"w-full"}),e.jsx(Ws,{triggerVariant:"menu",className:"w-full"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.Button,{variant:"ghost",className:"h-8 w-full justify-start gap-2 px-2 text-sm",onClick:$,children:[e.jsx(s.Download,{className:"h-4 w-4"}),e.jsx("span",{children:"Download CSV"})]}),e.jsxs(s.Button,{variant:"ghost",className:"h-8 w-full justify-start gap-2 px-2 text-sm",onClick:F,children:[e.jsx(on,{className:"h-4 w-4"}),e.jsx("span",{children:"Download JSON"})]}),e.jsxs(s.Button,{variant:"ghost",className:"h-8 w-full justify-start gap-2 px-2 text-sm",onClick:R,children:[e.jsx(s.Copy,{className:"h-4 w-4"}),e.jsx("span",{children:"Copy JSON"})]})]})]})]})]})]}),o?e.jsx(Hs,{}):e.jsxs(s.ResizablePanelGroup,{className:"py-2 pl-2 pr-6",direction:"horizontal",children:[p&&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:p&&e.jsx(ar,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:s.cn("relative flex h-full min-h-0 w-full flex-1 basis-0",{"py-2 pl-2 pr-6":p}),children:[(E==null?void 0:E.records)&&(E==null?void 0:E.records.length)>0&&e.jsx(s.TableVisual,{card:r,data:M,comparisonMetadata:(U=E==null?void 0:E.metadata)==null?void 0:U.comparisonMetadata,paginationMetadata:g,onPaginationChange:O,onSortChange:S,isLoading:j||k}),I&&e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto p-4",children:e.jsx(Qs,{error:I,errorSql:f||r.sql||r.python,onDebugWithAssistant:D,showFeedbackButton:!1})})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function ar(){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",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:n}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function nr(){var d,o,c,l,x,p;const t=s.useEditorStore(h=>h.card),n=s.useEditorStore(h=>h.actions.setCard),a=s.useEditorStore(h=>h.actions.setRunSql),r=s.useEditorStore(h=>h.actions.setCardPreferences),i=s.useEditorStore(h=>h.actions.updateCardInFrame);return t.type!=="table"&&t.type!=="detailTable"?null:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"dev-pagination",checked:((o=(d=t.preferences)==null?void 0:d.tablePrefs)==null?void 0:o.enableDevModePagination)??!1,onCheckedChange:h=>{var m;r({...t.preferences,tablePrefs:{...(m=t.preferences)==null?void 0:m.tablePrefs,enableDevModePagination:h}})}}),e.jsx(s.Label,{htmlFor:"dev-pagination",className:"cursor-pointer text-sm",children:"Paginate"}),((l=(c=t.preferences)==null?void 0:c.tablePrefs)==null?void 0:l.enableDevModePagination)&&e.jsxs(s.Select,{value:String(((p=(x=t.preferences)==null?void 0:x.tablePrefs)==null?void 0:p.pageSize)||50),onValueChange:h=>{var v,u,b;const m=Number(h),y={...t,preferences:{...t.preferences,tablePrefs:{...(v=t.preferences)==null?void 0:v.tablePrefs,pageSize:m}},paginationConfig:{page:1,pageSize:m}};n(y),i(y),t.sql&&((b=(u=t.preferences)==null?void 0:u.tablePrefs)!=null&&b.enableDevModePagination)&&a(!0)},children:[e.jsx(s.SelectTrigger,{className:"h-8 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"10",children:"10"}),e.jsx(s.SelectItem,{value:"25",children:"25"}),e.jsx(s.SelectItem,{value:"50",children:"50"}),e.jsx(s.SelectItem,{value:"100",children:"100"}),e.jsx(s.SelectItem,{value:"500",children:"500"}),e.jsx(s.SelectItem,{value:"1000",children:"1000"})]})]})]})}function rr(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs(s.Toggle,{pressed:!t,onPressedChange:a=>{n(!a)},variant:"default",size:"sm",className:"h-8 gap-2 border border-transparent text-foreground/80 hover:bg-accent hover:text-accent-foreground data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",children:[e.jsx(s.Table2,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Results"})]})}function Me({value:t,onCommit:n,type:a="text",placeholder:r,className:i}){const[d,o]=C.useState(t),c=C.useRef(!1);C.useEffect(()=>{o(t)},[t]);const l=()=>{if(c.current){c.current=!1;return}d!==t&&n(d)},x=p=>{if(p.key==="Enter"){p.currentTarget.blur();return}p.key==="Escape"&&(c.current=!0,o(t),p.currentTarget.blur())};return e.jsx(s.Input,{type:a,placeholder:r,value:d,onChange:p=>o(p.target.value),onBlur:l,onKeyDown:x,className:i})}function Je({defaultValue:t,label:n,options:a,value:r,onValueChange:i,className:d,icon:o,showPlaceholderLabel:c=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",d),children:e.jsxs("div",{className:"flex items-center gap-2",children:[o&&e.jsx("span",{children:o}),c&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}function lr(t,n){return s.getSlotDefinitionForIndex(t,n)||null}function hs(t){if(typeof t=="number")return`Tab ${t+1}`;const n=t.match(/^(\d+)-(\d+)$/);if(n){const[,r,i]=n;return`Tabs ${Number(r)+1}-${Number(i)+1}`}const a=t.match(/^(\d+)\+$/);return a?`Tabs ${Number(a[1])+1}+`:`Tab ${t}`}function or(t){return t?Array.isArray(t)?t:[t]:[]}function Bs(t){var r,i;if(!t)return!1;if(t.type==="text")return!!((r=t.description)!=null&&r.trim());const n=!!((i=t.sql)!=null&&i.trim()),a=s.hasValidCardConfig(t.config);return n||a}function ir({slots:t,cards:n,minInputs:a}){const r=[],i=n.filter(Boolean).length;return a&&i<a&&r.push({type:"too-few-inputs",message:`This visual requires at least ${a} tab${a===1?"":"s"}.`}),!t||t.length===0||(t.forEach(d=>{if(!d.required)return;if(typeof d.position=="number"){const l=n[d.position];Bs(l)||r.push({type:"missing-required",message:`${hs(d.position)} ("${d.label}") is required but has no data configured.`});return}const o=d.position.match(/^(\d+)-(\d+)$/);if(o){const[,l,x]=o.map(Number);for(let p=l;p<=x;p+=1){const h=n[p];if(!Bs(h)){r.push({type:"missing-required",message:`${hs(p)} ("${d.label}") is required but has no data configured.`});break}}return}const c=d.position.match(/^(\d+)\+$/);if(c){const l=Number(c[1]);if(n.length<=l){r.push({type:"missing-required",message:`${hs(l)} ("${d.label}") is required but has no data configured.`});return}for(let x=l;x<n.length;x+=1){const p=n[x];if(!Bs(p)){r.push({type:"missing-required",message:`${hs(x)} ("${d.label}") is required but has no data configured.`});break}}}}),n.forEach((d,o)=>{if(!d)return;const c=lr(t,o);if(!c||!c.expectedType)return;const l=or(c.expectedType);l.length!==0&&(l.includes(d.type)||r.push({type:"wrong-type",message:`${hs(o)} ("${c.label}") expects ${l.join(", ")}, but is configured as ${d.type}.`}))})),r}const cr={table:({children:t})=>e.jsx("table",{className:"my-3 w-full border-collapse overflow-hidden rounded-md border border-border text-sm",children:t}),thead:({children:t})=>e.jsx("thead",{className:"bg-muted",children:t}),th:({children:t})=>e.jsx("th",{className:"border border-border px-3 py-2 text-left font-medium",children:t}),td:({children:t})=>e.jsx("td",{className:"border border-border px-3 py-2",children:t}),code:({children:t,className:n})=>(n==null?void 0:n.includes("language-"))?e.jsx("pre",{className:"my-3 overflow-x-auto rounded-md bg-muted p-3 text-xs",children:e.jsx("code",{children:t})}):e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:t}),pre:({children:t})=>e.jsx(e.Fragment,{children:t})};function wa(){var D,M,P;const t=s.useEditorStore(N=>N.card.customCardPreferences),{data:n}=s.usePluginQuery(),a=(n==null?void 0:n.plugins)||[],r=s.useEditorStore(N=>N.card),i=s.useEditorStore(N=>N.frame),{setCustomCardPreferences:d}=s.useEditorActions(),o=C.useMemo(()=>s.findCustomVisualConfigCard(i,r),[i,r]),c=o==null?void 0:o.customCardPreferences,{components:l,manifest:x}=s.useCustomVisual((c==null?void 0:c.url)||(t==null?void 0:t.url)||""),p=(D=x==null?void 0:x.visuals)==null?void 0:D.find(N=>N.name===((c==null?void 0:c.componentName)||(t==null?void 0:t.componentName))),m=s.resolveMultiInputType(o||r,p)==="multiple",y=!!o&&o.id===r.id,v=(p==null?void 0:p.minInputs)??((M=o==null?void 0:o.customCardPreferences)==null?void 0:M.minInputs),u=(p==null?void 0:p.maxInputs)??((P=o==null?void 0:o.customCardPreferences)==null?void 0:P.maxInputs),b=C.useMemo(()=>s.getCustomVisualInputCards({frame:i,configCard:o||r,isMultiInputVisual:m}),[i,o,r,m]),w=C.useMemo(()=>s.buildSlotOrderedCards(b),[b]),T=C.useMemo(()=>w.map((N,O)=>{if(!N)return null;const S=s.getSlotIndexForCard(N,O),R=s.getEffectiveCardTypeForSlot(N,S,p==null?void 0:p.slots);return{...N,type:R??N.type}}),[w,p==null?void 0:p.slots]),V=C.useMemo(()=>ir({slots:p==null?void 0:p.slots,cards:T,minInputs:v}),[p==null?void 0:p.slots,T,v]),L=C.useMemo(()=>{const N=b.findIndex(O=>(O==null?void 0:O.id)===r.id);return N<0?-1:s.getSlotIndexForCard(r,N)},[b,r]);function E(N){if(typeof N=="number")return`Tab ${N+1}`;const O=N.match(/^(\d+)-(\d+)$/);if(O){const[,R,F]=O;return`Tabs ${Number(R)+1}-${Number(F)+1}`}const S=N.match(/^(\d+)\+$/);return S?`Tabs ${Number(S[1])+1}+`:`Tab ${N}`}function j(N){return N?(Array.isArray(N)?N:[N]).join(", "):null}function k(N,O,S=[],R="",F,$,U){const z=I({key:O,defaultValue:R,settingsValue:$,sourceCard:U});return N==="input"?e.jsx(Me,{className:`h-8 w-full ${s.removeRing}`,value:String(z??""),onCommit:H=>{f({key:O,value:H,settingsField:F,settingsValue:$,sourceCard:U})}},O):N==="select"?e.jsx(Je,{className:"h-8 w-full",label:"",options:S,value:String(z!==void 0?z:R??""),onValueChange:H=>{f({key:O,value:H,settingsField:F,settingsValue:$,sourceCard:U})}}):null}function I({key:N,defaultValue:O,settingsValue:S,sourceCard:R}){const F=S==null?void 0:S[N];return F!==void 0?F:N==="title"&&(R==null?void 0:R.title)!==void 0?R.title:N==="description"&&(R==null?void 0:R.description)!==void 0?R.description:O}function f({key:N,value:O,settingsField:S,settingsValue:R,sourceCard:F}){const $={...R||{}},U=N==="title"&&(F==null?void 0:F.title)!==void 0,z=N==="description"&&(F==null?void 0:F.description)!==void 0;U&&O===String((F==null?void 0:F.title)??"")||z&&O===String((F==null?void 0:F.description)??"")?delete $[N]:$[N]=O,d({...t||{},[S]:$})}function A({settingsSchema:N,settingsField:O,settingsValue:S,sourceCard:R,headerLabel:F}){const $=Object.entries(N||{});return e.jsxs("div",{className:"space-y-3",children:[F&&e.jsx(s.Label,{children:F}),$.map(([U,z])=>{var H;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{children:z.title}),((H=z.docs)==null?void 0:H.description)&&e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Info,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground"})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsx("p",{className:"text-xs",children:z.docs.description})})]})})]}),k(z.ui,U,z.options,z.defaultValue,O,S,R)]},U)})]})}function g(){return e.jsxs(e.Fragment,{children:[m&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Slot Guide"}),e.jsx("div",{className:"space-y-3 rounded-md border border-border bg-muted/40 px-3 py-2 text-xs",children:p!=null&&p.slots&&p.slots.length>0?e.jsx("div",{className:"space-y-3",children:p.slots.map((N,O)=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-foreground",children:[e.jsx("span",{className:"font-medium",children:E(N.position)}),e.jsx("span",{className:"text-muted-foreground",children:"•"}),e.jsx("span",{className:"font-medium",children:N.label})]}),N.description&&e.jsx("p",{className:"text-muted-foreground",children:N.description}),e.jsxs("div",{className:"flex flex-wrap gap-2 text-muted-foreground",children:[j(N.expectedType)&&e.jsxs("span",{children:["Expected: ",j(N.expectedType)]}),N.required&&e.jsx("span",{children:"Required"})]})]},`${N.label}-${O}`))}):e.jsxs("div",{className:"space-y-1 text-muted-foreground",children:[e.jsx("p",{children:"This visual renders all tabs in a flexible layout. Add as many tabs as needed."}),(v||u)&&e.jsxs("p",{children:[v?`Min ${v} tabs`:"",v&&u?" • ":"",u?`Max ${u} tabs`:""]})]})})]}),m&&V.length>0&&e.jsx(s.Alert,{className:"mt-3 border-yellow-500/40 bg-yellow-500/10 text-yellow-900 dark:text-yellow-100",children:e.jsx(s.AlertDescription,{children:e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs",children:V.map((N,O)=>e.jsx("li",{children:N.message},`${N.type}-${O}`))})})}),p&&!m&&p.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:A({settingsSchema:p.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:r})})}),p&&m&&(p.settings||p.slotSettings)&&e.jsxs("div",{className:"mt-4 space-y-4",children:[y&&p.settings&&e.jsx("div",{className:"px-2",children:A({settingsSchema:p.settings,settingsField:"settings",settingsValue:t==null?void 0:t.settings,sourceCard:o||r,headerLabel:"Global Settings"})}),p.slotSettings&&e.jsx("div",{className:"px-2",children:A({settingsSchema:p.slotSettings,settingsField:"slotSettings",settingsValue:t==null?void 0:t.slotSettings,sourceCard:r,headerLabel:(()=>{const N=r.tabTitle||r.title,O=L>=0?L:0,S=y?"Slot 0":`Slot ${O}`;return N?`${S}: ${N} Settings`:`${S} Settings`})()})})]})]})}return e.jsxs(s.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"",children:[e.jsxs(s.AccordionItem,{value:"plugin-settings",children:[e.jsx(s.AccordionTrigger,{children:"Plugin"}),e.jsx(s.AccordionContent,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"space-y-4",children:[(!m||y)&&e.jsx(Je,{icon:e.jsx(xa,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:a,value:(c==null?void 0:c.url)||"",onValueChange:N=>d({...t||{url:"",componentName:""},url:N})}),m&&!y&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Switch to the config tab to change the plugin or component."})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&(!m||y)&&e.jsx(e.Fragment,{children:l&&e.jsx(Je,{icon:e.jsx(ln,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(l==null?void 0:l.map(N=>({value:N.name,label:N.name})))||[],value:t.componentName||"",onValueChange:N=>{var R;const O=(R=x==null?void 0:x.visuals)==null?void 0:R.find(F=>F.name===N),S=l==null?void 0:l.find(F=>F.name===N);d({...t,componentName:N,visualType:(O==null?void 0:O.visualType)||(S==null?void 0:S.type)||"single",minInputs:O==null?void 0:O.minInputs,maxInputs:O==null?void 0:O.maxInputs,pluginChartType:O==null?void 0:O.chartType})}})})]})})]}),((c==null?void 0:c.componentName)||(t==null?void 0:t.componentName))&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:(p==null?void 0:p.name)||"Settings"}),(p==null?void 0:p.docs)&&e.jsxs(s.HoverCard,{openDelay:0,closeDelay:100,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,onClick:N=>N.stopPropagation(),children:e.jsx(s.Info,{className:"h-3.5 w-3.5 cursor-help text-muted-foreground transition-colors hover:text-foreground"})}),e.jsx(s.HoverCardContent,{side:"right",align:"start",className:"max-h-[40vh] w-[500px] overflow-y-auto text-left",children:e.jsxs("div",{className:"space-y-4 text-left",children:[p.docs.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:p.docs.description}),p.docs.dataSchema&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Data Schema"}),e.jsx("div",{className:"prose prose-sm dark:prose-invert prose-pre:bg-muted prose-pre:text-xs max-w-none",children:e.jsx(s.Markdown,{remarkPlugins:[s.remarkGfm],components:cr,children:p.docs.dataSchema})})]}),(()=>{var O;const N=(O=p.docs)==null?void 0:O.useCases;return!N||N.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Use Cases"}),e.jsx("ul",{className:"space-y-1 text-sm",children:N.map((S,R)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-1 text-primary",children:"•"}),e.jsx("span",{children:S})]},R))})]})})()]})})]})]})}),e.jsx(s.AccordionContent,{children:g()})]})]})}function dr({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function r(o,c,l){const x=[...t];x[o]={...x[o],[c]:l},n(x)}function i(o){const c=[...t];c.splice(o,1),n(c)}function d(){n([...t,a])}return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{children:"Color Range"}),e.jsx(s.Button,{onClick:d,variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.Plus,{className:"size-3"})})]}),t.map((o,c)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input,{onChange:l=>r(c,"start",l.target.value),value:o.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input,{value:o.end,onChange:l=>r(c,"end",l.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input,{onChange:l=>r(c,"color",l.target.value),value:o.color,className:s.cn(`h-7 min-w-14 p-0 ${s.removeRing}`),type:"color",list:"presetColors"}),e.jsxs("datalist",{id:"presetColors",children:[e.jsx("option",{children:s.colors.green[600]}),e.jsx("option",{children:s.colors.red[500]}),e.jsx("option",{children:s.colors.yellow[400]}),e.jsx("option",{children:s.colors.orange[500]})]}),e.jsx(s.Button,{onClick:()=>i(c),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.X,{className:"size-3"})})]},c))]})}function ur(){var p,h,m,y,v;const t=s.useEditorStore(u=>u.card.preferences),n=s.useEditorStore(u=>u.actions.setCardPreferences),a=s.useEditorStore(u=>u.card),r=s.hasValidCardConfig(a.config),i=s.useEditorStore(u=>u.actions.setNumberFormat);s.useEditorStore(u=>{var b,w;return(w=(b=u.card.preferences)==null?void 0:b.formatNumber)==null?void 0:w.decimalPlaces});const d=s.useEditorStore(u=>{var b,w;return(w=(b=u.card.preferences)==null?void 0:b.formatNumber)==null?void 0:w.locale}),o=s.useEditorStore(u=>{var b,w;return(w=(b=u.card.preferences)==null?void 0:b.formatNumber)==null?void 0:w.currency});s.useEditorStore(u=>u.actions.setFilterOnClickField);const c=s.useEditorStore(u=>{var b,w;return(w=(b=u.card.preferences)==null?void 0:b.formatNumber)==null?void 0:w.colorRanges})||[],l=s.useEditorStore(u=>u.actions.setColorRanges),x=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(u=>u.currency))];return e.jsxs("div",{children:[!r&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((p=t==null?void 0:t.formatNumber)!=null&&p.enabled),onCheckedChange:u=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:u}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((h=t==null?void 0:t.formatNumber)==null?void 0:h.enabled)===!0||r)&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4",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:d||"none",onValueChange:u=>{var b,w,T;return i(((b=t==null?void 0:t.formatNumber)==null?void 0:b.decimalPlaces)||0,((w=t==null?void 0:t.formatNumber)==null?void 0:w.currency)||"",u,((T=t==null?void 0:t.formatNumber)==null?void 0:T.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:"Auto"},"none"),s.LOCALE_CURRENCY_PAIRS.map(u=>e.jsx(s.SelectItem,{value:u.locale,children:u.locale},u.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:u=>{var b,w,T;console.log("currency",u),i(((b=t==null?void 0:t.formatNumber)==null?void 0:b.decimalPlaces)||0,u==="none"?"":u,((w=t==null?void 0:t.formatNumber)==null?void 0:w.locale)||"",((T=t==null?void 0:t.formatNumber)==null?void 0:T.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"),x.map(u=>e.jsx(s.SelectItem,{value:u,children:u},u))]})})]})]})]}),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:((y=(m=t==null?void 0:t.formatNumber)==null?void 0:m.decimalPlaces)==null?void 0:y.toString())||"0",onValueChange:u=>{var b,w,T;return i(Number(u),((b=t==null?void 0:t.formatNumber)==null?void 0:b.currency)||"",((w=t==null?void 0:t.formatNumber)==null?void 0:w.locale)||"",((T=t==null?void 0:t.formatNumber)==null?void 0:T.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(u=>e.jsx(s.SelectItem,{value:u,children:u},u))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((v=t==null?void 0:t.formatNumber)==null?void 0:v.suffix)||"",className:"h-8 font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"K, M, B, %",onChange:u=>{var b,w,T;return i(((b=t==null?void 0:t.formatNumber)==null?void 0:b.decimalPlaces)||0,((w=t==null?void 0:t.formatNumber)==null?void 0:w.currency)||"",((T=t==null?void 0:t.formatNumber)==null?void 0:T.locale)||"",u.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(dr,{colorRanges:c,setColorRanges:l})]})]})}const mr={combo:{label:"Combo Chart",query:"SELECT x-axis, metric-1, metric-2, ... FROM table",fields:[{name:"x-axis",type:"category",description:"dimension"},{name:"metric-1, metric-2",type:"number",description:"can be bar, line, or area"}],description:"Combo charts allow mixing bar and line series with optional dual Y-axis for metrics with different scales.",docsUrl:"https://docs.semaphor.cloud/docs/charts/combo"},area:{label:"Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Area charts display quantitative data with filled areas under the line.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedArea:{label:"Stacked Area Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, city"},{name:"Y-axis",type:"number",description:"e.g., sales, population"}],description:"Stacked area charts show how multiple series contribute to a total over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},bar:{label:"Bar Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., city, product"},{name:"Y-axis",type:"number",description:"e.g., sales, count"}],description:"Bar charts compare values across categories using horizontal or vertical bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},line:{label:"Line Chart",query:"SELECT x-axis, y-axis-1, y-axis-2, ... FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date, month"},{name:"Y-axis",type:"number",description:"e.g., revenue, count"}],description:"Line charts show trends over time or continuous data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bar-line-area"},stackedBar:{label:"Stacked Bar Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., month"},{name:"Stack-by",type:"category",description:"e.g., product type"},{name:"Y-axis",type:"number",description:"e.g., sales"}],description:"Stacked bar charts show how parts contribute to a whole across categories.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},stackedLine:{label:"Stacked Line Chart",query:"SELECT x-axis, stack-by, y-axis FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., date"},{name:"Stack-by",type:"category",description:"e.g., region"},{name:"Y-axis",type:"number",description:"e.g., revenue"}],description:"Stacked line charts show cumulative trends over time.",docsUrl:"https://docs.semaphor.cloud/docs/charts/stacked"},pie:{label:"Pie Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Pie charts show proportions of a whole.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},doughnut:{label:"Doughnut Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., product, region"},{name:"Measure",type:"number",description:"e.g., sales, count"}],description:"Doughnut charts show proportions with a hollow center.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},polarArea:{label:"Polar Area Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., skill, metric"},{name:"Measure",type:"number",description:"e.g., score, value"}],description:"Polar area charts compare values using sectors of equal angle but varying radius.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},radar:{label:"Radar Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., attribute, skill"},{name:"Measure",type:"number",description:"e.g., score, rating"}],description:"Radar charts display multivariate data on axes starting from the same point.",docsUrl:"https://docs.semaphor.cloud/docs/charts/pie-donut-polar"},funnel:{label:"Funnel Chart",query:"SELECT label, measure FROM table",fields:[{name:"Label",type:"category",description:"e.g., stage name"},{name:"Measure",type:"number",description:"e.g., count, value"}],description:"Funnel charts visualize progressive reduction of data through stages.",docsUrl:"https://docs.semaphor.cloud/docs/charts/funnel"},bubble:{label:"Bubble Chart",query:"SELECT label, [group], x-axis, y-axis, radius FROM table",fields:[{name:"Label",type:"category",description:"e.g., city"},{name:"Group",type:"category",description:"e.g., region",optional:!0},{name:"X-axis",type:"number",description:"e.g., population"},{name:"Y-axis",type:"number",description:"e.g., income"},{name:"Radius",type:"number",description:"e.g., area"}],description:"Bubble charts display three dimensions of data using position and size.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},scatter:{label:"Scatter Chart",query:"SELECT label, [group], x-axis, y-axis FROM table",fields:[{name:"Label",type:"category",description:"e.g., item name"},{name:"Group",type:"category",description:"e.g., type",optional:!0},{name:"X-axis",type:"number",description:"e.g., price"},{name:"Y-axis",type:"number",description:"e.g., quantity"}],description:"Scatter charts show relationships between two numeric variables.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bubble"},tornado:{label:"Tornado Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Tornado charts compare two groups across categories using back-to-back bars.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},pyramid:{label:"Pyramid Chart",query:"SELECT dimension, cohort, metric FROM table",fields:[{name:"Dimension",type:"category",description:"e.g., age group"},{name:"Cohort",type:"category",description:"e.g., gender"},{name:"Metric",type:"number",description:"e.g., population"}],description:"Population pyramids show age and gender distribution.",docsUrl:"https://docs.semaphor.cloud/docs/charts/tornado"},range:{label:"Range Chart",query:"SELECT y-axis, label, range-from, range-to, range-value FROM table",fields:[{name:"Y-axis",type:"category",description:"e.g., category"},{name:"Label",type:"category",description:"e.g., range name"},{name:"Range-from",type:"number",description:"start value"},{name:"Range-to",type:"number",description:"end value"},{name:"Range-value",type:"number",description:"e.g., midpoint"}],description:"Range charts display data ranges with start and end values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/range"},heatmap:{label:"Heatmap",query:"SELECT x-axis, y-axis, value FROM table",fields:[{name:"X-axis",type:"category",description:"e.g., day"},{name:"Y-axis",type:"category",description:"e.g., hour"},{name:"Value",type:"number",description:"e.g., count, intensity"}],description:"Heatmaps visualize data density using color intensity.",docsUrl:"https://docs.semaphor.cloud/docs/charts/heatmap"},bullet:{label:"Bullet Chart",query:"SELECT label, actual, target, [ranges] FROM table",fields:[{name:"Label",type:"category",description:"e.g., metric name"},{name:"Actual",type:"number",description:"current value"},{name:"Target",type:"number",description:"goal value"},{name:"Ranges",type:"number",description:"threshold values",optional:!0}],description:"Bullet charts compare actual performance against targets.",docsUrl:"https://docs.semaphor.cloud/docs/charts/bullet"},text:{label:"Text Visual",query:"SELECT text FROM table LIMIT 1",fields:[{name:"Text",type:"string",description:"content to display"}],description:"Text visuals display dynamic text content from your data.",docsUrl:"https://docs.semaphor.cloud/docs/charts/text"},kpi:{label:"KPI",query:"SELECT current, previous FROM table",fields:[{name:"Current",type:"number",description:"current value"},{name:"Previous",type:"number",description:"comparison value"}],description:"KPI visuals display key performance indicators with comparison values.",docsUrl:"https://docs.semaphor.cloud/docs/charts/kpi"},map:{label:"Map Chart",query:"SELECT country, value FROM table",fields:[{name:"Country/Region",type:"category",description:"geographic identifier"},{name:"Value",type:"number",description:"e.g., population, sales"}],description:"Map charts visualize geographic data using color intensity.",docsUrl:"https://docs.semaphor.cloud/docs/charts/map"},table:{label:"Table",query:"SELECT column1, column2, ... FROM table",fields:[{name:"Columns",type:"category",description:"any data columns"}],description:"Tables display data in rows and columns.",docsUrl:"https://docs.semaphor.cloud/docs/charts/table"},detailTable:{label:"Detail Table",query:"SELECT column1, column2, ... FROM table ORDER BY column1 DESC",fields:[{name:"Columns",type:"category",description:"columns to display (no aggregation)"}],description:"Detail tables display raw records without aggregation. Ideal for event logs, transaction history, and audit trails.",docsUrl:"https://docs.semaphor.cloud/docs/charts/detail-table"}};function Ta(t){return mr[t]}function xr({chartType:t,showDocsLink:n=!0}){const a=Ta(t);return a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Query Format"}),e.jsx("code",{className:"block rounded-md bg-muted/50 px-3 py-2 font-mono text-xs text-foreground",children:a.query})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Fields"}),e.jsx("div",{className:"rounded-md border",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Field"}),e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Type"}),e.jsx("th",{className:"px-2.5 py-1.5 text-left font-medium text-muted-foreground",children:"Description"})]})}),e.jsx("tbody",{children:a.fields.map((r,i)=>e.jsxs("tr",{className:i<a.fields.length-1?"border-b":"",children:[e.jsxs("td",{className:"px-2.5 py-1.5 font-medium text-foreground",children:[r.name,r.optional&&e.jsx("span",{className:"ml-1 text-muted-foreground",children:"?"})]}),e.jsx("td",{className:"px-2.5 py-1.5 font-mono text-muted-foreground",children:r.type}),e.jsx("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:r.description||"—"})]},r.name))})]})})]}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:a.description}),n&&a.docsUrl&&e.jsxs("a",{href:a.docsUrl,target:"_blank",rel:"noopener noreferrer",onClick:r=>r.stopPropagation(),className:"inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline",children:["View documentation",e.jsx(s.ExternalLink,{className:"h-3 w-3"})]})]}):null}function hr({chartType:t}){return Ta(t)?e.jsxs(s.HoverCard,{openDelay:200,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded bg-muted px-2 py-0.5 font-mono text-[10px] font-semibold uppercase tracking-wider text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground",children:"SQL"})}),e.jsx(s.HoverCardContent,{className:"w-80 p-4",side:"left",align:"start",sideOffset:8,children:e.jsx(xr,{chartType:t})})]}):null}function ws({chartType:t,suffix:n="Configuration"}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:n}),e.jsx(hr,{chartType:t})]})}function pr(){return e.jsxs("div",{className:"space-y-6 px-6 py-4",children:[e.jsx(ws,{chartType:"kpi"}),e.jsx("section",{children:e.jsx(ur,{})})]})}function sa({children:t,summary:n,open:a,className:r}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:n}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}function Ea(){const[t,n]=C.useState([]),a=s.useEditorStore(x=>x.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:i}=s.useEditorStore(x=>x.actions),d=s.useEditorStore(x=>x.queryResultColumns);s.useEditorStore(x=>{var p;return(p=x.card.preferences)==null?void 0:p.filterOnClickColumnIndex}),C.useEffect(()=>{d&&n(new Array(d.length).fill(!1))},[d]);function o(x,p){var h,m;p?a!=null&&a.onClickFilter&&((h=a==null?void 0:a.onClickFilter)==null?void 0:h.length)>0?i({...a,onClickFilter:[...a.onClickFilter,{columnIndex:x,expression:""}]}):i({...a,onClickFilter:[{columnIndex:x,expression:""}]}):(i({...a,onClickFilter:(m=a==null?void 0:a.onClickFilter)==null?void 0:m.filter(y=>y.columnIndex!==x)}),n(y=>{const v=[...y];return v[x]=!1,v}))}function c(x,p){var m;const h=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.map(y=>y.columnIndex===x?{...y,expression:p.target.value}:y);i({...a,onClickFilter:h})}function l(x){var p,h,m,y;if(t!=null&&t[x]||(h=(p=a==null?void 0:a.onClickFilter)==null?void 0:p.find(v=>v.columnIndex===x))!=null&&h.expression)return e.jsx(s.Input,{value:(y=(m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(v=>v.columnIndex===x))==null?void 0:y.expression,onChange:v=>c(x,v),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.jsx("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:d==null?void 0:d.map((x,p)=>{var h,m;return e.jsx("div",{className:"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:!!((h=a==null?void 0:a.onClickFilter)!=null&&h.find(y=>y.columnIndex===p)),onCheckedChange:y=>o(p,y)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:x}),e.jsx("div",{className:"flex items-center gap-2",children:((m=a==null?void 0:a.onClickFilter)==null?void 0:m.find(y=>y.columnIndex===p))&&e.jsx(s.Pencil,{onClick:()=>{n(y=>{const v=[...y];return v[p]=!y[p],v})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),l(p)]})},x)})})}const fr=[{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"}],gr=["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"],jr=gr.map(t=>({label:t,value:t}));function br(){var l,x,p,h,m,y,v,u,b,w,T,V,L,E,j,k,I,f;const t=s.useEditorStore(A=>A.card),n=(x=(l=t==null?void 0:t.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:x.topoJsonUrl,[a,r]=C.useState(((h=(p=t==null?void 0:t.preferences)==null?void 0:p.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:i}=s.useEditorActions(),{data:d}=s.useTopoJson(t),o=Object.keys((d==null?void 0:d.objects)||{}).map(A=>({label:A,value:A}))||[],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:"space-y-4 px-6 py-4",children:[e.jsx(ws,{chartType:"map"}),e.jsx(sa,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(Je,{className:"h-9",options:c,onValueChange:A=>{console.log("value",A),i({...t.preferences,mapVisualOptions:{topoJsonUrl:A}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input,{onChange:A=>{r(A.target.value)},onBlur:()=>{var A;console.log("onBlur",a),i({...t.preferences,mapVisualOptions:{...(A=t.preferences)==null?void 0:A.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(Je,{className:"h-9",options:o,value:((y=(m=t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:y.objectKey)||"",label:"Map Object",onValueChange:A=>{var g;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,objectKey:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(Je,{className:"h-9",options:fr,value:((u=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:u.projection)||"",label:"Projection",onValueChange:A=>{var g;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projection:A}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(Je,{className:"h-9",options:jr,value:((w=(b=t.preferences)==null?void 0:b.mapVisualOptions)==null?void 0:w.colorScale)||"",label:"Select Color Scale",onValueChange:A=>{var g;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,colorScale:A}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(sa,{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=(T=t.preferences)==null?void 0:T.mapVisualOptions)==null?void 0:V.projectionScale)||1,onChange:A=>{var g;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionScale:Number(A.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((j=(E=(L=t.preferences)==null?void 0:L.mapVisualOptions)==null?void 0:E.projectionOffset)==null?void 0:j[0])||0,onChange:A=>{var g,D,M,P;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[Number(A.target.value),((P=(M=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:P[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((f=(I=(k=t.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:I.projectionOffset)==null?void 0:f[1])||0,onChange:A=>{var g,D,M,P;i({...t.preferences,mapVisualOptions:{...(g=t.preferences)==null?void 0:g.mapVisualOptions,projectionOffset:[((P=(M=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:M.projectionOffset)==null?void 0:P[0])||0,Number(A.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Ea,{})]})}function Ia({color:t,onColorChange:n,onClose:a}){const[r,i]=C.useState(0),[d,o]=C.useState(100),[c,l]=C.useState(50),[x,p]=C.useState(t);C.useEffect(()=>{const b=ta(t);if(b){const w=aa(b.r,b.g,b.b);i(w.h),o(w.s),l(w.l),p(t)}},[t]);const h=b=>{i(b),y(b,d,c)},m=b=>{const w=b.currentTarget.getBoundingClientRect(),T=Math.max(0,Math.min(1,(b.clientX-w.left)/w.width)),V=Math.max(0,Math.min(1,(b.clientY-w.top)/w.height)),L=T*100,E=(1-V)*100;o(L),l(E),y(r,L,E)},y=(b,w,T)=>{const V=yr(b,w,T),L=vr(V.r,V.g,V.b);p(L)},v=b=>{if(p(b),/^#[0-9A-Fa-f]{6}$/.test(b)){const w=ta(b);if(w){const T=aa(w.r,w.g,w.b);i(T.h),o(T.s),l(T.l)}}},u=()=>{/^#[0-9A-Fa-f]{6}$/.test(x)&&(n(x),a())};return e.jsxs("div",{className:"p-4 space-y-4 w-[320px]",children:[e.jsxs("div",{className:"relative h-[200px] rounded cursor-crosshair",style:{background:`hsl(${r}, 100%, 50%)`},onClick:m,onMouseMove:b=>{b.buttons===1&&m(b)},children:[e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to right, white, transparent)"}}),e.jsx("div",{className:"absolute inset-0 rounded",style:{background:"linear-gradient(to bottom, transparent, black)"}}),e.jsx("div",{className:"absolute w-4 h-4 -ml-2 -mt-2 rounded-full border-2 border-white shadow-md",style:{left:`${d}%`,top:`${100-c}%`,backgroundColor:x}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:r,onChange:b=>h(Number(b.target.value)),className:"w-full h-4 rounded-lg appearance-none cursor-pointer",style:{background:"linear-gradient(to right, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000)"}})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"HEX"}),e.jsx(s.Input,{value:x,onChange:b=>v(b.target.value),placeholder:"#000000",className:"font-mono"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:t}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"CURRENT"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 rounded-full border shadow-sm",style:{backgroundColor:x}}),e.jsx("span",{className:"text-xs text-muted-foreground mt-1",children:"NEW"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(s.Button,{variant:"outline",onClick:a,children:"Cancel"}),e.jsx(s.Button,{onClick:u,children:"OK"})]})]})}function ta(t){const n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return n?{r:parseInt(n[1],16),g:parseInt(n[2],16),b:parseInt(n[3],16)}:null}function vr(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function aa(t,n,a){t/=255,n/=255,a/=255;const r=Math.max(t,n,a),i=Math.min(t,n,a);let d=0,o=0;const c=(r+i)/2;if(r!==i){const l=r-i;switch(o=c>.5?l/(2-r-i):l/(r+i),r){case t:d=((n-a)/l+(n<a?6:0))/6;break;case n:d=((a-t)/l+2)/6;break;case a:d=((t-n)/l+4)/6;break}}return{h:Math.round(d*360),s:Math.round(o*100),l:Math.round(c*100)}}function yr(t,n,a){t/=360,n/=100,a/=100;let r,i,d;if(n===0)r=i=d=a;else{const o=(x,p,h)=>(h<0&&(h+=1),h>1&&(h-=1),h<.16666666666666666?x+(p-x)*6*h:h<.5?p:h<.6666666666666666?x+(p-x)*(.6666666666666666-h)*6:x),c=a<.5?a*(1+n):a+n-a*n,l=2*a-c;r=o(l,c,t+1/3),i=o(l,c,t),d=o(l,c,t-1/3)}return{r:Math.round(r*255),g:Math.round(i*255),b:Math.round(d*255)}}const na=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Nr=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function Qe({value:t,onChange:n,label:a}){const[r,i]=C.useState(!1),[d,o]=C.useState(!1),c=()=>{const l=na.find(x=>x.value===t);return l?l.color:t.startsWith("#")?t:na[2].color};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:r,onOpenChange:i,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"size-5 rounded border-2 border-input shadow-sm transition-all hover:scale-110 hover:border-gray-400",style:{backgroundColor:c()},"aria-label":`Change color for ${a}`})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"grid grid-cols-3 items-center justify-items-center gap-1",children:Nr.map(l=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",c()===l?"border-gray-900":"border-transparent"),style:{backgroundColor:l},onClick:()=>{n(l),i(!1)},children:e.jsx("span",{className:"sr-only",children:l})},l))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{o(!0),i(!1)},children:"Custom color..."})]})})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),d&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>o(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Ia,{color:c(),onColorChange:l=>{n(l),o(!1)},onClose:()=>o(!1)})})]})]})}const Cr=["auto","number","currency","percent","scientific","date"],Sr=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"GBP",label:"GBP - British Pound"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"CHF",label:"CHF - Swiss Franc"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"},{value:"HKD",label:"HKD - Hong Kong Dollar"},{value:"SGD",label:"SGD - Singapore Dollar"},{value:"NZD",label:"NZD - New Zealand Dollar"},{value:"SEK",label:"SEK - Swedish Krona"},{value:"NOK",label:"NOK - Norwegian Krone"},{value:"DKK",label:"DKK - Danish Krone"},{value:"KRW",label:"KRW - South Korean Won"},{value:"INR",label:"INR - Indian Rupee"},{value:"RUB",label:"RUB - Russian Ruble"},{value:"BRL",label:"BRL - Brazilian Real"},{value:"MXN",label:"MXN - Mexican Peso"},{value:"TRY",label:"TRY - Turkish Lira"},{value:"ZAR",label:"ZAR - South African Rand"},{value:"SAR",label:"SAR - Saudi Riyal"},{value:"AED",label:"AED - UAE Dirham"},{value:"ARS",label:"ARS - Argentine Peso"},{value:"CLP",label:"CLP - Chilean Peso"},{value:"COP",label:"COP - Colombian Peso"},{value:"THB",label:"THB - Thai Baht"},{value:"IDR",label:"IDR - Indonesian Rupiah"},{value:"MYR",label:"MYR - Malaysian Ringgit"},{value:"PHP",label:"PHP - Philippine Peso"},{value:"PLN",label:"PLN - Polish Zloty"},{value:"NGN",label:"NGN - Nigerian Naira"},{value:"KES",label:"KES - Kenyan Shilling"},{value:"GHS",label:"GHS - Ghanaian Cedi"},{value:"ZMW",label:"ZMW - Zambian Kwacha"},{value:"ZWL",label:"ZWL - Zimbabwean Dollar"},{value:"EGP",label:"EGP - Egyptian Pound"},{value:"MAD",label:"MAD - Moroccan Dirham"},{value:"UAH",label:"UAH - Ukrainian Hryvnia"},{value:"HUF",label:"HUF - Hungarian Forint"},{value:"CZK",label:"CZK - Czech Koruna"},{value:"RON",label:"RON - Romanian Leu"},{value:"PKR",label:"PKR - Pakistani Rupee"},{value:"BDT",label:"BDT - Bangladeshi Taka"},{value:"VND",label:"VND - Vietnamese Dong"},{value:"TWD",label:"TWD - New Taiwan Dollar"},{value:"ILS",label:"ILS - Israeli New Shekel"}],wr=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"en-IN",label:"English (India)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"},{value:"ja-JP",label:"Japanese"},{value:"ko-KR",label:"Korean"},{value:"ru-RU",label:"Russian"},{value:"ar-SA",label:"Arabic"},{value:"hi-IN",label:"Hindi"},{value:"nl-NL",label:"Dutch"},{value:"sv-SE",label:"Swedish"}],Tr=t=>t.charAt(0).toUpperCase()+t.slice(1);function Ts({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:r="NUMBER FORMAT"}){const i=t.type||"auto",d=(c,l)=>{n({...t,[c]:l})},o=()=>i==="currency"?2:i==="percent"?1:0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[a&&e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:r}),e.jsxs(s.Select,{value:i,onValueChange:c=>d("type",c),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Cr.map(c=>e.jsx(s.SelectItem,{value:c,className:"text-xs",children:c==="auto"?"Auto (Default)":Tr(c)},c))})]})]}),i!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent"].includes(i)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",min:"0",max:"10",placeholder:"0",value:t.decimalPlaces??o(),onChange:c=>d("decimalPlaces",parseInt(c.target.value)||0),className:"h-8 text-xs"})})]}),i==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Currency"}),e.jsxs(s.Select,{value:t.currency||"USD",onValueChange:c=>d("currency",c),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Sr.map(c=>e.jsx(s.SelectItem,{value:c.value,className:"text-xs",children:c.label},c.value))})]})]}),["number","currency"].includes(i)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:t.useSuffix??!1,onCheckedChange:c=>d("useSuffix",c)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Locale"}),e.jsxs(s.Select,{value:t.locale||"en-US",onValueChange:c=>d("locale",c),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:wr.map(c=>e.jsx(s.SelectItem,{value:c.value,className:"text-xs",children:c.label},c.value))})]})]}),i==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Prefix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., $",value:t.prefix||"",onChange:c=>d("prefix",c.target.value),className:"h-8 text-xs"})})]}),i==="number"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Suffix"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{placeholder:"e.g., units",value:t.suffix||"",onChange:c=>d("suffix",c.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(i)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Negative in ()"}),e.jsx(s.SmallSwitch,{checked:t.negativeInParentheses??!1,onCheckedChange:c=>d("negativeInParentheses",c)})]}),i==="percent"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Multiply By"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"number",placeholder:"100",value:t.multiplyBy??"",onChange:c=>d("multiplyBy",c.target.value?parseFloat(c.target.value):void 0),className:"h-8 text-xs"})})]}),i==="date"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-20 text-xs text-muted-foreground",children:"Format"}),e.jsx("div",{className:"flex-1",children:e.jsx(s.Input,{type:"text",placeholder:"MM/DD/YYYY",value:t.dateFormat||"",onChange:c=>d("dateFormat",c.target.value),className:"h-8 text-xs"})})]})]})]})}function Er(){const t=s.useDashboardStore(c=>c.dashboard.filters),n=s.useEditorStore(c=>c.frame),{setFrame:a}=s.useEditorActions(),{columns:r}=s.useColumns(),{assignFilter:i}=s.useAssignFilter();function d(c){const l=i(c,"frame");a({...n,filterId:l})}const o=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(Ir,{onSelect:d,columns:r}),o&&e.jsx(s.FilterHeader,{filter:o})]})}function Ir({columns:t,onSelect:n}){var o;const[a,r]=Ks.useState(!1),[i,d]=Ks.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:[i?((o=t.find(c=>c.name===i))==null?void 0:o.label)||i:"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 column found."}),e.jsx(s.CommandGroup,{children:t==null?void 0:t.map(c=>e.jsxs(s.CommandItem,{value:c.name,onSelect:l=>{const x=l===i?"":l;d(x),r(!1),x&&n(c)},children:[c.label||c.name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",i===c.name?"opacity-100":"opacity-0")})]},c.id))})]})]})})]})}const kr=[{value:"difference",label:"Difference"},{value:"change",label:"Change (%)"},{value:"change_difference",label:"Change + Difference"},{value:"ratio",label:"Ratio"}],Dr=[{value:"arrow_badge",label:"Arrow + Badge"},{value:"arrow",label:"Arrow Only"},{value:"badge",label:"Badge Only"},{value:"none",label:"None"}];function Ar({cardType:t="table"}){var p,h,m,y,v;const n=s.useEditorStore(u=>u.card),a=s.useEditorStore(u=>{var b;return(b=u.card)==null?void 0:b.preferences}),r=s.useEditorStore(u=>u.actions.setCardPreferences),d=(((p=n.config)==null?void 0:p.metricColumns)||[]).some(u=>u.comparisonType&&u.comparisonType!=="none"),o=((h=a==null?void 0:a.tableVisualOptions)==null?void 0:h.metricComparison)||{},c=u=>{r({...a,tableVisualOptions:{...a==null?void 0:a.tableVisualOptions,metricComparison:{...o,...u}}})},l={increase:((m=o.colors)==null?void 0:m.increase)||"green",decrease:((y=o.colors)==null?void 0:y.decrease)||"red",neutral:((v=o.colors)==null?void 0:v.neutral)||"neutral"},x=u=>{r({...a,allowDownload:u})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsxs(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:[d&&e.jsxs(s.AccordionItem,{value:"comparison",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pa,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison Settings"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Calculated As"}),e.jsxs(s.Select,{value:o.calculatedAs||"change_difference",onValueChange:u=>c({calculatedAs:u}),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:kr.map(u=>e.jsx(s.SelectItem,{value:u.value,className:"text-xs",children:u.label},u.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Number Format"}),e.jsx(Ts,{formatOptions:o.formatOptions||{},onFormatOptionsChange:u=>c({formatOptions:u}),showTitle:!1})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Indicator Style"}),e.jsxs(s.Select,{value:o.indicatorStyle||"arrow_badge",onValueChange:u=>c({indicatorStyle:u}),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Dr.map(u=>e.jsx(s.SelectItem,{value:u.value,className:"text-xs",children:u.label},u.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Colors"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Qe,{value:l.increase,onChange:u=>c({colors:{...l,increase:u}}),label:"Increase"}),e.jsx(Qe,{value:l.decrease,onChange:u=>c({colors:{...l,decrease:u}}),label:"Decrease"}),e.jsx(Qe,{value:l.neutral,onChange:u=>c({colors:{...l,neutral:u}}),label:"No Change"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Lower is Better"}),e.jsx(s.Checkbox,{checked:o.lowerIsBetter||!1,onCheckedChange:u=>c({lowerIsBetter:!!u})})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Ea,{}),e.jsx(Er,{})]})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:x,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"})]})]})}function Lr(){var r;const t=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:n}=s.useEditorStore(i=>i.actions);function a(i){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:i==="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 Mr(){return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx(ws,{chartType:"text"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Text Type"}),e.jsx(Lr,{})]})]})}const Or=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function Rr(){var E,j,k,I,f,A,g,D,M,P;const t=s.useEditorStore(N=>N.card),n=s.useEditorStore(N=>{var O;return(O=N.card)==null?void 0:O.preferences}),a=Ie.useEffectiveEditorCardType(),{setCardPreferences:r,updateCardInFrame:i}=s.useEditorActions(),d=C.useMemo(()=>a!==t.type?{...t,type:a}:t,[t,a]),{data:o}=s.useDashboardCardQuery(d),[c,l]=C.useState({}),[x,p]=C.useState(null),[h,m]=C.useState(null),y=C.useMemo(()=>{var R,F,$,U,z,H,se;if(!(o!=null&&o.records)||o.records.length===0)return[];const N=a==="stackedBar"||a==="stackedLine",O=a==="bar"||a==="line"||a==="horizontalBar"||a==="bullet"||a==="combo"||a==="area"||a==="stackedArea",S=((R=t==null?void 0:t.config)==null?void 0:R.pivotByColumns)&&t.config.pivotByColumns.length>0;if((N||O)&&S){if(o.pivotSchema&&Array.isArray(o.pivotSchema)){const Y=new Set;return o.pivotSchema.forEach(ae=>{ae.alias&&Y.add(ae.alias)}),Array.from(Y)}if(o.records.length>0){const Y=o.records[0],ae=Object.keys(Y),q=new Set;(F=t==null?void 0:t.config)!=null&&F.groupByColumns&&t.config.groupByColumns.forEach(X=>{q.add(X.label||X.name),q.add(X.alias||X.name)});const J=new Set;return($=t==null?void 0:t.config)!=null&&$.metricColumns&&t.config.metricColumns.forEach(X=>{const oe=X.alias||X.name;J.add(oe),J.add(`${oe}_count`),J.add(`${oe}_sum`),J.add(`${oe}_avg`),J.add(`${oe}_min`),J.add(`${oe}_max`);const me=X.entityName||X.qualifiedEntityName;me&&(J.add(`${me}_${oe}`),J.add(`${me}_${oe}_count`))}),ae.filter(X=>!q.has(X)&&!J.has(X))}}if((O||N)&&!S&&((z=(U=t==null?void 0:t.config)==null?void 0:U.metricColumns)!=null&&z.length))return t.config.metricColumns.map(Y=>Y.alias||Y.label||Y.name);if((se=(H=t==null?void 0:t.config)==null?void 0:H.groupByColumns)!=null&&se.length){const Y=t.config.groupByColumns[0],ae=Y.label||Y.name,q=new Set;return o.records.forEach(J=>{const le=J[ae];le!=null&&q.add(String(le))}),Array.from(q)}return[]},[o,(E=t==null?void 0:t.config)==null?void 0:E.groupByColumns,(j=t==null?void 0:t.config)==null?void 0:j.pivotByColumns,(k=t==null?void 0:t.config)==null?void 0:k.metricColumns,t==null?void 0:t.type]),v=C.useMemo(()=>s.getDefaultChartColors(),[]);C.useEffect(()=>{const N={};y.forEach((O,S)=>{N[O]=s.getColorForValue(O,S,n==null?void 0:n.colorConfig)}),l(N)},[y,n==null?void 0:n.colorConfig,v]);const u=(N,O)=>{const S={...c,[N]:O};l(S);const R={...n||{},colorConfig:{segments:S}};r(R);const F={...t,preferences:R};i(F)},b=(N,O)=>{var z;const S=v[O%v.length],{[N]:R,...F}=((z=n==null?void 0:n.colorConfig)==null?void 0:z.segments)||{},$={...n||{},colorConfig:{segments:F}};r($);const U={...t,preferences:$};i(U),l(H=>({...H,[N]:S}))};if(!y.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((f=(I=t==null?void 0:t.config)==null?void 0:I.groupByColumns)==null?void 0:f.length)||((g=(A=t==null?void 0:t.config)==null?void 0:A.pivotByColumns)==null?void 0:g.length):(M=(D=t==null?void 0:t.config)==null?void 0:D.groupByColumns)==null?void 0:M.length)||["table","kpi","text","custom","heatmap"].includes(a))return null;const V=()=>{const N={...n||{},colorConfig:{segments:{}}};r(N);const O={...t,preferences:N};i(O);const S={};y.forEach((R,F)=>{S[R]=s.getColorForValue(R,F,void 0)}),l(S)},L=Object.keys(((P=n==null?void 0:n.colorConfig)==null?void 0:P.segments)||{}).length>0;return e.jsxs(s.AccordionItem,{value:"colors",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Colors"})]})}),e.jsx(s.AccordionContent,{className:"",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"flex items-center justify-between",children:L&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:V,children:[e.jsx(Gt,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:y.map((N,O)=>{const S=s.isDefaultColor(c[N],O),R=!S;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:x===N,onOpenChange:F=>p(F?N:null),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx("button",{className:"h-5 w-5 shrink-0 rounded border border-input shadow-sm transition-colors hover:border-gray-400 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",style:{backgroundColor:c[N]}})}),e.jsx(s.PopoverContent,{align:"start",className:"w-auto p-3",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Theme Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:v.slice(0,10).map((F,$)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",c[N]===F?"border-gray-900":"border-transparent"),style:{backgroundColor:F},onClick:()=>{u(N,F),p(null)},children:[$===O%v.length&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx("div",{className:"rounded-full bg-white/90 px-0.5 text-[8px] font-bold text-gray-900 shadow-sm",children:"D"})}),e.jsx("span",{className:"sr-only",children:F})]},`default-${$}`))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Popular Colors"}),e.jsx("div",{className:"grid grid-cols-5 gap-1.5",children:Or.map((F,$)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",c[N]===F?"border-2 border-gray-900":F==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:F},onClick:()=>{u(N,F),p(null)},children:e.jsx("span",{className:"sr-only",children:F})},`preset-${$}`))})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[e.jsx("button",{className:"text-sm font-medium text-blue-600 hover:text-blue-700",onClick:()=>{m({value:N,color:c[N]}),p(null)},children:"Custom color"}),!S&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{b(N,O),p(null)},children:[e.jsx(Gt,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:N}),R&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},N)})}),h&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>m(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(Ia,{color:h.color,onColorChange:N=>{u(h.value,N),m(null)},onClose:()=>m(null)})})]})]})})]})}function qe({value:t,onSave:n,placeholder:a="",type:r="text",className:i=""}){const[d,o]=C.useState(t??""),[c,l]=C.useState(!1);C.useEffect(()=>{o(t??"")},[t]);const x=()=>{n(d),l(!1)},p=()=>{o(t??""),l(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${i}`,children:[e.jsx(s.Input$1,{placeholder:a,type:r,value:c?d:t??"",onChange:h=>{o(h.target.value),l(!0)},onFocus:()=>l(!0),onClick:h=>h.stopPropagation(),className:"h-8 text-xs",onPointerDown:h=>h.stopPropagation(),onKeyDown:h=>{h.stopPropagation(),h.key==="Enter"&&c&&d!==t?x():h.key==="Escape"&&p()},"aria-label":a||"Edit field"}),c&&d!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm edit",onClick:x,children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel edit",onClick:p,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}function zs({axis:t,label:n,type:a,config:r,onChange:i,defaultTitle:d,hidePosition:o}){var y,v,u,b,w,T,V,L,E,j,k,I,f,A;const c=(g,D)=>{i({...r??{},[g]:D})},l=(g,D)=>{var O,S,R,F;const M=g==="enabled"&&D===!0,P=(O=r==null?void 0:r.name)==null?void 0:O.text,N=M&&!P&&d;i({...r??{},name:{...r==null?void 0:r.name,enabled:g==="enabled"?D:((S=r==null?void 0:r.name)==null?void 0:S.enabled)??!1,text:g==="text"?D:N?d:P,fontSize:g==="fontSize"?D:(R=r==null?void 0:r.name)==null?void 0:R.fontSize,fontWeight:g==="fontWeight"?D:(F=r==null?void 0:r.name)==null?void 0:F.fontWeight}})},x=(g,D)=>{var M,P;i({...r??{},labels:{enabled:g==="enabled"?D:((M=r==null?void 0:r.labels)==null?void 0:M.enabled)??!0,rotation:g==="rotation"?D:(P=r==null?void 0:r.labels)==null?void 0:P.rotation}})},p=(g,D)=>{i({...r??{},scale:{...r==null?void 0:r.scale,[g]:D===""?"auto":Number(D)}})},h=t==="x"?["auto","top","bottom"]:["auto","left","right"],m=["auto","0","45","90","-45","-90"];return e.jsxs(s.AccordionItem,{value:`${t}-axis`,className:"border-b-0",children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(s.AccordionTrigger,{className:"flex grow items-center justify-between gap-3 py-2 text-sm font-medium hover:no-underline",children:e.jsx("div",{className:"flex grow items-center justify-between gap-2",children:e.jsx("span",{children:n})})}),e.jsx(s.SmallSwitch,{checked:(r==null?void 0:r.enabled)!==!1,onCheckedChange:g=>c("enabled",g),onClick:g=>g.stopPropagation()})]}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:`${t}-title-enabled`,checked:((y=r==null?void 0:r.name)==null?void 0:y.enabled)??!1,onCheckedChange:g=>l("enabled",g===!0)}),e.jsx(s.Label,{htmlFor:`${t}-title-enabled`,className:"text-xs font-medium cursor-pointer",children:"TITLE"})]}),((v=r==null?void 0:r.name)==null?void 0:v.enabled)&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(qe,{placeholder:`${n} title`,value:((u=r==null?void 0:r.name)==null?void 0:u.text)||"",onSave:g=>l("text",g),className:""}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Size"}),e.jsx("div",{className:"w-14",children:e.jsx(qe,{type:"number",placeholder:"12",value:String(((b=r==null?void 0:r.name)==null?void 0:b.fontSize)||12),onSave:g=>l("fontSize",Number(g)||12),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Weight"}),e.jsxs(s.Select,{value:((w=r==null?void 0:r.name)==null?void 0:w.fontWeight)||"normal",onValueChange:g=>l("fontWeight",g),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(s.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]})]})]})]}),!o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"POSITION"}),e.jsxs(s.Select,{value:(r==null?void 0:r.position)||"auto",onValueChange:g=>c("position",g),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:h.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":s.titleCase(g)},g))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((T=r==null?void 0:r.labels)==null?void 0:T.enabled)!==!1,onCheckedChange:g=>x("enabled",g)})]}),((V=r==null?void 0:r.labels)==null?void 0:V.enabled)!==!1&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Rotation"}),e.jsxs(s.Select,{value:String(((L=r==null?void 0:r.labels)==null?void 0:L.rotation)||"auto"),onValueChange:g=>x("rotation",g==="auto"?"auto":Number(g)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:m.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:g==="auto"?"Auto (Default)":`${g}°`},g))})]})]})]}),a==="value"&&e.jsx(Ts,{formatOptions:(r==null?void 0:r.formatOptions)||{},onFormatOptionsChange:g=>i({...r,formatOptions:g}),showTitle:!0,title:"FORMAT"}),a==="value"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"SCALE"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Min"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"auto",value:((E=r==null?void 0:r.scale)==null?void 0:E.min)==="auto"||((j=r==null?void 0:r.scale)==null?void 0:j.min)===void 0?"":String(r.scale.min),onSave:g=>p("min",g),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Max"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"auto",value:((k=r==null?void 0:r.scale)==null?void 0:k.max)==="auto"||((I=r==null?void 0:r.scale)==null?void 0:I.max)===void 0?"":String(r.scale.max),onSave:g=>p("max",g),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"w-8 text-xs text-muted-foreground",children:"Step"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"auto",value:((f=r==null?void 0:r.scale)==null?void 0:f.stepSize)==="auto"||((A=r==null?void 0:r.scale)==null?void 0:A.stepSize)===void 0?"":String(r.scale.stepSize),onSave:g=>p("stepSize",g),className:""})})]})]})]})]})]})}function qs(t,n,a){var d,o,c;if(t==="x"){const l=(o=(d=n==null?void 0:n.config)==null?void 0:d.groupByColumns)==null?void 0:o[0];return(l==null?void 0:l.label)||(l==null?void 0:l.name)||""}const r=((c=n==null?void 0:n.config)==null?void 0:c.metricColumns)||[],i=(a==null?void 0:a.datasetOptions)||[];if(t==="y"){const l=r.filter((x,p)=>{const h=i.find(m=>m.idx===p);return!h||h.yAxisId!=="y2"});return l.length===1&&(l[0].label||l[0].name)||""}if(t==="y2"){const l=r.filter((x,p)=>{const h=i.find(m=>m.idx===p);return(h==null?void 0:h.yAxisId)==="y2"});return l.length===1&&(l[0].label||l[0].name)||""}return""}function Fr(){const t=s.useEditorStore(l=>l.card),n=s.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),{setCardPreferences:a,updateCardInFrame:r}=s.useEditorActions(),i=Ie.useEffectiveEditorCardType();if(!t||["tornado","pyramid","kpi","treemap"].includes(i))return null;const d=s.AxisConfigurator.getAxisInfo(i,n);if(!d.hasXAxis&&!d.hasYAxis)return null;const o=(l,x)=>{let p;l==="x"?p="xAxisConfig":l==="y"?p="yAxisConfig":p="secondaryYAxisConfig";const h={...n||{},[p]:x};a(h);const m={...t,preferences:h};r(m)},c=d.hasY2Axis&&i==="combo";return e.jsxs(s.AccordionItem,{value:"axes",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Us,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Axes"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:[d.hasXAxis&&e.jsx(zs,{axis:"x",label:"X-Axis",type:d.xAxisType,config:s.mergeAxisConfig(s.getDefaultAxisConfig(i,"x"),n==null?void 0:n.xAxisConfig),onChange:l=>o("x",l),defaultTitle:qs("x",t,n)}),d.hasYAxis&&e.jsx(zs,{axis:"y",label:c?"Y-Axis (Left)":"Y-Axis",type:d.yAxisType,config:s.mergeAxisConfig(s.getDefaultAxisConfig(i,"y"),n==null?void 0:n.yAxisConfig),onChange:l=>o("y",l),defaultTitle:qs("y",t,n)}),c&&e.jsx(zs,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:s.mergeAxisConfig({enabled:!0,position:"right"},n==null?void 0:n.secondaryYAxisConfig),onChange:l=>o("y2",l),defaultTitle:qs("y2",t,n),hidePosition:!0})]})})]})}function Vr(){const t=s.useEditorStore(h=>h.card),n=Ie.useEffectiveEditorCardType(),a=s.useEditorStore(h=>{var m,y,v,u;return(u=(v=(y=(m=h.card)==null?void 0:m.preferences)==null?void 0:y.chartOptions)==null?void 0:v.plugins)==null?void 0:u.legend}),{setLegendOptions:r}=s.useEditorActions();if(!t||!s.chartSupportsLegend(n))return null;const i=s.getDefaultLegendConfig(n),d=(i==null?void 0:i.display)??!0,o=(i==null?void 0:i.position)??"top",c=(i==null?void 0:i.align)??"center",l=(h,m)=>{const y={...a,[h]:m};r(y)},x=["top","bottom","left","right"],p=["start","center","end"];return e.jsxs(s.AccordionItem,{value:"legend",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(un,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Legend"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.display)??d,onCheckedChange:h=>l("display",h)})]}),((a==null?void 0:a.display)??d)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:(a==null?void 0:a.position)||o,onValueChange:h=>l("position",h),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:x.map(h=>e.jsx(s.SelectItem,{value:h,className:"text-xs",children:s.titleCase(h)},h))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Alignment"}),e.jsxs(s.Select,{value:(a==null?void 0:a.align)||c,onValueChange:h=>l("align",h),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:p.map(h=>e.jsx(s.SelectItem,{value:h,className:"text-xs",children:s.titleCase(h)},h))})]})]})]})]})})]})}function Pr(){var O,S,R,F,$,U,z,H,se,Y,ae;const t=s.useEditorStore(q=>q.card),n=Ie.useEffectiveEditorCardType(),a=s.useEditorStore(q=>{var J,le;return(le=(J=q.card)==null?void 0:J.preferences)==null?void 0:le.dataLabelsConfig}),r=s.useEditorStore(q=>{var J;return(J=q.card)==null?void 0:J.preferences}),{setCardPreferences:i,updateCardInFrame:d}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(n))return null;const o=n==="bullet"?((O=r==null?void 0:r.bulletConfig)==null?void 0:O.orientation)??(((S=r==null?void 0:r.chartOptions)==null?void 0:S.indexAxis)==="x"?"vertical":"horizontal"):void 0,c=o!=null?o==="horizontal":((R=r==null?void 0:r.chartOptions)==null?void 0:R.indexAxis)==="y",l=n==="stackedBar"||n==="stackedLine",x=n==="pie"||n==="doughnut"||n==="polarArea"||n==="funnel",p=!x,h=n==="bubble"||n==="scatter",m=($=(F=r==null?void 0:r.chartOptions)==null?void 0:F.plugins)==null?void 0:$.datalabels,y=(m==null?void 0:m.display)!==!1&&((m==null?void 0:m.anchor)||(m==null?void 0:m.align)),v=s.getDefaultDataLabelsConfig(n,t.preferences),u=a??v,b=(v==null?void 0:v.enabled)??y??!1,w=(a==null?void 0:a.enabled)!==void 0?a.enabled:b,T=(q,J)=>{const oe={...v??{},...a??{},[q]:J};q==="enabled"&&(oe.display=J,J&&h&&!oe.position&&(oe.position="bottom")),q==="position"&&h&&(oe.position="bottom");const me={...t.preferences||{},dataLabelsConfig:oe};i(me);const Z={...t,preferences:me};d(Z)},V=(q,J)=>{const le=a??{},oe={...v??{},...le,font:{...le.font||{},[q]:J}},me={...t.preferences||{},dataLabelsConfig:oe};i(me);const Z={...t,preferences:me};d(Z)},L=(q,J)=>{const le=a??{},oe={...v??{},...le,formatOptions:{...le.formatOptions||{},[q]:J}},me={...t.preferences||{},dataLabelsConfig:oe};i(me);const Z={...t,preferences:me};d(Z)},E=()=>{const q=n;return q==="stackedBar"||q==="stackedLine"||q==="pie"||q==="doughnut"?"center":c?"right":"top"},j=n!=="treemap"&&n!=="heatmap",k=n!=="treemap",I=E();let f=[];if(j)if(h)f=["bottom"];else if(l||x)f=["center"];else{const q=c?["center","left","right"]:["center","top","bottom"];f=["auto",...n==="bullet"?q:q.filter(le=>le!==I),"custom"]}const A=()=>s.titleCase(I),g=["center","start","end"],D=["center","start","end","top","bottom"],M=p?["auto","number","currency","percent","none"]:["number","currency","percent","none"],P=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],N=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}];return e.jsxs(s.AccordionItem,{value:"data-labels",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Cn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Data Labels"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Display"}),e.jsx(s.SmallSwitch,{checked:w,onCheckedChange:q=>T("enabled",q)})]}),w&&e.jsxs(e.Fragment,{children:[j&&!l&&!x&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Position"}),e.jsxs(s.Select,{value:h?(u==null?void 0:u.position)||"bottom":(u==null?void 0:u.position)||"auto",onValueChange:q=>T("position",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:f.map(q=>e.jsx(s.SelectItem,{value:q,className:"text-xs",children:q==="auto"?A():q==="custom"?"Custom (Advanced)":s.titleCase(q)},q))})]})]}),l&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Show Total"}),e.jsx(s.SmallSwitch,{checked:(a==null?void 0:a.showTotal)??!1,onCheckedChange:q=>T("showTotal",q)})]}),(u==null?void 0:u.position)==="custom"&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Anchor"}),e.jsxs(s.Select,{value:(u==null?void 0:u.anchor)||"center",onValueChange:q=>T("anchor",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:g.map(q=>e.jsx(s.SelectItem,{value:q,className:"text-xs",children:s.titleCase(q)},q))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-16",children:"Align"}),e.jsxs(s.Select,{value:String((u==null?void 0:u.align)||"center"),onValueChange:q=>T("align",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:D.map(q=>e.jsx(s.SelectItem,{value:q,className:"text-xs",children:s.titleCase(q)},q))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(u==null?void 0:u.format)||(p?"auto":"none"),onValueChange:q=>T("format",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:M.map(q=>e.jsx(s.SelectItem,{value:q,className:"text-xs",children:q==="auto"&&p?"Auto (Use Axis)":q==="none"?"None (Raw Value)":s.titleCase(q)},q))})]})]}),(u==null?void 0:u.format)&&!["auto","none"].includes(u.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(u.format)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Decimals"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"0",value:String(((U=u==null?void 0:u.formatOptions)==null?void 0:U.decimalPlaces)??(u.format==="currency"?2:u.format==="percent"?1:0)),onSave:q=>L("decimalPlaces",Number(q)),className:""})})]}),u.format==="currency"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Currency"}),e.jsxs(s.Select,{value:((z=u==null?void 0:u.formatOptions)==null?void 0:z.currency)||"USD",onValueChange:q=>L("currency",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:P.map(q=>e.jsx(s.SelectItem,{value:q.value,className:"text-xs",children:q.label},q.value))})]})]}),["number","currency"].includes(u.format)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:((H=u==null?void 0:u.formatOptions)==null?void 0:H.useSuffix)??!1,onCheckedChange:q=>L("useSuffix",q)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Locale"}),e.jsxs(s.Select,{value:((se=u==null?void 0:u.formatOptions)==null?void 0:se.locale)||"en-US",onValueChange:q=>L("locale",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:N.map(q=>e.jsx(s.SelectItem,{value:q.value,className:"text-xs",children:q.label},q.value))})]})]})]}),k&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Appearance"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Size"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"12",value:String(((Y=u==null?void 0:u.font)==null?void 0:Y.size)||12),onSave:q=>V("size",Number(q)),className:""})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Weight"}),e.jsxs(s.Select,{value:((ae=u==null?void 0:u.font)==null?void 0:ae.weight)||"normal",onValueChange:q=>V("weight",q),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(s.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Color"}),e.jsxs(s.Select,{value:(u==null?void 0:u.color)==="auto"||!(u!=null&&u.color)?"auto":"custom",onValueChange:q=>{q==="auto"&&T("color","auto")},children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Smart Contrast)"}),e.jsx(s.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom (Coming Soon)"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground w-20",children:"Rotation"}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{type:"number",placeholder:"0",value:String((u==null?void 0:u.rotation)||0),onSave:q=>T("rotation",Number(q)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}const ra={difference:{label:"Difference",description:"Shows the exact difference between two values.",formula:"Primary - Secondary",example:"Sales increased by $5,000 compared to last year."},change:{label:"Change",description:"Shows the percentage increase or decrease between two values.",formula:"(Primary - Secondary) / Secondary × 100%",example:"Year-over-year sales change of 25%."},change_difference:{label:"Change (difference)",description:"Shows both the percentage change and the exact difference between two values.",formula:`% Change: (Primary - Secondary) / Secondary × 100%
|
|
182
|
+
Difference: Primary - Secondary`,example:"Sales grew by 25% ($5,000) compared to last year."},ratio:{label:"Ratio",description:"Shows how much of one value is covered by another — useful for quotas and benchmarks.",formula:"Primary / Secondary × 100%",example:"You've achieved 80% of your sales quota."}};function Br(){var m,y,v,u,b,w,T,V,L,E;const t=s.useEditorStore(j=>j.card),{setCardPreferences:n}=s.useEditorActions(),a=Ie.useEffectiveEditorCardType(),r=((m=t.config)==null?void 0:m.metricColumns)||[],i=((y=t.config)==null?void 0:y.groupByColumns)||[],d=r.length===2&&i.length===0,o=r.some(j=>j.comparisonType&&j.comparisonType!=="none");if(!(a==="kpi"&&(d||o)))return null;const l=((u=(v=t.preferences)==null?void 0:v.kpiVisualOptions)==null?void 0:u.metricComparison)||{},x=j=>{var I;const k={...t.preferences,kpiVisualOptions:{...(I=t.preferences)==null?void 0:I.kpiVisualOptions,metricComparison:{...l,...j}}};n(k)},p=o||l.enabled,h=r.some(j=>j.comparisonType==="previous_period"||j.comparisonType==="same_period_last_year"||j.comparisonType==="start_vs_end");return e.jsxs(s.AccordionItem,{value:"comparison",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pa,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[d&&r.length===2&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"enable-comparison",className:"text-xs",children:"Enable Metric Comparison"}),e.jsx(s.SmallSwitch,{id:"enable-comparison",checked:l.enabled||!1,onCheckedChange:j=>x({enabled:j,...j&&!l.calculationType?{calculationType:"difference"}:{}})})]}),p&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Label,{htmlFor:"calculation-type",className:"text-xs font-medium uppercase text-muted-foreground",children:"Calculated as"}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Info,{className:"h-3 w-3 cursor-help text-muted-foreground"})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-xs",children:(()=>{const j=l.calculationType||"difference",k=ra[j];return e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsx("div",{className:"text-sm font-semibold",children:k==null?void 0:k.label}),e.jsx("p",{children:k==null?void 0:k.description}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Formula:"})," ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-[10px]",children:k==null?void 0:k.formula})]}),e.jsxs("div",{className:"border-t pt-1.5 italic",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",k==null?void 0:k.example]})]})})()})]})]}),e.jsxs(s.Select,{value:l.calculationType||"difference",onValueChange:j=>x({calculationType:j}),children:[e.jsx(s.SelectTrigger,{id:"calculation-type",className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Object.entries(ra).map(([j,k])=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:k.label},j))})]})]}),e.jsx(Ts,{formatOptions:l.formatOptions||{},onFormatOptionsChange:j=>x({formatOptions:j}),showTitle:!0,title:"COMPARISON FORMAT"}),(h||d)&&e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Indicator"}),d&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Position"}),e.jsxs(s.Select,{value:l.position||"right",onValueChange:j=>x({position:j}),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"right",className:"text-xs",children:"Right"}),e.jsx(s.SelectItem,{value:"left",className:"text-xs",children:"Left"}),e.jsx(s.SelectItem,{value:"top",className:"text-xs",children:"Top"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-arrow",checked:l.showArrow!==!1,onCheckedChange:j=>x({showArrow:j})}),e.jsx(s.Label,{htmlFor:"show-arrow",className:"cursor-pointer text-xs text-muted-foreground",children:"Arrow"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"show-color",checked:l.showColor!==!1,onCheckedChange:j=>x({showColor:j})}),e.jsx(s.Label,{htmlFor:"show-color",className:"cursor-pointer text-xs text-muted-foreground",children:"Color"})]}),l.showColor!==!1&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-3",children:[e.jsx(Qe,{value:((b=l.colorConfig)==null?void 0:b.increase)||"green",onChange:j=>x({colorConfig:{...l.colorConfig,increase:j}}),label:"Primary > Secondary"}),e.jsx(Qe,{value:((w=l.colorConfig)==null?void 0:w.decrease)||"red",onChange:j=>x({colorConfig:{...l.colorConfig,decrease:j}}),label:"Primary < Secondary"}),e.jsx(Qe,{value:((T=l.colorConfig)==null?void 0:T.noChange)||"neutral",onChange:j=>x({colorConfig:{...l.colorConfig,noChange:j}}),label:"Primary = Secondary"})]})]}),e.jsxs("div",{className:"space-y-3 border-t pt-3",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Label"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"conditional-label",checked:l.conditionalLabel||!1,onCheckedChange:j=>x({conditionalLabel:j})}),e.jsx(s.Label,{htmlFor:"conditional-label",className:"cursor-pointer text-xs text-muted-foreground",children:"Conditional"})]}),l.conditionalLabel?e.jsxs("div",{className:"space-y-3 border-l-2 border-muted pl-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-increase",className:"text-xs text-muted-foreground",children:["Primary ",">"," Secondary"]}),e.jsx(s.Input,{id:"label-increase",type:"text",value:((V=l.conditionalLabels)==null?void 0:V.increase)??"Increase",onChange:j=>x({conditionalLabels:{...l.conditionalLabels,increase:j.target.value}}),placeholder:"Increase",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"label-decrease",className:"text-xs text-muted-foreground",children:["Primary ","<"," Secondary"]}),e.jsx(s.Input,{id:"label-decrease",type:"text",value:((L=l.conditionalLabels)==null?void 0:L.decrease)??"Decrease",onChange:j=>x({conditionalLabels:{...l.conditionalLabels,decrease:j.target.value}}),placeholder:"Decrease",className:"h-7 text-xs"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-no-change",className:"text-xs text-muted-foreground",children:"Primary = Secondary"}),e.jsx(s.Input,{id:"label-no-change",type:"text",value:((E=l.conditionalLabels)==null?void 0:E.noChange)??"No change",onChange:j=>x({conditionalLabels:{...l.conditionalLabels,noChange:j.target.value}}),placeholder:"No change",className:"h-7 text-xs"})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"label-name",className:"text-xs text-muted-foreground",children:"Previous Label"}),e.jsx(s.Input,{id:"label-name",type:"text",value:l.labelName??"",onChange:j=>x({labelName:j.target.value}),placeholder:"e.g. Previous, Last Period",className:"h-7 text-xs"})]})]})]})]})]})}function zr(){var d,o;const t=s.useEditorStore(c=>c.card),{setCardPreferences:n}=s.useEditorActions();if(Ie.useEffectiveEditorCardType()!=="kpi")return null;const r=((o=(d=t.preferences)==null?void 0:d.kpiVisualOptions)==null?void 0:o.formatOptions)||{},i=c=>{var x;const l={...t.preferences,kpiVisualOptions:{...(x=t.preferences)==null?void 0:x.kpiVisualOptions,formatOptions:c}};n(l)};return e.jsxs(s.AccordionItem,{value:"kpi-format",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Hash,{className:"h-4 w-4"}),e.jsx("span",{children:"Number Format"})]})}),e.jsx(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:e.jsx(Ts,{formatOptions:r,onFormatOptionsChange:i,showTitle:!1})})]})}function qr(){var d;const t=s.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.type}),n=s.useEditorStore(o=>{var c;return(c=o.card)==null?void 0:c.preferences}),{setCardPreferences:a}=s.useEditorActions();if(t!=="treemap")return null;const r=((d=n==null?void 0:n.chartOptions)==null?void 0:d.treemapColorMode)??"branch",i=o=>{const c={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,treemapColorMode:o}};a(c)};return e.jsxs(s.AccordionItem,{value:"treemap-color-mode",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TbChartTreemap,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Treemap Colors"})]})}),e.jsx(s.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:e.jsxs(s.RadioGroup,{value:r,onValueChange:o=>i(o??"branch"),className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(s.RadioGroupItem,{id:"treemap-color-branch",value:"branch"}),e.jsxs(s.Label,{htmlFor:"treemap-color-branch",className:"flex flex-col text-sm font-normal leading-tight",children:[e.jsx("span",{className:"font-medium",children:"Shade by value (default)"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Keeps parent hue and adjusts lightness based on the node's share within the branch."})]})]}),e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(s.RadioGroupItem,{id:"treemap-color-category",value:"category"}),e.jsxs(s.Label,{htmlFor:"treemap-color-category",className:"flex flex-col text-sm font-normal leading-tight",children:[e.jsx("span",{className:"font-medium",children:"Single color per category"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Applies the top-level color to all descendants without lightening/darkening."})]})]})]})})]})}const $r=Object.keys(s.HEATMAP_PRESET_PALETTES);function _r(){const t=s.useEditorStore(m=>m.card),n=s.useEditorStore(m=>{var y;return(y=m.card)==null?void 0:y.preferences}),{setCardPreferences:a}=s.useEditorActions(),r=(t==null?void 0:t.type)==="heatmap",i=(n==null?void 0:n.heatmapConfig)||{},d=i.colorPalette??"green",o=i.legendPosition??"bottom",c=C.useMemo(()=>i.colorRange&&i.colorRange[0]&&i.colorRange[1]?[i.colorRange[0],i.colorRange[1]]:[...s.DEFAULT_HEATMAP_CUSTOM_RANGE],[i.colorRange]),l=m=>{const y={...i,...m};y.colorPalette!=="custom"?delete y.colorRange:(!y.colorRange||!y.colorRange[0]||!y.colorRange[1])&&(y.colorRange=[...s.DEFAULT_HEATMAP_CUSTOM_RANGE]),a({...n||{},heatmapConfig:y})},x=m=>{l({colorPalette:m,colorRange:m==="custom"?i.colorRange??[...s.DEFAULT_HEATMAP_CUSTOM_RANGE]:void 0})},p=(m,y)=>{const v=[...c];v[m]=y,l({colorPalette:"custom",colorRange:v})},h=m=>{l({legendPosition:m})};return r?e.jsxs(s.AccordionItem,{value:"heatmap-color-config",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Grid3x3,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Heatmap Settings"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[e.jsxs(s.RadioGroup,{value:d,onValueChange:m=>x(m??"blue"),className:"space-y-3",children:[$r.map(m=>{const y=s.HEATMAP_PRESET_PALETTES[m];return e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(s.RadioGroupItem,{id:`heatmap-${m}`,value:m}),e.jsxs(s.Label,{htmlFor:`heatmap-${m}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:y.label}),e.jsx("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${y.start}, ${y.end})`}})]})]},m)}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-md border border-border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.RadioGroupItem,{id:"heatmap-custom",value:"custom"}),e.jsx(s.Label,{htmlFor:"heatmap-custom",className:"text-sm font-medium",children:"Custom colors"})]}),d==="custom"&&e.jsxs("div",{className:"flex flex-col gap-3 pl-6",children:[e.jsx(Qe,{value:c[0],onChange:m=>p(0,m),label:"Start color"}),e.jsx(Qe,{value:c[1],onChange:m=>p(1,m),label:"End color"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Color scale position"}),e.jsxs(s.Select,{value:o,onValueChange:m=>h(m??"bottom"),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["top","bottom","left","right"].map(m=>e.jsx(s.SelectItem,{value:m,className:"text-xs",children:m[0].toUpperCase()+m.slice(1)},m))})]})]})]})]}):null}const la=["poor","satisfactory","good"];function oa(t){if(!t)return;const n={...t};return n.targetMetricKey||delete n.targetMetricKey,n.comparativeMetricKey||delete n.comparativeMetricKey,!n.targetValue&&n.targetValue!==0&&delete n.targetValue,(!n.rangeKeys||Object.keys(n.rangeKeys).length===0)&&delete n.rangeKeys,(!n.ranges||Object.keys(n.ranges).length===0)&&delete n.ranges,(!n.rangeLabels||Object.keys(n.rangeLabels).length===0)&&delete n.rangeLabels,n}function Gr(){var M,P;const t=s.useEditorStore(N=>N.card.preferences),n=s.useEditorStore(N=>N.card),a=s.useEditorStore(N=>N.isDevMode),{setCardPreferences:r,setChartOrientation:i}=s.useEditorActions(),d=C.useMemo(()=>(t==null?void 0:t.bulletConfig)||{},[t==null?void 0:t.bulletConfig]),c=s.hasValidCardConfig(n==null?void 0:n.config)&&!a,[l,x]=C.useState(d.showRanges??!1),[p,h]=C.useState(d.rangesArePercentages??!1),m=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!c,[y,v]=C.useState(m);C.useEffect(()=>{x(d.showRanges??!1)},[d.showRanges]),C.useEffect(()=>{h(d.rangesArePercentages??!1)},[d.rangesArePercentages]);const u=d.targetValue===void 0?"":String(d.targetValue);C.useEffect(()=>{const N=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!c;v(N)},[d.disableAutoComparative,d.comparativeMetricKey,c]);const b=C.useMemo(()=>{var N,O;return((O=(N=n==null?void 0:n.config)==null?void 0:N.metricColumns)==null?void 0:O.map(S=>{const R=S.label||S.name||S.alias||"";return{value:R,label:R}}))||[]},[(M=n==null?void 0:n.config)==null?void 0:M.metricColumns]);C.useEffect(()=>{var z,H;if(!t||b.length===0)return;const N={};let O=!1;const S=(z=b[1])==null?void 0:z.value;!d.targetMetricKey&&S&&(N.targetMetricKey=S,O=!0);const R=(H=b[2])==null?void 0:H.value;!d.comparativeMetricKey&&!d.disableAutoComparative&&R&&(N.comparativeMetricKey=R,O=!0);const F=b.slice(3),$={...d.rangeKeys||{}};let U=!1;if(la.forEach((se,Y)=>{!$[se]&&F[Y]&&($[se]=F[Y].value,U=!0)}),U&&(N.rangeKeys=$,O=!0,d.showRanges===void 0&&(N.showRanges=!0)),O){const se=oa({...d,...N});r({...t,bulletConfig:se})}},[b,d,t,r]);const w=N=>{const O=oa({...d,...N});r({...t,bulletConfig:O})},T=(N,O)=>{const S={...d.rangeKeys||{},[N]:O.trim()};O.trim()||delete S[N],w({rangeKeys:Object.keys(S).length>0?S:void 0})},V=(N,O)=>{const S=O===""?void 0:Number(O),R={...d.ranges||{}};S===void 0||Number.isNaN(S)?delete R[N]:R[N]=S,w({ranges:Object.keys(R).length?R:void 0})},L=N=>{if(N===""){w({targetValue:void 0});return}const O=Number(N);w({targetValue:Number.isNaN(O)?void 0:O})},E=(N,O)=>{const S=O.trim(),R={...d.rangeLabels||{}};S?R[N]=S:delete R[N],w({rangeLabels:Object.keys(R).length>0?R:void 0})},j=N=>{x(N),w({showRanges:N})},k=N=>{h(N),w({rangesArePercentages:N})},I=d.orientation||(((P=t==null?void 0:t.chartOptions)==null?void 0:P.indexAxis)==="y"?"horizontal":"vertical"),f=N=>{w({orientation:N}),i(N==="horizontal"?"y":"x")},A=[{value:"__none",label:"None"},...b.map(N=>({value:N.value,label:N.label}))],g=A,D=N=>{if(v(N),!N){w({comparativeMetricKey:void 0,disableAutoComparative:!0});return}if(!c){w({disableAutoComparative:!1});return}if(d.comparativeMetricKey)w({disableAutoComparative:!1});else{const O=b.find(S=>S.value!==d.targetMetricKey);w({comparativeMetricKey:O==null?void 0:O.value,disableAutoComparative:!1})}};return e.jsxs(s.AccordionItem,{value:"bullet-config",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.BulletChartIcon,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Bullet Chart"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-6 border-t border-border/50 py-4",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"ORIENTATION"}),e.jsxs(s.Select,{value:I,onValueChange:N=>f(N),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"horizontal",className:"text-xs",children:"Horizontal"}),e.jsx(s.SelectItem,{value:"vertical",className:"text-xs",children:"Vertical"})]})]})]}),c&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"TARGET METRIC"}),e.jsxs(s.Select,{value:d.targetMetricKey||"__none",onValueChange:N=>w({targetMetricKey:N==="__none"?void 0:N}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select metric"})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"__none",className:"text-xs",children:"None"}),b.map(N=>e.jsx(s.SelectItem,{value:N.value,className:"text-xs",children:N.label},N.value))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),c?e.jsxs(s.Select,{value:d.comparativeMetricKey||"__none",onValueChange:N=>w({comparativeMetricKey:N==="__none"?void 0:N,disableAutoComparative:N==="__none"}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select metric"})}),e.jsx(s.SelectContent,{children:A.map(N=>e.jsx(s.SelectItem,{value:N.value,className:"text-xs",children:N.label},N.value))})]}):e.jsxs("div",{className:"space-y-2 rounded-md border border-border/50 p-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between font-medium",children:[e.jsx("span",{children:"Show comparative"}),e.jsx(s.SmallSwitch,{checked:y,onCheckedChange:N=>D(N)})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Comparative values are auto-detected from the third metric in your results."})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"TARGET VALUE (FALLBACK)"}),e.jsx(Me,{type:"number",className:"h-8 text-xs",value:u,onCommit:L,placeholder:"Optional numeric fallback"})]})]}),e.jsxs("section",{className:"space-y-4 rounded-md border border-border/60 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"QUALITATIVE RANGES"}),e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:200,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground",children:e.jsx(s.Info,{className:"h-3.5 w-3.5"})})}),e.jsx(s.TooltipContent,{side:"top",children:"Use columns or static values for Poor / Average / Good."})]})})]}),e.jsx("div",{className:"flex items-center gap-2 text-xs font-medium",children:e.jsx(s.SmallSwitch,{checked:l,onCheckedChange:j})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsx("input",{type:"checkbox",checked:p,disabled:!l,onChange:N=>k(N.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),e.jsx("span",{children:"Use % of value"})]})]}),l&&e.jsx("div",{className:"space-y-3",children:la.map(N=>{var O,S,R,F,$;return e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/40 p-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[N," LABEL"]}),e.jsx(Me,{placeholder:`Display label (${N})`,value:((O=d.rangeLabels)==null?void 0:O[N])||"",onCommit:U=>E(N,U),className:"h-8 text-xs"})]}),c?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[N," COLUMN"]}),e.jsxs(s.Select,{value:((S=d.rangeKeys)==null?void 0:S[N])||"__none",onValueChange:U=>{U==="__none"?T(N,""):T(N,U)},children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select column"})}),e.jsx(s.SelectContent,{children:g.map(U=>e.jsx(s.SelectItem,{value:U.value,className:"text-xs",children:U.label},U.value))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[N," COLUMN KEY"]}),e.jsx(Me,{placeholder:"Column key",value:((R=d.rangeKeys)==null?void 0:R[N])||"",onCommit:U=>T(N,U),className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[N," VALUE"]}),e.jsx(Me,{type:"number",placeholder:p?"0.80":"Static value",value:((F=d.ranges)==null?void 0:F[N])===void 0?"":String(($=d.ranges)==null?void 0:$[N]),onCommit:U=>V(N,U),className:"h-8 text-xs"})]})]},N)})})]})]})]})}function ia(t){if(!t)return;const n={...t};if(n.xMetricKey||delete n.xMetricKey,n.yMetricKey||delete n.yMetricKey,n.radiusMetricKey||delete n.radiusMetricKey,n.labelKey||delete n.labelKey,n.groupKey||delete n.groupKey,n.enableGrouping===void 0&&delete n.enableGrouping,n.radiusScale||delete n.radiusScale,n.fixedRadius===void 0&&delete n.fixedRadius,n.minRadius===void 0&&delete n.minRadius,n.maxRadius===void 0&&delete n.maxRadius,Object.keys(n).length!==0)return n}function Kr(){var E,j,k,I,f,A,g,D,M,P,N,O;const t=s.useEditorStore(S=>S.card.preferences),n=s.useEditorStore(S=>S.card),a=Ie.useEffectiveEditorCardType(),r=s.useEditorStore(S=>S.isDevMode),{setCardPreferences:i,updateCardInFrame:d}=s.useEditorActions(),o=a==="bubble",c=a==="scatter",l=C.useMemo(()=>(t==null?void 0:t.bubbleScatterConfig)||{},[t==null?void 0:t.bubbleScatterConfig]),p=s.hasValidCardConfig(n==null?void 0:n.config)&&!r,h=C.useMemo(()=>{var S,R;return((R=(S=n==null?void 0:n.config)==null?void 0:S.metricColumns)==null?void 0:R.map(F=>{const $=F.label||F.name||F.alias||"";return{value:$,label:$}}))||[]},[(E=n==null?void 0:n.config)==null?void 0:E.metricColumns]),m=C.useMemo(()=>{var S,R;return((R=(S=n==null?void 0:n.config)==null?void 0:S.groupByColumns)==null?void 0:R.map(F=>{const $=F.label||F.name||F.alias||"";return{value:$,label:$}}))||[]},[(j=n==null?void 0:n.config)==null?void 0:j.groupByColumns]),y=C.useMemo(()=>l.enableGrouping!==void 0?l.enableGrouping:!r&&m.length>=2,[l.enableGrouping,r,m.length]),[v,u]=C.useState(y);C.useEffect(()=>{u(y)},[y]);const b=S=>{const R={...t||{},bubbleScatterConfig:S};i(R),n&&d({...n,preferences:R})},w=S=>{i(S),n&&d({...n,preferences:S})};C.useEffect(()=>{if(!t||h.length===0)return;const S={};let R=!1;if(!l.xMetricKey&&h[0]&&(S.xMetricKey=h[0].value,R=!0),!l.yMetricKey&&h[1]&&(S.yMetricKey=h[1].value,R=!0),o&&!l.radiusMetricKey&&h[2]&&(S.radiusMetricKey=h[2].value,R=!0),!l.labelKey&&m[0]&&(S.labelKey=m[0].value,R=!0),y&&!l.groupKey&&m[1]&&(S.groupKey=m[1].value,S.enableGrouping=!0,R=!0),R){const F=ia({...l,...S});b(F)}},[h,m,l,t,i,o,y]);const T=S=>{const R=ia({...l,...S});b(R)},V=S=>{u(S),T({enableGrouping:S,groupKey:S?l.groupKey:void 0})};if(!o&&!c)return null;const L=o?s.Circle:s.ChartScatter;return e.jsxs(s.AccordionItem,{value:"bubble-scatter-config",children:[e.jsx(s.AccordionTrigger,{className:"py-2 text-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4"}),e.jsxs("span",{children:[o?"Bubble":"Scatter"," Configuration"]})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-1 pb-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs font-medium text-muted-foreground",children:["Dimensions",e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(s.Info,{className:"h-3 w-3"})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsx("p",{children:"Label identifies each point. Group creates separate series in the legend."})})]})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Label Column"}),p?e.jsxs(s.Select,{value:l.labelKey||"",onValueChange:S=>T({labelKey:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select label column"})}),e.jsx(s.SelectContent,{children:m.map(S=>e.jsx(s.SelectItem,{value:S.value,children:S.label},S.value))})]}):e.jsx(Me,{className:"h-8 text-xs",placeholder:"Column name for labels",value:l.labelKey||"",onCommit:S=>T({labelKey:S})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Group points into series"}),e.jsx(s.SmallSwitch,{checked:v,onCheckedChange:V})]}),v&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Group By"}),p?e.jsxs(s.Select,{value:l.groupKey||"",onValueChange:S=>T({groupKey:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select group column"})}),e.jsx(s.SelectContent,{children:m.map(S=>e.jsx(s.SelectItem,{value:S.value,children:S.label},S.value))})]}):e.jsx(Me,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:l.groupKey||"",onCommit:S=>T({groupKey:S})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Metrics"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"X Axis"}),p?e.jsxs(s.Select,{value:l.xMetricKey||"",onValueChange:S=>T({xMetricKey:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select X metric"})}),e.jsx(s.SelectContent,{children:h.map(S=>e.jsx(s.SelectItem,{value:S.value,children:S.label},S.value))})]}):e.jsx(Me,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:l.xMetricKey||"",onCommit:S=>T({xMetricKey:S})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Y Axis"}),p?e.jsxs(s.Select,{value:l.yMetricKey||"",onValueChange:S=>T({yMetricKey:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select Y metric"})}),e.jsx(s.SelectContent,{children:h.map(S=>e.jsx(s.SelectItem,{value:S.value,children:S.label},S.value))})]}):e.jsx(Me,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:l.yMetricKey||"",onCommit:S=>T({yMetricKey:S})})]}),o&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Radius"}),p?e.jsxs(s.Select,{value:l.radiusMetricKey||"",onValueChange:S=>T({radiusMetricKey:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select radius metric"})}),e.jsx(s.SelectContent,{children:h.map(S=>e.jsx(s.SelectItem,{value:S.value,children:S.label},S.value))})]}):e.jsx(Me,{className:"h-8 text-xs",placeholder:"Column name for radius",value:l.radiusMetricKey||"",onCommit:S=>T({radiusMetricKey:S})})]})]}),o&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Radius Settings"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Scale Mode"}),e.jsxs(s.Select,{value:l.radiusScale||"sqrt",onValueChange:S=>T({radiusScale:S}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"sqrt",children:"Square Root (area-proportional)"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"fixed",children:"Fixed Size"})]})]})]}),l.radiusScale!=="fixed"&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Min Radius"}),e.jsx(Me,{className:"h-8 text-xs",type:"number",placeholder:"5",value:((k=l.minRadius)==null?void 0:k.toString())||"",onCommit:S=>T({minRadius:S?Number(S):void 0})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Max Radius"}),e.jsx(Me,{className:"h-8 text-xs",type:"number",placeholder:"30",value:((I=l.maxRadius)==null?void 0:I.toString())||"",onCommit:S=>T({maxRadius:S?Number(S):void 0})})]})]}),l.radiusScale==="fixed"&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(s.Label,{className:"text-xs",children:["Fixed Radius: ",l.fixedRadius||10]}),e.jsx(s.Slider,{value:[l.fixedRadius||10],onValueChange:([S])=>T({fixedRadius:S}),min:3,max:30,step:1,className:"py-2"})]})]}),c&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Point Settings"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs(s.Label,{className:"text-xs",children:["Point Size: ",l.fixedRadius||5]}),e.jsx(s.Slider,{value:[l.fixedRadius||5],onValueChange:([S])=>T({fixedRadius:S}),min:2,max:15,step:1,className:"py-2"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Axis Titles"}),e.jsx(s.SmallSwitch,{checked:((A=(f=t==null?void 0:t.xAxisConfig)==null?void 0:f.name)==null?void 0:A.enabled)??!1,onCheckedChange:S=>{var $,U,z,H;const R=l.xMetricKey||"X Axis",F=l.yMetricKey||"Y Axis";w({...t??{},xAxisConfig:{...t==null?void 0:t.xAxisConfig,name:{enabled:S,text:((U=($=t==null?void 0:t.xAxisConfig)==null?void 0:$.name)==null?void 0:U.text)||R}},yAxisConfig:{...t==null?void 0:t.yAxisConfig,name:{enabled:S,text:((H=(z=t==null?void 0:t.yAxisConfig)==null?void 0:z.name)==null?void 0:H.text)||F}}})}})]}),((D=(g=t==null?void 0:t.xAxisConfig)==null?void 0:g.name)==null?void 0:D.enabled)&&e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"X Title"}),e.jsx(Me,{className:"h-8 text-xs",placeholder:l.xMetricKey||"X Axis",value:((P=(M=t==null?void 0:t.xAxisConfig)==null?void 0:M.name)==null?void 0:P.text)||"",onCommit:S=>{var R;w({...t??{},xAxisConfig:{...t==null?void 0:t.xAxisConfig,name:{...(R=t==null?void 0:t.xAxisConfig)==null?void 0:R.name,enabled:!0,text:S||l.xMetricKey||"X Axis"}}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Y Title"}),e.jsx(Me,{className:"h-8 text-xs",placeholder:l.yMetricKey||"Y Axis",value:((O=(N=t==null?void 0:t.yAxisConfig)==null?void 0:N.name)==null?void 0:O.text)||"",onCommit:S=>{var R;w({...t??{},yAxisConfig:{...t==null?void 0:t.yAxisConfig,name:{...(R=t==null?void 0:t.yAxisConfig)==null?void 0:R.name,enabled:!0,text:S||l.yMetricKey||"Y Axis"}}})}})]})]})]})]})]})}const Ur=[{value:"percentOfTotal",label:"% of Total",description:"Each stage shows percentage of the sum of all values"},{value:"percentOfFirst",label:"% of Stage 1",description:"First stage = 100%, others relative to first stage"}];function Hr(){const t=s.useEditorStore(m=>m.card),n=s.useEditorStore(m=>{var y;return(y=m.card)==null?void 0:y.preferences}),{setCardPreferences:a}=s.useEditorActions(),r=(t==null?void 0:t.type)==="funnel",i=(n==null?void 0:n.funnelConfig)||{},d=i.percentMode??"percentOfTotal",o=i.shrinkFraction??1,c=i.labelThreshold??0,l=m=>{const y={...i,...m};a({...n||{},funnelConfig:y})},x=m=>{l({percentMode:m})},p=m=>{l({shrinkFraction:m[0]})},h=m=>{l({labelThreshold:m[0]})};return r?e.jsxs(s.AccordionItem,{value:"funnel-config",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-3 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Filter,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Funnel Settings"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 border-t border-border bg-background/50 px-3 py-4 text-sm",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"PERCENTAGE MODE"}),e.jsx(s.RadioGroup,{value:d,onValueChange:m=>x(m),className:"space-y-2",children:Ur.map(m=>e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-border px-3 py-2",children:[e.jsx(s.RadioGroupItem,{id:`funnel-${m.value}`,value:m.value,className:"mt-0.5"}),e.jsxs(s.Label,{htmlFor:`funnel-${m.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:m.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]})]},m.value))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"SEGMENT SHRINK"}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Same Width"}),e.jsx(s.Slider,{value:[o],onValueChange:p,min:0,max:1,step:.1,className:"flex-1"}),e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Full Shrink"})]}),e.jsxs("p",{className:"text-center text-xs text-muted-foreground",children:["Current: ",Math.round(o*100),"%"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"LABEL VISIBILITY THRESHOLD"}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Show All"}),e.jsx(s.Slider,{value:[c],onValueChange:h,min:0,max:25,step:1,className:"flex-1"}),e.jsx("span",{className:"whitespace-nowrap text-xs text-muted-foreground",children:"Hide Small"})]}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:c===0?"Showing all labels":`Hide labels below ${c}%`})]})]})]}):null}function Es(){const t=s.useEditorStore(d=>d.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),r=a.slice(1).filter(d=>!s.METADATA_KEYS.includes(d));let i=r;if(["stackedBar","stackedLine"].includes(t.type)){const d=s.pivotData({dataArray:(n==null?void 0:n.records)||[],groupKey:a[0],pivotKey:a[1],valueKey:a[2]}),{keys:o}=s.getKeys(d);i=o.slice(1)}return{transformedMetricKeys:i,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:r}}const Jr=[{value:"USD",label:"USD - US Dollar"},{value:"EUR",label:"EUR - Euro"},{value:"GBP",label:"GBP - British Pound"},{value:"JPY",label:"JPY - Japanese Yen"},{value:"CNY",label:"CNY - Chinese Yuan"},{value:"INR",label:"INR - Indian Rupee"},{value:"CAD",label:"CAD - Canadian Dollar"},{value:"AUD",label:"AUD - Australian Dollar"}],Qr=[{value:"en-US",label:"English (US)"},{value:"en-GB",label:"English (UK)"},{value:"de-DE",label:"German"},{value:"fr-FR",label:"French"},{value:"es-ES",label:"Spanish"},{value:"it-IT",label:"Italian"},{value:"pt-BR",label:"Portuguese (Brazil)"},{value:"zh-CN",label:"Chinese (Simplified)"}],Yr=["center","start","end"],Wr=["center","start","end","top","bottom"];function Is({config:t,onChange:n,isHorizontal:a=!1,showAutoFormat:r=!0,positionOptions:i,showAppearance:d=!0}){var v,u,b,w,T,V;const o=i??(a?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),c=r?["auto","number","currency","percent","none"]:["number","currency","percent","none"],l=(L,E)=>{const j={...t,[L]:E};n(j)},x=(L,E)=>{const j={...t,font:{...(t==null?void 0:t.font)||{},[L]:E}};n(j)},p=(L,E)=>{const j={...t,formatOptions:{...(t==null?void 0:t.formatOptions)||{},[L]:E}};n(j)},h=()=>a?"Right":"Top",m=t||{},y=m.format||(r?"auto":"number");return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Position"}),e.jsxs(s.Select,{value:m.position||"auto",onValueChange:L=>l("position",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:o.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"?h():L==="custom"?"Custom (Advanced)":s.titleCase(L)},L))})]})]}),m.position==="custom"&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Anchor"}),e.jsxs(s.Select,{value:m.anchor||"center",onValueChange:L=>l("anchor",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Yr.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Align"}),e.jsxs(s.Select,{value:String(m.align||"center"),onValueChange:L=>l("align",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Wr.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:s.titleCase(L)},L))})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Format"}),e.jsxs(s.Select,{value:y,onValueChange:L=>l("format",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:c.map(L=>e.jsx(s.SelectItem,{value:L,className:"text-xs",children:L==="auto"&&r?"Auto (Use Axis)":L==="none"?"None (Raw Value)":s.titleCase(L)},L))})]})]}),!["auto","none"].includes(y)&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(y)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Decimals"}),e.jsx("div",{className:"w-16",children:e.jsx(qe,{type:"number",placeholder:"0",value:String(((v=m.formatOptions)==null?void 0:v.decimalPlaces)??(y==="currency"?2:y==="percent"?1:0)),onSave:L=>p("decimalPlaces",Number(L)),className:""})})]}),y==="currency"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Currency"}),e.jsxs(s.Select,{value:((u=m.formatOptions)==null?void 0:u.currency)||"USD",onValueChange:L=>p("currency",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Jr.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.value))})]})]}),["number","currency"].includes(y)&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Abbreviate (K, M, B)"}),e.jsx(s.SmallSwitch,{checked:((b=m.formatOptions)==null?void 0:b.useSuffix)??!1,onCheckedChange:L=>p("useSuffix",L)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Locale"}),e.jsxs(s.Select,{value:((w=m.formatOptions)==null?void 0:w.locale)||"en-US",onValueChange:L=>p("locale",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Qr.map(L=>e.jsx(s.SelectItem,{value:L.value,className:"text-xs",children:L.label},L.value))})]})]})]}),d&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Appearance"}),e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Size"}),e.jsx("div",{className:"w-16",children:e.jsx(qe,{type:"number",placeholder:"12",value:String(((T=m.font)==null?void 0:T.size)||12),onSave:L=>x("size",Number(L)),className:""})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Weight"}),e.jsxs(s.Select,{value:((V=m.font)==null?void 0:V.weight)||"normal",onValueChange:L=>x("weight",L),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"normal",className:"text-xs",children:"Normal"}),e.jsx(s.SelectItem,{value:"bold",className:"text-xs",children:"Bold"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Color"}),e.jsxs(s.Select,{value:m.color==="auto"||!m.color?"auto":"custom",onValueChange:L=>{L==="auto"&&l("color","auto")},children:[e.jsx(s.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"auto",className:"text-xs",children:"Auto (Contrast)"}),e.jsx(s.SelectItem,{value:"custom",disabled:!0,className:"text-xs",children:"Custom"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Rotation"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("div",{className:"w-12",children:e.jsx(qe,{type:"number",placeholder:"0",value:String(m.rotation||0),onSave:L=>l("rotation",Number(L)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]})}const Xr=[{type:"bar",icon:s.ChartColumnIncreasing,label:"Bar"},{type:"line",icon:s.ChartLine,label:"Line"}],Zr=[0,1,2,3,4,5,6,8,10],el=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],sl=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function tl(){return s.useEditorStore(n=>{var a;return(a=n.card)==null?void 0:a.type})!=="combo"?null:e.jsxs(s.AccordionItem,{value:"combo-series",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsx(al,{})})]})}function al(){const{transformedMetricKeys:t}=Es();return t.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:t.map((n,a)=>e.jsx(nl,{metricKey:n,idx:a},n))})}function nl({metricKey:t,idx:n}){var w;const[a,r]=C.useState(!1),i=s.useEditorStore(T=>{var V;return(V=T.card)==null?void 0:V.preferences}),d=s.useEditorStore(T=>{var V,L;return(L=(V=T.card)==null?void 0:V.preferences)==null?void 0:L.datasetOptions}),o=d==null?void 0:d.find(T=>T.idx===n),{setCardPreferences:c}=s.useEditorStore(T=>T.actions),l=(o==null?void 0:o.type)||"bar",x=(o==null?void 0:o.yAxisId)||"y",p=((w=o==null?void 0:o.dataLabels)==null?void 0:w.enabled)??!1,h=l==="line"?s.ChartLine:s.ChartColumnIncreasing;function m(T){const V={idx:n,type:l,yAxisId:x,dataLabels:o==null?void 0:o.dataLabels,...T};if(!o)c({...i||{},datasetOptions:[...d||[],V]});else{const L=d==null?void 0:d.map(E=>E.idx===n?{...E,...V}:E);c({...i||{},datasetOptions:L})}}function y(T){m({type:T})}function v(T){m({yAxisId:T})}function u(T){m({dataLabels:{...o==null?void 0:o.dataLabels,enabled:T}})}function b(T){m({dataLabels:T})}return e.jsx(s.Collapsible,{open:a,onOpenChange:r,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(s.ChevronRight,{className:s.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",a&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("span",{className:s.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(h,{className:"h-3 w-3"}),l==="line"?"Line":"Bar"]}),e.jsx("span",{className:s.cn("rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:x==="y2"?"Y2":"Y1"})]})]})}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"flex items-end gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Chart Type"}),e.jsx("div",{className:"flex gap-2",children:Xr.map(({type:T,icon:V,label:L})=>{const E=l===T;return e.jsxs("button",{onClick:()=>y(T),className:s.cn("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",E?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx("span",{children:L})]},T)})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Axis"}),e.jsxs(s.Select,{value:x,onValueChange:T=>v(T),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-20 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"y",className:"text-xs",children:"Y1 (Left)"}),e.jsx(s.SelectItem,{value:"y2",className:"text-xs",children:"Y2 (Right)"})]})]})]})]}),l==="line"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(s.Select,{value:(o==null?void 0:o.lineStyle)||"solid",onValueChange:T=>m({lineStyle:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:sl.map(({value:T,label:V})=>e.jsx(s.SelectItem,{value:T,className:"text-xs",children:V},T))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(s.Select,{value:String((o==null?void 0:o.pointRadius)??3),onValueChange:T=>m({pointRadius:Number(T)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Zr.map(T=>e.jsx(s.SelectItem,{value:String(T),className:"text-xs",children:T===0?"None":T},T))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(s.Select,{value:(o==null?void 0:o.pointStyle)||"circle",onValueChange:T=>m({pointStyle:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:el.map(({value:T,label:V})=>e.jsx(s.SelectItem,{value:T,className:"text-xs",children:V},T))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(s.SmallSwitch,{checked:p,onCheckedChange:u})]}),p&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Is,{config:o==null?void 0:o.dataLabels,onChange:b,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const $s=[{value:"origin",label:"Origin (X-axis)",description:"Fill to the X-axis (y=0)"},{value:"start",label:"Start (Top)",description:"Fill to the top of chart area"},{value:"end",label:"End (Bottom)",description:"Fill to the bottom of chart area"},{value:"-1",label:"Previous Series",description:"Fill to the series below"},{value:"+1",label:"Next Series",description:"Fill to the series above"},{value:"false",label:"No Fill (Line)",description:"Show as line without fill"}],rl=[0,1,2,3,4,5,6,8,10],ll=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],ol=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function il(t){return t==null?"origin":t===!1?"false":t}function cl(){const t=s.useEditorStore(n=>{var a;return(a=n.card)==null?void 0:a.type});return t!=="area"&&t!=="stackedArea"?null:e.jsxs(s.AccordionItem,{value:"area-series",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsx(dl,{})})]})}function dl(){const{transformedMetricKeys:t}=Es();return t.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:t.map((n,a)=>e.jsx(ul,{metricKey:n,idx:a},n))})}function ul({metricKey:t,idx:n}){var u;const[a,r]=C.useState(!1),i=s.useEditorStore(b=>{var w;return(w=b.card)==null?void 0:w.preferences}),d=s.useEditorStore(b=>{var w,T;return(T=(w=b.card)==null?void 0:w.preferences)==null?void 0:T.datasetOptions}),o=d==null?void 0:d.find(b=>b.idx===n),{setCardPreferences:c}=s.useEditorStore(b=>b.actions),l=il(o==null?void 0:o.fill),x=((u=o==null?void 0:o.dataLabels)==null?void 0:u.enabled)??!1,p=$s.find(b=>b.value===l)||$s[0];function h(b){const w={idx:n,fill:l,dataLabels:o==null?void 0:o.dataLabels,...b};if(!o)c({...i||{},datasetOptions:[...d||[],w]});else{const T=d==null?void 0:d.map(V=>V.idx===n?{...V,...w}:V);c({...i||{},datasetOptions:T})}}function m(b){h({fill:b==="false"?!1:b})}function y(b){h({dataLabels:{...o==null?void 0:o.dataLabels,enabled:b}})}function v(b){h({dataLabels:b})}return e.jsx(s.Collapsible,{open:a,onOpenChange:r,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(s.ChevronRight,{className:s.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",a&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:e.jsxs("span",{className:s.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(s.ChartArea,{className:"h-3 w-3"}),p.label.split(" ")[0]]})})]})}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Fill Target"}),e.jsxs(s.Select,{value:l,onValueChange:b=>m(b),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:$s.map(b=>e.jsx(s.SelectItem,{value:b.value,className:"text-xs",children:e.jsx("div",{className:"flex flex-col",children:e.jsx("span",{children:b.label})})},b.value))})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(s.Select,{value:(o==null?void 0:o.lineStyle)||"solid",onValueChange:b=>h({lineStyle:b}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ol.map(({value:b,label:w})=>e.jsx(s.SelectItem,{value:b,className:"text-xs",children:w},b))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(s.Select,{value:String((o==null?void 0:o.pointRadius)??3),onValueChange:b=>h({pointRadius:Number(b)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:rl.map(b=>e.jsx(s.SelectItem,{value:String(b),className:"text-xs",children:b===0?"None":b},b))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(s.Select,{value:(o==null?void 0:o.pointStyle)||"circle",onValueChange:b=>h({pointStyle:b}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ll.map(({value:b,label:w})=>e.jsx(s.SelectItem,{value:b,className:"text-xs",children:w},b))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(s.SmallSwitch,{checked:x,onCheckedChange:y})]}),x&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Is,{config:o==null?void 0:o.dataLabels,onChange:v,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const ml=[0,1,2,3,4,5,6,8,10],xl=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],_s=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function hl(){return s.useEditorStore(n=>{var a;return(a=n.card)==null?void 0:a.type})!=="line"?null:e.jsxs(s.AccordionItem,{value:"line-series",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsx(pl,{})})]})}function pl(){const{transformedMetricKeys:t}=Es();return t.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:t.map((n,a)=>e.jsx(fl,{metricKey:n,idx:a},n))})}function fl({metricKey:t,idx:n}){var b;const[a,r]=C.useState(!1),i=s.useEditorStore(w=>{var T;return(T=w.card)==null?void 0:T.preferences}),d=s.useEditorStore(w=>{var T,V;return(V=(T=w.card)==null?void 0:T.preferences)==null?void 0:V.datasetOptions}),o=d==null?void 0:d.find(w=>w.idx===n),{setCardPreferences:c}=s.useEditorStore(w=>w.actions),l=(o==null?void 0:o.lineStyle)||"solid",x=(o==null?void 0:o.pointRadius)??3,p=(o==null?void 0:o.pointStyle)||"circle",h=((b=o==null?void 0:o.dataLabels)==null?void 0:b.enabled)??!1,m=_s.find(w=>w.value===l)||_s[0];function y(w){const T={idx:n,lineStyle:l,pointRadius:x,pointStyle:p,dataLabels:o==null?void 0:o.dataLabels,...w};if(!o)c({...i||{},datasetOptions:[...d||[],T]});else{const V=d==null?void 0:d.map(L=>L.idx===n?{...L,...T}:L);c({...i||{},datasetOptions:V})}}function v(w){y({dataLabels:{...o==null?void 0:o.dataLabels,enabled:w}})}function u(w){y({dataLabels:w})}return e.jsx(s.Collapsible,{open:a,onOpenChange:r,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(s.ChevronRight,{className:s.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",a&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:e.jsxs("span",{className:s.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(s.TrendingUp,{className:"h-3 w-3"}),m.label.split(" ")[0]]})})]})}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Line Style"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Pattern"}),e.jsxs(s.Select,{value:l,onValueChange:w=>y({lineStyle:w}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:_s.map(({value:w,label:T})=>e.jsx(s.SelectItem,{value:w,className:"text-xs",children:T},w))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Size"}),e.jsxs(s.Select,{value:String(x),onValueChange:w=>y({pointRadius:Number(w)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ml.map(w=>e.jsx(s.SelectItem,{value:String(w),className:"text-xs",children:w===0?"None":w},w))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Point Shape"}),e.jsxs(s.Select,{value:p,onValueChange:w=>y({pointStyle:w}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:xl.map(({value:w,label:T})=>e.jsx(s.SelectItem,{value:w,className:"text-xs",children:T},w))})]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(s.SmallSwitch,{checked:h,onCheckedChange:v})]}),h&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Is,{config:o==null?void 0:o.dataLabels,onChange:u,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const gl=[0,2,4,6,8,10,12,16,20];function jl(){const t=s.useEditorStore(n=>{var a;return(a=n.card)==null?void 0:a.type});return!t||!["bar","horizontalBar","stackedBar"].includes(t)?null:e.jsxs(s.AccordionItem,{value:"bar-series",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Layers,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Series"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsx(bl,{})})]})}function bl(){const{transformedMetricKeys:t}=Es();return t.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 text-center text-xs text-muted-foreground",children:"Add metrics to configure series"}):e.jsx("div",{className:"space-y-3",children:t.map((n,a)=>e.jsx(vl,{metricKey:n,idx:a},n))})}function vl({metricKey:t,idx:n}){var v;const[a,r]=C.useState(!1),i=s.useEditorStore(u=>{var b;return(b=u.card)==null?void 0:b.type}),d=s.useEditorStore(u=>{var b;return(b=u.card)==null?void 0:b.preferences}),o=s.useEditorStore(u=>{var b,w;return(w=(b=u.card)==null?void 0:b.preferences)==null?void 0:w.datasetOptions}),c=o==null?void 0:o.find(u=>u.idx===n),{setCardPreferences:l}=s.useEditorStore(u=>u.actions),x=(c==null?void 0:c.borderRadius)??0,p=((v=c==null?void 0:c.dataLabels)==null?void 0:v.enabled)??!1;function h(u){const b={idx:n,borderRadius:x,dataLabels:c==null?void 0:c.dataLabels,...u};if(!c)l({...d||{},datasetOptions:[...o||[],b]});else{const w=o==null?void 0:o.map(T=>T.idx===n?{...T,...b}:T);l({...d||{},datasetOptions:w})}}function m(u){h({dataLabels:{...c==null?void 0:c.dataLabels,enabled:u}})}function y(u){h({dataLabels:u})}return e.jsx(s.Collapsible,{open:a,onOpenChange:r,children:e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30",children:[e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{className:"flex w-full items-center justify-between gap-3 overflow-hidden px-3 py-2 text-left hover:bg-muted/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(s.ChevronRight,{className:s.cn("h-4 w-4 shrink-0 text-muted-foreground transition-transform",a&&"rotate-90")}),e.jsx("span",{className:"max-w-[100px] truncate text-xs font-medium",title:t,children:t})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:x>0&&e.jsxs("span",{className:s.cn("flex items-center gap-1 rounded px-1.5 py-0.5 text-xs","border border-border bg-background text-muted-foreground"),children:[e.jsx(s.ChartColumn,{className:"h-3 w-3"}),"r:",x]})})]})}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"border-t border-border",children:e.jsxs("div",{className:"space-y-4 p-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Bar Style"}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Corner Radius"}),e.jsxs(s.Select,{value:String(x),onValueChange:u=>h({borderRadius:Number(u)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:gl.map(u=>e.jsx(s.SelectItem,{value:String(u),className:"text-xs",children:u===0?"None":`${u}px`},u))})]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs text-muted-foreground",children:"Data Labels"}),e.jsx(s.SmallSwitch,{checked:p,onCheckedChange:m})]}),p&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Is,{config:c==null?void 0:c.dataLabels,onChange:y,isHorizontal:i==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const yl=[0,1,2,3,4,5,6,8,10],Nl=[{value:"circle",label:"Circle ●"},{value:"rect",label:"Square ■"},{value:"rectRounded",label:"Rounded ▢"},{value:"rectRot",label:"Diamond ◆"},{value:"triangle",label:"Triangle ▲"},{value:"cross",label:"Cross +"},{value:"crossRot",label:"X ×"},{value:"star",label:"Star ★"},{value:"dash",label:"Dash —"},{value:"line",label:"Line │"}],Cl=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Sl(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var l;return(l=c.card)==null?void 0:l.preferences}),a=Ie.useEffectiveEditorCardType(),r=n==null?void 0:n.lineStyleConfig,{setCardPreferences:i,updateCardInFrame:d}=s.useEditorActions();if(!t||!["line","area","stackedArea"].includes(a))return null;const o=(c,l)=>{const x={...n||{},lineStyleConfig:{...r,[c]:l}};i(x),d({...t,preferences:x})};return e.jsxs(s.AccordionItem,{value:"line-style",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(vn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Line Style"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Default styles for all series. Override per-series in the Series section."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Line Pattern"}),e.jsxs(s.Select,{value:(r==null?void 0:r.lineStyle)||"solid",onValueChange:c=>o("lineStyle",c),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Cl.map(({value:c,label:l})=>e.jsx(s.SelectItem,{value:c,className:"text-xs",children:l},c))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Point Size"}),e.jsxs(s.Select,{value:String((r==null?void 0:r.pointRadius)??3),onValueChange:c=>o("pointRadius",Number(c)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:yl.map(c=>e.jsx(s.SelectItem,{value:String(c),className:"text-xs",children:c===0?"None":c},c))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Point Shape"}),e.jsxs(s.Select,{value:(r==null?void 0:r.pointStyle)||"circle",onValueChange:c=>o("pointStyle",c),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Nl.map(({value:c,label:l})=>e.jsx(s.SelectItem,{value:c,className:"text-xs",children:l},c))})]})]})]})})]})}const wl=[0,2,4,6,8,10,12,16,20],Tl=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}],El=[{value:"0.5",label:"50%"},{value:"0.6",label:"60%"},{value:"0.7",label:"70%"},{value:"0.8",label:"80%"},{value:"0.9",label:"90%"},{value:"1",label:"100%"}];function Il(){const t=s.useEditorStore(c=>c.card),n=s.useEditorStore(c=>{var l;return(l=c.card)==null?void 0:l.preferences}),a=Ie.useEffectiveEditorCardType(),r=n==null?void 0:n.barStyleConfig,{setCardPreferences:i,updateCardInFrame:d}=s.useEditorActions();if(!t||!["bar","horizontalBar","stackedBar"].includes(a))return null;const o=(c,l)=>{const x={...n||{},barStyleConfig:{...r,[c]:l}};i(x),d({...t,preferences:x})};return e.jsxs(s.AccordionItem,{value:"bar-style",className:"border-b-0",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2 text-sm font-medium hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.ChartColumn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"Bar Style"})]})}),e.jsx(s.AccordionContent,{className:"pt-2",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Default styles for all bars. Override per-series in the Series section."}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Corner Radius"}),e.jsxs(s.Select,{value:String((r==null?void 0:r.borderRadius)??0),onValueChange:c=>o("borderRadius",Number(c)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:wl.map(c=>e.jsx(s.SelectItem,{value:String(c),className:"text-xs",children:c===0?"None":`${c}px`},c))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Bar Width"}),e.jsxs(s.Select,{value:String((r==null?void 0:r.barPercentage)??.9),onValueChange:c=>o("barPercentage",Number(c)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Tl.map(({value:c,label:l})=>e.jsx(s.SelectItem,{value:c,className:"text-xs",children:l},c))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Category Width"}),e.jsxs(s.Select,{value:String((r==null?void 0:r.categoryPercentage)??.8),onValueChange:c=>o("categoryPercentage",Number(c)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:El.map(({value:c,label:l})=>e.jsx(s.SelectItem,{value:c,className:"text-xs",children:l},c))})]})]})]})})]})}function kl(){const t=s.useEditorStore(a=>{var r,i;return(i=(r=a==null?void 0:a.card)==null?void 0:r.preferences)==null?void 0:i.sortChart}),{setSortChart:n}=s.useEditorActions();return e.jsxs(s.AccordionItem,{value:"stacked-sort",children:[e.jsx(s.AccordionTrigger,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.ArrowUpDown,{className:"h-4 w-4"}),"Sort"]})}),e.jsx(s.AccordionContent,{className:"space-y-4 px-1",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort Order"}),e.jsx(Je,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"Ascending",value:"asc"},{label:"Descending",value:"desc"}],value:t||"none",onValueChange:a=>{n(a)}})]})})]})}const Dl=["kpi"],ca={none:"None",previous_period:"Previous Period",same_period_last_year:"Same Period Last Year",start_vs_end:"Start vs End",target:"Target"},Gs=2;function es(t){return typeof t=="string"?t.trim().toLowerCase():((t==null?void 0:t.id)||(t==null?void 0:t.qualifiedFieldName)||(t==null?void 0:t.name)||(t==null?void 0:t.label)||"").trim().toLowerCase()}function Al(t){if(!(t!=null&&t.name)||!(t!=null&&t.dataType)||t.role==="metric")return!1;const n=s.getDataType(t.dataType);return["date","string","boolean"].includes(n)}function Ll(t){return{...t,role:"groupby"}}function Ml(){var T,V,L,E;const t=s.useEditorStore(j=>j.card),n=s.useEditorStore(j=>j.actions.updateCardConfig),a=Ie.useEffectiveEditorCardType(),{scopedFields:r}=s.useScopedFields(),i=((T=t.config)==null?void 0:T.metricColumns)||[],d=((V=t.config)==null?void 0:V.summary)||{},o=d.breakdownDimensions||[],c=Dl.includes(a),l=i.length>0,x=d.enabled===!0,p=c&&l,h=((L=t.config)==null?void 0:L.comparisonType)||((E=i.find(j=>j.comparisonType&&j.comparisonType!=="none"))==null?void 0:E.comparisonType)||"none",m=ca[h]||ca.none,y=Array.from(new Map(r.filter(Al).map(j=>[es(j),Ll(j)])).values()),v=new Set(y.map(j=>es(j))),u=new Set(o.map(j=>es(j)).filter(j=>j&&v.has(j)));if(!c)return null;const b=j=>{n(t.id,{summary:{...d,...j}})},w=(j,k)=>{const I=es(j),f=y.filter(g=>u.has(es(g))),A=k?u.has(I)?f:[...f,j].slice(0,Gs):f.filter(g=>es(g)!==I);b({breakdownDimensions:A})};return e.jsxs(s.AccordionItem,{value:"summary",className:"border-none",children:[e.jsx(s.AccordionTrigger,{className:"flex items-center gap-2 py-2 text-sm hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.FileText,{className:"h-4 w-4"}),e.jsx("span",{children:"Summary"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{htmlFor:"summary-enabled",className:"text-xs",children:"Enable Summary"}),!l&&e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Add at least one metric to enable summary."})]}),e.jsx(s.SmallSwitch,{id:"summary-enabled",checked:x,disabled:!p,onCheckedChange:j=>{if(!j){b({enabled:!1,showOnCard:!1,includeInDashboardSummary:!1});return}b({enabled:!0,showOnCard:d.showOnCard??!0,includeInDashboardSummary:d.includeInDashboardSummary??!0,anomalyEnabled:d.anomalyEnabled??!0})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Comparison"}),e.jsxs("p",{className:"rounded-md border border-border bg-muted/40 px-2 py-1.5 text-xs",children:["Using: ",m]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Comparison is configured from card/metric comparison settings."})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"summary-show-on-card",className:"text-xs",children:"Show summary on card"}),e.jsx(s.SmallSwitch,{id:"summary-show-on-card",checked:d.showOnCard===!0,disabled:!x,onCheckedChange:j=>b({showOnCard:j})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"summary-include-rollup",className:"text-xs",children:"Include in dashboard summary"}),e.jsx(s.SmallSwitch,{id:"summary-include-rollup",checked:d.includeInDashboardSummary===!0,disabled:!x,onCheckedChange:j=>b({includeInDashboardSummary:j})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium uppercase text-muted-foreground",children:"Breakdown Dimensions"}),e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:[o.length,"/",Gs]})]}),y.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No dimension fields available for breakdown."}):e.jsx("div",{className:"max-h-40 space-y-2 overflow-y-auto rounded-md border border-border p-2",children:y.map(j=>{const k=es(j),I=u.has(k),f=u.size>=Gs,A=!x||!I&&f;return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(s.Checkbox,{id:`summary-breakdown-${k}`,checked:I,disabled:A,onCheckedChange:g=>w(j,g===!0)}),e.jsx(s.Label,{htmlFor:`summary-breakdown-${k}`,className:"cursor-pointer text-xs",children:j.label||j.name})]},k)})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{htmlFor:"summary-anomaly",className:"text-xs",children:"Detect anomalies"}),e.jsx(s.SmallSwitch,{id:"summary-anomaly",checked:d.anomalyEnabled!==!1,disabled:!x,onCheckedChange:j=>b({anomalyEnabled:j})})]})]})]})}function ka({mode:t}){const n=s.useEditorStore(a=>{var r;return(r=a.card)==null?void 0:r.type});return e.jsxs(e.Fragment,{children:[n==="combo"&&e.jsx(tl,{}),(n==="area"||n==="stackedArea")&&e.jsx(cl,{}),n==="line"&&e.jsx(hl,{}),(n==="bar"||n==="horizontalBar"||n==="stackedBar")&&e.jsx(jl,{}),e.jsx(Sl,{}),e.jsx(Il,{}),e.jsx(qr,{}),t==="config"&&e.jsx(zr,{}),t==="config"&&e.jsx(Br,{}),t==="config"&&e.jsx(Ml,{}),e.jsx(_r,{}),n==="bullet"&&e.jsx(Gr,{}),n==="funnel"&&e.jsx(Hr,{}),(n==="bubble"||n==="scatter")&&e.jsx(Kr,{}),(n==="stackedBar"||n==="stackedLine")&&e.jsx(kl,{}),e.jsx(Rr,{}),e.jsx(Fr,{}),e.jsx(Vr,{}),e.jsx(Pr,{})]})}function Ol(){const t=s.useEditorStore(a=>a.card),n=t==null?void 0:t.type;return n?e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx(ws,{chartType:n}),e.jsx(s.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:e.jsx(ka,{mode:"dev"})})]}):null}function Rl(){const t=s.useEditorStore(a=>a.card.type);function n(){switch(t){case"kpi":return e.jsx(pr,{});case"table":return e.jsx(Ar,{});case"map":return e.jsx(br,{});case"custom":return e.jsx("div",{className:"px-6 py-2",children:e.jsx(wa,{})});case"text":return e.jsx(Mr,{});default:return e.jsx(Ol,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Fl(){const t=C.useRef(null),n=C.useRef(null),a=s.useEditorStore(h=>h.isShowingVisual),r=s.useEditorStore(h=>h.isDevMode),i=s.useEditorStore(h=>h.showAIDialog),[d,o]=C.useState(!1),c=a&&!i,l=c&&(!r||d),x=r&&c,p=()=>o(h=>!h);return C.useEffect(()=>{var h,m,y,v;i?((h=t.current)==null||h.resize(0),(m=n.current)==null||m.resize(0)):((y=t.current)==null||y.resize(25),(v=n.current)==null||v.resize(25))},[i]),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(Gn,{})}),e.jsx(s.ResizableHandle,{withHandle:!0,className:"data-[panel-group-direction=vertical]:ml-2 data-[panel-group-direction=vertical]:mr-6 data-[panel-group-direction=vertical]:w-auto"}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:l?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(Rl,{})})}),!i&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(ea,{visualAsideControl:x?{show:!0,isOpen:d,onToggle:p}:void 0})})]}):e.jsx(ea,{visualAsideControl:x?{show:!0,isOpen:d,onToggle:p}:void 0})})]})}function Vl(t){var xe;s.useAIInteractionStore(B=>B.currentAIContext);const[n,a]=C.useState(""),[r,i]=C.useState(null),{authToken:d,tokenProps:o}=s.useSemaphorContext(),c=s.useEditorStore(B=>{var ee;return(ee=B==null?void 0:B.card)==null?void 0:ee.sql}),l=s.useEditorStore(B=>B.isDevMode),x=s.useEditorStore(B=>{var ee;return(ee=B==null?void 0:B.card)==null?void 0:ee.python}),{setCardPython:p,setCardSql:h,setRunSql:m,switchCardType:y,setQueryConfig:v}=s.useEditorActions(),u=s.useEditorStore(B=>B.currentAssitantScope)||[],b=s.useEditorStore(B=>B.userInputForAI),w=s.useEditorStore(B=>B.triggerAIRun),T=s.useEditorStore(B=>B.card),V=s.useEditorStore(B=>B.selectedDatabaseName),L=s.useEditorStore(B=>B.selectedTableName),E=s.useEditorStore(B=>B.selectedConnectionId),j=s.useEditorStore(B=>B.selectedSchemaName),k=s.useDashboardStore(B=>B.dashboard.aiScopeTables),{errorMessage:I,refetch:f,data:A}=s.useDashboardCardQuery(T),{setTriggerAIRun:g,setCurrentAssitantScope:D,setCardConfig:M}=s.useEditorActions(),{selectedDatamodelName:P,connectionType:N,selectedDatamodelId:O}=s.useEditorAside(),S=(xe=s.useDashboardQuery().data)==null?void 0:xe.assistantProfileId,{messages:R,setMessages:F,regenerate:$,error:U,sendMessage:z,status:H,addToolResult:se,stop:Y,clearError:ae}=s.useChat({transport:new s.DefaultChatTransport({api:`${o.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${d==null?void 0:d.accessToken}`}),body:()=>{const B=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",assistantProfileId:S,isDevMode:l,aiContext:B.currentAIContext,reasoningEffort:B.reasoningEffort,showReasoning:B.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:B,body:ee})=>({body:{...ee,messages:s.cleanupIncompleteMessages(B)}})}),onError:B=>{var ee;if(B.name==="AbortError"||(ee=B.message)!=null&&ee.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",B)},onToolCall:q,onFinish({isAbort:B,isDisconnect:ee,isError:ce}){a(""),console.log(B?"[Editor Assistant] Stream aborted by user":ee?"[Editor Assistant] Stream disconnected (network error)":ce?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});C.useEffect(()=>{w&&b&&(z({role:"user",parts:[{type:"text",text:b}]}),g(!1))},[w,b,z,g]);async function q({toolCall:B}){var ee,ce,he,ke,ye,Ee,Se,Pe,ne,je,pe,Te,Ae,ve,Be,ze;if(["createChartFromSql","createForecast"].includes(B.toolName)){const De=((ee=B.input)==null?void 0:ee.sql)??((ce=B.args)==null?void 0:ce.sql),te=((he=B.input)==null?void 0:he.python)??((ke=B.args)==null?void 0:ke.python),be=((ye=B.input)==null?void 0:ye.chartType)??((Ee=B.args)==null?void 0:Ee.chartType);y(be),h(De),p(te),m(!0),se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(B.toolName==="getUserSql"){if(!c){se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"error",message:"No SQL found"}});return}se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"success",sql:c,python:x||""}})}else if(B.toolName==="generateQueryConfig"){a("Generating query config...");const De=((Se=B.input)==null?void 0:Se.chartType)??((Pe=B.args)==null?void 0:Pe.chartType),te=((ne=B.input)==null?void 0:ne.queryConfig)??((je=B.args)==null?void 0:je.queryConfig);((pe=B.input)==null?void 0:pe.cardConfig)??((Te=B.args)==null||Te.cardConfig),y(De),M(te),h(void 0),p(void 0);const be=await f();if((Ae=be==null?void 0:be.data)!=null&&Ae.error){se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"error",queryConfig:te,message:(ve=be==null?void 0:be.data)==null?void 0:ve.error.message}});return}if((Be=be==null?void 0:be.data)!=null&&Be.records){se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"success",queryConfig:te,message:"The data has been visualized"}});return}se({tool:B.toolName,toolCallId:B.toolCallId,output:{status:"success",queryConfig:te,message:"The data has been visualized",records:(ze=be==null?void 0:be.data)==null?void 0:ze.records}})}else a("Analyzing...")}function J(B){const ee=s.removeFromScopeArray(u,B);le(ee)}function le(B){const ee=s.sanitizeAIScope(B);D(ee),F(ce=>[...ce,{id:crypto.randomUUID(),role:"system",parts:[{type:"text",text:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(ee)}`}]}])}function X(){const B={databaseName:V||"",schemaName:j||"",tableName:L||"",datamodelId:O||"",datamodelName:s.resolveDatamodelName(P),connectionId:E||"",connectionType:N||""},ee=s.dedup([...u,B]);le(ee)}function oe(){const B={databaseName:V||"",schemaName:j||"",tableName:L||"",datamodelName:s.resolveDatamodelName(P),connectionId:E||"",connectionType:N||"",datamodelId:O||""};if(!s.isInAiScopeArray([...k||[],...u],B)||u.length===0){const ce=s.dedup([...k||[],...u,B]).filter(he=>he.connectionId===B.connectionId);le(ce)}}const me=!["ready","error"].includes(H),Z=s.getErrorMessage(U);return{messages:R,setMessages:F,sendMessage:z,regenerate:$,isLoading:me,handleSetAIScope:oe,handleAddCurrentTableToScope:X,removeFromCurrentSelections:J,currentAssitantScope:u,setCurrentAssitantScope:D,stop:Y,status:H,toolStatus:n,llmUsage:r,onFinish:t,errorMessage:Z,clearError:ae}}const Pl=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function da({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const r=C.useRef(null),[i,d]=C.useState(!1),[o,c]=C.useState(s.isDevEnv),[l,x]=C.useState(!1),[p,h]=C.useState(!1),[m,y]=C.useState(!1),v=t??m,u=s.useCurrentAIContext(),{setCurrentAIContext:b}=s.useAIActions(),{clearQueue:w}=s.useQueueActions(),{clearFileAttachments:T}=s.useFileActions(),V=s.useFileAttachments("editor"),L=s.useDashboardStore(te=>te.dashboard.aiContext),E=s.useEditorStore(te=>te.card.dataSource),j=s.useEditorStore(te=>te.actions.setCardSql),k=s.useEditorStore(te=>te.actions.setRunSql),I=s.useEditorStore(te=>te.showAIDialog),f=s.useDashboardStore(te=>te.handleOpenAssistantProfile),{setShowAIDialog:A,setCardPython:g}=s.useEditorActions(),{setDataSource:D}=s.useEditorActions(),{assistantProfile:M}=s.useAssistantProfile(),{messages:P,setMessages:N,sendMessage:O,isLoading:S,stop:R,status:F,llmUsage:$,errorMessage:U,clearError:z}=Vl(),[H,se]=C.useState(""),Y=te=>{se(te.target.value)},ae=te=>{te.preventDefault();const be=H.trim();if(!be&&V.length===0)return;const Oe=[];be&&Oe.push({type:"text",text:be}),V.forEach(_e=>{_e.data&&Oe.push({type:"file",mediaType:_e.type,filename:_e.name,url:`data:${_e.type};base64,${_e.data}`})}),O({role:"user",parts:Oe}),se(""),T("editor"),ce({force:!0})},{visibleMessages:q,hasMoreMessages:J,totalMessageCount:le,loadMoreMessages:X,resetMessageWindow:oe}=s.useMessageWindow(P,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:me,contentRef:Z,isAtBottom:xe,hasNewMessages:B,newMessageCount:ee,scrollToBottom:ce,handleScroll:he,resetNewMessageCount:ke}=s.useAutoScroll(q,{threshold:40,behavior:"smooth",isStreaming:S});C.useEffect(()=>{var te;I&&((te=r.current)==null||te.focus(),b({selectedEntities:(E==null?void 0:E.selectedEntities)||[]}))},[I,E,b]),s.useAutoSubmitQueue({assistantType:"editor",status:F,isLoading:S,sendMessage:O});const{hasActiveTools:ye}=s.useActiveToolStatus(P),Ee=C.useCallback(te=>{n==null||n(te),t===void 0&&y(te)},[t,n]);C.useEffect(()=>{if(!v)return;function te(be){be.key==="Escape"&&Ee(!1)}return window.addEventListener("keydown",te),()=>{window.removeEventListener("keydown",te)}},[v,Ee]);const Se=C.useCallback(te=>{O({role:"user",parts:[{type:"text",text:te}]}),ce({force:!0})},[O,ce]),Pe=C.useCallback(async()=>{const te=JSON.stringify(P??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(te),s.ue.success("Conversation copied")}catch(be){console.error("Failed to copy conversation",be),s.ue.error("Unable to copy conversation")}},[P]),ne=C.useCallback(()=>{Ee(!v)},[v,Ee]);function je(te,be){be==="sql"?(j(te),k(!0)):be==="python"&&(g(te),k(!0))}function pe(){u.selectedEntities.length===0&&b({selectedEntities:(L==null?void 0:L.selectedEntities)||[]})}function Te(te){pe();const be={role:"user",parts:[{type:"text",text:te.title+" "+te.subtitle}]};O(be)}function Ae(te){pe(),O({role:"user",parts:[{type:"text",text:te}]})}function ve(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",variant:"ghost",children:e.jsx(s.EllipsisVertical,{className:"size-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuLabel,{children:"Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:d,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:c,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:x,children:"System Message"})]})]})}function Be(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const ze=(H==null?void 0:H.length)===0&&(P==null?void 0:P.filter(te=>te.role==="user").length)===0,De=e.jsxs("div",{"data-role":"editor-assistant",className:s.cn("flex h-full w-full flex-col justify-between px-6 py-4",v&&"rounded-2xl border border-border/60 bg-background px-8 pb-6 pt-6 shadow-xl"),children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Be(),f&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:f,children:(M==null?void 0:M.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[ve(),o&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:Pe,children:"Copy Conversation"}),e.jsx(s.IconButton,{tooltip:v?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:ne,children:v?e.jsx(s.Minimize2,{className:"size-4"}):e.jsx(s.Maximize2,{className:"size-4"})}),e.jsx(s.IconButton,{className:"h-7 p-2 text-muted-foreground hover:text-foreground",tooltip:"New Chat",onClick:()=>{N([]),w("editor"),z(),oe()},children:e.jsx(s.SquarePen,{className:"size-4"})}),e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2 text-muted-foreground hover:text-foreground",size:"sm",onClick:()=>{A(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:me,className:"mt-2 flex min-w-0 w-full grow basis-0",onScroll:he,children:e.jsxs("div",{ref:Z,className:"min-w-0 space-y-4 py-2 pr-3","data-role":"messages",children:[J&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:X,className:"text-xs",children:["Load ",Math.min(5,le-q.length)," ","more messages (",le-q.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:q,showTools:o,handleRun:je,showSystemMessage:l,onQuickReply:Se,disableQuickReplies:S}),!ye&&e.jsx(s.AssistantStatus,{status:F,errorMessage:U})]})}),I&&!xe&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{ce({force:!0}),ke()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),B&&ee>0&&e.jsx("span",{className:"ml-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-primary text-xs text-primary-foreground",children:ee>9?"9+":ee})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[ze&&!M&&e.jsx(s.Placeholders,{onClick:Te,placeholders:Pl}),e.jsx("div",{children:ze&&M&&e.jsx(s.SeedQuestions,{seedQuestions:M.seedQuestions||[],handleSeedQuestionClick:Ae})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:r,setInput:se,stop:R,input:H,handleInputChange:Y,handleSubmit:te=>{pe(),ae(te),ce({force:!0})},isLoading:S,status:F,assistantType:"editor",onFocus:()=>{}})]}),$&&i&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",$.inputTokens," prompt tokens, ",$.outputTokens," ","completion tokens, ",$.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(E==null?void 0:E.selectedEntities)||[],open:p,onOpenChange:h,dataSource:E||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return v&&a?tn.createPortal(e.jsx("div",{className:"pointer-events-auto absolute inset-0 z-50 flex bg-background px-6 pb-6 pt-[calc(var(--app-header-height,15px)+1rem)]",children:e.jsx("div",{className:"flex h-full w-full",children:De})}),a):De}function Bl(t,n,a){if(!n)return!1;const r=n.qualifiedFieldName,i=n.qualifiedEntityName,d=i&&n.name?`${i}.${n.name}`:r;return t.some(o=>{if(!(s.getDataType(o.dataType||"")==="date"))return!1;const l=s.getSelectedDateFilterColumn(o,a),x=l.split("."),p=x[x.length-1]||l,h=x.length>1?x.slice(0,-1).join("."):void 0,m=o.qualifiedTableName||h,y=m?`${m}.${p}`:void 0;return r?y?y===d||y.endsWith(`.${r}`):p===n.name:y?y===d:p===n.name})}const Da=["day","week","month","quarter","year"],zl=[...Da,"hour","minute","second"],ql=t=>/timestamp|datetime|time/i.test(t||""),$l=t=>ql(t)?zl:Da,Zs=({dataType:t})=>s.getFieldIconComponent(t);function _l({aliasTemplate:t,onAliasTemplateChange:n}){var l;const[a,r]=C.useState(t),[i,d]=C.useState(!1),o=(l=s.useEditorStore(x=>{var p;return(p=x.card.config)==null?void 0:p.pivotByColumns}))==null?void 0:l[0],c=o?`e.g. Min Sales in {{${o.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:c,value:i?a:t,onChange:x=>{r(x.target.value),d(!0)},onFocus:()=>d(!0),onPointerDown:x=>x.stopPropagation(),className:"h-8 text-xs",onKeyDown:x=>{x.key==="Enter"&&i&&a!==t?(n(a),d(!1)):x.key==="Escape"&&(r(t),d(!1))},"aria-label":"Edit alias template"}),i&&a!==t&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm alias template",onClick:()=>{n(a),d(!1)},children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{r(t),d(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Gl({valueAliases:t,onValueAliasesChange:n}){const[a,r]=C.useState(null),[i,d]=C.useState(""),[o,c]=C.useState(""),l=()=>{n({...t,"":""})},x=h=>{const m={...t};delete m[h],n(m)},p=h=>{const m={...t};delete m[h],m[i]=o,n(m),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([h,m],y)=>e.jsx("div",{className:"flex items-center gap-2",children:a===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:i,onChange:v=>d(v.target.value),className:"h-8 w-24 text-xs",onPointerDown:v=>v.stopPropagation(),onKeyDown:v=>{v.key==="Enter"?p(h):v.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:o,onChange:v=>c(v.target.value),className:"h-8 w-24 text-xs",onPointerDown:v=>v.stopPropagation(),onKeyDown:v=>{v.key==="Enter"?p(h):v.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>p(h),children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>r(null),children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),d(h),c(m)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:m,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),d(h),c(m)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>x(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+y)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:l,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Kl({idx:t}){var c;const n=s.useEditorStore(l=>{var x;return(x=l.card)==null?void 0:x.preferences}),a=s.useEditorStore(l=>{var x;return(x=l.card.preferences)==null?void 0:x.datasetOptions}),r=s.useEditorStore(l=>l.actions.setCardPreferences),i=(c=n==null?void 0:n.chartOptions)==null?void 0:c.indexAxis,d=a==null?void 0:a.find(l=>l.idx===t);function o(l,x){(l==="end"||l==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const p={display:l!=="none",align:l,anchor:l,clamp:!0};if(!d)r({...n,datasetOptions:[...a||[],{idx:x,datalabels:p}]});else{const h={...d};h.datalabels=p;const m=a==null?void 0:a.map(y=>y.idx===x?h:y);r({...n,datasetOptions:m})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(s.Tag,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(s.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>o("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>o("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(mn,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>o("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(hn,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>o("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(xn,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function et({children:t,className:n,delayDuration:a}){return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:a,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",n),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function Ul(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function Hl({col:t,idx:n,className:a,iconClassName:r,children:i}){const d=s.useEditorStore(p=>{var h;return(h=p.card)==null?void 0:h.preferences}),o=s.useEditorStore(p=>{var h,m;return(m=(h=p.card)==null?void 0:h.preferences)==null?void 0:m.datasetOptions}),c=o==null?void 0:o.find(p=>p.idx===n),{setCardPreferences:l}=s.useEditorStore(p=>p.actions);function x(p){if(!c)l({...d,datasetOptions:[...o||[],{idx:n,type:p==="area"?"line":p,fill:p==="area"?"origin":""}]});else{const h={...c};h.type=p==="area"?"line":p,h.fill=p==="area"?"origin":"";const m=o==null?void 0:o.map(y=>y.idx===n?h:y);l({...d,datasetOptions:m})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[i||e.jsx(et,{className:"max-w-[100px]",title:t,children:Ul(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.ChartColumnIncreasing,{onClick:()=>x("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(s.ChartLine,{onClick:()=>x("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(s.ChartArea,{onClick:()=>x("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Kl,{idx:n})]})]})}function Jl(){const t=s.useEditorStore(c=>c.card.type),n=s.useEditorStore(c=>c.isDevMode),a=s.useEditorStore(c=>c.card.preferences),{setCardPreferences:r}=s.useEditorStore(c=>c.actions);function i(c){var p;const l={datalabels:{display:c!=="none",align:c,anchor:c,clamp:!0}},x={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(p=a==null?void 0:a.chartOptions)==null?void 0:p.plugins,...l}}};r(x)}function d(){var c,l,x;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((x=(l=(c=a==null?void 0:a.chartOptions)==null?void 0:c.plugins)==null?void 0:l.datalabels)==null?void 0:x.anchor)||"none",onValueChange:i,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"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"start",children:"Start"}),e.jsx(s.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{value:"end",children:"End"})]})})]})]})}function o(){var c,l,x;return e.jsx("div",{children:e.jsxs(s.Select,{value:((x=(l=(c=a==null?void 0:a.chartOptions)==null?void 0:c.plugins)==null?void 0:l.datalabels)==null?void 0:x.anchor)||"none",onValueChange:i,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"none",children:"None"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"start",children:"Start"}),e.jsx(s.SelectItem,{className:"text-xs",value:"center",children:"Center"}),!["pyramid","funnel"].includes(t)&&e.jsx(s.SelectItem,{className:"text-xs",value:"end",children:"End"})]})})]})})}return e.jsx(e.Fragment,{children:n?d():o()})}function Ql({column:t}){const n=s.useEditorStore(l=>l.card.type),a=s.useEditorStore(l=>{var x,p;return(p=(x=l.card)==null?void 0:x.config)==null?void 0:p.metricColumns}),r=(a==null?void 0:a.map(l=>l.label))||[],i=r==null?void 0:r.find(l=>l===t.label||l===t.name),d=i?r.indexOf(i):-1;function o(){return e.jsx("div",{className:"pr-1",children:i&&e.jsx(Hl,{idx:d,col:i,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function c(){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Data Labels"}),e.jsx(Jl,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&o(),["pie","doughnut"].includes(n)&&c()]})}function Yl({field:t,searchQuery:n="",limit:a=500}){const{authToken:r,tokenProps:i}=s.useSemaphorContext(),d=s.useEditorStore(x=>x.card),o=d==null?void 0:d.dataSource,c=["attribute-values",t.entityName,t.name,n,a],l=s.useQuery({queryKey:c,queryFn:async()=>{if(!(o!=null&&o.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const x={groupByColumns:[{...t,role:"groupby"}],metricColumns:[],filters:n?{id:"search-filter",logicalOperator:"AND",negate:!1,conditions:[{id:"search-condition",field:t,operator:"contains",value:n}],groups:[]}:void 0,rowLimit:a},p={connection_id:o.connectionId,cardConfig:x,cardDataSource:o,cache_config:s.getCacheConfig({card:d})};console.log("requestBody",p);const h=await s.postRequestRegular(`${i.apiServiceUrl}/v1/query`,(r==null?void 0:r.accessToken)||"",p);if(h!=null&&h.error)return console.error("Error fetching attribute values:",h.error),[];const m=t.name;return((h==null?void 0:h.records)||[]).map(v=>{const u=v[m]||v[t.alias||m]||v[t.label];return{id:u||"",value:u||"",label:String(u||"(empty)")}})}catch(x){return console.error("Error fetching attribute values:",x),[]}},enabled:!!t&&!!(o!=null&&o.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:l.data||[],isLoading:l.isLoading,isFetching:l.isFetching,isError:l.isError,error:l.error,refetch:l.refetch}}function Aa({open:t,onOpenChange:n,availableFields:a,existingFilters:r,editingCondition:i,onSave:d}){var V,L;const o=!!i,[c,l]=C.useState(o?"values":"fields"),[x,p]=C.useState(""),[h,m]=C.useState({id:(i==null?void 0:i.id)||s.v4(),field:(i==null?void 0:i.field)||null,selectedValues:i?Array.isArray(i.value)?i.value:[i.value]:[]}),y=a.filter(E=>{var k;return o?!1:!((k=r==null?void 0:r.conditions)==null?void 0:k.some(I=>I.field.id===E.id))&&E.label.toLowerCase().includes(x.toLowerCase())}),v=E=>{m({...h,field:E}),l("values")},u=()=>{if(h.field&&h.selectedValues.length>0){const E={id:h.id,field:h.field,operator:"in",value:h.selectedValues};let j;if(o){const k=((r==null?void 0:r.conditions)||[]).map(I=>I.id===i.id?E:I);j={...r,conditions:k}}else{const k=(r==null?void 0:r.conditions)||[];j={id:(r==null?void 0:r.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...k,E],groups:[]}}d(j),n(!1)}},b=()=>{if(!o||!i)return;const E=((r==null?void 0:r.conditions)||[]).filter(j=>j.id!==i.id);if(E.length>0){const j={...r,conditions:E};d(j)}else d(void 0);n(!1)},w=E=>{m({...h,selectedValues:E})},T=()=>{o&&i?(m({id:i.id,field:i.field,selectedValues:Array.isArray(i.value)?i.value:[i.value]}),l("values")):(m({id:s.v4(),field:null,selectedValues:[]}),l("fields")),p("")};return C.useEffect(()=>{t&&T()},[t,o,i]),e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:o?`Edit Filter: ${(V=h.field)==null?void 0:V.label}`:c==="fields"?"Select Field to Filter":`Select Values for ${(L=h.field)==null?void 0:L.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!o&&(r==null?void 0:r.conditions)&&r.conditions.length>0&&c==="fields"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Current Filters:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.conditions.map(E=>e.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted rounded-md text-xs",children:[e.jsxs("span",{className:"font-medium",children:[E.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(E.value)?`${E.value.length} values`:String(E.value)})]},E.id))})]}),c==="fields"&&!o?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search fields...",value:x,onChange:E=>p(E.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:y.map(E=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>v(E),children:[e.jsx(Zs,{dataType:s.getDataType(E.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:E.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[E.entityName,".",E.name]})]})]},E.id))}),y.length===0&&x&&e.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:['No fields found matching "',x,'"']}),y.length===0&&!x&&a.length>0&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"All available fields are already filtered"})]}):e.jsx(Wl,{field:h.field,selectedValues:h.selectedValues,onValuesChange:w,onBack:o?void 0:()=>l("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:o?e.jsx(s.Button,{variant:"destructive",onClick:b,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:T,children:"Reset"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsx(s.Button,{onClick:u,disabled:!h.field||h.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function Wl({field:t,selectedValues:n,onValuesChange:a,onBack:r}){const[i,d]=C.useState(""),{values:o,isLoading:c,isFetching:l}=Yl({field:t,searchQuery:i,limit:500}),x=i?o.filter(m=>String(m.value).toLowerCase().includes(i.toLowerCase())):o,p=m=>{const y=n.includes(m);a(y?n.filter(v=>v!==m):[...n,m])},h=()=>{n.length===x.length&&x.length>0?a([]):a(x.map(m=>m.value))};return e.jsxs("div",{className:"space-y-4",children:[r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:r,children:"← Back"}),e.jsxs(s.Label,{className:"text-sm font-medium",children:["Select values for ",t.label]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input$1,{placeholder:"Search values...",value:i,onChange:m=>d(m.target.value),className:"pl-10"})]}),c||l?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(s.LoaderCircle,{className:"h-6 w-6 animate-spin"})}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 pb-2 border-b",children:[e.jsx(s.Checkbox,{checked:n.length===x.length&&x.length>0,onCheckedChange:h}),e.jsxs(s.Label,{className:"text-sm",children:["Select All (",x.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:x.map(m=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>p(m.value),children:[e.jsx(s.Checkbox,{checked:n.includes(m.value),onCheckedChange:()=>p(m.value)}),e.jsx(et,{className:"text-sm",children:m.label})]},m.id))})]})]})}function Xl({field:t,zone:n,index:a,sortDirection:r,onSortDirectionChange:i,hasPivotColumns:d=!1,cardType:o}){var ct,dt,ut,mt,xt,ht,pt,ft,gt,jt,bt,vt,yt,Nt,Ct,St,wt,Tt,Et,It,kt,Dt,At,Lt,Mt,Ot,Rt,Ft,Vt,Pt,Bt,zt,qt,$t;const{attributes:c,listeners:l,setNodeRef:x,transform:p,transition:h,isDragging:m}=s.useSortable({id:t.id}),y=s.useEditorStore(_=>_.card),v=s.useEditorStore(_=>_.frame),{scopedFields:u,isLoading:b}=s.useScopedFields(),{userContext:w}=s.useCurrentUserInfo(),T=(w==null?void 0:w.type)==="organization",V=(ct=y.dataSource)==null?void 0:ct.semanticDomainId,{promoteMetric:L}=s.usePromoteCalculatedMetricToDomain({domainId:V}),{updateLabel:E,handleAggregationChange:j,handleDateFormatChange:k,handleGranularityChange:I,handleAliasTemplateChange:f,handleValueAliasesChange:A,removeField:g,handleMetricComparisonChange:D,handleMetricWindowTransformChange:M,handleMetricWindowOrderByChange:P,handleMetricWindowDirectionChange:N,handleMetricWindowPartitionToggle:O,handleMetricMovingAverageWindowSizeChange:S,handleMetricMovingAverageMinPeriodsChange:R,handleMetricPreviousPeriodDeltaModeChange:F,handleMetricPercentOfTotalScopeChange:$,handleMetricPercentOfTotalOutputChange:U,handleKpiShowTrendlineChange:z,handleKpiTrendlineWindowChange:H,handleKpiTrendlineGranularityChange:se,handleMetricTargetValueChange:Y}=s.useFieldManagement(y),[ae,q]=C.useState(!1),[J,le]=C.useState(()=>{var _;return!!((_=t.parameters)!=null&&_.windowTransform)}),[X,oe]=C.useState(!1),[me,Z]=C.useState(!1),[xe,B]=C.useState(null),ee=C.useMemo(()=>{const _=re=>re!=null&&re.startsWith("card-source-")?re.replace("card-source-",""):re,K=_(t.id),ie=u.find(re=>{if(t.qualifiedFieldName&&re.qualifiedFieldName&&re.qualifiedFieldName===t.qualifiedFieldName||t.qualifiedEntityName&&re.qualifiedEntityName&&re.qualifiedEntityName===t.qualifiedEntityName&&re.name===t.name)return!0;const Ne=_(re.id);return!!(K&&Ne&&K===Ne)});return{dataType:(ie==null?void 0:ie.dataType)||t.dataType,resolvedFromScopedField:!!ie}},[t.dataType,t.id,t.name,t.qualifiedEntityName,t.qualifiedFieldName,u]),ce=$l(ee.dataType),[he,ke]=C.useState(t.dateFormat||"YYYY-MM-DD"),[ye,Ee]=C.useState(t.customFormat||""),[Se,Pe]=C.useState(!!t.customFormat),ne=C.useRef(null),[je,pe]=C.useState(t.aliasTemplate||""),[Te,Ae]=C.useState(t.valueAliases||{}),[ve,Be]=C.useState((dt=t.parameters)==null?void 0:dt.filters),ze=_=>{_==="custom"?Pe(!0):(Pe(!1),ke(_),(n==="groupBy"||ds)&&k(a,_,"",n))},De=_=>{Ee(_),(n==="groupBy"||ds)&&k(a,"custom",_,n)},te=_=>{var re;const ie=(re=s.getDateFormatOptionsForGranularity(_)[0])==null?void 0:re.value;ie&&!Se&&(ke(ie),n==="groupBy"&&k(a,ie,"",n)),n==="groupBy"&&I(a,_)},be=_=>{pe(_),n==="metrics"&&f(a,_)},Oe=_=>{Ae(_),n==="metrics"&&A(a,_)},_e=_=>{E(n,a,_)},Ye=_=>_!=null&&_.startsWith("card-source-")?_.replace("card-source-",""):_,fs=(_,K,ie)=>{const re=Ye(_.id),Ne=Ye(K.id);return re&&Ne&&re===Ne?!0:_.name===K.name&&_.role===K.role},ss=s.isCalculatedMetric(t)?(ut=v==null?void 0:v.calculatedFields)==null?void 0:ut.find(_=>fs(_,t)):void 0,We=t.fieldScope==="dashboard"||t.fieldScope===void 0&&!!ss,gs=t.fieldScope==="domain",ls=gs?"domain":We?"dashboard":"card",Ds=gs?t:We&&ss?ss:t,js=_=>{var K;if(Be(_),n==="metrics"){const ie={...t,parameters:{...t.parameters,filters:_}},re=[...((K=y.config)==null?void 0:K.metricColumns)||[]];re[a]=ie,s.useEditorStore.getState().actions.updateCardConfig(y.id,{metricColumns:re})}oe(!1)},os=async _=>{await L(_),Za()},As=()=>{g(n,a)},bs={transform:s.CSS.Transform.toString(p),transition:h},is=s.getDataType(ee.dataType||t.dataType),cs=is==="date",vs=o==="kpi",ds=n==="detailColumns",us=(mt=y.config)==null?void 0:mt.metricColumns,Ge=(xt=y.config)==null?void 0:xt.groupByColumns,Xe=s.useDashboardStore(_=>{var K;return(K=_.dashboard)==null?void 0:K.filters}),ms=s.useDashboardStore(_=>_.filterValues),Ke=t.granularity||"day",G=ce.includes(Ke)?Ke:"day",W=n==="groupBy"&&!ce.includes(Ke),Q=s.getDateFormatOptionsForGranularity(G),ue=Se?"custom":Q.some(_=>_.value===he)?he:((ht=Q[0])==null?void 0:ht.value)??"YYYY-MM-DD";C.useEffect(()=>{var ie;if(b||!W){ne.current=null;return}const _=`${t.id}:${Ke}:${ee.dataType||t.dataType||""}:${a}`;if(ne.current===_)return;ne.current=_;const K="day";if(I(a,K),!Se){const re=(ie=s.getDateFormatOptionsForGranularity(K)[0])==null?void 0:ie.value;re&&(ke(re),k(a,re,"",n))}},[t.dataType,t.id,k,I,W,a,Se,b,Ke,ee.dataType,n]);const de=!!o&&s.COMPARISON_SUPPORTED_CHART_TYPES.includes(o),ge=o==="kpi"||o==="table",Ce=C.useMemo(()=>Ge==null?void 0:Ge.find(_=>s.getDataType(_.dataType||"")==="date"),[Ge]),Le=C.useMemo(()=>(Ge||[]).some(_=>s.getDataType(_.dataType||"")==="date"),[Ge]),Ue=C.useMemo(()=>{var re;if(!Ce)return!1;const _=(re=y.config)==null?void 0:re.filters;if(!_)return!1;const K=Ne=>{const we=Ne.field;return we?Ce.id&&we.id===Ce.id||Ce.qualifiedFieldName&&we.qualifiedFieldName===Ce.qualifiedFieldName?!0:we.name===Ce.name:!1},ie=Ne=>Ne.conditions.some(Ve=>s.getDataType(Ve.field.dataType||"")==="date"&&K(Ve))?!0:Ne.groups.some(Ve=>ie(Ve));return ie(_)},[(pt=y.config)==null?void 0:pt.filters,Ce]),ts=C.useMemo(()=>Bl(Xe||[],Ce,ms),[Xe,ms,Ce]),Ze=Ue||ts,fe=t,He=((gt=(ft=fe.parameters)==null?void 0:ft.windowTransform)==null?void 0:gt.function)||"none",Re=s.isMetricTransformEnabled(fe),Fe=Re?He:null,Ls=s.supportsMetricTransformForMetric({cardType:o||"table",cardConfig:y.config||{},metric:fe,transformMode:Fe||"running_total"}),xs=!!fe.comparisonType&&fe.comparisonType!=="none",tt=s.getRunningTotalOrderByCandidates(Ge||[]),as=((vt=(bt=(jt=fe.parameters)==null?void 0:jt.windowTransform)==null?void 0:bt.orderBy)==null?void 0:vt.fieldId)||"",Ma=((Ct=(Nt=(yt=fe.parameters)==null?void 0:yt.windowTransform)==null?void 0:Nt.orderBy)==null?void 0:Ct.direction)||"asc",at=tt.find(_=>_.id===as),Ms=Fe==="running_total"||Fe==="moving_average"||Fe==="previous_period_delta",Oa=Re&&Ms&&!!at&&s.getDataType(at.dataType||"")!=="date",Ra=s.getDefaultRunningTotalPartitionByFieldIds({cardType:o||"table",cardConfig:y.config||{},orderByFieldId:as||void 0}),Fa=new Set(((wt=(St=fe.parameters)==null?void 0:St.windowTransform)==null?void 0:wt.partitionByFieldIds)||Ra),Va=o==="pivotTable"||s.isSubtotalEnabledAggregateTable(o||"table",y.config||{}),nt=[...(Ge||[]).filter(_=>_.id&&(!Ms||_.id!==as)),...Va?(((Tt=y.config)==null?void 0:Tt.pivotByColumns)||[]).filter(_=>_.id):[]],rt=((kt=(It=(Et=fe.parameters)==null?void 0:Et.windowTransform)==null?void 0:It.movingAverage)==null?void 0:kt.windowSize)||7,Pa=((Lt=(At=(Dt=fe.parameters)==null?void 0:Dt.windowTransform)==null?void 0:At.movingAverage)==null?void 0:Lt.minPeriods)||1,Ba=((Rt=(Ot=(Mt=fe.parameters)==null?void 0:Mt.windowTransform)==null?void 0:Ot.previousPeriodDelta)==null?void 0:Rt.mode)||"absolute",lt=((Pt=(Vt=(Ft=fe.parameters)==null?void 0:Ft.windowTransform)==null?void 0:Vt.percentOfTotal)==null?void 0:Pt.scope)||"grand_total",za=((qt=(zt=(Bt=fe.parameters)==null?void 0:Bt.windowTransform)==null?void 0:zt.percentOfTotal)==null?void 0:qt.output)||"percent",qa=C.useMemo(()=>(us||[]).some(_=>_.comparisonType==="start_vs_end"),[us]);C.useEffect(()=>{Re&&le(!0)},[Re]);const $a=n!=="pivotBy",_a=cs&&n==="groupBy"&&(!vs||qa),Ga=!vs&&cs&&(n==="groupBy"||ds),Ka=o==="kpi"&&cs&&n==="groupBy",Ua=n==="metrics",ot=de&&n==="metrics",Ha=()=>{const _=t,K=n==="metrics"&&s.isCalculatedMetric(_);return e.jsxs("div",{className:"space-y-1",children:[!K&&e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:ie=>{ie.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-muted-foreground/80",children:`${t.entityName}.${t.name}`}),K&&_.calculatedFormula&&e.jsxs("div",{title:s.formatDisplayFormula(_.calculatedFormula),onPointerDown:ie=>{ie.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap rounded bg-muted/50 px-1.5 py-0.5 font-mono text-xs text-primary",children:["= ",s.formatDisplayFormula(_.calculatedFormula)]})]})},Ja=()=>$a?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(qe,{value:t.label??"",onSave:_e,placeholder:"Display label...",type:"text"})]}):null,it=()=>_a?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Granularity"}),e.jsxs(s.Select,{value:G,onValueChange:te,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsx(s.SelectContent,{children:ce.map(_=>e.jsx(s.SelectItem,{className:"text-xs",value:_,children:s.toTitleCase(_)},_))})]})]}):null,Qa=()=>Ga?e.jsxs(e.Fragment,{children:[it(),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Date Format"}),e.jsxs(s.Select,{value:ue,onValueChange:ze,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select date format..."})}),e.jsx(s.SelectContent,{children:Q.map(_=>e.jsx(s.SelectItem,{className:"text-xs",value:_.value,children:_.label},_.value))})]}),Se&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:ye,onChange:_=>{_.stopPropagation(),De(_.target.value)},onClick:_=>_.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}):null,Ya=()=>{var K,ie,re,Ne;const _=Ka;return _?e.jsx(e.Fragment,{children:_&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-1",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Show Trendline"}),e.jsx(s.SmallSwitch,{checked:((K=y.config)==null?void 0:K.showTrendline)||!1,onCheckedChange:z})]})}),((ie=y.config)==null?void 0:ie.showTrendline)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Window"}),e.jsx(s.Input$1,{type:"number",min:"1",max:"365",value:((re=y.config)==null?void 0:re.trendlineWindow)||30,onChange:we=>{const Ve=parseInt(we.target.value)||30;H(Ve)},className:"h-8 text-xs",placeholder:"30"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Trendline Granularity"}),e.jsxs(s.Select,{value:((Ne=y.config)==null?void 0:Ne.trendlineGranularity)||"day",onValueChange:se,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"day",children:"Day"}),e.jsx(s.SelectItem,{value:"week",children:"Week"}),e.jsx(s.SelectItem,{value:"month",children:"Month"})]})]})]})]})]})}):null},Wa=()=>{if(!Ua)return null;const _=s.isCalculatedMetric(fe);return e.jsxs(e.Fragment,{children:[_&&T&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Formula"}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>Z(!0),children:[e.jsx(s.Pencil,{className:"mr-2 h-3 w-3"}),"Edit Formula"]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:K=>{j(a,K)},disabled:_,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select function..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"COUNT",children:"Count"}),e.jsx(s.SelectItem,{className:"text-xs",value:"DISTINCT",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{className:"text-xs",value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{className:"text-xs",value:"MEDIAN",children:"Median"})]})]})]})]}),e.jsx(s.Collapsible,{open:J,onOpenChange:le,children:e.jsxs("div",{className:"space-y-2 rounded-md border border-border/60 bg-muted/20 p-2.5",children:[e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between rounded-sm px-0.5 py-0.5 text-left",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Metric Transform"}),e.jsxs("div",{className:"flex items-center text-[11px] text-muted-foreground",children:[!J&&e.jsx("span",{className:"mr-2",children:Re?s.toTitleCase(He.replace(/_/g," ")):"None"}),e.jsx(s.ChevronDown,{className:s.cn("h-3 w-3 transition-transform",J?"rotate-180":"")})]})]})}),e.jsxs(s.CollapsibleContent,{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Transform"}),e.jsxs(s.Select,{value:Re?He:"none",onValueChange:K=>M(a,K),disabled:!Ls.supported&&!Re,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select transform..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"none",children:"None"}),e.jsx(s.SelectItem,{value:"running_total",disabled:xs,children:"Running Total"}),e.jsx(s.SelectItem,{value:"moving_average",disabled:xs,children:"Moving Average"}),e.jsx(s.SelectItem,{value:"previous_period_delta",disabled:xs,children:"Previous Period Delta"}),e.jsx(s.SelectItem,{value:"percent_of_total",disabled:xs,children:"Percent of Total"})]})]}),!Ls.supported&&!Re&&e.jsx("div",{className:"text-xs text-muted-foreground",children:Ls.reason}),xs&&!Re&&e.jsx("div",{className:"text-xs text-muted-foreground",children:"Disable comparison to enable metric transforms."})]}),Re&&e.jsxs(e.Fragment,{children:[Ms&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Order By"}),e.jsxs(s.Select,{value:as,onValueChange:K=>P(a,K),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select order field..."})}),e.jsx(s.SelectContent,{children:tt.filter(K=>!!K.id).map(K=>e.jsx(s.SelectItem,{value:K.id,className:"text-xs",children:K.label||K.name},K.id))})]}),!as&&e.jsx("div",{className:"text-xs text-amber-700",children:"No date trend detected. Select an order field."}),Oa&&e.jsx("div",{className:"text-xs text-amber-700",children:"No date trend detected. The transform will follow the selected order field."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Direction"}),e.jsxs(s.Select,{value:Ma,onValueChange:K=>N(a,K),disabled:!as,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select direction..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"text-xs",value:"asc",children:"Ascending"}),e.jsx(s.SelectItem,{className:"text-xs",value:"desc",children:"Descending"})]})]})]})]}),Fe==="moving_average"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Window Size"}),e.jsx(s.Input$1,{type:"number",min:1,className:"h-8 text-xs",value:rt,onChange:K=>S(a,Number(K.target.value))}),e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Min Periods"}),e.jsx(s.Input$1,{type:"number",min:1,max:rt,className:"h-8 text-xs",value:Pa,onChange:K=>R(a,Number(K.target.value))})]}),Fe==="previous_period_delta"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),e.jsxs(s.Select,{value:Ba,onValueChange:K=>F(a,K),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select output..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"absolute",children:"Absolute Delta"}),e.jsx(s.SelectItem,{value:"percent",children:"Percent Delta"})]})]})]}),Fe==="percent_of_total"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Scope"}),e.jsxs(s.Select,{value:lt,onValueChange:K=>$(a,K),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select scope..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"grand_total",children:"Grand Total"}),e.jsx(s.SelectItem,{value:"partition_total",children:"Partition Total"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Output"}),e.jsxs(s.Select,{value:za,onValueChange:K=>U(a,K),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select output..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"percent",children:"Percent"}),e.jsx(s.SelectItem,{value:"fraction",children:"Fraction"})]})]})]})]}),(Fe==="running_total"||Fe==="moving_average"||Fe==="previous_period_delta"||Fe==="percent_of_total"&<==="partition_total")&&nt.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Reset By"}),e.jsx("div",{className:"space-y-1",children:nt.map(K=>{const ie=!!K.id&&Fa.has(K.id);return e.jsxs("button",{type:"button",onClick:()=>K.id&&O(a,K.id),className:s.cn("flex h-7 w-full items-center justify-between rounded border px-2 text-xs",ie?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground"),children:[e.jsx("span",{children:K.label||K.name}),ie?e.jsx(s.Check,{className:"h-3 w-3"}):null]},K.id)})})]})]})]})]})}),ot&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Comparison Type"}),e.jsxs(s.Select,{value:fe.comparisonType||"none",disabled:Re,onValueChange:K=>D(a,K),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select comparison type..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"none",children:"No Comparison"}),(()=>{const K=!Le||!Ze,ie=Le?Ze?void 0:"Add a date filter to enable":"Add a date groupBy to enable",re=(Ne,we)=>e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.SelectItem,{value:Ne,disabled:K,title:ie,children:we})}),K&&ie&&e.jsx(s.TooltipContent,{side:"right",children:ie})]})});return e.jsxs(e.Fragment,{children:[re("previous_period","Previous Period"),re("same_period_last_year","Same Period Last Year"),re("start_vs_end","Start vs End")]})})(),ge&&e.jsx(s.SelectItem,{value:"target",children:"Target"})]})]})]}),ot&&fe.comparisonType==="target"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Target Value"}),e.jsx(s.Input$1,{type:"number",value:fe.targetValue!==void 0&&fe.targetValue!==null?String(fe.targetValue):"",onChange:K=>{const ie=K.target.value;if(ie===""){Y(a,void 0);return}const re=Number(ie);Y(a,Number.isFinite(re)?re:void 0)},className:"h-8 text-xs",placeholder:"Enter target value..."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(ve==null?void 0:ve.conditions)&&ve.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:ve.conditions.map(K=>e.jsxs("div",{className:"flex cursor-pointer items-center gap-2 rounded bg-muted/50 p-2 text-xs transition-colors hover:bg-muted/70",onClick:()=>{B(K),oe(!0)},children:[e.jsxs("span",{className:"font-medium",children:[K.field.label,":"]}),e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:"cursor-help text-muted-foreground",children:Array.isArray(K.value)?K.value.length===1?String(K.value[0]):K.value.length<=2?K.value.join(", "):`${K.value.slice(0,2).join(", ")} +${K.value.length-2}`:String(K.value)})}),Array.isArray(K.value)&&K.value.length>1&&e.jsx(s.TooltipContent,{side:"top",className:"max-w-[300px]",children:e.jsxs("div",{className:"text-xs",children:[e.jsxs("div",{className:"mb-1 font-medium",children:["Selected values (",K.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:K.value.map((ie,re)=>e.jsx("div",{children:String(ie)},re))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:ie=>{var Ne;ie.stopPropagation();const re=ve.conditions.filter(we=>we.id!==K.id);if(re.length>0){const we={...ve,conditions:re};js(we)}else if(Be(void 0),n==="metrics"){const we={...t,parameters:{...t.parameters,filters:void 0}},Ve=[...((Ne=y.config)==null?void 0:Ne.metricColumns)||[]];Ve[a]=we,s.useEditorStore.getState().actions.updateCardConfig(y.id,{metricColumns:Ve})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},K.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{B(null),oe(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(Ql,{column:t}),d&&e.jsxs(e.Fragment,{children:[e.jsx(_l,{aliasTemplate:je,onAliasTemplateChange:be}),e.jsx(Gl,{valueAliases:Te,onValueAliasesChange:Oe})]})]})},{columns:Xa=[],refetch:Za}=s.useColumns(),en=(ve==null?void 0:ve.conditions)&&ve.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:x,style:bs,...c,...l,className:s.cn("group mx-auto flex w-full flex-col gap-2 rounded-md border border-border/55 bg-background p-2 transition-colors duration-150","hover:border-border/80 hover:bg-muted/20",ae&&"border-border/80 bg-muted/20 shadow-[inset_0_1px_0_rgba(255,255,255,0.35)]",m&&"z-50 scale-95 opacity-50",n==="filters"?"cursor-default":"cursor-move"),children:[e.jsxs("div",{className:"flex min-w-0 grow items-center gap-2",children:[e.jsx(Zs,{dataType:is}),e.jsx(et,{className:s.cn("w-[140px] min-w-0 flex-1 text-sm text-foreground/95",en&&"w-[120px] min-w-0"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&(($t=ve==null?void 0:ve.conditions)==null?void 0:$t.length)&&!ae&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs("div",{className:"flex items-center gap-1 rounded bg-primary/10 px-1.5 py-0.5 text-xs text-primary/90",children:[e.jsx(s.Filter,{className:"h-3 w-3"}),e.jsx("span",{children:ve.conditions.length})]})}),e.jsx(s.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:ve.conditions.map(_=>e.jsxs("div",{children:[_.field.label,":"," ",Array.isArray(_.value)?`${_.value.length} values`:String(_.value)]},_.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-foreground/55 hover:text-foreground",onClick:_=>{_.stopPropagation(),q(!ae)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${ae?"rotate-180":""}`})}),n==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-foreground/55 hover:text-foreground",onClick:_=>{_.stopPropagation(),i(r==="asc"?"desc":"asc")},children:r==="asc"?e.jsx(s.ArrowUp,{className:"h-3 w-3"}):e.jsx(s.ArrowDown,{className:"h-3 w-3"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-foreground/55 hover:text-foreground",onClick:_=>{_.stopPropagation(),As()},children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]}),ae&&e.jsxs("div",{className:"space-y-3 rounded-md bg-muted/20 p-2.5",children:[Ha(),Ja(),o==="kpi"&&it(),Qa(),Ya(),Wa()]})]}),X&&e.jsx(Aa,{open:X,onOpenChange:_=>{oe(_),_||B(null)},availableFields:Xa,existingFilters:ve,editingCondition:xe,onSave:_=>{var K;if(_)js(_);else if(Be(void 0),n==="metrics"){const ie={...t,parameters:{...t.parameters,filters:void 0}},re=[...((K=y.config)==null?void 0:K.metricColumns)||[]];re[a]=ie,s.useEditorStore.getState().actions.updateCardConfig(y.id,{metricColumns:re})}B(null)}}),me&&n==="metrics"&&e.jsx(s.CalculatedFieldEditor,{open:me,onOpenChange:Z,availableFields:u,existingField:Ds,existingFieldScope:ls,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:_=>{var ns;if(_.role!=="metric")return;const K=[...((ns=y.config)==null?void 0:ns.metricColumns)||[]];K[a]=_;const{frame:ie,actions:re}=s.useEditorStore.getState();if(re.updateCardConfig(y.id,{metricColumns:K}),!s.isCalculatedMetric(_))return;const Ne=ie.calculatedFields||[],we=Ne.findIndex($e=>$e.name===t.name&&$e.role===t.role);if(we<0)return;const Ve=Ne.map(($e,ys)=>ys===we?{..._,id:$e.id}:$e);re.updateFrame({calculatedFields:Ve})},onSaveToDashboard:_=>{var ys;if(_.role!=="metric")return;const{frame:K,actions:ie}=s.useEditorStore.getState(),re=K.calculatedFields||[],Ne=re.findIndex(Os=>fs(Os,_)),we=Ne>=0&&re[Ne].id!==_.id?{..._,id:re[Ne].id}:_,Ve=Ne>=0?re.map((Os,sn)=>sn===Ne?we:Os):[...re,we];ie.updateFrame({calculatedFields:Ve});const ns=[...((ys=y.config)==null?void 0:ys.metricColumns)||[]],$e=t;ns[a]={...we,id:$e.id,aliasTemplate:$e.aliasTemplate,valueAliases:$e.valueAliases,parameters:$e.parameters,customFormat:$e.customFormat},ie.updateCardConfig(y.id,{metricColumns:ns})},onPromoteMetricToDomain:V&&T?os:void 0,domainId:V,cardId:y.id})]})}function Zl({concept:t}){const n=()=>{switch(t){case"groupBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Rows = Group By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that define how your data is grouped into rows."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-100 text-xs font-medium dark:bg-blue-200/20",children:"Product"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Sales"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Profit"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/50 text-xs font-medium dark:bg-blue-200/20",children:"Electronics"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$5,200"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$1,300"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/30 text-xs font-medium dark:bg-blue-300/20",children:"Clothing"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$3,100"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$620"})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-1/3 bg-blue-200/20 text-xs font-medium dark:bg-blue-200/20",children:"Food"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$2,400"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$480"})]})]})]});case"pivotBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Pivot Columns = Pivot By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that split your data into multiple columns or series."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Region"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"North"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"South"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"East"})]}),e.jsxs("div",{className:"flex border-b py-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$2,300"}),e.jsx("div",{className:"w-1/4 bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$1,800"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$3,400"})]}),e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$460"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$360"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$680"})]})]})]});case"metrics":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Metric Values (Cells)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that represent the values shown in your visualization."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q2"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q3"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"rounded bg-blue-100 p-1 text-center text-xs dark:bg-blue-300/20",children:"$2,300"}),e.jsx("div",{className:"rounded bg-blue-200 p-1 text-center text-xs dark:bg-blue-400/20",children:"$3,100"}),e.jsx("div",{className:"rounded bg-blue-300 p-1 text-center text-xs dark:bg-blue-500/20",children:"$4,200"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"rounded bg-green-100 p-1 text-center text-xs dark:bg-green-300/20",children:"$460"}),e.jsx("div",{className:"rounded bg-green-200 p-1 text-center text-xs dark:bg-green-400/20",children:"$620"}),e.jsx("div",{className:"rounded bg-green-300 p-1 text-center text-xs dark:bg-green-500/20",children:"$840"})]})]})]});case"detailColumns":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Columns"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields to display as columns in the detail table. No aggregation applied - shows raw values from the database."})]});default:return null}};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.CircleHelp,{className:"size-4 text-muted-foreground hover:text-foreground"})}),e.jsx(s.TooltipContent,{side:"right",align:"start",className:"p-3",children:n()})]})})}const eo={groupBy:Ss,pivotBy:Js,metrics:bn,detailColumns:s.Table2,sortBy:s.ArrowUpDown};function ps({zone:t,fields:n,label:a,placeholder:r,shouldShow:i,hasPivotColumns:d=!1,activeField:o=null}){const{isOver:c,setNodeRef:l}=s.useDroppable({id:t}),{updateSortByColumn:x}=s.useEditorActions(),p=s.useEditorStore(w=>w.card),h=s.useEditorStore(w=>w.card.type),m=n.length>0,y=C.useMemo(()=>!o||!c?!0:s.validateFieldForChartType(o,t,h).isValid,[o,c,t,h]),v=(w,T)=>{var L;!((L=p.config)!=null&&L.sortByColumns)||p.config.sortByColumns.findIndex(E=>E.id===w)===-1||x(p.id,w,{direction:T})};if(t==="sortBy"&&i===!1)return null;const u=t!=="sortBy"&&h!=="kpi",b=eo[t]||s.Plus;return e.jsxs("div",{className:"mb-3 w-full",children:[e.jsxs("div",{className:"mb-1.5 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium text-foreground",{}),children:a}),u&&e.jsx(Zl,{concept:t})]}),e.jsx("div",{ref:l,className:s.cn("rounded-lg border p-0.5 transition-colors duration-150",{"border-green-500 bg-green-50 shadow-[0_0_0_1px_rgba(34,197,94,0.18)] dark:bg-green-950":c&&y,"border-red-500 bg-red-50 shadow-[0_0_0_1px_rgba(239,68,68,0.18)] dark:bg-red-950":c&&!y,"border-solid border-border/55 bg-background":!c&&m,"min-h-[56px] border-dashed border-border/60 bg-background":!c&&!m}),children:n.length===0?e.jsxs("div",{className:"flex min-h-[56px] items-center justify-center gap-2 text-sm text-muted-foreground/85",children:[e.jsx(b,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80"}),e.jsx("span",{children:r})]}):e.jsx(s.SortableContext,{id:t,items:n.map(w=>w.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.map((w,T)=>{const L=w.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(Xl,{field:w,zone:t,index:T,sortDirection:L,onSortDirectionChange:E=>v(w.id,E),hasPivotColumns:d,cardType:h})})},w.id)})})})})]})}function so({groupByFields:t,pivotByFields:n,metricsFields:a,sortByFields:r,detailFields:i,activeField:d}){var se,Y,ae,q;const[o,c]=C.useState(!1),l=s.useEditorStore(J=>{var le;return!!((le=J.card.customCardPreferences)!=null&&le.url)}),x=s.useEditorStore(J=>J.card),p=s.useEditorStore(J=>J.frame),h=s.findCustomVisualConfigCard(p,x),{manifest:m}=s.useCustomVisual(((se=h==null?void 0:h.customCardPreferences)==null?void 0:se.url)||""),y=(Y=m==null?void 0:m.visuals)==null?void 0:Y.find(J=>{var le;return J.name===((le=h==null?void 0:h.customCardPreferences)==null?void 0:le.componentName)}),v=s.resolveMultiInputType(h,y)==="multiple",u=v&&!!((ae=h==null?void 0:h.customCardPreferences)!=null&&ae.url),b=s.getConfigSlotExpectedType(y==null?void 0:y.slots),w=s.useEditorStore(J=>J.actions.updateCardConfig),T=s.useEditorStore(J=>J.actions.updateFrame),{scopedFields:V,refetch:L}=s.useScopedFields(),{userContext:E}=s.useCurrentUserInfo(),j=v&&(h==null?void 0:h.id)===x.id&&b?b:x==null?void 0:x.type,k=j==="detailTable",I=t.length>0||a.length>0||i.length>0,f=!k&&(j!=="kpi"||a.length<=2),A=!k,g=!k&&j!=="kpi",D=j!=="kpi"&&I,M=k,P="Drop sort fields here",N=(q=x.dataSource)==null?void 0:q.semanticDomainId,{promoteMetric:O}=s.usePromoteCalculatedMetricToDomain({domainId:N}),S=(E==null?void 0:E.type)==="organization",R=J=>{const le=p.calculatedFields||[],X=le.findIndex(ee=>ee.name===J.name&&ee.role===J.role),oe=X>=0?{...J,id:le[X].id}:J,me=X>=0?le.map((ee,ce)=>ce===X?oe:ee):[...le,oe];T({calculatedFields:me});const Z=s.getNewField(oe,"metrics",a),xe=a.findIndex(ee=>ee.name===Z.name&&ee.role===Z.role),B=xe>=0?a.map((ee,ce)=>ce===xe?{...ee,...Z,id:ee.id}:ee):[...a,Z];w(x.id,{metricColumns:B})},F=async J=>{await O(J),L()},$=["pie","doughnut","polar","funnel","aggregateTable","bubble","scatter"].includes(j),U=g&&!$,z=()=>j==="kpi"?{label:"Trend By",placeholder:"Drop trend field here"}:{label:"Rows",placeholder:"Drop dimensions here"},H=()=>j==="kpi"?{label:"Metric",placeholder:"Drop metric here"}:{label:"Metrics",placeholder:"Drop metrics here"};return e.jsxs(e.Fragment,{children:[e.jsxs(s.Accordion,{type:"single",collapsible:!0,defaultValue:"fields",className:"w-full space-y-2.5",children:[e.jsxs(s.AccordionItem,{value:"fields",className:"rounded-xl border border-border/55 border-b-0 bg-card px-3 shadow-[0_1px_2px_rgba(15,23,42,0.04)]",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2.5 text-xs font-semibold tracking-wide text-foreground/70 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.List,{className:"h-4 w-4 text-foreground/60"}),e.jsx("span",{children:"FIELDS"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-3 pt-1.5",children:[f&&e.jsx(ps,{zone:"groupBy",fields:t,label:z().label,placeholder:z().placeholder,activeField:d}),U&&e.jsx(ps,{zone:"pivotBy",fields:n,label:"Pivot Columns",placeholder:"Drop pivot fields here",activeField:d}),A&&e.jsx(ps,{zone:"metrics",fields:a,label:H().label,placeholder:H().placeholder,hasPivotColumns:n.length>0,activeField:d}),M&&e.jsx(ps,{zone:"detailColumns",fields:i,label:"Columns",placeholder:"Drop columns here"}),a.length>=1&&S&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>c(!0),className:"mt-1.5 w-full justify-start border-border/60 border-dashed bg-background text-xs text-foreground/70 hover:bg-muted/40 hover:text-foreground",children:[e.jsx(s.Calculator,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),D&&e.jsx(ps,{zone:"sortBy",fields:r,label:"Sort By",placeholder:P,activeField:d})]})]}),(!l||u)&&e.jsxs(s.AccordionItem,{value:"configuration",className:"rounded-xl border border-border/55 border-b-0 bg-card px-3 shadow-[0_1px_2px_rgba(15,23,42,0.04)]",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2.5 text-xs font-semibold tracking-wide text-foreground/70 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Settings2,{className:"h-4 w-4 text-foreground/60"}),e.jsx("span",{children:"CHART SETTINGS"})]})}),e.jsx(s.AccordionContent,{className:"mb-2 rounded-md bg-muted/20 px-3 py-0.5",children:e.jsx(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:e.jsx(ka,{mode:"config"})})})]}),(l||u)&&e.jsxs(s.AccordionItem,{value:"plugin",className:"rounded-xl border border-border/55 border-b-0 bg-card px-3 shadow-[0_1px_2px_rgba(15,23,42,0.04)]",children:[e.jsx(s.AccordionTrigger,{className:"flex w-full items-center gap-2 py-2.5 text-xs font-semibold tracking-wide text-foreground/70 outline-none ring-0 hover:no-underline focus:outline-none focus-visible:outline-none focus-visible:ring-0 focus-visible:ring-offset-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xa,{className:"h-4 w-4 text-foreground/60"}),e.jsx("span",{children:"COMPONENT SETTINGS"})]})}),e.jsx(s.AccordionContent,{className:"mb-2 rounded-md bg-muted/20 px-3 py-0.5",children:e.jsx(wa,{})})]})]}),e.jsx(s.CalculatedFieldEditor,{open:o,onOpenChange:c,availableFields:V,initialFieldType:"metric",allowedFieldTypes:["metric"],onSave:J=>{J.role==="metric"&&w(x.id,{metricColumns:[...a,J]})},onSaveToDashboard:J=>{J.role==="metric"&&R(J)},onPromoteMetricToDomain:N&&S?F:void 0,domainId:N,cardId:x.id})]})}function to({onEditJoins:t}){const n=s.useEditorStore(c=>c.card),{autoJoinMetadata:a}=s.useDashboardCardQuery(n);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:r}=a,i=(r==null?void 0:r.joins)||[];if(i.length===0)return null;const d=c=>!c||c.length===0?"No conditions":c.map(l=>{var m,y,v,u;const x=`${(m=l.source)==null?void 0:m.entityName}.${(y=l.source)==null?void 0:y.name}`,p=`${(v=l.target)==null?void 0:v.entityName}.${(u=l.target)==null?void 0:u.name}`,h=l.operator||"=";return`${x} ${h} ${p}`}).join(" AND "),o=c=>!c.joinKeyGroups||c.joinKeyGroups.length===0?"No conditions defined":c.joinKeyGroups.length===1?d(c.joinKeyGroups[0].keys):c.joinKeyGroups.map((l,x)=>({id:x,operator:l.operator,condition:d(l.keys)}));return e.jsx(s.Card,{className:"border-blue-500/20 bg-blue-50/15 shadow-sm dark:bg-blue-950/10",children:e.jsxs("div",{className:"flex items-center justify-between p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sn,{className:"size-4 text-blue-600/90 dark:text-blue-400"}),e.jsx("h3",{className:"text-xs font-semibold tracking-wide text-blue-900/90 dark:text-blue-100",children:"Resolved Joins"}),e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"secondary",className:"cursor-help bg-blue-100/80 text-xs text-blue-700 dark:bg-blue-900/70 dark:text-blue-300",children:i.length})}),e.jsx(s.TooltipContent,{side:"bottom",align:"start",className:"max-w-md p-3",children:e.jsx("div",{className:"space-y-2",children:i.map((c,l)=>{const x=o(c),p=Array.isArray(x);return e.jsxs("div",{className:"rounded-md border border-border bg-background p-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"font-medium text-foreground",children:c.source.name}),e.jsx(s.ArrowRight,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:c.target.name})]}),e.jsx(s.Badge,{variant:"outline",className:"border-green-500/40 bg-green-50/30 text-xs text-green-700 dark:bg-green-950/30 dark:text-green-300",children:c.joinType})]}),e.jsx("div",{className:"mt-1 space-y-1",children:p?x.map(h=>e.jsxs("div",{className:"rounded bg-muted/30 px-2 py-1",children:[e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:h.condition}),h.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",h.operator,")"]})]},h.id)):e.jsx("div",{className:"rounded bg-muted/30 px-2 py-1",children:e.jsx("code",{className:"block break-all text-xs text-muted-foreground",children:x})})})]},c.id||l)})})})]})})]}),t&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:t,className:"h-7 gap-1 p-2 text-xs text-blue-700/80 hover:text-blue-900 dark:text-blue-300 dark:hover:text-blue-100",children:e.jsx(s.SquarePen,{className:"size-3.5"})})]})})}const ua={getItem(t){if(typeof window>"u")return null;try{return localStorage.getItem(t)}catch(n){return console.warn(`Failed to read from localStorage (${t}):`,n),null}},setItem(t,n){if(!(typeof window>"u"))try{localStorage.setItem(t,n)}catch(a){console.warn(`Failed to write to localStorage (${t}):`,a)}}};function ao({selectedChart:t,onChartChange:n,groupByFields:a,pivotByFields:r,metricsFields:i,sortByFields:d,detailFields:o,activeField:c}){var f,A;const[l,x]=C.useState(()=>ua.getItem("chart-selector-expanded")==="true"),[p,h]=C.useState(!1),m=s.useEditorStore(g=>g.card),y=s.useEditorStore(g=>g.actions.updateCardConfig),v=a.length>0||r.length>0||i.length>0||o.length>0,{data:u,autoJoinMetadata:b}=s.useDashboardCardQuery(m),w=v||!!u,T=((f=m==null?void 0:m.config)==null?void 0:f.joinPlan)||(b!=null&&b.autoResolved?b.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),V=((A=m==null?void 0:m.dataSource)==null?void 0:A.selectedEntities)||[],L=g=>{y(m.id,{...m==null?void 0:m.config,joinPlan:g}),h(!1)},E=()=>{y(m.id,{...m==null?void 0:m.config,joinPlan:void 0}),h(!1)},j=()=>{h(!1)},k=()=>{h(!0)};C.useEffect(()=>{ua.setItem("chart-selector-expanded",String(l))},[l]);const I=()=>{x(g=>!g)};return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col bg-background",children:[e.jsx("div",{className:"pl-2 pr-4 pt-4",children:e.jsxs("div",{className:"rounded-xl border border-border/60 bg-card p-3 shadow-[0_1px_2px_rgba(15,23,42,0.05)]",children:[e.jsx("div",{className:s.cn("overflow-hidden transition-all duration-300 ease-in-out",l?"max-h-[210px] opacity-100":"max-h-0 opacity-0"),children:l&&e.jsx(Ys,{selectedChart:t,onChartChange:n,variant:"outline"})}),e.jsx("div",{"data-content":"Chart Quick Selector",className:s.cn("flex items-center justify-center",{"mt-3":l,"mt-2":!l}),children:e.jsx(s.ChartQuickSelector,{selectedChart:t,onChartChange:n,isDropdownExpanded:l,onToggleDropdown:I})})]})}),w&&e.jsx("div",{className:"pl-2 pr-4 py-3",children:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(Ie.EditorClearButton,{label:"Reset",variant:"secondary",className:"h-7 px-2 text-xs"})})}),e.jsx(s.ScrollArea,{className:"min-h-0 w-full flex-1 basis-0",children:e.jsxs("div",{className:s.cn("space-y-3 pl-2 pr-4 pb-6",w?"pt-1":"pt-4"),children:[e.jsx(to,{onEditJoins:k}),e.jsx(so,{groupByFields:a,pivotByFields:r,metricsFields:i,sortByFields:d,detailFields:o,activeField:c})]})}),e.jsx(ga,{open:p,onOpenChange:h,joinPlan:T,availableDataSources:V,onSave:L,onCancel:j,onRemove:E,children:e.jsx("div",{})})]})}function no({initialFilters:t,availableFields:n}={}){const[a,r]=C.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(E=>E.card.dataSource);const{columns:i,isLoading:d}=s.useColumns(),c=n||i||[],l={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},x=E=>{const j=k=>{if(k.id===E){const I=c[0]||l,f=s.getDataType(I.dataType)==="date";return{...k,conditions:[...k.conditions,{id:`condition-${Date.now()}`,field:I,operator:f?"between":"=",value:f?[]:""}]}}return{...k,groups:k.groups.map(j)}};r(j(a))},p=E=>{const j=k=>{if(k.id===E){const I=c[0]||l,f=s.getDataType(I.dataType)==="date";return{...k,groups:[...k.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:I,operator:f?"between":"=",value:f?[]:""}],groups:[]}]}}return{...k,groups:k.groups.map(j)}};r(j(a))},h=(E,j)=>{const k=I=>I.id===E?{...I,conditions:I.conditions.filter(f=>f.id!==j)}:{...I,groups:I.groups.map(k)};r(k(a))},m=(E,j)=>{const k=I=>I.id===E?{...I,groups:I.groups.filter(f=>f.id!==j)}:{...I,groups:I.groups.map(k)};r(k(a))},y=(E,j,k,I)=>{if(k==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const f=A=>A.id===E?{...A,conditions:A.conditions.map(g=>g.id===j?{...g,[k]:I}:g)}:{...A,groups:A.groups.map(f)};r(f(a))},v=(E,j,k)=>{const I=f=>f.id===E?{...f,conditions:f.conditions.map(A=>A.id===j?{...A,...k}:A)}:{...f,groups:f.groups.map(I)};r(I(a))},u=(E,j)=>{const k=I=>I.id===E?{...I,logicalOperator:j}:{...I,groups:I.groups.map(k)};r(k(a))},b=(E,j)=>{const k=I=>I.id===E?{...I,negate:j}:{...I,groups:I.groups.map(k)};r(k(a))},w=(E,j,k)=>{const I=f=>f.id===E?{...f,conditions:s.arrayMove(f.conditions,j,k)}:{...f,groups:f.groups.map(I)};r(I(a))},T=(E,j,k)=>{const I=f=>f.id===E?{...f,groups:s.arrayMove(f.groups,j,k)}:{...f,groups:f.groups.map(I)};r(I(a))},V=E=>{if(!E||E.conditions.length===0&&E.groups.length===0)return"-- No filters defined";const j=I=>{let f="";typeof I.field=="object"?f=I.field.entityName?`${I.field.entityName}.${I.field.name}`:I.field.name:f=String(I.field);const A=I.operator;let g=I.value;if(I.field.dataType==="string"&&!["in","not in"].includes(I.operator))typeof g=="string"?g=`'${g}'`:Array.isArray(g)&&(g=`'${g.join(", ")}'`);else if(I.field.dataType==="date"||I.field.dataType==="datetime"||I.field.dataType==="timestamp")if(I.operator==="between"&&Array.isArray(g)&&g.length===2){const D=g[0]?`'${g[0]}'`:"NULL",M=g[1]?`'${g[1]}'`:"NULL";return`${f} BETWEEN ${D} AND ${M}`}else if((I.operator==="in"||I.operator==="not in")&&Array.isArray(g)){const D=g.map(M=>M?`'${M}'`:"NULL").join(", ");return`${f} ${A} (${D})`}else typeof g=="string"||g instanceof Date?g=`'${g}'`:Array.isArray(g)&&g.length>0&&(g=`'${g[0]}'`);else if(["in","not in"].includes(I.operator)){let D=[];Array.isArray(g)?D=g.map(M=>typeof M=="string"?`'${M}'`:String(M)):typeof g=="string"?D=g.split(",").map(M=>{const P=M.trim();return I.field.dataType==="string"?`'${P}'`:P}):typeof g=="number"&&(D=[String(g)]),g=`(${D.join(", ")})`}switch(A){case"contains":return typeof g=="string"?`${f} LIKE '%${g.replace(/'/g,"")}'`:`${f} LIKE '%${String(g)}'`;case"startsWith":return typeof g=="string"?`${f} LIKE '${g.replace(/'/g,"")}%'`:`${f} LIKE '${String(g)}%'`;case"endsWith":return typeof g=="string"?`${f} LIKE '%${g.replace(/'/g,"")}'`:`${f} LIKE '%${String(g)}'`;case"isNull":return`${f} IS NULL`;case"isNotNull":return`${f} IS NOT NULL`;default:return`${f} ${A} ${g}`}},k=I=>{const f=I.conditions.map(j),A=I.groups.map(P=>k(P)),g=[...f,...A].filter(Boolean);if(g.length===0)return"";const D=g.join(` ${I.logicalOperator} `),M=g.length>1?`(${D})`:D;return I.negate?`NOT ${M}`:M};return k(E)},L=a.conditions.length>0||a.groups.length>0;return{currentFilters:a,setCurrentFilters:r,availableFields:c,isLoading:d,addCondition:x,addGroup:p,removeCondition:h,removeGroup:m,updateCondition:y,updateConditionFields:v,updateGroupOperator:u,updateGroupNegate:b,reorderConditions:w,reorderGroups:T,generateSQLPreview:V,hasAnyFilters:L}}function ro({children:t,className:n,delayDuration:a}){return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:a,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:s.cn("w-[200px] overflow-hidden text-ellipsis whitespace-nowrap text-sm",n),children:t})}),e.jsx(s.PortalTooltipContent,{children:t})]})})}const lo=t=>{if(t.qualifiedEntityName){const n=t.qualifiedEntityName.split(".");return n.length>1?n[0]:"default"}return"default"};function oo({value:t,onValueChange:n,availableFields:a,placeholder:r="Select field",className:i="w-64"}){const[d,o]=C.useState(!1),c=C.useMemo(()=>{const l={};return a.forEach(x=>{const p=lo(x);l[p]||(l[p]={}),l[p][x.entityId]||(l[p][x.entityId]=[]),l[p][x.entityId].push(x)}),l},[a]);return e.jsxs(s.Popover,{modal:!0,open:d,onOpenChange:o,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":d,className:s.cn("justify-between",!t&&"text-muted-foreground",i),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(ro,{children:[t.entityName,".",t.name]})}):r,e.jsx(s.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(s.CommandEmpty,{children:"No fields found."}),e.jsx(s.CommandList,{className:"max-h-80",children:Object.entries(c).map(([l,x])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),l]}),children:Object.entries(x).map(([p,h])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 bg-gray-50/50 px-2 py-1 text-xs font-medium text-gray-600",children:[s.getEntityIcon(h[0].entityType,{size:"h-3 w-3"}),e.jsx("span",{children:h[0].entityName})]}),h.map((m,y)=>e.jsxs(s.CommandItem,{value:m.id,onSelect:()=>{n(m),o(!1)},className:"overflow-x-auto",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===m.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"",children:m.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:m.description&&e.jsx("span",{children:m.description})})]})]},m.id+y))]},`${l}-${p}`))},l))})]})})]})}function st(t){var u;const n=s.useEditorStore(b=>b.card),{authToken:a,tokenProps:r}=s.useSemaphorContext(),i=s.useEditorStore(b=>b.card.config),d=i==null?void 0:i.joinPlan,o={...t,alias:t.name,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},l={...o,role:"sortby",direction:"asc"},x={joinPlan:d,groupByColumns:[o],metricColumns:[c],sortByColumns:[l]},p=((u=n.dataSource)==null?void 0:u.connectionId)||n.connectionId,{data:h,isPending:m,error:y}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular(`${r.apiServiceUrl}/v1/query`,(a==null?void 0:a.accessToken)||"",{connection_id:p,cardConfig:x,cardDataSource:n.dataSource})}catch(b){console.log(t),console.error("error",b)}},enabled:!!p,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((h==null?void 0:h.records)||[]).map(b=>({label:b.value||"BLANK",value:b.value||"BLANK",count:(b==null?void 0:b.count)||0})),isPending:m,error:y}}function io({field:t,selected:n,onChange:a,placeholder:r="Select items...",className:i}){const[d,o]=Ks.useState(!1),{filterValues:c}=st(t),l=p=>{a(n.filter(h=>h!==p))},x=p=>{n.includes(p)?a(n.filter(h=>h!==p)):a([...n,p])};return e.jsx("div",{className:s.cn("w-full",i),children:e.jsxs(s.Popover,{open:d,onOpenChange:o,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":d,className:"h-auto min-h-10 w-full justify-between p-2",children:[e.jsx("div",{className:"flex flex-1 flex-wrap gap-1",children:n.length>0?n.map(p=>{const h=c.find(m=>m.value===p);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:m=>{m.key==="Enter"&&l(p)},onMouseDown:m=>{m.preventDefault(),m.stopPropagation()},onClick:m=>{m.stopPropagation(),l(p)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},p)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:c.map((p,h)=>e.jsxs(s.CommandItem,{onSelect:()=>x(p.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",n.includes(p.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:p.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:p.count})]})]},p.value+h))})]})]})})]})})}function co({field:t,value:n,onChange:a,placeholder:r="Select value...",className:i}){const{filterValues:d,isPending:o,error:c}=st(t);return o?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):c?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:n,onValueChange:a,children:[e.jsx(s.SelectTrigger,{className:i||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:n})}),e.jsx(s.SelectContent,{children:d.map((l,x)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:l.value,children:l.label},l.value+x))})]})}function uo({value:t,operator:n,onChange:a,className:r}){var y,v,u;const{tokenProps:i}=s.useSemaphorContext(),d=((v=(y=i==null?void 0:i.params)==null?void 0:y.calendarContext)==null?void 0:v.tz)||((u=i==null?void 0:i.params)==null?void 0:u.timezone),o=d||Intl.DateTimeFormat().resolvedOptions().timeZone,c=n==="between"||n==="not between",l=C.useMemo(()=>{if(!(!t||!c)&&Array.isArray(t)&&t.length===2){const b=t[0]?new Date(t[0]):void 0,w=t[1]?new Date(t[1]):void 0;if(b&&w)return{from:b,to:w}}},[t,c]),x=C.useMemo(()=>{if(!t||c)return;const b=Array.isArray(t)?t[0]:t;if(!b)return;const w=new Date(b);if(!isNaN(w.getTime()))return w},[t,c]),p=b=>n==="<="||n===">"?s.endOfDayInTimezone(b,o):s.startOfDayInTimezone(b,o),h=b=>{if(!b){a([]);return}if(b.from&&b.to){a([b.from.toISOString(),b.to.toISOString()]);return}a([])},m=b=>{if(!b){a("");return}const w=p(b);a(w.toISOString())};return e.jsx(s.DateRangePicker,{value:c?l:void 0,selectionMode:c?"range":"single",singleValue:c?void 0:x,onChange:h,onSingleChange:m,timezone:d,showRelativeTab:c,className:r,placeholder:"Select date..."})}const mo=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],xo=["=","!=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],ho=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],po=["=","!=","isNull","isNotNull"],fo=["between","=","!=","<","<=",">",">=","isNull","isNotNull"],go={"=":"Equals","!=":"Not Equals",">":"Greater Than",">=":"Greater Than or Equal","<":"Less Than","<=":"Less Than or Equal",contains:"Contains",startsWith:"Starts With",endsWith:"Ends With",in:"In","not in":"Not In",between:"Between",isNull:"Is Null",isNotNull:"Is Not Null","not between":"Not Between"};function ma(t){return go[t]||s.titleCase(t)}function jo(t){switch(t){case"string":return xo;case"number":return ho;case"boolean":return po;case"date":return fo;default:return mo}}function La({condition:t,index:n,groupId:a,groupLogicalOperator:r,onUpdateCondition:i,onRemoveCondition:d,onUpdateGroupOperator:o,availableFields:c,updateConditionFields:l}){const{attributes:x,listeners:p,setNodeRef:h,transform:m,transition:y,isDragging:v}=s.useSortable({id:t.id}),{isPending:u,error:b}=st(t.field),w={transform:s.CSS.Transform.toString(m),transition:y};return e.jsxs("div",{ref:h,style:w,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${v?"z-50 opacity-50":""}`,children:[e.jsx("div",{...x,...p,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),n>0&&e.jsxs(s.Select,{value:r,onValueChange:T=>o(a,T),children:[e.jsx(s.SelectTrigger,{className:"w-24",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),n===0&&e.jsx("div",{className:"w-24"}),e.jsx(oo,{value:t.field,onValueChange:T=>{const V=T,L=s.getDataType(V.dataType)==="date";l(a,t.id,{field:V,value:"",operator:L?"between":"="})},availableFields:c,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:T=>{T==="in"||T==="not in"?l(a,t.id,{operator:T,value:[]}):T==="isNull"||T==="isNotNull"?l(a,t.id,{operator:T,value:null}):T==="between"||T==="not between"?l(a,t.id,{operator:T,value:[]}):l(a,t.id,{operator:T,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-32",children:e.jsx(s.SelectValue,{children:t.operator?ma(t.operator):""})}),e.jsx(s.SelectContent,{children:jo(s.getDataType(t.field.dataType)).map(T=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:T,children:ma(T)},T))})]}),t.operator==="isNull"||t.operator==="isNotNull"?e.jsx("div",{className:"flex-1"}):s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?u?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(s.LoaderCircle,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):b?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(io,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(T=>typeof T=="string")?t.value:[],onChange:T=>l(a,t.id,{value:T}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:T=>l(a,t.id,{value:T.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(co,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:T=>l(a,t.id,{value:T}),placeholder:"Select value...",className:"flex-1"}):s.getDataType(t.field.dataType)==="boolean"?e.jsxs(s.Select,{value:typeof t.value=="boolean"?String(t.value):"",onValueChange:T=>l(a,t.id,{value:T==="true"}),children:[e.jsx(s.SelectTrigger,{className:"flex-1",children:e.jsx(s.SelectValue,{placeholder:"Select value..."})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"true",children:"True"}),e.jsx(s.SelectItem,{value:"false",children:"False"})]})]}):s.getDataType(t.field.dataType)==="date"?e.jsx(uo,{value:t.value,operator:t.operator,onChange:T=>l(a,t.id,{value:T}),className:"flex-1"}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:T=>i(a,t.id,"value",T.target.value),className:"flex-1",placeholder:t.operator==="in"||t.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>d(a,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function bo({group:t,depth:n,parentGroupId:a,onUpdateGroupOperator:r,onUpdateGroupNegate:i,onRemoveGroup:d,onUpdateCondition:o,onUpdateField:c,onRemoveCondition:l,onReorderConditions:x,onReorderGroups:p,onAddCondition:h,onAddGroup:m,availableFields:y,renderFilterGroup:v,updateConditionFields:u}){const{attributes:b,listeners:w,setNodeRef:T,transform:V,transition:L,isDragging:E}=s.useSortable({id:t.id}),j={transform:s.CSS.Transform.toString(V),transition:L},k=f=>{const{active:A,over:g}=f;if(g&&A.id!==g.id){const D=t.conditions.findIndex(P=>P.id===A.id),M=t.conditions.findIndex(P=>P.id===g.id);D!==-1&&M!==-1&&x(t.id,D,M)}},I=f=>{const{active:A,over:g}=f;if(g&&A.id!==g.id&&a){const D=t.groups.findIndex(P=>P.id===A.id),M=t.groups.findIndex(P=>P.id===g.id);D!==-1&&M!==-1&&p(a,D,M)}};return e.jsxs("div",{ref:T,style:j,className:`rounded-lg ${n>0?"mt-2 border border-border":""} ${E?"z-50 opacity-50":""}`,children:[n>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...b,...w,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(s.Button,{variant:t.negate?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>i(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:f=>r(t.id,f),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-20",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>a&&d(a,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${n>0?"":"px-0"}`,children:[e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:k,children:e.jsx(s.SortableContext,{items:t.conditions.map(f=>f.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((f,A)=>e.jsx(La,{condition:f,index:A,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:o,onUpdateField:c,onRemoveCondition:l,onUpdateGroupOperator:r,availableFields:y,updateConditionFields:u},f.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:I,children:e.jsx(s.SortableContext,{items:t.groups.map(f=>f.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(f=>v(f,n+1,t.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function vo({filters:t,availableFields:n,onSave:a,onClearAll:r,onCancel:i}){const{currentFilters:d,availableFields:o,isLoading:c,addCondition:l,addGroup:x,removeCondition:p,removeGroup:h,updateCondition:m,updateConditionFields:y,updateGroupOperator:v,updateGroupNegate:u,reorderConditions:b,reorderGroups:w,generateSQLPreview:T,hasAnyFilters:V,setCurrentFilters:L}=no({initialFilters:t,availableFields:n}),E=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[j,k]=C.useState(!1),I=(g,D,M)=>{const P=N=>N.id===g?{...N,conditions:N.conditions.map(O=>O.id===D?{...O,field:M,dataType:M.dataType}:O)}:{...N,groups:N.groups.map(P)};L(P(d))},f=(g,D=0,M)=>D===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:E,collisionDetection:s.closestCenter,onDragEnd:P=>{const{active:N,over:O}=P;if(O&&N.id!==O.id){const S=g.conditions.findIndex(F=>F.id===N.id),R=g.conditions.findIndex(F=>F.id===O.id);S!==-1&&R!==-1&&b(g.id,S,R)}},children:e.jsx(s.SortableContext,{items:g.conditions.map(P=>P.id),strategy:s.verticalListSortingStrategy,children:g.conditions.map((P,N)=>e.jsx(La,{condition:P,index:N,groupId:g.id,groupLogicalOperator:g.logicalOperator,onUpdateCondition:m,onUpdateField:I,onRemoveCondition:p,onUpdateGroupOperator:v,availableFields:o,updateConditionFields:y},P.id))})}),e.jsx(s.DndContext,{sensors:E,collisionDetection:s.closestCenter,onDragEnd:P=>{const{active:N,over:O}=P;if(O&&N.id!==O.id){const S=g.groups.findIndex(F=>F.id===N.id),R=g.groups.findIndex(F=>F.id===O.id);S!==-1&&R!==-1&&w(g.id,S,R)}},children:e.jsx(s.SortableContext,{items:g.groups.map(P=>P.id),strategy:s.verticalListSortingStrategy,children:g.groups.map(P=>f(P,D+1,g.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>l(g.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),j&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>x(g.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},g.id):e.jsx(bo,{group:g,depth:D,parentGroupId:M,onUpdateGroupOperator:v,onUpdateGroupNegate:u,onRemoveGroup:h,onUpdateCondition:m,onUpdateField:I,onRemoveCondition:p,onReorderConditions:b,onReorderGroups:w,onAddCondition:l,onAddGroup:x,availableFields:o,renderFilterGroup:f,updateConditionFields:y},g.id),A=s.getFilterCount(t);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Card,{children:e.jsx(s.CardContent,{className:"p-4",children:e.jsxs("div",{className:"space-y-4",children:[c?e.jsxs("div",{className:"flex items-center justify-center p-4",children:[e.jsx("div",{className:"h-5 w-5 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600"}),e.jsx("span",{className:"ml-2 text-sm text-gray-600",children:"Loading columns..."})]}):f(d),e.jsx("div",{className:"mt-4 border-t border-border pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.SmallSwitch,{id:"advanced-mode",checked:j,onCheckedChange:g=>k(g)}),e.jsx(s.Label,{htmlFor:"advanced-mode",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Advanced mode (enable grouping)"})]})}),V&&e.jsxs("div",{className:"mt-4 border-t border-border pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:T(d)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:i,children:"Cancel"}),A>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>a(V?d:null),children:"Apply Filters"})]})]})}function yo({cardId:t,filters:n,onFiltersChange:a,onClearFilters:r,availableFields:i,isOpen:d,onOpenChange:o}){const c=x=>{a(t,x),o(!1)},l=()=>{r(t),o(!1)};return e.jsxs(s.Dialog,{modal:!1,open:d,onOpenChange:o,children:[d&&e.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-background/80 backdrop-blur-sm"}),e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-4xl overflow-y-auto",onInteractOutside:x=>{x.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Card Filters"}),e.jsx(s.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(vo,{filters:n,availableFields:i,onSave:c,onCancel:()=>o(!1),onClearAll:l})]})]})}function No({activeCardId:t,sourceFields:n,getFieldsForContainer:a,setFieldsForContainer:r}){var w,T;const[i,d]=C.useState(null),o=s.useEditorStore(V=>V.card),c=s.useEditorStore(V=>V.actions.updateCardConfig),l=(w=o==null?void 0:o.config)==null?void 0:w.joinPlan,x=C.useCallback(V=>V.entityName===s.CALCULATED_FIELD_ENTITY_MARKER||V.entityName==="calculated_fields"||V.qualifiedEntityName==="calculated_fields",[]),p=(T=o==null?void 0:o.dataSource)==null?void 0:T.semanticDomainId,{data:h}=s.useJoinabilityMap(p),m=[...n,...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy"),...a("detailColumns")],y=C.useCallback(V=>V.startsWith("card-source-")?"source":V.startsWith("card-")?null:V.startsWith("source-")||n.find(L=>L.id===V)?"source":a("groupBy").find(L=>L.id===V)?"groupBy":a("metrics").find(L=>L.id===V)?"metrics":a("pivotBy").find(L=>L.id===V)?"pivotBy":a("sortBy").find(L=>L.id===V)?"sortBy":a("detailColumns").find(L=>L.id===V)?"detailColumns":null,[n,a]),v=C.useCallback(V=>{d(V.active.id)},[]),u=C.useCallback(V=>{var A;const{active:L,over:E}=V;if(!E||!t){d(null);return}const j=L.id,k=E.id,I=y(j),f=y(k)||k;if(f==="sortBy"){if(I==="source"){const g=n.find(M=>M.id===j);if(!g){d(null);return}if(!(a("groupBy").some(M=>M.name===g.name&&M.qualifiedEntityName===g.qualifiedEntityName)||a("metrics").some(M=>M.name===g.name&&M.qualifiedEntityName===g.qualifiedEntityName)||a("detailColumns").some(M=>M.name===g.name&&M.qualifiedEntityName===g.qualifiedEntityName))){d(null);return}}else if(I==="pivotBy"){d(null);return}else if(I!=="groupBy"&&I!=="metrics"&&I!=="sortBy"&&I!=="detailColumns"){d(null);return}}if(I==="source"&&f==="sortBy"){const g=[...n].find(N=>N.id===j);if(!g){d(null);return}const D=a("sortBy");if(s.fieldAlreadyExists(g,D)){d(null);return}const M=s.validateFieldForChartType(g,"sortBy",o.type);if(!M.isValid){s.ue.error("Invalid Field Type",{description:M.reason,position:"top-center",duration:3e3}),d(null);return}const P=s.getNewField(g,"sortBy",D);d(null),r("sortBy",[...D,P]);return}if(I==="source"&&f!=="source"&&f!=="sortBy"){const g=[...n].find(R=>R.id===j);if(!g){d(null);return}const D=[...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy"),...a("detailColumns")],M=D.filter(R=>!x(R));if(M.length>0){const R=M[0].qualifiedEntityName;if(!R){d(null);return}if(R!==g.qualifiedEntityName&&!x(g)&&g.qualifiedEntityName)if(p&&(h!=null&&h.joinabilityMap)){if(s.calculateFieldState(g,{joinabilityMap:h.joinabilityMap,selectedFields:D,baseEntityName:(A=l==null?void 0:l.baseEntity)==null?void 0:A.name}).state==="unreachable"){s.showJoinRequiredNotification(),d(null);return}}else{if(!l){s.showJoinRequiredNotification(),d(null);return}if(!s.areEntitiesJoined(R,g.qualifiedEntityName,l)){s.showJoinRequiredNotification(),d(null);return}}}const P=a(f);if(s.fieldAlreadyExists(g,P)){d(null);return}const N=s.validateFieldForChartType(g,f,o.type);if(!N.isValid){s.ue.error("Invalid Field Type",{description:N.reason,position:"top-center",duration:3e3}),d(null);return}const O=s.getNewField(g,f,P),S=[...P,O];d(null),r(f,S),f==="metrics"&&t&&s.cleanupKpiMetricComparisonMode(o.type,o.config,c,t,S);return}if(I&&f&&I!=="source"&&f!=="source"&&I!==f){const g=a(I),D=a(f),M=g.find(R=>R.id===j);if(!M){d(null);return}const P=s.validateFieldForChartType(M,f,o.type);if(!P.isValid){s.ue.error("Invalid Field Type",{description:P.reason,position:"top-center",duration:3e3}),d(null);return}const N=s.getNewField(M,f,D);if(d(null),f==="sortBy"){s.fieldAlreadyExists(M,D)||r(f,[...D,N]);return}const O=g.filter(R=>R.id!==j),S=[...D,N];r(I,O),r(f,S),f==="metrics"&&t&&s.cleanupKpiMetricComparisonMode(o.type,o.config,c,t,S);return}if(I&&f&&I===f&&I!=="source"){const g=a(I),D=g.findIndex(P=>P.id===j),M=g.findIndex(P=>P.id===k);if(D!==M){const P=s.arrayMove(g,D,M);r(I,P)}}d(null)},[t,n,a,r,y,l,p,h,x,o.type,c,o.config]),b=i?m.find(V=>V.id===i):null;return{activeId:i,activeField:b,handleDragStart:v,handleDragEnd:u}}function Co({activeView:t,onViewChange:n,splitViewEnabled:a}){const r=s.useEditorStore(c=>c.card),{config:i}=C.useContext(s.SemaphorContext).tokenProps,d=(i==null?void 0:i.showInfoTab)!==!1,o=()=>a?!1:!["table","pivotTable","aggregateTable","detailTable"].includes(r.type);return e.jsx(s.Tabs,{value:t,onValueChange:c=>n(c),children:e.jsxs(s.TabsList,{className:"h-9 w-fit gap-1 bg-background p-0",children:[e.jsx(s.TabsTrigger,{value:"chart",className:"rounded-md transition data-[state=active]:bg-muted",children:"Chart"}),o()&&e.jsx(s.TabsTrigger,{value:"table",className:"rounded-md transition data-[state=active]:bg-muted",children:"Results"}),r.type!=="kpi"&&d&&e.jsx(s.TabsTrigger,{value:"info",className:"rounded-md transition data-[state=active]:bg-muted",children:"Info"})]})})}const So=[{value:"10",label:"Top 10"},{value:"20",label:"Top 20"},{value:"50",label:"Top 50"},{value:"100",label:"Top 100"},{value:"200",label:"Top 200"},{value:"500",label:"Top 500"},{value:"1000",label:"Top 1000"}];function wo(){var l,x;const t=s.useEditorStore(p=>p.card),{updateRowLimit:n}=s.useEditorActions(),[a,r]=C.useState(!1),[i,d]=C.useState(""),o=p=>{if(p==="custom"){r(!0);return}r(!1),n(t.id,parseInt(p))},c=p=>{const h=p.target.value;d(h),h&&!isNaN(parseInt(h))&&n(t.id,parseInt(h))};return e.jsx("div",{className:"flex items-center gap-2",children:a?e.jsx(s.Input,{type:"number",value:i,onChange:c,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((x=(l=t.config)==null?void 0:l.rowLimit)==null?void 0:x.toString())||"100",onValueChange:o,children:[e.jsx(s.SelectTrigger,{className:"h-8 w-24 border-none px-1 [&>svg]:hidden",children:e.jsx(s.SelectValue,{placeholder:"Select limit"})}),e.jsx(s.SelectContent,{children:So.map(p=>e.jsx(s.SelectItem,{value:p.value,children:p.label},p.value))})]})})}function To({card:t,queryData:n,isLoading:a,isFetching:r,pagination:i,onPaginationChange:d,onSortChange:o,sortState:c,splitViewEnabled:l}){const x=C.useMemo(()=>(n==null?void 0:n.records)||[],[n==null?void 0:n.records]);return!l||["table","pivotTable","aggregateTable","detailTable"].includes(t.type)?e.jsx(Hs,{}):e.jsxs(s.ResizablePanelGroup,{direction:"vertical",className:"h-full min-h-0 w-full",children:[e.jsx(s.ResizablePanel,{defaultSize:60,minSize:30,role:"chart-section",className:"flex flex-col pb-3",children:e.jsx(Hs,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 py-4 pl-2 pr-4",children:[(a||r)&&(n==null?void 0:n.records)&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),(n==null?void 0:n.records)&&e.jsx(s.TableVisual,{card:t,data:x,paginationMetadata:i,onPaginationChange:d,isLoading:a||r,onSortChange:o,sortState:c})]})})]})}const Eo="semaphor-split-view-enabled";function Io(){return ja(Eo,!0)}function ko({activeView:t,onViewChange:n,onFiltersClick:a,activeCard:r,columns:i}){var q,J,le;const d=s.useEditorStore(X=>X.card),o=s.useDashboardStore(X=>X.filterValues),c=s.useDashboardStore(X=>X.selectedSheetId),l=s.useDashboardStore(X=>X.inlineFilterValuesMap[(r==null?void 0:r.id)||""]),{updateCardConfig:x,setCard:p,updateCardInFrame:h,setShowAIDialog:m}=s.useEditorActions(),y=s.useEditorStore(X=>X.showAIDialog),v=s.useEditorStore(X=>X.isDevMode),u=s.useDashboardStore(X=>X.isVisualEditing),[b,w]=C.useState(!1),[T,V]=C.useState(!1),[L,E]=C.useState(null),{config:j}=C.useContext(s.SemaphorContext).tokenProps,k=(j==null?void 0:j.showInfoTab)!==!1,I=(j==null?void 0:j.showQueryDebugTools)!==!1,[f,A]=Io();s.useEditorStore(X=>{var oe;return!!((oe=X.card.customCardPreferences)!=null&&oe.url)});const{data:g,errorMessage:D,isLoading:M,isFetching:P,errorSql:N,pagination:O,refetch:S,comparisonMetadata:R,queryRequestPayload:F}=s.useDashboardCardQuery(r),$=C.useMemo(()=>(g==null?void 0:g.records)||[],[g==null?void 0:g.records]),[U,z]=C.useState(!1);C.useEffect(()=>{P||z(!1)},[P]);const H=()=>{const X=!f;X&&t==="table"&&n("chart"),A(X)},se=(X,oe)=>{const me={...r,paginationConfig:{page:X+1,pageSize:oe}};p(me),h(me)},Y=X=>{if(!d.config)return;const oe=s.sortStateToSortByColumns(X,d.config.metricColumns,d.config.groupByColumns,d.config.detailColumns);x(d.id,{...d.config,sortByColumns:oe})},ae=C.useMemo(()=>{var X;return s.sortByColumnsToSortState((X=d.config)==null?void 0:X.sortByColumns)},[(q=d.config)==null?void 0:q.sortByColumns]);return e.jsx("div",{className:s.cn("relative flex w-0 grow flex-col",{"border-l":y&&u}),children:e.jsxs("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col pt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 pl-2 pr-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t==="chart"&&y&&e.jsx("div",{className:"w-[200px]",children:e.jsx(Ys,{variant:v?"secondary":"ghost"})}),e.jsx(Co,{activeView:t,onViewChange:n,splitViewEnabled:f}),e.jsx(s.FilterInfo,{cardId:r.id,cardFilters:(J=r.config)==null?void 0:J.filters,cardFilterCount:s.getFilterCount(((le=r.config)==null?void 0:le.filters)||null),onFiltersClick:a,inlineFilters:r.inlineFilters,inlineFilterValues:l,sheetId:c||""}),R&&d.type!=="table"&&e.jsx(s.ComparisonMetadataBadge,{metadata:R,variant:"compact"}),e.jsx("div",{className:"ml-2",children:e.jsx(wo,{})}),y&&e.jsx(Ie.EditorClearButton,{})]}),e.jsxs("div",{className:s.cn("flex grow items-center justify-end gap-2"),children:[e.jsx(s.IconButton,{tooltip:"Refresh",disabled:M||P,onClick:()=>{z(!0),S()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":U})})}),t==="chart"&&e.jsx(Sa,{showInlineFilters:!1,showDisplayOptions:!1}),!y&&e.jsx(s.IconButton,{onClick:()=>m(!y),tooltip:"AI",className:"h-8","aria-label":"AI",children:e.jsx(s.Sparkles,{className:"size-4"})}),t==="chart"&&e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-8","aria-label":"More options",children:e.jsx(s.EllipsisVertical,{className:"size-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-64",children:[e.jsx(s.DropdownMenuLabel,{children:"More Options"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:H,children:[f?e.jsx(cn,{className:"mr-2 h-4 w-4"}):e.jsx(Nn,{className:"mr-2 h-4 w-4"}),f?"Hide Results Table":"Show Results Table"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs("div",{className:"px-1 py-1",children:[e.jsx(Xs,{triggerVariant:"menu",className:"w-full"}),e.jsx(Ws,{triggerVariant:"menu",className:"w-full"})]})]})]})]})]}),e.jsxs("div",{className:"mt-2 flex min-h-0 grow flex-col",children:[t==="chart"&&e.jsx("div",{className:s.cn("flex grow flex-col pb-4",{"pb-0":f&&!["table","pivotTable","aggregateTable","detailTable"].includes(r.type)}),children:e.jsx(To,{card:r,queryData:g,isLoading:M,isFetching:P,pagination:O,onPaginationChange:se,onSortChange:Y,sortState:ae,splitViewEnabled:f})}),t==="table"&&(g==null?void 0:g.records)&&e.jsxs("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 py-4 pl-2 pr-4",children:[(M||P)&&(g==null?void 0:g.records)&&e.jsx("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-background/50",children:e.jsx(s.LoadingDots,{size:"md",color:"muted","aria-label":"Loading data"})}),e.jsx(s.TableVisual,{card:r,data:$,comparisonMetadata:R,paginationMetadata:O,onPaginationChange:se,isLoading:M||P,onSortChange:Y,sortState:ae})]}),t==="info"&&k&&e.jsx("div",{className:"flex min-h-0 flex-1 flex-col pb-4",children:e.jsx("div",{className:"flex min-h-0 flex-1 flex-col rounded-md bg-background pl-2 pr-4",children:D?e.jsx(Qs,{error:D,errorSql:N,onSendFeedback:()=>{const X=s.prepareFeedbackData(s.FeedbackCategory.QUERY_GENERATION,{cardConfig:d.config,dataSource:r.dataSource,dashboardFilters:o,errorMessage:D,errorSql:N,generatedSql:g==null?void 0:g.sql});E(X),V(!0)},onOpenInEditor:()=>{m(!0),setTimeout(()=>{const X=s.useEditorStore.getState().actions;X.setIsDevMode(!0),X.setCardSql(N||""),setTimeout(()=>{X.setRunSql(!0)},100)},100)}}):(g==null?void 0:g.sql)&&e.jsx(ya,{sql:g.sql,showCardDetails:!0,debugPayloads:I?{queryRequest:F,queryResponse:g,columns:i,dashboardFilters:o}:void 0})})})]}),L&&e.jsx(s.FeedbackDialog,{open:T,onOpenChange:V,feedbackData:L})]})})}function Do({activeField:t}){const[n,a]=C.useState(!0);return C.useEffect(()=>{t&&a(!0)},[t]),t?e.jsxs("div",{className:`flex max-w-[300px] items-center gap-2 rounded-lg border border-blue-500 bg-background p-2 shadow-lg transition-all duration-200 ${n?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(s.GripVertical,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx(Zs,{dataType:t.dataType}),e.jsx("span",{className:"overflow-hidden text-ellipsis whitespace-nowrap text-sm dark:text-muted-foreground",children:t.label||t.name})]}):null}const Ao=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r)};const n=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1},a=r=>{var i;if((i=r.reason)!=null&&i.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1};return window.addEventListener("error",n,!0),window.addEventListener("unhandledrejection",a,!0),()=>{console.error=t,window.removeEventListener("error",n,!0),window.removeEventListener("unhandledrejection",a,!0)}};function Lo({column:t,isSelected:n,onSelect:a,availableFields:r,width:i,onWidthChange:d}){var F,$,U;const o=s.useEditorStore(z=>z.card),{updateCardConfig:c,removeGroupByColumn:l,removeMetricColumn:x,updateFilters:p}=s.useEditorActions(),[h,m]=C.useState(!1),[y,v]=C.useState(!1),u=C.useRef(null),b=C.useCallback(z=>{z.preventDefault(),z.stopPropagation(),v(!0),u.current={startX:z.clientX,startWidth:i||150};const H=Y=>{if(!u.current)return;const ae=Y.clientX-u.current.startX,q=Math.max(80,u.current.startWidth+ae);d==null||d(t.id,q)},se=()=>{v(!1),u.current=null,document.removeEventListener("mousemove",H),document.removeEventListener("mouseup",se)};document.addEventListener("mousemove",H),document.addEventListener("mouseup",se)},[i,t.id,d]),w=(F=o==null?void 0:o.config)==null?void 0:F.filters,T=($=w==null?void 0:w.conditions)==null?void 0:$.some(z=>z.field.name===t.name&&z.field.qualifiedEntityName===t.qualifiedEntityName),V=z=>{z?p(o.id,z):c(o.id,{filters:void 0})},{attributes:L,listeners:E,setNodeRef:j,transform:k,transition:I,isDragging:f}=s.useSortable({id:t.id}),A={transform:s.CSS.Transform.toString(k),transition:I},g=s.getDataType(t.dataType),D=Mo(g),M=()=>{var se;const z=((se=o==null?void 0:o.config)==null?void 0:se.sortByColumns)||[],H=z.findIndex(Y=>Y.name===t.name);if(H!==-1){const Y=[...z];Y[H]={...Y[H],direction:"asc"},c(o.id,{sortByColumns:Y})}else c(o.id,{sortByColumns:[...z,{...t,id:`sort-${t.id}`,role:"sortby",direction:"asc"}]})},P=()=>{var se;const z=((se=o==null?void 0:o.config)==null?void 0:se.sortByColumns)||[],H=z.findIndex(Y=>Y.name===t.name);if(H!==-1){const Y=[...z];Y[H]={...Y[H],direction:"desc"},c(o.id,{sortByColumns:Y})}else c(o.id,{sortByColumns:[...z,{...t,id:`sort-${t.id}`,role:"sortby",direction:"desc"}]})},N=()=>{var se;const z=((se=o==null?void 0:o.config)==null?void 0:se.groupByColumns)||[];if(!z.some(Y=>Y.name===t.name)){const Y={...t,id:`groupby-${t.id}-${Date.now()}`,role:"groupby"};c(o.id,{groupByColumns:[...z,Y]})}},O=z=>{var Y;const H=((Y=o==null?void 0:o.config)==null?void 0:Y.metricColumns)||[];if(!H.some(ae=>ae.name===t.name&&ae.aggregate===z)){const ae={...t,id:`metric-${t.id}-${z}-${Date.now()}`,label:`${z} of ${t.label||t.name}`,role:"metric",aggregate:z};c(o.id,{metricColumns:[...H,ae]})}},S=()=>{t.role==="groupby"?l(o.id,t.id):t.role==="metric"&&x(o.id,t.id)},R={...A,width:i?`${i}px`:void 0,minWidth:i?`${i}px`:"120px"};return e.jsxs("th",{ref:j,style:R,className:s.cn("group relative border-r border-border bg-background px-1 py-0",f&&"opacity-50",n&&"bg-primary/10",y&&"select-none"),children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{...L,...E,className:"cursor-grab p-1 text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover:opacity-100 active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-3 w-3"})}),e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs("button",{onClick:a,className:s.cn("flex flex-1 items-center justify-between gap-1 rounded px-2 py-2 text-left text-sm font-medium transition-colors hover:bg-muted/50",n&&"bg-primary/10"),children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(D,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:t.label||t.name}),t.role==="metric"&&t.aggregate&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",t.aggregate,")"]}),T&&e.jsx(s.Filter,{className:"h-3 w-3 text-primary"})]}),e.jsx(s.ChevronDown,{className:"h-3 w-3 text-muted-foreground"})]})}),e.jsxs(s.DropdownMenuContent,{align:"start",className:"w-48",children:[e.jsxs(s.DropdownMenuItem,{onClick:()=>m(!0),children:[e.jsx(s.Filter,{className:s.cn("mr-2 h-4 w-4",T&&"text-primary")}),T?"Edit Filter":"Filter"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:M,children:[e.jsx(rn,{className:"mr-2 h-4 w-4"}),"Sort A → Z"]}),e.jsxs(s.DropdownMenuItem,{onClick:P,children:[e.jsx(nn,{className:"mr-2 h-4 w-4"}),"Sort Z → A"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(s.Calculator,{className:"mr-2 h-4 w-4"}),"Summarize"]}),e.jsxs(s.DropdownMenuSubContent,{children:[e.jsx(s.DropdownMenuItem,{onClick:()=>O("SUM"),children:"Sum"}),e.jsx(s.DropdownMenuItem,{onClick:()=>O("AVG"),children:"Average"}),e.jsx(s.DropdownMenuItem,{onClick:()=>O("COUNT"),children:"Count"}),e.jsx(s.DropdownMenuItem,{onClick:()=>O("DISTINCT"),children:"Count Distinct"}),e.jsx(s.DropdownMenuItem,{onClick:()=>O("MIN"),children:"Min"}),e.jsx(s.DropdownMenuItem,{onClick:()=>O("MAX"),children:"Max"})]})]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:N,children:[e.jsx(Ss,{className:"mr-2 h-4 w-4"}),"Group by this column"]}),e.jsxs(s.DropdownMenuItem,{disabled:!0,children:[e.jsx(Js,{className:"mr-2 h-4 w-4"}),"Pivot by this column"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{disabled:!0,children:[e.jsx(s.EyeOff,{className:"mr-2 h-4 w-4"}),"Hide column"]}),e.jsxs(s.DropdownMenuItem,{onClick:S,className:"text-destructive focus:text-destructive",children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove column"]})]})]})]}),e.jsx("div",{onMouseDown:b,className:s.cn("absolute right-0 top-0 h-full w-1 cursor-col-resize bg-transparent hover:bg-primary/50",y&&"bg-primary")}),e.jsx(Aa,{open:h,onOpenChange:m,availableFields:r.length>0?r:[t],existingFilters:w,editingCondition:T?(U=w==null?void 0:w.conditions)==null?void 0:U.find(z=>z.field.name===t.name&&z.field.qualifiedEntityName===t.qualifiedEntityName):void 0,onSave:V})]})}function Mo(t){switch(t){case"number":return s.Hash;case"date":return s.Calendar;case"string":default:return s.Type}}function Oo({selectedColumn:t,onColumnSelect:n,isLoading:a=!1,sourceFields:r=[]}){var I,f,A,g;const i=s.useEditorStore(D=>D.card),{updateCardConfig:d}=s.useEditorActions(),[o,c]=C.useState(null),[l,x]=C.useState({}),[p,h]=C.useState(!1),m=C.useMemo(()=>{var P,N;const D=((P=i==null?void 0:i.config)==null?void 0:P.groupByColumns)||[],M=((N=i==null?void 0:i.config)==null?void 0:N.metricColumns)||[];return[...D,...M]},[(I=i==null?void 0:i.config)==null?void 0:I.groupByColumns,(f=i==null?void 0:i.config)==null?void 0:f.metricColumns]),y=C.useMemo(()=>{const D=new Set(m.map(M=>`${M.qualifiedEntityName}.${M.name}`));return r.filter(M=>!D.has(`${M.qualifiedEntityName}.${M.name}`))},[r,m]),{data:v,isLoading:u}=s.useDashboardCardQuery(i),b=(v==null?void 0:v.records)||[],w=C.useCallback((D,M)=>{x(P=>({...P,[D]:M}))},[]),T=C.useCallback(D=>{var O,S;const M=s.getDataType(D.dataType),P=((O=i==null?void 0:i.config)==null?void 0:O.groupByColumns)||[],N=((S=i==null?void 0:i.config)==null?void 0:S.metricColumns)||[];if(M==="number"){const R={...D,id:`metric-${D.id}-${Date.now()}`,role:"metric",aggregate:"SUM"};d(i.id,{metricColumns:[...N,R]})}else{const R={...D,id:`groupby-${D.id}-${Date.now()}`,role:"groupby"};d(i.id,{groupByColumns:[...P,R]})}h(!1)},[(A=i==null?void 0:i.config)==null?void 0:A.groupByColumns,(g=i==null?void 0:i.config)==null?void 0:g.metricColumns,i.id,d]),V=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),L=D=>{c(D.active.id)},E=D=>{const{active:M,over:P}=D;if(c(null),!P||M.id===P.id)return;const N=m.findIndex(S=>S.id===M.id),O=m.findIndex(S=>S.id===P.id);if(N!==-1&&O!==-1){const S=s.arrayMove(m,N,O),R=S.filter($=>$.role==="groupby"),F=S.filter($=>$.role==="metric");d(i.id,{groupByColumns:R,metricColumns:F})}},j=o?m.find(D=>D.id===o):null,k=D=>{let M="";for(;D>=0;)M=String.fromCharCode(D%26+65)+M,D=Math.floor(D/26)-1;return M};return a?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(s.LoaderCircle,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):m.length===0?e.jsx("div",{className:"flex h-full flex-col items-center justify-center gap-4 p-8 text-center",children:e.jsxs("div",{className:"rounded-lg border-2 border-dashed border-muted-foreground/25 p-12",children:[e.jsx("h3",{className:"text-lg font-medium text-muted-foreground",children:"No columns selected"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground/75",children:"Select columns from the panel on the right to build your table"})]})}):e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsxs(s.DndContext,{sensors:V,collisionDetection:s.closestCenter,onDragStart:L,onDragEnd:E,children:[e.jsxs("table",{className:"w-full border-collapse",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"border-b border-border bg-muted/30",children:[e.jsx("th",{className:"sticky left-0 z-20 w-12 border-r border-border bg-muted/50 px-2 py-1 text-center text-xs font-medium text-muted-foreground"}),e.jsx(s.SortableContext,{items:m.map(D=>D.id),strategy:s.horizontalListSortingStrategy,children:m.map((D,M)=>e.jsx("th",{style:{width:l[D.id]?`${l[D.id]}px`:void 0,minWidth:l[D.id]?`${l[D.id]}px`:"120px"},className:"border-r border-border bg-muted/30 px-2 py-1 text-center text-xs font-medium text-muted-foreground",children:k(M)},`letter-${D.id}`))}),e.jsx("th",{className:"w-10 border-r border-border bg-muted/30 px-2 py-1"})]}),e.jsxs("tr",{className:"border-b-2 border-border bg-background",children:[e.jsx("th",{className:"sticky left-0 z-20 w-12 border-r border-border bg-muted/50 px-2 py-2 text-center text-xs font-medium text-muted-foreground",children:"#"}),e.jsx(s.SortableContext,{items:m.map(D=>D.id),strategy:s.horizontalListSortingStrategy,children:m.map(D=>e.jsx(Lo,{column:D,isSelected:(t==null?void 0:t.id)===D.id,onSelect:()=>n(D),availableFields:r,width:l[D.id],onWidthChange:w},D.id))}),e.jsx("th",{className:"w-10 border-r border-border bg-background px-1 py-2",children:e.jsxs(s.Popover,{open:p,onOpenChange:h,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",title:"Add column",children:e.jsx(s.Plus,{className:"h-4 w-4"})})}),e.jsx(s.PopoverContent,{className:"w-[280px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search columns..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No columns available."}),e.jsx(s.CommandGroup,{heading:"Available Columns",children:y.map(D=>{const M=s.getDataType(D.dataType),P=M==="number"?s.Hash:M==="date"?s.Calendar:s.Type;return e.jsxs(s.CommandItem,{value:D.label||D.name,onSelect:()=>T(D),children:[e.jsx(P,{className:"mr-2 h-3.5 w-3.5 text-muted-foreground"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm",children:D.label||D.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:D.entityName})]})]},D.id)})})]})]})})]})})]})]}),e.jsx("tbody",{children:u?e.jsx("tr",{children:e.jsx("td",{colSpan:m.length+2,className:"h-32 text-center",children:e.jsx(s.LoaderCircle,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})})}):b.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:m.length+2,className:"h-32 text-center text-muted-foreground",children:"No data available"})}):b.slice(0,100).map((D,M)=>e.jsxs("tr",{className:s.cn("border-b border-border transition-colors hover:bg-muted/50",M%2===0?"bg-background":"bg-muted/20"),children:[e.jsx("td",{className:"sticky left-0 z-10 w-12 border-r border-border bg-muted/50 px-2 py-2 text-center text-xs font-medium text-muted-foreground",children:M+1}),m.map(P=>{const N=D[P.name]??D[P.label??""];return e.jsx("td",{style:{width:l[P.id]?`${l[P.id]}px`:void 0,minWidth:l[P.id]?`${l[P.id]}px`:"120px"},className:s.cn("border-r border-border px-3 py-2 text-sm",(t==null?void 0:t.id)===P.id&&"bg-primary/5"),children:e.jsx("span",{className:"block truncate",children:Ro(N,P)})},`${M}-${P.id}`)}),e.jsx("td",{className:"w-10 border-r border-border"})]},M))})]}),e.jsx(s.DragOverlay,{children:j&&e.jsx("div",{className:"rounded border border-primary bg-background px-3 py-2 text-sm font-medium shadow-lg",children:j.label||j.name})})]})}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border bg-muted/30 px-4 py-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["Showing ",Math.min(b.length,100)," of ",b.length," rows"]}),e.jsxs("span",{children:[m.length," columns"]})]})]})}function Ro(t,n){if(t==null)return"—";if(typeof t=="number")return n.role==="metric"?new Intl.NumberFormat("en-US",{minimumFractionDigits:0,maximumFractionDigits:2}).format(t):t.toString();if(t instanceof Date||typeof t=="string"&&!isNaN(Date.parse(t))){const a=new Date(t);if(!isNaN(a.getTime()))return a.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}return String(t)}function Fo({entityGroups:t,isLoading:n=!1}){var V,L;const a=s.useEditorStore(E=>E.card),{updateCardConfig:r,removeGroupByColumn:i,removeMetricColumn:d}=s.useEditorActions(),[o,c]=C.useState(!0),[l,x]=C.useState(""),[p,h]=C.useState(new Set),m=((V=a==null?void 0:a.config)==null?void 0:V.groupByColumns)||[],y=((L=a==null?void 0:a.config)==null?void 0:L.metricColumns)||[],v=E=>{const j=new Set(p);j.has(E)?j.delete(E):j.add(E),h(j)},u=E=>m.some(j=>j.name===E.name&&j.qualifiedEntityName===E.qualifiedEntityName)||y.some(j=>j.name===E.name&&j.qualifiedEntityName===E.qualifiedEntityName),b=(E,j)=>{if(j)if(s.getDataType(E.dataType)==="number"){const I={...E,id:`metric-${E.id}-${Date.now()}`,role:"metric",aggregate:"SUM"};r(a.id,{metricColumns:[...y,I]})}else{const I={...E,id:`groupby-${E.id}-${Date.now()}`,role:"groupby"};r(a.id,{groupByColumns:[...m,I]})}else{const k=m.findIndex(f=>f.name===E.name&&f.qualifiedEntityName===E.qualifiedEntityName),I=y.findIndex(f=>f.name===E.name&&f.qualifiedEntityName===E.qualifiedEntityName);k!==-1&&i(a.id,m[k].id),I!==-1&&d(a.id,y[I].id)}},w=E=>{if(!l)return E;const j=l.toLowerCase();return E.filter(k=>k.name.toLowerCase().includes(j)||k.label&&k.label.toLowerCase().includes(j))},T=E=>{switch(s.getDataType(E)){case"number":return s.Hash;case"date":return s.Calendar;default:return s.Type}};return o?e.jsxs("div",{className:"flex h-full w-72 flex-col border-l border-border bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Columns"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:()=>c(!1),title:"Close panel",children:e.jsx(fn,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"border-b border-border p-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{placeholder:"Search columns...",value:l,onChange:E=>x(E.target.value),className:"h-8 pl-8 text-sm"})]})}),(m.length>0||y.length>0)&&e.jsxs("div",{className:"border-b border-border",children:[m.length>0&&e.jsxs(s.Collapsible,{defaultOpen:!0,children:[e.jsxs(s.CollapsibleTrigger,{className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium hover:bg-muted/50",children:[e.jsx(s.ChevronRight,{className:"h-3.5 w-3.5 transition-transform duration-200 [[data-state=open]>&]:rotate-90"}),e.jsx(Ss,{className:"h-3.5 w-3.5 text-blue-500"}),e.jsx("span",{children:"Groupings"}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:m.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:m.map(E=>{const j=T(E.dataType);return e.jsxs("div",{className:"group flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[e.jsx(s.GripVertical,{className:"h-3 w-3 cursor-grab text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"}),e.jsx(j,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:E.label||E.name}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>i(a.id,E.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},E.id)})})})]}),y.length>0&&e.jsxs(s.Collapsible,{defaultOpen:!0,children:[e.jsxs(s.CollapsibleTrigger,{className:"flex w-full items-center gap-2 px-3 py-2 text-sm font-medium hover:bg-muted/50",children:[e.jsx(s.ChevronRight,{className:"h-3.5 w-3.5 transition-transform duration-200 [[data-state=open]>&]:rotate-90"}),e.jsx(s.Calculator,{className:"h-3.5 w-3.5 text-green-500"}),e.jsx("span",{children:"Metrics"}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:y.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:y.map(E=>{const j=T(E.dataType);return e.jsxs("div",{className:"group flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50",children:[e.jsx(s.GripVertical,{className:"h-3 w-3 cursor-grab text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"}),e.jsx(j,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:E.label||E.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:E.aggregate}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>d(a.id,E.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},E.id)})})})]})]}),e.jsx(s.ScrollArea,{className:"flex-1",children:e.jsx("div",{className:"p-2",children:n?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"h-6 w-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent"})}):t.length===0?e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No columns available"}):t.map(E=>{const j=w(E.columns);if(j.length===0)return null;const k=p.has(E.entityId)||l.length>0;return e.jsxs(s.Collapsible,{open:k,onOpenChange:()=>v(E.entityId),children:[e.jsxs(s.CollapsibleTrigger,{className:"flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm font-medium hover:bg-muted/50",children:[e.jsx(s.ChevronRight,{className:s.cn("h-3.5 w-3.5 transition-transform duration-200",k&&"rotate-90")}),e.jsx(s.Table2,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate text-left",children:E.label||E.entityName}),e.jsx("span",{className:"text-xs text-muted-foreground",children:j.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"ml-4 space-y-0.5 border-l border-border pl-2",children:j.map(I=>{const f=T(I.dataType),A=u(I);return e.jsxs("label",{className:s.cn("flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm transition-colors hover:bg-muted/50",A&&"bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:A,onCheckedChange:g=>b(I,g),className:"h-3.5 w-3.5"}),e.jsx(f,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:I.label||I.name})]},I.id)})})})]},E.entityId)})})})]}):e.jsx("div",{className:"flex h-full items-start border-l border-border bg-muted/30 p-2",children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>c(!0),title:"Open panel",children:e.jsx(gn,{className:"h-4 w-4"})})})}const Vo=[{name:"SUM",description:"Sum of values",syntax:"SUM([column])"},{name:"AVG",description:"Average of values",syntax:"AVG([column])"},{name:"COUNT",description:"Count of rows",syntax:"COUNT([column])"},{name:"COUNTD",description:"Count distinct values",syntax:"COUNTD([column])"},{name:"MIN",description:"Minimum value",syntax:"MIN([column])"},{name:"MAX",description:"Maximum value",syntax:"MAX([column])"},{name:"IF",description:"Conditional logic",syntax:"IF(condition, then, else)"},{name:"CASE",description:"Multiple conditions",syntax:"CASE WHEN ... THEN ... END"},{name:"CONCAT",description:"Concatenate text",syntax:"CONCAT([col1], [col2])"},{name:"ROUND",description:"Round number",syntax:"ROUND([column], decimals)"},{name:"FLOOR",description:"Round down",syntax:"FLOOR([column])"},{name:"CEIL",description:"Round up",syntax:"CEIL([column])"},{name:"ABS",description:"Absolute value",syntax:"ABS([column])"},{name:"DATEPART",description:"Extract date part",syntax:"DATEPART(year, [date])"},{name:"DATEDIFF",description:"Difference between dates",syntax:"DATEDIFF(day, [date1], [date2])"}];function Po({value:t,onChange:n,onSubmit:a,onCancel:r,selectedColumn:i,availableColumns:d}){const[o,c]=C.useState(!1),[l,x]=C.useState("column"),p=C.useRef(null);C.useEffect(()=>{const v=u=>{u.key==="Escape"&&t?r():u.key==="Enter"&&t&&!o&&a(t)};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[t,r,a,o]);const h=v=>{const u=`[${v.label||v.name}]`,b=p.current;if(b){const w=b.selectionStart||0,T=b.selectionEnd||0,V=t.slice(0,w)+u+t.slice(T);n(V),setTimeout(()=>{b.setSelectionRange(w+u.length,w+u.length),b.focus()},0)}else n(t+u);c(!1)},m=v=>{const u=p.current;if(u){const b=u.selectionStart||0,w=u.selectionEnd||0,T=t.slice(0,b)+v.syntax+t.slice(w);n(T),setTimeout(()=>{u.setSelectionRange(b+v.name.length+1,b+v.syntax.length-1),u.focus()},0)}else n(t+v.syntax);c(!1)},y=v=>{switch(s.getDataType(v)){case"number":return s.Hash;case"date":return s.Calendar;default:return s.Type}};return e.jsxs("div",{className:"flex items-center gap-2 border-b border-border bg-muted/30 px-3 py-1.5",children:[e.jsx("div",{className:"flex min-w-[100px] items-center justify-center rounded border border-border bg-background px-2 py-1 text-xs font-medium text-muted-foreground",children:i?e.jsx("span",{className:"truncate",children:i.label||i.name}):e.jsx("span",{children:"—"})}),e.jsxs(s.Popover,{open:o&&l==="function",onOpenChange:v=>{c(v),v&&x("function")},children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",title:"Insert function",children:e.jsx(yn,{className:"h-4 w-4"})})}),e.jsx(s.PopoverContent,{className:"w-[300px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search functions..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No functions found."}),e.jsx(s.CommandGroup,{heading:"Functions",children:Vo.map(v=>e.jsx(s.CommandItem,{value:v.name,onSelect:()=>m(v),children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-sm font-medium",children:v.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:v.description})]}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground/75",children:v.syntax})]})},v.name))})]})]})})]}),e.jsxs(s.Popover,{open:o&&l==="column",onOpenChange:v=>{c(v),v&&x("column")},children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1 px-2 text-xs text-muted-foreground hover:text-foreground",title:"Insert column reference",children:[e.jsx("span",{children:"Columns"}),e.jsx(s.ChevronDown,{className:"h-3 w-3"})]})}),e.jsx(s.PopoverContent,{className:"w-[250px] p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search columns..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No columns found."}),e.jsx(s.CommandGroup,{heading:"Available Columns",children:d.map(v=>{const u=y(v.dataType);return e.jsxs(s.CommandItem,{value:v.label||v.name,onSelect:()=>h(v),children:[e.jsx(u,{className:"mr-2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:v.label||v.name})]},v.id)})})]})]})})]}),e.jsx("div",{className:"relative flex-1",children:e.jsx(s.Input,{ref:p,value:t,onChange:v=>n(v.target.value),placeholder:"Enter a formula or select a column...",className:"h-7 border-border bg-background font-mono text-sm"})}),t&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:r,title:"Cancel (Esc)",children:e.jsx(s.X,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-green-600 hover:bg-green-600/10 hover:text-green-600",onClick:()=>a(t),title:"Apply (Enter)",children:e.jsx(s.Check,{className:"h-4 w-4"})})]})]})}function Bo({className:t}){var m,y,v,u;const n=s.useEditorStore(b=>b.card),[a,r]=C.useState(null),[i,d]=C.useState(""),{columns:o=[],columnGroups:c=[],isLoading:l}=s.useColumns();(m=n==null?void 0:n.config)!=null&&m.groupByColumns,(y=n==null?void 0:n.config)!=null&&y.metricColumns,(v=n==null?void 0:n.config)!=null&&v.groupByColumns,(u=n==null?void 0:n.config)!=null&&u.pivotByColumns;const x=b=>{r(b),d(b?`[${b.label||b.name}]`:"")},p=b=>{console.log("Formula submitted:",b),d(""),r(null)},h=()=>{d(""),r(null)};return e.jsxs("div",{className:s.cn("flex h-full w-full flex-col",t),children:[e.jsx(Po,{value:i,onChange:d,onSubmit:p,onCancel:h,selectedColumn:a,availableColumns:o}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx(Oo,{selectedColumn:a,onColumnSelect:x,isLoading:l,sourceFields:o})}),e.jsx(Fo,{entityGroups:c,isLoading:l})]})]})}function zo(){var O,S;const[t,n]=C.useState("chart"),[a,r]=C.useState(!1),[i,d]=C.useState(!0),o=s.useEditorStore(R=>R.showAIDialog),c=s.useDashboardStore(R=>R.isVisualEditing),{setCardType:l}=s.useEditorActions(),x=s.useEditorStore(R=>R.card.type);C.useEffect(()=>Ao(),[]);const p=R=>{l(R)},h=s.useEditorStore(R=>R.frame),m=s.useEditorStore(R=>R.card);s.useEditorStore(R=>R.activeTabCardId),s.useEditorStore(R=>R.actions.getAvailableFields);const{addCard:y,removeCard:v,updateCard:u,setActiveCard:b,updateFilters:w}=s.useEditorActions(),{columnFields:T=[],scopedFields:V=[]}=s.useScopedFields(),L=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),E=m,{getFieldsForContainer:j,setFieldsForContainer:k}=s.useFieldManagement(E),{activeField:I,handleDragStart:f,handleDragEnd:A}=No({activeCardId:h.activeCardId,sourceFields:V,getFieldsForContainer:j,setFieldsForContainer:k}),g=(R,F)=>{F&&w(R,F)},D=R=>{var F;u(R,{config:{...(F=h.cards.find($=>$.id===R))==null?void 0:F.config,filters:void 0}})},M=T,P=R=>{if(!R)return 0;let F=R.conditions.length;return R.groups.forEach($=>{F+=P($)}),F},N=P(((O=E==null?void 0:E.config)==null?void 0:O.filters)||null);return e.jsxs(s.DndContext,{sensors:L,collisionDetection:s.closestCenter,onDragStart:f,onDragEnd:A,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(ba,{isVisible:i,onToggleVisibility:()=>d(!i)}),e.jsx("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:x==="tableBuilder"?e.jsx(Bo,{className:"flex-1"}):e.jsxs(e.Fragment,{children:[!o&&e.jsx(ao,{selectedChart:x,onChartChange:p,groupByFields:j("groupBy"),pivotByFields:j("pivotBy"),metricsFields:j("metrics"),sortByFields:j("sortBy"),detailFields:j("detailColumns"),activeField:I}),e.jsx(ko,{selectedChart:x,activeView:t,onViewChange:n,onFiltersClick:()=>r(!0),filterCount:N,activeCard:E,columns:T,getFieldsForContainer:j,cards:h.cards,activeCardId:h.activeCardId,addCard:y,setActiveCard:b})]})}),!i&&c&&e.jsx("div",{className:"fixed left-6 top-[105px] z-50",children:e.jsx(s.Button,{size:"sm",variant:"outline",className:"h-10 w-10 rounded-full border-border bg-background p-0 shadow-lg hover:bg-muted",onClick:()=>d(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),E&&e.jsx(yo,{cardId:E.id,filters:((S=E.config)==null?void 0:S.filters)||null,onFiltersChange:g,onClearFilters:D,availableFields:M,isOpen:a,onOpenChange:r}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(Do,{activeField:I||null})})]})}function qo({authToken:t,onSave:n,onClose:a}){const r=C.useRef(null),i=s.useEditorStore(j=>j.showAIDialog),d=s.useEditorStore(j=>j.isDevMode),o=s.useAssistantLayoutStore(j=>j.setFullscreen),c=s.useAssistantLayoutStore(j=>j.setPanelOpen),l=s.useAssistantLayoutStore(j=>j.setContainer),x=s.useAssistantPanel("editor"),p=s.useFullscreenAssistant(),h=s.useAssistantContainer("editor"),m=p==="editor",y=C.useCallback(j=>{l("editor",j)},[l]),{setAuthToken:v}=s.useDashboardActions(),{setShowAIDialog:u,setOnSave:b,setOnClose:w}=s.useEditorActions(),{setActiveAssistantType:T}=s.useAIActions();C.useEffect(()=>{n&&b(n),a&&w(a)},[n,b,a,w]),C.useEffect(()=>{t&&t.accessToken&&v(t)},[t,v]),C.useEffect(()=>{var j,k;i?((j=r.current)==null||j.resize(40),c("editor",!0),T("editor")):((k=r.current)==null||k.resize(0),c("editor",!1),p==="editor"&&o(null),T(null))},[i,c,T,o,p]);function V(j){var k;j<1?(u(!1),c("editor",!1),p==="editor"&&o(null),T(null),(k=r.current)==null||k.resize(0)):(i||(u(!0),T("editor")),x.isOpen||c("editor",!0))}function L(){return e.jsxs(e.Fragment,{children:[e.jsx(ba,{isVisible:!0,onToggleVisibility:()=>{}}),e.jsxs("div",{className:"relative flex grow",children:[e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:s.cn("grow transition-opacity",m&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(Fl,{})}),e.jsx(s.ResizableHandle,{disabled:!i}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:V,defaultSize:x.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(da,{isFullscreen:m,onFullscreenChange:j=>o(j?"editor":null),fullscreenContainer:h})})})]}),e.jsx("div",{ref:y,className:s.cn("absolute inset-0",!m&&"pointer-events-none")})]})]})}function E(){return e.jsxs("div",{className:"relative flex h-full grow",children:[e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:s.cn("flex grow transition-opacity",m&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(zo,{})}),e.jsx(s.ResizableHandle,{disabled:!i}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:V,defaultSize:x.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(da,{isFullscreen:m,onFullscreenChange:j=>o(j?"editor":null),fullscreenContainer:h})})})]}),e.jsx("div",{ref:y,className:s.cn("absolute inset-0",!m&&"pointer-events-none")})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:d?e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:L()}):E()})}function $o(){s.useDashboardStore(l=>l.selectedCardId);const t=s.useDashboardStore(l=>l.selectedSheetId),n=s.useDashboardStore(l=>l.dashboard),{setIsVisualEditing:a,setSelectedSheetId:r}=s.useDashboardStore(l=>l.actions),i=s.useDashboardStore(l=>l.isVisualEditing),d=s.useDashboardStore(l=>l.actions.updateFrame);function o(l){var m,y,v;const x=t?(m=n==null?void 0:n.sheets)==null?void 0:m.some(u=>{var b;return u.id===t&&((b=u.frames)==null?void 0:b.some(w=>w.id===l.id))}):!1,p=(v=(y=n==null?void 0:n.sheets)==null?void 0:y.find(u=>{var b;return(b=u.frames)==null?void 0:b.some(w=>w.id===l.id)}))==null?void 0:v.id,h=x?t:p||null;h&&(d(h,l),t!==h&&r(h),a(!1))}function c(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!i}),children:e.jsx(qo,{onSave:o,onClose:c})})}exports.default=$o;
|