react-semaphor 0.1.154 → 0.1.156

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.
Files changed (29) hide show
  1. package/dist/chunks/{dashboard-controls-CfwJmqIk.js → dashboard-controls-Clm2GcxX.js} +1 -1
  2. package/dist/chunks/{dashboard-controls-BQN37S-Z.js → dashboard-controls-DXSsN2_k.js} +3 -3
  3. package/dist/chunks/{dashboard-export-dialog-Bk40DbBa.js → dashboard-export-dialog-CUhiiOCR.js} +3 -3
  4. package/dist/chunks/{dashboard-export-dialog-CleOul_2.js → dashboard-export-dialog-DwfP0g9l.js} +1 -1
  5. package/dist/chunks/{dashboard-json-DoH7BzSp.js → dashboard-json-BtbQ-MVO.js} +1 -1
  6. package/dist/chunks/{dashboard-json-DvDujj0u.js → dashboard-json-_LnU8Rxq.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-6Dbv7mp-.js → edit-dashboard-visual-CV7VBGw2.js} +9147 -7861
  8. package/dist/chunks/edit-dashboard-visual-DHHn6fRK.js +195 -0
  9. package/dist/chunks/{editor-action-buttons-D7XJarSH.js → editor-action-buttons-CBebX9XC.js} +1 -1
  10. package/dist/chunks/{editor-action-buttons-B9rrfO6d.js → editor-action-buttons-CiH4UMGY.js} +2 -2
  11. package/dist/chunks/{index-B57nSymH.js → index-BSYIyWCb.js} +19820 -19136
  12. package/dist/chunks/{index-4FLL7B4z.js → index-d_rBmGge.js} +226 -226
  13. package/dist/chunks/{resource-management-panel-DdtlZ9Cm.js → resource-management-panel-CLsxcpgo.js} +1 -1
  14. package/dist/chunks/{resource-management-panel-DJ7ZIbbt.js → resource-management-panel-CmVNvmIl.js} +2 -2
  15. package/dist/chunks/{use-visual-utils-CuGAdqrL.js → use-visual-utils-BAX5FL2F.js} +1 -1
  16. package/dist/chunks/{use-visual-utils-BX99ssnb.js → use-visual-utils-DlJJtCer.js} +1 -1
  17. package/dist/dashboard/index.cjs +1 -1
  18. package/dist/dashboard/index.js +1 -1
  19. package/dist/index.cjs +1 -1
  20. package/dist/index.js +4 -4
  21. package/dist/style.css +1 -1
  22. package/dist/surfboard/index.cjs +1 -1
  23. package/dist/surfboard/index.js +1 -1
  24. package/dist/types/dashboard.d.ts +53 -1
  25. package/dist/types/main.d.ts +53 -1
  26. package/dist/types/surfboard.d.ts +53 -1
  27. package/dist/types/types.d.ts +53 -1
  28. package/package.json +1 -1
  29. package/dist/chunks/edit-dashboard-visual-DHRzXa1_.js +0 -190
