react-semaphor 0.0.490 → 0.0.491
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/dashboard-plus-CDcYeiXL.js +440 -0
- package/dist/chunks/dashboard-plus-DjdIqzup.js +14145 -0
- package/dist/chunks/{index-1AZBqWCM.js → index-BjgdaiaG.js} +15643 -14845
- package/dist/chunks/index-Cf_bcSdd.js +452 -0
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -369
- package/dist/index.js +51 -8700
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +3 -3
- package/dist/types/dashboard.d.ts +157 -3
- package/dist/types/main.d.ts +231 -8
- package/dist/types/surfboard.d.ts +157 -3
- package/dist/types/types.d.ts +157 -3
- package/package.json +1 -1
- package/dist/chunks/index-DIAWqd3Y.js +0 -447
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
"use strict";var zs=t=>{throw TypeError(t)};var Ue=(t,a,n)=>a.has(t)||zs("Cannot "+n);var W=(t,a,n)=>(Ue(t,a,"read from private field"),n?n.call(t):a.get(t)),re=(t,a,n)=>a.has(t)?zs("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(t):a.set(t,n),ee=(t,a,n,r)=>(Ue(t,a,"write to private field"),r?r.call(t,n):a.set(t,n),n),ie=(t,a,n)=>(Ue(t,a,"access private method"),n);const e=require("react/jsx-runtime"),s=require("./index-Cf_bcSdd.js"),M=require("react");require("react-dom");function Rt(t){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return a.default=t,Object.freeze(a)}const ae=Rt(M);function Bs(t,a){return t.filter(n=>!a.includes(n))}function Pt(t,a,n){const r=t.slice(0);return r[a]=n,r}var he,te,be,ve,ne,ue,Ee,Ie,Te,Z,ts,ns,as,rs,is,Ks,Vt=(Ks=class extends s.Subscribable{constructor(a,n,r){super();re(this,Z);re(this,he);re(this,te);re(this,be);re(this,ve);re(this,ne);re(this,ue);re(this,Ee);re(this,Ie);re(this,Te,[]);ee(this,he,a),ee(this,ve,r),ee(this,be,[]),ee(this,ne,[]),ee(this,te,[]),this.setQueries(n)}onSubscribe(){this.listeners.size===1&&W(this,ne).forEach(a=>{a.subscribe(n=>{ie(this,Z,rs).call(this,a,n)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,W(this,ne).forEach(a=>{a.destroy()})}setQueries(a,n,r){if(ee(this,be,a),ee(this,ve,n),process.env.NODE_ENV!=="production"){const i=a.map(o=>W(this,he).defaultQueryOptions(o).queryHash);new Set(i).size!==i.length&&console.warn("[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.")}s.notifyManager.batch(()=>{const i=W(this,ne),o=ie(this,Z,as).call(this,W(this,be));ee(this,Te,o),o.forEach(m=>m.observer.setOptions(m.defaultedQueryOptions,r));const c=o.map(m=>m.observer),d=c.map(m=>m.getCurrentResult()),l=c.some((m,u)=>m!==i[u]);i.length===c.length&&!l||(ee(this,ne,c),ee(this,te,d),this.hasListeners()&&(Bs(i,c).forEach(m=>{m.destroy()}),Bs(c,i).forEach(m=>{m.subscribe(u=>{ie(this,Z,rs).call(this,m,u)})}),ie(this,Z,is).call(this)))})}getCurrentResult(){return W(this,te)}getQueries(){return W(this,ne).map(a=>a.getCurrentQuery())}getObservers(){return W(this,ne)}getOptimisticResult(a,n){const r=ie(this,Z,as).call(this,a),i=r.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions));return[i,o=>ie(this,Z,ns).call(this,o??i,n),()=>ie(this,Z,ts).call(this,i,r)]}},he=new WeakMap,te=new WeakMap,be=new WeakMap,ve=new WeakMap,ne=new WeakMap,ue=new WeakMap,Ee=new WeakMap,Ie=new WeakMap,Te=new WeakMap,Z=new WeakSet,ts=function(a,n){return n.map((r,i)=>{const o=a[i];return r.defaultedQueryOptions.notifyOnChangeProps?o:r.observer.trackResult(o,c=>{n.forEach(d=>{d.observer.trackProp(c)})})})},ns=function(a,n){return n?((!W(this,ue)||W(this,te)!==W(this,Ie)||n!==W(this,Ee))&&(ee(this,Ee,n),ee(this,Ie,W(this,te)),ee(this,ue,s.replaceEqualDeep(W(this,ue),n(a)))),W(this,ue)):a},as=function(a){const n=new Map(W(this,ne).map(i=>[i.options.queryHash,i])),r=[];return a.forEach(i=>{const o=W(this,he).defaultQueryOptions(i),c=n.get(o.queryHash);c?r.push({defaultedQueryOptions:o,observer:c}):r.push({defaultedQueryOptions:o,observer:new s.QueryObserver(W(this,he),o)})}),r},rs=function(a,n){const r=W(this,ne).indexOf(a);r!==-1&&(ee(this,te,Pt(W(this,te),r,n)),ie(this,Z,is).call(this))},is=function(){var a;if(this.hasListeners()){const n=W(this,ue),r=ie(this,Z,ts).call(this,W(this,te),W(this,Te)),i=ie(this,Z,ns).call(this,r,(a=W(this,ve))==null?void 0:a.combine);n!==i&&s.notifyManager.batch(()=>{this.listeners.forEach(o=>{o(W(this,te))})})}},Ks);function qt({queries:t,...a},n){const r=s.useQueryClient(),i=s.useIsRestoring(),o=s.useQueryErrorResetBoundary(),c=ae.useMemo(()=>t.map(f=>{const S=r.defaultQueryOptions(f);return S._optimisticResults=i?"isRestoring":"optimistic",S}),[t,r,i]);c.forEach(f=>{s.ensureSuspenseTimers(f),s.ensurePreventErrorBoundaryRetry(f,o)}),s.useClearResetErrorBoundary(o);const[d]=ae.useState(()=>new Vt(r,c,a)),[l,m,u]=d.getOptimisticResult(c,a.combine),h=!i&&a.subscribed!==!1;ae.useSyncExternalStore(ae.useCallback(f=>h?d.subscribe(s.notifyManager.batchCalls(f)):s.noop,[d,h]),()=>d.getCurrentResult(),()=>d.getCurrentResult()),ae.useEffect(()=>{d.setQueries(c,a,{listeners:!1})},[c,a,d]);const p=l.some((f,S)=>s.shouldSuspend(c[S],f))?l.flatMap((f,S)=>{const x=c[S];if(x){const N=new s.QueryObserver(r,x);if(s.shouldSuspend(x,f))return s.fetchOptimistic(x,N,o);s.willFetch(f,i)&&s.fetchOptimistic(x,N,o)}return[]}):[];if(p.length>0)throw Promise.all(p);const g=l.find((f,S)=>{const x=c[S];return x&&s.getHasError({result:f,errorResetBoundary:o,throwOnError:x.throwOnError,query:r.getQueryCache().get(x.queryHash),suspense:x.suspense})});if(g!=null&&g.error)throw g.error;return m(u())}/**
|
|
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 _t=s.createLucideIcon("AlignCenter",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 $t=s.createLucideIcon("AlignLeft",[["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M17 18H3",key:"1amg6g"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 Gt=s.createLucideIcon("AlignRight",[["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M21 18H7",key:"1ygte8"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);/**
|
|
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 Ht=s.createLucideIcon("ArrowDown10",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M17 10V4h-2",key:"zcsr5x"}],["path",{d:"M15 10h4",key:"id2lce"}],["rect",{x:"15",y:"14",width:"4",height:"6",ry:"2",key:"33xykx"}]]);/**
|
|
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 Jt=s.createLucideIcon("ArrowDownZA",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 4v16",key:"1glfcx"}],["path",{d:"M15 4h5l-5 6h5",key:"8asdl1"}],["path",{d:"M15 20v-3.5a2.5 2.5 0 0 1 5 0V20",key:"r6l5cz"}],["path",{d:"M20 18h-5",key:"18j1r2"}]]);/**
|
|
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 $e=s.createLucideIcon("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/**
|
|
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 Ut=s.createLucideIcon("ArrowLeftRight",[["path",{d:"M8 3 4 7l4 4",key:"9rb6wj"}],["path",{d:"M4 7h16",key:"6tx8e3"}],["path",{d:"m16 21 4-4-4-4",key:"siv7j2"}],["path",{d:"M20 17H4",key:"h6l3hr"}]]);/**
|
|
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 Yt=s.createLucideIcon("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
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 Kt=s.createLucideIcon("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
|
|
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 Qt=s.createLucideIcon("ArrowUp01",[["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}],["rect",{x:"15",y:"4",width:"4",height:"6",ry:"2",key:"1bwicg"}],["path",{d:"M17 20v-6h-2",key:"1qp1so"}],["path",{d:"M15 20h4",key:"1j968p"}]]);/**
|
|
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 Wt=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"}]]);/**
|
|
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 Xt=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"}]]);/**
|
|
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 Zt=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"}]]);/**
|
|
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 Qs=s.createLucideIcon("BookType",[["path",{d:"M10 13h4",key:"ytezjc"}],["path",{d:"M12 6v7",key:"1f6ttz"}],["path",{d:"M16 8V6H8v2",key:"x8j6u4"}],["path",{d:"M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H19a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H6.5a1 1 0 0 1 0-5H20",key:"k3hazp"}]]);/**
|
|
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 en=s.createLucideIcon("Box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]);/**
|
|
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 sn=s.createLucideIcon("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);/**
|
|
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 tn=s.createLucideIcon("Calculator",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",key:"1nb95v"}],["line",{x1:"8",x2:"16",y1:"6",y2:"6",key:"x4nwl0"}],["line",{x1:"16",x2:"16",y1:"14",y2:"18",key:"wjye3r"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M8 14h.01",key:"6423bh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M8 18h.01",key:"lrp35t"}]]);/**
|
|
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 nn=s.createLucideIcon("ChartArea",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M7 11.207a.5.5 0 0 1 .146-.353l2-2a.5.5 0 0 1 .708 0l3.292 3.292a.5.5 0 0 0 .708 0l4.292-4.292a.5.5 0 0 1 .854.353V16a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1z",key:"q0gr47"}]]);/**
|
|
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 Ge=s.createLucideIcon("ChartColumnIncreasing",[["path",{d:"M13 17V9",key:"1fwyjl"}],["path",{d:"M18 17V5",key:"sfb6ij"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
|
|
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 us=s.createLucideIcon("ChartColumnStacked",[["path",{d:"M11 13H7",key:"t0o9gq"}],["path",{d:"M19 9h-4",key:"rera1j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["rect",{x:"15",y:"5",width:"4",height:"12",rx:"1",key:"q8uenq"}],["rect",{x:"7",y:"8",width:"4",height:"9",rx:"1",key:"sr5ea"}]]);/**
|
|
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 ms=s.createLucideIcon("ChartColumn",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]]);/**
|
|
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 He=s.createLucideIcon("ChartLine",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]);/**
|
|
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 hs=s.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
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 xs=s.createLucideIcon("ChartPie",[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]]);/**
|
|
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 ps=s.createLucideIcon("ChartScatter",[["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}],["circle",{cx:"18.5",cy:"5.5",r:".5",fill:"currentColor",key:"lysivs"}],["circle",{cx:"11.5",cy:"11.5",r:".5",fill:"currentColor",key:"byv1b8"}],["circle",{cx:"7.5",cy:"16.5",r:".5",fill:"currentColor",key:"nkw3mc"}],["circle",{cx:"17.5",cy:"14.5",r:".5",fill:"currentColor",key:"1gjh6j"}],["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}]]);/**
|
|
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 an=s.createLucideIcon("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);/**
|
|
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 rn=s.createLucideIcon("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
|
|
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 on=s.createLucideIcon("CircleArrowRight",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"m12 16 4-4-4-4",key:"1i9zcv"}]]);/**
|
|
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 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"}]]);/**
|
|
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 ln=s.createLucideIcon("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/**
|
|
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 cn=s.createLucideIcon("Code",[["polyline",{points:"16 18 22 12 16 6",key:"z7tu5w"}],["polyline",{points:"8 6 2 12 8 18",key:"1eg1df"}]]);/**
|
|
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 dn=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"}]]);/**
|
|
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 un=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"}]]);/**
|
|
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 mn=s.createLucideIcon("CopyPlus",[["line",{x1:"15",x2:"15",y1:"12",y2:"18",key:"1p7wdc"}],["line",{x1:"12",x2:"18",y1:"15",y2:"15",key:"1nscbv"}],["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);/**
|
|
172
|
+
* @license lucide-react v0.453.0 - ISC
|
|
173
|
+
*
|
|
174
|
+
* This source code is licensed under the ISC license.
|
|
175
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
176
|
+
*/const Ne=s.createLucideIcon("Database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]);/**
|
|
177
|
+
* @license lucide-react v0.453.0 - ISC
|
|
178
|
+
*
|
|
179
|
+
* This source code is licensed under the ISC license.
|
|
180
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
181
|
+
*/const hn=s.createLucideIcon("DollarSign",[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]]);/**
|
|
182
|
+
* @license lucide-react v0.453.0 - ISC
|
|
183
|
+
*
|
|
184
|
+
* This source code is licensed under the ISC license.
|
|
185
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
186
|
+
*/const fs=s.createLucideIcon("Donut",[["path",{d:"M20.5 10a2.5 2.5 0 0 1-2.4-3H18a2.95 2.95 0 0 1-2.6-4.4 10 10 0 1 0 6.3 7.1c-.3.2-.8.3-1.2.3",key:"19sr3x"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
187
|
+
* @license lucide-react v0.453.0 - ISC
|
|
188
|
+
*
|
|
189
|
+
* This source code is licensed under the ISC license.
|
|
190
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
191
|
+
*/const Xs=s.createLucideIcon("Expand",[["path",{d:"m21 21-6-6m6 6v-4.8m0 4.8h-4.8",key:"1c15vz"}],["path",{d:"M3 16.2V21m0 0h4.8M3 21l6-6",key:"1fsnz2"}],["path",{d:"M21 7.8V3m0 0h-4.8M21 3l-6 6",key:"hawz9i"}],["path",{d:"M3 7.8V3m0 0h4.8M3 3l6 6",key:"u9ee12"}]]);/**
|
|
192
|
+
* @license lucide-react v0.453.0 - ISC
|
|
193
|
+
*
|
|
194
|
+
* This source code is licensed under the ISC license.
|
|
195
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
196
|
+
*/const xn=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"}]]);/**
|
|
197
|
+
* @license lucide-react v0.453.0 - ISC
|
|
198
|
+
*
|
|
199
|
+
* This source code is licensed under the ISC license.
|
|
200
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
201
|
+
*/const pn=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"}]]);/**
|
|
202
|
+
* @license lucide-react v0.453.0 - ISC
|
|
203
|
+
*
|
|
204
|
+
* This source code is licensed under the ISC license.
|
|
205
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
206
|
+
*/const fn=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"}]]);/**
|
|
207
|
+
* @license lucide-react v0.453.0 - ISC
|
|
208
|
+
*
|
|
209
|
+
* This source code is licensed under the ISC license.
|
|
210
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
211
|
+
*/const gn=s.createLucideIcon("FileText",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);/**
|
|
212
|
+
* @license lucide-react v0.453.0 - ISC
|
|
213
|
+
*
|
|
214
|
+
* This source code is licensed under the ISC license.
|
|
215
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
216
|
+
*/const jn=s.createLucideIcon("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
|
|
217
|
+
* @license lucide-react v0.453.0 - ISC
|
|
218
|
+
*
|
|
219
|
+
* This source code is licensed under the ISC license.
|
|
220
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
221
|
+
*/const gs=s.createLucideIcon("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
|
|
222
|
+
* @license lucide-react v0.453.0 - ISC
|
|
223
|
+
*
|
|
224
|
+
* This source code is licensed under the ISC license.
|
|
225
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
226
|
+
*/const yn=s.createLucideIcon("Fingerprint",[["path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4",key:"1nerag"}],["path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88",key:"o46ks0"}],["path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02",key:"ptglia"}],["path",{d:"M2 12a10 10 0 0 1 18-6",key:"ydlgp0"}],["path",{d:"M2 16h.01",key:"1gqxmh"}],["path",{d:"M21.8 16c.2-2 .131-5.354 0-6",key:"drycrb"}],["path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2",key:"1tidbn"}],["path",{d:"M8.65 22c.21-.66.45-1.32.57-2",key:"13wd9y"}],["path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2",key:"1fr1j5"}]]);/**
|
|
227
|
+
* @license lucide-react v0.453.0 - ISC
|
|
228
|
+
*
|
|
229
|
+
* This source code is licensed under the ISC license.
|
|
230
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
231
|
+
*/const bn=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
232
|
+
* @license lucide-react v0.453.0 - ISC
|
|
233
|
+
*
|
|
234
|
+
* This source code is licensed under the ISC license.
|
|
235
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
236
|
+
*/const vn=s.createLucideIcon("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/**
|
|
237
|
+
* @license lucide-react v0.453.0 - ISC
|
|
238
|
+
*
|
|
239
|
+
* This source code is licensed under the ISC license.
|
|
240
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
241
|
+
*/const Nn=s.createLucideIcon("Grid3x3",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"M15 3v18",key:"14nvp0"}]]);/**
|
|
242
|
+
* @license lucide-react v0.453.0 - ISC
|
|
243
|
+
*
|
|
244
|
+
* This source code is licensed under the ISC license.
|
|
245
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
246
|
+
*/const Cn=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"}]]);/**
|
|
247
|
+
* @license lucide-react v0.453.0 - ISC
|
|
248
|
+
*
|
|
249
|
+
* This source code is licensed under the ISC license.
|
|
250
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
251
|
+
*/const js=s.createLucideIcon("Hash",[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]]);/**
|
|
252
|
+
* @license lucide-react v0.453.0 - ISC
|
|
253
|
+
*
|
|
254
|
+
* This source code is licensed under the ISC license.
|
|
255
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
256
|
+
*/const Sn=s.createLucideIcon("House",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]]);/**
|
|
257
|
+
* @license lucide-react v0.453.0 - ISC
|
|
258
|
+
*
|
|
259
|
+
* This source code is licensed under the ISC license.
|
|
260
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
261
|
+
*/const wn=s.createLucideIcon("Layers",[["path",{d:"m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83Z",key:"8b97xw"}],["path",{d:"m22 17.65-9.17 4.16a2 2 0 0 1-1.66 0L2 17.65",key:"dd6zsq"}],["path",{d:"m22 12.65-9.17 4.16a2 2 0 0 1-1.66 0L2 12.65",key:"ep9fru"}]]);/**
|
|
262
|
+
* @license lucide-react v0.453.0 - ISC
|
|
263
|
+
*
|
|
264
|
+
* This source code is licensed under the ISC license.
|
|
265
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
266
|
+
*/const kn=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"}]]);/**
|
|
267
|
+
* @license lucide-react v0.453.0 - ISC
|
|
268
|
+
*
|
|
269
|
+
* This source code is licensed under the ISC license.
|
|
270
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
271
|
+
*/const En=s.createLucideIcon("Link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]);/**
|
|
272
|
+
* @license lucide-react v0.453.0 - ISC
|
|
273
|
+
*
|
|
274
|
+
* This source code is licensed under the ISC license.
|
|
275
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
276
|
+
*/const In=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"}]]);/**
|
|
277
|
+
* @license lucide-react v0.453.0 - ISC
|
|
278
|
+
*
|
|
279
|
+
* This source code is licensed under the ISC license.
|
|
280
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
281
|
+
*/const Tn=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"}]]);/**
|
|
282
|
+
* @license lucide-react v0.453.0 - ISC
|
|
283
|
+
*
|
|
284
|
+
* This source code is licensed under the ISC license.
|
|
285
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
286
|
+
*/const Dn=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"}]]);/**
|
|
287
|
+
* @license lucide-react v0.453.0 - ISC
|
|
288
|
+
*
|
|
289
|
+
* This source code is licensed under the ISC license.
|
|
290
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
291
|
+
*/const ce=s.createLucideIcon("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
292
|
+
* @license lucide-react v0.453.0 - ISC
|
|
293
|
+
*
|
|
294
|
+
* This source code is licensed under the ISC license.
|
|
295
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
296
|
+
*/const Mn=s.createLucideIcon("Logs",[["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M3 12h1",key:"lp3yf2"}],["path",{d:"M3 18h1",key:"1eiwyy"}],["path",{d:"M3 6h1",key:"rgxa97"}],["path",{d:"M8 12h1",key:"1con00"}],["path",{d:"M8 18h1",key:"13wk12"}],["path",{d:"M8 6h1",key:"tn6mkg"}]]);/**
|
|
297
|
+
* @license lucide-react v0.453.0 - ISC
|
|
298
|
+
*
|
|
299
|
+
* This source code is licensed under the ISC license.
|
|
300
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
301
|
+
*/const An=s.createLucideIcon("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);/**
|
|
302
|
+
* @license lucide-react v0.453.0 - ISC
|
|
303
|
+
*
|
|
304
|
+
* This source code is licensed under the ISC license.
|
|
305
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
306
|
+
*/const Ln=s.createLucideIcon("MapPin",[["path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0",key:"1r0f0z"}],["circle",{cx:"12",cy:"10",r:"3",key:"ilqhr7"}]]);/**
|
|
307
|
+
* @license lucide-react v0.453.0 - ISC
|
|
308
|
+
*
|
|
309
|
+
* This source code is licensed under the ISC license.
|
|
310
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
311
|
+
*/const ys=s.createLucideIcon("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]);/**
|
|
312
|
+
* @license lucide-react v0.453.0 - ISC
|
|
313
|
+
*
|
|
314
|
+
* This source code is licensed under the ISC license.
|
|
315
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
316
|
+
*/const Zs=s.createLucideIcon("MessageCircleMore",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}],["path",{d:"M8 12h.01",key:"czm47f"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M16 12h.01",key:"1l6xoz"}]]);/**
|
|
317
|
+
* @license lucide-react v0.453.0 - ISC
|
|
318
|
+
*
|
|
319
|
+
* This source code is licensed under the ISC license.
|
|
320
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
321
|
+
*/const On=s.createLucideIcon("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
|
|
322
|
+
* @license lucide-react v0.453.0 - ISC
|
|
323
|
+
*
|
|
324
|
+
* This source code is licensed under the ISC license.
|
|
325
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
326
|
+
*/const Rs=s.createLucideIcon("MoveHorizontal",[["path",{d:"m18 8 4 4-4 4",key:"1ak13k"}],["path",{d:"M2 12h20",key:"9i4pu4"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}]]);/**
|
|
327
|
+
* @license lucide-react v0.453.0 - ISC
|
|
328
|
+
*
|
|
329
|
+
* This source code is licensed under the ISC license.
|
|
330
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
331
|
+
*/const Ps=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"}]]);/**
|
|
332
|
+
* @license lucide-react v0.453.0 - ISC
|
|
333
|
+
*
|
|
334
|
+
* This source code is licensed under the ISC license.
|
|
335
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
336
|
+
*/const Fn=s.createLucideIcon("Network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]);/**
|
|
337
|
+
* @license lucide-react v0.453.0 - ISC
|
|
338
|
+
*
|
|
339
|
+
* This source code is licensed under the ISC license.
|
|
340
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
341
|
+
*/const zn=s.createLucideIcon("Plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M9 8V2",key:"14iosj"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z",key:"osxo6l"}]]);/**
|
|
342
|
+
* @license lucide-react v0.453.0 - ISC
|
|
343
|
+
*
|
|
344
|
+
* This source code is licensed under the ISC license.
|
|
345
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
346
|
+
*/const bs=s.createLucideIcon("Radar",[["path",{d:"M19.07 4.93A10 10 0 0 0 6.99 3.34",key:"z3du51"}],["path",{d:"M4 6h.01",key:"oypzma"}],["path",{d:"M2.29 9.62A10 10 0 1 0 21.31 8.35",key:"qzzz0"}],["path",{d:"M16.24 7.76A6 6 0 1 0 8.23 16.67",key:"1yjesh"}],["path",{d:"M12 18h.01",key:"mhygvu"}],["path",{d:"M17.99 11.66A6 6 0 0 1 15.77 16.67",key:"1u2y91"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"m13.41 10.59 5.66-5.66",key:"mhq4k0"}]]);/**
|
|
347
|
+
* @license lucide-react v0.453.0 - ISC
|
|
348
|
+
*
|
|
349
|
+
* This source code is licensed under the ISC license.
|
|
350
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
351
|
+
*/const et=s.createLucideIcon("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
352
|
+
* @license lucide-react v0.453.0 - ISC
|
|
353
|
+
*
|
|
354
|
+
* This source code is licensed under the ISC license.
|
|
355
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
356
|
+
*/const Bn=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"}]]);/**
|
|
357
|
+
* @license lucide-react v0.453.0 - ISC
|
|
358
|
+
*
|
|
359
|
+
* This source code is licensed under the ISC license.
|
|
360
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
361
|
+
*/const Rn=s.createLucideIcon("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);/**
|
|
362
|
+
* @license lucide-react v0.453.0 - ISC
|
|
363
|
+
*
|
|
364
|
+
* This source code is licensed under the ISC license.
|
|
365
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
366
|
+
*/const vs=s.createLucideIcon("Shapes",[["path",{d:"M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z",key:"1bo67w"}],["rect",{x:"3",y:"14",width:"7",height:"7",rx:"1",key:"1bkyp8"}],["circle",{cx:"17.5",cy:"17.5",r:"3.5",key:"w3z12y"}]]);/**
|
|
367
|
+
* @license lucide-react v0.453.0 - ISC
|
|
368
|
+
*
|
|
369
|
+
* This source code is licensed under the ISC license.
|
|
370
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
371
|
+
*/const Pn=s.createLucideIcon("Shrink",[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]]);/**
|
|
372
|
+
* @license lucide-react v0.453.0 - ISC
|
|
373
|
+
*
|
|
374
|
+
* This source code is licensed under the ISC license.
|
|
375
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
376
|
+
*/const st=s.createLucideIcon("Sigma",[["path",{d:"M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2",key:"wuwx1p"}]]);/**
|
|
377
|
+
* @license lucide-react v0.453.0 - ISC
|
|
378
|
+
*
|
|
379
|
+
* This source code is licensed under the ISC license.
|
|
380
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
381
|
+
*/const Vn=s.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
382
|
+
* @license lucide-react v0.453.0 - ISC
|
|
383
|
+
*
|
|
384
|
+
* This source code is licensed under the ISC license.
|
|
385
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
386
|
+
*/const Je=s.createLucideIcon("Table2",[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]]);/**
|
|
387
|
+
* @license lucide-react v0.453.0 - ISC
|
|
388
|
+
*
|
|
389
|
+
* This source code is licensed under the ISC license.
|
|
390
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
391
|
+
*/const Vs=s.createLucideIcon("Table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]);/**
|
|
392
|
+
* @license lucide-react v0.453.0 - ISC
|
|
393
|
+
*
|
|
394
|
+
* This source code is licensed under the ISC license.
|
|
395
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
396
|
+
*/const tt=s.createLucideIcon("Tag",[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]]);/**
|
|
397
|
+
* @license lucide-react v0.453.0 - ISC
|
|
398
|
+
*
|
|
399
|
+
* This source code is licensed under the ISC license.
|
|
400
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
401
|
+
*/const qn=s.createLucideIcon("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);/**
|
|
402
|
+
* @license lucide-react v0.453.0 - ISC
|
|
403
|
+
*
|
|
404
|
+
* This source code is licensed under the ISC license.
|
|
405
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
406
|
+
*/const nt=s.createLucideIcon("ToggleLeft",[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"6",ry:"6",key:"f2vt7d"}],["circle",{cx:"8",cy:"12",r:"2",key:"1nvbw3"}]]);/**
|
|
407
|
+
* @license lucide-react v0.453.0 - ISC
|
|
408
|
+
*
|
|
409
|
+
* This source code is licensed under the ISC license.
|
|
410
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
411
|
+
*/const Ns=s.createLucideIcon("Tornado",[["path",{d:"M21 4H3",key:"1hwok0"}],["path",{d:"M18 8H6",key:"41n648"}],["path",{d:"M19 12H9",key:"1g4lpz"}],["path",{d:"M16 16h-6",key:"1j5d54"}],["path",{d:"M11 20H9",key:"39obr8"}]]);/**
|
|
412
|
+
* @license lucide-react v0.453.0 - ISC
|
|
413
|
+
*
|
|
414
|
+
* This source code is licensed under the ISC license.
|
|
415
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
416
|
+
*/const at=s.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);/**
|
|
417
|
+
* @license lucide-react v0.453.0 - ISC
|
|
418
|
+
*
|
|
419
|
+
* This source code is licensed under the ISC license.
|
|
420
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
421
|
+
*/const _n=s.createLucideIcon("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);function Cs(t){var a;return{...t,sheets:(a=t==null?void 0:t.sheets)==null?void 0:a.map(n=>{var r;return{...n,frames:(r=n.frames)==null?void 0:r.map(i=>{var o;return{...i,cards:(o=i.cards)==null?void 0:o.map(c=>rt(c))}})}})}}function rt(t){return{...t,customCfg:$n(t.customCfg),data:[]}}function $n(t){var a,n;return t?{...t,data:{...t==null?void 0:t.data,labels:[],datasets:(n=(a=t==null?void 0:t.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Gn(t,a,n,r){if(!r)return null;const i=JSON.stringify(a);return await s.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:t,template:i,filterValues:n,operation:"create"})}async function os(t,a){if(!a)return null;const{id:n,template:r,filterValues:i,isDefault:o,shared:c}=t;return await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:i,isDefault:o,shared:c,operation:"update"})}async function Hn(t,a){return a?await s.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:t}):null}function Jn(){const[t,a]=M.useState(""),[n,r]=M.useState(!1),i=s.useDashboardStore(f=>f.lenses),{setLenses:o,setSelectedLensId:c}=s.useDashboardActions(),[d,l]=M.useState(!1),[m,u]=M.useState(!1),h=s.useDashboardStore(f=>f.dashboard),j=s.useDashboardStore(f=>f.filterValues),{authToken:p}=s.useSemaphorContext();async function g(){l(!0);const f=Cs(h),S=await Gn(t,f,j,p==null?void 0:p.accessToken);S&&(o([...i||[],S]),c(S.id),u(!1)),l(!1)}return e.jsxs(s.Dialog,{open:m,onOpenChange:u,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:f=>{a(f.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),n&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:d,children:d?"Creating...":"Add"})})]})]})}function Un(){const[t,a]=M.useState(!1),n=s.useDashboardStore(u=>u.lenses),r=s.useDashboardStore(u=>u.selectedLensId),{setLenses:i,setSelectedLensId:o}=s.useDashboardActions(),{authToken:c}=s.useSemaphorContext();async function d(u){o(u)}async function l(u){if(await Hn(u,c==null?void 0:c.accessToken)){const j=n==null?void 0:n.filter(p=>p.id!==u);i(j||[]),o("original")}}async function m(u){const h=n==null?void 0:n.map(g=>g.id===u.id?{...g,isDefault:!u.isDefault}:{...g,isDefault:!1});i(h||[]);const j={...u,isDefault:!u.isDefault};await os(j,c==null?void 0:c.accessToken);const p=n==null?void 0:n.find(g=>g.isDefault);if(p&&p.id!==u.id){const g={...p,isDefault:!1};await os(g,c==null?void 0:c.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:a,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(bn,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:d,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(u=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:u.id,children:[e.jsx("p",{children:u.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(Sn,{onClick:h=>{h.preventDefault(),m(u)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!u.isDefault,"text-green-500":u.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:h=>{h.preventDefault(),l(u.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},u.id))]})]})]})}function it(){var o;const t=s.useDashboardStore.getState().authToken,a=s.useDashboardStore.getState().theme,n=s.useDashboardStore.getState().filterValues,r=(o=s.useDashboardStore.getState().dashboard)==null?void 0:o.title,i=s.useDashboardStore.getState().selectedSheetId;return{authToken:t,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:i||""}}async function ot(){const t=s.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:i,selectedSheetId:o}=it();if(t)return;const c=new URLSearchParams;c.set("token",(a==null?void 0:a.accessToken)||""),c.set("theme",n),c.set("filterValues",JSON.stringify(r)),c.set("selectedSheetId",o||"");const d=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(c.toString())}`;s.useDashboardStore.setState({isDownloadingPdf:!0});const u=(await(await fetch(d,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,h=document.createElement("a");h.href=u;const j=`${i}-${new Date().toISOString()}.pdf`;h.download=j,h.click(),s.useDashboardStore.setState({isDownloadingPdf:!1})}function Yn({iconClassName:t}){const{authToken:a}=s.useSemaphorContext();s.useDashboardStore(i=>{var o;return(o=i.dashboard)==null?void 0:o.title}),s.useDashboardStore(i=>i.theme),s.useDashboardStore(i=>i.filterValues);const n=s.useDashboardStore(i=>i.isDownloadingPdf);async function r(){await ot()}return e.jsx(s.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(ce,{className:s.cn("size-3.5 animate-spin",t)}):e.jsx(s.Download,{className:s.cn("size-4",t)})})}function oe({defaultValue:t,label:a,options:n,value:r,onValueChange:i,className:o,icon:c,showPlaceholderLabel:d=!0}){return e.jsxs(s.Select,{defaultValue:t,value:r,onValueChange:i,children:[e.jsx(s.SelectTrigger,{className:s.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("span",{children:c}),d&&e.jsx(s.SelectValue,{placeholder:a})]})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:a}),n.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))]})})]})}const qs=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function lt({triggerButtonClassName:t}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:i,error:o,isDeleting:c}=Kn(),[d,l]=M.useState(""),[m,u]=M.useState(qs[0].value),[h,j]=M.useState("06:00"),[p,g]=M.useState("");return e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Schedule Dashboard",className:s.cn("h-7 p-2",t),children:e.jsx(ln,{className:"size-4"})})}),e.jsx(s.PopoverContent,{align:"end",className:"w-80",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Schedule Subscription"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Subscribe to receive dashboard via email"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"email",children:"Email"}),e.jsx(s.Input,{id:"email",value:d,onChange:f=>l(f.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(s.Input,{id:"subject",placeholder:"Monthly Sales Report",value:p,onChange:f=>{g(f.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(oe,{className:"col-span-2 h-8",label:"Select Frequency",options:qs,value:m,onValueChange:f=>u(f)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"time",children:"Time"}),e.jsx(s.Input,{id:"time",type:"time",value:h,onChange:f=>j(f.target.value),className:`col-span-2 h-8 ${s.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(s.Button,{onClick:async()=>{await n({email:d,frequency:m,time:h,subject:p}),j("00:00"),l(""),g("")},className:"h-8 p-2",disabled:i==="loading"||!d,children:[i==="loading"&&e.jsx(ce,{className:"mr-2 size-4 animate-spin"}),i==="success"&&e.jsx(s.Check,{className:"mr-2 size-4"}),i==="error"&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{children:e.jsx(Ws,{className:"mr-2 size-4 text-destructive"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:o})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Subscriptions"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active email subscriptions"})]}),s.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(f=>e.jsxs("div",{className:"group grid grid-cols-5 gap-3",children:[e.jsx("div",{className:"col-span-3 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"boder-border rounded-md border bg-muted px-2 py-1",children:[s.titleCase(f.frequency)," "]}),e.jsx(s.Label,{children:f.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(_s,{tooltip:`Next Run: ${new Date(f.nextRun).toLocaleString()} ${f.timezone}`,children:e.jsx(on,{className:"size-3.5"})}),e.jsx(_s,{tooltip:`${f.endUserEmail}`,children:e.jsx(An,{className:"size-3.5"})}),c===f.id?e.jsx(ce,{className:"size-3.5 animate-spin"}):e.jsx(s.Trash2,{onClick:()=>r(f.id),className:"size-3.5 cursor-pointer"})]})]},f.id))})]})]})]})})]})})}const _s=({children:t,tooltip:a})=>e.jsx(s.TooltipProvider,{delayDuration:0,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:t}),e.jsx(s.TooltipContent,{children:a})]})});function Kn(){const[t,a]=M.useState("idle"),[n,r]=M.useState(""),[i,o]=M.useState(null),c=s.useDashboardStore(D=>D.authToken),d=s.useDashboardStore(D=>D.dashboard.id),l=s.useDashboardStore(D=>D.dashboard.title),{endUserId:m}=s.getTenantAndEndUserId((c==null?void 0:c.accessToken)||""),u="https://semaphor.cloud/api/v1/subscriptions/get",h={dashboardId:d,endUserId:m},{data:j,isLoading:p,isError:g,isFetching:f,refetch:S}=s.useQuery({queryKey:["subscriptions",d,m],queryFn:()=>s.getRequest(u,(c==null?void 0:c.accessToken)||"",h),enabled:!!(c!=null&&c.accessToken)&&!!d&&!!m});async function x({email:D,subject:E,frequency:v,time:b}){const{authToken:w,...y}=it(),I=Intl.DateTimeFormat().resolvedOptions().timeZone,T={email:D,frequency:v,time:b,timezone:I,endUserId:m,endUserEmail:D,subject:E||l||"Scheduled Dashboard",dashboardId:d,dashboardParams:y};a("loading");const C="https://semaphor.cloud/api/v1/subscriptions/create";try{const B=await s.postRequestRegular(C,(w==null?void 0:w.accessToken)||"",{...T});a("success"),r(""),S(),setTimeout(()=>{a("idle")},2e3)}catch(B){console.error(B),a("error"),r(B.message)}}async function N(D){const E="https://semaphor.cloud/api/v1/subscriptions/delete";o(D);try{await s.postRequestRegular(E,(c==null?void 0:c.accessToken)||"",{id:D}),S(),setTimeout(()=>{o(null)},2e3)}catch(v){console.error(v),o(null),a("error"),r(v.message)}}return{data:j,isLoading:p,isFetching:f,isError:g,isDeleting:i,refetch:S,handleScheduleSubscription:x,handleDeleteSubscription:N,status:t,error:n}}function Qn(){const{authToken:t}=s.useSemaphorContext();s.useDashboardStore(T=>T.theme);const a=s.useDashboardStore(T=>T.lenses),n=s.useDashboardStore(T=>T.selectedLensId),r=a==null?void 0:a.find(T=>T.id===n),i=s.useDashboardStore(T=>T.dashboard);s.useDashboardStore(T=>T.selectedSheetId);const o=s.useDashboardStore(T=>T.isDashboardEditing),c=s.useEditorStore(T=>T.selectedConnectionId),[d,l]=M.useState(!1),m=s.useDashboardStore(T=>T.filterValues),u=s.useDashboardStore(T=>T.isVisualEditing),h=s.useDashboardStore(T=>T.showFilters);s.useDashboardStore(T=>T.showDashboardJSON);const j=s.useDashboardStore(T=>T.onSaveFunction),p=s.useDashboardStore(T=>T.actions.setShowFilters),{addFrame:g,setSelectedFrameId:f}=s.useDashboardStore(T=>T.actions),{getSelectedSheet:S,setIsDashboardEditing:x,setShowDashboardJSON:N}=s.useDashboardStore(T=>T.actions),D=S(),{tenantId:E,endUserId:v}=M.useMemo(()=>s.getTenantAndEndUserId(t==null?void 0:t.accessToken),[t==null?void 0:t.accessToken]),b=M.useMemo(()=>E||v,[E,v]),w=()=>{if(!o||!D)return;const T={connectionId:c,id:s.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},C={id:s.v4(),cards:[T],activeCardId:T.id};g(D.id,C),f(C.id)},y=()=>{x(!0)};async function I(){if(l(!0),!n||!r)return;const T=Cs(i),C=JSON.stringify(T),B={...r,template:C,filterValues:m};await os(B,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),j==null||j(T),l(!1)}return u?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(s.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!u&&e.jsx(Yn,{}),!u&&e.jsx(lt,{}),o&&!u&&b&&e.jsx(Jn,{}),!u&&b&&e.jsx(Un,{}),o&&!u&&e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!o,onClick:w,children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!o&&e.jsx(s.Button,{variant:"ghost",className:"h-7 p-2",onClick:y,size:"sm",children:e.jsx(s.Pencil,{className:"h-4 w-4"})}),o&&!u&&e.jsx(s.IconButton,{className:"h-7 p-2",onClick:()=>{x(!1),N(!1)},children:e.jsx(s.Cross2Icon,{className:"h-4 w-4"})}),o&&!u&&b&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",disabled:d,onClick:I,size:"sm",children:e.jsx(Rn,{className:"h-4 w-4"})}),!h&&!u&&o&&e.jsx(s.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>p(!0),size:"sm",children:e.jsx(gs,{className:"h-4 w-4"})}),!u&&o&&!1,!u&&!1]})]})}function Wn({name:t,items:a,value:n,onChange:r,isLoading:i,isError:o,refetch:c,className:d,icon:l,showNone:m=!1}){const u=ae.useRef(null),[h,j]=ae.useState(!1),[p,g]=ae.useState("100%"),f=m?[...a||[],{id:"none",name:"None"}]:a;ae.useLayoutEffect(()=>{u.current&&g(u.current.offsetWidth)},[]);function S(){var N;return i?"Loading...":o?"Error":n?(N=a==null?void 0:a.find(D=>D.id===n))==null?void 0:N.name:`Select ${t}`}function x(N,D){r(D),j(!1)}return e.jsxs(s.Popover,{open:h,onOpenChange:j,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{ref:u,variant:"outline",role:"combobox","aria-expanded":h,className:s.cn("flex h-9 w-full justify-between",d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l&&e.jsx("div",{className:"mr-2",children:l}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:S()})]}),e.jsx(s.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-full p-0",style:{minWidth:p},children:e.jsxs(s.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(s.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(s.IconButton,{className:"h-7",onClick:c,children:e.jsx(et,{className:s.cn("size-3.5 opacity-50",i&&"animate-spin")})})]}),e.jsxs(s.CommandList,{children:[e.jsxs(s.CommandEmpty,{children:["No ",t==null?void 0:t.toLowerCase()," found."]}),e.jsx(s.CommandGroup,{children:f==null?void 0:f.map(N=>e.jsx(s.CommandItem,{className:"overflow-x-auto",value:N.name,onSelect:D=>x(D,N.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Check,{className:s.cn("size-4",n===N.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:N.name,children:N.name})]})},N.id))})]})]})})]})}function ye({title:t,items:a,value:n,isLoading:r,isError:i,refetch:o,onChange:c,showNone:d=!1,className:l,disabled:m=!1,type:u="combobox"}){const h=r?"Loading...":i?"Error":n;function j(){if(t==="Connection")return e.jsx(zn,{className:"size-4"});if(t==="Database")return e.jsx(Ne,{className:"size-4"});if(t==="Schema")return e.jsx(Fn,{className:"size-4"});if(t==="Table")return e.jsx(Je,{className:"size-4"});if(t==="Model")return e.jsx(en,{className:"size-4"})}function p(){return e.jsxs(s.Select,{disabled:m,value:h,onValueChange:c,children:[e.jsx(s.SelectTrigger,{className:s.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",l),children:e.jsx(s.SelectValue,{placeholder:r?"Loading...":i?"Error":`Select ${t}`})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[r?e.jsx(s.SelectLabel,{children:"Loading..."}):e.jsxs(s.SelectLabel,{className:"flex items-center justify-between gap-2",children:[t,e.jsx(et,{className:s.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:o})]}),e.jsxs(e.Fragment,{children:[d&&e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((f,S)=>e.jsx(s.SelectItem,{value:f.id,children:f.name},S))]}),(r||i)&&e.jsx(s.SelectItem,{value:h,children:h})]})})]})}function g(){return e.jsx(Wn,{icon:j(),items:a,value:h,onChange:c||(()=>{}),isLoading:r,isError:i,refetch:o,name:t,showNone:d})}return e.jsx(s.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:u==="select"?p():g()})})}function Xn({column:t}){const[a,n]=M.useState(!1),r=s.useEditorStore(f=>f.selectedTableName),i=s.useEditorStore(f=>f.selectedSchemaName),o=s.useEditorStore(f=>f.selectedDatabaseName),c=s.useEditorStore(f=>f.selectedDatamodelId),d=s.useEditorStore(f=>f.sqlGen),{modelItems:l,connectionType:m}=s.useEditorAside(),u=s.useEditorStore(f=>f.actions.setSqlGen),h=s.useEditorStore(f=>f.actions.setCardSql),j=s.useEditorStore(f=>f.actions.setRunSql);function p(f,S){var E;const x=s.createSqlGenConfig(f,d,S),N=(E=l==null?void 0:l.find(v=>v.id===c))==null?void 0:E.name;u(x);const D=s.getSql(x,s.fmt(i||""),s.fmt(r),N||"",m,o||"");D&&(h(D),j(!0)),n(!1)}function g(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>p(t,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>p(t,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>p(t,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>p(t,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>p(t,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(s.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(s.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:g()})]})}function Ss({column:t}){return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger$1,{className:"shrink-0",asChild:!0,children:s.isTextDataType(t.data_type)?e.jsx(s.TextIcon,{className:"size-3 text-muted-foreground"}):s.isNumberDataType(t.data_type)?e.jsx(js,{className:"size-3 text-muted-foreground"}):s.isDateDataType(t.data_type)?e.jsx(s.Calendar,{className:"size-3 text-muted-foreground"}):s.isBooleanDataType(t.data_type)?e.jsx(nt,{className:"size-3 text-muted-foreground"}):t.data_type.startsWith("json")?e.jsx(sn,{className:"size-3 text-muted-foreground"}):e.jsx(s.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:t.data_type})})]})}function Ye({column:t,className:a}){return e.jsxs("div",{className:s.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(Ss,{column:t}),e.jsx("span",{children:t.column_name})]})}function Zn({id:t,children:a,type:n="column"}){const{attributes:r,listeners:i,setNodeRef:o,transform:c}=s.useDraggable({id:t,data:{type:n}}),d=c?{translate:s.CSS.Translate.toString(c),transform:s.CSS.Transform.toString(c)}:void 0;return e.jsx("div",{ref:o,style:d,...i,...r,children:a})}function ea({onClick:t,column:a}){const n=s.useDndStore(u=>u.activeId),r=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.groupByColumns}),i=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.metricColumns}),o=s.useEditorStore(u=>{var h;return(h=u.card.queryConfig)==null?void 0:h.filterColumns});function c(u){return d(u)||l(u)||m(u)}function d(u){return r==null?void 0:r.some(h=>h.name===u.column_name)}function l(u){return i==null?void 0:i.some(h=>h.name===u.column_name)}function m(u){return o==null?void 0:o.some(h=>h.name===u.column_name)}return e.jsxs("div",{onClick:()=>t(a),className:s.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":c(a)}),children:[n===a.column_name&&e.jsx(s.DragOverlay,{children:e.jsx(Ye,{column:a,className:"rounded-md border-2 border-dashed border-muted-foreground bg-muted shadow-md"})}),n===a.column_name&&e.jsx("div",{className:"absolute inset-0",children:n===a.column_name&&e.jsx(Ye,{column:a})}),e.jsx(Zn,{id:a.column_name,type:"column",children:e.jsx(Ye,{column:a})})]})}const Ke={id:"__placeholder__",role:"groupby",type:"string"},Qe={id:"__placeholder__",role:"groupby",type:"string"},We={id:"__placeholder__",role:"metric",type:"number"},Xe={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},ct={id:"__placeholder__"},xe="droppable-group-by",pe="droppable-metrics",fe="droppable-pivot-by",Be="sortable-group-by",ls="sortable-metrics",Re="sortable-pivot-by",cs="droppable-filters",ds="sortable-filters",ws="sortable-order-by";function sa(){const t=s.useDndStore(O=>O.insertIndex),a=s.useEditorStore(O=>{var k;return((k=O.card.queryConfig)==null?void 0:k.groupByColumns)||[]}),n=s.useEditorStore(O=>{var k;return((k=O.card.queryConfig)==null?void 0:k.metricColumns)||[]}),r=s.useEditorStore(O=>{var k;return((k=O.card.queryConfig)==null?void 0:k.filterColumns)||[]}),i=s.useEditorStore(O=>{var k;return((k=O.card.queryConfig)==null?void 0:k.orderBy)||[]}),o=s.useEditorStore(O=>{var k;return((k=O.card.queryConfig)==null?void 0:k.pivotColumns)||[]}),{setInsertIndex:c,setActiveId:d,setPreviewGroupByColumns:l,setPreviewMetricColumns:m,setPreviewFilterColumns:u,setPreviewPivotColumns:h}=s.useDndActions(),{setGroupByColumns:j,setMetricColumns:p,setFilterColumns:g,setOrderByColumns:f,setPivotByColumns:S}=s.useEditorActions(),{columns:x}=s.useDataColumns(),{formattedTableName:N}=s.useEditorAside(),D=s.useSensors(s.useSensor(s.MouseSensor,{activationConstraint:{distance:1}})),E=O=>{var R;const{active:k,over:A}=O;if(((R=k.data.current)==null?void 0:R.type)==="column"&&A){const P=A.id,$=x.find(F=>F.column_name===k.id);if(!$)return;const Y=s.isNumberDataType($.data_type),V=s.isTextDataType($.data_type),L=s.isDateDataType($.data_type);if(V||L){if(a.some(_=>_.id===P)){const _=a.findIndex(G=>G.id===P);c(_);const J=a.filter(G=>G.id!==Ke.id);J.splice(_,0,Ke),l(J)}else if(A.id===xe){c(a.length);const _=[...a,Ke];l(_),m(n),u(r)}}if(V||L){if(o.some(_=>_.id===P)){const _=o.findIndex(G=>G.id===P);c(_);const J=o.filter(G=>G.id!==Qe.id);J.splice(_,0,Qe),h(J)}else if(A.id===fe){c(o.length);const _=[...o,Qe];h(_),l(a),m(n),u(r)}}if(Y||V){if(n.some(_=>_.id===P)){console.log("isOverMetricSortable",P);const _=n.findIndex(G=>G.id===P);c(_);const J=n.filter(G=>G.id!==We.id);J.splice(_,0,We),m(J)}else if(A.id===pe){c(n.length);const _=[...n,We];m(_),u(r),l(a),h(o)}}if(b($)){if(r.some(_=>_.id===P)){const _=r.findIndex(G=>G.id===P);c(_);const J=r.filter(G=>G.id!==Xe.id);J.splice(_,0,Xe),u(J)}else if(A.id===cs){c(r.length);const _=[...r,Xe];u(_),m(n),l(a),h(o)}}}else l(a),m(n),u(r),h(o)};function v(O){d(O.active.id),c(null),l(a),m(n),u(r),h(o)}function b(O){return!r.some(k=>k.name===O.column_name)}function w(O,k="SUM"){const{column_name:A,data_type:R}=O,P=[...n],$=t!==null?t:n.length,Y={...O,id:le(A),name:A,label:ke(A,k),type:R,role:"metric",aggregate:k};P.splice($,0,Y),p(P)}function y(O){const k=s.isTextDataType(O.data_type);s.isDateDataType(O.data_type);const A=[...o],R=t!==null?t:o.length;let P;k?P={...O,id:le(O.column_name),name:O.column_name,type:O.data_type,role:"groupby"}:P={...O,id:le(O.column_name),name:O.column_name,type:O.data_type,role:"groupby",label:Ce(O.column_name,"month"),granularity:"month"},A.splice(R,0,P),S(A)}function I(O){const k=s.isTextDataType(O.data_type);s.isDateDataType(O.data_type);const A=[...a],R=t!==null?t:a.length;let P;k?P={...O,id:le(O.column_name),name:O.column_name,type:O.data_type,role:"groupby"}:P={...O,id:le(O.column_name),name:O.column_name,type:O.data_type,role:"groupby",label:Ce(O.column_name,"month"),granularity:"month"},A.splice(R,0,P),j(A)}function T(O){const k=[...r],A=t!==null?t:r.length,R={...O,id:le(O.column_name),name:O.column_name,type:O.data_type,sql:s.getDefaultFilterSql(O.data_type,N,s.fmt(O.column_name)),role:"filter"};k.splice(A,0,R),g(k)}function C(O){var P,$,Y,V,L,F,_,J;const{active:k,over:A}=O,R=k.data.current;if((R==null?void 0:R.type)==="column"&&A){const G=x.find(q=>q.column_name===k.id);if(!G)return;const Q=s.isNumberDataType(G.data_type),H=s.isTextDataType(G.data_type),U=s.isDateDataType(G.data_type);(H||U)&&(A.id===xe||((P=A.data.current)==null?void 0:P.type)===Be)&&I(G),(H||U)&&(A.id===fe||(($=A.data.current)==null?void 0:$.type)===Re)?y(G):(Q||H)&&(A.id===pe||((Y=A.data.current)==null?void 0:Y.type)===ls)?(Q&&w(G),H&&w(G,"COUNT")):b(G)&&(A.id===cs||((V=A.data.current)==null?void 0:V.type)===ds)&&T(G)}if(A&&((L=A.data.current)==null?void 0:L.type)===Be&&a.some(G=>G.id===k.id)){const G=a.findIndex(H=>H.id===k.id),Q=a.findIndex(H=>H.id===A.id);if(G!==-1&&Q!==-1&&G!==Q){const H=[...a],[U]=H.splice(G,1);H.splice(Q,0,U),j(H)}}if(A&&((F=A.data.current)==null?void 0:F.type)===Re&&o.some(G=>G.id===k.id)){const G=o.findIndex(H=>H.id===k.id),Q=o.findIndex(H=>H.id===A.id);if(G!==-1&&Q!==-1&&G!==Q){const H=[...o],[U]=H.splice(G,1);H.splice(Q,0,U),S(H)}}if(A&&((_=A.data.current)==null?void 0:_.type)===ls&&n.some(G=>G.id===k.id)){const G=n.findIndex(H=>H.id===k.id),Q=n.findIndex(H=>H.id===A.id);if(G!==-1&&Q!==-1&&G!==Q){const H=[...n],[U]=H.splice(G,1);H.splice(Q,0,U),p(H)}}if(A&&((J=A.data.current)==null?void 0:J.type)===ds&&r.some(G=>G.id===k.id)){const G=r.findIndex(H=>H.id===k.id),Q=r.findIndex(H=>H.id===A.id);if(G!==-1&&Q!==-1&&G!==Q){const H=[...r],[U]=H.splice(G,1);H.splice(Q,0,U),g(H)}}B(O),d(null),c(null),l(a),m(n),u(r),h(o)}function B(O){const{active:k,over:A}=O,R=k.data.current;if((R==null?void 0:R.type)===ws&&A){const P=i.findIndex(Y=>we(Y.columnId)===k.id),$=i.findIndex(Y=>we(Y.columnId)===A.id);if(P!==-1&&$!==-1&&P!==$){const Y=[...i],[V]=Y.splice(P,1);Y.splice($,0,V),f(Y)}}}function z(){d(null),c(null),l(a),m(n),u(r)}return{handleDragOver:E,handleDragEnd:C,handleDragStart:v,handleDragCancel:z,sensors:D}}function le(t){return`${t}-${s.v4()}`}function ke(t,a){const n=s.toTitleCase(t.replace(/_/g," "));switch(a){case"SUM":return`Sum of ${n}`;case"COUNT":return`Count of ${n}`;case"DISTINCT":return`Unique ${n}`;case"AVG":return`Average of ${n}`;case"MIN":return`Min of ${n}`;case"MAX":return`Max of ${n}`;default:return n}}function we(t){return`${ws}-${t}`}function Ce(t,a){const n=s.toTitleCase(t.replace(/_/g," "));switch(a){case"day":return`Date of ${n}`;case"week":return`Week of ${n}`;case"month":return`Month of ${n}`;case"year":return`Year of ${n}`;default:return n}}function ta({schemaName:t,tableName:a,columns:n,status:r}){const i=s.useEditorStore(k=>k.sqlGen),o=s.useEditorStore(k=>k.isDevMode),c=s.useEditorStore(k=>k.selectedConnectionId),d=s.useEditorStore(k=>{var A,R;return(R=(A=k.card)==null?void 0:A.queryConfig)==null?void 0:R.metricColumns});s.useEditorStore(k=>{var A,R;return(R=(A=k.card)==null?void 0:A.queryConfig)==null?void 0:R.groupByColumns});const l=s.useEditorStore(k=>k.selectedDatabaseName),m=s.useEditorStore(k=>k.selectedSchemaName),u=s.useEditorStore(k=>k.selectedTableName),h=s.useEditorStore(k=>k.selectedDatamodelId),j=s.useDashboardStore(k=>k.dashboard.aiScopeTables),{addToAIScope:p,removeFromAIScope:g}=s.useDashboardActions(),{addColumnToMetricColumns:f,addColumnToGroupBy:S,setCardSql:x,setRunSql:N,setSqlGen:D,setIsShowingVisual:E}=s.useEditorActions(),{connectionType:v,modelItems:b,selectedDatamodelName:w}=s.useEditorAside();function y(k){var A;if(o){const R=s.createSqlGenConfig(k,i);D(R);const P=(A=b==null?void 0:b.find(Y=>Y.id===h))==null?void 0:A.name,$=s.getSql(R,s.fmt(t),s.fmt(a),P||"",v,l||"");$&&(x($),N(!0))}if(!o){if(s.isTextDataType(k.data_type))if(d&&d.length>0){const R={...k,role:"groupby",id:le(k.column_name),name:k.column_name,type:k.data_type};S(R)}else{const R={...k,role:"metric",id:le(k.column_name),name:k.column_name,label:ke(k.column_name,"COUNT"),type:k.data_type,aggregate:"COUNT"};f(R)}if(s.isDateDataType(k.data_type)){const R={...k,role:"groupby",id:le(k.column_name),name:k.column_name,type:k.data_type,label:Ce(k.column_name,"month"),granularity:"month"};S(R)}if(s.isNumberDataType(k.data_type)){const R={...k,role:"metric",id:le(k.column_name),name:k.column_name,label:ke(k.column_name,"SUM"),type:k.data_type,aggregate:"SUM"};f(R)}}}function I(k){k===!0&&(u||w)&&c?(p({connectionId:c,connectionType:v==="S3"||v==="API"?"DuckDb":v,databaseName:l||"",schemaName:m||"",tableName:u||"",datamodelName:s.resolveDatamodelName(w),datamodelId:h||""}),s.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(g({connectionId:c||"",connectionType:v||"",tableName:u||"",datamodelName:s.resolveDatamodelName(w),datamodelId:h||"",databaseName:l||"",schemaName:m||""}),s.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function T(){const k=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:w,connectionType:v,databaseName:l||""});E(!1);const A=v==="MSSQL"?`SELECT top 10 * FROM ${k}`:`SELECT * FROM ${k} LIMIT 10`;x(A),N(!0)}function C(){const k=s.getFormattedTableNameForQuery({schemaName:t,tableName:a,modelName:w,connectionType:v,databaseName:l||""});x(`SELECT COUNT(*) as count FROM ${k}`),N(!0)}function B(){return(j==null?void 0:j.find(k=>k.connectionId===c&&(k.tableName===u||k.datamodelName===w)))!==void 0}function z(k){return o?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>y(k),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ss,{column:k}),e.jsx("span",{children:k.column_name})]}),e.jsx("div",{onClick:A=>A.stopPropagation(),className:"flex items-center justify-end",children:s.isNumberDataType(k.data_type)&&e.jsx(Xn,{column:k})})]}):e.jsx(ea,{onClick:y,column:k})}function O(){return e.jsxs(e.Fragment,{children:[e.jsxs(s.Toggle,{title:`${B()?"Remove from":"Add to"} Assistant Scope`,pressed:B(),onPressedChange:I,variant:"outline",className:s.cn("h-9 px-2",{}),children:[e.jsx(s.Plus,{className:s.cn("mr-1 size-4",{"text-green-400":B(),"text-muted-foreground":!B()})}),"AI"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:T,size:"sm",variant:"secondary",className:"flex",children:[r!=="Success"?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(Mn,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(s.Button,{disabled:r!=="Success",onClick:C,size:"sm",variant:"secondary",className:"w-full",children:[r!=="Success"?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin text-foreground/50"}):e.jsx(st,{className:"mr-2 size-4"}),"Count"]})]})}return r!=="Success"?e.jsx("div",{className:"flex grow flex-col justify-start gap-2 px-6",children:Array.from({length:3}).map((k,A)=>e.jsx(s.Skeleton,{className:"h-7 w-full"},A))}):e.jsxs("div",{className:"flex grow flex-col space-y-4 px-4",children:[o&&e.jsx("div",{className:"mx-2 flex items-center justify-center gap-2",children:O()}),e.jsxs(s.CustomScrollArea,{className:"flex-1 basis-0 overflow-y-auto px-2 py-0",children:[e.jsx("div",{className:"flex flex-col gap-1",children:n==null?void 0:n.map(k=>e.jsx("div",{className:s.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:z(k)},k.column_name))}),e.jsx(s.ScrollBar,{orientation:"vertical"}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function dt({ColumnsComponent:t,type:a}){var Fs;const n=s.useEditorStore(X=>X.card),r=s.useEditorStore(X=>X.selectedConnectionId),i=s.useDashboardStore(X=>X.showFilters),o=s.useEditorStore(X=>X.selectedDatamodelId),c=s.useEditorStore(X=>X.selectedDatabaseName),d=s.useEditorStore(X=>X.selectedSchemaName),l=s.useEditorStore(X=>X.selectedTableName),m=s.useEditorStore(X=>X.isDevMode),{setSelectedTableName:u,setIsDevMode:h,setCardSql:j}=s.useEditorActions(),{connectionItems:p,modelItems:g,schemaItems:f,databaseItems:S,tableItems:x,columns:N,isConnectionsLoading:D,isModelsLoading:E,isConnectionsError:v,isModelsError:b,isDatabasesLoadingOrFetching:w,isDatabaseError:y,isSchemaLoadingOrFetching:I,isSchemaError:T,isColumnsError:C,isColumnsLoadingOrFetching:B,isTableLoadingOrFetching:z,isTableError:O,connectionType:k,isNonDbConnection:A,refetchDatabases:R,refetchModels:P,refetchSchemas:$,refetchTables:Y,refetchColumns:V,refetchConnections:L,handleConnectionChange:F,handleDatabaseChange:_,handleSchemaChange:J,handleDatamodelChange:G,handleTableChange:Q,tableName:H,schemaName:U}=s.useEditorAside(),{data:q,refetch:K}=s.useDashboardCardQuery(n);function se(){return t?t(U,H,N):e.jsx(ta,{schemaName:U,tableName:H,columns:N,status:B?"Loading...":C?"Error":"Success"})}function de(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function Me(X){X===!0?q&&(j(q.userSql),setTimeout(()=>{K()},100)):j(""),h(X)}function Ae(){if(!r||k==="S3"||k==="API")return null;if(!o||o==="none")return e.jsx(ye,{refetch:R,showNone:!0,onChange:_,isError:y,isLoading:w,items:S,value:c||"",title:"Database",type:"combobox"})}function Ot(){if(r&&!A&&(!c||c==="none")&&(!o||o==="none"))return e.jsxs("div",{className:"grid grid-cols-3",children:[e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(s.Separator,{})})]})}function Ft(){if(!r||k==="S3"||k==="API")return null;if(!c||c==="none")return e.jsx(ye,{refetch:P,showNone:!0,onChange:G,isError:b,isLoading:E,items:g,value:o||"",title:"Model",type:"combobox"})}function zt(){return!r||k==="S3"||k==="API"||!c||c==="none"?null:e.jsx(ye,{refetch:$,onChange:J,isError:T,isLoading:I,items:f,value:d||"",title:"Schema",type:"combobox"})}function Bt(){function X(){let me=!1;return k==="API"?(me=!1,me):((k==="S3"||r&&c&&c!=="none"&&d)&&(me=!0),me)}return X()?e.jsx(ye,{refetch:Y,onChange:Q,isError:O,items:x,isLoading:z,value:l||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:s.cn("flex h-full min-w-[310px] max-w-[310px] flex-col justify-between rounded-none",{"border-r-[1px]":!i}),children:[e.jsxs("section",{className:"space-y-3 px-6 py-4",children:[e.jsx(ye,{refetch:L,items:p,title:"Connection",value:r||"",onChange:F,isLoading:D,isError:v,type:"combobox",connectionTooltip:((Fs=p==null?void 0:p.find(X=>X.id===r))==null?void 0:Fs.type)||""}),Ae(),Ot(),Ft(),zt(),Bt()]}),se(),e.jsx("div",{className:"flex items-center justify-between gap-2 px-6 py-4",children:a==="main"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:m,onCheckedChange:Me,id:"dev-mode"}),e.jsx(s.Label,{htmlFor:"dev-mode",children:"Advanced Mode"})]}),e.jsxs(s.Button,{onClick:de,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(Zs,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function ut({sql:t,error:a,onClick:n}){const r=s.useEditorStore(l=>l.isDevMode),{setIsDevMode:i,setCardSql:o,setRunSql:c}=s.useEditorActions();function d(){i(!r),o(t),setTimeout(()=>{c(!0)},100)}return e.jsx("div",{className:"flex justify-between space-x-4",children:e.jsxs("div",{className:"flex grow flex-col space-y-2",children:[e.jsxs(s.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsx("div",{className:"rounded-md",children:e.jsx(s.CodeHighlighter,{code:t,language:"sql"})})})]}),!r&&e.jsxs(s.Button,{onClick:d,variant:"secondary",size:"sm",children:[e.jsx(pn,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),a&&n&&e.jsxs(s.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(Cn,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function mt({sql:t,error:a,onClick:n}){return e.jsxs(s.HoverCard,{openDelay:a?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:a?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:"w-full min-w-fit max-w-[700px]",children:e.jsx(ut,{sql:t,error:a,onClick:n})})]})}var ht={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},$s=M.createContext&&M.createContext(ht),na=["attr","size","title"];function aa(t,a){if(t==null)return{};var n=ra(t,a),r,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(i=0;i<o.length;i++)r=o[i],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}function ra(t,a){if(t==null)return{};var n={};for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){if(a.indexOf(r)>=0)continue;n[r]=t[r]}return n}function Pe(){return Pe=Object.assign?Object.assign.bind():function(t){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},Pe.apply(this,arguments)}function Gs(t,a){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);a&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(t,i).enumerable})),n.push.apply(n,r)}return n}function Ve(t){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?Gs(Object(n),!0).forEach(function(r){ia(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Gs(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}function ia(t,a,n){return a=oa(a),a in t?Object.defineProperty(t,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[a]=n,t}function oa(t){var a=la(t,"string");return typeof a=="symbol"?a:a+""}function la(t,a){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(t)}function xt(t){return t&&t.map((a,n)=>M.createElement(a.tag,Ve({key:n},a.attr),xt(a.child)))}function ge(t){return a=>M.createElement(ca,Pe({attr:Ve({},t.attr)},a),xt(t.child))}function ca(t){var a=n=>{var{attr:r,size:i,title:o}=t,c=aa(t,na),d=i||n.size||"1em",l;return n.className&&(l=n.className),t.className&&(l=(l?l+" ":"")+t.className),M.createElement("svg",Pe({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,c,{className:l,style:Ve(Ve({color:t.color||n.color},n.style),t.style),height:d,width:d,xmlns:"http://www.w3.org/2000/svg"}),o&&M.createElement("title",null,o),t.children)};return $s!==void 0?M.createElement($s.Consumer,null,n=>a(n)):a(ht)}function da(t){return ge({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 pt(t){const{theme:a}=s.useTheme(),n=s.useDashboardStore(f=>f.theme),r=s.useEditorStore(f=>f.frame),i=s.useEditorStore(f=>f.card),o=s.useEditorStore(f=>f.activeTabCardId),c=s.Le(),{refetch:d}=s.useDashboardCardQuery(i),{updateCardTab:l,setRunSql:m}=s.useEditorActions(),u=M.useRef(),h=M.useRef({}),j=r.cards.find(f=>f.id===o),p=M.useCallback(()=>{let f="";return t==="python"&&(f=(j==null?void 0:j.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(f=(j==null?void 0:j.sql)||""),f},[t,j]);M.useEffect(()=>{if(o&&i.id&&i.id!==o){if(u.current&&c){const f=u.current.getModel();f&&(h.current[i.id]=f);let S=h.current[o];if(!S){const x=p();S=c.editor.createModel(x,t),h.current[o]=S}u.current.setModel(S)}l(o,i),m(!0)}},[o,i,l,c,m,t,p]),M.useEffect(()=>{if(!c)return;const f=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",S=n==="system"?f:n;c.editor.defineTheme("default",{base:S==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":S==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),c.editor.setTheme("default")},[a,n,c]),M.useEffect(()=>{const f=u.current;f&&c&&i&&f.addCommand(c.KeyMod.Shift|c.KeyCode.Enter,function(){return d(),!1})},[c,d,i]);function g(f,S){if(u.current=f,!h.current[i.id]){const x=f.getModel(),N=p();h.current[i.id]=x||(S==null?void 0:S.editor.createModel(N,t))||f.getModel()}f.setModel(h.current[i.id])}return{handleEditorDidMount:g}}function ua(){const t=s.useEditorStore(c=>c.card.sql),a=s.useEditorStore(c=>c.sqlGen),{setCardSql:n,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:i}=pt("sql");function o(c){n(c),s.isObjectEmpty(a)||r({})}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:o,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:i})]})}function ma(){const t=s.useEditorStore(i=>i.card.python),{setCardPython:a}=s.useEditorActions(),{handleEditorDidMount:n}=pt("python");function r(i){a(i)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function ha({jsonString:t}){return e.jsx(s.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:t,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function ft(t){const[a,n]=M.useState(""),[r,i]=M.useState(null),{authToken:o}=s.useSemaphorContext(),c=s.useEditorStore(q=>{var K;return(K=q==null?void 0:q.card)==null?void 0:K.sql}),d=s.useEditorStore(q=>q.isDevMode),l=s.useEditorStore(q=>{var K;return(K=q==null?void 0:q.card)==null?void 0:K.python}),{setCardPython:m,setCardSql:u,setRunSql:h,switchCardType:j,setQueryConfig:p}=s.useEditorActions(),g=s.useEditorStore(q=>q.currentAssitantScope)||[],f=s.useEditorStore(q=>q.userInputForAI),S=s.useEditorStore(q=>q.triggerAIRun),x=s.useEditorStore(q=>q.selectedDatabaseName),N=s.useEditorStore(q=>q.selectedTableName),D=s.useEditorStore(q=>q.selectedConnectionId),E=s.useEditorStore(q=>q.selectedSchemaName),v=s.useDashboardStore(q=>q.dashboard.aiScopeTables),{setTriggerAIRun:b,setCurrentAssitantScope:w}=s.useEditorActions(),{selectedDatamodelName:y,connectionType:I,selectedDatamodelId:T}=s.useEditorAside(),{messages:C,setMessages:B,reload:z,error:O,append:k,input:A,setInput:R,status:P,handleInputChange:$,handleSubmit:Y,stop:V}=s.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${o==null?void 0:o.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant",isDevMode:d},maxSteps:10,onError:q=>{console.log("on error",q)},onToolCall:L,onFinish(q,K){F(K.usage),n(""),K.finishReason==="stop"&&n("")}});M.useEffect(()=>{S&&f&&($({target:{value:f}}),setTimeout(()=>{Y(),b(!1)},100))},[S,Y,f,b,$]);async function L({toolCall:q}){if(["createChartFromSql","createForecast"].includes(q.toolName)){const K=q.args.sql,se=q.args.python,de=q.args.chartType;return j(de),u(K),m(se),h(!0),{status:"success",message:"Let the user know that chart is created"}}else if(q.toolName==="getTableColumns")n("Getting table columns...");else{if(q.toolName==="getUserSql")return c?{status:"success",sql:c,python:l||""}:{status:"error",message:"No SQL found"};if(q.toolName==="getCurrentTableScope")return n("Getting table scope..."),Q(),{status:"success",tables:g};if(q.toolName==="generateQueryConfig"){n("Generating query config...");const K=q.args.chartType,se=q.args.queryConfig;return j(K),p(se),u(void 0),m(void 0),h(!0),{status:"success",queryConfig:se}}else n("Analyzing...")}}function F(q){i(K=>K?{promptTokens:K.promptTokens+q.promptTokens,completionTokens:K.completionTokens+q.completionTokens,totalTokens:K.totalTokens+q.totalTokens}:q)}function _(q){const K=s.removeFromScopeArray(g,q);J(K)}function J(q){const K=s.sanitizeAIScope(q);w(K),B(se=>[...se,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(K)}`}])}function G(){const q={databaseName:x||"",schemaName:E||"",tableName:N||"",datamodelId:T||"",datamodelName:s.resolveDatamodelName(y),connectionId:D||"",connectionType:I||""},K=s.dedup([...g,q]);J(K)}function Q(){const q={databaseName:x||"",schemaName:E||"",tableName:N||"",datamodelName:s.resolveDatamodelName(y),connectionId:D||"",connectionType:I||"",datamodelId:T||""};if(!s.isInAiScopeArray([...v||[],...g],q)||g.length===0){const se=s.dedup([...v||[],...g,q]).filter(de=>de.connectionId===q.connectionId);J(se)}}const H=!["ready","error"].includes(P),U=s.getErrorMessage(O);return{messages:C,setMessages:B,reload:z,append:k,input:A,setInput:R,isLoading:H,handleSetAIScope:Q,handleAddCurrentTableToScope:G,removeFromCurrentSelections:_,currentAssitantScope:g,setCurrentAssitantScope:w,handleInputChange:$,handleSubmit:Y,stop:V,chatStatus:P,toolStatus:a,llmUsage:r,onFinish:t,errorMessage:U}}function xa(){const t=s.useQueryClient(),[a,n]=M.useState(!1),[r,i]=M.useState(!1);s.useEditorStore(V=>V.frame);const o=s.useEditorStore(V=>V.card);s.useEditorStore(V=>V.isShowingVisual),s.useEditorStore(V=>V.selectedConnectionId),s.useEditorStore(V=>V.tempQueryData),s.useEditorStore(V=>V.selectedDatabaseName),s.useEditorStore(V=>V.selectedDatamodelId),s.useEditorStore(V=>V.selectedSchemaName);const c=s.useEditorStore(V=>V.showAIDialog);s.useEditorStore(V=>V.selectedTableName);const d=s.useEditorStore(V=>{var L;return(L=V==null?void 0:V.card)==null?void 0:L.sql}),l=s.useEditorStore(V=>{var L;return(L=V==null?void 0:V.card)==null?void 0:L.python}),{sheetFilterValues:m}=s.useSheetFilterValues(),{setCardCustomCfg:u,setQueryResultColumns:h,setCardSql:j,setTempQueryData:p,setPythonStdOut:g,setCardPreferences:f,setCardType:S,setCardPython:x,runAssistant:N,setShowAIDialog:D}=s.useEditorActions();s.useEditorStore(V=>V.onSave),s.useEditorStore(V=>V.onClose),s.useEditorStore(V=>V.actions.setSqlGen);const E=s.useEditorStore(V=>V.runSql),v=s.useEditorStore(V=>V.actions.setRunSql),b=s.useEditorStore(V=>V.actions.setIsSqlRunning),{data:w,isLoading:y,isFetching:I,isSuccess:T,isError:C,error:B,queryKey:z,refetch:O,errorMessage:k}=s.useDashboardCardQuery(o),{handleSetAIScope:A}=ft();M.useEffect(()=>{if(w&&(w.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),g((w==null?void 0:w.output)||""),w.records.length>0)){const{dimensionKeys:V}=s.getKeys(w.records);h(V)}},[w,h,g]),M.useEffect(()=>{(y||I)&&b(!0),(C||T)&&b(!1),C&&(h([]),g(""))},[y,I,w,g,C,T,b,h,B]),M.useEffect(()=>{E&&(t.getQueryData(z)||O(),v(!1))},[E,O,v,z,t]);async function R(){const V=`Can you help me debug this query in the current table scope?
|
|
422
|
+
|
|
423
|
+
Error:
|
|
424
|
+
|
|
425
|
+
${k}
|
|
426
|
+
|
|
427
|
+
Query:
|
|
428
|
+
|
|
429
|
+
${d}
|
|
430
|
+
|
|
431
|
+
${l?`Python:
|
|
432
|
+
${l}`:""}
|
|
433
|
+
`;N(V)}function P(){return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"relative flex w-1/3 min-w-0 grow overflow-hidden text-xs",role:"editor-filter-container",children:e.jsx("div",{className:"mt-2 w-[99%]",children:e.jsx(ha,{jsonString:JSON.stringify(m,null,2)})})}),m&&m.length>0&&e.jsx(s.Button,{variant:"ghost",onClick:()=>i(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(s.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(gs,{className:"size-3.5 text-muted-foreground"})})]})}function $(){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(ua,{})}),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(ma,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function Y(){return e.jsxs("div",{role:"editor-controls",className:"item-center flex flex-wrap justify-between gap-2 px-6 py-4",children:[e.jsxs("div",{className:"flex grow items-center gap-2",children:[e.jsxs(s.Button,{title:"Shift + Enter",disabled:y||I,onClick:()=>{O()},className:"h-8 shrink-0",size:"sm",children:[y||I?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(s.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(mt,{sql:w==null?void 0:w.sql,error:k,onClick:R}),e.jsx(s.EditorClearButton,{}),e.jsx(s.Toggle,{pressed:a,onPressedChange:V=>n(V),className:"",size:"sm",children:e.jsx(da,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:c,onClick:()=>{A(),D(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:c?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.EditorCancelButton,{}),e.jsx(s.EditorAcceptButton,{})]})]})}return e.jsxs("section",{role:"editor-section",className:"flex grow flex-col justify-end",children:[e.jsxs("div",{className:"relative flex grow justify-between overflow-y-scroll",children:[$(),P()]}),Y()]})}function pa({data:t}){var c;const[a,n]=M.useState([]),i=Object.keys(t[0]).map(d=>({accessorKey:d,header:({column:l})=>{const m=l.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>l.toggleSorting(l.getIsSorted()==="asc"),children:[d,m==="asc"?e.jsx(s.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):m==="desc"?e.jsx(s.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),o=s.useReactTable({data:t,columns:i,getCoreRowModel:s.getCoreRowModel(),getPaginationRowModel:s.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:s.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsxs(s.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:[e.jsxs("table",{className:"w-full",children:[e.jsx(s.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:o.getHeaderGroups().map(d=>e.jsx(s.TableRow,{className:"",children:d.headers.map(l=>e.jsx(s.TableHead,{className:"h-11 font-semibold text-foreground",children:l.isPlaceholder?null:s.flexRender(l.column.columnDef.header,l.getContext())},l.id))},d.id))}),e.jsx(s.TableBody,{children:(c=o.getRowModel().rows)!=null&&c.length?o.getRowModel().rows.map(d=>e.jsx(s.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":d.getIsSelected()&&"selected",children:d.getVisibleCells().map(l=>e.jsx(s.TableCell,{className:"py-2",children:s.flexRender(l.column.columnDef.cell,l.getContext())},l.id))},d.id)):e.jsx(s.TableRow,{children:e.jsx(s.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function fa({card:t}){var N,D,E,v,b,w,y,I,T,C,B;const[a,n]=M.useState(!1),[r,i]=M.useState([]),{authToken:o}=s.useSemaphorContext(),c=s.getTokenParams(o==null?void 0:o.accessToken),d=s.useDashboardStore(z=>z.themeStyle),l={colors:((D=(N=d==null?void 0:d.chart)==null?void 0:N.dataset)==null?void 0:D.backgroundColor)||[]};(E=t.customCardPreferences)!=null&&E.inputData;const{getCard:m}=s.useCustomVisual(((v=t.customCardPreferences)==null?void 0:v.url)||""),u=((b=t.customCardPreferences)==null?void 0:b.visualType)||"single",h=s.useEditorStore(z=>z.frame),{setCustomCardPreferences:j}=s.useEditorActions(),{data:p}=s.useDashboardCardQuery(t),g=M.useCallback((z,O)=>{i(k=>({...k,[z]:O}))},[]);if(!((w=t.customCardPreferences)!=null&&w.componentName))return null;const f=m((y=t.customCardPreferences)==null?void 0:y.componentName);function S(z){n(z)}const x=Object.keys(((I=t.customCardPreferences)==null?void 0:I.dataInputCardIds)||{}).map(z=>{var A,R,P;const O=(R=(A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)==null?void 0:R[z].cardId,k=(P=h==null?void 0:h.cards)==null?void 0:P.find($=>$.id===O);return k||null});return e.jsx("div",{className:"semaphor-custom mb-3 flex grow basis-0 flex-col space-y-2 overflow-y-auto",children:e.jsxs(M.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[f&&u==="single"&&e.jsx(f,{params:c,theme:l,settings:(T=t.customCardPreferences)==null?void 0:T.settings,onDataChange:g,data:(p==null?void 0:p.records)||[]}),f&&u==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((C=t.customCardPreferences)==null?void 0:C.dataInputCardIds)||{}).map(z=>{var A,R,P;const O=(R=(A=t.customCardPreferences)==null?void 0:A.dataInputCardIds)==null?void 0:R[z].cardId,k=(P=h==null?void 0:h.cards)==null?void 0:P.find($=>$.id===O);if(k)return e.jsx(s.MultiInputEmptyRenderer,{onLoadingStatus:S,onDataChange:g,dataInputIndex:z,card:k},k.id+z)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(f,{theme:l,onDataChange:g,settings:x.map(z=>{var O;return(O=z==null?void 0:z.customCardPreferences)==null?void 0:O.settings}),data:x.map(z=>z!=null&&z.id?r==null?void 0:r[z.id]:[])})})]})]},(B=t.customCardPreferences)==null?void 0:B.componentName)})}function ks({className:t,...a}){var S;const n=s.useEditorStore(x=>x.card),r=((S=n.customCardPreferences)==null?void 0:S.showCardHeader)??!0,i=s.useEditorStore(x=>x.frame),o=s.useDashboardStore(x=>x.dashboard.filters);s.useEditorStore(x=>x.actions.setRunSql);const{updateFilter:c}=s.useDashboardActions(),d=o==null?void 0:o.find(x=>x.id===i.filterId),{data:l,isLoading:m,isFetching:u}=s.useDashboardCardQuery(n),{setCard:h}=s.useEditorActions(),{data:j}=s.useTopoJson(n),p=M.useMemo(()=>!n.id||!(l!=null&&l.records)?null:s.createChartConfig({card:n,data:l==null?void 0:l.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:j}),[n.id,l==null?void 0:l.records,n.type,n.queryConfig,n.customCfg,n.preferences,j]);function g(x){return e.jsx(fa,{card:x})}function f(){if(l!=null&&l.records&&(l==null?void 0:l.records.length)===0&&!m&&!u)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(s.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No records to display"})]});if(!n.id)return null;if(n.type==="custom")return g(n);if(!["table","custom"].includes(n.type)&&p)return e.jsx(e.Fragment,{children:m||u?e.jsx(e.Fragment,{}):e.jsx(s.ChartJsVisual,{cfg:p})});if(n.type==="table"&&(l!=null&&l.records)&&(l==null?void 0:l.records.length)>0)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:n,data:l==null?void 0:l.records})})}return e.jsxs(s.Card,{role:"editor-visual-card",className:s.cn("relative flex h-full flex-col rounded-none",t),...a,children:[r&&e.jsxs(s.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(s.Editable,{enabled:!0,text:n.title,onSave:x=>h({...n,title:x}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(s.CardTitle,{className:"text-base",children:n.title||"Add title"})})},n.title),e.jsx(s.Editable,{enabled:!0,text:n.description||"",onSave:x=>h({...n,description:x}),children:e.jsx(s.CardDescription,{children:n.description||"Add description"})},n.description)]}),d&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Editable,{enabled:!0,className:"my-1",text:d.title||d.column,onSave:x=>c({...d,title:x}),children:e.jsx(s.Label,{children:d.title})}),e.jsx(s.FilterComponent,{filter:d})]})]}),e.jsx(s.CardContent,{className:"flex grow flex-col",children:f()})]})}const Ze=({language:t,value:a,onChange:n,readonly:r})=>e.jsx(s.Ft,{className:"h-full w-full overflow-hidden text-xs",theme:"default",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,lineHeight:16,renderLineHighlight:"none",readOnly:r},defaultLanguage:t,value:a,onChange:n}),ga=()=>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."})]})]}),ja=({customCode:t,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:i})=>e.jsxs(s.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(s.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(s.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(s.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(s.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(s.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Ze,{language:"json",value:n,onChange:r})}),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:a,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:i})})]}),ya=({error:t,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:i})=>e.jsxs(s.DialogFooter,{className:"flex items-center",children:[e.jsx(s.Label,{className:"mr-2 text-red-500",children:t}),e.jsx(s.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(s.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(s.Button,{onClick:i,variant:"outline",children:"Close"})]});function ba(){const[t,a]=M.useState(!1),[n,r]=M.useState(""),[i,o]=M.useState(""),[c,d]=M.useState(""),[l,m]=M.useState(""),u=s.useEditorStore(v=>v.card),h=s.useEditorStore(v=>v.card.customCfg),j=h?JSON.stringify(h,null,2):"",{data:p}=s.useDashboardCardQuery(u),{data:g}=s.useTopoJson(u),{setCardCustomCfg:f,setCustomVisualCode:S}=s.useEditorActions(),x=v=>{var b,w;return JSON.stringify({...v,data:{...v.data,datasets:(w=(b=v.data)==null?void 0:b.datasets)==null?void 0:w.map(y=>({...y,data:[]}))}},null,2)},N=()=>{var b,w;if(!((b=p==null?void 0:p.records)!=null&&b.length))return;const v=s.createChartConfig({card:u,data:p.records,cardType:u.type,queryConfig:u.queryConfig,preferences:u.preferences,topoJson:g});if(v){r(x(v)),d(((w=u.preferences)==null?void 0:w.customVisualCode)||"");const y=s.merge(v,h);o(x(y))}},D=()=>{try{if(c&&S(c),i){const v=JSON.parse(i),b=s.getObjectDiff(JSON.parse(n),v);f(b),m("")}}catch{m("Invalid JSON configuration")}},E=Object.keys(h||{}).length===0;return e.jsxs(s.Dialog,{open:t,onOpenChange:a,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Customize Visual",onClick:N,className:E?"":"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(ga,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ks,{className:"w-1/2 rounded shadow-none"})}),e.jsx(ja,{customCode:c,cardCustomCfgString:j,mergedConfig:i,onConfigChange:v=>o(v??""),onCodeChange:v=>d(v??"")})]}),e.jsx(ya,{error:l,hasCardCustomConfig:!!h,onReset:()=>{o(n),f(null)},onApply:D,onClose:()=>a(!1)})]})]})}function gt(t){const[a,n]=M.useState(null);return a}function jt(){const{authToken:t}=s.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:i}=s.useQuery({queryKey:["plugins",t==null?void 0:t.accessToken],queryFn:()=>s.getPlugins(t==null?void 0:t.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:i}}function va({onChartTypeChange:t}){const[a,n]=M.useState([]),{setCardCustomCfg:r,setCardPreferences:i,setCardType:o,setCustomCardPreferences:c}=s.useEditorActions(),{data:d}=jt();function l(m,u){r(null),i({}),o(m),u&&c({type:"component",visualType:"single",url:u.url,componentName:u.name,icon:u.icon}),t==null||t()}return M.useEffect(()=>{(async()=>{var u;if(d){const j=(await Promise.all((u=d==null?void 0:d.plugins)==null?void 0:u.map(async p=>(await s.loadManifest(p.value)).visuals.map(S=>({name:S.name,icon:S.icon,url:p.value}))))).flat();n(j)}})()},[d]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((m,u)=>e.jsx(Na,{text:m.name,onClick:()=>l("custom",m),icon:m.icon},m.url+m.name+u))})]})}const Na=({text:t,icon:a,onClick:n})=>{const r=gt(),i=t.charAt(0).toUpperCase();return e.jsx(s.IconButton,{onClick:n,tooltip:t,children:r?e.jsx(r,{className:"h-4 w-4"}):i})};function Es(t){return ge({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(t)}function Ca(t){return ge({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M48,180c0,11,7.18,20,16,20a14.24,14.24,0,0,0,10.22-4.66A8,8,0,0,1,85.78,206.4,30.06,30.06,0,0,1,64,216c-17.65,0-32-16.15-32-36s14.35-36,32-36a30.06,30.06,0,0,1,21.78,9.6,8,8,0,0,1-11.56,11.06A14.24,14.24,0,0,0,64,160C55.18,160,48,169,48,180Zm79.6-8.69c-4-1.16-8.14-2.35-10.45-3.84-1.25-.81-1.23-1-1.12-1.9a4.57,4.57,0,0,1,2-3.67c4.6-3.12,15.34-1.73,19.82-.56A8,8,0,0,0,142,145.86c-2.12-.55-21-5.22-32.84,2.76a20.58,20.58,0,0,0-9,14.95c-2,15.88,13.65,20.41,23,23.11,12.06,3.49,13.12,4.92,12.78,7.59-.31,2.41-1.26,3.34-2.14,3.93-4.6,3.06-15.17,1.56-19.55.36A8,8,0,0,0,109.94,214a61.34,61.34,0,0,0,15.19,2c5.82,0,12.3-1,17.49-4.46a20.82,20.82,0,0,0,9.19-15.23C154,179,137.49,174.17,127.6,171.31Zm83.09-26.84a8,8,0,0,0-10.23,4.84L188,184.21l-12.47-34.9a8,8,0,0,0-15.07,5.38l20,56a8,8,0,0,0,15.07,0l20-56A8,8,0,0,0,210.69,144.47ZM216,88v24a8,8,0,0,1-16,0V96H152a8,8,0,0,1-8-8V40H56v72a8,8,0,0,1-16,0V40A16,16,0,0,1,56,24h96a8,8,0,0,1,5.66,2.34l56,56A8,8,0,0,1,216,88Zm-27.31-8L160,51.31V80Z"},child:[]}]})(t)}function Is(t){return ge({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(t)}function Ts(t){return ge({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M4.387 3h15.226a1 1 0 0 1 .948 1.316l-5.105 15.316a2 2 0 0 1 -1.898 1.368h-3.116a2 2 0 0 1 -1.898 -1.368l-5.104 -15.316a1 1 0 0 1 .947 -1.316"},child:[]},{tag:"path",attr:{d:"M5 9h14"},child:[]},{tag:"path",attr:{d:"M7 15h10"},child:[]}]})(t)}function Ds(t){return ge({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(t)}function Ms(t){return ge({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(t)}function yt({onChartTypeChange:t,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:i}=s.useEditorStore(u=>u.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:d}=s.useEditorActions();function l(u,h){o(null),r({}),n(u),["kpi","custom","text","map"].includes(u)&&(i(!0),d(void 0)),t==null||t()}const m=1e3;return e.jsxs("div",{className:"grid grid-cols-4 place-items-center",children:[e.jsx(s.IconButton,{openDelay:m,tooltip:"Table",onClick:()=>l("table"),className:"h-10 p-4",children:e.jsx(Je,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bar Chart",onClick:()=>l("bar"),className:"h-10 p-4",children:e.jsx(Ge,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Line Chart",onClick:()=>l("line"),className:"h-10 p-4",children:e.jsx(He,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Bar Chart",onClick:()=>l("stackedBar"),className:"h-10 p-4",children:e.jsx(us,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Stacked Line Chart",onClick:()=>l("stackedLine"),className:"h-10 p-4",children:e.jsx(Ds,{className:s.cn("size-5",a),strokeWidth:0})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Scatter Chart",onClick:()=>l("scatter"),className:"h-10 p-4",children:e.jsx(ps,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Bubble Chart",onClick:()=>l("bubble"),className:"h-10 p-4",children:e.jsx(Is,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Pie Chart",onClick:()=>l("pie"),className:"h-10 p-4",children:e.jsx(xs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Doughnut Chart",onClick:()=>l("doughnut"),className:"h-10 p-4",children:e.jsx(fs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Funnel Chart",onClick:()=>l("funnel"),className:"h-10 p-4",children:e.jsx(Ts,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Radar Chart",onClick:()=>l("radar"),className:"h-10 p-4",children:e.jsx(bs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Polar Area Chart",onClick:()=>l("polarArea"),className:"h-10 p-4",children:e.jsx(Es,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Tornado Chart",onClick:()=>l("tornado"),className:"h-10 p-4",children:e.jsx(Ns,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Range Chart",onClick:()=>l("range"),className:"h-10 p-4",children:e.jsx(hs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"KPI",onClick:()=>l("kpi"),className:"h-10 p-4",children:e.jsx(Ms,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Text",onClick:()=>l("text"),className:"h-10 p-4",children:e.jsx(Qs,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{tooltip:"Map",onClick:()=>l("map"),className:"h-10 p-4",children:e.jsx(ys,{className:s.cn("size-5",a)})}),e.jsx(s.IconButton,{openDelay:m,tooltip:"Custom",onClick:()=>l("custom"),className:"h-10 p-4",children:e.jsx(vs,{className:s.cn("size-5",a)})})]})}function Sa({chartType:t,className:a,customIcon:n,componentName:r}){const i=gt();switch(t){case"bar":return e.jsx(Ge,{className:a});case"line":return e.jsx(He,{className:a});case"pie":return e.jsx(xs,{className:a});case"radar":return e.jsx(bs,{className:a});case"scatter":return e.jsx(ps,{className:a});case"bubble":return e.jsx(Is,{className:a});case"doughnut":return e.jsx(fs,{className:a});case"stackedBar":return e.jsx(us,{className:a});case"stackedLine":return e.jsx(Ds,{className:a});case"polarArea":return e.jsx(Es,{className:a});case"funnel":return e.jsx(Ts,{className:a});case"tornado":case"pyramid":return e.jsx(Ns,{className:a});case"range":return e.jsx(hs,{className:a});case"kpi":return e.jsx(Ms,{className:a});case"text":return e.jsx(at,{className:a});case"map":return e.jsx(ys,{className:a});case"custom":return n&&i?e.jsx(i,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(vs,{className:a});default:return e.jsx(Je,{className:a})}}function bt({variant:t="ghost"}){var o,c;const[a,n]=M.useState(!1),r=s.useEditorStore(d=>d.card),i=r.type;return s.useDashboardStore(d=>d.isVisualEditing),e.jsxs(s.Popover,{open:a,onOpenChange:n,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:t||"ghost",children:e.jsx(Sa,{className:"size-4",chartType:i,customIcon:(o=r.customCardPreferences)==null?void 0:o.icon,componentName:(c=r.customCardPreferences)==null?void 0:c.componentName})})}),e.jsxs(s.PopoverContentCustom,{onOpenAutoFocus:d=>d.preventDefault(),className:"w-50",children:[e.jsx(yt,{onChartTypeChange:()=>n(!1)}),e.jsx(va,{onChartTypeChange:()=>n(!1)})]})]})}const Le="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function Hs(t,a){var r,i,o;const n=s.getNumberAxis(t,{});return["pie","doughnut","polarArea","funnel"].includes(a)?"category":((o=(i=(r=t==null?void 0:t.chartOptions)==null?void 0:r.scales)==null?void 0:i[n])==null?void 0:o.type)||"linear"}function wa(){var A,R,P,$,Y,V;const[t,a]=M.useState(!1),n=s.useEditorStore(L=>{var F;return(F=L.card)==null?void 0:F.preferences}),r=s.useEditorStore(L=>{var F;return(F=L.card)==null?void 0:F.type}),i=s.getNumberAxis(n,{}),[o,c]=M.useState(Hs(n,r)),[d,l]=M.useState(((P=(R=(A=n==null?void 0:n.chartOptions)==null?void 0:A.scales)==null?void 0:R[i])==null?void 0:P.min)||""),[m,u]=M.useState(((V=(Y=($=n==null?void 0:n.chartOptions)==null?void 0:$.scales)==null?void 0:Y[i])==null?void 0:V.max)||""),[h,j]=M.useState(d||m?"custom":"auto"),[p,g]=M.useState(""),[f,S]=M.useState(0),[x,N]=M.useState(""),[D,E]=M.useState(""),[v,b]=M.useState(""),w=s.useEditorStore(L=>L.actions.setCardPreferences),{updateCardInFrame:y}=s.useEditorActions(),I=s.useEditorStore(L=>L.card),T=["pie","doughnut","polarArea","funnel"].includes(r);M.useEffect(()=>{var L,F,_,J,G,Q,H,U,q,K,se,de,Me,Ae;c(Hs(n,r)),l(((_=(F=(L=n==null?void 0:n.chartOptions)==null?void 0:L.scales)==null?void 0:F[i])==null?void 0:_.min)===0?0:""),u(((Q=(G=(J=n==null?void 0:n.chartOptions)==null?void 0:J.scales)==null?void 0:G[i])==null?void 0:Q.max)||""),g(((K=(q=(U=(H=n==null?void 0:n.chartOptions)==null?void 0:H.scales)==null?void 0:U[i])==null?void 0:q.ticks)==null?void 0:K.stepSize)||""),S(((se=n==null?void 0:n.numberAxisFormat)==null?void 0:se.decimalPlaces)||0),N(((de=n==null?void 0:n.numberAxisFormat)==null?void 0:de.suffix)||""),E(((Me=n==null?void 0:n.numberAxisFormat)==null?void 0:Me.currency)||""),b(((Ae=n==null?void 0:n.numberAxisFormat)==null?void 0:Ae.locale)||"")},[t,n,i,r]);function C(L,F){return F===""||/^[0-9\b]+$/.test(F)?Number(F):Number(L)}function B(){const L=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(F=>F.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-2 hover:cursor-pointer hover:underline",htmlFor:"currency",children:e.jsx("a",{target:"_blank",href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat",children:"Currency"})}),e.jsxs(s.Select,{value:D||"none",onValueChange:F=>E(F==="none"?"":F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),L.map(F=>e.jsx(s.SelectItem,{value:F,children:F},F))]})})]}),e.jsxs(s.Select,{value:v,onValueChange:F=>b(F),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Locale"}),s.LOCALE_CURRENCY_PAIRS.map(F=>e.jsx(s.SelectItem,{value:F.locale,children:F.locale},F.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(s.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(s.Input,{value:f,onChange:F=>S(Number(F.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${Le}`})]})]})}function z(){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 space-y-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the scale for number axis"})}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(s.Select,{disabled:T,value:o,onValueChange:L=>c(L),children:[e.jsx(s.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{id:"type",children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Option"}),e.jsx(s.SelectItem,{value:"linear",children:"Linear"}),e.jsx(s.SelectItem,{value:"logarithmic",children:"Logarithmic"}),e.jsx(s.SelectItem,{value:"category",children:"Category"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(s.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(s.RadioGroup,{disabled:T,id:"scale-option",value:h,onValueChange:L=>j(L),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"auto",id:"r1"}),e.jsx("label",{className:"text-sm",htmlFor:"r1",children:"Auto"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),h==="custom"&&o=="linear"&&O()]})}function O(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"range",children:"Range"}),e.jsx(s.Input,{id:"min",value:d,onChange:L=>l(F=>C(F,L.target.value)),className:`col-span-1 h-8 w-full ${Le}`}),e.jsx(s.Input,{value:m,onChange:L=>u(F=>C(F,L.target.value)),id:"max",className:`col-span-1 h-8 w-full ${Le}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(s.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(s.Input,{value:p,onChange:L=>g(F=>C(F,L.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${Le}`})]})]})}function k(){var J;let L={};h==="custom"&&(L={min:d,max:m,ticks:{stepSize:p}});const F={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(J=n==null?void 0:n.chartOptions)==null?void 0:J.scales,[i]:{type:o,...o==="linear"?L:{}}}},numberAxisFormat:{decimalPlaces:f,suffix:x,currency:D,locale:v}};console.log(F),w(F);const _={...I,preferences:F};y(_)}return e.jsxs(s.Popover,{onOpenChange:L=>a(L),children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Format Number",children:e.jsx(hn,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"max-w-65",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Format Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the format for number axis"})]}),e.jsxs("div",{className:"grid gap-2",children:[B(),z(),e.jsx(s.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(s.Button,{onClick:k,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ka(){const t=s.useEditorStore(d=>{var l,m,u,h;return(h=(u=(m=(l=d.card.preferences)==null?void 0:l.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.position}),a=s.useEditorStore(d=>{var l,m,u,h;return(h=(u=(m=(l=d.card.preferences)==null?void 0:l.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.align}),n=s.useEditorStore(d=>{var l,m,u,h;return(h=(u=(m=(l=d.card.preferences)==null?void 0:l.chartOptions)==null?void 0:m.plugins)==null?void 0:u.legend)==null?void 0:h.display}),{setLegendOptions:r}=s.useEditorActions(),i=d=>{r({display:d,position:t,align:a})},o=d=>{r({display:n,position:d,align:a})},c=d=>{r({display:n,position:t,align:d})};return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Legend Settings",children:e.jsx(kn,{className:"size-4"})})}),e.jsx(s.PopoverContentCustom,{align:"end",className:"w-72",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium leading-none",children:"Legend Options"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set the legend options for the chart."})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(s.SmallSwitch,{checked:n,onCheckedChange:i,id:"displayLegend"})})]}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Top",onClick:()=>o("top"),children:e.jsx(s.ArrowUp,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Left",onClick:()=>o("left"),children:e.jsx(Yt,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Bottom",onClick:()=>o("bottom"),children:e.jsx($e,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Right",onClick:()=>o("right"),children:e.jsx(Kt,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(s.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(s.IconButton,{tooltip:"Start",onClick:()=>c("start"),children:e.jsx($t,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"Center",onClick:()=>c("center"),children:e.jsx(_t,{className:"size-4"})}),e.jsx(s.IconButton,{tooltip:"End",onClick:()=>c("end"),children:e.jsx(Gt,{className:"size-4"})})]})]})]})]})]})})]})}function Ea(){const t=s.useEditorStore(o=>{var c,d;return(d=(c=o.card.preferences)==null?void 0:c.chartOptions)==null?void 0:d.indexAxis}),a=s.useEditorStore(o=>o.card.type),{setChartOrientation:n}=s.useEditorStore(o=>o.actions);function r(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="x"||t===void 0?"y":"x")},tooltip:"Chart Orientation",children:t==="x"||t===void 0?e.jsx(Ps,{className:"size-4"}):e.jsx(Rs,{className:"size-4"})})}function i(){return e.jsx(s.IconButton,{onClick:()=>{n(t==="y"||t===void 0?"x":"y")},tooltip:"Chart Orientation",children:t==="y"||t===void 0?e.jsx(Ps,{className:"size-4"}):e.jsx(Rs,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?i():r()})}function vt(){const t=s.useEditorStore(c=>c.card),a=s.useEditorStore(c=>c.isShowingVisual),n=s.useEditorStore(c=>{var d,l;return(l=(d=c.card)==null?void 0:d.preferences)==null?void 0:l.chartOptions}),r=s.getChartGridStyle(n),{setChartGrid:i}=s.useEditorActions();function o(){const c=["xy","none","x","y"],l=(c.indexOf(r)+1)%c.length;i(c[l])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(t.type)&&e.jsx(Ea,{}),!["kpi","text","custom","table"].includes(t.type)&&e.jsxs(e.Fragment,{children:[e.jsx(wa,{}),e.jsx(ka,{})]}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(t.type)&&e.jsxs(s.IconButton,{tooltip:"Grid Style",onClick:o,children:[(r==="xy"||!r)&&e.jsx(Nn,{className:"size-4"}),r==="x"&&e.jsx(dn,{className:"size-4"}),r==="y"&&e.jsx(Bn,{className:"size-4"}),r==="none"&&e.jsx(Vn,{className:"size-4"})]})]}):null}function Oe({children:t}){var V;const a=s.useEditorStore(L=>L.frame),n=s.useEditorStore(L=>L.card),r=s.useEditorStore(L=>L.isDevMode),i=s.useEditorStore(L=>L.isShowingVisual),o=s.useDashboardStore(L=>L.isVisualEditing),c=s.useEditorStore(L=>L.isSqlRunning),d=s.useEditorStore(L=>L.pythonStdOut),l=s.useEditorStore(L=>{var F;return(F=L.card.preferences)==null?void 0:F.chartOptions}),m=s.useEditorStore(L=>L.actions.setRunSql);s.getChartGridStyle(l);const{setFrame:u,setCard:h,updateCardInFrame:j,setActiveTabCardId:p,runAssistant:g,setChartGrid:f,setIsDevMode:S}=s.useEditorActions(),{data:x,isLoading:N,isFetching:D,error:E,isPending:v}=s.useDashboardCardQuery(n);if(!n)return e.jsx(e.Fragment,{children:"No Active Card"});function b(L){const F={connectionId:L.connectionId,lastSelectedDatabase:L.lastSelectedDatabase,lastSelectedSchema:L.lastSelectedSchema,lastSelectedTable:L.lastSelectedTable,lastSelectedDatamodelId:L.lastSelectedDatamodelId,id:s.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};w(L,F)}function w(L,F){const _={...a,cards:[...a.cards,F],activeCardId:L.id};u(_),p(F.id)}function y(){const L={...n,id:s.v4(),title:`${n.title} Copy`,tabTitle:`${n.tabTitle||n.title} Copy`};w(n,L)}function I(L){const F=a.cards.filter(G=>G.id!==L),_=F[0],J={...a,cards:F,activeCardId:_.id};u(J),p(_.id),h(_)}function T(L){const F=a.cards.find(_=>_.id===L);if(F!=null&&F.sql){r||S(!0),p(L);return}if(F!=null&&F.queryConfig){r&&S(!1),C(L),p(L);return}r||C(L),p(L)}function C(L){const F={...a,cards:a.cards.map(J=>J.id===n.id?n:J),activeCardId:L};u(F);const _=F.cards.find(J=>J.id===L);_.sql&&m(!0),h(_)}const B=(L,F)=>{console.log("handleDragStart",F),L.dataTransfer.setData("tabIndex",F.toString())},z=L=>{L.preventDefault()},O=(L,F)=>{const _=L.dataTransfer.getData("tabIndex");if(_===F.toString())return;const J=Array.from(a.cards),[G]=J.splice(parseInt(_),1);J.splice(F,0,G),u({...a,cards:J})};function k(L,F){return L.cards.length===1&&(F.displayTab===!0||F.displayTab===void 0)||L.activeCardId!==F.id&&(F.displayTab===!0||F.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const _=F.displayTab===void 0?!1:!F.displayTab;h({...F,displayTab:_}),j({...F,displayTab:_})},children:F.displayTab===!0||F.displayTab===void 0?e.jsx(s.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(xn,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}function A(){return e.jsxs(s.Tabs,{onValueChange:T,value:a.activeCardId,className:"flex grow flex-col",children:[a.cards.map(L=>e.jsx(s.TabsContent,{className:"mt-0 grow",value:L.id,children:R()},L.id)),e.jsx(s.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[a.cards.map((L,F)=>e.jsxs(s.TabsTrigger,{draggable:!0,onDragStart:_=>B(_,F),onDragOver:z,onDrop:_=>O(_,F),className:"",value:L.id,children:[k(a,L),e.jsx(s.Editable,{enabled:a.activeCardId===L.id,text:L.tabTitle||L.title,onSave:_=>{h({...n,tabTitle:_}),j({...n,tabTitle:_})},children:L.tabTitle||L.title},L.id),a.activeCardId===L.id&&a.cards.length>1&&e.jsx(s.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>I(L.id)})]},L.id)),e.jsx(s.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>b(n),children:e.jsx(s.Plus,{className:"h-4 w-4"})}),e.jsx(s.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:y,children:e.jsx(mn,{className:"h-4 w-4"})})]})})]})}function R(){return n.type==="kpi"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.KPICard,{card:n,data:x==null?void 0:x.records,isPending:v})})}):n.type==="text"?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx("div",{className:"w-1/2 rounded-md border",children:e.jsx(s.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(s.TextCard,{isLoading:c,card:n,data:x==null?void 0:x.records})})})}):e.jsx(s.ErrorBoundary,{FallbackComponent:s.FallbackEditorCard,children:e.jsx(ks,{className:"grow border-none shadow-none"})})}function P(){const L=JSON.stringify(x==null?void 0:x.records,null,2),F=new Blob([L],{type:"application/json"}),_=URL.createObjectURL(F),J=document.createElement("a");J.href=_,J.download=`${n.title}.json`,J.click()}function $(){const F=[Object.keys(x==null?void 0:x.records.reduce((Q,H)=>({...Q,...H}),{})).join(","),...((x==null?void 0:x.records)||[]).map(Q=>Object.values(Q).join(","))].join(`
|
|
434
|
+
`),_=new Blob([F],{type:"text/csv"}),J=URL.createObjectURL(_),G=document.createElement("a");G.href=J,G.download=`${n.title}.csv`,G.click()}function Y(){const L=`Can you get the documentation for ${n.type} chart?`;g(L)}return e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[(N||D)&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 m-auto flex h-10 w-10 items-center justify-center rounded-md bg-muted",children:e.jsx(ce,{className:"h-8 w-8 animate-spin text-muted-foreground"})}),e.jsxs("div",{className:"z-10 mb-0 flex min-h-10 items-center justify-end gap-2 px-6",children:[i&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(bt,{}),o&&e.jsx(s.IconButton,{tooltip:"Visual Docs",onClick:Y,children:e.jsx(Zt,{className:"size-4"})}),!["table","custom"].includes(n.type)&&o&&e.jsx(ba,{})]}),!i&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(s.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:$,children:e.jsx(Ca,{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:P,children:e.jsx(fn,{strokeWidth:1.5,className:"size-4"})}),e.jsx(s.CopyButton,{text:JSON.stringify(x==null?void 0:x.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx(vt,{})]}),r&&e.jsx(Ta,{})]}),i?A():e.jsxs(s.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[d&&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:d&&e.jsx(Ia,{})}),e.jsx(s.ResizableHandle,{})]}),e.jsxs(s.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(x==null?void 0:x.records)&&(x==null?void 0:x.records.length)>0&&e.jsx(pa,{data:(x==null?void 0:x.records)||[]}),(E||(x==null?void 0:x.error))&&e.jsx("span",{className:"font-mono text-xs",children:(E==null?void 0:E.message)||((V=x==null?void 0:x.error)==null?void 0:V.message)})]})]})]})}function Ia(){const t=s.useEditorStore(n=>n.pythonStdOut);if(!t)return null;const a=t.replace(/\n/g,"<br>");return e.jsxs("div",{className:"relative flex w-full flex-col border-r",children:[e.jsx("div",{className:"sticky top-0 flex max-h-11 min-h-11 grow items-center border-b bg-muted px-3 font-mono text-xs font-semibold text-foreground/70",children:"Python Output"}),e.jsxs(s.ScrollArea,{className:"overflow-y-auto px-2 pt-1 font-mono text-xs text-foreground/90",children:[e.jsx("div",{dangerouslySetInnerHTML:{__html:a}}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Ta(){const t=s.useEditorStore(n=>n.isShowingVisual),a=s.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(s.SmallSwitch,{checked:t,onCheckedChange:()=>a(!t),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Da(){var f,S;const t=s.useEditorStore(x=>x.card.customCardPreferences),{data:a}=jt(),n=(a==null?void 0:a.plugins)||[],r=s.useEditorStore(x=>x.card),i=s.useEditorStore(x=>x.frame),o=(t==null?void 0:t.visualType)||"single",{setCustomCardPreferences:c}=s.useEditorActions(),{components:d,manifest:l}=s.useCustomVisual((t==null?void 0:t.url)||""),m=(f=l==null?void 0:l.visuals)==null?void 0:f.find(x=>x.name===(t==null?void 0:t.componentName));function u(x,N){if(!t)return;const E={...(t==null?void 0:t.dataInputCardIds)||{},[x]:{cardId:N,hookRef:null}};c({...t,dataInputCardIds:E})}function h(x){var D,E;const N=(D=i==null?void 0:i.cards)==null?void 0:D.filter(v=>{var b;return((b=v==null?void 0:v.customCardPreferences)==null?void 0:b.visualType)!=="multiple"}).map(v=>({value:v.id,label:v.tabTitle||v.title}));return e.jsx("div",{className:"space-y-2",children:(E=x==null?void 0:x.dataInputs)==null?void 0:E.map((v,b)=>{var w,y;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:v}),e.jsx(oe,{className:"col-span-6 h-8 w-full justify-between",label:"",options:N||[],value:((y=(w=t==null?void 0:t.dataInputCardIds)==null?void 0:w[b])==null?void 0:y.cardId)||"",onValueChange:I=>u(b,I)})]},b+Math.random())})})}function j(x,N,D=[],E=""){var v,b;return t?x==="input"?e.jsx(s.Input,{className:`h-8 w-full ${s.removeRing}`,value:((v=t==null?void 0:t.settings)==null?void 0:v[N])||E,onChange:w=>{c({...t,settings:{...t==null?void 0:t.settings,[N]:w.target.value}})}},N):x==="select"?e.jsx(oe,{className:"h-8 w-full",label:"",options:D,value:((b=t==null?void 0:t.settings)==null?void 0:b[N])||E,onValueChange:w=>{c({...t,settings:{...t==null?void 0:t.settings,[N]:w}})}}):null:null}function p(x){const N=Object.entries((x==null?void 0:x.settings)||{});return e.jsx("div",{className:"space-y-3",children:N.map(([D,E])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:E.title}),j(E.ui,D,E.options,E.defaultValue)]},D))})}function g(x){t&&c({...t,visualType:x,componentName:""})}return e.jsxs(s.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",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(oe,{icon:e.jsx(Xt,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(t==null?void 0:t.url)||"",onValueChange:x=>c({...t||{url:"",componentName:""},url:x})}),((t==null?void 0:t.type)==="component"||(t==null?void 0:t.type)===void 0)&&e.jsx(s.Tabs,{value:o,onValueChange:g,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:d&&e.jsx(oe,{icon:e.jsx(un,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(d==null?void 0:d.filter(x=>x.type===o).map(x=>({value:x.name,label:x.name})))||[],value:t.componentName,onValueChange:x=>{console.log("changing value",x),c({...t,componentName:x})}})})]})})]}),((S=r==null?void 0:r.customCardPreferences)==null?void 0:S.componentName)&&e.jsxs(s.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{children:[m&&m.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:h(m)})]}),m&&m.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:p(m)})})]})]})]})}function je(){const[t,a]=M.useState([]),n=s.useEditorStore(m=>m.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:i}=s.useEditorStore(m=>m.actions),o=s.useEditorStore(m=>m.queryResultColumns);s.useEditorStore(m=>{var u;return(u=m.card.preferences)==null?void 0:u.filterOnClickColumnIndex}),M.useEffect(()=>{o&&a(new Array(o.length).fill(!1))},[o]);function c(m,u){var h,j;u?n!=null&&n.onClickFilter&&((h=n==null?void 0:n.onClickFilter)==null?void 0:h.length)>0?i({...n,onClickFilter:[...n.onClickFilter,{columnIndex:m,expression:""}]}):i({...n,onClickFilter:[{columnIndex:m,expression:""}]}):(i({...n,onClickFilter:(j=n==null?void 0:n.onClickFilter)==null?void 0:j.filter(p=>p.columnIndex!==m)}),a(p=>{const g=[...p];return g[m]=!1,g}))}function d(m,u){var j;const h=(j=n==null?void 0:n.onClickFilter)==null?void 0:j.map(p=>p.columnIndex===m?{...p,expression:u.target.value}:p);i({...n,onClickFilter:h})}function l(m){var u,h,j,p;if(t!=null&&t[m]||(h=(u=n==null?void 0:n.onClickFilter)==null?void 0:u.find(g=>g.columnIndex===m))!=null&&h.expression)return e.jsx(s.Input,{value:(p=(j=n==null?void 0:n.onClickFilter)==null?void 0:j.find(g=>g.columnIndex===m))==null?void 0:p.expression,onChange:g=>d(m,g),type:"text",className:"h-9 w-full font-mono text-xs focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0",placeholder:"Expression"})}return e.jsxs("div",{className:"max-h-[150px] space-y-2 overflow-y-auto",children:[e.jsx(s.Label,{children:"On Click"}),o==null?void 0:o.map((m,u)=>{var h,j;return e.jsx("div",{className:"group flex items-center justify-between space-y-2",children:e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(s.Checkbox,{checked:!!((h=n==null?void 0:n.onClickFilter)!=null&&h.find(p=>p.columnIndex===u)),onCheckedChange:p=>c(u,p)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:m}),e.jsx("div",{className:"flex items-center gap-2",children:((j=n==null?void 0:n.onClickFilter)==null?void 0:j.find(p=>p.columnIndex===u))&&e.jsx(s.Pencil,{onClick:()=>{a(p=>{const g=[...p];return g[u]=!p[u],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),l(u)]})},m)})]})}function Ma({idx:t}){var d;const a=s.useEditorStore(l=>{var m;return(m=l.card)==null?void 0:m.preferences}),n=s.useEditorStore(l=>{var m;return(m=l.card.preferences)==null?void 0:m.datasetOptions}),r=s.useEditorStore(l=>l.actions.setCardPreferences),i=(d=a==null?void 0:a.chartOptions)==null?void 0:d.indexAxis,o=n==null?void 0:n.find(l=>l.idx===t);function c(l,m){(l==="end"||l==="start")&&s.getContrastColor(s.getCanvasBackgroundColor());const u={display:l!=="none",align:l,anchor:l,clamp:!0};if(!o)r({...a,datasetOptions:[...n||[],{idx:m,datalabels:u}]});else{const h={...o};h.datalabels=u;const j=n==null?void 0:n.map(p=>p.idx===m?h:p);r({...a,datasetOptions:j})}}return e.jsxs(s.Popover,{children:[e.jsx(s.PopoverTrigger,{children:e.jsx(tt,{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:()=>c("none",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(s.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>c("start",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(In,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>c("center",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Dn,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>c("end",t),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Tn,{className:s.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function Nt(){const t=s.useEditorStore(o=>o.card),{data:a}=s.useDashboardCardQuery(t),{keys:n}=s.getKeys((a==null?void 0:a.records)||[]),r=n.slice(1).filter(o=>!s.METADATA_KEYS.includes(o));let i=r;if(["stackedBar","stackedLine"].includes(t.type)){const o=s.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:n[0],pivotKey:n[1],valueKey:n[2]}),{keys:c}=s.getKeys(o);i=c.slice(1)}return{transformedMetricKeys:i,dimensionKeys:n.slice(0,1),keys:n,defaultMetricKeys:r}}function qe({children:t,className:a,delayDuration:n}){return e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{delayDuration:n,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:s.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:t})}),e.jsx(s.TooltipContent,{children:t})]})})}function Ct(){const t=s.useEditorStore(l=>l.card),a=s.useEditorStore(l=>{var m,u,h;return(h=(u=(m=l==null?void 0:l.card)==null?void 0:m.preferences)==null?void 0:u.chartOptions)==null?void 0:h.indexAxis}),{data:n}=s.useDashboardCardQuery(t),r=a==="y"?"Metric":"Dimension",i=a==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:c,keys:d}=Nt();return d.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:o.map(l=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:l,children:St(l)},l))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:i}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:c.map((l,m)=>e.jsx(wt,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:l,idx:m},l))})]})]})}function St(t,a=30){return t.length>a?t.slice(0,a)+"...":t}function wt({col:t,idx:a,className:n,iconClassName:r,children:i}){const o=s.useEditorStore(u=>{var h;return(h=u.card)==null?void 0:h.preferences}),c=s.useEditorStore(u=>{var h,j;return(j=(h=u.card)==null?void 0:h.preferences)==null?void 0:j.datasetOptions}),d=c==null?void 0:c.find(u=>u.idx===a),{setCardPreferences:l}=s.useEditorStore(u=>u.actions);function m(u){if(!d)l({...o,datasetOptions:[...c||[],{idx:a,type:u==="area"?"line":u,fill:u==="area"?"origin":""}]});else{const h={...d};h.type=u==="area"?"line":u,h.fill=u==="area"?"origin":"";const j=c==null?void 0:c.map(p=>p.idx===a?h:p);l({...o,datasetOptions:j})}}return e.jsxs("div",{className:s.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[i||e.jsx(qe,{className:"max-w-[100px]",title:t,children:St(t)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ge,{onClick:()=>m("bar"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(He,{onClick:()=>m("line"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(nn,{onClick:()=>m("area"),className:s.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Ma,{idx:a})]})]})}function kt(){const t=s.useEditorStore(p=>p.selectedConnectionId),a=s.useEditorStore(p=>p.selectedDatamodelId),n=s.useEditorStore(p=>p.selectedDatabaseName),r=s.useEditorStore(p=>p.selectedSchemaName),i=s.useEditorStore(p=>p.selectedTableName),o=s.useDashboardStore(p=>p.dashboard.filters)||[],c=s.useDashboardStore(p=>p.actions.addFilter),d=s.useDashboardStore(p=>p.actions.removeFilter),{removeFilterValues:l}=s.useDashboardActions(),{modelItems:m,tableName:u,connectionType:h}=s.useEditorAside();function j(p,g="dashboard"){var w;const f=s.fmt(p.column_name),S=s.fmt(n||""),x=s.fmt(r||""),N=s.fmt(u);let D=s.getQualifiedTableName({schemaName:x,tableName:N,connectionType:h,databaseName:S}),E=`${D}.${f}`;const v=(w=m==null?void 0:m.find(y=>y.id===a))==null?void 0:w.name;a&&a!=="none"&&(E=`${s.DATAMODEL_NAMESPCACE}.${v}.${f}`,D=`${s.DATAMODEL_NAMESPCACE}.${v}`);const b=o==null?void 0:o.find(y=>y.column===E&&y.table===N&&(y.database===S||y.database===n));if(b)l(b.id),d(b.id);else{const y=s.v4();return u==="api"&&t?(c({location:g,id:y,column:E,title:p.column_name,dataType:p.data_type,table:"api",database:"",connectionId:t,operation:"in",sql:s.getDefaultFilterSql(p.data_type,D,f)}),y):(c({id:y,location:g,column:E,title:p.column_name,dataType:p.data_type,table:i||"",database:n||"",connectionId:t||"",operation:"in",sql:s.getDefaultFilterSql(p.data_type,D,f)}),y)}}return{assignFilter:j}}function Se(){const t=s.useDashboardStore(d=>d.dashboard.filters),a=s.useEditorStore(d=>d.frame),{setFrame:n}=s.useEditorActions(),{columns:r}=s.useEditorAside(),{assignFilter:i}=kt();function o(d){const l=i(d,"frame");n({...a,filterId:l})}const c=t==null?void 0:t.find(d=>d.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(s.Label,{children:"Card Filter"}),e.jsx(Aa,{onSelect:o,columns:r}),c&&e.jsx(s.FilterHeader,{filter:c})]})}function Aa({columns:t,onSelect:a}){var c;const[n,r]=ae.useState(!1),[i,o]=ae.useState("");return e.jsxs(s.Popover,{open:n,onOpenChange:r,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[i?(c=t.find(d=>d.column_name===i))==null?void 0:c.column_name:"Select Column...",e.jsx(s.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No framework found."}),e.jsx(s.CommandGroup,{children:t==null?void 0:t.map(d=>e.jsxs(s.CommandItem,{value:d.column_name,onSelect:l=>{const m=l===i?"":l;o(m),r(!1),m&&a(d)},children:[d.column_name,e.jsx(s.CheckIcon,{className:s.cn("ml-auto h-4 w-4",i===d.column_name?"opacity-100":"opacity-0")})]},d.column_name))})]})]})})]})}function La({cardType:t}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, y-axis-1, y-axis-2,... FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"y-axis1 - number"}),e.jsx("li",{children:"y-axis2 - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:a=>a.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bar-line-area",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(Ct,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(je,{}),e.jsx(Se,{})]})]})]})})}function As(){var i,o,c;const t=s.useEditorStore(d=>d.card.type),a=s.useEditorStore(d=>d.card.preferences),{setCardPreferences:n}=s.useEditorStore(d=>d.actions);function r(d){var u;const l={datalabels:{display:d!=="none",align:d,anchor:d,clamp:!0}},m={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(u=a==null?void 0:a.chartOptions)==null?void 0:u.plugins,...l}}};n(m),console.log(d)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(s.Select,{value:((c=(o=(i=a==null?void 0:a.chartOptions)==null?void 0:i.plugins)==null?void 0:o.datalabels)==null?void 0:c.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(s.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{placeholder:"Select position"})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Data Labels"}),e.jsx(s.SelectItem,{value:"none",children:"None"}),!["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 Oa({cardType:t}){function a(n){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:n==="bubble"?"SELECT label, [group], x-axis, y-axis, radius FROM table":"SELECT label, [group], x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"group (optional) - category"}),e.jsx("li",{children:"x-axis - number"}),e.jsx("li",{children:"y-axis - number"}),n==="bubble"&&e.jsx("li",{children:"radius - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:o=>o.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/bubble",children:"example"})," in the docs."]})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} Chart`}),e.jsx(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(t)})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsx(s.AccordionContent,{className:"px-2",children:e.jsx(As,{})})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(je,{}),e.jsx(Se,{})]})]})]})})}const Fa={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},za={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ba(){const t=s.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(s.Accordion,{className:" ",type:"single",collapsible:!0,children:Ra(t)}),!["kpi"].includes(t)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(As,{}),e.jsx(je,{}),e.jsx(Se,{})]})]})}function Ra(t){if(["line","bar"].includes(t))return e.jsxs(e.Fragment,{children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT x-axis, y-axis-1, y-axis-2, y-axis-3,... FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"X-axis - Category (ex. city)"}),e.jsx("li",{children:"Y-axis - Number (ex. population)"})]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and change the `type` property in the dataset."]}),e.jsx("pre",{children:JSON.stringify(Fa,null,2)})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-2 text-xs",children:[e.jsxs("p",{children:["Click ",e.jsx("b",{children:"Customize"})," and add `fill` property to the dataset. See",e.jsx("a",{className:"mx-1 text-blue-500 hover:underline",href:"https://www.chartjs.org/docs/latest/samples/area/line-boundaries.html",target:"_blank",children:"docs"}),"for more options."]}),e.jsx("pre",{children:JSON.stringify(za,null,2)})]})]})]});if(t==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis, radius FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Bubble Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"}),e.jsx("li",{children:"Radius - Number (ex. population)"})]})]})]})});if(t==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:t})," chart query?"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, x-axis, y-axis FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Group (opt) - Category (ex. state)"}),e.jsx("li",{children:"X-axis - Number (ex. avg. age)"}),e.jsx("li",{children:"Y-axis - Number (ex. avg. weight)"})]})]})]})});if(["pie","doughnut","polarArea","funnel"].includes(t))return e.jsx(e.Fragment,{children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:t==="polarArea"?"Polar":t.charAt(0).toUpperCase()+t.slice(1)})," ","chart query"]})}),e.jsxs(s.AccordionContent,{className:" ",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs font-semibold",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs font-normal [&>li]:mt-2",children:[e.jsx("li",{children:"Label - Category (ex. city)"}),e.jsx("li",{children:"Measure - Number (ex. population)"})]})]})]})})}function Pa(){var l,m,u,h,j;const t=s.useEditorStore(p=>p.card.preferences),a=s.useEditorStore(p=>p.actions.setCardPreferences),n=s.useEditorStore(p=>p.actions.setNumberFormat);s.useEditorStore(p=>{var g,f;return(f=(g=p.card.preferences)==null?void 0:g.formatNumber)==null?void 0:f.decimalPlaces});const r=s.useEditorStore(p=>{var g,f;return(f=(g=p.card.preferences)==null?void 0:g.formatNumber)==null?void 0:f.locale}),i=s.useEditorStore(p=>{var g,f;return(f=(g=p.card.preferences)==null?void 0:g.formatNumber)==null?void 0:f.currency});s.useEditorStore(p=>p.actions.setFilterOnClickField);const o=s.useEditorStore(p=>{var g,f;return(f=(g=p.card.preferences)==null?void 0:g.formatNumber)==null?void 0:f.colorRanges})||[],c=s.useEditorStore(p=>p.actions.setColorRanges),d=[...new Set(s.LOCALE_CURRENCY_PAIRS.map(p=>p.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(s.Checkbox,{checked:!!((l=t==null?void 0:t.formatNumber)!=null&&l.enabled),onCheckedChange:p=>{a({...t,formatNumber:{...t==null?void 0:t.formatNumber,enabled:p}})}}),e.jsx(s.Label,{children:"Format Number"})]}),((m=t==null?void 0:t.formatNumber)==null?void 0:m.enabled)===!0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{children:e.jsxs("div",{className:"space-y-4 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Locale"}),e.jsxs(s.Select,{value:r||"none",onValueChange:p=>{var g,f,S;return n(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",p,((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Format"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),s.LOCALE_CURRENCY_PAIRS.map(p=>e.jsx(s.SelectItem,{value:p.locale,children:p.locale},p.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Currency"}),e.jsxs(s.Select,{value:i||"none",onValueChange:p=>{var g,f,S;console.log("currency",p),n(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,p==="none"?"":p,((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:e.jsxs(s.SelectGroup,{children:[e.jsx(s.SelectLabel,{children:"Currency"}),e.jsx(s.SelectItem,{value:"none",children:"None"},"none"),d.map(p=>e.jsx(s.SelectItem,{value:p,children:p},p))]})})]})]})]}),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:((h=(u=t==null?void 0:t.formatNumber)==null?void 0:u.decimalPlaces)==null?void 0:h.toString())||"0",onValueChange:p=>{var g,f,S;return n(Number(p),((g=t==null?void 0:t.formatNumber)==null?void 0:g.currency)||"",((f=t==null?void 0:t.formatNumber)==null?void 0:f.locale)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.suffix)||"")},children:[e.jsx(s.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:["0","1","2","3","4"].map(p=>e.jsx(s.SelectItem,{value:p,children:p},p))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(s.Label,{children:"Suffix"}),e.jsx(s.Input,{value:((j=t==null?void 0:t.formatNumber)==null?void 0:j.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:p=>{var g,f,S;return n(((g=t==null?void 0:t.formatNumber)==null?void 0:g.decimalPlaces)||0,((f=t==null?void 0:t.formatNumber)==null?void 0:f.currency)||"",((S=t==null?void 0:t.formatNumber)==null?void 0:S.locale)||"",p.target.value)}})]})]})]})}),e.jsx(s.Separator,{className:"my-3"}),e.jsx(s.ColorFormat,{colorRanges:o,setColorRanges:c})]})]})}function Va(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{type:"single",collapsible:!0,children:e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(s.AccordionContent,{className:"font-mono",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 font-mono text-xs",children:"SELECT current, previous FROM table"}),e.jsxs("ul",{className:"my-6 ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"current - number"}),e.jsx("li",{children:"previous - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/kpi",children:"example"})," in the docs."]})]})]})}),e.jsx("section",{className:"",children:e.jsx(Pa,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function es({children:t,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:s.cn("space-y-4 [&_summary>svg]:open:-rotate-180",r),children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center justify-between gap-4",children:[e.jsx(s.Label,{children:a}),e.jsx(s.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:t})]})}const qa=[{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"}],_a=["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"],$a=_a.map(t=>({label:t,value:t}));function Ga(){var l,m,u,h,j,p,g,f,S,x,N,D,E,v,b,w,y,I;const t=s.useEditorStore(T=>T.card),a=(m=(l=t==null?void 0:t.preferences)==null?void 0:l.mapVisualOptions)==null?void 0:m.topoJsonUrl,[n,r]=M.useState(((h=(u=t==null?void 0:t.preferences)==null?void 0:u.mapVisualOptions)==null?void 0:h.customTopoJsonUrl)||""),{setCardPreferences:i}=s.useEditorActions(),{data:o}=s.useTopoJson(t),c=Object.keys((o==null?void 0:o.objects)||{}).map(T=>({label:T,value:T}))||[],d=[{label:"US States 10m",value:"https://unpkg.com/us-atlas/states-10m.json"},{label:"Countries 50m",value:"https://unpkg.com/world-atlas/countries-50m.json"},{label:"Custom",value:"custom"}];return e.jsxs("div",{className:"p-6",children:[e.jsx(es,{summary:"Map Chart",children:e.jsx("p",{className:"rounded-md bg-muted p-2 font-mono text-xs",children:"SELECT country, value FROM table"})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(es,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(oe,{className:"h-9",options:d,onValueChange:T=>{console.log("value",T),i({...t.preferences,mapVisualOptions:{topoJsonUrl:T}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(s.Input,{onChange:T=>{r(T.target.value)},onBlur:()=>{var T;console.log("onBlur",n),i({...t.preferences,mapVisualOptions:{...(T=t.preferences)==null?void 0:T.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${s.removeRing}`,placeholder:"Custom URL"}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Map Object"}),e.jsx(oe,{className:"h-9",options:c,value:((p=(j=t.preferences)==null?void 0:j.mapVisualOptions)==null?void 0:p.objectKey)||"",label:"Map Object",onValueChange:T=>{var C;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,objectKey:T}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Projection"}),e.jsx(oe,{className:"h-9",options:qa,value:((f=(g=t.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:f.projection)||"",label:"Projection",onValueChange:T=>{var C;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projection:T}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{children:"Colors"}),e.jsx(oe,{className:"h-9",options:$a,value:((x=(S=t.preferences)==null?void 0:S.mapVisualOptions)==null?void 0:x.colorScale)||"",label:"Select Color Scale",onValueChange:T=>{var C;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,colorScale:T}})}})]})]})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(es,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:.1,value:((D=(N=t.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:D.projectionScale)||1,onChange:T=>{var C;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionScale:Number(T.target.value)}})}}),e.jsx(s.Label,{children:"X"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((b=(v=(E=t.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:v.projectionOffset)==null?void 0:b[0])||0,onChange:T=>{var C,B,z,O;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[Number(T.target.value),((O=(z=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:O[1])||0]}})}}),e.jsx(s.Label,{children:"Y"}),e.jsx(s.Input,{className:`h-9 w-full ${s.removeRing}`,type:"number",step:10,value:((I=(y=(w=t.preferences)==null?void 0:w.mapVisualOptions)==null?void 0:y.projectionOffset)==null?void 0:I[1])||0,onChange:T=>{var C,B,z,O;i({...t.preferences,mapVisualOptions:{...(C=t.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[((O=(z=(B=t.preferences)==null?void 0:B.mapVisualOptions)==null?void 0:z.projectionOffset)==null?void 0:O[0])||0,Number(T.target.value)]}})}})]})}),e.jsx(s.Separator,{className:"my-4"}),e.jsx(je,{})]})}function Ha(){var r;const t=s.useEditorStore(i=>i.card.preferences),{setCardPreferences:a}=s.useEditorStore(i=>i.actions);function n(i){a({...t,textVisualOptions:{...t==null?void 0:t.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxs(s.RadioGroup,{value:(r=t==null?void 0:t.textVisualOptions)!=null&&r.isDynamicText?"dynamic":"static",onValueChange:n,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 Fe({cardType:t,docContent:a,suffix:n="Chart"}){let r="pie-donut-polar";return t==="funnel"&&(r="funnel"),e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:`${s.titleCase(t)} ${n}`}),e.jsx(s.AccordionContent,{children:a||e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT label, measure FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"label - category"}),e.jsx("li",{children:"measure - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:i=>i.stopPropagation(),className:"text-blue-700",href:`https://docs.semaphor.cloud/docs/charts/${r}`,children:"example"})," in the docs."]})]})})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[t!=="text"&&e.jsx(As,{}),t==="text"&&e.jsx(Ha,{})]})]}),!["range","text"].includes(t)&&e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(je,{}),e.jsx(Se,{})]})]})]})})}function Ja(){const t=s.useEditorStore(r=>{var i,o;return(o=(i=r==null?void 0:r.card)==null?void 0:i.preferences)==null?void 0:o.sortChart}),{setSortChart:a}=s.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Sort"}),e.jsx(oe,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:t||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(s.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(s.AccordionItem,{value:"item-1",children:[e.jsx(s.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(s.AccordionContent,{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT x-axis, stack-by, y-axis FROM table"}),e.jsxs("ul",{className:"ml-6 list-disc text-xs [&>li]:mt-2",children:[e.jsx("li",{children:"x-axis - category"}),e.jsx("li",{children:"stack by - category"}),e.jsx("li",{children:"y-axis - number"})]}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:r=>r.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/stacked",children:"example"})," in the docs."]})]})]}),e.jsxs(s.AccordionItem,{value:"item-2",children:[e.jsx(s.AccordionTrigger,{children:"Settings"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(Ct,{})]})]}),e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(je,{}),e.jsx(Se,{})]})]})]})})}function Ua({cardType:t="table"}){console.log("cardType",t);const a=s.useEditorStore(i=>{var o;return(o=i.card)==null?void 0:o.preferences}),n=s.useEditorStore(i=>i.actions.setCardPreferences),r=i=>{n({...a,allowDownload:i})};return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(s.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(s.AccordionItem,{value:"item-3",children:[e.jsx(s.AccordionTrigger,{children:"Filters"}),e.jsxs(s.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(je,{}),e.jsx(Se,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{onCheckedChange:r,id:"allow-download"}),e.jsx("label",{htmlFor:"allow-download",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Allow Download"})]})]})}const Ya=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),Ka=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),Qa=e.jsxs("div",{className:"space-y-4 font-mono text-xs",children:[e.jsx("div",{className:"rounded bg-muted px-2 py-1 text-xs",children:"SELECT text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:t=>t.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function Wa(){const t=s.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Ja,{});case"tornado":case"pyramid":return e.jsx(Fe,{docContent:Ya,cardType:n});case"kpi":return e.jsx(Va,{});case"line":case"bar":return e.jsx(La,{cardType:n});case"range":return e.jsx(Fe,{docContent:Ka,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return e.jsx(Fe,{cardType:n});case"bubble":case"scatter":return e.jsx(Oa,{cardType:n});case"table":return e.jsx(Ua,{cardType:n});case"text":return e.jsx(Fe,{docContent:Qa,cardType:n,suffix:"Visual"});case"map":return e.jsx(Ga,{});case"custom":return e.jsx(Da,{});default:return e.jsx(Ba,{})}}return e.jsxs(s.ScrollArea,{className:"h-full w-full text-sm",children:[a(t),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})}function Et({label:t,column:a,functions:n,onFunctionChange:r}){let i=n[0];"aggregate"in a?i=n.find(c=>c.value===a.aggregate)||n[0]:"granularity"in a&&(i=n.find(c=>c.value===a.granularity)||n[0]);function o(c){r(c)}return e.jsx(oe,{className:"flex h-8 w-8 justify-center overflow-clip rounded-none border-none bg-muted px-0 [&>svg]:hidden",icon:i.logo,options:n,value:i.value,onValueChange:c=>o(c),label:t,showPlaceholderLabel:!1})}const Xa=[{label:"Sum",value:"SUM",logo:e.jsx(st,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(js,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(yn,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Ut,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx($e,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(s.ArrowUp,{className:"size-3.5"})}];function Za({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions();let n=Xa;s.isTextDataType(t.type)&&(n=n.filter(i=>["COUNT","DISTINCT"].includes(i.value))),s.isNumberDataType(t.type)&&(n=n.filter(i=>!["DISTINCT"].includes(i.value)));function r(i){const o={...t,aggregate:i,label:ke(t.name,i)};a(t.id,o)}return e.jsx(Et,{column:t,functions:n,onFunctionChange:i=>r(i),label:"Aggregation"})}const er=[{label:"Day (D)",value:"day",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(s.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function sr({column:t}){const{updateGroupByColumnOld:a}=s.useEditorActions();function n(r){const i={...t,granularity:r,label:Ce(t.name,r)};a(t.id,i)}return e.jsx(Et,{column:t,functions:er,onFunctionChange:r=>n(r),label:"Granularity"})}function tr({col:t,onChange:a,droppableId:n}){const{columns:r}=s.useDataColumns(),i=M.useMemo(()=>{let d=[];(n===xe||n===pe||n===fe)&&(d=r);const l=d==null?void 0:d.filter(m=>m.column_name!==t.name);return l==null?void 0:l.map(m=>({id:m.column_name,value:m.column_name}))},[r,n,t.name]),o=[{id:t.name,value:t.name}];function c(d){const l=r==null?void 0:r.find(m=>{var u;return m.column_name===((u=d[0])==null?void 0:u.id)});l&&a(l)}return i!=null&&i.length?e.jsx(s.ComboBox2,{multiple:!1,options:i,selectedOptions:o,onChange:c,selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"border-none bg-muted pl-0 pr-8"}):e.jsx("input",{disabled:!0,type:"text",className:"overflow-hidden truncate text-ellipsis whitespace-nowrap bg-muted text-sm",value:t.name})}function nr({column:t}){const{updateMetricColumnOld:a}=s.useEditorActions(),{transformedMetricKeys:n,dimensionKeys:r}=Nt();console.log(n,r);const i=s.useEditorStore(l=>{var m;return(m=l.card.queryConfig)==null?void 0:m.pivotColumns}),o=!!(i&&i.length>0),c=n.find(l=>l===t.label||l===t.name),d=c?n.indexOf(c):-1;return e.jsxs("div",{className:"space-y-3",children:[c&&e.jsx(wt,{idx:d,col:c,children:e.jsx(s.Editable,{enabled:!0,className:"w-[130px]",text:t.label||"",placeholder:"Enter label",onSave:l=>{a(t.id,{...t,label:l||t.name})},children:e.jsx(qe,{className:"w-[130px]",children:t.label||t.name})})}),o&&e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(s.Label,{children:"Pivot Header"}),e.jsx(s.Editable,{enabled:!0,text:t.aliasTemplate||"",placeholder:"{label} ({pivot})",onSave:l=>{a(t.id,{...t,aliasTemplate:l||""})},children:e.jsx(qe,{className:"font-mono text-xs text-muted-foreground",children:t.aliasTemplate||"{label} ({pivot})"})})]})]})}function ar({column:t,type:a,onRemoveColumn:n,droppableId:r}){const[i,o]=M.useState(!1),{updateGroupByColumnOld:c,updateMetricColumnOld:d,updatePivotByColumnOld:l}=s.useEditorActions(),{attributes:m,listeners:u,setNodeRef:h,transform:j,transition:p,isDragging:g}=s.useSortable({id:t.id,data:{type:a}}),f=j?{opacity:g?.5:void 0,transform:s.CSS.Translate.toString(j),transition:p}:void 0,S=s.isTextDataType(t.type);function x(b){const w=s.isNumberDataType(b.data_type),y=s.isTextDataType(b.data_type),I=s.isDateDataType(b.data_type),T=w?"number":y?"string":I?"date":"string";if(r===xe){if(y){const C={id:t.id,name:b.column_name,type:T,role:"groupby"};c(t.id,C)}if(I){const C={id:t.id,name:b.column_name,type:T,role:"groupby",label:Ce(b.column_name,"month"),granularity:"month"};c(t.id,C)}}if(r===fe){if(y){const C={id:t.id,name:b.column_name,type:T,role:"groupby"};l(t.id,C)}if(I){const C={id:t.id,name:b.column_name,type:T,label:Ce(b.column_name,"month"),granularity:"month",role:"groupby"};l(t.id,C)}}if(r===pe){const C={id:t.id,name:b.column_name,type:T,role:"metric",label:ke(b.column_name,"SUM"),aggregate:w?"SUM":"COUNT"};d(t.id,C)}}function N(){if(r===pe)return e.jsx("div",{"data-setting-container":"",className:"mt-1.5 max-h-32 overflow-y-auto rounded-md border border-border p-3 text-sm",children:e.jsx(nr,{column:t})})}function D(){const b=s.isDateDataType(t.type);if(r===pe)return e.jsx(Za,{column:t});if((r===xe||r===fe)&&b)return e.jsx(sr,{column:t})}function E(){return e.jsx("div",{className:s.cn("grow",{"pl-3":(r===xe||r===fe)&&S}),children:e.jsx(tr,{col:t,onChange:x,droppableId:r})})}function v(){return e.jsx("div",{"data-setting-actions":"",className:"flex h-full items-center gap-2",children:e.jsx("button",{className:"h-full pl-2",onClick:()=>o(!i),children:i?e.jsx(Pn,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(Xs,{className:s.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...u,...m,ref:h,style:f,children:e.jsxs("div",{className:"group flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"grow",children:[e.jsxs("div",{className:"flex h-8 grow items-center justify-between rounded-md bg-muted",children:[v(),D(),E()]}),i&&N()]}),e.jsx("div",{className:s.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:i}),children:e.jsx("button",{onClick:()=>n(t.id),children:e.jsx(s.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function ss({id:t,label:a,columns:n,previewColumns:r,sortableType:i,onRemoveColumn:o}){var f,S;const{setNodeRef:c,isOver:d,over:l}=s.useDroppable({id:t}),m=s.useDndStore(x=>x.activeId),u=s.useEditorStore(x=>{var N;return(N=x.card)==null?void 0:N.type}),h=d||((S=(f=l==null?void 0:l.data)==null?void 0:f.current)==null?void 0:S.type)===i,j=m?r:n,p=i===Be?"Rows":i===Re?"Pivot Columns":"Columns";function g(){if(!j||j.length===0)return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(x=>x.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md p-4",h&&"border border-muted-foreground/20"),ref:c,children:[e.jsxs("div",{className:"flex items-center justify-between pr-5",children:[e.jsx(s.Label,{className:"text-sm",children:a}),u!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:p})]}),g(),e.jsx("div",{className:"space-y-2",children:j==null?void 0:j.map(x=>x.id===ct.id?e.jsx(rr,{},x.id):e.jsx(ar,{droppableId:t,type:i,column:x,onRemoveColumn:o},x.id))})]})})}function rr(){return e.jsx("div",{className:"mr-5 flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm",children:e.jsx("span",{className:"text-muted-foreground/70",children:"Drop here"})})}function It({children:t,id:a,type:n}){const{attributes:r,listeners:i,setNodeRef:o,transform:c,transition:d,isDragging:l}=s.useSortable({id:a,data:{type:n}}),m=c?{opacity:l?.5:void 0,transform:s.CSS.Translate.toString(c),transition:d}:void 0;return e.jsx("div",{...i,...r,ref:o,style:m,children:t})}function ir(){const t=s.useEditorStore(x=>{var N;return(N=x.card.queryConfig)==null?void 0:N.orderBy})||[],a=s.useEditorStore(x=>{var N;return(N=x.card.queryConfig)==null?void 0:N.groupByColumns})||[],n=s.useEditorStore(x=>{var N;return(N=x.card.queryConfig)==null?void 0:N.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:i,updateOrderByColumn:o}=s.useEditorActions(),c=[...a,...n];if(c.length===0)return e.jsx(e.Fragment,{});const d=e.jsx(Wt,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),l=e.jsx(Jt,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=e.jsx(Qt,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),u=e.jsx(Ht,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=c==null?void 0:c.filter(x=>!t.some(N=>N.columnId===x.id)).map(x=>({id:x.id,value:x.label||x.name}));function j(x,N){const D=p(x);return D?D.role==="metric"?N==="asc"?m:u:N==="asc"?d:l:null}function p(x){return c.find(N=>N.id===x)}function g(x){const N=t.find(D=>D.columnId===x);if(N){const D={...N,direction:N.direction==="asc"?"desc":"asc"};o(D)}}const f=x=>{r({columnId:x.id,direction:"asc"})};function S(x){const N=t.find(D=>D.columnId===x);N&&i(N)}return e.jsx(s.SortableContext,{items:t.map(x=>we(x.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md p-4 text-sm",children:[e.jsx(s.Label,{className:"text-sm",children:"Sort By"}),h.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(s.ComboBox2,{multiple:!1,options:h,selectedOptions:[],onChange:x=>f(x[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),t.map(x=>{var N,D;return e.jsx(It,{id:we(x.columnId),type:ws,children:e.jsx("div",{className:"group flex h-8 items-center gap-2 rounded-sm p-0",children:e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex h-full grow items-center justify-between gap-2 rounded-sm bg-muted px-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Xs,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(qe,{className:"w-[175px] text-sm",children:((N=p(x.columnId))==null?void 0:N.label)||((D=p(x.columnId))==null?void 0:D.name)})]}),e.jsx("button",{title:x.direction==="asc"?"Ascending":"Descending",onClick:()=>g(x.columnId),className:"rounded-sm p-0",children:j(x.columnId,x.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>S(x.columnId),className:"rounded-sm p-0",children:e.jsx(s.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},x.columnId)},we(x.columnId))})]})})}function or(){const t=s.useEditorStore(S=>{var x;return((x=S.card.queryConfig)==null?void 0:x.groupByColumns)||[]}),a=s.useEditorStore(S=>S.card.type),n=s.useDndStore(S=>S.previewGroupByColumns),r=s.useEditorStore(S=>{var x;return((x=S.card.queryConfig)==null?void 0:x.metricColumns)||[]}),i=s.useDndStore(S=>S.previewMetricColumns),o=s.useEditorStore(S=>{var x;return((x=S.card.queryConfig)==null?void 0:x.pivotColumns)||[]}),c=s.useDndStore(S=>S.previewPivotColumns),{removeColumnFromGroupBy:d,removeColumnFromMetricColumns:l,removeColumnFromPivotBy:m}=s.useEditorActions();function u(S){d(S)}function h(S){l(S)}function j(S){m(S)}let p="Group By",g="Metrics",f="Stack By";return a==="table"&&(p="Rows",g="Metrics",f="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(yt,{iconClassName:"size-[19px]"}),e.jsxs(s.CustomScrollArea,{className:"flex min-h-0 grow basis-0 flex-col gap-4 overflow-y-auto",children:[e.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[e.jsx(ss,{onRemoveColumn:u,sortableType:Be,id:xe,label:p,columns:t,previewColumns:n}),e.jsx(ss,{onRemoveColumn:j,sortableType:Re,id:fe,label:f,columns:o,previewColumns:c}),e.jsx(ss,{onRemoveColumn:h,sortableType:ls,id:pe,label:g,columns:r,previewColumns:i}),e.jsx(ir,{})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"})]})]})}function Ls({children:t,column:a,id:n,sortableType:r,className:i}){const[o,c]=M.useState(!1),{removeEditorFilter:d,clearEditorFilter:l}=s.useEditorActions(),m=s.useEditorStore(h=>{var j,p;return(p=(j=h.card.queryConfig)==null?void 0:j.filters)==null?void 0:p.some(g=>g.filterColumnName===a.name)});function u(h){d(h)}return e.jsx(It,{id:n,type:r,children:e.jsxs("div",{className:s.cn("group space-y-1 rounded-md bg-muted px-3 py-2",{"border-border":o}),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Label,{className:"text-sm",children:a.name}),m&&e.jsx("button",{onClick:()=>l(a),children:e.jsx(s.FilterX,{className:"size-3 cursor-pointer items-center justify-center text-muted-foreground hover:text-foreground"})})]}),e.jsx("div",{"data-setting-actions":"",className:"invisible flex h-full items-center gap-2 group-hover:visible",children:e.jsx("button",{onClick:()=>u(a),children:e.jsx(s.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:s.cn("group flex items-center rounded-t-md text-sm",!o&&"rounded-b-md",o&&"border border-border"),children:[e.jsx("div",{children:e.jsx(s.GripVertical,{className:"mr-2 size-3.5 cursor-move items-center justify-center p-0 text-muted-foreground/60 hover:text-foreground"})}),e.jsx("div",{className:s.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",i),children:t})]})]})})}function lr({column:t,sortableType:a}){const n=s.useDashboardStore(D=>D.themeStyle),r=s.useEditorStore(D=>{var E,v;return(v=(E=D.card)==null?void 0:E.queryConfig)==null?void 0:v.filters}),i=s.useEditorStore(D=>{var E,v;return(v=(E=D.card.queryConfig)==null?void 0:E.filterColumns)==null?void 0:v.find(b=>b.name===t.name)}),{selectedConnectionId:o,selectedDatabaseName:c,selectedTableName:d}=s.useEditorAside(),l=M.useMemo(()=>{var D;return(D=r==null?void 0:r.find(E=>E.filterColumnName===t.name))==null?void 0:D.filterValue},[r,t.name]),m=M.useMemo(()=>Array.isArray(l)?l.map(D=>({id:D,value:D})):[],[l]),{updateEditorFilterValue:u}=s.useEditorActions(),h={column:t.name,sql:t.sql,id:t.name,connectionId:o,dataType:t.type},{data:j,isLoading:p,isFetching:g,isError:f}=s.useFilterQuery(h),S=M.useMemo(()=>{var E;return h.column?(E=j==null?void 0:j.records)==null?void 0:E.map(v=>{let b=h.column.split(".").slice(-1)[0].replace(/"/g,"");return v[b]===void 0&&(b=b.toLowerCase()),{id:v[b],value:v[b]}}):[]},[j,h.column]);function x(D){const E=D.map(v=>v.id);u(t.name,E)}function N(){return p||g?e.jsx(s.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):f?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(s.ComboBox2,{renderFilterModeButton:()=>e.jsx(cr,{columnName:t.name}),showNegativeIndicator:(i==null?void 0:i.mode)==="exclude",options:S,onChange:x,selectedOptions:m,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(Ls,{className:"w-60",id:t.id,sortableType:a,column:t,children:N()})}function cr({columnName:t}){const{setEditorFilterMode:a}=s.useEditorActions(),n=s.useEditorStore(i=>{var o,c;return(c=(o=i.card.queryConfig)==null?void 0:o.filterColumns)==null?void 0:c.find(d=>d.name===t)});function r(){(n==null?void 0:n.mode)==="exclude"?a(t,"include"):a(t,"exclude")}return e.jsx(s.Button,{onClick:r,variant:"secondary",size:"sm",className:s.cn("h-5 text-xs hover:underline",{}),children:s.titleCase((n==null?void 0:n.mode)==="exclude"?"exclude":"include")})}function dr({column:t,sortableType:a}){const[n,r]=M.useState(!1),{selectedConnectionId:i,selectedDatabaseName:o,selectedTableName:c}=s.useEditorAside(),d={column:t.name,sql:t.sql,id:t.name,connectionId:i,title:"",dataType:t.type},{isLoading:l,isFetching:m,isError:u,data:h}=s.useFilterQuery(d),j=h==null?void 0:h.records,{dateRange:p,setDateRange:g,initialDateRange:f}=s.useDateRangeFromRecords(j),{updateEditorFilterValue:S}=s.useEditorActions();function x(E){var b,w;const v={gte:(b=E==null?void 0:E.from)==null?void 0:b.toISOString(),lte:(w=E==null?void 0:E.to)==null?void 0:w.toISOString()};S(t.name,v)}function N(){S(t.name,null,!0),g(f)}function D(){return l||m?e.jsx("div",{children:e.jsx(s.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):u?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):j?e.jsx(s.DateRangePopover,{title:d.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:p,setDateRange:g,onApply:x,onClear:N}):e.jsx(s.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(Ls,{className:"w-72",id:t.id,sortableType:a,column:t,children:D()})}function ur({id:t,label:a,columns:n,previewColumns:r,sortableType:i}){var g,f;const{setNodeRef:o,isOver:c,over:d}=s.useDroppable({id:t}),l=s.useDndStore(S=>S.activeId),m={},u=c||((f=(g=d==null?void 0:d.data)==null?void 0:g.current)==null?void 0:f.type)===i;function h(){if(!p||p.length===0)return e.jsx("div",{className:"flex h-8 grow items-center space-x-2 rounded-md border border-dashed border-muted-foreground/80 bg-background px-2 py-1 text-sm text-muted-foreground",children:e.jsx("span",{className:"invisible text-muted-foreground/70 group-hover:visible",children:"Drag here"})})}function j(S){const x=s.isDateDataType(S.type);return S.id===ct.id?e.jsx(Ls,{id:S.id,sortableType:i,column:S,children:e.jsx(mr,{})},S.id):x?e.jsx(dr,{droppableId:t,sortableType:i,column:S},S.id):e.jsx(lr,{droppableId:t,sortableType:i,column:S},S.id)}const p=l?r:n;return e.jsx(s.SortableContext,{items:n==null?void 0:n.map(S=>S.id),children:e.jsxs("div",{className:s.cn("group space-y-2 rounded-md border-muted-foreground/50 p-4",u&&"border border-muted-foreground/20"),ref:o,style:m,children:[e.jsx(s.Label,{className:"text-sm",children:a}),h(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:p==null?void 0:p.map(S=>j(S))})]})})}function mr(){return e.jsx("div",{className:"flex h-8 w-60 items-center space-x-2 rounded-md border border-dashed border-muted-foreground bg-background px-2 py-1 text-sm text-muted-foreground",children:"Drop here"})}function hr(){const t=s.useEditorStore(i=>{var o;return((o=i.card.queryConfig)==null?void 0:o.filterColumns)||[]}),a=s.useDndStore(i=>i.previewFilterColumns),{removeColumnFromFilterColumns:n}=s.useEditorActions();function r(i){n(i)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(ur,{onRemoveColumn:r,sortableType:ds,id:cs,label:"Filters",columns:t,previewColumns:a})})}function xr(){const t=s.useEditorStore(o=>o.card),a=s.useEditorStore(o=>o.showAIDialog),{setShowAIDialog:n}=s.useEditorActions(),{data:r,errorMessage:i}=s.useDashboardCardQuery(t);return e.jsxs("section",{className:"flex justify-between gap-2 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s.EditorClearButton,{}),!a&&e.jsxs(s.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(On,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(mt,{sql:r==null?void 0:r.sql,error:i})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-green-300 px-3 py-1 text-xs font-medium text-black",children:"Preview"}),e.jsx(s.EditorCancelButton,{}),e.jsx(s.EditorAcceptButton,{variant:"default"})]})]})}function pr(){const t=M.useRef(null),a=M.useRef(null),n=s.useEditorStore(d=>d.isShowingVisual),r=s.useEditorStore(d=>d.showAIDialog),i=s.useEditorStore(d=>d.isDevMode);M.useEffect(()=>{var d,l,m,u;r?((d=t.current)==null||d.resize(0),(l=a.current)==null||l.resize(0)):((m=t.current)==null||m.resize(25),(u=a.current)==null||u.resize(25))},[r]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(s.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(xa,{})}),e.jsx(s.ResizableHandle,{withHandle:!0}),e.jsx(s.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!r?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(Wa,{})})}),!r&&e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Oe,{})})]}):e.jsx(Oe,{})})]})}function c(){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"grow","data-biz-mode-container":"",children:n?e.jsxs(s.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(s.ResizablePanel,{ref:a,defaultSize:25,maxSize:30,children:e.jsx(or,{})})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{defaultSize:75,maxSize:100,children:e.jsxs(s.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(s.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(xr,{}),e.jsx(hr,{})]}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(Oe,{})})]})})]}):e.jsx(Oe,{})})})}return e.jsx(s.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:i?o():c()})}const fr=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Js(){const t=M.useRef(null),a=M.useRef(null),[n,r]=M.useState(!1),[i,o]=M.useState(s.isDevEnv),[c,d]=M.useState(!1),l=s.useEditorStore(L=>L.actions.setCardSql),m=s.useEditorStore(L=>L.actions.setRunSql),u=s.useEditorStore(L=>L.showAIDialog),h=s.useDashboardStore(L=>L.handleOpenAssistantProfile),{setShowAIDialog:j,setCardPython:p}=s.useEditorActions(),{assistantProfile:g}=s.useAssistantProfile(),{messages:f,setMessages:S,reload:x,append:N,input:D,setInput:E,isLoading:v,handleAddCurrentTableToScope:b,removeFromCurrentSelections:w,currentAssitantScope:y,handleInputChange:I,handleSubmit:T,stop:C,chatStatus:B,llmUsage:z,errorMessage:O}=ft();s.useAssistantScroll({scrollContainerRef:t,inputRef:a,messages:f}),M.useEffect(()=>{var L;u&&((L=a.current)==null||L.focus())},[u]);function k(L,F){F==="sql"?(l(L),m(!0)):F==="python"&&(p(L),m(!0))}function A(L){const F={role:"user",content:L.title+" "+L.subtitle};N(F)}function R(L){N({role:"user",content:L})}function P(){return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(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:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(s.DropdownMenuCheckboxItem,{checked:c,onCheckedChange:d,children:"System Message"})]})]})}function $(){return e.jsxs("div",{children:[y&&y.length>0&&e.jsx("div",{className:"mt-2 flex max-h-16 flex-wrap items-center gap-2 overflow-y-auto",children:y==null?void 0:y.map((L,F)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted px-2 py-1 text-xs",children:[s.getFormattedTableNameForQuery({schemaName:L.schemaName||"",tableName:L.tableName||"",modelName:L.datamodelName||"",connectionType:L.connectionType||"",databaseName:L.databaseName||""}),e.jsx("button",{onClick:()=>{w(L)},children:e.jsx(s.X,{className:"size-3 text-muted-foreground hover:text-foreground"})})]},F))}),(y==null?void 0:y.length)===0&&e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Context: None"}),e.jsxs(s.Button,{className:"h-6 text-xs",size:"sm",variant:"secondary",onClick:b,children:[e.jsx(s.Plus,{className:"mr-2 size-3"}),"Current Table"]})]})]})}function Y(){return e.jsx("div",{"data-role":"header",children:e.jsx("div",{className:"text-lg font-semibold",children:"Assistant"})})}const V=(D==null?void 0:D.length)===0&&(f==null?void 0:f.filter(L=>L.role==="user").length)===0;return e.jsxs("div",{"data-role":"editor-assistant",className:"flex h-full w-full flex-col justify-between px-6 py-4",children:[e.jsxs("div",{"data-role":"header-section",className:"flex items-start justify-between gap-2",children:[Y(),h&&e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:h,children:(g==null?void 0:g.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center",children:[P(),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{S([]),x()},children:e.jsx(s.Plus,{className:"size-4"})}),e.jsx(s.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{j(!1)},children:e.jsx(s.PanelRight,{className:"size-4"})})]})]}),$(),e.jsx(s.CustomScrollArea,{ref:t,className:"mt-2 flex w-full grow basis-0",children:e.jsxs("div",{className:"space-y-4 py-2 pr-3","data-role":"messages",children:[e.jsx(s.PrintMessages,{messages:f,showTools:i,handleRun:k,showSystemMessage:c}),e.jsx(s.ChatStatus,{messages:f,chatStatus:B,errorMessage:O})]})}),e.jsxs("div",{className:"mb-3",children:[V&&!g&&e.jsx(s.Placeholders,{onClick:A,placeholders:fr}),e.jsx("div",{children:V&&g&&e.jsx(s.SeedQuestions,{seedQuestions:g.seedQuestions||[],handleSeedQuestionClick:R})})]}),e.jsx(s.ChatInput,{onFocus:()=>{b()},stop:C,ref:a,setInput:E,input:D,handleInputChange:I,handleSubmit:T,isLoading:v}),z&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",z.promptTokens," prompt tokens,"," ",z.completionTokens," completion tokens,"," ",z.totalTokens," total tokens"]})})]})}const gr=()=>{const[t,a]=M.useState([]),[n,r]=M.useState(!0),[i,o]=M.useState(null);return M.useEffect(()=>{(async()=>{try{await new Promise(l=>setTimeout(l,800)),a([{id:"sm-1",name:"Sales Analytics Model",label:"Sales Analytics",description:"Comprehensive sales performance metrics and analysis",type:"model",connectionId:"default",connectionType:"none"},{id:"sm-2",name:"Customer Insights Model",label:"Customer Insights",description:"Customer behavior and segmentation analysis",type:"model",connectionId:"default",connectionType:"none"},{id:"sm-3",name:"Marketing Performance Model",label:"Marketing Performance",description:"Marketing campaign effectiveness metrics",type:"model",connectionId:"default",connectionType:"none"},{id:"sm-4",name:"Financial Reporting Model",label:"Financial Reports",description:"Financial metrics and reporting dashboards",type:"model",connectionId:"default",connectionType:"none"},{id:"sm-5",name:"Operations Dashboard Model",label:"Operations",description:"Operational efficiency and performance metrics",type:"model",connectionId:"default",connectionType:"none"},{id:"sm-6",name:"Product Analytics Model",label:"Product Analytics",description:"Product usage and performance metrics",type:"model",connectionId:"default",connectionType:"none"}]),o(null)}catch(d){o(d instanceof Error?d:new Error("Failed to fetch semantic models"))}finally{r(!1)}})()},[]),{semanticModels:t,isPending:n,error:i}},jr=t=>{const[a,n]=M.useState([]),[r,i]=M.useState(!0),[o,c]=M.useState(null);return M.useEffect(()=>{(async()=>{if(!t){n([]),i(!1);return}try{await new Promise(m=>setTimeout(m,800)),n([{id:"ds-1",name:"sales_transactions",label:"Sales Transactions",description:"Daily sales transaction data with customer and product details",type:"dataset",connectionId:"default",connectionType:"none"},{id:"ds-2",name:"customer_profiles",label:"Customer Profiles",description:"Customer demographic and behavioral data",type:"dataset",connectionId:"default",connectionType:"none"},{id:"ds-3",name:"product_catalog",label:"Product Catalog",description:"Product information and inventory data",type:"dataset",connectionId:"default",connectionType:"none"},{id:"ds-4",name:"marketing_campaigns",label:"Marketing Campaigns",description:"Campaign performance and engagement metrics",type:"dataset",connectionId:"default",connectionType:"none"},{id:"ds-5",name:"financial_metrics",label:"Financial Metrics",description:"Revenue, cost, and profitability metrics",type:"dataset",connectionId:"default",connectionType:"none"}]),c(null)}catch(l){c(l instanceof Error?l:new Error("Failed to fetch datasets"))}finally{i(!1)}})()},[t]),{datasets:a,isPending:r,error:o}};function yr(t){var g,f;const a=s.useDashboardStore(S=>S.authToken)||t,{connections:n}=s.useConnections(t),r=s.useEditorStore(S=>{var x,N;return(N=(x=S==null?void 0:S.card)==null?void 0:x.dataSource)==null?void 0:N.connectionId}),i=n==null?void 0:n.find(S=>S.id===r),o=i==null?void 0:i.type,c=i==null?void 0:i.capabilities,d=((g=c==null?void 0:c.labels)==null?void 0:g.database)||"Database";function l(S){return r&&S?!(S==="API"||S==="S3"):!1}const{data:m,isPending:u,error:h,refetch:j}=s.useQuery({queryKey:["databases",r],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/databases",(a==null?void 0:a.accessToken)||"",{connection_id:r}),enabled:l(o)}),p=(f=m==null?void 0:m.databases)==null?void 0:f.map(S=>({id:S.database_name,name:S.database_name}));return{isPending:u,error:h,databases:p||[],refetch:j,label:d}}function br(t){var g;const a=s.useDashboardStore(f=>f.authToken)||t,{connections:n}=s.useConnections(t),r=s.useEditorStore(f=>{var S,x;return(x=(S=f==null?void 0:f.card)==null?void 0:S.dataSource)==null?void 0:x.connectionId}),i=s.useEditorStore(f=>{var S,x,N;return(N=(x=(S=f==null?void 0:f.card)==null?void 0:S.dataSource)==null?void 0:x.dbSelection)==null?void 0:N.database}),o=n==null?void 0:n.find(f=>f.id===r),c=o==null?void 0:o.capabilities,d=((g=c==null?void 0:c.labels)==null?void 0:g.schema)||"Schema";function l(){return!(!r||(o==null?void 0:o.type)==="API"||(o==null?void 0:o.type)==="S3"||!i||!(c!=null&&c.path.includes("schema")))}const{data:m,isPending:u,error:h,refetch:j}=s.useQuery({queryKey:["schemas",r,i],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/schemas",(a==null?void 0:a.accessToken)||"",{connection_id:r,database_name:i}),enabled:l()}),p=m==null?void 0:m.schemas.map(f=>({id:f.schema_name,name:f.schema_name}));return{isPending:u,error:h,schemas:p||[],refetch:j,label:d}}function Tt(t){const a=s.useDashboardStore(m=>m.authToken)||t;s.useConnections(t);const n=s.useEditorStore(m=>{var u,h;return(h=(u=m==null?void 0:m.card)==null?void 0:u.dataSource)==null?void 0:h.connectionId});function r(){return!(!(a!=null&&a.accessToken)||!n)}const{data:i,isPending:o,error:c,refetch:d}=s.useQuery({queryKey:["dataModels",n],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/datamodels",(a==null?void 0:a.accessToken)||"",{connection_id:n}),enabled:r()}),l=i==null?void 0:i.datamodels.map(m=>({id:m.id,name:m.name,label:m.label,description:m.description,type:"model",database:m.database,schema:m.schema}));return{isPending:o,error:c,dataModels:l||[],refetch:d}}function vr(){var D,E,v;const t=s.useEditorStore(b=>b.card.dataSource),a=s.useEditorStore(b=>b.actions.updateDirectSource),n=s.useEditorStore(b=>b.actions.updateDataSource),[r,i]=M.useState(""),{error:o}=s.useConnections(),{databases:c,isPending:d,error:l,label:m}=yr(),{schemas:u,isPending:h,error:j,label:p}=br(),{error:g}=Tt(),f=m==null?void 0:m.toLowerCase(),S=p==null?void 0:p.toLowerCase(),x=b=>{if(!t)return;a({...t,dbSelection:{database:b,schema:"",entityType:"table"}});const y=(t.selectedEntities||[]).filter(I=>"database"in I?I.database!==b:!0);n({...t,dbSelection:{database:b,schema:"",entityType:"table"},selectedEntities:y})},N=b=>{var T;if(!((T=t==null?void 0:t.dbSelection)!=null&&T.database))return;const w=t.dbSelection||{database:"",schema:"",entityType:"table"};a({...t,dbSelection:{...w,schema:b}});const I=((t==null?void 0:t.selectedEntities)||[]).filter(C=>"schema"in C?C.schema!==b:!0);n({...t,dbSelection:{...w,schema:b},selectedEntities:I})};return e.jsxs(e.Fragment,{children:[(o||l||j||g)&&e.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-3",children:[e.jsx("div",{className:"flex items-center",children:e.jsxs("div",{className:"text-sm text-red-800",children:[e.jsx("strong",{children:"Error loading data:"}),e.jsxs("ul",{className:"mt-1 list-inside list-disc",children:[o&&e.jsxs("li",{children:["Connections: ",o]}),l&&e.jsxs("li",{children:[m,": ",l.message]}),j&&e.jsxs("li",{children:[p,": ",j.message]}),g&&e.jsxs("li",{children:["Data Models: ",g.message]})]})]})}),e.jsx(s.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:m}),e.jsxs(s.Select,{value:((D=t==null?void 0:t.dbSelection)==null?void 0:D.database)||"",onValueChange:x,disabled:d,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:l?`Error loading ${f}`:d?`Loading ${f}...`:`Select ${f}...`})}),e.jsx(s.SelectContent,{children:c.map(b=>e.jsx(s.SelectItem,{value:b.id,children:b.name},b.id))})]})]}),((E=t==null?void 0:t.dbSelection)==null?void 0:E.database)&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:p}),e.jsxs(s.Select,{value:((v=t==null?void 0:t.dbSelection)==null?void 0:v.schema)||"",onValueChange:N,disabled:h,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:j?`Error loading ${S}`:h?`Loading ${S}...`:`Select ${S}...`})}),e.jsx(s.SelectContent,{children:u.map(b=>e.jsx(s.SelectItem,{value:b.id,children:b.name},b.id))})]})]})]})]})}function Nr(){const t=s.useEditorStore(l=>l.card.dataSource),a=s.useEditorStore(l=>l.actions.updateDataSource),[n,r]=M.useState(!1),i=l=>{if(!l||(t==null?void 0:t.mode)!=="upload")return;const m=Array.from(l).map(h=>({id:`file-${Date.now()}-${Math.random()}`,name:h.name,type:"upload",connectionId:"default",connectionType:"none",label:h.name,description:`Uploaded ${new Date().toLocaleString()}`,originalName:h.name,file:h})),u=(t==null?void 0:t.selectedEntities)||[];a({...t,selectedEntities:[...u,...m]})},o=l=>{if(!t)return;const m=(t.selectedEntities||[]).filter(u=>u.id!==l);a({...t,selectedEntities:m})},c=l=>{if(l===0)return"0 Bytes";const m=1024,u=["Bytes","KB","MB","GB"],h=Math.floor(Math.log(l)/Math.log(m));return Number.parseFloat((l/Math.pow(m,h)).toFixed(2))+" "+u[h]},d=(t==null?void 0:t.selectedEntities)||[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:"Upload Files"}),e.jsxs("div",{className:`rounded-lg border-2 border-dashed p-6 text-center transition-colors ${n?"border-blue-400 bg-blue-50":"border-gray-300 hover:border-gray-400"}`,onDragOver:l=>{l.preventDefault(),r(!0)},onDragLeave:()=>r(!1),onDrop:l=>{l.preventDefault(),r(!1),i(l.dataTransfer.files)},children:[e.jsx(_n,{className:"mx-auto mb-2 h-8 w-8 text-gray-400"}),e.jsx("p",{className:"mb-2 text-sm text-gray-600",children:"Drag and drop files here, or click to select"}),e.jsx("input",{type:"file",multiple:!0,className:"hidden",id:"file-upload",onChange:l=>i(l.target.files),accept:".csv,.json,.xlsx,.xls"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:()=>{var l;return(l=document.getElementById("file-upload"))==null?void 0:l.click()},children:"Select Files"}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Supports CSV, JSON, Excel files"})]})]}),d.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{className:"text-xs text-gray-600",children:["Uploaded Files (",d.length,")"]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:d.map(l=>e.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(gn,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm text-gray-700",children:l.originalName}),e.jsx("p",{className:"text-xs text-gray-500",children:l.file?c(l.file.size):""})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>o(l.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},l.id))})]})]})}function Cr(){const t=s.useEditorStore(h=>h.card.dataSource),a=s.useEditorStore(h=>h.actions.updateDataSource),[n,r]=M.useState(""),[i,o]=M.useState(""),[c,d]=M.useState("api"),l=()=>{if(!n.trim()||!i.trim()||!t)return;const h={id:`url-${Date.now()}-${Math.random()}`,name:n.trim(),type:"url",connectionId:"default",connectionType:"none",label:n.trim(),description:`URL source of type ${c}`,url:i.trim(),sourceType:c,originalName:n.trim()},j=(t==null?void 0:t.selectedEntities)||[];a({...t,selectedEntities:[...j,h]}),r(""),o(""),d("api")},m=h=>{if(!t)return;const j=(t.selectedEntities||[]).filter(p=>p.id!==h);a({...t,selectedEntities:j})},u=(t==null?void 0:t.selectedEntities)||[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:"URL Sources"}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-gray-50 p-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-gray-600",children:"Source Name"}),e.jsx(s.Input,{placeholder:"e.g., Sales API, Customer Data",value:n,onChange:h=>r(h.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-gray-600",children:"URL"}),e.jsx(s.Input,{placeholder:"https://api.example.com/data",value:i,onChange:h=>o(h.target.value),className:"h-8 text-sm"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-xs text-gray-600",children:"Type"}),e.jsxs("select",{value:c,onChange:h=>d(h.target.value),className:"h-8 w-full rounded-md border border-gray-300 px-2 text-sm",children:[e.jsx("option",{value:"api",children:"API Endpoint"}),e.jsx("option",{value:"csv",children:"CSV File"}),e.jsx("option",{value:"json",children:"JSON File"})]})]}),e.jsxs(s.Button,{onClick:l,disabled:!n.trim()||!i.trim(),size:"sm",className:"w-full",children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Source"]})]})]}),u.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{className:"text-xs text-gray-600",children:["Added Sources (",u.length,")"]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:u.map(h=>e.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(vn,{className:"h-4 w-4 flex-shrink-0 text-gray-500"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm text-gray-700",children:h.name}),e.jsx("p",{className:"truncate text-xs text-gray-500",children:h.url})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 flex-shrink-0 p-0",onClick:()=>m(h.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},h.id))})]})]})}function Us(t,a){var S,x;const n=s.useDashboardStore(N=>N.authToken)||a,{connections:r}=s.useConnections(a),i=s.useEditorStore(N=>{var D,E;return(E=(D=N==null?void 0:N.card)==null?void 0:D.dataSource)==null?void 0:E.connectionId}),o=s.useEditorStore(N=>{var D,E,v;return(v=(E=(D=N==null?void 0:N.card)==null?void 0:D.dataSource)==null?void 0:E.dbSelection)==null?void 0:v.database}),c=s.useEditorStore(N=>{var D,E,v;return(v=(E=(D=N==null?void 0:N.card)==null?void 0:D.dataSource)==null?void 0:E.dbSelection)==null?void 0:v.schema}),d=r==null?void 0:r.find(N=>N.id===i),l=d==null?void 0:d.capabilities,m=((S=l==null?void 0:l.labels)==null?void 0:S.schema)||"Schema";function u(){return!(!i||(d==null?void 0:d.type)==="API"||(d==null?void 0:d.type)==="S3"||!o||l!=null&&l.path.includes("schema")&&!c||t==="view")}const{data:h,isPending:j,error:p,refetch:g}=s.useQuery({queryKey:[t,i,o,c],queryFn:()=>s.getRequest(`https://semaphor.cloud/api/v1/${t}s`,(n==null?void 0:n.accessToken)||"",{connection_id:i,database_name:o,schema_name:c}),enabled:u()}),f=(x=h==null?void 0:h[`${t}s`])==null?void 0:x.map(N=>({connectionId:d==null?void 0:d.id,connectionType:d==null?void 0:d.type,dialect:d==null?void 0:d.dialect,type:t,id:N[`${t}_name`],database:o,schema:c,name:N[`${t}_name`]}));return{isPending:j,error:p,entities:f||[],refetch:g,label:m}}function _e({title:t,message:a}){return e.jsx("div",{className:"rounded-xl border border-destructive/40 bg-destructive/10 p-4 text-destructive shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(rn,{className:"h-6 w-6 flex-shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"text-base font-semibold",children:t}),a&&e.jsx("p",{className:"mt-1 text-sm text-destructive/90",children:a})]})]})})}function Sr(){const{connections:t,isPending:a}=s.useConnections(),n=s.useEditorStore(y=>y.card),r=s.useEditorStore(y=>y.card.dataSource),i=s.useEditorStore(y=>y.actions.updateCard);s.useEditorStore(y=>y.actions.setCard);const[o,c]=M.useState(""),[d,l]=M.useState(""),[m,u]=M.useState(""),h=(r==null?void 0:r.selectedEntities)||[],{entities:j,isPending:p,error:g}=Us("table"),{entities:f}=Us("view"),{dataModels:S,isPending:x,error:N}=Tt(),D=y=>{if(!r)return;const I=t.find(B=>B.id===y);if(!I)return;const T=I.type==="upload"?"upload":I.type==="url"?"url":"database";console.log("Changing connection:",{connectionId:y,connectionType:I.type,newMode:T});const C={...r,connectionId:y,connectionType:I.type,mode:T,dbSelection:{database:"",schema:"",entityType:"table"},selectedEntities:[]};console.log("Updating card with data source:",C),i(n.id,{dataSource:C,connectionId:y})},E=(y,I)=>{var z,O;if(!r)return;const T=h||[],C=T.some(k=>k.name===y&&k.type===I);let B;if(C)B=T.filter(k=>!(k.name===y&&k.type===I));else{const k={connectionId:r.connectionId,connectionType:r.connectionType,type:I,database:((z=r.dbSelection)==null?void 0:z.database)||"",schema:((O=r.dbSelection)==null?void 0:O.schema)||"",name:y};B=[...T,k]}i(n.id,{dataSource:{...r,selectedEntities:B}})},v=y=>{if(!r)return;const I=h||[],T=I.some(B=>B.type==="model"&&B.name===y.name);let C;T?C=I.filter(B=>!(B.type==="model"&&B.name===y.name)):C=[...I,y],i(n.id,{dataSource:{...r,selectedEntities:C}})},b=j.filter(y=>y.name.toLowerCase().includes(o.toLowerCase()));f.filter(y=>y.name.toLowerCase().includes(d.toLowerCase()));const w=S.filter(y=>y.name.toLowerCase().includes(m.toLowerCase()));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:"Connection"}),e.jsxs(s.Select,{value:(r==null?void 0:r.connectionId)||"",onValueChange:D,disabled:a,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:a?"Loading connections...":"Select connection..."})}),e.jsx(s.SelectContent,{children:t.map(y=>e.jsx(s.SelectItem,{value:y.id,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Ne,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{className:"truncate",children:y.name}),e.jsx(s.Badge,{variant:"secondary",className:"flex-shrink-0 text-xs",children:y.type})]})},y.id))})]})]}),(r==null?void 0:r.connectionId)&&e.jsxs(e.Fragment,{children:[r.connectionType==="upload"&&e.jsx(Nr,{}),r.connectionType==="url"&&e.jsx(Cr,{}),r.connectionType!=="upload"&&r.connectionType!=="url"&&e.jsxs(e.Fragment,{children:[e.jsx(vr,{}),e.jsx("div",{className:"space-y-4",children:e.jsx("div",{className:"space-y-2",children:e.jsxs(s.Tabs,{defaultValue:"tables",className:"w-full",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-3",children:[e.jsx(s.TabsTrigger,{value:"tables",children:"Tables"}),e.jsx(s.TabsTrigger,{value:"datamodels",children:"Data Models"}),e.jsx(s.TabsTrigger,{value:"views",children:"Views (Coming soon)"})]}),e.jsxs(s.TabsContent,{value:"tables",className:"space-y-2",children:[e.jsx(s.Input$1,{placeholder:"Search tables...",value:o,onChange:y=>c(y.target.value),className:"h-8 text-sm",disabled:p}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:p?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Loading tables..."}):g?e.jsx(_e,{title:"Error loading tables",message:g.message||"Failed to load tables. Please try again.",onRetry:()=>window.location.reload()}):b.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No tables found"}):b.map(y=>{const I=h.some(T=>T.name===y.name&&T.type==="table");return e.jsxs("div",{className:"flex items-center space-x-2 rounded p-2 hover:bg-gray-50",children:[e.jsx(s.Checkbox,{id:`table-${y.name}`,checked:I,onCheckedChange:()=>E(y.name,"table"),disabled:p}),e.jsx(s.Label,{htmlFor:`table-${y.name}`,children:y.name})]},y.name)})})]}),e.jsxs(s.TabsContent,{value:"datamodels",className:"space-y-2",children:[e.jsx(s.Input$1,{placeholder:"Search data models...",value:m,onChange:y=>u(y.target.value),className:"h-8 text-sm",disabled:x}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:x?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Loading data models..."}):N?e.jsx(_e,{title:"Error loading data models",message:N.message||"Failed to load data models. Please try again.",onRetry:()=>window.location.reload()}):w.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No data models found"}):w.map(y=>{const I=h.some(T=>T.name===y.name&&T.type==="model");return e.jsxs("div",{className:"flex items-center space-x-2 rounded p-2 hover:bg-gray-50",children:[e.jsx(s.Checkbox,{id:`dataModel-${y.name}`,checked:I,onCheckedChange:()=>v(y),disabled:x}),e.jsx(s.Label,{htmlFor:`dataModel-${y.name}`,children:y.name})]},y.name)})})]}),e.jsx(s.TabsContent,{value:"views",className:"space-y-2",children:e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Views support coming soon"})})]})})})]})]})]})}function wr(){const t=s.useEditorStore(g=>g.card.dataSource),a=s.useEditorStore(g=>g.actions.updateDataSource),[n,r]=M.useState(""),{semanticModels:i,isPending:o,error:c}=gr(),{datasets:d,isPending:l,error:m}=jr(t==null?void 0:t.semanticModelId);i.find(g=>g.id===(t==null?void 0:t.semanticModelId));const u=g=>{if(!t)return;const f={connectionId:t.connectionId||"default",connectionType:t.connectionType||"none",mode:"semanticModel",semanticModelId:g};a({...f,selectedEntities:[]})},h=g=>{if(!t)return;const f=d.find(N=>N.id===g);if(!f)return;const S=t.selectedEntities||[],x={id:f.id,name:f.name,label:f.label,description:f.description,type:"dataset",connectionId:"default",connectionType:"none"};a({...t,selectedEntities:[...S,x]})},j=g=>{if(!t)return;const S=(t.selectedEntities||[]).filter(x=>"id"in x&&x.id!==g);a({...t,selectedEntities:S})},p=d.filter(g=>g.name.toLowerCase().includes(n.toLowerCase()));return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:"Semantic Model"}),e.jsxs(s.Select,{value:(t==null?void 0:t.semanticModelId)||"",onValueChange:u,disabled:o,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:o?"Loading semantic models...":"Select semantic model..."})}),e.jsx(s.SelectContent,{children:i.map(g=>e.jsx(s.SelectItem,{value:g.id,children:e.jsxs("div",{className:"flex flex-col items-start",children:[e.jsx("span",{className:"font-medium",children:g.label}),e.jsx("span",{className:"text-xs text-gray-500",children:g.description})]})},g.id))})]}),c&&e.jsx(_e,{title:"Error loading semantic models",message:c.message})]}),(t==null?void 0:t.semanticModelId)&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{className:"text-sm font-medium text-gray-700",children:"Datasets"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Input$1,{placeholder:"Search datasets...",value:n,onChange:g=>r(g.target.value),className:"h-8 text-sm",disabled:l}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-y-auto",children:l?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"Loading datasets..."}):m?e.jsx(_e,{title:"Error loading datasets",message:m.message||"Failed to load datasets. Please try again.",onRetry:()=>window.location.reload()}):p.length===0?e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:n?"No datasets match your search":"No datasets available"}):p.map(g=>{var S;const f=(S=t==null?void 0:t.selectedEntities)==null?void 0:S.some(x=>"id"in x&&x.id===g.id);return e.jsxs("div",{className:"flex items-center space-x-2 rounded p-2 hover:bg-gray-50",children:[e.jsx(s.Checkbox,{id:`dataset-${g.id}`,checked:f,onCheckedChange:()=>{f?j(g.id):h(g.id)},disabled:l}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(s.Label,{htmlFor:`dataset-${g.id}`,className:"font-medium",children:g.label||g.name}),e.jsx("span",{className:"text-xs text-gray-500",children:g.description})]})]},g.id)})})]}),(t==null?void 0:t.selectedEntities)&&t.selectedEntities.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{className:"text-xs text-gray-600",children:["Selected Datasets (",t.selectedEntities.length,")"]}),e.jsx("div",{className:"space-y-1",children:t.selectedEntities.map(g=>{if(g.type!=="dataset"||!("id"in g))return null;const f=g;return e.jsxs("div",{className:"flex items-center justify-between rounded border bg-gray-50 p-2",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm text-gray-700",children:f.label||f.name}),e.jsx("span",{className:"text-xs text-gray-500",children:f.description})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",onClick:()=>j(f.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]},f.id)})})]})]})]})}function kr(){const t=s.useEditorStore(n=>n.card.dataSource),a=s.useEditorStore(n=>n.actions.updateDataSource);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-2",children:e.jsx(s.Tabs,{defaultValue:t==null?void 0:t.mode,value:t==null?void 0:t.mode,onValueChange:n=>{a({...t,connectionId:(t==null?void 0:t.connectionId)||"",connectionType:(t==null?void 0:t.connectionType)||"",mode:n})},className:"w-full",children:e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"semanticModel",children:"Semantic Model"}),e.jsx(s.TabsTrigger,{value:"database",children:"Direct Source"})]})})}),(t==null?void 0:t.mode)==="semanticModel"&&e.jsx(wr,{}),(t==null?void 0:t.mode)==="database"&&e.jsx(Sr,{})]})}function Er(t){return t.flatMap(a=>a.columns.map(n=>({id:`${a.entityId}-${n.name}`,name:n.name,dataType:n.dataType,qualifiedEntityName:a.qualifiedEntityName,label:n.label||s.toTitleCase(n.name),description:n.description,entityId:a.entityId,entityName:a.entityName,entityType:a.entityType})))}function Ir(t){if(t.entityType==="table"||t.entityType==="view"){if(t.database&&t.schema)return`${t.database}.${t.schema}.${t.entityName}`;if(t.database)return`${t.database}.${t.entityName}`}return t.entityName}function De(t){var S;const a=s.useDashboardStore(x=>x.authToken)||t,{hasSchemaSupport:n}=s.useSelectedConnection(t),r=s.useEditorStore(x=>{var N;return(N=x.card.dataSource)==null?void 0:N.connectionId}),i=s.useEditorStore(x=>{var N,D;return(D=(N=x.card.dataSource)==null?void 0:N.selectedEntities)==null?void 0:D.filter(E=>E.type==="model")}),o=s.useEditorStore(x=>{var N,D;return(D=(N=x.card.dataSource)==null?void 0:N.selectedEntities)==null?void 0:D.filter(E=>E.type==="table"||E.type==="view")});function c(x){return x.entityType==="model"?!!r&&!!x.entityId:x.entityType==="table"||x.entityType==="view"?n?!!r&&!!x.entityId&&!!x.database&&!!x.schema:!!r&&!!x.entityId&&!!x.database:!1}const d=(i==null?void 0:i.map(x=>({entityId:x.id,entityName:x.name,entityType:"model",label:x.label,description:x.description})))||[],l=(o==null?void 0:o.map(x=>({entityId:x.name,entityName:x.name,entityType:x.type,database:x.database,schema:x.schema,label:"",description:""})))||[],m=[...d,...l],u=qt({queries:m.map(x=>({queryKey:["columns",r,x],queryFn:()=>s.getRequest("https://semaphor.cloud/api/v1/columns",(a==null?void 0:a.accessToken)||"",x.entityType==="model"?{connection_id:r,datamodel_id:x.entityId,database_name:"",schema_name:"",table_name:""}:{connection_id:r,datamodel_id:"",database_name:x.database,schema_name:x.schema,table_name:x.entityName}),enabled:!!r&&c(x)}))}),h=u.some(x=>x.isPending),j=u.some(x=>x.isError),p=(S=u.find(x=>x.isError))==null?void 0:S.error,g=u.map((x,N)=>{var v;const D=m[N],E=Ir(D);return{entityId:D.entityId,entityType:D.entityType,entityName:D.entityName,label:D.label,description:D.description,qualifiedEntityName:E,columns:(v=x.data)==null?void 0:v.columns.map(b=>({id:`${D.entityId}-${b.column_name}`,name:b.column_name,dataType:b.data_type,label:b.label||s.toLabel(b.column_name),description:b.description||"",qualifiedEntityName:E,entityId:D.entityId,entityName:D.entityName,entityType:D.entityType}))}}).filter(x=>{var N;return((N=x==null?void 0:x.columns)==null?void 0:N.length)>0})||[],f=Er(g);return{columnGroups:g,columns:f,isLoading:h,hasError:j,error:p,refetch:()=>{u.forEach(x=>x.refetch())}}}function Tr({field:t}){const{attributes:a,listeners:n,setNodeRef:r,transform:i,transition:o,isDragging:c}=s.useSortable({id:t.id}),[d,l]=M.useState(!1),m={transform:s.CSS.Transform.toString(i),transition:o},u=s.getDataType(t.dataType),j=(p=>{const g=(p||"").toLowerCase();switch(s.getDataType(g)){case"number":return js;case"date":return s.Calendar;case"boolean":return nt;case"json":return cn;case"geo":return Ln;default:return at}})(t.dataType);return e.jsxs("div",{ref:r,style:m,...a,...n,className:`group/container overflow-hidden rounded-lg transition-all ${c?"scale-95 opacity-50":"border border-transparent hover:border-blue-200 hover:bg-blue-50 dark:hover:border-blue-800 dark:hover:bg-blue-950"}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1 p-2",onClick:()=>l(!d),children:[e.jsx("div",{className:"flex-shrink-0 hover:cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"invisible size-3.5 text-gray-400 group-hover/container:visible"})}),e.jsx(j,{className:s.cn("size-3.5 flex-shrink-0 text-gray-500",u==="string"?"text-blue-500":"",u==="number"?"text-green-500":"",u==="date"?"text-purple-500":"",u==="boolean"?"text-orange-500":"")}),e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:e.jsx("span",{className:`block text-sm dark:text-muted-foreground ${d?"whitespace-normal break-words":"truncate"}`,children:t.name})})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium",children:t.label||t.name}),t.label&&t.label!==t.name&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Name: ",t.name]}),e.jsx("p",{className:"text-xs text-gray-500",children:t.qualifiedEntityName?`${t.qualifiedEntityName}.${t.name}`:t.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Type: ",t.dataType]})]})})]})}),e.jsx("button",{onClick:p=>{p.stopPropagation(),l(!d)},className:"invisible flex-shrink-0 text-gray-400 hover:text-gray-600 group-hover/container:visible",children:d?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronRight,{className:"h-4 w-4"})})]}),d&&e.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:e.jsx(s.Card,{className:"",children:e.jsxs(s.CardContent,{className:"space-y-2 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.label||t.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qn,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:t.name})]}),e.jsx(s.Badge,{variant:"outline",className:"mt-2 text-xs",children:t.dataType})]})})})]})}function Dr({entityGroup:t,fields:a,isOpen:n,onToggle:r}){return e.jsxs(s.Collapsible,{open:n,onOpenChange:r,children:[e.jsxs(s.CollapsibleTrigger,{className:"flex w-full items-center gap-2 rounded-md px-3 py-2 hover:bg-muted",children:[e.jsx("span",{className:"flex-1 text-left text-sm font-medium",children:t.label||t.entityName}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",a.length,")"]}),n?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronRight,{className:"h-4 w-4"})]}),e.jsx(s.CollapsibleContent,{className:"mt-1 space-y-1",children:e.jsx(s.SortableContext,{items:a.map(i=>i.id),strategy:s.verticalListSortingStrategy,children:a.map(i=>e.jsx(Tr,{field:i},i.id))})})]})}function Mr(){const[t,a]=M.useState(""),[n,r]=M.useState(new Set),[i,o]=M.useState("all"),c=s.useEditorStore(E=>E.card.dataSource),{columns:d=[],columnGroups:l=[],isLoading:m,error:u}=De(),h=d.filter(E=>E.name.toLowerCase().includes(t.toLowerCase())||E.dataType.toLowerCase().includes(t.toLowerCase())||E.qualifiedEntityName&&E.qualifiedEntityName.toLowerCase().includes(t.toLowerCase())),j=E=>E.dataType==="number"||E.dataType==="integer"||E.dataType==="float"||E.dataType==="decimal"||E.dataType==="currency"?"metrics":"dimensions",g=(i==="all"?h:h.filter(E=>j(E)===i)).reduce((E,v)=>{const b=v.qualifiedEntityName||"Other Fields";return E[b]||(E[b]={label:s.toLabel(v.entityName),fields:[]}),E[b].fields.push(v),E},{});M.useEffect(()=>{const E=Object.keys(g);r(new Set(E))},[Object.keys(g).join(",")]);const f=E=>{const v=new Set(n);v.has(E)?v.delete(E):v.add(E),r(v)},S=h.filter(E=>j(E)==="dimensions").length,x=h.filter(E=>j(E)==="metrics").length,N=h.filter(E=>j(E)==="calculated").length,D=h.length>0;return m?e.jsxs("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:[e.jsx(ce,{className:"h-8 w-8 animate-spin text-gray-400"}),e.jsx("span",{className:"mt-2 text-sm text-gray-500",children:"Loading fields..."})]}):u?e.jsxs("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:[e.jsx(Ne,{className:"mb-4 h-12 w-12 text-red-300"}),e.jsx("p",{className:"mb-2 text-sm text-red-500",children:"Error loading fields"}),e.jsx("p",{className:"px-4 text-center text-xs text-red-400",children:u.message||"Failed to load column data"})]}):!c||!c.selectedEntities||c.selectedEntities.length===0?e.jsx(s.ScrollArea,{className:"h-[calc(100vh-200px)] w-[290px]",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(Ne,{className:"mb-4 h-12 w-12 text-gray-300"}),e.jsx("p",{className:"mb-2 text-sm text-gray-500",children:"No data source selected"}),e.jsx("p",{className:"px-4 text-xs text-gray-400",children:"Select a table, view, or dataset from the data source panel to see available fields"})]})}):e.jsxs("div",{className:"mt-2 flex h-[calc(100vh-200px)] w-[290px] grow flex-col gap-2 pb-6",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 p-1 pb-0",children:[d.length>0&&e.jsx("div",{className:"mb-4",children:e.jsx(s.Input$1,{type:"text",placeholder:"Search fields...",value:t,onChange:E=>a(E.target.value)})}),D&&e.jsx(s.Tabs,{defaultValue:"all",value:i,onValueChange:E=>o(E),className:"mb-4",children:e.jsxs(s.TabsList,{className:"grid h-9 w-full grid-cols-4",children:[e.jsxs(s.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:h.length})]}),e.jsxs(s.TabsTrigger,{value:"dimensions",className:"text-xs",children:[e.jsx(wn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:S})]}),e.jsxs(s.TabsTrigger,{value:"metrics",className:"text-xs",children:[e.jsx(ms,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:x})]}),e.jsxs(s.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(tn,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:N})]})]})})]}),e.jsxs(s.ScrollArea,{className:"flex-1",children:[e.jsxs("div",{className:"space-y-2 p-1 pt-0",children:[Object.entries(g).map(([E,v])=>{const b=l.find(w=>w.entityName===E)||{entityName:E,label:v.label};return e.jsx(Dr,{entityGroup:b,fields:v.fields,isOpen:n.has(E),onToggle:()=>f(E)},E)}),Object.keys(g).length===0&&d.length===0&&e.jsxs("div",{className:"py-8 text-center text-sm text-gray-500",children:[e.jsx("p",{children:"No fields found for selected data source"}),e.jsx("p",{className:"mt-1 text-xs text-gray-400",children:"Try selecting different data sources"})]}),Object.keys(g).length===0&&d.length>0&&e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"})]}),e.jsx(s.ScrollBar,{orientation:"horizontal"}),e.jsx(s.ScrollBar,{orientation:"vertical"})]})]})}function Ar(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(Mr,{})," "]})}function Lr({initialJoinPlan:t,availableDataSources:a}){const[n,r]=M.useState(t),[i,o]=M.useState(new Set),c=()=>{const b=n.joins.length>0?Math.max(...n.joins.map(y=>y.sequence))+1:1,w={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:b,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...n,joins:[...n.joins,w]}),o(new Set([...i,w.id]))},d=b=>{r({...n,joins:n.joins.filter(w=>w.id!==b)}),o(new Set([...i].filter(w=>w!==b)))},l=(b,w)=>{var C,B;const y=n.joins.find(z=>z.id===b);if(!y)return;const I={...y,...w},T=n.joins.map(z=>z.id===b?I:z);if((C=I.source)!=null&&C.name&&((B=I.target)!=null&&B.name)&&I.joinKeyGroups[0].keys.length===0){const z=a.find(R=>{var P;return R.name===((P=I.source)==null?void 0:P.name)}),O=a.find(R=>{var P;return R.name===((P=I.target)==null?void 0:P.name)}),k={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",entityId:(z==null?void 0:z.name)||"",entityName:(z==null?void 0:z.name)||"",entityType:(z==null?void 0:z.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(O==null?void 0:O.name)||"",entityName:(O==null?void 0:O.name)||"",entityType:(O==null?void 0:O.type)||"table"},operator:"="},A=[...I.joinKeyGroups];A[0]={...A[0],keys:[k]},I.joinKeyGroups=A,T[T.findIndex(R=>R.id===b)]=I}r({...n,joins:T})};return{joinPlan:n,expandedJoins:i,setJoinPlan:r,addJoin:c,removeJoin:d,updateJoin:l,moveJoinUp:b=>{const w=n.joins.findIndex(y=>y.id===b);if(w>0){const y=[...n.joins],I={...y[w]},T={...y[w-1]};y[w]=T,y[w-1]=I,y.forEach((B,z)=>{B.sequence=z+1});const C={...n,joins:y};r(C)}},moveJoinDown:b=>{const w=n.joins.findIndex(y=>y.id===b);if(w<n.joins.length-1){const y=[...n.joins],I={...y[w]},T={...y[w+1]};y[w]=T,y[w+1]=I,y.forEach((B,z)=>{B.sequence=z+1});const C={...n,joins:y};r(C)}},toggleJoinExpansion:b=>{const w=new Set(i);w.has(b)?w.delete(b):w.add(b),o(w)},getAvailableSourceEntities:b=>{if(n.joins.length===0)return a;const w=n.joins.findIndex(I=>I.id===b);if(w===0)return a;const y=new Set;return n.baseEntity.name&&y.add(n.baseEntity.name),n.joins.slice(0,w).forEach(I=>{y.add(I.source.name),y.add(I.target.name)}),a.filter(I=>y.has(I.name))},getAvailableTargetEntities:b=>a.filter(w=>w.name!==b),addJoinKeyGroup:b=>{const w=n.joins.find(I=>I.id===b);if(!w)return;const y=[...w.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];l(b,{joinKeyGroups:y})},updateGroupOperator:(b,w,y)=>{const I=n.joins.find(C=>C.id===b);if(!I)return;const T=[...I.joinKeyGroups];T[w]={...T[w],operator:y},l(b,{joinKeyGroups:T})},removeJoinKeyGroup:(b,w)=>{const y=n.joins.find(T=>T.id===b);if(!y)return;const I=[...y.joinKeyGroups];I.splice(w,1),l(b,{joinKeyGroups:I})},addJoinKey:(b,w)=>{const y=n.joins.find(z=>z.id===b);if(!y)return;const I=a.find(z=>z.name===y.source.name),T=a.find(z=>z.name===y.target.name),C=[...y.joinKeyGroups],B={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",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:"",entityId:(T==null?void 0:T.name)||"",entityName:(T==null?void 0:T.name)||"",entityType:(T==null?void 0:T.type)||"table"},operator:"="};C[w]={...C[w],keys:[...C[w].keys,B]},l(b,{joinKeyGroups:C})},updateJoinKey:(b,w,y,I,T)=>{const C=n.joins.find(A=>A.id===b);if(!C)return;const B=a.find(A=>A.name===C.source.name),z=a.find(A=>A.name===C.target.name),O=[...C.joinKeyGroups],k=O[w].keys[y];I==="sourceColumnName"&&B?O[w].keys[y]={...k,source:{...k.source,name:T}}:I==="targetColumnName"&&z?O[w].keys[y]={...k,target:{...k.target,name:T}}:I==="operator"&&(O[w].keys[y]={...k,operator:T}),l(b,{joinKeyGroups:O})},removeJoinKey:(b,w,y)=>{const I=n.joins.find(C=>C.id===b);if(!I)return;const T=[...I.joinKeyGroups];T[w].keys.splice(y,1),l(b,{joinKeyGroups:T})},generateSQLPreview:()=>{const b=[...n.joins].sort((I,T)=>I.sequence-T.sequence),w=n.baseEntity;if(!w.name)return"SELECT * FROM table -- Please select a base entity";let y=`SELECT *
|
|
435
|
+
FROM ${w.name}`;return b.forEach(I=>{const T=a.find(z=>z.name===I.target.name);if(!T)return;const C=I.joinKeyGroups.filter(z=>z.keys&&z.keys.length>0).map(z=>{const O=z.keys.filter(k=>{var A,R,P,$;return((A=k.source)==null?void 0:A.name)&&((R=k.target)==null?void 0:R.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 O.length>1?`(${O.join(` ${z.operator} `)})`:O[0]}).filter(Boolean),B=C.length>1?C.join(" OR "):C[0]||"condition_here";y+=`
|
|
436
|
+
${I.joinType} JOIN ${T.name}
|
|
437
|
+
ON ${B}`}),y},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(I=>!I.source.name||!I.target.name)||n.joins.some(I=>I.joinKeyGroups.some(T=>T.keys.length===0))||n.joins.some(I=>I.joinKeyGroups.some(T=>T.keys.some(C=>!C.source.name||!C.target.name||!C.operator))))}}function Or({joinPlan:t,availableDataSources:a,onSave:n,onRemove:r,onCancel:i}){const{setCardConfig:o}=s.useEditorActions();s.useEditorStore(C=>C.card.config);const{columnGroups:c}=De(),{joinPlan:d,expandedJoins:l,setJoinPlan:m,addJoin:u,removeJoin:h,updateJoin:j,moveJoinUp:p,moveJoinDown:g,toggleJoinExpansion:f,getAvailableSourceEntities:S,getAvailableTargetEntities:x,addJoinKeyGroup:N,updateGroupOperator:D,removeJoinKeyGroup:E,addJoinKey:v,updateJoinKey:b,removeJoinKey:w,generateSQLPreview:y,isValidConfiguration:I}=Lr({initialJoinPlan:t,availableDataSources:a}),T=C=>{const B=c.find(z=>z.entityName===C);return(B==null?void 0:B.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:d.baseEntity.name,onValueChange:C=>{const B=a.find(z=>z.name===C);m({...d,baseEntity:{connectionId:(B==null?void 0:B.connectionId)||"",connectionType:(B==null?void 0:B.connectionType)||"none",type:(B==null?void 0:B.type)||"table",name:C,database:B==null?void 0:B.database,schema:B==null?void 0:B.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:a.map(C=>e.jsx(s.SelectItem,{value:C.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:C.type}),C.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},C.name))})]}),e.jsx("p",{className:"text-xs text-gray-500",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 bg-gray-100 p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-gray-600",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:y()})]}),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 (",d.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:u,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),d.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-gray-500",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:d.joins.map(C=>{const B=a.find(k=>k.name===C.source.name),z=a.find(k=>k.name===C.target.name),O=l.has(C.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:C.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",C.sequence,B&&z&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",B.name," → ",z.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(C.id),disabled:C.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>g(C.id),disabled:C.sequence===d.joins.length,children:e.jsx($e,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>f(C.id),children:O?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:()=>h(C.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),O&&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:C.source.name,onValueChange:k=>{const A=a.find(R=>R.name===k);j(C.id,{source:{connectionId:(A==null?void 0:A.connectionId)||"",connectionType:(A==null?void 0:A.connectionType)||"none",type:(A==null?void 0:A.type)||"table",name:k,database:A==null?void 0:A.database,schema:A==null?void 0:A.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:S(C.id).map(k=>e.jsx(s.SelectItem,{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:C.joinType,onValueChange:k=>j(C.id,{joinType:k}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:C.target.name,onValueChange:k=>{const A=a.find(R=>R.name===k);j(C.id,{target:{connectionId:(A==null?void 0:A.connectionId)||"",connectionType:(A==null?void 0:A.connectionType)||"none",type:(A==null?void 0:A.type)||"table",name:k,database:A==null?void 0:A.database,schema:A==null?void 0:A.schema}})},disabled:!C.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:C.source.name?x(C.source.name).map(k=>e.jsx(s.SelectItem,{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===C.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},k.name)):[]})]})]})]}),C.source.name&&C.target.name&&B&&z&&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:()=>N(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),C.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:C.joinKeyGroups.map((k,A)=>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 ",A+1]}),A>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:R=>D(C.id,A,R),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",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"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(C.id,A),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((R,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:R.source.name,onValueChange:$=>b(C.id,A,P,"sourceColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:T(C.source.name).map($=>e.jsx(s.SelectItem,{value:$.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:$.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:$.dataType})]})},$.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:R.operator,onValueChange:$=>b(C.id,A,P,"operator",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{value:"=",children:"="}),e.jsx(s.SelectItem,{value:"<",children:"<"}),e.jsx(s.SelectItem,{value:">",children:">"}),e.jsx(s.SelectItem,{value:"<=",children:"<="}),e.jsx(s.SelectItem,{value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:R.target.name,onValueChange:$=>b(C.id,A,P,"targetColumnName",$),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:T(C.target.name).map($=>e.jsx(s.SelectItem,{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(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>w(C.id,A,P),children:e.jsx(s.X,{className:"size-3.5"})})]},R.id||P))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>v(C.id,A),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},k.id))})]})]})]},C.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),i()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>n(d),disabled:!I(),children:"Save"})]})]})}function Ys({children:t,open:a,onOpenChange:n,joinPlan:r,availableDataSources:i,onRemove:o,onSave:c,onCancel:d}){return e.jsxs(s.Dialog,{open:a,onOpenChange:n,children:[e.jsx(s.DialogContent,{className:"max-w-4xl",children:e.jsx(Or,{joinPlan:r,availableDataSources:i,onSave:c,onCancel:d,onRemove:o})}),t]})}function Fr({joins:t,baseEntityId:a,availableDataSources:n,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",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 i=[...t].sort((c,d)=>c.sequence-d.sequence),o=n.find(c=>c.name===a);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:o==null?void 0:o.type}),e.jsx("span",{className:"text-xs font-medium",children:o==null?void 0:o.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),i.map(c=>{const d=n.find(l=>l.name===c.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:c.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:d==null?void 0:d.type}),e.jsx("span",{className:"text-xs font-medium",children:d==null?void 0:d.name})]})]},c.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((i,o)=>i.sequence-o.sequence).map((i,o)=>{const c=n.find(l=>l.name===i.source.name),d=n.find(l=>l.name===i.target.name);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted p-2 text-left",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:o+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:i.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[c==null?void 0:c.name," → ",d==null?void 0:d.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[i.joinKeyGroups.reduce((l,m)=>l+m.keys.length,0)," ","condition",i.joinKeyGroups.reduce((l,m)=>l+m.keys.length,0)>1?"s":""]})]},i.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function zr(){var h,j;De(),s.useEditorStore(p=>p.card.dataSource);const t=s.useEditorStore(p=>p.frame),a=s.useEditorStore(p=>p.card),n=s.useEditorStore(p=>p.actions.updateCardConfig),r=((h=a==null?void 0:a.config)==null?void 0:h.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[i,o]=M.useState(!1),c=((j=a==null?void 0:a.dataSource)==null?void 0:j.selectedEntities)||[],d=p=>{t.activeCardId&&(n(t.activeCardId,{...a==null?void 0:a.config,joinPlan:p}),o(!1))},l=()=>{n(t.activeCardId,{...a==null?void 0:a.config,joinPlan:void 0})},m=()=>{o(!1)},u=()=>{const p=[...r.joins].sort((S,x)=>S.sequence-x.sequence),g=r.baseEntity;if(!g.name)return"SELECT * FROM table -- Please select a base entity";let f=`SELECT *
|
|
438
|
+
FROM ${g.name}`;return p.forEach(S=>{const x=c.find(E=>E.name===S.target.name);if(!x)return;const N=S.joinKeyGroups.filter(E=>E.keys&&E.keys.length>0).map(E=>{const v=E.keys.filter(b=>{var w,y,I,T;return((w=b.source)==null?void 0:w.name)&&((y=b.target)==null?void 0:y.name)&&((I=b.source)==null?void 0:I.entityName)&&((T=b.target)==null?void 0:T.entityName)}).map(b=>`${b.source.entityName}.${b.source.name} ${b.operator} ${b.target.entityName}.${b.target.name}`);return v.length>1?`(${v.join(` ${E.operator} `)})`:v[0]}).filter(Boolean),D=N.length>1?N.join(" OR "):N[0]||"condition_here";f+=`
|
|
439
|
+
${S.joinType} JOIN ${x.name}
|
|
440
|
+
ON ${D}`}),f};return c.length<2?null:e.jsx(e.Fragment,{children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[r.joins.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.TooltipProvider$1,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>o(!0),children:[e.jsx(En,{className:s.cn("mr-1 h-3 w-3",{"text-blue-500":r.joins.length>0,"text-gray-500":r.joins.length===0})}),"Join",r.joins.length>1?"s":""," (",r.joins.length,")"]})}),e.jsx(s.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(Fr,{joins:r.joins,baseEntityId:r.baseEntity.name,availableDataSources:c,generateSQLPreview:u})})]})}),e.jsx(Ys,{open:i,onOpenChange:o,joinPlan:r,availableDataSources:c,onSave:d,onCancel:m,onRemove:l,children:e.jsx("div",{})})]}),r.joins.length===0&&e.jsx(Ys,{open:i,onOpenChange:o,joinPlan:r,availableDataSources:c,onSave:d,onCancel:m,onRemove:l,children:e.jsxs(s.Button,{onClick:()=>o(!0),variant:"outline",className:"h-6 text-xs font-semibold",children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Configure Join"]})})]})})})}function Br({selectedEntities:t,onDeselectEntity:a}){return t.length===0?null:e.jsxs("div",{className:"mb-4",children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium text-gray-700",children:["Selected Entities (",t.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:t.map((n,r)=>e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[e.jsxs("span",{className:"mr-1 text-gray-500",children:["[",n.type,"]"]}),n.name,e.jsx("button",{onClick:i=>{i.stopPropagation(),a(n)},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 opacity-0 transition-opacity hover:bg-red-100 group-hover:opacity-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 text-red-500"})})]},`${n.type}-${n.name}-${r}`))})]})}function Rr(){const[t,a]=M.useState(!1),[n,r]=M.useState(!0),i=s.useEditorStore(m=>m.card.dataSource);s.useEditorStore(m=>m.card);const{updateDataSource:o}=s.useEditorActions(),c={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},d=(i||c).selectedEntities||[],l=m=>{if(!i)return;const u=d.filter(h=>!(h.name===m.name&&h.type===m.type));o({...i,selectedEntities:u})};return e.jsxs("div",{className:"flex w-80 flex-col border-r bg-background",children:[e.jsxs("div",{className:"",children:[e.jsx("div",{className:s.cn("p-4",{"pb-0":!n}),children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex cursor-pointer items-center gap-2",onClick:()=>r(!n),children:[n?e.jsx(s.ChevronDown,{className:"h-4 w-4 text-gray-500"}):e.jsx(s.ChevronRight,{className:"h-4 w-4 text-gray-500"}),e.jsx(Ne,{className:"h-5 w-5 text-cyan-600"}),e.jsx("h2",{className:"font-semibold text-gray-900",children:"Data Source"})]}),e.jsxs(s.Dialog,{open:t,onOpenChange:a,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-8",children:[e.jsx(s.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Add"]})}),e.jsx(s.DialogContent,{className:"flex max-w-2xl flex-col",children:e.jsxs("div",{children:[e.jsxs(s.DialogHeader,{className:"flex-shrink-0",children:[e.jsx(s.DialogTitle,{children:"Configure Data Source"}),e.jsx(s.DialogDescription$1,{children:"Select data sets to analyze"})]}),e.jsx("div",{className:"flex-1 grow overflow-y-auto py-4",children:e.jsx(kr,{})}),e.jsx(Br,{selectedEntities:d,onDeselectEntity:l}),e.jsx(s.DialogFooter,{className:"flex-shrink-0",children:e.jsx("div",{className:"flex justify-end",children:e.jsx(s.Button,{onClick:()=>{a(!1),o(i||c)},disabled:d.length===0,children:"Add Data"})})})]})})]})]})}),e.jsxs("div",{className:`overflow-hidden px-4 ${n?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[d.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[d.slice(0,3).map((m,u)=>e.jsxs(s.Badge,{variant:"secondary",className:"group relative cursor-pointer pr-6 text-xs transition-colors hover:border-red-200 hover:bg-red-50 dark:hover:border-red-800 dark:hover:bg-red-950",children:[m.name,e.jsx("button",{onClick:h=>{h.stopPropagation(),l(m)},className:"absolute right-1 top-1/2 -translate-y-1/2 rounded-full p-0.5 opacity-0 transition-opacity hover:bg-red-100 group-hover:opacity-100",children:e.jsx(s.X,{className:"h-2.5 w-2.5 text-red-500"})})]},`${m.type}-${m.name}-${u}`)),d.length>3&&e.jsxs(s.Badge,{variant:"outline",className:"text-xs",children:["+",d.length-3," more"]})]}),e.jsx(zr,{})]})]}),e.jsx(Ar,{})]})}const Pr=[{id:"table",icon:Je,label:"Table"},{id:"bar",icon:Ge,label:"Bar Chart"},{id:"line",icon:He,label:"Line Chart"},{id:"stackedBar",icon:us,label:"Stacked Bar Chart"},{id:"stackedLine",icon:Ds,label:"Stacked Line Chart"},{id:"scatter",icon:ps,label:"Scatter Chart"},{id:"bubble",icon:Is,label:"Bubble Chart"},{id:"pie",icon:xs,label:"Pie Chart"},{id:"doughnut",icon:fs,label:"Doughnut Chart"},{id:"funnel",icon:Ts,label:"Funnel Chart"},{id:"radar",icon:bs,label:"Radar Chart"},{id:"polarArea",icon:Es,label:"Polar Area Chart"},{id:"tornado",icon:Ns,label:"Tornado Chart"},{id:"range",icon:hs,label:"Range Chart"},{id:"kpi",icon:Ms,label:"KPI"},{id:"text",icon:Qs,label:"Text"},{id:"map",icon:ys,label:"Map"},{id:"custom",icon:vs,label:"Custom"}];function Vr({selectedChart:t,onChartChange:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:i}=s.useEditorStore(m=>m.actions),{setCardCustomCfg:o,setCustomCardPreferences:c,setQueryConfig:d}=s.useEditorActions();function l(m){o(null),r({}),n(m),["kpi","custom","text","map"].includes(m)&&(i(!0),d(void 0)),a(m)}return e.jsx("div",{className:"mb-6",children:e.jsxs(s.Select,{value:t,onValueChange:l,children:[e.jsx(s.SelectTrigger,{className:"w-full",children:e.jsx(s.SelectValue,{placeholder:"Select chart type"})}),e.jsx(s.SelectContent,{children:Pr.map(m=>{const u=m.icon;return e.jsx(s.SelectItem,{value:m.id,className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(u,{className:"h-4 w-4"}),e.jsx("span",{children:m.label})]})},m.id)})})]})})}const Dt=({dataType:t})=>{const a=s.getDataType(t);return a==="string"?e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-sm bg-blue-500 text-xs text-white",children:"T"}):a==="number"?e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-sm bg-green-500 text-xs text-white",children:"#"}):a==="date"?e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-sm bg-purple-500 text-xs text-white",children:"D"}):a==="boolean"?e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-sm bg-orange-500 text-xs text-white",children:"B"}):e.jsx("span",{className:"flex h-4 w-4 items-center justify-center rounded-sm bg-gray-500 text-xs text-white",children:"?"})};function qr({label:t,onLabelChange:a}){const[n,r]=M.useState(t??""),[i,o]=M.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Display Label"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:"Display label...",value:i?n:t??"",onChange:c=>{r(c.target.value),o(!0)},onFocus:()=>o(!0),onClick:c=>c.stopPropagation(),className:"h-8 text-xs",onKeyDown:c=>{c.key==="Enter"&&i&&n!==(t??"")?(a(n),o(!1)):c.key==="Escape"&&(r(t??""),o(!1))},"aria-label":"Edit display label"}),i&&n!==(t??"")&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm label",onClick:()=>{a(n),o(!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 label edit",onClick:()=>{r(t??""),o(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function _r({aliasTemplate:t,onAliasTemplateChange:a}){const[n,r]=M.useState(t),[i,o]=M.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Alias Template"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Input$1,{placeholder:"e.g. Min Sales in {{region}}",value:i?n:t,onChange:c=>{r(c.target.value),o(!0)},onFocus:()=>o(!0),className:"h-8 text-xs",onKeyDown:c=>{c.key==="Enter"&&i&&n!==t?(a(n),o(!1)):c.key==="Escape"&&(r(t),o(!1))},"aria-label":"Edit alias template"}),i&&n!==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:()=>{a(n),o(!1)},children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{r(t),o(!1)},children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function $r({valueAliases:t,onValueAliasesChange:a}){const[n,r]=M.useState(null),[i,o]=M.useState(""),[c,d]=M.useState(""),l=()=>{a({...t,"":""})},m=h=>{const j={...t};delete j[h],a(j)},u=h=>{const j={...t};delete j[h],j[i]=c,a(j),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(t).map(([h,j],p)=>e.jsx("div",{className:"flex items-center gap-2",children:n===h?e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:i,onChange:g=>o(g.target.value),className:"h-8 w-24 text-xs",onKeyDown:g=>{g.key==="Enter"?u(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:c,onChange:g=>d(g.target.value),className:"h-8 w-24 text-xs",onKeyDown:g=>{g.key==="Enter"?u(h):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>u(h),children:e.jsx(s.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(s.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>r(null),children:e.jsx(s.X,{className:"h-4 w-4 text-gray-400"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Input$1,{placeholder:"Value key",value:h,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),o(h),d(j)},"aria-label":"Edit value alias key"}),e.jsx(s.Input$1,{placeholder:"Alias label",value:j,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(h),o(h),d(j)},"aria-label":"Edit value alias label"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>m(h),"aria-label":"Remove value alias",children:e.jsx(s.X,{className:"h-3 w-3"})})]})},h+p)),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:l,children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function Gr({field:t,zone:a,onRemove:n,onLabelChange:r,onAliasTemplateChange:i,onValueAliasesChange:o,onAggregationChange:c,onDateFormatChange:d,onGranularityChange:l,hasPivotColumns:m=!1}){const{attributes:u,listeners:h,setNodeRef:j,transform:p,transition:g,isDragging:f}=s.useSortable({id:t.id}),[S,x]=M.useState(!1),[N,D]=M.useState(t.dateFormat||"YYYY-MM-DD"),[E,v]=M.useState(t.customFormat||""),[b,w]=M.useState(!!t.customFormat),[y,I]=M.useState(t.granularity||"day"),[T,C]=M.useState(t.aliasTemplate||""),[B,z]=M.useState(t.valueAliases||{}),O=F=>{F==="custom"?w(!0):(w(!1),D(F),a==="groupBy"&&d&&d(F,""))},k=F=>{v(F),a==="groupBy"&&d&&d("custom",F)},A=F=>{I(F),a==="groupBy"&&l&&l(F)},R=F=>{C(F),i&&i(F)},P=F=>{z(F),o&&o(F)},$={transform:s.CSS.Transform.toString(p),transition:g},Y=s.getDataType(t.dataType),V=Y==="date",L=[{value:"YYYY-MM-DD",label:"2024-01-15 (YYYY-MM-DD)"},{value:"MM/DD/YYYY",label:"01/15/2024 (MM/DD/YYYY)"},{value:"DD/MM/YYYY",label:"15/01/2024 (DD/MM/YYYY)"},{value:"MMMM DD, YYYY",label:"January 15, 2024 (MMMM DD, YYYY)"},{value:"MMM DD, YYYY",label:"Jan 15, 2024 (MMM DD, YYYY)"},{value:"DD MMM YYYY",label:"15 Jan 2024 (DD MMM YYYY)"},{value:"YYYY-MM",label:"2024-01 (YYYY-MM)"},{value:"MMMM YYYY",label:"January 2024 (MMMM YYYY)"},{value:"custom",label:"Custom Format..."}];return e.jsxs("div",{ref:j,style:$,...u,...h,className:`group flex w-full flex-col gap-2 rounded border border-border bg-background p-2 transition-all hover:shadow-sm dark:border-gray-800 ${f?"z-50 scale-95 opacity-50":"border-slate-200"} ${a==="filters"?"cursor-default":"cursor-move"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.GripVertical,{className:"h-3 w-3"}),e.jsx(Dt,{dataType:Y}),e.jsx("span",{className:"flex-1 overflow-hidden truncate text-sm",children:t.label||t.name}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:F=>{F.stopPropagation(),x(!S)},children:e.jsx(s.ChevronDown,{className:`h-3 w-3 transition-transform ${S?"rotate-180":""}`})}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:F=>{F.stopPropagation(),n()},children:e.jsx(s.X,{className:"h-3 w-3"})})]}),S&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("span",{className:"flex-1 overflow-hidden truncate px-0.5 text-xs text-gray-500",children:`${t.entityName}.${t.name}`}),a!=="pivotBy"&&e.jsx(qr,{label:t.label??"",onLabelChange:r}),V&&a!=="groupBy"&&e.jsx("div",{className:"space-y-1",children:e.jsxs(s.Select,{defaultValue:"day",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"}),e.jsx(s.SelectItem,{value:"quarter",children:"Quarter"}),e.jsx(s.SelectItem,{value:"year",children:"Year"})]})]})}),V&&a==="groupBy"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Granularity"}),e.jsxs(s.Select,{value:y,onValueChange:A,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"}),e.jsx(s.SelectItem,{value:"quarter",children:"Quarter"}),e.jsx(s.SelectItem,{value:"year",children:"Year"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Date Format"}),e.jsxs(s.Select,{value:b?"custom":N,onValueChange:O,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:L.map(F=>e.jsx(s.SelectItem,{value:F.value,children:F.label},F.value))})]}),b&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(s.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:E,onChange:F=>{F.stopPropagation(),k(F.target.value)},onClick:F=>F.stopPropagation(),className:"h-8 text-xs"}),e.jsx("div",{className:"text-xs text-gray-500",children:"Examples: YYYY-MM-DD, MM/DD/YY, DD-MMM-YYYY HH:mm"})]})]})]}),a==="metrics"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(s.Label,{className:"text-xs font-medium text-gray-600",children:"Aggregation"}),e.jsxs(s.Select,{value:t.aggregate,onValueChange:F=>{c&&c(F)},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,{value:"count",children:"Count"}),e.jsx(s.SelectItem,{value:"distinct",children:"Count Distinct"}),s.getDataType(t.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(s.SelectItem,{value:"SUM",children:"Sum"}),e.jsx(s.SelectItem,{value:"AVG",children:"Average"}),e.jsx(s.SelectItem,{value:"MIN",children:"Min"}),e.jsx(s.SelectItem,{value:"MAX",children:"Max"}),e.jsx(s.SelectItem,{value:"MEDIAN",children:"Median"})]})]})]})]}),m&&e.jsxs(e.Fragment,{children:[e.jsx(_r,{aliasTemplate:T,onAliasTemplateChange:R}),e.jsx($r,{valueAliases:B,onValueAliasesChange:P})]})]})]})]})}function ze({zone:t,fields:a,label:n,placeholder:r,onRemove:i,onLabelChange:o,onAggregationChange:c,onDateFormatChange:d,onGranularityChange:l,onAliasTemplateChange:m,onValueAliasesChange:u,shouldShow:h,hasPivotColumns:j=!1}){const{isOver:p,setNodeRef:g}=s.useDroppable({id:t}),f=a.length>0,[S,x]=M.useState(a.reduce((D,E)=>({...D,[E.id]:"asc"}),{})),N=D=>{x(E=>({...E,[D]:E[D]==="asc"?"desc":"asc"}))};return t==="sortBy"&&h===!1?null:e.jsxs("div",{className:"mb-4",children:[e.jsx(s.Label,{className:"mb-2 block text-sm font-medium",children:n}),e.jsx("div",{ref:g,className:`min-h-[60px] rounded-lg border-2 border-dashed p-3 transition-all ${p?"border-blue-500 bg-blue-50 dark:bg-blue-950":"border-muted-foreground/20 bg-muted/50"}`,children:a.length===0?e.jsxs("div",{className:"flex min-h-[40px] items-center justify-center text-sm text-gray-400",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),r]}):e.jsx(s.SortableContext,{items:a.map(D=>D.id),strategy:s.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((D,E)=>{const v=S[D.id];return e.jsxs("div",{className:"flex w-full items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(Gr,{field:D,zone:t,onRemove:()=>i(E),onLabelChange:b=>o(E,b),sortDirection:v,setSortDirection:()=>N(D.id),onAggregationChange:c?b=>c(E,b):void 0,onAliasTemplateChange:m?b=>m(E,b):void 0,onValueAliasesChange:u?b=>u(E,b):void 0,onDateFormatChange:d?(b,w)=>d(E,b,w):void 0,onGranularityChange:l?b=>l(E,b):void 0,hasPivotColumns:j})}),t==="sortBy"&&e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>N(D.id),children:v==="asc"?e.jsx(s.ArrowUp,{className:"h-3 w-3"}):e.jsx($e,{className:"h-3 w-3"})})]},D.id)})})})})]})}function Hr({groupByFields:t,pivotByFields:a,metricsFields:n,sortByFields:r,onRemoveField:i,onLabelChange:o,onAggregationChange:c,onDateFormatChange:d,onGranularityChange:l,onAliasTemplateChange:m,onValueAliasesChange:u}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ze,{zone:"groupBy",fields:t,label:"Group By",placeholder:"Drop fields to group data",onRemove:h=>i("groupBy",h),onLabelChange:(h,j)=>o("groupBy",h,j),onDateFormatChange:(h,j,p)=>d&&d(h,j,p),onGranularityChange:(h,j)=>l&&l(h,j)}),e.jsx(ze,{zone:"pivotBy",fields:a,label:"Pivot By",placeholder:"Drop fields to pivot data",onRemove:h=>i("pivotBy",h),onLabelChange:(h,j)=>o("pivotBy",h,j)}),e.jsx(ze,{zone:"metrics",fields:n,label:"Metrics",placeholder:"Drop fields to measure",onRemove:h=>i("metrics",h),onLabelChange:(h,j)=>o("metrics",h,j),onAggregationChange:c,onAliasTemplateChange:m,onValueAliasesChange:u,hasPivotColumns:a.length>0}),e.jsx(ze,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields to sort data",onRemove:h=>i("sortBy",h),onLabelChange:(h,j)=>o("sortBy",h,j),shouldShow:t.length>0||a.length>0||n.length>0})]})}function Jr({selectedChart:t,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:i,sortByFields:o,onRemoveField:c,onLabelChange:d,onAggregationChange:l,onDateFormatChange:m,onGranularityChange:u,onAliasTemplateChange:h,onValueAliasesChange:j}){const p=s.useEditorStore(f=>f.showAIDialog),{setShowAIDialog:g}=s.useEditorActions();return e.jsxs("div",{className:"flex w-96 flex-col border-r bg-background",children:[e.jsxs("div",{className:"space-y-3 border-b px-6 py-4",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(ms,{className:"h-5 w-5 text-cyan-600"}),e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})]}),e.jsx(s.Button,{onClick:()=>g(!p),variant:"outline",className:"h-8",size:"sm",children:e.jsx(Zs,{className:"h-4 w-4"})})]}),e.jsx(Vr,{selectedChart:t,onChartChange:a})]}),e.jsx(s.ScrollArea,{className:"flex-1 p-6",children:e.jsx(Hr,{groupByFields:n,pivotByFields:r,metricsFields:i,sortByFields:o,onRemoveField:c,onLabelChange:d,onAggregationChange:l,onDateFormatChange:m,onGranularityChange:u,onAliasTemplateChange:h,onValueAliasesChange:j})})]})}function Ur({initialFilters:t,availableFields:a}={}){const[n,r]=M.useState(t||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});s.useEditorStore(v=>v.card.dataSource);const{columns:i,isLoading:o}=De(),d=a||i||[],l={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},m=v=>{const b=w=>{if(w.id===v){const y=d[0]||l;return{...w,conditions:[...w.conditions,{id:`condition-${Date.now()}`,field:y,operator:"=",value:""}]}}return{...w,groups:w.groups.map(b)}};r(b(n))},u=v=>{const b=w=>{if(w.id===v){const y=d[0]||l;return{...w,groups:[...w.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:y,operator:"=",value:""}],groups:[]}]}}return{...w,groups:w.groups.map(b)}};r(b(n))},h=(v,b)=>{const w=y=>y.id===v?{...y,conditions:y.conditions.filter(I=>I.id!==b)}:{...y,groups:y.groups.map(w)};r(w(n))},j=(v,b)=>{const w=y=>y.id===v?{...y,groups:y.groups.filter(I=>I.id!==b)}:{...y,groups:y.groups.map(w)};r(w(n))},p=(v,b,w,y)=>{if(w==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const I=T=>T.id===v?{...T,conditions:T.conditions.map(C=>C.id===b?{...C,[w]:y}:C)}:{...T,groups:T.groups.map(I)};r(I(n))},g=(v,b,w)=>{const y=I=>I.id===v?{...I,conditions:I.conditions.map(T=>T.id===b?{...T,...w}:T)}:{...I,groups:I.groups.map(y)};r(y(n))},f=(v,b)=>{const w=y=>y.id===v?{...y,logicalOperator:b}:{...y,groups:y.groups.map(w)};r(w(n))},S=(v,b)=>{const w=y=>y.id===v?{...y,negate:b}:{...y,groups:y.groups.map(w)};r(w(n))},x=(v,b,w)=>{const y=I=>I.id===v?{...I,conditions:s.arrayMove(I.conditions,b,w)}:{...I,groups:I.groups.map(y)};r(y(n))},N=(v,b,w)=>{const y=I=>I.id===v?{...I,groups:s.arrayMove(I.groups,b,w)}:{...I,groups:I.groups.map(y)};r(y(n))},D=v=>{if(!v||v.conditions.length===0&&v.groups.length===0)return"-- No filters defined";const b=y=>{let I="";typeof y.field=="object"?I=y.field.entityName?`${y.field.entityName}.${y.field.name}`:y.field.name:I=String(y.field);const T=y.operator;let C=y.value;if(y.field.dataType==="string"&&!["in","not in"].includes(y.operator))typeof C=="string"?C=`'${C}'`:Array.isArray(C)&&(C=`'${C.join(", ")}'`);else if(y.field.dataType==="date")(typeof C=="string"||C instanceof Date)&&(C=`DATE('${C}')`);else if(["in","not in"].includes(y.operator)){let B=[];Array.isArray(C)?B=C.map(z=>typeof z=="string"?`'${z}'`:String(z)):typeof C=="string"?B=C.split(",").map(z=>{const O=z.trim();return y.field.dataType==="string"?`'${O}'`:O}):typeof C=="number"&&(B=[String(C)]),C=`(${B.join(", ")})`}switch(T){case"contains":return typeof C=="string"?`${I} LIKE '%${C.replace(/'/g,"")}'`:`${I} LIKE '%${String(C)}'`;case"startsWith":return typeof C=="string"?`${I} LIKE '${C.replace(/'/g,"")}%'`:`${I} LIKE '${String(C)}%'`;case"endsWith":return typeof C=="string"?`${I} LIKE '%${C.replace(/'/g,"")}'`:`${I} LIKE '%${String(C)}'`;default:return`${I} ${T} ${C}`}},w=y=>{const I=y.conditions.map(b),T=y.groups.map(O=>w(O)),C=[...I,...T].filter(Boolean);if(C.length===0)return"";const B=C.join(` ${y.logicalOperator} `),z=C.length>1?`(${B})`:B;return y.negate?`NOT ${z}`:z};return w(v)},E=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:d,isLoading:o,addCondition:m,addGroup:u,removeCondition:h,removeGroup:j,updateCondition:p,updateConditionFields:g,updateGroupOperator:f,updateGroupNegate:S,reorderConditions:x,reorderGroups:N,generateSQLPreview:D,hasAnyFilters:E}}const Yr=t=>{switch(t){case"table":return e.jsx(Vs,{className:"h-3 w-3"});case"view":return e.jsx(s.Eye,{className:"h-3 w-3"});case"dataset":return e.jsx(ms,{className:"h-3 w-3"});case"file":return e.jsx(jn,{className:"h-3 w-3"});default:return e.jsx(Vs,{className:"h-3 w-3"})}},Kr=t=>{switch(t){case"table":return"Table";case"view":return"View";case"dataset":return"Dataset";case"file":return"File";default:return"Table"}},Qr=t=>{if(t.qualifiedEntityName){const a=t.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Wr({value:t,onValueChange:a,availableFields:n,placeholder:r="Select field",className:i="w-64"}){const[o,c]=M.useState(!1),d=M.useMemo(()=>{const l={};return n.forEach(m=>{const u=Qr(m);l[u]||(l[u]={}),l[u][m.entityId]||(l[u][m.entityId]=[]),l[u][m.entityId].push(m)}),l},[n]);return e.jsxs(s.Popover,{modal:!0,open:o,onOpenChange:c,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:s.cn("justify-between",!t&&"text-muted-foreground",i),children:[t?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"truncate text-sm",children:[t.entityName,".",t.name]})}):r,e.jsx(an,{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(d).map(([l,m])=>e.jsx(s.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"h-3 w-3"}),l]}),children:Object.entries(m).map(([u,h])=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 bg-gray-50/50 px-2 py-1 text-xs font-medium text-gray-600",children:[Yr(h[0].entityType),e.jsx("span",{children:h[0].entityName}),e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:Kr(h[0].entityType)})]}),h.map(j=>e.jsxs(s.CommandItem,{value:j.id,onSelect:()=>{a(j),c(!1)},className:"pl-6",children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",(t==null?void 0:t.id)===j.id?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate",children:j.label}),j.role&&e.jsx(s.Badge,{variant:"outline",className:"text-xs capitalize",children:j.role})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx("span",{children:j.dataType}),j.description&&e.jsxs("span",{children:["• ",j.description]}),j.customFormat&&e.jsxs("span",{children:["• ",j.customFormat]})]})]})]},j.id))]},`${l}-${u}`))},l))})]})})]})}function Os(t){var p;const a=s.useEditorStore(g=>g.card),{authToken:n}=s.useSemaphorContext(),r=s.useEditorStore(g=>g.card.config),i=r==null?void 0:r.joinPlan,o={...t,label:"value",role:"groupby"},c={...t,role:"metric",label:"count",aggregate:"COUNT"},d={joinPlan:i,groupByColumns:[o],metricColumns:[c]},l=((p=a.dataSource)==null?void 0:p.connectionId)||a.connectionId,{data:m,isPending:u,error:h}=s.useQuery({queryKey:["filterValues",t.entityId,t.name,t.qualifiedEntityName],queryFn:async()=>{try{return await s.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:l,cardConfig:d,cardDataSource:a.dataSource})}catch(g){console.log(t),console.error("error",g)}},enabled:!!l,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((m==null?void 0:m.records)||[]).map(g=>({label:g.value||"BLANK",value:g.value||"BLANK",count:g.count})),isPending:u,error:h}}function Xr({field:t,selected:a,onChange:n,placeholder:r="Select items...",className:i}){const[o,c]=ae.useState(!1),{filterValues:d}=Os(t),l=u=>{n(a.filter(h=>h!==u))},m=u=>{a.includes(u)?n(a.filter(h=>h!==u)):n([...a,u])};return e.jsx("div",{className:s.cn("w-full",i),children:e.jsxs(s.Popover,{open:o,onOpenChange:c,modal:!0,children:[e.jsx(s.PopoverTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"outline",role:"combobox","aria-expanded":o,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:a.length>0?a.map(u=>{const h=d.find(j=>j.value===u);return e.jsxs(s.Badge,{variant:"secondary",className:"text-xs",children:[h==null?void 0:h.label,e.jsx("div",{className:"ml-1 rounded-full outline-none ring-offset-background focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:j=>{j.key==="Enter"&&l(u)},onMouseDown:j=>{j.preventDefault(),j.stopPropagation()},onClick:j=>{j.stopPropagation(),l(u)},children:e.jsx(s.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},u)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(s.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(s.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(s.Command,{children:[e.jsx(s.CommandInput,{placeholder:"Search..."}),e.jsxs(s.CommandList,{children:[e.jsx(s.CommandEmpty,{children:"No results found."}),e.jsx(s.CommandGroup,{children:d.map(u=>e.jsxs(s.CommandItem,{onSelect:()=>m(u.value),children:[e.jsx(s.Check,{className:s.cn("mr-2 h-4 w-4",a.includes(u.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:u.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:u.count})]})]},u.value))})]})]})})]})})}const Mt=t=>{if(!t)return 0;let a=t.conditions.length;return t.groups.forEach(n=>{a+=Mt(n)}),a};function Zr({field:t,value:a,onChange:n,placeholder:r="Select value...",className:i}){const{filterValues:o,isPending:c,error:d}=Os(t);return c?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(ce,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):d?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(s.Select,{value:a,onValueChange:n,children:[e.jsx(s.SelectTrigger,{className:i||"flex-1",children:e.jsx(s.SelectValue,{placeholder:r,children:a})}),e.jsx(s.SelectContent,{children:o.map(l=>e.jsx(s.SelectItem,{value:l.value,children:l.label},l.value))})]})}const ei=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],si=["=","!=","contains","startsWith","endsWith","in","not in"],ti=["=","!=",">",">=","<","<=","in","not in"],ni=["=","!="],ai=["=","!=",">",">=","<","<=","in","not in"];function ri(t){switch(t){case"string":return si;case"number":return ti;case"boolean":return ni;case"date":return ai;default:return ei}}function At({condition:t,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:i,onRemoveCondition:o,onUpdateGroupOperator:c,availableFields:d,updateConditionFields:l}){const{attributes:m,listeners:u,setNodeRef:h,transform:j,transition:p,isDragging:g}=s.useSortable({id:t.id}),{isPending:f,error:S}=Os(t.field),x={transform:s.CSS.Transform.toString(j),transition:p};return e.jsxs("div",{ref:h,style:x,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-gray-50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...m,...u,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(s.Select,{value:r,onValueChange:N=>c(n,N),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"})]})]}),a===0&&e.jsx("div",{className:"w-24"}),e.jsx(Wr,{value:t.field,onValueChange:N=>{l(n,t.id,{field:N,value:""})},availableFields:d,placeholder:"Select field",className:"w-64"}),e.jsxs(s.Select,{value:t.operator,onValueChange:N=>{N==="in"||N==="not in"?l(n,t.id,{operator:N,value:[]}):l(n,t.id,{operator:N,value:""})},children:[e.jsx(s.SelectTrigger,{className:"w-28",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:ri(s.getDataType(t.field.dataType)).map(N=>e.jsx(s.SelectItem,{value:N,children:N},N))})]}),s.getDataType(t.field.dataType)==="string"?t.operator==="in"||t.operator==="not in"?f?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(ce,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):S?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(Xr,{field:t.field,selected:Array.isArray(t.value)&&t.value.every(N=>typeof N=="string")?t.value:[],onChange:N=>l(n,t.id,{value:N}),placeholder:`Select values for ${t.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(t.operator)?e.jsx(s.Input$1,{value:typeof t.value=="string"?t.value:"",onChange:N=>l(n,t.id,{value:N.target.value}),className:"flex-1",placeholder:t.operator.charAt(0).toUpperCase()+t.operator.slice(1)+"..."}):e.jsx(Zr,{field:t.field,value:typeof t.value=="string"?t.value:"",onChange:N=>l(n,t.id,{value:N}),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:N=>l(n,t.id,{value:N==="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"})]})]}):e.jsx(s.Input$1,{value:typeof t.value=="string"||typeof t.value=="number"?t.value:"",onChange:N=>i(n,t.id,"value",N.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:()=>o(n,t.id),children:e.jsx(s.X,{className:"h-3 w-3"})})]})}function ii({group:t,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:i,onRemoveGroup:o,onUpdateCondition:c,onUpdateField:d,onRemoveCondition:l,onReorderConditions:m,onReorderGroups:u,onAddCondition:h,onAddGroup:j,availableFields:p,renderFilterGroup:g,updateConditionFields:f}){const{attributes:S,listeners:x,setNodeRef:N,transform:D,transition:E,isDragging:v}=s.useSortable({id:t.id}),b={transform:s.CSS.Transform.toString(D),transition:E},w=I=>{const{active:T,over:C}=I;if(C&&T.id!==C.id){const B=t.conditions.findIndex(O=>O.id===T.id),z=t.conditions.findIndex(O=>O.id===C.id);B!==-1&&z!==-1&&m(t.id,B,z)}},y=I=>{const{active:T,over:C}=I;if(C&&T.id!==C.id&&n){const B=t.groups.findIndex(O=>O.id===T.id),z=t.groups.findIndex(O=>O.id===C.id);B!==-1&&z!==-1&&u(n,B,z)}};return e.jsxs("div",{ref:N,style:b,className:`rounded-lg ${a>0?"mt-2 border border-gray-200":""} ${v?"z-50 opacity-50":""}`,children:[a>0&&e.jsxs("div",{className:"flex items-center justify-between rounded-t-lg bg-gray-50 p-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...S,...x,className:"cursor-grab active:cursor-grabbing",children:e.jsx(s.GripVertical,{className:"h-4 w-4 text-gray-400"})}),e.jsx(s.Button,{variant:t.negate?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>i(t.id,!t.negate),children:"NOT"}),e.jsxs(s.Select,{value:t.logicalOperator,onValueChange:I=>r(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,{value:"AND",children:"AND"}),e.jsx(s.SelectItem,{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:()=>n&&o(n,t.id),children:e.jsx(s.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${a>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:w,children:e.jsx(s.SortableContext,{items:t.conditions.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:t.conditions.map((I,T)=>e.jsx(At,{condition:I,index:T,groupId:t.id,groupLogicalOperator:t.logicalOperator,onUpdateCondition:c,onUpdateField:d,onRemoveCondition:l,onUpdateGroupOperator:r,availableFields:p,updateConditionFields:f},I.id))})}),e.jsx(s.DndContext,{sensors:s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),collisionDetection:s.closestCenter,onDragEnd:y,children:e.jsx(s.SortableContext,{items:t.groups.map(I=>I.id),strategy:s.verticalListSortingStrategy,children:t.groups.map(I=>g(I,a+1,t.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>h(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>j(t.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function oi({filters:t,availableFields:a,onSave:n,onClearAll:r,onCancel:i}){const{currentFilters:o,availableFields:c,isLoading:d,addCondition:l,addGroup:m,removeCondition:u,removeGroup:h,updateCondition:j,updateConditionFields:p,updateGroupOperator:g,updateGroupNegate:f,reorderConditions:S,reorderGroups:x,generateSQLPreview:N,hasAnyFilters:D,setCurrentFilters:E}=Ur({initialFilters:t,availableFields:a}),v=s.useSensors(s.useSensor(s.PointerSensor),s.useSensor(s.KeyboardSensor,{coordinateGetter:s.sortableKeyboardCoordinates})),[b,w]=M.useState(!1),y=(C,B,z)=>{const O=k=>k.id===C?{...k,conditions:k.conditions.map(A=>A.id===B?{...A,field:z,dataType:z.dataType}:A)}:{...k,groups:k.groups.map(O)};E(O(o))},I=(C,B=0,z)=>B===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(s.DndContext,{sensors:v,collisionDetection:s.closestCenter,onDragEnd:O=>{const{active:k,over:A}=O;if(A&&k.id!==A.id){const R=C.conditions.findIndex($=>$.id===k.id),P=C.conditions.findIndex($=>$.id===A.id);R!==-1&&P!==-1&&S(C.id,R,P)}},children:e.jsx(s.SortableContext,{items:C.conditions.map(O=>O.id),strategy:s.verticalListSortingStrategy,children:C.conditions.map((O,k)=>e.jsx(At,{condition:O,index:k,groupId:C.id,groupLogicalOperator:C.logicalOperator,onUpdateCondition:j,onUpdateField:y,onRemoveCondition:u,onUpdateGroupOperator:g,availableFields:c,updateConditionFields:p},O.id))})}),e.jsx(s.DndContext,{sensors:v,collisionDetection:s.closestCenter,onDragEnd:O=>{const{active:k,over:A}=O;if(A&&k.id!==A.id){const R=C.groups.findIndex($=>$.id===k.id),P=C.groups.findIndex($=>$.id===A.id);R!==-1&&P!==-1&&x(C.id,R,P)}},children:e.jsx(s.SortableContext,{items:C.groups.map(O=>O.id),strategy:s.verticalListSortingStrategy,children:C.groups.map(O=>I(O,B+1,C.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(s.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>l(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),b&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>m(C.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},C.id):e.jsx(ii,{group:C,depth:B,parentGroupId:z,onUpdateGroupOperator:g,onUpdateGroupNegate:f,onRemoveGroup:h,onUpdateCondition:j,onUpdateField:y,onRemoveCondition:u,onReorderConditions:S,onReorderGroups:x,onAddCondition:l,onAddGroup:m,availableFields:c,renderFilterGroup:I,updateConditionFields:p},C.id),T=Mt(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:[d?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(o),e.jsx("div",{className:"mt-4 border-t border-gray-200 pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Checkbox,{id:"advanced-mode",checked:b,onCheckedChange:C=>w(!!C)}),e.jsx("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)"})]})}),D&&e.jsxs("div",{className:"mt-4 border-t border-gray-200 pt-4",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-gray-700",children:"SQL WHERE Clause Preview"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-gray-50 p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap font-mono text-xs text-gray-800",children:N(o)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(s.Button,{size:"sm",variant:"outline",onClick:i,children:"Cancel"}),T>0&&e.jsx(s.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(s.Button,{size:"sm",onClick:()=>n(D?o:null),children:"Apply Filters"})]})]})}function li({cardId:t,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:i,isOpen:o,onOpenChange:c}){const d=m=>{n(t,m),c(!1)},l=()=>{r(t),c(!1)};return e.jsx(s.Dialog,{open:o,onOpenChange:c,children:e.jsxs(s.DialogContent,{className:"max-h-[80vh] max-w-4xl overflow-y-auto",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(oi,{filters:a,availableFields:i,onSave:d,onCancel:()=>c(!1),onClearAll:l})]})})}function Lt(t,a){return`${s.toLabel(a)} of ${s.toLabel(t)}`}function ci({activeCardId:t,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){const[i,o]=M.useState(null),c=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],d=M.useCallback(j=>j.startsWith("card-")?null:j.startsWith("source-")||a.find(p=>p.id===j)?"source":n("groupBy").find(p=>p.id===j)?"groupBy":n("metrics").find(p=>p.id===j)?"metrics":n("pivotBy").find(p=>p.id===j)?"pivotBy":n("sortBy").find(p=>p.id===j)?"sortBy":null,[a,n]),l=(j,p)=>{const g=`${p}-${j.qualifiedEntityName}-${j.name}-${Date.now()}`,f=s.getDataType(j.dataType),S=f==="date",x={id:g,name:j.name,dataType:j.dataType,label:s.toLabel(j.name),qualifiedEntityName:j.qualifiedEntityName,entityId:j.entityId,entityName:j.entityName,entityType:j.entityType};if(p==="metrics"){const N=f==="number"?"SUM":"COUNT",D=Lt(j.label,N);return{...x,role:"metric",label:D,aggregate:N}}return p==="groupBy"?{...x,role:"groupby",...S&&{granularity:"month"}}:p==="pivotBy"?{...x,role:"pivotby"}:p==="sortBy"?{...x,role:"sortby",direction:"asc"}:null},m=M.useCallback(j=>{o(j.active.id)},[]),u=M.useCallback(j=>{const{active:p,over:g}=j;if(!g||!t){o(null);return}const f=p.id,S=g.id,x=d(f),N=d(S)||S;if(x==="source"&&N!=="source"){const D=[...a].find(w=>w.id===f);if(!D){o(null);return}const E=n(N);if(E.some(w=>w.name===D.name&&w.qualifiedEntityName===D.qualifiedEntityName)){o(null);return}const b=l(D,N);o(null),r(N,[...E,b]);return}if(x&&N&&x!=="source"&&N!=="source"&&x!==N){const D=n(x),E=n(N),v=D.find(y=>y.id===f);if(!v){o(null);return}const b=l(v,N);o(null);const w=D.filter(y=>y.id!==f);r(x,w),r(N,[...E,b]);return}if(x&&N&&x===N&&x!=="source"){const D=n(x),E=D.findIndex(b=>b.id===f),v=D.findIndex(b=>b.id===S);if(E!==v){const b=s.arrayMove(D,E,v);r(x,b)}}o(null)},[t,a,n,r,d]),h=i?c.find(j=>j.id===i):null;return{activeId:i,activeField:h,handleDragStart:m,handleDragEnd:u}}const di=t=>{const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:i,updateSortByColumn:o,removeGroupByColumn:c,removeMetricColumn:d,removePivotByColumn:l,removeSortByColumn:m}=s.useEditorActions(),u=t==null?void 0:t.id,h=M.useCallback(E=>{if(!(t!=null&&t.config))return[];switch(E){case"groupBy":return(t.config.groupByColumns||[]).map(v=>({id:v.id,name:v.name,dataType:v.dataType,label:v.label!==void 0?v.label:v.name,qualifiedEntityName:v.qualifiedEntityName,entityId:v.entityId,entityName:v.entityName,entityType:v.entityType,dateFormat:v.dateFormat,customFormat:v.customFormat,granularity:v.granularity}));case"metrics":return t.config.metricColumns||[];case"pivotBy":return(t.config.pivotByColumns||[]).map(v=>({id:v.id,name:v.name,dataType:v.dataType,label:v.label!==void 0?v.label:v.name,qualifiedEntityName:v.qualifiedEntityName,entityId:v.entityId,entityName:v.entityName,entityType:v.entityType}));case"sortBy":return(t.config.sortByColumns||[]).map(v=>({id:v.id,name:v.name,dataType:v.dataType,label:v.label!==void 0?v.label:v.name,qualifiedEntityName:v.qualifiedEntityName,entityId:v.entityId,entityName:v.entityName,entityType:v.entityType}));case"source":return[];default:return[]}},[t]),j=M.useCallback((E,v)=>{if(u)switch(E){case"groupBy":{a(u,{groupByColumns:v});break}case"metrics":{a(u,{metricColumns:v});break}case"pivotBy":{a(u,{pivotByColumns:v});break}case"sortBy":{a(u,{sortByColumns:v});break}}},[u,a]),p=M.useCallback((E,v,b)=>{if(!u)return;const y=h(E)[v];if(y)switch(E){case"groupBy":n(u,y.id,{label:b});break;case"metrics":r(u,y.id,{label:b});break;case"pivotBy":i(u,y.id,{label:b});break;case"sortBy":o(u,y.id,{label:b});break}},[u,h,n,r,i,o]),g=M.useCallback((E,v)=>{if(!u)return;const w=h("metrics")[E];w&&r(u,w.id,{aggregate:v,label:Lt(w.name,v)})},[u,h,r]),f=M.useCallback((E,v,b)=>{if(!u)return;const y=h("groupBy")[E];if(!y)return;const I={dateFormat:v};v==="custom"&&b?I.customFormat=b:I.customFormat=void 0,n(u,y.id,I)},[u,h,n]),S=M.useCallback((E,v)=>{if(!u)return;const w=h("groupBy")[E];w&&n(u,w.id,{granularity:v})},[u,h,n]),x=M.useCallback((E,v)=>{if(!u)return;const w=h("metrics")[E];w&&r(u,w.id,{aliasTemplate:v})},[u,h,r]),N=M.useCallback((E,v)=>{if(console.log("handleValueAliasesChange",E,v),!u)return;console.log("handleValueAliasesChange",E,v);const w=h("metrics")[E];w&&(console.log("handleValueAliasesChange",v),r(u,w.id,{valueAliases:v}))},[u,h,r]),D=M.useCallback((E,v)=>{if(!u)return;const w=h(E)[v];if(w)switch(E){case"groupBy":c(u,w.id);break;case"metrics":d(u,w.id);break;case"pivotBy":l(u,w.id);break;case"sortBy":m(u,w.id);break}},[u,h,c,d,l,m]);return{getFieldsForContainer:h,setFieldsForContainer:j,updateLabel:p,handleAggregationChange:g,handleDateFormatChange:f,handleGranularityChange:S,handleAliasTemplateChange:x,handleValueAliasesChange:N,removeField:D}};function ui({activeView:t,onViewChange:a}){return e.jsx(s.Tabs,{value:t,onValueChange:n=>a(n),children:e.jsxs(s.TabsList,{className:"h-9 w-fit",children:[e.jsx(s.TabsTrigger,{value:"chart",className:"text-xs",children:"Chart"}),e.jsx(s.TabsTrigger,{value:"table",className:"text-xs",children:"Table"}),e.jsx(s.TabsTrigger,{value:"sql",className:"text-xs",children:"SQL"})]})})}function mi({activeView:t,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:i,onClear:o,onAdvancedToggle:c,onFiltersClick:d,filterCount:l,activeCard:m,columns:u,columnsLoading:h,columnsError:j}){const p=s.useEditorStore(N=>N.card.config),g=s.useEditorStore(N=>N.card),{data:f,errorMessage:S}=s.useDashboardCardQuery(g);function x(){return e.jsx("div",{className:"border-b border-border bg-background p-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium text-gray-700",children:"Active Card Config"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs text-gray-800",children:JSON.stringify(p||{},null,2)})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-sm font-medium text-gray-700",children:"Card Data Source State"}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs text-gray-800",children:JSON.stringify(g.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium text-gray-700",children:["Columns (",u.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs text-gray-800",children:h?"Loading...":j?"Error loading columns":JSON.stringify(u.slice(0,5),null,2)})]})]})})}return e.jsxs("div",{className:"flex w-0 grow flex-col",children:[e.jsx(s.ExplorerHeader,{showDebug:n,onDebugToggle:r,onAccept:i,onClear:o,onAdvancedToggle:c,onFiltersClick:d,filterCount:l}),n&&x(),e.jsxs("div",{className:"flex max-w-full grow flex-col",children:[e.jsxs("div",{className:"z-50 flex items-center gap-2 px-6",children:[e.jsx(ui,{activeView:t,onViewChange:a}),d&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"gap-1",onClick:d,children:[e.jsx(gs,{className:"h-3.5 w-3.5"}),l>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:l})]}),e.jsxs("div",{className:"flex grow items-center justify-between",children:[t==="chart"&&e.jsx(bt,{variant:"outline"}),t==="chart"&&e.jsx(vt,{})]})]}),e.jsxs("div",{className:"flex grow flex-col",children:[t==="chart"&&e.jsx("div",{className:"flex grow flex-col",children:e.jsx(ks,{className:"border-none"})}),t==="table"&&(f==null?void 0:f.records)&&e.jsx("div",{className:"flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(s.TableVisual,{card:m,data:f==null?void 0:f.records})}),t==="sql"&&e.jsx("div",{className:"p-6",children:e.jsxs("div",{className:"rounded-md border bg-background p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-medium text-gray-700",children:"Generated SQL Query"}),e.jsx(ut,{sql:f==null?void 0:f.sql,error:S})]})})]})]})]})}function hi({activeField:t}){const[a,n]=M.useState(!0);return M.useEffect(()=>{t&&n(!0)},[t]),t?e.jsxs("div",{className:`flex items-center gap-2 rounded-lg border border-blue-500 bg-background p-2 shadow-lg transition-all duration-200 ${a?"scale-100 opacity-100":"scale-95 opacity-0"}`,children:[e.jsx(s.GripVertical,{className:"h-3 w-3 text-gray-400"}),e.jsx(Dt,{dataType:t.dataType}),e.jsx("span",{className:"text-sm dark:text-muted-foreground",children:t.name})]}):null}const xi=()=>{const t=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||t.apply(console,r)};const a=r=>{if(r.message&&(r.message.includes("ResizeObserver loop completed with undelivered notifications")||r.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),r.stopPropagation(),!1},n=r=>{var i;if((i=r.reason)!=null&&i.message&&(r.reason.message.includes("ResizeObserver loop completed with undelivered notifications")||r.reason.message.includes("ResizeObserver loop limit exceeded")))return r.preventDefault(),!1};return window.addEventListener("error",a,!0),window.addEventListener("unhandledrejection",n,!0),()=>{console.error=t,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",n,!0)}};function pi(){var Q,H;const[t,a]=M.useState("chart"),[n,r]=M.useState(!1),[i,o]=M.useState(!1),c=s.useEditorStore(U=>U.showAIDialog),{setCardType:d}=s.useEditorActions(),l=s.useEditorStore(U=>U.card.type);M.useEffect(()=>xi(),[]);const m=()=>{console.log("Accept clicked - would save/apply current configuration")},u=()=>{console.log("Clear clicked - would reset all configurations")},h=()=>{console.log("Advanced mode toggled")},j=()=>{o(!0)},p=U=>{d(U)},g=s.useEditorStore(U=>U.frame),f=s.useEditorStore(U=>U.card);s.useEditorStore(U=>U.activeTabCardId),s.useEditorStore(U=>U.actions.getAvailableFields);const{addCard:S,removeCard:x,updateCard:N,setActiveCard:D,updateFilters:E}=s.useEditorActions(),{columns:v=[],isLoading:b,error:w}=De(),y=s.useSensors(s.useSensor(s.PointerSensor,{activationConstraint:{distance:8}})),I=f,{getFieldsForContainer:T,setFieldsForContainer:C,updateLabel:B,handleAggregationChange:z,handleDateFormatChange:O,handleGranularityChange:k,handleAliasTemplateChange:A,handleValueAliasesChange:R,removeField:P}=di(I),{activeField:$,handleDragStart:Y,handleDragEnd:V}=ci({activeCardId:g.activeCardId,sourceFields:v,getFieldsForContainer:T,setFieldsForContainer:C}),L=(U,q)=>{q&&E(U,q)},F=U=>{var q;N(U,{config:{...(q=g.cards.find(K=>K.id===U))==null?void 0:q.config,filters:void 0}})},_=v,J=U=>{if(!U)return 0;let q=U.conditions.length;return U.groups.forEach(K=>{q+=J(K)}),q},G=J(((Q=I==null?void 0:I.config)==null?void 0:Q.filters)||null);return e.jsxs(s.DndContext,{sensors:y,collisionDetection:s.closestCenter,onDragStart:Y,onDragEnd:V,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(Rr,{}),!c&&e.jsx(Jr,{selectedChart:l,onChartChange:p,groupByFields:T("groupBy"),pivotByFields:T("pivotBy"),metricsFields:T("metrics"),sortByFields:T("sortBy"),onRemoveField:P,onLabelChange:B,onAggregationChange:z,onDateFormatChange:O,onGranularityChange:k,onAliasTemplateChange:A,onValueAliasesChange:R}),f&&e.jsx(mi,{selectedChart:l,activeView:t,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:m,onClear:u,onAdvancedToggle:h,onFiltersClick:j,filterCount:G,activeCard:I,dataSourceState:f.dataSource||s.EMPTY_DATA_SOURCE,columns:v,columnsLoading:b,columnsError:w,getFieldsForContainer:T,cards:g.cards,activeCardId:g.activeCardId,addCard:S,setActiveCard:D})]}),I&&e.jsx(li,{cardId:I.id,filters:((H=I.config)==null?void 0:H.filters)||null,onFiltersChange:L,onClearFilters:F,availableFields:_,isOpen:i,onOpenChange:o}),e.jsx(s.DragOverlay,{dropAnimation:null,children:e.jsx(hi,{activeField:$||null})})]})}function fi({authToken:t,onSave:a,onClose:n}){const r=M.useRef(null),i=s.useEditorStore(N=>N.showAIDialog),o=s.useEditorStore(N=>N.isDevMode),{setAuthToken:c}=s.useDashboardActions(),{setShowAIDialog:d,setOnSave:l,setOnClose:m}=s.useEditorActions(),{handleDragOver:u,handleDragEnd:h,handleDragStart:j,handleDragCancel:p,sensors:g}=sa();M.useEffect(()=>{a&&l(a),n&&m(n)},[a,l,n,m]),M.useEffect(()=>{t&&t.accessToken&&c(t)},[t,c]),M.useEffect(()=>{var N,D;i?((N=r.current)==null||N.resize(40),d(!0)):(d(!1),(D=r.current)==null||D.resize(0))},[i,d]);function f(N){N<1?d(!1):i||d(!0)}function S(){return e.jsxs(e.Fragment,{children:[e.jsx(dt,{type:"main"}),e.jsxs(s.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(pr,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:f,defaultSize:0,children:e.jsx(Js,{})})]})]})}function x(){return e.jsxs(s.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(s.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(pi,{})}),e.jsx(s.ResizableHandle,{}),e.jsx(s.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:f,defaultSize:0,children:e.jsx(Js,{})})]})}return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:o?e.jsx(s.DndContext,{sensors:g,onDragStart:j,onDragEnd:h,onDragOver:u,onDragCancel:p,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:S()})}):x()})}function gi(){s.useDashboardStore(c=>c.selectedCardId);const t=s.useDashboardStore(c=>c.selectedSheetId),{setIsVisualEditing:a}=s.useDashboardStore(c=>c.actions),n=s.useDashboardStore(c=>c.isVisualEditing),r=s.useDashboardStore(c=>c.actions.updateFrame);function i(c){t&&(r(t,c),a(!1))}function o(){a(!1)}return e.jsx("div",{role:"editor-container",className:s.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(fi,{onSave:i,onClose:o})})}function ji(){const t=s.useEditorStore(o=>o.selectedDatabaseName),a=s.useEditorStore(o=>o.selectedTableName),n=s.useDashboardStore(o=>o.dashboard.filters)||[],{columns:r}=s.useEditorAside(),{assignFilter:i}=kt();return e.jsx(s.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(o=>{const c=n==null?void 0:n.find(d=>d.column===s.fmt(o.column_name)&&d.table===a&&d.database===t);return e.jsx("div",{onClick:()=>i(o),className:s.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":c}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ss,{column:o}),e.jsx("span",{children:o.column_name})]})},o.column_name)})})}function yi(){s.useDashboardStore(a=>a.showFilters);const t=s.useDashboardStore(a=>a.actions.setShowFilters);return e.jsxs("section",{className:"relative flex min-w-[320px] grow flex-col border-l px-1",children:[e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-2 px-3",children:[e.jsx(s.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(s.Button,{onClick:()=>t(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(s.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(dt,{type:"filter",ColumnsComponent:()=>e.jsx(ji,{})})})]})}function bi(){const t=s.useDashboardStore(r=>r.dashboard.filters),a=s.useDashboardStore(r=>r.theme),n=t==null?void 0:t.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:s.cn("mb-1 flex items-center gap-2 border-y px-0.5 pb-0.5",{"bg-[repeating-linear-gradient(45deg,_#ffffff_0_3px,_#f3f3f3_3px_6px)]":a==="light","bg-[repeating-linear-gradient(45deg,_#18171d_0_3px,_#272729_3px_6px)]":a==="dark"}),children:n==null?void 0:n.map(r=>e.jsxs("div",{className:"flex min-w-[250px] max-w-fit flex-col gap-1 p-2",children:[e.jsx(s.FilterHeader,{filter:r}),e.jsx(s.FilterComponent,{filter:r})]},r.id))}):null}function vi(){const t=s.useDashboardStore(r=>r.showFilters),a=s.useDashboardStore(r=>r.isVisualEditing),n=s.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:s.cn("",{"max-h-0 overflow-hidden":a,"flex grow overflow-auto":!a}),children:[e.jsxs("section",{className:"flex grow flex-col",children:[n&&e.jsx(bi,{}),e.jsx(s.DashboardTabs,{})]}),t&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(yi,{})})]})}function Ni(){const t=s.useDashboardStore(i=>i.dashboard),a=s.useDashboardStore(i=>i.actions.setDashboard),n=s.useDashboardStore(i=>i.showDashboardJSON),r=s.useDashboardStore(i=>i.actions.setShowDashboardJSON);return e.jsxs("div",{className:s.cn("relative p-2",{hidden:!n}),children:[e.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(s.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(s.de,{onChange:i=>{if(i)try{JSON.parse(i),a(JSON.parse(i))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(t,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function Ci({showControls:t=!1,showFooter:a=!0,...n}){return e.jsx(s.ErrorBoundary,{FallbackComponent:s.Fallback,children:e.jsxs(s.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(s.$e,{}),e.jsxs(s.UXProvider,{children:[e.jsx(Ni,{}),e.jsxs(s.DashboardPanel,{...n,children:[t&&e.jsx(Qn,{}),e.jsx(gi,{}),e.jsx(vi,{})]})]})]})})}exports.DashboardPlus=Ci;exports.ScheduleDashboard=lt;exports.SelectComponent=ye;exports.cleanCard=rt;exports.downloadPdf=ot;exports.getDashbaordStateWithoutData=Cs;
|