react-semaphor 0.0.501 → 0.0.503
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-ChZEjlj_.js → dashboard-plus-DWnr_Ipf.js} +3283 -3138
- package/dist/chunks/dashboard-plus-YxvFQ3pi.js +405 -0
- package/dist/chunks/{index-_4KUL8lP.js → index-BClntpzH.js} +71 -71
- package/dist/chunks/{index-BiB577h9.js → index-CEr4Bl2R.js} +18 -17
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunks/dashboard-plus-RqtXH4Hf.js +0 -405
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";var Ft=s=>{throw TypeError(s)};var Je=(s,a,n)=>a.has(s)||Ft("Cannot "+n);var W=(s,a,n)=>(Je(s,a,"read from private field"),n?n.call(s):a.get(s)),ie=(s,a,n)=>a.has(s)?Ft("Cannot add the same private member more than once"):a instanceof WeakSet?a.add(s):a.set(s,n),te=(s,a,n,r)=>(Je(s,a,"write to private field"),r?r.call(s,n):a.set(s,n),n),oe=(s,a,n)=>(Je(s,a,"access private method"),n);const e=require("react/jsx-runtime"),t=require("./index-BClntpzH.js"),L=require("react");require("react-dom");function Fs(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const n in s)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(s,n);Object.defineProperty(a,n,r.get?r:{enumerable:!0,get:()=>s[n]})}}return a.default=s,Object.freeze(a)}const re=Fs(L);function Bt(s,a){return s.filter(n=>!a.includes(n))}function Bs(s,a,n){const r=s.slice(0);return r[a]=n,r}var pe,ne,Ne,Ce,ae,he,Ie,De,Te,ee,tt,st,nt,at,rt,Jt,zs=(Jt=class extends t.Subscribable{constructor(a,n,r){super();ie(this,ee);ie(this,pe);ie(this,ne);ie(this,Ne);ie(this,Ce);ie(this,ae);ie(this,he);ie(this,Ie);ie(this,De);ie(this,Te,[]);te(this,pe,a),te(this,Ce,r),te(this,Ne,[]),te(this,ae,[]),te(this,ne,[]),this.setQueries(n)}onSubscribe(){this.listeners.size===1&&W(this,ae).forEach(a=>{a.subscribe(n=>{oe(this,ee,at).call(this,a,n)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,W(this,ae).forEach(a=>{a.destroy()})}setQueries(a,n,r){if(te(this,Ne,a),te(this,Ce,n),process.env.NODE_ENV!=="production"){const i=a.map(o=>W(this,pe).defaultQueryOptions(o).queryHash);new Set(i).size!==i.length&&console.warn("[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior.")}t.notifyManager.batch(()=>{const i=W(this,ae),o=oe(this,ee,nt).call(this,W(this,Ne));te(this,Te,o),o.forEach(h=>h.observer.setOptions(h.defaultedQueryOptions,r));const l=o.map(h=>h.observer),u=l.map(h=>h.getCurrentResult()),c=l.some((h,d)=>h!==i[d]);i.length===l.length&&!c||(te(this,ae,l),te(this,ne,u),this.hasListeners()&&(Bt(i,l).forEach(h=>{h.destroy()}),Bt(l,i).forEach(h=>{h.subscribe(d=>{oe(this,ee,at).call(this,h,d)})}),oe(this,ee,rt).call(this)))})}getCurrentResult(){return W(this,ne)}getQueries(){return W(this,ae).map(a=>a.getCurrentQuery())}getObservers(){return W(this,ae)}getOptimisticResult(a,n){const r=oe(this,ee,nt).call(this,a),i=r.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions));return[i,o=>oe(this,ee,st).call(this,o??i,n),()=>oe(this,ee,tt).call(this,i,r)]}},pe=new WeakMap,ne=new WeakMap,Ne=new WeakMap,Ce=new WeakMap,ae=new WeakMap,he=new WeakMap,Ie=new WeakMap,De=new WeakMap,Te=new WeakMap,ee=new WeakSet,tt=function(a,n){return n.map((r,i)=>{const o=a[i];return r.defaultedQueryOptions.notifyOnChangeProps?o:r.observer.trackResult(o,l=>{n.forEach(u=>{u.observer.trackProp(l)})})})},st=function(a,n){return n?((!W(this,he)||W(this,ne)!==W(this,De)||n!==W(this,Ie))&&(te(this,Ie,n),te(this,De,W(this,ne)),te(this,he,t.replaceEqualDeep(W(this,he),n(a)))),W(this,he)):a},nt=function(a){const n=new Map(W(this,ae).map(i=>[i.options.queryHash,i])),r=[];return a.forEach(i=>{const o=W(this,pe).defaultQueryOptions(i),l=n.get(o.queryHash);l?r.push({defaultedQueryOptions:o,observer:l}):r.push({defaultedQueryOptions:o,observer:new t.QueryObserver(W(this,pe),o)})}),r},at=function(a,n){const r=W(this,ae).indexOf(a);r!==-1&&(te(this,ne,Bs(W(this,ne),r,n)),oe(this,ee,rt).call(this))},rt=function(){var a;if(this.hasListeners()){const n=W(this,he),r=oe(this,ee,tt).call(this,W(this,ne),W(this,Te)),i=oe(this,ee,st).call(this,r,(a=W(this,Ce))==null?void 0:a.combine);n!==i&&t.notifyManager.batch(()=>{this.listeners.forEach(o=>{o(W(this,ne))})})}},Jt);function Rs({queries:s,...a},n){const r=t.useQueryClient(),i=t.useIsRestoring(),o=t.useQueryErrorResetBoundary(),l=re.useMemo(()=>s.map(x=>{const v=r.defaultQueryOptions(x);return v._optimisticResults=i?"isRestoring":"optimistic",v}),[s,r,i]);l.forEach(x=>{t.ensureSuspenseTimers(x),t.ensurePreventErrorBoundaryRetry(x,o)}),t.useClearResetErrorBoundary(o);const[u]=re.useState(()=>new zs(r,l,a)),[c,h,d]=u.getOptimisticResult(l,a.combine),m=!i&&a.subscribed!==!1;re.useSyncExternalStore(re.useCallback(x=>m?u.subscribe(t.notifyManager.batchCalls(x)):t.noop,[u,m]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),re.useEffect(()=>{u.setQueries(l,a,{listeners:!1})},[l,a,u]);const f=c.some((x,v)=>t.shouldSuspend(l[v],x))?c.flatMap((x,v)=>{const p=l[v];if(p){const k=new t.QueryObserver(r,p);if(t.shouldSuspend(p,x))return t.fetchOptimistic(p,k,o);t.willFetch(x,i)&&t.fetchOptimistic(p,k,o)}return[]}):[];if(f.length>0)throw Promise.all(f);const g=c.find((x,v)=>{const p=l[v];return p&&t.getHasError({result:x,errorResetBoundary:o,throwOnError:p.throwOnError,query:r.getQueryCache().get(p.queryHash),suspense:p.suspense})});if(g!=null&&g.error)throw g.error;return h(d())}/**
|
|
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 Ps=t.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 Vs=t.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 qs=t.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 _s=t.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 $s=t.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 qe=t.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 Gs=t.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 Hs=t.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 Js=t.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 Us=t.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 Ys=t.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 _e=t.createLucideIcon("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
|
|
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 Ks=t.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"}]]);/**
|
|
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=t.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"}]]);/**
|
|
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 Ut=t.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"}]]);/**
|
|
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 Ws=t.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"}]]);/**
|
|
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 Xs=t.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"}]]);/**
|
|
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 Zs=t.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"}]]);/**
|
|
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 en=t.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"}]]);/**
|
|
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 $e=t.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"}]]);/**
|
|
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 ut=t.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"}]]);/**
|
|
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 mt=t.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"}]]);/**
|
|
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 Ge=t.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"}]]);/**
|
|
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 ht=t.createLucideIcon("ChartNoAxesGantt",[["path",{d:"M8 6h10",key:"9lnwnk"}],["path",{d:"M6 12h9",key:"1g9pqf"}],["path",{d:"M11 18h7",key:"c8dzvl"}]]);/**
|
|
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 xt=t.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"}]]);/**
|
|
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 pt=t.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"}]]);/**
|
|
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 tn=t.createLucideIcon("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);/**
|
|
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 sn=t.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 Yt=t.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 nn=t.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 an=t.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 rn=t.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 on=t.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 ln=t.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 cn=t.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"}]]);/**
|
|
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 ft=t.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"}]]);/**
|
|
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 Kt=t.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"}]]);/**
|
|
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 dn=t.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"}]]);/**
|
|
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 un=t.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"}]]);/**
|
|
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 mn=t.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"}]]);/**
|
|
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 hn=t.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"}]]);/**
|
|
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 gt=t.createLucideIcon("Filter",[["polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3",key:"1yg77f"}]]);/**
|
|
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 xn=t.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"}]]);/**
|
|
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 pn=t.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"}]]);/**
|
|
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 fn=t.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"}]]);/**
|
|
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 gn=t.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"}]]);/**
|
|
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 jt=t.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"}]]);/**
|
|
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 jn=t.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"}]]);/**
|
|
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 yn=t.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"}]]);/**
|
|
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 bn=t.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"}]]);/**
|
|
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 vn=t.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"}]]);/**
|
|
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 Nn=t.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"}]]);/**
|
|
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 ce=t.createLucideIcon("LoaderCircle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]]);/**
|
|
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 Cn=t.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"}]]);/**
|
|
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 Sn=t.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"}]]);/**
|
|
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 wn=t.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"}]]);/**
|
|
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 yt=t.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"}]]);/**
|
|
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 kn=t.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"}]]);/**
|
|
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 En=t.createLucideIcon("MessageCircle",[["path",{d:"M7.9 20A9 9 0 1 0 4 16.1L2 22Z",key:"vv11sd"}]]);/**
|
|
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 zt=t.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"}]]);/**
|
|
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 Rt=t.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"}]]);/**
|
|
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 In=t.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"}]]);/**
|
|
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 Dn=t.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"}]]);/**
|
|
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 bt=t.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"}]]);/**
|
|
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 Qt=t.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"}]]);/**
|
|
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 Tn=t.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"}]]);/**
|
|
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 Mn=t.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"}]]);/**
|
|
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 vt=t.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"}]]);/**
|
|
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 An=t.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"}]]);/**
|
|
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 Wt=t.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"}]]);/**
|
|
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 Ln=t.createLucideIcon("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
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 He=t.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"}]]);/**
|
|
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 Xt=t.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"}]]);/**
|
|
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 On=t.createLucideIcon("Terminal",[["polyline",{points:"4 17 10 11 4 5",key:"akl6gq"}],["line",{x1:"12",x2:"20",y1:"19",y2:"19",key:"q2wloq"}]]);/**
|
|
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 Zt=t.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"}]]);/**
|
|
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 Nt=t.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"}]]);/**
|
|
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 es=t.createLucideIcon("Type",[["polyline",{points:"4 7 4 4 20 4 20 7",key:"1nosan"}],["line",{x1:"9",x2:"15",y1:"20",y2:"20",key:"swin9y"}],["line",{x1:"12",x2:"12",y1:"4",y2:"20",key:"1tx1rr"}]]);function Ct(s){var a;return{...s,sheets:(a=s==null?void 0:s.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(l=>ts(l))}})}})}}function ts(s){return{...s,customCfg:Fn(s.customCfg),data:[]}}function Fn(s){var a,n;return s?{...s,data:{...s==null?void 0:s.data,labels:[],datasets:(n=(a=s==null?void 0:s.data)==null?void 0:a.datasets)==null?void 0:n.map(r=>({...r,data:[]}))}}:null}async function Bn(s,a,n,r){if(!r)return null;const i=JSON.stringify(a);return await t.postRequest("https://semaphor.cloud/api/v1/lens",r,{name:s,template:i,filterValues:n,operation:"create"})}async function it(s,a){if(!a)return null;const{id:n,template:r,filterValues:i,isDefault:o,shared:l}=s;return await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{lensId:n,template:r,filterValues:i,isDefault:o,shared:l,operation:"update"})}async function zn(s,a){return a?await t.postRequest("https://semaphor.cloud/api/v1/lens",a,{operation:"delete",lensId:s}):null}function Rn(){const[s,a]=L.useState(""),[n,r]=L.useState(!1),i=t.useDashboardStore(x=>x.lenses),{setLenses:o,setSelectedLensId:l}=t.useDashboardActions(),[u,c]=L.useState(!1),[h,d]=L.useState(!1),m=t.useDashboardStore(x=>x.dashboard),N=t.useDashboardStore(x=>x.filterValues),{authToken:f}=t.useSemaphorContext();async function g(){c(!0);const x=Ct(m),v=await Bn(s,x,N,f==null?void 0:f.accessToken);v&&(o([...i||[],v]),l(v.id),d(!1)),c(!1)}return e.jsxs(t.Dialog,{open:h,onOpenChange:d,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(t.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create Lens"}),e.jsx(t.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(t.Label,{className:"text-right",children:"Name"}),e.jsx(t.Input,{value:s,onChange:x=>{a(x.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(t.DialogFooter,{children:e.jsx(t.Button,{size:"sm",variant:"outline",type:"submit",onClick:g,disabled:u,children:u?"Creating...":"Add"})})]})]})}function Pn(){const[s,a]=L.useState(!1),n=t.useDashboardStore(d=>d.lenses),r=t.useDashboardStore(d=>d.selectedLensId),{setLenses:i,setSelectedLensId:o}=t.useDashboardActions(),{authToken:l}=t.useSemaphorContext();async function u(d){o(d)}async function c(d){if(await zn(d,l==null?void 0:l.accessToken)){const N=n==null?void 0:n.filter(f=>f.id!==d);i(N||[]),o("original")}}async function h(d){const m=n==null?void 0:n.map(g=>g.id===d.id?{...g,isDefault:!d.isDefault}:{...g,isDefault:!1});i(m||[]);const N={...d,isDefault:!d.isDefault};await it(N,l==null?void 0:l.accessToken);const f=n==null?void 0:n.find(g=>g.isDefault);if(f&&f.id!==d.id){const g={...f,isDefault:!1};await it(g,l==null?void 0:l.accessToken)}}return e.jsxs(t.DropdownMenu,{open:s,onOpenChange:a,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(pn,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(t.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuRadioGroup,{value:r,onValueChange:u,children:[e.jsx(t.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(t.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(jn,{onClick:m=>{m.preventDefault(),h(d)},className:t.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(t.Cross2Icon,{onClick:m=>{m.preventDefault(),c(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})]})}function ss(){var o;const s=t.useDashboardStore.getState().authToken,a=t.useDashboardStore.getState().theme,n=t.useDashboardStore.getState().filterValues,r=(o=t.useDashboardStore.getState().dashboard)==null?void 0:o.title,i=t.useDashboardStore.getState().selectedSheetId;return{authToken:s,theme:a||"light",filterValues:n,dashboardTitle:r||"",selectedSheetId:i||""}}async function ns(){const s=t.useDashboardStore.getState().isDownloadingPdf,{authToken:a,theme:n,filterValues:r,dashboardTitle:i,selectedSheetId:o}=ss();if(s)return;const l=new URLSearchParams;l.set("token",(a==null?void 0:a.accessToken)||""),l.set("theme",n),l.set("filterValues",JSON.stringify(r)),l.set("selectedSheetId",o||"");const u=`https://semaphor.cloud/api/v1/generate-pdf?params=${encodeURIComponent(l.toString())}`;t.useDashboardStore.setState({isDownloadingPdf:!0});const d=(await(await fetch(u,{method:"GET",headers:{Authorization:`Bearer ${a==null?void 0:a.accessToken}`}})).json()).url,m=document.createElement("a");m.href=d;const N=`${i}-${new Date().toISOString()}.pdf`;m.download=N,m.click(),t.useDashboardStore.setState({isDownloadingPdf:!1})}function Vn({iconClassName:s}){const{authToken:a}=t.useSemaphorContext();t.useDashboardStore(i=>{var o;return(o=i.dashboard)==null?void 0:o.title}),t.useDashboardStore(i=>i.theme),t.useDashboardStore(i=>i.filterValues);const n=t.useDashboardStore(i=>i.isDownloadingPdf);async function r(){await ns()}return e.jsx(t.IconButton,{tooltip:"Download PDF",className:"h-7 p-2",onClick:r,children:n?e.jsx(ce,{className:t.cn("size-3.5 animate-spin",s)}):e.jsx(t.Download,{className:t.cn("size-4",s)})})}function le({defaultValue:s,label:a,options:n,value:r,onValueChange:i,className:o,icon:l,showPlaceholderLabel:u=!0}){return e.jsxs(t.Select,{defaultValue:s,value:r,onValueChange:i,children:[e.jsx(t.SelectTrigger,{className:t.cn("w-full focus:ring-0 focus:ring-offset-0",o),children:e.jsxs("div",{className:"flex items-center gap-2",children:[l&&e.jsx("span",{children:l}),u&&e.jsx(t.SelectValue,{placeholder:a})]})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:a}),n.map(c=>e.jsx(t.SelectItem,{value:c.value,children:c.label},c.value))]})})]})}const Pt=[{value:"daily",label:"Daily"},{value:"weekly",label:"Weekly"},{value:"biweekly",label:"Bi-Weekly"},{value:"monthly",label:"Monthly"}];function as({triggerButtonClassName:s}){const{data:a,handleScheduleSubscription:n,handleDeleteSubscription:r,status:i,error:o,isDeleting:l}=qn(),[u,c]=L.useState(""),[h,d]=L.useState(Pt[0].value),[m,N]=L.useState("06:00"),[f,g]=L.useState("");return e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Schedule Dashboard",className:t.cn("h-7 p-2",s),children:e.jsx(nn,{className:"size-4"})})}),e.jsx(t.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(t.Label,{htmlFor:"email",children:"Email"}),e.jsx(t.Input,{id:"email",value:u,onChange:x=>c(x.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"subject",children:"Subject"}),e.jsx(t.Input,{id:"subject",placeholder:"Monthly Sales Report",value:f,onChange:x=>{g(x.target.value.replace(/[^a-zA-Z0-9\s-_]/g,""))},className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"frequency",children:"Frequency"}),e.jsx(le,{className:"col-span-2 h-8",label:"Select Frequency",options:Pt,value:h,onValueChange:x=>d(x)})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"time",children:"Time"}),e.jsx(t.Input,{id:"time",type:"time",value:m,onChange:x=>N(x.target.value),className:`col-span-2 h-8 ${t.removeRing}`})]}),e.jsx("div",{className:"mt-2 flex justify-end",children:e.jsxs(t.Button,{onClick:async()=>{await n({email:u,frequency:h,time:m,subject:f}),N("00:00"),c(""),g("")},className:"h-8 p-2",disabled:i==="loading"||!u,children:[i==="loading"&&e.jsx(ce,{className:"mr-2 size-4 animate-spin"}),i==="success"&&e.jsx(t.Check,{className:"mr-2 size-4"}),i==="error"&&e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{children:e.jsx(Yt,{className:"mr-2 size-4 text-destructive"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{children:o})})]}),"Schedule"]})}),a&&a.length>0&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.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"})]}),t.isDevEnv]})}),e.jsx("div",{className:"grid gap-2",children:a==null?void 0:a.map(x=>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:[t.titleCase(x.frequency)," "]}),e.jsx(t.Label,{children:x.time})]})}),e.jsxs("div",{className:"col-span-2 flex items-center justify-end gap-4",children:[e.jsx(Vt,{tooltip:`Next Run: ${new Date(x.nextRun).toLocaleString()} ${x.timezone}`,children:e.jsx(sn,{className:"size-3.5"})}),e.jsx(Vt,{tooltip:`${x.endUserEmail}`,children:e.jsx(Sn,{className:"size-3.5"})}),l===x.id?e.jsx(ce,{className:"size-3.5 animate-spin"}):e.jsx(t.Trash2,{onClick:()=>r(x.id),className:"size-3.5 cursor-pointer"})]})]},x.id))})]})]})]})})]})})}const Vt=({children:s,tooltip:a})=>e.jsx(t.TooltipProvider,{delayDuration:0,children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:s}),e.jsx(t.TooltipContent,{children:a})]})});function qn(){const[s,a]=L.useState("idle"),[n,r]=L.useState(""),[i,o]=L.useState(null),l=t.useDashboardStore(T=>T.authToken),u=t.useDashboardStore(T=>T.dashboard.id),c=t.useDashboardStore(T=>T.dashboard.title),{endUserId:h}=t.getTenantAndEndUserId((l==null?void 0:l.accessToken)||""),d="https://semaphor.cloud/api/v1/subscriptions/get",m={dashboardId:u,endUserId:h},{data:N,isLoading:f,isError:g,isFetching:x,refetch:v}=t.useQuery({queryKey:["subscriptions",u,h],queryFn:()=>t.getRequest(d,(l==null?void 0:l.accessToken)||"",m),enabled:!!(l!=null&&l.accessToken)&&!!u&&!!h});async function p({email:T,subject:E,frequency:j,time:b}){const{authToken:y,...S}=ss(),I=Intl.DateTimeFormat().resolvedOptions().timeZone,D={email:T,frequency:j,time:b,timezone:I,endUserId:h,endUserEmail:T,subject:E||c||"Scheduled Dashboard",dashboardId:u,dashboardParams:S};a("loading");const C="https://semaphor.cloud/api/v1/subscriptions/create";try{const F=await t.postRequestRegular(C,(y==null?void 0:y.accessToken)||"",{...D});a("success"),r(""),v(),setTimeout(()=>{a("idle")},2e3)}catch(F){console.error(F),a("error"),r(F.message)}}async function k(T){const E="https://semaphor.cloud/api/v1/subscriptions/delete";o(T);try{await t.postRequestRegular(E,(l==null?void 0:l.accessToken)||"",{id:T}),v(),setTimeout(()=>{o(null)},2e3)}catch(j){console.error(j),o(null),a("error"),r(j.message)}}return{data:N,isLoading:f,isFetching:x,isError:g,isDeleting:i,refetch:v,handleScheduleSubscription:p,handleDeleteSubscription:k,status:s,error:n}}function _n(){const{authToken:s}=t.useSemaphorContext();t.useDashboardStore(D=>D.theme);const a=t.useDashboardStore(D=>D.lenses),n=t.useDashboardStore(D=>D.selectedLensId),r=a==null?void 0:a.find(D=>D.id===n),i=t.useDashboardStore(D=>D.dashboard);t.useDashboardStore(D=>D.selectedSheetId);const o=t.useDashboardStore(D=>D.isDashboardEditing),l=t.useEditorStore(D=>D.selectedConnectionId),[u,c]=L.useState(!1),h=t.useDashboardStore(D=>D.filterValues),d=t.useDashboardStore(D=>D.isVisualEditing),m=t.useDashboardStore(D=>D.showFilters);t.useDashboardStore(D=>D.showDashboardJSON);const N=t.useDashboardStore(D=>D.onSaveFunction),f=t.useDashboardStore(D=>D.actions.setShowFilters),{addFrame:g,setSelectedFrameId:x}=t.useDashboardStore(D=>D.actions),{getSelectedSheet:v,setIsDashboardEditing:p,setShowDashboardJSON:k}=t.useDashboardStore(D=>D.actions),T=v(),{tenantId:E,endUserId:j}=L.useMemo(()=>t.getTenantAndEndUserId(s==null?void 0:s.accessToken),[s==null?void 0:s.accessToken]),b=L.useMemo(()=>E||j,[E,j]),y=()=>{if(!o||!T)return;const D={connectionId:l,id:t.v4(),title:"Title",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]},C={id:t.v4(),cards:[D],activeCardId:D.id};g(T.id,C),x(C.id)},S=()=>{p(!0)};async function I(){if(c(!0),!n||!r)return;const D=Ct(i),C=JSON.stringify(D),F={...r,template:C,filterValues:h};await it(F,s==null?void 0:s.accessToken),t.ue.success("Lens saved"),N==null||N(D),c(!1)}return d?null:e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b py-1 pl-3 pr-2",role:"dashboard-controls",children:[!d&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(t.Label,{children:r==null?void 0:r.name})}),e.jsxs("div",{className:"flex gap-2",children:[!1,!d&&e.jsx(Vn,{}),!d&&e.jsx(as,{}),o&&!d&&b&&e.jsx(Rn,{}),!d&&b&&e.jsx(Pn,{}),o&&!d&&e.jsxs(t.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",disabled:!o,onClick:y,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Frame"]}),!o&&e.jsx(t.Button,{variant:"ghost",className:"h-7 p-2",onClick:S,size:"sm",children:e.jsx(t.Pencil,{className:"h-4 w-4"})}),o&&!d&&e.jsx(t.IconButton,{className:"h-7 p-2",onClick:()=>{p(!1),k(!1)},children:e.jsx(t.Cross2Icon,{className:"h-4 w-4"})}),o&&!d&&b&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",disabled:u,onClick:I,size:"sm",children:e.jsx(Mn,{className:"h-4 w-4"})}),!m&&!d&&o&&e.jsx(t.Button,{className:"h-7 p-2",variant:"ghost",onClick:()=>f(!0),size:"sm",children:e.jsx(gt,{className:"h-4 w-4"})}),!d&&o&&!1,!d&&!1]})]})}function $n({name:s,items:a,value:n,onChange:r,isLoading:i,isError:o,refetch:l,className:u,icon:c,showNone:h=!1}){const d=re.useRef(null),[m,N]=re.useState(!1),[f,g]=re.useState("100%"),x=h?[...a||[],{id:"none",name:"None"}]:a;re.useLayoutEffect(()=>{d.current&&g(d.current.offsetWidth)},[]);function v(){var k;return i?"Loading...":o?"Error":n?(k=a==null?void 0:a.find(T=>T.id===n))==null?void 0:k.name:`Select ${s}`}function p(k,T){r(T),N(!1)}return e.jsxs(t.Popover,{open:m,onOpenChange:N,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{ref:d,variant:"outline",role:"combobox","aria-expanded":m,className:t.cn("flex h-9 w-full justify-between",u),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c&&e.jsx("div",{className:"mr-2",children:c}),e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate text-ellipsis whitespace-nowrap",children:v()})]}),e.jsx(t.ChevronDown,{className:"size-4 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-full p-0",style:{minWidth:f},children:e.jsxs(t.Command,{children:[e.jsxs("div",{className:"flex h-9 items-center justify-between border-b pr-1",children:[e.jsx(t.CommandInput,{className:"h-9",placeholder:"Search..."}),e.jsx(t.IconButton,{className:"h-7",onClick:l,children:e.jsx(Qt,{className:t.cn("size-3.5 opacity-50",i&&"animate-spin")})})]}),e.jsxs(t.CommandList,{children:[e.jsxs(t.CommandEmpty,{children:["No ",s==null?void 0:s.toLowerCase()," found."]}),e.jsx(t.CommandGroup,{children:x==null?void 0:x.map(k=>e.jsx(t.CommandItem,{className:"overflow-x-auto",value:k.name,onSelect:T=>p(T,k.id),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Check,{className:t.cn("size-4",n===k.id?"opacity-100":"opacity-0")}),e.jsx("div",{title:k.name,children:k.name})]})},k.id))})]})]})})]})}function ve({title:s,items:a,value:n,isLoading:r,isError:i,refetch:o,onChange:l,showNone:u=!1,className:c,disabled:h=!1,type:d="combobox"}){const m=r?"Loading...":i?"Error":n;function N(){if(s==="Connection")return e.jsx(Dn,{className:"size-4"});if(s==="Database")return e.jsx(t.Database,{className:"size-4"});if(s==="Schema")return e.jsx(In,{className:"size-4"});if(s==="Table")return e.jsx(He,{className:"size-4"});if(s==="Model")return e.jsx(Ws,{className:"size-4"})}function f(){return e.jsxs(t.Select,{disabled:h,value:m,onValueChange:l,children:[e.jsx(t.SelectTrigger,{className:t.cn("h-9 w-full border-muted focus:ring-1 focus:ring-offset-0",c),children:e.jsx(t.SelectValue,{placeholder:r?"Loading...":i?"Error":`Select ${s}`})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[r?e.jsx(t.SelectLabel,{children:"Loading..."}):e.jsxs(t.SelectLabel,{className:"flex items-center justify-between gap-2",children:[s,e.jsx(Qt,{className:t.cn("mr-1 size-3 cursor-pointer text-muted-foreground hover:text-foreground",r&&"animate-spin"),onClick:o})]}),e.jsxs(e.Fragment,{children:[u&&e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),a&&a.map((x,v)=>e.jsx(t.SelectItem,{value:x.id,children:x.name},v))]}),(r||i)&&e.jsx(t.SelectItem,{value:m,children:m})]})})]})}function g(){return e.jsx($n,{icon:N(),items:a,value:m,onChange:l||(()=>{}),isLoading:r,isError:i,refetch:o,name:s,showNone:u})}return e.jsx(t.TooltipProvider$1,{delayDuration:0,children:e.jsx("div",{className:"flex items-center gap-2",children:d==="select"?f():g()})})}function Gn({column:s}){const[a,n]=L.useState(!1),r=t.useEditorStore(x=>x.selectedTableName),i=t.useEditorStore(x=>x.selectedSchemaName),o=t.useEditorStore(x=>x.selectedDatabaseName),l=t.useEditorStore(x=>x.selectedDatamodelId),u=t.useEditorStore(x=>x.sqlGen),{modelItems:c,connectionType:h}=t.useEditorAside(),d=t.useEditorStore(x=>x.actions.setSqlGen),m=t.useEditorStore(x=>x.actions.setCardSql),N=t.useEditorStore(x=>x.actions.setRunSql);function f(x,v){var E;const p=t.createSqlGenConfig(x,u,v),k=(E=c==null?void 0:c.find(j=>j.id===l))==null?void 0:E.name;d(p);const T=t.getSql(p,t.fmt(i||""),t.fmt(r),k||"",h,o||"");T&&(m(T),N(!0)),n(!1)}function g(){return e.jsxs("ul",{className:"text-xs",children:[e.jsx("li",{onClick:()=>f(s,"COUNT"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Count"}),e.jsx("li",{onClick:()=>f(s,"AVG"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Avg"}),e.jsx("li",{onClick:()=>f(s,"SUM"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Sum"}),e.jsx("li",{onClick:()=>f(s,"MAX"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Max"}),e.jsx("li",{onClick:()=>f(s,"MIN"),className:"cursor-pointer p-1 px-3 transition-colors hover:bg-muted",children:"Min"})]})}return e.jsxs(t.HoverCard,{openDelay:0,open:a,onOpenChange:n,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.EllipsisVertical,{className:"invisible size-3.5 cursor-pointer text-foreground/40 group-hover:visible"})}),e.jsx(t.HoverCardContent,{align:"center",className:"w-20 rounded-md p-0 shadow-none",children:g()})]})}function St({column:s}){return e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger$1,{className:"shrink-0",asChild:!0,children:t.isTextDataType(s.data_type)?e.jsx(t.TextIcon,{className:"size-3 text-muted-foreground"}):t.isNumberDataType(s.data_type)?e.jsx(jt,{className:"size-3 text-muted-foreground"}):t.isDateDataType(s.data_type)?e.jsx(t.Calendar,{className:"size-3 text-muted-foreground"}):t.isBooleanDataType(s.data_type)?e.jsx(Zt,{className:"size-3 text-muted-foreground"}):s.data_type.startsWith("json")?e.jsx(Xs,{className:"size-3 text-muted-foreground"}):e.jsx(t.QuestionMarkIcon,{className:"size-3 text-muted-foreground"})}),e.jsx(t.TooltipContent,{children:e.jsx("p",{className:"text-xs",children:s.data_type})})]})}function Ue({column:s,className:a}){return e.jsxs("div",{className:t.cn("flex min-h-8 grow items-center space-x-2 px-2 text-sm",a),children:[e.jsx(St,{column:s}),e.jsx("span",{children:s.column_name})]})}function Hn({id:s,children:a,type:n="column"}){const{attributes:r,listeners:i,setNodeRef:o,transform:l}=t.useDraggable({id:s,data:{type:n}}),u=l?{translate:t.CSS.Translate.toString(l),transform:t.CSS.Transform.toString(l)}:void 0;return e.jsx("div",{ref:o,style:u,...i,...r,children:a})}function Jn({onClick:s,column:a}){const n=t.useDndStore(d=>d.activeId),r=t.useEditorStore(d=>{var m;return(m=d.card.queryConfig)==null?void 0:m.groupByColumns}),i=t.useEditorStore(d=>{var m;return(m=d.card.queryConfig)==null?void 0:m.metricColumns}),o=t.useEditorStore(d=>{var m;return(m=d.card.queryConfig)==null?void 0:m.filterColumns});function l(d){return u(d)||c(d)||h(d)}function u(d){return r==null?void 0:r.some(m=>m.name===d.column_name)}function c(d){return i==null?void 0:i.some(m=>m.name===d.column_name)}function h(d){return o==null?void 0:o.some(m=>m.name===d.column_name)}return e.jsxs("div",{onClick:()=>s(a),className:t.cn("relative grow overflow-x-hidden overflow-y-hidden rounded-md active:border active:border-dashed active:border-muted-foreground",{"bg-muted-foreground/10":l(a)}),children:[n===a.column_name&&e.jsx(t.DragOverlay,{children:e.jsx(Ue,{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(Ue,{column:a})}),e.jsx(Hn,{id:a.column_name,type:"column",children:e.jsx(Ue,{column:a})})]})}const Ye={id:"__placeholder__",role:"groupby",type:"string"},Ke={id:"__placeholder__",role:"groupby",type:"string"},Qe={id:"__placeholder__",role:"metric",type:"number"},We={name:"Filter",id:"__placeholder__",role:"filter",type:"string"},rs={id:"__placeholder__"},fe="droppable-group-by",ge="droppable-metrics",je="droppable-pivot-by",Be="sortable-group-by",ot="sortable-metrics",ze="sortable-pivot-by",lt="droppable-filters",ct="sortable-filters",wt="sortable-order-by";function Un(){const s=t.useDndStore(A=>A.insertIndex),a=t.useEditorStore(A=>{var w;return((w=A.card.queryConfig)==null?void 0:w.groupByColumns)||[]}),n=t.useEditorStore(A=>{var w;return((w=A.card.queryConfig)==null?void 0:w.metricColumns)||[]}),r=t.useEditorStore(A=>{var w;return((w=A.card.queryConfig)==null?void 0:w.filterColumns)||[]}),i=t.useEditorStore(A=>{var w;return((w=A.card.queryConfig)==null?void 0:w.orderBy)||[]}),o=t.useEditorStore(A=>{var w;return((w=A.card.queryConfig)==null?void 0:w.pivotColumns)||[]}),{setInsertIndex:l,setActiveId:u,setPreviewGroupByColumns:c,setPreviewMetricColumns:h,setPreviewFilterColumns:d,setPreviewPivotColumns:m}=t.useDndActions(),{setGroupByColumns:N,setMetricColumns:f,setFilterColumns:g,setOrderByColumns:x,setPivotByColumns:v}=t.useEditorActions(),{columns:p}=t.useDataColumns(),{formattedTableName:k}=t.useEditorAside(),T=t.useSensors(t.useSensor(t.MouseSensor,{activationConstraint:{distance:1}})),E=A=>{var B;const{active:w,over:M}=A;if(((B=w.data.current)==null?void 0:B.type)==="column"&&M){const R=M.id,P=p.find(G=>G.column_name===w.id);if(!P)return;const z=t.isNumberDataType(P.data_type),K=t.isTextDataType(P.data_type),J=t.isDateDataType(P.data_type);if(K||J){if(a.some(U=>U.id===R)){const U=a.findIndex(V=>V.id===R);l(U);const q=a.filter(V=>V.id!==Ye.id);q.splice(U,0,Ye),c(q)}else if(M.id===fe){l(a.length);const U=[...a,Ye];c(U),h(n),d(r)}}if(K||J){if(o.some(U=>U.id===R)){const U=o.findIndex(V=>V.id===R);l(U);const q=o.filter(V=>V.id!==Ke.id);q.splice(U,0,Ke),m(q)}else if(M.id===je){l(o.length);const U=[...o,Ke];m(U),c(a),h(n),d(r)}}if(z||K){if(n.some(U=>U.id===R)){console.log("isOverMetricSortable",R);const U=n.findIndex(V=>V.id===R);l(U);const q=n.filter(V=>V.id!==Qe.id);q.splice(U,0,Qe),h(q)}else if(M.id===ge){l(n.length);const U=[...n,Qe];h(U),d(r),c(a),m(o)}}if(b(P)){if(r.some(U=>U.id===R)){const U=r.findIndex(V=>V.id===R);l(U);const q=r.filter(V=>V.id!==We.id);q.splice(U,0,We),d(q)}else if(M.id===lt){l(r.length);const U=[...r,We];d(U),h(n),c(a),m(o)}}}else c(a),h(n),d(r),m(o)};function j(A){u(A.active.id),l(null),c(a),h(n),d(r),m(o)}function b(A){return!r.some(w=>w.name===A.column_name)}function y(A,w="SUM"){const{column_name:M,data_type:B}=A,R=[...n],P=s!==null?s:n.length,z={...A,id:ue(M),name:M,label:Ee(M,w),type:B,role:"metric",aggregate:w};R.splice(P,0,z),f(R)}function S(A){const w=t.isTextDataType(A.data_type);t.isDateDataType(A.data_type);const M=[...o],B=s!==null?s:o.length;let R;w?R={...A,id:ue(A.column_name),name:A.column_name,type:A.data_type,role:"groupby"}:R={...A,id:ue(A.column_name),name:A.column_name,type:A.data_type,role:"groupby",label:Se(A.column_name,"month"),granularity:"month"},M.splice(B,0,R),v(M)}function I(A){const w=t.isTextDataType(A.data_type);t.isDateDataType(A.data_type);const M=[...a],B=s!==null?s:a.length;let R;w?R={...A,id:ue(A.column_name),name:A.column_name,type:A.data_type,role:"groupby"}:R={...A,id:ue(A.column_name),name:A.column_name,type:A.data_type,role:"groupby",label:Se(A.column_name,"month"),granularity:"month"},M.splice(B,0,R),N(M)}function D(A){const w=[...r],M=s!==null?s:r.length,B={...A,id:ue(A.column_name),name:A.column_name,type:A.data_type,sql:t.getDefaultFilterSql(A.data_type,k,t.fmt(A.column_name)),role:"filter"};w.splice(M,0,B),g(w)}function C(A){var R,P,z,K,J,G,U,q;const{active:w,over:M}=A,B=w.data.current;if((B==null?void 0:B.type)==="column"&&M){const V=p.find(Z=>Z.column_name===w.id);if(!V)return;const _=t.isNumberDataType(V.data_type),H=t.isTextDataType(V.data_type),Y=t.isDateDataType(V.data_type);(H||Y)&&(M.id===fe||((R=M.data.current)==null?void 0:R.type)===Be)&&I(V),(H||Y)&&(M.id===je||((P=M.data.current)==null?void 0:P.type)===ze)?S(V):(_||H)&&(M.id===ge||((z=M.data.current)==null?void 0:z.type)===ot)?(_&&y(V),H&&y(V,"COUNT")):b(V)&&(M.id===lt||((K=M.data.current)==null?void 0:K.type)===ct)&&D(V)}if(M&&((J=M.data.current)==null?void 0:J.type)===Be&&a.some(V=>V.id===w.id)){const V=a.findIndex(H=>H.id===w.id),_=a.findIndex(H=>H.id===M.id);if(V!==-1&&_!==-1&&V!==_){const H=[...a],[Y]=H.splice(V,1);H.splice(_,0,Y),N(H)}}if(M&&((G=M.data.current)==null?void 0:G.type)===ze&&o.some(V=>V.id===w.id)){const V=o.findIndex(H=>H.id===w.id),_=o.findIndex(H=>H.id===M.id);if(V!==-1&&_!==-1&&V!==_){const H=[...o],[Y]=H.splice(V,1);H.splice(_,0,Y),v(H)}}if(M&&((U=M.data.current)==null?void 0:U.type)===ot&&n.some(V=>V.id===w.id)){const V=n.findIndex(H=>H.id===w.id),_=n.findIndex(H=>H.id===M.id);if(V!==-1&&_!==-1&&V!==_){const H=[...n],[Y]=H.splice(V,1);H.splice(_,0,Y),f(H)}}if(M&&((q=M.data.current)==null?void 0:q.type)===ct&&r.some(V=>V.id===w.id)){const V=r.findIndex(H=>H.id===w.id),_=r.findIndex(H=>H.id===M.id);if(V!==-1&&_!==-1&&V!==_){const H=[...r],[Y]=H.splice(V,1);H.splice(_,0,Y),g(H)}}F(A),u(null),l(null),c(a),h(n),d(r),m(o)}function F(A){const{active:w,over:M}=A,B=w.data.current;if((B==null?void 0:B.type)===wt&&M){const R=i.findIndex(z=>ke(z.columnId)===w.id),P=i.findIndex(z=>ke(z.columnId)===M.id);if(R!==-1&&P!==-1&&R!==P){const z=[...i],[K]=z.splice(R,1);z.splice(P,0,K),x(z)}}}function O(){u(null),l(null),c(a),h(n),d(r)}return{handleDragOver:E,handleDragEnd:C,handleDragStart:j,handleDragCancel:O,sensors:T}}function ue(s){return`${s}-${t.v4()}`}function Ee(s,a){const n=t.toTitleCase(s.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 ke(s){return`${wt}-${s}`}function Se(s,a){const n=t.toTitleCase(s.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 Yn({schemaName:s,tableName:a,columns:n,status:r}){const i=t.useEditorStore(w=>w.sqlGen),o=t.useEditorStore(w=>w.isDevMode),l=t.useEditorStore(w=>w.selectedConnectionId),u=t.useEditorStore(w=>{var M,B;return(B=(M=w.card)==null?void 0:M.queryConfig)==null?void 0:B.metricColumns});t.useEditorStore(w=>{var M,B;return(B=(M=w.card)==null?void 0:M.queryConfig)==null?void 0:B.groupByColumns});const c=t.useEditorStore(w=>w.selectedDatabaseName),h=t.useEditorStore(w=>w.selectedSchemaName),d=t.useEditorStore(w=>w.selectedTableName),m=t.useEditorStore(w=>w.selectedDatamodelId),N=t.useDashboardStore(w=>w.dashboard.aiScopeTables),{addToAIScope:f,removeFromAIScope:g}=t.useDashboardActions(),{addColumnToMetricColumns:x,addColumnToGroupBy:v,setCardSql:p,setRunSql:k,setSqlGen:T,setIsShowingVisual:E}=t.useEditorActions(),{connectionType:j,modelItems:b,selectedDatamodelName:y}=t.useEditorAside();function S(w){var M;if(o){const B=t.createSqlGenConfig(w,i);T(B);const R=(M=b==null?void 0:b.find(z=>z.id===m))==null?void 0:M.name,P=t.getSql(B,t.fmt(s),t.fmt(a),R||"",j,c||"");P&&(p(P),k(!0))}if(!o){if(t.isTextDataType(w.data_type))if(u&&u.length>0){const B={...w,role:"groupby",id:ue(w.column_name),name:w.column_name,type:w.data_type};v(B)}else{const B={...w,role:"metric",id:ue(w.column_name),name:w.column_name,label:Ee(w.column_name,"COUNT"),type:w.data_type,aggregate:"COUNT"};x(B)}if(t.isDateDataType(w.data_type)){const B={...w,role:"groupby",id:ue(w.column_name),name:w.column_name,type:w.data_type,label:Se(w.column_name,"month"),granularity:"month"};v(B)}if(t.isNumberDataType(w.data_type)){const B={...w,role:"metric",id:ue(w.column_name),name:w.column_name,label:Ee(w.column_name,"SUM"),type:w.data_type,aggregate:"SUM"};x(B)}}}function I(w){w===!0&&(d||y)&&l?(f({connectionId:l,connectionType:j==="S3"||j==="API"?"DuckDb":j||"",databaseName:c||"",schemaName:h||"",tableName:d||"",datamodelName:t.resolveDatamodelName(y),datamodelId:m||""}),t.ue.success("Added to Assistant Scope",{position:"top-right",duration:2500,richColors:!0})):(g({connectionId:l||"",connectionType:j||"",tableName:d||"",datamodelName:t.resolveDatamodelName(y),datamodelId:m||"",databaseName:c||"",schemaName:h||""}),t.ue("Removed from Assistant Scope",{position:"top-right",duration:2e3,richColors:!0}))}function D(){const w=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:y,connectionType:j,databaseName:c||""});E(!1);const M=j==="MSSQL"?`SELECT top 10 * FROM ${w}`:`SELECT * FROM ${w} LIMIT 10`;p(M),k(!0)}function C(){const w=t.getFormattedTableNameForQuery({schemaName:s,tableName:a,modelName:y,connectionType:j,databaseName:c||""});p(`SELECT COUNT(*) as count FROM ${w}`),k(!0)}function F(){return(N==null?void 0:N.find(w=>w.connectionId===l&&(w.tableName===d||w.datamodelName===y)))!==void 0}function O(w){return o?e.jsxs("div",{className:"flex grow items-center justify-between space-x-2 rounded-md px-2 py-1",onClick:()=>S(w),children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(St,{column:w}),e.jsx("span",{children:w.column_name})]}),e.jsx("div",{onClick:M=>M.stopPropagation(),className:"flex items-center justify-end",children:t.isNumberDataType(w.data_type)&&e.jsx(Gn,{column:w})})]}):e.jsx(Jn,{onClick:S,column:w})}function A(){return e.jsxs(e.Fragment,{children:[e.jsxs(t.Toggle,{title:`${F()?"Remove from":"Add to"} Assistant Scope`,pressed:F(),onPressedChange:I,variant:"outline",className:t.cn("h-9 px-2",{}),children:[e.jsx(t.Plus,{className:t.cn("mr-1 size-4",{"text-green-400":F(),"text-muted-foreground":!F()})}),"AI"]}),e.jsxs(t.Button,{disabled:r!=="Success",onClick:D,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(Cn,{className:"mr-2 size-4"}),"Top 10"]}),e.jsxs(t.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(Wt,{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((w,M)=>e.jsx(t.Skeleton,{className:"h-7 w-full"},M))}):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:A()}),e.jsxs(t.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(w=>e.jsx("div",{className:t.cn("mr-2 cursor-pointer rounded-md text-sm transition-colors hover:bg-muted"),children:O(w)},w.column_name))}),e.jsx(t.ScrollBar,{orientation:"vertical"}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function is({ColumnsComponent:s,type:a}){var Ot;const n=t.useEditorStore(X=>X.card),r=t.useEditorStore(X=>X.selectedConnectionId),i=t.useDashboardStore(X=>X.showFilters),o=t.useEditorStore(X=>X.selectedDatamodelId),l=t.useEditorStore(X=>X.selectedDatabaseName),u=t.useEditorStore(X=>X.selectedSchemaName),c=t.useEditorStore(X=>X.selectedTableName),h=t.useEditorStore(X=>X.isDevMode),{setSelectedTableName:d,setIsDevMode:m,setCardSql:N}=t.useEditorActions(),{connectionItems:f,modelItems:g,schemaItems:x,databaseItems:v,tableItems:p,columns:k,isConnectionsLoading:T,isModelsLoading:E,isConnectionsError:j,isModelsError:b,isDatabasesLoadingOrFetching:y,isDatabaseError:S,isSchemaLoadingOrFetching:I,isSchemaError:D,isColumnsError:C,isColumnsLoadingOrFetching:F,isTableLoadingOrFetching:O,isTableError:A,connectionType:w,isNonDbConnection:M,refetchDatabases:B,refetchModels:R,refetchSchemas:P,refetchTables:z,refetchColumns:K,refetchConnections:J,handleConnectionChange:G,handleDatabaseChange:U,handleSchemaChange:q,handleDatamodelChange:V,handleTableChange:_,tableName:H,schemaName:Y}=t.useEditorAside(),{data:Z,refetch:de}=t.useDashboardCardQuery(n);function $(){return s?s(Y,H,k):e.jsx(Yn,{schemaName:Y,tableName:H,columns:k,status:F?"Loading...":C?"Error":"Success"})}function Q(){window.location.href="mailto:support@semaphor.cloud?subject=Help&body=I need help with..."}function se(X){X===!0?Z&&(N(Z.userSql),setTimeout(()=>{de()},100)):N(""),m(X)}function me(){if(!r||w==="S3"||w==="API")return null;if(!o||o==="none")return e.jsx(ve,{refetch:B,showNone:!0,onChange:U,isError:S,isLoading:y,items:v,value:l||"",title:"Database",type:"combobox"})}function Ms(){if(r&&!M&&(!l||l==="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(t.Separator,{})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Label,{children:"OR"})}),e.jsx("div",{className:"col-span-1 grid place-items-center",children:e.jsx(t.Separator,{})})]})}function As(){if(!r||w==="S3"||w==="API")return null;if(!l||l==="none")return e.jsx(ve,{refetch:R,showNone:!0,onChange:V,isError:b,isLoading:E,items:g,value:o||"",title:"Model",type:"combobox"})}function Ls(){return!r||w==="S3"||w==="API"||!l||l==="none"?null:e.jsx(ve,{refetch:P,onChange:q,isError:D,isLoading:I,items:x,value:u||"",title:"Schema",type:"combobox"})}function Os(){function X(){let xe=!1;return w==="API"?(xe=!1,xe):((w==="S3"||r&&l&&l!=="none"&&u)&&(xe=!0),xe)}return X()?e.jsx(ve,{refetch:z,onChange:_,isError:A,items:p,isLoading:O,value:c||"",title:"Table",type:"combobox"}):null}return e.jsxs("aside",{className:t.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(ve,{refetch:J,items:f,title:"Connection",value:r||"",onChange:G,isLoading:T,isError:j,type:"combobox",connectionTooltip:((Ot=f==null?void 0:f.find(X=>X.id===r))==null?void 0:Ot.type)||""}),me(),Ms(),As(),Ls(),Os()]}),$(),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(t.Switch,{className:"data-[state=checked]:bg-muted-foreground/80",checked:h,onCheckedChange:se,id:"dev-mode"}),e.jsx(t.Label,{htmlFor:"dev-mode",children:"Advanced Mode"})]}),e.jsxs(t.Button,{onClick:Q,size:"sm",variant:"secondary",className:"group flex items-center gap-2 rounded-full",children:[e.jsx(kn,{className:"size-4"}),e.jsx("span",{className:"hidden group-hover:block",children:"Help"})]})]})})]})}function os({sql:s,error:a,onClick:n}){const r=t.useEditorStore(c=>c.isDevMode),{setIsDevMode:i,setCardSql:o,setRunSql:l}=t.useEditorActions();function u(){i(!r),o(s),setTimeout(()=>{l(!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(t.ScrollArea,{className:"max-h-[250px] min-h-0 overflow-scroll text-xs leading-relaxed text-foreground/80",children:[a&&a,s&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsx("div",{className:"rounded-md",children:e.jsx(t.CodeHighlighter,{code:s,language:"sql"})})})]}),!r&&e.jsxs(t.Button,{onClick:u,variant:"secondary",size:"sm",children:[e.jsx(un,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),a&&n&&e.jsxs(t.Button,{onClick:n,size:"sm",variant:"secondary",children:[e.jsx(gn,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})]})})}function ls({sql:s,error:a,onClick:n}){return e.jsxs(t.HoverCard,{openDelay:a?0:500,children:[e.jsx(t.HoverCardTrigger,{asChild:!0,children:e.jsx(t.Button,{variant:"link",className:"h-5 p-0",children:a?e.jsx(Yt,{className:"h-4 w-4 text-red-500"}):e.jsx(t.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(t.HoverCardContent,{align:"start",className:"w-full min-w-fit max-w-[700px]",children:e.jsx(os,{sql:s,error:a,onClick:n})})]})}var cs={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},qt=L.createContext&&L.createContext(cs),Kn=["attr","size","title"];function Qn(s,a){if(s==null)return{};var n=Wn(s,a),r,i;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(s);for(i=0;i<o.length;i++)r=o[i],!(a.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(s,r)&&(n[r]=s[r])}return n}function Wn(s,a){if(s==null)return{};var n={};for(var r in s)if(Object.prototype.hasOwnProperty.call(s,r)){if(a.indexOf(r)>=0)continue;n[r]=s[r]}return n}function Re(){return Re=Object.assign?Object.assign.bind():function(s){for(var a=1;a<arguments.length;a++){var n=arguments[a];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(s[r]=n[r])}return s},Re.apply(this,arguments)}function _t(s,a){var n=Object.keys(s);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(s);a&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(s,i).enumerable})),n.push.apply(n,r)}return n}function Pe(s){for(var a=1;a<arguments.length;a++){var n=arguments[a]!=null?arguments[a]:{};a%2?_t(Object(n),!0).forEach(function(r){Xn(s,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(s,Object.getOwnPropertyDescriptors(n)):_t(Object(n)).forEach(function(r){Object.defineProperty(s,r,Object.getOwnPropertyDescriptor(n,r))})}return s}function Xn(s,a,n){return a=Zn(a),a in s?Object.defineProperty(s,a,{value:n,enumerable:!0,configurable:!0,writable:!0}):s[a]=n,s}function Zn(s){var a=ea(s,"string");return typeof a=="symbol"?a:a+""}function ea(s,a){if(typeof s!="object"||!s)return s;var n=s[Symbol.toPrimitive];if(n!==void 0){var r=n.call(s,a);if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(a==="string"?String:Number)(s)}function ds(s){return s&&s.map((a,n)=>L.createElement(a.tag,Pe({key:n},a.attr),ds(a.child)))}function ye(s){return a=>L.createElement(ta,Re({attr:Pe({},s.attr)},a),ds(s.child))}function ta(s){var a=n=>{var{attr:r,size:i,title:o}=s,l=Qn(s,Kn),u=i||n.size||"1em",c;return n.className&&(c=n.className),s.className&&(c=(c?c+" ":"")+s.className),L.createElement("svg",Re({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,l,{className:c,style:Pe(Pe({color:s.color||n.color},n.style),s.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),o&&L.createElement("title",null,o),s.children)};return qt!==void 0?L.createElement(qt.Consumer,null,n=>a(n)):a(cs)}function sa(s){return ye({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(s)}function us(s){const{theme:a}=t.useTheme(),n=t.useDashboardStore(x=>x.theme),r=t.useEditorStore(x=>x.frame),i=t.useEditorStore(x=>x.card),o=t.useEditorStore(x=>x.activeTabCardId),l=t.Le(),{refetch:u}=t.useDashboardCardQuery(i),{updateCardTab:c,setRunSql:h}=t.useEditorActions(),d=L.useRef(),m=L.useRef({}),N=r.cards.find(x=>x.id===o),f=L.useCallback(()=>{let x="";return s==="python"&&(x=(N==null?void 0:N.python)||t.PYTHON_DEFAULT_CODE),s==="sql"&&(x=(N==null?void 0:N.sql)||""),x},[s,N]);L.useEffect(()=>{if(o&&i.id&&i.id!==o){if(d.current&&l){const x=d.current.getModel();x&&(m.current[i.id]=x);let v=m.current[o];if(!v){const p=f();v=l.editor.createModel(p,s),m.current[o]=v}d.current.setModel(v)}c(o,i),h(!0)}},[o,i,c,l,h,s,f]),L.useEffect(()=>{if(!l)return;const x=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",v=n==="system"?x:n;l.editor.defineTheme("default",{base:v==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":v==="light"?"#ffffff":t.hslStringToHex("240 10% 10%")}}),l.editor.setTheme("default")},[a,n,l]),L.useEffect(()=>{const x=d.current;x&&l&&i&&x.addCommand(l.KeyMod.Shift|l.KeyCode.Enter,function(){return u(),!1})},[l,u,i]);function g(x,v){if(d.current=x,!m.current[i.id]){const p=x.getModel(),k=f();m.current[i.id]=p||(v==null?void 0:v.editor.createModel(k,s))||x.getModel()}x.setModel(m.current[i.id])}return{handleEditorDidMount:g}}function na(){const s=t.useEditorStore(l=>l.card.sql),a=t.useEditorStore(l=>l.sqlGen),{setCardSql:n,setSqlGen:r}=t.useEditorActions(),{handleEditorDidMount:i}=us("sql");function o(l){n(l),t.isObjectEmpty(a)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!s&&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(t.Ft,{theme:"default",className:"pt-3",onChange:o,value:s||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:i})]})}function aa(){const s=t.useEditorStore(i=>i.card.python),{setCardPython:a}=t.useEditorActions(),{handleEditorDidMount:n}=us("python");function r(i){a(i)}return e.jsx(t.Ft,{className:"pt-3",theme:"default",onChange:r,value:s||t.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:n})}function ra({jsonString:s}){return e.jsx(t.Ft,{theme:"default",defaultLanguage:"json",className:"mt-1 min-h-[220px]",value:s,options:{readOnly:!0,minimap:{enabled:!1},lineNumbers:"off",glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})}function ia(){const s=t.useQueryClient(),[a,n]=L.useState(!1),[r,i]=L.useState(!1);t.useEditorStore(z=>z.frame);const o=t.useEditorStore(z=>z.card);t.useEditorStore(z=>z.isShowingVisual),t.useEditorStore(z=>z.selectedConnectionId),t.useEditorStore(z=>z.tempQueryData),t.useEditorStore(z=>z.selectedDatabaseName),t.useEditorStore(z=>z.selectedDatamodelId),t.useEditorStore(z=>z.selectedSchemaName);const l=t.useEditorStore(z=>z.showAIDialog);t.useEditorStore(z=>z.selectedTableName);const u=t.useEditorStore(z=>{var K;return(K=z==null?void 0:z.card)==null?void 0:K.sql}),c=t.useEditorStore(z=>{var K;return(K=z==null?void 0:z.card)==null?void 0:K.python}),{sheetFilterValues:h}=t.useSheetFilterValues(),{setCardCustomCfg:d,setQueryResultColumns:m,setCardSql:N,setTempQueryData:f,setPythonStdOut:g,setCardPreferences:x,setCardType:v,setCardPython:p,runAssistant:k,setShowAIDialog:T}=t.useEditorActions();t.useEditorStore(z=>z.onSave),t.useEditorStore(z=>z.onClose),t.useEditorStore(z=>z.actions.setSqlGen);const E=t.useEditorStore(z=>z.runSql),j=t.useEditorStore(z=>z.actions.setRunSql),b=t.useEditorStore(z=>z.actions.setIsSqlRunning),{data:y,isLoading:S,isFetching:I,isSuccess:D,isError:C,error:F,queryKey:O,refetch:A,errorMessage:w}=t.useDashboardCardQuery(o);L.useEffect(()=>{if(y&&(y.rowLimitExceeded&&t.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),g((y==null?void 0:y.output)||""),y.records.length>0)){const{dimensionKeys:z}=t.getKeys(y.records);m(z)}},[y,m,g]),L.useEffect(()=>{(S||I)&&b(!0),(C||D)&&b(!1),C&&(m([]),g(""))},[S,I,y,g,C,D,b,m,F]),L.useEffect(()=>{E&&(s.getQueryData(O)||A(),j(!1))},[E,A,j,O,s]);async function M(){const z=`Can you help me debug this query in the current table scope?
|
|
387
|
+
|
|
388
|
+
Error:
|
|
389
|
+
|
|
390
|
+
${w}
|
|
391
|
+
|
|
392
|
+
Query:
|
|
393
|
+
|
|
394
|
+
${u}
|
|
395
|
+
|
|
396
|
+
${c?`Python:
|
|
397
|
+
${c}`:""}
|
|
398
|
+
`;k(z)}function B(){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(ra,{jsonString:JSON.stringify(h,null,2)})})}),h&&h.length>0&&e.jsx(t.Button,{variant:"ghost",onClick:()=>i(!r),className:"absolute bottom-0 right-6 size-7 p-1",children:r?e.jsx(t.X,{className:"size-3.5 text-muted-foreground"}):e.jsx(gt,{className:"size-3.5 text-muted-foreground"})})]})}function R(){return e.jsxs(t.ResizablePanelGroup,{className:"flex grow pb-1",direction:"vertical",role:"editor-resizable-group",children:[e.jsxs(t.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(na,{})}),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(t.ResizableHandle,{withHandle:!0,className:"border"}),e.jsxs(t.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(aa,{})}),e.jsx("code",{className:"absolute right-6 top-3 text-xs text-muted-foreground/70",children:"python"})]})]})]})}function P(){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(t.Button,{title:"Shift + Enter",disabled:S||I,onClick:()=>{A()},className:"h-8 shrink-0",size:"sm",children:[S||I?e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(t.Play,{className:"mr-2 h-4 w-4"}),"Run"]}),e.jsx(ls,{sql:y==null?void 0:y.sql,error:w,onClick:M}),e.jsx(t.EditorClearButton,{}),e.jsx(t.Toggle,{pressed:a,onPressedChange:z=>n(z),className:"",size:"sm",children:e.jsx(sa,{className:"size-4 text-foreground/70"})}),e.jsx("button",{disabled:l,onClick:()=>{T(!0)},className:"h-9 w-full cursor-text px-3 text-left text-sm text-muted-foreground",children:l?"":"Type your question..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.EditorCancelButton,{}),e.jsx(t.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:[R(),B()]}),P()]})}function oa({data:s}){var l;const[a,n]=L.useState([]),i=Object.keys(s[0]).map(u=>({accessorKey:u,header:({column:c})=>{const h=c.getIsSorted();return e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"flex cursor-pointer items-center",onClick:()=>c.toggleSorting(c.getIsSorted()==="asc"),children:[u,h==="asc"?e.jsx(t.TriangleUpIcon,{className:"ml-2 h-5 w-5"}):h==="desc"?e.jsx(t.TriangleDownIcon,{className:"ml-2 h-5 w-5"}):null]})})}})),o=t.useReactTable({data:s,columns:i,getCoreRowModel:t.getCoreRowModel(),getPaginationRowModel:t.getPaginationRowModel(),onSortingChange:n,getSortedRowModel:t.getSortedRowModel(),manualPagination:!0,state:{sorting:a}});return e.jsxs(t.CustomScrollArea,{className:"grow overflow-auto font-mono text-xs text-foreground/95",children:[e.jsxs("table",{className:"w-full",children:[e.jsx(t.TableHeader,{className:"sticky top-0 z-50 h-0 bg-muted",children:o.getHeaderGroups().map(u=>e.jsx(t.TableRow,{className:"",children:u.headers.map(c=>e.jsx(t.TableHead,{className:"h-11 font-semibold text-foreground",children:c.isPlaceholder?null:t.flexRender(c.column.columnDef.header,c.getContext())},c.id))},u.id))}),e.jsx(t.TableBody,{children:(l=o.getRowModel().rows)!=null&&l.length?o.getRowModel().rows.map(u=>e.jsx(t.TableRow,{className:"h-11 whitespace-nowrap py-2","data-state":u.getIsSelected()&&"selected",children:u.getVisibleCells().map(c=>e.jsx(t.TableCell,{className:"py-2",children:t.flexRender(c.column.columnDef.cell,c.getContext())},c.id))},u.id)):e.jsx(t.TableRow,{children:e.jsx(t.TableCell,{colSpan:i.length,className:"h-24 text-center",children:"No results."})})})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}function la({card:s}){var k,T,E,j,b,y,S,I,D,C,F;const[a,n]=L.useState(!1),[r,i]=L.useState([]),{authToken:o}=t.useSemaphorContext(),l=t.getTokenParams(o==null?void 0:o.accessToken),u=t.useDashboardStore(O=>O.themeStyle),c={colors:((T=(k=u==null?void 0:u.chart)==null?void 0:k.dataset)==null?void 0:T.backgroundColor)||[]};(E=s.customCardPreferences)!=null&&E.inputData;const{getCard:h}=t.useCustomVisual(((j=s.customCardPreferences)==null?void 0:j.url)||""),d=((b=s.customCardPreferences)==null?void 0:b.visualType)||"single",m=t.useEditorStore(O=>O.frame),{setCustomCardPreferences:N}=t.useEditorActions(),{data:f}=t.useDashboardCardQuery(s),g=L.useCallback((O,A)=>{i(w=>({...w,[O]:A}))},[]);if(!((y=s.customCardPreferences)!=null&&y.componentName))return null;const x=h((S=s.customCardPreferences)==null?void 0:S.componentName);function v(O){n(O)}const p=Object.keys(((I=s.customCardPreferences)==null?void 0:I.dataInputCardIds)||{}).map(O=>{var M,B,R;const A=(B=(M=s.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:B[O].cardId,w=(R=m==null?void 0:m.cards)==null?void 0:R.find(P=>P.id===A);return w||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(L.Suspense,{fallback:e.jsx(e.Fragment,{}),children:[x&&d==="single"&&e.jsx(x,{params:l,theme:c,settings:(D=s.customCardPreferences)==null?void 0:D.settings,onDataChange:g,data:(f==null?void 0:f.records)||[]}),x&&d==="multiple"&&e.jsxs(e.Fragment,{children:[Object.keys(((C=s.customCardPreferences)==null?void 0:C.dataInputCardIds)||{}).map(O=>{var M,B,R;const A=(B=(M=s.customCardPreferences)==null?void 0:M.dataInputCardIds)==null?void 0:B[O].cardId,w=(R=m==null?void 0:m.cards)==null?void 0:R.find(P=>P.id===A);if(w)return e.jsx(t.MultiInputEmptyRenderer,{onLoadingStatus:v,onDataChange:g,dataInputIndex:O,card:w},w.id+O)}),e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx(x,{theme:c,onDataChange:g,settings:p.map(O=>{var A;return(A=O==null?void 0:O.customCardPreferences)==null?void 0:A.settings}),data:p.map(O=>O!=null&&O.id?r==null?void 0:r[O.id]:[])})})]})]},(F=s.customCardPreferences)==null?void 0:F.componentName)})}function ms({className:s,...a}){var v;const n=t.useEditorStore(p=>p.card),r=((v=n.customCardPreferences)==null?void 0:v.showCardHeader)??!0,i=t.useEditorStore(p=>p.frame),o=t.useDashboardStore(p=>p.dashboard.filters);t.useEditorStore(p=>p.actions.setRunSql);const{updateFilter:l}=t.useDashboardActions(),u=o==null?void 0:o.find(p=>p.id===i.filterId),{data:c,isLoading:h,isFetching:d}=t.useDashboardCardQuery(n),{setCard:m}=t.useEditorActions(),{data:N}=t.useTopoJson(n),f=L.useMemo(()=>!n.id||!(c!=null&&c.records)?null:t.createChartConfig({card:n,data:c==null?void 0:c.records,cardType:n.type,queryConfig:n.queryConfig,customCfg:n.customCfg,preferences:n.preferences,topoJson:N}),[n.id,c==null?void 0:c.records,n.type,n.queryConfig,n.customCfg,n.preferences,N]);function g(p){return e.jsx(la,{card:p})}function x(){if(c!=null&&c.records&&(c==null?void 0:c.records.length)===0&&!h&&!d)return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2",children:[e.jsx(t.TreePalm,{className:"size-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No results to display"})]});if(!n.id)return null;if(n.type==="custom")return g(n);if(!["table","custom"].includes(n.type)&&f)return e.jsx(e.Fragment,{children:h||d?e.jsx(e.Fragment,{}):e.jsx(t.ChartJsVisual,{cfg:f})});if(n.type==="table"&&(c!=null&&c.records)&&(c==null?void 0:c.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(t.TableVisual,{card:n,data:c==null?void 0:c.records})})}return e.jsxs(t.Card,{role:"editor-visual-card",className:t.cn("relative flex h-full flex-col rounded-none",s),...a,children:[r&&e.jsxs(t.CardHeader,{className:"flex flex-row items-start justify-between py-4",children:[e.jsxs("div",{children:[e.jsx(t.Editable,{enabled:!0,text:n.title,onSave:p=>m({...n,title:p}),children:e.jsx("div",{className:"flex items-center gap-5",children:e.jsx(t.CardTitle,{className:"text-base",children:n.title||"Add title"})})},n.title),e.jsx(t.Editable,{enabled:!0,text:n.description||"",onSave:p=>m({...n,description:p}),children:e.jsx(t.CardDescription,{children:n.description||"Add description"})},n.description)]}),u&&e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Editable,{enabled:!0,className:"my-1",text:u.title||u.column,onSave:p=>l({...u,title:p}),children:e.jsx(t.Label,{children:u.title})}),e.jsx(t.FilterComponent,{filter:u})]})]}),e.jsx(t.CardContent,{className:"flex grow flex-col",children:x()})]})}const Xe=({language:s,value:a,onChange:n,readonly:r})=>e.jsx(t.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:s,value:a,onChange:n}),ca=()=>e.jsxs(t.DialogHeader,{children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(t.DialogTitle,{children:"Customize Card"})}),e.jsxs(t.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."})]})]}),da=({customCode:s,cardCustomCfgString:a,mergedConfig:n,onConfigChange:r,onCodeChange:i})=>e.jsxs(t.Tabs,{defaultValue:"final-config",className:"flex w-1/2 flex-col",children:[e.jsxs(t.TabsList,{className:"justify-start rounded-sm rounded-b-none border border-b-0",children:[e.jsx(t.TabsTrigger,{value:"final-config",children:"Config"}),e.jsx(t.TabsTrigger,{value:"custom-config",children:"Changes"}),e.jsx(t.TabsTrigger,{value:"custom-code",children:"Custom Code"})]}),e.jsx(t.TabsContent,{value:"final-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{language:"json",value:n,onChange:r})}),e.jsx(t.TabsContent,{value:"custom-config",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{readonly:!0,language:"json",value:a,onChange:()=>{}})}),e.jsx(t.TabsContent,{value:"custom-code",className:"mt-0 grow rounded-b border border-t-0",children:e.jsx(Xe,{language:"javascript",value:s,onChange:i})})]}),ua=({error:s,hasCardCustomConfig:a,onReset:n,onApply:r,onClose:i})=>e.jsxs(t.DialogFooter,{className:"flex items-center",children:[e.jsx(t.Label,{className:"mr-2 text-red-500",children:s}),e.jsx(t.Button,{disabled:!a,onClick:n,variant:"outline",children:"Reset"}),e.jsx(t.Button,{onClick:r,variant:"outline",children:"Apply"}),e.jsx(t.Button,{onClick:i,variant:"outline",children:"Close"})]});function ma(){const[s,a]=L.useState(!1),[n,r]=L.useState(""),[i,o]=L.useState(""),[l,u]=L.useState(""),[c,h]=L.useState(""),d=t.useEditorStore(j=>j.card),m=t.useEditorStore(j=>j.card.customCfg),N=m?JSON.stringify(m,null,2):"",{data:f}=t.useDashboardCardQuery(d),{data:g}=t.useTopoJson(d),{setCardCustomCfg:x,setCustomVisualCode:v}=t.useEditorActions(),p=j=>{var b,y;return JSON.stringify({...j,data:{...j.data,datasets:(y=(b=j.data)==null?void 0:b.datasets)==null?void 0:y.map(S=>({...S,data:[]}))}},null,2)},k=()=>{var b,y;if(!((b=f==null?void 0:f.records)!=null&&b.length))return;const j=t.createChartConfig({card:d,data:f.records,cardType:d.type,queryConfig:d.queryConfig,preferences:d.preferences,topoJson:g});if(j){r(p(j)),u(((y=d.preferences)==null?void 0:y.customVisualCode)||"");const S=t.merge(j,m);o(p(S))}},T=()=>{try{if(l&&v(l),i){const j=JSON.parse(i),b=t.getObjectDiff(JSON.parse(n),j);x(b),h("")}}catch{h("Invalid JSON configuration")}},E=Object.keys(m||{}).length===0;return e.jsxs(t.Dialog,{open:s,onOpenChange:a,children:[e.jsx(t.DialogTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Customize Visual",onClick:k,className:E?"":"text-green-600 hover:text-green-700",children:e.jsx(t.Settings,{className:"h-4 w-4"})})}),e.jsxs(t.DialogContent,{className:"flex h-[600px] grow flex-col overflow-auto sm:min-w-[900px] lg:min-w-[1200px]",children:[e.jsx(ca,{}),e.jsxs("div",{className:"flex grow gap-2",children:[e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(ms,{className:"w-1/2 rounded shadow-none"})}),e.jsx(da,{customCode:l,cardCustomCfgString:N,mergedConfig:i,onConfigChange:j=>o(j??""),onCodeChange:j=>u(j??"")})]}),e.jsx(ua,{error:c,hasCardCustomConfig:!!m,onReset:()=>{o(n),x(null)},onApply:T,onClose:()=>a(!1)})]})]})}function hs(s){const[a,n]=L.useState(null);return a}function xs(){const{authToken:s}=t.useSemaphorContext(),{data:a,isLoading:n,isFetching:r,isError:i}=t.useQuery({queryKey:["plugins",s==null?void 0:s.accessToken],queryFn:()=>t.getPlugins(s==null?void 0:s.accessToken)});return{data:a,isLoading:n,isFetching:r,isError:i}}function ha({onChartTypeChange:s}){const[a,n]=L.useState([]),{setCardCustomCfg:r,setCardPreferences:i,setCardType:o,setCustomCardPreferences:l}=t.useEditorActions(),{data:u}=xs();function c(h,d){r(null),i({}),o(h),d&&l({type:"component",visualType:"single",url:d.url,componentName:d.name,icon:d.icon}),s==null||s()}return L.useEffect(()=>{(async()=>{var d;if(u){const N=(await Promise.all((d=u==null?void 0:u.plugins)==null?void 0:d.map(async f=>(await t.loadManifest(f.value)).visuals.map(v=>({name:v.name,icon:v.icon,url:f.value}))))).flat();n(N)}})()},[u]),a.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx(t.Separator,{className:"my-2"}),e.jsx("div",{className:"grid grid-cols-4 place-items-center",children:a.map((h,d)=>e.jsx(xa,{text:h.name,onClick:()=>c("custom",h),icon:h.icon},h.url+h.name+d))})]})}const xa=({text:s,icon:a,onClick:n})=>{const r=hs(),i=s.charAt(0).toUpperCase();return e.jsx(t.IconButton,{onClick:n,tooltip:s,children:r?e.jsx(r,{className:"h-4 w-4"}):i})};function kt(s){return ye({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm87.63,96H191.48A64.1,64.1,0,0,0,136,64.52V40.37A88.13,88.13,0,0,1,215.63,120ZM120,120H80.68A48.09,48.09,0,0,1,120,80.68Zm0,16v39.32A48.09,48.09,0,0,1,80.68,136Zm16,0h39.32A48.09,48.09,0,0,1,136,175.32Zm0-16V80.68A48.09,48.09,0,0,1,175.32,120ZM120,40.37V64.52A64.1,64.1,0,0,0,64.52,120H40.37A88.13,88.13,0,0,1,120,40.37ZM40.37,136H64.52A64.1,64.1,0,0,0,120,191.48v24.15A88.13,88.13,0,0,1,40.37,136ZM136,215.63V191.48A64.1,64.1,0,0,0,191.48,136h24.15A88.13,88.13,0,0,1,136,215.63Z"},child:[]}]})(s)}function pa(s){return ye({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:[]}]})(s)}function Et(s){return ye({attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M6 16m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"},child:[]},{tag:"path",attr:{d:"M16 19m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"},child:[]},{tag:"path",attr:{d:"M14.5 7.5m-4.5 0a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0 -9 0"},child:[]}]})(s)}function It(s){return ye({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:[]}]})(s)}function Dt(s){return ye({attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"},child:[]},{tag:"path",attr:{d:"m2 19.99 7.5-7.51 4 4 7.09-7.97L22 9.92l-8.5 9.56-4-4-6 6.01-1.5-1.5zm1.5-4.5 6-6.01 4 4L22 3.92l-1.41-1.41-7.09 7.97-4-4L2 13.99l1.5 1.5z"},child:[]}]})(s)}function Tt(s){return ye({attr:{version:"1.2",baseProfile:"tiny",viewBox:"0 0 24 24"},child:[{tag:"path",attr:{d:"M4 18c-.552 0-1-.448-1-1v-6.382l-.553.276c-.495.248-1.095.046-1.342-.447-.247-.494-.046-1.094.448-1.342l2-1c.31-.155.678-.139.973.044.294.183.474.504.474.851v8c0 .552-.448 1-1 1zM13 18h-5c-.404 0-.769-.244-.924-.617-.155-.374-.069-.804.217-1.09l4-4c.254-.254.394-.591.394-.95 0-.358-.14-.695-.394-.949-.508-.508-1.39-.508-1.9.001-.253.252-.393.589-.393.948 0 .552-.448 1-1 1s-1-.448-1-1c0-.894.348-1.733.98-2.364 1.265-1.263 3.464-1.263 4.727.001.632.631.979 1.471.979 2.363 0 .893-.348 1.733-.979 2.364l-2.293 2.293h2.586c.552 0 1 .448 1 1s-.448 1-1 1zM20.955 12.377c.338-.457.545-1.016.545-1.627 0-1.517-1.234-2.75-2.75-2.75-1.031 0-1.966.569-2.44 1.484-.254.49-.063 1.094.428 1.348.49.254 1.094.062 1.348-.428.128-.249.383-.404.664-.404.414 0 .75.336.75.75s-.336.75-.75.75c-.552 0-1 .448-1 1s.448 1 1 1c.689 0 1.25.561 1.25 1.25s-.561 1.25-1.25 1.25-1.25-.561-1.25-1.25c0-.552-.448-1-1-1s-1 .448-1 1c0 1.792 1.458 3.25 3.25 3.25s3.25-1.458 3.25-3.25c0-.939-.406-1.779-1.045-2.373z"},child:[]}]})(s)}function ps({onChartTypeChange:s,iconClassName:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:i}=t.useEditorStore(d=>d.actions),{setCardCustomCfg:o,setCustomCardPreferences:l,setQueryConfig:u}=t.useEditorActions();function c(d,m){o(null),r({}),n(d),["kpi","custom","text","map"].includes(d)&&(i(!0),u(void 0)),s==null||s()}const h=1e3;return e.jsxs("div",{className:"grid grid-cols-5 place-items-center",children:[e.jsx(t.IconButton,{openDelay:h,tooltip:"Table",onClick:()=>c("table"),className:"h-10 p-4",children:e.jsx(He,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Bar Chart",onClick:()=>c("bar"),className:"h-10 p-4",children:e.jsx($e,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Line Chart",onClick:()=>c("line"),className:"h-10 p-4",children:e.jsx(Ge,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Stacked Bar Chart",onClick:()=>c("stackedBar"),className:"h-10 p-4",children:e.jsx(ut,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Stacked Line Chart",onClick:()=>c("stackedLine"),className:"h-10 p-4",children:e.jsx(Dt,{className:t.cn("size-5",a),strokeWidth:0})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Scatter Chart",onClick:()=>c("scatter"),className:"h-10 p-4",children:e.jsx(pt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Bubble Chart",onClick:()=>c("bubble"),className:"h-10 p-4",children:e.jsx(Et,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Pie Chart",onClick:()=>c("pie"),className:"h-10 p-4",children:e.jsx(xt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Doughnut Chart",onClick:()=>c("doughnut"),className:"h-10 p-4",children:e.jsx(ft,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Funnel Chart",onClick:()=>c("funnel"),className:"h-10 p-4",children:e.jsx(It,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Radar Chart",onClick:()=>c("radar"),className:"h-10 p-4",children:e.jsx(bt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Polar Area Chart",onClick:()=>c("polarArea"),className:"h-10 p-4",children:e.jsx(kt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Tornado Chart",onClick:()=>c("tornado"),className:"h-10 p-4",children:e.jsx(Nt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{tooltip:"Range Chart",onClick:()=>c("range"),className:"h-10 p-4",children:e.jsx(ht,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"KPI",onClick:()=>c("kpi"),className:"h-10 p-4",children:e.jsx(Tt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Text",onClick:()=>c("text"),className:"h-10 p-4",children:e.jsx(Ut,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{tooltip:"Map",onClick:()=>c("map"),className:"h-10 p-4",children:e.jsx(yt,{className:t.cn("size-5",a)})}),e.jsx(t.IconButton,{openDelay:h,tooltip:"Custom",onClick:()=>c("custom"),className:"h-10 p-4",children:e.jsx(vt,{className:t.cn("size-5",a)})})]})}function fa({chartType:s,className:a,customIcon:n,componentName:r}){const i=hs();switch(s){case"bar":return e.jsx($e,{className:a});case"line":return e.jsx(Ge,{className:a});case"pie":return e.jsx(xt,{className:a});case"radar":return e.jsx(bt,{className:a});case"scatter":return e.jsx(pt,{className:a});case"bubble":return e.jsx(Et,{className:a});case"doughnut":return e.jsx(ft,{className:a});case"stackedBar":return e.jsx(ut,{className:a});case"stackedLine":return e.jsx(Dt,{className:a});case"polarArea":return e.jsx(kt,{className:a});case"funnel":return e.jsx(It,{className:a});case"tornado":case"pyramid":return e.jsx(Nt,{className:a});case"range":return e.jsx(ht,{className:a});case"kpi":return e.jsx(Tt,{className:a});case"text":return e.jsx(es,{className:a});case"map":return e.jsx(yt,{className:a});case"custom":return n&&i?e.jsx(i,{className:a}):r?r==null?void 0:r.charAt(0).toUpperCase():e.jsx(vt,{className:a});default:return e.jsx(He,{className:a})}}function fs({variant:s="ghost"}){var o,l;const[a,n]=L.useState(!1),r=t.useEditorStore(u=>u.card),i=r.type;return t.useDashboardStore(u=>u.isVisualEditing),e.jsxs(t.Popover,{open:a,onOpenChange:n,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:s||"ghost",children:e.jsx(fa,{className:"size-4",chartType:i,customIcon:(o=r.customCardPreferences)==null?void 0:o.icon,componentName:(l=r.customCardPreferences)==null?void 0:l.componentName})})}),e.jsxs(t.PopoverContentCustom,{onOpenAutoFocus:u=>u.preventDefault(),className:"w-72 p-1",children:[e.jsx(ps,{onChartTypeChange:()=>n(!1)}),e.jsx(ha,{onChartTypeChange:()=>n(!1)})]})]})}const Ae="focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0";function $t(s,a){var r,i,o;const n=t.getNumberAxis(s,{});return["pie","doughnut","polarArea","funnel"].includes(a)?"category":((o=(i=(r=s==null?void 0:s.chartOptions)==null?void 0:r.scales)==null?void 0:i[n])==null?void 0:o.type)||"linear"}function ga(){var M,B,R,P,z,K;const[s,a]=L.useState(!1),n=t.useEditorStore(J=>{var G;return(G=J.card)==null?void 0:G.preferences}),r=t.useEditorStore(J=>{var G;return(G=J.card)==null?void 0:G.type}),i=t.getNumberAxis(n,{}),[o,l]=L.useState($t(n,r)),[u,c]=L.useState(((R=(B=(M=n==null?void 0:n.chartOptions)==null?void 0:M.scales)==null?void 0:B[i])==null?void 0:R.min)||""),[h,d]=L.useState(((K=(z=(P=n==null?void 0:n.chartOptions)==null?void 0:P.scales)==null?void 0:z[i])==null?void 0:K.max)||""),[m,N]=L.useState(u||h?"custom":"auto"),[f,g]=L.useState(""),[x,v]=L.useState(0),[p,k]=L.useState(""),[T,E]=L.useState(""),[j,b]=L.useState(""),y=t.useEditorStore(J=>J.actions.setCardPreferences),{updateCardInFrame:S}=t.useEditorActions(),I=t.useEditorStore(J=>J.card),D=["pie","doughnut","polarArea","funnel"].includes(r);L.useEffect(()=>{var J,G,U,q,V,_,H,Y,Z,de,$,Q,se,me;l($t(n,r)),c(((U=(G=(J=n==null?void 0:n.chartOptions)==null?void 0:J.scales)==null?void 0:G[i])==null?void 0:U.min)===0?0:""),d(((_=(V=(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales)==null?void 0:V[i])==null?void 0:_.max)||""),g(((de=(Z=(Y=(H=n==null?void 0:n.chartOptions)==null?void 0:H.scales)==null?void 0:Y[i])==null?void 0:Z.ticks)==null?void 0:de.stepSize)||""),v((($=n==null?void 0:n.numberAxisFormat)==null?void 0:$.decimalPlaces)||0),k(((Q=n==null?void 0:n.numberAxisFormat)==null?void 0:Q.suffix)||""),E(((se=n==null?void 0:n.numberAxisFormat)==null?void 0:se.currency)||""),b(((me=n==null?void 0:n.numberAxisFormat)==null?void 0:me.locale)||"")},[s,n,i,r]);function C(J,G){return G===""||/^[0-9\b]+$/.test(G)?Number(G):Number(J)}function F(){const J=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(G=>G.currency))];return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-6 items-center gap-2",children:[e.jsx(t.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(t.Select,{value:T||"none",onValueChange:G=>E(G==="none"?"":G),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),J.map(G=>e.jsx(t.SelectItem,{value:G,children:G},G))]})})]}),e.jsxs(t.Select,{value:j,onValueChange:G=>b(G),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Locale"}),t.LOCALE_CURRENCY_PAIRS.map(G=>e.jsx(t.SelectItem,{value:G.locale,children:G.locale},G.locale))]})})]})]}),e.jsxs("div",{className:"grid grid-cols-9 items-center gap-2",children:[e.jsx(t.Label,{className:"col-span-3",htmlFor:"format",children:"Decimals"}),e.jsx(t.Input,{value:x,onChange:G=>v(Number(G.target.value)),id:"format",className:`col-span-6 h-8 w-full tracking-wide ${Ae}`})]})]})}function O(){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(t.Label,{htmlFor:"scale",children:"Type"}),e.jsxs(t.Select,{disabled:D,value:o,onValueChange:J=>l(J),children:[e.jsx(t.SelectTrigger,{className:"col-span-2 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{id:"type",children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Option"}),e.jsx(t.SelectItem,{value:"linear",children:"Linear"}),e.jsx(t.SelectItem,{value:"logarithmic",children:"Logarithmic"}),e.jsx(t.SelectItem,{value:"category",children:"Category"})]})})]})]}),o=="linear"&&e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2 py-1",children:[e.jsx(t.Label,{htmlFor:"scale-option",children:"Setup"}),e.jsxs(t.RadioGroup,{disabled:D,id:"scale-option",value:m,onValueChange:J=>N(J),className:"col-span-2 flex gap-3",defaultValue:"x",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.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(t.RadioGroupItem,{value:"custom",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Custom"})]})]})]}),m==="custom"&&o=="linear"&&A()]})}function A(){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"range",children:"Range"}),e.jsx(t.Input,{id:"min",value:u,onChange:J=>c(G=>C(G,J.target.value)),className:`col-span-1 h-8 w-full ${Ae}`}),e.jsx(t.Input,{value:h,onChange:J=>d(G=>C(G,J.target.value)),id:"max",className:`col-span-1 h-8 w-full ${Ae}`})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-2",children:[e.jsx(t.Label,{htmlFor:"step-size",children:"Step Size"}),e.jsx(t.Input,{value:f,onChange:J=>g(G=>C(G,J.target.value)),id:"step-size",className:`col-span-1 h-8 w-full ${Ae}`})]})]})}function w(){var q;let J={};m==="custom"&&(J={min:u,max:h,ticks:{stepSize:f}});const G={...n||{},chartOptions:{...n==null?void 0:n.chartOptions,scales:{...(q=n==null?void 0:n.chartOptions)==null?void 0:q.scales,[i]:{type:o,...o==="linear"?J:{}}}},numberAxisFormat:{decimalPlaces:x,suffix:p,currency:T,locale:j}};console.log(G),y(G);const U={...I,preferences:G};S(U)}return e.jsxs(t.Popover,{onOpenChange:J=>a(J),children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Format Number",children:e.jsx(cn,{className:"size-4"})})}),e.jsx(t.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:[F(),O(),e.jsx(t.SelectSeparator,{}),e.jsx("div",{className:"grid grid-cols-3",children:e.jsx(t.Button,{onClick:w,variant:"secondary",className:"col-span-1 col-start-3 h-8 w-full",children:"Apply"})})]})]})})]})}function ja(){const s=t.useEditorStore(u=>{var c,h,d,m;return(m=(d=(h=(c=u.card.preferences)==null?void 0:c.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:m.position}),a=t.useEditorStore(u=>{var c,h,d,m;return(m=(d=(h=(c=u.card.preferences)==null?void 0:c.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:m.align}),n=t.useEditorStore(u=>{var c,h,d,m;return(m=(d=(h=(c=u.card.preferences)==null?void 0:c.chartOptions)==null?void 0:h.plugins)==null?void 0:d.legend)==null?void 0:m.display}),{setLegendOptions:r}=t.useEditorActions(),i=u=>{r({display:u,position:s,align:a})},o=u=>{r({display:n,position:u,align:a})},l=u=>{r({display:n,position:s,align:u})};return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsx(t.IconButton,{tooltip:"Legend Settings",children:e.jsx(yn,{className:"size-4"})})}),e.jsx(t.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(t.Label,{htmlFor:"displayLegend",children:"Display"}),e.jsx("div",{className:"col-span-2 flex h-8 items-center",children:e.jsx(t.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(t.Label,{htmlFor:"position",children:"Position"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Top",onClick:()=>o("top"),children:e.jsx(_e,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Left",onClick:()=>o("left"),children:e.jsx(Hs,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Bottom",onClick:()=>o("bottom"),children:e.jsx(qe,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Right",onClick:()=>o("right"),children:e.jsx(Js,{className:"size-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 items-center gap-4",children:[e.jsx(t.Label,{htmlFor:"align",children:"Align"}),e.jsxs("div",{className:"col-span-2 flex h-8 items-center",children:[e.jsx(t.IconButton,{tooltip:"Start",onClick:()=>l("start"),children:e.jsx(Vs,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"Center",onClick:()=>l("center"),children:e.jsx(Ps,{className:"size-4"})}),e.jsx(t.IconButton,{tooltip:"End",onClick:()=>l("end"),children:e.jsx(qs,{className:"size-4"})})]})]})]})]})]})})]})}function ya(){const s=t.useEditorStore(o=>{var l,u;return(u=(l=o.card.preferences)==null?void 0:l.chartOptions)==null?void 0:u.indexAxis}),a=t.useEditorStore(o=>o.card.type),{setChartOrientation:n}=t.useEditorStore(o=>o.actions);function r(){return e.jsx(t.IconButton,{onClick:()=>{n(s==="x"||s===void 0?"y":"x")},tooltip:"Chart Orientation",children:s==="x"||s===void 0?e.jsx(Rt,{className:"size-4"}):e.jsx(zt,{className:"size-4"})})}function i(){return e.jsx(t.IconButton,{onClick:()=>{n(s==="y"||s===void 0?"x":"y")},tooltip:"Chart Orientation",children:s==="y"||s===void 0?e.jsx(Rt,{className:"size-4"}):e.jsx(zt,{className:"size-4"})})}return e.jsx(e.Fragment,{children:a==="funnel"?i():r()})}function gs(){const s=t.useEditorStore(l=>l.card),a=t.useEditorStore(l=>l.isShowingVisual),n=t.useEditorStore(l=>{var u,c;return(c=(u=l.card)==null?void 0:u.preferences)==null?void 0:c.chartOptions}),r=t.getChartGridStyle(n),{setChartGrid:i}=t.useEditorActions();function o(){const l=["xy","none","x","y"],c=(l.indexOf(r)+1)%l.length;i(l[c])}return a?e.jsxs("div",{"data-info":"visual-settings",className:"flex items-center",children:[["line","bar","range","stackedBar","stackedLine","horizontalBar","funnel"].includes(s.type)&&e.jsx(ya,{}),!["kpi","text","custom","table"].includes(s.type)&&e.jsxs(e.Fragment,{children:[e.jsx(ga,{}),e.jsx(ja,{})]}),!["pie","doughnut","funnel","radar","polarArea","table","custom","kpi","text","map"].includes(s.type)&&e.jsxs(t.IconButton,{tooltip:"Grid Style",onClick:o,children:[(r==="xy"||!r)&&e.jsx(fn,{className:"size-4"}),r==="x"&&e.jsx(rn,{className:"size-4"}),r==="y"&&e.jsx(Tn,{className:"size-4"}),r==="none"&&e.jsx(Ln,{className:"size-4"})]})]}):null}function ba(){const s=t.useEditorStore(g=>g.frame),a=t.useEditorStore(g=>g.card),{setFrame:n,setActiveTabCardId:r,setCard:i,updateCardInFrame:o}=t.useEditorActions(),l=(g,x)=>{g.dataTransfer.setData("tabIndex",x.toString())},u=g=>{g.preventDefault()},c=(g,x)=>{const v=g.dataTransfer.getData("tabIndex");if(v===x.toString())return;const p=Array.from(s.cards),[k]=p.splice(parseInt(v),1);p.splice(x,0,k),n({...s,cards:p})};function h(g){const x=s.cards.filter(k=>k.id!==g),v=x[0],p={...s,cards:x,activeCardId:v.id};n(p),r(v.id),i(v)}function d(g,x){const v={...s,cards:[...s.cards,x],activeCardId:g.id};n(v),r(x.id)}function m(){const g={...a,id:t.v4(),title:`${a.title} Copy`,tabTitle:`${a.tabTitle||a.title} Copy`};d(a,g)}function N(g){const x={connectionId:g.connectionId,lastSelectedDatabase:g.lastSelectedDatabase,lastSelectedSchema:g.lastSelectedSchema,lastSelectedTable:g.lastSelectedTable,lastSelectedDatamodelId:g.lastSelectedDatamodelId,id:t.v4(),title:"Title",description:"",preferences:{onClickFilter:[{columnIndex:0,expression:""}]},type:"bar",sql:"",data:[]};d(g,x)}function f(g,x){return g.cards.length===1&&(x.displayTab===!0||x.displayTab===void 0)||g.activeCardId!==x.id&&(x.displayTab===!0||x.displayTab===void 0)?null:e.jsx("div",{onClick:()=>{const v=x.displayTab===void 0?!1:!x.displayTab;i({...x,displayTab:v}),o({...x,displayTab:v})},children:x.displayTab===!0||x.displayTab===void 0?e.jsx(t.Eye,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"}):e.jsx(dn,{className:"mr-2 size-3.5 text-muted-foreground hover:text-foreground"})})}return e.jsx(t.TabsList,{className:"group mx-4 justify-between overflow-x-auto",children:e.jsxs("div",{className:"flex items-center",children:[s.cards.map((g,x)=>e.jsxs(t.TabsTrigger,{draggable:!0,onDragStart:v=>l(v,x),onDragOver:u,onDrop:v=>c(v,x),className:"",value:g.id,children:[f(s,g),e.jsx(t.Editable,{enabled:s.activeCardId===g.id,text:g.tabTitle||g.title,onSave:v=>{i({...a,tabTitle:v}),o({...a,tabTitle:v})},children:g.tabTitle||g.title},g.id),s.activeCardId===g.id&&s.cards.length>1&&e.jsx(t.X,{className:"ml-2 size-3.5 text-muted-foreground hover:text-foreground",onClick:()=>h(g.id)})]},g.id)),e.jsx(t.Button,{className:"ml-1 h-8 px-2 hover:bg-muted-foreground/50",variant:"outline",onClick:()=>N(a),children:e.jsx(t.Plus,{className:"h-4 w-4"})}),e.jsx(t.Button,{className:"invisible ml-1 h-8 px-2 hover:bg-muted-foreground/50 group-hover:visible",variant:"outline",onClick:m,children:e.jsx(ln,{className:"h-4 w-4"})})]})})}function js(){const s=t.useEditorStore(x=>x.frame),a=t.useEditorStore(x=>x.card),n=t.useEditorStore(x=>x.isSqlRunning),r=t.useEditorStore(x=>x.isDevMode),{setFrame:i,setActiveTabCardId:o,setCard:l,setIsDevMode:u,setRunSql:c}=t.useEditorActions(),{data:h,isLoading:d,isFetching:m}=t.useDashboardCardQuery(a);function N(x){const v=s.cards.find(p=>p.id===x);if(v!=null&&v.sql){r||u(!0),o(x);return}if(v!=null&&v.queryConfig){r&&u(!1),f(x),o(x);return}r||f(x),o(x)}function f(x){const v={...s,cards:s.cards.map(k=>k.id===a.id?a:k),activeCardId:x};i(v);const p=v.cards.find(k=>k.id===x);p.sql&&c(!0),l(p)}function g(){return a.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(t.KPICard,{card:a,data:h==null?void 0:h.records,isPending:d})})}):a.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(t.ScrollArea,{className:"mx-3 my-6 h-[300px] overflow-y-auto break-words px-3",children:e.jsx(t.TextCard,{isLoading:n,card:a,data:h==null?void 0:h.records})})})}):e.jsx(t.ErrorBoundary,{FallbackComponent:t.FallbackEditorCard,children:e.jsx(ms,{className:"grow border-none shadow-none"})})}return e.jsxs(t.Tabs,{onValueChange:N,value:s.activeCardId,className:"flex grow flex-col",children:[s.cards.map(x=>e.jsx(t.TabsContent,{className:"mt-0 grow",value:x.id,children:g()},x.id)),e.jsx(ba,{})]})}function Le({children:s}){var k;t.useEditorStore(T=>T.frame);const a=t.useEditorStore(T=>T.card),n=t.useEditorStore(T=>T.isDevMode),r=t.useEditorStore(T=>T.isShowingVisual),i=t.useDashboardStore(T=>T.isVisualEditing),o=t.useEditorStore(T=>T.pythonStdOut);t.useEditorStore(T=>T.actions.setRunSql);const{setFrame:l,setCard:u,setActiveTabCardId:c,runAssistant:h,setIsDevMode:d}=t.useEditorActions(),{data:m,isLoading:N,isFetching:f,error:g}=t.useDashboardCardQuery(a);function x(){const T=JSON.stringify(m==null?void 0:m.records,null,2),E=new Blob([T],{type:"application/json"}),j=URL.createObjectURL(E),b=document.createElement("a");b.href=j,b.download=`${a.title}.json`,b.click()}function v(){const E=[Object.keys(m==null?void 0:m.records.reduce((S,I)=>({...S,...I}),{})).join(","),...((m==null?void 0:m.records)||[]).map(S=>Object.values(S).join(","))].join(`
|
|
399
|
+
`),j=new Blob([E],{type:"text/csv"}),b=URL.createObjectURL(j),y=document.createElement("a");y.href=b,y.download=`${a.title}.csv`,y.click()}function p(){const T=`Can you get the documentation for ${a.type} chart?`;h(T)}return a?e.jsxs("div",{className:"relative isolate flex h-full flex-col py-2 pb-3",children:[(N||f)&&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:[r&&e.jsxs("div",{className:"flex grow items-center",children:[e.jsx(fs,{}),i&&e.jsx(t.IconButton,{tooltip:"Visual Docs",onClick:p,children:e.jsx(Qs,{className:"size-4"})}),!["table","custom"].includes(a.type)&&i&&e.jsx(ma,{})]}),!r&&e.jsxs("div",{className:"flex grow items-center gap-1",children:[e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:v,children:e.jsx(pa,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70",variant:"ghost",size:"icon",onClick:x,children:e.jsx(mn,{strokeWidth:1.5,className:"size-4"})}),e.jsx(t.CopyButton,{text:JSON.stringify(m==null?void 0:m.records,null,2),className:"h-7 w-fit px-1 font-mono text-xs text-muted-foreground/70"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s,e.jsx(gs,{})]}),n&&e.jsx(Na,{})]}),r?e.jsx(js,{}):e.jsxs(t.ResizablePanelGroup,{className:"px-6",direction:"horizontal",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{id:"1",order:1,defaultSize:30,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:o&&e.jsx(va,{})}),e.jsx(t.ResizableHandle,{})]}),e.jsxs(t.ResizablePanel,{id:"2",order:2,minSize:10,className:"relative flex h-full min-h-0 w-full flex-1 basis-0",children:[(m==null?void 0:m.records)&&(m==null?void 0:m.records.length)>0&&e.jsx(oa,{data:(m==null?void 0:m.records)||[]}),(g||(m==null?void 0:m.error))&&e.jsx("span",{className:"font-mono text-xs",children:(g==null?void 0:g.message)||((k=m==null?void 0:m.error)==null?void 0:k.message)})]})]})]}):e.jsx(e.Fragment,{children:"No Active Card"})}function va(){const s=t.useEditorStore(n=>n.pythonStdOut);if(!s)return null;const a=s.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(t.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(t.ScrollBar,{orientation:"horizontal"})]})]})}function Na(){const s=t.useEditorStore(n=>n.isShowingVisual),a=t.useEditorStore(n=>n.actions.setIsShowingVisual);return e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Label,{htmlFor:"visualize",children:"Chart"}),e.jsx(t.SmallSwitch,{checked:s,onCheckedChange:()=>a(!s),id:"visualize",className:"data-[state=checked]:bg-foreground/50"})]})}function Ca(){var x,v;const s=t.useEditorStore(p=>p.card.customCardPreferences),{data:a}=xs(),n=(a==null?void 0:a.plugins)||[],r=t.useEditorStore(p=>p.card),i=t.useEditorStore(p=>p.frame),o=(s==null?void 0:s.visualType)||"single",{setCustomCardPreferences:l}=t.useEditorActions(),{components:u,manifest:c}=t.useCustomVisual((s==null?void 0:s.url)||""),h=(x=c==null?void 0:c.visuals)==null?void 0:x.find(p=>p.name===(s==null?void 0:s.componentName));function d(p,k){if(!s)return;const E={...(s==null?void 0:s.dataInputCardIds)||{},[p]:{cardId:k,hookRef:null}};l({...s,dataInputCardIds:E})}function m(p){var T,E;const k=(T=i==null?void 0:i.cards)==null?void 0:T.filter(j=>{var b;return((b=j==null?void 0:j.customCardPreferences)==null?void 0:b.visualType)!=="multiple"}).map(j=>({value:j.id,label:j.tabTitle||j.title}));return e.jsx("div",{className:"space-y-2",children:(E=p==null?void 0:p.dataInputs)==null?void 0:E.map((j,b)=>{var y,S;return e.jsxs("div",{className:"grid grid-cols-10 gap-2",children:[e.jsx("div",{className:"col-span-4 flex items-center",children:j}),e.jsx(le,{className:"col-span-6 h-8 w-full justify-between",label:"",options:k||[],value:((S=(y=s==null?void 0:s.dataInputCardIds)==null?void 0:y[b])==null?void 0:S.cardId)||"",onValueChange:I=>d(b,I)})]},b+Math.random())})})}function N(p,k,T=[],E=""){var j,b;return s?p==="input"?e.jsx(t.Input,{className:`h-8 w-full ${t.removeRing}`,value:((j=s==null?void 0:s.settings)==null?void 0:j[k])||E,onChange:y=>{l({...s,settings:{...s==null?void 0:s.settings,[k]:y.target.value}})}},k):p==="select"?e.jsx(le,{className:"h-8 w-full",label:"",options:T,value:((b=s==null?void 0:s.settings)==null?void 0:b[k])||E,onValueChange:y=>{l({...s,settings:{...s==null?void 0:s.settings,[k]:y}})}}):null:null}function f(p){const k=Object.entries((p==null?void 0:p.settings)||{});return e.jsx("div",{className:"space-y-3",children:k.map(([T,E])=>e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:E.title}),N(E.ui,T,E.options,E.defaultValue)]},T))})}function g(p){s&&l({...s,visualType:p,componentName:""})}return e.jsxs(t.Accordion,{type:"multiple",defaultValue:["component-settings"],className:"px-6 py-2",children:[e.jsxs(t.AccordionItem,{value:"plugin-settings",children:[e.jsx(t.AccordionTrigger,{children:"Plugin"}),e.jsx(t.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(le,{icon:e.jsx(Ks,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Plugin",options:n,value:(s==null?void 0:s.url)||"",onValueChange:p=>l({...s||{url:"",componentName:""},url:p})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&e.jsx(t.Tabs,{value:o,onValueChange:g,children:e.jsxs(t.TabsList,{className:"h-9 w-full",children:[e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"single",children:"Single Visual"}),e.jsx(t.TabsTrigger,{className:"h-7 w-full",value:"multiple",children:"Multi-Visual"})]})})]})}),((s==null?void 0:s.type)==="component"||(s==null?void 0:s.type)===void 0)&&s&&e.jsx(e.Fragment,{children:u&&e.jsx(le,{icon:e.jsx(on,{className:"h-3.5 w-3.5"}),className:"h-9 w-full",label:"Select Component",options:(u==null?void 0:u.filter(p=>p.type===o).map(p=>({value:p.name,label:p.name})))||[],value:s.componentName,onValueChange:p=>{console.log("changing value",p),l({...s,componentName:p})}})})]})})]}),((v=r==null?void 0:r.customCardPreferences)==null?void 0:v.componentName)&&e.jsxs(t.AccordionItem,{className:"border-none",value:"component-settings",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{children:[h&&h.dataInputs&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Input Mapping"}),e.jsx("div",{className:"px-2",children:m(h)})]}),h&&h.settings&&e.jsx("div",{className:"space-y-3",children:e.jsx("div",{className:"px-2",children:f(h)})})]})]})]})}function be(){const[s,a]=L.useState([]),n=t.useEditorStore(h=>h.card.preferences),{setFilterOnClickColumnIndex:r,setCardPreferences:i}=t.useEditorStore(h=>h.actions),o=t.useEditorStore(h=>h.queryResultColumns);t.useEditorStore(h=>{var d;return(d=h.card.preferences)==null?void 0:d.filterOnClickColumnIndex}),L.useEffect(()=>{o&&a(new Array(o.length).fill(!1))},[o]);function l(h,d){var m,N;d?n!=null&&n.onClickFilter&&((m=n==null?void 0:n.onClickFilter)==null?void 0:m.length)>0?i({...n,onClickFilter:[...n.onClickFilter,{columnIndex:h,expression:""}]}):i({...n,onClickFilter:[{columnIndex:h,expression:""}]}):(i({...n,onClickFilter:(N=n==null?void 0:n.onClickFilter)==null?void 0:N.filter(f=>f.columnIndex!==h)}),a(f=>{const g=[...f];return g[h]=!1,g}))}function u(h,d){var N;const m=(N=n==null?void 0:n.onClickFilter)==null?void 0:N.map(f=>f.columnIndex===h?{...f,expression:d.target.value}:f);i({...n,onClickFilter:m})}function c(h){var d,m,N,f;if(s!=null&&s[h]||(m=(d=n==null?void 0:n.onClickFilter)==null?void 0:d.find(g=>g.columnIndex===h))!=null&&m.expression)return e.jsx(t.Input,{value:(f=(N=n==null?void 0:n.onClickFilter)==null?void 0:N.find(g=>g.columnIndex===h))==null?void 0:f.expression,onChange:g=>u(h,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(t.Label,{children:"On Click"}),o==null?void 0:o.map((h,d)=>{var m,N;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(t.Checkbox,{checked:!!((m=n==null?void 0:n.onClickFilter)!=null&&m.find(f=>f.columnIndex===d)),onCheckedChange:f=>l(d,f)}),e.jsx("label",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:h}),e.jsx("div",{className:"flex items-center gap-2",children:((N=n==null?void 0:n.onClickFilter)==null?void 0:N.find(f=>f.columnIndex===d))&&e.jsx(t.Pencil,{onClick:()=>{a(f=>{const g=[...f];return g[d]=!f[d],g})},className:"invisible size-3 cursor-pointer text-gray-400 group-hover:visible"})})]}),c(d)]})},h)})]})}function Sa({idx:s}){var u;const a=t.useEditorStore(c=>{var h;return(h=c.card)==null?void 0:h.preferences}),n=t.useEditorStore(c=>{var h;return(h=c.card.preferences)==null?void 0:h.datasetOptions}),r=t.useEditorStore(c=>c.actions.setCardPreferences),i=(u=a==null?void 0:a.chartOptions)==null?void 0:u.indexAxis,o=n==null?void 0:n.find(c=>c.idx===s);function l(c,h){(c==="end"||c==="start")&&t.getContrastColor(t.getCanvasBackgroundColor());const d={display:c!=="none",align:c,anchor:c,clamp:!0};if(!o)r({...a,datasetOptions:[...n||[],{idx:h,datalabels:d}]});else{const m={...o};m.datalabels=d;const N=n==null?void 0:n.map(f=>f.idx===h?m:f);r({...a,datasetOptions:N})}}return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{children:e.jsx(Xt,{className:"size-4 rotate-[135deg] cursor-pointer text-muted-foreground hover:text-foreground"})}),e.jsx(t.PopoverContent,{className:"w-fit px-2 py-1",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>l("none",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(t.X,{className:"size-3.5"})}),e.jsx("button",{onClick:()=>l("start",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(bn,{className:t.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>l("center",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(Nn,{className:t.cn("h-4 w-4",{"rotate-90":i==="y"})})}),e.jsx("button",{onClick:()=>l("end",s),className:"h-7 p-1 text-xs font-normal",children:e.jsx(vn,{className:t.cn("h-4 w-4",{"rotate-90":i==="y"})})})]})})]})}function ys(){const s=t.useEditorStore(o=>o.card),{data:a}=t.useDashboardCardQuery(s),{keys:n}=t.getKeys((a==null?void 0:a.records)||[]),r=n.slice(1).filter(o=>!t.METADATA_KEYS.includes(o));let i=r;if(["stackedBar","stackedLine"].includes(s.type)){const o=t.pivotData({dataArray:(a==null?void 0:a.records)||[],groupKey:n[0],pivotKey:n[1],valueKey:n[2]}),{keys:l}=t.getKeys(o);i=l.slice(1)}return{transformedMetricKeys:i,dimensionKeys:n.slice(0,1),keys:n,defaultMetricKeys:r}}function Ve({children:s,className:a,delayDuration:n}){return e.jsx(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{delayDuration:n,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:t.cn("overflow-hidden text-ellipsis whitespace-nowrap",a),children:s})}),e.jsx(t.TooltipContent,{children:s})]})})}function bs(){const s=t.useEditorStore(c=>c.card),a=t.useEditorStore(c=>{var h,d,m;return(m=(d=(h=c==null?void 0:c.card)==null?void 0:h.preferences)==null?void 0:d.chartOptions)==null?void 0:m.indexAxis}),{data:n}=t.useDashboardCardQuery(s),r=a==="y"?"Metric":"Dimension",i=a==="y"?"Dimension":"Metric",{dimensionKeys:o,transformedMetricKeys:l,keys:u}=ys();return u.length===0?null:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:r}),e.jsx("div",{className:"max-h-[125px] space-y-1 overflow-y-auto",children:o.map(c=>e.jsx("p",{className:"flex h-8 items-center rounded-md bg-muted/70 px-3 hover:bg-muted",title:c,children:vs(c)},c))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:i}),e.jsx("div",{className:"my-1 max-h-[125px] space-y-1 overflow-y-auto",children:l.map((c,h)=>e.jsx(Ns,{className:"flex h-8 items-center bg-muted/70 px-3 hover:bg-muted",iconClassName:"invisible group-hover:visible",col:c,idx:h},c))})]})]})}function vs(s,a=30){return s.length>a?s.slice(0,a)+"...":s}function Ns({col:s,idx:a,className:n,iconClassName:r,children:i}){const o=t.useEditorStore(d=>{var m;return(m=d.card)==null?void 0:m.preferences}),l=t.useEditorStore(d=>{var m,N;return(N=(m=d.card)==null?void 0:m.preferences)==null?void 0:N.datasetOptions}),u=l==null?void 0:l.find(d=>d.idx===a),{setCardPreferences:c}=t.useEditorStore(d=>d.actions);function h(d){if(!u)c({...o,datasetOptions:[...l||[],{idx:a,type:d==="area"?"line":d,fill:d==="area"?"origin":""}]});else{const m={...u};m.type=d==="area"?"line":d,m.fill=d==="area"?"origin":"";const N=l==null?void 0:l.map(f=>f.idx===a?m:f);c({...o,datasetOptions:N})}}return e.jsxs("div",{className:t.cn("group flex items-center justify-between gap-2 rounded-md",n),children:[i||e.jsx(Ve,{className:"max-w-[100px]",title:s,children:vs(s)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx($e,{onClick:()=>h("bar"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Ge,{onClick:()=>h("line"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(en,{onClick:()=>h("area"),className:t.cn("size-4 cursor-pointer text-muted-foreground hover:text-foreground",r)}),e.jsx(Sa,{idx:a})]})]})}function Cs(){const s=t.useEditorStore(f=>f.selectedConnectionId),a=t.useEditorStore(f=>f.selectedDatamodelId),n=t.useEditorStore(f=>f.selectedDatabaseName),r=t.useEditorStore(f=>f.selectedSchemaName),i=t.useEditorStore(f=>f.selectedTableName),o=t.useDashboardStore(f=>f.dashboard.filters)||[],l=t.useDashboardStore(f=>f.actions.addFilter),u=t.useDashboardStore(f=>f.actions.removeFilter),{removeFilterValues:c}=t.useDashboardActions(),{modelItems:h,tableName:d,connectionType:m}=t.useEditorAside();function N(f,g="dashboard"){var y;const x=t.fmt(f.column_name),v=t.fmt(n||""),p=t.fmt(r||""),k=t.fmt(d);let T=t.getQualifiedTableName({schemaName:p,tableName:k,connectionType:m,databaseName:v}),E=`${T}.${x}`;const j=(y=h==null?void 0:h.find(S=>S.id===a))==null?void 0:y.name;a&&a!=="none"&&(E=`${t.DATAMODEL_NAMESPCACE}.${j}.${x}`,T=`${t.DATAMODEL_NAMESPCACE}.${j}`);const b=o==null?void 0:o.find(S=>S.column===E&&S.table===k&&(S.database===v||S.database===n));if(b)c(b.id),u(b.id);else{const S=t.v4();return d==="api"&&s?(l({location:g,id:S,column:E,title:f.column_name,dataType:f.data_type,table:"api",database:"",connectionId:s,operation:"in",sql:t.getDefaultFilterSql(f.data_type,T,x)}),S):(l({id:S,location:g,column:E,title:f.column_name,dataType:f.data_type,table:i||"",database:n||"",connectionId:s||"",operation:"in",sql:t.getDefaultFilterSql(f.data_type,T,x)}),S)}}return{assignFilter:N}}function we(){const s=t.useDashboardStore(u=>u.dashboard.filters),a=t.useEditorStore(u=>u.frame),{setFrame:n}=t.useEditorActions(),{columns:r}=t.useEditorAside(),{assignFilter:i}=Cs();function o(u){const c=i(u,"frame");n({...a,filterId:c})}const l=s==null?void 0:s.find(u=>u.id===a.filterId);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(t.Label,{children:"Card Filter"}),e.jsx(wa,{onSelect:o,columns:r}),l&&e.jsx(t.FilterHeader,{filter:l})]})}function wa({columns:s,onSelect:a}){var l;const[n,r]=re.useState(!1),[i,o]=re.useState("");return e.jsxs(t.Popover,{open:n,onOpenChange:r,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{size:"sm",variant:"outline",role:"combobox","aria-expanded":n,className:"w-full justify-between font-normal",children:[i?(l=s.find(u=>u.column_name===i))==null?void 0:l.column_name:"Select Column...",e.jsx(t.CaretSortIcon,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"w-[200px] p-0",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search column",className:"h-9"}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No framework found."}),e.jsx(t.CommandGroup,{children:s==null?void 0:s.map(u=>e.jsxs(t.CommandItem,{value:u.column_name,onSelect:c=>{const h=c===i?"":c;o(h),r(!1),h&&a(u)},children:[u.column_name,e.jsx(t.CheckIcon,{className:t.cn("ml-auto h-4 w-4",i===u.column_name?"opacity-100":"opacity-0")})]},u.column_name))})]})]})})]})}function ka({cardType:s}){return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"space-y-4 px-2",children:e.jsx(bs,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(be,{}),e.jsx(we,{})]})]})]})})}function Mt(){var i,o,l;const s=t.useEditorStore(u=>u.card.type),a=t.useEditorStore(u=>u.card.preferences),{setCardPreferences:n}=t.useEditorStore(u=>u.actions);function r(u){var d;const c={datalabels:{display:u!=="none",align:u,anchor:u,clamp:!0}},h={...a,chartOptions:{...a==null?void 0:a.chartOptions,plugins:{...(d=a==null?void 0:a.chartOptions)==null?void 0:d.plugins,...c}}};n(h),console.log(u)}return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"font-medium",children:"Data Labels"}),e.jsxs(t.Select,{value:((l=(o=(i=a==null?void 0:a.chartOptions)==null?void 0:i.plugins)==null?void 0:o.datalabels)==null?void 0:l.anchor)||"none",onValueChange:r,defaultValue:"none",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{placeholder:"Select position"})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Data Labels"}),e.jsx(t.SelectItem,{value:"none",children:"None"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{value:"start",children:"Start"}),e.jsx(t.SelectItem,{value:"center",children:"Center"}),!["pyramid","funnel"].includes(s)&&e.jsx(t.SelectItem,{value:"end",children:"End"})]})})]})]})}function Ea({cardType:s}){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(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} Chart`}),e.jsx(t.AccordionContent,{className:"space-y-4 font-mono text-xs",children:a(s)})]}),e.jsxs(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsx(t.AccordionContent,{className:"px-2",children:e.jsx(Mt,{})})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(be,{}),e.jsx(we,{})]})]})]})})}const Ia={datasets:[{type:"line",label:"Sum_sales",data:[]},{type:"bar",label:"Sum_profit",data:[]}]},Da={datasets:[{fill:"origin",type:"line",label:"Sum_sales",data:[]}]};function Ta(){const s=t.useEditorStore(a=>a.card.type);return e.jsxs("div",{className:"space-y-6 p-6",children:[e.jsx(t.Accordion,{className:" ",type:"single",collapsible:!0,children:Ma(s)}),!["kpi"].includes(s)&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(Mt,{}),e.jsx(be,{}),e.jsx(we,{})]})]})}function Ma(s){if(["line","bar"].includes(s))return e.jsxs(e.Fragment,{children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsx("p",{children:"Chart Query"})}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Mixed Chart"}),e.jsxs(t.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(Ia,null,2)})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:"Area Chart"}),e.jsxs(t.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(Da,null,2)})]})]})]});if(s==="bubble")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.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(s==="scatter")return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:["How to create a ",e.jsx("span",{children:s})," chart query?"]})}),e.jsxs(t.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(s))return e.jsx(e.Fragment,{children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"font-normal",children:e.jsxs("p",{children:[e.jsx("span",{children:s==="polarArea"?"Polar":s.charAt(0).toUpperCase()+s.slice(1)})," ","chart query"]})}),e.jsxs(t.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 Aa(){var c,h,d,m,N;const s=t.useEditorStore(f=>f.card.preferences),a=t.useEditorStore(f=>f.actions.setCardPreferences),n=t.useEditorStore(f=>f.actions.setNumberFormat);t.useEditorStore(f=>{var g,x;return(x=(g=f.card.preferences)==null?void 0:g.formatNumber)==null?void 0:x.decimalPlaces});const r=t.useEditorStore(f=>{var g,x;return(x=(g=f.card.preferences)==null?void 0:g.formatNumber)==null?void 0:x.locale}),i=t.useEditorStore(f=>{var g,x;return(x=(g=f.card.preferences)==null?void 0:g.formatNumber)==null?void 0:x.currency});t.useEditorStore(f=>f.actions.setFilterOnClickField);const o=t.useEditorStore(f=>{var g,x;return(x=(g=f.card.preferences)==null?void 0:g.formatNumber)==null?void 0:x.colorRanges})||[],l=t.useEditorStore(f=>f.actions.setColorRanges),u=[...new Set(t.LOCALE_CURRENCY_PAIRS.map(f=>f.currency))];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(t.Checkbox,{checked:!!((c=s==null?void 0:s.formatNumber)!=null&&c.enabled),onCheckedChange:f=>{a({...s,formatNumber:{...s==null?void 0:s.formatNumber,enabled:f}})}}),e.jsx(t.Label,{children:"Format Number"})]}),((h=s==null?void 0:s.formatNumber)==null?void 0:h.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(t.Label,{children:"Locale"}),e.jsxs(t.Select,{value:r||"none",onValueChange:f=>{var g,x,v;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((x=s==null?void 0:s.formatNumber)==null?void 0:x.currency)||"",f,((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Format"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),t.LOCALE_CURRENCY_PAIRS.map(f=>e.jsx(t.SelectItem,{value:f.locale,children:f.locale},f.locale))]})})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Currency"}),e.jsxs(t.Select,{value:i||"none",onValueChange:f=>{var g,x,v;console.log("currency",f),n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,f==="none"?"":f,((x=s==null?void 0:s.formatNumber)==null?void 0:x.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-6 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:e.jsxs(t.SelectGroup,{children:[e.jsx(t.SelectLabel,{children:"Currency"}),e.jsx(t.SelectItem,{value:"none",children:"None"},"none"),u.map(f=>e.jsx(t.SelectItem,{value:f,children:f},f))]})})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Decimals"}),e.jsxs(t.Select,{value:((m=(d=s==null?void 0:s.formatNumber)==null?void 0:d.decimalPlaces)==null?void 0:m.toString())||"0",onValueChange:f=>{var g,x,v;return n(Number(f),((g=s==null?void 0:s.formatNumber)==null?void 0:g.currency)||"",((x=s==null?void 0:s.formatNumber)==null?void 0:x.locale)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.suffix)||"")},children:[e.jsx(t.SelectTrigger,{className:"col-span-3 h-8 w-full focus:ring-1 focus:ring-offset-0",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:["0","1","2","3","4"].map(f=>e.jsx(t.SelectItem,{value:f,children:f},f))})]})]}),e.jsxs("div",{className:"w-full space-y-1",children:[e.jsx(t.Label,{children:"Suffix"}),e.jsx(t.Input,{value:((N=s==null?void 0:s.formatNumber)==null?void 0:N.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:f=>{var g,x,v;return n(((g=s==null?void 0:s.formatNumber)==null?void 0:g.decimalPlaces)||0,((x=s==null?void 0:s.formatNumber)==null?void 0:x.currency)||"",((v=s==null?void 0:s.formatNumber)==null?void 0:v.locale)||"",f.target.value)}})]})]})]})}),e.jsx(t.Separator,{className:"my-3"}),e.jsx(t.ColorFormat,{colorRanges:o,setColorRanges:l})]})]})}function La(){return e.jsxs("div",{className:"space-y-6 px-6 py-2",children:[e.jsx(t.Accordion,{type:"single",collapsible:!0,children:e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{className:"",children:"KPI Query"}),e.jsxs(t.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:s=>s.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(Aa,{})}),e.jsx("div",{}),e.jsx("div",{})]})}function Ze({children:s,summary:a,open:n,className:r}){return e.jsxs("details",{open:n,className:t.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(t.Label,{children:a}),e.jsx(t.ChevronUp,{className:"h-4 w-4"})]}),e.jsx("div",{className:"transition-all ease-in-out",children:s})]})}const Oa=[{label:"Mercator",value:"mercator"},{label:"Azimuthal Equidistant",value:"azimuthalEquidistant"},{label:"Gnomonic",value:"gnomonic"},{label:"Orthographic",value:"orthographic"},{label:"Stereographic",value:"stereographic"},{label:"Equal Earth",value:"equalEarth"},{label:"Albers",value:"albers"},{label:"Albers USA",value:"albersUsa"},{label:"Conic Conformal",value:"conicConformal"},{label:"Conic Equal Area",value:"conicEqualArea"},{label:"Conic Equidistant",value:"conicEquidistant"},{label:"Equirectangular",value:"equirectangular"},{label:"Transverse Mercator",value:"transverseMercator"},{label:"Natural Earth 1",value:"naturalEarth1"}],Fa=["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"],Ba=Fa.map(s=>({label:s,value:s}));function za(){var c,h,d,m,N,f,g,x,v,p,k,T,E,j,b,y,S,I;const s=t.useEditorStore(D=>D.card),a=(h=(c=s==null?void 0:s.preferences)==null?void 0:c.mapVisualOptions)==null?void 0:h.topoJsonUrl,[n,r]=L.useState(((m=(d=s==null?void 0:s.preferences)==null?void 0:d.mapVisualOptions)==null?void 0:m.customTopoJsonUrl)||""),{setCardPreferences:i}=t.useEditorActions(),{data:o}=t.useTopoJson(s),l=Object.keys((o==null?void 0:o.objects)||{}).map(D=>({label:D,value:D}))||[],u=[{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(Ze,{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(t.Separator,{className:"my-4"}),e.jsx(Ze,{open:!0,summary:"Settings",children:e.jsxs("div",{className:"space-y-3 px-2",children:[e.jsx(le,{className:"h-9",options:u,onValueChange:D=>{console.log("value",D),i({...s.preferences,mapVisualOptions:{topoJsonUrl:D}})},value:a||"",label:"Select Map"}),a==="custom"&&e.jsx(t.Input,{onChange:D=>{r(D.target.value)},onBlur:()=>{var D;console.log("onBlur",n),i({...s.preferences,mapVisualOptions:{...(D=s.preferences)==null?void 0:D.mapVisualOptions,customTopoJsonUrl:n}})},value:n,className:`h-9 w-full ${t.removeRing}`,placeholder:"Custom URL"}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Map Object"}),e.jsx(le,{className:"h-9",options:l,value:((f=(N=s.preferences)==null?void 0:N.mapVisualOptions)==null?void 0:f.objectKey)||"",label:"Map Object",onValueChange:D=>{var C;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,objectKey:D}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Projection"}),e.jsx(le,{className:"h-9",options:Oa,value:((x=(g=s.preferences)==null?void 0:g.mapVisualOptions)==null?void 0:x.projection)||"",label:"Projection",onValueChange:D=>{var C;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,projection:D}})}})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{children:"Colors"}),e.jsx(le,{className:"h-9",options:Ba,value:((p=(v=s.preferences)==null?void 0:v.mapVisualOptions)==null?void 0:p.colorScale)||"",label:"Select Color Scale",onValueChange:D=>{var C;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,colorScale:D}})}})]})]})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(Ze,{className:"",summary:"Scale Options",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:.1,value:((T=(k=s.preferences)==null?void 0:k.mapVisualOptions)==null?void 0:T.projectionScale)||1,onChange:D=>{var C;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,projectionScale:Number(D.target.value)}})}}),e.jsx(t.Label,{children:"X"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((b=(j=(E=s.preferences)==null?void 0:E.mapVisualOptions)==null?void 0:j.projectionOffset)==null?void 0:b[0])||0,onChange:D=>{var C,F,O,A;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[Number(D.target.value),((A=(O=(F=s.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:A[1])||0]}})}}),e.jsx(t.Label,{children:"Y"}),e.jsx(t.Input,{className:`h-9 w-full ${t.removeRing}`,type:"number",step:10,value:((I=(S=(y=s.preferences)==null?void 0:y.mapVisualOptions)==null?void 0:S.projectionOffset)==null?void 0:I[1])||0,onChange:D=>{var C,F,O,A;i({...s.preferences,mapVisualOptions:{...(C=s.preferences)==null?void 0:C.mapVisualOptions,projectionOffset:[((A=(O=(F=s.preferences)==null?void 0:F.mapVisualOptions)==null?void 0:O.projectionOffset)==null?void 0:A[0])||0,Number(D.target.value)]}})}})]})}),e.jsx(t.Separator,{className:"my-4"}),e.jsx(be,{})]})}function Ra(){var r;const s=t.useEditorStore(i=>i.card.preferences),{setCardPreferences:a}=t.useEditorStore(i=>i.actions);function n(i){a({...s,textVisualOptions:{...s==null?void 0:s.textVisualOptions,isDynamicText:i==="dynamic"}})}return e.jsxs(t.RadioGroup,{value:(r=s==null?void 0:s.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(t.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(t.RadioGroupItem,{value:"dynamic",id:"r2"}),e.jsx("label",{className:"text-sm",htmlFor:"r2",children:"Dynamic"})]})]})}function Oe({cardType:s,docContent:a,suffix:n="Chart"}){let r="pie-donut-polar";return s==="funnel"&&(r="funnel"),e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:`${t.titleCase(s)} ${n}`}),e.jsx(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[s!=="text"&&e.jsx(Mt,{}),s==="text"&&e.jsx(Ra,{})]})]}),!["range","text"].includes(s)&&e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(be,{}),e.jsx(we,{})]})]})]})})}function Pa(){const s=t.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}=t.useEditorActions();function n(){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Sort"}),e.jsx(le,{className:"h-8",label:"Sort Chart",options:[{label:"None",value:"none"},{label:"ASC",value:"asc"},{label:"DESC",value:"desc"}],value:s||"none",onValueChange:r=>{a(r)}})]})}return e.jsx("div",{className:"space-y-6 px-6 py-2",children:e.jsxs(t.Accordion,{defaultValue:["item-2"],type:"multiple",children:[e.jsxs(t.AccordionItem,{value:"item-1",children:[e.jsx(t.AccordionTrigger,{children:"Stacked Chart"}),e.jsxs(t.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(t.AccordionItem,{value:"item-2",children:[e.jsx(t.AccordionTrigger,{children:"Settings"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[n(),e.jsx(bs,{})]})]}),e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(be,{}),e.jsx(we,{})]})]})]})})}function Va({cardType:s="table"}){console.log("cardType",s);const a=t.useEditorStore(i=>{var o;return(o=i.card)==null?void 0:o.preferences}),n=t.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(t.Accordion,{defaultValue:["item-3"],type:"multiple",children:e.jsxs(t.AccordionItem,{value:"item-3",children:[e.jsx(t.AccordionTrigger,{children:"Filters"}),e.jsxs(t.AccordionContent,{className:"space-y-4 px-2",children:[e.jsx(be,{}),e.jsx(we,{})]})]})}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.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 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 dimension, cohort, metric FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/tornado",children:"example"})," in the docs."]})]}),_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 y-axis, label, range-from, range-to, range-value FROM table"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/range",children:"example"})," in the docs."]})]}),$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 text FROM table limit 1"}),e.jsxs("div",{children:["See ",e.jsx("a",{target:"_blank",onClick:s=>s.stopPropagation(),className:"text-blue-700",href:"https://docs.semaphor.cloud/docs/charts/text",children:"example"})," in the docs."]})]});function Ga(){const s=t.useEditorStore(n=>n.card.type);function a(n){switch(n){case"stackedBar":case"stackedLine":return e.jsx(Pa,{});case"tornado":case"pyramid":return e.jsx(Oe,{docContent:qa,cardType:n});case"kpi":return e.jsx(La,{});case"line":case"bar":return e.jsx(ka,{cardType:n});case"range":return e.jsx(Oe,{docContent:_a,cardType:n});case"pie":case"doughnut":case"polarArea":case"radar":case"funnel":return e.jsx(Oe,{cardType:n});case"bubble":case"scatter":return e.jsx(Ea,{cardType:n});case"table":return e.jsx(Va,{cardType:n});case"text":return e.jsx(Oe,{docContent:$a,cardType:n,suffix:"Visual"});case"map":return e.jsx(za,{});case"custom":return e.jsx(Ca,{});default:return e.jsx(Ta,{})}}return e.jsxs(t.ScrollArea,{className:"h-full w-full text-sm",children:[a(s),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})}function Ss({label:s,column:a,functions:n,onFunctionChange:r}){let i=n[0];"aggregate"in a?i=n.find(l=>l.value===a.aggregate)||n[0]:"granularity"in a&&(i=n.find(l=>l.value===a.granularity)||n[0]);function o(l){r(l)}return e.jsx(le,{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:l=>o(l),label:s,showPlaceholderLabel:!1})}const Ha=[{label:"Sum",value:"SUM",logo:e.jsx(Wt,{className:"size-3.5"})},{label:"Count",value:"COUNT",logo:e.jsx(jt,{className:"size-3.5"})},{label:"Unique",value:"DISTINCT",logo:e.jsx(xn,{className:"size-3.5"})},{label:"Average",value:"AVG",logo:e.jsx(Gs,{className:"size-3.5"})},{label:"Min",value:"MIN",logo:e.jsx(qe,{className:"size-3.5"})},{label:"Max",value:"MAX",logo:e.jsx(_e,{className:"size-3.5"})}];function Ja({column:s}){const{updateMetricColumnOld:a}=t.useEditorActions();let n=Ha;t.isTextDataType(s.type)&&(n=n.filter(i=>["COUNT","DISTINCT"].includes(i.value))),t.isNumberDataType(s.type)&&(n=n.filter(i=>!["DISTINCT"].includes(i.value)));function r(i){const o={...s,aggregate:i,label:Ee(s.name,i)};a(s.id,o)}return e.jsx(Ss,{column:s,functions:n,onFunctionChange:i=>r(i),label:"Aggregation"})}const Ua=[{label:"Day (D)",value:"day",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"D"})},{label:"Week (W)",value:"week",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"W"})},{label:"Month (M)",value:"month",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"M"})},{label:"Year (Y)",value:"year",logo:e.jsx(t.Label,{className:"cursor-pointer text-xs",children:"Y"})}];function Ya({column:s}){const{updateGroupByColumnOld:a}=t.useEditorActions();function n(r){const i={...s,granularity:r,label:Se(s.name,r)};a(s.id,i)}return e.jsx(Ss,{column:s,functions:Ua,onFunctionChange:r=>n(r),label:"Granularity"})}function Ka({col:s,onChange:a,droppableId:n}){const{columns:r}=t.useDataColumns(),i=L.useMemo(()=>{let u=[];(n===fe||n===ge||n===je)&&(u=r);const c=u==null?void 0:u.filter(h=>h.column_name!==s.name);return c==null?void 0:c.map(h=>({id:h.column_name,value:h.column_name}))},[r,n,s.name]),o=[{id:s.name,value:s.name}];function l(u){const c=r==null?void 0:r.find(h=>{var d;return h.column_name===((d=u[0])==null?void 0:d.id)});c&&a(c)}return i!=null&&i.length?e.jsx(t.ComboBox2,{multiple:!1,options:i,selectedOptions:o,onChange:l,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:s.name})}function Qa({column:s}){const{updateMetricColumnOld:a}=t.useEditorActions(),{transformedMetricKeys:n,dimensionKeys:r}=ys();console.log(n,r);const i=t.useEditorStore(c=>{var h;return(h=c.card.queryConfig)==null?void 0:h.pivotColumns}),o=!!(i&&i.length>0),l=n.find(c=>c===s.label||c===s.name),u=l?n.indexOf(l):-1;return e.jsxs("div",{className:"space-y-3",children:[l&&e.jsx(Ns,{idx:u,col:l,children:e.jsx(t.Editable,{enabled:!0,className:"w-[130px]",text:s.label||"",placeholder:"Enter label",onSave:c=>{a(s.id,{...s,label:c||s.name})},children:e.jsx(Ve,{className:"w-[130px]",children:s.label||s.name})})}),o&&e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(t.Label,{children:"Pivot Header"}),e.jsx(t.Editable,{enabled:!0,text:s.aliasTemplate||"",placeholder:"{label} ({pivot})",onSave:c=>{a(s.id,{...s,aliasTemplate:c||""})},children:e.jsx(Ve,{className:"font-mono text-xs text-muted-foreground",children:s.aliasTemplate||"{label} ({pivot})"})})]})]})}function Wa({column:s,type:a,onRemoveColumn:n,droppableId:r}){const[i,o]=L.useState(!1),{updateGroupByColumnOld:l,updateMetricColumnOld:u,updatePivotByColumnOld:c}=t.useEditorActions(),{attributes:h,listeners:d,setNodeRef:m,transform:N,transition:f,isDragging:g}=t.useSortable({id:s.id,data:{type:a}}),x=N?{opacity:g?.5:void 0,transform:t.CSS.Translate.toString(N),transition:f}:void 0,v=t.isTextDataType(s.type);function p(b){const y=t.isNumberDataType(b.data_type),S=t.isTextDataType(b.data_type),I=t.isDateDataType(b.data_type),D=y?"number":S?"string":I?"date":"string";if(r===fe){if(S){const C={id:s.id,name:b.column_name,type:D,role:"groupby"};l(s.id,C)}if(I){const C={id:s.id,name:b.column_name,type:D,role:"groupby",label:Se(b.column_name,"month"),granularity:"month"};l(s.id,C)}}if(r===je){if(S){const C={id:s.id,name:b.column_name,type:D,role:"groupby"};c(s.id,C)}if(I){const C={id:s.id,name:b.column_name,type:D,label:Se(b.column_name,"month"),granularity:"month",role:"groupby"};c(s.id,C)}}if(r===ge){const C={id:s.id,name:b.column_name,type:D,role:"metric",label:Ee(b.column_name,"SUM"),aggregate:y?"SUM":"COUNT"};u(s.id,C)}}function k(){if(r===ge)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(Qa,{column:s})})}function T(){const b=t.isDateDataType(s.type);if(r===ge)return e.jsx(Ja,{column:s});if((r===fe||r===je)&&b)return e.jsx(Ya,{column:s})}function E(){return e.jsx("div",{className:t.cn("grow",{"pl-3":(r===fe||r===je)&&v}),children:e.jsx(Ka,{col:s,onChange:p,droppableId:r})})}function j(){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(An,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")}):e.jsx(Kt,{className:t.cn("size-3 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground")})})})}return e.jsx("div",{...d,...h,ref:m,style:x,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:[j(),T(),E()]}),i&&k()]}),e.jsx("div",{className:t.cn("opacity-0 transition-opacity duration-200 group-hover:opacity-100",{hidden:i}),children:e.jsx("button",{onClick:()=>n(s.id),children:e.jsx(t.X,{className:"size-3 cursor-pointer text-muted-foreground"})})})]})})}function et({id:s,label:a,columns:n,previewColumns:r,sortableType:i,onRemoveColumn:o}){var x,v;const{setNodeRef:l,isOver:u,over:c}=t.useDroppable({id:s}),h=t.useDndStore(p=>p.activeId),d=t.useEditorStore(p=>{var k;return(k=p.card)==null?void 0:k.type}),m=u||((v=(x=c==null?void 0:c.data)==null?void 0:x.current)==null?void 0:v.type)===i,N=h?r:n,f=i===Be?"Rows":i===ze?"Pivot Columns":"Columns";function g(){if(!N||N.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(t.SortableContext,{items:n==null?void 0:n.map(p=>p.id),children:e.jsxs("div",{className:t.cn("group space-y-2 rounded-md p-4",m&&"border border-muted-foreground/20"),ref:l,children:[e.jsxs("div",{className:"flex items-center justify-between pr-5",children:[e.jsx(t.Label,{className:"text-sm",children:a}),d!=="table"&&e.jsx("span",{className:"text-xs text-muted-foreground/50",children:f})]}),g(),e.jsx("div",{className:"space-y-2",children:N==null?void 0:N.map(p=>p.id===rs.id?e.jsx(Xa,{},p.id):e.jsx(Wa,{droppableId:s,type:i,column:p,onRemoveColumn:o},p.id))})]})})}function Xa(){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 ws({children:s,id:a,type:n}){const{attributes:r,listeners:i,setNodeRef:o,transform:l,transition:u,isDragging:c}=t.useSortable({id:a,data:{type:n}}),h=l?{opacity:c?.5:void 0,transform:t.CSS.Translate.toString(l),transition:u}:void 0;return e.jsx("div",{...i,...r,ref:o,style:h,children:s})}function Za(){const s=t.useEditorStore(p=>{var k;return(k=p.card.queryConfig)==null?void 0:k.orderBy})||[],a=t.useEditorStore(p=>{var k;return(k=p.card.queryConfig)==null?void 0:k.groupByColumns})||[],n=t.useEditorStore(p=>{var k;return(k=p.card.queryConfig)==null?void 0:k.metricColumns})||[],{addOrderByColumn:r,removeOrderByColumn:i,updateOrderByColumn:o}=t.useEditorActions(),l=[...a,...n];if(l.length===0)return e.jsx(e.Fragment,{});const u=e.jsx(Ys,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),c=e.jsx($s,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),h=e.jsx(Us,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),d=e.jsx(_s,{className:"size-3.5 text-muted-foreground hover:text-foreground"}),m=l==null?void 0:l.filter(p=>!s.some(k=>k.columnId===p.id)).map(p=>({id:p.id,value:p.label||p.name}));function N(p,k){const T=f(p);return T?T.role==="metric"?k==="asc"?h:d:k==="asc"?u:c:null}function f(p){return l.find(k=>k.id===p)}function g(p){const k=s.find(T=>T.columnId===p);if(k){const T={...k,direction:k.direction==="asc"?"desc":"asc"};o(T)}}const x=p=>{r({columnId:p.id,direction:"asc"})};function v(p){const k=s.find(T=>T.columnId===p);k&&i(k)}return e.jsx(t.SortableContext,{items:s.map(p=>ke(p.columnId)),children:e.jsxs("div",{className:"space-y-2 rounded-md p-4 text-sm",children:[e.jsx(t.Label,{className:"text-sm",children:"Sort By"}),m.length>0&&e.jsx("div",{className:"mr-5",children:e.jsx(t.ComboBox2,{multiple:!1,options:m,selectedOptions:[],onChange:p=>x(p[0]),selectAllChecked:!1,onSelectAllCheckedChange:()=>{},inputClassName:"h-8 bg-muted border-none"})}),s.map(p=>{var k,T;return e.jsx(ws,{id:ke(p.columnId),type:wt,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(Kt,{className:"size-3 cursor-move text-muted-foreground hover:text-foreground"}),e.jsx(Ve,{className:"w-[175px] text-sm",children:((k=f(p.columnId))==null?void 0:k.label)||((T=f(p.columnId))==null?void 0:T.name)})]}),e.jsx("button",{title:p.direction==="asc"?"Ascending":"Descending",onClick:()=>g(p.columnId),className:"rounded-sm p-0",children:N(p.columnId,p.direction)})]}),e.jsx("div",{children:e.jsx("button",{onClick:()=>v(p.columnId),className:"rounded-sm p-0",children:e.jsx(t.X,{className:"size-3 text-muted-foreground opacity-0 transition-opacity duration-200 hover:text-foreground group-hover:opacity-100"})})})]})},p.columnId)},ke(p.columnId))})]})})}function er(){const s=t.useEditorStore(v=>{var p;return((p=v.card.queryConfig)==null?void 0:p.groupByColumns)||[]}),a=t.useEditorStore(v=>v.card.type),n=t.useDndStore(v=>v.previewGroupByColumns),r=t.useEditorStore(v=>{var p;return((p=v.card.queryConfig)==null?void 0:p.metricColumns)||[]}),i=t.useDndStore(v=>v.previewMetricColumns),o=t.useEditorStore(v=>{var p;return((p=v.card.queryConfig)==null?void 0:p.pivotColumns)||[]}),l=t.useDndStore(v=>v.previewPivotColumns),{removeColumnFromGroupBy:u,removeColumnFromMetricColumns:c,removeColumnFromPivotBy:h}=t.useEditorActions();function d(v){u(v)}function m(v){c(v)}function N(v){h(v)}let f="Group By",g="Metrics",x="Stack By";return a==="table"&&(f="Rows",g="Metrics",x="Columns"),e.jsxs("div",{className:"flex h-full w-full flex-col gap-3 py-4",children:[e.jsx(ps,{iconClassName:"size-[19px]"}),e.jsxs(t.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(et,{onRemoveColumn:d,sortableType:Be,id:fe,label:f,columns:s,previewColumns:n}),e.jsx(et,{onRemoveColumn:N,sortableType:ze,id:je,label:x,columns:o,previewColumns:l}),e.jsx(et,{onRemoveColumn:m,sortableType:ot,id:ge,label:g,columns:r,previewColumns:i}),e.jsx(Za,{})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function At({children:s,column:a,id:n,sortableType:r,className:i}){const[o,l]=L.useState(!1),{removeEditorFilter:u,clearEditorFilter:c}=t.useEditorActions(),h=t.useEditorStore(m=>{var N,f;return(f=(N=m.card.queryConfig)==null?void 0:N.filters)==null?void 0:f.some(g=>g.filterColumnName===a.name)});function d(m){u(m)}return e.jsx(ws,{id:n,type:r,children:e.jsxs("div",{className:t.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(t.Label,{className:"text-sm",children:a.name}),h&&e.jsx("button",{onClick:()=>c(a),children:e.jsx(t.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:()=>d(a),children:e.jsx(t.X,{className:"size-3.5 cursor-pointer items-center justify-center rounded-r-sm text-muted-foreground"})})})]}),e.jsxs("div",{className:t.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(t.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:t.cn("grow cursor-pointer overflow-hidden truncate text-ellipsis whitespace-nowrap",i),children:s})]})]})})}function tr({column:s,sortableType:a}){const n=t.useDashboardStore(T=>T.themeStyle),r=t.useEditorStore(T=>{var E,j;return(j=(E=T.card)==null?void 0:E.queryConfig)==null?void 0:j.filters}),i=t.useEditorStore(T=>{var E,j;return(j=(E=T.card.queryConfig)==null?void 0:E.filterColumns)==null?void 0:j.find(b=>b.name===s.name)}),{selectedConnectionId:o,selectedDatabaseName:l,selectedTableName:u}=t.useEditorAside(),c=L.useMemo(()=>{var T;return(T=r==null?void 0:r.find(E=>E.filterColumnName===s.name))==null?void 0:T.filterValue},[r,s.name]),h=L.useMemo(()=>Array.isArray(c)?c.map(T=>({id:T,value:T})):[],[c]),{updateEditorFilterValue:d}=t.useEditorActions(),m={column:s.name,sql:s.sql,id:s.name,connectionId:o,dataType:s.type},{data:N,isLoading:f,isFetching:g,isError:x}=t.useFilterQuery(m),v=L.useMemo(()=>{var E;return m.column?(E=N==null?void 0:N.records)==null?void 0:E.map(j=>{let b=m.column.split(".").slice(-1)[0].replace(/"/g,"");return j[b]===void 0&&(b=b.toLowerCase()),{id:j[b],value:j[b]}}):[]},[N,m.column]);function p(T){const E=T.map(j=>j.id);d(s.name,E)}function k(){return f||g?e.jsx(t.Skeleton,{style:{borderRadius:n==null?void 0:n.controlInputRadius},className:"h-8 min-w-60 bg-foreground/10"}):x?e.jsx("div",{className:"flex h-8 min-w-60 items-center bg-muted px-2 text-sm",children:"Error"}):e.jsx(t.ComboBox2,{renderFilterModeButton:()=>e.jsx(sr,{columnName:s.name}),showNegativeIndicator:(i==null?void 0:i.mode)==="exclude",options:v,onChange:p,selectedOptions:h,selectAllChecked:!1,onSelectAllCheckedChange:()=>{}})}return e.jsx(At,{className:"w-60",id:s.id,sortableType:a,column:s,children:k()})}function sr({columnName:s}){const{setEditorFilterMode:a}=t.useEditorActions(),n=t.useEditorStore(i=>{var o,l;return(l=(o=i.card.queryConfig)==null?void 0:o.filterColumns)==null?void 0:l.find(u=>u.name===s)});function r(){(n==null?void 0:n.mode)==="exclude"?a(s,"include"):a(s,"exclude")}return e.jsx(t.Button,{onClick:r,variant:"secondary",size:"sm",className:t.cn("h-5 text-xs hover:underline",{}),children:t.titleCase((n==null?void 0:n.mode)==="exclude"?"exclude":"include")})}function nr({column:s,sortableType:a}){const[n,r]=L.useState(!1),{selectedConnectionId:i,selectedDatabaseName:o,selectedTableName:l}=t.useEditorAside(),u={column:s.name,sql:s.sql,id:s.name,connectionId:i,title:"",dataType:s.type},{isLoading:c,isFetching:h,isError:d,data:m}=t.useFilterQuery(u),N=m==null?void 0:m.records,{dateRange:f,setDateRange:g,initialDateRange:x}=t.useDateRangeFromRecords(N),{updateEditorFilterValue:v}=t.useEditorActions();function p(E){var b,y;const j={gte:(b=E==null?void 0:E.from)==null?void 0:b.toISOString(),lte:(y=E==null?void 0:E.to)==null?void 0:y.toISOString()};v(s.name,j)}function k(){v(s.name,null,!0),g(x)}function T(){return c||h?e.jsx("div",{children:e.jsx(t.Skeleton,{className:"h-8 w-72 bg-foreground/10"})}):d?e.jsx("div",{className:"h-8 w-72 bg-muted px-2",children:"Error"}):N?e.jsx(t.DateRangePopover,{title:u.title,open:n,inputClassName:"h-8",setOpen:r,dateRange:f,setDateRange:g,onApply:p,onClear:k}):e.jsx(t.Label,{className:"flex h-8 w-72 items-center bg-muted px-2",children:"No Data"})}return e.jsx(At,{className:"w-72",id:s.id,sortableType:a,column:s,children:T()})}function ar({id:s,label:a,columns:n,previewColumns:r,sortableType:i}){var g,x;const{setNodeRef:o,isOver:l,over:u}=t.useDroppable({id:s}),c=t.useDndStore(v=>v.activeId),h={},d=l||((x=(g=u==null?void 0:u.data)==null?void 0:g.current)==null?void 0:x.type)===i;function m(){if(!f||f.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 N(v){const p=t.isDateDataType(v.type);return v.id===rs.id?e.jsx(At,{id:v.id,sortableType:i,column:v,children:e.jsx(rr,{})},v.id):p?e.jsx(nr,{droppableId:s,sortableType:i,column:v},v.id):e.jsx(tr,{droppableId:s,sortableType:i,column:v},v.id)}const f=c?r:n;return e.jsx(t.SortableContext,{items:n==null?void 0:n.map(v=>v.id),children:e.jsxs("div",{className:t.cn("group space-y-2 rounded-md border-muted-foreground/50 p-4",d&&"border border-muted-foreground/20"),ref:o,style:h,children:[e.jsx(t.Label,{className:"text-sm",children:a}),m(),e.jsx("div",{className:"flex flex-wrap items-center gap-4",children:f==null?void 0:f.map(v=>N(v))})]})})}function rr(){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 ir(){const s=t.useEditorStore(i=>{var o;return((o=i.card.queryConfig)==null?void 0:o.filterColumns)||[]}),a=t.useDndStore(i=>i.previewFilterColumns),{removeColumnFromFilterColumns:n}=t.useEditorActions();function r(i){n(i)}return e.jsx("section",{className:"size-full px-4 pb-4",children:e.jsx(ar,{onRemoveColumn:r,sortableType:ct,id:lt,label:"Filters",columns:s,previewColumns:a})})}function or(){const s=t.useEditorStore(o=>o.card),a=t.useEditorStore(o=>o.showAIDialog),{setShowAIDialog:n}=t.useEditorActions(),{data:r,errorMessage:i}=t.useDashboardCardQuery(s);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(t.EditorClearButton,{}),!a&&e.jsxs(t.Button,{onClick:()=>n(!0),variant:"secondary",size:"sm",children:[e.jsx(En,{className:"mr-2 h-4 w-4"}),"Assistant"]}),e.jsx(ls,{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(t.EditorCancelButton,{}),e.jsx(t.EditorAcceptButton,{variant:"default"})]})]})}function lr(){const s=L.useRef(null),a=L.useRef(null),n=t.useEditorStore(u=>u.isShowingVisual),r=t.useEditorStore(u=>u.showAIDialog),i=t.useEditorStore(u=>u.isDevMode);L.useEffect(()=>{var u,c,h,d;r?((u=s.current)==null||u.resize(0),(c=a.current)==null||c.resize(0)):((h=s.current)==null||h.resize(25),(d=a.current)==null||d.resize(25))},[r]);function o(){return e.jsxs(e.Fragment,{children:[e.jsx(t.ResizablePanel,{role:"query-section",className:"flex",minSize:20,defaultSize:40,children:e.jsx(ia,{})}),e.jsx(t.ResizableHandle,{withHandle:!0}),e.jsx(t.ResizablePanel,{className:"pb-1",role:"visual-section",minSize:0,defaultSize:60,children:n&&!r?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:s,className:"flex",defaultSize:25,maxSize:30,children:e.jsx(Ga,{})})}),!r&&e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{minSize:40,defaultSize:75,maxSize:100,children:e.jsx(Le,{})})]}):e.jsx(Le,{})})]})}function l(){return e.jsx(e.Fragment,{children:e.jsx("div",{className:"grow","data-biz-mode-container":"",children:n?e.jsxs(t.ResizablePanelGroup,{direction:"horizontal",children:[e.jsx(e.Fragment,{children:e.jsx(t.ResizablePanel,{ref:a,defaultSize:25,maxSize:30,children:e.jsx(er,{})})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{defaultSize:75,maxSize:100,children:e.jsxs(t.ResizablePanelGroup,{direction:"vertical",children:[e.jsxs(t.ResizablePanel,{className:"flex min-h-fit flex-col",minSize:10,defaultSize:20,children:[e.jsx(or,{}),e.jsx(ir,{})]}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{minSize:60,defaultSize:80,children:e.jsx(Le,{})})]})})]}):e.jsx(Le,{})})})}return e.jsx(t.ResizablePanelGroup,{direction:"vertical",className:"min-h-[250px] min-w-full max-w-lg",children:i?o():l()})}function cr(s,a){const[n,r]=L.useState(""),[i,o]=L.useState(null),{authToken:l}=t.useSemaphorContext(),u=t.useEditorStore($=>{var Q;return(Q=$==null?void 0:$.card)==null?void 0:Q.sql}),c=t.useEditorStore($=>$.isDevMode),h=t.useEditorStore($=>{var Q;return(Q=$==null?void 0:$.card)==null?void 0:Q.python}),{setCardPython:d,setCardSql:m,setRunSql:N,switchCardType:f,setQueryConfig:g}=t.useEditorActions(),x=t.useEditorStore($=>$.currentAssitantScope)||[],v=t.useEditorStore($=>$.userInputForAI),p=t.useEditorStore($=>$.triggerAIRun),k=t.useEditorStore($=>$.selectedDatabaseName),T=t.useEditorStore($=>$.selectedTableName),E=t.useEditorStore($=>$.selectedConnectionId),j=t.useEditorStore($=>$.selectedSchemaName),b=t.useDashboardStore($=>$.dashboard.aiScopeTables),{setTriggerAIRun:y,setCurrentAssitantScope:S,setCardConfig:I}=t.useEditorActions(),{selectedDatamodelName:D,connectionType:C,selectedDatamodelId:F}=t.useEditorAside(),{messages:O,setMessages:A,reload:w,error:M,append:B,input:R,setInput:P,status:z,handleInputChange:K,handleSubmit:J,stop:G}=t.useChat({api:"https://semaphor.cloud/api/v1/assistant",headers:{Authorization:`Bearer ${l==null?void 0:l.accessToken}`},body:{random:Math.random(),assistantId:"editor-assistant",isDevMode:c,aiContext:s},maxSteps:10,onError:$=>{console.log("on error",$)},onToolCall:U,onFinish($,Q){q(Q.usage),r(""),Q.finishReason==="stop"&&r("")}});L.useEffect(()=>{p&&v&&(K({target:{value:v}}),setTimeout(()=>{J(),y(!1)},100))},[p,J,v,y,K]);async function U({toolCall:$}){if(["createChartFromSql","createForecast"].includes($.toolName)){const Q=$.args.sql,se=$.args.python,me=$.args.chartType;return f(me),m(Q),d(se),N(!0),{status:"success",message:"Let the user know that chart is created"}}else if($.toolName==="getTableColumns")r("Getting table columns...");else{if($.toolName==="getUserSql")return u?{status:"success",sql:u,python:h||""}:{status:"error",message:"No SQL found"};if($.toolName==="getCurrentTableScope")return r("Getting table scope..."),Y(),{status:"success",tables:x};if($.toolName==="generateQueryConfig"){r("Generating query config...");const Q=$.args.chartType,se=$.args.queryConfig;return $.args.cardConfig,f(Q),I(se),m(void 0),d(void 0),N(!0),{status:"success",queryConfig:se}}else r("Analyzing...")}}function q($){o(Q=>Q?{promptTokens:Q.promptTokens+$.promptTokens,completionTokens:Q.completionTokens+$.completionTokens,totalTokens:Q.totalTokens+$.totalTokens}:$)}function V($){const Q=t.removeFromScopeArray(x,$);_(Q)}function _($){const Q=t.sanitizeAIScope($);S(Q),A(se=>[...se,{id:crypto.randomUUID(),role:"system",content:`Current scope of tables. Always use the table reference format when generating SQL | ${JSON.stringify(Q)}`}])}function H(){const $={databaseName:k||"",schemaName:j||"",tableName:T||"",datamodelId:F||"",datamodelName:t.resolveDatamodelName(D),connectionId:E||"",connectionType:C||""},Q=t.dedup([...x,$]);_(Q)}function Y(){const $={databaseName:k||"",schemaName:j||"",tableName:T||"",datamodelName:t.resolveDatamodelName(D),connectionId:E||"",connectionType:C||"",datamodelId:F||""};if(!t.isInAiScopeArray([...b||[],...x],$)||x.length===0){const se=t.dedup([...b||[],...x,$]).filter(me=>me.connectionId===$.connectionId);_(se)}}const Z=!["ready","error"].includes(z),de=t.getErrorMessage(M);return{messages:O,setMessages:A,reload:w,append:B,input:R,setInput:P,isLoading:Z,handleSetAIScope:Y,handleAddCurrentTableToScope:H,removeFromCurrentSelections:V,currentAssitantScope:x,setCurrentAssitantScope:S,handleInputChange:K,handleSubmit:J,stop:G,chatStatus:z,toolStatus:n,llmUsage:i,onFinish:a,errorMessage:de}}const dr=[{title:"Help me write a query for",subtitle:"orders by month"},{title:"Create a bar chart for",subtitle:"sales by category"}];function Gt(){const s=L.useRef(null),a=L.useRef(null),[n,r]=L.useState(!1),[i,o]=L.useState(t.isDevEnv),[l,u]=L.useState(!1),[c,h]=L.useState(!1),[d,m]=L.useState({selectedEntities:[]}),N=t.useDashboardStore(_=>_.dashboard.aiContext),f=t.useEditorStore(_=>_.card.dataSource),g=t.useEditorStore(_=>_.actions.setCardSql),x=t.useEditorStore(_=>_.actions.setRunSql),v=t.useEditorStore(_=>_.showAIDialog),p=t.useDashboardStore(_=>_.handleOpenAssistantProfile),{setShowAIDialog:k,setCardPython:T}=t.useEditorActions(),{setDataSource:E}=t.useEditorActions(),{assistantProfile:j}=t.useAssistantProfile(),{messages:b,setMessages:y,reload:S,append:I,input:D,setInput:C,isLoading:F,handleInputChange:O,handleSubmit:A,stop:w,chatStatus:M,llmUsage:B,errorMessage:R}=cr(d);t.useAssistantScroll({scrollContainerRef:s,inputRef:a,messages:b}),L.useEffect(()=>{var _;v&&((_=a.current)==null||_.focus())},[v]);function P(_,H){H==="sql"?(g(_),x(!0)):H==="python"&&(T(_),x(!0))}function z(){var _;(_=N==null?void 0:N.selectedEntities)==null||_[0],h(!0)}function K(){d.selectedEntities.length===0&&m({selectedEntities:(N==null?void 0:N.selectedEntities)||[]})}function J(_){K();const H={role:"user",content:_.title+" "+_.subtitle};I(H)}function G(_){K(),I({role:"user",content:_})}function U(){return e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",children:e.jsx(t.EllipsisVertical,{className:"size-3.5"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[e.jsx(t.DropdownMenuLabel,{children:"Options"}),e.jsx(t.DropdownMenuSeparator,{}),e.jsx(t.DropdownMenuCheckboxItem,{checked:n,onCheckedChange:r,children:"Token Usage"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:i,onCheckedChange:o,children:"Tool Invocations"}),e.jsx(t.DropdownMenuCheckboxItem,{checked:l,onCheckedChange:u,children:"System Message"})]})]})}function q(){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&&(b==null?void 0:b.filter(_=>_.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:[q(),p&&e.jsx(t.Button,{variant:"outline",size:"sm",className:"h-7 p-2",onClick:p,children:(j==null?void 0:j.name)||"Default Profile"}),e.jsxs("div",{"data-role":"header-actions",className:"flex items-center gap-2",children:[U(),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 p-2",onClick:z,children:e.jsx(t.Settings,{className:"size-4"})}),e.jsx(t.Button,{className:"h-7 p-2",size:"sm",variant:"ghost",onClick:()=>{y([]),S()},children:e.jsx(t.SquarePen,{className:"size-4"})}),e.jsx(t.Button,{variant:"ghost",className:"h-8",size:"sm",onClick:()=>{k(!1)},children:e.jsx(t.ChevronRight,{className:"size-4"})})]})]}),e.jsx(t.CustomScrollArea,{ref:s,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(t.PrintMessages,{messages:b,showTools:i,handleRun:P,showSystemMessage:l}),e.jsx(t.ChatStatus,{messages:b,chatStatus:M,errorMessage:R})]})}),e.jsxs("div",{className:"mb-3",children:[V&&!j&&e.jsx(t.Placeholders,{onClick:J,placeholders:dr}),e.jsx("div",{children:V&&j&&e.jsx(t.SeedQuestions,{seedQuestions:j.seedQuestions||[],handleSeedQuestionClick:G})})]}),e.jsx(t.ChatInputWithContext,{ref:a,setInput:C,stop:w,input:D,localAiContext:d,setLocalAiContext:m,handleInputChange:O,handleSubmit:_=>{K(),A(_)},isLoading:F,onFocus:()=>{}}),B&&n&&e.jsx("div",{className:"flex h-8 items-center justify-between",children:e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Usage: ",B.promptTokens," prompt tokens,"," ",B.completionTokens," completion tokens,"," ",B.totalTokens," total tokens"]})}),e.jsx(t.DataSourceDialog,{incomingSelectedEntities:(N==null?void 0:N.selectedEntities)||[],open:c,onOpenChange:h,dataSource:f||t.EMPTY_DATA_SOURCE,fallbackDataSource:t.EMPTY_DATA_SOURCE,dialogMode:"aiContext"})]})}function ur(s){return s.flatMap(a=>a.columns.map(n=>({id:`${a.entityId}-${n.name}`,name:n.name,dataType:n.dataType,qualifiedEntityName:a.qualifiedEntityName,label:n.label||t.toTitleCase(n.name),description:n.description,entityId:a.entityId,entityName:a.entityName,entityType:a.entityType})))}function dt(s){if(s.type==="table"||s.type==="view"){if(s.database&&s.schema)return`${s.database}.${s.schema}.${s.name}`;if(s.database)return`${s.database}.${s.name}`}return s.name}function Me(s){var g;const a=t.useDashboardStore(x=>x.authToken)||s,{hasSchemaSupport:n}=t.useSelectedConnection(s),r=t.useEditorStore(x=>{var v;return(v=x.card.dataSource)==null?void 0:v.connectionId}),i=t.useEditorStore(x=>{var v,p;return(p=(v=x.card.dataSource)==null?void 0:v.selectedEntities)==null?void 0:p.filter(k=>k.type==="model")})||[],o=t.useEditorStore(x=>{var v,p;return(p=(v=x.card.dataSource)==null?void 0:v.selectedEntities)==null?void 0:p.filter(k=>k.type==="table"||k.type==="view")})||[];function l(x){return x.type==="model"?!!r&&!!x.id:x.type==="table"||x.type==="view"?n?!!r&&!!x.name&&!!x.database&&!!x.schema:!!r&&!!x.name&&!!x.database:!1}const u=[...i,...o],c=Rs({queries:u.map(x=>({queryKey:["columns",r,x],queryFn:()=>t.getRequest("https://semaphor.cloud/api/v1/columns",(a==null?void 0:a.accessToken)||"",x.type==="model"?{connection_id:r,datamodel_id:x.id,database_name:"",schema_name:"",table_name:""}:{connection_id:r,datamodel_id:"",database_name:x.database,schema_name:x.schema,table_name:x.name}),enabled:!!r&&l(x)}))}),h=c.some(x=>x.isPending),d=c.some(x=>x.isError),m=(g=c.find(x=>x.isError))==null?void 0:g.error,N=c.map((x,v)=>{var T;const p=u[v],k=dt(p);return{entityId:p.id||p.name,entityType:p.type,entityName:p.name,label:p.label,description:p.description,qualifiedEntityName:k,columns:(T=x.data)==null?void 0:T.columns.map(E=>({id:`${p.name}-${E.column_name}`,name:E.column_name,dataType:E.data_type,label:E.label||t.toLabel(E.column_name),description:E.description||"",qualifiedEntityName:k,entityId:p.id||p.name,entityName:p.name,entityType:p.type}))}}).filter(x=>{var v;return((v=x==null?void 0:x.columns)==null?void 0:v.length)>0})||[],f=ur(N);return{columnGroups:N,columns:f,isLoading:h,hasError:d,error:m,refetch:()=>{c.forEach(x=>x.refetch())}}}function mr({field:s}){const{attributes:a,listeners:n,setNodeRef:r,transform:i,transition:o,isDragging:l}=t.useSortable({id:s.id}),[u,c]=L.useState(!1),h={transform:t.CSS.Transform.toString(i),transition:o},d=t.getDataType(s.dataType),N=(f=>{const g=(f||"").toLowerCase();switch(t.getDataType(g)){case"number":return jt;case"date":return t.Calendar;case"boolean":return Zt;case"json":return an;case"geo":return wn;default:return es}})(s.dataType);return e.jsxs("div",{ref:r,style:h,...a,...n,className:`group/container overflow-hidden rounded-lg transition-all ${l?"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:()=>c(!u),children:[e.jsx("div",{className:"flex-shrink-0 hover:cursor-grab active:cursor-grabbing",children:e.jsx(t.GripVertical,{className:"invisible size-3.5 text-gray-400 group-hover/container:visible"})}),e.jsx(N,{className:t.cn("size-3.5 flex-shrink-0 text-gray-500",d==="string"?"text-blue-500":"",d==="number"?"text-green-500":"",d==="date"?"text-purple-500":"",d==="boolean"?"text-orange-500":"")}),e.jsx(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.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 ${u?"whitespace-normal break-words":"truncate"}`,children:s.name})})}),e.jsx(t.TooltipContent,{side:"right",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1 overflow-x-auto",children:[e.jsx("p",{className:"font-medium",children:s.label||s.name}),s.label&&s.label!==s.name&&e.jsxs("p",{className:"text-xs text-gray-500",children:["Name: ",s.name]}),e.jsx("p",{className:"text-xs text-gray-500",children:s.qualifiedEntityName?`${s.qualifiedEntityName}.${s.name}`:s.name}),e.jsxs("p",{className:"text-xs text-gray-500",children:["Type: ",s.dataType]})]})})]})}),e.jsx("button",{onClick:f=>{f.stopPropagation(),c(!u)},className:"invisible flex-shrink-0 text-gray-400 hover:text-gray-600 group-hover/container:visible",children:u?e.jsx(t.ChevronDown,{className:"h-4 w-4"}):e.jsx(t.ChevronRight,{className:"h-4 w-4"})})]}),u&&e.jsx("div",{className:"text-muted-foreground-700 px-2 pb-3 text-sm",children:e.jsx(t.Card,{className:"",children:e.jsxs(t.CardContent,{className:"space-y-2 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xt,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:s.label||s.name})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(On,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:s.name})]}),e.jsx(t.Badge,{variant:"outline",className:"mt-2 text-xs",children:s.dataType})]})})})]})}function hr({entityGroup:s,fields:a,isOpen:n,onToggle:r}){return e.jsxs(t.Collapsible,{open:n,onOpenChange:r,children:[e.jsxs(t.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:s.label||s.entityName}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",a.length,")"]}),n?e.jsx(t.ChevronDown,{className:"h-4 w-4"}):e.jsx(t.ChevronRight,{className:"h-4 w-4"})]}),e.jsx(t.CollapsibleContent,{className:"mt-1 space-y-1",children:e.jsx(t.SortableContext,{items:a.map(i=>i.id),strategy:t.verticalListSortingStrategy,children:a.map(i=>e.jsx(mr,{field:i},i.id))})})]})}function xr(){const[s,a]=L.useState(""),[n,r]=L.useState(new Set),[i,o]=L.useState("all"),l=t.useEditorStore(E=>E.card.dataSource),{columns:u=[],columnGroups:c=[],isLoading:h,error:d}=Me(),m=u.filter(E=>E.name.toLowerCase().includes(s.toLowerCase())||E.dataType.toLowerCase().includes(s.toLowerCase())||E.qualifiedEntityName&&E.qualifiedEntityName.toLowerCase().includes(s.toLowerCase())),N=E=>E.dataType==="number"||E.dataType==="integer"||E.dataType==="float"||E.dataType==="decimal"||E.dataType==="currency"?"metrics":"dimensions",g=(i==="all"?m:m.filter(E=>N(E)===i)).reduce((E,j)=>{const b=j.qualifiedEntityName||"Other Fields";return E[b]||(E[b]={label:t.toLabel(j.entityName),fields:[]}),E[b].fields.push(j),E},{});L.useEffect(()=>{const E=Object.keys(g);r(new Set(E))},[Object.keys(g).join(",")]);const x=E=>{const j=new Set(n);j.has(E)?j.delete(E):j.add(E),r(j)},v=m.filter(E=>N(E)==="dimensions").length,p=m.filter(E=>N(E)==="metrics").length,k=m.filter(E=>N(E)==="calculated").length,T=m.length>0;return h?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..."})]}):d?e.jsxs("div",{className:"flex h-[calc(100vh-200px)] w-[290px] flex-col items-center justify-center",children:[e.jsx(t.Database,{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:d.message||"Failed to load column data"})]}):!l||!l.selectedEntities||l.selectedEntities.length===0?e.jsx(t.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(t.Database,{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-full grow flex-col gap-2 px-6 pb-6",children:[e.jsxs("div",{className:"mt-1 flex-shrink-0 space-y-2",children:[u.length>0&&e.jsx("div",{className:"mb-4",children:e.jsx(t.Input$1,{type:"text",placeholder:"Search fields...",value:s,onChange:E=>a(E.target.value)})}),T&&e.jsx(t.Tabs,{defaultValue:"all",value:i,onValueChange:E=>o(E),className:"mb-4",children:e.jsxs(t.TabsList,{className:"grid h-9 w-full grid-cols-4",children:[e.jsxs(t.TabsTrigger,{value:"all",className:"text-xs",children:["All",e.jsx("span",{className:"ml-2 text-xs font-semibold",children:m.length})]}),e.jsxs(t.TabsTrigger,{value:"dimensions",className:"text-xs",children:[e.jsx(t.Layers,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:v})]}),e.jsxs(t.TabsTrigger,{value:"metrics",className:"text-xs",children:[e.jsx(mt,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:p})]}),e.jsxs(t.TabsTrigger,{value:"calculated",className:"text-xs",children:[e.jsx(Zs,{className:"size-4 shrink-0"}),e.jsx("span",{className:"ml-2 text-xs font-semibold",children:k})]})]})})]}),e.jsxs(t.CustomScrollArea,{className:"py-2",children:[e.jsxs("div",{className:"space-y-2",children:[Object.entries(g).map(([E,j])=>{const b=c.find(y=>y.entityName===E)||{entityName:E,label:j.label};return e.jsx(hr,{entityGroup:b,fields:j.fields,isOpen:n.has(E),onToggle:()=>x(E)},E)}),Object.keys(g).length===0&&u.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&&u.length>0&&e.jsx("div",{className:"py-4 text-center text-sm text-gray-500",children:"No fields found for this category"})]}),e.jsx(t.ScrollBar,{orientation:"horizontal"}),e.jsx(t.ScrollBar,{orientation:"vertical"})]})]})}function pr(){return e.jsxs("div",{className:" h-full flex flex-col items-center",children:[" ",e.jsx(xr,{})," "]})}function fr({initialJoinPlan:s,availableDataSources:a}){const[n,r]=L.useState(s),[i,o]=L.useState(new Set),l=()=>{const b=n.joins.length>0?Math.max(...n.joins.map(S=>S.sequence))+1:1,y={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,y]}),o(new Set([...i,y.id]))},u=b=>{r({...n,joins:n.joins.filter(y=>y.id!==b)}),o(new Set([...i].filter(y=>y!==b)))},c=(b,y)=>{var C,F;const S=n.joins.find(O=>O.id===b);if(!S)return;const I={...S,...y},D=n.joins.map(O=>O.id===b?I:O);if((C=I.source)!=null&&C.name&&((F=I.target)!=null&&F.name)&&I.joinKeyGroups[0].keys.length===0){const O=a.find(B=>{var R;return B.name===((R=I.source)==null?void 0:R.name)}),A=a.find(B=>{var R;return B.name===((R=I.target)==null?void 0:R.name)}),w={id:`key-${Date.now()}`,source:{id:`source-${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"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",entityId:(A==null?void 0:A.name)||"",entityName:(A==null?void 0:A.name)||"",entityType:(A==null?void 0:A.type)||"table"},operator:"="},M=[...I.joinKeyGroups];M[0]={...M[0],keys:[w]},I.joinKeyGroups=M,D[D.findIndex(B=>B.id===b)]=I}r({...n,joins:D})};return{joinPlan:n,expandedJoins:i,setJoinPlan:r,addJoin:l,removeJoin:u,updateJoin:c,moveJoinUp:b=>{const y=n.joins.findIndex(S=>S.id===b);if(y>0){const S=[...n.joins],I={...S[y]},D={...S[y-1]};S[y]=D,S[y-1]=I,S.forEach((F,O)=>{F.sequence=O+1});const C={...n,joins:S};r(C)}},moveJoinDown:b=>{const y=n.joins.findIndex(S=>S.id===b);if(y<n.joins.length-1){const S=[...n.joins],I={...S[y]},D={...S[y+1]};S[y]=D,S[y+1]=I,S.forEach((F,O)=>{F.sequence=O+1});const C={...n,joins:S};r(C)}},toggleJoinExpansion:b=>{const y=new Set(i);y.has(b)?y.delete(b):y.add(b),o(y)},getAvailableSourceEntities:b=>{if(n.joins.length===0)return a;const y=n.joins.findIndex(I=>I.id===b);if(y===0)return a;const S=new Set;return n.baseEntity.name&&S.add(n.baseEntity.name),n.joins.slice(0,y).forEach(I=>{S.add(I.source.name),S.add(I.target.name)}),a.filter(I=>S.has(I.name))},getAvailableTargetEntities:b=>a.filter(y=>y.name!==b),addJoinKeyGroup:b=>{const y=n.joins.find(I=>I.id===b);if(!y)return;const S=[...y.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];c(b,{joinKeyGroups:S})},updateGroupOperator:(b,y,S)=>{const I=n.joins.find(C=>C.id===b);if(!I)return;const D=[...I.joinKeyGroups];D[y]={...D[y],operator:S},c(b,{joinKeyGroups:D})},removeJoinKeyGroup:(b,y)=>{const S=n.joins.find(D=>D.id===b);if(!S)return;const I=[...S.joinKeyGroups];I.splice(y,1),c(b,{joinKeyGroups:I})},addJoinKey:(b,y)=>{const S=n.joins.find(O=>O.id===b);if(!S)return;const I=a.find(O=>O.name===S.source.name),D=a.find(O=>O.name===S.target.name),C=[...S.joinKeyGroups],F={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:(D==null?void 0:D.name)||"",entityName:(D==null?void 0:D.name)||"",entityType:(D==null?void 0:D.type)||"table"},operator:"="};C[y]={...C[y],keys:[...C[y].keys,F]},c(b,{joinKeyGroups:C})},updateJoinKey:(b,y,S,I,D)=>{const C=n.joins.find(M=>M.id===b);if(!C)return;const F=a.find(M=>M.name===C.source.name),O=a.find(M=>M.name===C.target.name),A=[...C.joinKeyGroups],w=A[y].keys[S];I==="sourceColumnName"&&F?A[y].keys[S]={...w,source:{...w.source,name:D}}:I==="targetColumnName"&&O?A[y].keys[S]={...w,target:{...w.target,name:D}}:I==="operator"&&(A[y].keys[S]={...w,operator:D}),c(b,{joinKeyGroups:A})},removeJoinKey:(b,y,S)=>{const I=n.joins.find(C=>C.id===b);if(!I)return;const D=[...I.joinKeyGroups];D[y].keys.splice(S,1),c(b,{joinKeyGroups:D})},generateSQLPreview:()=>{const b=[...n.joins].sort((I,D)=>I.sequence-D.sequence),y=n.baseEntity;if(!y.name)return"SELECT * FROM table -- Please select a base entity";let S=`SELECT *
|
|
400
|
+
FROM ${y.name}`;return b.forEach(I=>{const D=a.find(O=>O.name===I.target.name);if(!D)return;const C=I.joinKeyGroups.filter(O=>O.keys&&O.keys.length>0).map(O=>{const A=O.keys.filter(w=>{var M,B,R,P;return((M=w.source)==null?void 0:M.name)&&((B=w.target)==null?void 0:B.name)&&((R=w.source)==null?void 0:R.entityName)&&((P=w.target)==null?void 0:P.entityName)}).map(w=>`${w.source.entityName}.${w.source.name} ${w.operator} ${w.target.entityName}.${w.target.name}`);return A.length>1?`(${A.join(` ${O.operator} `)})`:A[0]}).filter(Boolean),F=C.length>1?C.join(" OR "):C[0]||"condition_here";S+=`
|
|
401
|
+
${I.joinType} JOIN ${D.name}
|
|
402
|
+
ON ${F}`}),S},isValidConfiguration:()=>!(!n.baseEntity.name||n.joins.some(I=>!I.source.name||!I.target.name)||n.joins.some(I=>I.joinKeyGroups.some(D=>D.keys.length===0))||n.joins.some(I=>I.joinKeyGroups.some(D=>D.keys.some(C=>!C.source.name||!C.target.name||!C.operator))))}}function gr({joinPlan:s,availableDataSources:a,onSave:n,onRemove:r,onCancel:i}){const{setCardConfig:o}=t.useEditorActions();t.useEditorStore(C=>C.card.config);const{columnGroups:l}=Me(),{joinPlan:u,expandedJoins:c,setJoinPlan:h,addJoin:d,removeJoin:m,updateJoin:N,moveJoinUp:f,moveJoinDown:g,toggleJoinExpansion:x,getAvailableSourceEntities:v,getAvailableTargetEntities:p,addJoinKeyGroup:k,updateGroupOperator:T,removeJoinKeyGroup:E,addJoinKey:j,updateJoinKey:b,removeJoinKey:y,generateSQLPreview:S,isValidConfiguration:I}=fr({initialJoinPlan:s,availableDataSources:a}),D=C=>{const F=l.find(O=>O.entityName===C);return(F==null?void 0:F.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(t.Select,{value:u.baseEntity.name,onValueChange:C=>{const F=a.find(O=>O.name===C);h({...u,baseEntity:{connectionId:(F==null?void 0:F.connectionId)||"",connectionType:(F==null?void 0:F.connectionType)||"none",type:(F==null?void 0:F.type)||"table",name:C,database:F==null?void 0:F.database,schema:F==null?void 0:F.schema}})},children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(t.SelectContent,{children:a.map(C=>e.jsx(t.SelectItem,{value:C.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Badge,{variant:"outline",className:"text-xs",children:C.type}),C.name,e.jsx(t.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:S()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(t.Label,{children:["Joins Configuration (",u.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(t.Button,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(t.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),u.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:u.joins.map(C=>{const F=a.find(w=>w.name===C.source.name),O=a.find(w=>w.name===C.target.name),A=c.has(C.id);return e.jsxs(t.Card,{className:"border",children:[e.jsx(t.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(t.Badge,{children:C.sequence}),e.jsxs(t.CardTitle,{className:"text-sm",children:["Join ",C.sequence,F&&O&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",F.name," → ",O.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",onClick:()=>f(C.id),disabled:C.sequence===1,children:e.jsx(_e,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"ghost",size:"sm",onClick:()=>g(C.id),disabled:C.sequence===u.joins.length,children:e.jsx(qe,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"ghost",size:"sm",onClick:()=>x(C.id),children:A?e.jsx(t.ChevronUp,{className:"h-4 w-4"}):e.jsx(t.ChevronDown,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"ghost",size:"sm",onClick:()=>m(C.id),children:e.jsx(t.X,{className:"h-4 w-4"})})]})]})}),A&&e.jsxs(t.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(t.Label,{children:"Source"}),e.jsxs(t.Select,{value:C.source.name,onValueChange:w=>{const M=a.find(B=>B.name===w);N(C.id,{source:{connectionId:(M==null?void 0:M.connectionId)||"",connectionType:(M==null?void 0:M.connectionType)||"none",type:(M==null?void 0:M.type)||"table",name:w,database:M==null?void 0:M.database,schema:M==null?void 0:M.schema}})},children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Select source..."})}),e.jsx(t.SelectContent,{children:v(C.id).map(w=>e.jsx(t.SelectItem,{value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name]})},w.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Join Type"}),e.jsxs(t.Select,{value:C.joinType,onValueChange:w=>N(C.id,{joinType:w}),children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"INNER",children:"INNER JOIN"}),e.jsx(t.SelectItem,{value:"LEFT",children:"LEFT JOIN"}),e.jsx(t.SelectItem,{value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(t.SelectItem,{value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{children:"Target"}),e.jsxs(t.Select,{value:C.target.name,onValueChange:w=>{const M=a.find(B=>B.name===w);N(C.id,{target:{connectionId:(M==null?void 0:M.connectionId)||"",connectionType:(M==null?void 0:M.connectionType)||"none",type:(M==null?void 0:M.type)||"table",name:w,database:M==null?void 0:M.database,schema:M==null?void 0:M.schema}})},disabled:!C.source.name,children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Select target..."})}),e.jsx(t.SelectContent,{children:C.source.name?p(C.source.name).map(w=>e.jsx(t.SelectItem,{value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,w.name===C.source.name&&e.jsx(t.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},w.name)):[]})]})]})]}),C.source.name&&C.target.name&&F&&O&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(t.Label,{children:"Join Conditions"}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>k(C.id),children:[e.jsx(t.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((w,M)=>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(t.Label,{children:["Group ",M+1]}),M>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(t.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(t.Select,{value:w.operator,onValueChange:B=>T(C.id,M,B),children:[e.jsx(t.SelectTrigger,{className:"w-[100px]",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"AND",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>E(C.id,M),children:e.jsx(t.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[w.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:w.keys.map((B,R)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[R>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:w.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(t.Select,{value:B.source.name,onValueChange:P=>b(C.id,M,R,"sourceColumnName",P),children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Source column"})}),e.jsx(t.SelectContent,{children:D(C.source.name).map(P=>e.jsx(t.SelectItem,{value:P.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:P.name}),e.jsx(t.Badge,{variant:"outline",className:"ml-2 text-xs",children:P.dataType})]})},P.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(t.Select,{value:B.operator,onValueChange:P=>b(C.id,M,R,"operator",P),children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"=",children:"="}),e.jsx(t.SelectItem,{value:"<",children:"<"}),e.jsx(t.SelectItem,{value:">",children:">"}),e.jsx(t.SelectItem,{value:"<=",children:"<="}),e.jsx(t.SelectItem,{value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(t.Select,{value:B.target.name,onValueChange:P=>b(C.id,M,R,"targetColumnName",P),children:[e.jsx(t.SelectTrigger,{children:e.jsx(t.SelectValue,{placeholder:"Target column"})}),e.jsx(t.SelectContent,{children:D(C.target.name).map(P=>e.jsx(t.SelectItem,{value:P.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:P.name}),e.jsx(t.Badge,{variant:"outline",className:"ml-2 text-xs",children:P.dataType})]})},P.name))})]})}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>y(C.id,M,R),children:e.jsx(t.X,{className:"size-3.5"})})]},B.id||R))}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>j(C.id,M),children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},w.id))})]})]})]},C.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>{r(),i()},children:"Remove All"}),e.jsx(t.Button,{variant:"outline",onClick:i,children:"Cancel"}),e.jsx(t.Button,{onClick:()=>n(u),disabled:!I(),children:"Save"})]})]})}function Ht({children:s,open:a,onOpenChange:n,joinPlan:r,availableDataSources:i,onRemove:o,onSave:l,onCancel:u}){return e.jsxs(t.Dialog,{open:a,onOpenChange:n,children:[e.jsxs(t.DialogContent,{className:"max-w-4xl",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Join Configuration"}),e.jsx(t.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(gr,{joinPlan:r,availableDataSources:i,onSave:l,onCancel:u,onRemove:o})]}),s]})}function jr({joins:s,baseEntityId:a,availableDataSources:n,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",children:[s.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=[...s].sort((l,u)=>l.sequence-u.sequence),o=n.find(l=>l.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(t.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(t.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),i.map(l=>{const u=n.find(c=>c.name===l.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(t.Badge,{variant:"outline",className:"text-xs",children:l.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(t.Badge,{variant:"secondary",className:"text-xs",children:u==null?void 0:u.type}),e.jsx("span",{className:"text-xs font-medium",children:u==null?void 0:u.name})]})]},l.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",s.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...s].sort((i,o)=>i.sequence-o.sequence).map((i,o)=>{const l=n.find(c=>c.name===i.source.name),u=n.find(c=>c.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(t.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:o+1}),e.jsx(t.Badge,{variant:"outline",className:"shrink-0 text-xs",children:i.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[l==null?void 0:l.name," → ",u==null?void 0:u.name]}),e.jsxs(t.Badge,{variant:"outline",className:"ml-auto text-xs",children:[i.joinKeyGroups.reduce((c,h)=>c+h.keys.length,0)," ","condition",i.joinKeyGroups.reduce((c,h)=>c+h.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 yr(){var m,N;Me(),t.useEditorStore(f=>f.card.dataSource);const s=t.useEditorStore(f=>f.frame),a=t.useEditorStore(f=>f.card),n=t.useEditorStore(f=>f.actions.updateCardConfig),r=((m=a==null?void 0:a.config)==null?void 0:m.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[i,o]=L.useState(!1),l=((N=a==null?void 0:a.dataSource)==null?void 0:N.selectedEntities)||[],u=f=>{s.activeCardId&&(n(s.activeCardId,{...a==null?void 0:a.config,joinPlan:f}),o(!1))},c=()=>{n(s.activeCardId,{...a==null?void 0:a.config,joinPlan:void 0})},h=()=>{o(!1)},d=()=>{const f=[...r.joins].sort((v,p)=>v.sequence-p.sequence),g=r.baseEntity;if(!g.name)return"SELECT * FROM table -- Please select a base entity";let x=`SELECT *
|
|
403
|
+
FROM ${g.name}`;return f.forEach(v=>{const p=l.find(E=>E.name===v.target.name);if(!p)return;const k=v.joinKeyGroups.filter(E=>E.keys&&E.keys.length>0).map(E=>{const j=E.keys.filter(b=>{var y,S,I,D;return((y=b.source)==null?void 0:y.name)&&((S=b.target)==null?void 0:S.name)&&((I=b.source)==null?void 0:I.entityName)&&((D=b.target)==null?void 0:D.entityName)}).map(b=>`${b.source.entityName}.${b.source.name} ${b.operator} ${b.target.entityName}.${b.target.name}`);return j.length>1?`(${j.join(` ${E.operator} `)})`:j[0]}).filter(Boolean),T=k.length>1?k.join(" OR "):k[0]||"condition_here";x+=`
|
|
404
|
+
${v.joinType} JOIN ${p.name}
|
|
405
|
+
ON ${T}`}),x};return l.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(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",size:"sm",className:"h-6 text-xs font-semibold",onClick:()=>o(!0),children:[e.jsx(t.Link,{className:t.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(t.TooltipContent,{side:"right",className:"max-w-md overflow-hidden p-0",children:e.jsx(jr,{joins:r.joins,baseEntityId:r.baseEntity.name,availableDataSources:l,generateSQLPreview:d})})]})}),e.jsx(Ht,{open:i,onOpenChange:o,joinPlan:r,availableDataSources:l,onSave:u,onCancel:h,onRemove:c,children:e.jsx("div",{})})]}),r.joins.length===0&&e.jsx(Ht,{open:i,onOpenChange:o,joinPlan:r,availableDataSources:l,onSave:u,onCancel:h,onRemove:c,children:e.jsxs(t.Button,{onClick:()=>o(!0),variant:"outline",className:"h-6 text-xs font-semibold",children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"}),"Configure Join"]})})]})})})}function br(){const[s,a]=L.useState(!1),[n,r]=L.useState(!0),i=t.useEditorStore(c=>c.card.dataSource),{updateDataSource:o}=t.useEditorActions(),l={connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},u={...l,...i,selectedEntities:(i==null?void 0:i.selectedEntities)||[]};return e.jsxs("div",{className:"flex w-[325px] flex-col border-r bg-background",children:[e.jsxs("div",{onMouseEnter:()=>r(!0),onMouseLeave:()=>r(!1),children:[e.jsx("div",{className:t.cn("p-4 px-6",{"pb-0":!n}),children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Database,{className:"h-5 w-5 text-cyan-600"}),e.jsx("h2",{className:"font-semibold text-gray-900",children:"Data Source"})]}),e.jsxs(t.Button,{size:"sm",variant:"outline",className:"h-7",onClick:()=>a(!0),children:[e.jsx(t.Plus,{className:"mr-1 h-3.5 w-3.5"}),"Add"]})]})}),e.jsxs("div",{className:`overflow-hidden px-6 ${n?"max-h-96 space-y-4":"max-h-0 py-0 opacity-0"}`,children:[u.selectedEntities.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[u.selectedEntities.slice(0,3).map((c,h)=>e.jsxs(t.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:[c.name,e.jsx("button",{onClick:d=>{d.stopPropagation();const m=u.selectedEntities.filter(N=>!(N.name===c.name&&N.type===c.type));o({...l,...i,selectedEntities: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(t.X,{className:"h-2.5 w-2.5 text-red-500"})})]},`${c.type}-${c.name}-${h}`)),u.selectedEntities.length>3&&e.jsxs(t.Badge,{variant:"outline",className:"text-xs",children:["+",u.selectedEntities.length-3," more"]})]}),e.jsx(yr,{})]})]}),e.jsx(pr,{}),e.jsx(t.DataSourceDialog,{incomingSelectedEntities:(i==null?void 0:i.selectedEntities)||[],dialogMode:"dataSource",open:s,onOpenChange:a,dataSource:u,fallbackDataSource:l})]})}const vr=[{id:"table",icon:He,label:"Table"},{id:"bar",icon:$e,label:"Bar Chart"},{id:"line",icon:Ge,label:"Line Chart"},{id:"stackedBar",icon:ut,label:"Stacked Bar Chart"},{id:"stackedLine",icon:Dt,label:"Stacked Line Chart"},{id:"scatter",icon:pt,label:"Scatter Chart"},{id:"bubble",icon:Et,label:"Bubble Chart"},{id:"pie",icon:xt,label:"Pie Chart"},{id:"doughnut",icon:ft,label:"Doughnut Chart"},{id:"funnel",icon:It,label:"Funnel Chart"},{id:"radar",icon:bt,label:"Radar Chart"},{id:"polarArea",icon:kt,label:"Polar Area Chart"},{id:"tornado",icon:Nt,label:"Tornado Chart"},{id:"range",icon:ht,label:"Range Chart"},{id:"kpi",icon:Tt,label:"KPI"},{id:"text",icon:Ut,label:"Text"},{id:"map",icon:yt,label:"Map"},{id:"custom",icon:vt,label:"Custom"}];function Nr({selectedChart:s,onChartChange:a}){const{setCardType:n,setCardPreferences:r,setIsDevMode:i}=t.useEditorStore(h=>h.actions),{setCardCustomCfg:o,setCustomCardPreferences:l,setQueryConfig:u}=t.useEditorActions();function c(h){o(null),r({}),n(h),["kpi","custom","text","map"].includes(h)&&(i(!0),u(void 0)),a(h)}return e.jsx("div",{className:"mb-6",children:e.jsxs(t.Select,{value:s,onValueChange:c,children:[e.jsx(t.SelectTrigger,{className:"w-full",children:e.jsx(t.SelectValue,{placeholder:"Select chart type"})}),e.jsx(t.SelectContent,{children:vr.map(h=>{const d=h.icon;return e.jsx(t.SelectItem,{value:h.id,className:"flex items-center gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(d,{className:"h-4 w-4"}),e.jsx("span",{children:h.label})]})},h.id)})})]})})}const ks=({dataType:s})=>{const a=t.getDataType(s);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 Cr({label:s,onLabelChange:a}){const[n,r]=L.useState(s??""),[i,o]=L.useState(!1);return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-gray-600",children:"Display Label"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Input$1,{placeholder:"Display label...",value:i?n:s??"",onChange:l=>{r(l.target.value),o(!0)},onFocus:()=>o(!0),onClick:l=>l.stopPropagation(),className:"h-8 text-xs",onPointerDown:l=>l.stopPropagation(),onKeyDown:l=>{l.stopPropagation(),l.key==="Enter"&&i&&n!==(s??"")?(a(n),o(!1)):l.key==="Escape"&&(r(s??""),o(!1))},"aria-label":"Edit display label"}),i&&n!==(s??"")&&e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm label",onClick:()=>{a(n),o(!1)},children:e.jsx(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel label edit",onClick:()=>{r(s??""),o(!1)},children:e.jsx(t.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function Sr({aliasTemplate:s,onAliasTemplateChange:a}){var c;const[n,r]=L.useState(s),[i,o]=L.useState(!1),l=(c=t.useEditorStore(h=>{var d;return(d=h.card.config)==null?void 0:d.pivotByColumns}))==null?void 0:c[0],u=l?`e.g. Min Sales in {{${l.name}}}`:"e.g. Min Sales in {{region}}";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.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(t.Input$1,{placeholder:u,value:i?n:s,onChange:h=>{r(h.target.value),o(!0)},onFocus:()=>o(!0),onPointerDown:h=>h.stopPropagation(),className:"h-8 text-xs",onKeyDown:h=>{h.key==="Enter"&&i&&n!==s?(a(n),o(!1)):h.key==="Escape"&&(r(s),o(!1))},"aria-label":"Edit alias template"}),i&&n!==s&&e.jsxs(e.Fragment,{children:[e.jsx(t.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(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel alias template edit",onClick:()=>{r(s),o(!1)},children:e.jsx(t.X,{className:"h-4 w-4 text-gray-400"})})]})]})]})}function wr({valueAliases:s,onValueAliasesChange:a}){const[n,r]=L.useState(null),[i,o]=L.useState(""),[l,u]=L.useState(""),c=()=>{a({...s,"":""})},h=m=>{const N={...s};delete N[m],a(N)},d=m=>{const N={...s};delete N[m],N[i]=l,a(N),r(null)};return e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-gray-600",children:"Pivot Value Aliases"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(s).map(([m,N],f)=>e.jsx("div",{className:"flex items-center gap-2",children:n===m?e.jsxs(e.Fragment,{children:[e.jsx(t.Input$1,{placeholder:"Value key",value:i,onChange:g=>o(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?d(m):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias key"}),e.jsx(t.Input$1,{placeholder:"Alias label",value:l,onChange:g=>u(g.target.value),className:"h-8 w-24 text-xs",onPointerDown:g=>g.stopPropagation(),onKeyDown:g=>{g.key==="Enter"?d(m):g.key==="Escape"&&r(null)},"aria-label":"Edit value alias label"}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Confirm value alias edit",onClick:()=>d(m),children:e.jsx(t.Check,{className:"h-4 w-4 text-green-600"})}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 p-0","aria-label":"Cancel value alias edit",onClick:()=>r(null),children:e.jsx(t.X,{className:"h-4 w-4 text-gray-400"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(t.Input$1,{placeholder:"Value key",value:m,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(m),o(m),u(N)},"aria-label":"Edit value alias key"}),e.jsx(t.Input$1,{placeholder:"Alias label",value:N,className:"h-8 w-24 text-xs",readOnly:!0,onClick:()=>{r(m),o(m),u(N)},"aria-label":"Edit value alias label"}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",onClick:()=>h(m),"aria-label":"Remove value alias",children:e.jsx(t.X,{className:"h-3 w-3"})})]})},m+f)),e.jsxs(t.Button,{variant:"outline",size:"sm",className:"mt-1 h-8 text-xs",onClick:c,children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"})," Add Value Alias"]})]})]})}function kr({field:s,zone:a,onRemove:n,onLabelChange:r,sortDirection:i,onSortDirectionChange:o,onAliasTemplateChange:l,onValueAliasesChange:u,onAggregationChange:c,onDateFormatChange:h,onGranularityChange:d,hasPivotColumns:m=!1}){const{attributes:N,listeners:f,setNodeRef:g,transform:x,transition:v,isDragging:p}=t.useSortable({id:s.id}),[k,T]=L.useState(!1),[E,j]=L.useState(s.dateFormat||"YYYY-MM-DD"),[b,y]=L.useState(s.customFormat||""),[S,I]=L.useState(!!s.customFormat),[D,C]=L.useState(s.granularity||"day"),[F,O]=L.useState(s.aliasTemplate||""),[A,w]=L.useState(s.valueAliases||{}),M=q=>{q==="custom"?I(!0):(I(!1),j(q),a==="groupBy"&&h&&h(q,""))},B=q=>{y(q),a==="groupBy"&&h&&h("custom",q)},R=q=>{C(q),a==="groupBy"&&d&&d(q)},P=q=>{O(q),l&&l(q)},z=q=>{w(q),u&&u(q)},K={transform:t.CSS.Transform.toString(x),transition:v},J=t.getDataType(s.dataType),G=J==="date",U=[{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:g,style:K,...N,...f,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 ${p?"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(t.GripVertical,{className:"h-3 w-3"}),e.jsx(ks,{dataType:J}),e.jsx("span",{className:"max-w-[180px] flex-1 overflow-hidden truncate text-sm",children:s.label||s.name}),a!=="sortBy"&&e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:q=>{q.stopPropagation(),T(!k)},children:e.jsx(t.ChevronDown,{className:`h-3 w-3 transition-transform ${k?"rotate-180":""}`})}),a==="sortBy"&&e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 group-hover:opacity-100",onClick:q=>{q.stopPropagation(),console.log("DraggableField - Current sortDirection:",i);const V=i==="asc"?"desc":"asc";console.log("DraggableField - New direction to set:",V),o(V)},children:i==="asc"?e.jsx(_e,{className:"h-3 w-3"}):e.jsx(qe,{className:"h-3 w-3"})}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100",onClick:q=>{q.stopPropagation(),n()},children:e.jsx(t.X,{className:"h-3 w-3"})})]}),k&&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:`${s.entityName}.${s.name}`}),a!=="pivotBy"&&e.jsx(Cr,{label:s.label??"",onLabelChange:r}),G&&a!=="groupBy"&&e.jsx("div",{className:"space-y-1",children:e.jsxs(t.Select,{defaultValue:"day",children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"day",children:"Day"}),e.jsx(t.SelectItem,{value:"week",children:"Week"}),e.jsx(t.SelectItem,{value:"month",children:"Month"}),e.jsx(t.SelectItem,{value:"quarter",children:"Quarter"}),e.jsx(t.SelectItem,{value:"year",children:"Year"})]})]})}),G&&a==="groupBy"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-gray-600",children:"Granularity"}),e.jsxs(t.Select,{value:D,onValueChange:R,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select granularity..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"day",children:"Day"}),e.jsx(t.SelectItem,{value:"week",children:"Week"}),e.jsx(t.SelectItem,{value:"month",children:"Month"}),e.jsx(t.SelectItem,{value:"quarter",children:"Quarter"}),e.jsx(t.SelectItem,{value:"year",children:"Year"})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(t.Label,{className:"text-xs font-medium text-gray-600",children:"Date Format"}),e.jsxs(t.Select,{value:S?"custom":E,onValueChange:M,children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select date format..."})}),e.jsx(t.SelectContent,{children:U.map(q=>e.jsx(t.SelectItem,{value:q.value,children:q.label},q.value))})]}),S&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx(t.Input$1,{placeholder:"Enter custom format (e.g., YYYY-MM-DD HH:mm)",value:b,onChange:q=>{q.stopPropagation(),B(q.target.value)},onClick:q=>q.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(t.Label,{className:"text-xs font-medium text-gray-600",children:"Aggregation"}),e.jsxs(t.Select,{value:s.aggregate,onValueChange:q=>{c&&c(q)},children:[e.jsx(t.SelectTrigger,{className:"h-8 w-full text-xs",children:e.jsx(t.SelectValue,{placeholder:"Select function..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"COUNT",children:"Count"}),e.jsx(t.SelectItem,{value:"DISTINCT",children:"Count Distinct"}),t.getDataType(s.dataType)==="number"&&e.jsxs(e.Fragment,{children:[e.jsx(t.SelectItem,{value:"SUM",children:"Sum"}),e.jsx(t.SelectItem,{value:"AVG",children:"Average"}),e.jsx(t.SelectItem,{value:"MIN",children:"Min"}),e.jsx(t.SelectItem,{value:"MAX",children:"Max"}),e.jsx(t.SelectItem,{value:"MEDIAN",children:"Median"})]})]})]})]}),m&&e.jsxs(e.Fragment,{children:[e.jsx(Sr,{aliasTemplate:F,onAliasTemplateChange:P}),e.jsx(wr,{valueAliases:A,onValueAliasesChange:z})]})]})]})]})}function Er({concept:s}){const a=()=>{switch(s){case"groupBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Rows = Group By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that define how your data is grouped into rows."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-amber-100 text-xs font-medium dark:bg-amber-200/20",children:"Product"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Sales"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"Profit"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-amber-100 text-xs font-medium dark:bg-amber-200/20",children:"Electronics"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$5,200"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$1,300"})]}),e.jsxs("div",{className:"flex border-b dark:border-border",children:[e.jsx("div",{className:"w-1/3 bg-amber-50 text-xs font-medium dark:bg-amber-300/20",children:"Clothing"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$3,100"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$620"})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-1/3 bg-amber-100 text-xs font-medium dark:bg-amber-200/20",children:"Food"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$2,400"}),e.jsx("div",{className:"w-1/3 text-center text-xs",children:"$480"})]})]})]});case"pivotBy":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Columns = Pivot By"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that split your data into multiple columns or series."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"flex border-b pb-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Region"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"North"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"South"}),e.jsx("div",{className:"w-1/4 rounded-t bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"East"})]}),e.jsxs("div",{className:"flex border-b py-1 dark:border-border",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$2,300"}),e.jsx("div",{className:"w-1/4 bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$1,800"}),e.jsx("div",{className:"w-1/4 bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$3,400"})]}),e.jsxs("div",{className:"flex py-1",children:[e.jsx("div",{className:"w-1/4 text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$460"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-100 text-center text-xs dark:bg-purple-400/20",children:"$360"}),e.jsx("div",{className:"w-1/4 rounded-b bg-purple-50 text-center text-xs dark:bg-purple-300/20",children:"$680"})]})]})]});case"metrics":return e.jsxs("div",{className:"w-64 space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Metrics = Values (Cells)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fields that represent the values shown in your visualization."}),e.jsxs("div",{className:"rounded-md border bg-white p-2 dark:border-muted dark:bg-muted",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"col-span-1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q1"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q2"}),e.jsx("div",{className:"col-span-1 text-center text-xs font-medium",children:"Q3"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Sales"}),e.jsx("div",{className:"rounded bg-blue-100 p-1 text-center text-xs dark:bg-blue-300/20",children:"$2,300"}),e.jsx("div",{className:"rounded bg-blue-200 p-1 text-center text-xs dark:bg-blue-400/20",children:"$3,100"}),e.jsx("div",{className:"rounded bg-blue-300 p-1 text-center text-xs dark:bg-blue-500/20",children:"$4,200"})]}),e.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-1",children:[e.jsx("div",{className:"text-xs font-medium",children:"Profit"}),e.jsx("div",{className:"rounded bg-green-100 p-1 text-center text-xs dark:bg-green-300/20",children:"$460"}),e.jsx("div",{className:"rounded bg-green-200 p-1 text-center text-xs dark:bg-green-400/20",children:"$620"}),e.jsx("div",{className:"rounded bg-green-300 p-1 text-center text-xs dark:bg-green-500/20",children:"$840"})]})]})]});default:return null}};return e.jsx(t.TooltipProvider$1,{children:e.jsxs(t.Tooltip,{delayDuration:300,children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx(t.CircleHelp,{className:"size-4 text-muted-foreground hover:text-foreground"})}),e.jsx(t.TooltipContent,{side:"right",align:"start",className:"p-3",children:a()})]})})}function Fe({zone:s,fields:a,label:n,placeholder:r,onRemove:i,onLabelChange:o,onAggregationChange:l,onDateFormatChange:u,onGranularityChange:c,onAliasTemplateChange:h,onValueAliasesChange:d,shouldShow:m,hasPivotColumns:N=!1}){const{isOver:f,setNodeRef:g}=t.useDroppable({id:s}),{updateSortByColumn:x}=t.useEditorActions(),v=t.useEditorStore(T=>T.card),p=a.length>0,k=(T,E)=>{var b;!((b=v.config)!=null&&b.sortByColumns)||v.config.sortByColumns.findIndex(y=>y.id===T)===-1||x(v.id,T,{direction:E})};return s==="sortBy"&&m===!1?null:e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsx(t.Label,{className:"block text-sm font-medium",children:n}),e.jsx(Er,{concept:s})]}),e.jsx("div",{ref:g,className:`min-h-[60px] rounded-lg border-2 border-dashed p-3 transition-all ${f?"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(t.Plus,{className:"mr-2 h-4 w-4"}),r]}):e.jsx(t.SortableContext,{items:a.map(T=>T.id),strategy:t.verticalListSortingStrategy,children:e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map((T,E)=>{const b=T.direction;return e.jsx("div",{className:"flex w-full items-center gap-2",children:e.jsx("div",{className:"flex-1",children:e.jsx(kr,{field:T,zone:s,onRemove:()=>i(E),onLabelChange:y=>o(E,y),sortDirection:b,onSortDirectionChange:y=>k(T.id,y),onAggregationChange:l?y=>l(E,y):void 0,onAliasTemplateChange:h?y=>h(E,y):void 0,onValueAliasesChange:d?y=>d(E,y):void 0,onDateFormatChange:u?(y,S)=>u(E,y,S):void 0,onGranularityChange:c?y=>c(E,y):void 0,hasPivotColumns:N})})},T.id)})})})})]})}function Ir({groupByFields:s,pivotByFields:a,metricsFields:n,sortByFields:r,onRemoveField:i,onLabelChange:o,onAggregationChange:l,onDateFormatChange:u,onGranularityChange:c,onAliasTemplateChange:h,onValueAliasesChange:d}){return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Fe,{zone:"groupBy",fields:s,label:"Rows",placeholder:"Drop fields to group data",onRemove:m=>i("groupBy",m),onLabelChange:(m,N)=>o("groupBy",m,N),onDateFormatChange:(m,N,f)=>u&&u(m,N,f),onGranularityChange:(m,N)=>c&&c(m,N)}),e.jsx(Fe,{zone:"pivotBy",fields:a,label:"Columns",placeholder:"Drop fields to pivot data",onRemove:m=>i("pivotBy",m),onLabelChange:(m,N)=>o("pivotBy",m,N)}),e.jsx(Fe,{zone:"metrics",fields:n,label:"Metrics",placeholder:"Drop fields to measure",onRemove:m=>i("metrics",m),onLabelChange:(m,N)=>o("metrics",m,N),onAggregationChange:l,onAliasTemplateChange:h,onValueAliasesChange:d,hasPivotColumns:a.length>0}),r&&r.length>0&&e.jsx(Fe,{zone:"sortBy",fields:r,label:"Sort By",placeholder:"Drop fields to sort data",onRemove:m=>i("sortBy",m),onLabelChange:(m,N)=>o("sortBy",m,N),shouldShow:s.length>0||a.length>0||n.length>0})]})}function Dr({selectedChart:s,onChartChange:a,groupByFields:n,pivotByFields:r,metricsFields:i,sortByFields:o,onRemoveField:l,onLabelChange:u,onAggregationChange:c,onDateFormatChange:h,onGranularityChange:d,onAliasTemplateChange:m,onValueAliasesChange:N}){t.useEditorStore(g=>g.showAIDialog);const{setShowAIDialog:f}=t.useEditorActions();return e.jsxs("div",{className:"flex w-96 flex-col border-r bg-background",children:[e.jsxs("div",{className:"mt-1 space-y-4 border-b px-6 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mt,{className:"h-5 w-5 text-cyan-600"}),e.jsx("h2",{className:"font-semibold",children:"Chart Configuration"})]}),e.jsx(Nr,{selectedChart:s,onChartChange:a})]}),e.jsxs(t.ScrollArea,{className:"flex-1 p-6",children:[e.jsx(Ir,{groupByFields:n,pivotByFields:r,metricsFields:i,sortByFields:o,onRemoveField:l,onLabelChange:u,onAggregationChange:c,onDateFormatChange:h,onGranularityChange:d,onAliasTemplateChange:m,onValueAliasesChange:N}),e.jsx(t.ScrollBar,{orientation:"horizontal"})]})]})}function Tr({initialFilters:s,availableFields:a}={}){const[n,r]=L.useState(s||{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[],groups:[]});t.useEditorStore(j=>j.card.dataSource);const{columns:i,isLoading:o}=Me(),u=a||i||[],c={id:"default",name:"default",dataType:"string",label:"Default",entityId:"default",entityName:"Default",entityType:"table"},h=j=>{const b=y=>{if(y.id===j){const S=u[0]||c;return{...y,conditions:[...y.conditions,{id:`condition-${Date.now()}`,field:S,operator:"=",value:""}]}}return{...y,groups:y.groups.map(b)}};r(b(n))},d=j=>{const b=y=>{if(y.id===j){const S=u[0]||c;return{...y,groups:[...y.groups,{id:`group-${Date.now()}`,logicalOperator:"AND",negate:!1,conditions:[{id:`condition-${Date.now()}`,field:S,operator:"=",value:""}],groups:[]}]}}return{...y,groups:y.groups.map(b)}};r(b(n))},m=(j,b)=>{const y=S=>S.id===j?{...S,conditions:S.conditions.filter(I=>I.id!==b)}:{...S,groups:S.groups.map(y)};r(y(n))},N=(j,b)=>{const y=S=>S.id===j?{...S,groups:S.groups.filter(I=>I.id!==b)}:{...S,groups:S.groups.map(y)};r(y(n))},f=(j,b,y,S)=>{if(y==="field")throw new Error("Use a dedicated method to update the field property with a Field object");const I=D=>D.id===j?{...D,conditions:D.conditions.map(C=>C.id===b?{...C,[y]:S}:C)}:{...D,groups:D.groups.map(I)};r(I(n))},g=(j,b,y)=>{const S=I=>I.id===j?{...I,conditions:I.conditions.map(D=>D.id===b?{...D,...y}:D)}:{...I,groups:I.groups.map(S)};r(S(n))},x=(j,b)=>{const y=S=>S.id===j?{...S,logicalOperator:b}:{...S,groups:S.groups.map(y)};r(y(n))},v=(j,b)=>{const y=S=>S.id===j?{...S,negate:b}:{...S,groups:S.groups.map(y)};r(y(n))},p=(j,b,y)=>{const S=I=>I.id===j?{...I,conditions:t.arrayMove(I.conditions,b,y)}:{...I,groups:I.groups.map(S)};r(S(n))},k=(j,b,y)=>{const S=I=>I.id===j?{...I,groups:t.arrayMove(I.groups,b,y)}:{...I,groups:I.groups.map(S)};r(S(n))},T=j=>{if(!j||j.conditions.length===0&&j.groups.length===0)return"-- No filters defined";const b=S=>{let I="";typeof S.field=="object"?I=S.field.entityName?`${S.field.entityName}.${S.field.name}`:S.field.name:I=String(S.field);const D=S.operator;let C=S.value;if(S.field.dataType==="string"&&!["in","not in"].includes(S.operator))typeof C=="string"?C=`'${C}'`:Array.isArray(C)&&(C=`'${C.join(", ")}'`);else if(S.field.dataType==="date")(typeof C=="string"||C instanceof Date)&&(C=`DATE('${C}')`);else if(["in","not in"].includes(S.operator)){let F=[];Array.isArray(C)?F=C.map(O=>typeof O=="string"?`'${O}'`:String(O)):typeof C=="string"?F=C.split(",").map(O=>{const A=O.trim();return S.field.dataType==="string"?`'${A}'`:A}):typeof C=="number"&&(F=[String(C)]),C=`(${F.join(", ")})`}switch(D){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} ${D} ${C}`}},y=S=>{const I=S.conditions.map(b),D=S.groups.map(A=>y(A)),C=[...I,...D].filter(Boolean);if(C.length===0)return"";const F=C.join(` ${S.logicalOperator} `),O=C.length>1?`(${F})`:F;return S.negate?`NOT ${O}`:O};return y(j)},E=n.conditions.length>0||n.groups.length>0;return{currentFilters:n,setCurrentFilters:r,availableFields:u,isLoading:o,addCondition:h,addGroup:d,removeCondition:m,removeGroup:N,updateCondition:f,updateConditionFields:g,updateGroupOperator:x,updateGroupNegate:v,reorderConditions:p,reorderGroups:k,generateSQLPreview:T,hasAnyFilters:E}}const Mr=s=>{switch(s){case"table":return e.jsx(t.Table,{className:"h-3 w-3"});case"view":return e.jsx(t.Eye,{className:"h-3 w-3"});case"dataset":return e.jsx(mt,{className:"h-3 w-3"});case"file":return e.jsx(hn,{className:"h-3 w-3"});default:return e.jsx(t.Table,{className:"h-3 w-3"})}},Ar=s=>{switch(s){case"table":return"Table";case"view":return"View";case"dataset":return"Dataset";case"file":return"File";default:return"Table"}},Lr=s=>{if(s.qualifiedEntityName){const a=s.qualifiedEntityName.split(".");return a.length>1?a[0]:"default"}return"default"};function Or({value:s,onValueChange:a,availableFields:n,placeholder:r="Select field",className:i="w-64"}){const[o,l]=L.useState(!1),u=L.useMemo(()=>{const c={};return n.forEach(h=>{const d=Lr(h);c[d]||(c[d]={}),c[d][h.entityId]||(c[d][h.entityId]=[]),c[d][h.entityId].push(h)}),c},[n]);return e.jsxs(t.Popover,{modal:!0,open:o,onOpenChange:l,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:"outline",role:"combobox","aria-expanded":o,className:t.cn("justify-between",!s&&"text-muted-foreground",i),children:[s?e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"truncate text-sm",children:[s.entityName,".",s.name]})}):r,e.jsx(tn,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"z-50 w-80 p-0",align:"start",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search fields...",className:"h-9"}),e.jsx(t.CommandEmpty,{children:"No fields found."}),e.jsx(t.CommandList,{className:"max-h-80",children:Object.entries(u).map(([c,h])=>e.jsx(t.CommandGroup,{heading:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Database,{className:"h-3 w-3"}),c]}),children:Object.entries(h).map(([d,m])=>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:[Mr(m[0].entityType),e.jsx("span",{children:m[0].entityName}),e.jsx(t.Badge,{variant:"secondary",className:"text-xs",children:Ar(m[0].entityType)})]}),m.map(N=>e.jsxs(t.CommandItem,{value:N.id,onSelect:()=>{a(N),l(!1)},className:"pl-6",children:[e.jsx(t.Check,{className:t.cn("mr-2 h-4 w-4",(s==null?void 0:s.id)===N.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:N.label}),N.role&&e.jsx(t.Badge,{variant:"outline",className:"text-xs capitalize",children:N.role})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[e.jsx("span",{children:N.dataType}),N.description&&e.jsxs("span",{children:["• ",N.description]}),N.customFormat&&e.jsxs("span",{children:["• ",N.customFormat]})]})]})]},N.id))]},`${c}-${d}`))},c))})]})})]})}function Lt(s){var f;const a=t.useEditorStore(g=>g.card),{authToken:n}=t.useSemaphorContext(),r=t.useEditorStore(g=>g.card.config),i=r==null?void 0:r.joinPlan,o={...s,label:"value",role:"groupby"},l={...s,role:"metric",label:"count",aggregate:"COUNT"},u={joinPlan:i,groupByColumns:[o],metricColumns:[l]},c=((f=a.dataSource)==null?void 0:f.connectionId)||a.connectionId,{data:h,isPending:d,error:m}=t.useQuery({queryKey:["filterValues",s.entityId,s.name,s.qualifiedEntityName],queryFn:async()=>{try{return await t.postRequestRegular("https://semaphor.cloud/api/v1/query",(n==null?void 0:n.accessToken)||"",{connection_id:c,cardConfig:u,cardDataSource:a.dataSource})}catch(g){console.log(s),console.error("error",g)}},enabled:!!c,refetchOnMount:!0,refetchOnWindowFocus:!1});return{filterValues:((h==null?void 0:h.records)||[]).map(g=>({label:g.value||"BLANK",value:g.value||"BLANK",count:g.count})),isPending:d,error:m}}function Fr({field:s,selected:a,onChange:n,placeholder:r="Select items...",className:i}){const[o,l]=re.useState(!1),{filterValues:u}=Lt(s),c=d=>{n(a.filter(m=>m!==d))},h=d=>{a.includes(d)?n(a.filter(m=>m!==d)):n([...a,d])};return e.jsx("div",{className:t.cn("w-full",i),children:e.jsxs(t.Popover,{open:o,onOpenChange:l,modal:!0,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.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(d=>{const m=u.find(N=>N.value===d);return e.jsxs(t.Badge,{variant:"secondary",className:"text-xs",children:[m==null?void 0:m.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:N=>{N.key==="Enter"&&c(d)},onMouseDown:N=>{N.preventDefault(),N.stopPropagation()},onClick:N=>{N.stopPropagation(),c(d)},children:e.jsx(t.X,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},d)}):e.jsx("span",{className:"text-muted-foreground",children:r})}),e.jsx(t.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(t.PopoverContent,{className:"z-50 w-fit overflow-auto p-0",align:"start",children:e.jsxs(t.Command,{children:[e.jsx(t.CommandInput,{placeholder:"Search..."}),e.jsxs(t.CommandList,{children:[e.jsx(t.CommandEmpty,{children:"No results found."}),e.jsx(t.CommandGroup,{children:u.map(d=>e.jsxs(t.CommandItem,{onSelect:()=>h(d.value),children:[e.jsx(t.Check,{className:t.cn("mr-2 h-4 w-4",a.includes(d.value)?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"flex grow items-center justify-between gap-4",children:[e.jsx("span",{children:d.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:d.count})]})]},d.value))})]})]})})]})})}const Es=s=>{if(!s)return 0;let a=s.conditions.length;return s.groups.forEach(n=>{a+=Es(n)}),a};function Br({field:s,value:a,onChange:n,placeholder:r="Select value...",className:i}){const{filterValues:o,isPending:l,error:u}=Lt(s);return l?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..."]}):u?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsxs(t.Select,{value:a,onValueChange:n,children:[e.jsx(t.SelectTrigger,{className:i||"flex-1",children:e.jsx(t.SelectValue,{placeholder:r,children:a})}),e.jsx(t.SelectContent,{children:o.map(c=>e.jsx(t.SelectItem,{value:c.value,children:c.label},c.value))})]})}const zr=["=","!=",">",">=","<","<=","contains","startsWith","endsWith","in","not in"],Rr=["=","!=","contains","startsWith","endsWith","in","not in"],Pr=["=","!=",">",">=","<","<=","in","not in"],Vr=["=","!="],qr=["=","!=",">",">=","<","<=","in","not in"];function _r(s){switch(s){case"string":return Rr;case"number":return Pr;case"boolean":return Vr;case"date":return qr;default:return zr}}function Is({condition:s,index:a,groupId:n,groupLogicalOperator:r,onUpdateCondition:i,onRemoveCondition:o,onUpdateGroupOperator:l,availableFields:u,updateConditionFields:c}){const{attributes:h,listeners:d,setNodeRef:m,transform:N,transition:f,isDragging:g}=t.useSortable({id:s.id}),{isPending:x,error:v}=Lt(s.field),p={transform:t.CSS.Transform.toString(N),transition:f};return e.jsxs("div",{ref:m,style:p,className:`mb-2 flex items-center gap-2 rounded p-2 hover:bg-gray-50 ${g?"z-50 opacity-50":""}`,children:[e.jsx("div",{...h,...d,className:"cursor-grab active:cursor-grabbing",children:e.jsx(t.GripVertical,{className:"h-4 w-4 flex-shrink-0 text-gray-400"})}),a>0&&e.jsxs(t.Select,{value:r,onValueChange:k=>l(n,k),children:[e.jsx(t.SelectTrigger,{className:"w-24",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"AND",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",children:"OR"})]})]}),a===0&&e.jsx("div",{className:"w-24"}),e.jsx(Or,{value:s.field,onValueChange:k=>{c(n,s.id,{field:k,value:""})},availableFields:u,placeholder:"Select field",className:"w-64"}),e.jsxs(t.Select,{value:s.operator,onValueChange:k=>{k==="in"||k==="not in"?c(n,s.id,{operator:k,value:[]}):c(n,s.id,{operator:k,value:""})},children:[e.jsx(t.SelectTrigger,{className:"w-28",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:_r(t.getDataType(s.field.dataType)).map(k=>e.jsx(t.SelectItem,{value:k,children:k},k))})]}),t.getDataType(s.field.dataType)==="string"?s.operator==="in"||s.operator==="not in"?x?e.jsxs("div",{className:"flex flex-1 items-center justify-center p-2 text-xs text-gray-500",children:[e.jsx(ce,{className:"mr-2 size-3.5 animate-spin"})," Loading values..."]}):v?e.jsx("div",{className:"flex-1 p-2 text-xs text-red-500",children:"Error loading values"}):e.jsx(Fr,{field:s.field,selected:Array.isArray(s.value)&&s.value.every(k=>typeof k=="string")?s.value:[],onChange:k=>c(n,s.id,{value:k}),placeholder:`Select values for ${s.operator}...`,className:"flex-1"}):["contains","startsWith","endsWith"].includes(s.operator)?e.jsx(t.Input$1,{value:typeof s.value=="string"?s.value:"",onChange:k=>c(n,s.id,{value:k.target.value}),className:"flex-1",placeholder:s.operator.charAt(0).toUpperCase()+s.operator.slice(1)+"..."}):e.jsx(Br,{field:s.field,value:typeof s.value=="string"?s.value:"",onChange:k=>c(n,s.id,{value:k}),placeholder:"Select value...",className:"flex-1"}):t.getDataType(s.field.dataType)==="boolean"?e.jsxs(t.Select,{value:typeof s.value=="boolean"?String(s.value):"",onValueChange:k=>c(n,s.id,{value:k==="true"}),children:[e.jsx(t.SelectTrigger,{className:"flex-1",children:e.jsx(t.SelectValue,{placeholder:"Select value..."})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"true",children:"True"}),e.jsx(t.SelectItem,{value:"false",children:"False"})]})]}):e.jsx(t.Input$1,{value:typeof s.value=="string"||typeof s.value=="number"?s.value:"",onChange:k=>i(n,s.id,"value",k.target.value),className:"flex-1",placeholder:s.operator==="in"||s.operator==="not in"?"value1, value2, value3":"Value"}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 flex-shrink-0 p-0",onClick:()=>o(n,s.id),children:e.jsx(t.X,{className:"h-3 w-3"})})]})}function $r({group:s,depth:a,parentGroupId:n,onUpdateGroupOperator:r,onUpdateGroupNegate:i,onRemoveGroup:o,onUpdateCondition:l,onUpdateField:u,onRemoveCondition:c,onReorderConditions:h,onReorderGroups:d,onAddCondition:m,onAddGroup:N,availableFields:f,renderFilterGroup:g,updateConditionFields:x}){const{attributes:v,listeners:p,setNodeRef:k,transform:T,transition:E,isDragging:j}=t.useSortable({id:s.id}),b={transform:t.CSS.Transform.toString(T),transition:E},y=I=>{const{active:D,over:C}=I;if(C&&D.id!==C.id){const F=s.conditions.findIndex(A=>A.id===D.id),O=s.conditions.findIndex(A=>A.id===C.id);F!==-1&&O!==-1&&h(s.id,F,O)}},S=I=>{const{active:D,over:C}=I;if(C&&D.id!==C.id&&n){const F=s.groups.findIndex(A=>A.id===D.id),O=s.groups.findIndex(A=>A.id===C.id);F!==-1&&O!==-1&&d(n,F,O)}};return e.jsxs("div",{ref:k,style:b,className:`rounded-lg ${a>0?"mt-2 border border-gray-200":""} ${j?"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",{...v,...p,className:"cursor-grab active:cursor-grabbing",children:e.jsx(t.GripVertical,{className:"h-4 w-4 text-gray-400"})}),e.jsx(t.Button,{variant:s.negate?"default":"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>i(s.id,!s.negate),children:"NOT"}),e.jsxs(t.Select,{value:s.logicalOperator,onValueChange:I=>r(s.id,I),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-20",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"AND",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx("span",{className:"text-sm font-medium",children:"Group"})]}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>n&&o(n,s.id),children:e.jsx(t.Trash2,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:`p-3 ${a>0?"":"px-0"}`,children:[e.jsx(t.DndContext,{sensors:t.useSensors(t.useSensor(t.PointerSensor),t.useSensor(t.KeyboardSensor,{coordinateGetter:t.sortableKeyboardCoordinates})),collisionDetection:t.closestCenter,onDragEnd:y,children:e.jsx(t.SortableContext,{items:s.conditions.map(I=>I.id),strategy:t.verticalListSortingStrategy,children:s.conditions.map((I,D)=>e.jsx(Is,{condition:I,index:D,groupId:s.id,groupLogicalOperator:s.logicalOperator,onUpdateCondition:l,onUpdateField:u,onRemoveCondition:c,onUpdateGroupOperator:r,availableFields:f,updateConditionFields:x},I.id))})}),e.jsx(t.DndContext,{sensors:t.useSensors(t.useSensor(t.PointerSensor),t.useSensor(t.KeyboardSensor,{coordinateGetter:t.sortableKeyboardCoordinates})),collisionDetection:t.closestCenter,onDragEnd:S,children:e.jsx(t.SortableContext,{items:s.groups.map(I=>I.id),strategy:t.verticalListSortingStrategy,children:s.groups.map(I=>g(I,a+1,s.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(t.Button,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>m(s.id),children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),e.jsxs(t.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>N(s.id),children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})]})}function Gr({filters:s,availableFields:a,onSave:n,onClearAll:r,onCancel:i}){const{currentFilters:o,availableFields:l,isLoading:u,addCondition:c,addGroup:h,removeCondition:d,removeGroup:m,updateCondition:N,updateConditionFields:f,updateGroupOperator:g,updateGroupNegate:x,reorderConditions:v,reorderGroups:p,generateSQLPreview:k,hasAnyFilters:T,setCurrentFilters:E}=Tr({initialFilters:s,availableFields:a}),j=t.useSensors(t.useSensor(t.PointerSensor),t.useSensor(t.KeyboardSensor,{coordinateGetter:t.sortableKeyboardCoordinates})),[b,y]=L.useState(!1),S=(C,F,O)=>{const A=w=>w.id===C?{...w,conditions:w.conditions.map(M=>M.id===F?{...M,field:O,dataType:O.dataType}:M)}:{...w,groups:w.groups.map(A)};E(A(o))},I=(C,F=0,O)=>F===0?e.jsx("div",{className:"rounded-lg",children:e.jsxs("div",{className:"p-3 px-0",children:[e.jsx(t.DndContext,{sensors:j,collisionDetection:t.closestCenter,onDragEnd:A=>{const{active:w,over:M}=A;if(M&&w.id!==M.id){const B=C.conditions.findIndex(P=>P.id===w.id),R=C.conditions.findIndex(P=>P.id===M.id);B!==-1&&R!==-1&&v(C.id,B,R)}},children:e.jsx(t.SortableContext,{items:C.conditions.map(A=>A.id),strategy:t.verticalListSortingStrategy,children:C.conditions.map((A,w)=>e.jsx(Is,{condition:A,index:w,groupId:C.id,groupLogicalOperator:C.logicalOperator,onUpdateCondition:N,onUpdateField:S,onRemoveCondition:d,onUpdateGroupOperator:g,availableFields:l,updateConditionFields:f},A.id))})}),e.jsx(t.DndContext,{sensors:j,collisionDetection:t.closestCenter,onDragEnd:A=>{const{active:w,over:M}=A;if(M&&w.id!==M.id){const B=C.groups.findIndex(P=>P.id===w.id),R=C.groups.findIndex(P=>P.id===M.id);B!==-1&&R!==-1&&p(C.id,B,R)}},children:e.jsx(t.SortableContext,{items:C.groups.map(A=>A.id),strategy:t.verticalListSortingStrategy,children:C.groups.map(A=>I(A,F+1,C.id))})}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs(t.Button,{size:"sm",className:"h-7 text-xs",variant:"outline",onClick:()=>c(C.id),children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"}),"Add Condition"]}),b&&e.jsxs(t.Button,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>h(C.id),children:[e.jsx(t.Plus,{className:"mr-1 h-3 w-3"}),"Add Group"]})]})]})},C.id):e.jsx($r,{group:C,depth:F,parentGroupId:O,onUpdateGroupOperator:g,onUpdateGroupNegate:x,onRemoveGroup:m,onUpdateCondition:N,onUpdateField:S,onRemoveCondition:d,onReorderConditions:v,onReorderGroups:p,onAddCondition:c,onAddGroup:h,availableFields:l,renderFilterGroup:I,updateConditionFields:f},C.id),D=Es(s);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(t.Card,{children:e.jsx(t.CardContent,{className:"p-4",children:e.jsxs("div",{className:"space-y-4",children:[u?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(t.Checkbox,{id:"advanced-mode",checked:b,onCheckedChange:C=>y(!!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)"})]})}),T&&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:k(o)})})]})]})})}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(t.Button,{size:"sm",variant:"outline",onClick:i,children:"Cancel"}),D>0&&e.jsx(t.Button,{variant:"outline",size:"sm",onClick:r,children:"Clear All"}),e.jsx(t.Button,{size:"sm",onClick:()=>n(T?o:null),children:"Apply Filters"})]})]})}function Hr({cardId:s,filters:a,onFiltersChange:n,onClearFilters:r,availableFields:i,isOpen:o,onOpenChange:l}){const u=h=>{n(s,h),l(!1)},c=()=>{r(s),l(!1)};return e.jsx(t.Dialog,{open:o,onOpenChange:l,children:e.jsxs(t.DialogContent,{className:"max-h-[80vh] max-w-4xl overflow-y-auto",children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Card Filters"}),e.jsx(t.DialogDescription,{children:"Add filters to the card to limit the data that is displayed."})]}),e.jsx(Gr,{filters:a,availableFields:i,onSave:u,onCancel:()=>l(!1),onClearAll:c})]})})}function Ds(s,a){return`${t.toLabel(a)} of ${t.toLabel(s)}`}function Ts(s,a){return`${s}-${a.qualifiedEntityName}-${a.name}-${Date.now()}`}function Jr({activeCardId:s,sourceFields:a,getFieldsForContainer:n,setFieldsForContainer:r}){var v;const[i,o]=L.useState(null),l=t.useEditorStore(p=>p.card),u=(v=l==null?void 0:l.config)==null?void 0:v.joinPlan,c=[...a,...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")],h=L.useCallback(p=>p.startsWith("card-")?null:p.startsWith("source-")||a.find(k=>k.id===p)?"source":n("groupBy").find(k=>k.id===p)?"groupBy":n("metrics").find(k=>k.id===p)?"metrics":n("pivotBy").find(k=>k.id===p)?"pivotBy":n("sortBy").find(k=>k.id===p)?"sortBy":null,[a,n]),d=L.useCallback((p,k)=>{var T;return!u||!((T=u.baseEntity)!=null&&T.name)||!u.joins?!1:p===k||p===u.baseEntity.name||k===u.baseEntity.name?!0:u.joins.some(E=>{const j=dt(E.source),b=dt(E.target);return console.log(j,b),console.log(j===p&&b===k||j===k&&b===p),j===p&&b===k||j===k&&b===p})},[u]),m=L.useCallback(()=>{t.ue.error("Join Configuration Required",{richColors:!0,description:"To combine fields from two different tables, you need to define a join between them first.",position:"top-center",duration:4e3})},[]),N=(p,k)=>{const T=Ts(k,p),E=t.getDataType(p.dataType),j=E==="date",b={id:T,name:p.name,dataType:p.dataType,label:t.toLabel(p.name),qualifiedEntityName:p.qualifiedEntityName,entityId:p.entityId,entityName:p.entityName,entityType:p.entityType};if(k==="metrics"){const y=E==="number"?"SUM":"COUNT",S=Ds(p.label,y);return{...b,role:"metric",label:S,aggregate:y}}return k==="groupBy"?{...b,role:"groupby",...j&&{granularity:"month"}}:k==="pivotBy"?{...b,role:"pivotby"}:k==="sortBy"?{...b,role:"sortby",direction:"asc"}:null},f=L.useCallback(p=>{o(p.active.id)},[]),g=L.useCallback(p=>{const{active:k,over:T}=p;if(!T||!s){o(null);return}const E=k.id,j=T.id,b=h(E),y=h(j)||j;if(b==="source"&&y!=="source"){const S=[...a].find(O=>O.id===E);if(!S){o(null);return}const I=[...n("groupBy"),...n("pivotBy"),...n("metrics"),...n("sortBy")];if(I.length>0){const O=I[0].qualifiedEntityName;if(!O){o(null);return}if(O!==S.qualifiedEntityName&&S.qualifiedEntityName)if(u){if(!d(O,S.qualifiedEntityName)){m(),o(null);return}}else{m(),o(null);return}}const D=n(y);if(D.some(O=>O.name===S.name&&O.qualifiedEntityName===S.qualifiedEntityName)){o(null);return}const F=N(S,y);o(null),r(y,[...D,F]);return}if(b&&y&&b!=="source"&&y!=="source"&&b!==y){const S=n(b),I=n(y),D=S.find(O=>O.id===E);if(!D){o(null);return}const C=N(D,y);o(null);const F=S.filter(O=>O.id!==E);r(b,F),r(y,[...I,C]);return}if(b&&y&&b===y&&b!=="source"){const S=n(b),I=S.findIndex(C=>C.id===E),D=S.findIndex(C=>C.id===j);if(I!==D){const C=t.arrayMove(S,I,D);r(b,C)}}o(null)},[s,a,n,r,h,u,m,d]),x=i?c.find(p=>p.id===i):null;return{activeId:i,activeField:x,handleDragStart:f,handleDragEnd:g}}const Ur=s=>{const{updateCardConfig:a,updateGroupByColumn:n,updateMetricColumn:r,updatePivotByColumn:i,updateSortByColumn:o,removeGroupByColumn:l,removeMetricColumn:u,removePivotByColumn:c,removeSortByColumn:h}=t.useEditorActions(),d=s==null?void 0:s.id,m=L.useCallback(E=>{if(!(s!=null&&s.config))return[];switch(E){case"groupBy":return(s.config.groupByColumns||[]).map(j=>({id:j.id,name:j.name,dataType:j.dataType,label:j.label!==void 0?j.label:j.name,qualifiedEntityName:j.qualifiedEntityName,entityId:j.entityId,entityName:j.entityName,entityType:j.entityType,dateFormat:j.dateFormat,customFormat:j.customFormat,granularity:j.granularity}));case"metrics":return s.config.metricColumns||[];case"pivotBy":return(s.config.pivotByColumns||[]).map(j=>({id:j.id,name:j.name,dataType:j.dataType,label:j.label!==void 0?j.label:j.name,qualifiedEntityName:j.qualifiedEntityName,entityId:j.entityId,entityName:j.entityName,entityType:j.entityType}));case"sortBy":return(s.config.sortByColumns||[]).map(j=>({id:j.id,name:j.name,dataType:j.dataType,label:j.label!==void 0?j.label:j.name,qualifiedEntityName:j.qualifiedEntityName,entityId:j.entityId,entityName:j.entityName,entityType:j.entityType,direction:j.direction}));case"source":return[];default:return[]}},[s]),N=L.useCallback((E,j)=>{if(d)switch(E){case"groupBy":{a(d,{groupByColumns:j});break}case"metrics":{a(d,{metricColumns:j});break}case"pivotBy":{a(d,{pivotByColumns:j});break}case"sortBy":{a(d,{sortByColumns:j});break}}},[d,a]),f=L.useCallback((E,j,b)=>{if(!d)return;const S=m(E)[j];if(S)switch(E){case"groupBy":n(d,S.id,{label:b});break;case"metrics":r(d,S.id,{label:b});break;case"pivotBy":i(d,S.id,{label:b});break;case"sortBy":o(d,S.id,{label:b});break}},[d,m,n,r,i,o]),g=L.useCallback((E,j)=>{if(!d)return;const y=m("metrics")[E];y&&r(d,y.id,{aggregate:j,label:Ds(y.name,j)})},[d,m,r]),x=L.useCallback((E,j,b)=>{if(!d)return;const S=m("groupBy")[E];if(!S)return;const I={dateFormat:j};j==="custom"&&b?I.customFormat=b:I.customFormat=void 0,n(d,S.id,I)},[d,m,n]),v=L.useCallback((E,j)=>{if(!d)return;const y=m("groupBy")[E];y&&n(d,y.id,{granularity:j})},[d,m,n]),p=L.useCallback((E,j)=>{if(!d)return;const y=m("metrics")[E];y&&r(d,y.id,{aliasTemplate:j})},[d,m,r]),k=L.useCallback((E,j)=>{if(console.log("handleValueAliasesChange",E,j),!d)return;console.log("handleValueAliasesChange",E,j);const y=m("metrics")[E];y&&(console.log("handleValueAliasesChange",j),r(d,y.id,{valueAliases:j}))},[d,m,r]),T=L.useCallback((E,j)=>{if(!d)return;const y=m(E)[j];if(y)switch(E){case"groupBy":l(d,y.id);break;case"metrics":u(d,y.id);break;case"pivotBy":c(d,y.id);break;case"sortBy":h(d,y.id);break}},[d,m,l,u,c,h]);return{getFieldsForContainer:m,setFieldsForContainer:N,updateLabel:f,handleAggregationChange:g,handleDateFormatChange:x,handleGranularityChange:v,handleAliasTemplateChange:p,handleValueAliasesChange:k,removeField:T}};function Yr({activeView:s,onViewChange:a}){return e.jsx(t.Tabs,{value:s,onValueChange:n=>a(n),children:e.jsxs(t.TabsList,{className:"h-9 w-fit",children:[e.jsx(t.TabsTrigger,{value:"table",className:"text-xs",children:"Results"}),e.jsx(t.TabsTrigger,{value:"chart",className:"text-xs",children:"Chart"}),e.jsx(t.TabsTrigger,{value:"sql",className:"text-xs",children:"SQL"})]})})}const Kr=[{value:"10",label:"Top 10"},{value:"20",label:"Top 20"},{value:"50",label:"Top 50"},{value:"100",label:"Top 100"},{value:"200",label:"Top 200"},{value:"500",label:"Top 500"},{value:"1000",label:"Top 1000"}];function Qr(){var c,h;const s=t.useEditorStore(d=>d.card),{updateRowLimit:a}=t.useEditorActions(),[n,r]=L.useState(!1),[i,o]=L.useState(""),l=d=>{if(d==="custom"){r(!0);return}r(!1),a(s.id,parseInt(d))},u=d=>{const m=d.target.value;o(m),m&&!isNaN(parseInt(m))&&a(s.id,parseInt(m))};return e.jsx("div",{className:"flex items-center gap-2",children:n?e.jsx(t.Input,{type:"number",value:i,onChange:u,className:"h-9 w-24",placeholder:"Enter limit",min:1}):e.jsxs(t.Select,{value:((h=(c=s.config)==null?void 0:c.rowLimit)==null?void 0:h.toString())||"100",onValueChange:l,children:[e.jsx(t.SelectTrigger,{className:"h-9 w-24",children:e.jsx(t.SelectValue,{placeholder:"Select limit"})}),e.jsx(t.SelectContent,{children:Kr.map(d=>e.jsx(t.SelectItem,{value:d.value,children:d.label},d.value))})]})})}function Wr({activeView:s,onViewChange:a,showDebug:n,onDebugToggle:r,onAccept:i,onClear:o,onAdvancedToggle:l,onFiltersClick:u,filterCount:c,activeCard:h,columns:d,columnsLoading:m,columnsError:N}){var S;const f=t.useEditorStore(I=>I.card),{updateCardConfig:g}=t.useEditorActions(),x=t.useEditorStore(I=>I.showAIDialog),{data:v,errorMessage:p,isPending:k,isLoading:T,isFetching:E}=t.useDashboardCardQuery(h);function j(){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(f.config||{},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(h.dataSource||{},null,2)})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"mb-2 text-sm font-medium text-gray-700",children:["Columns (",d.length,")"]}),e.jsx("pre",{className:"max-h-40 overflow-auto rounded border bg-background p-3 text-xs text-gray-800",children:m?"Loading...":N?"Error loading columns":JSON.stringify(d.slice(0,5),null,2)})]})]})})}const b=I=>{if(!f.config)return;if(!I.length){g(f.id,{...f.config,sortByColumns:[]});return}const D=f.config,C=I.map(({id:F,desc:O})=>{var B,R;const A=(B=D.metricColumns)==null?void 0:B.find(P=>P.label===F),w=(R=D.groupByColumns)==null?void 0:R.find(P=>P.label===F),M=A||w;return M?{id:Ts("sortBy",M),name:M.name,dataType:M.dataType,label:M.label,qualifiedEntityName:M.qualifiedEntityName,entityId:M.entityId,entityName:M.entityName,entityType:M.entityType,role:"sortby",direction:O?"desc":"asc"}:null}).filter(F=>F!==null);g(f.id,{...D,sortByColumns:C})},y=L.useMemo(()=>{var I,D;return(D=(I=f.config)==null?void 0:I.sortByColumns)==null?void 0:D.map(C=>({id:C.label,desc:C.direction==="desc"}))},[(S=f.config)==null?void 0:S.sortByColumns]);return e.jsxs("div",{className:"flex w-0 grow flex-col",children:[e.jsx(t.ExplorerHeader,{showDebug:n,onDebugToggle:r,onAccept:i,onClear:o,onAdvancedToggle:l,onFiltersClick:u,filterCount:c}),n&&j(),e.jsxs("div",{className:"group/visualization flex max-w-full grow flex-col",children:[e.jsxs("div",{className:"z-50 flex items-center gap-2 px-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(Yr,{activeView:s,onViewChange:a}),e.jsx(Qr,{})]}),u&&e.jsxs(t.Button,{variant:"outline",size:"sm",className:"gap-1",onClick:u,children:[e.jsx(gt,{className:"h-3.5 w-3.5"}),c>0&&e.jsx("span",{className:"ml-1 rounded-full bg-blue-100 px-1.5 py-0.5 text-xs text-blue-800",children:c})]}),e.jsxs("div",{className:t.cn("flex grow items-center justify-end",{"justify-between":x}),children:[s==="chart"&&x&&e.jsx(fs,{variant:"outline"}),e.jsx("div",{className:"opacity-0 transition-opacity group-hover/visualization:opacity-100",children:s==="chart"&&e.jsx(gs,{})})]})]}),e.jsxs("div",{className:"flex grow flex-col",children:[s==="chart"&&e.jsx("div",{className:"flex grow flex-col pb-6",children:T||E?e.jsx("div",{className:"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.jsx(js,{})}),s==="table"&&(v==null?void 0:v.records)&&e.jsx("div",{className:"flex h-full min-h-0 max-w-full flex-1 grow basis-0 p-6",children:e.jsx(t.TableVisual,{card:h,data:v==null?void 0:v.records,onSortChange:b,sortState:y})}),s==="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(os,{sql:v==null?void 0:v.sql,error:p})]})})]})]})]})}function Xr({activeField:s}){const[a,n]=L.useState(!0);return L.useEffect(()=>{s&&n(!0)},[s]),s?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(t.GripVertical,{className:"h-3 w-3 text-gray-400"}),e.jsx(ks,{dataType:s.dataType}),e.jsx("span",{className:"text-sm dark:text-muted-foreground",children:s.name})]}):null}const Zr=()=>{const s=console.error;console.error=(...r)=>{r.length>0&&typeof r[0]=="string"&&r[0].includes("ResizeObserver loop completed with undelivered notifications")||s.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=s,window.removeEventListener("error",a,!0),window.removeEventListener("unhandledrejection",n,!0)}};function ei(){var _,H;const[s,a]=L.useState("chart"),[n,r]=L.useState(!1),[i,o]=L.useState(!1),l=t.useEditorStore(Y=>Y.showAIDialog),{setCardType:u}=t.useEditorActions(),c=t.useEditorStore(Y=>Y.card.type);L.useEffect(()=>Zr(),[]);const h=()=>{console.log("Accept clicked - would save/apply current configuration")},d=()=>{console.log("Clear clicked - would reset all configurations")},m=()=>{console.log("Advanced mode toggled")},N=()=>{o(!0)},f=Y=>{u(Y)},g=t.useEditorStore(Y=>Y.frame),x=t.useEditorStore(Y=>Y.card);t.useEditorStore(Y=>Y.activeTabCardId),t.useEditorStore(Y=>Y.actions.getAvailableFields);const{addCard:v,removeCard:p,updateCard:k,setActiveCard:T,updateFilters:E}=t.useEditorActions(),{columns:j=[],isLoading:b,error:y}=Me(),S=t.useSensors(t.useSensor(t.PointerSensor,{activationConstraint:{distance:8}})),I=x,{getFieldsForContainer:D,setFieldsForContainer:C,updateLabel:F,handleAggregationChange:O,handleDateFormatChange:A,handleGranularityChange:w,handleAliasTemplateChange:M,handleValueAliasesChange:B,removeField:R}=Ur(I),{activeField:P,handleDragStart:z,handleDragEnd:K}=Jr({activeCardId:g.activeCardId,sourceFields:j,getFieldsForContainer:D,setFieldsForContainer:C}),J=(Y,Z)=>{Z&&E(Y,Z)},G=Y=>{var Z;k(Y,{config:{...(Z=g.cards.find(de=>de.id===Y))==null?void 0:Z.config,filters:void 0}})},U=j,q=Y=>{if(!Y)return 0;let Z=Y.conditions.length;return Y.groups.forEach(de=>{Z+=q(de)}),Z},V=q(((_=I==null?void 0:I.config)==null?void 0:_.filters)||null);return e.jsxs(t.DndContext,{sensors:S,collisionDetection:t.closestCenter,onDragStart:z,onDragEnd:K,children:[e.jsxs("div",{className:"flex h-full grow",children:[e.jsx(br,{}),!l&&e.jsx(Dr,{selectedChart:c,onChartChange:f,groupByFields:D("groupBy"),pivotByFields:D("pivotBy"),metricsFields:D("metrics"),sortByFields:D("sortBy"),onRemoveField:R,onLabelChange:F,onAggregationChange:O,onDateFormatChange:A,onGranularityChange:w,onAliasTemplateChange:M,onValueAliasesChange:B}),e.jsx(Wr,{selectedChart:c,activeView:s,onViewChange:a,showDebug:n,onDebugToggle:()=>r(!n),onAccept:h,onClear:d,onAdvancedToggle:m,onFiltersClick:N,filterCount:V,activeCard:I,dataSourceState:x.dataSource||t.EMPTY_DATA_SOURCE,columns:j,columnsLoading:b,columnsError:y,getFieldsForContainer:D,cards:g.cards,activeCardId:g.activeCardId,addCard:v,setActiveCard:T})]}),I&&e.jsx(Hr,{cardId:I.id,filters:((H=I.config)==null?void 0:H.filters)||null,onFiltersChange:J,onClearFilters:G,availableFields:U,isOpen:i,onOpenChange:o}),e.jsx(t.DragOverlay,{dropAnimation:null,children:e.jsx(Xr,{activeField:P||null})})]})}function ti({authToken:s,onSave:a,onClose:n}){const r=L.useRef(null),i=t.useEditorStore(k=>k.showAIDialog),o=t.useEditorStore(k=>k.isDevMode),{setAuthToken:l}=t.useDashboardActions(),{setShowAIDialog:u,setOnSave:c,setOnClose:h}=t.useEditorActions(),{handleDragOver:d,handleDragEnd:m,handleDragStart:N,handleDragCancel:f,sensors:g}=Un();L.useEffect(()=>{a&&c(a),n&&h(n)},[a,c,n,h]),L.useEffect(()=>{s&&s.accessToken&&l(s)},[s,l]),L.useEffect(()=>{var k,T;i?((k=r.current)==null||k.resize(40),u(!0)):(u(!1),(T=r.current)==null||T.resize(0))},[i,u]);function x(k){k<1?u(!1):i||u(!0)}function v(){return e.jsxs(e.Fragment,{children:[e.jsx(is,{type:"main"}),e.jsxs(t.ResizablePanelGroup,{"data-content":"editor-main",className:"grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] rounded-none",children:e.jsx(lr,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(Gt,{})})]})]})}function p(){return e.jsxs(t.ResizablePanelGroup,{"data-content":"explorer",className:"flex grow",direction:"horizontal",children:[e.jsx(t.ResizablePanel,{className:"min-w-[510px] grow rounded-none",children:e.jsx(ei,{})}),e.jsx(t.ResizableHandle,{}),e.jsx(t.ResizablePanel,{"data-role":"editor-assistant-panel",ref:r,onResize:x,defaultSize:0,children:e.jsx(Gt,{})})]})}return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:o?e.jsx(t.DndContext,{sensors:g,onDragStart:N,onDragEnd:m,onDragOver:d,onDragCancel:f,children:e.jsx("section",{className:"isolate flex h-full grow","data-content":"editor-panel",children:v()})}):p()})}function si(){t.useDashboardStore(l=>l.selectedCardId);const s=t.useDashboardStore(l=>l.selectedSheetId),{setIsVisualEditing:a}=t.useDashboardStore(l=>l.actions),n=t.useDashboardStore(l=>l.isVisualEditing),r=t.useDashboardStore(l=>l.actions.updateFrame);function i(l){s&&(r(s,l),a(!1))}function o(){a(!1)}return e.jsx("div",{role:"editor-container",className:t.cn("flex grow",{"max-h-0 overflow-hidden":!n}),children:e.jsx(ti,{onSave:i,onClose:o})})}function ni(){const s=t.useEditorStore(o=>o.selectedDatabaseName),a=t.useEditorStore(o=>o.selectedTableName),n=t.useDashboardStore(o=>o.dashboard.filters)||[],{columns:r}=t.useEditorAside(),{assignFilter:i}=Cs();return e.jsx(t.ScrollArea,{className:"flex-1 basis-0 flex-col px-3",children:r==null?void 0:r.map(o=>{const l=n==null?void 0:n.find(u=>u.column===t.fmt(o.column_name)&&u.table===a&&u.database===s);return e.jsx("div",{onClick:()=>i(o),className:t.cn("group flex cursor-pointer items-center justify-between border border-dashed border-background px-3 py-[6px] text-sm transition-colors hover:bg-muted/50",{"bg-muted":l}),children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(St,{column:o}),e.jsx("span",{children:o.column_name})]})},o.column_name)})})}function ai(){t.useDashboardStore(a=>a.showFilters);const s=t.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(t.Label,{className:"px-2 text-lg",children:"Filters"}),e.jsx(t.Button,{onClick:()=>s(!1),className:"h-7 w-7 p-0",variant:"ghost",children:e.jsx(t.Cross2Icon,{})})]}),e.jsx("div",{className:"flex grow",children:e.jsx(is,{type:"filter",ColumnsComponent:()=>e.jsx(ni,{})})})]})}function ri(){const s=t.useDashboardStore(r=>r.dashboard.filters),a=t.useDashboardStore(r=>r.theme),n=s==null?void 0:s.filter(r=>r.hide);return n!=null&&n.length?e.jsx("div",{className:t.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(t.FilterHeader,{filter:r}),e.jsx(t.FilterComponent,{filter:r})]},r.id))}):null}function ii(){const s=t.useDashboardStore(r=>r.showFilters),a=t.useDashboardStore(r=>r.isVisualEditing),n=t.useDashboardStore(r=>r.isDashboardEditing);return e.jsxs("div",{role:"dashboard-plus-main",className:t.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(ri,{}),e.jsx(t.DashboardTabs,{})]}),s&&e.jsx("div",{role:"filter-aside-container",className:"flex",children:e.jsx(ai,{})})]})}function oi(){const s=t.useDashboardStore(i=>i.dashboard),a=t.useDashboardStore(i=>i.actions.setDashboard),n=t.useDashboardStore(i=>i.showDashboardJSON),r=t.useDashboardStore(i=>i.actions.setShowDashboardJSON);return e.jsxs("div",{className:t.cn("relative p-2",{hidden:!n}),children:[e.jsxs(t.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>r(!1),children:[e.jsx(t.X,{className:"mr-2 h-4 w-4"}),"Close"]}),e.jsx(t.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(s,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}function li({showControls:s=!1,showFooter:a=!0,...n}){return e.jsx(t.ErrorBoundary,{FallbackComponent:t.Fallback,children:e.jsxs(t.SemaphorContextProvider,{dashboardProps:n,children:[e.jsx(t.$e,{}),e.jsxs(t.UXProvider,{children:[e.jsx(oi,{}),e.jsxs(t.DashboardPanel,{...n,children:[s&&e.jsx(_n,{}),e.jsx(si,{}),e.jsx(ii,{})]})]})]})})}exports.DashboardPlus=li;exports.ScheduleDashboard=as;exports.SelectComponent=ve;exports.cleanCard=ts;exports.downloadPdf=ns;exports.getDashbaordStateWithoutData=Ct;
|