@@ -0,0 +1,195 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-d_rBmGge.js"),L=require("react"),He=require("./editor-action-buttons-CBebX9XC.js"),Ws=require("react-dom");function Xs(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,l.get?l:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Ue=Xs(L);/**
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 Zs=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 et=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 Ss=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 st=s.createLucideIcon("BookOpenText",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M16 12h2",key:"7q9ll5"}],["path",{d:"M16 8h2",key:"msurwy"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}],["path",{d:"M6 12h2",key:"32wvfc"}],["path",{d:"M6 8h2",key:"30oboj"}]]);/**
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 ws=s.createLucideIcon("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);/**
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 Ts=s.createLucideIcon("Columns3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
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 tt=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"}]]);/**
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 at=s.createLucideIcon("EyeClosed",[["path",{d:"m15 18-.722-3.25",key:"1j64jw"}],["path",{d:"M2 8a10.645 10.645 0 0 0 20 0",key:"1e7gxb"}],["path",{d:"m20 15-1.726-2.05",key:"1cnuld"}],["path",{d:"m4 15 1.726-2.05",key:"1dsqqd"}],["path",{d:"m9 18 .722-3.25",key:"ypw2yx"}]]);/**
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 Es=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"}]]);/**
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 nt=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"}]]);/**
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 rt=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"}]]);/**
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 lt=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"}]]);/**
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 ot=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"}]]);/**
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 it=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"}]]);/**
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 ct=s.createLucideIcon("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);/**
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 dt=s.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);/**
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 ut=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"}]]);/**
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 mt=s.createLucideIcon("ListFilter",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M7 12h10",key:"b7w52i"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/**
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 xt=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"}]]);/**
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 ht=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"}]]);/**
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 Pe=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"}]]);/**
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 Ve=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"}]]);/**
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 pt=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"}]]);/**
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 gt=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"}]]);/**
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 ft=s.createLucideIcon("PanelRight",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
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 ls=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"}]]);/**
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 Je=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"}]]);/**
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 ks=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"}]]);/**
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 jt=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"}]]);/**
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 bt=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"}]]);/**
152
+ * @license lucide-react v0.453.0 - ISC
153
+ *
154
+ * This source code is licensed under the ISC license.
155
+ * See the LICENSE file in the root directory of this source tree.
156
+ */const vt=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"}]]);/**
157
+ * @license lucide-react v0.453.0 - ISC
158
+ *
159
+ * This source code is licensed under the ISC license.
160
+ * See the LICENSE file in the root directory of this source tree.
161
+ */const yt=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
162
+ * @license lucide-react v0.453.0 - ISC
163
+ *
164
+ * This source code is licensed under the ISC license.
165
+ * See the LICENSE file in the root directory of this source tree.
166
+ */const Nt=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"}]]);/**
167
+ * @license lucide-react v0.453.0 - ISC
168
+ *
169
+ * This source code is licensed under the ISC license.
170
+ * See the LICENSE file in the root directory of this source tree.
171
+ */const Ct=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 St({initialJoinPlan:t,availableDataSources:n}){const[a,l]=L.useState(t),[c,d]=L.useState(new Set),r=()=>{const E=a.joins.length>0?Math.max(...a.joins.map(S=>S.sequence))+1:1,C={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:E,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};l({...a,joins:[...a.joins,C]}),d(new Set([...c,C.id]))},i=E=>{l({...a,joins:a.joins.filter(C=>C.id!==E)}),d(new Set([...c].filter(C=>C!==E)))},o=(E,C)=>{var v,A,R,k,O;const S=a.joins.find(T=>T.id===E);if(!S)return;const I={...S,...C};if((v=I.source)!=null&&v.name&&((A=I.target)!=null&&A.name)&&I.source.name===I.target.name){s.ue.error("Self-joins are not yet supported",{description:`Joining ${I.source.name} to itself is not currently supported. Please select a different target table.`});return}const M=a.joins.filter(T=>{var P;return T.id!==E&&T.target.name===((P=I.target)==null?void 0:P.name)});if((R=I.target)!=null&&R.name&&M.length>0){s.ue.error("Duplicate join targets are not supported",{description:`The table ${I.target.name} is already used as a target in another join. Each table can only be joined once.`});return}const b=a.joins.map(T=>T.id===E?I:T);if((k=I.source)!=null&&k.name&&((O=I.target)!=null&&O.name)&&I.joinKeyGroups[0].keys.length===0){const T=n.find(q=>{var K;return q.name===((K=I.source)==null?void 0:K.name)}),P=n.find(q=>{var K;return q.name===((K=I.target)==null?void 0:K.name)}),$={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(T==null?void 0:T.name)||"",entityName:(T==null?void 0:T.name)||"",entityType:(T==null?void 0:T.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(P==null?void 0:P.name)||"",entityName:(P==null?void 0:P.name)||"",entityType:(P==null?void 0:P.type)||"table"},operator:"="},H=[...I.joinKeyGroups];H[0]={...H[0],keys:[$]},I.joinKeyGroups=H,b[b.findIndex(q=>q.id===E)]=I}l({...a,joins:b})};return{joinPlan:a,expandedJoins:c,setJoinPlan:l,addJoin:r,removeJoin:i,updateJoin:o,moveJoinUp:E=>{const C=a.joins.findIndex(S=>S.id===E);if(C>0){const S=[...a.joins],I={...S[C]},M={...S[C-1]};S[C]=M,S[C-1]=I,S.forEach((v,A)=>{v.sequence=A+1});const b={...a,joins:S};l(b)}},moveJoinDown:E=>{const C=a.joins.findIndex(S=>S.id===E);if(C<a.joins.length-1){const S=[...a.joins],I={...S[C]},M={...S[C+1]};S[C]=M,S[C+1]=I,S.forEach((v,A)=>{v.sequence=A+1});const b={...a,joins:S};l(b)}},toggleJoinExpansion:E=>{const C=new Set(c);C.has(E)?C.delete(E):C.add(E),d(C)},getAvailableSourceEntities:E=>{if(a.joins.length===0)return n;const C=a.joins.findIndex(I=>I.id===E);if(C===0)return n.filter(I=>I.name===a.baseEntity.name);const S=new Set;return a.baseEntity.name&&S.add(a.baseEntity.name),a.joins.slice(0,C).forEach(I=>{S.add(I.source.name),S.add(I.target.name)}),n.filter(I=>S.has(I.name))},getAvailableTargetEntities:E=>n.filter(C=>C.name!==E),addJoinKeyGroup:E=>{const C=a.joins.find(I=>I.id===E);if(!C)return;const S=[...C.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];o(E,{joinKeyGroups:S})},updateGroupOperator:(E,C,S)=>{const I=a.joins.find(b=>b.id===E);if(!I)return;const M=[...I.joinKeyGroups];M[C]={...M[C],operator:S},o(E,{joinKeyGroups:M})},removeJoinKeyGroup:(E,C)=>{const S=a.joins.find(M=>M.id===E);if(!S)return;const I=[...S.joinKeyGroups];I.splice(C,1),o(E,{joinKeyGroups:I})},addJoinKey:(E,C)=>{const S=a.joins.find(A=>A.id===E);if(!S)return;const I=n.find(A=>A.name===S.source.name),M=n.find(A=>A.name===S.target.name),b=[...S.joinKeyGroups],v={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(I==null?void 0:I.name)||"",entityName:(I==null?void 0:I.name)||"",entityType:(I==null?void 0:I.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(M==null?void 0:M.name)||"",entityName:(M==null?void 0:M.name)||"",entityType:(M==null?void 0:M.type)||"table"},operator:"="};b[C]={...b[C],keys:[...b[C].keys,v]},o(E,{joinKeyGroups:b})},updateJoinKey:(E,C,S,I,M)=>{const b=a.joins.find(O=>O.id===E);if(!b)return;const v=n.find(O=>O.name===b.source.name),A=n.find(O=>O.name===b.target.name),R=[...b.joinKeyGroups],k=R[C].keys[S];I==="sourceColumnName"&&v?R[C].keys[S]={...k,source:{...k.source,name:M}}:I==="targetColumnName"&&A?R[C].keys[S]={...k,target:{...k.target,name:M}}:I==="operator"&&(R[C].keys[S]={...k,operator:M}),o(E,{joinKeyGroups:R})},removeJoinKey:(E,C,S)=>{const I=a.joins.find(b=>b.id===E);if(!I)return;const M=[...I.joinKeyGroups];M[C].keys.splice(S,1),o(E,{joinKeyGroups:M})},generateSQLPreview:()=>{const E=[...a.joins].sort((I,M)=>I.sequence-M.sequence),C=a.baseEntity;if(!C.name)return"SELECT * FROM table -- Please select a base entity";let S=`SELECT *
172
+ FROM ${C.name}`;return E.forEach(I=>{const M=n.find(A=>A.name===I.target.name);if(!M)return;const b=I.joinKeyGroups.filter(A=>A.keys&&A.keys.length>0).map(A=>{const R=A.keys.filter(k=>{var O,T,P,$;return((O=k.source)==null?void 0:O.name)&&((T=k.target)==null?void 0:T.name)&&((P=k.source)==null?void 0:P.entityName)&&(($=k.target)==null?void 0:$.entityName)}).map(k=>`${k.source.entityName}.${k.source.name} ${k.operator} ${k.target.entityName}.${k.target.name}`);return R.length>1?`(${R.join(` ${A.operator} `)})`:R[0]}).filter(Boolean),v=b.length>1?b.join(" OR "):b[0]||"condition_here";S+=`
173
+ ${I.joinType} JOIN ${M.name}
174
+ ON ${v}`}),S},isValidConfiguration:()=>!(!a.baseEntity.name||a.joins.some(I=>!I.source.name||!I.target.name)||a.joins.some(I=>I.joinKeyGroups.some(M=>M.keys.length===0))||a.joins.some(I=>I.joinKeyGroups.some(M=>M.keys.some(b=>!b.source.name||!b.target.name||!b.operator))))}}function wt({joinPlan:t,availableDataSources:n,onSave:a,onRemove:l,onCancel:c}){const{setCardConfig:d}=s.useEditorActions();s.useEditorStore(b=>b.card.config);const{columnGroups:r}=s.useColumns(),{joinPlan:i,expandedJoins:o,setJoinPlan:u,addJoin:g,removeJoin:p,updateJoin:h,moveJoinUp:w,moveJoinDown:m,toggleJoinExpansion:x,getAvailableSourceEntities:f,getAvailableTargetEntities:j,addJoinKeyGroup:y,updateGroupOperator:F,removeJoinKeyGroup:D,addJoinKey:N,updateJoinKey:E,removeJoinKey:C,generateSQLPreview:S,isValidConfiguration:I}=St({initialJoinPlan:t,availableDataSources:n}),M=b=>{const v=r.find(A=>A.entityName===b);return(v==null?void 0:v.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:i.baseEntity.name,onValueChange:b=>{const v=n.find(A=>A.name===b);u({...i,baseEntity:{connectionId:(v==null?void 0:v.connectionId)||"",connectionType:(v==null?void 0:v.connectionType)||"none",type:(v==null?void 0:v.type)||"table",name:b,database:v==null?void 0:v.database,schema:v==null?void 0:v.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:n.map(b=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:b.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:b.type}),b.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},b.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:S()})]}),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 (",i.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:g,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),i.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:i.joins.map(b=>{const v=n.find(k=>k.name===b.source.name),A=n.find(k=>k.name===b.target.name),R=o.has(b.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:b.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",b.sequence,v&&A&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",v.name," → ",A.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>w(b.id),disabled:b.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>m(b.id),disabled:b.sequence===i.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>x(b.id),children:R?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:()=>p(b.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),R&&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:b.source.name,onValueChange:k=>{const O=n.find(T=>T.name===k);h(b.id,{source:{connectionId:(O==null?void 0:O.connectionId)||"",connectionType:(O==null?void 0:O.connectionType)||"none",type:(O==null?void 0:O.type)||"table",name:k,database:O==null?void 0:O.database,schema:O==null?void 0:O.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:f(b.id).map(k=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:k.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:k.type}),k.name]})},k.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:b.joinType,onValueChange:k=>h(b.id,{joinType:k}),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:b.target.name,onValueChange:k=>{const O=n.find(T=>T.name===k);h(b.id,{target:{connectionId:(O==null?void 0:O.connectionId)||"",connectionType:(O==null?void 0:O.connectionType)||"none",type:(O==null?void 0:O.type)||"table",name:k,database:O==null?void 0:O.database,schema:O==null?void 0:O.schema}})},disabled:!b.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:b.source.name?j(b.source.name).map(k=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:k.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:k.type}),k.name,k.name===b.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},k.name)):[]})]})]})]}),b.source.name&&b.target.name&&v&&A&&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:()=>y(b.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),b.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:b.joinKeyGroups.map((k,O)=>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 ",O+1]}),O>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:k.operator,onValueChange:T=>F(b.id,O,T),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:()=>D(b.id,O),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[k.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:k.keys.map((T,P)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[P>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:k.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:T.source.name,onValueChange:$=>E(b.id,O,P,"sourceColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:M(b.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:T.operator,onValueChange:$=>E(b.id,O,P,"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:T.target.name,onValueChange:$=>E(b.id,O,P,"targetColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:M(b.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:()=>C(b.id,O,P),children:e.jsx(s.X,{className:"size-3.5"})})]},T.id||P))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>N(b.id,O),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},k.id))})]})]})]},b.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{l(),c()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:c,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>a(i),disabled:!I(),children:"Save"})]})]})}function Is({children:t,open:n,onOpenChange:a,joinPlan:l,availableDataSources:c,onRemove:d,onSave:r,onCancel:i}){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(wt,{joinPlan:l,availableDataSources:c,onSave:r,onCancel:i,onRemove:d})]}),t]})}function Tt({joins:t,baseEntityId:n,availableDataSources:a,generateSQLPreview:l}){return e.jsxs("div",{className:"max-h-[400px] divide-y divide-border overflow-y-auto",children:[t.length>0&&e.jsxs("div",{className:"p-4",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 c=[...t].sort((r,i)=>r.sequence-i.sequence),d=a.find(r=>r.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"})]}),c.map(r=>{const i=a.find(o=>o.name===r.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:r.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:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.name})]})]},r.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((c,d)=>c.sequence-d.sequence).map((c,d)=>{const r=a.find(u=>u.name===c.source.name),i=a.find(u=>u.name===c.target.name),o=c.joinKeyGroups.reduce((u,g)=>u+g.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:c.joinType}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto shrink-0 text-xs",children:[o," condition",o>1?"s":""]})]}),e.jsxs("div",{className:"mt-1 truncate pl-1 text-xs text-muted-foreground",children:[r==null?void 0:r.name," → ",i==null?void 0:i.name]})]},c.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:l()})})]})]})}function os({open:t,onOpenChange:n,variant:a="button"}={}){var y,F;const l=s.useEditorStore(D=>D.card),{autoJoinMetadata:c}=s.useDashboardCardQuery(l),d=s.useEditorStore(D=>D.actions.updateCardConfig),r=((y=l==null?void 0:l.config)==null?void 0:y.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[i,o]=L.useState(!1),u=t!==void 0,g=u?t:i,p=u?n:o,h=((F=l==null?void 0:l.dataSource)==null?void 0:F.selectedEntities)||[],w=D=>{d(l.id,{...l==null?void 0:l.config,joinPlan:D}),p(!1)},m=()=>{d(l.id,{...l==null?void 0:l.config,joinPlan:void 0})},x=()=>{p(!1)},f=()=>{const D=[...r.joins].sort((C,S)=>C.sequence-S.sequence),N=r.baseEntity;if(!N.name)return"SELECT * FROM table -- Please select a base entity";let E=`SELECT *
175
+ FROM ${N.name}`;return D.forEach(C=>{const S=h.find(b=>b.name===C.target.name);if(!S)return;const I=C.joinKeyGroups.filter(b=>b.keys&&b.keys.length>0).map(b=>{const v=b.keys.filter(A=>{var R,k,O,T;return((R=A.source)==null?void 0:R.name)&&((k=A.target)==null?void 0:k.name)&&((O=A.source)==null?void 0:O.entityName)&&((T=A.target)==null?void 0:T.entityName)}).map(A=>`${A.source.entityName}.${A.source.name} ${A.operator} ${A.target.entityName}.${A.target.name}`);return v.length>1?`(${v.join(` ${b.operator} `)})`:v[0]}).filter(Boolean),M=I.length>1?I.join(" OR "):I[0]||"condition_here";E+=`
176
+ ${C.joinType} JOIN ${S.name}
177
+ ON ${M}`}),E};if(h.length<2)return null;const j=r.joins.length>0&&e.jsx(s.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(Tt,{joins:r.joins,baseEntityId:r.baseEntity.name,availableDataSources:h,generateSQLPreview:f})});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:D=>{D.stopPropagation(),p(!0)},children:[e.jsx(s.Link,{className:"h-3 w-3"}),r.joins.length]}):e.jsxs(s.Button,{onClick:()=>p(!0),variant:"outline",className:"w-full bg-muted/50",children:[e.jsx(s.Link,{className:"mr-2 h-3.5 w-3.5"}),r.joins.length===0?"Configure Joins":r.joins.length===1?"Join":"Joins",r.joins.length>0&&e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-medium text-primary-foreground",children:r.joins.length}),(c==null?void 0:c.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"]})]})}),j]})}),e.jsx(Is,{open:g,onOpenChange:p,joinPlan:r,availableDataSources:h,onSave:w,onCancel:x,onRemove:m,children:e.jsx("div",{})})]})}function Et({open:t,onOpenChange:n}){const[a,l]=L.useState([]),{updateDataSource:c}=s.useEditorActions(),d=s.useDashboardStore(m=>m.dashboard.aiContext),r=(d==null?void 0:d.selectedEntities)||[];L.useEffect(()=>{t&&l([])},[t]);const i=m=>{l(x=>x.some(j=>j.name===m.name&&j.type===m.type)?x.filter(j=>!(j.name===m.name&&j.type===m.type)):[...x,m])},o=()=>{l([...r])},u=()=>{l([])},g=()=>{if(a.length===0)return;const m=a[0],x=m.connectionId||"",f=m.connectionType||"",y=a.some(D=>D.type==="dataset")?"semanticDomain":"database";c({connectionId:x,connectionType:f,mode:y,selectedEntities:a}),n(!1)},p=m=>"label"in m&&m.label?m.label:m.name,h=m=>{if("description"in m&&m.description)return m.description;const x=[];return m.database&&x.push(m.database),m.schema&&x.push(m.schema),m.name&&x.push(m.name),x.join(".")},w=m=>a.some(x=>x.name===m.name&&x.type===m.type);return r.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:o,disabled:a.length===r.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:u,disabled:a.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[a.length," of ",r.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:r.map((m,x)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",w(m)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:w(m),onCheckedChange:()=>i(m)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:s.getEntityIcon(m.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:p(m)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:h(m)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:m.type})]},`${m.type}-${m.name}-${x}`))})})]}),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:g,disabled:a.length===0,children:["Select"," ",a.length>0?`(${a.length})`:""]})]})})})]})})}function is({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((l,c)=>{const d=s.getEntityDetails(l),r=d.find(o=>o.label==="Description"&&o.value),i=d.filter(o=>o.label==="Description"?!1:a?!0:!["Connection","Database","Schema"].includes(o.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(l)}),r&&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:r.value})]}),i.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:i.map((o,u)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[o.label,":"]}),e.jsx("span",{className:"font-mono",children:o.value})]},u))})]},`remaining-${l.type}-${l.name}-${c}`)})})]})})}function As(t,n){const[a,l]=L.useState(()=>{const c=localStorage.getItem(t);return c?JSON.parse(c):n});return L.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,l]}function Ds({isVisible:t}){var x,f;const n=s.useEditorStore(j=>j.isDevMode);s.useSyncLegacyEditorState();const[a,l]=L.useState(!1),[c,d]=L.useState(!1),[r,i]=As("semaphor:data-source-collapsed",!1),o=s.useEditorStore(j=>j.card.dataSource),u=s.useEditorStore(j=>{var y,F;return(F=(y=j.card)==null?void 0:y.config)==null?void 0:F.joinPlan}),{updateDataSource:g}=s.useEditorActions(),p=((x=o==null?void 0:o.selectedEntities)==null?void 0:x.length)||0,h=((f=u==null?void 0:u.joins)==null?void 0:f.length)||0,m={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...o,selectedEntities:(o==null?void 0:o.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[p===0&&h===0?e.jsx("div",{className:"p-4 px-6",children:e.jsxs(s.Button,{className:"w-full bg-muted/50",variant:"outline",onClick:()=>l(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),"Choose Dataset"]})}):e.jsxs("div",{children:[e.jsxs("div",{className:s.cn("flex cursor-pointer items-center justify-between px-6 pt-3",!r&&"pb-3"),onClick:()=>i(!r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Data Source"}),r&&e.jsxs("div",{className:"flex items-center gap-1.5",onClick:j=>j.stopPropagation(),children:[p>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:()=>l(!0),children:[e.jsx(s.Database,{className:"h-3 w-3"}),p]})}),e.jsx(is,{entities:m.selectedEntities,title:`${p} selected ${p===1?"entity":"entities"}`})]})}),h>0&&!n&&e.jsx(os,{variant:"badge"})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:j=>{j.stopPropagation(),i(!r)},children:r?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronUp,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:s.cn("overflow-hidden transition-all duration-200 ease-in-out",r?"max-h-0 opacity-0":"max-h-96 opacity-100"),children:[e.jsx("div",{className:"px-6 pb-2",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-muted/50",variant:"outline",onClick:()=>l(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),p===1?"Dataset":"Datasets",e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-medium text-primary-foreground",children:p})]})}),e.jsx(is,{entities:m.selectedEntities,title:`${p} selected ${p===1?"entity":"entities"}`})]})})}),!n&&e.jsx("div",{className:"px-6 pb-2",children:e.jsx(os,{})})]})]}),e.jsx(s.FieldsSection,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(o==null?void 0:o.selectedEntities)||[],dialogMode:"dataSource",open:a,onOpenChange:l,dataSource:m}),e.jsx(Et,{open:c,onOpenChange:d})]})}function Ye({error:t,errorSql:n,onSendFeedback:a,onOpenInEditor:l,className:c,showFeedbackButton:d=!0,errorTitle:r="Query Error"}){const[i,o]=L.useState(!1);return e.jsx("div",{className:s.cn("rounded-lg border border-destructive/30 bg-destructive/5 p-4",c),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(s.CircleAlert,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-destructive"}),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-destructive",children:r}),e.jsxs("div",{className:"relative rounded-md bg-background/60 p-3",children:[e.jsx(s.CopyButton,{text:t,className:"absolute right-2 top-2 h-6 w-6 z-10"}),e.jsx("div",{className:"max-h-40 overflow-auto pr-10",children:e.jsx("p",{className:"font-mono text-xs text-foreground/80 break-all",children:t})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.jsx(s.Collapsible,{open:i,onOpenChange:o,children:e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",children:i?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"]})})})}),l&&n&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:l,children:[e.jsx(Es,{className:"mr-1.5 h-3.5 w-3.5"}),"Open in Editor"]}),d&&a&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:a,children:[e.jsx(s.MessageSquareWarning,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Feedback"]})]}),n&&e.jsx(s.Collapsible,{open:i,onOpenChange:o,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:"Error SQL Query"}),e.jsx(s.CopyButton,{text:n,className:"h-6 w-6"})]}),e.jsx("div",{className:"rounded-md bg-background/60 p-2 max-h-80 overflow-auto",children:e.jsx(s.CodeHighlighter,{code:n,language:"sql"})})]})})})]})]})})}function Ls({sql:t,error:n,errorSql:a,onDebugWithAssistant:l}){const c=s.useEditorStore(x=>x.isDevMode),{setIsDevMode:d,setCardSql:r,setRunSql:i}=s.useEditorActions(),[o,u]=L.useState(!1),g=s.useEditorStore(x=>x.card),p=s.useEditorStore(x=>x.frame),h=s.useDashboardStore(x=>x.selectedSheetId),w=s.useDashboardStore(x=>{var f;return(f=x.dashboard)==null?void 0:f.id});function m(x){d(!0),r(x||t),setTimeout(()=>{i(!0)},100)}return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col pt-4",children:[!c&&t&&!n&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:()=>m(),variant:"secondary",size:"sm",children:[e.jsx(Es,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),e.jsxs(s.Button,{onClick:()=>u(!o),variant:"outline",size:"sm",children:[e.jsx(s.Info,{className:"mr-2 h-4 w-4"}),"Card Details"]})]}),o&&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:()=>u(!1),children:e.jsx(ws,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Card ID"}),e.jsx("code",{className:"text-xs font-mono",children:g.id||"N/A"})]}),e.jsx(s.CopyButton,{text:g.id||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Frame ID"}),e.jsx("code",{className:"text-xs font-mono",children:p.id||"N/A"})]}),e.jsx(s.CopyButton,{text:p.id||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Sheet ID"}),e.jsx("code",{className:"text-xs font-mono",children:h||"N/A"})]}),e.jsx(s.CopyButton,{text:h||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Dashboard ID"}),e.jsx("code",{className:"text-xs font-mono",children:w||"N/A"})]}),e.jsx(s.CopyButton,{text:w||"",className:"h-6 w-6"})]})]})]})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto text-xs leading-relaxed text-foreground/80",children:[n&&e.jsx(Ye,{error:n,errorSql:a,showFeedbackButton:!1,onOpenInEditor:()=>m(a)}),!n&&t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute right-2 top-2 z-10",children:e.jsx(s.CopyButton,{text:t,className:"h-6 w-6"})}),e.jsx(s.CodeHighlighter,{code:t,language:"sql"})]})})]}),n&&l&&e.jsx("div",{className:"mt-3",children:e.jsxs(s.Button,{onClick:l,size:"sm",variant:"outline",children:[e.jsx(ot,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})})]})}function kt({sql:t,error:n,errorSql:a,onDebugWithAssistant:l}){return e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(ws,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"flex w-[700px]",children:e.jsx(Ls,{errorSql:a,sql:t,error:n,onDebugWithAssistant:l})})]})}function It(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 Ms(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(x=>x.theme),l=s.useEditorStore(x=>x.frame),c=s.useEditorStore(x=>x.card),d=s.useEditorStore(x=>x.activeTabCardId),r=s.Le(),{refetch:i}=s.useDashboardCardQuery(c),{updateCardTab:o,setRunSql:u}=s.useEditorActions(),g=L.useRef(void 0),p=L.useRef({}),h=l.cards.find(x=>x.id===d),w=L.useCallback(()=>{let x="";return t==="python"&&(x=(h==null?void 0:h.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(x=(h==null?void 0:h.sql)||""),x},[t,h]);L.useEffect(()=>{if(d&&c.id&&c.id!==d){if(g.current&&r){const x=g.current.getModel();x&&(p.current[c.id]=x);let f=p.current[d];if(!f){const j=w();f=r.editor.createModel(j,t),p.current[d]=f}g.current.setModel(f)}o(d,c),u(!0)}},[d,c,o,r,u,t,w]),L.useEffect(()=>{if(!r)return;const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",f=a==="system"?x:a;r.editor.defineTheme("default",{base:f==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":f==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),r.editor.setTheme("default")},[n,a,r]),L.useEffect(()=>{const x=g.current;x&&r&&c&&x.addCommand(r.KeyMod.Shift|r.KeyCode.Enter,function(){return i(),!1})},[r,i,c]);function m(x,f){if(g.current=x,!p.current[c.id]){const j=x.getModel(),y=w();p.current[c.id]=j||(f==null?void 0:f.editor.createModel(y,t))||x.getModel()}x.setModel(p.current[c.id])}return{handleEditorDidMount:m}}function At(){const t=s.useEditorStore(r=>r.card.sql),n=s.useEditorStore(r=>r.sqlGen),{setCardSql:a,setSqlGen:l}=s.useEditorActions(),{handleEditorDidMount:c}=Ms("sql");function d(r){a(r),s.isObjectEmpty(n)||l({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!t&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] 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:d,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:c})]})}function Dt(){const t=s.useEditorStore(c=>c.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=Ms("python");function l(c){n(c)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:l,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function Lt(){const t=s.useQueryClient(),{isConsoleMode:n}=s.useDashboardPreferences(),[a,l]=L.useState(!1);s.useEditorStore(B=>B.frame);const c=s.useEditorStore(B=>B.card);s.useEditorStore(B=>B.isShowingVisual),s.useEditorStore(B=>B.selectedConnectionId),s.useEditorStore(B=>B.tempQueryData),s.useEditorStore(B=>B.selectedDatabaseName),s.useEditorStore(B=>B.selectedDatamodelId),s.useEditorStore(B=>B.selectedSchemaName);const d=s.useEditorStore(B=>B.showAIDialog);s.useEditorStore(B=>B.selectedTableName);const r=s.useEditorStore(B=>{var U;return(U=B==null?void 0:B.card)==null?void 0:U.sql}),i=s.useEditorStore(B=>{var U;return(U=B==null?void 0:B.card)==null?void 0:U.python}),{cardFilterValues:o}=s.useCardFilterValues((c==null?void 0:c.id)??""),u=s.useDashboardStore(B=>B.inlineFilterValuesMap[(c==null?void 0:c.id)??""]),g=L.useRef(!0),{setCardCustomCfg:p,setQueryResultColumns:h,setCardSql:w,setTempQueryData:m,setPythonStdOut:x,setCardPreferences:f,setCardType:j,setCardPython:y,runAssistant:F,setShowAIDialog:D,setCard:N,updateCardInFrame:E}=s.useEditorActions();s.useEditorStore(B=>B.onSave),s.useEditorStore(B=>B.onClose),s.useEditorStore(B=>B.actions.setSqlGen);const C=s.useEditorStore(B=>B.runSql),S=s.useEditorStore(B=>B.actions.setRunSql),I=s.useEditorStore(B=>B.actions.setIsSqlRunning),{data:M,isLoading:b,isFetching:v,isSuccess:A,isError:R,error:k,errorSql:O,queryKey:T,refetch:P,errorMessage:$}=s.useDashboardCardQuery(c);L.useEffect(()=>{if(M&&(M.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),x((M==null?void 0:M.output)||""),M.records.length>0)){const{dimensionKeys:B}=s.getKeys(M.records);h(B)}},[M,h,x]),L.useEffect(()=>{(b||v)&&I(!0),(R||A)&&I(!1),R&&(h([]),x(""))},[b,v,M,x,R,A,I,h,k]),L.useEffect(()=>{C&&(t.getQueryData(T)||P(),S(!1))},[C,P,S,T,t]);const H=L.useRef(P);H.current=P,L.useEffect(()=>{if(g.current){g.current=!1;return}H.current()},[u]);async function q(){const B=`Can you help me debug this query?
178
+
179
+ Error:
180
+
181
+ ${$}
182
+
183
+ Error SQL:
184
+
185
+ ${O}
186
+
187
+ Query:
188
+
189
+ ${r}
190
+
191
+ ${i?`Python:
192
+ ${i}`:""}
193
+ `;F(B)}function K(){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:a?20:100,className:"relative flex grow",children:[e.jsx("div",{id:"sql-container",className:"relative flex w-[99%]",children:e.jsx(At,{})}),a&&e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"sql"})]}),a&&e.jsxs(e.Fragment,{children:[e.jsx(s.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(s.ResizablePanel,{id:"2",order:2,defaultSize:80,className:"relative flex grow",children:[e.jsx("div",{id:"python-container",className:"relative flex w-[99%] pt-0",children:e.jsx(Dt,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function _(){var B,U,V,W,X,se;return e.jsx("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:e.jsxs("div",{className:"flex grow items-center gap-4",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:b||v,onClick:()=>{P()},className:"h-8 shrink-0",size:"sm",children:[b||v?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"]}),e.jsx(kt,{errorSql:O,sql:M==null?void 0:M.sql,error:$,onDebugWithAssistant:q}),e.jsx(He.EditorClearButton,{}),e.jsxs(s.Toggle,{pressed:a,onPressedChange:J=>l(J),className:"h-8",size:"sm",variant:"outline",children:[e.jsx(It,{className:"mr-2 size-4 text-foreground/70"}),"Python"]}),!d&&e.jsxs("button",{disabled:d,onClick:()=>{D(!0)},className:"flex h-8 w-full cursor-text items-center justify-start rounded-md bg-muted/50 px-3 text-left text-sm text-muted-foreground",children:[e.jsx(s.Sparkles,{className:"mr-3 size-4 text-foreground/70"}),"Type your question..."]}),e.jsxs("div",{className:"flex flex-1 items-center justify-end gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Checkbox,{id:"pagination",checked:((U=(B=c.preferences)==null?void 0:B.tablePrefs)==null?void 0:U.enableDevModePagination)??!1,onCheckedChange:J=>{var te;f({...c.preferences,tablePrefs:{...(te=c.preferences)==null?void 0:te.tablePrefs,enableDevModePagination:J}})}}),e.jsx(s.Label,{htmlFor:"pagination",className:"cursor-pointer text-sm",children:"Paginate"}),((W=(V=c.preferences)==null?void 0:V.tablePrefs)==null?void 0:W.enableDevModePagination)&&e.jsxs(s.Select,{value:String(((se=(X=c.preferences)==null?void 0:X.tablePrefs)==null?void 0:se.pageSize)||50),onValueChange:J=>{var le,de,z;const te=Number(J),Q={...c,preferences:{...c.preferences,tablePrefs:{...(le=c.preferences)==null?void 0:le.tablePrefs,pageSize:te}},paginationConfig:{page:1,pageSize:te}};N(Q),E(Q),c.sql&&((z=(de=c.preferences)==null?void 0:de.tablePrefs)!=null&&z.enableDevModePagination)&&S(!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"})]})]})]}),o&&o.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:o.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(o,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:K()}),_()]})}const Mt=[{value:"table",label:"Table",icon:s.Table2},{value:"aggregateTable",label:"Aggregate",icon:s.Layers},{value:"pivotTable",label:"Pivot",icon:s.Grid3x3}];function Ot({className:t}){const n=s.useEditorStore(o=>o.card),{setCardType:a,setCard:l,updateCardInFrame:c}=s.useEditorActions(),d=["table","aggregateTable","pivotTable"].includes(n.type),r=s.hasValidCardConfig(n.config);if(!d||!r)return null;const i=o=>{var g;const u=o;if(u==="aggregateTable"&&((g=n.config)!=null&&g.pivotByColumns)&&n.config.pivotByColumns.length>0){const p={...n,type:u,config:{...n.config,pivotByColumns:[]}};l(p),c(p)}else{a(u);const p={...n,type:u};c(p)}};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsx(s.RadioGroup,{value:n.type,onValueChange:i,className:"flex flex-row items-center justify-between gap-1 rounded-lg border p-1",children:Mt.map(o=>{const u=o.icon,g=n.type===o.value;return e.jsxs("div",{className:"flex items-center",children:[e.jsx(s.RadioGroupItem,{value:o.value,id:`table-type-${o.value}`,className:"peer sr-only"}),e.jsxs(s.Label,{htmlFor:`table-type-${o.value}`,className:s.cn("flex cursor-pointer items-center gap-1.5 rounded-md px-3 py-1 text-sm font-medium transition-all",g?"bg-muted text-foreground shadow-sm":"text-muted-foreground hover:bg-muted/50"),children:[e.jsx(u,{className:"h-3.5 w-3.5"}),o.label]})]},o.value)})})})}function Rt({type:t,isLinked:n,className:a}){const l=s.useDashboardStore(h=>h.selectedFrameId),c=s.useManagementStore(h=>h.selectedVisual),d=s.useEditorStore(h=>h.frame);let r;if(t)r=t;else if(n!==void 0)r=n?"linked":"library";else if(!!!(d!=null&&d.visualId||c!=null&&c.id)&&l)r="local";else if(c&&!l)r="library";else if(d!=null&&d.visualId&&l)r="linked";else if(c!=null&&c.id&&l)r="library";else return null;if(r==="local")return null;const i={linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},o={linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},u={linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},g={linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},p={linked:e.jsx(dt,{className:"h-3.5 w-3.5"}),library:e.jsx(ct,{className:"h-3.5 w-3.5"})};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",i[r],a),children:p[r]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",u[r]),children:[e.jsx(s.TooltipArrow,{className:g[r]}),e.jsx("p",{children:o[r]})]})]})})}function Os({className:t,...n}){var q,K,_;const a=s.useEditorStore(B=>B.card),l=((q=a.customCardPreferences)==null?void 0:q.showCardHeader)??!0,c=((_=(K=a.preferences)==null?void 0:K.displayOptions)==null?void 0:_.showInlineFilterBar)??!0,d=s.useEditorStore(B=>B.frame),r=s.useDashboardStore(B=>B.dashboard.filters),i=s.useDashboardStore(B=>B.selectedSheetId),[o,u]=L.useState(!1),{currentUser:g}=s.useCurrentUserInfo(),{tokenProps:p}=L.useContext(s.SemaphorContext),h=s.useEditorStore(B=>B.actions.setRunSql),{updateFilter:w}=s.useDashboardActions(),m=r==null?void 0:r.find(B=>B.id===d.filterId),{data:x,isLoading:f,isFetching:j,errorMessage:y,errorSql:F,pagination:D}=s.useDashboardCardQuery(a),N=L.useMemo(()=>(x==null?void 0:x.records)||[],[x==null?void 0:x.records]),{setCard:E,updateCardInFrame:C,setIsDevMode:S,setCardSql:I}=s.useEditorActions(),{data:M}=s.useTopoJson(a),b=L.useMemo(()=>{var B;return a.type!=="pivotTable"||!((B=x==null?void 0:x.records)!=null&&B.length)?null:{records:x.records,columnSubtotalMeta:x.columnSubtotalMeta,subtotalColumns:x.subtotalColumns||[],pivotSchema:x.pivotSchema||[],groupByColumns:x.groupByColumns}},[a.type,x==null?void 0:x.records,x==null?void 0:x.columnSubtotalMeta,x==null?void 0:x.subtotalColumns,x==null?void 0:x.pivotSchema,x==null?void 0:x.groupByColumns]),v=s.usePivotTableConfig(a,b),A=B=>{S(!0),I(B||F||a.sql||a.python||""),setTimeout(()=>{h(!0)},100)},R=()=>{u(!0)},k=L.useMemo(()=>{const B=typeof window<"u"?window.location.href:"",U=typeof navigator<"u"?navigator.userAgent:"",V=typeof window<"u"?`${window.innerWidth}x${window.innerHeight}`:"";return{category:s.FeedbackCategory.QUERY_GENERATION,user:g,tokenContext:p,systemState:{cardConfig:a.config,dataSource:a.dataSource,dashboardFilters:r,errorMessage:y||void 0,errorSql:F||a.sql||a.python,generatedSql:F||a.sql},metadata:{url:B,userAgent:U,timestamp:new Date().toISOString(),viewport:V}}},[g,p,a,r,y,F]),O=(B,U)=>{var W,X;const V={...a,paginationConfig:{page:B+1,pageSize:U}};E(V),C(V),a.sql&&((X=(W=a.preferences)==null?void 0:W.tablePrefs)!=null&&X.enableDevModePagination)&&h(!0)},T=B=>{var W,X,se,J;const U=s.sortStateToSortByColumns(B,(W=a.config)==null?void 0:W.metricColumns,(X=a.config)==null?void 0:X.groupByColumns),V={...a,config:{...a.config||{},sortByColumns:U}};E(V),C(V),a.sql&&((J=(se=a.preferences)==null?void 0:se.tablePrefs)!=null&&J.enableDevModePagination)&&h(!0)},P=L.useMemo(()=>!a.id||!(x!=null&&x.records)?null:s.createChartConfig({card:a,data:x==null?void 0:x.records,cardType:a.type,queryConfig:a.queryConfig,customCfg:a.customCfg,preferences:a.preferences,topoJson:M}),[a.id,x==null?void 0:x.records,a.type,a.customCfg,a.preferences,M]);function $(B){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(s.EditorCustomVisual,{card:B})})}function H(){if(x!=null&&x.records&&(x==null?void 0:x.records.length)===0&&!f&&!j)return y?e.jsx("div",{className:"flex h-full flex-col items-start justify-start overflow-auto p-4",children:e.jsx(Ye,{error:y,errorSql:F||a.sql||a.python,onOpenInEditor:A,onSendFeedback:R,showFeedbackButton:!0,errorTitle:"Unable to Create Visual"})}):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((f||j)&&(!(x!=null&&x.records)||x.records.length===0))return a.type==="table"?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(!a.id)return null;if(a.type==="custom")return $(a);if(!["table","pivotTable","aggregateTable","custom"].includes(a.type)&&P)return e.jsx("div",{className:"relative h-full min-h-0 w-full flex-1 grow basis-0",children:f||j?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:P})});if(a.type==="table")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:a,data:N,paginationMetadata:D,onPaginationChange:O,onSortChange:T,isLoading:f||j})});if(a.type==="pivotTable"&&v)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:a,data:v.data,options:v.options,onAggregationChange:B=>{const U=s.handleAggregationChange(B,a.config),V={...a,config:U};E(V),C(V)},onAggregationLabelChange:B=>{const U=s.handleAggregationLabelChange(B,a.config),V={...a,config:U};E(V),C(V)}})});if(a.type==="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:a,data:(x==null?void 0:x.records)||[],groupByColumns:x==null?void 0:x.groupByColumns,pivotSchema:x==null?void 0:x.pivotSchema,paginationMetadata:D,onPaginationChange:O,onAggregationChange:B=>{const U=s.handleAggregationChange(B,a.config),V={...a,config:U};E(V),C(V)},isLoading:f||j})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...n,children:[(f||j)&&(x==null?void 0:x.records)&&x.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"})}),l&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",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=>E({...a,title:B}),isEditable:!0,placeholder:"Add title",displayClassName:"text-base font-semibold",inputClassName:"text-base font-semibold"})}),e.jsx(Rt,{}),e.jsx("div",{className:"ml-auto",children:e.jsx(Ot,{})})]}),e.jsx("div",{className:"w-1/2",children:e.jsx(s.EditableText,{value:a.description||"",onSave:B=>E({...a,description:B}),isEditable:!0,placeholder:"Add description",displayClassName:"text-sm text-muted-foreground",inputClassName:"text-sm"})})]}),m&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Label,{className:"my-1",children:e.jsx(s.EditableText,{value:m.title||m.column,onSave:B=>w({...m,title:B}),isEditable:!0,placeholder:"Filter",displayClassName:"text-sm",inputClassName:"text-sm"})}),e.jsx(s.FilterComponent,{filter:m})]})]}),c&&a.inlineFilters&&a.inlineFilters.length>0&&e.jsx("div",{className:"px-6 pb-3",children:e.jsx(s.InlineFilterBar,{card:a,sheetId:i||""})}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:H()}),e.jsx(s.FeedbackDialog,{open:o,onOpenChange:u,feedbackData:k,showDebugInfo:!0})]})}const ze=({language:t,value:n,onChange:a,readonly:l})=>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:l},defaultLanguage:t,value:n,onChange:a}),Ft=()=>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."})]})]}),Bt=({customCode:t,cardCustomCfgString:n,mergedConfig:a,onConfigChange:l,onCodeChange:c})=>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(ze,{language:"json",value:a,onChange:l})}),e.jsx(s.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(ze,{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(ze,{language:"javascript",value:t,onChange:c})})]}),Pt=({error:t,hasCardCustomConfig:n,onReset:a,onApply:l,onClose:c})=>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:l,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:c,variant:"outline",children:"Close"})]});function Vt(){const[t,n]=L.useState(!1),[a,l]=L.useState(""),[c,d]=L.useState(""),[r,i]=L.useState(""),[o,u]=L.useState(""),g=s.useEditorStore(N=>N.card),p=s.useEditorStore(N=>N.card.customCfg),h=p?JSON.stringify(p,null,2):"",{data:w}=s.useDashboardCardQuery(g),{data:m}=s.useTopoJson(g),{setCardCustomCfg:x,setCustomVisualCode:f}=s.useEditorActions(),j=N=>{var E,C;return JSON.stringify({...N,data:{...N.data,datasets:(C=(E=N.data)==null?void 0:E.datasets)==null?void 0:C.map(S=>({...S,data:[]}))}},null,2)},y=()=>{var E,C;if(!((E=w==null?void 0:w.records)!=null&&E.length))return;const N=s.createChartConfig({card:g,data:w.records,cardType:g.type,queryConfig:g.queryConfig,preferences:g.preferences,topoJson:m});if(N){l(j(N)),i(((C=g.preferences)==null?void 0:C.customVisualCode)||"");const S=s.merge(N,p);d(j(S))}},F=()=>{try{if(r&&f(r),c){const N=JSON.parse(c),E=s.getObjectDiff(JSON.parse(a),N);x(E),u("")}}catch{u("Invalid JSON configuration")}},D=Object.keys(p||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:n,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:y,className:D?"":"text-green-600 hover:text-green-700",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(Ft,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Os,{className:"w-1/2 rounded shadow-none"})}),e.jsx(Bt,{customCode:r,cardCustomCfgString:h,mergedConfig:c,onConfigChange:N=>d(N??""),onCodeChange:N=>i(N??"")})]}),e.jsx(Pt,{error:o,hasCardCustomConfig:!!p,onReset:()=>{d(a),x(null)},onApply:F,onClose:()=>n(!1)})]})]})}function zt({isStarred:t,onClick:n,className:a}){const l=c=>{c.stopPropagation(),c.preventDefault(),n(c)};return e.jsx("button",{type:"button",onClick:l,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 cs({chartType:t,chartName:n,isCustom:a=!1,pluginName:l,isStarred:c,showStar:d=!0,onSelect:r,onToggleStar:i}){return e.jsxs("button",{onClick:r,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",c?"opacity-100":"opacity-0 group-hover:opacity-100"),children:e.jsx(zt,{isStarred:c,onClick:()=>i()})}),a&&l&&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:l})]})}),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 ds=[{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:"kpi",name:"KPI"},{id:"text",name:"Text"},{id:"map",name:"Map"}];function Rs({onChartSelect:t,onClose:n}){const[a,l]=L.useState(""),{starredCharts:c,isStarred:d,toggleStar:r}=s.useStarredChartsStore(),{data:i=[],isLoading:o}=s.useCustomVisualsQuery(),{setCardType:u,setCardPreferences:g,setIsDevMode:p}=s.useEditorStore(N=>N.actions),{setCardCustomCfg:h,setCustomCardPreferences:w,setQueryConfig:m}=s.useEditorActions(),x=L.useMemo(()=>{if(!a)return ds;const N=a.toLowerCase();return ds.filter(E=>E.name.toLowerCase().includes(N))},[a]),f=L.useMemo(()=>{const N=i.filter(C=>C.componentType==="chart");if(!a)return N;const E=a.toLowerCase();return N.filter(C=>C.name.toLowerCase().includes(E))},[i,a]),j=N=>{h(null),g({}),u(N),["custom","text","map"].includes(N)&&(p(!0),m(void 0)),t==null||t(N),n==null||n()},y=N=>{h(null),g({}),u("custom"),w({type:"component",visualType:"single",url:N.url,componentName:N.name,icon:N.icon,pluginChartType:N.chartType}),m(void 0),t==null||t("custom",N),n==null||n()},F=N=>{const E={type:"default",id:N.id,name:N.name};r(E)},D=N=>{const E={type:"custom",id:N.name,url:N.url,icon:N.icon,name:N.name};r(E)};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,{placeholder:"Search charts...",value:a,onChange:N=>l(N.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-[400px] overflow-y-auto",children:[x.length>0&&e.jsxs("div",{className:"mb-3",children:[e.jsx("span",{className:"mb-2 block text-xs font-medium text-muted-foreground",children:"Default Charts"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:x.map(N=>e.jsx(cs,{chartType:N.id,chartName:N.name,isCustom:!1,isStarred:d("default",N.id),onSelect:()=>j(N.id),onToggleStar:()=>F(N)},N.id))})]}),f.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-3"}),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:f.map((N,E)=>e.jsx(cs,{chartName:N.name,isCustom:!0,pluginName:N.pluginName,isStarred:d("custom",N.name),onSelect:()=>y(N),onToggleStar:()=>D(N)},`${N.url}-${N.name}-${E}`))})]})]}),o&&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..."})]}),x.length===0&&f.length===0&&!o&&e.jsx("div",{className:"py-8 text-center text-sm text-muted-foreground",children:"No charts found"})]})]})}function Fs({variant:t="ghost"}){var d,r;const[n,a]=L.useState(!1),l=s.useEditorStore(i=>i.card),c=l.type;return e.jsxs(s.Popover,{open:n,onOpenChange:a,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(s.SelectedChartIcon,{className:"size-4",chartType:c,customIcon:(d=l.customCardPreferences)==null?void 0:d.icon,componentName:(r=l.customCardPreferences)==null?void 0:r.componentName})})}),e.jsx(s.PopoverContent,{onOpenAutoFocus:i=>i.preventDefault(),className:"z-[70] w-[360px] p-3",children:e.jsx(Rs,{onClose:()=>a(!1)})})]})}function $t({error:t,className:n="",textClassName:a="",copyButtonClassName:l=""}){const[c,d]=L.useState(!1),r=L.useRef(null),i=L.useRef(!1);function o(){t&&!i.current&&navigator.clipboard.writeText(t)}function u(h){(h.key==="Enter"||h.key===" ")&&(h.preventDefault(),o())}function g(){const h=window.getSelection();if(h&&h.toString().trim()!==""){const w=h.toString();navigator.clipboard.writeText(w),d(!0),i.current=!0,setTimeout(()=>{d(!1),i.current=!1},1e3)}else i.current=!1}function p(){d(!1),i.current=!1}return e.jsxs("div",{className:`relative rounded-md border border-red-200 bg-red-50 p-3 dark:border-red-800 dark:bg-red-950/20 ${n}`,children:[e.jsx("div",{className:"float-right mb-2 ml-2",children:e.jsx(s.CopyButton,{text:t,className:`h-6 w-6 p-0 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 ${l}`})}),e.jsx("div",{ref:r,className:`cursor-pointer select-text break-all font-mono text-xs text-red-700 dark:text-red-300 ${a}`,onClick:o,onKeyDown:u,onMouseUp:g,onMouseDown:p,tabIndex:0,role:"button","aria-label":"Click to copy error message or select text to copy",children:t}),c&&e.jsx("div",{className:"absolute bottom-1 right-1 rounded bg-green-100 px-2 py-1 text-xs text-green-600 dark:bg-green-900/30 dark:text-green-400",children:"Copied!"}),e.jsx("div",{className:"clear-both"})]})}function qt(){const t=s.useEditorStore(o=>{var u,g;return(g=(u=o.card.preferences)==null?void 0:u.chartOptions)==null?void 0:g.indexAxis}),n=s.useEditorStore(o=>o.card.type),{setChartOrientation:a,setCardPreferences:l}=s.useEditorStore(o=>o.actions),c=o=>{if(a(o),n!=="bullet")return;const u=o==="y"?"horizontal":"vertical",g=s.useEditorStore.getState().card.preferences,p={...g||{},bulletConfig:{...(g==null?void 0:g.bulletConfig)||{},orientation:u}};l(p)};function d(){const o=t??"x",u=()=>{c(o==="x"?"y":"x")};return e.jsx(s.IconButton,{onClick:u,tooltip:"Chart Orientation",children:o==="x"?e.jsx(Ve,{className:"size-4"}):e.jsx(Pe,{className:"size-4"})})}function r(){const o=()=>{c(t==="y"||t===void 0?"x":"y")};return e.jsx(s.IconButton,{onClick:o,tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(Ve,{className:"size-4"}):e.jsx(Pe,{className:"size-4"})})}function i(){const o=t??"y",u=()=>{c(o==="y"?"x":"y")};return e.jsx(s.IconButton,{onClick:u,tooltip:"Chart Orientation",children:o==="y"?e.jsx(Pe,{className:"size-4"}):e.jsx(Ve,{className:"size-4"})})}return e.jsx(e.Fragment,{children:n==="funnel"?r():n==="bullet"?i():d()})}function Kt({className:t}){var w,m,x,f,j,y,F,D,N,E;const n=s.useEditorStore(C=>C.card),{setCardPreferences:a,updateCardInFrame:l,setCard:c}=s.useEditorActions(),[d,r]=L.useState(!1),i=((m=(w=n.preferences)==null?void 0:w.displayOptions)==null?void 0:m.showFilterInfo)??!0,o=((f=(x=n.preferences)==null?void 0:x.displayOptions)==null?void 0:f.showCardToolbar)??!0,u=((y=(j=n.preferences)==null?void 0:j.displayOptions)==null?void 0:y.showChrome)??!0,g=((D=(F=n.preferences)==null?void 0:F.displayOptions)==null?void 0:D.allowScroll)??!0,p=((E=(N=n.preferences)==null?void 0:N.displayOptions)==null?void 0:E.showInlineFilterBar)??!0,h=(C,S)=>{var b;const I={...n.preferences,displayOptions:{...(b=n.preferences)==null?void 0:b.displayOptions,[C]:S}};a(I);const M={...n,preferences:I};c(M),l(M)};return e.jsx("div",{className:s.cn("flex items-center",t),children:e.jsxs(s.DropdownMenu,{modal:!1,open:d,onOpenChange:r,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{className:"h-8 w-8 p-0",tooltip:"Display Options",children:e.jsx(ks,{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:i,onCheckedChange:C=>{h("showFilterInfo",C)},onSelect:C=>C.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:o,onCheckedChange:C=>{h("showCardToolbar",C)},onSelect:C=>C.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:u,onCheckedChange:C=>{h("showChrome",C)},onSelect:C=>C.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:g,onCheckedChange:C=>{h("allowScroll",C)},onSelect:C=>C.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:p,onCheckedChange:C=>{h("showInlineFilterBar",C)},onSelect:C=>C.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 Gt(){const[t,n]=L.useState(!1),a=s.useEditorStore(p=>p.card),l=s.useEditorStore(p=>p.selectedConnectionId),{setCard:c}=s.useEditorActions(),d=s.useDashboardStore(p=>p.actions.removeCardInlineFilterValue),r=(a==null?void 0:a.inlineFilters)||[];function i(p){const h=p.qualifiedFieldName||p.name;if(r.find(y=>y.column===h))return;const m=p.qualifiedFieldName?p.qualifiedFieldName.split(".").slice(0,-1).join("."):p.qualifiedEntityName||p.entityName,x=s.fmt(p.name),f=p.qualifiedFieldName||x,j={id:s.v4(),column:h,title:p.label||p.name,dataType:p.dataType,table:p.entityName||"",database:"",connectionId:l||"",operation:"in",sql:s.getDefaultFilterSql(p.dataType,m,f),width:250};c({...a,inlineFilters:[...r,j]})}function o(p){const h=r.filter(w=>w.id!==p);c({...a,inlineFilters:h}),d(a.id,p)}function u(p,h){const w=r.map(m=>m.id===p?{...m,...h}:m);c({...a,inlineFilters:w})}return["bar","line","pie","doughnut","table","stackedBar","stackedLine","horizontalBar","radar","polarArea","scatter","bubble","funnel","aggregateTable","custom"].includes(a==null?void 0:a.type)?e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs(s.Popover,{open:t,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.IconButton,{tooltip:"Add Inline Filter",className:s.cn("relative",{"text-primary":r.length>0}),children:[e.jsx(mt,{className:"h-4 w-4"}),r.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:r.length})]})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80 p-0",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:i,inlineFilters:r})})})}),r.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:r.map(p=>e.jsx(Ut,{filter:p,onUpdate:h=>u(p.id,h),onRemove:()=>o(p.id)},p.id))})]})]})})]})}):null}function Ut({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:l=>n(l),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 Bs(){const t=s.useEditorStore(d=>d.card),n=s.useEditorStore(d=>{var r,i;return(i=(r=d.card)==null?void 0:r.preferences)==null?void 0:i.chartOptions}),a=s.getChartGridStyle(n),{setChartGrid:l}=s.useEditorActions();function c(){const d=["xy","none","x","y"],i=(d.indexOf(a)+1)%d.length;l(d[i])}return e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center gap-2",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel","bullet"].includes(t.type)&&e.jsx(e.Fragment,{children:e.jsx(qt,{})}),!["kpi","text","custom","table"].includes(t.type)&&e.jsx(e.Fragment,{}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:c,children:[(a==="xy"||!a)&&e.jsx(s.Grid3x3,{className:"size-4"}),a==="x"&&e.jsx(Ts,{className:"size-4"}),a==="y"&&e.jsx(Je,{className:"size-4"}),a==="none"&&e.jsx(yt,{className:"size-4"})]}),e.jsx(Gt,{}),e.jsx(Kt,{})]})}function _t(){const t=s.useEditorStore(m=>m.frame),n=s.useEditorStore(m=>m.card),{setFrame:a,setActiveTabCardId:l,setCard:c,updateCardInFrame:d}=s.useEditorActions(),r=(m,x)=>{m.dataTransfer.setData("tabIndex",x.toString())},i=m=>{m.preventDefault()},o=(m,x)=>{const f=m.dataTransfer.getData("tabIndex");if(f===x.toString())return;const j=Array.from(t.cards),[y]=j.splice(parseInt(f),1);j.splice(x,0,y),a({...t,cards:j})};function u(m){const x=t.cards.filter(y=>y.id!==m),f=x[0],j={...t,cards:x,activeCardId:f.id};a(j),l(f.id),c(f)}function g(m,x){const f={...t,cards:[...t.cards,x],activeCardId:m.id};a(f),l(x.id)}function p(){const m={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};g(n,m)}function h(m){const x={dataSource:m.dataSource,connectionId:m.connectionId,lastSelectedDatabase:m.lastSelectedDatabase,lastSelectedSchema:m.lastSelectedSchema,lastSelectedTable:m.lastSelectedTable,lastSelectedDatamodelId:m.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[],mode:"explorer"};g(m,x)}function w(m,x){return m.cards.length===1&&(x.displayTab===!0||x.displayTab===void 0)||m.activeCardId!==x.id&&(x.displayTab===!0||x.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const f=x.displayTab===void 0?!1:!x.displayTab;c({...x,displayTab:f}),d({...x,displayTab:f})},children:x.displayTab===!0||x.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(at,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(s.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[t.cards.map((m,x)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:f=>r(f,x),onDragOver:i,onDrop:f=>o(f,x),className:"",value:m.id,children:[w(t,m),e.jsx(s.Editable,{enabled:t.activeCardId===m.id,text:m.tabTitle||m.title,onSave:f=>{c({...n,tabTitle:f}),d({...n,tabTitle:f})},children:m.tabTitle||m.title},m.id),t.activeCardId===m.id&&e.jsx(s.CopyPlus,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:f=>{f.stopPropagation(),p()}}),t.activeCardId===m.id&&t.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>u(m.id)})]},m.id)),e.jsx(s.IconButton,{tooltip:"Add Card",className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",onClick:()=>h(n),children:e.jsx(s.Plus,{className:"h-4 w-4"})})]})})}function _e(){const t=s.useEditorStore(f=>f.frame),n=s.useEditorStore(f=>f.card),a=s.useEditorStore(f=>f.isSqlRunning),l=s.useEditorStore(f=>f.isDevMode),{setFrame:c,setActiveTabCardId:d,setCard:r,setIsDevMode:i,setRunSql:o}=s.useEditorActions(),{data:u,isLoading:g,isFetching:p,isError:h}=s.useDashboardCardQuery(n);function w(f){const j=t.cards.find(y=>y.id===f);if(j!=null&&j.sql){l||i(!0),d(f);return}if(j!=null&&j.queryConfig){l&&i(!1),m(f),d(f);return}l||m(f),d(f)}function m(f){const j={...t,cards:t.cards.map(F=>F.id===n.id?n:F),activeCardId:f};c(j);const y=j.cards.find(F=>F.id===f);y.sql&&o(!0),r(y)}function x(){return n.type==="kpi"?g||p?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 border-border",children:e.jsx(s.KPICard,{card:n,data:u==null?void 0:u.records,isPending:g||p,isError:h})})}):n.type==="text"?g||p?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:a,card:n,data:u==null?void 0:u.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackVisual,children:e.jsx(Os,{className:"grow border-none shadow-none"})})}return e.jsxs(s.Tabs,{onValueChange:w,value:t.activeCardId,className:"flex grow flex-col",children:[t.cards.map(f=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:f.id,children:x()},f.id)),e.jsx(_t,{})]})}function us({children:t}){const n=s.useEditorStore(v=>v.frame),a=s.useEditorStore(v=>v.card),l=s.useEditorStore(v=>v.isDevMode),c=s.useEditorStore(v=>v.isShowingVisual),d=s.useDashboardStore(v=>v.isVisualEditing),r=s.useEditorStore(v=>v.pythonStdOut),i=s.useEditorStore(v=>v.actions.setRunSql),{setFrame:o,setCard:u,setActiveTabCardId:g,runAssistant:p,setIsDevMode:h,setCardPreferences:w}=s.useEditorActions(),{data:m,isLoading:x,isFetching:f,errorMessage:j,refetch:y,pagination:F}=s.useDashboardCardQuery(a),D=L.useMemo(()=>(m==null?void 0:m.records)||[],[m==null?void 0:m.records]),[N,E]=L.useState(!1);L.useEffect(()=>{f||E(!1)},[f]);function C(v,A){var O,T;const R={...a,paginationConfig:{page:v+1,pageSize:A}};u(R);const k={...n,cards:n.cards.map(P=>P.id===a.id?R:P)};o(k),a.sql&&((T=(O=a.preferences)==null?void 0:O.tablePrefs)!=null&&T.enableDevModePagination)&&i(!0)}function S(v){var O,T,P,$;const A=s.sortStateToSortByColumns(v,(O=a.config)==null?void 0:O.metricColumns,(T=a.config)==null?void 0:T.groupByColumns),R={...a,config:{...a.config||{},sortByColumns:A}};u(R);const k={...n,cards:n.cards.map(H=>H.id===a.id?R:H)};o(k),a.sql&&(($=(P=a.preferences)==null?void 0:P.tablePrefs)!=null&&$.enableDevModePagination)&&i(!0)}function I(){const v=JSON.stringify(m==null?void 0:m.records,null,2),A=new Blob([v],{type:"application/json"}),R=URL.createObjectURL(A),k=document.createElement("a");k.href=R,k.download=`${a.title}.json`,k.click()}function M(){const A=[Object.keys(m==null?void 0:m.records.reduce((T,P)=>({...T,...P}),{})).join(","),...((m==null?void 0:m.records)||[]).map(T=>Object.values(T).join(","))].join(`
194
+ `),R=new Blob([A],{type:"text/csv"}),k=URL.createObjectURL(R),O=document.createElement("a");O.href=k,O.download=`${a.title}.csv`,O.click()}function b(){const v=`Can you get the documentation for ${a.type} chart?`;p(v)}return a?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 px-6",children:[c&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(Fs,{}),d&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:b,children:e.jsx(st,{className:"size-4"})}),!["table","custom"].includes(a.type)&&d&&e.jsx(Vt,{})]}),!c&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:M,children:e.jsx(s.PiFileCsv,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:I,children:e.jsx(nt,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(m==null?void 0:m.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(s.IconButton,{tooltip:"Refresh",disabled:x||f,onClick:()=>{E(!0),y()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":N})})}),e.jsx(Bs,{})]}),l&&e.jsx(Jt,{})]}),c?e.jsx(_e,{}):e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[r&&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:r&&e.jsx(Ht,{})}),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",{"px-6":r}),children:[(m==null?void 0:m.records)&&(m==null?void 0:m.records.length)>0&&e.jsx(s.TableVisual,{card:a,data:D,paginationMetadata:F,onPaginationChange:C,onSortChange:S,isLoading:x||f}),j&&e.jsx($t,{error:j})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function Ht(){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 Jt(){const t=s.useEditorStore(a=>a.isShowingVisual),n=s.useEditorStore(a=>a.actions.setIsShowingVisual);return e.jsxs(s.Toggle,{pressed:!t,onPressedChange:()=>n(!t),variant:"outline",size:"sm",className:"h-8 gap-2",children:[e.jsx(s.Table2,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:"Results"})]})}function ie({value:t,onCommit:n,type:a="text",placeholder:l,className:c}){const[d,r]=L.useState(t),i=L.useRef(!1);L.useEffect(()=>{r(t)},[t]);const o=()=>{if(i.current){i.current=!1;return}d!==t&&n(d)},u=g=>{if(g.key==="Enter"){g.currentTarget.blur();return}g.key==="Escape"&&(i.current=!0,r(t),g.currentTarget.blur())};return e.jsx(s.Input$1,{type:a,placeholder:l,value:d,onChange:g=>r(g.target.value),onBlur:o,onKeyDown:u,className:c})}function pe({defaultValue:t,label:n,options:a,value:l,onValueChange:c,className:d,icon:r,showPlaceholderLabel:i=!0}){return e.jsxs(s.Select,{defaultValue:t,value:l,onValueChange:c,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:[r&&e.jsx("span",{children:r}),i&&e.jsx(s.SelectValue,{placeholder:n})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:n}),a.map(o=>e.jsx(s.SelectItem,{value:o.value,children:o.label},o.value))]})})]})}const Yt={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 Ps(){var x,f;const t=s.useEditorStore(j=>j.card.customCardPreferences),{data:n}=s.usePluginQuery(),a=(n==null?void 0:n.plugins)||[],l=s.useEditorStore(j=>j.card),c=s.useEditorStore(j=>j.frame),d=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:r}=s.useEditorActions(),{components:i,manifest:o}=s.useCustomVisual((t==null?void 0:t.url)||""),u=(x=o==null?void 0:o.visuals)==null?void 0:x.find(j=>j.name===(t==null?void 0:t.componentName));function g(j,y){if(!t)return;const D={...(t==null?void 0:t.dataInputCardIds)||{},[j]:{cardId:y,hookRef:null}};r({...t,dataInputCardIds:D})}function p(j){var F,D;const y=(F=c==null?void 0:c.cards)==null?void 0:F.filter(N=>{var E;return((E=N==null?void 0:N.customCardPreferences)==null?void 0:E.visualType)!=="multiple"}).map(N=>({value:N.id,label:N.tabTitle||N.title}));return e.jsx("div",{className:"space-y-2",children:(D=j==null?void 0:j.dataInputs)==null?void 0:D.map((N,E)=>{var C,S;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:N}),e.jsx(pe,{className:"col-span-6 h-8 w-full justify-between",label:"",options:y||[],value:((S=(C=t==null?void 0:t.dataInputCardIds)==null?void 0:C[E])==null?void 0:S.cardId)||"",onValueChange:I=>g(E,I)})]},E+Math.random())})})}function h(j,y,F=[],D=""){var N,E;return t?j==="input"?e.jsx(ie,{className:`h-8 w-full ${s.removeRing}`,value:String(((N=t==null?void 0:t.settings)==null?void 0:N[y])??D??""),onCommit:C=>{r({...t,settings:{...t==null?void 0:t.settings,[y]:C}})}},y):j==="select"?e.jsx(pe,{className:"h-8 w-full",label:"",options:F,value:((E=t==null?void 0:t.settings)==null?void 0:E[y])||D,onValueChange:C=>{r({...t,settings:{...t==null?void 0:t.settings,[y]:C}})}}):null:null}function w(j){const y=Object.entries((j==null?void 0:j.settings)||{});return e.jsx("div",{className:"space-y-3",children:y.map(([F,D])=>{var N;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{children:D.title}),((N=D.docs)==null?void 0:N.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:D.docs.description})})]})})]}),h(D.ui,F,D.options,D.defaultValue)]},F)})})}function m(j){t&&r({...t,visualType:j,componentName:""})}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:[e.jsx(pe,{icon:e.jsx(Ss,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:a,value:(t==null?void 0:t.url)||"",onValueChange:j=>r({...t||{url:"",componentName:""},url:j})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:d,onValueChange:m,children:e.jsxs(s.TabsList,{className:"h-9 w-full",children:[e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(s.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&t&&e.jsx(e.Fragment,{children:i&&e.jsx(pe,{icon:e.jsx(tt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(i==null?void 0:i.filter(j=>j.type===d).map(j=>({value:j.name,label:j.name})))||[],value:t.componentName,onValueChange:j=>{console.log("changing value",j),r({...t,componentName:j})}})})]})})]}),((f=l==null?void 0:l.customCardPreferences)==null?void 0:f.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:(u==null?void 0:u.name)||"Settings"}),(u==null?void 0:u.docs)&&e.jsxs(s.HoverCard,{openDelay:0,closeDelay:100,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,onClick:j=>j.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:[u.docs.description&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u.docs.description}),u.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:Yt,children:u.docs.dataSchema})})]}),u.docs.useCases&&u.docs.useCases.length>0&&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:u.docs.useCases.map((j,y)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-1 text-primary",children:"•"}),e.jsx("span",{children:j})]},y))})]})]})})]})]})}),e.jsxs(s.AccordionContent,{children:[u&&u.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:p(u)})]}),u&&u.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:w(u)})})]})]})]})}function Qt({colorRanges:t,setColorRanges:n}){const a={start:-1/0,end:100,color:""};function l(r,i,o){const u=[...t];u[r]={...u[r],[i]:o},n(u)}function c(r){const i=[...t];i.splice(r,1),n(i)}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((r,i)=>e.jsxs("div",{className:"flex items-center gap-2 px-2",children:[e.jsx(s.Input$1,{onChange:o=>l(i,"start",o.target.value),value:r.start,className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx("span",{children:"-"}),e.jsx(s.Input$1,{value:r.end,onChange:o=>l(i,"end",o.target.value),className:s.cn(`h-7 ${s.removeRing}`)}),e.jsx(s.Input$1,{onChange:o=>l(i,"color",o.target.value),value:r.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:()=>c(i),variant:"secondary",className:"h-5 p-1 text-muted-foreground",children:e.jsx(s.X,{className:"size-3"})})]},i))]})}function Wt(){var g,p,h,w,m;const t=s.useEditorStore(x=>x.card.preferences),n=s.useEditorStore(x=>x.actions.setCardPreferences),a=s.useEditorStore(x=>x.card),l=s.hasValidCardConfig(a.config),c=s.useEditorStore(x=>x.actions.setNumberFormat);s.useEditorStore(x=>{var f,j;return(j=(f=x.card.preferences)==null?void 0:f.formatNumber)==null?void 0:j.decimalPlaces});const d=s.useEditorStore(x=>{var f,j;return(j=(f=x.card.preferences)==null?void 0:f.formatNumber)==null?void 0:j.locale}),r=s.useEditorStore(x=>{var f,j;return(j=(f=x.card.preferences)==null?void 0:f.formatNumber)==null?void 0:j.currency});s.useEditorStore(x=>x.actions.setFilterOnClickField);const i=s.useEditorStore(x=>{var f,j;return(j=(f=x.card.preferences)==null?void 0:f.formatNumber)==null?void 0:j.colorRanges})||[],o=s.useEditorStore(x=>x.actions.setColorRanges),u=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(x=>x.currency))];return e.jsxs("div",{children:[!l&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((g=t==null?void 0:t.formatNumber)!=null&&g.enabled),onCheckedChange:x=>{n({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:x}})}}),e.jsx(s.Label,{children:"Format Number"})]}),(((p=t==null?void 0:t.formatNumber)==null?void 0:p.enabled)===!0||l)&&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:x=>{var f,j,y;return c(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",x,((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"Auto"},"none"),s.LOCALE_CURRENCY_PAIRS.map(x=>e.jsx(s.SelectItem,{value:x.locale,children:x.locale},x.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:r||"none",onValueChange:x=>{var f,j,y;console.log("currency",x),c(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,x==="none"?"":x,((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),u.map(x=>e.jsx(s.SelectItem,{value:x,children:x},x))]})})]})]})]}),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:((w=(h=t==null?void 0:t.formatNumber)==null?void 0:h.decimalPlaces)==null?void 0:w.toString())||"0",onValueChange:x=>{var f,j,y;return c(Number(x),((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((j=t==null?void 0:t.formatNumber)==null?void 0:j.locale)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(x=>e.jsx(s.SelectItem,{value:x,children:x},x))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input$1,{value:((m=t==null?void 0:t.formatNumber)==null?void 0:m.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:x=>{var f,j,y;return c(((f=t==null?void 0:t.formatNumber)==null?void 0:f.decimalPlaces)||0,((j=t==null?void 0:t.formatNumber)==null?void 0:j.currency)||"",((y=t==null?void 0:t.formatNumber)==null?void 0:y.locale)||"",x.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(Qt,{colorRanges:i,setColorRanges:o})]})]})}const Xt={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"}};function Qe(t){return Xt[t]}function Zt({chartType:t,showDocsLink:n=!0}){const a=Qe(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((l,c)=>e.jsxs("tr",{className:c<a.fields.length-1?"border-b":"",children:[e.jsxs("td",{className:"px-2.5 py-1.5 font-medium text-foreground",children:[l.name,l.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:l.type}),e.jsx("td",{className:"px-2.5 py-1.5 text-muted-foreground",children:l.description||"—"})]},l.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:l=>l.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 ea({chartType:t}){return Qe(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(Zt,{chartType:t})})]}):null}function Re({chartType:t,suffix:n="Configuration"}){const a=Qe(t),l=(a==null?void 0:a.label)||t;return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-medium",children:[l," ",n]}),e.jsx(ea,{chartType:t})]})}function sa(){return e.jsxs("div",{className:"space-y-6 px-6 py-4",children:[e.jsx(Re,{chartType:"kpi"}),e.jsx("section",{children:e.jsx(Wt,{})})]})}function ms({children:t,summary:n,open:a,className:l}){return e.jsxs("details",{open:a,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",l),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 Vs(){const[t,n]=L.useState([]),a=s.useEditorStore(u=>u.card.preferences),{setFilterOnClickColumnIndex:l,setCardPreferences:c}=s.useEditorStore(u=>u.actions),d=s.useEditorStore(u=>u.queryResultColumns);s.useEditorStore(u=>{var g;return(g=u.card.preferences)==null?void 0:g.filterOnClickColumnIndex}),L.useEffect(()=>{d&&n(new Array(d.length).fill(!1))},[d]);function r(u,g){var p,h;g?a!=null&&a.onClickFilter&&((p=a==null?void 0:a.onClickFilter)==null?void 0:p.length)>0?c({...a,onClickFilter:[...a.onClickFilter,{columnIndex:u,expression:""}]}):c({...a,onClickFilter:[{columnIndex:u,expression:""}]}):(c({...a,onClickFilter:(h=a==null?void 0:a.onClickFilter)==null?void 0:h.filter(w=>w.columnIndex!==u)}),n(w=>{const m=[...w];return m[u]=!1,m}))}function i(u,g){var h;const p=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.map(w=>w.columnIndex===u?{...w,expression:g.target.value}:w);c({...a,onClickFilter:p})}function o(u){var g,p,h,w;if(t!=null&&t[u]||(p=(g=a==null?void 0:a.onClickFilter)==null?void 0:g.find(m=>m.columnIndex===u))!=null&&p.expression)return e.jsx(s.Input$1,{value:(w=(h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(m=>m.columnIndex===u))==null?void 0:w.expression,onChange:m=>i(u,m),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((u,g)=>{var p,h;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:!!((p=a==null?void 0:a.onClickFilter)!=null&&p.find(w=>w.columnIndex===g)),onCheckedChange:w=>r(g,w)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:u}),e.jsx("div",{className:"flex items-center gap-2",children:((h=a==null?void 0:a.onClickFilter)==null?void 0:h.find(w=>w.columnIndex===g))&&e.jsx(s.Pencil,{onClick:()=>{n(w=>{const m=[...w];return m[g]=!w[g],m})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),o(g)]})},u)})})}const ta=[{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"}],aa=["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"],na=aa.map(t=>({label:t,value:t}));function ra(){var o,u,g,p,h,w,m,x,f,j,y,F,D,N,E,C,S,I;const t=s.useEditorStore(M=>M.card),n=(u=(o=t==null?void 0:t.preferences)==null?void 0:o.mapVisualOptions)==null?void 0:u.topoJsonUrl,[a,l]=L.useState(((p=(g=t==null?void 0:t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:p.customTopoJsonUrl)||""),{setCardPreferences:c}=s.useEditorActions(),{data:d}=s.useTopoJson(t),r=Object.keys((d==null?void 0:d.objects)||{}).map(M=>({label:M,value:M}))||[],i=[{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(Re,{chartType:"map"}),e.jsx(ms,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(pe,{className:"h-9",options:i,onValueChange:M=>{console.log("value",M),c({...t.preferences,mapVisualOptions:{topoJsonUrl:M}})},value:n||"",label:"Select Map"}),n==="custom"&&e.jsx(s.Input$1,{onChange:M=>{l(M.target.value)},onBlur:()=>{var M;console.log("onBlur",a),c({...t.preferences,mapVisualOptions:{...(M=t.preferences)==null?void 0:M.mapVisualOptions,customTopoJsonUrl:a}})},value:a,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),d&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(pe,{className:"h-9",options:r,value:((w=(h=t.preferences)==null?void 0:h.mapVisualOptions)==null?void 0:w.objectKey)||"",label:"Map Object",onValueChange:M=>{var b;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,objectKey:M}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(pe,{className:"h-9",options:ta,value:((x=(m=t.preferences)==null?void 0:m.mapVisualOptions)==null?void 0:x.projection)||"",label:"Projection",onValueChange:M=>{var b;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,projection:M}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(pe,{className:"h-9",options:na,value:((j=(f=t.preferences)==null?void 0:f.mapVisualOptions)==null?void 0:j.colorScale)||"",label:"Select Color Scale",onValueChange:M=>{var b;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,colorScale:M}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(ms,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input$1,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((F=(y=t.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:F.projectionScale)||1,onChange:M=>{var b;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,projectionScale:Number(M.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input$1,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((E=(N=(D=t.preferences)==null?void 0:D.mapVisualOptions)==null?void 0:N.projectionOffset)==null?void 0:E[0])||0,onChange:M=>{var b,v,A,R;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,projectionOffset:[Number(M.target.value),((R=(A=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:R[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input$1,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((I=(S=(C=t.preferences)==null?void 0:C.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:I[1])||0,onChange:M=>{var b,v,A,R;c({...t.preferences,mapVisualOptions:{...(b=t.preferences)==null?void 0:b.mapVisualOptions,projectionOffset:[((R=(A=(v=t.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:A.projectionOffset)==null?void 0:R[0])||0,Number(M.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(Vs,{})]})}function la(){const t=s.useDashboardStore(i=>i.dashboard.filters),n=s.useEditorStore(i=>i.frame),{setFrame:a}=s.useEditorActions(),{columns:l}=s.useEditorAside(),{assignFilter:c}=s.useAssignFilter();function d(i){const o=c(i,"frame");a({...n,filterId:o})}const r=t==null?void 0:t.find(i=>i.id===n.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(oa,{onSelect:d,columns:l}),r&&e.jsx(s.FilterHeader,{filter:r})]})}function oa({columns:t,onSelect:n}){var r;const[a,l]=Ue.useState(!1),[c,d]=Ue.useState("");return e.jsxs(s.Popover,{open:a,onOpenChange:l,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:[c?(r=t.find(i=>i.column_name===c))==null?void 0:r.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t==null?void 0:t.map(i=>e.jsxs(s.CommandItem,{value:i.column_name,onSelect:o=>{const u=o===c?"":o;d(u),l(!1),u&&n(i)},children:[i.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",c===i.column_name?"opacity-100":"opacity-0")})]},i.column_name))})]})]})})]})}function ia({cardType:t="table"}){console.log("cardType",t);const n=s.useEditorStore(c=>{var d;return(d=c.card)==null?void 0:d.preferences}),a=s.useEditorStore(c=>c.actions.setCardPreferences),l=c=>{a({...n,allowDownload:c})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Click Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(Vs,{}),e.jsx(la,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:l,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 ca(){var l;const t=s.useEditorStore(c=>c.card.preferences),{setCardPreferences:n}=s.useEditorStore(c=>c.actions);function a(c){n({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:c==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(l=t==null?void 0:t.textVisualOptions)!=null&&l.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 da(){return e.jsxs("div",{className:"space-y-4 px-6 py-4",children:[e.jsx(Re,{chartType:"text"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Text Type"}),e.jsx(ca,{})]})]})}function zs({color:t,onColorChange:n,onClose:a}){const[l,c]=L.useState(0),[d,r]=L.useState(100),[i,o]=L.useState(50),[u,g]=L.useState(t);L.useEffect(()=>{const f=xs(t);if(f){const j=hs(f.r,f.g,f.b);c(j.h),r(j.s),o(j.l),g(t)}},[t]);const p=f=>{c(f),w(f,d,i)},h=f=>{const j=f.currentTarget.getBoundingClientRect(),y=Math.max(0,Math.min(1,(f.clientX-j.left)/j.width)),F=Math.max(0,Math.min(1,(f.clientY-j.top)/j.height)),D=y*100,N=(1-F)*100;r(D),o(N),w(l,D,N)},w=(f,j,y)=>{const F=ma(f,j,y),D=ua(F.r,F.g,F.b);g(D)},m=f=>{if(g(f),/^#[0-9A-Fa-f]{6}$/.test(f)){const j=xs(f);if(j){const y=hs(j.r,j.g,j.b);c(y.h),r(y.s),o(y.l)}}},x=()=>{/^#[0-9A-Fa-f]{6}$/.test(u)&&(n(u),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(${l}, 100%, 50%)`},onClick:h,onMouseMove:f=>{f.buttons===1&&h(f)},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-i}%`,backgroundColor:u}})]}),e.jsx("div",{className:"space-y-2",children:e.jsx("input",{type:"range",min:"0",max:"360",value:l,onChange:f=>p(Number(f.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$1,{value:u,onChange:f=>m(f.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:u}}),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:x,children:"OK"})]})]})}function xs(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 ua(t,n,a){return"#"+((1<<24)+(t<<16)+(n<<8)+a).toString(16).slice(1)}function hs(t,n,a){t/=255,n/=255,a/=255;const l=Math.max(t,n,a),c=Math.min(t,n,a);let d=0,r=0;const i=(l+c)/2;if(l!==c){const o=l-c;switch(r=i>.5?o/(2-l-c):o/(l+c),l){case t:d=((n-a)/o+(n<a?6:0))/6;break;case n:d=((a-t)/o+2)/6;break;case a:d=((t-n)/o+4)/6;break}}return{h:Math.round(d*360),s:Math.round(r*100),l:Math.round(i*100)}}function ma(t,n,a){t/=360,n/=100,a/=100;let l,c,d;if(n===0)l=c=d=a;else{const r=(u,g,p)=>(p<0&&(p+=1),p>1&&(p-=1),p<.16666666666666666?u+(g-u)*6*p:p<.5?g:p<.6666666666666666?u+(g-u)*(.6666666666666666-p)*6:u),i=a<.5?a*(1+n):a+n-a*n,o=2*a-i;l=r(o,i,t+1/3),c=r(o,i,t),d=r(o,i,t-1/3)}return{r:Math.round(l*255),g:Math.round(c*255),b:Math.round(d*255)}}const xa=["#000000","#ffffff","#6b7280","#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#c026d3","#e11d48","#0f172a","#f3f4f6","#fbbf24"];function ha(){var F,D,N,E,C,S,I,M,b,v;const t=s.useEditorStore(A=>A.card),n=s.useEditorStore(A=>{var R;return(R=A.card)==null?void 0:R.preferences}),{setCardPreferences:a,updateCardInFrame:l}=s.useEditorActions(),{data:c}=s.useDashboardCardQuery(t),[d,r]=L.useState({}),[i,o]=L.useState(null),[u,g]=L.useState(null),p=L.useMemo(()=>{var O,T,P,$,H,q,K;if(!(c!=null&&c.records)||c.records.length===0)return[];const A=(t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine",R=(t==null?void 0:t.type)==="bar"||(t==null?void 0:t.type)==="line"||(t==null?void 0:t.type)==="horizontalBar"||(t==null?void 0:t.type)==="bullet"||(t==null?void 0:t.type)==="combo"||(t==null?void 0:t.type)==="area"||(t==null?void 0:t.type)==="stackedArea",k=((O=t==null?void 0:t.config)==null?void 0:O.pivotByColumns)&&t.config.pivotByColumns.length>0;if((A||R)&&k){if(c.pivotSchema&&Array.isArray(c.pivotSchema)){const _=new Set;return c.pivotSchema.forEach(B=>{B.alias&&_.add(B.alias)}),Array.from(_)}if(c.records.length>0){const _=c.records[0],B=Object.keys(_),U=new Set;(T=t==null?void 0:t.config)!=null&&T.groupByColumns&&t.config.groupByColumns.forEach(X=>{U.add(X.label||X.name),U.add(X.alias||X.name)});const V=new Set;return(P=t==null?void 0:t.config)!=null&&P.metricColumns&&t.config.metricColumns.forEach(X=>{const se=X.alias||X.name;V.add(se),V.add(`${se}_count`),V.add(`${se}_sum`),V.add(`${se}_avg`),V.add(`${se}_min`),V.add(`${se}_max`);const J=X.entityName||X.qualifiedEntityName;J&&(V.add(`${J}_${se}`),V.add(`${J}_${se}_count`))}),B.filter(X=>!U.has(X)&&!V.has(X))}}if((R||A)&&!k&&((H=($=t==null?void 0:t.config)==null?void 0:$.metricColumns)!=null&&H.length))return t.config.metricColumns.map(_=>_.alias||_.label||_.name);if((K=(q=t==null?void 0:t.config)==null?void 0:q.groupByColumns)!=null&&K.length){const _=t.config.groupByColumns[0],B=_.label||_.name,U=new Set;return c.records.forEach(V=>{const W=V[B];W!=null&&U.add(String(W))}),Array.from(U)}return[]},[c,(F=t==null?void 0:t.config)==null?void 0:F.groupByColumns,(D=t==null?void 0:t.config)==null?void 0:D.pivotByColumns,(N=t==null?void 0:t.config)==null?void 0:N.metricColumns,t==null?void 0:t.type]),h=L.useMemo(()=>s.getDefaultChartColors(),[]);L.useEffect(()=>{const A={};p.forEach((R,k)=>{A[R]=s.getColorForValue(R,k,n==null?void 0:n.colorConfig)}),r(A)},[p,n==null?void 0:n.colorConfig,h]);const w=(A,R)=>{const k={...d,[A]:R};r(k);const O={...n||{},colorConfig:{segments:k}};a(O);const T={...t,preferences:O};l(T)},m=(A,R)=>{var H;const k=h[R%h.length],{[A]:O,...T}=((H=n==null?void 0:n.colorConfig)==null?void 0:H.segments)||{},P={...n||{},colorConfig:{segments:T}};a(P);const $={...t,preferences:P};l($),r(q=>({...q,[A]:k}))};if(!p.length||!((t==null?void 0:t.type)==="stackedBar"||(t==null?void 0:t.type)==="stackedLine"?((C=(E=t==null?void 0:t.config)==null?void 0:E.groupByColumns)==null?void 0:C.length)||((I=(S=t==null?void 0:t.config)==null?void 0:S.pivotByColumns)==null?void 0:I.length):(b=(M=t==null?void 0:t.config)==null?void 0:M.groupByColumns)==null?void 0:b.length)||["table","kpi","text","custom","heatmap"].includes(t.type))return null;const j=()=>{const A={...n||{},colorConfig:{segments:{}}};a(A);const R={...t,preferences:A};l(R);const k={};p.forEach((O,T)=>{k[O]=s.getColorForValue(O,T,void 0)}),r(k)},y=Object.keys(((v=n==null?void 0:n.colorConfig)==null?void 0:v.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(pt,{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:y&&e.jsxs("button",{className:"ml-auto flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:j,children:[e.jsx(ls,{className:"h-3 w-3"}),"Reset All"]})})}),e.jsx("div",{className:"max-h-[200px] space-y-2 overflow-y-auto pr-1",children:p.map((A,R)=>{const k=s.isDefaultColor(d[A],R),O=!k;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:i===A,onOpenChange:T=>o(T?A: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:d[A]}})}),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:h.slice(0,10).map((T,P)=>e.jsxs("button",{className:s.cn("relative h-5 w-5 rounded border-2 transition-all hover:scale-110",d[A]===T?"border-gray-900":"border-transparent"),style:{backgroundColor:T},onClick:()=>{w(A,T),o(null)},children:[P===R%h.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:T})]},`default-${P}`))})]}),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:xa.map((T,P)=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border transition-all hover:scale-110",d[A]===T?"border-2 border-gray-900":T==="#ffffff"?"border border-gray-300":"border border-transparent"),style:{backgroundColor:T},onClick:()=>{w(A,T),o(null)},children:e.jsx("span",{className:"sr-only",children:T})},`preset-${P}`))})]}),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:()=>{g({value:A,color:d[A]}),o(null)},children:"Custom color"}),!k&&e.jsxs("button",{className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",onClick:()=>{m(A,R),o(null)},children:[e.jsx(ls,{className:"h-3 w-3"}),"Reset"]})]})]})})]}),e.jsx("span",{className:"flex-1 truncate text-sm",children:A}),O&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(custom)"})]},A)})}),u&&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:()=>g(null)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(zs,{color:u.color,onColorChange:A=>{w(u.value,A),g(null)},onClose:()=>g(null)})})]})]})})]})}function ce({value:t,onSave:n,placeholder:a="",type:l="text",className:c=""}){const[d,r]=L.useState(t??""),[i,o]=L.useState(!1);L.useEffect(()=>{r(t??"")},[t]);const u=()=>{n(d),o(!1)},g=()=>{r(t??""),o(!1)};return e.jsxs("div",{className:`flex items-center gap-2 ${c}`,children:[e.jsx(s.Input,{placeholder:a,type:l,value:i?d:t??"",onChange:p=>{r(p.target.value),o(!0)},onFocus:()=>o(!0),onClick:p=>p.stopPropagation(),className:"h-8 text-xs",onPointerDown:p=>p.stopPropagation(),onKeyDown:p=>{p.stopPropagation(),p.key==="Enter"&&i&&d!==t?u():p.key==="Escape"&&g()},"aria-label":a||"Edit field"}),i&&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:u,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:g,children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]})]})}const pa=["auto","number","currency","percent","scientific","date"],ga=[{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"}],fa=[{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"}],ja=t=>t.charAt(0).toUpperCase()+t.slice(1);function We({formatOptions:t={},onFormatOptionsChange:n,showTitle:a=!0,title:l="NUMBER FORMAT"}){const c=t.type||"auto",d=(i,o)=>{n({...t,[i]:o})},r=()=>c==="currency"?2:c==="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:l}),e.jsxs(s.Select,{value:c,onValueChange:i=>d("type",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:pa.map(i=>e.jsx(s.SelectItem,{value:i,className:"text-xs",children:i==="auto"?"Auto (Default)":ja(i)},i))})]})]}),c!=="auto"&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-4",children:[["number","currency","percent"].includes(c)&&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$1,{type:"number",min:"0",max:"10",placeholder:"0",value:t.decimalPlaces??r(),onChange:i=>d("decimalPlaces",parseInt(i.target.value)||0),className:"h-8 text-xs"})})]}),c==="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:i=>d("currency",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ga.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),["number","currency"].includes(c)&&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:i=>d("useSuffix",i)})]}),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:i=>d("locale",i),children:[e.jsx(s.SelectTrigger,{className:"h-8 flex-1 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:fa.map(i=>e.jsx(s.SelectItem,{value:i.value,className:"text-xs",children:i.label},i.value))})]})]}),c==="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$1,{placeholder:"e.g., $",value:t.prefix||"",onChange:i=>d("prefix",i.target.value),className:"h-8 text-xs"})})]}),c==="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$1,{placeholder:"e.g., units",value:t.suffix||"",onChange:i=>d("suffix",i.target.value),className:"h-8 text-xs"})})]}),["number","currency"].includes(c)&&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:i=>d("negativeInParentheses",i)})]}),c==="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$1,{type:"number",placeholder:"100",value:t.multiplyBy??"",onChange:i=>d("multiplyBy",i.target.value?parseFloat(i.target.value):void 0),className:"h-8 text-xs"})})]}),c==="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$1,{type:"text",placeholder:"MM/DD/YYYY",value:t.dateFormat||"",onChange:i=>d("dateFormat",i.target.value),className:"h-8 text-xs"})})]})]})]})}function $e({axis:t,label:n,type:a,config:l,onChange:c,defaultTitle:d,hidePosition:r}){var w,m,x,f,j,y,F,D,N,E,C,S,I,M;const i=(b,v)=>{c({...l??{},[b]:v})},o=(b,v)=>{var O,T,P,$;const A=b==="enabled"&&v===!0,R=(O=l==null?void 0:l.name)==null?void 0:O.text,k=A&&!R&&d;c({...l??{},name:{...l==null?void 0:l.name,enabled:b==="enabled"?v:((T=l==null?void 0:l.name)==null?void 0:T.enabled)??!1,text:b==="text"?v:k?d:R,fontSize:b==="fontSize"?v:(P=l==null?void 0:l.name)==null?void 0:P.fontSize,fontWeight:b==="fontWeight"?v:($=l==null?void 0:l.name)==null?void 0:$.fontWeight}})},u=(b,v)=>{var A,R;c({...l??{},labels:{enabled:b==="enabled"?v:((A=l==null?void 0:l.labels)==null?void 0:A.enabled)??!0,rotation:b==="rotation"?v:(R=l==null?void 0:l.labels)==null?void 0:R.rotation}})},g=(b,v)=>{c({...l??{},scale:{...l==null?void 0:l.scale,[b]:v===""?"auto":Number(v)}})},p=t==="x"?["auto","top","bottom"]:["auto","left","right"],h=["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:(l==null?void 0:l.enabled)!==!1,onCheckedChange:b=>i("enabled",b),onClick:b=>b.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:((w=l==null?void 0:l.name)==null?void 0:w.enabled)??!1,onCheckedChange:b=>o("enabled",b===!0)}),e.jsx(s.Label,{htmlFor:`${t}-title-enabled`,className:"text-xs font-medium cursor-pointer",children:"TITLE"})]}),((m=l==null?void 0:l.name)==null?void 0:m.enabled)&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(ce,{placeholder:`${n} title`,value:((x=l==null?void 0:l.name)==null?void 0:x.text)||"",onSave:b=>o("text",b),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(ce,{type:"number",placeholder:"12",value:String(((f=l==null?void 0:l.name)==null?void 0:f.fontSize)||12),onSave:b=>o("fontSize",Number(b)||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:((j=l==null?void 0:l.name)==null?void 0:j.fontWeight)||"normal",onValueChange:b=>o("fontWeight",b),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"})]})]})]})]})]})]}),!r&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"POSITION"}),e.jsxs(s.Select,{value:(l==null?void 0:l.position)||"auto",onValueChange:b=>i("position",b),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:p.map(b=>e.jsx(s.SelectItem,{value:b,className:"text-xs",children:b==="auto"?"Auto (Default)":s.titleCase(b)},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 font-medium",children:"LABELS"}),e.jsx(s.SmallSwitch,{checked:((y=l==null?void 0:l.labels)==null?void 0:y.enabled)!==!1,onCheckedChange:b=>u("enabled",b)})]}),((F=l==null?void 0:l.labels)==null?void 0:F.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(((D=l==null?void 0:l.labels)==null?void 0:D.rotation)||"auto"),onValueChange:b=>u("rotation",b==="auto"?"auto":Number(b)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:h.map(b=>e.jsx(s.SelectItem,{value:b,className:"text-xs",children:b==="auto"?"Auto (Default)":`${b}°`},b))})]})]})]}),a==="value"&&e.jsx(We,{formatOptions:(l==null?void 0:l.formatOptions)||{},onFormatOptionsChange:b=>c({...l,formatOptions:b}),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(ce,{type:"number",placeholder:"auto",value:((N=l==null?void 0:l.scale)==null?void 0:N.min)==="auto"||((E=l==null?void 0:l.scale)==null?void 0:E.min)===void 0?"":String(l.scale.min),onSave:b=>g("min",b),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(ce,{type:"number",placeholder:"auto",value:((C=l==null?void 0:l.scale)==null?void 0:C.max)==="auto"||((S=l==null?void 0:l.scale)==null?void 0:S.max)===void 0?"":String(l.scale.max),onSave:b=>g("max",b),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(ce,{type:"number",placeholder:"auto",value:((I=l==null?void 0:l.scale)==null?void 0:I.stepSize)==="auto"||((M=l==null?void 0:l.scale)==null?void 0:M.stepSize)===void 0?"":String(l.scale.stepSize),onSave:b=>g("stepSize",b),className:""})})]})]})]})]})]})}function qe(t,n,a){var d,r,i;if(t==="x"){const o=(r=(d=n==null?void 0:n.config)==null?void 0:d.groupByColumns)==null?void 0:r[0];return(o==null?void 0:o.label)||(o==null?void 0:o.name)||""}const l=((i=n==null?void 0:n.config)==null?void 0:i.metricColumns)||[],c=(a==null?void 0:a.datasetOptions)||[];if(t==="y"){const o=l.filter((u,g)=>{const p=c.find(h=>h.idx===g);return!p||p.yAxisId!=="y2"});return o.length===1&&(o[0].label||o[0].name)||""}if(t==="y2"){const o=l.filter((u,g)=>{const p=c.find(h=>h.idx===g);return(p==null?void 0:p.yAxisId)==="y2"});return o.length===1&&(o[0].label||o[0].name)||""}return""}function ba(){const t=s.useEditorStore(i=>i.card),n=s.useEditorStore(i=>{var o;return(o=i.card)==null?void 0:o.preferences}),{setCardPreferences:a,updateCardInFrame:l}=s.useEditorActions();if(!t||["tornado","pyramid","kpi","treemap"].includes(t.type))return null;const c=s.AxisConfigurator.getAxisInfo(t.type,n);if(!c.hasXAxis&&!c.hasYAxis)return null;const d=(i,o)=>{let u;i==="x"?u="xAxisConfig":i==="y"?u="yAxisConfig":u="secondaryYAxisConfig";const g={...n||{},[u]:o};a(g);const p={...t,preferences:g};l(p)},r=c.hasY2Axis&&t.type==="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(ks,{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:[c.hasXAxis&&e.jsx($e,{axis:"x",label:"X-Axis",type:c.xAxisType,config:s.mergeAxisConfig(s.getDefaultAxisConfig(t.type,"x"),n==null?void 0:n.xAxisConfig),onChange:i=>d("x",i),defaultTitle:qe("x",t,n)}),c.hasYAxis&&e.jsx($e,{axis:"y",label:r?"Y-Axis (Left)":"Y-Axis",type:c.yAxisType,config:s.mergeAxisConfig(s.getDefaultAxisConfig(t.type,"y"),n==null?void 0:n.yAxisConfig),onChange:i=>d("y",i),defaultTitle:qe("y",t,n)}),r&&e.jsx($e,{axis:"y2",label:"Y2-Axis (Right)",type:"value",config:s.mergeAxisConfig({enabled:!0,position:"right"},n==null?void 0:n.secondaryYAxisConfig),onChange:i=>d("y2",i),defaultTitle:qe("y2",t,n),hidePosition:!0})]})})]})}function va(){const t=s.useEditorStore(g=>g.card),n=s.useEditorStore(g=>{var p,h,w,m;return(m=(w=(h=(p=g.card)==null?void 0:p.preferences)==null?void 0:h.chartOptions)==null?void 0:w.plugins)==null?void 0:m.legend}),{setLegendOptions:a}=s.useEditorActions();if(!t||!s.chartSupportsLegend(t.type))return null;const l=s.getDefaultLegendConfig(t.type),c=(l==null?void 0:l.display)??!0,d=(l==null?void 0:l.position)??"top",r=(l==null?void 0:l.align)??"center",i=(g,p)=>{const h={...n,[g]:p};a(h)},o=["top","bottom","left","right"],u=["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(it,{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:(n==null?void 0:n.display)??c,onCheckedChange:g=>i("display",g)})]}),((n==null?void 0:n.display)??c)&&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:(n==null?void 0:n.position)||d,onValueChange:g=>i("position",g),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:o.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:s.titleCase(g)},g))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Alignment"}),e.jsxs(s.Select,{value:(n==null?void 0:n.align)||r,onValueChange:g=>i("align",g),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:u.map(g=>e.jsx(s.SelectItem,{value:g,className:"text-xs",children:s.titleCase(g)},g))})]})]})]})]})})]})}function ya(){var k,O,T,P,$,H,q,K,_,B,U;const t=s.useEditorStore(V=>V.card),n=s.useEditorStore(V=>{var W,X;return(X=(W=V.card)==null?void 0:W.preferences)==null?void 0:X.dataLabelsConfig}),a=s.useEditorStore(V=>{var W;return(W=V.card)==null?void 0:W.preferences}),{setCardPreferences:l,updateCardInFrame:c}=s.useEditorActions();if(!t||!s.chartSupportsDataLabels(t.type))return null;const d=t.type==="bullet"?((k=a==null?void 0:a.bulletConfig)==null?void 0:k.orientation)??(((O=a==null?void 0:a.chartOptions)==null?void 0:O.indexAxis)==="x"?"vertical":"horizontal"):void 0,r=d!=null?d==="horizontal":((T=a==null?void 0:a.chartOptions)==null?void 0:T.indexAxis)==="y",i=t.type==="stackedBar"||t.type==="stackedLine",o=t.type==="pie"||t.type==="doughnut"||t.type==="polarArea"||t.type==="funnel",u=!o,g=t.type==="bubble"||t.type==="scatter",p=($=(P=a==null?void 0:a.chartOptions)==null?void 0:P.plugins)==null?void 0:$.datalabels,h=(p==null?void 0:p.display)!==!1&&((p==null?void 0:p.anchor)||(p==null?void 0:p.align)),w=s.getDefaultDataLabelsConfig(t.type,t.preferences),m=n??w,x=(w==null?void 0:w.enabled)??h??!1,f=(n==null?void 0:n.enabled)!==void 0?n.enabled:x,j=(V,W)=>{const J={...w??{},...n??{},[V]:W};V==="enabled"&&(J.display=W,W&&g&&!J.position&&(J.position="bottom")),V==="position"&&g&&(J.position="bottom");const te={...t.preferences||{},dataLabelsConfig:J};l(te);const Q={...t,preferences:te};c(Q)},y=(V,W)=>{const X=n??{},J={...w??{},...X,font:{...X.font||{},[V]:W}},te={...t.preferences||{},dataLabelsConfig:J};l(te);const Q={...t,preferences:te};c(Q)},F=(V,W)=>{const X=n??{},J={...w??{},...X,formatOptions:{...X.formatOptions||{},[V]:W}},te={...t.preferences||{},dataLabelsConfig:J};l(te);const Q={...t,preferences:te};c(Q)},D=()=>{const V=t.type;return V==="stackedBar"||V==="stackedLine"||V==="pie"||V==="doughnut"?"center":r?"right":"top"},N=t.type!=="treemap"&&t.type!=="heatmap",E=t.type!=="treemap",C=D();let S=[];if(N)if(g)S=["bottom"];else if(i||o)S=["center"];else{const V=r?["center","left","right"]:["center","top","bottom"];S=["auto",...t.type==="bullet"?V:V.filter(X=>X!==C),"custom"]}const I=()=>s.titleCase(C),M=["center","start","end"],b=["center","start","end","top","bottom"],v=u?["auto","number","currency","percent","none"]:["number","currency","percent","none"],A=[{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"}],R=[{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(Nt,{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:f,onCheckedChange:V=>j("enabled",V)})]}),f&&e.jsxs(e.Fragment,{children:[N&&!i&&!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:g?(m==null?void 0:m.position)||"bottom":(m==null?void 0:m.position)||"auto",onValueChange:V=>j("position",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:S.map(V=>e.jsx(s.SelectItem,{value:V,className:"text-xs",children:V==="auto"?I():V==="custom"?"Custom (Advanced)":s.titleCase(V)},V))})]})]}),i&&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:(n==null?void 0:n.showTotal)??!1,onCheckedChange:V=>j("showTotal",V)})]}),(m==null?void 0:m.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:(m==null?void 0:m.anchor)||"center",onValueChange:V=>j("anchor",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:M.map(V=>e.jsx(s.SelectItem,{value:V,className:"text-xs",children:s.titleCase(V)},V))})]})]}),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((m==null?void 0:m.align)||"center"),onValueChange:V=>j("align",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:b.map(V=>e.jsx(s.SelectItem,{value:V,className:"text-xs",children:s.titleCase(V)},V))})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"Format"}),e.jsxs(s.Select,{value:(m==null?void 0:m.format)||(u?"auto":"none"),onValueChange:V=>j("format",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:v.map(V=>e.jsx(s.SelectItem,{value:V,className:"text-xs",children:V==="auto"&&u?"Auto (Use Axis)":V==="none"?"None (Raw Value)":s.titleCase(V)},V))})]})]}),(m==null?void 0:m.format)&&!["auto","none"].includes(m.format)&&e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[["number","currency","percent"].includes(m.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(ce,{type:"number",placeholder:"0",value:String(((H=m==null?void 0:m.formatOptions)==null?void 0:H.decimalPlaces)??(m.format==="currency"?2:m.format==="percent"?1:0)),onSave:V=>F("decimalPlaces",Number(V)),className:""})})]}),m.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:((q=m==null?void 0:m.formatOptions)==null?void 0:q.currency)||"USD",onValueChange:V=>F("currency",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:A.map(V=>e.jsx(s.SelectItem,{value:V.value,className:"text-xs",children:V.label},V.value))})]})]}),["number","currency"].includes(m.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:((K=m==null?void 0:m.formatOptions)==null?void 0:K.useSuffix)??!1,onCheckedChange:V=>F("useSuffix",V)})]}),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:((_=m==null?void 0:m.formatOptions)==null?void 0:_.locale)||"en-US",onValueChange:V=>F("locale",V),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs flex-1",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:R.map(V=>e.jsx(s.SelectItem,{value:V.value,className:"text-xs",children:V.label},V.value))})]})]})]}),E&&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(ce,{type:"number",placeholder:"12",value:String(((B=m==null?void 0:m.font)==null?void 0:B.size)||12),onSave:V=>y("size",Number(V)),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:((U=m==null?void 0:m.font)==null?void 0:U.weight)||"normal",onValueChange:V=>y("weight",V),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:(m==null?void 0:m.color)==="auto"||!(m!=null&&m.color)?"auto":"custom",onValueChange:V=>{V==="auto"&&j("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(ce,{type:"number",placeholder:"0",value:String((m==null?void 0:m.rotation)||0),onSave:V=>j("rotation",Number(V)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"degrees"})]})]})]})]})})]})}const ps=[{value:"green",color:"#16a34a",label:"Green"},{value:"red",color:"#dc2626",label:"Red"},{value:"neutral",color:"#6b7280",label:"Neutral"}],Na=["#16a34a","#dc2626","#6b7280","#2563eb","#ca8a04","#7c3aed","#0891b2","#e11d48","#ea580c"];function De({value:t,onChange:n,label:a}){const[l,c]=L.useState(!1),[d,r]=L.useState(!1),i=()=>{const o=ps.find(u=>u.value===t);return o?o.color:t.startsWith("#")?t:ps[2].color};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Popover,{open:l,onOpenChange:c,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:i()},"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:Na.map(o=>e.jsx("button",{className:s.cn("h-5 w-5 rounded border-2 transition-all",i()===o?"border-gray-900":"border-transparent"),style:{backgroundColor:o},onClick:()=>{n(o),c(!1)},children:e.jsx("span",{className:"sr-only",children:o})},o))}),e.jsx("button",{className:"w-full rounded border border-input px-2 py-1 text-xs hover:bg-muted",onClick:()=>{r(!0),c(!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:()=>r(!1)}),e.jsx("div",{className:"relative rounded-lg bg-white shadow-lg",children:e.jsx(zs,{color:i(),onColorChange:o=>{n(o),r(!1)},onClose:()=>r(!1)})})]})]})}const gs={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%
195
+ 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 Ca(){var h,w,m,x,f,j,y,F,D,N,E;const t=s.useEditorStore(C=>C.card),{setCardPreferences:n}=s.useEditorActions(),a=((h=t.config)==null?void 0:h.metricColumns)||[],l=((w=t.config)==null?void 0:w.groupByColumns)||[],c=a.length===2&&l.length===0,d=a.length>=1&&l.length>0;if(!(t.type==="kpi"&&(c||d)))return null;const i=((x=(m=t.preferences)==null?void 0:m.kpiVisualOptions)==null?void 0:x.metricComparison)||{},o=C=>{var I;const S={...t.preferences,kpiVisualOptions:{...(I=t.preferences)==null?void 0:I.kpiVisualOptions,metricComparison:{...i,...C}}};n(S)},u=d||i.enabled,g=((f=t.config)==null?void 0:f.comparisonType)||"none",p=g==="previous_period"||g==="same_period_last_year"||g==="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(lt,{className:"h-4 w-4"}),e.jsx("span",{children:"Comparison"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pb-4 pt-2",children:[c&&a.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:i.enabled||!1,onCheckedChange:C=>o({enabled:C,...C&&!i.calculationType?{calculationType:"difference"}:{}})})]}),u&&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 C=i.calculationType||"difference",S=gs[C];return e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsx("div",{className:"text-sm font-semibold",children:S==null?void 0:S.label}),e.jsx("p",{children:S==null?void 0:S.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:S==null?void 0:S.formula})]}),e.jsxs("div",{className:"border-t pt-1.5 italic",children:[e.jsx("span",{className:"font-medium",children:"Example:"})," ",S==null?void 0:S.example]})]})})()})]})]}),e.jsxs(s.Select,{value:i.calculationType||"difference",onValueChange:C=>o({calculationType:C}),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(gs).map(([C,S])=>e.jsx(s.SelectItem,{value:C,className:"text-xs",children:S.label},C))})]})]}),e.jsx(We,{formatOptions:i.formatOptions||{},onFormatOptionsChange:C=>o({formatOptions:C}),showTitle:!0,title:"COMPARISON FORMAT"}),(p||c)&&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"}),c&&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:i.position||"right",onValueChange:C=>o({position:C}),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:i.showArrow!==!1,onCheckedChange:C=>o({showArrow:C})}),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:i.showColor!==!1,onCheckedChange:C=>o({showColor:C})}),e.jsx(s.Label,{htmlFor:"show-color",className:"cursor-pointer text-xs text-muted-foreground",children:"Color"})]}),i.showColor!==!1&&e.jsxs("div",{className:"space-y-2 border-l-2 border-muted pl-3",children:[e.jsx(De,{value:((j=i.colorConfig)==null?void 0:j.increase)||"green",onChange:C=>o({colorConfig:{...i.colorConfig,increase:C}}),label:"Primary > Secondary"}),e.jsx(De,{value:((y=i.colorConfig)==null?void 0:y.decrease)||"red",onChange:C=>o({colorConfig:{...i.colorConfig,decrease:C}}),label:"Primary < Secondary"}),e.jsx(De,{value:((F=i.colorConfig)==null?void 0:F.noChange)||"neutral",onChange:C=>o({colorConfig:{...i.colorConfig,noChange:C}}),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:i.conditionalLabel||!1,onCheckedChange:C=>o({conditionalLabel:C})}),e.jsx(s.Label,{htmlFor:"conditional-label",className:"cursor-pointer text-xs text-muted-foreground",children:"Conditional"})]}),i.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$1,{id:"label-increase",type:"text",value:((D=i.conditionalLabels)==null?void 0:D.increase)??"Increase",onChange:C=>o({conditionalLabels:{...i.conditionalLabels,increase:C.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$1,{id:"label-decrease",type:"text",value:((N=i.conditionalLabels)==null?void 0:N.decrease)??"Decrease",onChange:C=>o({conditionalLabels:{...i.conditionalLabels,decrease:C.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$1,{id:"label-no-change",type:"text",value:((E=i.conditionalLabels)==null?void 0:E.noChange)??"No change",onChange:C=>o({conditionalLabels:{...i.conditionalLabels,noChange:C.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$1,{id:"label-name",type:"text",value:i.labelName??"",onChange:C=>o({labelName:C.target.value}),placeholder:"e.g. Previous, Last Period",className:"h-7 text-xs"})]})]})]})]})]})}function Sa(){var c,d;const t=s.useEditorStore(r=>r.card),{setCardPreferences:n}=s.useEditorActions();if(t.type!=="kpi")return null;const a=((d=(c=t.preferences)==null?void 0:c.kpiVisualOptions)==null?void 0:d.formatOptions)||{},l=r=>{var o;const i={...t.preferences,kpiVisualOptions:{...(o=t.preferences)==null?void 0:o.kpiVisualOptions,formatOptions:r}};n(i)};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(We,{formatOptions:a,onFormatOptionsChange:l,showTitle:!1})})]})}function wa(){var d;const t=s.useEditorStore(r=>{var i;return(i=r.card)==null?void 0:i.type}),n=s.useEditorStore(r=>{var i;return(i=r.card)==null?void 0:i.preferences}),{setCardPreferences:a}=s.useEditorActions();if(t!=="treemap")return null;const l=((d=n==null?void 0:n.chartOptions)==null?void 0:d.treemapColorMode)??"branch",c=r=>{const i={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,treemapColorMode:r}};a(i)};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:l,onValueChange:r=>c(r??"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 Ta=Object.keys(s.HEATMAP_PRESET_PALETTES);function Ea(){const t=s.useEditorStore(h=>h.card),n=s.useEditorStore(h=>{var w;return(w=h.card)==null?void 0:w.preferences}),{setCardPreferences:a}=s.useEditorActions(),l=(t==null?void 0:t.type)==="heatmap",c=(n==null?void 0:n.heatmapConfig)||{},d=c.colorPalette??"green",r=c.legendPosition??"bottom",i=L.useMemo(()=>c.colorRange&&c.colorRange[0]&&c.colorRange[1]?[c.colorRange[0],c.colorRange[1]]:[...s.DEFAULT_HEATMAP_CUSTOM_RANGE],[c.colorRange]),o=h=>{const w={...c,...h};w.colorPalette!=="custom"?delete w.colorRange:(!w.colorRange||!w.colorRange[0]||!w.colorRange[1])&&(w.colorRange=[...s.DEFAULT_HEATMAP_CUSTOM_RANGE]),a({...n||{},heatmapConfig:w})},u=h=>{o({colorPalette:h,colorRange:h==="custom"?c.colorRange??[...s.DEFAULT_HEATMAP_CUSTOM_RANGE]:void 0})},g=(h,w)=>{const m=[...i];m[h]=w,o({colorPalette:"custom",colorRange:m})},p=h=>{o({legendPosition:h})};return l?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:h=>u(h??"blue"),className:"space-y-3",children:[Ta.map(h=>{const w=s.HEATMAP_PRESET_PALETTES[h];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-${h}`,value:h}),e.jsxs(s.Label,{htmlFor:`heatmap-${h}`,className:"flex w-full flex-col gap-1 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:w.label}),e.jsx("span",{className:"h-2 rounded-full",style:{background:`linear-gradient(90deg, ${w.start}, ${w.end})`}})]})]},h)}),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(De,{value:i[0],onChange:h=>g(0,h),label:"Start color"}),e.jsx(De,{value:i[1],onChange:h=>g(1,h),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:r,onValueChange:h=>p(h??"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(h=>e.jsx(s.SelectItem,{value:h,className:"text-xs",children:h[0].toUpperCase()+h.slice(1)},h))})]})]})]})]}):null}const fs=["poor","satisfactory","good"];function js(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 ka(){var A,R;const t=s.useEditorStore(k=>k.card.preferences),n=s.useEditorStore(k=>k.card),a=s.useEditorStore(k=>k.isDevMode),{setCardPreferences:l,setChartOrientation:c}=s.useEditorActions(),d=L.useMemo(()=>(t==null?void 0:t.bulletConfig)||{},[t==null?void 0:t.bulletConfig]),i=s.hasValidCardConfig(n==null?void 0:n.config)&&!a,[o,u]=L.useState(d.showRanges??!1),[g,p]=L.useState(d.rangesArePercentages??!1),h=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!i,[w,m]=L.useState(h);L.useEffect(()=>{u(d.showRanges??!1)},[d.showRanges]),L.useEffect(()=>{p(d.rangesArePercentages??!1)},[d.rangesArePercentages]);const x=d.targetValue===void 0?"":String(d.targetValue);L.useEffect(()=>{const k=d.disableAutoComparative?!1:d.comparativeMetricKey!==void 0||!i;m(k)},[d.disableAutoComparative,d.comparativeMetricKey,i]);const f=L.useMemo(()=>{var k,O;return((O=(k=n==null?void 0:n.config)==null?void 0:k.metricColumns)==null?void 0:O.map(T=>{const P=T.label||T.name||T.alias||"";return{value:P,label:P}}))||[]},[(A=n==null?void 0:n.config)==null?void 0:A.metricColumns]);L.useEffect(()=>{var K,_;if(!t||f.length===0)return;const k={};let O=!1;const T=(K=f[1])==null?void 0:K.value;!d.targetMetricKey&&T&&(k.targetMetricKey=T,O=!0);const P=(_=f[2])==null?void 0:_.value;!d.comparativeMetricKey&&!d.disableAutoComparative&&P&&(k.comparativeMetricKey=P,O=!0);const $=f.slice(3),H={...d.rangeKeys||{}};let q=!1;if(fs.forEach((B,U)=>{!H[B]&&$[U]&&(H[B]=$[U].value,q=!0)}),q&&(k.rangeKeys=H,O=!0,d.showRanges===void 0&&(k.showRanges=!0)),O){const B=js({...d,...k});l({...t,bulletConfig:B})}},[f,d,t,l]);const j=k=>{const O=js({...d,...k});l({...t,bulletConfig:O})},y=(k,O)=>{const T={...d.rangeKeys||{},[k]:O.trim()};O.trim()||delete T[k],j({rangeKeys:Object.keys(T).length>0?T:void 0})},F=(k,O)=>{const T=O===""?void 0:Number(O),P={...d.ranges||{}};T===void 0||Number.isNaN(T)?delete P[k]:P[k]=T,j({ranges:Object.keys(P).length?P:void 0})},D=k=>{if(k===""){j({targetValue:void 0});return}const O=Number(k);j({targetValue:Number.isNaN(O)?void 0:O})},N=(k,O)=>{const T=O.trim(),P={...d.rangeLabels||{}};T?P[k]=T:delete P[k],j({rangeLabels:Object.keys(P).length>0?P:void 0})},E=k=>{u(k),j({showRanges:k})},C=k=>{p(k),j({rangesArePercentages:k})},S=d.orientation||(((R=t==null?void 0:t.chartOptions)==null?void 0:R.indexAxis)==="y"?"horizontal":"vertical"),I=k=>{j({orientation:k}),c(k==="horizontal"?"y":"x")},M=[{value:"__none",label:"None"},...f.map(k=>({value:k.value,label:k.label}))],b=M,v=k=>{if(m(k),!k){j({comparativeMetricKey:void 0,disableAutoComparative:!0});return}if(!i){j({disableAutoComparative:!1});return}if(d.comparativeMetricKey)j({disableAutoComparative:!1});else{const O=f.find(T=>T.value!==d.targetMetricKey);j({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:S,onValueChange:k=>I(k),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"})]})]})]}),i&&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:k=>j({targetMetricKey:k==="__none"?void 0:k}),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"}),f.map(k=>e.jsx(s.SelectItem,{value:k.value,className:"text-xs",children:k.label},k.value))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(s.Label,{className:"text-xs font-medium",children:"COMPARATIVE METRIC"}),i?e.jsxs(s.Select,{value:d.comparativeMetricKey||"__none",onValueChange:k=>j({comparativeMetricKey:k==="__none"?void 0:k,disableAutoComparative:k==="__none"}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select metric"})}),e.jsx(s.SelectContent,{children:M.map(k=>e.jsx(s.SelectItem,{value:k.value,className:"text-xs",children:k.label},k.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:w,onCheckedChange:k=>v(k)})]}),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(ie,{type:"number",className:"h-8 text-xs",value:x,onCommit:D,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:o,onCheckedChange:E})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium",children:[e.jsx("input",{type:"checkbox",checked:g,disabled:!o,onChange:k=>C(k.target.checked),className:"h-3.5 w-3.5 accent-primary disabled:opacity-50"}),e.jsx("span",{children:"Use % of value"})]})]}),o&&e.jsx("div",{className:"space-y-3",children:fs.map(k=>{var O,T,P,$,H;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:[k," LABEL"]}),e.jsx(ie,{placeholder:`Display label (${k})`,value:((O=d.rangeLabels)==null?void 0:O[k])||"",onCommit:q=>N(k,q),className:"h-8 text-xs"})]}),i?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[k," COLUMN"]}),e.jsxs(s.Select,{value:((T=d.rangeKeys)==null?void 0:T[k])||"__none",onValueChange:q=>{q==="__none"?y(k,""):y(k,q)},children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select column"})}),e.jsx(s.SelectContent,{children:b.map(q=>e.jsx(s.SelectItem,{value:q.value,className:"text-xs",children:q.label},q.value))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(s.Label,{className:"text-[11px] font-medium uppercase tracking-wide",children:[k," COLUMN KEY"]}),e.jsx(ie,{placeholder:"Column key",value:((P=d.rangeKeys)==null?void 0:P[k])||"",onCommit:q=>y(k,q),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:[k," VALUE"]}),e.jsx(ie,{type:"number",placeholder:g?"0.80":"Static value",value:(($=d.ranges)==null?void 0:$[k])===void 0?"":String((H=d.ranges)==null?void 0:H[k]),onCommit:q=>F(k,q),className:"h-8 text-xs"})]})]},k)})})]})]})]})}function bs(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 Ia(){var N,E,C,S,I,M,b,v,A,R,k,O;const t=s.useEditorStore(T=>T.card.preferences),n=s.useEditorStore(T=>T.card),a=s.useEditorStore(T=>T.card.type),l=s.useEditorStore(T=>T.isDevMode),{setCardPreferences:c,updateCardInFrame:d}=s.useEditorActions(),r=a==="bubble",i=a==="scatter",o=L.useMemo(()=>(t==null?void 0:t.bubbleScatterConfig)||{},[t==null?void 0:t.bubbleScatterConfig]),g=s.hasValidCardConfig(n==null?void 0:n.config)&&!l,p=L.useMemo(()=>{var T,P;return((P=(T=n==null?void 0:n.config)==null?void 0:T.metricColumns)==null?void 0:P.map($=>{const H=$.label||$.name||$.alias||"";return{value:H,label:H}}))||[]},[(N=n==null?void 0:n.config)==null?void 0:N.metricColumns]),h=L.useMemo(()=>{var T,P;return((P=(T=n==null?void 0:n.config)==null?void 0:T.groupByColumns)==null?void 0:P.map($=>{const H=$.label||$.name||$.alias||"";return{value:H,label:H}}))||[]},[(E=n==null?void 0:n.config)==null?void 0:E.groupByColumns]),w=L.useMemo(()=>o.enableGrouping!==void 0?o.enableGrouping:!l&&h.length>=2,[o.enableGrouping,l,h.length]),[m,x]=L.useState(w);L.useEffect(()=>{x(w)},[w]);const f=T=>{const P={...t||{},bubbleScatterConfig:T};c(P),n&&d({...n,preferences:P})},j=T=>{c(T),n&&d({...n,preferences:T})};L.useEffect(()=>{if(!t||p.length===0)return;const T={};let P=!1;if(!o.xMetricKey&&p[0]&&(T.xMetricKey=p[0].value,P=!0),!o.yMetricKey&&p[1]&&(T.yMetricKey=p[1].value,P=!0),r&&!o.radiusMetricKey&&p[2]&&(T.radiusMetricKey=p[2].value,P=!0),!o.labelKey&&h[0]&&(T.labelKey=h[0].value,P=!0),w&&!o.groupKey&&h[1]&&(T.groupKey=h[1].value,T.enableGrouping=!0,P=!0),P){const $=bs({...o,...T});f($)}},[p,h,o,t,c,r,w]);const y=T=>{const P=bs({...o,...T});f(P)},F=T=>{x(T),y({enableGrouping:T,groupKey:T?o.groupKey:void 0})};if(!r&&!i)return null;const D=r?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(D,{className:"h-4 w-4"}),e.jsxs("span",{children:[r?"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"}),g?e.jsxs(s.Select,{value:o.labelKey||"",onValueChange:T=>y({labelKey:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select label column"})}),e.jsx(s.SelectContent,{children:h.map(T=>e.jsx(s.SelectItem,{value:T.value,children:T.label},T.value))})]}):e.jsx(ie,{className:"h-8 text-xs",placeholder:"Column name for labels",value:o.labelKey||"",onCommit:T=>y({labelKey:T})})]}),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:m,onCheckedChange:F})]}),m&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Group By"}),g?e.jsxs(s.Select,{value:o.groupKey||"",onValueChange:T=>y({groupKey:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select group column"})}),e.jsx(s.SelectContent,{children:h.map(T=>e.jsx(s.SelectItem,{value:T.value,children:T.label},T.value))})]}):e.jsx(ie,{className:"h-8 text-xs",placeholder:"Column name for grouping",value:o.groupKey||"",onCommit:T=>y({groupKey:T})})]})]}),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"}),g?e.jsxs(s.Select,{value:o.xMetricKey||"",onValueChange:T=>y({xMetricKey:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select X metric"})}),e.jsx(s.SelectContent,{children:p.map(T=>e.jsx(s.SelectItem,{value:T.value,children:T.label},T.value))})]}):e.jsx(ie,{className:"h-8 text-xs",placeholder:"Column name for X axis",value:o.xMetricKey||"",onCommit:T=>y({xMetricKey:T})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Y Axis"}),g?e.jsxs(s.Select,{value:o.yMetricKey||"",onValueChange:T=>y({yMetricKey:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select Y metric"})}),e.jsx(s.SelectContent,{children:p.map(T=>e.jsx(s.SelectItem,{value:T.value,children:T.label},T.value))})]}):e.jsx(ie,{className:"h-8 text-xs",placeholder:"Column name for Y axis",value:o.yMetricKey||"",onCommit:T=>y({yMetricKey:T})})]}),r&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Radius"}),g?e.jsxs(s.Select,{value:o.radiusMetricKey||"",onValueChange:T=>y({radiusMetricKey:T}),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{placeholder:"Select radius metric"})}),e.jsx(s.SelectContent,{children:p.map(T=>e.jsx(s.SelectItem,{value:T.value,children:T.label},T.value))})]}):e.jsx(ie,{className:"h-8 text-xs",placeholder:"Column name for radius",value:o.radiusMetricKey||"",onCommit:T=>y({radiusMetricKey:T})})]})]}),r&&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:o.radiusScale||"sqrt",onValueChange:T=>y({radiusScale:T}),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"})]})]})]}),o.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(ie,{className:"h-8 text-xs",type:"number",placeholder:"5",value:((C=o.minRadius)==null?void 0:C.toString())||"",onCommit:T=>y({minRadius:T?Number(T):void 0})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Max Radius"}),e.jsx(ie,{className:"h-8 text-xs",type:"number",placeholder:"30",value:((S=o.maxRadius)==null?void 0:S.toString())||"",onCommit:T=>y({maxRadius:T?Number(T):void 0})})]})]}),o.radiusScale==="fixed"&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(s.Label,{className:"text-xs",children:["Fixed Radius: ",o.fixedRadius||10]}),e.jsx(s.Slider,{value:[o.fixedRadius||10],onValueChange:([T])=>y({fixedRadius:T}),min:3,max:30,step:1,className:"py-2"})]})]}),i&&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: ",o.fixedRadius||5]}),e.jsx(s.Slider,{value:[o.fixedRadius||5],onValueChange:([T])=>y({fixedRadius:T}),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:((M=(I=t==null?void 0:t.xAxisConfig)==null?void 0:I.name)==null?void 0:M.enabled)??!1,onCheckedChange:T=>{var H,q,K,_;const P=o.xMetricKey||"X Axis",$=o.yMetricKey||"Y Axis";j({...t??{},xAxisConfig:{...t==null?void 0:t.xAxisConfig,name:{enabled:T,text:((q=(H=t==null?void 0:t.xAxisConfig)==null?void 0:H.name)==null?void 0:q.text)||P}},yAxisConfig:{...t==null?void 0:t.yAxisConfig,name:{enabled:T,text:((_=(K=t==null?void 0:t.yAxisConfig)==null?void 0:K.name)==null?void 0:_.text)||$}}})}})]}),((v=(b=t==null?void 0:t.xAxisConfig)==null?void 0:b.name)==null?void 0:v.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(ie,{className:"h-8 text-xs",placeholder:o.xMetricKey||"X Axis",value:((R=(A=t==null?void 0:t.xAxisConfig)==null?void 0:A.name)==null?void 0:R.text)||"",onCommit:T=>{var P;j({...t??{},xAxisConfig:{...t==null?void 0:t.xAxisConfig,name:{...(P=t==null?void 0:t.xAxisConfig)==null?void 0:P.name,enabled:!0,text:T||o.xMetricKey||"X Axis"}}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs",children:"Y Title"}),e.jsx(ie,{className:"h-8 text-xs",placeholder:o.yMetricKey||"Y Axis",value:((O=(k=t==null?void 0:t.yAxisConfig)==null?void 0:k.name)==null?void 0:O.text)||"",onCommit:T=>{var P;j({...t??{},yAxisConfig:{...t==null?void 0:t.yAxisConfig,name:{...(P=t==null?void 0:t.yAxisConfig)==null?void 0:P.name,enabled:!0,text:T||o.yMetricKey||"Y Axis"}}})}})]})]})]})]})]})}const Aa=[{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 Da(){const t=s.useEditorStore(h=>h.card),n=s.useEditorStore(h=>{var w;return(w=h.card)==null?void 0:w.preferences}),{setCardPreferences:a}=s.useEditorActions(),l=(t==null?void 0:t.type)==="funnel",c=(n==null?void 0:n.funnelConfig)||{},d=c.percentMode??"percentOfTotal",r=c.shrinkFraction??1,i=c.labelThreshold??0,o=h=>{const w={...c,...h};a({...n||{},funnelConfig:w})},u=h=>{o({percentMode:h})},g=h=>{o({shrinkFraction:h[0]})},p=h=>{o({labelThreshold:h[0]})};return l?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:h=>u(h),className:"space-y-2",children:Aa.map(h=>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-${h.value}`,value:h.value,className:"mt-0.5"}),e.jsxs(s.Label,{htmlFor:`funnel-${h.value}`,className:"flex flex-col gap-0.5 text-sm font-normal",children:[e.jsx("span",{className:"font-medium",children:h.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:h.description})]})]},h.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:[r],onValueChange:g,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(r*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:[i],onValueChange:p,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:i===0?"Showing all labels":`Hide labels below ${i}%`})]})]})]}):null}function Fe(){const t=s.useEditorStore(d=>d.card),{data:n}=s.useDashboardCardQuery(t),{keys:a}=s.getKeys((n==null?void 0:n.records)||[]),l=a.slice(1).filter(d=>!s.METADATA_KEYS.includes(d));let c=l;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:r}=s.getKeys(d);c=r.slice(1)}return{transformedMetricKeys:c,dimensionKeys:a.slice(0,1),keys:a,defaultMetricKeys:l}}const La=[{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"}],Ma=[{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)"}],Oa=["center","start","end"],Ra=["center","start","end","top","bottom"];function Be({config:t,onChange:n,isHorizontal:a=!1,showAutoFormat:l=!0,positionOptions:c,showAppearance:d=!0}){var m,x,f,j,y,F;const r=c??(a?["auto","center","left","right","custom"]:["auto","center","top","bottom","custom"]),i=l?["auto","number","currency","percent","none"]:["number","currency","percent","none"],o=(D,N)=>{const E={...t,[D]:N};n(E)},u=(D,N)=>{const E={...t,font:{...(t==null?void 0:t.font)||{},[D]:N}};n(E)},g=(D,N)=>{const E={...t,formatOptions:{...(t==null?void 0:t.formatOptions)||{},[D]:N}};n(E)},p=()=>a?"Right":"Top",h=t||{},w=h.format||(l?"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:h.position||"auto",onValueChange:D=>o("position",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:r.map(D=>e.jsx(s.SelectItem,{value:D,className:"text-xs",children:D==="auto"?p():D==="custom"?"Custom (Advanced)":s.titleCase(D)},D))})]})]}),h.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:h.anchor||"center",onValueChange:D=>o("anchor",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Oa.map(D=>e.jsx(s.SelectItem,{value:D,className:"text-xs",children:s.titleCase(D)},D))})]})]}),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(h.align||"center"),onValueChange:D=>o("align",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-24 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ra.map(D=>e.jsx(s.SelectItem,{value:D,className:"text-xs",children:s.titleCase(D)},D))})]})]})]}),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:w,onValueChange:D=>o("format",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:i.map(D=>e.jsx(s.SelectItem,{value:D,className:"text-xs",children:D==="auto"&&l?"Auto (Use Axis)":D==="none"?"None (Raw Value)":s.titleCase(D)},D))})]})]}),!["auto","none"].includes(w)&&e.jsxs("div",{className:"space-y-2 rounded-md border border-border bg-background p-2",children:[["number","currency","percent"].includes(w)&&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(ce,{type:"number",placeholder:"0",value:String(((m=h.formatOptions)==null?void 0:m.decimalPlaces)??(w==="currency"?2:w==="percent"?1:0)),onSave:D=>g("decimalPlaces",Number(D)),className:""})})]}),w==="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:((x=h.formatOptions)==null?void 0:x.currency)||"USD",onValueChange:D=>g("currency",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:La.map(D=>e.jsx(s.SelectItem,{value:D.value,className:"text-xs",children:D.label},D.value))})]})]}),["number","currency"].includes(w)&&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:((f=h.formatOptions)==null?void 0:f.useSuffix)??!1,onCheckedChange:D=>g("useSuffix",D)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{className:"text-xs",children:"Locale"}),e.jsxs(s.Select,{value:((j=h.formatOptions)==null?void 0:j.locale)||"en-US",onValueChange:D=>g("locale",D),children:[e.jsx(s.SelectTrigger,{className:"h-7 w-28 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ma.map(D=>e.jsx(s.SelectItem,{value:D.value,className:"text-xs",children:D.label},D.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(ce,{type:"number",placeholder:"12",value:String(((y=h.font)==null?void 0:y.size)||12),onSave:D=>u("size",Number(D)),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:((F=h.font)==null?void 0:F.weight)||"normal",onValueChange:D=>u("weight",D),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:h.color==="auto"||!h.color?"auto":"custom",onValueChange:D=>{D==="auto"&&o("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(ce,{type:"number",placeholder:"0",value:String(h.rotation||0),onSave:D=>o("rotation",Number(D)),className:""})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"°"})]})]})]})]})]})}const Fa=[{type:"bar",icon:s.ChartColumnIncreasing,label:"Bar"},{type:"line",icon:s.ChartLine,label:"Line"}],Ba=[0,1,2,3,4,5,6,8,10],Pa=[{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 │"}],Va=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function za(){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($a,{})})]})}function $a(){const{transformedMetricKeys:t}=Fe();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(qa,{metricKey:n,idx:a},n))})}function qa({metricKey:t,idx:n}){var j;const[a,l]=L.useState(!1),c=s.useEditorStore(y=>{var F;return(F=y.card)==null?void 0:F.preferences}),d=s.useEditorStore(y=>{var F,D;return(D=(F=y.card)==null?void 0:F.preferences)==null?void 0:D.datasetOptions}),r=d==null?void 0:d.find(y=>y.idx===n),{setCardPreferences:i}=s.useEditorStore(y=>y.actions),o=(r==null?void 0:r.type)||"bar",u=(r==null?void 0:r.yAxisId)||"y",g=((j=r==null?void 0:r.dataLabels)==null?void 0:j.enabled)??!1,p=o==="line"?s.ChartLine:s.ChartColumnIncreasing;function h(y){const F={idx:n,type:o,yAxisId:u,dataLabels:r==null?void 0:r.dataLabels,...y};if(!r)i({...c||{},datasetOptions:[...d||[],F]});else{const D=d==null?void 0:d.map(N=>N.idx===n?{...N,...F}:N);i({...c||{},datasetOptions:D})}}function w(y){h({type:y})}function m(y){h({yAxisId:y})}function x(y){h({dataLabels:{...r==null?void 0:r.dataLabels,enabled:y}})}function f(y){h({dataLabels:y})}return e.jsx(s.Collapsible,{open:a,onOpenChange:l,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 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:"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(p,{className:"h-3 w-3"}),o==="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:u==="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:Fa.map(({type:y,icon:F,label:D})=>{const N=o===y;return e.jsxs("button",{onClick:()=>w(y),className:s.cn("flex items-center gap-2 rounded-md border px-3 py-1.5 text-xs transition-colors",N?"border-primary bg-primary/10 text-primary":"border-border bg-background text-muted-foreground hover:bg-muted"),children:[e.jsx(F,{className:"h-4 w-4"}),e.jsx("span",{children:D})]},y)})})]}),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:u,onValueChange:y=>m(y),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)"})]})]})]})]}),o==="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:(r==null?void 0:r.lineStyle)||"solid",onValueChange:y=>h({lineStyle:y}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Va.map(({value:y,label:F})=>e.jsx(s.SelectItem,{value:y,className:"text-xs",children:F},y))})]})]}),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((r==null?void 0:r.pointRadius)??3),onValueChange:y=>h({pointRadius:Number(y)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ba.map(y=>e.jsx(s.SelectItem,{value:String(y),className:"text-xs",children:y===0?"None":y},y))})]})]}),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:(r==null?void 0:r.pointStyle)||"circle",onValueChange:y=>h({pointStyle:y}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Pa.map(({value:y,label:F})=>e.jsx(s.SelectItem,{value:y,className:"text-xs",children:F},y))})]})]})]})]}),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:g,onCheckedChange:x})]}),g&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Be,{config:r==null?void 0:r.dataLabels,onChange:f,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const Ke=[{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"}],Ka=[0,1,2,3,4,5,6,8,10],Ga=[{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 │"}],Ua=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function _a(t){return t==null?"origin":t===!1?"false":t}function Ha(){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(Ja,{})})]})}function Ja(){const{transformedMetricKeys:t}=Fe();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(Ya,{metricKey:n,idx:a},n))})}function Ya({metricKey:t,idx:n}){var x;const[a,l]=L.useState(!1),c=s.useEditorStore(f=>{var j;return(j=f.card)==null?void 0:j.preferences}),d=s.useEditorStore(f=>{var j,y;return(y=(j=f.card)==null?void 0:j.preferences)==null?void 0:y.datasetOptions}),r=d==null?void 0:d.find(f=>f.idx===n),{setCardPreferences:i}=s.useEditorStore(f=>f.actions),o=_a(r==null?void 0:r.fill),u=((x=r==null?void 0:r.dataLabels)==null?void 0:x.enabled)??!1,g=Ke.find(f=>f.value===o)||Ke[0];function p(f){const j={idx:n,fill:o,dataLabels:r==null?void 0:r.dataLabels,...f};if(!r)i({...c||{},datasetOptions:[...d||[],j]});else{const y=d==null?void 0:d.map(F=>F.idx===n?{...F,...j}:F);i({...c||{},datasetOptions:y})}}function h(f){p({fill:f==="false"?!1:f})}function w(f){p({dataLabels:{...r==null?void 0:r.dataLabels,enabled:f}})}function m(f){p({dataLabels:f})}return e.jsx(s.Collapsible,{open:a,onOpenChange:l,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 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:"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"}),g.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:o,onValueChange:f=>h(f),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ke.map(f=>e.jsx(s.SelectItem,{value:f.value,className:"text-xs",children:e.jsx("div",{className:"flex flex-col",children:e.jsx("span",{children:f.label})})},f.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:(r==null?void 0:r.lineStyle)||"solid",onValueChange:f=>p({lineStyle:f}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ua.map(({value:f,label:j})=>e.jsx(s.SelectItem,{value:f,className:"text-xs",children:j},f))})]})]}),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((r==null?void 0:r.pointRadius)??3),onValueChange:f=>p({pointRadius:Number(f)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ka.map(f=>e.jsx(s.SelectItem,{value:String(f),className:"text-xs",children:f===0?"None":f},f))})]})]}),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:(r==null?void 0:r.pointStyle)||"circle",onValueChange:f=>p({pointStyle:f}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ga.map(({value:f,label:j})=>e.jsx(s.SelectItem,{value:f,className:"text-xs",children:j},f))})]})]})]})]}),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:u,onCheckedChange:w})]}),u&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Be,{config:r==null?void 0:r.dataLabels,onChange:m,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const Qa=[0,1,2,3,4,5,6,8,10],Wa=[{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 │"}],Ge=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function Xa(){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(Za,{})})]})}function Za(){const{transformedMetricKeys:t}=Fe();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(en,{metricKey:n,idx:a},n))})}function en({metricKey:t,idx:n}){var f;const[a,l]=L.useState(!1),c=s.useEditorStore(j=>{var y;return(y=j.card)==null?void 0:y.preferences}),d=s.useEditorStore(j=>{var y,F;return(F=(y=j.card)==null?void 0:y.preferences)==null?void 0:F.datasetOptions}),r=d==null?void 0:d.find(j=>j.idx===n),{setCardPreferences:i}=s.useEditorStore(j=>j.actions),o=(r==null?void 0:r.lineStyle)||"solid",u=(r==null?void 0:r.pointRadius)??3,g=(r==null?void 0:r.pointStyle)||"circle",p=((f=r==null?void 0:r.dataLabels)==null?void 0:f.enabled)??!1,h=Ge.find(j=>j.value===o)||Ge[0];function w(j){const y={idx:n,lineStyle:o,pointRadius:u,pointStyle:g,dataLabels:r==null?void 0:r.dataLabels,...j};if(!r)i({...c||{},datasetOptions:[...d||[],y]});else{const F=d==null?void 0:d.map(D=>D.idx===n?{...D,...y}:D);i({...c||{},datasetOptions:F})}}function m(j){w({dataLabels:{...r==null?void 0:r.dataLabels,enabled:j}})}function x(j){w({dataLabels:j})}return e.jsx(s.Collapsible,{open:a,onOpenChange:l,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 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:"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"}),h.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:o,onValueChange:j=>w({lineStyle:j}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Ge.map(({value:j,label:y})=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:y},j))})]})]}),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(u),onValueChange:j=>w({pointRadius:Number(j)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Qa.map(j=>e.jsx(s.SelectItem,{value:String(j),className:"text-xs",children:j===0?"None":j},j))})]})]}),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:g,onValueChange:j=>w({pointStyle:j}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:Wa.map(({value:j,label:y})=>e.jsx(s.SelectItem,{value:j,className:"text-xs",children:y},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 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(Be,{config:r==null?void 0:r.dataLabels,onChange:x,isHorizontal:!1,showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const sn=[0,2,4,6,8,10,12,16,20];function tn(){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(an,{})})]})}function an(){const{transformedMetricKeys:t}=Fe();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(nn,{metricKey:n,idx:a},n))})}function nn({metricKey:t,idx:n}){var m;const[a,l]=L.useState(!1),c=s.useEditorStore(x=>{var f;return(f=x.card)==null?void 0:f.type}),d=s.useEditorStore(x=>{var f;return(f=x.card)==null?void 0:f.preferences}),r=s.useEditorStore(x=>{var f,j;return(j=(f=x.card)==null?void 0:f.preferences)==null?void 0:j.datasetOptions}),i=r==null?void 0:r.find(x=>x.idx===n),{setCardPreferences:o}=s.useEditorStore(x=>x.actions),u=(i==null?void 0:i.borderRadius)??0,g=((m=i==null?void 0:i.dataLabels)==null?void 0:m.enabled)??!1;function p(x){const f={idx:n,borderRadius:u,dataLabels:i==null?void 0:i.dataLabels,...x};if(!i)o({...d||{},datasetOptions:[...r||[],f]});else{const j=r==null?void 0:r.map(y=>y.idx===n?{...y,...f}:y);o({...d||{},datasetOptions:j})}}function h(x){p({dataLabels:{...i==null?void 0:i.dataLabels,enabled:x}})}function w(x){p({dataLabels:x})}return e.jsx(s.Collapsible,{open:a,onOpenChange:l,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 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:"truncate text-xs font-medium",title:t,children:t})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:u>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:",u]})})]})}),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(u),onValueChange:x=>p({borderRadius:Number(x)}),children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:sn.map(x=>e.jsx(s.SelectItem,{value:String(x),className:"text-xs",children:x===0?"None":`${x}px`},x))})]})]})})]}),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:g,onCheckedChange:h})]}),g&&e.jsx("div",{className:"rounded-md border border-border bg-background p-2",children:e.jsx(Be,{config:i==null?void 0:i.dataLabels,onChange:w,isHorizontal:c==="horizontalBar",showAutoFormat:!0,showAppearance:!0})})]})]})})})]})})}const rn=[0,1,2,3,4,5,6,8,10],ln=[{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 │"}],on=[{value:"solid",label:"Solid ───"},{value:"dashed",label:"Dashed - - -"},{value:"dotted",label:"Dotted ···"},{value:"dash-dot",label:"Dash-Dot -·-·"}];function cn(){const t=s.useEditorStore(r=>r.card),n=s.useEditorStore(r=>{var i;return(i=r.card)==null?void 0:i.preferences}),a=n==null?void 0:n.lineStyleConfig,{setCardPreferences:l,updateCardInFrame:c}=s.useEditorActions();if(!t||!["line","area","stackedArea"].includes(t.type))return null;const d=(r,i)=>{const o={...n||{},lineStyleConfig:{...a,[r]:i}};l(o),c({...t,preferences:o})};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(jt,{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:(a==null?void 0:a.lineStyle)||"solid",onValueChange:r=>d("lineStyle",r),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:on.map(({value:r,label:i})=>e.jsx(s.SelectItem,{value:r,className:"text-xs",children:i},r))})]})]}),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((a==null?void 0:a.pointRadius)??3),onValueChange:r=>d("pointRadius",Number(r)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:rn.map(r=>e.jsx(s.SelectItem,{value:String(r),className:"text-xs",children:r===0?"None":r},r))})]})]}),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:(a==null?void 0:a.pointStyle)||"circle",onValueChange:r=>d("pointStyle",r),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ln.map(({value:r,label:i})=>e.jsx(s.SelectItem,{value:r,className:"text-xs",children:i},r))})]})]})]})})]})}const dn=[0,2,4,6,8,10,12,16,20],un=[{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%"}],mn=[{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 xn(){const t=s.useEditorStore(r=>r.card),n=s.useEditorStore(r=>{var i;return(i=r.card)==null?void 0:i.preferences}),a=n==null?void 0:n.barStyleConfig,{setCardPreferences:l,updateCardInFrame:c}=s.useEditorActions();if(!t||!["bar","horizontalBar","stackedBar"].includes(t.type))return null;const d=(r,i)=>{const o={...n||{},barStyleConfig:{...a,[r]:i}};l(o),c({...t,preferences:o})};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((a==null?void 0:a.borderRadius)??0),onValueChange:r=>d("borderRadius",Number(r)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:dn.map(r=>e.jsx(s.SelectItem,{value:String(r),className:"text-xs",children:r===0?"None":`${r}px`},r))})]})]}),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((a==null?void 0:a.barPercentage)??.9),onValueChange:r=>d("barPercentage",Number(r)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:un.map(({value:r,label:i})=>e.jsx(s.SelectItem,{value:r,className:"text-xs",children:i},r))})]})]}),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((a==null?void 0:a.categoryPercentage)??.8),onValueChange:r=>d("categoryPercentage",Number(r)),children:[e.jsx(s.SelectTrigger,{className:"h-8 text-xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:mn.map(({value:r,label:i})=>e.jsx(s.SelectItem,{value:r,className:"text-xs",children:i},r))})]})]})]})})]})}function hn(){const t=s.useEditorStore(a=>{var l,c;return(c=(l=a==null?void 0:a.card)==null?void 0:l.preferences)==null?void 0:c.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(pe,{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)}})]})})]})}function $s({mode:t}){const n=s.useEditorStore(a=>{var l;return(l=a.card)==null?void 0:l.type});return e.jsxs(e.Fragment,{children:[n==="combo"&&e.jsx(za,{}),(n==="area"||n==="stackedArea")&&e.jsx(Ha,{}),n==="line"&&e.jsx(Xa,{}),(n==="bar"||n==="horizontalBar"||n==="stackedBar")&&e.jsx(tn,{}),e.jsx(cn,{}),e.jsx(xn,{}),e.jsx(wa,{}),t==="config"&&e.jsx(Sa,{}),t==="config"&&e.jsx(Ca,{}),e.jsx(Ea,{}),n==="bullet"&&e.jsx(ka,{}),n==="funnel"&&e.jsx(Da,{}),(n==="bubble"||n==="scatter")&&e.jsx(Ia,{}),(n==="stackedBar"||n==="stackedLine")&&e.jsx(hn,{}),e.jsx(ha,{}),e.jsx(ba,{}),e.jsx(va,{}),e.jsx(ya,{})]})}function pn(){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(Re,{chartType:n}),e.jsx(s.Accordion,{type:"single",collapsible:!0,className:"w-full px-2",children:e.jsx($s,{mode:"dev"})})]}):null}function gn(){const t=s.useEditorStore(a=>a.card.type);function n(){switch(t){case"kpi":return e.jsx(sa,{});case"table":return e.jsx(ia,{});case"map":return e.jsx(ra,{});case"custom":return e.jsx("div",{className:"px-6 py-2",children:e.jsx(Ps,{})});case"text":return e.jsx(da,{});default:return e.jsx(pn,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[n(),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function fn(){const t=L.useRef(null),n=L.useRef(null),a=s.useEditorStore(c=>c.isShowingVisual),l=s.useEditorStore(c=>c.showAIDialog);return L.useEffect(()=>{var c,d,r,i;l?((c=t.current)==null||c.resize(0),(d=n.current)==null||d.resize(0)):((r=t.current)==null||r.resize(25),(i=n.current)==null||i.resize(25))},[l]),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(Lt,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:a&&!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(gn,{})})}),!l&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(us,{})})]}):e.jsx(us,{})})]})}function jn(t){var de;s.useAIInteractionStore(z=>z.currentAIContext);const[n,a]=L.useState(""),[l,c]=L.useState(null),{authToken:d,tokenProps:r}=s.useSemaphorContext(),i=s.useEditorStore(z=>{var ee;return(ee=z==null?void 0:z.card)==null?void 0:ee.sql}),o=s.useEditorStore(z=>z.isDevMode),u=s.useEditorStore(z=>{var ee;return(ee=z==null?void 0:z.card)==null?void 0:ee.python}),{setCardPython:g,setCardSql:p,setRunSql:h,switchCardType:w,setQueryConfig:m}=s.useEditorActions(),x=s.useEditorStore(z=>z.currentAssitantScope)||[],f=s.useEditorStore(z=>z.userInputForAI),j=s.useEditorStore(z=>z.triggerAIRun),y=s.useEditorStore(z=>z.card),F=s.useEditorStore(z=>z.selectedDatabaseName),D=s.useEditorStore(z=>z.selectedTableName),N=s.useEditorStore(z=>z.selectedConnectionId),E=s.useEditorStore(z=>z.selectedSchemaName),C=s.useDashboardStore(z=>z.dashboard.aiScopeTables),{errorMessage:S,refetch:I,data:M}=s.useDashboardCardQuery(y),{setTriggerAIRun:b,setCurrentAssitantScope:v,setCardConfig:A}=s.useEditorActions(),{selectedDatamodelName:R,connectionType:k,selectedDatamodelId:O}=s.useEditorAside(),T=(de=s.useDashboardQuery().data)==null?void 0:de.assistantProfileId,{messages:P,setMessages:$,regenerate:H,error:q,sendMessage:K,status:_,addToolResult:B,stop:U,clearError:V}=s.useChat({transport:new s.DefaultChatTransport({api:`${r.apiServiceUrl}/v1/assistant`,headers:()=>({Authorization:`Bearer ${d==null?void 0:d.accessToken}`}),body:()=>{const z=s.useAIInteractionStore.getState();return{random:Math.random(),assistantId:"editor-assistant",assistantProfileId:T,isDevMode:o,aiContext:z.currentAIContext,reasoningEffort:z.reasoningEffort,showReasoning:z.showReasoning}},credentials:"omit",prepareSendMessagesRequest:({messages:z,body:ee})=>({body:{...ee,messages:s.cleanupIncompleteMessages(z)}})}),onError:z=>{var ee;if(z.name==="AbortError"||(ee=z.message)!=null&&ee.includes("aborted")){console.log("[Editor Assistant] Stream aborted (expected)");return}console.error("[Editor Assistant] Stream error:",z)},onToolCall:W,onFinish({isAbort:z,isDisconnect:ee,isError:ue}){a(""),console.log(z?"[Editor Assistant] Stream aborted by user":ee?"[Editor Assistant] Stream disconnected (network error)":ue?"[Editor Assistant] Stream error occurred":"[Editor Assistant] Stream completed successfully")}});L.useEffect(()=>{j&&f&&(K({role:"user",parts:[{type:"text",text:f}]}),b(!1))},[j,f,K,b]);async function W({toolCall:z}){var ee,ue,me,Se,xe,je,he,be,we,ge,Te,Ee,ke,Ie,ve,ye;if(["createChartFromSql","createForecast"].includes(z.toolName)){const Y=((ee=z.input)==null?void 0:ee.sql)??((ue=z.args)==null?void 0:ue.sql),ne=((me=z.input)==null?void 0:me.python)??((Se=z.args)==null?void 0:Se.python),re=((xe=z.input)==null?void 0:xe.chartType)??((je=z.args)==null?void 0:je.chartType);w(re),p(Y),g(ne),h(!0),B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"success",message:"Let the user know that chart is created"}})}else if(z.toolName==="getUserSql"){if(!i){B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"error",message:"No SQL found"}});return}B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"success",sql:i,python:u||""}})}else if(z.toolName==="generateQueryConfig"){a("Generating query config...");const Y=((he=z.input)==null?void 0:he.chartType)??((be=z.args)==null?void 0:be.chartType),ne=((we=z.input)==null?void 0:we.queryConfig)??((ge=z.args)==null?void 0:ge.queryConfig);((Te=z.input)==null?void 0:Te.cardConfig)??((Ee=z.args)==null||Ee.cardConfig),w(Y),A(ne),p(void 0),g(void 0);const re=await I();if((ke=re==null?void 0:re.data)!=null&&ke.error){B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"error",queryConfig:ne,message:(Ie=re==null?void 0:re.data)==null?void 0:Ie.error.message}});return}if((ve=re==null?void 0:re.data)!=null&&ve.records){B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"success",queryConfig:ne,message:"The data has been visualized"}});return}B({tool:z.toolName,toolCallId:z.toolCallId,output:{status:"success",queryConfig:ne,message:"The data has been visualized",records:(ye=re==null?void 0:re.data)==null?void 0:ye.records}})}else a("Analyzing...")}function X(z){const ee=s.removeFromScopeArray(x,z);se(ee)}function se(z){const ee=s.sanitizeAIScope(z);v(ee),$(ue=>[...ue,{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 J(){const z={databaseName:F||"",schemaName:E||"",tableName:D||"",datamodelId:O||"",datamodelName:s.resolveDatamodelName(R),connectionId:N||"",connectionType:k||""},ee=s.dedup([...x,z]);se(ee)}function te(){const z={databaseName:F||"",schemaName:E||"",tableName:D||"",datamodelName:s.resolveDatamodelName(R),connectionId:N||"",connectionType:k||"",datamodelId:O||""};if(!s.isInAiScopeArray([...C||[],...x],z)||x.length===0){const ue=s.dedup([...C||[],...x,z]).filter(me=>me.connectionId===z.connectionId);se(ue)}}const Q=!["ready","error"].includes(_),le=s.getErrorMessage(q);return{messages:P,setMessages:$,sendMessage:K,regenerate:H,isLoading:Q,handleSetAIScope:te,handleAddCurrentTableToScope:J,removeFromCurrentSelections:X,currentAssitantScope:x,setCurrentAssitantScope:v,stop:U,status:_,toolStatus:n,llmUsage:l,onFinish:t,errorMessage:le,clearError:V}}const bn=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function vs({isFullscreen:t,onFullscreenChange:n,fullscreenContainer:a}){const l=L.useRef(null),[c,d]=L.useState(!1),[r,i]=L.useState(s.isDevEnv),[o,u]=L.useState(!1),[g,p]=L.useState(!1),[h,w]=L.useState(!1),m=t??h,x=s.useCurrentAIContext(),{setCurrentAIContext:f}=s.useAIActions(),{clearQueue:j}=s.useQueueActions(),{clearFileAttachments:y}=s.useFileActions(),F=s.useFileAttachments("editor"),D=s.useDashboardStore(Y=>Y.dashboard.aiContext),N=s.useEditorStore(Y=>Y.card.dataSource),E=s.useEditorStore(Y=>Y.actions.setCardSql),C=s.useEditorStore(Y=>Y.actions.setRunSql),S=s.useEditorStore(Y=>Y.showAIDialog),I=s.useDashboardStore(Y=>Y.handleOpenAssistantProfile),{setShowAIDialog:M,setCardPython:b}=s.useEditorActions(),{setDataSource:v}=s.useEditorActions(),{assistantProfile:A}=s.useAssistantProfile(),{messages:R,setMessages:k,sendMessage:O,isLoading:T,stop:P,status:$,llmUsage:H,errorMessage:q,clearError:K}=jn(),[_,B]=L.useState(""),U=Y=>{B(Y.target.value)},V=Y=>{Y.preventDefault();const ne=_.trim();if(!ne&&F.length===0)return;const re=[];ne&&re.push({type:"text",text:ne}),F.forEach(Ne=>{Ne.data&&re.push({type:"file",mediaType:Ne.type,filename:Ne.name,url:`data:${Ne.type};base64,${Ne.data}`})}),O({role:"user",parts:re}),B(""),y("editor"),ee({force:!0})},{visibleMessages:W,hasMoreMessages:X,totalMessageCount:se,loadMoreMessages:J,resetMessageWindow:te}=s.useMessageWindow(R,{maxVisibleMessages:15,initialLoadCount:10,loadMoreCount:5}),{scrollRef:Q,isAtBottom:le,hasNewMessages:de,newMessageCount:z,scrollToBottom:ee,handleScroll:ue,resetNewMessageCount:me}=s.useAutoScroll(W,{threshold:50,behavior:"smooth",isStreaming:T});L.useEffect(()=>{var Y;S&&((Y=l.current)==null||Y.focus(),f({selectedEntities:(N==null?void 0:N.selectedEntities)||[]}))},[S,N,f]),s.useAutoSubmitQueue({assistantType:"editor",status:$,isLoading:T,sendMessage:O});const{hasActiveTools:Se}=s.useActiveToolStatus(R),xe=L.useCallback(Y=>{n==null||n(Y),t===void 0&&w(Y)},[t,n]);L.useEffect(()=>{if(!m)return;function Y(ne){ne.key==="Escape"&&xe(!1)}return window.addEventListener("keydown",Y),()=>{window.removeEventListener("keydown",Y)}},[m,xe]);const je=L.useCallback(Y=>{O({role:"user",parts:[{type:"text",text:Y}]}),ee({force:!0})},[O,ee]),he=L.useCallback(async()=>{const Y=JSON.stringify(R??[],null,2);try{if(typeof navigator>"u"||!navigator.clipboard)throw new Error("Clipboard API unavailable");await navigator.clipboard.writeText(Y),s.ue.success("Conversation copied")}catch(ne){console.error("Failed to copy conversation",ne),s.ue.error("Unable to copy conversation")}},[R]),be=L.useCallback(()=>{xe(!m)},[m,xe]);function we(Y,ne){ne==="sql"?(E(Y),C(!0)):ne==="python"&&(b(Y),C(!0))}function ge(){x.selectedEntities.length===0&&f({selectedEntities:(D==null?void 0:D.selectedEntities)||[]})}function Te(Y){ge();const ne={role:"user",parts:[{type:"text",text:Y.title+" "+Y.subtitle}]};O(ne)}function Ee(Y){ge(),O({role:"user",parts:[{type:"text",text:Y}]})}function ke(){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:c,onCheckedChange:d,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:r,onCheckedChange:i,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:o,onCheckedChange:u,children:"System Message"})]})]})}function Ie(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const ve=(_==null?void 0:_.length)===0&&(R==null?void 0:R.filter(Y=>Y.role==="user").length)===0,ye=e.jsxs("div",{"data-role":"editor-assistant",className:s.cn("flex h-full w-full flex-col justify-between px-6 py-4",m&&"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:[Ie(),I&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:I,children:(A==null?void 0:A.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[ke(),r&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-2 h-7 px-2 text-muted-foreground hover:text-foreground",onClick:he,children:"Copy Conversation"}),e.jsx(s.IconButton,{tooltip:m?"Exit Fullscreen":"Expand",className:"h-7 p-2 text-muted-foreground hover:text-foreground",onClick:be,children:m?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:()=>{k([]),j("editor"),K(),te()},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:()=>{M(!1)},children:e.jsx(s.X,{className:"size-4"})})]})]}),e.jsx(s.CustomScrollArea,{ref:Q,className:"mt-2 flex w-full grow basis-0",onScroll:ue,children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[X&&e.jsx("div",{className:"flex justify-center py-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:J,className:"text-xs",children:["Load ",Math.min(5,se-W.length)," ","more messages (",se-W.length," ","hidden)"]})}),e.jsx(s.PrintMessages,{messages:W,showTools:r,handleRun:we,showSystemMessage:o,onQuickReply:je,disableQuickReplies:T}),!Se&&e.jsx(s.AssistantStatus,{status:$,errorMessage:q})]})}),S&&!le&&e.jsx("div",{className:"absolute bottom-24 right-8 z-10",children:e.jsxs(s.Button,{onClick:()=>{ee({force:!0}),me()},size:"sm",variant:"secondary",className:"rounded-full shadow-lg","aria-label":"Scroll to bottom",children:[e.jsx(s.ChevronDown,{className:"h-4 w-4"}),de&&z>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:z>9?"9+":z})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[ve&&!A&&e.jsx(s.Placeholders,{onClick:Te,placeholders:bn}),e.jsx("div",{children:ve&&A&&e.jsx(s.SeedQuestions,{seedQuestions:A.seedQuestions||[],handleSeedQuestionClick:Ee})})]}),e.jsx(s.PendingMessagesDisplay,{assistantType:"editor",className:"mb-3"}),e.jsx(s.ChatInputWithContext,{ref:l,setInput:B,stop:P,input:_,handleInputChange:U,handleSubmit:Y=>{ge(),V(Y),ee({force:!0})},isLoading:T,status:$,assistantType:"editor",onFocus:()=>{}})]}),H&&c&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",H.inputTokens," prompt tokens, ",H.outputTokens," ","completion tokens, ",H.totalTokens," total tokens"]})}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(N==null?void 0:N.selectedEntities)||[],open:g,onOpenChange:p,dataSource:N||s.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]});return m&&a?Ws.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:ye})}),a):ye}function vn({selectedChart:t,onChartChange:n}){const[a,l]=L.useState(!1),c=s.useEditorStore(i=>i.card),d=()=>{var o;if(t==="custom")return((o=c==null?void 0:c.customCardPreferences)==null?void 0:o.componentName)||"Custom Visual";const i=s.chartTypes.find(u=>u.id===t);return(i==null?void 0:i.label)||"Select chart type"},r=()=>{var o;if(t==="custom"){const u=(o=c==null?void 0:c.customCardPreferences)==null?void 0:o.componentName;if(u){const g=s.getAutoDetectedChartIcon(u);return g||e.jsx(s.ChartIcon,{chartName:u,isCustom:!0,className:"h-4 w-4"})}return e.jsx(s.Shapes,{className:"h-4 w-4"})}const i=s.chartTypes.find(u=>u.id===t);if(i){const u=i.icon;return e.jsx(u,{className:"h-4 w-4"})}return e.jsx(s.Shapes,{className:"h-4 w-4"})};return e.jsx("div",{children:e.jsxs(s.Popover,{open:a,onOpenChange:l,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":a,className:"w-full justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r(),e.jsx("span",{children:d()})]}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[360px] p-3",align:"start",onOpenAutoFocus:i=>i.preventDefault(),children:e.jsx(Rs,{onChartSelect:i=>n(i),onClose:()=>l(!1)})})]})})}let yn=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce((n,a)=>(a&=63,a<36?n+=a.toString(36):a<62?n+=(a-26).toString(36).toUpperCase():a>62?n+="-":n+="_",n),"");const Oe=[{id:"sum",label:"Sum",symbol:"+",description:"Add two metrics together",template:()=>"({field_0} + {field_1})",requiresTwoInputs:!0},{id:"difference",label:"Difference",symbol:"−",description:"Subtract one metric from another",template:()=>"({field_0} - {field_1})",requiresTwoInputs:!0},{id:"product",label:"Product (Multiplication)",symbol:"×",description:"Multiply two metrics",template:()=>"({field_0} * {field_1})",requiresTwoInputs:!0},{id:"ratio",label:"Ratio",symbol:"÷",description:"Divide one metric by another",template:()=>"({field_0} / NULLIF({field_1}, 0))",requiresTwoInputs:!0},{id:"change",label:"Change",symbol:"Δ",description:"Calculate percentage change from A to B",template:()=>"(({field_1} - {field_0}) / NULLIF({field_0}, 0))",requiresTwoInputs:!0},{id:"percentage",label:"Percentage",symbol:"%",description:"Calculate (A / B) × 100",template:()=>"(({field_0} / NULLIF({field_1}, 0)) * 100)",requiresTwoInputs:!0},{id:"scale",label:"Scale (Multiply by Factor)",symbol:"×n",description:"Multiply a metric by a constant factor",template:()=>"({field_0} * {constant})",requiresTwoInputs:!1},{id:"custom",label:"Custom Expression",symbol:"{}",description:"Drag fields to create custom expression with tokens",requiresTwoInputs:!1,allowsCustomExpression:!0}];function Nn(t,n,a,l,c,d,r,i,o){const u=Oe.find(x=>x.id===n);if(!u)throw new Error(`Unknown operation: ${n}`);let g,p=[],h;if(n==="custom"){if(!(i!=null&&i.trim()))throw new Error("Custom expression is required");g=i.trim()}else if(n==="scale"){if(!a)throw new Error("Metric A is required for scale operation");if(o===void 0||o===0)throw new Error("Constant factor is required for scale operation");g=u.template().replace("{constant}",String(o)),p=[a],h=o}else{if(!a||!l)throw new Error("Metrics A and B are required for standard operations");g=u.template(),p=[a,l]}const w={operation:n,inputFields:p,...h!==void 0&&{constant:h}};return{id:r||`calc_${yn(10)}`,name:t.toLowerCase().replace(/\s+/g,"_"),label:t,alias:t.toLowerCase().replace(/\s+/g,"_"),qualifiedFieldName:t.toLowerCase().replace(/\s+/g,"_"),dataType:"number",role:"metric",aggregate:"SUM",expression:g,calculatedFormula:w,entityId:d,entityName:s.CALCULATED_FIELD_ENTITY_MARKER,entityType:"table",description:`Calculated field: ${t}`}}function ys(t){var l,c;const n=Oe.find(d=>d.id===t.operation);if(!n)return"Unknown operation";if(t.operation==="custom")return"Custom expression";if(t.operation==="scale"){const d=((l=t.inputFields[0])==null?void 0:l.label)||((c=t.inputFields[0])==null?void 0:c.name)||"A",r=t.constant??1;return`${d} × ${r}`}return t.inputFields.map(d=>d.label||d.name).join(` ${n.symbol} `)}const Xe=({dataType:t})=>s.getFieldIconComponent(t);function Cn({aliasTemplate:t,onAliasTemplateChange:n}){var o;const[a,l]=L.useState(t),[c,d]=L.useState(!1),r=(o=s.useEditorStore(u=>{var g;return(g=u.card.config)==null?void 0:g.pivotByColumns}))==null?void 0:o[0],i=r?`e.g. Min Sales in {{${r.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,{placeholder:i,value:c?a:t,onChange:u=>{l(u.target.value),d(!0)},onFocus:()=>d(!0),onPointerDown:u=>u.stopPropagation(),className:"h-8 text-xs",onKeyDown:u=>{u.key==="Enter"&&c&&a!==t?(n(a),d(!1)):u.key==="Escape"&&(l(t),d(!1))},"aria-label":"Edit alias template"}),c&&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:()=>{l(t),d(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Sn({valueAliases:t,onValueAliasesChange:n}){const[a,l]=L.useState(null),[c,d]=L.useState(""),[r,i]=L.useState(""),o=()=>{n({...t,"":""})},u=p=>{const h={...t};delete h[p],n(h)},g=p=>{const h={...t};delete h[p],h[c]=r,n(h),l(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(([p,h],w)=>e.jsx("div",{className:"flex items-center gap-2",children:a===p?e.jsxs(e.Fragment,{children:[e.jsx(s.Input,{placeholder:"Value key",value:c,onChange:m=>d(m.target.value),className:"h-8 w-24 text-xs",onPointerDown:m=>m.stopPropagation(),onKeyDown:m=>{m.key==="Enter"?g(p):m.key==="Escape"&&l(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input,{placeholder:"Alias label",value:r,onChange:m=>i(m.target.value),className:"h-8 w-24 text-xs",onPointerDown:m=>m.stopPropagation(),onKeyDown:m=>{m.key==="Enter"?g(p):m.key==="Escape"&&l(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:()=>g(p),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:()=>l(null),children:e.jsx(s.X,{className:"h-4 w-4 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input,{placeholder:"Value key",value:p,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{l(p),d(p),i(h)},"aria-label":"Edit value alias key"}),e.jsx(s.Input,{placeholder:"Alias label",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{l(p),d(p),i(h)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>u(p),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},p+w)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:o,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function wn({idx:t}){var i;const n=s.useEditorStore(o=>{var u;return(u=o.card)==null?void 0:u.preferences}),a=s.useEditorStore(o=>{var u;return(u=o.card.preferences)==null?void 0:u.datasetOptions}),l=s.useEditorStore(o=>o.actions.setCardPreferences),c=(i=n==null?void 0:n.chartOptions)==null?void 0:i.indexAxis,d=a==null?void 0:a.find(o=>o.idx===t);function r(o,u){(o==="end"||o==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const g={display:o!=="none",align:o,anchor:o,clamp:!0};if(!d)l({...n,datasetOptions:[...a||[],{idx:u,datalabels:g}]});else{const p={...d};p.datalabels=g;const h=a==null?void 0:a.map(w=>w.idx===u?p:w);l({...n,datasetOptions:h})}}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:()=>r("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>r("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(ut,{className:s.cn("h-4 w-4",{"rotate-90":c==="y"})})}),e.jsx("button",{onClick:()=>r("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(ht,{className:s.cn("h-4 w-4",{"rotate-90":c==="y"})})}),e.jsx("button",{onClick:()=>r("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(xt,{className:s.cn("h-4 w-4",{"rotate-90":c==="y"})})})]})})]})}function Ze({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 Tn(t,n=30){return t.length>n?t.slice(0,n)+"...":t}function En({col:t,idx:n,className:a,iconClassName:l,children:c}){const d=s.useEditorStore(g=>{var p;return(p=g.card)==null?void 0:p.preferences}),r=s.useEditorStore(g=>{var p,h;return(h=(p=g.card)==null?void 0:p.preferences)==null?void 0:h.datasetOptions}),i=r==null?void 0:r.find(g=>g.idx===n),{setCardPreferences:o}=s.useEditorStore(g=>g.actions);function u(g){if(!i)o({...d,datasetOptions:[...r||[],{idx:n,type:g==="area"?"line":g,fill:g==="area"?"origin":""}]});else{const p={...i};p.type=g==="area"?"line":g,p.fill=g==="area"?"origin":"";const h=r==null?void 0:r.map(w=>w.idx===n?p:w);o({...d,datasetOptions:h})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",a),children:[c||e.jsx(Ze,{className:"max-w-[100px]",title:t,children:Tn(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.ChartColumnIncreasing,{onClick:()=>u("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",l)}),e.jsx(s.ChartLine,{onClick:()=>u("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",l)}),e.jsx(s.ChartArea,{onClick:()=>u("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",l)}),e.jsx(wn,{idx:n})]})]})}function kn(){const t=s.useEditorStore(i=>i.card.type),n=s.useEditorStore(i=>i.isDevMode),a=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:l}=s.useEditorStore(i=>i.actions);function c(i){var g;const o={datalabels:{display:i!=="none",align:i,anchor:i,clamp:!0}},u={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(g=a==null?void 0:a.chartOptions)==null?void 0:g.plugins,...o}}};l(u)}function d(){var i,o,u;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((u=(o=(i=a==null?void 0:a.chartOptions)==null?void 0:i.plugins)==null?void 0:o.datalabels)==null?void 0:u.anchor)||"none",onValueChange:c,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 r(){var i,o,u;return e.jsx("div",{children:e.jsxs(s.Select,{value:((u=(o=(i=a==null?void 0:a.chartOptions)==null?void 0:i.plugins)==null?void 0:o.datalabels)==null?void 0:u.anchor)||"none",onValueChange:c,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():r()})}function In({column:t}){const n=s.useEditorStore(o=>o.card.type),a=s.useEditorStore(o=>{var u,g;return(g=(u=o.card)==null?void 0:u.config)==null?void 0:g.metricColumns}),l=(a==null?void 0:a.map(o=>o.label))||[],c=l==null?void 0:l.find(o=>o===t.label||o===t.name),d=c?l.indexOf(c):-1;function r(){return e.jsx("div",{className:"pr-1",children:c&&e.jsx(En,{idx:d,col:c,children:e.jsx("div",{className:"w-[130px] text-xs text-muted-foreground",children:"Display Series As"})})})}function i(){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(kn,{})]})}return e.jsxs("div",{className:"space-y-1",children:[["stackedBar","stackedLine","bar","line"].includes(n)&&r(),["pie","doughnut"].includes(n)&&i()]})}function An({field:t,searchQuery:n="",limit:a=500}){const{authToken:l,tokenProps:c}=s.useSemaphorContext(),d=s.useEditorStore(u=>u.card),r=d==null?void 0:d.dataSource,i=["attribute-values",t.entityName,t.name,n,a],o=s.useQuery({queryKey:i,queryFn:async()=>{if(!(r!=null&&r.connectionId))return console.warn("No connection ID available for attribute values query"),[];try{const u={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},g={connection_id:r.connectionId,cardConfig:u,cardDataSource:r,cache_config:s.getCacheConfig({card:d})};console.log("requestBody",g);const p=await s.postRequestRegular(`${c.apiServiceUrl}/v1/query`,(l==null?void 0:l.accessToken)||"",g);if(p!=null&&p.error)return console.error("Error fetching attribute values:",p.error),[];const h=t.name;return((p==null?void 0:p.records)||[]).map(m=>{const x=m[h]||m[t.alias||h]||m[t.label];return{id:x||"",value:x||"",label:String(x||"(empty)")}})}catch(u){return console.error("Error fetching attribute values:",u),[]}},enabled:!!t&&!!(r!=null&&r.connectionId),staleTime:5*60*1e3,gcTime:10*60*1e3});return{values:o.data||[],isLoading:o.isLoading,isFetching:o.isFetching,isError:o.isError,error:o.error,refetch:o.refetch}}function qs({open:t,onOpenChange:n,availableFields:a,existingFilters:l,editingCondition:c,onSave:d}){var F,D;const r=!!c,[i,o]=L.useState(r?"values":"fields"),[u,g]=L.useState(""),[p,h]=L.useState({id:(c==null?void 0:c.id)||s.v4(),field:(c==null?void 0:c.field)||null,selectedValues:c?Array.isArray(c.value)?c.value:[c.value]:[]}),w=a.filter(N=>{var C;return r?!1:!((C=l==null?void 0:l.conditions)==null?void 0:C.some(S=>S.field.id===N.id))&&N.label.toLowerCase().includes(u.toLowerCase())}),m=N=>{h({...p,field:N}),o("values")},x=()=>{if(p.field&&p.selectedValues.length>0){const N={id:p.id,field:p.field,operator:"in",value:p.selectedValues};let E;if(r){const C=((l==null?void 0:l.conditions)||[]).map(S=>S.id===c.id?N:S);E={...l,conditions:C}}else{const C=(l==null?void 0:l.conditions)||[];E={id:(l==null?void 0:l.id)||s.v4(),logicalOperator:"AND",negate:!1,conditions:[...C,N],groups:[]}}d(E),n(!1)}},f=()=>{if(!r||!c)return;const N=((l==null?void 0:l.conditions)||[]).filter(E=>E.id!==c.id);if(N.length>0){const E={...l,conditions:N};d(E)}else d(void 0);n(!1)},j=N=>{h({...p,selectedValues:N})},y=()=>{r&&c?(h({id:c.id,field:c.field,selectedValues:Array.isArray(c.value)?c.value:[c.value]}),o("values")):(h({id:s.v4(),field:null,selectedValues:[]}),o("fields")),g("")};return L.useEffect(()=>{t&&y()},[t,r,c]),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:r?`Edit Filter: ${(F=p.field)==null?void 0:F.label}`:i==="fields"?"Select Field to Filter":`Select Values for ${(D=p.field)==null?void 0:D.label}`})}),e.jsxs("div",{className:"space-y-4",children:[!r&&(l==null?void 0:l.conditions)&&l.conditions.length>0&&i==="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:l.conditions.map(N=>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:[N.field.label,":"]}),e.jsx("span",{className:"text-muted-foreground",children:Array.isArray(N.value)?`${N.value.length} values`:String(N.value)})]},N.id))})]}),i==="fields"&&!r?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,{placeholder:"Search fields...",value:u,onChange:N=>g(N.target.value),className:"pl-10"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-[400px] overflow-y-auto",children:w.map(N=>e.jsxs(s.Button,{variant:"outline",className:"justify-start h-auto py-2 px-3",onClick:()=>m(N),children:[e.jsx(Xe,{dataType:s.getDataType(N.dataType)}),e.jsxs("div",{className:"ml-2 text-left",children:[e.jsx("div",{className:"text-sm font-medium",children:N.label}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[N.entityName,".",N.name]})]})]},N.id))}),w.length===0&&u&&e.jsxs("div",{className:"text-center py-4 text-sm text-muted-foreground",children:['No fields found matching "',u,'"']}),w.length===0&&!u&&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(Dn,{field:p.field,selectedValues:p.selectedValues,onValuesChange:j,onBack:r?void 0:()=>o("fields")}),e.jsxs("div",{className:"flex justify-between pt-4 border-t",children:[e.jsx("div",{children:r?e.jsx(s.Button,{variant:"destructive",onClick:f,children:"Delete Filter"}):e.jsx(s.Button,{variant:"outline",onClick:y,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:x,disabled:!p.field||p.selectedValues.length===0,children:"Apply"})]})]})]})]})})}function Dn({field:t,selectedValues:n,onValuesChange:a,onBack:l}){const[c,d]=L.useState(""),{values:r,isLoading:i,isFetching:o}=An({field:t,searchQuery:c,limit:500}),u=c?r.filter(h=>String(h.value).toLowerCase().includes(c.toLowerCase())):r,g=h=>{const w=n.includes(h);a(w?n.filter(m=>m!==h):[...n,h])},p=()=>{n.length===u.length&&u.length>0?a([]):a(u.map(h=>h.value))};return e.jsxs("div",{className:"space-y-4",children:[l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:l,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,{placeholder:"Search values...",value:c,onChange:h=>d(h.target.value),className:"pl-10"})]}),i||o?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===u.length&&u.length>0,onCheckedChange:p}),e.jsxs(s.Label,{className:"text-sm",children:["Select All (",u.length,")"]})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-1",children:u.map(h=>e.jsxs("div",{className:"flex items-center gap-2 p-2 hover:bg-muted/50 rounded cursor-pointer",onClick:()=>g(h.value),children:[e.jsx(s.Checkbox,{checked:n.includes(h.value),onCheckedChange:()=>g(h.value)}),e.jsx(Ze,{className:"text-sm",children:h.label})]},h.id))})]})]})}function Ks({open:t,onOpenChange:n,availableMetrics:a,existingField:l,onSave:c,cardId:d}){const[r,i]=L.useState(""),[o,u]=L.useState("ratio"),[g,p]=L.useState(null),[h,w]=L.useState(null),[m,x]=L.useState(1),[f,j]=L.useState(""),[y,F]=L.useState({format:"number",decimalPlaces:2}),[D,N]=L.useState({}),E=Oe.find(v=>v.id===o),C=a.find(v=>v.id===g),S=a.find(v=>v.id===h);L.useEffect(()=>{if(l&&t)if(i(l.label),l.calculatedFormula)if(u(l.calculatedFormula.operation),l.calculatedFormula.operation==="custom")j(l.expression||"");else if(l.calculatedFormula.operation==="scale"){const v=l.calculatedFormula.inputFields;if(v.length>=1){const A=a.find(R=>R.qualifiedFieldName===v[0].qualifiedFieldName);p((A==null?void 0:A.id)||null)}l.calculatedFormula.constant!==void 0&&x(l.calculatedFormula.constant)}else{const v=l.calculatedFormula.inputFields;if(v.length>=2){const A=a.find(k=>k.qualifiedFieldName===v[0].qualifiedFieldName),R=a.find(k=>k.qualifiedFieldName===v[1].qualifiedFieldName);p((A==null?void 0:A.id)||null),w((R==null?void 0:R.id)||null)}}else u("custom"),j(l.expression||"")},[l,t,a]);const I=()=>{const v={};return r.trim()||(v.name="Name is required"),o==="custom"?f.trim()||(v.customExpression="Custom expression is required"):o==="scale"?(g||(v.inputA="Please select a metric for input A"),(isNaN(m)||m===0)&&(v.constantFactor="Please enter a valid non-zero number"),l&&g===l.id&&(v.circular="Cannot reference the field being edited")):(g||(v.inputA="Please select a metric for input A"),h||(v.inputB="Please select a metric for input B"),g===h&&(v.inputs="Inputs A and B must be different metrics"),l&&(g===l.id||h===l.id)&&(v.circular="Cannot reference the field being edited")),N(v),Object.keys(v).length===0},M=()=>{if(!I())return;const v=Nn(r,o,C||null,S||null,y,d,l==null?void 0:l.id,o==="custom"?f:void 0,o==="scale"?m:void 0);c(v),b()},b=()=>{i(""),u("ratio"),p(null),w(null),x(1),j(""),N({}),n(!1)};return e.jsxs(s.Dialog,{modal:!1,open:t,onOpenChange:n,children:[t&&e.jsx("div",{className:"pointer-events-none fixed inset-0 z-40 bg-background/80 backdrop-blur-sm"}),e.jsxs(s.DialogContent,{className:"max-w-md max-h-[90vh] overflow-y-auto",onInteractOutside:v=>{v.preventDefault()},children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{children:[l?"Edit":"Create"," Calculated Metric"]}),e.jsx(s.DialogDescription,{children:"Combine existing metrics to create a new calculated field"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"name",children:"Name"}),e.jsx(s.Input$1,{id:"name",value:r,onChange:v=>i(v.target.value),placeholder:"e.g., Profit Margin",className:D.name?"border-red-500":""}),D.name&&e.jsx("p",{className:"text-xs text-red-500",children:D.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"operation",children:"Outcome is"}),e.jsxs(s.Select,{value:o,onValueChange:v=>{u(v),v==="custom"?(p(null),w(null)):o==="custom"&&j("")},children:[e.jsx(s.SelectTrigger,{id:"operation",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"CALCULATED"}),Oe.map(v=>e.jsx(s.SelectItem,{value:v.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-sm",children:v.symbol}),e.jsx("span",{children:v.label})]})},v.id))]})})]}),E&&e.jsx("p",{className:"text-xs text-muted-foreground",children:E.description})]}),o==="custom"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"customExpression",children:"SQL Expression"}),e.jsx(s.Textarea,{id:"customExpression",value:f,onChange:v=>j(v.target.value),placeholder:"e.g., CASE WHEN revenue > 1000 THEN revenue - cost ELSE 0 END",className:s.cn("font-mono text-sm",D.customExpression&&"border-red-500"),rows:4}),D.customExpression&&e.jsx("p",{className:"text-xs text-red-500",children:D.customExpression}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Write a SQL expression using column names from your data source"})]}):e.jsxs("div",{className:"rounded-md bg-muted p-3 font-mono text-sm",children:["= ",g&&C?C.label:"A"," ",E==null?void 0:E.symbol," ",h&&S?S.label:"B"]}),o!=="custom"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"inputA",children:"Where"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded bg-muted font-mono text-sm font-medium",children:"A"}),e.jsxs(s.Select,{value:g||"",onValueChange:p,children:[e.jsx(s.SelectTrigger,{id:"inputA",className:D.inputA?"border-red-500":"",children:e.jsx(s.SelectValue,{placeholder:"+ Choose metric"})}),e.jsx(s.SelectContent,{children:a.filter(v=>!s.isCalculatedMetric(v)||v.id!==(l==null?void 0:l.id)).map(v=>e.jsxs(s.SelectItem,{value:v.id,children:[v.label||v.name,v.aggregate&&` (${v.aggregate})`]},v.id))})]})]}),D.inputA&&e.jsx("p",{className:"text-xs text-red-500",children:D.inputA})]}),o!=="custom"&&o!=="scale"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded bg-muted font-mono text-sm font-medium",children:"B"}),e.jsxs(s.Select,{value:h||"",onValueChange:w,children:[e.jsx(s.SelectTrigger,{id:"inputB",className:D.inputB?"border-red-500":"",children:e.jsx(s.SelectValue,{placeholder:"+ Choose metric"})}),e.jsx(s.SelectContent,{children:a.filter(v=>!s.isCalculatedMetric(v)||v.id!==(l==null?void 0:l.id)).map(v=>e.jsxs(s.SelectItem,{value:v.id,children:[v.label||v.name,v.aggregate&&` (${v.aggregate})`]},v.id))})]})]}),D.inputB&&e.jsx("p",{className:"text-xs text-red-500",children:D.inputB})]}),o==="scale"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"constantFactor",children:"Multiplication Factor"}),e.jsx(s.Input$1,{id:"constantFactor",type:"number",step:"any",value:m,onChange:v=>x(parseFloat(v.target.value)||0),placeholder:"e.g., 0.15",className:D.constantFactor?"border-red-500":""}),D.constantFactor&&e.jsx("p",{className:"text-xs text-red-500",children:D.constantFactor}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter the constant value to multiply the metric by (e.g., 0.15 for 15%)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{htmlFor:"format",children:"Format"}),e.jsxs(s.Select,{value:y.format,onValueChange:v=>F({...y,format:v}),children:[e.jsx(s.SelectTrigger,{id:"format",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsxs(s.SelectItem,{value:"number",children:["Decimal (",y.decimalPlaces,")"]}),e.jsx(s.SelectItem,{value:"currency",children:"Currency"}),e.jsx(s.SelectItem,{value:"percent",children:"Percentage"})]})]})]}),(D.inputs||D.circular)&&e.jsxs(s.Alert,{variant:"destructive",children:[e.jsx(s.CircleAlert,{className:"h-4 w-4"}),e.jsx(s.AlertDescription,{children:D.inputs||D.circular})]})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(s.Button,{variant:"outline",onClick:b,children:"Cancel"}),e.jsxs(s.Button,{onClick:M,children:[l?"Update":"Create"," Metric"]})]})]})]})}function Ln({field:t,zone:n,index:a,sortDirection:l,onSortDirectionChange:c,hasPivotColumns:d=!1,cardType:r}){var ss,ts,as,ns,rs;const{attributes:i,listeners:o,setNodeRef:u,transform:g,transition:p,isDragging:h}=s.useSortable({id:t.id}),w=s.useEditorStore(G=>G.card),{updateLabel:m,handleAggregationChange:x,handleDateFormatChange:f,handleGranularityChange:j,handleAliasTemplateChange:y,handleValueAliasesChange:F,removeField:D,handleKpiComparisonTypeChange:N,handleKpiShowTrendlineChange:E,handleKpiTrendlineWindowChange:C,handleKpiTrendlineGranularityChange:S,handleKpiTargetValueChange:I}=s.useFieldManagement(w),[M,b]=L.useState(!1),[v,A]=L.useState(!1),[R,k]=L.useState(!1),[O,T]=L.useState(null),[P,$]=L.useState(t.dateFormat||"YYYY-MM-DD"),[H,q]=L.useState(t.customFormat||""),[K,_]=L.useState(!!t.customFormat),[B,U]=L.useState(t.granularity||"day"),[V,W]=L.useState(t.aliasTemplate||""),[X,se]=L.useState(t.valueAliases||{}),[J,te]=L.useState((ss=t.parameters)==null?void 0:ss.filters),Q=G=>{G==="custom"?_(!0):(_(!1),$(G),n==="groupBy"&&f(a,G,""))},le=G=>{q(G),n==="groupBy"&&f(a,"custom",G)},de=G=>{var oe;U(G);const Z=(oe=s.getDateFormatOptionsForGranularity(G)[0])==null?void 0:oe.value;Z&&!K&&($(Z),n==="groupBy"&&f(a,Z,"")),n==="groupBy"&&j(a,G)},z=G=>{W(G),n==="metrics"&&y(a,G)},ee=G=>{se(G),n==="metrics"&&F(a,G)},ue=G=>{m(n,a,G)},me=G=>{var ae;if(te(G),n==="metrics"){const Z={...t,parameters:{...t.parameters,filters:G}},oe=[...((ae=w.config)==null?void 0:ae.metricColumns)||[]];oe[a]=Z,s.useEditorStore.getState().actions.updateCardConfig(w.id,{metricColumns:oe})}A(!1)},Se=()=>{D(n,a)},xe={transform:s.CSS.Transform.toString(g),transition:p},je=s.getDataType(t.dataType),he=je==="date",be=r==="kpi",we=s.getDateFormatOptionsForGranularity(B),ge=n!=="pivotBy",Te=he&&n==="groupBy"&&(!be||((ts=w.config)==null?void 0:ts.comparisonType)==="start_vs_end"),Ee=!be&&he&&n==="groupBy",ke=r&&s.COMPARISON_SUPPORTED_CHART_TYPES.includes(r)&&he&&n==="groupBy",Ie=r==="kpi"&&he&&n==="groupBy",ve=r&&r!=="pivotTable"&&n==="metrics"&&((as=w.config)==null?void 0:as.comparisonType)==="target",ye=n==="metrics",Y=()=>{const G=t,ae=n==="metrics"&&s.isCalculatedMetric(G);return e.jsxs("div",{className:"space-y-1",children:[!ae&&e.jsx("div",{title:`${t.entityName}.${t.name}`,onPointerDown:Z=>{Z.stopPropagation()},className:"max-w-[270px] cursor-default overflow-hidden text-ellipsis whitespace-nowrap px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),ae&&G.calculatedFormula&&e.jsxs("div",{title:ys(G.calculatedFormula),onPointerDown:Z=>{Z.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:["= ",ys(G.calculatedFormula)]})]})},ne=()=>ge?e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Label"}),e.jsx(ce,{value:t.label??"",onSave:ue,placeholder:"Display label...",type:"text"})]}):null,re=()=>Te?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:B,onValueChange:de,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:["day","week","month","quarter","year"].map(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G,children:s.toTitleCase(G)},G))})]})]}):null,Ne=()=>Ee?e.jsxs(e.Fragment,{children:[re(),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:K?"custom":P,onValueChange:Q,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:we.map(G=>e.jsx(s.SelectItem,{className:"text-xs",value:G.value,children:G.label},G.value))})]}),K&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:H,onChange:G=>{G.stopPropagation(),le(G.target.value)},onClick:G=>G.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,Us=()=>{var Z,oe,Ce,Ae,fe;const G=ke,ae=Ie;return!G&&!ae?null:e.jsxs(e.Fragment,{children:[G&&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:((Z=w.config)==null?void 0:Z.comparisonType)||"none",onValueChange:N,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"}),e.jsx(s.SelectItem,{value:"previous_period",children:"Previous Period"}),e.jsx(s.SelectItem,{value:"same_period_last_year",children:"Same Period Last Year"}),e.jsx(s.SelectItem,{value:"start_vs_end",children:"Start vs End"})]})]})]}),ae&&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:((oe=w.config)==null?void 0:oe.showTrendline)||!1,onCheckedChange:E})]})}),((Ce=w.config)==null?void 0:Ce.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,{type:"number",min:"1",max:"365",value:((Ae=w.config)==null?void 0:Ae.trendlineWindow)||30,onChange:Le=>{const Qs=parseInt(Le.target.value)||30;C(Qs)},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:((fe=w.config)==null?void 0:fe.trendlineGranularity)||"day",onValueChange:S,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"})]})]})]})]})]})]})},_s=()=>{var G,ae;return ve?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(ce,{value:((G=w.config)==null?void 0:G.targetValue)!==void 0&&((ae=w.config)==null?void 0:ae.targetValue)!==null?String(w.config.targetValue):"",onSave:Z=>{!isNaN(Number(Z))&&Z!==null?I(Number(Z)):I(0)},placeholder:"Enter target value...",type:"text"})]}):null},Hs=()=>{if(!ye)return null;const G=t,ae=s.isCalculatedMetric(G);return e.jsxs(e.Fragment,{children:[ae&&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:()=>k(!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:Z=>{x(a,Z)},disabled:ae,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.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-muted-foreground",children:"Attribute Filters"}),(J==null?void 0:J.conditions)&&J.conditions.length>0&&e.jsx("div",{className:"mb-2 space-y-1",children:J.conditions.map(Z=>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:()=>{T(Z),A(!0)},children:[e.jsxs("span",{className:"font-medium",children:[Z.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(Z.value)?Z.value.length===1?String(Z.value[0]):Z.value.length<=2?Z.value.join(", "):`${Z.value.slice(0,2).join(", ")} +${Z.value.length-2}`:String(Z.value)})}),Array.isArray(Z.value)&&Z.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 (",Z.value.length,"):"]}),e.jsx("div",{className:"max-h-[200px] overflow-y-auto",children:Z.value.map((oe,Ce)=>e.jsx("div",{children:String(oe)},Ce))})]})})]})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"ml-auto h-4 w-4 p-0",onClick:oe=>{var Ae;oe.stopPropagation();const Ce=J.conditions.filter(fe=>fe.id!==Z.id);if(Ce.length>0){const fe={...J,conditions:Ce};me(fe)}else if(te(void 0),n==="metrics"){const fe={...t,parameters:{...t.parameters,filters:void 0}},Le=[...((Ae=w.config)==null?void 0:Ae.metricColumns)||[]];Le[a]=fe,s.useEditorStore.getState().actions.updateCardConfig(w.id,{metricColumns:Le})}},children:e.jsx(s.X,{className:"h-3 w-3"})})]},Z.id))}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8 w-full justify-start text-xs",onClick:()=>{T(null),A(!0)},children:[e.jsx(s.Filter,{className:"mr-2 h-3 w-3"}),"Add attribute filter"]})]}),e.jsx(In,{column:t}),d&&e.jsxs(e.Fragment,{children:[e.jsx(Cn,{aliasTemplate:V,onAliasTemplateChange:z}),e.jsx(Sn,{valueAliases:X,onValueAliasesChange:ee})]})]})},{columns:Js=[]}=s.useColumns(),Ys=(J==null?void 0:J.conditions)&&J.conditions.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:u,style:xe,...i,...o,className:`group mx-auto flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${h?"z-50 scale-95 opacity-50":"border-slate-200"} ${n==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsx(Xe,{dataType:je}),e.jsx(Ze,{className:s.cn("w-[140px] flex-1 text-sm",Ys&&"w-[120px]"),children:s.getMetricDisplayLabel(t)}),n==="metrics"&&((ns=J==null?void 0:J.conditions)==null?void 0:ns.length)&&!M&&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",children:[e.jsx(s.Filter,{className:"h-3 w-3"}),e.jsx("span",{children:J.conditions.length})]})}),e.jsx(s.TooltipContent,{side:"top",children:e.jsx("div",{className:"text-xs",children:J.conditions.map(G=>e.jsxs("div",{children:[G.field.label,":"," ",Array.isArray(G.value)?`${G.value.length} values`:String(G.value)]},G.id))})})]})}),n!=="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:G=>{G.stopPropagation(),b(!M)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${M?"rotate-180":""}`})}),n==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:G=>{G.stopPropagation(),console.log("DraggableField - Current sortDirection:",l);const ae=l==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",ae),c(ae)},children:l==="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",onClick:G=>{G.stopPropagation(),Se()},children:e.jsx(s.X,{className:"h-2.5 w-2.5"})})]}),M&&e.jsxs("div",{className:"space-y-3",children:[Y(),ne(),r==="kpi"&&re(),Ne(),Us(),_s(),Hs()]})]}),v&&e.jsx(qs,{open:v,onOpenChange:G=>{A(G),G||T(null)},availableFields:Js,existingFilters:J,editingCondition:O,onSave:G=>{var ae;if(G)me(G);else if(te(void 0),n==="metrics"){const Z={...t,parameters:{...t.parameters,filters:void 0}},oe=[...((ae=w.config)==null?void 0:ae.metricColumns)||[]];oe[a]=Z,s.useEditorStore.getState().actions.updateCardConfig(w.id,{metricColumns:oe})}T(null)}}),R&&n==="metrics"&&e.jsx(Ks,{open:R,onOpenChange:k,availableMetrics:((rs=w.config)==null?void 0:rs.metricColumns)||[],existingField:t,onSave:G=>{var Z;const ae=[...((Z=w.config)==null?void 0:Z.metricColumns)||[]];ae[a]=G,s.useEditorStore.getState().actions.updateCardConfig(w.id,{metricColumns:ae})},cardId:w.id})]})}function Mn({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"})]})]})]});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()})]})})}function Me({zone:t,fields:n,label:a,placeholder:l,shouldShow:c,hasPivotColumns:d=!1,activeField:r=null}){const{isOver:i,setNodeRef:o}=s.useDroppable({id:t}),{updateSortByColumn:u}=s.useEditorActions(),g=s.useEditorStore(f=>f.card),p=s.useEditorStore(f=>f.card.type),h=n.length>0,w=L.useMemo(()=>!r||!i?!0:s.validateFieldForChartType(r,t,p).isValid,[r,i,t,p]),m=(f,j)=>{var F;!((F=g.config)!=null&&F.sortByColumns)||g.config.sortByColumns.findIndex(D=>D.id===f)===-1||u(g.id,f,{direction:j})};if(t==="sortBy"&&c===!1)return null;const x=t!=="sortBy"&&p!=="kpi";return e.jsxs("div",{className:"mb-4 w-full",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(s.Label,{className:s.cn("block text-sm font-medium",{}),children:a}),x&&e.jsx(Mn,{concept:t})]}),e.jsx("div",{ref:o,className:s.cn("rounded-lg border-2 border-dotted p-0.5 transition-all",{"border-green-500 bg-green-50 dark:bg-green-950":i&&w,"border-red-500 bg-red-50 dark:bg-red-950":i&&!w,"border-muted-foreground/30 bg-muted/40":!i&&h,"min-h-[60px] border-muted-foreground/20 bg-background":!i&&!h}),children:n.length===0?e.jsx("div",{className:"flex min-h-[60px] items-center justify-center text-sm text-muted-foreground/60",children:l}):e.jsx(s.SortableContext,{items:n.map(f=>f.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-1",children:n.map((f,j)=>{const F=f.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(Ln,{field:f,zone:t,index:j,sortDirection:F,onSortDirectionChange:D=>m(f.id,D),hasPivotColumns:d,cardType:p})})},f.id)})})})})]})}function On({groupByFields:t,pivotByFields:n,metricsFields:a,sortByFields:l,activeField:c}){const[d,r]=L.useState(!1),i=s.useEditorStore(F=>{var D;return((D=F.card.customCardPreferences)==null?void 0:D.url)&&F.card.type==="custom"}),o=s.useEditorStore(F=>F.card),u=s.useEditorStore(F=>F.actions.updateCardConfig),g=o==null?void 0:o.type,p=t.length>0||a.length>0,h=g!=="kpi"||a.length<=2,w=g!=="kpi",m=g!=="kpi"&&p,x=["pie","doughnut","polar","funnel","aggregateTable","bubble","scatter"].includes(g),f=w&&!x,j=()=>g==="kpi"?{label:"Trend By",placeholder:"Drop fields to trend data"}:{label:"Rows",placeholder:"Drop fields to group data"},y=()=>g==="kpi"?{label:"Metric",placeholder:"Drop field for KPI"}:{label:"Columns",placeholder:"Drop fields to measure"};return e.jsxs(e.Fragment,{children:[e.jsxs(s.Accordion,{type:"single",collapsible:!0,defaultValue:"fields",className:"w-full",children:[e.jsxs(s.AccordionItem,{value:"fields",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.List,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"FIELDS"})]})}),e.jsxs(s.AccordionContent,{className:"space-y-4 pt-2",children:[h&&e.jsx(Me,{zone:"groupBy",fields:t,label:j().label,placeholder:j().placeholder,activeField:c}),f&&e.jsx(Me,{zone:"pivotBy",fields:n,label:"Pivot Columns",placeholder:"Drop fields to pivot data",activeField:c}),e.jsx(Me,{zone:"metrics",fields:a,label:y().label,placeholder:y().placeholder,hasPivotColumns:n.length>0,activeField:c}),a.length>=1&&e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:()=>r(!0),className:"mt-2 w-full justify-start text-xs text-muted-foreground hover:text-foreground",children:[e.jsx(s.Calculator,{className:"mr-2 h-4 w-4"}),"Create Metric"]}),m&&e.jsx(Me,{zone:"sortBy",fields:l,label:"Sort By",placeholder:"Drop fields from Rows or Metrics",activeField:c})]})]}),!i&&e.jsxs(s.AccordionItem,{value:"configuration",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.Settings2,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"CONFIGURATION"})]})}),e.jsx(s.AccordionContent,{className:"rounded-md border border-border bg-muted/50 px-3 py-0",children:e.jsx(s.Accordion,{type:"single",collapsible:!0,className:"w-full",children:e.jsx($s,{mode:"config"})})})]}),i&&e.jsxs(s.AccordionItem,{value:"plugin",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(Ss,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{children:"CONFIGURATION"})]})}),e.jsx(s.AccordionContent,{className:"rounded-md border border-border bg-muted/50 px-3 py-0",children:e.jsx(Ps,{})})]})]}),e.jsx(Ks,{open:d,onOpenChange:r,availableMetrics:a,onSave:F=>{u(o.id,{metricColumns:[...a,F]})},cardId:o.id})]})}function Rn({onEditJoins:t}){const n=s.useEditorStore(i=>i.card),{autoJoinMetadata:a}=s.useDashboardCardQuery(n);if(!(a!=null&&a.autoResolved))return null;const{resolvedJoinPlan:l}=a,c=(l==null?void 0:l.joins)||[];if(c.length===0)return null;const d=i=>!i||i.length===0?"No conditions":i.map(o=>{var h,w,m,x;const u=`${(h=o.source)==null?void 0:h.entityName}.${(w=o.source)==null?void 0:w.name}`,g=`${(m=o.target)==null?void 0:m.entityName}.${(x=o.target)==null?void 0:x.name}`,p=o.operator||"=";return`${u} ${p} ${g}`}).join(" AND "),r=i=>!i.joinKeyGroups||i.joinKeyGroups.length===0?"No conditions defined":i.joinKeyGroups.length===1?d(i.joinKeyGroups[0].keys):i.joinKeyGroups.map((o,u)=>({id:u,operator:o.operator,condition:d(o.keys)}));return e.jsx(s.Card,{className:"border-blue-500/30 bg-blue-50/30 dark:bg-blue-950/20",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(Ct,{className:"size-4 text-blue-600 dark:text-blue-400"}),e.jsx("h3",{className:"text-sm font-medium text-blue-900 dark:text-blue-100",children:"Auto-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 text-xs text-blue-700 dark:bg-blue-900 dark:text-blue-300",children:c.length})}),e.jsx(s.TooltipContent,{side:"bottom",align:"start",className:"max-w-md p-3",children:e.jsx("div",{className:"space-y-2",children:c.map((i,o)=>{const u=r(i),g=Array.isArray(u);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:i.source.name}),e.jsx(s.ArrowRight,{className:"size-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium text-foreground",children:i.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:i.joinType})]}),e.jsx("div",{className:"mt-1 space-y-1",children:g?u.map(p=>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:p.condition}),p.operator&&e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",p.operator,")"]})]},p.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:u})})})]},i.id||o)})})})]})})]}),t&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:t,className:"h-7 gap-1 p-2 text-xs text-blue-700 hover:text-blue-900 dark:text-blue-300 dark:hover:text-blue-100",children:e.jsx(s.SquarePen,{className:"size-3.5"})})]})})}const Ns={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 Fn({selectedChart:t,onChartChange:n,groupByFields:a,pivotByFields:l,metricsFields:c,sortByFields:d,activeField:r}){var C,S;const[i,o]=L.useState(()=>Ns.getItem("chart-selector-expanded")==="true"),[u,g]=L.useState(!1),p=s.useEditorStore(I=>I.card),h=s.useEditorStore(I=>I.actions.updateCardConfig),w=a.length>0||l.length>0||c.length>0,{data:m,autoJoinMetadata:x}=s.useDashboardCardQuery(p),f=((C=p==null?void 0:p.config)==null?void 0:C.joinPlan)||(x!=null&&x.autoResolved?x.resolvedJoinPlan:{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]}),j=((S=p==null?void 0:p.dataSource)==null?void 0:S.selectedEntities)||[],y=I=>{h(p.id,{...p==null?void 0:p.config,joinPlan:I}),g(!1)},F=()=>{h(p.id,{...p==null?void 0:p.config,joinPlan:void 0}),g(!1)},D=()=>{g(!1)},N=()=>{g(!0)};L.useEffect(()=>{Ns.setItem("chart-selector-expanded",String(i))},[i]);const E=()=>{o(I=>!I)};return e.jsxs("div",{"data-content":"Chart Configuration Panel",className:"flex w-[350px] flex-col border-x border-border",children:[e.jsxs("div",{className:s.cn("px-6 pt-4",{"space-y-4":i}),children:[e.jsx("div",{className:s.cn("overflow-hidden transition-all duration-300 ease-in-out",i?"max-h-[200px] opacity-100":"max-h-0 opacity-0"),children:i&&e.jsx(vn,{selectedChart:t,onChartChange:n})}),e.jsx("div",{"data-content":"Chart Quick Selector",className:"flex items-center justify-center",children:e.jsx(s.ChartQuickSelector,{selectedChart:t,onChartChange:n,isDropdownExpanded:i,onToggleDropdown:E})})]}),e.jsx("div",{className:s.cn("flex justify-end gap-2 px-6 py-6"),children:e.jsx("div",{className:s.cn("invisible flex gap-2",{visible:w||m}),children:e.jsx(He.EditorClearButton,{})})}),e.jsxs(s.ScrollArea,{className:"w-full flex-1 basis-0 px-6 pb-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(Rn,{onEditJoins:N}),e.jsx(On,{groupByFields:a,pivotByFields:l,metricsFields:c,sortByFields:d,activeField:r})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]}),e.jsx(Is,{open:u,onOpenChange:g,joinPlan:f,availableDataSources:j,onSave:y,onCancel:D,onRemove:F,children:e.jsx("div",{})})]})}function Bn({initialFilters:t,availableFields:n}={}){const[a,l]=L.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(N=>N.card.dataSource);const{columns:c,isLoading:d}=s.useColumns(),i=n||c||[],o={id:"default",qualifiedFieldName:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},u=N=>{const E=C=>{if(C.id===N){const S=i[0]||o,I=s.getDataType(S.dataType)==="date";return{...C,conditions:[...C.conditions,{id:`condition-${Date.now()}`,field:S,operator:I?"between":"=",value:I?[]:""}]}}return{...C,groups:C.groups.map(E)}};l(E(a))},g=N=>{const E=C=>{if(C.id===N){const S=i[0]||o,I=s.getDataType(S.dataType)==="date";return{...C,groups:[...C.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:S,operator:I?"between":"=",value:I?[]:""}],groups:[]}]}}return{...C,groups:C.groups.map(E)}};l(E(a))},p=(N,E)=>{const C=S=>S.id===N?{...S,conditions:S.conditions.filter(I=>I.id!==E)}:{...S,groups:S.groups.map(C)};l(C(a))},h=(N,E)=>{const C=S=>S.id===N?{...S,groups:S.groups.filter(I=>I.id!==E)}:{...S,groups:S.groups.map(C)};l(C(a))},w=(N,E,C,S)=>{if(C==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const I=M=>M.id===N?{...M,conditions:M.conditions.map(b=>b.id===E?{...b,[C]:S}:b)}:{...M,groups:M.groups.map(I)};l(I(a))},m=(N,E,C)=>{const S=I=>I.id===N?{...I,conditions:I.conditions.map(M=>M.id===E?{...M,...C}:M)}:{...I,groups:I.groups.map(S)};l(S(a))},x=(N,E)=>{const C=S=>S.id===N?{...S,logicalOperator:E}:{...S,groups:S.groups.map(C)};l(C(a))},f=(N,E)=>{const C=S=>S.id===N?{...S,negate:E}:{...S,groups:S.groups.map(C)};l(C(a))},j=(N,E,C)=>{const S=I=>I.id===N?{...I,conditions:s.arrayMove(I.conditions,E,C)}:{...I,groups:I.groups.map(S)};l(S(a))},y=(N,E,C)=>{const S=I=>I.id===N?{...I,groups:s.arrayMove(I.groups,E,C)}:{...I,groups:I.groups.map(S)};l(S(a))},F=N=>{if(!N||N.conditions.length===0&&N.groups.length===0)return"-- No filters defined";const E=S=>{let I="";typeof S.field=="object"?I=S.field.entityName?`${S.field.entityName}.${S.field.name}`:S.field.name:I=String(S.field);const M=S.operator;let b=S.value;if(S.field.dataType==="string"&&!["in","not in"].includes(S.operator))typeof b=="string"?b=`'${b}'`:Array.isArray(b)&&(b=`'${b.join(", ")}'`);else if(S.field.dataType==="date"||S.field.dataType==="datetime"||S.field.dataType==="timestamp")if(S.operator==="between"&&Array.isArray(b)&&b.length===2){const v=b[0]?`'${b[0]}'`:"NULL",A=b[1]?`'${b[1]}'`:"NULL";return`${I} BETWEEN ${v} AND ${A}`}else if((S.operator==="in"||S.operator==="not in")&&Array.isArray(b)){const v=b.map(A=>A?`'${A}'`:"NULL").join(", ");return`${I} ${M} (${v})`}else typeof b=="string"||b instanceof Date?b=`'${b}'`:Array.isArray(b)&&b.length>0&&(b=`'${b[0]}'`);else if(["in","not in"].includes(S.operator)){let v=[];Array.isArray(b)?v=b.map(A=>typeof A=="string"?`'${A}'`:String(A)):typeof b=="string"?v=b.split(",").map(A=>{const R=A.trim();return S.field.dataType==="string"?`'${R}'`:R}):typeof b=="number"&&(v=[String(b)]),b=`(${v.join(", ")})`}switch(M){case"contains":return typeof b=="string"?`${I} LIKE '%${b.replace(/'/g,"")}'`:`${I} LIKE '%${String(b)}'`;case"startsWith":return typeof b=="string"?`${I} LIKE '${b.replace(/'/g,"")}%'`:`${I} LIKE '${String(b)}%'`;case"endsWith":return typeof b=="string"?`${I} LIKE '%${b.replace(/'/g,"")}'`:`${I} LIKE '%${String(b)}'`;case"isNull":return`${I} IS NULL`;case"isNotNull":return`${I} IS NOT NULL`;default:return`${I} ${M} ${b}`}},C=S=>{const I=S.conditions.map(E),M=S.groups.map(R=>C(R)),b=[...I,...M].filter(Boolean);if(b.length===0)return"";const v=b.join(` ${S.logicalOperator} `),A=b.length>1?`(${v})`:v;return S.negate?`NOT ${A}`:A};return C(N)},D=a.conditions.length>0||a.groups.length>0;return{currentFilters:a,setCurrentFilters:l,availableFields:i,isLoading:d,addCondition:u,addGroup:g,removeCondition:p,removeGroup:h,updateCondition:w,updateConditionFields:m,updateGroupOperator:x,updateGroupNegate:f,reorderConditions:j,reorderGroups:y,generateSQLPreview:F,hasAnyFilters:D}}function Pn({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 Vn=t=>{if(t.qualifiedEntityName){const n=t.qualifiedEntityName.split(".");return n.length>1?n[0]:"default"}return"default"};function zn({value:t,onValueChange:n,availableFields:a,placeholder:l="Select field",className:c="w-64"}){const[d,r]=L.useState(!1),i=L.useMemo(()=>{const o={};return a.forEach(u=>{const g=Vn(u);o[g]||(o[g]={}),o[g][u.entityId]||(o[g][u.entityId]=[]),o[g][u.entityId].push(u)}),o},[a]);return e.jsxs(s.Popover,{modal:!0,open:d,onOpenChange:r,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",c),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(Pn,{children:[t.entityName,".",t.name]})}):l,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(i).map(([o,u])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Database,{className:"h-3 w-3"}),o]}),children:Object.entries(u).map(([g,p])=>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(p[0].entityType,{size:"h-3 w-3"}),e.jsx("span",{children:p[0].entityName})]}),p.map((h,w)=>e.jsxs(s.CommandItem,{value:h.id,onSelect:()=>{n(h),r(!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)===h.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:h.name})}),e.jsx("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:h.description&&e.jsx("span",{children:h.description})})]})]},h.id+w))]},`${o}-${g}`))},o))})]})})]})}function es(t){var x;const n=s.useEditorStore(f=>f.card),{authToken:a,tokenProps:l}=s.useSemaphorContext(),c=s.useEditorStore(f=>f.card.config),d=c==null?void 0:c.joinPlan,r={...t,alias:t.name,label:"value",role:"groupby"},i={...t,role:"metric",label:"count",alias:"count",aggregate:"COUNT"},o={...r,role:"sortby",direction:"asc"},u={joinPlan:d,groupByColumns:[r],metricColumns:[i],sortByColumns:[o]},g=((x=n.dataSource)==null?void 0:x.connectionId)||n.connectionId,{data:p,isPending:h,error:w}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular(`${l.apiServiceUrl}/v1/query`,(a==null?void 0:a.accessToken)||"",{connection_id:g,cardConfig:u,cardDataSource:n.dataSource})}catch(f){console.log(t),console.error("error",f)}},enabled:!!g,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((p==null?void 0:p.records)||[]).map(f=>({label:f.value||"BLANK",value:f.value||"BLANK",count:(f==null?void 0:f.count)||0})),isPending:h,error:w}}function $n({field:t,selected:n,onChange:a,placeholder:l="Select items...",className:c}){const[d,r]=Ue.useState(!1),{filterValues:i}=es(t),o=g=>{a(n.filter(p=>p!==g))},u=g=>{n.includes(g)?a(n.filter(p=>p!==g)):a([...n,g])};return e.jsx("div",{className:s.cn("w-full",c),children:e.jsxs(s.Popover,{open:d,onOpenChange:r,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(g=>{const p=i.find(h=>h.value===g);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[p==null?void 0:p.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:h=>{h.key==="Enter"&&o(g)},onMouseDown:h=>{h.preventDefault(),h.stopPropagation()},onClick:h=>{h.stopPropagation(),o(g)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},g)}):e.jsx("span",{className:"text-muted-foreground",children:l})}),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:i.map((g,p)=>e.jsxs(s.CommandItem,{onSelect:()=>u(g.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",n.includes(g.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:g.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:g.count})]})]},g.value+p))})]})]})})]})})}function qn({field:t,value:n,onChange:a,placeholder:l="Select value...",className:c}){const{filterValues:d,isPending:r,error:i}=es(t);return r?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..."]}):i?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:c||"flex-1",children:e.jsx(s.SelectValue,{placeholder:l,children:n})}),e.jsx(s.SelectContent,{children:d.map((o,u)=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:o.value,children:o.label},o.value+u))})]})}function Kn({value:t,operator:n,onChange:a,className:l}){var o;const{tokenProps:c}=s.useSemaphorContext(),d=(o=c==null?void 0:c.params)==null?void 0:o.timezone,r=L.useMemo(()=>{if(t){if(n==="between"||n==="not between"){if(Array.isArray(t)&&t.length===2){const u=t[0]?new Date(t[0]):void 0,g=t[1]?new Date(t[1]):void 0;if(u&&g)return{from:u,to:g}}}else if(n==="="||n==="!="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:u,to:u}}}else if(n===">"||n===">="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:u,to:void 0}}}else if(n==="<"||n==="<="){if(!Array.isArray(t)&&t){const u=new Date(t);if(!isNaN(u.getTime()))return{from:void 0,to:u}}}else if((n==="in"||n==="not in")&&Array.isArray(t)&&t.length>0){const u=new Date(t[0]),g=t.length>1?new Date(t[t.length-1]):u;if(!isNaN(u.getTime()))return{from:u,to:g}}}},[t,n]),i=u=>{if(!u){a(void 0);return}if(u.from&&u.to)a([u.from.toISOString(),u.to.toISOString()]);else if(u.from){const g=new Date(u.from);g.setHours(23,59,59,999),a([u.from.toISOString(),g.toISOString()])}else if(u.to){const g=new Date(u.to);g.setHours(0,0,0,0),a([g.toISOString(),u.to.toISOString()])}};return e.jsx(s.DateRangePicker,{value:r,onChange:i,timezone:d,showRelativeTab:!0,className:l,placeholder:"Select date..."})}const Gn=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],Un=["=","!=","contains","startsWith","endsWith","in","not in","isNull","isNotNull"],_n=["=","!=",">",">=","<","<=","in","not in","isNull","isNotNull"],Hn=["=","!=","isNull","isNotNull"],Jn=["between","isNull","isNotNull"],Yn={"=":"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 Cs(t){return Yn[t]||s.titleCase(t)}function Qn(t){switch(t){case"string":return Un;case"number":return _n;case"boolean":return Hn;case"date":return Jn;default:return Gn}}function Gs({condition:t,index:n,groupId:a,groupLogicalOperator:l,onUpdateCondition:c,onRemoveCondition:d,onUpdateGroupOperator:r,availableFields:i,updateConditionFields:o}){const{attributes:u,listeners:g,setNodeRef:p,transform:h,transition:w,isDragging:m}=s.useSortable({id:t.id}),{isPending:x,error:f}=es(t.field),j={transform:s.CSS.Transform.toString(h),transition:w};return e.jsxs("div",{ref:p,style:j,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-muted/50 ${m?"z-50 opacity-50":""}`,children:[e.jsx("div",{...u,...g,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:l,onValueChange:y=>r(a,y),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(zn,{value:t.field,onValueChange:y=>{const F=y,D=s.getDataType(F.dataType)==="date";o(a,t.id,{field:F,value:"",operator:D?"between":"="})},availableFields:i,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:y=>{y==="in"||y==="not in"?o(a,t.id,{operator:y,value:[]}):y==="isNull"||y==="isNotNull"?o(a,t.id,{operator:y,value:null}):o(a,t.id,{operator:y,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-32",children:e.jsx(s.SelectValue,{children:t.operator?Cs(t.operator):""})}),e.jsx(s.SelectContent,{children:Qn(s.getDataType(t.field.dataType)).map(y=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:y,children:Cs(y)},y))})]}),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"?x?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..."]}):f?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx($n,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(y=>typeof y=="string")?t.value:[],onChange:y=>o(a,t.id,{value:y}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input,{value:typeof t.value=="string"?t.value:"",onChange:y=>o(a,t.id,{value:y.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(qn,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:y=>o(a,t.id,{value:y}),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:y=>o(a,t.id,{value:y==="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(Kn,{value:t.value,operator:t.operator,onChange:y=>o(a,t.id,{value:y}),className:"flex-1"}):e.jsx(s.Input,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:y=>c(a,t.id,"value",y.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 Wn({group:t,depth:n,parentGroupId:a,onUpdateGroupOperator:l,onUpdateGroupNegate:c,onRemoveGroup:d,onUpdateCondition:r,onUpdateField:i,onRemoveCondition:o,onReorderConditions:u,onReorderGroups:g,onAddCondition:p,onAddGroup:h,availableFields:w,renderFilterGroup:m,updateConditionFields:x}){const{attributes:f,listeners:j,setNodeRef:y,transform:F,transition:D,isDragging:N}=s.useSortable({id:t.id}),E={transform:s.CSS.Transform.toString(F),transition:D},C=I=>{const{active:M,over:b}=I;if(b&&M.id!==b.id){const v=t.conditions.findIndex(R=>R.id===M.id),A=t.conditions.findIndex(R=>R.id===b.id);v!==-1&&A!==-1&&u(t.id,v,A)}},S=I=>{const{active:M,over:b}=I;if(b&&M.id!==b.id&&a){const v=t.groups.findIndex(R=>R.id===M.id),A=t.groups.findIndex(R=>R.id===b.id);v!==-1&&A!==-1&&g(a,v,A)}};return e.jsxs("div",{ref:y,style:E,className:`rounded-lg ${n>0?"mt-2 border border-border":""} ${N?"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",{...f,...j,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:()=>c(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:I=>l(t.id,I),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:C,children:e.jsx(s.SortableContext,{items:t.conditions.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((I,M)=>e.jsx(Gs,{condition:I,index:M,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:r,onUpdateField:i,onRemoveCondition:o,onUpdateGroupOperator:l,availableFields:w,updateConditionFields:x},I.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:S,children:e.jsx(s.SortableContext,{items:t.groups.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(I=>m(I,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:()=>p(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:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Xn({filters:t,availableFields:n,onSave:a,onClearAll:l,onCancel:c}){const{currentFilters:d,availableFields:r,isLoading:i,addCondition:o,addGroup:u,removeCondition:g,removeGroup:p,updateCondition:h,updateConditionFields:w,updateGroupOperator:m,updateGroupNegate:x,reorderConditions:f,reorderGroups:j,generateSQLPreview:y,hasAnyFilters:F,setCurrentFilters:D}=Bn({initialFilters:t,availableFields:n}),N=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[E,C]=L.useState(!1),S=(b,v,A)=>{const R=k=>k.id===b?{...k,conditions:k.conditions.map(O=>O.id===v?{...O,field:A,dataType:A.dataType}:O)}:{...k,groups:k.groups.map(R)};D(R(d))},I=(b,v=0,A)=>v===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:N,collisionDetection:s.closestCenter,onDragEnd:R=>{const{active:k,over:O}=R;if(O&&k.id!==O.id){const T=b.conditions.findIndex($=>$.id===k.id),P=b.conditions.findIndex($=>$.id===O.id);T!==-1&&P!==-1&&f(b.id,T,P)}},children:e.jsx(s.SortableContext,{items:b.conditions.map(R=>R.id),strategy:s.verticalListSortingStrategy,children:b.conditions.map((R,k)=>e.jsx(Gs,{condition:R,index:k,groupId:b.id,groupLogicalOperator:b.logicalOperator,onUpdateCondition:h,onUpdateField:S,onRemoveCondition:g,onUpdateGroupOperator:m,availableFields:r,updateConditionFields:w},R.id))})}),e.jsx(s.DndContext,{sensors:N,collisionDetection:s.closestCenter,onDragEnd:R=>{const{active:k,over:O}=R;if(O&&k.id!==O.id){const T=b.groups.findIndex($=>$.id===k.id),P=b.groups.findIndex($=>$.id===O.id);T!==-1&&P!==-1&&j(b.id,T,P)}},children:e.jsx(s.SortableContext,{items:b.groups.map(R=>R.id),strategy:s.verticalListSortingStrategy,children:b.groups.map(R=>I(R,v+1,b.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:()=>o(b.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),E&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>u(b.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},b.id):e.jsx(Wn,{group:b,depth:v,parentGroupId:A,onUpdateGroupOperator:m,onUpdateGroupNegate:x,onRemoveGroup:p,onUpdateCondition:h,onUpdateField:S,onRemoveCondition:g,onReorderConditions:f,onReorderGroups:j,onAddCondition:o,onAddGroup:u,availableFields:r,renderFilterGroup:I,updateConditionFields:w},b.id),M=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:[i?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..."})]}):I(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:E,onCheckedChange:b=>C(b)}),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)"})]})}),F&&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:y(d)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:c,children:"Cancel"}),M>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:l,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>a(F?d:null),children:"Apply Filters"})]})]})}function Zn({cardId:t,filters:n,onFiltersChange:a,onClearFilters:l,availableFields:c,isOpen:d,onOpenChange:r}){const i=u=>{a(t,u),r(!1)},o=()=>{l(t),r(!1)};return e.jsxs(s.Dialog,{modal:!1,open:d,onOpenChange:r,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:u=>{u.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(Xn,{filters:n,availableFields:c,onSave:i,onCancel:()=>r(!1),onClearAll:o})]})]})}function er({activeCardId:t,sourceFields:n,getFieldsForContainer:a,setFieldsForContainer:l}){var f,j;const[c,d]=L.useState(null),r=s.useEditorStore(y=>y.card),i=s.useEditorStore(y=>y.actions.updateCardConfig),o=(f=r==null?void 0:r.config)==null?void 0:f.joinPlan,u=(j=r==null?void 0:r.dataSource)==null?void 0:j.semanticDomainId,{data:g}=s.useJoinabilityMap(u),p=[...n,...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")],h=L.useCallback(y=>y.startsWith("card-")?null:y.startsWith("source-")||n.find(F=>F.id===y)?"source":a("groupBy").find(F=>F.id===y)?"groupBy":a("metrics").find(F=>F.id===y)?"metrics":a("pivotBy").find(F=>F.id===y)?"pivotBy":a("sortBy").find(F=>F.id===y)?"sortBy":null,[n,a]),w=L.useCallback(y=>{d(y.active.id)},[]),m=L.useCallback(y=>{var I;const{active:F,over:D}=y;if(!D||!t){d(null);return}const N=F.id,E=D.id,C=h(N),S=h(E)||E;if(S==="sortBy"){if(C==="source"){const M=n.find(v=>v.id===N);if(!M){d(null);return}if(!(a("groupBy").some(v=>v.name===M.name&&v.qualifiedEntityName===M.qualifiedEntityName)||a("metrics").some(v=>v.name===M.name&&v.qualifiedEntityName===M.qualifiedEntityName))){d(null);return}}else if(C==="pivotBy"){d(null);return}else if(C!=="groupBy"&&C!=="metrics"&&C!=="sortBy"){d(null);return}}if(C==="source"&&S==="sortBy"){const M=[...n].find(R=>R.id===N);if(!M){d(null);return}const b=a("sortBy");if(s.fieldAlreadyExists(M,b)){d(null);return}const v=s.validateFieldForChartType(M,"sortBy",r.type);if(!v.isValid){s.ue.error("Invalid Field Type",{description:v.reason,position:"top-center",duration:3e3}),d(null);return}const A=s.getNewField(M,"sortBy",b);d(null),l("sortBy",[...b,A]);return}if(C==="source"&&S!=="source"&&S!=="sortBy"){const M=[...n].find(O=>O.id===N);if(!M){d(null);return}const b=[...a("groupBy"),...a("pivotBy"),...a("metrics"),...a("sortBy")];if(b.length>0){const O=b[0].qualifiedEntityName;if(!O){d(null);return}if(O!==M.qualifiedEntityName&&M.qualifiedEntityName)if(u&&(g!=null&&g.joinabilityMap)){if(s.calculateFieldState(M,{joinabilityMap:g.joinabilityMap,selectedFields:b,baseEntityName:(I=o==null?void 0:o.baseEntity)==null?void 0:I.name}).state==="unreachable"){s.showJoinRequiredNotification(),d(null);return}}else{if(!o){s.showJoinRequiredNotification(),d(null);return}if(!s.areEntitiesJoined(O,M.qualifiedEntityName,o)){s.showJoinRequiredNotification(),d(null);return}}}const v=a(S);if(s.fieldAlreadyExists(M,v)){d(null);return}const A=s.validateFieldForChartType(M,S,r.type);if(!A.isValid){s.ue.error("Invalid Field Type",{description:A.reason,position:"top-center",duration:3e3}),d(null);return}const R=s.getNewField(M,S,v),k=[...v,R];d(null),l(S,k),S==="metrics"&&t&&s.cleanupKpiMetricComparisonMode(r.type,r.config,i,t,k);return}if(C&&S&&C!=="source"&&S!=="source"&&C!==S){const M=a(C),b=a(S),v=M.find(T=>T.id===N);if(!v){d(null);return}const A=s.validateFieldForChartType(v,S,r.type);if(!A.isValid){s.ue.error("Invalid Field Type",{description:A.reason,position:"top-center",duration:3e3}),d(null);return}const R=s.getNewField(v,S,b);if(d(null),S==="sortBy"){s.fieldAlreadyExists(v,b)||l(S,[...b,R]);return}const k=M.filter(T=>T.id!==N),O=[...b,R];l(C,k),l(S,O),S==="metrics"&&t&&s.cleanupKpiMetricComparisonMode(r.type,r.config,i,t,O);return}if(C&&S&&C===S&&C!=="source"){const M=a(C),b=M.findIndex(A=>A.id===N),v=M.findIndex(A=>A.id===E);if(b!==v){const A=s.arrayMove(M,b,v);l(C,A)}}d(null)},[t,n,a,l,h,o,u,g,r.type,i,r.config]),x=c?p.find(y=>y.id===c):null;return{activeId:c,activeField:x,handleDragStart:w,handleDragEnd:m}}function sr({activeView:t,onViewChange:n,splitViewEnabled:a}){const l=s.useEditorStore(o=>o.card),{config:c}=L.useContext(s.SemaphorContext).tokenProps,d=(c==null?void 0:c.showInfoTab)!==!1,{errorMessage:r}=s.useDashboardCardQuery(l),i=()=>a?!1:!["table","pivotTable","aggregateTable"].includes(l.type);return e.jsx(s.Tabs,{value:t,onValueChange:o=>n(o),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"}),i()&&e.jsx(s.TabsTrigger,{value:"table",className:"rounded-md transition data-[state=active]:bg-muted",children:"Results"}),l.type!=="kpi"&&d&&e.jsx(s.TabsTrigger,{value:"info",className:s.cn("rounded-md transition data-[state=active]:bg-muted",r&&"text-destructive data-[state=active]:bg-destructive/10 data-[state=active]:text-destructive"),children:r?"Error":"Info"})]})})}const tr=[{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 ar(){var o,u;const t=s.useEditorStore(g=>g.card),{updateRowLimit:n}=s.useEditorActions(),[a,l]=L.useState(!1),[c,d]=L.useState(""),r=g=>{if(g==="custom"){l(!0);return}l(!1),n(t.id,parseInt(g))},i=g=>{const p=g.target.value;d(p),p&&!isNaN(parseInt(p))&&n(t.id,parseInt(p))};return e.jsx("div",{className:"flex items-center gap-2",children:a?e.jsx(s.Input$1,{type:"number",value:c,onChange:i,className:"h-7 w-24",placeholder:"Enter limit",min:1}):e.jsxs(s.Select,{value:((u=(o=t.config)==null?void 0:o.rowLimit)==null?void 0:u.toString())||"100",onValueChange:r,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:tr.map(g=>e.jsx(s.SelectItem,{value:g.value,children:g.label},g.value))})]})})}function nr({card:t,queryData:n,isLoading:a,isFetching:l,pagination:c,onPaginationChange:d,onSortChange:r,sortState:i,splitViewEnabled:o}){const u=L.useMemo(()=>(n==null?void 0:n.records)||[],[n==null?void 0:n.records]);return!o||["table","pivotTable","aggregateTable"].includes(t.type)?e.jsx(_e,{}):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(_e,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{defaultSize:40,minSize:20,role:"results-section",className:"flex flex-col",children:e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:(n==null?void 0:n.records)&&e.jsx(s.TableVisual,{card:t,data:u,paginationMetadata:c,onPaginationChange:d,isLoading:a||l,onSortChange:r,sortState:i})})})]})}const rr="semaphor-split-view-enabled";function lr(){return As(rr,!0)}function or({activeView:t,onViewChange:n,showDebug:a,onDebugToggle:l,onFiltersClick:c,activeCard:d,columns:r,columnsLoading:i,columnsError:o}){var se,J,te;const u=s.useEditorStore(Q=>Q.card),g=s.useDashboardStore(Q=>Q.filterValues),p=s.useDashboardStore(Q=>Q.selectedSheetId),h=s.useDashboardStore(Q=>Q.inlineFilterValuesMap[(d==null?void 0:d.id)||""]),{updateCardConfig:w,setCard:m,updateCardInFrame:x,setShowAIDialog:f}=s.useEditorActions(),j=s.useEditorStore(Q=>Q.showAIDialog),y=s.useDashboardStore(Q=>Q.isVisualEditing),[F,D]=L.useState(!1),[N,E]=L.useState(!1),[C,S]=L.useState(null),{config:I}=L.useContext(s.SemaphorContext).tokenProps,M=(I==null?void 0:I.showInfoTab)!==!1,[b,v]=lr();s.useEditorStore(Q=>{var le;return((le=Q.card.customCardPreferences)==null?void 0:le.url)&&Q.card.type==="custom"});const{data:A,errorMessage:R,isLoading:k,isFetching:O,errorSql:T,pagination:P,refetch:$,comparisonMetadata:H}=s.useDashboardCardQuery(d),q=L.useMemo(()=>(A==null?void 0:A.records)||[],[A==null?void 0:A.records]),[K,_]=L.useState(!1);L.useEffect(()=>{O||_(!1)},[O]);const B=()=>{const Q=!b;Q&&t==="table"&&n("chart"),v(Q)},U=(Q,le)=>{const de={...d,paginationConfig:{page:Q+1,pageSize:le}};m(de),x(de)};function V(){return e.jsxs("div",{className:"relative border-b border-border bg-background p-4",children:[e.jsx("button",{onClick:l,className:"absolute right-4 top-4 rounded-md p-1 hover:bg-muted","aria-label":"Close Debug Panel",children:e.jsx(s.X,{className:"h-4 w-4"})}),e.jsxs("div",{className:"space-y-4 pr-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Active Card Config"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(u.config||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Dashboard Filters"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(g||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium",children:"Card Data Source State"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:JSON.stringify(d.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium",children:["Columns (",r.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs",children:i?"Loading...":o?"Error loading columns":JSON.stringify(r.slice(0,5),null,2)})]})]})]})}const W=Q=>{if(!u.config)return;const le=s.sortStateToSortByColumns(Q,u.config.metricColumns,u.config.groupByColumns);w(u.id,{...u.config,sortByColumns:le})},X=L.useMemo(()=>{var Q;return s.sortByColumnsToSortState((Q=u.config)==null?void 0:Q.sortByColumns)},[(se=u.config)==null?void 0:se.sortByColumns]);return e.jsxs("div",{className:s.cn("relative flex w-0 grow flex-col",{"border-l":j&&y}),children:[a&&V(),e.jsxs("div",{className:"group/visualization relative flex h-full max-w-full grow flex-col pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t==="chart"&&j&&e.jsx(Fs,{variant:"outline"}),e.jsx(sr,{activeView:t,onViewChange:n,splitViewEnabled:b}),e.jsx(s.FilterInfo,{cardId:d.id,cardFilters:(J=d.config)==null?void 0:J.filters,cardFilterCount:s.getFilterCount(((te=d.config)==null?void 0:te.filters)||null),onFiltersClick:c,inlineFilters:d.inlineFilters,inlineFilterValues:h,sheetId:p||""}),H&&e.jsx(s.ComparisonMetadataBadge,{metadata:H,variant:"compact"}),e.jsx("div",{className:"ml-2",children:e.jsx(ar,{})}),j&&e.jsx(He.EditorClearButton,{})]}),e.jsxs("div",{className:s.cn("flex grow items-center justify-end gap-2"),children:[e.jsx(s.IconButton,{tooltip:"Refresh",disabled:k||O,onClick:()=>{_(!0),$()},children:e.jsx(s.RefreshCcw,{className:s.cn("h-4 w-4",{"animate-spin":K})})}),t==="chart"&&e.jsx(s.IconButton,{tooltip:b?"Hide Results Table":"Show Results Table",onClick:B,children:b?e.jsx(rt,{className:"size-4"}):e.jsx(vt,{className:"size-4"})}),t==="chart"&&e.jsx(e.Fragment,{children:e.jsx(Bs,{})}),!j&&e.jsx(s.IconButton,{onClick:()=>f(!j),tooltip:"AI",className:"h-8","aria-label":"AI",children:e.jsx(s.Sparkles,{className:"size-4"})}),l&&s.isDevEnv]})]}),e.jsxs("div",{className:"mt-3 flex min-h-0 grow flex-col",children:[t==="chart"&&e.jsx("div",{className:s.cn("flex grow flex-col pb-6",{"pb-0":b&&!["table","pivotTable","aggregateTable"].includes(d.type)}),children:e.jsx(nr,{card:d,queryData:A,isLoading:k,isFetching:O,pagination:P,onPaginationChange:U,onSortChange:W,sortState:X,splitViewEnabled:b})}),t==="table"&&(A==null?void 0:A.records)&&e.jsx("div",{className:"relative flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:d,data:q,paginationMetadata:P,onPaginationChange:U,isLoading:k||O,onSortChange:W,sortState:X})}),t==="info"&&M&&e.jsx("div",{className:"flex min-h-0 flex-1 flex-col pb-6",children:e.jsx("div",{className:"flex min-h-0 flex-1 flex-col rounded-md bg-background px-6",children:R?e.jsx(Ye,{error:R,errorSql:T,onSendFeedback:()=>{const Q=s.prepareFeedbackData(s.FeedbackCategory.QUERY_GENERATION,{cardConfig:u.config,dataSource:d.dataSource,dashboardFilters:g,errorMessage:R,errorSql:T,generatedSql:A==null?void 0:A.sql});S(Q),E(!0)},onOpenInEditor:()=>{f(!0),setTimeout(()=>{const Q=s.useEditorStore.getState().actions;Q.setIsDevMode(!0),Q.setCardSql(T||""),setTimeout(()=>{Q.setRunSql(!0)},100)},100)}}):e.jsx(Ls,{sql:A==null?void 0:A.sql,error:R,errorSql:T})})})]}),C&&e.jsx(s.FeedbackDialog,{open:N,onOpenChange:E,feedbackData:C})]})]})}function ir({activeField:t}){const[n,a]=L.useState(!0);return L.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(Xe,{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 cr=()=>{const t=console.error;console.error=(...l)=>{l.length>0&&typeof l[0]=="string"&&l[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,l)};const n=l=>{if(l.message&&(l.message.includes("ResizeObserver loop completed with undelivered notifications")||l.message.includes("ResizeObserver loop limit exceeded")))return l.preventDefault(),l.stopPropagation(),!1},a=l=>{var c;if((c=l.reason)!=null&&c.message&&(l.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||l.reason.message.includes("ResizeObserver loop limit exceeded")))return l.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 dr({column:t,isSelected:n,onSelect:a,availableFields:l,width:c,onWidthChange:d}){var $,H,q;const r=s.useEditorStore(K=>K.card),{updateCardConfig:i,removeGroupByColumn:o,removeMetricColumn:u,updateFilters:g}=s.useEditorActions(),[p,h]=L.useState(!1),[w,m]=L.useState(!1),x=L.useRef(null),f=L.useCallback(K=>{K.preventDefault(),K.stopPropagation(),m(!0),x.current={startX:K.clientX,startWidth:c||150};const _=U=>{if(!x.current)return;const V=U.clientX-x.current.startX,W=Math.max(80,x.current.startWidth+V);d==null||d(t.id,W)},B=()=>{m(!1),x.current=null,document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",B)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",B)},[c,t.id,d]),j=($=r==null?void 0:r.config)==null?void 0:$.filters,y=(H=j==null?void 0:j.conditions)==null?void 0:H.some(K=>K.field.name===t.name&&K.field.qualifiedEntityName===t.qualifiedEntityName),F=K=>{K?g(r.id,K):i(r.id,{filters:void 0})},{attributes:D,listeners:N,setNodeRef:E,transform:C,transition:S,isDragging:I}=s.useSortable({id:t.id}),M={transform:s.CSS.Transform.toString(C),transition:S},b=s.getDataType(t.dataType),v=ur(b),A=()=>{var B;const K=((B=r==null?void 0:r.config)==null?void 0:B.sortByColumns)||[],_=K.findIndex(U=>U.name===t.name);if(_!==-1){const U=[...K];U[_]={...U[_],direction:"asc"},i(r.id,{sortByColumns:U})}else i(r.id,{sortByColumns:[...K,{...t,id:`sort-${t.id}`,role:"sortby",direction:"asc"}]})},R=()=>{var B;const K=((B=r==null?void 0:r.config)==null?void 0:B.sortByColumns)||[],_=K.findIndex(U=>U.name===t.name);if(_!==-1){const U=[...K];U[_]={...U[_],direction:"desc"},i(r.id,{sortByColumns:U})}else i(r.id,{sortByColumns:[...K,{...t,id:`sort-${t.id}`,role:"sortby",direction:"desc"}]})},k=()=>{var B;const K=((B=r==null?void 0:r.config)==null?void 0:B.groupByColumns)||[];if(!K.some(U=>U.name===t.name)){const U={...t,id:`groupby-${t.id}-${Date.now()}`,role:"groupby"};i(r.id,{groupByColumns:[...K,U]})}},O=K=>{var U;const _=((U=r==null?void 0:r.config)==null?void 0:U.metricColumns)||[];if(!_.some(V=>V.name===t.name&&V.aggregate===K)){const V={...t,id:`metric-${t.id}-${K}-${Date.now()}`,label:`${K} of ${t.label||t.name}`,role:"metric",aggregate:K};i(r.id,{metricColumns:[..._,V]})}},T=()=>{t.role==="groupby"?o(r.id,t.id):t.role==="metric"&&u(r.id,t.id)},P={...M,width:c?`${c}px`:void 0,minWidth:c?`${c}px`:"120px"};return e.jsxs("th",{ref:E,style:P,className:s.cn("group relative border-r border-border bg-background px-1 py-0",I&&"opacity-50",n&&"bg-primary/10",w&&"select-none"),children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{...D,...N,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(v,{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,")"]}),y&&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:()=>h(!0),children:[e.jsx(s.Filter,{className:s.cn("mr-2 h-4 w-4",y&&"text-primary")}),y?"Edit Filter":"Filter"]}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuItem,{onClick:A,children:[e.jsx(et,{className:"mr-2 h-4 w-4"}),"Sort A → Z"]}),e.jsxs(s.DropdownMenuItem,{onClick:R,children:[e.jsx(Zs,{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:k,children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Group by this column"]}),e.jsxs(s.DropdownMenuItem,{disabled:!0,children:[e.jsx(Ts,{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:T,className:"text-destructive focus:text-destructive",children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove column"]})]})]})]}),e.jsx("div",{onMouseDown:f,className:s.cn("absolute right-0 top-0 h-full w-1 cursor-col-resize bg-transparent hover:bg-primary/50",w&&"bg-primary")}),e.jsx(qs,{open:p,onOpenChange:h,availableFields:l.length>0?l:[t],existingFilters:j,editingCondition:y?(q=j==null?void 0:j.conditions)==null?void 0:q.find(K=>K.field.name===t.name&&K.field.qualifiedEntityName===t.qualifiedEntityName):void 0,onSave:F})]})}function ur(t){switch(t){case"number":return s.Hash;case"date":return s.Calendar;case"string":default:return s.Type}}function mr({selectedColumn:t,onColumnSelect:n,isLoading:a=!1,sourceFields:l=[]}){var S,I,M,b;const c=s.useEditorStore(v=>v.card),{updateCardConfig:d}=s.useEditorActions(),[r,i]=L.useState(null),[o,u]=L.useState({}),[g,p]=L.useState(!1),h=L.useMemo(()=>{var R,k;const v=((R=c==null?void 0:c.config)==null?void 0:R.groupByColumns)||[],A=((k=c==null?void 0:c.config)==null?void 0:k.metricColumns)||[];return[...v,...A]},[(S=c==null?void 0:c.config)==null?void 0:S.groupByColumns,(I=c==null?void 0:c.config)==null?void 0:I.metricColumns]),w=L.useMemo(()=>{const v=new Set(h.map(A=>`${A.qualifiedEntityName}.${A.name}`));return l.filter(A=>!v.has(`${A.qualifiedEntityName}.${A.name}`))},[l,h]),{data:m,isLoading:x}=s.useDashboardCardQuery(c),f=(m==null?void 0:m.records)||[],j=L.useCallback((v,A)=>{u(R=>({...R,[v]:A}))},[]),y=L.useCallback(v=>{var O,T;const A=s.getDataType(v.dataType),R=((O=c==null?void 0:c.config)==null?void 0:O.groupByColumns)||[],k=((T=c==null?void 0:c.config)==null?void 0:T.metricColumns)||[];if(A==="number"){const P={...v,id:`metric-${v.id}-${Date.now()}`,role:"metric",aggregate:"SUM"};d(c.id,{metricColumns:[...k,P]})}else{const P={...v,id:`groupby-${v.id}-${Date.now()}`,role:"groupby"};d(c.id,{groupByColumns:[...R,P]})}p(!1)},[(M=c==null?void 0:c.config)==null?void 0:M.groupByColumns,(b=c==null?void 0:c.config)==null?void 0:b.metricColumns,c.id,d]),F=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),D=v=>{i(v.active.id)},N=v=>{const{active:A,over:R}=v;if(i(null),!R||A.id===R.id)return;const k=h.findIndex(T=>T.id===A.id),O=h.findIndex(T=>T.id===R.id);if(k!==-1&&O!==-1){const T=s.arrayMove(h,k,O),P=T.filter(H=>H.role==="groupby"),$=T.filter(H=>H.role==="metric");d(c.id,{groupByColumns:P,metricColumns:$})}},E=r?h.find(v=>v.id===r):null,C=v=>{let A="";for(;v>=0;)A=String.fromCharCode(v%26+65)+A,v=Math.floor(v/26)-1;return A};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"})}):h.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:F,collisionDetection:s.closestCenter,onDragStart:D,onDragEnd:N,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:h.map(v=>v.id),strategy:s.horizontalListSortingStrategy,children:h.map((v,A)=>e.jsx("th",{style:{width:o[v.id]?`${o[v.id]}px`:void 0,minWidth:o[v.id]?`${o[v.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:C(A)},`letter-${v.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:h.map(v=>v.id),strategy:s.horizontalListSortingStrategy,children:h.map(v=>e.jsx(dr,{column:v,isSelected:(t==null?void 0:t.id)===v.id,onSelect:()=>n(v),availableFields:l,width:o[v.id],onWidthChange:j},v.id))}),e.jsx("th",{className:"w-10 border-r border-border bg-background px-1 py-2",children:e.jsxs(s.Popover,{open:g,onOpenChange:p,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:w.map(v=>{const A=s.getDataType(v.dataType),R=A==="number"?s.Hash:A==="date"?s.Calendar:s.Type;return e.jsxs(s.CommandItem,{value:v.label||v.name,onSelect:()=>y(v),children:[e.jsx(R,{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:v.label||v.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:v.entityName})]})]},v.id)})})]})]})})]})})]})]}),e.jsx("tbody",{children:x?e.jsx("tr",{children:e.jsx("td",{colSpan:h.length+2,className:"h-32 text-center",children:e.jsx(s.LoaderCircle,{className:"mx-auto h-6 w-6 animate-spin text-muted-foreground"})})}):f.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:h.length+2,className:"h-32 text-center text-muted-foreground",children:"No data available"})}):f.slice(0,100).map((v,A)=>e.jsxs("tr",{className:s.cn("border-b border-border transition-colors hover:bg-muted/50",A%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:A+1}),h.map(R=>{const k=v[R.name]??v[R.label??""];return e.jsx("td",{style:{width:o[R.id]?`${o[R.id]}px`:void 0,minWidth:o[R.id]?`${o[R.id]}px`:"120px"},className:s.cn("border-r border-border px-3 py-2 text-sm",(t==null?void 0:t.id)===R.id&&"bg-primary/5"),children:e.jsx("span",{className:"block truncate",children:xr(k,R)})},`${A}-${R.id}`)}),e.jsx("td",{className:"w-10 border-r border-border"})]},A))})]}),e.jsx(s.DragOverlay,{children:E&&e.jsx("div",{className:"rounded border border-primary bg-background px-3 py-2 text-sm font-medium shadow-lg",children:E.label||E.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(f.length,100)," of ",f.length," rows"]}),e.jsxs("span",{children:[h.length," columns"]})]})]})}function xr(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 hr({entityGroups:t,isLoading:n=!1}){var F,D;const a=s.useEditorStore(N=>N.card),{updateCardConfig:l,removeGroupByColumn:c,removeMetricColumn:d}=s.useEditorActions(),[r,i]=L.useState(!0),[o,u]=L.useState(""),[g,p]=L.useState(new Set),h=((F=a==null?void 0:a.config)==null?void 0:F.groupByColumns)||[],w=((D=a==null?void 0:a.config)==null?void 0:D.metricColumns)||[],m=N=>{const E=new Set(g);E.has(N)?E.delete(N):E.add(N),p(E)},x=N=>h.some(E=>E.name===N.name&&E.qualifiedEntityName===N.qualifiedEntityName)||w.some(E=>E.name===N.name&&E.qualifiedEntityName===N.qualifiedEntityName),f=(N,E)=>{if(E)if(s.getDataType(N.dataType)==="number"){const S={...N,id:`metric-${N.id}-${Date.now()}`,role:"metric",aggregate:"SUM"};l(a.id,{metricColumns:[...w,S]})}else{const S={...N,id:`groupby-${N.id}-${Date.now()}`,role:"groupby"};l(a.id,{groupByColumns:[...h,S]})}else{const C=h.findIndex(I=>I.name===N.name&&I.qualifiedEntityName===N.qualifiedEntityName),S=w.findIndex(I=>I.name===N.name&&I.qualifiedEntityName===N.qualifiedEntityName);C!==-1&&c(a.id,h[C].id),S!==-1&&d(a.id,w[S].id)}},j=N=>{if(!o)return N;const E=o.toLowerCase();return N.filter(C=>C.name.toLowerCase().includes(E)||C.label&&C.label.toLowerCase().includes(E))},y=N=>{switch(s.getDataType(N)){case"number":return s.Hash;case"date":return s.Calendar;default:return s.Type}};return r?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:()=>i(!1),title:"Close panel",children:e.jsx(gt,{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$1,{placeholder:"Search columns...",value:o,onChange:N=>u(N.target.value),className:"h-8 pl-8 text-sm"})]})}),(h.length>0||w.length>0)&&e.jsxs("div",{className:"border-b border-border",children:[h.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(Je,{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:h.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:h.map(N=>{const E=y(N.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(E,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:N.label||N.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:()=>c(a.id,N.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},N.id)})})})]}),w.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:w.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"space-y-0.5 px-3 pb-2",children:w.map(N=>{const E=y(N.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(E,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:N.label||N.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:N.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,N.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},N.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(N=>{const E=j(N.columns);if(E.length===0)return null;const C=g.has(N.entityId)||o.length>0;return e.jsxs(s.Collapsible,{open:C,onOpenChange:()=>m(N.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",C&&"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:N.label||N.entityName}),e.jsx("span",{className:"text-xs text-muted-foreground",children:E.length})]}),e.jsx(s.CollapsibleContent,{children:e.jsx("div",{className:"ml-4 space-y-0.5 border-l border-border pl-2",children:E.map(S=>{const I=y(S.dataType),M=x(S);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",M&&"bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:M,onCheckedChange:b=>f(S,b),className:"h-3.5 w-3.5"}),e.jsx(I,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"flex-1 truncate",children:S.label||S.name})]},S.id)})})})]},N.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:()=>i(!0),title:"Open panel",children:e.jsx(ft,{className:"h-4 w-4"})})})}const pr=[{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 gr({value:t,onChange:n,onSubmit:a,onCancel:l,selectedColumn:c,availableColumns:d}){const[r,i]=L.useState(!1),[o,u]=L.useState("column"),g=L.useRef(null);L.useEffect(()=>{const m=x=>{x.key==="Escape"&&t?l():x.key==="Enter"&&t&&!r&&a(t)};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[t,l,a,r]);const p=m=>{const x=`[${m.label||m.name}]`,f=g.current;if(f){const j=f.selectionStart||0,y=f.selectionEnd||0,F=t.slice(0,j)+x+t.slice(y);n(F),setTimeout(()=>{f.setSelectionRange(j+x.length,j+x.length),f.focus()},0)}else n(t+x);i(!1)},h=m=>{const x=g.current;if(x){const f=x.selectionStart||0,j=x.selectionEnd||0,y=t.slice(0,f)+m.syntax+t.slice(j);n(y),setTimeout(()=>{x.setSelectionRange(f+m.name.length+1,f+m.syntax.length-1),x.focus()},0)}else n(t+m.syntax);i(!1)},w=m=>{switch(s.getDataType(m)){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:c?e.jsx("span",{className:"truncate",children:c.label||c.name}):e.jsx("span",{children:"—"})}),e.jsxs(s.Popover,{open:r&&o==="function",onOpenChange:m=>{i(m),m&&u("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(bt,{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:pr.map(m=>e.jsx(s.CommandItem,{value:m.name,onSelect:()=>h(m),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:m.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground/75",children:m.syntax})]})},m.name))})]})]})})]}),e.jsxs(s.Popover,{open:r&&o==="column",onOpenChange:m=>{i(m),m&&u("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(m=>{const x=w(m.dataType);return e.jsxs(s.CommandItem,{value:m.label||m.name,onSelect:()=>p(m),children:[e.jsx(x,{className:"mr-2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:m.label||m.name})]},m.id)})})]})]})})]}),e.jsx("div",{className:"relative flex-1",children:e.jsx(s.Input$1,{ref:g,value:t,onChange:m=>n(m.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:l,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 fr({className:t}){var h,w,m,x;const n=s.useEditorStore(f=>f.card),[a,l]=L.useState(null),[c,d]=L.useState(""),{columns:r=[],columnGroups:i=[],isLoading:o}=s.useColumns();(h=n==null?void 0:n.config)!=null&&h.groupByColumns,(w=n==null?void 0:n.config)!=null&&w.metricColumns,(m=n==null?void 0:n.config)!=null&&m.groupByColumns,(x=n==null?void 0:n.config)!=null&&x.pivotByColumns;const u=f=>{l(f),d(f?`[${f.label||f.name}]`:"")},g=f=>{console.log("Formula submitted:",f),d(""),l(null)},p=()=>{d(""),l(null)};return e.jsxs("div",{className:s.cn("flex h-full w-full flex-col",t),children:[e.jsx(gr,{value:c,onChange:d,onSubmit:g,onCancel:p,selectedColumn:a,availableColumns:r}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"flex-1 overflow-auto",children:e.jsx(mr,{selectedColumn:a,onColumnSelect:u,isLoading:o,sourceFields:r})}),e.jsx(hr,{entityGroups:i,isLoading:o})]})]})}function jr(){var $,H;const[t,n]=L.useState("chart"),[a,l]=L.useState(!1),[c,d]=L.useState(!1),[r,i]=L.useState(!0),o=s.useEditorStore(q=>q.showAIDialog),u=s.useDashboardStore(q=>q.isVisualEditing),{setCardType:g}=s.useEditorActions(),p=s.useEditorStore(q=>q.card.type);L.useEffect(()=>cr(),[]);const h=q=>{g(q)},w=s.useEditorStore(q=>q.frame),m=s.useEditorStore(q=>q.card);s.useEditorStore(q=>q.activeTabCardId),s.useEditorStore(q=>q.actions.getAvailableFields);const{addCard:x,removeCard:f,updateCard:j,setActiveCard:y,updateFilters:F}=s.useEditorActions(),{columns:D=[],isLoading:N,error:E}=s.useColumns(),C=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),S=m,{getFieldsForContainer:I,setFieldsForContainer:M}=s.useFieldManagement(S),{activeField:b,handleDragStart:v,handleDragEnd:A}=er({activeCardId:w.activeCardId,sourceFields:D,getFieldsForContainer:I,setFieldsForContainer:M}),R=(q,K)=>{K&&F(q,K)},k=q=>{var K;j(q,{config:{...(K=w.cards.find(_=>_.id===q))==null?void 0:K.config,filters:void 0}})},O=D,T=q=>{if(!q)return 0;let K=q.conditions.length;return q.groups.forEach(_=>{K+=T(_)}),K},P=T((($=S==null?void 0:S.config)==null?void 0:$.filters)||null);return e.jsxs(s.DndContext,{sensors:C,collisionDetection:s.closestCenter,onDragStart:v,onDragEnd:A,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(Ds,{isVisible:r,onToggleVisibility:()=>i(!r)}),e.jsx("div",{className:"flex flex-1 transition-all duration-300 ease-in-out",children:p==="tableBuilder"?e.jsx(fr,{className:"flex-1"}):e.jsxs(e.Fragment,{children:[!o&&e.jsx(Fn,{selectedChart:p,onChartChange:h,groupByFields:I("groupBy"),pivotByFields:I("pivotBy"),metricsFields:I("metrics"),sortByFields:I("sortBy"),activeField:b}),e.jsx(or,{selectedChart:p,activeView:t,onViewChange:n,showDebug:a,onDebugToggle:()=>l(!a),onFiltersClick:()=>d(!0),filterCount:P,activeCard:S,dataSourceState:m.dataSource||s.EMPTY_DATA_SOURCE,columns:D,columnsLoading:N,columnsError:E,getFieldsForContainer:I,cards:w.cards,activeCardId:w.activeCardId,addCard:x,setActiveCard:y})]})}),!r&&u&&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:()=>i(!0),title:"Show Data Source Panel",children:e.jsx(s.Database,{className:"h-4 w-4"})})})]}),S&&e.jsx(Zn,{cardId:S.id,filters:((H=S.config)==null?void 0:H.filters)||null,onFiltersChange:R,onClearFilters:k,availableFields:O,isOpen:c,onOpenChange:d}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(ir,{activeField:b||null})})]})}function br({authToken:t,onSave:n,onClose:a}){const l=L.useRef(null),c=s.useEditorStore(E=>E.showAIDialog),d=s.useEditorStore(E=>E.isDevMode),r=s.useAssistantLayoutStore(E=>E.setFullscreen),i=s.useAssistantLayoutStore(E=>E.setPanelOpen),o=s.useAssistantLayoutStore(E=>E.setContainer),u=s.useAssistantPanel("editor"),g=s.useFullscreenAssistant(),p=s.useAssistantContainer("editor"),h=g==="editor",w=L.useCallback(E=>{o("editor",E)},[o]),{setAuthToken:m}=s.useDashboardActions(),{setShowAIDialog:x,setOnSave:f,setOnClose:j}=s.useEditorActions(),{setActiveAssistantType:y}=s.useAIActions();L.useEffect(()=>{n&&f(n),a&&j(a)},[n,f,a,j]),L.useEffect(()=>{t&&t.accessToken&&m(t)},[t,m]),L.useEffect(()=>{var E,C;c?((E=l.current)==null||E.resize(40),i("editor",!0),y("editor")):((C=l.current)==null||C.resize(0),i("editor",!1),g==="editor"&&r(null),y(null))},[c,i,y,r,g]);function F(E){E<1?(x(!1),i("editor",!1),g==="editor"&&r(null),y(null)):(c||(x(!0),y("editor")),u.isOpen||i("editor",!0))}function D(){return e.jsxs(e.Fragment,{children:[e.jsx(Ds,{isVisible:!0,onToggleVisibility:()=>{}}),e.jsxs("div",{className:"relative flex grow border-l",children:[e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:s.cn("grow transition-opacity",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(fn,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:l,onResize:F,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(vs,{isFullscreen:h,onFullscreenChange:E=>r(E?"editor":null),fullscreenContainer:p})})})]}),e.jsx("div",{ref:w,className:s.cn("absolute inset-0",!h&&"pointer-events-none")})]})]})}function N(){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",h&&"pointer-events-none opacity-0"),direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(jr,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:l,onResize:F,defaultSize:u.isOpen?40:0,className:"flex",children:e.jsx("div",{className:"grow overflow-y-auto",children:e.jsx(vs,{isFullscreen:h,onFullscreenChange:E=>r(E?"editor":null),fullscreenContainer:p})})})]}),e.jsx("div",{ref:w,className:s.cn("absolute inset-0",!h&&"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:D()}):N()})}function vr(){s.useDashboardStore(r=>r.selectedCardId);const t=s.useDashboardStore(r=>r.selectedSheetId),{setIsVisualEditing:n}=s.useDashboardStore(r=>r.actions),a=s.useDashboardStore(r=>r.isVisualEditing),l=s.useDashboardStore(r=>r.actions.updateFrame);function c(r){t&&(l(t,r),n(!1))}function d(){n(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex-1 grow basis-0 overflow-auto",{"max-h-0 overflow-hidden":!a}),children:e.jsx(br,{onSave:c,onClose:d})})}exports.default=vr;